use of cz.mzk.recordmanager.server.model.TezaurusRecord in project RecordManager2 by moravianlibrary.
the class ImportTezaurusRecordsWriter method write.
@Override
public void write(List<? extends List<Record>> items) throws Exception {
if (config == null) {
config = oaiHarvestConfDao.get(confId);
}
for (List<Record> records : items) {
for (Record currentRecord : records) {
try {
MarcRecord marc = new MarcRecordImpl(currentRecord);
MetadataRecord metadata = metadataFactory.getMetadataRecord(marc, config);
String recordId = metadata.getUniqueId();
TezaurusRecord tr = tezaurusDao.findByIdAndHarvestConfiguration(recordId, config);
if (tr == null) {
tr = new TezaurusRecord();
tr.setRecordId(recordId);
tr.setHarvestedFrom(config);
}
tr.setTezaurusKey(metadata.getTezaurusKey());
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
MarcWriter marcWriter = new MarcXmlWriter(outStream, true);
marcWriter.write(currentRecord);
marcWriter.close();
byte[] recordContent = outStream.toByteArray();
tr.setRawRecord(recordContent);
tezaurusDao.persist(tr);
} catch (Exception e) {
logger.warn("Error occured in processing record");
throw e;
}
}
}
}
use of cz.mzk.recordmanager.server.model.TezaurusRecord in project RecordManager2 by moravianlibrary.
the class AbstractAgrovocVizFields method getEnrichingValues.
@Override
protected List<String> getEnrichingValues(String key, String enrichingField) {
if (config == null) {
List<ImportConfiguration> configs = configDao.findByIdPrefix(Constants.PREFIX_AGROVOC);
if (configs != null && !configs.isEmpty()) {
config = configs.get(0);
}
}
Map<String, List<String>> cache = cacheMap.get(enrichingField);
if (cache.containsKey(key)) {
return new ArrayList<>(cache.get(key));
} else {
TezaurusRecord tr = tezaurusDao.findByConfigAndSourceFieldAndName(config, "1" + enrichingField.substring(1), key);
if (tr != null) {
MarcRecord mr = marcXmlParser.parseRecord(new ByteArrayInputStream(tr.getRawRecord()));
List<String> results = new ArrayList<>();
for (DataField df : mr.getDataFields(enrichingField)) {
if (df.getSubfield('a') != null) {
results.add(df.getSubfield('a').getData());
}
}
if (!results.isEmpty()) {
results = Collections.unmodifiableList(results);
cache.put(key, results);
return new ArrayList<>(results);
}
}
}
return null;
}
use of cz.mzk.recordmanager.server.model.TezaurusRecord in project RecordManager2 by moravianlibrary.
the class AbstractMeshVizFields method getEnrichingValues.
@Override
protected List<String> getEnrichingValues(String key, String enrichingField) {
if (config == null) {
List<ImportConfiguration> configs = configDao.findByIdPrefix(Constants.PREFIX_MESH);
if (configs != null && !configs.isEmpty()) {
config = configs.get(0);
}
}
Map<String, List<String>> cache = cacheMap.get(enrichingField);
if (cache.containsKey(key)) {
return new ArrayList<>(cache.get(key));
} else {
TezaurusRecord tr = tezaurusDao.findByConfigAndSourceFieldAndName(config, "1" + enrichingField.substring(1), key);
if (tr != null) {
MarcRecord mr = marcXmlParser.parseRecord(new ByteArrayInputStream(tr.getRawRecord()));
List<String> results = new ArrayList<>();
for (DataField df : mr.getDataFields(enrichingField)) {
if (df.getSubfield('a') != null && df.getSubfield('7') != null && df.getSubfield('7').getData().startsWith("cze")) {
results.add(df.getSubfield('a').getData());
}
}
if (!results.isEmpty()) {
results = Collections.unmodifiableList(results);
cache.put(key, results);
return new ArrayList<>(results);
}
}
}
return null;
}
Aggregations