Search in sources :

Example 41 with AttachmentContent

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

the class AttachmentPortletUtils method createAttachmentContent.

public AttachmentContent createAttachmentContent(ResourceRequest request) throws IOException {
    String filename = request.getParameter("fileName");
    AttachmentContent attachmentContent = new AttachmentContent().setContentType("application/octet-stream").setFilename(filename);
    try {
        attachmentContent = client.makeAttachmentContent(attachmentContent);
    } catch (TException e) {
        log.error("Error creating attachment", e);
        attachmentContent = null;
    }
    return attachmentContent;
}
Also used : TException(org.apache.thrift.TException) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)

Example 42 with AttachmentContent

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

the class AttachmentPortletUtils method checkAttachmentExistsFromRequest.

public boolean checkAttachmentExistsFromRequest(ResourceRequest request) {
    ResumableUpload resumableUpload = ResumableUpload.from(request);
    final AttachmentContent attachment = getAttachmentContent(resumableUpload);
    return alreadyHavePart(attachment, resumableUpload);
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)

Example 43 with AttachmentContent

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

the class RemoteAttachmentDownloaderTest method testWithBrokenURL.

@Test
public void testWithBrokenURL() throws Exception {
    AttachmentContent attachmentContent = saveRemoteAttachment(TestUtils.BLACK_HOLE_ADDRESS);
    AttachmentContent attachmentGood = saveRemoteAttachment(url);
    assertThat(repository.getOnlyRemoteAttachments(), hasSize(2));
    assertThat(retrieveRemoteAttachments(DatabaseSettings.getConfiguredHttpClient(), dbName, downloadTimeout), is(1));
    assertThat(repository.getOnlyRemoteAttachments(), hasSize(1));
    assertThat(attachmentConnector.getAttachmentStream(attachmentGood, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentGood.getId())))), hasLength(greaterThan(0l)));
    assertThat(repository.getOnlyRemoteAttachments(), hasSize(1));
    assertThat(retrieveRemoteAttachments(DatabaseSettings.getConfiguredHttpClient(), dbName, downloadTimeout), is(0));
    assertThat(repository.getOnlyRemoteAttachments(), hasSize(1));
    try {
        assertThat(attachmentConnector.getAttachmentStream(attachmentContent, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentContent.getId())))), hasLength(greaterThan(0l)));
        fail("expected exception not thrown");
    } catch (SW360Exception e) {
        assertThat(e.getWhy(), containsString(attachmentContent.getId()));
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Test(org.junit.Test)

Example 44 with AttachmentContent

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

the class RemoteAttachmentDownloaderTest method saveRemoteAttachment.

private AttachmentContent saveRemoteAttachment(String remoteUrl) {
    AttachmentContent attachmentContent = new AttachmentContent().setFilename("testfile").setContentType("text").setOnlyRemote(true).setRemoteUrl(remoteUrl);
    repository.add(attachmentContent);
    garbage.add(attachmentContent.getId());
    return attachmentContent;
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)

Example 45 with AttachmentContent

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

the class RemoteAttachmentDownloaderTest method testIntegration.

@Test
public void testIntegration() throws Exception {
    AttachmentContent attachmentContent = saveRemoteAttachment(url);
    assertThat(retrieveRemoteAttachments(DatabaseSettings.getConfiguredHttpClient(), dbName, downloadTimeout), is(1));
    assertThat(attachmentConnector.getAttachmentStream(attachmentContent, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentContent.getId())))), hasLength(greaterThan(0l)));
    assertThat(retrieveRemoteAttachments(DatabaseSettings.getConfiguredHttpClient(), dbName, downloadTimeout), is(0));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Aggregations

AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)52 InputStream (java.io.InputStream)24 Test (org.junit.Test)20 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)13 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)11 IOException (java.io.IOException)10 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)10 User (org.eclipse.sw360.datahandler.thrift.users.User)10 Release (org.eclipse.sw360.datahandler.thrift.components.Release)8 TException (org.apache.thrift.TException)7 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)6 AttachmentInputStream (org.ektorp.AttachmentInputStream)6 OutputStream (java.io.OutputStream)5 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)5 StringReader (java.io.StringReader)4 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)4 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)3 LicenseInfo (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo)3 PipedInputStream (java.io.PipedInputStream)2