Search in sources :

Example 86 with EntityList

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

the class ShiftTest method shouldParseTimeTableExceptions.

@Test
public final void shouldParseTimeTableExceptions() {
    // given
    String hours = "6:00-12:00, 21:30-2:30";
    given(shiftEntity.getStringField(ShiftFields.MONDAY_HOURS)).willReturn(hours);
    given(shiftEntity.getBooleanField(ShiftFields.MONDAY_WORKING)).willReturn(true);
    DateTime mondayMidnight = new DateTime(2013, 9, 2, 0, 0);
    DateTime freeTimeBegin = mondayMidnight.plusHours(8);
    DateTime freeTimeEnd = freeTimeBegin.plusHours(4);
    Entity freeTime = mockTimetableException(TimetableExceptionType.FREE_TIME, freeTimeBegin, freeTimeEnd);
    DateTime workTimeBegin = mondayMidnight.plusHours(20);
    DateTime workTimeEnd = workTimeBegin.plusHours(2);
    Entity workTime = mockTimetableException(TimetableExceptionType.WORK_TIME, workTimeBegin, workTimeEnd);
    EntityList timetableExceptionsList = mockEntityList(Lists.newArrayList(freeTime, workTime));
    given(shiftEntity.getHasManyField(ShiftFields.TIMETABLE_EXCEPTIONS)).willReturn(timetableExceptionsList);
    // when
    Shift shift = new Shift(shiftEntity);
    // then
    assertTrue(shift.worksAt(DateTimeConstants.MONDAY, new LocalTime(10, 30)));
    assertFalse(shift.worksAt(DateTimeConstants.SUNDAY, new LocalTime(12, 0)));
    assertFalse(shift.worksAt(DateTimeConstants.MONDAY, new LocalTime(12, 01)));
    assertEquals(Optional.of(new DateRange(mondayMidnight.plusHours(6).toDate(), mondayMidnight.plusHours(12).toDate())), shift.findWorkTimeAt(mondayMidnight.plusHours(7).toDate()));
    assertFalse(shift.findWorkTimeAt(mondayMidnight.plusDays(2).toDate()).isPresent());
    assertFalse(shift.findWorkTimeAt(mondayMidnight.plusHours(9).toDate()).isPresent());
}
Also used : Entity(com.qcadoo.model.api.Entity) DateRange(com.qcadoo.commons.dateTime.DateRange) LocalTime(org.joda.time.LocalTime) EntityList(com.qcadoo.model.api.EntityList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 87 with EntityList

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

the class CopyOfTechnologyHooks method getOrderForTechnology.

public Entity getOrderForTechnology(final ViewDefinitionState state) {
    DataDefinition orderDD = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER);
    String orderId = null;
    try {
        orderId = state.getJsonContext().getString("window.mainTab.technology.orderId");
    } catch (JSONException ex) {
        EntityList entities = ((FormComponent) state.getComponentByReference(QcadooViewConstants.L_FORM)).getPersistedEntityWithIncludedFormValues().getHasManyField("orders");
        if (!entities.isEmpty()) {
            orderId = String.valueOf(entities.get(0).getId());
        }
    }
    return orderDD.get(Long.valueOf(orderId));
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) EntityList(com.qcadoo.model.api.EntityList) JSONException(org.json.JSONException) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 88 with EntityList

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

the class WarehouseIssueListenerAspect method onDiscard.

@RunInPhase(WarehouseIssueStateChangePhase.LAST)
@RunForStateTransition(sourceState = WarehouseIssueStringValues.DRAFT, targetState = WarehouseIssueStringValues.DISCARD)
@After(PHASE_EXECUTION_POINTCUT)
public void onDiscard(final StateChangeContext stateChangeContext, final int phase) {
    Entity warehouseIssue = stateChangeContext.getOwner();
    EntityList productsToIssue = warehouseIssue.getHasManyField(WarehouseIssueFields.PRODUCTS_TO_ISSUES);
    productsToIssue.forEach(productToIssue -> {
        reservationsServiceForProductsToIssue.deleteReservationFromProductToIssue(productToIssue);
    });
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) RunForStateTransition(com.qcadoo.mes.states.annotation.RunForStateTransition) After(org.aspectj.lang.annotation.After) RunInPhase(com.qcadoo.mes.states.annotation.RunInPhase)

Example 89 with EntityList

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

the class WarehouseIssueListenerAspect method onCompleted.

@RunInPhase(WarehouseIssueStateChangePhase.PRE_VALIDATION)
@RunForStateTransition(sourceState = WarehouseIssueStringValues.IN_PROGRESS, targetState = WarehouseIssueStringValues.COMPLETED)
@After(PHASE_EXECUTION_POINTCUT)
public void onCompleted(final StateChangeContext stateChangeContext, final int phase) {
    if (issueStateService.checkIfAnyNotIssuedPositionsExists(stateChangeContext)) {
        return;
    }
    Entity warehouseIssue = stateChangeContext.getOwner();
    EntityList productsToIssue = warehouseIssue.getHasManyField(WarehouseIssueFields.PRODUCTS_TO_ISSUES);
    productsToIssue.forEach(productToIssue -> {
        reservationsServiceForProductsToIssue.deleteReservationFromProductToIssue(productToIssue);
    });
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) RunForStateTransition(com.qcadoo.mes.states.annotation.RunForStateTransition) After(org.aspectj.lang.annotation.After) RunInPhase(com.qcadoo.mes.states.annotation.RunInPhase)

Example 90 with EntityList

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

the class TechnologyValidationService method checkTopComponentsProducesProductForTechnology.

private boolean checkTopComponentsProducesProductForTechnology(final StateChangeContext stateChangeContext, final FormComponent technologyForm, final Entity technology) {
    final Entity savedTechnology = technology.getDataDefinition().get(technology.getId());
    final Entity product = savedTechnology.getBelongsToField(TechnologyFields.PRODUCT);
    final EntityTree operationComponents = savedTechnology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    final EntityTreeNode root = operationComponents.getRoot();
    if (Objects.nonNull(root)) {
        final EntityList operationProductOutComponents = root.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
        for (Entity operationProductOutComponent : operationProductOutComponents) {
            if (product.getId().equals(operationProductOutComponent.getBelongsToField(OperationProductOutComponentFields.PRODUCT).getId())) {
                return true;
            }
        }
    }
    if (Objects.nonNull(technologyForm)) {
        technologyForm.addMessage("technologies.technology.validate.global.error.noFinalProductInTechnologyTree", MessageType.FAILURE);
    } else {
        stateChangeContext.addValidationError("technologies.technology.validate.global.error.noFinalProductInTechnologyTree");
    }
    return false;
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityTreeNode(com.qcadoo.model.api.EntityTreeNode) EntityList(com.qcadoo.model.api.EntityList) EntityTree(com.qcadoo.model.api.EntityTree)

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