Search in sources :

Example 1 with IdmAttachmentDto

use of eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto in project CzechIdMng by bcvsolutions.

the class AbstractReportExecutor method generate.

@Override
public RptReportDto generate(RptReportDto report) {
    try {
        IdmAttachmentDto data = generateData(report);
        report.setData(data.getId());
        return report;
    } catch (Exception ex) {
        // TODO: better exception
        throw new CoreException(ex);
    }
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with IdmAttachmentDto

use of eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto in project CzechIdMng by bcvsolutions.

the class AbstractReportExecutor method createAttachment.

/**
 * Saves (temporrary) file as attachment
 *
 * @param report
 * @param data
 * @return
 * @throws FileNotFoundException
 */
protected IdmAttachmentDto createAttachment(RptReportDto report, InputStream jsonData) throws FileNotFoundException {
    IdmAttachmentDto attachmentDto = new IdmAttachmentDto();
    attachmentDto.setDescription(getDescription());
    attachmentDto.setName(getName());
    attachmentDto.setMimetype(MediaType.APPLICATION_JSON_UTF8.toString());
    attachmentDto.setInputData(jsonData);
    return attachmentManager.saveAttachment(report, attachmentDto);
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)

Example 3 with IdmAttachmentDto

use of eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto in project CzechIdMng by bcvsolutions.

the class TestFilterReportExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    try {
        IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
        String username = (String) formInstance.toSinglePersistentValue(IdmIdentity_.username.getName());
        List<IdmIdentityDto> results = TestReportExecutor.identities.stream().filter(identity -> {
            return StringUtils.isEmpty(username) || username.equals(identity.getUsername());
        }).collect(Collectors.toList());
        return createAttachment(report, IOUtils.toInputStream(getMapper().writeValueAsString(results)));
    } catch (FileNotFoundException | JsonProcessingException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Description(org.springframework.context.annotation.Description) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) AbstractReportExecutor(eu.bcvsolutions.idm.rpt.api.executor.AbstractReportExecutor) FileNotFoundException(java.io.FileNotFoundException) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) FileNotFoundException(java.io.FileNotFoundException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with IdmAttachmentDto

use of eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManagerIntegrationTest method testCreateAttachment.

@Test
@Transactional
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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with IdmAttachmentDto

use of eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManagerIntegrationTest method testAttachmentVersionsWithSameName.

@Test
@Transactional
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) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)8 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 Test (org.junit.Test)4 Transactional (org.springframework.transaction.annotation.Transactional)4 FileNotFoundException (java.io.FileNotFoundException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Lists (com.google.common.collect.Lists)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)1 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)1 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)1 IdmIdentity_ (eu.bcvsolutions.idm.core.model.entity.IdmIdentity_)1 RptReportDto (eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)1 ReportGenerateException (eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException)1 AbstractReportExecutor (eu.bcvsolutions.idm.rpt.api.executor.AbstractReportExecutor)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IOUtils (org.apache.commons.io.IOUtils)1