Search in sources :

Example 11 with FormableEntity

use of eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity in project CzechIdMng by bcvsolutions.

the class DefaultFormService method getFormInstance.

@Override
@Transactional(readOnly = true)
public IdmFormInstanceDto getFormInstance(Identifiable owner, IdmFormDefinitionDto formDefinition) {
    Assert.notNull(owner, "Form values owner is required!");
    Assert.notNull(owner.getId(), "Owner id is required!");
    FormableEntity ownerEntity = getOwnerEntity(owner);
    formDefinition = checkDefaultDefinition(owner.getClass(), formDefinition);
    // 
    FormValueService<FormableEntity> formValueService = getFormValueService(owner);
    // 
    return new IdmFormInstanceDto(ownerEntity, formDefinition, formValueService.getValues(ownerEntity, formDefinition));
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with FormableEntity

use of eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity in project CzechIdMng by bcvsolutions.

the class DefaultFormService method deleteValues.

@Override
@Transactional
public void deleteValues(Identifiable owner, IdmFormDefinitionDto formDefinition) {
    Assert.notNull(owner, "Form values owner is required!");
    Assert.notNull(owner.getId(), "Owner id is required!");
    FormableEntity ownerEntity = getOwnerEntity(owner);
    // 
    FormValueService<FormableEntity> formValueService = getFormValueService(ownerEntity);
    formValueService.deleteValues(ownerEntity, formDefinition);
}
Also used : FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with FormableEntity

use of eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity in project CzechIdMng by bcvsolutions.

the class DefaultFormService method deleteValues.

@Override
@Transactional
public void deleteValues(Identifiable owner, IdmFormAttributeDto attribute) {
    Assert.notNull(owner, "Form values owner is required!");
    Assert.notNull(owner.getId(), "Owner id is required!");
    Assert.notNull(attribute, "Form attribute definition is required!");
    // 
    FormableEntity ownerEntity = getOwnerEntity(owner);
    FormValueService<FormableEntity> formValueService = getFormValueService(ownerEntity);
    formValueService.deleteValues(ownerEntity, attribute);
}
Also used : FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with FormableEntity

use of eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity 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 15 with FormableEntity

use of eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity in project CzechIdMng by bcvsolutions.

the class DefaultFormServiceItegrationTest method testOwnerWithoutId.

@Test(expected = IllegalArgumentException.class)
public void testOwnerWithoutId() {
    // unpersisted identity
    FormableEntity owner = new IdmIdentity();
    formService.getValues(owner);
}
Also used : 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

FormableEntity (eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity)22 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)15 Test (org.junit.Test)15 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)14 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)12 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)9 Transactional (org.springframework.transaction.annotation.Transactional)6 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)5 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)1 ConfigurationClassProperty (eu.bcvsolutions.idm.core.api.domain.ConfigurationClassProperty)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)1 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)1 CoreEvent (eu.bcvsolutions.idm.core.api.event.CoreEvent)1