use of cz.mzk.recordmanager.server.model.ImportConfiguration in project RecordManager2 by moravianlibrary.
the class MetadataRecordFactory method getMetadataRecord.
public MetadataRecord getMetadataRecord(HarvestedRecord record) {
if (record == null) {
return null;
}
ImportConfiguration configuration = record.getHarvestedFrom();
InputStream is = new ByteArrayInputStream(record.getRawRecord());
String recordFormat = record.getFormat();
if (Constants.METADATA_FORMAT_MARC21.equals(recordFormat) || Constants.METADATA_FORMAT_XML_MARC.equals(recordFormat) || Constants.METADATA_FORMAT_MARC_CPK.equals(recordFormat) || Constants.METADATA_FORMAT_OAI_MARCXML_CPK.equals(recordFormat) || Constants.METADATA_FORMAT_MARC21E.equals(recordFormat)) {
MarcRecord marcRec = marcXmlParser.parseRecord(is);
return getMetadataRecord(marcRec, configuration);
}
if (Constants.METADATA_FORMAT_DUBLIN_CORE.equals(recordFormat) || Constants.METADATA_FORMAT_ESE.equals(recordFormat)) {
DublinCoreRecord dcRec = dcParser.parseRecord(is);
return getMetadataRecord(record, dcRec, configuration);
}
return null;
}
use of cz.mzk.recordmanager.server.model.ImportConfiguration in project RecordManager2 by moravianlibrary.
the class HarvestedRecordRowMapper method mapRow.
@Override
public HarvestedRecord mapRow(ResultSet rs, int rowNum) throws SQLException {
ImportConfiguration importConfig = importConfDao.load(rs.getLong("import_conf_id"));
HarvestedRecordUniqueId id = new HarvestedRecordUniqueId(importConfig, rs.getString("record_id"));
HarvestedRecord record = new HarvestedRecord(id);
record.setId(rs.getLong("id"));
record.setHarvestedFrom(importConfig);
record.setUpdated(rs.getDate("updated"));
record.setDeleted(rs.getDate("deleted"));
record.setRawRecord(rs.getBytes("raw_record"));
record.setFormat(rs.getString("format"));
return record;
}
use of cz.mzk.recordmanager.server.model.ImportConfiguration in project RecordManager2 by moravianlibrary.
the class ImportConfigurationServiceImpl method getConfigurations.
@Override
@Transactional(readOnly = true)
public List<ImportConfigurationDto> getConfigurations() {
List<ImportConfiguration> configurations = importConfigurationDAO.findAll();
List<ImportConfigurationDto> result = new ArrayList<ImportConfigurationDto>(configurations.size());
for (ImportConfiguration configuration : configurations) {
result.add(translator.translate(configuration));
}
return result;
}
use of cz.mzk.recordmanager.server.model.ImportConfiguration in project RecordManager2 by moravianlibrary.
the class InspirationImportWriter method write.
@Override
public void write(List<? extends Map<String, List<String>>> items) throws Exception {
for (Map<String, List<String>> map : items) {
for (Entry<String, List<String>> entry : map.entrySet()) {
String inspiration_name = entry.getKey();
logger.info(String.format(TEXT_INFO, inspiration_name, entry.getValue().size()));
// actual list of records with inspiration in db
hrWithInspiration = inspirationDao.fingHrByInspiraion(inspiration_name);
// added inspiration records
int added_ins = 0;
// inspirations in db
int exists_ins = 0;
// hr not in db
int not_exists_rec = 0;
for (String id : entry.getValue()) {
Matcher matcher = PATTERN_ID.matcher(id);
if (matcher.matches()) {
String id_prefix = matcher.group(1);
String record_id = matcher.group(2);
List<ImportConfiguration> confs = confDao.findByIdPrefix(id_prefix);
int counter = 0;
for (ImportConfiguration conf : confs) {
if (conf == null)
continue;
HarvestedRecord hr = hrDao.findByIdAndHarvestConfiguration(record_id, conf);
if (hr == null) {
if (++counter == confs.size())
++not_exists_rec;
continue;
}
if (hrWithInspiration.contains(hr)) {
// inspiration is already in db
hrWithInspiration.remove(hr);
++exists_ins;
} else {
// add inspiration to hr
List<Inspiration> result = hr.getInspiration();
Inspiration newInspiration = new Inspiration(entry.getKey());
newInspiration.setHarvestedRecordId(hr.getId());
result.add(newInspiration);
hr.setInspiration(result);
hr.setUpdated(new Date());
hrDao.persist(hr);
++added_ins;
}
}
}
}
// rest of records - delete inspiration
for (HarvestedRecord hr : hrWithInspiration) {
Inspiration delete = inspirationDao.findByHrIdAndName(hr.getId(), inspiration_name);
List<Inspiration> inspirations = hr.getInspiration();
inspirations.remove(delete);
hr.setInspiration(inspirations);
hr.setUpdated(new Date());
hrDao.persist(hr);
inspirationDao.delete(delete);
}
logger.info(String.format(TEXT_EXISTS, exists_ins));
logger.info(String.format(TEXT_ADD, added_ins));
logger.info(String.format(TEXT_RECORD_NOT_EXIST, not_exists_rec));
logger.info(String.format(TEXT_DELETE, hrWithInspiration.size()));
logger.info(String.format(TEXT_COMPLETE, inspiration_name));
}
}
}
use of cz.mzk.recordmanager.server.model.ImportConfiguration 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;
}
Aggregations