Search in sources :

Example 1 with AbstractFormableService

use of eu.bcvsolutions.idm.core.eav.api.service.AbstractFormableService in project CzechIdMng by bcvsolutions.

the class DefaultFormServiceIntegrationTest method testSaveEavWithOwner.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testSaveEavWithOwner() {
    List<FormableDto> owners = new ArrayList<>();
    // implemented authorization policies for eav attributes
    owners.add(getHelper().createIdentity((GuardedString) null));
    // without authorization policies for eav attributes
    owners.add(getHelper().createRole());
    // 
    owners.forEach(owner -> {
        // 
        // create definition with parameter
        IdmFormAttributeDto attribute = new IdmFormAttributeDto();
        String attributeName = getHelper().createName();
        attribute.setCode(attributeName);
        attribute.setName(attributeName);
        attribute.setPersistentType(PersistentType.SHORTTEXT);
        IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(owner.getClass().getCanonicalName(), getHelper().createName(), Lists.newArrayList(attribute));
        attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
        // 
        // fill values
        IdmFormValueDto value = new IdmFormValueDto(attribute);
        value.setValue(FORM_VALUE_ONE);
        owner.getEavs().add(new IdmFormInstanceDto(owner, formDefinitionOne, Lists.newArrayList(value)));
        owner = (FormableDto) ((AbstractFormableService) lookupService.getDtoService(owner.getClass())).save(owner);
        // check form instance values were saved
        owner.getEavs().forEach(formInstance -> {
            Assert.assertFalse(formInstance.getValues().isEmpty());
            formInstance.getValues().forEach(formValue -> {
                Assert.assertNotNull(formValue.getId());
                Assert.assertNotNull(formValue.getCreated());
            });
        });
        // 
        // load saved
        Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
        Assert.assertEquals(1, m.get(attributeName).size());
        Assert.assertEquals(FORM_VALUE_ONE, (m.get(attributeName).get(0)).getValue());
    });
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) AbstractFormableService(eu.bcvsolutions.idm.core.eav.api.service.AbstractFormableService) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) ArrayList(java.util.ArrayList) 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) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

FormableDto (eu.bcvsolutions.idm.core.api.dto.FormableDto)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 AbstractFormableService (eu.bcvsolutions.idm.core.eav.api.service.AbstractFormableService)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