use of org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testReplacementOfUsageWithoutEmptyUsageData.
@Test
public void testReplacementOfUsageWithoutEmptyUsageData() throws Exception {
AttachmentUsage usage1 = createUsage("p1", "r1", "a11");
usage1.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet("l1", "l2"))));
AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
usage2.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet())));
AttachmentUsage usage3 = createUsage("p1", "r2", "a21");
AttachmentUsage usage4 = createUsage("p2", "r1", "a11");
AttachmentUsage usage5 = createUsage("p3", "r1", "a11");
usage5.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet("l3"))));
handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5));
AttachmentUsage usage6 = createUsage("p1", "r19", "a91");
usage6.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet("l9"))));
handler.replaceAttachmentUsages(Source.projectId("p1"), Lists.newArrayList(usage6));
Assert.assertThat(handler.getUsedAttachments(Source.projectId("p1"), null), Matchers.containsInAnyOrder(usage3, usage6));
Assert.assertThat(handler.getUsedAttachments(Source.projectId("p2"), null), Matchers.containsInAnyOrder(usage4));
Assert.assertThat(handler.getUsedAttachments(Source.projectId("p3"), null), Matchers.containsInAnyOrder(usage5));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testGetAttachmentUsagesWithFilter.
@Test
public void testGetAttachmentUsagesWithFilter() throws Exception {
AttachmentUsage usage1 = createUsage("p1", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
AttachmentUsage usage3 = createUsage("p2", "r2", "a21");
AttachmentUsage usage4 = createUsage("p3", "r1", "a11");
AttachmentUsage usage5 = createUsage("p4", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5));
Assert.assertThat(handler.getAttachmentUsages(Source.releaseId("r1"), "a11", UsageData.licenseInfo(new LicenseInfoUsage())), Matchers.containsInAnyOrder(usage1, usage5));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testUpdateAttachmentUsage.
@Test
public void testUpdateAttachmentUsage() throws Exception {
AttachmentUsage usage1 = new AttachmentUsage();
usage1.setOwner(Source.projectId("r1"));
usage1.setUsedBy(Source.projectId("p1"));
usage1.setAttachmentContentId("a1");
handler.makeAttachmentUsage(usage1);
usage1.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet("l1", "l2"))));
handler.updateAttachmentUsage(usage1);
Assert.assertThat(handler.getAttachmentUsage(usage1.getId()), is(usage1));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testGetUsedAttachmentsWithFilter.
@Test
public void testGetUsedAttachmentsWithFilter() throws Exception {
AttachmentUsage usage1 = createUsage("p1", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
AttachmentUsage usage2 = createUsage("p1", "r1", "a12", UsageData.licenseInfo(new LicenseInfoUsage()));
AttachmentUsage usage3 = createUsage("p1", "r2", "a21");
AttachmentUsage usage4 = createUsage("p3", "r1", "a11");
AttachmentUsage usage5 = createUsage("p4", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5));
Assert.assertThat(handler.getUsedAttachments(Source.projectId("p1"), UsageData.licenseInfo(new LicenseInfoUsage())), Matchers.containsInAnyOrder(usage1, usage2));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage in project sw360portal by sw360.
the class ProjectPortlet method prepareLicenseInfo.
private void prepareLicenseInfo(RenderRequest request, RenderResponse response) throws IOException, PortletException {
User user = UserCacheHolder.getUserFromRequest(request);
String id = request.getParameter(PROJECT_ID);
request.setAttribute(PortalConstants.SW360_USER, user);
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
request.setAttribute(PROJECT_LINK_TABLE_MODE, PROJECT_LINK_TABLE_MODE_LICENSE_INFO);
if (id != null) {
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
Project project = client.getProjectById(id, user);
request.setAttribute(PROJECT, project);
request.setAttribute(DOCUMENT_ID, id);
LicenseInfoService.Iface licenseInfoClient = thriftClients.makeLicenseInfoClient();
List<OutputFormatInfo> outputFormats = licenseInfoClient.getPossibleOutputFormats();
request.setAttribute(PortalConstants.LICENSE_INFO_OUTPUT_FORMATS, outputFormats);
List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, filterAndSortAttachments(SW360Constants.LICENSE_INFO_ATTACHMENT_TYPES), true, user);
request.setAttribute(PROJECT_LIST, mappedProjectLinks);
addProjectBreadcrumb(request, response, project);
AttachmentService.Iface attachmentClient = thriftClients.makeAttachmentClient();
Map<Source, Set<String>> containedAttachments = ProjectPortletUtils.extractContainedAttachments(mappedProjectLinks);
Map<Map<Source, String>, Integer> attachmentUsages = attachmentClient.getAttachmentUsageCount(containedAttachments, UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet())));
Map<String, Integer> countMap = attachmentUsages.entrySet().stream().collect(Collectors.toMap(entry -> {
Entry<Source, String> key = entry.getKey().entrySet().iterator().next();
return key.getKey().getFieldValue() + "_" + key.getValue();
}, entry -> entry.getValue()));
request.setAttribute(ATTACHMENT_USAGE_COUNT_MAP, countMap);
} catch (TException e) {
log.error("Error fetching project from backend!", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
}
}
}
Aggregations