Search in sources :

Example 16 with IdmRoleFormAttributeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleFormAttributeService method export.

@Override
public void export(UUID id, IdmExportImportDto batch) {
    Assert.notNull(batch, "Batch cannot be null!");
    IdmRoleFormAttributeDto roleFormAttributeDto = this.get(id);
    if (roleFormAttributeDto != null) {
        IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
        Assert.notNull(formAttributeDto, "Form attribute DTO cannot be null!");
        // Export only form-definition - without attribute definitions
        formDefinitionService.exportOnlyDefinition(formAttributeDto.getFormDefinition(), batch);
        // Export form-attribute
        formAttributeService.export(roleFormAttributeDto.getFormAttribute(), batch);
    }
    // Export role-form-attribute
    super.export(id, batch);
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)

Example 17 with IdmRoleFormAttributeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto 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);
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) BigDecimal(java.math.BigDecimal) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) After(org.junit.After) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) UUID(java.util.UUID) InvalidFormException(eu.bcvsolutions.idm.core.api.exception.InvalidFormException) Serializable(java.io.Serializable) List(java.util.List) LocalDate(java.time.LocalDate) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRoleFormAttribute_(eu.bcvsolutions.idm.core.model.entity.IdmRoleFormAttribute_) IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Lists(com.google.common.collect.Lists) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) Sets(org.mockito.internal.util.collections.Sets) ImmutableList(com.google.common.collect.ImmutableList) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) Test(org.junit.Test) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 18 with IdmRoleFormAttributeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto 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());
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter)

Example 19 with IdmRoleFormAttributeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto in project CzechIdMng by bcvsolutions.

the class RoleFormAttributeSaveProcessor method process.

@Override
public EventResult<IdmRoleFormAttributeDto> process(EntityEvent<IdmRoleFormAttributeDto> event) {
    IdmRoleFormAttributeDto entity = event.getContent();
    entity = service.saveInternal(entity);
    event.setContent(entity);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 20 with IdmRoleFormAttributeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto in project CzechIdMng by bcvsolutions.

the class RoleFormAttributeDeleteProcessor method process.

@Override
public EventResult<IdmRoleFormAttributeDto> process(EntityEvent<IdmRoleFormAttributeDto> event) {
    IdmRoleFormAttributeDto entityEvent = event.getContent();
    // 
    service.deleteInternal(entityEvent);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Aggregations

IdmRoleFormAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto)29 IdmRoleFormAttributeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter)25 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)23 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)20 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)20 Test (org.junit.Test)20 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)19 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)17 IdmRoleFormAttributeService (eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService)17 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)17 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)17 List (java.util.List)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 Lists (com.google.common.collect.Lists)16 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)16 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)16 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)16 DtoUtils (eu.bcvsolutions.idm.core.api.utils.DtoUtils)16 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)16 Assert (org.junit.Assert)16