use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testSubDefinitionOverrideValidationUnique.
@Test
public void testSubDefinitionOverrideValidationUnique() {
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes();
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());
// Set unique validation on false to IP attribute in the sub-definition
list.stream().filter(roleFormAttributeDto -> {
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
return formAttributeDto.getCode().equals(IP);
}).forEach(roleFormAttributeDto -> {
Assert.assertFalse(roleFormAttributeDto.isUnique());
roleFormAttributeDto.setUnique(true);
roleFormAttributeService.save(roleFormAttributeDto);
});
// Load sub-definition by role
formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
IdmFormAttributeDto ipFormAttribute = formAttributeSubdefinition.getFormAttributes().stream().filter(attributeDto -> {
return attributeDto.getCode().equals(IP);
}).findFirst().orElse(null);
Assert.assertNotNull(ipFormAttribute);
Assert.assertTrue(ipFormAttribute.isUnique());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testSubDefinitionOverrideDefaultValue.
@Test
public void testSubDefinitionOverrideDefaultValue() {
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes();
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());
// Set unique defaultValue to IP attribute in the sub-definition
String uniqueDefaultValue = this.getHelper().createName();
list.stream().filter(roleFormAttributeDto -> {
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
return formAttributeDto.getCode().equals(IP);
}).forEach(roleFormAttributeDto -> {
roleFormAttributeDto.setDefaultValue(uniqueDefaultValue);
roleFormAttributeService.save(roleFormAttributeDto);
});
// Load sub-definition by role
formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
IdmFormAttributeDto ipFormAttribute = formAttributeSubdefinition.getFormAttributes().stream().filter(attributeDto -> {
return attributeDto.getCode().equals(IP);
}).findFirst().orElse(null);
Assert.assertNotNull(ipFormAttribute);
Assert.assertEquals(uniqueDefaultValue, ipFormAttribute.getDefaultValue());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class RoleSaveProcessor method process.
@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
IdmRoleDto entity = event.getContent();
IdmRoleDto originalSource = event.getOriginalSource();
UUID roleAttributeDefinition = entity.getIdentityRoleAttributeDefinition();
UUID originalRoleAttributeDefinition = originalSource != null ? originalSource.getIdentityRoleAttributeDefinition() : null;
// Validation - form definition can be changed only if none role-form-attributes exists (for this role)
if (!Objects.equals(roleAttributeDefinition, originalRoleAttributeDefinition)) {
IdmRoleFormAttributeFilter roleFormAttributeFilter = new IdmRoleFormAttributeFilter();
roleFormAttributeFilter.setRole(entity.getId());
long count = roleFormAttributeService.count(roleFormAttributeFilter);
if (count > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_FORM_ATTRIBUTE_CHANGE_DEF_NOT_ALLOWED, ImmutableMap.of("role", entity.getCode()));
}
}
entity = service.saveInternal(entity);
event.setContent(entity);
// TODO: clone content - mutable previous event content :/
return new DefaultEventResult<>(event, this);
}
Aggregations