private String getAttrValueForMonthAsString(EmployeeDO employee, String attrGroup, String attrProperty, Calendar selectedDate) { final EmployeeTimedDO attribute = timeableService.getAttrRowForSameMonth(employee, attrGroup, selectedDate.getTime()); return attribute != null ? attribute.getStringAttribute(attrProperty) : null; }
private T getAttrRowForCurrentDate(final List<T> attrRows) { return timeableService.getAttrRowValidAtDate(attrRows, attrGroup, new Date()); }
private VisitorbookTimedDO getNewestEntry(final VisitorbookDO visitor) { List<VisitorbookTimedDO> timeableAttributes = timeableService.getTimeableAttrRowsForGroupName(visitor, "timeofvisit"); if (timeableAttributes != null && timeableAttributes.size() > 0) { List<VisitorbookTimedDO> sortedList = timeableService.sortTimeableAttrRowsByDateDescending(timeableAttributes); return sortedList.get(0); } return null; }
@Override public boolean isFulltimeEmployee(final EmployeeDO employee, final Calendar selectedDate) { final Calendar date = (Calendar) selectedDate.clone(); // create a clone to avoid changing the original object final Date startOfMonth = date.getTime(); date.add(Calendar.MONTH, 1); date.add(Calendar.DATE, -1); final Date endOfMonth = date.getTime(); final List<EmployeeTimedDO> attrRows = timeableService .getAttrRowsWithinDateRange(employee, InternalAttrSchemaConstants.EMPLOYEE_STATUS_GROUP_NAME, startOfMonth, endOfMonth); final EmployeeTimedDO rowValidAtBeginOfMonth = timeableService .getAttrRowValidAtDate(employee, InternalAttrSchemaConstants.EMPLOYEE_STATUS_GROUP_NAME, selectedDate.getTime()); if (rowValidAtBeginOfMonth != null) { attrRows.add(rowValidAtBeginOfMonth); } return attrRows .stream() .map(row -> row.getStringAttribute(InternalAttrSchemaConstants.EMPLOYEE_STATUS_DESC_NAME)) .filter(Objects::nonNull) .anyMatch(s -> EmployeeStatus.FEST_ANGESTELLTER.getI18nKey().equals(s) || EmployeeStatus.BEFRISTET_ANGESTELLTER.getI18nKey().equals(s)); }
final List<VisitorbookDO> resultList = getList(queryFilter); final Predicate<VisitorbookDO> afterStartTimeOrSameDay = visitor -> timeableService.getTimeableAttrRowsForGroupName(visitor, "timeofvisit").stream() .anyMatch(timeAttr -> timeAttr.getStartTime().before(myFilter.getStartTime()) == false); // before() == false -> after or same day final Predicate<VisitorbookDO> beforeStopTimeOrSameDay = visitor -> timeableService.getTimeableAttrRowsForGroupName(visitor, "timeofvisit").stream() .anyMatch(timeAttr -> timeAttr.getStartTime().after(myFilter.getStopTime()) == false); // after() == false -> before or same day
private List<T> getTimeableAttrRowsOfThisGroup() { return timeableService.getTimeableAttrRowsForGroup(entity, attrGroup); }
private List<T> getTimeableAttrRowsOfThisGroupSorted() { return timeableService.sortTimeableAttrRowsByDateDescending(getTimeableAttrRowsOfThisGroup()); }
public List<Integer> getDropDownYears() { // do not cache the years because this is a long lasting service and the years could change in the meantime final List<Integer> years = timeableService.getAvailableStartTimeYears(employeeDao.internalLoadAll()); final Integer actualYear = new GregorianCalendar().get(Calendar.YEAR); if (years.contains(actualYear) == false) { years.add(actualYear); } if (years.contains(actualYear + 1) == false) { years.add(actualYear + 1); } return years .stream() .sorted() .collect(Collectors.toList()); }
private boolean getAttrValueForMonthAsBoolean(EmployeeDO employee, String attrGroup, String attrProperty, Calendar selectedDate) { final EmployeeTimedDO attribute = timeableService.getAttrRowForSameMonth(employee, attrGroup, selectedDate.getTime()); if (attribute == null) { return false; } final Boolean value = attribute.getAttribute(attrProperty, Boolean.class); return Boolean.TRUE.equals(value); }
/** * @see org.projectforge.web.wicket.CellItemListenerPropertyColumn#populateItem(org.apache.wicket.markup.repeater.Item, * java.lang.String, org.apache.wicket.model.IModel) */ @Override public void populateItem(final Item<ICellPopulator<VisitorbookDO>> item, final String componentId, final IModel<VisitorbookDO> rowModel) { final VisitorbookDO visitor = rowModel.getObject(); String value = ""; List<VisitorbookTimedDO> timeableAttributes = timeableService.getTimeableAttrRowsForGroupName(visitor, "timeofvisit"); if (timeableAttributes != null && timeableAttributes.size() > 0) { List<VisitorbookTimedDO> sortedList = timeableService.sortTimeableAttrRowsByDateDescending(timeableAttributes); VisitorbookTimedDO newestEntry = sortedList.get(0); SimpleDateFormat sdfParser = new SimpleDateFormat("dd.MM.yyyy"); String date = sdfParser.format(newestEntry.getStartTime()); String time = newestEntry.getAttribute("arrive") != null ? newestEntry.getAttribute("arrive", String.class) : ""; value = date + " " + time; } item.add(new TextPanel(componentId, value)); cellItemListener.populateItem(item, componentId, rowModel); } });
@Override public BigDecimal getMonthlySalary(EmployeeDO employee, Calendar selectedDate) { final EmployeeTimedDO attribute = timeableService.getAttrRowValidAtDate(employee, "annuity", selectedDate.getTime()); final BigDecimal annualSalary = attribute != null ? attribute.getAttribute("annuity", BigDecimal.class) : null; final BigDecimal weeklyWorkingHours = employee.getWeeklyWorkingHours(); if (annualSalary != null && weeklyWorkingHours != null && BigDecimal.ZERO.compareTo(weeklyWorkingHours) < 0) { // do the multiplication before the division to minimize rounding problems // we need a rounding mode to avoid ArithmeticExceptions when the exact result cannot be represented in the result return annualSalary .multiply(weeklyWorkingHours) .divide(MONTHS_PER_YEAR, BigDecimal.ROUND_HALF_UP) .divide(FULL_TIME_WEEKLY_WORKING_HOURS, BigDecimal.ROUND_HALF_UP); } return null; }
private BigDecimal getAttrValueForMonthAsBigDecimal(EmployeeDO employee, String attrGroupString, String attrProperty, Calendar selectedDate) { final EmployeeTimedDO attribute = timeableService.getAttrRowForSameMonth(employee, attrGroupString, selectedDate.getTime()); return attribute != null ? attribute.getAttribute(attrProperty, BigDecimal.class) : null; }
/** * @see org.projectforge.web.wicket.CellItemListenerPropertyColumn#populateItem(org.apache.wicket.markup.repeater.Item, * java.lang.String, org.apache.wicket.model.IModel) */ @Override public void populateItem(final Item<ICellPopulator<VisitorbookDO>> item, final String componentId, final IModel<VisitorbookDO> rowModel) { final VisitorbookDO visitor = rowModel.getObject(); String value = ""; List<VisitorbookTimedDO> timeableAttributes = timeableService.getTimeableAttrRowsForGroupName(visitor, "timeofvisit"); if (timeableAttributes != null && timeableAttributes.size() > 0) { List<VisitorbookTimedDO> sortedList = timeableService.sortTimeableAttrRowsByDateDescending(timeableAttributes); VisitorbookTimedDO newestEntry = sortedList.get(0); SimpleDateFormat sdfParser = new SimpleDateFormat("dd.MM.yyyy"); String date = sdfParser.format(newestEntry.getStartTime()); String time = newestEntry.getAttribute("depart") != null ? newestEntry.getAttribute("depart", String.class) : ""; value = date + " " + time; } item.add(new TextPanel(componentId, value)); cellItemListener.populateItem(item, componentId, rowModel); } });
@Override public EmployeeStatus getEmployeeStatus(final EmployeeDO employee) { final EmployeeTimedDO attrRow = timeableService .getAttrRowValidAtDate(employee, InternalAttrSchemaConstants.EMPLOYEE_STATUS_GROUP_NAME, new Date()); if (attrRow != null && StringUtils.isEmpty(attrRow.getStringAttribute(InternalAttrSchemaConstants.EMPLOYEE_STATUS_DESC_NAME)) == false) { return EmployeeStatus.findByi18nKey(attrRow.getStringAttribute(InternalAttrSchemaConstants.EMPLOYEE_STATUS_DESC_NAME)); } return null; }
private BigDecimal getAttrValueForMonthAsBigDecimal(EmployeeConfigurationDO configuration, String attrGroup, String attrProperty, Calendar selectedDate) { EmployeeConfigurationTimedDO attribute = timeableService.getAttrRowForSameMonth(configuration, attrGroup, selectedDate.getTime()); return attribute != null ? attribute.getAttribute(attrProperty, BigDecimal.class) : null; }
@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); }
private String getAttribute(final EmployeeDO employee, final AttrColumnDescription desc) { final EmployeeTimedDO attrRow = timeableService.getAttrRowForSameMonth(employee, desc.getGroupName(), dateToSelectAttrRow); return attrRow.getStringAttribute(desc.getPropertyName()); } }
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); } } }
/** * Call CellItemListener. If a property model object is of type I18nEnum then the translation is automatically used. * * @see org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn#populateItem(org.apache.wicket.markup.repeater.Item, * java.lang.String, org.apache.wicket.model.IModel) * @see CellItemListener#populateItem(Item, String, IModel) */ @Override public void populateItem(final Item<ICellPopulator<T>> item, final String componentId, final IModel<T> rowModel) { final EmployeeDO employee = (EmployeeDO) rowModel.getObject(); final Calendar cal = new GregorianCalendar(selectedYear, selectedMonth - 1, 1, 0, 0); EmployeeTimedDO row = timeableService.getAttrRowForSameMonth(employee, getPropertyExpression(), cal.getTime()); if (row == null) { row = employeeService.addNewTimeAttributeRow(employee, getPropertyExpression()); row.setStartTime(cal.getTime()); } final AttrGroup attrGroup = guiAttrSchemaService.getAttrGroup(employee, getPropertyExpression()); final AttrDescription attrDescription = guiAttrSchemaService.getAttrDescription(attrGroup, groupAttribute); item.add((Component) guiAttrSchemaService.createWicketComponent(componentId, attrGroup, attrDescription, row)); if (cellItemListener != null) { cellItemListener.populateItem(item, componentId, rowModel); } } }