Search in sources :

Example 6 with FormDefinitionAttributes

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

FormDefinitionAttributes (eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes)6 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)4 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)4 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)4 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 UUID (java.util.UUID)3 Test (org.junit.Test)3 IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)2 IdentityProjectionEvent (eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent)2 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ValueWrapper (eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper)1 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)1 ConfigurationClassProperty (eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty)1