Search in sources :

Example 41 with IdmFormAttributeDto

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());
}
Also used : Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with IdmFormAttributeDto

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));
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with IdmFormAttributeDto

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;
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Example 44 with IdmFormAttributeDto

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());
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 45 with IdmFormAttributeDto

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());
}
Also used : Serializable(java.io.Serializable) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)67 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)40 Test (org.junit.Test)40 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)22 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)15 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)15 Transactional (org.springframework.transaction.annotation.Transactional)12 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)11 FormableEntity (eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity)10 ArrayList (java.util.ArrayList)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)7 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)7 UUID (java.util.UUID)7 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 Serializable (java.io.Serializable)5 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)4 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)4