Search in sources :

Example 1 with FormDefinitionEvent

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

the class DefaultIdmFormDefinitionService method saveInternal.

/**
 * Fill default definition code and name, if no code / name is given.
 */
@Override
@Transactional
public IdmFormDefinitionDto saveInternal(IdmFormDefinitionDto dto) {
    if (StringUtils.isEmpty(dto.getCode())) {
        dto.setMain(true);
        dto.setCode(DEFAULT_DEFINITION_CODE);
    }
    if (StringUtils.isEmpty(dto.getName())) {
        dto.setName(dto.getCode());
    }
    if (dto.isMain()) {
        IdmFormDefinitionDto mainDefinition = findOneByMain(dto.getType());
        if (mainDefinition != null && !mainDefinition.getId().equals(dto.getId())) {
            mainDefinition.setMain(false);
            // 
            FormDefinitionEvent formDefinitionEvent = new FormDefinitionEvent(FormDefinitionEventType.UPDATE, mainDefinition);
            // We don't need validation - main definition is set in the same transaction bellow.
            formDefinitionEvent.getProperties().put(FormService.SKIP_EAV_VALIDATION, Boolean.TRUE);
            // 
            publish(formDefinitionEvent);
        }
    }
    // 
    return super.saveInternal(dto);
}
Also used : FormDefinitionEvent(eu.bcvsolutions.idm.core.eav.api.event.FormDefinitionEvent) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with FormDefinitionEvent

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

the class FormDefinitionDeleteBulkAction method processDto.

@Override
protected OperationResult processDto(IdmFormDefinitionDto formDefinition) {
    try {
        FormDefinitionEvent event = new FormDefinitionEvent(FormDefinitionEventType.DELETE, formDefinition, new ConfigurationMap(getProperties()).toMap());
        event.setPriority(PriorityType.HIGH);
        service.publish(event);
        // 
        return new OperationResult.Builder(OperationState.EXECUTED).build();
    } catch (ResultCodeException ex) {
        return new OperationResult.Builder(OperationState.EXCEPTION).setException(ex).build();
    } catch (Exception ex) {
        Throwable resolvedException = ExceptionUtils.resolveException(ex);
        if (resolvedException instanceof ResultCodeException) {
            return // 
            new OperationResult.Builder(OperationState.EXCEPTION).setException(// 
            (ResultCodeException) resolvedException).build();
        }
        return new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build();
    }
}
Also used : FormDefinitionEvent(eu.bcvsolutions.idm.core.eav.api.event.FormDefinitionEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Aggregations

FormDefinitionEvent (eu.bcvsolutions.idm.core.eav.api.event.FormDefinitionEvent)2 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)1 Transactional (org.springframework.transaction.annotation.Transactional)1