Search in sources :

Example 71 with EntityList

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;
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 72 with 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));
        }
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) QcadooSecurityConstants(com.qcadoo.security.constants.QcadooSecurityConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) DataDefinition(com.qcadoo.model.api.DataDefinition) Collectors(java.util.stream.Collectors) EntityList(com.qcadoo.model.api.EntityList) FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) Objects(java.util.Objects) UserFieldsMF(com.qcadoo.mes.materialFlow.constants.UserFieldsMF) UserLocationFields(com.qcadoo.mes.materialFlow.constants.UserLocationFields) Service(org.springframework.stereotype.Service) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SecurityService(com.qcadoo.security.api.SecurityService) EntityList(com.qcadoo.model.api.EntityList)

Example 73 with EntityList

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);
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) OrderDates(com.qcadoo.mes.orders.dates.OrderDates) EntityList(com.qcadoo.model.api.EntityList) DataDefinition(com.qcadoo.model.api.DataDefinition) Date(java.util.Date)

Example 74 with EntityList

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();
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchConjunction(com.qcadoo.model.api.search.SearchConjunction) EntityList(com.qcadoo.model.api.EntityList)

Example 75 with EntityList

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)));
        }
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) QcadooSecurityConstants(com.qcadoo.security.constants.QcadooSecurityConstants) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityList(com.qcadoo.model.api.EntityList) Objects(java.util.Objects) FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) UserFieldsMF(com.qcadoo.mes.materialFlow.constants.UserFieldsMF) UserLocationFields(com.qcadoo.mes.materialFlow.constants.UserLocationFields) Service(org.springframework.stereotype.Service) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SecurityService(com.qcadoo.security.api.SecurityService) EntityList(com.qcadoo.model.api.EntityList)

Aggregations

EntityList (com.qcadoo.model.api.EntityList)103 Entity (com.qcadoo.model.api.Entity)52 Test (org.junit.Test)27 DataDefinition (com.qcadoo.model.api.DataDefinition)16 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 Before (org.junit.Before)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)10 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 Objects (java.util.Objects)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Service (org.springframework.stereotype.Service)10 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)9 BigDecimal (java.math.BigDecimal)9 StateChangeTest (com.qcadoo.mes.states.StateChangeTest)5