use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmFormDefinitionService method saveInternal.
/**
* Fill default definition code and name, if no code / name is given
*/
@Override
@Transactional
public IdmFormDefinitionDto saveInternal(IdmFormDefinitionDto dto) {
if (StringUtils.isEmpty(dto.getCode())) {
dto.setMain(true);
dto.setCode(DEFAULT_DEFINITION_CODE);
}
if (StringUtils.isEmpty(dto.getName())) {
dto.setName(dto.getCode());
}
if (dto.isMain()) {
IdmFormDefinitionDto mainDefinition = findOneByMain(dto.getType());
if (mainDefinition != null && !mainDefinition.getId().equals(dto.getId())) {
mainDefinition.setMain(false);
save(mainDefinition);
}
}
return super.saveInternal(dto);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmFormDefinitionService method updateDefinition.
@Override
@Transactional
public IdmFormDefinitionDto updateDefinition(String definitionType, String definitionCode, List<IdmFormAttributeDto> attributes) {
Assert.notNull(definitionType);
//
IdmFormDefinitionDto formDefinition = findOneByTypeAndCode(definitionType, definitionCode);
if (formDefinition == null) {
formDefinition = new IdmFormDefinitionDto();
formDefinition.setType(definitionType);
formDefinition.setCode(definitionCode);
// TODO: we don't set definition to unmodifiable - some changes can be done through ui?
formDefinition = save(formDefinition);
}
//
if (attributes == null || attributes.isEmpty()) {
// change script has to be provided
return formDefinition;
}
// upgrade definition
boolean changed = false;
Short seq = 0;
for (IdmFormAttributeDto attribute : attributes) {
// update seq - attributes can be simply given in different order
if (attribute.getSeq() == null) {
attribute.setSeq(seq);
}
IdmFormAttributeDto savedAttribute = formAttributeService.findAttribute(formDefinition.getType(), formDefinition.getCode(), attribute.getCode());
if (savedAttribute == null) {
savedAttribute = attribute;
savedAttribute.setFormDefinition(formDefinition.getId());
if (savedAttribute.getSeq() == null) {
savedAttribute.setSeq(seq);
}
//
formAttributeService.save(savedAttribute);
changed = true;
} else {
// throw exception, if incompatible change was found
checkIncompatibleChanges(formDefinition, savedAttribute, attribute);
// save compatible changes
if (compareCompatibleChanges(savedAttribute, attribute) != 0) {
// update attribute - compatible changes
savedAttribute.setSeq(attribute.getSeq());
savedAttribute.setName(attribute.getName());
savedAttribute.setFaceType(attribute.getFaceType());
savedAttribute.setReadonly(attribute.isReadonly());
savedAttribute.setRequired(attribute.isRequired());
savedAttribute.setDefaultValue(attribute.getDefaultValue());
savedAttribute.setDescription(attribute.getDescription());
savedAttribute.setMultiple(attribute.isMultiple());
savedAttribute.setPlaceholder(attribute.getPlaceholder());
savedAttribute.setUnmodifiable(attribute.isUnmodifiable());
formAttributeService.save(savedAttribute);
changed = true;
}
}
seq++;
}
if (changed) {
formDefinition = get(formDefinition.getId());
}
return formDefinition;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceTest method testFormAttributes.
/**
* Test add and delete extended attributes to owner
*/
@Test
public void testFormAttributes() {
// create owner
SysSystemDto system = new SysSystemDto();
system.setName(SYSTEM_NAME_ONE);
system = systemService.save(system);
SysSystemDto systemOne = systemService.getByCode(SYSTEM_NAME_ONE);
assertEquals(SYSTEM_NAME_ONE, systemOne.getName());
//
// create definition one
IdmFormDefinitionDto formDefinitionOne = new IdmFormDefinitionDto();
formDefinitionOne.setType(SysSystem.class.getCanonicalName());
formDefinitionOne.setCode("v1");
formDefinitionOne = formDefinitionService.save(formDefinitionOne);
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setFormDefinition(formDefinitionOne.getId());
attributeDefinitionOne.setCode("name_" + System.currentTimeMillis());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
attributeDefinitionOne = formAttributeService.save(attributeDefinitionOne);
formDefinitionOne = formDefinitionService.get(formDefinitionOne.getId());
//
// create definition two
IdmFormDefinitionDto formDefinitionTwo = new IdmFormDefinitionDto();
formDefinitionTwo.setType(SysSystem.class.getCanonicalName());
formDefinitionTwo.setCode("v2");
formDefinitionTwo = formDefinitionService.save(formDefinitionTwo);
IdmFormAttributeDto attributeDefinitionTwo = new IdmFormAttributeDto();
attributeDefinitionTwo.setFormDefinition(formDefinitionTwo.getId());
attributeDefinitionTwo.setCode("name_" + System.currentTimeMillis());
attributeDefinitionTwo.setName(attributeDefinitionTwo.getCode());
attributeDefinitionTwo.setPersistentType(PersistentType.TEXT);
attributeDefinitionTwo = formAttributeService.save(attributeDefinitionTwo);
formDefinitionTwo = formDefinitionService.get(formDefinitionTwo.getId());
//
IdmFormValueDto value1 = new IdmFormValueDto(attributeDefinitionOne);
value1.setValue("test1");
IdmFormValueDto value2 = new IdmFormValueDto(attributeDefinitionTwo);
value2.setValue("test2");
formService.saveValues(system, formDefinitionOne, Lists.newArrayList(value1));
formService.saveValues(system, formDefinitionTwo, Lists.newArrayList(value2));
assertEquals("test1", formService.getValues(system, formDefinitionOne).get(0).getStringValue());
assertEquals("test2", formService.getValues(system, formDefinitionTwo).get(0).getStringValue());
assertEquals("test2", formService.getValues(system, formDefinitionTwo, attributeDefinitionTwo.getName()).get(0).getValue());
//
// create second owner
SysSystemDto systemTwo = new SysSystemDto();
systemTwo.setName(SYSTEM_NAME_TWO);
systemTwo = systemService.save(systemTwo);
assertEquals(0, formService.getValues(systemTwo, formDefinitionOne).size());
assertEquals(0, formService.getValues(systemTwo, formDefinitionTwo).size());
assertEquals(1, formService.getValues(system, formDefinitionOne).size());
assertEquals(1, formService.getValues(system, formDefinitionTwo).size());
systemService.delete(systemTwo);
assertEquals(1, formService.getValues(system, formDefinitionOne).size());
assertEquals(1, formService.getValues(system, formDefinitionTwo).size());
formService.deleteValues(system, formDefinitionOne);
assertEquals(0, formService.getValues(system, formDefinitionOne).size());
assertEquals("test2", formService.getValues(system, formDefinitionTwo).get(0).getStringValue());
systemService.delete(system);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultTreeSynchronizationServiceTest method initData.
private void initData() {
// create test system
system = helper.createSystem("test_tree_resource");
system.setName(SYSTEM_NAME);
system = systemService.save(system);
// key to EAV
IdmFormDefinitionDto formDefinition = systemService.getConnectorFormDefinition(system.getConnectorInstance());
formService.saveValues(system, formDefinition, "keyColumn", ImmutableList.of("ID"));
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
IdmTreeTypeDto treeType = new IdmTreeTypeDto();
treeType.setCode(TREE_TYPE_TEST);
treeType.setName(TREE_TYPE_TEST);
treeType = treeTypeService.save(treeType);
// Create synchronization mapping
SysSystemMappingDto syncSystemMapping = new SysSystemMappingDto();
syncSystemMapping.setName("default_" + System.currentTimeMillis());
syncSystemMapping.setEntityType(SystemEntityType.TREE);
syncSystemMapping.setTreeType(treeType.getId());
syncSystemMapping.setOperationType(SystemOperationType.SYNCHRONIZATION);
syncSystemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto syncMapping = systemMappingService.save(syncSystemMapping);
createMapping(system, syncMapping);
initTreeData();
syncConfigService.find(null).getContent().forEach(config -> {
syncConfigService.delete(config);
});
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto 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.TEXT, 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.TEXT, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("string_value")) {
assertEquals(PersistentType.TEXT, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("uuid_value")) {
assertEquals(PersistentType.BYTEARRAY, attribute.getPersistentType());
} else {
fail();
}
}
}
Aggregations