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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations