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;
}
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);
}
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()));
}
}
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;
}
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));
}
Aggregations