Search in sources :

Example 1 with ImportConfiguration

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;
}
Also used : DublinCoreRecord(cz.mzk.recordmanager.server.dc.DublinCoreRecord) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration)

Example 2 with ImportConfiguration

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;
}
Also used : HarvestedRecordUniqueId(cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 3 with ImportConfiguration

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;
}
Also used : ImportConfigurationDto(cz.mzk.recordmanager.api.model.configurations.ImportConfigurationDto) ArrayList(java.util.ArrayList) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ImportConfiguration

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));
        }
    }
}
Also used : Inspiration(cz.mzk.recordmanager.server.model.Inspiration) Matcher(java.util.regex.Matcher) List(java.util.List) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration) Date(java.util.Date) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 5 with ImportConfiguration

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;
}
Also used : DataField(org.marc4j.marc.DataField) ByteArrayInputStream(java.io.ByteArrayInputStream) TezaurusRecord(cz.mzk.recordmanager.server.model.TezaurusRecord) ArrayList(java.util.ArrayList) MarcRecord(cz.mzk.recordmanager.server.marc.MarcRecord) ArrayList(java.util.ArrayList) List(java.util.List) ImportConfiguration(cz.mzk.recordmanager.server.model.ImportConfiguration)

Aggregations

ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)10 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)4 Test (org.testng.annotations.Test)4 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)3 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HarvestedRecordUniqueId (cz.mzk.recordmanager.server.model.HarvestedRecord.HarvestedRecordUniqueId)2 TezaurusRecord (cz.mzk.recordmanager.server.model.TezaurusRecord)2 InputStream (java.io.InputStream)2 DataField (org.marc4j.marc.DataField)2 ImportConfigurationDto (cz.mzk.recordmanager.api.model.configurations.ImportConfigurationDto)1 DublinCoreRecord (cz.mzk.recordmanager.server.dc.DublinCoreRecord)1 Inspiration (cz.mzk.recordmanager.server.model.Inspiration)1 OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 Transactional (org.springframework.transaction.annotation.Transactional)1