Search in sources :

Example 81 with IdmFormDefinitionDto

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

the class AdUserConnectorType method executeDeleteUserTest.

/**
 * Execute permission test for delete user from AD.
 */
protected void executeDeleteUserTest(ConnectorTypeDto connectorType) {
    String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
    Assert.notNull(systemId, "System ID cannot be null!");
    SysSystemDto systemDto = this.getSystemService().get(systemId);
    connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
    IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
    String port = getValueFromConnectorInstance(PORT, systemDto, connectorFormDef);
    String host = getValueFromConnectorInstance(HOST, systemDto, connectorFormDef);
    String user = getValueFromConnectorInstance(PRINCIPAL, systemDto, connectorFormDef);
    boolean ssl = Boolean.parseBoolean(getValueFromConnectorInstance(SSL, systemDto, connectorFormDef));
    String password = getConfidentialValueFromConnectorInstance(CREDENTIALS, systemDto, connectorFormDef);
    String entityStateId = connectorType.getMetadata().get(ENTITY_STATE_WITH_TEST_CREATED_USER_DN_KEY);
    Assert.notNull(entityStateId, "Entity state ID with created test user DN cannot be null!");
    // As protection against unauthorized deletion of a user other than the one
    // created, the DN will be loaded from the entity state.
    IdmEntityStateDto entityStateDto = entityStateService.get(entityStateId);
    Assert.notNull(entityStateDto, "Entity state with created test user DN cannot be null!");
    ResultModel model = entityStateDto.getResult().getModel();
    Object dn = model.getParameters().get(TEST_CREATED_USER_DN_KEY);
    Assert.isTrue(dn instanceof String, "Test domain users cannot be null!");
    String testDomainUsers = (String) dn;
    // Delete test user from AD.
    deleteTestUser(testDomainUsers, port, host, user, password, ssl);
    // Delete entity state.
    entityStateService.delete(entityStateDto);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 82 with IdmFormDefinitionDto

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

the class AdUserConnectorType method executeCreateUserTest.

/**
 * Execute test for check permissions for create account/user on the AD.
 */
protected void executeCreateUserTest(ConnectorTypeDto connectorType) {
    String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
    Assert.notNull(systemId, "System ID cannot be null!");
    SysSystemDto systemDto = this.getSystemService().get(systemId);
    connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
    IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
    String port = getValueFromConnectorInstance(PORT, systemDto, connectorFormDef);
    String host = getValueFromConnectorInstance(HOST, systemDto, connectorFormDef);
    String user = getValueFromConnectorInstance(PRINCIPAL, systemDto, connectorFormDef);
    boolean ssl = Boolean.parseBoolean(getValueFromConnectorInstance(SSL, systemDto, connectorFormDef));
    String password = getConfidentialValueFromConnectorInstance(CREDENTIALS, systemDto, connectorFormDef);
    String testUser = connectorType.getMetadata().get(TEST_USERNAME_KEY);
    Assert.notNull(testUser, "Test username cannot be null!");
    String usersContainer = connectorType.getMetadata().get(TEST_USER_CONTAINER_KEY);
    Assert.notNull(usersContainer, "Test user container cannot be null!");
    // Check exist of container on the AD.
    String usersContainerDN = this.findDn(MessageFormat.format("(&(distinguishedName={0})(|(objectClass=container)(objectClass=organizationalUnit)))", usersContainer), port, host, user, password, ssl);
    if (Strings.isBlank(usersContainerDN)) {
        throw new ResultCodeException(AccResultCode.WIZARD_AD_CONTAINER_NOT_FOUND, ImmutableMap.of("dn", usersContainer));
    }
    String createdUserDN = createTestUser(testUser, usersContainerDN, port, host, user, password, ssl);
    // As protection against unauthorized deletion of a user other than the one
    // created, the DN on the BE will be in the entity state.
    IdmEntityStateDto entityStateWithTestUser = createEntityStateWithTestUser(systemDto, createdUserDN);
    connectorType.getMetadata().put(ENTITY_STATE_WITH_TEST_CREATED_USER_DN_KEY, entityStateWithTestUser.getId().toString());
    connectorType.getMetadata().put(TEST_CREATED_USER_DN_KEY, createdUserDN);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 83 with IdmFormDefinitionDto

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

the class AdGroupConnectorTypeTest method createMemberSystem.

private SysSystemDto createMemberSystem() {
    ConnectorType connectorType = connectorManager.getConnectorType(MockAdUserConnectorType.NAME);
    ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
    SysSystemDto systemDto = createSystem(this.getHelper().createName(), connectorTypeDto);
    connectorTypeDto.getMetadata().put(MockAdUserConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
    String newUserContainerMock = this.getHelper().createName();
    connectorTypeDto.getMetadata().put(MockAdUserConnectorType.NEW_USER_CONTAINER_KEY, newUserContainerMock);
    String userContainerMock = this.getHelper().createName();
    connectorTypeDto.getMetadata().put(MockAdUserConnectorType.USER_SEARCH_CONTAINER_KEY, userContainerMock);
    String deletedUserContainerMock = this.getHelper().createName();
    connectorTypeDto.getMetadata().put(MockAdUserConnectorType.DELETE_USER_CONTAINER_KEY, deletedUserContainerMock);
    String domainMock = this.getHelper().createName();
    connectorTypeDto.getMetadata().put(MockAdUserConnectorType.DOMAIN_KEY, domainMock);
    connectorTypeDto.setWizardStepName(MockAdUserConnectorType.STEP_FOUR);
    // Generate mock schema.
    generateMockMemberSchema(systemDto);
    // Execute step four.
    connectorManager.execute(connectorTypeDto);
    // Check containers on the system's operationOptions.
    systemDto = systemService.get(systemDto.getId());
    IdmFormDefinitionDto operationOptionsFormDefinition = systemService.getOperationOptionsConnectorFormDefinition(systemDto);
    String newUserContainer = getValueFromConnectorInstance(MockAdUserConnectorType.NEW_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition);
    assertEquals(newUserContainerMock, newUserContainer);
    String deletedUserContainer = getValueFromConnectorInstance(MockAdUserConnectorType.DELETE_USER_CONTAINER_KEY, systemDto, operationOptionsFormDefinition);
    // Protected mode is not active -> delete user container should be null.
    assertNull(deletedUserContainer);
    String searchUserContainer = getValueFromConnectorInstance(MockAdUserConnectorType.USER_SEARCH_CONTAINER_KEY, systemDto, operationOptionsFormDefinition);
    assertEquals(userContainerMock, searchUserContainer);
    String domain = getValueFromConnectorInstance(MockAdUserConnectorType.DOMAIN_KEY, systemDto, operationOptionsFormDefinition);
    assertEquals(domainMock, domain);
    // Check created schema attributes.
    SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
    schemaAttributeFilter.setSystemId(systemDto.getId());
    List<SysSchemaAttributeDto> attributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
    assertTrue(attributes.stream().anyMatch(attribute -> IcAttributeInfo.NAME.equals(attribute.getName())));
    assertTrue(attributes.stream().anyMatch(attribute -> IcAttributeInfo.PASSWORD.equals(attribute.getName())));
    assertTrue(attributes.stream().anyMatch(attribute -> IcAttributeInfo.ENABLE.equals(attribute.getName())));
    assertTrue(attributes.stream().anyMatch(attribute -> MockAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(attribute.getName())));
    assertTrue(attributes.stream().anyMatch(attribute -> MockAdUserConnectorType.SAM_ACCOUNT_NAME_ATTRIBUTE.equals(attribute.getName())));
    // Check created schema attributes.
    SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
    attributeMappingFilter.setSystemId(systemDto.getId());
    List<SysSystemAttributeMappingDto> attributeMappingDtos = attributeMappingService.find(attributeMappingFilter, null).getContent();
    assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> IcAttributeInfo.NAME.equals(attribute.getName())));
    assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> IcAttributeInfo.PASSWORD.equals(attribute.getName())));
    assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> IcAttributeInfo.ENABLE.equals(attribute.getName())));
    assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> MockAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(attribute.getName())));
    assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> MockAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(attribute.getName()) && AttributeMappingStrategyType.MERGE == attribute.getStrategyType()));
    assertTrue(attributeMappingDtos.stream().anyMatch(attribute -> MockAdUserConnectorType.SAM_ACCOUNT_NAME_ATTRIBUTE.equals(attribute.getName())));
    return systemDto;
}
Also used : AdGroupConnectorType(eu.bcvsolutions.idm.acc.connector.AdGroupConnectorType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) MsAdSyncMappingRoleAutoAttributesProcessor(eu.bcvsolutions.idm.acc.event.processor.MsAdSyncMappingRoleAutoAttributesProcessor) After(org.junit.After) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmEntityStateService(eu.bcvsolutions.idm.core.api.service.IdmEntityStateService) MockAdUserConnectorType(eu.bcvsolutions.idm.acc.service.impl.mock.MockAdUserConnectorType) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmRoleCatalogueService(eu.bcvsolutions.idm.core.api.service.IdmRoleCatalogueService) List(java.util.List) ConnectorManager(eu.bcvsolutions.idm.acc.service.api.ConnectorManager) Assert.assertFalse(org.junit.Assert.assertFalse) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) ConnectorType(eu.bcvsolutions.idm.acc.service.api.ConnectorType) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IcObjectClassInfo(eu.bcvsolutions.idm.ic.api.IcObjectClassInfo) Lists(com.google.common.collect.Lists) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) ConnectorTypeDto(eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) Before(org.junit.Before) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) MockAdGroupConnectorType(eu.bcvsolutions.idm.acc.service.impl.mock.MockAdGroupConnectorType) Assert.assertNotNull(org.junit.Assert.assertNotNull) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) Assert.assertTrue(org.junit.Assert.assertTrue) SysSyncRoleConfig_(eu.bcvsolutions.idm.acc.entity.SysSyncRoleConfig_) Test(org.junit.Test) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSyncRoleConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncRoleConfigDto) Assert.assertNull(org.junit.Assert.assertNull) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) ConnectorTypeDto(eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto) AdGroupConnectorType(eu.bcvsolutions.idm.acc.connector.AdGroupConnectorType) MockAdUserConnectorType(eu.bcvsolutions.idm.acc.service.impl.mock.MockAdUserConnectorType) ConnectorType(eu.bcvsolutions.idm.acc.service.api.ConnectorType) MockAdGroupConnectorType(eu.bcvsolutions.idm.acc.service.impl.mock.MockAdGroupConnectorType) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 84 with IdmFormDefinitionDto

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

the class AdUserConnectorTypeTest method testReopenSystemWithoutOptionsAttributes.

@Test
public void testReopenSystemWithoutOptionsAttributes() {
    ConnectorType connectorType = connectorManager.getConnectorType(MockAdUserConnectorType.NAME);
    ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
    SysSystemDto systemDto = createSystem(this.getHelper().createName(), connectorTypeDto);
    connectorTypeDto.getMetadata().put(MockAdUserConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
    IdmFormDefinitionDto operationOptionsConnectorFormDefinition = systemService.getOperationOptionsConnectorFormDefinition(systemDto);
    // Try to find attribute for one of container. If exist -> change code = simulate delete.
    IdmFormAttributeDto userSearchContainerAttribute = operationOptionsConnectorFormDefinition.getMappedAttributeByCode(MockAdUserConnectorType.USER_SEARCH_CONTAINER_KEY);
    if (userSearchContainerAttribute != null) {
        userSearchContainerAttribute.setCode(getHelper().createName());
        formService.saveAttribute(userSearchContainerAttribute);
    }
    connectorType = connectorManager.getConnectorType(MockAdUserConnectorType.NAME);
    connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
    connectorTypeDto.setReopened(true);
    connectorTypeDto.getEmbedded().put(MockAdUserConnectorType.SYSTEM_DTO_KEY, systemDto);
    connectorTypeDto.getMetadata().put(MockAdUserConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
    ConnectorTypeDto loadedConnectorTypeDto = connectorManager.load(connectorTypeDto);
    assertNotNull(loadedConnectorTypeDto);
    // Clean
    systemService.delete(systemDto);
}
Also used : ConnectorTypeDto(eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto) ConnectorType(eu.bcvsolutions.idm.acc.service.api.ConnectorType) MockAdUserConnectorType(eu.bcvsolutions.idm.acc.service.impl.mock.MockAdUserConnectorType) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 85 with IdmFormDefinitionDto

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

the class DefaultFormService method saveAttributeValues.

/**
 * Save single attribute values. Main business logic is here => all method ends here.
 *
 * @param ownerEntity
 * @param attribute
 * @param previousValues
 * @param newValues
 * @param permission
 * @return
 */
private List<IdmFormValueDto> saveAttributeValues(FormableEntity ownerEntity, IdmFormAttributeDto attribute, List<IdmFormValueDto> previousValues, List<IdmFormValueDto> newValues, BasePermission... permission) {
    // 
    IdmFormDefinitionDto formDefinition = getCachedDefinition(attribute.getFormDefinition());
    FormValueService<FormableEntity> formValueService = getFormValueService(ownerEntity);
    List<IdmFormValueDto> results = new ArrayList<>();
    // ordered by seq
    Map<UUID, IdmFormValueDto> unprocessedPreviousValues = new LinkedHashMap<>();
    if (CollectionUtils.isNotEmpty(previousValues)) {
        previousValues.forEach(previousValue -> {
            unprocessedPreviousValues.put(previousValue.getId(), previousValue);
        });
    }
    // 
    if (newValues == null || newValues.isEmpty()) {
        // confidential values has to removed directly, they could not be sent with form (only changed values)
        if (!attribute.isConfidential()) {
            // delete previous attributes
            unprocessedPreviousValues.values().forEach(value -> {
                formValueService.delete(value, permission);
                if (value.getPersistentType() == PersistentType.ATTACHMENT) {
                    // delete attachment - permissions are evaluated before
                    attachmentManager.deleteAttachments(value.getId(), attachmentManager.getOwnerType(formValueService.getEntityClass()));
                }
                LOG.trace("FormValue [{}:{}] for owner [{}] was deleted", value.getFormAttribute(), value.getId(), ownerEntity);
            });
        }
        return results;
    }
    // 
    if (!attribute.isMultiple() && newValues.size() > 1) {
        throw new IllegalArgumentException(MessageFormat.format("Form attribute [{0}:{1}] does not support multivalue, sent [{2}] values.", formDefinition.getCode(), attribute.getCode(), newValues.size()));
    }
    // 
    // compare values
    IdmFormValueDto[] sortedPreviousValues = resolvePreviousValues(unprocessedPreviousValues, newValues);
    for (short index = 0; index < newValues.size(); index++) {
        IdmFormValueDto previousValue = sortedPreviousValues[index];
        IdmFormValueDto newValue = newValues.get(index);
        // 
        if (previousValue == null) {
            if (newValue.getOwnerId() != null && !newValue.getOwnerId().equals(ownerEntity.getId())) {
                // owner was changed, new value will be created => prevent to move (update) value into new owner.
                newValue.setId(null);
                DtoUtils.clearAuditFields(newValue);
            // 
            // FIXME: move deep copy of attachments an confidential storage here.
            }
            newValue.setOwnerAndAttribute(ownerEntity, attribute);
            newValue.setSeq(index);
            // 
            if (!newValue.isNull()) {
                // null values are not saved
                newValue = formValueService.save(newValue, permission);
                // 
                if (newValue.getPersistentType() == PersistentType.ATTACHMENT) {
                    // update attachment - set current owner, if temporary owner is given
                    IdmAttachmentDto attachment = attachmentManager.get(newValue.getUuidValue());
                    if (attachment != null && attachment.getOwnerType().equals(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE)) {
                        attachment.setOwnerType(attachmentManager.getOwnerType(formValueService.getEntityClass()));
                        attachment.setOwnerId(newValue.getId());
                        // permissions are evaluated above
                        attachmentManager.save(attachment);
                    }
                }
                results.add(newValue);
                LOG.trace("FormValue [{}:{}] for owner [{}] was created.", attribute.getCode(), newValue.getId(), ownerEntity);
            }
        } else {
            // confidential value is always updated - only new values are sent from client
            if (newValue.isConfidential() || !previousValue.isEquals(newValue)) {
                UUID previousUuidValue = previousValue.getUuidValue();
                // set value for the previous value
                previousValue.setValues(newValue);
                // attribute persistent type could be changed
                previousValue.setOwnerAndAttribute(ownerEntity, attribute);
                previousValue.setSeq(index);
                if (!previousValue.isNull()) {
                    // null values are not saved
                    previousValue = formValueService.save(previousValue, permission);
                    // 
                    if (previousValue.getPersistentType() == PersistentType.ATTACHMENT) {
                        // fill attachments version and owners
                        IdmAttachmentDto previousAttachment = previousUuidValue == null ? null : attachmentManager.get(previousUuidValue);
                        // update attachment - set current owner, if temporary owner is given
                        IdmAttachmentDto attachment = attachmentManager.get(previousValue.getUuidValue());
                        if (attachment != null && attachment.getOwnerType().equals(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE)) {
                            attachment.setOwnerType(attachmentManager.getOwnerType(formValueService.getEntityClass()));
                            attachment.setOwnerId(previousValue.getId());
                            if (previousAttachment != null) {
                                if (previousAttachment.getParent() != null) {
                                    attachment.setParent(previousAttachment.getParent());
                                } else {
                                    attachment.setParent(previousAttachment.getId());
                                }
                                attachment.setVersionNumber(previousAttachment.getVersionNumber() + 1);
                                attachment.setVersionLabel(attachment.getVersionNumber() + ".0");
                            }
                            // permissions are evaluated above
                            attachment = attachmentManager.save(attachment);
                            if (previousAttachment != null) {
                                previousAttachment.setNextVersion(attachment.getId());
                                attachmentManager.save(previousAttachment);
                            }
                        }
                    }
                    results.add(previousValue);
                    LOG.trace("FormValue [{}:{}] for owner [{}] was updated.", attribute.getCode(), previousValue.getId(), ownerEntity);
                } else {
                    formValueService.delete(previousValue, permission);
                    if (previousValue.getPersistentType() == PersistentType.ATTACHMENT) {
                        // delete attachment - permissions are evaluated before
                        attachmentManager.deleteAttachments(previousValue.getId(), attachmentManager.getOwnerType(formValueService.getEntityClass()));
                    }
                    LOG.trace("FormValue [{}:{}] for owner [{}] was deleted.", attribute.getCode(), previousValue.getId(), ownerEntity);
                }
            } else {
                results.add(previousValue);
                LOG.trace("FormValue [{}:{}] for owner [{}] was preserved unchanged.", attribute.getCode(), previousValue.getId(), ownerEntity);
            }
        }
    }
    // remove unprocessed values
    // confidential property will be removed too => none or all confidential values have to be given for multiple attributes
    unprocessedPreviousValues.values().forEach(value -> {
        formValueService.delete(value, permission);
        if (value.getPersistentType() == PersistentType.ATTACHMENT) {
            // delete attachment - permissions are evaluated before
            attachmentManager.deleteAttachments(value.getId(), attachmentManager.getOwnerType(formValueService.getEntityClass()));
        }
        LOG.trace("FormValue [{}:{}] for owner [{}] was deleted", value.getFormAttribute(), value.getId(), ownerEntity);
    });
    return results;
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) LinkedHashMap(java.util.LinkedHashMap) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) UUID(java.util.UUID)

Aggregations

IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)398 Test (org.junit.Test)230 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)224 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)190 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)165 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)123 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)119 List (java.util.List)109 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)108 UUID (java.util.UUID)102 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)98 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)83 Autowired (org.springframework.beans.factory.annotation.Autowired)83 ArrayList (java.util.ArrayList)82 Transactional (org.springframework.transaction.annotation.Transactional)80 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)77 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)71 Serializable (java.io.Serializable)68 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)65 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)61