Search in sources :

Example 41 with EntityList

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

the class MasterOrderHooksTest method shouldSetDeadline.

@Test
public final void shouldSetDeadline() {
    // given
    DateTime now = DateTime.now();
    stubId(masterOrder, MASTER_ORDER_ID);
    stubDateField(masterOrder, MasterOrderFields.DEADLINE, now.toDate());
    stubStringField(order1, OrderFields.STATE, OrderState.PENDING.getStringValue());
    stubStringField(order2, OrderFields.STATE, OrderState.IN_PROGRESS.getStringValue());
    stubDateField(order1, OrderFields.DEADLINE, now.plusHours(6).toDate());
    EntityList orders = mockEntityList(Lists.newArrayList(order1, order2));
    stubHasManyField(masterOrder, MasterOrderFields.ORDERS, orders);
    // when
    masterOrderHooks.changedDeadlineAndInOrder(masterOrder);
    // then
    verify(masterOrder).setField(eq(MasterOrderFields.ORDERS), entityListCaptor.capture());
    List<Entity> actualOrders = entityListCaptor.getValue();
    assertEquals(2, actualOrders.size());
    assertTrue(actualOrders.contains(order1));
    assertTrue(actualOrders.contains(order2));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 42 with EntityList

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

the class MasterOrderHooksTest method shouldSetCustomer.

@Test
public final void shouldSetCustomer() {
    // given
    stubId(masterOrder, MASTER_ORDER_ID);
    stubBelongsToField(masterOrder, MasterOrderFields.COMPANY, customer);
    stubStringField(order1, OrderFields.STATE, OrderState.PENDING.getStringValue());
    stubStringField(order2, OrderFields.STATE, OrderState.IN_PROGRESS.getStringValue());
    Entity yetAnotherCustomer = mockEntity();
    stubBelongsToField(order1, OrderFields.COMPANY, yetAnotherCustomer);
    EntityList orders = mockEntityList(Lists.newArrayList(order1, order2));
    given(masterOrder.getHasManyField(MasterOrderFields.ORDERS)).willReturn(orders);
    // when
    masterOrderHooks.changedDeadlineAndInOrder(masterOrder);
    // then
    verify(masterOrder).setField(eq(MasterOrderFields.ORDERS), entityListCaptor.capture());
    List<Entity> actualOrders = entityListCaptor.getValue();
    assertEquals(2, actualOrders.size());
    assertTrue(actualOrders.contains(order1));
    assertTrue(actualOrders.contains(order2));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with EntityList

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

the class StorageLocationsCriteriaModifier 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<Long> locationIds = userLocations.stream().map(ul -> ul.getBelongsToField(UserLocationFields.LOCATION)).map(Entity::getId).collect(Collectors.toSet());
            scb.add(SearchRestrictions.in("location.id", locationIds));
        }
    }
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 44 with EntityList

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

the class StorageLocationsStateCriteriaModifier 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.in(LOCATION_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)

Example 45 with EntityList

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

the class WarehouseStocksCriteriaModifier 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.in(LOCATION_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