use of cz.mzk.recordmanager.server.model.Isbn in project RecordManager2 by moravianlibrary.
the class DublinCoreDSL method getISBNs.
public List<String> getISBNs() {
List<Isbn> isbns = dcMetadataRecord.getISBNs();
List<String> isbnsS = new ArrayList<String>();
for (Isbn n : isbns) {
String isbn = n.getIsbn().toString();
isbnsS.add(isbn);
}
return isbnsS;
}
use of cz.mzk.recordmanager.server.model.Isbn 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 "";
}
use of cz.mzk.recordmanager.server.model.Isbn in project RecordManager2 by moravianlibrary.
the class MetadataMarcRecord method getISBNs.
@Override
public List<Isbn> getISBNs() {
List<Isbn> isbns = new ArrayList<>();
Long isbnCounter = 0L;
Isbn isbn;
for (DataField df : underlayingMarc.getDataFields("020")) {
try {
isbn = ISBNUtils.createIsbn(df);
} catch (NoDataException nde) {
continue;
} catch (NumberFormatException nfe) {
logger.info(String.format("Invalid ISBN: %s", nfe.getMessage()));
continue;
}
isbn.setOrderInRecord(++isbnCounter);
isbns.add(isbn);
}
return isbns;
}
use of cz.mzk.recordmanager.server.model.Isbn 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;
}
use of cz.mzk.recordmanager.server.model.Isbn in project RecordManager2 by moravianlibrary.
the class HarvestedRecordDAOHibernate method dropDedupKeys.
@Override
public void dropDedupKeys(HarvestedRecord hr) {
if (hr == null || hr.getId() == null) {
return;
}
Session session = sessionFactory.getCurrentSession();
// don't delete keys for not managed entities
if (!session.contains(hr)) {
System.out.println("NOT CONT");
return;
}
hr.setAuthorAuthKey(null);
hr.setAuthorString(null);
hr.setClusterId(null);
hr.setPages(null);
hr.setPublicationYear(null);
hr.setRaw001Id(null);
hr.setScale(null);
hr.setUuid(null);
hr.setSourceInfoT(null);
hr.setSourceInfoX(null);
hr.setSourceInfoG(null);
hr.setIssnSeries(null);
hr.setIssnSeriesOrder(null);
hr.setWeight(null);
List<Title> titles = hr.getTitles();
hr.setTitles(new ArrayList<>());
for (Title t : titles) {
session.delete(t);
}
List<ShortTitle> shortTitles = hr.getShortTitles();
hr.setShortTitles(new ArrayList<>());
for (ShortTitle st : shortTitles) {
session.delete(st);
}
List<Isbn> isbns = hr.getIsbns();
hr.setIsbns(new ArrayList<>());
for (Isbn i : isbns) {
session.delete(i);
}
List<Issn> issns = hr.getIssns();
hr.setIssns(new ArrayList<>());
for (Issn i : issns) {
session.delete(i);
}
List<Ismn> ismns = hr.getIsmns();
hr.setIsmns(new ArrayList<>());
for (Ismn i : ismns) {
session.delete(i);
}
List<Oclc> oclcs = hr.getOclcs();
hr.setOclcs(new ArrayList<>());
for (Oclc o : oclcs) {
session.delete(o);
}
List<Cnb> cnbs = hr.getCnb();
hr.setCnb(new ArrayList<>());
for (Cnb c : cnbs) {
session.delete(c);
}
List<Ean> eans = hr.getEans();
hr.setEans(new ArrayList<>());
for (Ean ean : eans) {
session.delete(ean);
}
List<HarvestedRecordFormat> physicalFormats = hr.getPhysicalFormats();
hr.getPhysicalFormats().clear();
for (HarvestedRecordFormat hrf : physicalFormats) {
session.delete(hrf);
}
hr.setLanguages(new ArrayList<>());
session.update(hr);
session.flush();
}
Aggregations