Search in sources :

Example 6 with LicenseInfoUsage

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

the class ProjectPortletUtils method makeAttachmentUsages.

public static List<AttachmentUsage> makeAttachmentUsages(Project project, Map<String, Set<String>> selectedReleaseAndAttachmentIds, Map<String, Set<LicenseNameWithText>> excludedLicensesPerAttachmentId) {
    List<AttachmentUsage> attachmentUsages = Lists.newArrayList();
    for (String releaseId : selectedReleaseAndAttachmentIds.keySet()) {
        for (String attachmentContentId : selectedReleaseAndAttachmentIds.get(releaseId)) {
            AttachmentUsage usage = new AttachmentUsage();
            usage.setUsedBy(Source.projectId(project.getId()));
            usage.setOwner(Source.releaseId(releaseId));
            usage.setAttachmentContentId(attachmentContentId);
            Set<String> licenseIds = CommonUtils.nullToEmptySet(excludedLicensesPerAttachmentId.get(attachmentContentId)).stream().filter(LicenseNameWithText::isSetLicenseName).map(LicenseNameWithText::getLicenseName).collect(Collectors.toSet());
            usage.setUsageData(UsageData.licenseInfo(new LicenseInfoUsage(licenseIds)));
            attachmentUsages.add(usage);
        }
    }
    return attachmentUsages;
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)

Example 7 with LicenseInfoUsage

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

the class AttachmentHandlerTest method testDeleteAttachmentUsagesByUsageDataTypeWithNonEmptyType.

@Test
public void testDeleteAttachmentUsagesByUsageDataTypeWithNonEmptyType() 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));
    handler.deleteAttachmentUsagesByUsageDataType(Source.projectId("p1"), UsageData.licenseInfo(new LicenseInfoUsage(Collections.emptySet())));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p1"), null), Matchers.containsInAnyOrder(usage3));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p2"), null), Matchers.containsInAnyOrder(usage4));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p3"), null), Matchers.containsInAnyOrder(usage5));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)

Example 8 with LicenseInfoUsage

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

the class AttachmentHandlerTest method testReplacingWithEmptyUsagesListDoesNothing.

@Test
public void testReplacingWithEmptyUsagesListDoesNothing() 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));
    handler.replaceAttachmentUsages(Source.projectId("p1"), Lists.newArrayList());
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p1"), null), Matchers.containsInAnyOrder(usage1, usage2, usage3));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p2"), null), Matchers.containsInAnyOrder(usage4));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p3"), null), Matchers.containsInAnyOrder(usage5));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)

Example 9 with LicenseInfoUsage

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

the class AttachmentHandlerTest method testReplacementOfUsageWithEmptyUsageData.

@Test
public void testReplacementOfUsageWithEmptyUsageData() 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", "r8", "a81");
    AttachmentUsage usage7 = createUsage("p1", "r9", "a91");
    handler.replaceAttachmentUsages(Source.projectId("p1"), Lists.newArrayList(usage6, usage7));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p1"), null), Matchers.containsInAnyOrder(usage1, usage2, usage6, usage7));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p2"), null), Matchers.containsInAnyOrder(usage4));
    Assert.assertThat(handler.getUsedAttachments(Source.projectId("p3"), null), Matchers.containsInAnyOrder(usage5));
}
Also used : AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)

Example 10 with LicenseInfoUsage

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

the class AttachmentHandlerTest method testAttachmentUsageCountWithFilter.

@Test
public void testAttachmentUsageCountWithFilter() throws Exception {
    AttachmentUsage usage1 = createUsage("p1", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
    AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
    AttachmentUsage usage3 = createUsage("p2", "r2", "a21", UsageData.licenseInfo(new LicenseInfoUsage()));
    AttachmentUsage usage4 = createUsage("p3", "r1", "a11", UsageData.licenseInfo(new LicenseInfoUsage()));
    AttachmentUsage usage5 = createUsage("p4", "r1", "a11");
    AttachmentUsage usage6 = createUsage("p5", "r3", "a31");
    handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5, usage6));
    Map<Source, Set<String>> queryFor = ImmutableMap.of(Source.releaseId("r1"), ImmutableSet.of("a11", "a12"), Source.releaseId("r3"), ImmutableSet.of("a31"));
    Map<Map<Source, String>, Integer> counts = handler.getAttachmentUsageCount(queryFor, UsageData.licenseInfo(new LicenseInfoUsage()));
    Map<Map<Source, String>, Integer> expected = ImmutableMap.of(ImmutableMap.of(Source.releaseId("r1"), "a11"), 2);
    for (Entry<Map<Source, String>, Integer> entry : expected.entrySet()) {
        Assert.assertThat(counts.get(entry.getKey()), is(entry.getValue()));
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Source(org.eclipse.sw360.datahandler.thrift.Source)

Aggregations

AttachmentUsage (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage)10 LicenseInfoUsage (org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Strings.nullToEmpty (com.google.common.base.Strings.nullToEmpty)1 com.google.common.collect (com.google.common.collect)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONException (com.liferay.portal.kernel.json.JSONException)1 JSONFactoryUtil (com.liferay.portal.kernel.json.JSONFactoryUtil)1 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)1 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 PortletResponseUtil (com.liferay.portal.kernel.portlet.PortletResponseUtil)1 SessionMessages (com.liferay.portal.kernel.servlet.SessionMessages)1 Organization (com.liferay.portal.model.Organization)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1