Search in sources :

Example 11 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class OrderClosingHelperTest method mockEntityList.

private EntityList mockEntityList(final int size) {
    EntityList list = mock(EntityList.class);
    given(list.size()).willReturn(size);
    return list;
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 12 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class OrderDetailsHooksPPS method checkOrderDates.

private void checkOrderDates(final ViewDefinitionState view, final Entity order) {
    if (order.getId() == null) {
        return;
    }
    Entity pps = productionPerShiftDataProvider.getProductionPerShiftDD().find().add(SearchRestrictions.belongsTo("order", OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, order.getId())).setMaxResults(1).uniqueResult();
    if (pps != null) {
        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);
        Optional<OrderDates> maybeOrderDates;
        try {
            maybeOrderDates = OrderDates.of(order);
        } catch (IllegalArgumentException e) {
            return;
        }
        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 : 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 13 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class StateChangeTest method stubStateChangeEntity.

protected void stubStateChangeEntity(final StateChangeEntityDescriber describer) {
    given(stateChangeEntity.getDataDefinition()).willReturn(stateChangeDD);
    final EntityList emptyEntityList = mockEntityList(Collections.<Entity>emptyList());
    given(stateChangeEntity.getHasManyField(describer.getMessagesFieldName())).willReturn(emptyEntityList);
    stubEntityField(stateChangeEntity, describer.getStatusFieldName(), StateChangeStatus.IN_PROGRESS.getStringValue());
    given(stateChangeEntity.isValid()).willReturn(true);
    given(stateChangeDD.save(Mockito.any(Entity.class))).willAnswer(new Answer<Entity>() {

        @Override
        public Entity answer(final InvocationOnMock invocation) throws Throwable {
            return (Entity) invocation.getArguments()[0];
        }
    });
}
Also used : Entity(com.qcadoo.model.api.Entity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityList(com.qcadoo.model.api.EntityList)

Example 14 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class AbstractStateChangeAspectTest method mockEmptyEntityList.

@SuppressWarnings("unchecked")
private EntityList mockEmptyEntityList() {
    EntityList entityList = mock(EntityList.class);
    given(entityList.isEmpty()).willReturn(true);
    given(entityList.iterator()).willReturn(Collections.EMPTY_LIST.iterator());
    return entityList;
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 15 with EntityList

use of com.qcadoo.model.api.EntityList in project mes by qcadoo.

the class AbstractStateChangeAspectTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    stubStateChangeEntity(DESCRIBER);
    EntityList emptyEntityList = mockEmptyEntityList();
    stubStateChangeContext();
    stubOwner();
    given(stateChangeEntity.getHasManyField("messages")).willReturn(emptyEntityList);
    given(DESCRIBER.getOwnerDataDefinition().save(Mockito.any(Entity.class))).willAnswer(new Answer<Entity>() {

        @Override
        public Entity answer(final InvocationOnMock invocation) throws Throwable {
            return (Entity) invocation.getArguments()[0];
        }
    });
}
Also used : Entity(com.qcadoo.model.api.Entity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityList(com.qcadoo.model.api.EntityList) Before(org.junit.Before)

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