Search in sources :

Example 1 with IdmFormValueFilter

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

the class FormAttributeDeleteProcessor method process.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public EventResult<IdmFormAttributeDto> process(EntityEvent<IdmFormAttributeDto> event) {
    IdmFormAttributeDto formAttribute = event.getContent();
    UUID formAttributeId = formAttribute.getId();
    Assert.notNull(formAttributeId, "Form attribute id is required.");
    // 
    boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
    if (forceDelete) {
        IdmFormValueFilter filter = new IdmFormValueFilter();
        filter.setAttributeId(formAttributeId);
        formValueServices.getPlugins().forEach(formValueService -> {
            formValueService.find(filter, null).getContent().forEach(formValue -> {
                formValueService.delete((IdmFormValueDto) formValue);
                // 
                clearSession();
            });
        });
    }
    // 
    service.deleteInternal(formAttribute);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) UUID(java.util.UUID)

Example 2 with IdmFormValueFilter

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

the class FormValueDeleteBulkActionIntegrationTest method processBulkActionByFilter.

@Test
public void processBulkActionByFilter() {
    Identifiable owner = getHelper().createIdentity((GuardedString) null);
    // 
    // create definition with attribute
    IdmFormAttributeDto attribute = new IdmFormAttributeDto();
    String attributeName = getHelper().createName();
    attribute.setCode(attributeName);
    attribute.setName(attribute.getCode());
    attribute.setMultiple(true);
    attribute.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attribute));
    attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
    // 
    // fill values
    formService.saveValues(owner, attribute, Lists.newArrayList(FORM_VALUE_ONE, FORM_VALUE_TWO));
    Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
    // 
    // check value and persistent type
    Assert.assertEquals(2, m.get(attributeName).size());
    Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_ONE)));
    Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_TWO)));
    // 
    IdmBulkActionDto bulkAction = findBulkAction(IdmFormValue.class, FormValueDeleteBulkAction.NAME);
    IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
    filter.setDefinitionId(formDefinitionOne.getId());
    filter.setShortTextValue(FORM_VALUE_ONE);
    filter.setAttributeId(attribute.getId());
    bulkAction.setTransformedFilter(filter);
    bulkAction.setFilter(toMap(filter));
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, 1l, null, null);
    m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
    // 
    Assert.assertEquals(1, m.get(attributeName).size());
    Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_TWO)));
}
Also used : ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ObserveLongRunningTaskEndProcessor(eu.bcvsolutions.idm.core.scheduler.ObserveLongRunningTaskEndProcessor) IdmFormValue(eu.bcvsolutions.idm.core.eav.entity.IdmFormValue) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) Map(java.util.Map) After(org.junit.After) Before(org.junit.Before) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 3 with IdmFormValueFilter

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

the class DefaultFormService method validateAttribute.

private InvalidFormAttributeDto validateAttribute(IdmFormDefinitionDto formDefinition, IdmFormAttributeDto formAttribute, List<IdmFormValueDto> formValues, boolean validateOnlySameOwnerType) {
    Assert.notNull(formAttribute, "Form attribute is required.");
    // 
    InvalidFormAttributeDto result = new InvalidFormAttributeDto(formAttribute);
    result.setDefinitionCode(formDefinition.getCode());
    // 
    if (formAttribute.isRequired()) {
        if (CollectionUtils.isEmpty(formValues) || !formValues.stream().filter(formValue -> !formValue.isEmpty()).findFirst().isPresent()) {
            LOG.debug("Form attribute [{}] validation failed - value is required.", formAttribute.getCode());
            // 
            result.setMissingValue(true);
        }
    }
    if (CollectionUtils.isEmpty(formValues)) {
        // values are not filled => other validations is not needed.
        return result;
    }
    // TODO: redesign to registrable validators
    // TODO: multiple values -> the last validation error is returned. Return invalid attribute for the all values ...
    formValues.stream().filter(formValue -> !formValue.isEmpty()).forEach(formValue -> {
        // minimum value validation
        if (formAttribute.getMin() != null) {
            if (formAttribute.getPersistentType() == PersistentType.SHORTTEXT) {
                String value = formValue.getShortTextValue();
                if (value.length() < formAttribute.getMin().intValue()) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is shorter than min [{}].", formAttribute.getCode(), value.length(), formAttribute.getMin());
                    // 
                    result.setMinValue(formAttribute.getMin());
                }
            } else if (formAttribute.getPersistentType() == PersistentType.TEXT) {
                String value = formValue.getStringValue();
                if (value.length() < formAttribute.getMin().intValue()) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is shorter than min [{}].", formAttribute.getCode(), value.length(), formAttribute.getMin());
                    // 
                    result.setMinValue(formAttribute.getMin());
                }
            } else if (formAttribute.getPersistentType() == PersistentType.DATE) {
                LocalDate value = formValue.getDateValue().toLocalDate();
                if (value.isBefore(LocalDate.now().plusDays(formAttribute.getMin().longValue()))) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is before than [{}] days.", formAttribute.getCode(), value, formAttribute.getMin());
                    // 
                    result.setMinValue(formAttribute.getMin());
                }
            } else if (formAttribute.getPersistentType() == PersistentType.DATETIME) {
                ZonedDateTime value = formValue.getDateValue();
                if (value.isBefore(ZonedDateTime.now().plusDays(formAttribute.getMin().longValue()))) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is before than [{}] days.", formAttribute.getCode(), value, formAttribute.getMin());
                    // 
                    result.setMinValue(formAttribute.getMin());
                }
            } else {
                if (formValue.getLongValue() != null && formAttribute.getMin().compareTo(BigDecimal.valueOf(formValue.getLongValue())) > 0) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is lesser than min [{}].", formAttribute.getCode(), formValue.getLongValue(), formAttribute.getMin());
                    // 
                    result.setMinValue(formAttribute.getMin());
                }
                if (formValue.getDoubleValue() != null && formAttribute.getMin().compareTo(formValue.getDoubleValue()) > 0) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is lesser than min [{}].", formAttribute.getCode(), formValue.getDoubleValue(), formAttribute.getMin());
                    // 
                    result.setMinValue(formAttribute.getMin());
                }
            }
        }
        // maximum value validation
        if (formAttribute.getMax() != null) {
            if (formAttribute.getPersistentType() == PersistentType.SHORTTEXT) {
                String value = formValue.getShortTextValue();
                if (value.length() > formAttribute.getMax().intValue()) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is shorter than min [{}].", formAttribute.getCode(), value.length(), formAttribute.getMax());
                    // 
                    result.setMaxValue(formAttribute.getMax());
                }
            } else if (formAttribute.getPersistentType() == PersistentType.TEXT) {
                String value = formValue.getStringValue();
                if (value.length() > formAttribute.getMax().intValue()) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is greater than min [{}].", formAttribute.getCode(), value.length(), formAttribute.getMax());
                    // 
                    result.setMaxValue(formAttribute.getMax());
                }
            } else if (formAttribute.getPersistentType() == PersistentType.DATE) {
                LocalDate value = formValue.getDateValue().toLocalDate();
                if (value.isAfter(LocalDate.now().plusDays(formAttribute.getMax().longValue()))) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is after than [{}] days.", formAttribute.getCode(), value, formAttribute.getMax());
                    // 
                    result.setMaxValue(formAttribute.getMax());
                }
            } else if (formAttribute.getPersistentType() == PersistentType.DATETIME) {
                ZonedDateTime value = formValue.getDateValue();
                if (value.isAfter(ZonedDateTime.now().plusDays(formAttribute.getMax().longValue()))) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is after than [{}] days.", formAttribute.getCode(), value, formAttribute.getMax());
                    // 
                    result.setMaxValue(formAttribute.getMax());
                }
            } else {
                if (formValue.getLongValue() != null && formAttribute.getMax().compareTo(BigDecimal.valueOf(formValue.getLongValue())) < 0) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is greater than max [{}].", formAttribute.getCode(), formValue.getLongValue(), formAttribute.getMax());
                    // 
                    result.setMaxValue(formAttribute.getMax());
                }
                if (formValue.getDoubleValue() != null && formAttribute.getMax().compareTo(formValue.getDoubleValue()) < 0) {
                    LOG.debug("Form attribute [{}] validation failed - given value [{}] is greater than max [{}].", formAttribute.getCode(), formValue.getDoubleValue(), formAttribute.getMax());
                    // 
                    result.setMaxValue(formAttribute.getMax());
                }
            }
        }
        String regex = formAttribute.getRegex();
        if (StringUtils.isNotEmpty(regex)) {
            Pattern p = Pattern.compile(regex);
            String stringValue = formValue.getValue().toString();
            // all persistent types are supported on BE, but string values makes the good sense.
            Matcher m = p.matcher(stringValue);
            if (!m.matches()) {
                LOG.debug("Form attribute [{}] validation failed - given value [{}] does not match regex [{}].", formAttribute.getCode(), stringValue, regex);
                // 
                result.setRegexValue(regex);
            }
        }
        if (formAttribute.isUnique()) {
            IdmFormValueFilter<FormableEntity> valueFilter = new IdmFormValueFilter<>();
            valueFilter.setAttributeId(formValue.getFormAttribute());
            valueFilter.setPersistentType(formValue.getPersistentType());
            valueFilter.setStringValue(formValue.getStringValue());
            valueFilter.setShortTextValue(formValue.getShortTextValue());
            valueFilter.setBooleanValue(formValue.getBooleanValue());
            valueFilter.setLongValue(formValue.getLongValue());
            valueFilter.setDoubleValue(formValue.getDoubleValue());
            valueFilter.setDateValue(formValue.getDateValue());
            valueFilter.setUuidValue(formValue.getUuidValue());
            // 
            Identifiable owner = getEmptyOwner(formDefinition);
            Assert.notNull(owner, "Filter - attribute owner is required. Is possible to filter form values by given owner only");
            // 
            FormValueService<FormableEntity> formValueService = getFormValueService(owner.getClass());
            // 
            List<IdmFormValueDto> existValues = formValueService.find(valueFilter, PageRequest.of(0, 2)).getContent();
            // 
            if (existValues.stream().filter(v -> {
                if (validateOnlySameOwnerType) {
                    return v.getOwnerType().equals(formValue.getOwnerType());
                }
                return true;
            }).anyMatch(v -> formValue.getId() == null || !formValue.getId().equals(v.getId()))) {
                LOG.debug("Form attribute [{}] validation failed - given value [{}] is not unigue.", formAttribute.getCode(), formValue.getValue());
                // 
                result.setUniqueValue(formValue.getValue().toString());
            }
        }
    });
    // 
    return result;
}
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) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) LocalDate(java.time.LocalDate) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) ZonedDateTime(java.time.ZonedDateTime) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter)

Example 4 with IdmFormValueFilter

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

the class DefaultFormService method toValueFilter.

/**
 * Construct value filter for find form values.
 *
 * @param ownerEntity owner
 * @param formDefinition form definition
 * @param filter only some attributes can be found only
 * @return
 * @since 10.3.0
 */
protected IdmFormValueFilter<FormableEntity> toValueFilter(FormableEntity ownerEntity, IdmFormDefinitionDto formDefinition, FormableFilter filter) {
    IdmFormValueFilter<FormableEntity> valueFilter = new IdmFormValueFilter<>();
    valueFilter.setOwner(ownerEntity);
    valueFilter.setDefinitionId(formDefinition.getId());
    valueFilter.setAddSecredProxyString(true);
    if (filter == null) {
        // filter is not given => all attributes
        return valueFilter;
    }
    // 
    // apply formable filter with given parameters
    List<FormDefinitionAttributes> formDefinitionAttributes = filter.getFormDefinitionAttributes();
    if (CollectionUtils.isEmpty(formDefinitionAttributes)) {
        // filter is given, but empty  => all attributes
        return valueFilter;
    }
    // 
    UUID formDefinitionId = formDefinition.getId();
    FormDefinitionAttributes attributes = formDefinitionAttributes.stream().filter(a -> formDefinitionId.equals(a.getDefinition())).findFirst().orElse(null);
    if (attributes == null) {
        // filter is given, but without processed definition  => all attributes
        return valueFilter;
    }
    // 
    List<UUID> attributeIds = attributes.getAttributes();
    if (CollectionUtils.isEmpty(attributeIds)) {
        // filter for processed definition is given, but without attributes  => all attributes
        return valueFilter;
    }
    // set attributes by filter
    valueFilter.setAttributeIds(attributes.getAttributes());
    // 
    return valueFilter;
}
Also used : IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) UUID(java.util.UUID) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes)

Example 5 with IdmFormValueFilter

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

the class AbstractFormValueService method saveInternal.

/**
 * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the
 * entity instance completely.
 *
 * @param entity
 * @return the saved entity
 */
@Override
@Transactional
public IdmFormValueDto saveInternal(IdmFormValueDto dto) {
    Assert.notNull(dto, "DTO is required to be saved.");
    Serializable formValue = dto.getValue();
    // 
    E persistedEntity = null;
    if (dto.getId() != null) {
        persistedEntity = this.getEntity(dto.getId());
    }
    // check, if value has to be persisted in confidential storage
    if (dto.isConfidential()) {
        dto.clearValues();
        if (formValue != null) {
            String previousFormValue;
            if (dto.getId() != null) {
                previousFormValue = confidentialStorage.get(dto.getId(), getEntityClass(), getConfidentialStorageKey(dto.getFormAttribute()), String.class);
            } else {
                previousFormValue = null;
            }
            if (Objects.equals(formValue, previousFormValue) && persistedEntity != null) {
                dto.setStringValue(persistedEntity.getStringValue());
                dto.setShortTextValue(persistedEntity.getShortTextValue());
            } else {
                String proxyValue = String.format("%s-%s", CONFIDENTIAL_STORAGE_VALUE_PREFIX, UUID.randomUUID());
                // we need only to know, if value was filled and when (~ for audit)
                dto.setStringValue(proxyValue);
                dto.setShortTextValue(proxyValue);
            }
        }
    }
    // persist entity
    E entity = getRepository().save(toEntity(dto, persistedEntity));
    // save values to confidential storage
    if (entity.isConfidential()) {
        confidentialStorage.save(entity.getId(), entity.getClass(), getConfidentialStorageKey(entity.getFormAttribute().getId()), formValue);
        LOG.debug("FormValue [{}] is persisted in confidential storage", entity.getId());
    }
    // return actual dto with proxy string
    IdmFormValueFilter<O> context = new IdmFormValueFilter<>();
    context.setAddSecredProxyString(true);
    return toDto(entity, null, context);
}
Also used : Serializable(java.io.Serializable) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmFormValueFilter (eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter)23 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)20 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)18 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)18 UUID (java.util.UUID)17 Test (org.junit.Test)16 Lists (com.google.common.collect.Lists)15 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)15 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)15 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)15 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 List (java.util.List)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)14 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)14 BigDecimal (java.math.BigDecimal)14 ZonedDateTime (java.time.ZonedDateTime)14 Assert (org.junit.Assert)14 TransactionContextHolder (eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder)13 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)13