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;
}
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()));
}
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[] {}));
}
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)));
}
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"));
}
Aggregations