Search in sources :

Example 6 with Subfield

use of org.marc4j.marc.Subfield 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 7 with Subfield

use of org.marc4j.marc.Subfield 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 8 with Subfield

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

the class EANUtils method createEan.

/**
 * @param rawDataField {@link DataField}, usually tag 024, 1. indicator = 3
 * @return {@link Ean}
 */
public static Ean createEan(final DataField rawDataField) {
    Subfield subfieldA = rawDataField.getSubfield('a');
    if (rawDataField.getIndicator1() != '3' || subfieldA == null)
        throw new NoDataException(IdentifierUtils.NO_SUBFIELD);
    Matcher matcher = EAN_NOTE_PATTERN.matcher(subfieldA.getData());
    if (!matcher.find())
        throw new NoDataException(IdentifierUtils.NO_USABLE_DATA);
    Long validEan = getEAN13Long(matcher.group(1));
    if (validEan == null)
        throw new NumberFormatException(matcher.group(1));
    List<String> notes = new ArrayList<>();
    notes.add(IdentifierUtils.parseNote(matcher.group(2)));
    for (Subfield subfieldQ : rawDataField.getSubfields('q')) {
        notes.add(IdentifierUtils.parseNote(subfieldQ.getData()));
    }
    return Ean.create(validEan, 1L, String.join(" ", notes));
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Subfield(org.marc4j.marc.Subfield)

Example 9 with Subfield

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

the class ISBNUtils method createIsbn.

/**
 * @param rawDataField {@link DataField}, usually tag 020
 * @return {@link Isbn}
 */
public static Isbn createIsbn(final DataField rawDataField) {
    Subfield subfieldA = rawDataField.getSubfield('a');
    if (subfieldA == null)
        throw new NoDataException(IdentifierUtils.NO_SUBFIELD);
    Matcher matcherIsbn = ISBN_PATTERN.matcher(subfieldA.getData());
    if (!matcherIsbn.find())
        throw new NoDataException(IdentifierUtils.NO_USABLE_DATA);
    Long isbnLong = toISBN13LongThrowing(matcherIsbn.group(1));
    List<String> notes = new ArrayList<>();
    notes.add(IdentifierUtils.parseNote(matcherIsbn.group(2)));
    for (Subfield subfieldQ : rawDataField.getSubfields('q')) {
        notes.add(IdentifierUtils.parseNote(subfieldQ.getData()));
    }
    return Isbn.create(isbnLong, 1L, String.join(" ", notes));
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Subfield(org.marc4j.marc.Subfield)

Example 10 with Subfield

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

the class ISSNUtils method createIssn.

/**
 * @param rawDataField {@link DataField}, usually tag 022
 * @return {@link Issn}
 */
public static Issn createIssn(final DataField rawDataField) {
    Subfield subfieldA = rawDataField.getSubfield('a');
    if (subfieldA == null)
        throw new NoDataException(IdentifierUtils.NO_SUBFIELD);
    Matcher matcherIssn = ISSN_PATTERN.matcher(subfieldA.getData());
    if (!matcherIssn.find())
        throw new NoDataException(IdentifierUtils.NO_USABLE_DATA);
    if (!isValidLocal(matcherIssn.group(1)))
        throw new NumberFormatException(matcherIssn.group(1));
    List<String> notes = new ArrayList<>();
    notes.add(IdentifierUtils.parseNote(matcherIssn.group(2)));
    for (Subfield subfieldQ : rawDataField.getSubfields('q')) {
        notes.add(IdentifierUtils.parseNote(subfieldQ.getData()));
    }
    return Issn.create(matcherIssn.group(1), 1L, String.join(" ", notes));
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Subfield(org.marc4j.marc.Subfield)

Aggregations

Subfield (org.marc4j.marc.Subfield)24 DataField (org.marc4j.marc.DataField)17 ArrayList (java.util.ArrayList)8 Matcher (java.util.regex.Matcher)6 ControlField (org.marc4j.marc.ControlField)4 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)3 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)3 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)3 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)3 List (java.util.List)3 TreeSet (java.util.TreeSet)3 MarcFactory (org.marc4j.marc.MarcFactory)3 Record (org.marc4j.marc.Record)3 IOException (java.io.IOException)2 Oclc (cz.mzk.recordmanager.server.model.Oclc)1 Sigla (cz.mzk.recordmanager.server.model.Sigla)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 StringJoiner (java.util.StringJoiner)1 Pair (org.apache.commons.lang3.tuple.Pair)1