Search in sources :

Example 41 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultFormServiceIntegrationTest method testFindOwnersByDateAttributeValue.

@Test
public void testFindOwnersByDateAttributeValue() {
    Identifiable owner = getHelper().createIdentity((GuardedString) null);
    Identifiable ownerTwo = getHelper().createIdentity((GuardedString) null);
    IdmFormDefinitionDto formDefinition = formService.getDefinition(owner.getClass());
    IdmFormAttributeDto attribute = formDefinition.getMappedAttributeByCode(InitDemoDataProcessor.FORM_ATTRIBUTE_DATETIME);
    // save values
    ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
    ZonedDateTime tomorrow = now.plusDays(1).truncatedTo(ChronoUnit.MILLIS);
    formService.saveValues(owner, attribute, Lists.newArrayList(now));
    formService.saveValues(ownerTwo, attribute, Lists.newArrayList(tomorrow));
    // 
    Page<? extends Identifiable> owners = formService.findOwners(owner.getClass(), InitDemoDataProcessor.FORM_ATTRIBUTE_DATETIME, now, null);
    // 
    assertEquals(1, owners.getTotalElements());
    assertEquals(owner.getId(), owners.getContent().get(0).getId());
    // 
    owners = formService.findOwners(owner.getClass(), InitDemoDataProcessor.FORM_ATTRIBUTE_DATETIME, tomorrow, 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) ZonedDateTime(java.time.ZonedDateTime) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 42 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultFormServiceIntegrationTest method testOwnerWithoutId.

@Test(expected = IllegalArgumentException.class)
public void testOwnerWithoutId() {
    // unpersisted identity
    Identifiable owner = new IdmIdentity();
    formService.getValues(owner);
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 43 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultFormServiceIntegrationTest method testMoveValueIntoOtherOwner.

@Test
public void testMoveValueIntoOtherOwner() {
    Identifiable ownerOne = getHelper().createIdentity((GuardedString) null);
    Identifiable ownerTwo = getHelper().createIdentity((GuardedString) null);
    // 
    // create definition with attribute
    IdmFormAttributeDto attribute = new IdmFormAttributeDto();
    String attributeName = getHelper().createName();
    attribute.setCode(attributeName);
    attribute.setName(attribute.getCode());
    attribute.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attribute));
    attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
    // 
    // fill values
    List<IdmFormValueDto> savedValueOne = formService.saveValues(ownerOne, attribute, Lists.newArrayList(FORM_VALUE_ONE));
    List<IdmFormValueDto> savedValueTwo = formService.saveValues(ownerTwo, formDefinitionOne, savedValueOne);
    List<IdmFormValueDto> getValueOne = formService.getValues(ownerOne, attribute);
    // both values should be saved
    Assert.assertEquals(1, getValueOne.size());
    Assert.assertEquals(1, savedValueTwo.size());
    Assert.assertNotEquals(getValueOne.get(0).getId(), savedValueTwo.get(0).getId());
    // 
    // prevent to move value for original owner
    List<IdmFormValueDto> getValueAfterMoveOne = formService.getValues(ownerOne, attribute);
    Assert.assertEquals(1, getValueAfterMoveOne.size());
    Assert.assertEquals(getValueOne.get(0).getId(), getValueAfterMoveOne.get(0).getId());
}
Also used : 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) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 44 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultFormServiceIntegrationTest method testFillFormValues.

@Test
public void testFillFormValues() {
    Identifiable owner = getHelper().createIdentity((GuardedString) null);
    // 
    // create definition one
    IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
    attributeDefinitionOne.setCode(getHelper().createName());
    attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
    attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
    attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
    // 
    // create definition two
    IdmFormAttributeDto attributeDefinitionTwo = new IdmFormAttributeDto();
    attributeDefinitionTwo.setCode(getHelper().createName());
    attributeDefinitionTwo.setName(attributeDefinitionTwo.getCode());
    attributeDefinitionTwo.setPersistentType(PersistentType.TEXT);
    IdmFormDefinitionDto formDefinitionTwo = formService.createDefinition(IdmIdentity.class.getCanonicalName(), getHelper().createName(), Lists.newArrayList(attributeDefinitionTwo));
    attributeDefinitionTwo = formDefinitionTwo.getMappedAttributeByCode(attributeDefinitionTwo.getCode());
    // 
    IdmFormValueDto value1 = new IdmFormValueDto(attributeDefinitionOne);
    value1.setValue(FORM_VALUE_ONE);
    IdmFormValueDto value2 = new IdmFormValueDto(attributeDefinitionTwo);
    value2.setValue(FORM_VALUE_TWO);
    formService.saveValues(owner, formDefinitionOne, Lists.newArrayList(value1));
    formService.saveValues(owner, formDefinitionTwo, Lists.newArrayList(value2));
    assertEquals(FORM_VALUE_ONE, formService.getValues(owner, formDefinitionOne).get(0).getStringValue());
    assertEquals(FORM_VALUE_TWO, formService.getValues(owner, formDefinitionTwo).get(0).getStringValue());
    // 
    // create second owner
    Identifiable owner2 = getHelper().createIdentity((GuardedString) null);
    assertEquals(0, formService.getValues(owner2, formDefinitionOne).size());
    assertEquals(1, formService.getValues(owner, formDefinitionOne).size());
    assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
    identityService.deleteById(owner2.getId());
    // TODO: remove this test? - not exists entity has to be given
    assertEquals(0, formService.getValues(new IdmIdentity((UUID) owner2.getId()), formDefinitionOne).size());
    assertEquals(1, formService.getValues(owner, formDefinitionOne).size());
    assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
    formService.deleteValues(owner, formDefinitionOne);
    assertEquals(0, formService.getValues(owner, formDefinitionOne).size());
    assertEquals(1, formService.getValues(owner, formDefinitionTwo).size());
    assertEquals(FORM_VALUE_TWO, formService.getValues(owner, formDefinitionTwo).get(0).getStringValue());
    identityService.deleteById(owner.getId());
    assertEquals(0, formService.getValues(new IdmIdentity((UUID) owner.getId()), formDefinitionOne).size());
    assertEquals(0, formService.getValues(new IdmIdentity((UUID) owner.getId()), formDefinitionTwo).size());
}
Also used : 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) UUID(java.util.UUID) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 45 with Identifiable

use of eu.bcvsolutions.idm.core.api.domain.Identifiable in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManagerIntegrationTest method testUpdateAttachment.

@Test
public void testUpdateAttachment() {
    Identifiable owner = new TestOwnerEntity(UUID.randomUUID());
    String contentOne = "test data 1";
    IdmAttachmentDto attachment = prepareAttachment(contentOne);
    attachment = attachmentManager.saveAttachment(owner, attachment);
    // 
    String updatedContent = "update";
    attachment.setInputData(IOUtils.toInputStream(updatedContent));
    attachment.setDescription(updatedContent);
    attachment = attachmentManager.updateAttachment(attachment);
    // 
    List<IdmAttachmentDto> attachments = attachmentManager.getAttachmentVersions(attachment.getId());
    // 
    Assert.assertEquals(1, attachments.size());
    IdmAttachmentDto createdAttachment = attachments.get(0);
    Assert.assertEquals(attachment.getName(), createdAttachment.getName());
    Assert.assertEquals(attachment.getMimetype(), createdAttachment.getMimetype());
    Assert.assertEquals(owner.getClass().getCanonicalName(), createdAttachment.getOwnerType());
    Assert.assertEquals(owner.getId(), createdAttachment.getOwnerId());
    Assert.assertNotNull(createdAttachment.getContentId());
    Assert.assertNotNull(createdAttachment.getContentPath());
    Assert.assertNull(createdAttachment.getParent());
    Assert.assertNull(createdAttachment.getNextVersion());
    Assert.assertEquals(Integer.valueOf(1), createdAttachment.getVersionNumber());
    Assert.assertEquals("1.0", createdAttachment.getVersionLabel());
    Assert.assertEquals(AttachableEntity.DEFAULT_ENCODING, createdAttachment.getEncoding());
    Assert.assertEquals(Long.valueOf(updatedContent.getBytes(AttachableEntity.DEFAULT_CHARSET).length), createdAttachment.getFilesize());
    Assert.assertEquals(updatedContent, createdAttachment.getDescription());
    // 
    attachmentManager.deleteAttachment(attachment);
    // 
    Assert.assertEquals(0, attachmentManager.getAttachmentVersions(attachment.getId()).size());
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)51 Test (org.junit.Test)37 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)32 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)31 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)27 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)24 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)24 List (java.util.List)19 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)17 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)16 UUID (java.util.UUID)16 ArrayList (java.util.ArrayList)14 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)12 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Lists (com.google.common.collect.Lists)10 Serializable (java.io.Serializable)10 HashSet (java.util.HashSet)10 Map (java.util.Map)10 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)9