Search in sources :

Example 1 with LOCATION_TO_ID

use of com.qcadoo.mes.materialFlowResources.constants.DocumentDtoFields.LOCATION_TO_ID 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)

Aggregations

UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)1 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)1 LOCATION_FROM_ID (com.qcadoo.mes.materialFlowResources.constants.DocumentDtoFields.LOCATION_FROM_ID)1 LOCATION_TO_ID (com.qcadoo.mes.materialFlowResources.constants.DocumentDtoFields.LOCATION_TO_ID)1 DocumentFields (com.qcadoo.mes.materialFlowResources.constants.DocumentFields)1 DocumentState (com.qcadoo.mes.materialFlowResources.constants.DocumentState)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)1 EntityList (com.qcadoo.model.api.EntityList)1 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)1 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)1 SecurityService (com.qcadoo.security.api.SecurityService)1 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)1 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1