Search in sources :

Example 31 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class ModerationPortlet method renderLicenseModeration.

public void renderLicenseModeration(RenderRequest request, RenderResponse response, ModerationRequest moderationRequest, User user) throws IOException, PortletException, TException {
    License actual_license = null;
    User requestingUser = UserCacheHolder.getUserFromEmail(moderationRequest.getRequestingUser());
    try {
        LicenseService.Iface client = thriftClients.makeLicenseClient();
        actual_license = client.getByID(moderationRequest.getDocumentId(), requestingUser.getDepartment());
        request.setAttribute(KEY_LICENSE_DETAIL, actual_license);
        List<Obligation> obligations = client.getObligations();
        request.setAttribute(KEY_OBLIGATION_LIST, obligations);
    } catch (TException e) {
        log.error("Could not retrieve license", e);
    }
    if (actual_license == null) {
        renderNextModeration(request, response, user, "Ignored unretrievable target", thriftClients.makeModerationClient(), moderationRequest);
        return;
    }
    include("/html/moderation/licenses/merge.jsp", request, response);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) Obligation(org.eclipse.sw360.datahandler.thrift.licenses.Obligation) LicenseService(org.eclipse.sw360.datahandler.thrift.licenses.LicenseService) License(org.eclipse.sw360.datahandler.thrift.licenses.License)

Example 32 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class ProjectPortlet method serveAttachmentFileLicenses.

private void serveAttachmentFileLicenses(ResourceRequest request, ResourceResponse response) throws IOException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    final String attachmentContentId = request.getParameter(PortalConstants.ATTACHMENT_ID);
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    final LicenseInfoService.Iface licenseInfoClient = thriftClients.makeLicenseInfoClient();
    try {
        Release release = componentClient.getReleaseById(request.getParameter(PortalConstants.RELEASE_ID), user);
        List<LicenseInfoParsingResult> licenseInfos = licenseInfoClient.getLicenseInfoForAttachment(release, attachmentContentId, user);
        // We generate a JSON-serializable list of licenses here.
        // In addition we remember the license information for exclusion later on
        Map<String, LicenseNameWithText> licenseStore = Maps.newHashMap();
        List<Map<String, String>> licenses = Lists.newArrayList();
        licenseInfos.forEach(licenseInfoResult -> addLicenseInfoResultToJsonSerializableLicensesList(licenseInfoResult, licenses, licenseStore::put));
        licenses.sort((l1, l2) -> Strings.nullToEmpty(l1.get(LICENSE_NAME_WITH_TEXT_NAME)).compareTo(l2.get(LICENSE_NAME_WITH_TEXT_NAME)));
        request.getPortletSession().setAttribute(LICENSE_STORE_KEY_PREFIX + attachmentContentId, licenseStore);
        writeJSON(request, response, OBJECT_MAPPER.writeValueAsString(licenses));
    } catch (TException exception) {
        log.error("Cannot retrieve license information for attachment id " + attachmentContentId + ".", exception);
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 33 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class DatabaseSanitation method deleteAllLicenseInformation.

private void deleteAllLicenseInformation(ResourceRequest request, ResourceResponse response) {
    User user = UserCacheHolder.getUserFromRequest(request);
    LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
    try {
        RequestSummary requestSummary = licenseClient.deleteAllLicenseInformation(user);
        renderRequestSummary(request, response, requestSummary);
    } catch (TException te) {
        log.error("Got TException when trying to delete all license information.", te);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) LicenseService(org.eclipse.sw360.datahandler.thrift.licenses.LicenseService) RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary)

Example 34 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class ComponentUploadPortlet method updateLicenses.

@UsedAsLiferayAction
public void updateLicenses(ActionRequest request, ActionResponse response) throws PortletException, IOException, TException {
    final HashMap<String, InputStream> inputMap = new HashMap<>();
    User user = UserCacheHolder.getUserFromRequest(request);
    try {
        fillFilenameInputStreamMap(request, inputMap);
        if (ZipTools.isValidLicenseArchive(inputMap)) {
            final LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
            log.debug("Parsing risk categories ...");
            Map<Integer, RiskCategory> riskCategoryMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(RISK_CATEGORY_FILE), RiskCategory.class, Integer.class, user);
            log.debug("Parsing risks ...");
            Map<Integer, Risk> riskMap = getIntegerRiskMap(licenseClient, riskCategoryMap, inputMap.get(RISK_FILE), user);
            log.debug("Parsing obligations ...");
            Map<Integer, Obligation> obligationMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(OBLIGATION_FILE), Obligation.class, Integer.class, user);
            log.debug("Parsing obligation todos ...");
            List<CSVRecord> obligationTodoRecords = readAsCSVRecords(inputMap.get(OBLIGATION_TODO_FILE));
            Map<Integer, Set<Integer>> obligationTodoMapping = convertRelationalTableWithIntegerKeys(obligationTodoRecords);
            log.debug("Parsing license types ...");
            Map<Integer, LicenseType> licenseTypeMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(LICENSETYPE_FILE), LicenseType.class, Integer.class, user);
            log.debug("Parsing todos ...");
            Map<Integer, Todo> todoMap = getTodoMapAndWriteMissingToDatabase(licenseClient, obligationMap, obligationTodoMapping, inputMap.get(TODO_FILE), user);
            if (inputMap.containsKey(CUSTOM_PROPERTIES_FILE)) {
                log.debug("Parsing custom properties ...");
                Map<Integer, PropertyWithValue> customPropertiesMap = getCustomPropertiesWithValuesByIdAndWriteMissingToDatabase(licenseClient, inputMap.get(CUSTOM_PROPERTIES_FILE), user);
                log.debug("Parsing todo custom properties relation ...");
                List<CSVRecord> todoPropertiesRecord = readAsCSVRecords(inputMap.get(TODO_CUSTOM_PROPERTIES_FILE));
                Map<Integer, Set<Integer>> todoPropertiesMap = convertRelationalTableWithIntegerKeys(todoPropertiesRecord);
                todoMap = updateTodoMapWithCustomPropertiesAndWriteToDatabase(licenseClient, todoMap, customPropertiesMap, todoPropertiesMap, user);
            }
            log.debug("Parsing license todos ...");
            List<CSVRecord> licenseTodoRecord = readAsCSVRecords(inputMap.get(LICENSE_TODO_FILE));
            Map<String, Set<Integer>> licenseTodoMap = convertRelationalTable(licenseTodoRecord);
            log.debug("Parsing license risks ...");
            List<CSVRecord> licenseRiskRecord = readAsCSVRecords(inputMap.get(LICENSE_RISK_FILE));
            Map<String, Set<Integer>> licenseRiskMap = convertRelationalTable(licenseRiskRecord);
            log.debug("Parsing licenses ...");
            List<CSVRecord> licenseRecord = readAsCSVRecords(inputMap.get(LICENSE_FILE));
            final List<License> licensesToAdd = ConvertRecord.fillLicenses(licenseRecord, licenseTypeMap, todoMap, riskMap, licenseTodoMap, licenseRiskMap);
            addLicenses(licenseClient, licensesToAdd, log, user);
        } else {
            throw new SW360Exception("Invalid file format");
        }
    } finally {
        for (InputStream inputStream : inputMap.values()) {
            inputStream.close();
        }
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) CSVRecord(org.apache.commons.csv.CSVRecord) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 35 with License

use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.

the class SPDXParserTools method getAllLicenseTextsFromInfo.

private static Stream<LicenseNameWithText> getAllLicenseTextsFromInfo(AnyLicenseInfo spdxLicenseInfo) {
    log.trace("Seen the spdxLicenseInfo=" + spdxLicenseInfo.toString() + "]");
    if (spdxLicenseInfo instanceof LicenseSet) {
        LicenseSet LicenseSet = (LicenseSet) spdxLicenseInfo;
        return Arrays.stream(LicenseSet.getMembers()).flatMap(SPDXParserTools::getAllLicenseTextsFromInfo);
    } else if (spdxLicenseInfo instanceof ExtractedLicenseInfo) {
        ExtractedLicenseInfo extractedLicenseInfo = (ExtractedLicenseInfo) spdxLicenseInfo;
        return Stream.of(new LicenseNameWithText().setLicenseName(extractLicenseName(extractedLicenseInfo)).setLicenseText(extractedLicenseInfo.getExtractedText()));
    } else if (spdxLicenseInfo instanceof License) {
        License license = (License) spdxLicenseInfo;
        return Stream.of(new LicenseNameWithText().setLicenseName(extractLicenseName(license)).setLicenseText(license.getLicenseText()));
    } else if (spdxLicenseInfo instanceof OrLaterOperator) {
        OrLaterOperator orLaterOperator = (OrLaterOperator) spdxLicenseInfo;
        return getAllLicenseTextsFromInfo(orLaterOperator.getLicense()).map(lnwt -> lnwt.setLicenseName(lnwt.getLicenseName() + " or later"));
    } else if (spdxLicenseInfo instanceof WithExceptionOperator) {
        WithExceptionOperator withExceptionOperator = (WithExceptionOperator) spdxLicenseInfo;
        String licenseExceptionText = withExceptionOperator.getException().getLicenseExceptionText();
        return getAllLicenseTextsFromInfo(withExceptionOperator.getLicense()).map(licenseNWT -> licenseNWT.setLicenseText(licenseNWT.getLicenseText() + "\n\n" + licenseExceptionText).setLicenseName(licenseNWT.getLicenseName() + " with " + withExceptionOperator.getException().getName()));
    }
    log.debug("the spdxLicenseInfo=[" + spdxLicenseInfo.toString() + "] did not contain any license information");
    return Stream.empty();
}
Also used : LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) Arrays(java.util.Arrays) SpdxPackage(org.spdx.rdfparser.model.SpdxPackage) SpdxFile(org.spdx.rdfparser.model.SpdxFile) LicenseInfoRequestStatus(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoRequestStatus) Collectors(java.util.stream.Collectors) org.spdx.rdfparser.license(org.spdx.rdfparser.license) HashSet(java.util.HashSet) Logger(org.apache.log4j.Logger) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Stream(java.util.stream.Stream) LicenseInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo) InvalidSPDXAnalysisException(org.spdx.rdfparser.InvalidSPDXAnalysisException) SpdxItem(org.spdx.rdfparser.model.SpdxItem) SpdxDocument(org.spdx.rdfparser.model.SpdxDocument) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) CommonUtils.isNullEmptyOrWhitespace(org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)20 TException (org.apache.thrift.TException)16 License (org.eclipse.sw360.datahandler.thrift.licenses.License)16 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)8 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 java.util (java.util)5 Collectors (java.util.stream.Collectors)5 Logger (org.apache.log4j.Logger)5 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)5 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Release (org.eclipse.sw360.datahandler.thrift.components.Release)4 Maps (com.google.common.collect.Maps)3 Sets (com.google.common.collect.Sets)3 XWPFRun (org.apache.poi.xwpf.usermodel.XWPFRun)3 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)3 Ternary (org.eclipse.sw360.datahandler.thrift.Ternary)3 LicenseService (org.eclipse.sw360.datahandler.thrift.licenses.LicenseService)3 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3