Search in sources :

Example 26 with Identifiable

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

the class DefaultAttachmentManagerIntegrationTest method testCreateAttachment.

@Test
public void testCreateAttachment() throws IOException {
    Identifiable owner = new TestOwnerEntity(UUID.randomUUID());
    String content = "test data";
    IdmAttachmentDto attachment = prepareAttachment(content);
    // 
    attachmentManager.saveAttachment(owner, attachment);
    List<IdmAttachmentDto> attachments = attachmentManager.getAttachments(owner, null).getContent();
    // 
    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(content.getBytes(AttachableEntity.DEFAULT_CHARSET).length), createdAttachment.getFilesize());
    Assert.assertEquals(1, attachmentManager.getAttachmentVersions(createdAttachment.getId()).size());
    // 
    // get attachment data
    Assert.assertEquals(content, IOUtils.toString(attachmentManager.getAttachmentData(createdAttachment.getId())));
    // 
    // remove owner
    attachmentManager.deleteAttachments(owner);
    // 
    Assert.assertEquals(0, attachmentManager.getAttachments(owner, null).getTotalElements());
}
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)

Example 27 with Identifiable

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

the class DefaultAttachmentManagerIntegrationTest method testAttachmentVersionsWithSameName.

@Test
public void testAttachmentVersionsWithSameName() throws IOException {
    Identifiable owner = new TestOwnerEntity(UUID.randomUUID());
    String contentOne = "test data 1";
    IdmAttachmentDto attachmentOne = prepareAttachment(contentOne);
    attachmentOne = attachmentManager.saveAttachment(owner, attachmentOne);
    String contentTwo = "test data 2";
    IdmAttachmentDto attachmentTwo = prepareAttachment(contentTwo);
    attachmentTwo = attachmentManager.saveAttachmentVersion(owner, attachmentTwo, (IdmAttachmentDto) null);
    String contentThree = "test data 3";
    IdmAttachmentDto attachmentThree = prepareAttachment(contentThree);
    attachmentThree = attachmentManager.saveAttachmentVersion(owner, attachmentThree, (IdmAttachmentDto) null);
    // 
    Assert.assertNotNull(attachmentManager.get(attachmentOne));
    Assert.assertNotNull(attachmentManager.get(attachmentTwo));
    Assert.assertNotNull(attachmentManager.get(attachmentThree));
    // 
    // last version only
    List<IdmAttachmentDto> attachments = attachmentManager.getAttachments(owner, null).getContent();
    Assert.assertEquals(1, attachments.size());
    Assert.assertEquals(contentThree, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(0).getId())));
    // 
    attachments = attachmentManager.getAttachmentVersions(attachmentOne.getId());
    Assert.assertEquals(3, attachments.size());
    // three
    Assert.assertEquals(Integer.valueOf(3), attachments.get(0).getVersionNumber());
    Assert.assertEquals("3.0", attachments.get(0).getVersionLabel());
    Assert.assertNull(attachments.get(0).getNextVersion());
    Assert.assertEquals(attachmentOne.getId(), attachments.get(0).getParent());
    Assert.assertEquals(contentThree, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(0).getId())));
    // two
    Assert.assertEquals(Integer.valueOf(2), attachments.get(1).getVersionNumber());
    Assert.assertEquals("2.0", attachments.get(1).getVersionLabel());
    Assert.assertEquals(attachmentThree.getId(), attachments.get(1).getNextVersion());
    Assert.assertEquals(attachmentOne.getId(), attachments.get(1).getParent());
    Assert.assertEquals(contentTwo, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(1).getId())));
    // one
    Assert.assertEquals(Integer.valueOf(1), attachments.get(2).getVersionNumber());
    Assert.assertEquals("1.0", attachments.get(2).getVersionLabel());
    Assert.assertEquals(attachmentTwo.getId(), attachments.get(2).getNextVersion());
    Assert.assertNull(attachments.get(2).getParent());
    Assert.assertEquals(contentOne, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(2).getId())));
    // 
    attachmentManager.deleteAttachment(attachmentThree);
    // 
    Assert.assertNull(attachmentManager.get(attachmentOne));
    Assert.assertNull(attachmentManager.get(attachmentTwo));
    Assert.assertNull(attachmentManager.get(attachmentThree));
}
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)

Example 28 with Identifiable

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

the class DefaultAttachmentManagerIntegrationTest method testAttachmentVersions.

@Test
@Transactional
public void testAttachmentVersions() throws IOException {
    Identifiable owner = new TestOwnerEntity(UUID.randomUUID());
    String contentOne = "test data 1";
    IdmAttachmentDto attachmentOne = prepareAttachment(contentOne);
    attachmentOne = attachmentManager.saveAttachment(owner, attachmentOne);
    String contentTwo = "test data 2";
    IdmAttachmentDto attachmentTwo = prepareAttachment(contentTwo);
    attachmentTwo = attachmentManager.saveAttachmentVersion(owner, attachmentTwo, attachmentOne);
    String contentThree = "test data 3";
    IdmAttachmentDto attachmentThree = prepareAttachment(contentThree);
    attachmentThree = attachmentManager.saveAttachmentVersion(owner, attachmentThree, attachmentTwo);
    // 
    Assert.assertNotNull(attachmentManager.get(attachmentOne));
    Assert.assertNotNull(attachmentManager.get(attachmentTwo));
    Assert.assertNotNull(attachmentManager.get(attachmentThree));
    // 
    // last version only
    List<IdmAttachmentDto> attachments = attachmentManager.getAttachments(owner, null).getContent();
    Assert.assertEquals(1, attachments.size());
    Assert.assertEquals(contentThree, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(0).getId())));
    // 
    attachments = attachmentManager.getAttachmentVersions(attachmentOne.getId());
    Assert.assertEquals(3, attachments.size());
    // three
    Assert.assertEquals(Integer.valueOf(3), attachments.get(0).getVersionNumber());
    Assert.assertEquals("3.0", attachments.get(0).getVersionLabel());
    Assert.assertNull(attachments.get(0).getNextVersion());
    Assert.assertEquals(attachmentOne.getId(), attachments.get(0).getParent());
    Assert.assertEquals(contentThree, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(0).getId())));
    // two
    Assert.assertEquals(Integer.valueOf(2), attachments.get(1).getVersionNumber());
    Assert.assertEquals("2.0", attachments.get(1).getVersionLabel());
    Assert.assertEquals(attachmentThree.getId(), attachments.get(1).getNextVersion());
    Assert.assertEquals(attachmentOne.getId(), attachments.get(1).getParent());
    Assert.assertEquals(contentTwo, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(1).getId())));
    // one
    Assert.assertEquals(Integer.valueOf(1), attachments.get(2).getVersionNumber());
    Assert.assertEquals("1.0", attachments.get(2).getVersionLabel());
    Assert.assertEquals(attachmentTwo.getId(), attachments.get(2).getNextVersion());
    Assert.assertNull(attachments.get(2).getParent());
    Assert.assertEquals(contentOne, IOUtils.toString(attachmentManager.getAttachmentData(attachments.get(2).getId())));
    // 
    attachmentManager.deleteAttachment(attachmentThree);
    // 
    Assert.assertNull(attachmentManager.get(attachmentOne));
    Assert.assertNull(attachmentManager.get(attachmentTwo));
    Assert.assertNull(attachmentManager.get(attachmentThree));
}
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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with Identifiable

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

the class DefaultRequestManager method makeNiceValue.

private Object makeNiceValue(Object value) {
    if (value == null) {
        return null;
    }
    if (value instanceof Codeable) {
        Codeable codeable = (Codeable) value;
        return codeable.getCode();
    }
    if (value instanceof Niceable) {
        Niceable codeable = (Niceable) value;
        return codeable.getNiceLabel();
    }
    if (value instanceof Identifiable) {
        Identifiable identifiable = (Identifiable) value;
        return identifiable.getId();
    }
    if (value instanceof ConfigurationMap) {
        ConfigurationMap configurationMap = (ConfigurationMap) value;
        Map<String, Serializable> map = configurationMap.toMap();
        return map.toString();
    }
    return value;
}
Also used : Niceable(eu.bcvsolutions.idm.core.api.domain.Niceable) Serializable(java.io.Serializable) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable)

Example 30 with Identifiable

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

the class FormValueDeleteBulkActionIntegrationTest method testDeleteOneRequiredAttributes.

@Test
public void testDeleteOneRequiredAttributes() {
    Identifiable owner = getHelper().createIdentity((GuardedString) null);
    // 
    // create definition with attribute
    IdmFormAttributeDto attribute = new IdmFormAttributeDto();
    String attributeName = getHelper().createName();
    attribute.setCode(attributeName);
    attribute.setName(attribute.getCode());
    attribute.setMultiple(true);
    attribute.setRequired(true);
    attribute.setPersistentType(PersistentType.SHORTTEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attribute));
    attribute = formDefinitionOne.getMappedAttributeByCode(attribute.getCode());
    // 
    // fill values
    formService.saveValues(owner, attribute, Lists.newArrayList(FORM_VALUE_ONE, FORM_VALUE_TWO));
    Map<String, List<IdmFormValueDto>> m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
    // 
    // check value and persistent type
    Assert.assertEquals(2, m.get(attributeName).size());
    Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_ONE)));
    Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_TWO)));
    // 
    IdmBulkActionDto bulkAction = findBulkAction(IdmFormValue.class, FormValueDeleteBulkAction.NAME);
    Set<UUID> ids = new HashSet<>();
    ids.add(m.get(attributeName).stream().filter(v -> v.getValue().equals(FORM_VALUE_ONE)).findFirst().get().getId());
    bulkAction.setIdentifiers(ids);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, 1L, null, null);
    m = formService.getFormInstance(owner, formDefinitionOne).toValueMap();
    // 
    Assert.assertEquals(1, m.get(attributeName).size());
    Assert.assertTrue(m.get(attributeName).stream().anyMatch(v -> v.getValue().equals(FORM_VALUE_TWO)));
}
Also used : ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ObserveLongRunningTaskEndProcessor(eu.bcvsolutions.idm.core.scheduler.ObserveLongRunningTaskEndProcessor) IdmFormValue(eu.bcvsolutions.idm.core.eav.entity.IdmFormValue) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) Map(java.util.Map) After(org.junit.After) Before(org.junit.Before) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) Set(java.util.Set) Test(org.junit.Test) UUID(java.util.UUID) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UUID(java.util.UUID) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) HashSet(java.util.HashSet) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

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