use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class AbstractRoleParametrizationFormDefaultValueGenerator method getDefaultValue.
/**
* Return default value for given form-attribute. First try to find override
* role-form-attribute. If exists, then return it's default value. If not, then
* default value from given form-attribute will be returned.
*
* @param attribute
* @param role
* @return
*/
private String getDefaultValue(IdmFormAttributeDto attribute, IdmRoleDto role) {
Assert.notNull(attribute, "Attribute is required.");
Assert.notNull(role, "Role is required.");
IdmRoleFormAttributeFilter roleFormAttributeFilter = new IdmRoleFormAttributeFilter();
roleFormAttributeFilter.setRole(role.getId());
roleFormAttributeFilter.setFormAttribute(attribute.getId());
List<IdmRoleFormAttributeDto> roleFormAttributes = roleFormAttributeService.find(roleFormAttributeFilter, null).getContent();
if (roleFormAttributes.size() > 0) {
return roleFormAttributes.get(0).getDefaultValue();
}
return attribute.getDefaultValue();
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleService method getFormAttributeSubdefinition.
@Override
public IdmFormDefinitionDto getFormAttributeSubdefinition(IdmRoleDto role) {
Assert.notNull(role, "Role is required.");
UUID identityRoleAttributeDefinition = role.getIdentityRoleAttributeDefinition();
if (identityRoleAttributeDefinition == null) {
return null;
}
IdmFormDefinitionDto definition = this.getFormService().getDefinition(identityRoleAttributeDefinition);
List<IdmFormAttributeDto> allAttributes = definition.getFormAttributes();
// Find sub-definition for given role
IdmRoleFormAttributeFilter attributeFilter = new IdmRoleFormAttributeFilter();
attributeFilter.setRole(role.getId());
List<IdmRoleFormAttributeDto> roleFormAttributes = roleFormAttributeService.find(attributeFilter, null).getContent();
// Find allowed attributes by sub-definition (and set default value from sub-definition attribute)
List<IdmFormAttributeDto> allowedAttributes = //
allAttributes.stream().filter(attribute -> {
IdmRoleFormAttributeDto result = //
roleFormAttributes.stream().filter(roleFormAttribute -> attribute.getId().equals(roleFormAttribute.getFormAttribute())).findFirst().orElse(//
null);
if (result != null) {
// Set default value from sub-definition attribute
attribute.setDefaultValue(result.getDefaultValue());
// Set validations
attribute.setRequired(result.isRequired());
attribute.setUnique(result.isUnique());
attribute.setMin(result.getMin());
attribute.setMax(result.getMax());
attribute.setRegex(result.getRegex());
attribute.setValidationMessage(result.getValidationMessage());
return true;
}
return false;
}).collect(Collectors.toList());
definition.setFormAttributes(allowedAttributes);
return definition;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmFormAttributeService method deleteInternal.
@Override
@Transactional
@SuppressWarnings({ "rawtypes", "unchecked" })
public void deleteInternal(IdmFormAttributeDto dto) {
Assert.notNull(dto, "DTO is required.");
// attribute with filled values cannot be deleted
IdmFormValueFilter filter = new IdmFormValueFilter();
filter.setAttributeId(dto.getId());
formValueServices.getPlugins().forEach(formValueService -> {
if (formValueService.find(filter, PageRequest.of(0, 1)).getTotalElements() > 0) {
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_HAS_VALUES, ImmutableMap.of("formAttribute", dto.getCode()));
}
});
//
// check rules for automatic role attributes
IdmAutomaticRoleAttributeRuleFilter automaticRoleRuleFilter = new IdmAutomaticRoleAttributeRuleFilter();
automaticRoleRuleFilter.setFormAttributeId(dto.getId());
long totalElements = automaticRoleAttributeService.find(automaticRoleRuleFilter, PageRequest.of(0, 1)).getTotalElements();
if (totalElements > 0) {
// some automatic roles use this attribute
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_AUTOMATIC_ROLE_RULE_ASSIGNED, ImmutableMap.of("formAttribute", dto.getId()));
}
// Check on using this attribute on role (sub-definition)
if (dto.getId() != null) {
IdmRoleFormAttributeFilter roleFormAttributeFilter = new IdmRoleFormAttributeFilter();
roleFormAttributeFilter.setFormAttribute(dto.getId());
List<IdmRoleFormAttributeDto> attributes = roleFormAttributeService.find(roleFormAttributeFilter, PageRequest.of(0, 1)).getContent();
if (attributes.size() > 0) {
IdmRoleDto roleDto = DtoUtils.getEmbedded(attributes.get(0), IdmRoleFormAttribute_.role.getName(), IdmRoleDto.class);
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_ROLE_ATTRIBUTE, ImmutableMap.of("definition", dto.getCode(), "role", roleDto.getCode()));
}
}
//
// Check rules requests for automatic role attributes. Deletes relation on this form attribute.
IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRuleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
automaticRoleRuleRequestFilter.setFormAttributeId(dto.getId());
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleRequests = automaticRoleAttributeRequestService.find(automaticRoleRuleRequestFilter, null).getContent();
ruleRequests.forEach(rule -> {
rule.setFormAttribute(null);
automaticRoleAttributeRequestService.save(rule);
});
//
super.deleteInternal(dto);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter 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);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class RoleExportBulkAction method exportRoleAttributes.
/**
* Export role-attributes for given role.
*
* @param role
*/
private void exportRoleAttributes(IdmRoleDto role) {
IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
filter.setRole(role.getId());
List<IdmRoleFormAttributeDto> dtos = roleFormAttributeService.find(filter, null).getContent();
if (dtos.isEmpty()) {
roleFormAttributeService.export(ExportManager.BLANK_UUID, this.getBatch());
}
dtos.forEach(dto -> {
roleFormAttributeService.export(dto.getId(), this.getBatch());
});
// Set parent field -> set authoritative mode.
this.getExportManager().setAuthoritativeMode(IdmRoleFormAttribute_.role.getName(), "role", IdmRoleFormAttributeDto.class, this.getBatch());
}
Aggregations