Search in sources :

Example 6 with ProjectLink

use of org.eclipse.sw360.datahandler.thrift.projects.ProjectLink in project sw360portal by sw360.

the class ProjectPortlet method prepareLicenseInfo.

private void prepareLicenseInfo(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    User user = UserCacheHolder.getUserFromRequest(request);
    String id = request.getParameter(PROJECT_ID);
    request.setAttribute(PortalConstants.SW360_USER, user);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
    request.setAttribute(PROJECT_LINK_TABLE_MODE, PROJECT_LINK_TABLE_MODE_LICENSE_INFO);
    if (id != null) {
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            Project project = client.getProjectById(id, user);
            request.setAttribute(PROJECT, project);
            request.setAttribute(DOCUMENT_ID, id);
            LicenseInfoService.Iface licenseInfoClient = thriftClients.makeLicenseInfoClient();
            List<OutputFormatInfo> outputFormats = licenseInfoClient.getPossibleOutputFormats();
            request.setAttribute(PortalConstants.LICENSE_INFO_OUTPUT_FORMATS, outputFormats);
            List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, filterAndSortAttachments(SW360Constants.LICENSE_INFO_ATTACHMENT_TYPES), true, user);
            request.setAttribute(PROJECT_LIST, mappedProjectLinks);
            addProjectBreadcrumb(request, response, project);
            AttachmentService.Iface attachmentClient = thriftClients.makeAttachmentClient();
            Map<Source, Set<String>> containedAttachments = ProjectPortletUtils.extractContainedAttachments(mappedProjectLinks);
            Map<Map<Source, String>, Integer> attachmentUsages = attachmentClient.getAttachmentUsageCount(containedAttachments, UsageData.licenseInfo(new LicenseInfoUsage(Sets.newHashSet())));
            Map<String, Integer> countMap = attachmentUsages.entrySet().stream().collect(Collectors.toMap(entry -> {
                Entry<Source, String> key = entry.getKey().entrySet().iterator().next();
                return key.getKey().getFieldValue() + "_" + key.getValue();
            }, entry -> entry.getValue()));
            request.setAttribute(ATTACHMENT_USAGE_COUNT_MAP, countMap);
        } catch (TException e) {
            log.error("Error fetching project from backend!", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
        }
    }
}
Also used : ReleaseClearingStatusData(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStatusData) User(org.eclipse.sw360.datahandler.thrift.users.User) Release(org.eclipse.sw360.datahandler.thrift.components.Release) TSimpleJSONProtocol(org.apache.thrift.protocol.TSimpleJSONProtocol) TSerializer(org.apache.thrift.TSerializer) ProjectExporter(org.eclipse.sw360.exporter.ProjectExporter) Logger(org.apache.log4j.Logger) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) SW360Utils.printName(org.eclipse.sw360.datahandler.common.SW360Utils.printName) CONTENT_TYPE_OPENXML_SPREADSHEET(org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET) LifeRayUserSession(org.eclipse.sw360.portal.users.LifeRayUserSession) com.google.common.collect(com.google.common.collect) UserUtils(org.eclipse.sw360.portal.users.UserUtils) PrintWriter(java.io.PrintWriter) CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) Predicate(java.util.function.Predicate) PermissionUtils(org.eclipse.sw360.datahandler.permissions.PermissionUtils) org.eclipse.sw360.portal.common(org.eclipse.sw360.portal.common) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) Collectors(java.util.stream.Collectors) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) Entry(java.util.Map.Entry) Organization(com.liferay.portal.model.Organization) NotNull(org.jetbrains.annotations.NotNull) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) java.util(java.util) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) JSONException(com.liferay.portal.kernel.json.JSONException) PortletResponseUtil(com.liferay.portal.kernel.portlet.PortletResponseUtil) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Function(java.util.function.Function) Strings(com.google.common.base.Strings) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) org.eclipse.sw360.datahandler.thrift.vulnerabilities(org.eclipse.sw360.datahandler.thrift.vulnerabilities) org.eclipse.sw360.datahandler.thrift(org.eclipse.sw360.datahandler.thrift) ReleaseLink(org.eclipse.sw360.datahandler.thrift.components.ReleaseLink) org.eclipse.sw360.datahandler.thrift.projects(org.eclipse.sw360.datahandler.thrift.projects) SessionMessages(com.liferay.portal.kernel.servlet.SessionMessages) URLConnection(java.net.URLConnection) BiConsumer(java.util.function.BiConsumer) javax.portlet(javax.portlet) org.eclipse.sw360.datahandler.thrift.attachments(org.eclipse.sw360.datahandler.thrift.attachments) org.eclipse.sw360.datahandler.common(org.eclipse.sw360.datahandler.common) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction) JSONFactoryUtil.createJSONArray(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) HttpServletResponse(javax.servlet.http.HttpServletResponse) TException(org.apache.thrift.TException) JSONFactoryUtil(com.liferay.portal.kernel.json.JSONFactoryUtil) IOException(java.io.IOException) JSONObject(com.liferay.portal.kernel.json.JSONObject) FossologyAwarePortlet(org.eclipse.sw360.portal.portlets.FossologyAwarePortlet) ReleaseExporter(org.eclipse.sw360.exporter.ReleaseExporter) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) JSONArray(com.liferay.portal.kernel.json.JSONArray) org.eclipse.sw360.datahandler.thrift.licenseinfo(org.eclipse.sw360.datahandler.thrift.licenseinfo) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) Entry(java.util.Map.Entry)

Example 7 with ProjectLink

use of org.eclipse.sw360.datahandler.thrift.projects.ProjectLink in project sw360portal by sw360.

the class ProjectPortletUtils method extractContainedAttachments.

/**
 * Walks through a list of project links and extracts all release attachments
 * with their owner. The returned map is a mapping from a release to its
 * attachment content ids.
 *
 * @param projectLinks
 *            list of project links to walk through
 *
 * @return map of releases and their attachment content ids
 */
public static Map<Source, Set<String>> extractContainedAttachments(Collection<ProjectLink> projectLinks) {
    Map<Source, Set<String>> attachments = Maps.newHashMap();
    for (ProjectLink projectLink : projectLinks) {
        for (ReleaseLink releaseLink : projectLink.linkedReleases) {
            Set<String> attachmentIds = attachments.getOrDefault(Source.releaseId(releaseLink.getId()), Sets.newHashSet());
            attachmentIds.addAll(releaseLink.getAttachments().stream().map(a -> a.getAttachmentContentId()).collect(Collectors.toList()));
            attachments.put(Source.releaseId(releaseLink.getId()), attachmentIds);
        }
    }
    return attachments;
}
Also used : ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) ReleaseLink(org.eclipse.sw360.datahandler.thrift.components.ReleaseLink)

Example 8 with ProjectLink

use of org.eclipse.sw360.datahandler.thrift.projects.ProjectLink in project sw360portal by sw360.

the class DisplayProjectChanges method renderProjectLinkListCompare.

private void renderProjectLinkListCompare(StringBuilder display, Map<String, ProjectRelationship> oldProjectRelationshipMap, Map<String, ProjectRelationship> deleteProjectRelationshipMap, Map<String, ProjectRelationship> updateProjectRelationshipMap, Set<String> projectIds, User user) {
    if (projectIds.isEmpty())
        return;
    StringBuilder candidate = new StringBuilder();
    try {
        ProjectService.Iface client = new ThriftClients().makeProjectClient();
        Map<String, ProjectRelationship> changeMap = new HashMap<>();
        for (String projectId : projectIds) {
            ProjectRelationship updateProjectRelationship = updateProjectRelationshipMap.get(projectId);
            ProjectRelationship oldProjectRelationship = oldProjectRelationshipMap.get(projectId);
            if (!updateProjectRelationship.equals(oldProjectRelationship)) {
                changeMap.put(projectId, oldProjectRelationshipMap.get(projectId));
            }
        }
        // ! This code doubling is done to reduce the database queries. I.e. one big query instead of multiple small ones
        for (ProjectLink projectLink : client.getLinkedProjects(changeMap, user)) {
            ProjectRelationship updateProjectRelationship = updateProjectRelationshipMap.get(projectLink.getId());
            ProjectRelationship deleteProjectRelationship = deleteProjectRelationshipMap.get(projectLink.getId());
            ProjectRelationship oldProjectRelationship = oldProjectRelationshipMap.get(projectLink.getId());
            candidate.append(String.format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", projectLink.getName(), oldProjectRelationship, deleteProjectRelationship, updateProjectRelationship));
        }
    } catch (TException ignored) {
    }
    String tableContent = candidate.toString();
    if (!tableContent.isEmpty()) {
        display.append(String.format("<table class=\"%s\" id=\"%sUpdated\" >", tableClasses, idPrefix));
        display.append("<thead><tr><th colspan=\"4\">Updated Project Links</th></tr>" + "<tr><th>Project Name</th>" + "<th>Current Project Relationship</th>" + "<th>Deleted Project Relationship</th>" + "<th>Suggested Project Relationship</th></tr>" + "</thead><tbody>");
        display.append(tableContent);
        display.append("</tbody></table>");
    }
}
Also used : TException(org.apache.thrift.TException) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) HashMap(java.util.HashMap) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Example 9 with ProjectLink

use of org.eclipse.sw360.datahandler.thrift.projects.ProjectLink in project sw360portal by sw360.

the class DisplayProjectChanges method renderProjectLinkList.

private void renderProjectLinkList(StringBuilder display, Map<String, ProjectRelationship> projectRelationshipMap, Set<String> projectIds, String msg, User user) {
    if (projectIds.isEmpty())
        return;
    Map<String, ProjectRelationship> filteredMap = new HashMap<>();
    for (String id : projectIds) {
        filteredMap.put(id, projectRelationshipMap.get(id));
    }
    StringBuilder candidate = new StringBuilder();
    try {
        ProjectService.Iface client = new ThriftClients().makeProjectClient();
        for (ProjectLink projectLink : client.getLinkedProjects(filteredMap, user)) {
            candidate.append(String.format("<tr><td>%s</td><td>%s</td></tr>", projectLink.getName(), projectLink.getRelation()));
        }
    } catch (TException ignored) {
    }
    String tableContent = candidate.toString();
    if (!tableContent.isEmpty()) {
        display.append(String.format("<table class=\"%s\" id=\"%s%s\" >", tableClasses, idPrefix, msg));
        display.append(String.format("<thead><tr><th colspan=\"2\">%s</th></tr>" + "<tr><th>Project Name</th><th>Project Relationship</th></tr></thead><tbody>", msg));
        display.append(tableContent);
        display.append("</tbody></table>");
    }
}
Also used : TException(org.apache.thrift.TException) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) HashMap(java.util.HashMap) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Example 10 with ProjectLink

use of org.eclipse.sw360.datahandler.thrift.projects.ProjectLink in project sw360portal by sw360.

the class LinkedReleasesAndProjectsAwarePortlet method serveLoadLinkedProjectsRows.

protected void serveLoadLinkedProjectsRows(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    String branchId = request.getParameter(PARENT_BRANCH_ID);
    request.setAttribute(PARENT_BRANCH_ID, branchId);
    if (branchId != null) {
        String id = branchId.split("_")[0];
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            Project project = client.getProjectById(id, user);
            List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, user);
            request.setAttribute(PROJECT_LIST, mappedProjectLinks);
        } catch (TException e) {
            log.error("Error getting projects!", e);
            throw new PortletException("cannot get projects", e);
        }
    } else {
        List<ProjectLink> mappedProjectLinks = createLinkedProjects(new Project(), user);
        request.setAttribute(PROJECT_LIST, mappedProjectLinks);
    }
    request.setAttribute(PortalConstants.PARENT_SCOPE_GROUP_ID, request.getParameter(PortalConstants.PARENT_SCOPE_GROUP_ID));
    include("/html/utils/ajax/linkedProjectsRows.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
Also used : TException(org.apache.thrift.TException) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) User(org.eclipse.sw360.datahandler.thrift.users.User) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) PortletException(javax.portlet.PortletException) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService)

Aggregations

TException (org.apache.thrift.TException)7 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)7 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)6 User (org.eclipse.sw360.datahandler.thrift.users.User)5 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)4 ReleaseLink (org.eclipse.sw360.datahandler.thrift.components.ReleaseLink)3 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 ThriftClients (org.eclipse.sw360.datahandler.thrift.ThriftClients)2 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Strings.nullToEmpty (com.google.common.base.Strings.nullToEmpty)1 com.google.common.collect (com.google.common.collect)1 JSONArray (com.liferay.portal.kernel.json.JSONArray)1 JSONException (com.liferay.portal.kernel.json.JSONException)1 JSONFactoryUtil (com.liferay.portal.kernel.json.JSONFactoryUtil)1 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)1