Search in sources :

Example 76 with PageRequest

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

the class InitTestData method init.

protected void init() {
    // we are reusing demo data in tests as well
    initDemoData.init();
    // 
    securityService.setSystemAuthentication();
    // 
    try {
        IdmRoleDto superAdminRole = this.roleService.getByCode(InitApplicationData.ADMIN_ROLE);
        IdmTreeNodeDto rootOrganization = treeNodeService.findRoots((UUID) null, new PageRequest(0, 1)).getContent().get(0);
        // 
        if (!configurationService.getBooleanValue(PARAMETER_TEST_DATA_CREATED, false)) {
            log.info("Creating test data ...");
            // 
            IdmRoleDto role1 = new IdmRoleDto();
            role1.setName(TEST_USER_ROLE);
            role1 = this.roleService.save(role1);
            log.info(MessageFormat.format("Test role created [id: {0}]", role1.getId()));
            // 
            IdmRoleDto role2 = new IdmRoleDto();
            role2.setName(TEST_CUSTOM_ROLE);
            List<IdmRoleCompositionDto> subRoles = new ArrayList<>();
            subRoles.add(new IdmRoleCompositionDto(role2.getId(), superAdminRole.getId()));
            role2.setSubRoles(subRoles);
            role2 = this.roleService.save(role2);
            log.info(MessageFormat.format("Test role created [id: {0}]", role2.getId()));
            // 
            // Users for JUnit testing
            IdmIdentityDto testUser1 = new IdmIdentityDto();
            testUser1.setUsername(TEST_USER_1);
            testUser1.setPassword(new GuardedString("heslo"));
            testUser1.setFirstName("Test");
            testUser1.setLastName("First User");
            testUser1.setEmail("test1@bscsolutions.eu");
            testUser1 = this.identityService.save(testUser1);
            log.info(MessageFormat.format("Identity created [id: {0}]", testUser1.getId()));
            IdmIdentityDto testUser2 = new IdmIdentityDto();
            testUser2.setUsername(TEST_USER_2);
            testUser2.setPassword(new GuardedString("heslo"));
            testUser2.setFirstName("Test");
            testUser2.setLastName("Second User");
            testUser2.setEmail("test2@bscsolutions.eu");
            testUser2 = this.identityService.save(testUser2);
            log.info(MessageFormat.format("Identity created [id: {0}]", testUser2.getId()));
            IdmTreeTypeDto type = this.treeTypeService.get(rootOrganization.getTreeType());
            IdmTreeNodeDto organization = new IdmTreeNodeDto();
            organization.setCode("test");
            organization.setName("Organization Test");
            organization.setCreator("ja");
            organization.setParent(rootOrganization.getId());
            organization.setTreeType(type.getId());
            organization = this.treeNodeService.save(organization);
            IdmIdentityContractDto identityWorkPosition2 = new IdmIdentityContractDto();
            identityWorkPosition2.setIdentity(testUser1.getId());
            identityWorkPosition2.setWorkPosition(organization.getId());
            identityWorkPosition2 = identityContractService.save(identityWorkPosition2);
            IdmContractGuaranteeDto contractGuarantee = new IdmContractGuaranteeDto();
            contractGuarantee.setIdentityContract(identityWorkPosition2.getId());
            contractGuarantee.setGuarantee(testUser2.getId());
            contractGuaranteeService.save(contractGuarantee);
            // 
            log.info("Test data was created.");
            // 
            configurationService.setBooleanValue(PARAMETER_TEST_DATA_CREATED, true);
        }
    // 
    } finally {
        SecurityContextHolder.clearContext();
    }
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PageRequest(org.springframework.data.domain.PageRequest) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) ArrayList(java.util.ArrayList) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 77 with PageRequest

use of org.springframework.data.domain.PageRequest 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 78 with PageRequest

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

the class DefaultIdmFormAttributeService method deleteInternal.

@Override
@Transactional
@SuppressWarnings({ "rawtypes", "unchecked" })
public void deleteInternal(IdmFormAttributeDto dto) {
    Assert.notNull(dto);
    // attribute with filled values cannot be deleted
    IdmFormValueFilter filter = new IdmFormValueFilter();
    filter.setAttributeId(dto.getId());
    formValueServices.getPlugins().forEach(formValueService -> {
        if (formValueService.find(filter, new PageRequest(0, 1)).getTotalElements() > 0) {
            throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_HAS_VALUES, ImmutableMap.of("formAttribute", dto.getCode()));
        }
    });
    // delete all values
    // TODO: add some force delete parameter => rewrite service to event usage
    /* formValueServices.getPlugins().forEach(formValueService -> {
			formValueService.find(filter, null).getContent().forEach(formValue -> {
				formValueService.delete((IdmFormValueDto) formValue);
			});
		});*/
    // 
    // check rules for automatic role attributes
    IdmAutomaticRoleAttributeRuleFilter automaticRoleRuleFilter = new IdmAutomaticRoleAttributeRuleFilter();
    automaticRoleRuleFilter.setFormAttributeId(dto.getId());
    long totalElements = automaticRoleAttributeService.find(automaticRoleRuleFilter, new PageRequest(0, 1)).getTotalElements();
    if (totalElements > 0) {
        // some automatic roles use this attribute
        throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_AUTOMATIC_ROLE_RULE_ASSIGNED, ImmutableMap.of("formAttribute", dto.getId()));
    }
    // 
    // Check rules requests for automatic role attributes. Deletes relation on this form attribute.
    IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRuleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
    automaticRoleRuleRequestFilter.setFormAttributeId(dto.getId());
    List<IdmAutomaticRoleAttributeRuleRequestDto> ruleRequests = automaticRoleAttributeRequestService.find(automaticRoleRuleRequestFilter, null).getContent();
    ruleRequests.forEach(rule -> {
        rule.setFormAttribute(null);
        automaticRoleAttributeRequestService.save(rule);
    });
    // 
    super.deleteInternal(dto);
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 79 with PageRequest

use of org.springframework.data.domain.PageRequest 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)

Example 80 with PageRequest

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

the class DefaultAttachmentManager method getAttachmentVersions.

@Override
@Transactional
public List<IdmAttachmentDto> getAttachmentVersions(UUID attachmentId, BasePermission... permission) {
    Assert.notNull(attachmentId);
    // 
    IdmAttachmentFilter filter = new IdmAttachmentFilter();
    filter.setVersionsFor(attachmentId);
    // 
    return find(filter, new PageRequest(0, Integer.MAX_VALUE, new Sort(Direction.DESC, IdmAttachment_.versionNumber.getName())), permission).getContent();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort) IdmAttachmentFilter(eu.bcvsolutions.idm.core.ecm.api.dto.filter.IdmAttachmentFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)106 Sort (org.springframework.data.domain.Sort)29 Pageable (org.springframework.data.domain.Pageable)25 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)9 UUID (java.util.UUID)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 ApiOperation (io.swagger.annotations.ApiOperation)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)6 List (java.util.List)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 PageImpl (org.springframework.data.domain.PageImpl)5