private Map<String, YDate> processYDates(final List<YDate> yDates) { Map<String, YDate> dates = new HashMap<>(); if (yDates != null) { for (final YDate yDate : yDates) { dates.put(yDate.getType(), yDate); } } return dates; }
/** * Selects most apropriate (English if available) description. * * @param descriptions * list of available descriptions * @return best found description or null if list is empty */ protected static String selectBestDate(List<YDate> dates) { if (dates == null || dates.size() == 0) { return null; } StringBuilder text = new StringBuilder(); for (YDate date : dates) { text.append(date.getType() + ":"+date.getYear()+YElementToZentralBlattConverter.SUGGESTED_MULTIVALUE_FIELD_SEPARATOR); } return text.toString(); }
/** * Selects most appropriate (Publication's if available) data. */ protected static String selectBestDate(List<YDate> dates) { if (dates == null || dates.size() == 0) { return null; } int py = dates.get(0).getYear(); for (YDate date: dates) { //Search for English version if (date.getType().equals(YConstants.DT_PUBLISHED)) { py = date.getYear(); } } if (py > 1000) { return new Integer(py).toString(); } else { return null; } }
@Override void compare(YElement expected, YElement actual, EvalResult result) { List<YDate> expDates = expected.getDates(); Map<String, YDate> actDatesMap = new HashMap<String, YDate>(); for (YDate date : actual.getDates()) { String type = date.getType(); actDatesMap.put(type, date); } for (YDate date : expDates) { String type = date.getType(); if (actDatesMap.containsKey(type)) { if (date.equals(actDatesMap.get(type))) { result.append("Date - " + type, ResultStatus.RECOGNIZED, 1); } else { result.append("Date - " + type, ResultStatus.FAILED, 1); } actDatesMap.remove(type); } else { result.append("Date - " + type, ResultStatus.FAILED, 1); } } for (String type : actDatesMap.keySet()) { result.append("Date - " + type, ResultStatus.REDUNDANT, 1); } } },
@Override protected void postProcessELements(List<YElement> elements) { Optional<YElement> chapterElement = getElementByPredicate(elements, this::hasChapterLevel); Optional<YElement> bookElement = getElementByPredicate(elements, this::hasBookLevel); if (chapterElement.isPresent() && bookElement.isPresent()) { for(YDate date:chapterElement.get().getDates()){ if(bookElement.get().getDate(date.getType()) == null){ bookElement.get().addDate(date); } } } }
private DateDTO dateDTOFromYDate(YDate date) { return new DateDTO(date.getType(), date.getText()); }
private Map<String, Object> prepareDates(YElement element, IFilteringContext filteringContext) { Map<String, List<String>> datesMap = new HashMap<String, List<String>>(); ArrayList<DateDTO> datesList = new ArrayList<DateDTO>(); DateDTO publicationDate = null; for (YDate date : element.getDates()) { String type = date.getType(); if (!datesMap.containsKey(type)) { datesMap.put(type, new ArrayList<String>()); } datesMap.get(type).add( detailsFilter.filter(date.getText(), InputType.IDENTIFIER, filteringContext)); if (!type.equals(YConstants.DT_PUBLISHED)) { datesList.add(dateDTOFromYDate(date)); } else { publicationDate = dateDTOFromYDate(date); } } Collections.sort(datesList); publicationDateFirst(datesList, publicationDate); Map<String, Object> result = new HashMap<String, Object>(); result.put("chronology", datesList); result.put("bytype", datesMap); Map<String, String> labels = createLabelsByType(datesMap); result.put("labels", labels); return result; }
protected void fillDates(YElement yElement, List<YExportable> referedElements, Map<String, List<StringWithAttributes>> ret) { // date element if (!yElement.getDates().isEmpty()) { ret.put(E_DATE, new ArrayList<StringWithAttributes>()); } for (YDate yDate : yElement.getDates()) { String yDateStr; String y = String.format("%02d", yDate.getYear()); String m = String.format("%02d", yDate.getMonth()); String d = String.format("%02d", yDate.getDay()); if (y != null && m != null && d != null) { yDateStr = y + "-" + m + "-" + d; } else if (y != null && m != null) { yDateStr = y + "-" + m; } else if (y != null) { yDateStr = y; } else { yDateStr = yDate.getText(); } StringWithAttributes dat = new StringWithAttributes(yDateStr); dat.addAttribute("dateType", yDate.getType()); ret.get(E_DATE).add(dat); // root.addContent(date); } }
@Override public void parseMetadata(YElement element, PublicationMeta pm, YLanguage defaultLanguage, List<YElement> ancestors) { element.getDates().addAll(getDates(pm.getEventGroup())); for (YElement ancestor : ancestors) { for (YDate date : ancestor.getDates()) { if (element.getDate(date.getType()) == null) { element.addDate(date); } } } }
@Override public BasicDBObject convert(YDate source) { if(source == null){ return null; } BasicDBObject object = new BasicDBObject(); object.put("year", source.getYear()); object.put("day", source.getDay()); object.put("month", source.getMonth()); object.put("type", source.getType()); object.put("text", source.getText()); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); String dateString = String.format("%04d%02d%02d", getOneIfZero(source.getYear()), getOneIfZero(source.getMonth()), getOneIfZero(source.getDay())); try { Date parsedDate = dateFormat.parse(dateString); object.put("date", parsedDate); } catch (ParseException e) { LOGGER.warn("Couldn't parse date: " + dateString); } return object; }
protected void fillPublicationDate(HtmlMetaHeaders metadata, YElement yElement) { for (YDate date : yElement.getDates()) { if (StringUtils.equals(DateTypes.DT_PUBLISHED, date.getType())) { String parsedDate = parseDate(date); if (parsedDate != null) { metadata.addMetadataName(WP_PUBLICATION_DATE, parseDate(date)); return; } } } if (yElement.getStructure(HierarchyWithLevelIds.EXT_HIERARCHY_JOURNAL) != null) { YAncestor yAncestor = yElement.getStructure(HierarchyWithLevelIds.EXT_HIERARCHY_JOURNAL).getAncestor(HierarchyWithLevelIds.EXT_LEVEL_JOURNAL_YEAR); if (yAncestor != null && yAncestor.getOneName() != null) { metadata.addMetadataName(WP_PUBLICATION_DATE, yAncestor.getOneName().getText()); } } }
if (!YConstants.DT_PUBLISHED.equals(elementDate.getType())) { continue;