use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestIdentityRoleService method conceptToRequestIdentityRole.
/**
* Converts concept to the request-identity-roles.
*
* @param concept
* @param filter
* @return
*/
@SuppressWarnings("unchecked")
private IdmRequestIdentityRoleDto conceptToRequestIdentityRole(IdmConceptRoleRequestDto concept, IdmRequestIdentityRoleFilter filter) {
IdmRequestIdentityRoleDto requestIdentityRoleDto = modelMapper.map(concept, IdmRequestIdentityRoleDto.class);
// load permission from related contract or role (OR)
if (// from find method only
filter != null && // newly requested role only
ConceptRoleRequestOperation.ADD == concept.getOperation() && !concept.getState().isTerminatedState()) {
// not terminated concepts
// by related contract (backward compatible)
IdmIdentityContractDto contract = lookupService.lookupEmbeddedDto(concept, IdmConceptRoleRequest_.identityContract);
Set<String> contractPermissions = identityContractService.getPermissions(contract);
if (PermissionUtils.hasPermission(contractPermissions, ContractBasePermission.CHANGEPERMISSION)) {
Set<String> permissions = requestIdentityRoleDto.getPermissions();
if (permissions == null) {
permissions = new HashSet<>();
}
permissions.add(ContractBasePermission.CHANGEPERMISSION.getName());
requestIdentityRoleDto.setPermissions(permissions);
} else {
// by related role
IdmRoleDto role = lookupService.lookupEmbeddedDto(concept, IdmConceptRoleRequest_.role);
Set<String> rolePermissions = roleService.getPermissions(role);
if (PermissionUtils.hasPermission(rolePermissions, RoleBasePermission.CHANGEPERMISSION)) {
Set<String> permissions = requestIdentityRoleDto.getPermissions();
if (permissions == null) {
permissions = new HashSet<>();
}
permissions.add(RoleBasePermission.CHANGEPERMISSION.getName());
requestIdentityRoleDto.setPermissions(permissions);
}
}
}
if (filter != null && filter.isIncludeEav()) {
IdmFormInstanceDto formInstanceDto;
if (ConceptRoleRequestOperation.REMOVE == concept.getOperation()) {
IdmIdentityRoleDto identityRole = DtoUtils.getEmbedded(concept, IdmConceptRoleRequest_.identityRole, IdmIdentityRoleDto.class, (IdmIdentityRoleDto) null);
if (identityRole == null) {
// Identity-role was not found, remove concept was executed (identity-role was removed).
return addCandidates(requestIdentityRoleDto, concept, filter);
}
formInstanceDto = identityRoleService.getRoleAttributeValues(identityRole);
} else {
// Check on change of values is made only on ended request! 'Original' value is current value and in audit it was confusing (only 'new' value is show now).
formInstanceDto = conceptRoleService.getRoleAttributeValues(concept, !concept.getState().isTerminatedState());
}
addEav(requestIdentityRoleDto, formInstanceDto);
}
// Include info if is role in cross-domain group.
if (filter != null && filter.isIncludeCrossDomainsSystemsCount()) {
if (ConceptRoleRequestOperation.REMOVE != concept.getOperation()) {
IdmRoleDto roleDto = DtoUtils.getEmbedded(concept, IdmConceptRoleRequest_.role.getName(), IdmRoleDto.class, null);
if (roleDto != null && this.roleSystemService instanceof AbstractReadDtoService) {
AbstractReadDtoService<?, ?, IdmRoleSystemFilter> roleSystemService = (AbstractReadDtoService<?, ?, IdmRoleSystemFilter>) this.roleSystemService;
BaseFilter roleSystemFilter = roleSystemService.createFilterInstance();
if (roleSystemFilter instanceof IdmRoleSystemFilter) {
IdmRoleSystemFilter idmRoleSystemFilter = (IdmRoleSystemFilter) roleSystemFilter;
idmRoleSystemFilter.setIsInCrossDomainGroupRoleId(roleDto.getId());
long count = roleSystemService.count(idmRoleSystemFilter);
roleDto.setSystemsInCrossDomains(count);
}
}
}
}
return addCandidates(requestIdentityRoleDto, concept, filter);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestIdentityRoleService method conceptsToRequestIdentityRoles.
/**
* Converts concepts to request-identity-roles
*
* @param concepts
* @param filter
* @return
*/
private List<IdmRequestIdentityRoleDto> conceptsToRequestIdentityRoles(List<IdmConceptRoleRequestDto> concepts, IdmRequestIdentityRoleFilter filter) {
List<IdmRequestIdentityRoleDto> results = Lists.newArrayList();
if (concepts == null) {
return results;
}
// Mark duplicates
// TODO: Rewrite to query, this is very ineffective!!
UUID identityId = filter.getIdentityId();
LOG.debug(MessageFormat.format("Start searching duplicates for identity [{1}].", identityId));
Assert.notNull(identityId, "Identity identifier is required.");
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findValidRoles(identityId, null).getContent();
// Add to all identity roles form instance. For identity role can exists only
// one form instance.
identityRoles.forEach(identityRole -> {
IdmFormInstanceDto formInstance = identityRoleService.getRoleAttributeValues(identityRole);
if (formInstance != null) {
identityRole.setEavs(Lists.newArrayList(formInstance));
}
});
// Find potential duplicated concepts (only ADD and not in terminated state)
List<IdmConceptRoleRequestDto> conceptsForMarkDuplicates = //
concepts.stream().filter(//
concept -> ConceptRoleRequestOperation.ADD == concept.getOperation()).filter(//
concept -> !concept.getState().isTerminatedState()).collect(//
Collectors.toList());
roleRequestService.markDuplicates(conceptsForMarkDuplicates, identityRoles);
// End mark duplicates
LOG.debug(MessageFormat.format("End searching duplicates for identity [{1}].", identityId));
concepts.forEach(concept -> {
IdmRequestIdentityRoleDto requestIdentityRoleDto = conceptToRequestIdentityRole(concept, filter);
results.add(requestIdentityRoleDto);
});
return results;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestIdentityRoleService method identityRolesToRequestIdentityRoles.
/**
* Converts identity-roles to request-identity-roles
*
* @param identityRoles
* @param filter
* @return
*/
private List<IdmRequestIdentityRoleDto> identityRolesToRequestIdentityRoles(List<IdmIdentityRoleDto> identityRoles, IdmRequestIdentityRoleFilter filter) {
List<IdmRequestIdentityRoleDto> concepts = Lists.newArrayList();
if (identityRoles == null) {
return concepts;
}
identityRoles.forEach(identityRole -> {
IdmRequestIdentityRoleDto request = new IdmRequestIdentityRoleDto();
request.setId(identityRole.getId());
request.setRole(identityRole.getRole());
request.setIdentityRole(identityRole.getId());
request.setDirectRole(identityRole.getDirectRole());
request.setRoleSystem(identityRole.getRoleSystem());
request.setRoleComposition(identityRole.getRoleComposition());
request.setIdentityContract(identityRole.getIdentityContract());
request.setValidFrom(identityRole.getValidFrom());
request.setValidTill(identityRole.getValidTill());
request.setAutomaticRole(identityRole.getAutomaticRole());
request.setTrimmed(true);
request.getEmbedded().put(IdmIdentityRole_.role.getName(), identityRole.getEmbedded().get(IdmIdentityRole_.role.getName()));
request.getEmbedded().put(IdmIdentityRole_.identityContract.getName(), identityRole.getEmbedded().get(IdmIdentityRole_.identityContract.getName()));
request.setPermissions(identityRole.getPermissions());
if (filter.isIncludeEav()) {
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRole);
addEav(request, formInstanceDto);
}
concepts.add(request);
});
return concepts;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testFindByRoleText.
@Test
@Transactional
public void testFindByRoleText() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto assignedRole = this.getHelper().createRole();
IdmIdentityRoleDto identityRole = this.getHelper().createIdentityRole(contract, assignedRole);
IdmRoleDto role = this.getHelper().createRole();
IdmRequestIdentityRoleFilter filter = new IdmRequestIdentityRoleFilter();
filter.setIdentityId(identity.getId());
filter.setRoleText(assignedRole.getCode());
// We expecting only one already assigned identity-role
List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(filter, null).getContent();
Assert.assertEquals(1, requestIdentityRoles.size());
Assert.assertEquals(identityRole.getId(), requestIdentityRoles.get(0).getId());
// Create request for new identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setRole(role.getId());
dto.setValidFrom(LocalDate.now().minusDays(1));
dto.setValidTill(LocalDate.now().plusDays(10));
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
// Filter will be filtering by this request
filter.setRoleRequestId(createdRequestIdentityRole.getRoleRequest());
// We expecting one item
requestIdentityRoles = requestIdentityRoleService.find(filter, null).getContent();
Assert.assertEquals(1, requestIdentityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testUniqueConceptValidation.
@Test(expected = InvalidFormException.class)
public void testUniqueConceptValidation() {
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes(true);
IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
filter.setRole(role.getId());
List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
Assert.assertEquals(2, list.size());
IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
// Delete IP attribute from the sub-definition
list.stream().filter(roleFormAttributeDto -> {
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
return formAttributeDto.getCode().equals(IP);
}).forEach(roleFormAttributeDto -> roleFormAttributeService.delete(roleFormAttributeDto));
formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(1, formAttributeSubdefinition.getFormAttributes().size());
Assert.assertEquals(NUMBER_OF_FINGERS, formAttributeSubdefinition.getFormAttributes().get(0).getCode());
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(contract.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(0, identityRoles.size());
// Create request identity-role
IdmRequestIdentityRoleDto createdRequestIdentityRole = new IdmRequestIdentityRoleDto();
createdRequestIdentityRole.setIdentityContract(contract.getId());
// Change the valid from
createdRequestIdentityRole.setValidFrom(LocalDate.now());
createdRequestIdentityRole.setRole(role.getId());
// Create role attribute value in concept
IdmFormDefinitionDto formDefinitionDto = roleService.getFormAttributeSubdefinition(role);
IdmFormInstanceDto formInstanceDto = new IdmFormInstanceDto();
IdmFormAttributeDto attribute = formDefinitionDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
IdmFormValueDto formValueDto = new IdmFormValueDto(attribute);
formValueDto.setValue(5);
List<IdmFormValueDto> values = Lists.newArrayList(formValueDto);
formInstanceDto.setValues(values);
List<IdmFormInstanceDto> forms = Lists.newArrayList(formInstanceDto);
createdRequestIdentityRole.setEavs(forms);
createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Execute a role-request.
getHelper().executeRequest(request, false, true);
IdmRequestIdentityRoleFilter filterRequestIdentityRole = new IdmRequestIdentityRoleFilter();
filterRequestIdentityRole.setIdentityId(identity.getId());
filterRequestIdentityRole.setRoleRequestId(request.getId());
// Include EAV attributes
filterRequestIdentityRole.setIncludeEav(true);
// Check EAV value in the request-identity-role
List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(filterRequestIdentityRole, null).getContent();
Assert.assertEquals(1, requestIdentityRoles.size());
Assert.assertEquals(role.getId(), requestIdentityRoles.get(0).getRole());
Assert.assertEquals(1, requestIdentityRoles.get(0).getEavs().size());
IdmFormInstanceDto formInstance = requestIdentityRoles.get(0).getEavs().get(0);
Assert.assertEquals(1, formInstance.getValues().size());
IdmFormValueDto formValue = formInstance.getValues().get(0);
Serializable value = formValue.getValue();
Assert.assertEquals(((BigDecimal) formValueDto.getValue()).longValue(), ((BigDecimal) value).longValue());
IdmFormAttributeDto mappedAttribute = formInstance.getMappedAttribute(formValue.getFormAttribute());
Assert.assertNotNull(mappedAttribute);
Assert.assertNull(formInstance.getValidationErrors());
identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(1, identityRoles.size());
// Create request identity-role
createdRequestIdentityRole = new IdmRequestIdentityRoleDto();
createdRequestIdentityRole.setIdentityContract(contract.getId());
// Change the valid from
createdRequestIdentityRole.setValidFrom(LocalDate.now());
createdRequestIdentityRole.setRole(role.getId());
// Create role attribute value in concept
formDefinitionDto = roleService.getFormAttributeSubdefinition(role);
formInstanceDto = new IdmFormInstanceDto();
attribute = formDefinitionDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
formValueDto = new IdmFormValueDto(attribute);
formValueDto.setValue(5);
values = Lists.newArrayList(formValueDto);
formInstanceDto.setValues(values);
forms = Lists.newArrayList(formInstanceDto);
createdRequestIdentityRole.setEavs(forms);
requestIdentityRoleService.save(createdRequestIdentityRole);
}
Aggregations