use of cz.mzk.recordmanager.server.model.SkatKey.SkatKeyCompositeId in project RecordManager2 by moravianlibrary.
the class GenerateSkatKeysProcessor method process.
@Override
public Set<SkatKey> process(Long item) throws Exception {
Set<SkatKey> parsedKeys = new HashSet<>();
HarvestedRecord hr = harvestedRecordDao.get(item);
if (hr.getRawRecord() == null) {
return parsedKeys;
}
MarcRecord marc = null;
InputStream is = new ByteArrayInputStream(hr.getRawRecord());
try {
marc = marcXmlParser.parseRecord(is);
} catch (Exception e) {
return parsedKeys;
}
for (DataField df : marc.getDataFields("996")) {
if (df.getSubfield('e') == null) {
continue;
}
if (df.getSubfield('w') == null) {
continue;
}
String sigla = df.getSubfield('e').getData();
String recordId = df.getSubfield('w').getData();
if (recordId.length() > 100 || sigla.length() > 20) {
// ignore garbage
continue;
}
SkatKey key = new SkatKey(new SkatKeyCompositeId(hr.getId(), sigla, recordId));
parsedKeys.add(key);
}
// ignore records having not enough information
if (parsedKeys.size() < 2) {
return Collections.emptySet();
}
// find already existing keys
Set<SkatKey> existingKeys = new HashSet<>(skatKeyDao.getSkatKeysForRecord(item));
Set<SkatKey> newKeys = new HashSet<>();
for (SkatKey current : parsedKeys) {
if (existingKeys.contains(current)) {
continue;
}
newKeys.add(current);
}
return newKeys;
}
use of cz.mzk.recordmanager.server.model.SkatKey.SkatKeyCompositeId in project RecordManager2 by moravianlibrary.
the class SkatKeyDAOHibernate method getSkatKeysForRecord.
@SuppressWarnings({ "unchecked", "serial" })
@Override
public List<SkatKey> getSkatKeysForRecord(Long skatRecordId) {
Session session = sessionFactory.getCurrentSession();
return (List<SkatKey>) session.createSQLQuery("SELECT skat_record_id,sigla,local_record_id,manually_merged" + " FROM skat_keys" + " WHERE skat_record_id = ?").setResultTransformer(new ResultTransformer() {
@Override
public Object transformTuple(Object[] tuple, String[] aliases) {
SkatKeyCompositeId compositeId = new SkatKeyCompositeId();
boolean manuallyMerged = false;
for (int i = 0; i < tuple.length; i++) {
switch(aliases[i]) {
case "skat_record_id":
compositeId.setSkatHarvestedRecordId(((BigDecimal) tuple[i]).longValue());
break;
case "sigla":
compositeId.setSigla(((String) tuple[i]));
break;
case "local_record_id":
compositeId.setRecordId((String) tuple[i]);
break;
case "manually_merged":
manuallyMerged = (boolean) tuple[i];
break;
}
}
SkatKey key = new SkatKey(compositeId);
key.setManuallyMerged(manuallyMerged);
return key;
}
@SuppressWarnings("rawtypes")
@Override
public List transformList(List collection) {
return collection;
}
}).setParameter(0, skatRecordId).list();
}
Aggregations