use of eu.bcvsolutions.idm.core.api.exception.InvalidFormException 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.exception.InvalidFormException 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;
}
use of eu.bcvsolutions.idm.core.api.exception.InvalidFormException in project CzechIdMng by bcvsolutions.
the class FormableValidateBasicFieldsProcessor method process.
@Override
public EventResult<FormableDto> process(EntityEvent<FormableDto> event) {
// saved dto
FormableDto savedDto = event.getContent();
//
IdmFormInstanceDto basicFields = formProjectionManager.getBasicFieldsInstance(savedDto);
if (basicFields != null) {
List<InvalidFormAttributeDto> errors = formService.validate(basicFields);
if (!errors.isEmpty()) {
throw new InvalidFormException(errors);
}
}
//
return new DefaultEventResult<>(event, this);
}
Aggregations