Search in sources :

Example 1 with DefaultFormableFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.DefaultFormableFilter in project CzechIdMng by bcvsolutions.

the class DefaultFormServiceIntegrationTest method testFindFormInstances.

@Test
public void testFindFormInstances() {
    IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(getHelper().createName(), getHelper().createName(), PersistentType.SHORTTEXT);
    IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(getHelper().createName(), getHelper().createName(), PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeOne, attributeTwo));
    attributeOne = formDefinition.getMappedAttributeByCode(attributeOne.getCode());
    attributeTwo = formDefinition.getMappedAttributeByCode(attributeTwo.getCode());
    // create owner
    IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
    // fill values
    IdmFormValueDto valueOne = new IdmFormValueDto(attributeOne);
    valueOne.setValue(FORM_VALUE_ONE);
    IdmFormValueDto valueTwo = new IdmFormValueDto(attributeTwo);
    valueTwo.setValue(FORM_VALUE_TWO);
    owner.getEavs().add(new IdmFormInstanceDto(owner, formDefinition, Lists.newArrayList(valueOne, valueTwo)));
    identityService.save(owner);
    // 
    // find saved values without filter
    Map<String, List<IdmFormValueDto>> m = formService.findFormInstance(owner, formDefinition, null).toValueMap();
    Assert.assertEquals(FORM_VALUE_ONE, (m.get(attributeOne.getCode()).get(0)).getValue());
    Assert.assertEquals(FORM_VALUE_TWO, (m.get(attributeTwo.getCode()).get(0)).getValue());
    // 
    m = formService.findFormInstances(owner, null).stream().filter(fi -> fi.getFormDefinition().equals(formDefinition)).findFirst().get().toValueMap();
    Assert.assertEquals(FORM_VALUE_ONE, (m.get(attributeOne.getCode()).get(0)).getValue());
    Assert.assertEquals(FORM_VALUE_TWO, (m.get(attributeTwo.getCode()).get(0)).getValue());
    // 
    // find saved values with filter
    DefaultFormableFilter filter = new DefaultFormableFilter();
    FormDefinitionAttributes attributes = new FormDefinitionAttributes();
    attributes.setDefinition(formDefinition.getId());
    attributes.getAttributes().add(attributeOne.getId());
    filter.setFormDefinitionAttributes(Lists.newArrayList(attributes));
    List<IdmFormValueDto> values = formService.findFormInstances(owner, filter).get(0).getValues();
    Assert.assertEquals(1, values.size());
    Assert.assertEquals(FORM_VALUE_ONE, values.get(0).getValue());
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) DefaultFormableFilter(eu.bcvsolutions.idm.core.api.dto.filter.DefaultFormableFilter) 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) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 DefaultFormableFilter (eu.bcvsolutions.idm.core.api.dto.filter.DefaultFormableFilter)1 FormDefinitionAttributes (eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes)1 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)1 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)1 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)1 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)1 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1