package no.deichman.services.entity.external;

import org.marc4j.marc.ControlField;

/**
 *  Extends MARCMapper by extracting local id from 001.
 */
public class DFBMarcMapper extends MARCMapper {
    DFBMarcMapper(String cataloguingSourceUri, boolean simpleIdGenerator) {
        super(cataloguingSourceUri, simpleIdGenerator);
    }

    DFBMarcMapper(Target cataloguingSource) {
        super(cataloguingSource);
    }

    DFBMarcMapper(Target cataloguingSource, boolean simpleIdGenerator) {
        super(cataloguingSource, simpleIdGenerator);
    }

    @Override
    protected final boolean handleControlFieldHook(ControlField controlField, Work work, Publication publication) {
        if (controlField.getTag().equals("001")) {
            getControlFieldValue(controlField).ifPresent(publication::setCataloguingSourceIdentifier);
            return true;
        } else {
            return false;
        }
    }
}

@@ -856,11 +856,12 @@
 urn 
-tru
+fals
 e;%0A 
@@ -872,20 +872,9 @@
    %7D
- else %7B%0A    
+%0A
     
@@ -884,32 +884,21 @@
  return 
-false;%0A        %7D
+true;
 %0A    %7D%0A%7D

fix mapping of control field 008 (DFB)