Search in sources :

Example 51 with IdmFormDefinitionDto

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

the class DefaultFormDefinitionIntegrationTest method testSwitchMainDefinition.

@Test
@Transactional
public void testSwitchMainDefinition() {
    String type = helper.createName();
    IdmFormDefinitionDto formDefinitionOne = new IdmFormDefinitionDto();
    formDefinitionOne.setType(type);
    formDefinitionOne.setCode(helper.createName());
    formDefinitionOne.setMain(true);
    formDefinitionOne = formDefinitionService.save(formDefinitionOne);
    Assert.assertTrue(formDefinitionOne.isMain());
    formDefinitionOne = formDefinitionService.save(formDefinitionOne);
    Assert.assertTrue(formDefinitionOne.isMain());
    // 
    IdmFormDefinitionDto formDefinitionTwo = new IdmFormDefinitionDto();
    formDefinitionTwo.setType(type);
    formDefinitionTwo.setCode(helper.createName());
    formDefinitionTwo.setMain(true);
    formDefinitionTwo = formDefinitionService.save(formDefinitionTwo);
    formDefinitionOne = formDefinitionService.get(formDefinitionOne);
    // 
    Assert.assertFalse(formDefinitionOne.isMain());
    Assert.assertTrue(formDefinitionTwo.isMain());
}
Also used : IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with IdmFormDefinitionDto

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

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

the class DefaultFormServiceItegrationTest method testSaveMultipleAttributeValuesToSingleAttribute.

@Test(expected = IllegalArgumentException.class)
public void testSaveMultipleAttributeValuesToSingleAttribute() {
    FormableEntity owner = createTestOwner("test9");
    IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
    IdmFormAttributeDto attribute = formDefinition.getMappedAttributeByCode(InitDemoData.FORM_ATTRIBUTE_PHONE);
    // save value
    formService.saveValues(owner, attribute, Lists.newArrayList(FORM_VALUE_ONE, FORM_VALUE_TWO));
    // 
    identityService.deleteById(owner.getId());
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 54 with IdmFormDefinitionDto

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

the class DefaultFormServiceItegrationTest method testFindOwnersByUuidAttributeValue.

@Test
public void testFindOwnersByUuidAttributeValue() {
    IdmIdentityDto owner = helper.createIdentity();
    IdmIdentityDto ownerTwo = helper.createIdentity();
    IdmFormDefinitionDto formDefinition = formService.getDefinition(owner.getClass());
    IdmFormAttributeDto attribute = formDefinition.getMappedAttributeByCode(InitDemoData.FORM_ATTRIBUTE_UUID);
    // save values
    UUID one = UUID.randomUUID();
    UUID two = UUID.randomUUID();
    formService.saveValues(owner, attribute, Lists.newArrayList(one));
    formService.saveValues(ownerTwo, attribute, Lists.newArrayList(two));
    // 
    Page<? extends Identifiable> owners = formService.findOwners(owner.getClass(), InitDemoData.FORM_ATTRIBUTE_UUID, one, null);
    // 
    assertEquals(1, owners.getTotalElements());
    assertEquals(owner.getId(), owners.getContent().get(0).getId());
    // 
    owners = formService.findOwners(owner.getClass(), InitDemoData.FORM_ATTRIBUTE_UUID, two, null);
    // 
    assertEquals(1, owners.getTotalElements());
    assertEquals(ownerTwo.getId(), owners.getContent().get(0).getId());
    // 
    identityService.deleteById(owner.getId());
    identityService.deleteById(ownerTwo.getId());
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 55 with IdmFormDefinitionDto

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

the class DefaultFormServiceItegrationTest method testFindOwnersByStringAttributeValue.

@Test
public void testFindOwnersByStringAttributeValue() {
    IdmIdentityDto owner = helper.createIdentity();
    IdmIdentityDto ownerTwo = helper.createIdentity();
    IdmIdentityDto ownerThree = helper.createIdentity();
    IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
    IdmFormAttributeDto attribute = formDefinition.getMappedAttributeByCode(InitDemoData.FORM_ATTRIBUTE_PHONE);
    // save values
    formService.saveValues(owner.getId(), IdmIdentity.class, attribute, Lists.newArrayList(FORM_VALUE_ONE));
    formService.saveValues(ownerTwo.getId(), IdmIdentity.class, attribute, Lists.newArrayList(FORM_VALUE_TWO));
    formService.saveValues(ownerThree.getId(), IdmIdentity.class, attribute, Lists.newArrayList(FORM_VALUE_FOUR));
    // 
    Page<? extends Identifiable> owners = formService.findOwners(IdmIdentity.class, attribute, FORM_VALUE_ONE, null);
    // 
    assertEquals(1, owners.getTotalElements());
    assertEquals(owner.getId(), owners.getContent().get(0).getId());
    // 
    owners = formService.findOwners(IdmIdentity.class, attribute.getCode(), FORM_VALUE_TWO, null);
    assertEquals(1, owners.getTotalElements());
    // 
    owners = formService.findOwners(IdmIdentity.class, attribute, FORM_VALUE_FOUR, null);
    assertEquals(1, owners.getTotalElements());
    // 
    identityService.delete(owner);
    identityService.delete(ownerTwo);
    identityService.delete(ownerThree);
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)71 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)35 Test (org.junit.Test)35 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)33 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)23 Transactional (org.springframework.transaction.annotation.Transactional)18 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)16 FormableEntity (eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity)14 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)13 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)12 ArrayList (java.util.ArrayList)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 UUID (java.util.UUID)8 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)7 List (java.util.List)7 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)6 Serializable (java.io.Serializable)6