use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class CombinedCLIParserTest method testGetCLI.
@Test
public void testGetCLI() throws Exception {
Attachment cliAttachment = new Attachment("A1", "a.xml");
when(connector.getAttachmentStream(anyObject(), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(cliTestfile)));
List<LicenseInfoParsingResult> results = parser.getLicenseInfos(cliAttachment, new User(), new Project());
assertThat(results.size(), is(1));
LicenseInfoParsingResult res = results.get(0);
assertLicenseInfoParsingResult(res);
assertThat(res.getLicenseInfo().getFilenames(), containsInAnyOrder("a.xml"));
assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().size(), is(3));
assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().stream().map(LicenseNameWithText::getLicenseText).collect(Collectors.toSet()), containsInAnyOrder("License1Text", "License2Text", "License3&'Text"));
LicenseNameWithText l2 = res.getLicenseInfo().getLicenseNamesWithTexts().stream().filter(l -> l.getLicenseName().equals("License2")).findFirst().orElseThrow(AssertionError::new);
assertThat(l2.getAcknowledgements(), is("License2Acknowledgements"));
assertThat(res.getLicenseInfo().getCopyrights().size(), is(5));
assertThat(res.getLicenseInfo().getCopyrights(), containsInAnyOrder("Copyright1", "Copyright2", "Copyright3", "Copyright4", "Copyright5"));
assertThat(res.getVendor(), is("VendorA"));
assertThat(res.getName(), is("r1"));
assertThat(res.getVersion(), is("1.0"));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class CombinedCLIParser method getLicenseInfos.
@Override
public <T> List<LicenseInfoParsingResult> getLicenseInfos(Attachment attachment, User user, T context) throws TException {
AttachmentContent attachmentContent = attachmentContentProvider.getAttachmentContent(attachment);
InputStream attachmentStream = null;
List<LicenseInfoParsingResult> parsingResults = new ArrayList<>();
Map<String, Release> releasesByExternalId = prepareReleasesByExternalId(getCorrelationKey());
try {
attachmentStream = attachmentConnector.getAttachmentStream(attachmentContent, user, context);
Document doc = getDocument(attachmentStream);
Map<String, Set<String>> copyrightSetsByExternalId = getCopyrightSetsByExternalIdsMap(doc);
Map<String, Set<LicenseNameWithText>> licenseNamesWithTextsByExternalId = getLicenseNamesWithTextsByExternalIdsMap(doc);
Set<String> allExternalIds = Sets.union(copyrightSetsByExternalId.keySet(), licenseNamesWithTextsByExternalId.keySet());
allExternalIds.forEach(extId -> {
LicenseInfoParsingResult parsingResult = getLicenseInfoParsingResultForExternalId(attachmentContent, releasesByExternalId, copyrightSetsByExternalId, licenseNamesWithTextsByExternalId, extId);
parsingResults.add(parsingResult);
});
} catch (ParserConfigurationException | IOException | XPathExpressionException | SAXException | SW360Exception e) {
log.error(e);
parsingResults.add(new LicenseInfoParsingResult().setStatus(LicenseInfoRequestStatus.FAILURE).setMessage("Error while parsing combined CLI file: " + e.toString()));
} finally {
closeQuietly(attachmentStream, log);
}
return parsingResults;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class SPDXParser method getLicenseInfo.
public <T> LicenseInfoParsingResult getLicenseInfo(Attachment attachment, User user, T context) throws TException {
AttachmentContent attachmentContent = attachmentContentProvider.getAttachmentContent(attachment);
final Optional<SpdxDocument> spdxDocument = openAsSpdx(attachmentContent, user, context);
if (!spdxDocument.isPresent()) {
return new LicenseInfoParsingResult().setStatus(LicenseInfoRequestStatus.FAILURE);
}
return getLicenseInfoFromSpdx(attachmentContent, spdxDocument.get());
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class CLIParserTest method testIsApplicableTo.
@Test
public void testIsApplicableTo() throws Exception {
when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(CLI_TESTFILE)));
assertTrue(parser.isApplicableTo(attachment, new User(), new Project()));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class CLIParserTest method testIsApplicableToFailsOnMalformedXML.
@Test
public void testIsApplicableToFailsOnMalformedXML() throws Exception {
AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader("this is not an xml file")));
assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
Aggregations