Search in sources :

Example 1 with ResourceRequest

use of javax.portlet.ResourceRequest 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)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 PortletRequest (javax.portlet.PortletRequest)1 ResourceRequest (javax.portlet.ResourceRequest)1 StringEscapeUtils (org.apache.commons.lang.StringEscapeUtils)1 Logger (org.apache.log4j.Logger)1 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)1 SW360Utils (org.eclipse.sw360.datahandler.common.SW360Utils)1 org.eclipse.sw360.datahandler.thrift (org.eclipse.sw360.datahandler.thrift)1 AttachmentUsage (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage)1 LicenseInfoUsage (org.eclipse.sw360.datahandler.thrift.attachments.LicenseInfoUsage)1 UsageData (org.eclipse.sw360.datahandler.thrift.attachments.UsageData)1 ReleaseLink (org.eclipse.sw360.datahandler.thrift.components.ReleaseLink)1 LicenseNameWithText (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)1 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)1 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)1