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;
}
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())));
}
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);
}
Aggregations