Search in sources :

Example 6 with InvalidFormAttributeDto

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

the class DefaultFormServiceIntegrationTest method testRequiredValidation.

@Test
public void testRequiredValidation() {
    // prepare form definition a test saving form values
    IdmFormAttributeDto attribute = new IdmFormAttributeDto();
    String attributeName = getHelper().createName();
    attribute.setCode(attributeName);
    attribute.setName(attributeName);
    attribute.setPersistentType(PersistentType.SHORTTEXT);
    attribute.setRequired(true);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attribute));
    attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
    // 
    IdmFormValueDto valueOne = new IdmFormValueDto(attribute);
    IdmFormValueDto valueTwo = new IdmFormValueDto(attribute);
    valueTwo.setShortTextValue("value");
    // 
    IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
    formInstance.setFormDefinition(formDefinitionOne);
    formInstance.setValues(Lists.newArrayList(valueOne));
    // 
    List<InvalidFormAttributeDto> validationErrors = formService.validate(formInstance);
    // 
    Assert.assertEquals(1, validationErrors.size());
    Assert.assertTrue(validationErrors.stream().anyMatch(error -> error.isMissingValue()));
    Assert.assertTrue(validationErrors.stream().anyMatch(error -> error.getAttributeCode().equals(attributeName)));
    // 
    valueOne.setShortTextValue("value");
    validationErrors = formService.validate(formInstance);
    // 
    Assert.assertTrue(validationErrors.isEmpty());
    formService.validate(formInstance);
    // 
    Assert.assertTrue(validationErrors.isEmpty());
    // 
    formInstance.setValues(Lists.newArrayList());
    // 
    validationErrors = formService.validate(formInstance);
    // 
    Assert.assertEquals(1, validationErrors.size());
    Assert.assertTrue(validationErrors.stream().anyMatch(error -> error.isMissingValue()));
    Assert.assertTrue(validationErrors.stream().anyMatch(error -> error.getAttributeCode().equals(attributeName)));
    // 
    formInstance.setValues(Lists.newArrayList(new IdmFormValueDto(attribute)));
    // 
    validationErrors = formService.validate(formInstance);
    // 
    Assert.assertEquals(1, validationErrors.size());
    Assert.assertTrue(validationErrors.stream().anyMatch(error -> error.isMissingValue()));
    Assert.assertTrue(validationErrors.stream().anyMatch(error -> error.getAttributeCode().equals(attributeName)));
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormDefinitionCache(eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache) IdmRoleFormValue_(eu.bcvsolutions.idm.core.model.entity.eav.IdmRoleFormValue_) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) BigDecimal(java.math.BigDecimal) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) Predicate(javax.persistence.criteria.Predicate) IdmFormDefinition(eu.bcvsolutions.idm.core.eav.entity.IdmFormDefinition) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) ChangePersistentTypeException(eu.bcvsolutions.idm.core.eav.api.exception.ChangePersistentTypeException) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) IdentityEventType(eu.bcvsolutions.idm.core.model.event.IdentityEvent.IdentityEventType) Sort(org.springframework.data.domain.Sort) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) IdmRoleRepository(eu.bcvsolutions.idm.core.model.repository.IdmRoleRepository) Page(org.springframework.data.domain.Page) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) ChangeConfidentialException(eu.bcvsolutions.idm.core.eav.api.exception.ChangeConfidentialException) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) IdmFormAttribute(eu.bcvsolutions.idm.core.eav.entity.IdmFormAttribute) Specification(org.springframework.data.jpa.domain.Specification) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) IdmFormAttribute_(eu.bcvsolutions.idm.core.eav.entity.IdmFormAttribute_) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) AbstractFormValueEvaluator(eu.bcvsolutions.idm.core.security.evaluator.eav.AbstractFormValueEvaluator) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) DefaultFormableFilter(eu.bcvsolutions.idm.core.api.dto.filter.DefaultFormableFilter) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Direction(org.springframework.data.domain.Sort.Direction) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Root(javax.persistence.criteria.Root) Before(org.junit.Before) IdentityFormValueEvaluator(eu.bcvsolutions.idm.core.security.evaluator.eav.IdentityFormValueEvaluator) Assert.assertNotNull(org.junit.Assert.assertNotNull) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) IdmRoleFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmRoleFormValue) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) InitDemoDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitDemoDataProcessor) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) IdmEntityEventService(eu.bcvsolutions.idm.core.api.service.IdmEntityEventService) Assert.assertNull(org.junit.Assert.assertNull) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) IdmFormDefinitionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormDefinitionService) IdmEntityEvent_(eu.bcvsolutions.idm.core.model.entity.IdmEntityEvent_) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) AbstractFormableService(eu.bcvsolutions.idm.core.eav.api.service.AbstractFormableService) Subquery(javax.persistence.criteria.Subquery) Assert(org.junit.Assert) FormAttributeValidateProcessor(eu.bcvsolutions.idm.core.eav.processor.FormAttributeValidateProcessor) Assert.assertEquals(org.junit.Assert.assertEquals) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 7 with InvalidFormAttributeDto

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

the class DefaultIdmConceptRoleRequestService method saveInternal.

@Override
@Transactional
public IdmConceptRoleRequestDto saveInternal(IdmConceptRoleRequestDto dto) {
    IdmConceptRoleRequestDto savedDto = super.saveInternal(dto);
    if (dto != null && dto.getRole() != null) {
        // TODO: concept role request hasn't events, after implement events for the dto, please remove this.
        boolean isNew = false;
        if (isNew(dto)) {
            isNew = true;
            dto = valueGeneratorManager.generate(dto);
        }
        IdmRoleDto roleDto = roleService.get(dto.getRole());
        if (roleDto == null) {
            throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", dto.getRole()));
        }
        List<InvalidFormAttributeDto> validationErrors = validateFormAttributes(dto);
        if (validationErrors != null && !validationErrors.isEmpty()) {
            throw new InvalidFormException(validationErrors);
        }
        List<IdmFormValueDto> attributeValues = dto.getEavs().size() == 1 && dto.getEavs().get(0) != null ? dto.getEavs().get(0).getValues() : null;
        // If concept is new, then we have to clear id of EAV values (new one have to be generated for this case).
        if (isNew && attributeValues != null) {
            attributeValues.forEach(value -> {
                DtoUtils.clearAuditFields(value);
                value.setId(null);
            });
        }
        // Load sub definition by role
        IdmFormDefinitionDto formDefinitionDto = roleService.getFormAttributeSubdefinition(roleDto);
        if (formDefinitionDto != null) {
            // Save form values for sub-definition. Validation is skipped. Was made before in this method, because now can be id of values null.
            List<IdmFormValueDto> savedValues = formService.saveFormInstance(savedDto, formDefinitionDto, attributeValues, false).getValues();
            IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
            formInstance.setValues(savedValues);
            savedDto.getEavs().clear();
            savedDto.getEavs().add(formInstance);
        }
    }
    return savedDto;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) InvalidFormException(eu.bcvsolutions.idm.core.api.exception.InvalidFormException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with InvalidFormAttributeDto

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

the class DefaultIdmRoleRequestService method validate.

@Override
public void validate(IdmRoleRequestDto request) {
    Assert.notNull(request, "Request is required.");
    List<IdmConceptRoleRequestDto> conceptRoles = request.getConceptRoles();
    conceptRoles.forEach(concept -> {
        List<InvalidFormAttributeDto> validationResults = conceptRoleRequestService.validateFormAttributes(concept);
        if (validationResults != null && !validationResults.isEmpty()) {
            IdmRoleDto role = null;
            if (concept.getRole() != null) {
                role = DtoUtils.getEmbedded(concept, IdmConceptRoleRequest_.role, IdmRoleDto.class, null);
                if (role == null) {
                    role = roleService.get(concept.getRole());
                }
            } else {
                IdmIdentityRoleDto identityRole = DtoUtils.getEmbedded(concept, IdmConceptRoleRequest_.identityRole, IdmIdentityRoleDto.class, null);
                if (identityRole == null) {
                    identityRole = identityRoleThinService.get(concept.getIdentityRole());
                }
                if (identityRole != null) {
                    role = DtoUtils.getEmbedded(concept, IdmIdentityRole_.role, IdmRoleDto.class);
                }
            }
            throw new ResultCodeException(CoreResultCode.ROLE_REQUEST_UNVALID_CONCEPT_ATTRIBUTE, // 
            ImmutableMap.of(// 
            "concept", // 
            concept.getId(), "roleCode", role != null ? role.getCode() : "", // 
            "request", // 
            concept.getRoleRequest(), // 
            "attributeCode", // 
            validationResults.get(0).getAttributeCode()));
        // 
        }
    });
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 9 with InvalidFormAttributeDto

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

the class DefaultFormService method validate.

@Override
public List<InvalidFormAttributeDto> validate(IdmFormInstanceDto formInstance, boolean validateOnlySameOwnerType) {
    Assert.notNull(formInstance, "Form instance cannot be null!");
    IdmFormDefinitionDto formDefinition = formInstance.getFormDefinition();
    Assert.notNull(formDefinition, "Form definition cannot be null!");
    // 
    List<InvalidFormAttributeDto> results = Lists.newArrayList();
    formDefinition.getFormAttributes().stream().forEach(formAttribute -> {
        List<IdmFormValueDto> formValueForAttributes = formInstance.getValues().stream().filter(formValue -> formAttribute.getId().equals(formValue.getFormAttribute())).peek(formValue -> {
            // we don't trust value persistent type - set current from attribute
            formValue.setPersistentType(formAttribute.getPersistentType());
            // we need owner type to perform validations
            if (formValue.getOwnerType() == null && formInstance.getOwnerType() != null) {
                formValue.setOwnerType(formDefinitionService.getFormableOwnerType(formInstance.getOwnerType()));
            }
        }).collect(// 
        Collectors.toList());
        InvalidFormAttributeDto result = this.validateAttribute(formDefinition, formAttribute, formValueForAttributes, validateOnlySameOwnerType);
        if (!result.isValid()) {
            // Invalid attributes for owner => more owners can be saved together (e.g. from projection).
            // ~ identifiable
            result.setOwnerId(formInstance.getOwnerId());
            Class<? extends Identifiable> ownerType = formInstance.getOwnerType();
            if (ownerType != null) {
                result.setOwnerType(lookupService.getOwnerType(ownerType));
            }
            results.add(result);
        }
    });
    return results;
}
Also used : AbstractFormValue_(eu.bcvsolutions.idm.core.eav.entity.AbstractFormValue_) Order(org.springframework.data.domain.Sort.Order) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) PluginRegistry(org.springframework.plugin.core.PluginRegistry) FormProjectionManager(eu.bcvsolutions.idm.core.eav.api.service.FormProjectionManager) Autowired(org.springframework.beans.factory.annotation.Autowired) FormDefinitionCache(eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Matcher(java.util.regex.Matcher) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) FormableFilter(eu.bcvsolutions.idm.core.api.dto.filter.FormableFilter) Method(java.lang.reflect.Method) ImmutableMap(com.google.common.collect.ImmutableMap) ConfigurationClassProperty(eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) PermissionUtils(eu.bcvsolutions.idm.core.security.api.utils.PermissionUtils) PropertyDescriptor(java.beans.PropertyDescriptor) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) Lazy(org.springframework.context.annotation.Lazy) Pattern(java.util.regex.Pattern) PageImpl(org.springframework.data.domain.PageImpl) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) IdmFormAttribute_(eu.bcvsolutions.idm.core.eav.entity.IdmFormAttribute_) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) FormAttributeRendererDto(eu.bcvsolutions.idm.core.eav.api.dto.FormAttributeRendererDto) OrderAwarePluginRegistry(org.springframework.plugin.core.OrderAwarePluginRegistry) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) HashMap(java.util.HashMap) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) Introspector(java.beans.Introspector) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) CollectionUtils(org.apache.commons.collections.CollectionUtils) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) ConfigurationClass(eu.bcvsolutions.idm.core.api.domain.ConfigurationClass) IdmFormDefinition_(eu.bcvsolutions.idm.core.eav.entity.IdmFormDefinition_) FormAttributeRenderer(eu.bcvsolutions.idm.core.eav.api.service.FormAttributeRenderer) IdmFormDefinitionFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) ObjectUtils(org.springframework.util.ObjectUtils) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) EnabledEvaluator(eu.bcvsolutions.idm.core.security.api.service.EnabledEvaluator) ApplicationContext(org.springframework.context.ApplicationContext) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ExportDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) IdmFormDefinitionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormDefinitionService) IdmForm(eu.bcvsolutions.idm.core.eav.entity.IdmForm) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Comparator(java.util.Comparator) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)

Example 10 with InvalidFormAttributeDto

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

the class DefaultIdmConceptRoleRequestService method validateFormAttributes.

@Override
public List<InvalidFormAttributeDto> validateFormAttributes(IdmConceptRoleRequestDto concept) {
    if (concept == null || ConceptRoleRequestOperation.REMOVE == concept.getOperation() || concept.getState() == null || concept.getState().isTerminatedState()) {
        return null;
    }
    IdmFormInstanceDto formInstanceDto = this.getRoleAttributeValues(concept, false);
    if (formInstanceDto != null) {
        UUID identityRoleId = null;
        IdmIdentityRoleDto identityRoleDto = DtoUtils.getEmbedded(concept, IdmConceptRoleRequest_.identityRole, IdmIdentityRoleDto.class, null);
        if (identityRoleDto == null) {
            identityRoleId = concept.getIdentityRole();
        } else {
            identityRoleId = identityRoleDto.getId();
        }
        if (identityRoleId != null && ConceptRoleRequestOperation.UPDATE == concept.getOperation()) {
            // Cache for save original ID of concepts.
            // Id will be replaced by identity-role id and have to be returned after
            // validation back, because formInstance is not immutable.
            Map<UUID, UUID> identityRoleConceptValueMap = new HashMap<>();
            // Find identity role value for concept value and change ID of value (because validation have to be made via identityRole).
            UUID finalIdentityRoleId = identityRoleId;
            formInstanceDto.getValues().forEach(value -> {
                IdmFormAttributeDto formAttributeDto = new IdmFormAttributeDto();
                formAttributeDto.setId(value.getFormAttribute());
                formAttributeDto.setFormDefinition(formInstanceDto.getFormDefinition().getId());
                IdmFormValueDto identityRoleValueDto = formService.getValues(new IdmIdentityRoleDto(finalIdentityRoleId), formAttributeDto).stream().filter(identityRoleValue -> identityRoleValue.getSeq() == value.getSeq()).findFirst().orElse(null);
                // Replace concept IDs by identity-role IDs.
                if (identityRoleValueDto != null) {
                    identityRoleConceptValueMap.put(identityRoleValueDto.getId(), value.getId());
                    value.setId(identityRoleValueDto.getId());
                }
            });
            List<InvalidFormAttributeDto> validationErrors = formService.validate(formInstanceDto, false);
            // Set IDs of concept back to values (formInstance is not immutable).
            formInstanceDto.getValues().forEach(value -> {
                if (identityRoleConceptValueMap.containsKey(value.getId())) {
                    value.setId(identityRoleConceptValueMap.get(value.getId()));
                }
            });
            return validationErrors;
        }
        return formService.validate(formInstanceDto, false);
    }
    return null;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) HashMap(java.util.HashMap) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Aggregations

InvalidFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto)13 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)12 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)11 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)10 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)10 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)10 Lists (com.google.common.collect.Lists)9 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)9 FormableDto (eu.bcvsolutions.idm.core.api.dto.FormableDto)9 CoreEventType (eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType)9 LookupService (eu.bcvsolutions.idm.core.api.service.LookupService)9 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)9 Serializable (java.io.Serializable)9 List (java.util.List)9 Map (java.util.Map)9 UUID (java.util.UUID)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Transactional (org.springframework.transaction.annotation.Transactional)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)8 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)8