Search in sources :

Example 91 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class AttachmentStreamConnector method downloadRemoteAttachmentAndUpdate.

private AttachmentContent downloadRemoteAttachmentAndUpdate(AttachmentContent attachmentContent) throws SW360Exception {
    final InputStream downloadStream;
    try {
        downloadStream = attachmentContentDownloader.download(attachmentContent, downloadTimeout);
    } catch (IOException e) {
        String msg = "Cannot download attachment " + attachmentContent.getId() + " from URL";
        log.error(msg, e);
        throw new SW360Exception(msg);
    }
    uploadAttachment(attachmentContent, downloadStream);
    attachmentContent = connector.get(AttachmentContent.class, attachmentContent.getId());
    attachmentContent.setOnlyRemote(false);
    connector.update(attachmentContent);
    return attachmentContent;
}
Also used : ConcatClosingInputStream(org.eclipse.sw360.datahandler.common.ConcatClosingInputStream) PipedInputStream(java.io.PipedInputStream) AttachmentInputStream(org.ektorp.AttachmentInputStream) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) IOException(java.io.IOException) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 92 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class PortletUtilsTest method testUpdateAttachmentsFromRequestIdsAreEmpty.

@Test
public void testUpdateAttachmentsFromRequestIdsAreEmpty() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    new TestUserCacheHolder().enable();
    // existing data
    // use immutable set to ensure that set is not changed.
    Set<Attachment> documentAttachments = ImmutableSet.of();
    // fill request
    setAttachmentIds(request);
    // run test
    assertThat(PortletUtils.updateAttachmentsFromRequest(request, documentAttachments), is(empty()));
}
Also used : PortletRequest(javax.portlet.PortletRequest) TestUserCacheHolder(org.eclipse.sw360.portal.TestUserCacheHolder) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 93 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class PortletUtilsTest method setAttachmentCheckStatus.

protected static void setAttachmentCheckStatus(PortletRequest request, CheckStatus... statuses) {
    List<String> stringTypes = Lists.newArrayList();
    for (CheckStatus status : statuses) {
        stringTypes.add("" + status.getValue());
    }
    Mockito.when(request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.CHECK_STATUS.toString())).thenReturn(stringTypes.toArray(new String[] {}));
}
Also used : CheckStatus(org.eclipse.sw360.datahandler.thrift.attachments.CheckStatus)

Example 94 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class PortletUtilsTest method testUpdateAttachmentsFromRequestOneArrayIsNull.

@Test
public void testUpdateAttachmentsFromRequestOneArrayIsNull() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    new TestUserCacheHolder().enable();
    // fill existing data
    // use immutable set to ensure that set is not changed.
    Set<Attachment> documentAttachments = ImmutableSet.of();
    // fill request
    setAttachmentIds(request, "1", "2", "3");
    // run test
    Set<Attachment> updatedAttachments = PortletUtils.updateAttachmentsFromRequest(request, documentAttachments);
    assertTrue(updatedAttachments.isEmpty());
    assertThat(updatedAttachments, is(sameInstance(documentAttachments)));
}
Also used : PortletRequest(javax.portlet.PortletRequest) TestUserCacheHolder(org.eclipse.sw360.portal.TestUserCacheHolder) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 95 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class PortletUtilsTest method testUpdateAttachmentsFromRequestUpdateOnly.

@Test
public void testUpdateAttachmentsFromRequestUpdateOnly() {
    PortletRequest request = Mockito.mock(PortletRequest.class);
    // fill existing data
    User user = createUser("tid", "test@example.org", "tpd");
    new TestUserCacheHolder().enable(user);
    Set<Attachment> documentAttachments = createAttachments(user, "1", "2", "3");
    // fill request
    new TestUserCacheHolder().enable(createUser("cid", "check@example.org", "cpd"));
    setAttachmentIds(request, "1", "2", "3");
    setAttachmentFilenames(request, "A", "B", "C");
    setAttachmentTypes(request, AttachmentType.DOCUMENT, AttachmentType.SOURCE, AttachmentType.DESIGN);
    setAttachmenCreatedComments(request, "CC1", "CC2", "CC3");
    setAttachmentCheckStatus(request, CheckStatus.NOTCHECKED, CheckStatus.ACCEPTED, CheckStatus.ACCEPTED);
    setAttachmentCheckComment(request, "", "CCK2", "CCK3");
    // run tests
    Set<Attachment> updatedAttachments = PortletUtils.updateAttachmentsFromRequest(request, documentAttachments);
    assertThat(updatedAttachments.size(), is(3));
    assertThat(updatedAttachments.stream().map(Attachment::getAttachmentContentId).collect(Collectors.toList()), containsInAnyOrder("1", "2", "3"));
    assertThat(updatedAttachments.stream().map(Attachment::getFilename).collect(Collectors.toList()), containsInAnyOrder("file1", "file2", "file3"));
    assertThat(updatedAttachments.stream().map(Attachment::getAttachmentType).collect(Collectors.toList()), containsInAnyOrder(AttachmentType.DOCUMENT, AttachmentType.SOURCE, AttachmentType.DESIGN));
    assertThat(updatedAttachments.stream().map(Attachment::getCreatedBy).collect(Collectors.toList()), containsInAnyOrder("test@example.org", "test@example.org", "test@example.org"));
    assertThat(updatedAttachments.stream().map(Attachment::getCreatedTeam).collect(Collectors.toList()), containsInAnyOrder("tpd", "tpd", "tpd"));
    assertThat(updatedAttachments.stream().map(Attachment::getCreatedComment).collect(Collectors.toList()), containsInAnyOrder("CC1", "CC2", "CC3"));
    assertThat(updatedAttachments.stream().map(Attachment::getCheckStatus).collect(Collectors.toList()), containsInAnyOrder(CheckStatus.NOTCHECKED, CheckStatus.ACCEPTED, CheckStatus.ACCEPTED));
    assertThat(updatedAttachments.stream().map(Attachment::getCheckedBy).collect(Collectors.toList()), containsInAnyOrder(null, "check@example.org", "check@example.org"));
    assertThat(updatedAttachments.stream().map(Attachment::getCheckedTeam).collect(Collectors.toList()), containsInAnyOrder(null, "cpd", "cpd"));
    assertThat(updatedAttachments.stream().map(Attachment::getCheckedComment).collect(Collectors.toList()), containsInAnyOrder("", "CCK2", "CCK3"));
}
Also used : PortletRequest(javax.portlet.PortletRequest) User(org.eclipse.sw360.datahandler.thrift.users.User) TestUserCacheHolder(org.eclipse.sw360.portal.TestUserCacheHolder) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Aggregations

Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)65 Test (org.junit.Test)40 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)38 User (org.eclipse.sw360.datahandler.thrift.users.User)27 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)22 InputStream (java.io.InputStream)19 Release (org.eclipse.sw360.datahandler.thrift.components.Release)15 IOException (java.io.IOException)13 PortletRequest (javax.portlet.PortletRequest)11 TestUserCacheHolder (org.eclipse.sw360.portal.TestUserCacheHolder)9 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 TException (org.apache.thrift.TException)8 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)8 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)7 OutputStream (java.io.OutputStream)5 AttachmentInputStream (org.ektorp.AttachmentInputStream)5 ResponseEntity (org.springframework.http.ResponseEntity)5 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)4 Maps (com.google.common.collect.Maps)3