public static boolean isEmpty(org.orcid.jaxb.model.common_v2.Day day) { if (day==null) return true; return isEmpty(day.getValue()); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; FuzzyDate other = (FuzzyDate) obj; if (day == null) { if (other.day != null) return false; } else if (!day.equals(other.day)) return false; if (month == null) { if (other.month != null) return false; } else if (!month.equals(other.month)) return false; if (year == null) { if (other.year != null) return false; } else if (!year.equals(other.year)) return false; return true; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((day == null) ? 0 : day.hashCode()); result = prime * result + ((month == null) ? 0 : month.hashCode()); result = prime * result + ((year == null) ? 0 : year.hashCode()); return result; }
public FuzzyDate(org.orcid.jaxb.model.message.FuzzyDate other) { if (other == null) throw new IllegalArgumentException("Invalid init parameter"); if (other.getYear() != null) { this.year = new Year(); this.year.setValue(other.getYear().getValue()); } if (other.getMonth() != null) { this.month = new Month(); this.month.setValue(other.getMonth().getValue()); } if (other.getDay() != null) { this.day = new Day(); this.day.setValue(other.getDay().getValue()); } }
public static FuzzyDate valueOf(Integer year, Integer month, Integer day) { FuzzyDate fuzzyDate = new FuzzyDate(); fuzzyDate.year = year != null ? new Year(year) : null; fuzzyDate.month = month != null ? new Month(month) : null; fuzzyDate.day = day != null ? new Day(day) : null; return fuzzyDate; }
/** * Sets the value of the value property. * * @param value * allowed object is * {@link String } * */ public void setValue(String value) { this.value = tidyValue(value); }
@Override public void mapBtoA(EndDateEntity entity, FuzzyDate fuzzyDate, MappingContext context) { if (entity.getYear() != null) { fuzzyDate.setYear(new Year(entity.getYear())); } else { fuzzyDate.setYear(null); } if (entity.getMonth() != null) { fuzzyDate.setMonth(new Month(entity.getMonth())); } else { fuzzyDate.setMonth(null); } if (entity.getDay() != null) { fuzzyDate.setDay(new Day(entity.getDay())); } else { fuzzyDate.setDay(null); } } }).register();
public Day(Integer value) { this.value = tidyValue(value); }
@Override public String toString() { StringBuilder builder = new StringBuilder(year.getValue()); if (month != null) { builder.append("-"); builder.append(month.getValue()); } if (day != null) { builder.append("-"); builder.append(day.getValue()); } return builder.toString(); }
@Override public void mapBtoA(StartDateEntity entity, FuzzyDate fuzzyDate, MappingContext context) { if (entity.getYear() != null) { fuzzyDate.setYear(new Year(entity.getYear())); } else { fuzzyDate.setYear(null); } if (entity.getMonth() != null) { fuzzyDate.setMonth(new Month(entity.getMonth())); } else { fuzzyDate.setMonth(null); } if (entity.getDay() != null) { fuzzyDate.setDay(new Day(entity.getDay())); } else { fuzzyDate.setDay(null); } } }).register();
private String tidyValue(Integer value) { return tidyValue(Integer.toString(value)); }
@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); } }
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 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; } } catch (DateTimeParseException e) { } } if (!valid) { Map<String, String> params = new HashMap<>(); params.put("dateString", dateString); throw new InvalidFuzzyDateException(params); } }
Integer.valueOf(day.getValue()); } catch (NumberFormatException n) { Map<String, String> params = new HashMap<String, String>(); if (day.getValue().length() != 2) { throw new OrcidValidationException("Invalid day " + day.getValue() + " please specify a two digits value"); boolean isDayEmpty = (day == null || day.getValue() == null) ? true : false; if (isYearEmpty && (!isMonthEmpty || !isDayEmpty)) { throw new OrcidValidationException("Invalid date, please specify a year element");
public static String createDateSortString(org.orcid.jaxb.model.common_v2.FuzzyDate start, org.orcid.jaxb.model.common_v2.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; }
year = Integer.parseInt(work.getPublicationDate().getYear().getValue()); month = Integer.parseInt(work.getPublicationDate().getMonth().getValue()); day = Integer.parseInt(work.getPublicationDate().getDay().getValue()); } catch (Exception e) {