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;
}
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 "";
}
Aggregations