Search in sources :

Example 1 with IdmRequestAttributeValueDto

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

the class DefaultRequestManager method getChanges.

@Override
public List<IdmRequestItemAttributeDto> getChanges(AbstractDto currentDto, AbstractDto changedDto, RequestOperationType itemOperation) {
    List<IdmRequestItemAttributeDto> resultAttributes = new ArrayList<>();
    Map<String, Object> currentFieldsValues = this.dtoToMap(currentDto);
    Map<String, Object> changedFieldsValues = this.dtoToMap(changedDto);
    // First add all new attributes
    changedFieldsValues.keySet().stream().forEach(changedAttribute -> {
        if (!currentFieldsValues.containsKey(changedAttribute)) {
            Object value = changedFieldsValues.get(changedAttribute);
            IdmRequestItemAttributeDto attribute = new IdmRequestItemAttributeDto(changedAttribute, value instanceof List, true);
            if (attribute.isMultivalue()) {
                if (value instanceof List) {
                    ((List<?>) value).forEach(v -> {
                        attribute.getValues().add(new IdmRequestAttributeValueDto(v, null, RequestOperationType.ADD));
                    });
                }
            } else {
                attribute.setValue(new IdmRequestAttributeValueDto(value, null, RequestOperationType.ADD));
            }
            resultAttributes.add(attribute);
        }
    });
    // Second add all already exists attributes
    currentFieldsValues.keySet().forEach(currentAttribute -> {
        Object changedValue = changedFieldsValues.get(currentAttribute);
        IdmRequestItemAttributeDto attribute;
        Object currentValue = currentFieldsValues.get(currentAttribute);
        attribute = new IdmRequestItemAttributeDto(currentAttribute, changedValue instanceof List, false);
        if (attribute.isMultivalue()) {
            if (changedValue instanceof List) {
                ((List<?>) changedValue).forEach(value -> {
                    if (currentValue instanceof List && ((List<?>) currentValue).contains(value)) {
                        attribute.getValues().add(new IdmRequestAttributeValueDto(value, value, null));
                    } else {
                        attribute.setChanged(true);
                        attribute.getValues().add(new IdmRequestAttributeValueDto(value, null, RequestOperationType.ADD));
                    }
                });
            }
            if (currentValue instanceof List) {
                ((List<?>) currentValue).forEach(value -> {
                    if (changedValue == null || !((List<?>) changedValue).contains(value)) {
                        attribute.setChanged(true);
                        attribute.getValues().add(new IdmRequestAttributeValueDto(value, value, RequestOperationType.REMOVE));
                    }
                });
            }
        } else {
            if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentValue)) || (currentValue != null && currentValue.equals(changedValue))) {
                attribute.setChanged(RequestOperationType.UPDATE == itemOperation ? false : true);
                attribute.setValue(new IdmRequestAttributeValueDto(changedValue, currentValue, RequestOperationType.UPDATE == itemOperation ? null : itemOperation));
            } else {
                attribute.setChanged(true);
                attribute.setValue(new IdmRequestAttributeValueDto(changedValue, currentValue, itemOperation));
            }
        }
        resultAttributes.add(attribute);
    });
    // Make all values nicer
    // 
    resultAttributes.stream().filter(// 
    attribute -> attribute.getValue() != null).forEach(attribute -> {
        // 
        attribute.getValue().setValue(this.makeNiceValue(attribute.getValue().getValue()));
        attribute.getValue().setOldValue(this.makeNiceValue(attribute.getValue().getOldValue()));
        List<IdmRequestAttributeValueDto> attributeValues = attribute.getValues();
        attributeValues.forEach(attributeValue -> {
            attributeValue.setValue(this.makeNiceValue(attributeValue.getValue()));
            attributeValue.setOldValue(this.makeNiceValue(attributeValue.getOldValue()));
        });
    });
    return resultAttributes;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) 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) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) Map(java.util.Map) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) PropertyDescriptor(java.beans.PropertyDescriptor) Builder(eu.bcvsolutions.idm.core.api.dto.OperationResultDto.Builder) Lazy(org.springframework.context.annotation.Lazy) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) Field(java.lang.reflect.Field) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) RequestEventType(eu.bcvsolutions.idm.core.model.event.RequestEvent.RequestEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) RequestEvent(eu.bcvsolutions.idm.core.model.event.RequestEvent) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Pageable(org.springframework.data.domain.Pageable) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Modifier(java.lang.reflect.Modifier) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) PageImpl(org.springframework.data.domain.PageImpl) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) IdmRequestItem(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem) HashMap(java.util.HashMap) MessageFormat(java.text.MessageFormat) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) RequestFilterPredicate(eu.bcvsolutions.idm.core.api.domain.RequestFilterPredicate) ImmutableList(com.google.common.collect.ImmutableList) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) Niceable(eu.bcvsolutions.idm.core.api.domain.Niceable) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) IdmRequestAttributeValueDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestAttributeValueDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) MethodDescriptor(java.beans.MethodDescriptor) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) Comparator(java.util.Comparator) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) IdmRequestAttributeValueDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestAttributeValueDto)

Aggregations

JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Codeable (eu.bcvsolutions.idm.core.api.domain.Codeable)1 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)1 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)1 Niceable (eu.bcvsolutions.idm.core.api.domain.Niceable)1 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)1 RequestFilterPredicate (eu.bcvsolutions.idm.core.api.domain.RequestFilterPredicate)1 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)1 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)1 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)1 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)1 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)1