Search in sources :

Example 1 with InvalidSPDXAnalysisException

use of org.spdx.rdfparser.InvalidSPDXAnalysisException in project sw360portal by sw360.

the class SPDXParserTools method getLicenseInfoFromSpdx.

protected static LicenseInfoParsingResult getLicenseInfoFromSpdx(AttachmentContent attachmentContent, SpdxDocument doc) {
    LicenseInfo licenseInfo = new LicenseInfo().setFilenames(Arrays.asList(attachmentContent.getFilename()));
    licenseInfo.setLicenseNamesWithTexts(new HashSet<>());
    licenseInfo.setCopyrights(new HashSet<>());
    try {
        for (SpdxItem spdxItem : doc.getDocumentDescribes()) {
            licenseInfo.getLicenseNamesWithTexts().addAll(getAllLicenseTexts(spdxItem, true).collect(Collectors.toSet()));
            licenseInfo.getCopyrights().addAll(getAllCopyrights(spdxItem).collect(Collectors.toSet()));
        }
    } catch (UncheckedInvalidSPDXAnalysisException e) {
        return new LicenseInfoParsingResult().setStatus(LicenseInfoRequestStatus.FAILURE).setMessage(e.getInvalidSPDXAnalysisExceptionCause().getMessage());
    } catch (InvalidSPDXAnalysisException e) {
        return new LicenseInfoParsingResult().setStatus(LicenseInfoRequestStatus.FAILURE).setMessage(e.getMessage());
    }
    return new LicenseInfoParsingResult().setLicenseInfo(licenseInfo).setStatus(LicenseInfoRequestStatus.SUCCESS);
}
Also used : LicenseInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo) SpdxItem(org.spdx.rdfparser.model.SpdxItem) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) InvalidSPDXAnalysisException(org.spdx.rdfparser.InvalidSPDXAnalysisException)

Aggregations

LicenseInfo (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo)1 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)1 InvalidSPDXAnalysisException (org.spdx.rdfparser.InvalidSPDXAnalysisException)1 SpdxItem (org.spdx.rdfparser.model.SpdxItem)1