Search in sources :

Example 1 with FormableDto

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);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 2 with FormableDto

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());
    });
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) AbstractFormableService(eu.bcvsolutions.idm.core.eav.api.service.AbstractFormableService) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with FormableDto

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;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashMap(java.util.HashMap) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) List(java.util.List) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) RptReportService(eu.bcvsolutions.idm.rpt.api.service.RptReportService) Map(java.util.Map) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Example 4 with FormableDto

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());
    }
}
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) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)

Example 5 with FormableDto

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());
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Sort(org.springframework.data.domain.Sort) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

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