Search in sources :

Example 31 with DataField

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

the class OsobnostiRegionuXmlStreamReader method addFields003And040.

private void addFields003And040(String f003, String sigla) {
    newControlfield("003", f003);
    DataField df = factory.newDataField("040", ' ', ' ');
    newSubfield(df, 'a', sigla);
    newSubfield(df, 'b', TEXT_040B);
    newSubfield(df, 'd', TEXT_040D);
    record.addVariableField(df);
}
Also used : DataField(org.marc4j.marc.DataField)

Example 32 with DataField

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

the class OsobnostiRegionuXmlStreamReader method addField678.

private void addField678(String field, String description) {
    if (!field.isEmpty())
        field += ". ";
    if (!field.isEmpty() || !description.isEmpty()) {
        DataField df = factory.newDataField("678", '0', ' ');
        newSubfield(df, 'a', TEXT_670A_FRONT + field + description.trim());
        record.addVariableField(df);
    }
}
Also used : DataField(org.marc4j.marc.DataField)

Example 33 with DataField

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

the class SfxJibXmlStreamReader method next.

/**
 * Returns the next record in the iteration.
 *
 * @return Record - the record object
 */
public Record next() {
    record = null;
    List<DataField> isbns = new ArrayList<>();
    List<DataField> issns = new ArrayList<>();
    String coverage = null;
    String from = null;
    int minFrom = Integer.MAX_VALUE;
    String to = null;
    int maxTo = 0;
    String embargo = null;
    String type = null;
    Set<String> years = new TreeSet<>();
    int volumeFirstYear = 0;
    int volumeYear = 0;
    try {
        while (xmlReader.hasNext()) {
            switch(xmlReader.getEventType()) {
                case XMLStreamReader.START_ELEMENT:
                    switch(xmlReader.getLocalName()) {
                        case ELEMENT_RECORD:
                            record = factory.newRecord();
                            addFields();
                            break;
                        case ELEMENT_ID:
                            record.addVariableField(factory.newControlField("001", xmlReader.getElementText()));
                            break;
                        case ELEMENT_ISSN:
                            issns.add(getIsxnField("022"));
                            break;
                        case ELEMENT_EISSN:
                            issns.add(0, getIsxnField("022"));
                            break;
                        case ELEMENT_ISBN:
                            isbns.add(getIsxnField("020"));
                            break;
                        case ELEMENT_EISBN:
                            isbns.add(0, getIsxnField("020"));
                            break;
                        case ELEMENT_OBJECT_TYPE:
                            type = xmlReader.getElementText();
                            record.addVariableField(factory.newDataField("300", ' ', ' ', "a", type));
                            break;
                        case ELEMENT_AUTHOR:
                            if (record.getVariableField("100") == null) {
                                record.addVariableField(factory.newDataField("100", '1', '#', "a", xmlReader.getElementText()));
                            } else {
                                record.addVariableField(factory.newDataField("700", '1', '0', "a", xmlReader.getElementText()));
                            }
                            break;
                        case ELEMENT_TITLE:
                            if (record.getVariableField("245") == null) {
                                String data = xmlReader.getElementText();
                                Matcher matcher;
                                char ind2 = '0';
                                if ((matcher = PREFIX.matcher(data)).matches()) {
                                    ind2 = Character.forDigit(matcher.group(1).length(), 10);
                                }
                                record.addVariableField(factory.newDataField("245", '1', ind2, "a", data));
                            } else {
                                record.addVariableField(factory.newDataField("246", '0', '3', "a", xmlReader.getElementText()));
                            }
                            break;
                        case ELEMENT_DAYS_AVAILABLE:
                            String available = xmlReader.getElementText();
                            if (record.getVariableField("500") == null) {
                                record.addVariableField(factory.newDataField("500", ' ', ' ', "a", TEXT_EMBARGO_AVAILABLE + available));
                            }
                            embargo = "a" + available;
                            break;
                        case ELEMENT_DAYS_NOT_AVAILABLE:
                            String notAvailable = xmlReader.getElementText();
                            if (record.getVariableField("500") == null) {
                                record.addVariableField(factory.newDataField("500", ' ', ' ', "a", TEXT_EMBARGO_NOT_AVAILABLE + notAvailable));
                            }
                            embargo = "n" + notAvailable;
                            break;
                        case ELEMENT_FROM:
                            coverage = "from";
                            break;
                        case ELEMENT_TO:
                            coverage = "to";
                            break;
                        case ELEMENT_YEAR:
                            String year = xmlReader.getElementText();
                            if (coverage != null) {
                                if (coverage.equals("from")) {
                                    from = year;
                                } else
                                    to = year;
                            }
                            volumeYear = (year != null) ? Integer.valueOf(year) : 0;
                            break;
                        case ELEMENT_VOLUME:
                            if (volumeFirstYear < 0) {
                                // error
                                break;
                            }
                            String volumeStr = xmlReader.getElementText();
                            if (volumeStr != null && volumeYear != 0) {
                                int volumeFirstYearLocal = volumeYear - Integer.valueOf(volumeStr) + 1;
                                if (volumeFirstYear == 0) {
                                    // new first year
                                    volumeFirstYear = volumeFirstYearLocal;
                                } else if (volumeFirstYear != volumeFirstYearLocal) {
                                    // error
                                    volumeFirstYear = -1;
                                }
                            }
                            break;
                    }
                    break;
                case XMLStreamReader.END_ELEMENT:
                    switch(xmlReader.getLocalName()) {
                        case ELEMENT_RECORD:
                            while (xmlReader.hasNext() && xmlReader.getEventType() != XMLStreamReader.START_ELEMENT) {
                                xmlReader.next();
                            }
                            isbns.forEach(df -> record.addVariableField(df));
                            issns.forEach(df -> record.addVariableField(df));
                            String year008 = "        ";
                            String year260 = "";
                            if (minFrom != Integer.MAX_VALUE) {
                                if (SERIALS.contains(type)) {
                                    year260 = String.valueOf(minFrom) + "-" + ((minFrom < maxTo) ? String.valueOf(maxTo) : "");
                                    year008 = String.valueOf(minFrom) + ((maxTo == 0) ? "9999" : maxTo);
                                } else {
                                    year260 = String.valueOf(minFrom);
                                    year008 = String.valueOf(minFrom) + "    ";
                                }
                                record.addVariableField(factory.newDataField("260", ' ', ' ', "c", year260));
                            }
                            record.addVariableField(factory.newControlField("008", String.format(TEXT_008, year008)));
                            record.setLeader(factory.newLeader(SERIALS.contains(type) ? TEXT_LEADER_SERIAL : TEXT_LEADER_MONOGRAPH));
                            generateFields996(years, volumeFirstYear);
                            return RecordUtils.sortFields(record);
                        case ELEMENT_FROM:
                        case ELEMENT_TO:
                            coverage = null;
                            break;
                        case ELEMENT_COVERAGE:
                            try {
                                if (Integer.valueOf(from) < minFrom) {
                                    minFrom = Integer.valueOf(from);
                                }
                                if (maxTo < Integer.valueOf(to)) {
                                    maxTo = Integer.valueOf(to);
                                }
                            } catch (Exception e) {
                            }
                            generateYears(years, from, to, embargo);
                            from = to = embargo = null;
                            break;
                    }
                    break;
            }
            xmlReader.next();
        }
    } catch (XMLStreamException e) {
        e.printStackTrace();
    }
    return record;
}
Also used : DataField(org.marc4j.marc.DataField) XMLStreamException(javax.xml.stream.XMLStreamException) Matcher(java.util.regex.Matcher) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 34 with DataField

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

the class ZakonyProLidiMetadataXmlStreamReader method addField6557.

private void addField6557(String textA, String text7, String text2) {
    DataField df = factory.newDataField("655", '7', ' ');
    newSubfield(df, 'a', textA);
    newSubfield(df, '7', text7);
    newSubfield(df, '2', text2);
    record.addVariableField(df);
}
Also used : DataField(org.marc4j.marc.DataField)

Example 35 with DataField

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

the class ZakonyProLidiMetadataXmlStreamReader method addField260.

private void addField260() throws ParseException {
    DataField df = factory.newDataField("260", ' ', ' ');
    newSubfield(df, 'c', SDF_260.format(SDF_ORIGIN.parse(getAttr(ATTR_NAME_PUBLISH_DATE))));
    record.addVariableField(df);
}
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