use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentStreamConnectorTest method testGetFullStream.
@Test
public void testGetFullStream() throws Exception {
AttachmentContent attachment = mock(AttachmentContent.class);
when(attachment.isOnlyRemote()).thenReturn(false);
when(attachment.isSetPartsCount()).thenReturn(false);
when(attachment.getFilename()).thenReturn("fil");
String attachmentId = "id";
when(attachment.getId()).thenReturn(attachmentId);
AttachmentInputStream full = mock(AttachmentInputStream.class);
when(connector.getAttachment(attachmentId, "fil")).thenReturn(full);
when(full.read()).thenReturn(1, 2, -1);
InputStream attachmentStream = attachmentStreamConnector.getAttachmentStream(attachment, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentId))));
assertThat(attachmentStream.read(), is(1));
assertThat(attachmentStream.read(), is(2));
assertThat(attachmentStream.read(), is(-1));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentSpecTest method before.
@Before
public void before() throws TException {
List<Attachment> attachmentList = new ArrayList<>();
attachment = new Attachment();
attachment.setAttachmentContentId("76537653");
attachment.setFilename("spring-core-4.3.4.RELEASE.jar");
attachment.setSha1("da373e491d3863477568896089ee9457bc316783");
attachment.setAttachmentType(AttachmentType.BINARY_SELF);
attachment.setCreatedTeam("Clearing Team 1");
attachment.setCreatedComment("please check before Christmas :)");
attachment.setCreatedOn("2016-12-18");
attachment.setCreatedBy("admin@sw360.org");
attachment.setCheckedTeam("Clearing Team 2");
attachment.setCheckedComment("everything looks good");
attachment.setCheckedOn("2016-12-18");
attachment.setCheckStatus(CheckStatus.ACCEPTED);
attachmentList.add(attachment);
Release release = new Release();
release.setId("874687");
release.setName("Spring Core 4.3.4");
release.setCpeid("cpe:/a:pivotal:spring-core:4.3.4:");
release.setReleaseDate("2016-12-07");
release.setVersion("4.3.4");
release.setCreatedOn("2016-12-18");
release.setCreatedBy("admin@sw360.org");
release.setModerators(new HashSet<>(Arrays.asList(testUserId, testUserPassword)));
release.setComponentId("678dstzd8");
release.setClearingState(ClearingState.APPROVED);
AttachmentInfo attachmentInfo = new AttachmentInfo(attachment, release);
given(this.attachmentServiceMock.getAttachmentByIdForUser(eq(attachment.getAttachmentContentId()), anyObject())).willReturn(attachmentInfo);
User user = new User();
user.setId("admin@sw360.org");
user.setEmail("admin@sw360.org");
user.setFullname("John Doe");
given(this.userServiceMock.getUserByEmail("admin@sw360.org")).willReturn(user);
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentConnector method getSha1FromAttachmentContentId.
public String getSha1FromAttachmentContentId(String attachmentContentId) {
InputStream attachmentStream = null;
try {
AttachmentContent attachmentContent = getAttachmentContent(attachmentContentId);
attachmentStream = readAttachmentStream(attachmentContent);
return sha1Hex(attachmentStream);
} catch (SW360Exception e) {
log.error("Problem retrieving content of attachment", e);
return "";
} catch (IOException e) {
log.error("Problem computing the sha1 checksum", e);
return "";
} finally {
closeQuietly(attachmentStream, log);
}
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentConnector method setSha1ForAttachments.
public void setSha1ForAttachments(Set<Attachment> attachments) {
for (Attachment attachment : attachments) {
if (isNullOrEmpty(attachment.getSha1())) {
String sha1 = getSha1FromAttachmentContentId(attachment.getAttachmentContentId());
attachment.setSha1(sha1);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class ProjectPortletUtils method extractContainedAttachments.
/**
* Walks through a list of project links and extracts all release attachments
* with their owner. The returned map is a mapping from a release to its
* attachment content ids.
*
* @param projectLinks
* list of project links to walk through
*
* @return map of releases and their attachment content ids
*/
public static Map<Source, Set<String>> extractContainedAttachments(Collection<ProjectLink> projectLinks) {
Map<Source, Set<String>> attachments = Maps.newHashMap();
for (ProjectLink projectLink : projectLinks) {
for (ReleaseLink releaseLink : projectLink.linkedReleases) {
Set<String> attachmentIds = attachments.getOrDefault(Source.releaseId(releaseLink.getId()), Sets.newHashSet());
attachmentIds.addAll(releaseLink.getAttachments().stream().map(a -> a.getAttachmentContentId()).collect(Collectors.toList()));
attachments.put(Source.releaseId(releaseLink.getId()), attachmentIds);
}
}
return attachments;
}
Aggregations