Search in sources :

Example 6 with NoDataException

use of cz.mzk.recordmanager.server.util.identifier.NoDataException in project RecordManager2 by moravianlibrary.

the class MetadataDublinCoreRecord method getISBNs.

/**
 * go through all identifiers, look for isbn:.*, validate isbn
 *
 * @return list of {@link Isbn}
 */
@Override
public List<Isbn> getISBNs() {
    List<Isbn> isbns = new ArrayList<>();
    Matcher matcher;
    Long isbnCounter = 0L;
    for (String identifier : dcRecord.getIdentifiers()) {
        String rawIsbnStr = "";
        if ((matcher = DC_ISBN_PATTERN.matcher(identifier)).find())
            rawIsbnStr = matcher.group(1);
        else if (!DC_IDENTIFIER_PATTERN.matcher(identifier).matches())
            rawIsbnStr = identifier;
        Long isbnLong;
        try {
            isbnLong = ISBNUtils.toISBN13LongThrowing(rawIsbnStr);
        } catch (NoDataException nde) {
            continue;
        } catch (NumberFormatException nfe) {
            logger.info(String.format("Invalid ISBN: %s", rawIsbnStr));
            continue;
        }
        isbns.add(Isbn.create(isbnLong, ++isbnCounter, ""));
    }
    return isbns;
}
Also used : Isbn(cz.mzk.recordmanager.server.model.Isbn) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) NoDataException(cz.mzk.recordmanager.server.util.identifier.NoDataException)

Example 7 with NoDataException

use of cz.mzk.recordmanager.server.util.identifier.NoDataException in project RecordManager2 by moravianlibrary.

the class MetadataDublinCoreRecord method getISSNs.

@Override
public List<Issn> getISSNs() {
    List<Issn> results = new ArrayList<>();
    Long issnCounter = 0L;
    Matcher matcher;
    for (String identifier : dcRecord.getIdentifiers()) {
        String rawIssnStr = "";
        if ((matcher = DC_ISSN_PATTERN.matcher(identifier)).find())
            rawIssnStr = matcher.group(1);
        else if (!DC_IDENTIFIER_PATTERN.matcher(identifier).matches())
            rawIssnStr = identifier;
        String validIssn;
        try {
            validIssn = ISSNUtils.getValidIssnThrowing(rawIssnStr);
        } catch (NoDataException nde) {
            continue;
        } catch (NumberFormatException nfe) {
            logger.info(String.format("Invalid ISSN: %s", rawIssnStr));
            continue;
        }
        results.add(Issn.create(validIssn, ++issnCounter, ""));
    }
    return results;
}
Also used : Matcher(java.util.regex.Matcher) Issn(cz.mzk.recordmanager.server.model.Issn) ArrayList(java.util.ArrayList) NoDataException(cz.mzk.recordmanager.server.util.identifier.NoDataException)

Aggregations

NoDataException (cz.mzk.recordmanager.server.util.identifier.NoDataException)7 ArrayList (java.util.ArrayList)7 DataField (org.marc4j.marc.DataField)4 Matcher (java.util.regex.Matcher)3 Isbn (cz.mzk.recordmanager.server.model.Isbn)2 Ismn (cz.mzk.recordmanager.server.model.Ismn)2 Issn (cz.mzk.recordmanager.server.model.Issn)2 Ean (cz.mzk.recordmanager.server.model.Ean)1