Search in sources :

Example 6 with IdmFormAttributeFilter

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

the class DefaultFormService method getCachedDefinitions.

private FormDefinitionCache getCachedDefinitions(String type) {
    String cacheKey = getCacheKey(type);
    ValueWrapper value = cacheManager.getValue(FORM_DEFINITION_CACHE_NAME, cacheKey);
    if (value != null) {
        // never null
        return (FormDefinitionCache) value.get();
    }
    // 
    IdmFormDefinitionFilter filter = new IdmFormDefinitionFilter();
    filter.setType(type);
    List<IdmFormDefinitionDto> definitions = formDefinitionService.find(filter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmFormDefinition_.code.getName()))).getContent();
    // 
    // cache definition by id
    definitions.forEach(definition -> {
        // set mapped attributes - required to cache form definition with attributes
        IdmFormAttributeFilter attributeFilter = new IdmFormAttributeFilter();
        attributeFilter.setDefinitionId(definition.getId());
        definition.setTrimmed(false);
        definition.setFormAttributes(formAttributeService.find(attributeFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmFormAttribute_.seq.getName(), IdmFormAttribute_.name.getName()))).getContent());
        // 
        FormDefinitionCache cachedDefinition = new FormDefinitionCache();
        cachedDefinition.putDefinition(definition);
        // 
        cacheManager.cacheValue(FORM_DEFINITION_CACHE_NAME, getCacheKey(definition.getId()), cachedDefinition);
    });
    // 
    // cache by type
    FormDefinitionCache cachedDefinitions = new FormDefinitionCache();
    cachedDefinitions.putDefinitions(definitions);
    cacheManager.cacheValue(FORM_DEFINITION_CACHE_NAME, cacheKey, cachedDefinitions);
    // 
    return cachedDefinitions;
}
Also used : FormDefinitionCache(eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache) IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) IdmFormDefinitionFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Example 7 with IdmFormAttributeFilter

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

the class DefaultIdmCodeListService method toDto.

@Override
protected IdmCodeListDto toDto(IdmCodeList entity, IdmCodeListDto dto) {
    dto = super.toDto(entity, dto);
    if (dto == null) {
        return null;
    }
    if (!dto.isTrimmed()) {
        // set mapped attributes
        IdmFormAttributeFilter filter = new IdmFormAttributeFilter();
        filter.setDefinitionId(dto.getFormDefinition().getId());
        dto.getFormDefinition().setFormAttributes(formAttributeService.find(filter, getPageableAll(Sort.by(IdmFormAttribute_.seq.getName(), IdmFormAttribute_.name.getName()))).getContent());
    }
    // 
    return dto;
}
Also used : IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter)

Example 8 with IdmFormAttributeFilter

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

the class DefaultIdmFormAttributeService method saveInternal.

@Override
@Transactional
public IdmFormAttributeDto saveInternal(IdmFormAttributeDto dto) {
    // default seq
    if (dto.getSeq() == null) {
        if (isNew(dto)) {
            // new => try to init order
            IdmFormAttributeFilter filter = new IdmFormAttributeFilter();
            filter.setDefinitionId(dto.getFormDefinition());
            List<IdmFormAttributeDto> attributes = find(filter, PageRequest.of(0, 1, Sort.by(Direction.DESC, IdmFormAttribute_.seq.getName()))).getContent();
            if (attributes.isEmpty()) {
                dto.setSeq((short) 0);
            } else {
                // last by form definition // why big Short, why ... but it's too late ...
                Short lastSeq = attributes.get(0).getSeq();
                if (lastSeq == null) {
                    // cannot be saved by application, but can be broken in DB (TODO: change script + default 0)
                    dto.setSeq((short) 0);
                } else if (lastSeq.shortValue() >= Short.MAX_VALUE) {
                    dto.setSeq(Short.MAX_VALUE);
                } else {
                    dto.setSeq((short) (attributes.get(0).getSeq() + 1));
                }
            }
        } else {
            // update => ~ reset was requested.
            dto.setSeq((short) 0);
        }
    }
    // 
    return super.saveInternal(dto);
}
Also used : IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with IdmFormAttributeFilter

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

the class GenerateSchemaWithEavTest method testFormAttributeType.

@Test
public void testFormAttributeType() {
    IdmFormDefinitionDto definition = formService.getDefinition(IdmIdentity.class);
    IdmFormAttributeFilter filter = new IdmFormAttributeFilter();
    filter.setDefinitionId(definition.getId());
    // 
    SysSystemDto systemDto = this.initData();
    filter.setText("in resource " + systemDto.getName());
    // 
    long totalFormAttributesSecond = formAttributeService.find(filter, null).getTotalElements();
    // 
    // 9 new eav attribute
    assertEquals(9, totalFormAttributesSecond);
    // 
    for (IdmFormAttributeDto attribute : formAttributeService.find(filter, null)) {
        if (attribute.getCode().toLowerCase().equals("boolean_value")) {
            assertEquals(PersistentType.BOOLEAN, attribute.getPersistentType());
        } else if (attribute.getCode().toLowerCase().equals("byte_value")) {
            assertEquals(PersistentType.BYTEARRAY, attribute.getPersistentType());
        } else if (attribute.getCode().toLowerCase().equals("date_value")) {
            // TODO: date value is saved as text
            assertEquals(PersistentType.SHORTTEXT, attribute.getPersistentType());
        } else if (attribute.getCode().toLowerCase().equals("double_value")) {
            assertEquals(PersistentType.DOUBLE, attribute.getPersistentType());
        } else if (attribute.getCode().toLowerCase().equals("int_value")) {
            assertEquals(PersistentType.INT, attribute.getPersistentType());
        } else if (attribute.getCode().toLowerCase().equals("long_value")) {
            assertEquals(PersistentType.LONG, attribute.getPersistentType());
        } else if (attribute.getCode().toLowerCase().equals("short_text_value")) {
            // TODO: now is short text saved as TEXT
            assertEquals(PersistentType.SHORTTEXT, attribute.getPersistentType());
        } else if (attribute.getCode().toLowerCase().equals("string_value")) {
            assertEquals(PersistentType.SHORTTEXT, attribute.getPersistentType());
        } else if (attribute.getCode().toLowerCase().equals("uuid_value")) {
            assertEquals(PersistentType.BYTEARRAY, attribute.getPersistentType());
        } else {
            fail();
        }
    }
}
Also used : IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) 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 10 with IdmFormAttributeFilter

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

the class RoleWorkflowAdSyncTest method n92_testSyncWithWfSituationLinkedResolveMember.

@Test
public void n92_testSyncWithWfSituationLinkedResolveMember() {
    createRolesInSystem();
    final String newDN = "CN=" + ROLE_NAME + ",OU=Flat,OU=Pardubice,DC=bcvsolutions,DC=eu";
    this.getBean().initIdentityData(ROLE_NAME, newDN);
    String valueOfMemberAtt = "" + System.currentTimeMillis();
    String nameOfEav = "externalIdentifier";
    configurationService.setValue("idm.pub.acc.syncRole.identity.eav.externalIdentifier.code", nameOfEav);
    configurationService.setValue("idm.pub.acc.syncRole.roles.attributeNameOfMembership", helper.getSchemaColumnName(ATTRIBUTE_MEMBER));
    configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", true);
    IdmIdentityDto identity = this.getHelper().createIdentity();
    IdmFormAttributeFilter attributeFilter = new IdmFormAttributeFilter();
    attributeFilter.setCode(nameOfEav);
    IdmFormAttributeDto formAttribute = formAttributeService.find(attributeFilter, null).getContent().stream().findFirst().orElse(null);
    Assert.assertNotNull(formAttribute);
    helper.setEavValue(identity, formAttribute, IdmIdentity.class, valueOfMemberAtt, PersistentType.SHORTTEXT);
    this.getBean().deleteAllResourceData();
    this.getBean().addRoleToResource(ROLE_NAME, ATTRIBUTE_DN, valueOfMemberAtt);
    IdmRoleFilter roleFilter = new IdmRoleFilter();
    roleFilter.setText(ROLE_NAME);
    List<IdmRoleDto> roles = roleService.find(roleFilter, null).getContent();
    // role is in already synced ind idm
    Assert.assertEquals(1, roles.size());
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityId(identity.getId());
    List<IdmIdentityRoleDto> content = identityRoleService.find(filter, null).getContent();
    // identity does not have assigned this role
    Assert.assertEquals(0, content.size());
    SysSystemDto systemDto = systemService.getByCode(SYSTEM_NAME);
    Assert.assertNotNull(systemDto);
    SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
    syncFilter.setSystemId(systemDto.getId());
    List<AbstractSysSyncConfigDto> syncConfig = syncConfigService.find(syncFilter, null).getContent();
    // find synchronization config to start sync
    Assert.assertEquals(1, syncConfig.size());
    // Start sync
    helper.startSynchronization(syncConfig.get(0));
    SysSyncLogDto log = checkSyncLog(syncConfig.get(0), SynchronizationActionType.LINKED, 1, OperationResultType.WF);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    roles = roleService.find(roleFilter, null).getContent();
    Assert.assertEquals(1, roles.size());
    content = identityRoleService.find(filter, null).getContent();
    Assert.assertEquals(1, content.size());
    identityRoleService.delete(content.get(0));
    // Delete log
    syncLogService.delete(log);
    configurationService.deleteValue("idm.pub.acc.syncRole.provisioningOfIdentities.system.code");
    configurationService.deleteValue("idm.pub.acc.syncRole.system.mapping.attributeMemberOf");
    configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", false);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmFormAttributeFilter (eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter)14 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)8 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)6 Test (org.junit.Test)4 Transactional (org.springframework.transaction.annotation.Transactional)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)3 IdmFormDefinitionFilter (eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 UUID (java.util.UUID)3 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)2 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)2 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 IdmRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter)2 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)2 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)1