Search in sources :

Example 36 with License

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

the class LicenseDatabaseHandler method updateWhitelist.

/**
 * Update the whitelisted todos for an organisation
 */
public RequestStatus updateWhitelist(String licenseId, Set<String> whitelistTodos, User user) throws SW360Exception {
    License license = licenseRepository.get(licenseId);
    assertNotNull(license);
    String organisation = user.getDepartment();
    String businessUnit = SW360Utils.getBUFromOrganisation(organisation);
    if (makePermission(license, user).isActionAllowed(RequestedAction.WRITE)) {
        List<Todo> todos = todoRepository.get(license.todoDatabaseIds);
        for (Todo todo : todos) {
            String todoId = todo.getId();
            Set<String> currentWhitelist = todo.whitelist != null ? todo.whitelist : new HashSet<>();
            // Add to whitelist if necessary
            if (whitelistTodos.contains(todoId) && !currentWhitelist.contains(businessUnit)) {
                todo.addToWhitelist(businessUnit);
                todoRepository.update(todo);
            }
            // Remove from whitelist if necessary
            if (!whitelistTodos.contains(todoId) && currentWhitelist.contains(businessUnit)) {
                currentWhitelist.remove(businessUnit);
                todoRepository.update(todo);
            }
        }
        return RequestStatus.SUCCESS;
    } else {
        // add updated whitelists to todos in moderation request, not yet in database
        License licenseForModerationRequest = getLicenseForOrganisationWithOwnModerationRequests(licenseId, user.getDepartment(), user);
        List<Todo> todos = licenseForModerationRequest.getTodos();
        for (Todo todo : todos) {
            String todoId = todo.getId();
            Set<String> currentWhitelist = todo.whitelist != null ? todo.whitelist : new HashSet<>();
            // Add to whitelist if necessary
            if (whitelistTodos.contains(todoId) && !currentWhitelist.contains(businessUnit)) {
                todo.addToWhitelist(businessUnit);
            }
            // Remove from whitelist if necessary
            if (!whitelistTodos.contains(todoId) && currentWhitelist.contains(businessUnit)) {
                currentWhitelist.remove(businessUnit);
            }
        }
        // Only moderators can edit whitelists!
        return moderator.updateLicense(licenseForModerationRequest, user);
    }
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)

Example 37 with License

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

the class LicenseDatabaseHandler method fillLicenseForOrganisation.

private void fillLicenseForOrganisation(String organisation, License license) {
    if (license.isSetTodoDatabaseIds()) {
        license.setTodos(getTodosByIds(license.todoDatabaseIds));
    }
    if (license.isSetTodos()) {
        for (Todo todo : license.getTodos()) {
            // remove other organisations from whitelist of todo
            todo.setWhitelist(SW360Utils.filterBUSet(organisation, todo.whitelist));
            if (todo.isSetObligationDatabaseIds()) {
                todo.setObligations(getObligationsByIds(todo.obligationDatabaseIds));
            }
        }
    }
    if (license.isSetLicenseTypeDatabaseId()) {
        final LicenseType licenseType = licenseTypeRepository.get(license.getLicenseTypeDatabaseId());
        license.setLicenseType(licenseType);
    }
    if (license.isSetRiskDatabaseIds()) {
        license.setRisks(getRisksByIds(license.riskDatabaseIds));
        license.unsetRiskDatabaseIds();
    }
    license.setShortname(license.getId());
}
Also used : CommonUtils.isTemporaryTodo(org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)

Example 38 with License

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

the class DocxGenerator method fillLicenseList.

private void fillLicenseList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults) {
    List<LicenseNameWithText> licenseNameWithTexts = OutputGenerator.getSortedLicenseNameWithTexts(projectLicenseInfoResults);
    XWPFRun licenseHeaderRun = document.createParagraph().createRun();
    addFormattedText(licenseHeaderRun, "License texts", FONT_SIZE + 2, true);
    addNewLines(document, 0);
    for (LicenseNameWithText licenseNameWithText : licenseNameWithTexts) {
        XWPFParagraph licenseParagraph = document.createParagraph();
        licenseParagraph.setStyle(STYLE_HEADING);
        String licenseName = licenseNameWithText.isSetLicenseName() ? licenseNameWithText.getLicenseName() : UNKNOWN_LICENSE_NAME;
        addBookmark(licenseParagraph, licenseName, licenseName);
        addNewLines(document, 0);
        setText(document.createParagraph().createRun(), nullToEmptyString(licenseNameWithText.getLicenseText()));
        addNewLines(document, 1);
    }
}
Also used : XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 39 with License

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

the class DocxGenerator method fillReleaseDetailList.

private void fillReleaseDetailList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, boolean includeObligations) throws TException {
    addFormattedText(document.createParagraph().createRun(), "Detailed Releases Information", FONT_SIZE + 2, true);
    setText(document.createParagraph().createRun(), "Please note the following license conditions and copyright " + "notices applicable to Open Source Software and/or other components (or parts thereof):");
    addNewLines(document, 0);
    for (LicenseInfoParsingResult parsingResult : projectLicenseInfoResults) {
        addReleaseTitle(document, parsingResult);
        if (parsingResult.getStatus() == LicenseInfoRequestStatus.SUCCESS) {
            addCopyrights(document, parsingResult);
            addLicenses(document, parsingResult, includeObligations);
        } else {
            XWPFRun errorRun = document.createParagraph().createRun();
            String errorText = nullToEmptyString(parsingResult.getMessage());
            String filename = getFilename(parsingResult);
            addFormattedText(errorRun, String.format("Error reading license information: %s", errorText), FONT_SIZE, false, ALERT_COLOR);
            addFormattedText(errorRun, String.format("Source file: %s", filename), FONT_SIZE, false, ALERT_COLOR);
        }
        addNewLines(document, 1);
    }
    addPageBreak(document);
}
Also used : XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 40 with License

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

the class DocxGenerator method addLicenseObligations.

private void addLicenseObligations(XWPFDocument document, String spdxLicense) throws TException {
    List<License> sw360Licenses = getLicenses();
    XWPFRun todoTitleRun = document.createParagraph().createRun();
    addNewLines(todoTitleRun, 0);
    Set<String> todos = getTodosFromLicenses(spdxLicense, sw360Licenses);
    addFormattedText(todoTitleRun, "Obligations for license " + spdxLicense + ":", FONT_SIZE, true);
    for (String todo : todos) {
        XWPFParagraph copyPara = document.createParagraph();
        copyPara.setSpacingAfter(0);
        XWPFRun todoRun = copyPara.createRun();
        setText(todoRun, todo);
        addNewLines(todoRun, 1);
    }
}
Also used : XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) License(org.eclipse.sw360.datahandler.thrift.licenses.License) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

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