Search in sources :

Example 1 with Inspiration

use of cz.mzk.recordmanager.server.model.Inspiration in project RecordManager2 by moravianlibrary.

the class InspirationDeleteWriter method write.

@Override
public void write(List<? extends Long> items) throws Exception {
    for (Long id : items) {
        Inspiration ins = insDao.get(id);
        if (ins == null)
            continue;
        HarvestedRecord hr = hrDao.get(ins.getHarvestedRecordId());
        if (hr == null)
            continue;
        List<Inspiration> inspirations = hr.getInspiration();
        inspirations.remove(ins);
        hr.setInspiration(inspirations);
        hr.setUpdated(new Date());
        hrDao.persist(hr);
        insDao.delete(ins);
    }
}
Also used : Inspiration(cz.mzk.recordmanager.server.model.Inspiration) Date(java.util.Date) HarvestedRecord(cz.mzk.recordmanager.server.model.HarvestedRecord)

Example 2 with Inspiration

use of cz.mzk.recordmanager.server.model.Inspiration 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)

Aggregations

HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)2 Inspiration (cz.mzk.recordmanager.server.model.Inspiration)2 Date (java.util.Date)2 ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1