use of eu.bcvsolutions.idm.core.api.dto.FormableDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method doUpdateEntity.
/**
* Fill data from IC attributes to entity (EAV and confidential storage too)
*
* @param context
*/
protected void doUpdateEntity(SynchronizationContext context) {
String uid = context.getUid();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
if (context.isSkipEntityUpdate()) {
addToItemLog(logItem, MessageFormat.format("Update of entity for account with uid [{0}] is skipped", uid));
return;
}
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
AccAccountDto account = context.getAccount();
List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
// Find entity ID, first try entity ID in the context then load by account
UUID entityId = context.getEntityId();
if (entityId == null && account != null) {
entityId = getEntityByAccount(account.getId());
}
DTO entity = null;
if (entityId != null) {
entity = this.getService().get(entityId);
}
if (entity != null) {
// Fill entity
entity = fillEntity(mappedAttributes, uid, icAttributes, entity, false, 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, false, context);
formableDto.getEavs().add(formInstanceDto);
}
// Update entity
if (context.isEntityDifferent()) {
entity = this.save(entity, true, context);
}
// Entity updated
addToItemLog(logItem, MessageFormat.format("Entity with id [{0}] was updated", entity.getId()));
if (logItem != null) {
logItem.setDisplayName(this.getDisplayNameForEntity(entity));
}
SystemEntityType entityType = context.getEntityType();
if (context.isEntityDifferent() && this.isProvisioningImplemented(entityType, logItem) && !context.isSkipProvisioning()) {
// Call provisioning for this entity
callProvisioningForEntity(entity, entityType, logItem);
}
// Add updated entity to the context
context.addEntityDto(entity);
} else {
addToItemLog(logItem, "Warning! - Entity-account relation (with ownership = true) was not found!");
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
}
}
use of eu.bcvsolutions.idm.core.api.dto.FormableDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testSaveEavWithOwner.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testSaveEavWithOwner() {
List<FormableDto> owners = new ArrayList<>();
// implemented authorization policies for eav attributes
owners.add(getHelper().createIdentity((GuardedString) null));
// without authorization policies for eav attributes
owners.add(getHelper().createRole());
//
owners.forEach(owner -> {
//
// create definition with parameter
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
String attributeName = getHelper().createName();
attribute.setCode(attributeName);
attribute.setName(attributeName);
attribute.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(owner.getClass().getCanonicalName(), getHelper().createName(), Lists.newArrayList(attribute));
attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
//
// fill values
IdmFormValueDto value = new IdmFormValueDto(attribute);
value.setValue(FORM_VALUE_ONE);
owner.getEavs().add(new IdmFormInstanceDto(owner, formDefinitionOne, Lists.newArrayList(value)));
owner = (FormableDto) ((AbstractFormableService) lookupService.getDtoService(owner.getClass())).save(owner);
// check form instance values were saved
owner.getEavs().forEach(formInstance -> {
Assert.assertFalse(formInstance.getValues().isEmpty());
formInstance.getValues().forEach(formValue -> {
Assert.assertNotNull(formValue.getId());
Assert.assertNotNull(formValue.getCreated());
});
});
//
// load saved
Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
Assert.assertEquals(1, m.get(attributeName).size());
Assert.assertEquals(FORM_VALUE_ONE, (m.get(attributeName).get(0)).getValue());
});
}
use of eu.bcvsolutions.idm.core.api.dto.FormableDto in project CzechIdMng by bcvsolutions.
the class AbstractFormableEntityExport method tramsformToMap.
@Override
protected Map<String, String> tramsformToMap(D dto) {
Map<String, String> map = super.tramsformToMap(dto);
//
if (dto instanceof FormableDto) {
List<IdmFormDefinitionDto> definitions = formService.getDefinitions(dto, IdmBasePermission.AUTOCOMPLETE);
List<IdmFormInstanceDto> formInstances = definitions.stream().map(d -> formService.getFormInstance(dto, d, IdmBasePermission.READ)).collect(Collectors.toList());
//
FormableDto formableDto = (FormableDto) dto;
formInstances.forEach(formInstance -> processFormInstance(map, formInstance, formableDto.getEavs().size() > 1));
}
return map;
}
use of eu.bcvsolutions.idm.core.api.dto.FormableDto in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method doCreateEntity.
/**
* Create and persist new entity by data from IC attributes
*
* @param entityType
* @param mappedAttributes
* @param logItem
* @param uid
* @param icAttributes
* @param account
*/
@Override
protected void doCreateEntity(SystemEntityType entityType, List<SysSystemAttributeMappingDto> mappedAttributes, SysSyncItemLogDto logItem, String uid, List<IcAttribute> icAttributes, AccAccountDto account, SynchronizationContext context) {
// We will create new TreeNode
addToItemLog(logItem, "Missing entity action is CREATE_ENTITY, we will create a new entity.");
IdmTreeNodeDto treeNode = new IdmTreeNodeDto();
// Fill entity by mapped attribute
treeNode = fillEntity(mappedAttributes, uid, icAttributes, treeNode, true, context);
treeNode.setTreeType(this.getSystemMapping(mappedAttributes).getTreeType());
// Fill extended attributes to the entity. EAV attributes will be saved within entity.
if (treeNode instanceof FormableDto) {
FormableDto formableDto = (FormableDto) treeNode;
formableDto.getEavs().clear();
IdmFormInstanceDto formInstanceDto = fillExtendedAttributes(mappedAttributes, uid, icAttributes, treeNode, true, context);
formableDto.getEavs().add(formInstanceDto);
}
// Create new Entity
treeNode = this.save(treeNode, true, context);
// Create new Entity account relation
EntityAccountDto entityAccount = this.createEntityAccountDto();
entityAccount.setAccount(account.getId());
entityAccount.setEntity(treeNode.getId());
entityAccount.setOwnership(true);
this.getEntityAccountService().save(entityAccount);
if (this.isProvisioningImplemented(entityType, logItem)) {
// Call provisioning for this entity
callProvisioningForEntity(treeNode, entityType, logItem);
}
// Entity Created
addToItemLog(logItem, MessageFormat.format("Tree node with id {0} was created", treeNode.getId()));
if (logItem != null) {
logItem.setDisplayName(treeNode.getName());
}
}
use of eu.bcvsolutions.idm.core.api.dto.FormableDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceIntegrationTest method testPropagateHighEventPriority.
@Test
public void testPropagateHighEventPriority() {
try {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
Assert.assertTrue(eventConfiguration.isAsynchronous());
Assert.assertTrue(entityEventManager.isAsynchronous());
//
FormableDto owner = getHelper().createIdentity((GuardedString) null);
getHelper().waitForResult(null, 1, 1);
//
// create definition one
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode(getHelper().createName());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
//
IdmFormValueDto value1 = new IdmFormValueDto(attributeDefinitionOne);
value1.setValue(FORM_VALUE_ONE);
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(owner, formDefinitionOne, Lists.newArrayList(value1));
// prepare event envelope
CoreEvent<IdmFormInstanceDto> event = new CoreEvent<IdmFormInstanceDto>(CoreEventType.UPDATE, formInstance);
// FE - high event priority
event.setPriority(PriorityType.HIGH);
// publish event for save form instance
formService.publish(event);
//
Assert.assertEquals(FORM_VALUE_ONE, formService.getValues(owner, formDefinitionOne).get(0).getShortTextValue());
//
IdmEntityEventFilter filter = new IdmEntityEventFilter();
filter.setOwnerId(owner.getId());
filter.setEventType(IdentityEventType.NOTIFY.name());
//
List<IdmEntityEventDto> events = entityEventService.find(filter, PageRequest.of(0, 1, new Sort(Direction.DESC, IdmEntityEvent_.created.getName()))).getContent();
//
Assert.assertFalse(events.isEmpty());
Assert.assertEquals(PriorityType.HIGH, events.get(0).getPriority());
} finally {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
Assert.assertFalse(eventConfiguration.isAsynchronous());
}
}
Aggregations