use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class OrderRealizationTimeServiceImplTest method mockEntityListIterator.
private static EntityList mockEntityListIterator(List<Entity> list) {
EntityList entityList = mock(EntityList.class);
when(entityList.iterator()).thenReturn(list.iterator());
return entityList;
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class IssueCriteriaModifiers method restrictToUserLocations.
public void restrictToUserLocations(final SearchCriteriaBuilder scb, final FilterValueHolder filter) {
Long currentUserId = securityService.getCurrentUserId();
if (Objects.nonNull(currentUserId)) {
EntityList userLocations = userDataDefinition().get(currentUserId).getHasManyField(UserFieldsMF.USER_LOCATIONS);
if (!userLocations.isEmpty()) {
Set<Integer> locationIds = userLocations.stream().map(ul -> ul.getBelongsToField(UserLocationFields.LOCATION)).mapToInt(e -> e.getId().intValue()).boxed().collect(Collectors.toSet());
scb.add(SearchRestrictions.in("locationId", locationIds));
}
}
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class ProductionPerShiftDetailsHooks method checkOrderDates.
private void checkOrderDates(final ViewDefinitionState view, final Entity order) {
FormComponent productionPerShiftForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity pps = productionPerShiftForm.getPersistedEntityWithIncludedFormValues();
boolean shouldBeCorrected = OrderState.of(order).compareTo(OrderState.PENDING) != 0;
Set<Long> progressForDayIds = productionPerShiftDataProvider.findIdsOfEffectiveProgressForDay(pps, shouldBeCorrected);
DataDefinition progressForDayDD = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PROGRESS_FOR_DAY);
java.util.Optional<OrderDates> maybeOrderDates = OrderDates.of(order);
DataDefinition orderDD = order.getDataDefinition();
Entity dbOrder = orderDD.get(order.getId());
boolean areDatesCorrect = true;
if (maybeOrderDates.isPresent()) {
OrderDates orderDates = maybeOrderDates.get();
Date orderStart = removeTime(orderDates.getStart().effectiveWithFallback().toDate());
Date orderEnd = orderDates.getEnd().effectiveWithFallback().toDate();
Date ppsFinishDate = null;
for (Long id : progressForDayIds) {
Entity progressForDay = progressForDayDD.get(id);
Date progressDate = progressForDay.getDateField(ProgressForDayFields.ACTUAL_DATE_OF_DAY);
if (progressDate == null) {
progressDate = progressForDay.getDateField(ProgressForDayFields.DATE_OF_DAY);
}
EntityList dailyProgresses = progressForDay.getHasManyField(ProgressForDayFields.DAILY_PROGRESS);
for (Entity dailyProgress : dailyProgresses) {
Date shiftFinishDate = ppsTimeHelper.findFinishDate(dailyProgress, progressDate, dbOrder);
if (shiftFinishDate == null) {
view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
return;
}
if (ppsFinishDate == null || ppsFinishDate.before(shiftFinishDate)) {
ppsFinishDate = shiftFinishDate;
}
if (shiftFinishDate.before(orderStart)) {
areDatesCorrect = false;
}
}
}
if (ppsFinishDate != null) {
if (ppsFinishDate.after(orderEnd)) {
view.addMessage("productionPerShift.info.endDateTooLate", MessageType.INFO, false);
} else if (ppsFinishDate.before(orderEnd)) {
view.addMessage("productionPerShift.info.endDateTooEarly", MessageType.INFO, false);
}
}
}
if (!areDatesCorrect) {
view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
}
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class DraftDocumentsNotificationService method countDraftDocumentsForUser.
int countDraftDocumentsForUser(Long currentUserId) {
EntityList userLocations = userDataDefinition().get(currentUserId).getHasManyField(UserFieldsMF.USER_LOCATIONS);
SearchConjunction conjunction = SearchRestrictions.conjunction();
conjunction.add(eq(DocumentFields.STATE, DocumentState.DRAFT.getStringValue()));
conjunction.add(eq(DocumentFields.ACTIVE, Boolean.TRUE));
conjunction.add(isNull("order.id"));
SearchCriteriaBuilder criteriaBuilder = documentDataDefinition().find();
if (!userLocations.isEmpty()) {
criteriaBuilder.createAlias(DocumentFields.LOCATION_FROM, "locFrom", JoinType.LEFT);
criteriaBuilder.createAlias(DocumentFields.LOCATION_TO, "locTo", JoinType.LEFT);
Set<Long> locationIds = userLocations.stream().map(ul -> ul.getBelongsToField(UserLocationFields.LOCATION)).map(Entity::getId).collect(Collectors.toSet());
conjunction.add(or(in("locFrom.id", locationIds), in("locTo.id", locationIds)));
}
criteriaBuilder.add(conjunction);
return criteriaBuilder.list().getTotalNumberOfEntities();
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class ProductsToIssueCriteriaModifier method restrictToUserLocations.
public void restrictToUserLocations(final SearchCriteriaBuilder scb, final FilterValueHolder filterValue) {
Long currentUserId = securityService.getCurrentUserId();
if (Objects.nonNull(currentUserId)) {
EntityList userLocations = userDataDefinition().get(currentUserId).getHasManyField(UserFieldsMF.USER_LOCATIONS);
if (!userLocations.isEmpty()) {
Set<Integer> locationIds = userLocations.stream().map(ul -> ul.getBelongsToField(UserLocationFields.LOCATION)).mapToInt(e -> e.getId().intValue()).boxed().collect(Collectors.toSet());
scb.add(SearchRestrictions.or(SearchRestrictions.in(LOCATION_TO_ID, locationIds), SearchRestrictions.in(LOCATION_FROM_ID, locationIds)));
}
}
}
Aggregations