Search in sources :

Example 21 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class MarcRecordImpl method addDataField.

@Override
public void addDataField(String tag, char ind1, char ind2, String... subfields) {
    MarcFactory factory = MarcFactoryImpl.newInstance();
    DataField df = factory.newDataField(tag, ind1, ind2, subfields);
    record.addVariableField(df);
}
Also used : DataField(org.marc4j.marc.DataField) MarcFactory(org.marc4j.marc.MarcFactory)

Example 22 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class AdresarKnihovenMarcFunctions method adresarGetHours.

public String adresarGetHours(MarcFunctionContext ctx) {
    String separator = " | ";
    for (DataField df : ctx.record().getDataFields("OTD")) {
        StringBuilder sb = new StringBuilder();
        for (Subfield sf : df.getSubfields()) {
            try {
                List<String> get = propertyResolver.resolve(MAP_ADRESAR_HOURS).get(String.valueOf(sf.getCode()));
                if (get != null) {
                    if (sb.length() > 0)
                        sb.append(separator);
                    sb.append(get.get(0) + " " + sf.getData());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        String temp = sb.toString();
        if (!temp.isEmpty())
            return temp;
    }
    return null;
}
Also used : DataField(org.marc4j.marc.DataField) IOException(java.io.IOException) Subfield(org.marc4j.marc.Subfield)

Example 23 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class AdresarKnihovenMarcFunctions method adresarGetUrlDisplay.

public List<String> adresarGetUrlDisplay(MarcFunctionContext ctx) {
    List<String> results = new ArrayList<>();
    results.addAll(ctx.record().getFields("URL", " | ", 'u', 'z'));
    for (DataField df : ctx.record().getDataFields("ADK")) {
        if (df.getSubfield('u') != null) {
            results.add(df.getSubfield('u').getData() + " | " + (df.getSubfield('z') != null ? df.getSubfield('z').getData() : URL_COMMENT));
        }
    }
    return results.isEmpty() ? null : results;
}
Also used : DataField(org.marc4j.marc.DataField)

Example 24 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class GetStatusesMarcFunctions method getStatuses.

private List<String> getStatuses(MarcRecord record, String statusField) {
    List<DataField> fields = record.getAllFields().get(statusField);
    if (fields == null || fields.isEmpty()) {
        return Collections.emptyList();
    }
    List<String> statuses = new ArrayList<String>();
    boolean present = false;
    boolean absent = false;
    boolean freestack = false;
    for (DataField field : fields) {
        Subfield s = field.getSubfield('s');
        if (s == null) {
            continue;
        }
        String statusInS = s.getData().toLowerCase();
        switch(statusInS) {
            case ABSENT:
                absent = true;
                break;
            case PRESENT:
                present = true;
                break;
        }
        s = field.getSubfield('a');
        if (s == null) {
            continue;
        }
        String statusInA = s.getData().toLowerCase();
        switch(statusInA) {
            case FREESTACK:
                freestack = true;
                break;
        }
    }
    if (absent) {
        statuses.addAll(SolrUtils.createHierarchicFacetValues("absent"));
    }
    if (present) {
        statuses.addAll(SolrUtils.createHierarchicFacetValues("present"));
    }
    if (freestack) {
        statuses.addAll(SolrUtils.createHierarchicFacetValues("freestack"));
    }
    return statuses;
}
Also used : DataField(org.marc4j.marc.DataField) ArrayList(java.util.ArrayList) Subfield(org.marc4j.marc.Subfield)

Example 25 with DataField

use of org.marc4j.marc.DataField in project RecordManager2 by moravianlibrary.

the class RecordUtils method sortFields.

public static Record sortFields(Record record) {
    Record newRecord = factory.newRecord();
    newRecord.setLeader(record.getLeader());
    for (ControlField cf : record.getControlFields()) {
        newRecord.addVariableField(cf);
    }
    MarcRecord marc = new MarcRecordImpl(record);
    Map<String, List<DataField>> dfMap = marc.getAllFields();
    for (String tag : new TreeSet<>(dfMap.keySet())) {
        // sorted tags
        for (DataField df : dfMap.get(tag)) {
            newRecord.addVariableField(df);
        }
    }
    return newRecord;
}
Also used : ControlField(org.marc4j.marc.ControlField) MarcRecordImpl(cz.mzk.recordmanager.server.marc.MarcRecordImpl) DataField(org.marc4j.marc.DataField) TreeSet(java.util.TreeSet) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) Record(org.marc4j.marc.Record) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) List(java.util.List)

Aggregations

DataField (org.marc4j.marc.DataField)82 ArrayList (java.util.ArrayList)18 Subfield (org.marc4j.marc.Subfield)17 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)15 ControlField (org.marc4j.marc.ControlField)13 Record (org.marc4j.marc.Record)13 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)12 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)11 List (java.util.List)11 TreeSet (java.util.TreeSet)11 Matcher (java.util.regex.Matcher)11 MarcFactory (org.marc4j.marc.MarcFactory)8 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 NoDataException (cz.mzk.recordmanager.server.util.identifier.NoDataException)4 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)3 IOException (java.io.IOException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)2 ShortTitle (cz.mzk.recordmanager.server.model.ShortTitle)2