Search in sources :

Example 26 with IdmFormValueDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.

the class AbstractFormValueUnitTest method testDateValueAsDate.

@Test
public void testDateValueAsDate() {
    IdmFormValueDto formValue = new IdmFormValueDto();
    formValue.setPersistentType(PersistentType.DATETIME);
    DateTime current = new DateTime();
    formValue.setValue(current.toDate());
    assertEquals(current, formValue.getValue());
}
Also used : IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) DateTime(org.joda.time.DateTime) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 27 with IdmFormValueDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto 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 28 with IdmFormValueDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto 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)

Example 29 with IdmFormValueDto

use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.

the class DefaultFormServiceItegrationTest method testSaveValuesByOwnerId.

@Test
public void testSaveValuesByOwnerId() {
    FormableEntity owner = createTestOwner("test8");
    IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
    IdmFormAttributeDto attribute = formDefinition.getMappedAttributeByCode(InitDemoData.FORM_ATTRIBUTE_PHONE);
    // save value
    List<IdmFormValueDto> attributeValues = formService.saveValues((UUID) owner.getId(), owner.getClass(), attribute, Lists.newArrayList(FORM_VALUE_ONE));
    assertEquals(1, attributeValues.size());
    assertEquals(FORM_VALUE_ONE, attributeValues.get(0).getValue());
    List<IdmFormValueDto> getValues = formService.getValues((UUID) owner.getId(), owner.getClass(), attribute);
    assertEquals(1, getValues.size());
    assertEquals(FORM_VALUE_ONE, ((IdmFormValueDto) getValues.get(0)).getValue());
    // 
    identityService.deleteById(owner.getId());
}
Also used : 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) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 30 with IdmFormValueDto

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

IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)39 Test (org.junit.Test)24 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)23 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)19 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)13 FormableEntity (eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity)12 Transactional (org.springframework.transaction.annotation.Transactional)11 ArrayList (java.util.ArrayList)10 List (java.util.List)9 UUID (java.util.UUID)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)8 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)6 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)6 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)5 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 SysConnectorKeyDto (eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto)3 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)3 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)3