use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method testFillFormValues.
@Test
public void testFillFormValues() {
FormableEntity owner = createTestOwner("test1");
//
// create definition one
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode("name_" + System.currentTimeMillis());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), "t_v1", Lists.newArrayList(attributeDefinitionOne));
attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
//
// create definition two
IdmFormAttributeDto attributeDefinitionTwo = new IdmFormAttributeDto();
attributeDefinitionTwo.setCode("name_" + System.currentTimeMillis());
attributeDefinitionTwo.setName(attributeDefinitionTwo.getCode());
attributeDefinitionTwo.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionTwo = formService.createDefinition(IdmIdentity.class.getCanonicalName(), "t_v2", Lists.newArrayList(attributeDefinitionTwo));
attributeDefinitionTwo = formDefinitionTwo.getMappedAttributeByCode(attributeDefinitionTwo.getCode());
//
IdmFormValueDto value1 = new IdmFormValueDto(attributeDefinitionOne);
value1.setValue(FORM_VALUE_ONE);
IdmFormValueDto value2 = new IdmFormValueDto(attributeDefinitionTwo);
value2.setValue(FORM_VALUE_TWO);
formService.saveValues(owner, formDefinitionOne, Lists.newArrayList(value1));
formService.saveValues(owner, formDefinitionTwo, Lists.newArrayList(value2));
assertEquals(FORM_VALUE_ONE, formService.getValues(owner, formDefinitionOne).get(0).getStringValue());
assertEquals(FORM_VALUE_TWO, formService.getValues(owner, formDefinitionTwo).get(0).getStringValue());
//
// create second owner
FormableEntity owner2 = createTestOwner("test2");
assertEquals(0, formService.getValues(owner2, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
identityService.deleteById(owner2.getId());
assertEquals(0, formService.getValues(owner2, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
formService.deleteValues(owner, formDefinitionOne);
assertEquals(0, formService.getValues(owner, formDefinitionOne).size());
assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
assertEquals(FORM_VALUE_TWO, formService.getValues(owner, formDefinitionTwo).get(0).getStringValue());
identityService.deleteById(owner.getId());
assertEquals(0, formService.getValues(owner, formDefinitionOne).size());
assertEquals(0, formService.getValues(owner, formDefinitionTwo).size());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method testFindTreeNodesByNullAttributeValue.
@Test
public void testFindTreeNodesByNullAttributeValue() {
IdmTreeNodeDto owner = helper.createTreeNode();
IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmTreeNode.class);
IdmFormAttributeDto attribute = formDefinition.getFormAttributes().get(0);
// save values
formService.saveValues(owner.getId(), IdmTreeNode.class, attribute, Lists.newArrayList(FORM_VALUE_ONE));
//
Page<? extends Identifiable> owners = formService.findOwners(IdmTreeNode.class, attribute, FORM_VALUE_ONE, null);
//
assertEquals(1, owners.getTotalElements());
assertEquals(owner.getId(), owners.getContent().get(0).getId());
//
owners = formService.findOwners(IdmTreeNode.class, attribute.getCode(), null, null);
assertEquals(0, owners.getTotalElements());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method testFindOwnersByMultiStringAttributeValue.
@Test
public void testFindOwnersByMultiStringAttributeValue() {
FormableEntity owner = createTestOwner("test12");
FormableEntity ownerTwo = createTestOwner("test13");
FormableEntity ownerThree = createTestOwner("test14");
IdmFormDefinitionDto formDefinition = formService.getDefinition(owner.getClass());
IdmFormAttributeDto attribute = formDefinition.getMappedAttributeByCode(InitDemoData.FORM_ATTRIBUTE_WWW);
// save values
formService.saveValues(owner, attribute, Lists.newArrayList(FORM_VALUE_ONE, FORM_VALUE_TWO));
formService.saveValues(ownerTwo, attribute, Lists.newArrayList(FORM_VALUE_THREE, FORM_VALUE_TWO));
formService.saveValues(ownerThree, attribute, Lists.newArrayList(FORM_VALUE_FOUR, FORM_VALUE_FOUR));
//
Page<? extends Identifiable> owners = formService.findOwners(owner.getClass(), attribute, FORM_VALUE_ONE, null);
//
assertEquals(1, owners.getTotalElements());
assertEquals(owner.getId(), owners.getContent().get(0).getId());
//
owners = formService.findOwners(owner.getClass(), attribute.getCode(), FORM_VALUE_TWO, null);
assertEquals(2, owners.getTotalElements());
//
owners = formService.findOwners(owner.getClass(), attribute, FORM_VALUE_FOUR, null);
assertEquals(1, owners.getTotalElements());
//
identityService.deleteById(owner.getId());
identityService.deleteById(ownerTwo.getId());
identityService.deleteById(ownerThree.getId());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormServiceItegrationTest method testFindAttribute.
@Test
public void testFindAttribute() {
IdmFormAttributeDto attribute = formService.getAttribute(IdmIdentity.class, InitDemoData.FORM_ATTRIBUTE_DATETIME);
//
assertNotNull(attribute);
assertEquals(PersistentType.DATETIME, attribute.getPersistentType());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAssingByContractEavAttrWithoutRecalcualte.
@Test
public void testAssingByContractEavAttrWithoutRecalcualte() {
String testValue = "123!@#" + System.currentTimeMillis();
IdmIdentityDto identity = testHelper.createIdentity();
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
//
IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.SHORTTEXT);
//
IdmRoleDto role = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, createEavAttribute.getId(), testValue);
//
primeContract.setPosition(testValue);
primeContract = identityContractService.save(primeContract);
//
// we need to save eav value, resave identity doesn't enough - we need event eav_save
testHelper.setEavValue(primeContract, createEavAttribute, IdmIdentityContract.class, testValue, PersistentType.SHORTTEXT);
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
//
IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
assertNotNull(identityRoleDto.getRoleTreeNode());
assertEquals(automaticRole.getId(), identityRoleDto.getRoleTreeNode());
assertEquals(automaticRole.getRole(), identityRoleDto.getRole());
//
// change value and recalculate
testHelper.setEavValue(primeContract, createEavAttribute, IdmIdentityContract.class, testValue + "-test", PersistentType.SHORTTEXT);
//
// recalculate isn't needed, is done when save identity
//
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
Aggregations