Search in sources :

Example 66 with EntityList

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

the class DocumentPositionsCriteriaModifier 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)

Example 67 with EntityList

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

the class DocumentsCriteriaModifier method restrictToUserLocations.

private void restrictToUserLocations(SearchCriteriaBuilder scb) {
    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) DocumentFields(com.qcadoo.mes.materialFlowResources.constants.DocumentFields) DocumentState(com.qcadoo.mes.materialFlowResources.constants.DocumentState) UserLocationFields(com.qcadoo.mes.materialFlow.constants.UserLocationFields) LOCATION_FROM_ID(com.qcadoo.mes.materialFlowResources.constants.DocumentDtoFields.LOCATION_FROM_ID) Service(org.springframework.stereotype.Service) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) LOCATION_TO_ID(com.qcadoo.mes.materialFlowResources.constants.DocumentDtoFields.LOCATION_TO_ID) SecurityService(com.qcadoo.security.api.SecurityService) EntityList(com.qcadoo.model.api.EntityList)

Example 68 with EntityList

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

the class ResourcesCriteriaModifier 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 69 with EntityList

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

the class OperationWorkTimeServiceTest method mockEntityList.

private static EntityList mockEntityList(final List<Entity> entities) {
    final EntityList entityList = mock(EntityList.class);
    given(entityList.iterator()).willAnswer((Answer<Iterator<Entity>>) invocation -> ImmutableList.copyOf(entities).iterator());
    given(entityList.isEmpty()).willReturn(entities.isEmpty());
    return entityList;
}
Also used : Assert.assertEquals(junit.framework.Assert.assertEquals) Arrays(java.util.Arrays) Mock(org.mockito.Mock) BigDecimal(java.math.BigDecimal) MockitoAnnotations(org.mockito.MockitoAnnotations) Answer(org.mockito.stubbing.Answer) ImmutableList(com.google.common.collect.ImmutableList) BDDMockito.given(org.mockito.BDDMockito.given) Map(java.util.Map) RoundingMode(java.math.RoundingMode) Before(org.junit.Before) Iterator(java.util.Iterator) MathContext(java.math.MathContext) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Maps(com.google.common.collect.Maps) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityList(com.qcadoo.model.api.EntityList) Mockito(org.mockito.Mockito) List(java.util.List) Entity(com.qcadoo.model.api.Entity) Assert(junit.framework.Assert) NumberService(com.qcadoo.model.api.NumberService) Mockito.mock(org.mockito.Mockito.mock) EntityList(com.qcadoo.model.api.EntityList) Iterator(java.util.Iterator)

Example 70 with EntityList

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

the class OperationWorkTimeServiceTest method shouldEstimateTotalOrderTimeWithAdditionalTime.

@Test
public void shouldEstimateTotalOrderTimeWithAdditionalTime() throws Exception {
    // // given
    EntityList operationComponents = mockEntityList(Arrays.asList(operComp1, operComp2, operComp3));
    // when
    operationWorkTime = operationWorkTimeService.estimateTotalWorkTime(operationComponents, operationRuns, false, true, false);
    // // then
    assertEquals(operationWorkTime.getLaborWorkTime(), new Integer(6930));
    assertEquals(operationWorkTime.getMachineWorkTime(), new Integer(2730));
}
Also used : EntityList(com.qcadoo.model.api.EntityList) Test(org.junit.Test)

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