Search in sources :

Example 1 with IdmFormDefinitionFilter

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

the class FormDefinitionExportBulkActionIntegrationTest method testExportImportFormDefinition.

@Test
public void testExportImportFormDefinition() {
    IdmFormDefinitionDto formDef = getHelper().createFormDefinition("type_" + getHelper().createName(), false);
    Assert.assertNotNull(formDef.getId());
    final String testAttrName = "testFormAttr" + getHelper().createName();
    IdmFormAttributeDto formAttr = new IdmFormAttributeDto();
    formAttr.setFormDefinition(formDef.getId());
    formAttr.setName(testAttrName);
    formAttr.setCode(testAttrName);
    formAttr.setPlaceholder(testAttrName);
    formAttr.setPersistentType(PersistentType.INT);
    formAttr.setDefaultValue("500000");
    formAttr.setMax(new BigDecimal(1000000));
    formAttr.setMin(new BigDecimal(1000));
    formAttr.setRequired(true);
    formAttr.setRegex("testRegExp");
    formAttr.setValidationMessage("testRegExp");
    List<IdmFormAttributeDto> formAttrs = new ArrayList<IdmFormAttributeDto>();
    formAttrs.add(formAttr);
    formDef.setFormAttributes(formAttrs);
    formDef = formDefService.updateDefinition(formDef);
    executeExportAndImport(formDef, FormDefinitionExportBulkAction.NAME);
    IdmFormDefinitionFilter filter = new IdmFormDefinitionFilter();
    filter.setId(formDef.getId());
    List<IdmFormDefinitionDto> importedDtos = formDefService.find(filter, null).getContent();
    Assert.assertEquals(1, importedDtos.size());
    // Form definition equivalence
    IdmFormDefinitionDto importedFormDef = importedDtos.get(0);
    Assert.assertEquals(formDef.getId(), importedFormDef.getId());
    Assert.assertEquals(formDef.getCode(), importedFormDef.getCode());
    Assert.assertEquals(formDef.getName(), importedFormDef.getName());
    Assert.assertEquals(formDef.isMain(), importedFormDef.isMain());
    // Form attribute equivalence
    IdmFormAttributeDto importedFormAttr = formDef.getMappedAttributeByCode(testAttrName);
    Assert.assertNotNull(importedFormAttr);
    Assert.assertEquals(formAttr.getCode(), importedFormAttr.getCode());
    Assert.assertEquals(formAttr.getName(), importedFormAttr.getName());
    Assert.assertEquals(formAttr.getFormDefinition(), importedFormAttr.getFormDefinition());
    Assert.assertEquals(formAttr.getPlaceholder(), importedFormAttr.getPlaceholder());
    Assert.assertEquals(formAttr.getPersistentType(), importedFormAttr.getPersistentType());
    Assert.assertEquals(formAttr.getDefaultValue(), importedFormAttr.getDefaultValue());
    Assert.assertEquals(formAttr.getMax(), importedFormAttr.getMax());
    Assert.assertEquals(formAttr.getMin(), importedFormAttr.getMin());
    Assert.assertEquals(formAttr.isRequired(), importedFormAttr.isRequired());
    Assert.assertEquals(formAttr.getRegex(), importedFormAttr.getRegex());
    Assert.assertEquals(formAttr.getValidationMessage(), importedFormAttr.getValidationMessage());
}
Also used : IdmFormDefinitionFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest)

Example 2 with IdmFormDefinitionFilter

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

the class ComplexHrProcessIntegrationTest method addEavIdentityContractFormDef.

/**
 * Creating required contract EAV attribute for the purpose of automatic roles assignment
 */
private void addEavIdentityContractFormDef() {
    IdmFormDefinitionFilter filt = new IdmFormDefinitionFilter();
    filt.setType(IdmIdentityContract.class.getCanonicalName());
    filt.setMain(true);
    IdmFormDefinitionDto formDef = formDefService.find(filt, null).getContent().get(0);
    IdmFormAttributeFilter formAttrFilt = new IdmFormAttributeFilter();
    formAttrFilt.setCode(eavAutoRoleAttrName);
    formAttrFilt.setDefinitionId(formDef.getId());
    if (formAttrService.count(formAttrFilt) > 0) {
        // already created
        return;
    }
    IdmFormAttributeDto formAttr = new IdmFormAttributeDto();
    formAttr.setCode(eavAutoRoleAttrName);
    formAttr.setName(eavAutoRoleAttrName);
    formAttr.setPersistentType(PersistentType.SHORTTEXT);
    formAttr.setFormDefinition(formDef.getId());
    formAttrService.save(formAttr);
}
Also used : IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) IdmFormDefinitionFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)

Example 3 with IdmFormDefinitionFilter

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

the class FormDefinitionDeleteBulkActionIntegrationTest method processBulkActionByFilter.

@Test
public void processBulkActionByFilter() {
    String type = getHelper().createName();
    // creates Main definition which won't be deleted
    getHelper().createFormDefinition(type, true);
    List<IdmFormDefinitionDto> defDtos = new ArrayList<IdmFormDefinitionDto>();
    for (int i = 0; i < TEST_COUNT; ++i) {
        getHelper().createFormDefinition(type);
    }
    IdmFormDefinitionFilter filter = new IdmFormDefinitionFilter();
    filter.setType(type);
    filter.setMain(false);
    defDtos = formDefService.find(filter, null).getContent();
    Set<UUID> defIds = defDtos.stream().map(IdmFormDefinitionDto::getId).collect(Collectors.toSet());
    Assert.assertTrue(defIds.size() == TEST_COUNT);
    IdmBulkActionDto bulkAction = findBulkAction(IdmFormDefinition.class, FormDefinitionDeleteBulkAction.NAME);
    bulkAction.setTransformedFilter(filter);
    bulkAction.setFilter(toMap(filter));
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, Long.valueOf(TEST_COUNT), null, null);
    filter.setMain(null);
    List<IdmFormDefinitionDto> defsRemain = formDefService.find(filter, null).getContent();
    Assert.assertEquals(1, defsRemain.size());
    Set<UUID> result = defsRemain.stream().map(IdmFormDefinitionDto::getId).collect(Collectors.toSet());
    result.retainAll(defIds);
    Assert.assertTrue(result.isEmpty());
}
Also used : IdmFormDefinitionFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UUID(java.util.UUID) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 4 with IdmFormDefinitionFilter

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

the class DefaultFormService method getDefinitions.

@Override
@Transactional(readOnly = true)
public List<IdmFormDefinitionDto> getDefinitions(String type, BasePermission... permission) {
    if (PermissionUtils.isEmpty(permission)) {
        return getCachedDefinitions(type).getDefinitions();
    }
    // 
    IdmFormDefinitionFilter filter = new IdmFormDefinitionFilter();
    filter.setType(type);
    // 
    return formDefinitionService.find(filter, getDefinitionPageable(), permission).getContent();
}
Also used : IdmFormDefinitionFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with IdmFormDefinitionFilter

use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter 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)

Aggregations

IdmFormDefinitionFilter (eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter)9 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)7 ArrayList (java.util.ArrayList)4 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)3 IdmFormAttributeFilter (eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter)3 UUID (java.util.UUID)3 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)2 ValueWrapper (eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper)2 FormDefinitionCache (eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache)2 Test (org.junit.Test)2 ResponseEntity (org.springframework.http.ResponseEntity)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)1 ConfigurationClassProperty (eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)1 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)1 ExportDescriptorDto (eu.bcvsolutions.idm.core.api.dto.ExportDescriptorDto)1 FormableDto (eu.bcvsolutions.idm.core.api.dto.FormableDto)1