Search in sources :

Example 1 with FormDefinitionCache

use of eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache 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 2 with FormDefinitionCache

use of eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache in project CzechIdMng by bcvsolutions.

the class DefaultFormServiceIntegrationTest method testEvictCacheAfterChange.

@Test
public void testEvictCacheAfterChange() {
    String definitionCode = getHelper().createName();
    String definitionType = formService.getOwnerType(IdmIdentity.class);
    formService.getDefinitions(definitionType);
    Assert.assertNull(((FormDefinitionCache) cacheManager.getValue(FormService.FORM_DEFINITION_CACHE_NAME, formService.getCacheKey(definitionType)).get()).getByCode(definitionCode));
    // 
    // create definition with attribute
    IdmFormAttributeDto attribute = new IdmFormAttributeDto();
    String attributeName = getHelper().createName();
    attribute.setCode(attributeName);
    attribute.setName(attribute.getCode());
    attribute.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, definitionCode, Lists.newArrayList(attribute));
    attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
    formService.getDefinitions(definitionType);
    // 
    IdmFormDefinitionDto byCode = ((FormDefinitionCache) cacheManager.getValue(FormService.FORM_DEFINITION_CACHE_NAME, formService.getCacheKey(definitionType)).get()).getByCode(definitionCode);
    Assert.assertNotNull(byCode);
    Assert.assertEquals(formDefinitionOne.getId(), byCode.getId());
    Assert.assertEquals(1, byCode.getFormAttributes().size());
    IdmFormDefinitionDto byId = ((FormDefinitionCache) cacheManager.getValue(FormService.FORM_DEFINITION_CACHE_NAME, formService.getCacheKey(formDefinitionOne.getId())).get()).getById(formDefinitionOne.getId());
    Assert.assertNotNull(byId);
    Assert.assertEquals(formDefinitionOne.getId(), byId.getId());
    Assert.assertEquals(1, byId.getFormAttributes().size());
    // 
    // change form definition => evict both caches
    formDefinitionOne.setDescription(getHelper().createName());
    formService.saveDefinition(formDefinitionOne);
    Assert.assertNull(cacheManager.getValue(FormService.FORM_DEFINITION_CACHE_NAME, formService.getCacheKey(definitionType)));
    Assert.assertNull(cacheManager.getValue(FormService.FORM_DEFINITION_CACHE_NAME, formService.getCacheKey(formDefinitionOne.getId())));
    // 
    // fill cache
    formService.getDefinitions(definitionType);
    Assert.assertNotNull(((FormDefinitionCache) cacheManager.getValue(FormService.FORM_DEFINITION_CACHE_NAME, formService.getCacheKey(definitionType)).get()).getByCode(definitionCode));
    Assert.assertNotNull(((FormDefinitionCache) cacheManager.getValue(FormService.FORM_DEFINITION_CACHE_NAME, formService.getCacheKey(formDefinitionOne.getId())).get()).getById(formDefinitionOne.getId()));
    // 
    // change attribute
    attribute.setDescription(getHelper().createName());
    formAttributeService.save(attribute);
    Assert.assertNull(cacheManager.getValue(FormService.FORM_DEFINITION_CACHE_NAME, formService.getCacheKey(definitionType)));
    Assert.assertNull(cacheManager.getValue(FormService.FORM_DEFINITION_CACHE_NAME, formService.getCacheKey(formDefinitionOne.getId())));
}
Also used : FormDefinitionCache(eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) 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 FormDefinitionCache

use of eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache in project CzechIdMng by bcvsolutions.

the class DefaultFormService method getCachedDefinition.

private IdmFormDefinitionDto getCachedDefinition(UUID definitionId) {
    String cacheKey = getCacheKey(definitionId);
    ValueWrapper value = cacheManager.getValue(FORM_DEFINITION_CACHE_NAME, cacheKey);
    if (value != null) {
        // never null
        return ((FormDefinitionCache) value.get()).getById(definitionId);
    }
    // 
    IdmFormDefinitionDto definition = formDefinitionService.get(definitionId);
    if (definition == null) {
        // definition not found => not cached
        return null;
    }
    FormDefinitionCache cachedDefinitions = new FormDefinitionCache();
    cachedDefinitions.putDefinition(definition);
    cacheManager.cacheValue(FORM_DEFINITION_CACHE_NAME, cacheKey, cachedDefinitions);
    // 
    return cachedDefinitions.getById(definitionId);
}
Also used : FormDefinitionCache(eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Aggregations

FormDefinitionCache (eu.bcvsolutions.idm.core.eav.api.domain.FormDefinitionCache)3 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)3 ValueWrapper (eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper)2 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)1 IdmFormAttributeFilter (eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter)1 IdmFormDefinitionFilter (eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormDefinitionFilter)1 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)1 Test (org.junit.Test)1