Search in sources :

Example 36 with Sort

use of org.springframework.data.domain.Sort in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowProcessInstanceService method find.

@Override
public Page<WorkflowProcessInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
    // we must call original method search because is there check flag checkRight
    if (pageable != null) {
        filter.setPageNumber(pageable.getPageNumber());
        filter.setPageSize(pageable.getPageSize());
        // 
        String fieldForSort = null;
        boolean ascSort = false;
        boolean descSort = false;
        if (pageable != null) {
            Sort sort = pageable.getSort();
            if (sort != null) {
                for (Order order : sort) {
                    if (!StringUtils.isEmpty(order.getProperty())) {
                        // TODO: now is implemented only one property sort
                        fieldForSort = order.getProperty();
                        if (order.getDirection() == Direction.ASC) {
                            ascSort = true;
                        } else if (order.getDirection() == Direction.DESC) {
                            descSort = true;
                        }
                        break;
                    }
                }
            }
        }
        filter.setSortAsc(ascSort);
        filter.setSortDesc(descSort);
        filter.setSortByFields(fieldForSort);
    }
    ResourcesWrapper<WorkflowProcessInstanceDto> search = this.search(filter);
    // 
    ResourcePage pages = search.getPage();
    List<WorkflowProcessInstanceDto> processes = (List<WorkflowProcessInstanceDto>) search.getResources();
    // 
    return new PageImpl<WorkflowProcessInstanceDto>(processes, pageable, pages.getTotalElements());
}
Also used : Order(org.springframework.data.domain.Sort.Order) PageImpl(org.springframework.data.domain.PageImpl) Sort(org.springframework.data.domain.Sort) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) ResourcePage(eu.bcvsolutions.idm.core.api.rest.domain.ResourcePage)

Example 37 with Sort

use of org.springframework.data.domain.Sort in project CzechIdMng by bcvsolutions.

the class IdmIdentityController method organizationPosition.

/**
 * Get given identity's prime position in organization.
 *
 * @param backendId
 * @return Positions from root to closest parent
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/work-position", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity prime position in organization.", nickname = "getIdentityPosition", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public ResponseEntity<?> organizationPosition(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable String backendId) {
    IdmIdentityDto identity = getDto(backendId);
    if (identity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    // 
    IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identity.getId());
    if (primeContract == null) {
        return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
    }
    WorkPositionDto position = new WorkPositionDto(identity, primeContract);
    if (primeContract.getWorkPosition() != null) {
        IdmTreeNodeDto contractPosition = treeNodeService.get(primeContract.getWorkPosition());
        position.getPath().addAll(treeNodeService.findAllParents(contractPosition.getId(), new Sort(Direction.ASC, "forestIndex.lft")));
        position.getPath().add(contractPosition);
    }
    return new ResponseEntity<WorkPositionDto>(position, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) WorkPositionDto(eu.bcvsolutions.idm.core.model.dto.WorkPositionDto) Sort(org.springframework.data.domain.Sort) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with Sort

use of org.springframework.data.domain.Sort in project CzechIdMng by bcvsolutions.

the class RebuildTreeNodeIndexTaskExecutor method process.

@Override
public Boolean process() {
    if (!configurationService.getBooleanValue(DefaultForestIndexService.PROPERTY_INDEX_ENABLED, true)) {
        throw new ResultCodeException(CoreResultCode.FOREST_INDEX_DISABLED, ImmutableMap.of("property", DefaultForestIndexService.PROPERTY_INDEX_ENABLED));
    }
    IdmTreeTypeDto treeType = getTreeType();
    String longRunningTaskId = configurationService.getValue(treeTypeService.getConfigurationPropertyName(treeTypeCode, IdmTreeTypeService.CONFIGURATION_PROPERTY_REBUILD));
    if (StringUtils.hasLength(longRunningTaskId) && !longRunningTaskId.equals(getLongRunningTaskId().toString())) {
        throw new ResultCodeException(CoreResultCode.FOREST_INDEX_RUNNING, ImmutableMap.of("type", IdmTreeNode.toForestTreeType(treeType.getId())));
    }
    // 
    LOG.info("Starting rebuilding tree node index for tree type code [{}].", treeTypeCode);
    // clear all rgt, lft
    try {
        forestIndexService.dropIndexes(IdmTreeNode.toForestTreeType(treeType.getId()));
    } finally {
        configurationService.setBooleanValue(treeTypeService.getConfigurationPropertyName(treeTypeCode, IdmTreeTypeService.CONFIGURATION_PROPERTY_VALID), false);
    }
    try {
        configurationService.setValue(treeTypeService.getConfigurationPropertyName(treeTypeCode, IdmTreeTypeService.CONFIGURATION_PROPERTY_REBUILD), getLongRunningTaskId().toString());
        // 
        Page<IdmTreeNode> nodes = treeNodeRepository.findByTreeType_Id(treeType.getId(), new PageRequest(0, 100, new Sort("id")));
        count = nodes.getTotalElements();
        counter = 0L;
        boolean canContinue = true;
        while (canContinue) {
            for (IdmTreeNode node : nodes) {
                if (node.getForestIndex() == null) {
                    forestIndexService.index(node.getForestTreeType(), node.getId(), node.getParentId());
                }
                counter++;
                canContinue = updateState();
                if (!canContinue) {
                    break;
                }
            }
            ;
            if (!nodes.hasNext()) {
                break;
            }
            nodes = treeNodeRepository.findByTreeType_Id(treeType.getId(), nodes.nextPageable());
        }
        // 
        if (count.equals(counter)) {
            configurationService.deleteValue(treeTypeService.getConfigurationPropertyName(treeTypeCode, IdmTreeTypeService.CONFIGURATION_PROPERTY_VALID));
            LOG.info("Tree node index for tree type code [{}] was successfully rebuilt (index size [{}]).", treeTypeCode, counter);
            return Boolean.TRUE;
        }
        // 
        LOG.warn("Tree node index for tree type code [{}] rebuild was canceled (index size [{}]).", treeTypeCode, counter);
        return Boolean.FALSE;
    } finally {
        configurationService.deleteValue(treeTypeService.getConfigurationPropertyName(treeTypeCode, IdmTreeTypeService.CONFIGURATION_PROPERTY_REBUILD));
    }
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) PageRequest(org.springframework.data.domain.PageRequest) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Sort(org.springframework.data.domain.Sort)

Example 39 with Sort

use of org.springframework.data.domain.Sort in project CzechIdMng by bcvsolutions.

the class RemoveOldLogsTaskExecutor method process.

@Override
public Boolean process() {
    if (days == null) {
        LOG.warn("Parameter {} is not filled. This task will be skipped.", PARAMETER_DAYS);
        return Boolean.TRUE;
    }
    // 
    IdmLoggingEventFilter filter = new IdmLoggingEventFilter();
    filter.setTill(DateTime.now().minusDays(days.intValue()));
    Page<IdmLoggingEventDto> loggingEvents = loggingEventService.find(filter, new PageRequest(0, 100, new Sort(IdmLoggingEvent_.timestmp.getName())));
    // 
    Long exceptionCounter = 0l;
    boolean canContinue = true;
    this.count = loggingEvents.getTotalElements();
    this.setCounter(0l);
    // 
    while (canContinue) {
        for (IdmLoggingEventDto event : loggingEvents) {
            Long eventId = Long.valueOf(event.getId().toString());
            // 
            LOG.debug("Event id: [{}] will be removed", event.getId());
            loggingEventExceptionService.deleteByEventId(eventId);
            loggingEventPropertyService.deleteAllByEventId(eventId);
            loggingEventService.deleteAllById(eventId);
            this.increaseCounter();
            // 
            canContinue = updateState();
            if (!canContinue) {
                break;
            }
        }
        // 
        loggingEvents = loggingEventService.find(filter, new PageRequest(0, 100, new Sort(IdmLoggingEvent_.timestmp.getName())));
        // 
        if (loggingEvents.getContent().isEmpty()) {
            break;
        }
    }
    // 
    LOG.info("Removed logs older than [{}] days was successfully completed. Removed logs: [{}] and their exceptions [{}].", days, this.counter, exceptionCounter);
    // 
    return Boolean.TRUE;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IdmLoggingEventDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto) IdmLoggingEventFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter) Sort(org.springframework.data.domain.Sort)

Example 40 with Sort

use of org.springframework.data.domain.Sort in project CzechIdMng by bcvsolutions.

the class DefaultIdmFormDefinitionService method toDto.

@Override
protected IdmFormDefinitionDto toDto(IdmFormDefinition entity, IdmFormDefinitionDto dto) {
    dto = super.toDto(entity, dto);
    if (dto != null && !dto.isTrimmed()) {
        // set mapped attributes
        IdmFormAttributeFilter filter = new IdmFormAttributeFilter();
        filter.setDefinitionId(dto.getId());
        dto.setFormAttributes(formAttributeService.find(filter, new PageRequest(0, Integer.MAX_VALUE, new Sort(IdmFormAttribute_.seq.getName(), IdmFormAttribute_.name.getName()))).getContent());
    }
    return dto;
}
Also used : IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort)

Aggregations

Sort (org.springframework.data.domain.Sort)49 PageRequest (org.springframework.data.domain.PageRequest)29 Pageable (org.springframework.data.domain.Pageable)14 ArrayList (java.util.ArrayList)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 List (java.util.List)5 Order (org.springframework.data.domain.Sort.Order)5 BooleanBuilder (com.querydsl.core.BooleanBuilder)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 Collectors (java.util.stream.Collectors)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 ApiOperation (io.swagger.annotations.ApiOperation)3 Date (java.util.Date)3 PageImpl (org.springframework.data.domain.PageImpl)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 Commentable (com.odysseusinc.arachne.portal.api.v1.dto.Commentable)2 SubmissionInsightDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO)2 CommentTopic (com.odysseusinc.arachne.portal.model.CommentTopic)2 SubmissionInsight (com.odysseusinc.arachne.portal.model.SubmissionInsight)2