use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.
the class AttachmentHandler method getAttachmentUsage.
@Override
public AttachmentUsage getAttachmentUsage(String id) throws TException {
assertNotNull(id);
assertNotEmpty(id);
AttachmentUsage attachmentUsage = attachmentUsageRepository.get(id);
assertNotNull(attachmentUsage);
return attachmentUsage;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage 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;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method testGetAttachmentUsages.
@Test
public void testGetAttachmentUsages() throws Exception {
AttachmentUsage usage1 = createUsage("p1", "r1", "a11");
AttachmentUsage usage2 = createUsage("p1", "r1", "a12");
AttachmentUsage usage3 = createUsage("p2", "r2", "a21");
AttachmentUsage usage4 = createUsage("p3", "r1", "a11");
AttachmentUsage usage5 = createUsage("p4", "r1", "a11");
handler.makeAttachmentUsages(Lists.newArrayList(usage1, usage2, usage3, usage4, usage5));
Assert.assertThat(handler.getAttachmentUsages(Source.releaseId("r1"), "a11", null), Matchers.containsInAnyOrder(usage1, usage4, usage5));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage 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));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage in project sw360portal by sw360.
the class AttachmentHandlerTest method createUsage.
private AttachmentUsage createUsage(String usedBy, String owner, String attachmentId, UsageData usageData) {
AttachmentUsage usage = createUsage(usedBy, owner, attachmentId);
usage.setUsageData(usageData);
return usage;
}
Aggregations