if (sourceRow.getPk() == null || targetRows.containsKey(sourceRow.getPk()) == false) { mod = mod.combine(ModificationStatus.MAJOR); target.addTimeableAttribute(sourceRow); continue; T targetRow = targetRows.get(sourceRow.getPk()); mod = mod.combine(copyDeclaredSimpleFields(targetRow.getClass(), targetRow, sourceRow, "createdAt", "createdBy", "updateCounter")); mod = mod.combine(BaseDaoJpaAdapter.copyTabAttributes(targetRow, sourceRow)); if (sourcePks.contains(tagetrow.getPk()) == false) { mod = mod.combine(ModificationStatus.MAJOR); lis.remove();
@Override public <PK extends Serializable, T extends TimeableAttrRow<PK>, U extends EntityWithTimeableAttr<PK, T> & EntityWithConfigurableAttr> Optional<IModel<String>> getStringAttribute(final U entity, final Date date, final String groupName, final String descName) { final T attrRowForCurrentDate = timeableService.getAttrRowValidAtDate(entity, groupName, date); if (attrRowForCurrentDate == null) { return Optional.empty(); } final String attribute = attrRowForCurrentDate.getStringAttribute(descName); if (attribute == null) { return Optional.empty(); } final AttrDescription attrDescription = getAttrDescription(entity, groupName, descName); final IModel<String> valueModel = (attrDescription.getWicketComponentFactoryClass() instanceof DropDownAttrWicketComponentFactory) ? new ResourceModel(attribute) : // DropDownAttrWicketComponentFactory -> it's a list of i18nkeys, so we need a ResourceModel for the translation new Model<>(attribute); return Optional.of(valueModel); }
@Override public Object getDisplayValue(T attrRow) { final Date startTime = attrRow.getStartTime(); return dateConverter.convertToString(startTime, null); }
private PropertyDelta createPropertyDelta(final AttrColumnDescription colDesc) { final String fieldName = colDesc.getGroupName() + "." + colDesc.getPropertyName(); final T attrRow = timeableService.getAttrRowForSameMonth(value, colDesc.getGroupName(), dateToSelectAttrRow); final T oldAttrRow = timeableService.getAttrRowForSameMonth(oldValue, colDesc.getGroupName(), dateToSelectAttrRow); if (attrRow == null) { return null; } final Object newVal = attrRow.getAttribute(colDesc.getPropertyName()); final Object oldVal = (oldAttrRow == null) ? null : oldAttrRow.getAttribute(colDesc.getPropertyName()); if (newVal == null && oldVal == null) { return null; } final Class type = (newVal != null) ? newVal.getClass() : oldVal.getClass(); return createPropertyDelta(fieldName, newVal, oldVal, type).orElse(null); } }
@Override protected void addMappings(PropertyMapping mapping, Object entry) { @SuppressWarnings("unchecked") final EntityWithTimeableAttr<PK, T> entity = (EntityWithTimeableAttr<PK, T>) entry; for (final AttrColumnDescription attrFieldToExport : attrFieldsToExport) { final T attrRow = timeableService.getAttrRowForSameMonth(entity, attrFieldToExport.getGroupName(), dateToSelectAttrRow); if (attrRow != null) { final String attributeValue = attrRow.getStringAttribute(attrFieldToExport.getPropertyName()); mapping.add(attrFieldToExport.getCombinedName(), attributeValue); } } }
if (valid && (selectedAttrRow == null || selectedAttrRow.getPk() != null)) {
private void validateDate(IValidatable<Date> iValidatable) { final Date dateToValidate = iValidatable.getValue(); final T selectedAttrRow = selectedAttrRowModel.getObject(); DayMonthGranularity gran = attrGroup.getDayMonthGranularity(); if (gran == null) { gran = DayMonthGranularity.DAY; } Predicate<T> predicate; String errorKey; switch (gran) { case MONTH: predicate = row -> DateUtils.isSameMonth(row.getStartTime(), dateToValidate); errorKey = "attr.starttime.alreadyexists.month"; break; default: predicate = row -> DateHelper.isSameDay(row.getStartTime(), dateToValidate); errorKey = "attr.starttime.alreadyexists.day"; } final boolean thereIsAlreadyAnEntryWithTheSameDate = getTimeableAttrRowsOfThisGroup() .stream() // remove the currently selected entry from the stream, otherwise this will always be true if you don't change the date .filter(row -> !row.equals(selectedAttrRow)) .anyMatch(predicate); if (thereIsAlreadyAnEntryWithTheSameDate) { iValidatable.error(new ValidationError().addKey(errorKey)); } }