use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultCommonFormServiceIntegrationTest method testCreateForm.
@Test
@Transactional
public void testCreateForm() {
Codeable owner = helper.createIdentity();
IdmFormAttributeDto attribute = createDefinition();
IdmFormValueDto formValue = new IdmFormValueDto(attribute);
formValue.setValue("testOne");
IdmFormDto formOne = new IdmFormDto();
formOne.setName("test");
formOne.setFormDefinition(attribute.getFormDefinition());
formOne.setValues(Lists.newArrayList(formValue));
formOne.setOwnerCode(owner.getCode());
//
commonFormService.saveForm(owner, formOne);
formOne = commonFormService.getForms(owner).get(0);
//
Assert.assertNotNull(formOne.getId());
Assert.assertEquals(owner.getCode(), formOne.getOwnerCode());
Assert.assertEquals(lookupService.lookupEntity(owner.getClass(), owner.getId()).getClass().getCanonicalName(), formOne.getOwnerType());
Assert.assertEquals(owner.getId(), formOne.getOwnerId());
Assert.assertEquals(formValue.getValue(), formOne.getValues().get(0).getValue());
//
commonFormService.deleteForms(owner);
Assert.assertTrue(commonFormService.getForms(owner).isEmpty());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto 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.IdmFormAttributeDto 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.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method testFindOwnersByShortTextAttributeValue.
@Test
@Transactional
public void testFindOwnersByShortTextAttributeValue() {
IdmIdentityDto owner = helper.createIdentity();
IdmIdentityDto ownerTwo = helper.createIdentity();
IdmFormAttributeDto shortTextAttr = new IdmFormAttributeDto();
String shortTextAttrName = helper.createName();
shortTextAttr.setCode(shortTextAttrName);
shortTextAttr.setName(shortTextAttrName);
shortTextAttr.setPersistentType(PersistentType.SHORTTEXT);
IdmFormAttributeDto attribute = formService.saveAttribute(owner.getClass(), shortTextAttr);
// save values
String one = "one";
String two = "two";
formService.saveValues(owner, attribute, Lists.newArrayList(one));
formService.saveValues(ownerTwo, attribute, Lists.newArrayList(two));
//
Page<? extends Identifiable> owners = formService.findOwners(owner.getClass(), shortTextAttrName, one, null);
//
assertEquals(1, owners.getTotalElements());
assertEquals(owner.getId(), owners.getContent().get(0).getId());
//
owners = formService.findOwners(owner.getClass(), shortTextAttrName, two, null);
//
assertEquals(1, owners.getTotalElements());
assertEquals(ownerTwo.getId(), owners.getContent().get(0).getId());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method testMultipleValues.
/**
* Test multi values order and removal
*/
@Test
public void testMultipleValues() {
FormableEntity owner = createTestOwner("test3");
//
// create definition with multi parameter
IdmFormAttributeDto multiAttribite = new IdmFormAttributeDto();
String multiAttributeName = "name_" + System.currentTimeMillis();
multiAttribite.setCode(multiAttributeName);
multiAttribite.setName(multiAttribite.getCode());
multiAttribite.setPersistentType(PersistentType.TEXT);
multiAttribite.setMultiple(true);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), "t_v3", Lists.newArrayList(multiAttribite));
multiAttribite = formDefinitionOne.getMappedAttributeByCode(multiAttribite.getCode());
//
// fill values
IdmFormValueDto value1 = new IdmFormValueDto(multiAttribite);
value1.setValue(FORM_VALUE_ONE);
value1.setSeq((short) 0);
IdmFormValueDto value2 = new IdmFormValueDto(multiAttribite);
value2.setValue(FORM_VALUE_TWO);
value2.setSeq((short) 1);
formService.saveValues(owner, formDefinitionOne, Lists.newArrayList(value1, value2));
Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
// check order
assertEquals(2, m.get(multiAttributeName).size());
assertEquals(FORM_VALUE_ONE, (m.get(multiAttributeName).get(0)).getValue());
assertEquals(FORM_VALUE_TWO, (m.get(multiAttributeName).get(1)).getValue());
formService.saveValues(owner, formDefinitionOne, Lists.newArrayList(value1));
// check delete unsaved multiple values
m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
assertEquals(1, m.get(multiAttributeName).size());
assertEquals(FORM_VALUE_ONE, m.get(multiAttributeName).get(0).getValue());
// checks value map
Map<String, ? extends List<Serializable>> v = formService.getFormInstance(owner, formDefinitionOne).toPersistentValueMap();
assertEquals(1, v.get(multiAttributeName).size());
assertEquals(FORM_VALUE_ONE, v.get(multiAttributeName).get(0));
//
identityService.deleteById(owner.getId());
}
Aggregations