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));
}
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));
}
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));
}
}
}
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));
}
}
}
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));
}
}
}
Aggregations