Search in sources :

Example 41 with PageRequest

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

the class HrEndContractProcessIntegrationTest method addRolesToContract.

private void addRolesToContract(IdmIdentityContractDto contract) {
    roleService.find(new PageRequest(0, 5)).forEach(role -> {
        IdmIdentityRoleDto d = new IdmIdentityRoleDto();
        d.setRole(role.getId());
        d.setAutomaticRole(false);
        d.setIdentityContract(contract.getId());
        identityRoleService.save(d);
    });
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 42 with PageRequest

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

the class IdentityReportExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    File temp = null;
    FileOutputStream outputStream = null;
    try {
        // prepare temp file for json stream
        temp = getAttachmentManager().createTempFile();
        outputStream = new FileOutputStream(temp);
        // write into json stream
        JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
        try {
            // json will be array of identities
            jGenerator.writeStartArray();
            // form instance has useful methods to transform form values
            IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
            // initialize filter by given form - transform to multi value map
            // => form attribute defined above will be automaticaly mapped to identity filter
            IdmIdentityFilter filter = new IdmIdentityFilter(formInstance.toMultiValueMap());
            // report extends long running task - show progress by count and counter lrt attributes
            counter = 0L;
            // find a first page of identities
            Pageable pageable = new PageRequest(0, 100, new Sort(Direction.ASC, IdmIdentity_.username.getName()));
            do {
                Page<IdmIdentityDto> identities = identityService.find(filter, pageable, IdmBasePermission.READ);
                if (count == null) {
                    // report extends long running task - show progress by count and counter lrt attributes
                    count = identities.getTotalElements();
                }
                boolean canContinue = true;
                for (Iterator<IdmIdentityDto> i = identities.iterator(); i.hasNext() && canContinue; ) {
                    // write single identity into json
                    getMapper().writeValue(jGenerator, i.next());
                    // 
                    // supports cancel report generating (report extends long running task)
                    ++counter;
                    canContinue = updateState();
                }
                // iterate while next page of identities is available
                pageable = identities.hasNext() && canContinue ? identities.nextPageable() : null;
            } while (pageable != null);
            // 
            // close array of identities
            jGenerator.writeEndArray();
        } finally {
            // close json stream
            jGenerator.close();
        }
        // save create temp file with array of identities in json as attachment
        return createAttachment(report, new FileInputStream(temp));
    } catch (IOException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    } finally {
        // just for sure - jGenerator should close stream itself
        IOUtils.closeQuietly(outputStream);
        FileUtils.deleteQuietly(temp);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) FileInputStream(java.io.FileInputStream) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Sort(org.springframework.data.domain.Sort) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) File(java.io.File)

Example 43 with PageRequest

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

the class IdentityReportExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    File temp = null;
    FileOutputStream outputStream = null;
    try {
        // prepare temp file for json stream
        temp = getAttachmentManager().createTempFile();
        outputStream = new FileOutputStream(temp);
        // write into json stream
        JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
        try {
            // json will be array of identities
            jGenerator.writeStartArray();
            // form instance has useful methods to transform form values
            IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
            // initialize filter by given form - transform to multi value map
            // => form attribute defined above will be automaticaly mapped to identity filter
            IdmIdentityFilter filter = new IdmIdentityFilter(formInstance.toMultiValueMap());
            // report extends long running task - show progress by count and counter lrt attributes
            counter = 0L;
            // find a first page of identities
            Pageable pageable = new PageRequest(0, 100, new Sort(Direction.ASC, IdmIdentity_.username.getName()));
            do {
                Page<IdmIdentityDto> identities = identityService.find(filter, pageable, IdmBasePermission.READ);
                if (count == null) {
                    // report extends long running task - show progress by count and counter lrt attributes
                    count = identities.getTotalElements();
                }
                boolean canContinue = true;
                for (Iterator<IdmIdentityDto> i = identities.iterator(); i.hasNext() && canContinue; ) {
                    // write single identity into json
                    getMapper().writeValue(jGenerator, i.next());
                    // 
                    // supports cancel report generating (report extends long running task)
                    ++counter;
                    canContinue = updateState();
                }
                // iterate while next page of identities is available
                pageable = identities.hasNext() && canContinue ? identities.nextPageable() : null;
            } while (pageable != null);
            // 
            // close array of identities
            jGenerator.writeEndArray();
        } finally {
            // close json stream
            jGenerator.close();
        }
        // save create temp file with array of identities in json as attachment
        return createAttachment(report, new FileInputStream(temp));
    } catch (IOException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    } finally {
        // just for sure - jGenerator should close stream itself
        IOUtils.closeQuietly(outputStream);
        FileUtils.deleteQuietly(temp);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) FileInputStream(java.io.FileInputStream) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Sort(org.springframework.data.domain.Sort) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) File(java.io.File)

Example 44 with PageRequest

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

the class SendNotificationToApplicantAndImplementerTest method createStructure.

/**
 * Creates organization's structure and identity testUser2 as manager
 */
private void createStructure() {
    IdmRoleDto superAdminRole = this.roleService.getByCode(InitApplicationData.ADMIN_ROLE);
    IdmTreeNodeDto rootOrganization = treeNodeService.findRoots((UUID) null, new PageRequest(0, 1)).getContent().get(0);
    IdmRoleDto role2 = new IdmRoleDto();
    role2.setName("TestCustomRole002" + System.currentTimeMillis());
    List<IdmRoleCompositionDto> subRoles = new ArrayList<>();
    subRoles.add(new IdmRoleCompositionDto(role2.getId(), superAdminRole.getId()));
    role2.setSubRoles(subRoles);
    role2 = this.roleService.save(role2);
    testUser2 = new IdmIdentityDto();
    testUser2.setUsername("Test_user_Manager" + System.currentTimeMillis());
    testUser2.setPassword(new GuardedString("heslo"));
    testUser2.setFirstName("Test");
    testUser2.setLastName("Second User");
    testUser2.setEmail("test2@bscsolutions.eu");
    testUser2 = this.identityService.save(testUser2);
    IdmTreeTypeDto type = treeTypeService.get(rootOrganization.getTreeType());
    organization = new IdmTreeNodeDto();
    organization.setCode("test" + System.currentTimeMillis());
    organization.setName("Organization Test Notification");
    organization.setParent(rootOrganization.getId());
    organization.setTreeType(type.getId());
    organization = this.treeNodeService.save(organization);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PageRequest(org.springframework.data.domain.PageRequest) 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)

Example 45 with PageRequest

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

the class BasicVirtualConnector method search.

@Override
public void search(IcObjectClass objectClass, IcFilter filter, IcResultsHandler handler) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(handler, "Result handler cannot be null for search operation!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    if (filter == null) {
        Pageable pageable = new PageRequest(0, 10);
        searchByPage(handler, pageable);
    } else {
        // TODO: Search by filter
        throw new IcException("Virtual system connector does not support search by filter! Filter must be null!. It means search return always all accounts.");
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) IcException(eu.bcvsolutions.idm.ic.exception.IcException)

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