Search in sources :

Example 21 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment 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 22 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class CompareAttachments method renderCompareAttachment.

private void renderCompareAttachment(StringBuilder display, Attachment old, Attachment deleted, Attachment added) {
    if (old.equals(added))
        return;
    display.append(String.format("<table class=\"%s\" id=\"%schanges%s\" >", tableClasses, idPrefix, old.getAttachmentContentId()));
    display.append(String.format("<thead><tr><th colspan=\"4\"> Changes for Attachment %s </th></tr>", old.getFilename()));
    display.append(String.format("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr></thead><tbody>", FIELD_NAME, CURRENT_VAL, DELETED_VAL, SUGGESTED_VAL));
    for (Attachment._Fields field : RELEVANT_FIELDS) {
        FieldMetaData fieldMetaData = Attachment.metaDataMap.get(field);
        displaySimpleFieldOrSet(display, old, added, deleted, field, fieldMetaData, Release._Fields.ATTACHMENTS.getFieldName());
    }
    display.append("</tbody></table>");
}
Also used : FieldMetaData(org.apache.thrift.meta_data.FieldMetaData) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Example 23 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class AttachmentAwarePortlet method doGetAttachmentForDisplay.

private void doGetAttachmentForDisplay(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
    final String attachmentId = request.getParameter(PortalConstants.ATTACHMENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    Attachment attachment = attachmentPortletUtils.getAttachmentForDisplay(user, attachmentId);
    if (attachment == null) {
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
    } else {
        writeJSON(request, response, OBJECT_MAPPER.writeValueAsString(attachment));
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Example 24 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class AttachmentAwarePortlet method serveNewAttachmentId.

private void serveNewAttachmentId(ResourceRequest request, ResourceResponse response) throws IOException {
    final AttachmentContent attachment = attachmentPortletUtils.createAttachmentContent(request);
    if (attachment == null) {
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "404");
    } else {
        final String attachmentId = attachment.getId();
        response.getWriter().write(attachmentId);
    }
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)

Example 25 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class FossologyAwarePortlet method serveFossologyStatus.

protected void serveFossologyStatus(ResourceRequest request, ResourceResponse response) throws IOException {
    DataTablesParameters parameters = DataTablesParser.parametersFrom(request);
    Release release = getReleaseForFossologyStatus(request);
    Map<String, FossologyStatus> fossologyStatus = getFossologyStatus(release);
    JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
    JSONArray data = JSONFactoryUtil.createJSONArray();
    for (Map.Entry<String, FossologyStatus> entry : fossologyStatus.entrySet()) {
        JSONObject row = JSONFactoryUtil.createJSONObject();
        row.put("0", entry.getKey());
        row.put("1", ThriftEnumUtils.enumToString(entry.getValue()));
        data.put(row);
    }
    jsonResponse.put("attachment", getFossologyUploadableAttachment(release));
    jsonResponse.put("data", data);
    jsonResponse.put("draw", parameters.getDraw());
    jsonResponse.put("recordsTotal", fossologyStatus.size());
    jsonResponse.put("recordsFiltered", fossologyStatus.size());
    writeJSON(request, response, jsonResponse);
}
Also used : DataTablesParameters(org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) CommonUtils.nullToEmptyMap(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)65 Test (org.junit.Test)40 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)38 User (org.eclipse.sw360.datahandler.thrift.users.User)27 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)22 InputStream (java.io.InputStream)19 Release (org.eclipse.sw360.datahandler.thrift.components.Release)15 IOException (java.io.IOException)13 PortletRequest (javax.portlet.PortletRequest)11 TestUserCacheHolder (org.eclipse.sw360.portal.TestUserCacheHolder)9 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 TException (org.apache.thrift.TException)8 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)8 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)7 OutputStream (java.io.OutputStream)5 AttachmentInputStream (org.ektorp.AttachmentInputStream)5 ResponseEntity (org.springframework.http.ResponseEntity)5 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)4 Maps (com.google.common.collect.Maps)3