use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method createIdentityWithDefaultRoleTest.
@Test
public void createIdentityWithDefaultRoleTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(IDENTITY_ONE);
List<IdmIdentityDto> identities = identityService.find(identityFilter, null).getContent();
Assert.assertEquals(0, identities.size());
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
// Have to be in the warning state, because default role cannot be assigned for
// new identity, because sync do not creates the default contract. See
// IdmIdentityContractService.SKIP_CREATION_OF_DEFAULT_POSITION.
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
identities = identityService.find(identityFilter, null).getContent();
Assert.assertEquals(1, identities.size());
List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identities.get(0).getId());
Assert.assertEquals(0, roles.size());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityService method findAllManagers.
/**
* Method finds all identity's managers by identity contract (guarantee or by assigned tree structure).
*
* @param forIdentity
* @param byTreeType If optional tree type is given, then only managers defined with this type is returned
* @return
*/
@Override
@Transactional(readOnly = true)
public List<IdmIdentityDto> findAllManagers(UUID forIdentity, UUID byTreeType) {
Assert.notNull(forIdentity, "Identity id is required.");
//
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setManagersFor(forIdentity);
filter.setManagersByTreeType(byTreeType);
//
List<IdmIdentityDto> results = new ArrayList<>();
Page<IdmIdentityDto> managers = find(filter, new PageRequest(0, 50, Sort.Direction.ASC, IdmIdentity_.username.getName()));
results.addAll(managers.getContent());
while (managers.hasNext()) {
managers = find(filter, managers.nextPageable());
results.addAll(managers.getContent());
}
//
if (!results.isEmpty()) {
return results;
}
// return all valid identities with admin role
return this.findValidByRole(roleConfiguration.getAdminRoleId());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter 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 eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter 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 eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter in project CzechIdMng by bcvsolutions.
the class IdentityFilterTest method testUsernameFilter.
@Test
public void testUsernameFilter() {
IdmIdentityDto person = getIdmIdentity("ThisIsTestName001", "ThisIsTestName001", "ThisIsTestName001@gemail.eu", "000000001", false);
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setUsername(person.getUsername());
Page<IdmIdentityDto> result = identityService.find(filter, null);
assertEquals("Wrong Username", 1, result.getTotalElements());
assertEquals("Wrong Username user ID", person.getId(), result.getContent().get(0).getId());
}
Aggregations