Search in sources :

Example 6 with FormableDto

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

the class AbstractSynchronizationExecutor method doCreateEntity.

/**
 * Create and persist new entity by data from IC attributes
 *
 * @param entityType
 * @param mappedAttributes
 * @param logItem
 * @param uid
 * @param icAttributes
 * @param account
 * @param context
 */
protected void doCreateEntity(SystemEntityType entityType, List<SysSystemAttributeMappingDto> mappedAttributes, SysSyncItemLogDto logItem, String uid, List<IcAttribute> icAttributes, AccAccountDto account, SynchronizationContext context) {
    // We will create new entity
    addToItemLog(logItem, "Missing entity action is CREATE_ENTITY, we will create new entity.");
    DTO entity = this.createEntityDto();
    // Fill entity by mapped attribute
    entity = fillEntity(mappedAttributes, uid, icAttributes, entity, true, context);
    // Fill extended attributes to the entity. EAV attributes will be saved within entity.
    if (entity instanceof FormableDto) {
        FormableDto formableDto = (FormableDto) entity;
        formableDto.getEavs().clear();
        IdmFormInstanceDto formInstanceDto = fillExtendedAttributes(mappedAttributes, uid, icAttributes, entity, true, context);
        formableDto.getEavs().add(formInstanceDto);
    }
    // Create new entity
    entity = this.save(entity, true, context);
    EntityAccountDto roleAccount = createEntityAccount(account, entity, context);
    this.getEntityAccountService().save(roleAccount);
    // Entity created
    addToItemLog(logItem, MessageFormat.format("Entity with id [{0}] was created", entity.getId()));
    if (logItem != null) {
        logItem.setDisplayName(this.getDisplayNameForEntity(entity));
    }
    if (this.isProvisioningImplemented(entityType, logItem)) {
        // Call provisioning for this entity
        callProvisioningForEntity(entity, entityType, logItem);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto)

Example 7 with FormableDto

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

the class FormableSaveProcessor method process.

@Override
public EventResult<FormableDto> process(EntityEvent<FormableDto> event) {
    // saved dto
    FormableDto savedDto = event.getContent();
    // 
    // save filled eavs as "PATCH" - access is evaluated before - check {@link #publish} method in {@link AbstractFormableService}
    // the same behavior as saving form values separately
    List<IdmFormInstanceDto> processedInstances = new ArrayList<>();
    savedDto.getEavs().forEach(formInstance -> {
        // find definition by id or code -  loaded form definition is needed (with attributes)
        IdmFormDefinitionDto formDefinition = null;
        if (formInstance.getFormDefinition().getId() == null) {
            formDefinition = formService.getDefinition(savedDto.getClass(), formInstance.getFormDefinition().getCode());
        } else {
            formDefinition = formInstance.getFormDefinition();
        }
        // 
        if (formDefinition == null) {
            LOG.debug("Internal form definition [{}] cannot be saved", formInstance.getFormDefinition().getCode());
            // Prevent to loose internal form instance => just flow through without change.
            processedInstances.add(formInstance);
        } else {
            formInstance.setOwnerId(savedDto.getId());
            // entity owner type is used
            formInstance.setOwnerType(lookupService.getEntityClass(savedDto.getClass()));
            formInstance.setFormDefinition(formDefinition);
            // 
            CoreEvent<IdmFormInstanceDto> formInstanceEvent = new CoreEvent<IdmFormInstanceDto>(CoreEventType.UPDATE, formInstance);
            // We don't need to propagate other "NOTIFY" event on all form instances (duplicate to owner event)
            formInstanceEvent.getProperties().put(EntityEventManager.EVENT_PROPERTY_SKIP_NOTIFY, Boolean.TRUE);
            // we don't need to evaluate access on values again - see above publish method
            processedInstances.add(entityEventManager.process(formInstanceEvent, event).getContent());
        }
    });
    // set processed instances and content into event => can be used for another processing
    savedDto.setEavs(processedInstances);
    event.setContent(savedDto);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Example 8 with FormableDto

use of eu.bcvsolutions.idm.core.api.dto.FormableDto 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);
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) InvalidFormException(eu.bcvsolutions.idm.core.api.exception.InvalidFormException)

Aggregations

FormableDto (eu.bcvsolutions.idm.core.api.dto.FormableDto)8 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)8 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)4 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)3 ArrayList (java.util.ArrayList)3 EntityAccountDto (eu.bcvsolutions.idm.acc.dto.EntityAccountDto)2 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)2 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)2 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 List (java.util.List)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)1 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)1 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)1