Search in sources :

Example 96 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class FormInstanceValidateProcessor method process.

@Override
public EventResult<IdmFormInstanceDto> process(EntityEvent<IdmFormInstanceDto> event) {
    IdmFormInstanceDto formInstance = event.getContent();
    Assert.notNull(formInstance.getFormDefinition(), "Form definition is required for form instance validation.");
    // 
    // resolve given / configured / overridden / default form definition
    // configured definition is loaded only once and applied twice (optimization)
    IdmFormDefinitionDto configuredFormDefinition = formProjectionManager.getConfiguredFormDefinition(getOwner(formInstance), formInstance.getFormDefinition());
    IdmFormDefinitionDto formDefinition = formProjectionManager.overrideFormDefinition(formService.getDefinition(formInstance.getFormDefinition().getId()), configuredFormDefinition);
    Assert.notNull(formDefinition, "Form definition is required for form instance validation.");
    IdmFormDefinitionDto formInstanceDefinition = formProjectionManager.overrideFormDefinition(formInstance.getFormDefinition(), configuredFormDefinition);
    Assert.notNull(formInstanceDefinition, "Form definition is required for form instance validation.");
    // 
    Map<String, Serializable> properties = event.getProperties();
    // 
    // get distinct attributes from the sent values
    // PATCH is used - only sent attributes are validated
    Set<IdmFormAttributeDto> sentAttributes = formInstance.getValues().stream().map(IdmFormValueDto::getFormAttribute).map(attributeId -> {
        IdmFormAttributeDto mappedAttribute = formInstanceDefinition.getMappedAttribute(attributeId);
        if (mappedAttribute != null) {
            return mappedAttribute;
        }
        return formDefinition.getMappedAttribute(attributeId);
    }).collect(Collectors.toSet());
    // only sent attributes in definition and instance
    formDefinition.setFormAttributes(Lists.newArrayList(sentAttributes));
    formInstance.setFormDefinition(formDefinition);
    // validate
    List<InvalidFormAttributeDto> errors = formService.validate(formInstance);
    // skip <required> validation if contract update is performed from time slice
    if (getBooleanProperty(ContractSliceManager.SKIP_CHECK_FOR_SLICES, properties)) {
        errors = errors.stream().filter(error -> {
            return !error.isMissingValue();
        }).collect(Collectors.toList());
    }
    if (!errors.isEmpty()) {
        throw new InvalidFormException(errors);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) FormProjectionManager(eu.bcvsolutions.idm.core.eav.api.service.FormProjectionManager) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) FormInstanceProcessor(eu.bcvsolutions.idm.core.eav.api.event.processor.FormInstanceProcessor) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) Map(java.util.Map) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Description(org.springframework.context.annotation.Description) Set(java.util.Set) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) InvalidFormException(eu.bcvsolutions.idm.core.api.exception.InvalidFormException) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) Component(org.springframework.stereotype.Component) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) ContractSliceManager(eu.bcvsolutions.idm.core.api.service.ContractSliceManager) Assert(org.springframework.util.Assert) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) InvalidFormException(eu.bcvsolutions.idm.core.api.exception.InvalidFormException) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)

Example 97 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class FormProjectionSaveProcessor method process.

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

Example 98 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class IdentityProjectionSaveProcessor method process.

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

Example 99 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class FormAttributeValidateProcessor method process.

@Override
public EventResult<IdmFormAttributeDto> process(EntityEvent<IdmFormAttributeDto> event) {
    IdmFormAttributeDto dto = event.getContent();
    IdmFormAttributeDto original = event.getOriginalSource();
    // just for sure - wrong event type can be provided manually
    if (original == null) {
        return new DefaultEventResult<>(event, this);
    }
    // 
    boolean persistentTypeChanged = original.getPersistentType() != dto.getPersistentType();
    boolean confidentialChanged = original.isConfidential() != dto.isConfidential();
    if (!persistentTypeChanged && !confidentialChanged) {
        return new DefaultEventResult<>(event, this);
    }
    // 
    // Change persistent type is possible, only if no form values for this attribute is persisted.
    IdmFormValueFilter<FormableEntity> filter = new IdmFormValueFilter<>();
    filter.setAttributeId(dto.getId());
    try {
        if (formService.findValues(filter, PageRequest.of(0, 1)).getTotalElements() > 0) {
            throwException(dto.getCode(), persistentTypeChanged, confidentialChanged, null);
        }
    } catch (ResultCodeException ex) {
        // some form definition cannot have owner specified - drop and create attribute is supported only
        throwException(dto.getCode(), persistentTypeChanged, confidentialChanged, ex);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity)

Example 100 with DefaultEventResult

use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.

the class FormDefinitionValidateProcessor method process.

@Override
public EventResult<IdmFormDefinitionDto> process(EntityEvent<IdmFormDefinitionDto> event) {
    IdmFormDefinitionDto dto = event.getContent();
    IdmFormDefinitionDto original = event.getOriginalSource();
    // 
    if (event.hasType(FormDefinitionEventType.DELETE) && dto.isMain()) {
        throw new ResultCodeException(CoreResultCode.FORM_DEFINITION_DELETE_FAILED_MAIN_FORM, ImmutableMap.of("code", dto.getCode()));
    }
    if (original != null && original.isMain() && !dto.isMain()) {
        throw new ResultCodeException(CoreResultCode.FORM_DEFINITION_UPDATE_FAILED_MAIN_FORM, ImmutableMap.of("code", dto.getCode()));
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Aggregations

DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)256 UUID (java.util.UUID)67 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)41 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)28 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)27 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)23 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)19 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)19 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)18 EventResult (eu.bcvsolutions.idm.core.api.event.EventResult)18 EntityEvent (eu.bcvsolutions.idm.core.api.event.EntityEvent)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)16 Description (org.springframework.context.annotation.Description)16 Component (org.springframework.stereotype.Component)16 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)15 List (java.util.List)15 CoreEventProcessor (eu.bcvsolutions.idm.core.api.event.CoreEventProcessor)14 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)13 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)12