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