Search in sources :

Example 1 with PublisherNumber

use of cz.mzk.recordmanager.server.model.PublisherNumber in project RecordManager2 by moravianlibrary.

the class MetadataMarcRecord method getPublisherNumber.

@Override
public List<PublisherNumber> getPublisherNumber() {
    List<PublisherNumber> results = new ArrayList<>();
    Long i = 0L;
    for (DataField df : underlayingMarc.getDataFields("028")) {
        if (df.getIndicator1() == '0' && df.getSubfield('a') != null) {
            String result = PUBLISHER_NUMBER_PATTERN.matcher(df.getSubfield('a').getData().toLowerCase()).replaceAll("");
            results.add(new PublisherNumber(result, ++i));
        }
    }
    return results;
}
Also used : DataField(org.marc4j.marc.DataField) ArrayList(java.util.ArrayList) PublisherNumber(cz.mzk.recordmanager.server.model.PublisherNumber)

Example 2 with PublisherNumber

use of cz.mzk.recordmanager.server.model.PublisherNumber in project RecordManager2 by moravianlibrary.

the class HashingDedupKeyParser method computeHashValue.

/**
 * Compute SHA1 hash of deduplication keys from given {@link DedupKeysencapsulator}
 * @param encapsulator
 * @return
 */
protected String computeHashValue(final DedupKeysencapsulator encapsulator) {
    try {
        // change of hash function also requires changes in database row
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        for (Title t : encapsulator.getTitles()) {
            md.update(t.getTitleStr().getBytes("utf-8"));
        }
        for (Isbn i : encapsulator.getIsbns()) {
            md.update(i.getIsbn().byteValue());
        }
        for (Issn i : encapsulator.getIssns()) {
            md.update(i.getIssn().getBytes());
        }
        for (Ismn i : encapsulator.getIsmns()) {
            md.update(i.getIsmn().byteValue());
        }
        for (Cnb c : encapsulator.getCnbs()) {
            md.update(c.getCnb().getBytes());
        }
        if (encapsulator.getPublicationYear() != null) {
            md.update(encapsulator.getPublicationYear().byteValue());
        }
        for (HarvestedRecordFormat hrfe : encapsulator.getFormats()) {
            md.update(hrfe.getName().getBytes());
        }
        if (encapsulator.getAuthorAuthKey() != null) {
            md.update(encapsulator.getAuthorAuthKey().getBytes());
        }
        if (encapsulator.getAuthorString() != null) {
            md.update(encapsulator.getAuthorString().getBytes());
        }
        if (encapsulator.getScale() != null) {
            md.update(encapsulator.getScale().byteValue());
        }
        if (encapsulator.getUuid() != null) {
            md.update(encapsulator.getUuid().getBytes());
        }
        if (encapsulator.getPages() != null) {
            md.update(encapsulator.getPages().byteValue());
        }
        if (encapsulator.getIssnSeries() != null) {
            md.update(encapsulator.getIssnSeries().getBytes());
        }
        if (encapsulator.getIssnSeriesOrder() != null) {
            md.update(encapsulator.getIssnSeriesOrder().getBytes());
        }
        for (Oclc o : encapsulator.getOclcs()) {
            md.update(o.getOclcStr().getBytes());
        }
        for (String l : encapsulator.getLanguages()) {
            md.update(l.getBytes());
        }
        if (encapsulator.getClusterId() != null) {
            md.update(encapsulator.getClusterId().getBytes());
        }
        if (encapsulator.getRaw001Id() != null) {
            md.update(encapsulator.getRaw001Id().getBytes());
        }
        if (encapsulator.getSourceInfoT() != null) {
            md.update(encapsulator.getSourceInfoT().getBytes());
        }
        if (encapsulator.getSourceInfoX() != null) {
            md.update(encapsulator.getSourceInfoX().getBytes());
        }
        if (encapsulator.getSourceInfoG() != null) {
            md.update(encapsulator.getSourceInfoG().getBytes());
        }
        for (Ean ean : encapsulator.getEans()) {
            md.update(ean.getEan().byteValue());
        }
        for (PublisherNumber publisherNumber : encapsulator.getPublisherNumbers()) {
            md.update(publisherNumber.getPublisherNumber().getBytes("utf-8"));
        }
        for (ShortTitle st : encapsulator.getShortTitles()) {
            md.update(st.getShortTitleStr().getBytes("utf-8"));
        }
        byte[] hash = md.digest();
        StringBuilder sb = new StringBuilder();
        for (byte b : hash) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    } catch (NoSuchAlgorithmException e) {
    // should never be thrown, SHA-1 is required by Java specification
    } catch (UnsupportedEncodingException uee) {
        throw new DedupKeyParserException("Uncoding problems in hash computation", uee);
    }
    return "";
}
Also used : Issn(cz.mzk.recordmanager.server.model.Issn) Title(cz.mzk.recordmanager.server.model.Title) ShortTitle(cz.mzk.recordmanager.server.model.ShortTitle) Ismn(cz.mzk.recordmanager.server.model.Ismn) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Oclc(cz.mzk.recordmanager.server.model.Oclc) Ean(cz.mzk.recordmanager.server.model.Ean) Isbn(cz.mzk.recordmanager.server.model.Isbn) ShortTitle(cz.mzk.recordmanager.server.model.ShortTitle) Cnb(cz.mzk.recordmanager.server.model.Cnb) HarvestedRecordFormat(cz.mzk.recordmanager.server.model.HarvestedRecordFormat) MessageDigest(java.security.MessageDigest) PublisherNumber(cz.mzk.recordmanager.server.model.PublisherNumber)

Aggregations

PublisherNumber (cz.mzk.recordmanager.server.model.PublisherNumber)2 Cnb (cz.mzk.recordmanager.server.model.Cnb)1 Ean (cz.mzk.recordmanager.server.model.Ean)1 HarvestedRecordFormat (cz.mzk.recordmanager.server.model.HarvestedRecordFormat)1 Isbn (cz.mzk.recordmanager.server.model.Isbn)1 Ismn (cz.mzk.recordmanager.server.model.Ismn)1 Issn (cz.mzk.recordmanager.server.model.Issn)1 Oclc (cz.mzk.recordmanager.server.model.Oclc)1 ShortTitle (cz.mzk.recordmanager.server.model.ShortTitle)1 Title (cz.mzk.recordmanager.server.model.Title)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 DataField (org.marc4j.marc.DataField)1