use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity_ in project CzechIdMng by bcvsolutions.
the class TestFilterReportExecutor method generateData.
@Override
@SuppressWarnings("rawtypes")
protected IdmAttachmentDto generateData(RptReportDto report) {
try {
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
//
List usernames = (List) formInstance.toPersistentValues(IdmIdentity_.username.getName());
List<IdmIdentityDto> results = TestReportExecutor.identities.stream().filter(identity -> {
return ObjectUtils.isEmpty(usernames) || usernames.contains(identity.getUsername());
}).collect(Collectors.toList());
return createAttachment(report, IOUtils.toInputStream(getMapper().writeValueAsString(results)));
} catch (FileNotFoundException | JsonProcessingException ex) {
throw new ReportGenerateException(report.getName(), ex);
}
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity_ in project CzechIdMng by bcvsolutions.
the class IdmAuditControllerRestTest method testFindEntityByUsername.
@Test
public void testFindEntityByUsername() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
MultiValueMap<String, String> filter = new LinkedMultiValueMap<>();
filter.set("ownerType", IdmIdentity.class.getCanonicalName());
filter.set(IdmIdentity_.username.getName(), identity.getUsername());
//
List<IdmAuditDto> find = find(filter, "/audits/search/entity");
//
Assert.assertFalse(find.isEmpty());
Assert.assertTrue(find.stream().allMatch(a -> a.getOwnerId().equals(identity.getId().toString())));
//
// test get revision
String response = getMockMvc().perform(get(BaseController.BASE_PATH + "/audits/" + find.get(0).getId()).with(authentication(getAdminAuthentication())).params(filter).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
// FIXME: jsou deserialization doesn't work ...
// IdmAuditDto audit = getMapper().convertValue(response, IdmAuditDto.class);
// //
// Assert.assertNotNull(audit);
// Assert.assertEquals(identity.getId().toString(), audit.getOwnerId());
// ugly workaround:
Assert.assertTrue(response.contains(identity.getId().toString()));
// username => entity Id is set
Assert.assertTrue(response.contains(identity.getUsername()));
//
// delete identity - check revision values is set
identityService.delete(identity);
Assert.assertNull(identityService.get(identity));
//
filter = new LinkedMultiValueMap<>();
filter.set("type", IdmIdentity.class.getCanonicalName());
filter.set("entityId", identity.getId().toString());
response = getMockMvc().perform(get(BaseController.BASE_PATH + "/audits/search/quick").with(authentication(getAdminAuthentication())).params(filter).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
//
// ugly workaround:
Assert.assertTrue(response.contains(identity.getId().toString()));
// username => entity Id is set
Assert.assertTrue(response.contains(identity.getUsername()));
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity_ in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testRecalculationWithManyIdentities.
@Test
@Ignore
public void testRecalculationWithManyIdentities() {
String description = getHelper().createName();
List<IdmIdentityDto> identities = new ArrayList<IdmIdentityDto>();
try {
//
for (int index = 0; index < 187; index++) {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
identity.setDescription(description);
identityService.save(identity);
identities.add(identity);
}
assertEquals(187, identities.size());
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.description.getName(), null, description);
// turn on async processing
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// execute recalculation
automaticRoleAttributeService.recalculate(automaticRole.getId());
//
// wait for result
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setAutomaticRoleId(automaticRole.getId());
getHelper().waitForResult(res -> {
return identityRoleService.count(filter) != 187;
}, 1000, 300);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(187, identityRoles.size());
for (IdmIdentityDto identity : identities) {
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, allByIdentity.size());
Assert.assertTrue(allByIdentity.stream().anyMatch(ir -> automaticRole.getId().equals(ir.getAutomaticRole()) && ir.getRole().equals(role.getId())));
Assert.assertTrue(allByIdentity.stream().anyMatch(ir -> ir.getDirectRole() != null && ir.getRole().equals(subRole.getId())));
}
} finally {
// turn off async processing
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
identityService.deleteAll(identities);
}
}
Aggregations