Search in sources :

Example 6 with License

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

the class ModerationPortlet method renderEditViewForId.

private void renderEditViewForId(RenderRequest request, RenderResponse response, String id) throws IOException, PortletException, TException {
    if (id != null) {
        ModerationRequest moderationRequest = null;
        User user = UserCacheHolder.getUserFromRequest(request);
        try {
            ModerationService.Iface client = thriftClients.makeModerationClient();
            moderationRequest = client.getModerationRequestById(id);
            boolean actionsAllowed = moderationRequest.getModerators().contains(user.getEmail()) && ModerationPortletUtils.isOpenModerationRequest(moderationRequest);
            request.setAttribute(PortalConstants.MODERATION_ACTIONS_ALLOWED, actionsAllowed);
            if (actionsAllowed) {
                SessionMessages.add(request, "request_processed", "You have assigned yourself to this moderation request.");
                client.setInProgress(id, user);
            }
            request.setAttribute(PortalConstants.MODERATION_REQUEST, moderationRequest);
            addModerationBreadcrumb(request, response, moderationRequest);
        } catch (TException e) {
            log.error("Error fetching moderation  details from backend", e);
        }
        if (moderationRequest != null) {
            switch(moderationRequest.getDocumentType()) {
                case COMPONENT:
                    renderComponentModeration(request, response, moderationRequest, user);
                    break;
                case RELEASE:
                    VendorService.Iface vendorClient = thriftClients.makeVendorClient();
                    Release additions = moderationRequest.getReleaseAdditions();
                    if (additions.isSetVendorId()) {
                        additions.setVendor(vendorClient.getByID(additions.getVendorId()));
                    }
                    Release deletions = moderationRequest.getReleaseDeletions();
                    if (deletions.isSetVendorId()) {
                        deletions.setVendor(vendorClient.getByID(deletions.getVendorId()));
                    }
                    renderReleaseModeration(request, response, moderationRequest, user);
                    break;
                case PROJECT:
                    renderProjectModeration(request, response, moderationRequest, user);
                    break;
                case LICENSE:
                    renderLicenseModeration(request, response, moderationRequest, user);
                    break;
                case USER:
                    renderUserModeration(request, response, moderationRequest, user);
                    break;
            }
        }
    }
}
Also used : ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) TException(org.apache.thrift.TException) VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) User(org.eclipse.sw360.datahandler.thrift.users.User) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 7 with License

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

the class ProjectPortletUtils method getExcludedLicensesPerAttachmentIdFromRequest.

/**
 * Returns a map of excluded licenses. They key is an attachment content id, the
 * value is a list of excluded licenses.
 * <p>
 * For this method to work it is crucial that there is a so called
 * "license-store-&lt;attachmentContentId&gt;" map in the session. This map must
 * contain a mapping from a key to a {@link LicenseNameWithText} object.
 *
 * @param attachmentContentIds list of attachment content id to check for exclusions in the
 *                             request
 * @param request              the request containing the excluded licenses as parameters
 * @return a map containing the licenses to exclude
 * @see ProjectPortletUtilsTest for a better understanding
 */
public static Map<String, Set<LicenseNameWithText>> getExcludedLicensesPerAttachmentIdFromRequest(Set<String> attachmentContentIds, ResourceRequest request) {
    Map<String, Set<LicenseNameWithText>> excludedLicenses = Maps.newHashMap();
    for (String attachmentContentId : attachmentContentIds) {
        String[] checkboxes = request.getParameterValues(attachmentContentId);
        String[] keys = request.getParameterValues(attachmentContentId + "_key");
        if (checkboxes == null) {
            // no details present
            continue;
        }
        @SuppressWarnings("unchecked") Map<String, LicenseNameWithText> licenseStore = (Map<String, LicenseNameWithText>) request.getPortletSession().getAttribute(ProjectPortlet.LICENSE_STORE_KEY_PREFIX + attachmentContentId);
        if (licenseStore == null) {
            throw new IllegalStateException("No license store found for attachment content id " + attachmentContentId);
        }
        Set<Integer> includedIds = Arrays.stream(checkboxes).map(s -> Integer.valueOf(s)).collect(Collectors.toSet());
        Set<LicenseNameWithText> licenseNameWithTexts = Sets.newHashSet();
        for (int index = 0; index < keys.length; index++) {
            if (includedIds.contains(index)) {
                // transferred
                continue;
            }
            LicenseNameWithText licenseNameWithText = licenseStore.get(keys[index]);
            if (licenseNameWithText == null) {
                throw new IllegalStateException("No license found for key " + keys[index]);
            }
            licenseNameWithTexts.add(licenseNameWithText);
        }
        excludedLicenses.put(attachmentContentId, licenseNameWithTexts);
    }
    return excludedLicenses;
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) ProjectVulnerabilityRating(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) Logger(org.apache.log4j.Logger) ResourceRequest(javax.portlet.ResourceRequest) org.eclipse.sw360.datahandler.thrift(org.eclipse.sw360.datahandler.thrift) Lists(com.google.common.collect.Lists) ReleaseLink(org.eclipse.sw360.datahandler.thrift.components.ReleaseLink) CUSTOM_FIELD_PROJECT_GROUP_FILTER(org.eclipse.sw360.portal.common.PortalConstants.CUSTOM_FIELD_PROJECT_GROUP_FILTER) VulnerabilityCheckStatus(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityCheckStatus) CustomFieldHelper(org.eclipse.sw360.portal.common.CustomFieldHelper) PortletRequest(javax.portlet.PortletRequest) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) SW360Utils(org.eclipse.sw360.datahandler.common.SW360Utils) ImmutableMap(com.google.common.collect.ImmutableMap) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) VulnerabilityRatingForProject(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityRatingForProject) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) AttachmentUsage(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage) UsageData(org.eclipse.sw360.datahandler.thrift.attachments.UsageData) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) LicenseInfoUsage(org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) PortletUtils(org.eclipse.sw360.portal.common.PortletUtils) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 8 with License

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

the class DisplayProjectChanges method prepareLicenseInfoHeaderTextInProject.

private Project prepareLicenseInfoHeaderTextInProject(Project project) {
    Project modifiedProject = project.deepCopy();
    String defaultTextAsHtmlForDisplay = "<span title=\"" + defaultLicenseInfoHeaderText + "\">" + PortalConstants.DEFAULT_LICENSE_INFO_HEADER_TEXT_FOR_DISPALY + "</span>";
    if (!modifiedProject.isSetLicenseInfoHeaderText()) {
        // if the project contains the default license info header text, we wrap it into an html span-element such that the default text is given as a hover text.
        // this is only done for displaying it in a three-way merge in a moderation request.
        modifiedProject.setLicenseInfoHeaderText(defaultTextAsHtmlForDisplay);
    } else {
        // for a custom text escape html properly
        modifiedProject.setLicenseInfoHeaderText(StringEscapeUtils.escapeHtml(modifiedProject.getLicenseInfoHeaderText()).replace("\n", "<br>"));
    }
    return modifiedProject;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 9 with License

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

the class LicensesPortlet method prepareDetailView.

private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    String id = request.getParameter(LICENSE_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    request.setAttribute(IS_USER_AT_LEAST_CLEARING_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user) ? "Yes" : "No");
    if (id != null) {
        try {
            LicenseService.Iface client = thriftClients.makeLicenseClient();
            License moderationLicense = client.getByIDWithOwnModerationRequests(id, user.getDepartment(), user);
            List<Todo> allTodos = nullToEmptyList(moderationLicense.getTodos());
            List<Todo> addedTodos = allTodos.stream().filter(CommonUtils::isTemporaryTodo).collect(Collectors.toList());
            List<Todo> currentTodos = allTodos.stream().filter(t -> !CommonUtils.isTemporaryTodo(t)).collect(Collectors.toList());
            request.setAttribute(ADDED_TODOS_FROM_MODERATION_REQUEST, addedTodos);
            request.setAttribute(DB_TODOS_FROM_MODERATION_REQUEST, currentTodos);
            request.setAttribute(MODERATION_LICENSE_DETAIL, moderationLicense);
            License dbLicense = client.getByID(id, user.getDepartment());
            request.setAttribute(KEY_LICENSE_DETAIL, dbLicense);
            List<Obligation> obligations = client.getObligations();
            request.setAttribute(KEY_OBLIGATION_LIST, obligations);
            addLicenseBreadcrumb(request, response, moderationLicense);
        } catch (TException e) {
            log.error("Error fetching license details from backend", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_LICENSE);
        }
    }
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) PortletResponseUtil(com.liferay.portal.kernel.portlet.PortletResponseUtil) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) TMP_TODO_ID_PREFIX(org.eclipse.sw360.datahandler.common.CommonUtils.TMP_TODO_ID_PREFIX) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Function(java.util.function.Function) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Strings(com.google.common.base.Strings) Logger(org.apache.log4j.Logger) SessionMessages(com.liferay.portal.kernel.servlet.SessionMessages) CONTENT_TYPE_OPENXML_SPREADSHEET(org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET) ThriftEnumUtils(org.eclipse.sw360.datahandler.common.ThriftEnumUtils) Ternary(org.eclipse.sw360.datahandler.thrift.Ternary) javax.portlet(javax.portlet) org.eclipse.sw360.datahandler.thrift.licenses(org.eclipse.sw360.datahandler.thrift.licenses) Sw360Portlet(org.eclipse.sw360.portal.portlets.Sw360Portlet) ImmutableSet(com.google.common.collect.ImmutableSet) UserGroup(org.eclipse.sw360.datahandler.thrift.users.UserGroup) HttpServletResponse(javax.servlet.http.HttpServletResponse) TException(org.apache.thrift.TException) PermissionUtils(org.eclipse.sw360.datahandler.permissions.PermissionUtils) IOException(java.io.IOException) CommonUtils.nullToEmptyList(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyList) Collectors(java.util.stream.Collectors) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) ErrorMessages(org.eclipse.sw360.portal.common.ErrorMessages) EnumUtils(org.apache.commons.lang.enums.EnumUtils) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) LicenseExporter(org.eclipse.sw360.exporter.LicenseExporter) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 10 with License

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

the class LicensesPortlet method delete.

@UsedAsLiferayAction
public void delete(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    RequestStatus requestStatus = deleteLicense(request);
    setSessionMessage(request, requestStatus, "License", "remove");
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

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