private String getDateString(FuzzyDate fuzzyDate) { String year = fuzzyDate.getYear() != null ? fuzzyDate.getYear().getValue() : null; String month = fuzzyDate.getMonth() != null ? fuzzyDate.getMonth().getValue() : null; String day = fuzzyDate.getDay() != null ? fuzzyDate.getDay().getValue() : null; if (day != null) { return year + "-" + month + "-" + day; } if (month != null) { return year + "-" + month; } if (year != null) { return year; } return null; } }
private static void populateFromFuzzyDate(FuzzyDateEntity fuzzyDateEntity, FuzzyDate fuzzyDate) { if (fuzzyDate != null) { Year Year = fuzzyDate.getYear(); if (Year != null) { fuzzyDateEntity.setYear(Integer.valueOf(Year.getValue())); } Month month = fuzzyDate.getMonth(); if (month != null) { fuzzyDateEntity.setMonth(Integer.valueOf(month.getValue())); } Day day = fuzzyDate.getDay(); if (day != null) { fuzzyDateEntity.setDay(Integer.valueOf(day.getValue())); } } }
public static boolean isEmpty(org.orcid.jaxb.model.v3.rc2.common.FuzzyDate date) { if (date == null) return true; if (!isEmpty(date.getDay())) return false; if (!isEmpty(date.getMonth())) return false; if (!isEmpty(date.getYear())) return false; return true; }
public static Date convertDate(org.orcid.jaxb.model.v3.rc2.common.FuzzyDate fuzzyDate) { if (fuzzyDate != null) { Integer year = PojoUtil.isEmpty(fuzzyDate.getYear()) ? null : Integer.valueOf(fuzzyDate.getYear().getValue()); Integer month = PojoUtil.isEmpty(fuzzyDate.getMonth()) ? null : Integer.valueOf(fuzzyDate.getMonth().getValue()); Integer day = PojoUtil.isEmpty(fuzzyDate.getDay()) ? null : Integer.valueOf(fuzzyDate.getDay().getValue()); if (year != null && year == 0) { year = null; } if (month != null && month == 0) { month = null; } if (day != null && day == 0) { day = null; } return Date.valueOf(org.orcid.jaxb.model.v3.rc2.common.FuzzyDate.valueOf(year, month, day)); } return null; } }
private static Date getCompletionDate(FuzzyDate completionDate) { if (completionDate != null) { Integer year = PojoUtil.isEmpty(completionDate.getYear()) ? null : Integer.valueOf(completionDate.getYear().getValue()); Integer month = PojoUtil.isEmpty(completionDate.getMonth()) ? null : Integer.valueOf(completionDate.getMonth().getValue()); Integer day = PojoUtil.isEmpty(completionDate.getDay()) ? null : Integer.valueOf(completionDate.getDay().getValue()); if (year != null && year == 0) { year = null; } if (month != null && month == 0) { month = null; } if (day != null && day == 0) { day = null; } return Date.valueOf(FuzzyDate.valueOf(year, month, day)); } return null; }
@Override public void mapAtoB(FuzzyDate fuzzyDate, StartDateEntity entity, MappingContext context) { if (fuzzyDate.getYear() != null) { entity.setYear(Integer.valueOf(fuzzyDate.getYear().getValue())); } else { entity.setYear(null); } if (fuzzyDate.getMonth() != null) { entity.setMonth(Integer.valueOf(fuzzyDate.getMonth().getValue())); } else { entity.setMonth(null); } if (fuzzyDate.getDay() != null) { entity.setDay(Integer.valueOf(fuzzyDate.getDay().getValue())); } else { entity.setDay(null); } }
@Override public void mapAtoB(FuzzyDate fuzzyDate, EndDateEntity entity, MappingContext context) { if (fuzzyDate.getYear() != null) { entity.setYear(Integer.valueOf(fuzzyDate.getYear().getValue())); } else { entity.setYear(null); } if (fuzzyDate.getMonth() != null) { entity.setMonth(Integer.valueOf(fuzzyDate.getMonth().getValue())); } else { entity.setMonth(null); } if (fuzzyDate.getDay() != null) { entity.setDay(Integer.valueOf(fuzzyDate.getDay().getValue())); } else { entity.setDay(null); } }
public static Date valueOf(FuzzyDate fuzzyDate) { Date d = new Date(); if (fuzzyDate.getDay() != null && fuzzyDate.getDay().getValue() != null) d.setDay(fuzzyDate.getDay().getValue()); if (fuzzyDate.getMonth() != null && fuzzyDate.getMonth().getValue() != null) d.setMonth(fuzzyDate.getMonth().getValue()); if (fuzzyDate.getYear() != null && fuzzyDate.getYear().getValue() != null) d.setYear(fuzzyDate.getYear().getValue()); return d; }
public static String createDateSortString(org.orcid.jaxb.model.v3.rc2.common.FuzzyDate start, org.orcid.jaxb.model.v3.rc2.common.FuzzyDate end) { String year = "0"; String month = "0"; String day = "0"; if (!isEmpty(start) && !isEmpty(start.getYear())) { year = start.getYear().getValue(); if (!PojoUtil.isEmpty(start.getMonth())) month = start.getMonth().getValue(); if (!PojoUtil.isEmpty(start.getDay())) day = start.getDay().getValue(); } else if (!isEmpty(end) && !isEmpty(end.getYear())) { year = end.getYear().getValue(); if (!PojoUtil.isEmpty(end.getMonth())) month = end.getMonth().getValue(); if (!PojoUtil.isEmpty(end.getDay())) day = end.getDay().getValue(); } return year + "-" + month + '-' + day; }
private void validateFuzzyDate(FuzzyDate fuzzyDate) { String dateString = getDateString(fuzzyDate); DateTimeFormatter[] formatters = { new DateTimeFormatterBuilder().appendPattern("yyyy").parseDefaulting(ChronoField.MONTH_OF_YEAR, 1).parseDefaulting(ChronoField.DAY_OF_MONTH, 1) .toFormatter(), new DateTimeFormatterBuilder().appendPattern("yyyy-MM").parseDefaulting(ChronoField.DAY_OF_MONTH, 1).toFormatter(), new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd").parseStrict().toFormatter() }; boolean valid = false; for (DateTimeFormatter formatter : formatters) { try { LocalDate localDate = LocalDate.parse(dateString, formatter); if (PojoUtil.isEmpty(fuzzyDate.getDay()) || localDate.getDayOfMonth() == Integer.parseInt(fuzzyDate.getDay().getValue())) { valid = true; break; } } catch (DateTimeParseException e) { } } if (!valid) { Map<String, String> params = new HashMap<>(); params.put("dateString", dateString); throw new InvalidFuzzyDateException(params); } }
if (!PojoUtil.isEmpty(startDate.getDay())) { dateSortString += "-" + startDate.getDay().getValue(); } else { dateSortString += "-00"; dateSortString += "-00"; if (!PojoUtil.isEmpty(endDate.getDay())) { dateSortString += "-" + endDate.getDay().getValue(); } else { dateSortString += "-00"; dateSortString += "-00"; if (!PojoUtil.isEmpty(startDate.getDay())) { dateSortString += "-" + startDate.getDay().getValue(); } else { dateSortString += "-00";