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);
});
}
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);
}
}
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);
}
}
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);
}
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.");
}
}
Aggregations