use of com.qcadoo.mes.assignmentToShift.dataProviders.AssignmentToShiftCriteria in project mes by qcadoo.
the class AssignmentToShiftHooks method findNextStartDatesMatching.
private Set<LocalDate> findNextStartDatesMatching(final DataDefinition assignmentToShiftDD, final LocalDate laterThan, final Shift shift, final Entity factory, Entity crew) {
AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty();
criteria.withCriteria(gt(AssignmentToShiftFields.START_DATE, laterThan.toDate()));
criteria.withShiftCriteria(idEq(shift.getId()));
criteria.withFactoryCriteria(idEq(factory.getId()));
if (Objects.nonNull(crew)) {
criteria.withCrewCriteria(idEq(crew.getId()));
}
List<Entity> matchingStartDatesProjection = assignmentToShiftDataProvider.findAll(criteria, Optional.of(alias(field(AssignmentToShiftFields.START_DATE), AssignmentToShiftFields.START_DATE)), Optional.of(asc(AssignmentToShiftFields.START_DATE)));
return FluentIterable.from(matchingStartDatesProjection).transform(EntityUtils.<Date>getFieldExtractor(AssignmentToShiftFields.START_DATE)).transform(TO_LOCAL_DATE).toSet();
}
use of com.qcadoo.mes.assignmentToShift.dataProviders.AssignmentToShiftCriteria in project mes by qcadoo.
the class AssignmentToShiftHooks method checkUniqueEntity.
boolean checkUniqueEntity(final Entity assignmentToShift) {
Date startDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE);
Entity shift = assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT);
Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY);
Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW);
AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty();
SearchCriterion additionalCriteria = eq(AssignmentToShiftFields.START_DATE, startDate);
criteria.withShiftCriteria(idEq(shift.getId()));
criteria.withFactoryCriteria(idEq(factory.getId()));
if (crew != null) {
criteria.withCrewCriteria(idEq(crew.getId()));
} else {
additionalCriteria = and(additionalCriteria, isNull(AssignmentToShiftFields.CREW));
}
if (assignmentToShift.getId() != null) {
additionalCriteria = and(additionalCriteria, idNe(assignmentToShift.getId()));
}
criteria.withCriteria(additionalCriteria);
for (Entity matchingAssignment : assignmentToShiftDataProvider.find(criteria, Optional.of(alias(id(), "id"))).asSet()) {
addErrorMessages(assignmentToShift.getDataDefinition(), assignmentToShift);
return false;
}
return true;
}
Aggregations