Search in sources :

Example 41 with DataField

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

the class AbstractMeshVizFields method getEnrichingValues.

@Override
protected List<String> getEnrichingValues(String key, String enrichingField) {
    if (config == null) {
        List<ImportConfiguration> configs = configDao.findByIdPrefix(Constants.PREFIX_MESH);
        if (configs != null && !configs.isEmpty()) {
            config = configs.get(0);
        }
    }
    Map<String, List<String>> cache = cacheMap.get(enrichingField);
    if (cache.containsKey(key)) {
        return new ArrayList<>(cache.get(key));
    } else {
        TezaurusRecord tr = tezaurusDao.findByConfigAndSourceFieldAndName(config, "1" + enrichingField.substring(1), key);
        if (tr != null) {
            MarcRecord mr = marcXmlParser.parseRecord(new ByteArrayInputStream(tr.getRawRecord()));
            List<String> results = new ArrayList<>();
            for (DataField df : mr.getDataFields(enrichingField)) {
                if (df.getSubfield('a') != null && df.getSubfield('7') != null && df.getSubfield('7').getData().startsWith("cze")) {
                    results.add(df.getSubfield('a').getData());
                }
            }
            if (!results.isEmpty()) {
                results = Collections.unmodifiableList(results);
                cache.put(key, results);
                return new ArrayList<>(results);
            }
        }
    }
    return null;
}
Also used : DataField(org.marc4j.marc.DataField) ByteArrayInputStream(java.io.ByteArrayInputStream) TezaurusRecord(cz.mzk.recordmanager.server.model.TezaurusRecord) ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ArrayList(java.util.ArrayList) List(java.util.List) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration)

Example 42 with DataField

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

the class MarcDSL method getAuthorExact.

public String getAuthorExact() {
    List<DataField> list = record.getDataFields("100");
    if (list.isEmpty())
        return null;
    DataField df = list.get(0);
    String name = getNameForExact(df);
    if (name != null && name.isEmpty())
        return null;
    else
        return name;
}
Also used : DataField(org.marc4j.marc.DataField)

Example 43 with DataField

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

the class MarcDSL method getAuthorFacet.

/**
 * remove dot at the end of 700d
 */
public List<String> getAuthorFacet(String k) {
    Set<String> results = new HashSet<>();
    results.addAll(getFields("100abcdq:975abcdq"));
    char[] sfCodes = new char[] { 'a', 'b', 'c', 'd', 'q' };
    for (DataField df : record.getDataFields("700")) {
        String author = "";
        for (char c : sfCodes) {
            if (df.getSubfield(c) != null) {
                author += df.getSubfield(c).getData() + " ";
                if (c == 'd') {
                    author = author.trim();
                    if (author.endsWith("."))
                        author = author.substring(0, author.length() - 1);
                }
            }
        }
        if (!author.isEmpty())
            results.add(author.trim());
    }
    return new ArrayList<>(results);
}
Also used : DataField(org.marc4j.marc.DataField)

Example 44 with DataField

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

the class MarcDSL method getISBNISSNISMN.

public Set<String> getISBNISSNISMN() {
    Set<String> result = new HashSet<String>();
    for (DataField df : record.getDataFields("024")) {
        if (df.getIndicator1() == '2') {
            result.addAll(getFields("024az"));
        }
    }
    result.addAll(getFields("020az:022az:787xz:902a"));
    return result;
}
Also used : DataField(org.marc4j.marc.DataField)

Example 45 with DataField

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

the class MarcDSL method getConspectus.

public Set<String> getConspectus() throws IOException {
    Set<String> result = new HashSet<>();
    for (DataField df : record.getDataFields("072")) {
        if ((df.getSubfield('2') != null) && (df.getSubfield('2').getData().equals("Konspekt")) && (df.getSubfield('9') != null) && (df.getSubfield('x') != null && (df.getSubfield('a') != null))) {
            String subcat_code_source = df.getSubfield('a').getData().trim();
            String subcat_name_source = df.getSubfield('x').getData().trim();
            String cat_code_source = df.getSubfield('9').getData().trim();
            boolean cat_code_exists = false;
            List<String> cat_code = translate(MAP_CONSPECTUS_SUBCAT_CAT_CHANGE, subcat_code_source, null);
            if (cat_code != null) {
                String[] split = cat_code.get(0).split("\\|");
                if (split[1].equals(cat_code_source)) {
                    cat_code_source = split[0];
                    cat_code_exists = true;
                }
            }
            if (!cat_code_exists) {
                cat_code = translate(MAP_CATEGORY_SUBCATEGORY, subcat_code_source, null);
                if (cat_code == null || !cat_code.contains(cat_code_source))
                    continue;
            }
            List<String> subcat_name = translate(MAP_SUBCATEGORY_NAME, subcat_code_source, null);
            if (subcat_name != null && subcat_name.contains(subcat_name_source)) {
                String subcat_name_for_facet = null;
                List<String> subcat_name_temp = translate(MAP_CONSPECTUS_NAMES, subcat_code_source + " - " + subcat_name_source, null);
                if (subcat_name_temp != null && !subcat_name_temp.isEmpty()) {
                    subcat_name_for_facet = subcat_name_temp.get(0);
                } else
                    subcat_name_for_facet = subcat_name_source;
                List<String> category = translate(MAP_CONSPECTUS_CATEGORY, cat_code_source, null);
                result.addAll(SolrUtils.createHierarchicFacetValues(category.get(0), subcat_name_for_facet));
            }
        }
    }
    return result;
}
Also used : DataField(org.marc4j.marc.DataField)

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