use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultFormService method createDefinition.
@Override
@Transactional
public IdmFormDefinitionDto createDefinition(String type, String code, List<IdmFormAttributeDto> formAttributes) {
Assert.hasLength(type);
//
// create definition
IdmFormDefinitionDto formDefinition = new IdmFormDefinitionDto();
formDefinition.setType(type);
formDefinition.setCode(code);
formDefinition = formDefinitionService.save(formDefinition);
// and their attributes
if (formAttributes != null) {
Short seq = 0;
for (IdmFormAttributeDto formAttribute : formAttributes) {
// default attribute order
if (formAttribute.getSeq() == null) {
formAttribute.setSeq(seq);
seq++;
}
formAttribute.setFormDefinition(formDefinition.getId());
formAttribute = formAttributeService.save(formAttribute);
formDefinition.addFormAttribute(formAttribute);
}
}
return formDefinition;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultFormService method convertConfigurationToFormDefinition.
/**
* Create instance form definition from the given configuration class
*
* @param configurationClass
* @return
*/
@Override
public IdmFormDefinitionDto convertConfigurationToFormDefinition(Class<? extends ConfigurationClass> configurationClass) {
Assert.notNull(configurationClass, "Class with the configuration is required!");
try {
ConfigurationClass configurationClassInstance = configurationClass.newInstance();
List<IdmFormAttributeDto> properties = new ArrayList<>();
PropertyDescriptor[] descriptors = Introspector.getBeanInfo(configurationClass).getPropertyDescriptors();
Lists.newArrayList(descriptors).stream().forEach(descriptor -> {
Method readMethod = descriptor.getReadMethod();
String propertyName = descriptor.getName();
ConfigurationClassProperty property = readMethod.getAnnotation(ConfigurationClassProperty.class);
if (property != null) {
IdmFormAttributeDto formAttribute = this.convertConfigurationProperty(property);
formAttribute.setCode(propertyName);
// TODO: Better convertors (move from IC and ACC module to the Core)!
initPersistentType(readMethod, formAttribute);
try {
formAttribute.setDefaultValue(this.convertDefaultValue(readMethod.invoke(configurationClassInstance), formAttribute.isMultiple()));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new CoreException("Cannot read value of connector configuration property!", e);
}
properties.add(formAttribute);
}
});
IdmFormDefinitionDto definition = new IdmFormDefinitionDto();
definition.setFormAttributes(properties);
return definition;
} catch (IntrospectionException | InstantiationException | IllegalAccessException e) {
throw new CoreException("Cannot read configuration property!", e);
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultFormDefinitionIntegrationTest method testUpdateDefinitionConfidential.
@Test(expected = ResultCodeException.class)
@Transactional
public void testUpdateDefinitionConfidential() {
IdmFormAttributeDto attribute = new IdmFormAttributeDto("code", "Code", PersistentType.TEXT);
IdmFormDefinitionDto formDefinition = formDefinitionService.updateDefinition(IdmIdentityDto.class, helper.createName(), Lists.newArrayList(attribute));
Assert.assertEquals(1, formDefinition.getFormAttributes().size());
//
// update
attribute.setConfidential(true);
formDefinitionService.updateDefinition(IdmIdentityDto.class, formDefinition.getCode(), Lists.newArrayList(attribute));
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultFormDefinitionIntegrationTest method createDefinition.
/**
* Creates definition
*
* @param name
* @param randomAttributes with random count of attributes
*/
private ResultHolder createDefinition(String code, boolean randomAttributes, boolean log) {
ResultHolder result = new ResultHolder();
IdmFormDefinitionDto formDefinition = new IdmFormDefinitionDto();
formDefinition.setType("test_type");
formDefinition.setCode(code);
if (log) {
LOG.info("Before definition save [{}]", code);
}
long startTime = System.currentTimeMillis();
formDefinition = formDefinitionService.save(formDefinition);
if (log) {
result.createTime = System.currentTimeMillis() - startTime;
LOG.info("--- {}ms: After definition save [{}]", result.createTime, code);
}
int attributeCount = r.nextInt(40);
if (log) {
LOG.info("Before definition [{}] attributes save, attributes count [{}]", code, attributeCount);
}
startTime = System.currentTimeMillis();
for (int i = 0; i < attributeCount; i++) {
IdmFormAttributeDto attributeDefinition = new IdmFormAttributeDto();
attributeDefinition.setFormDefinition(formDefinition.getId());
attributeDefinition.setCode("name_" + i);
attributeDefinition.setName(attributeDefinition.getCode());
attributeDefinition.setPersistentType(PersistentType.TEXT);
attributeDefinition = formAttributeService.save(attributeDefinition);
}
if (log) {
result.childrenCreateTime = (double) System.currentTimeMillis() - startTime;
LOG.info("--- {}ms: After definition [{}] attributes save, attributes count [{}]", result.childrenCreateTime, code, attributeCount);
if (attributeCount > 0) {
result.childrenCreateTime = result.childrenCreateTime / attributeCount;
}
startTime = System.currentTimeMillis();
int realAttributeCount = formAttributeRepository.findByFormDefinition_IdOrderBySeq(formDefinition.getId()).size();
assertEquals(attributeCount, realAttributeCount);
result.childrenLoadTime = System.currentTimeMillis() - startTime;
LOG.info("--- {}ms: After definition [{}] attributes load, attributes count [{}]", result.childrenLoadTime, code, realAttributeCount);
}
result.formDefinition = formDefinition;
return result;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultFormDefinitionIntegrationTest method testDeleteDefinitionWithAttributes.
@Test
@Transactional
public void testDeleteDefinitionWithAttributes() {
IdmFormDefinitionDto formDefinition = createDefinition("one", true, true).formDefinition;
formDefinitionService.delete(formDefinition);
assertEquals(0, formAttributeRepository.findByFormDefinition_IdOrderBySeq(formDefinition.getId()).size());
}
Aggregations