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