Search in sources :

Example 31 with Project

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

the class ProjectPortlet method serveProjectSearchResults.

private void serveProjectSearchResults(ResourceRequest request, ResourceResponse response, String searchText) throws IOException, PortletException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    List<Project> searchResult;
    try {
        ProjectService.Iface client = thriftClients.makeProjectClient();
        if (isNullOrEmpty(searchText)) {
            searchResult = client.getAccessibleProjectsSummary(user);
        } else {
            searchResult = client.searchByName(searchText, user);
        }
    } catch (TException e) {
        log.error("Error searching projects", e);
        searchResult = Collections.emptyList();
    }
    request.setAttribute(PortalConstants.PROJECT_SEARCH, searchResult);
    include("/html/projects/ajax/searchProjectsAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 32 with Project

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

the class ProjectPortlet method removeProject.

private RequestStatus removeProject(PortletRequest request) {
    String projectId = request.getParameter(PortalConstants.PROJECT_ID);
    String encodedDeleteComment = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
    final User user = UserCacheHolder.getUserFromRequest(request);
    if (encodedDeleteComment != null) {
        String deleteComment = new String(Base64.getDecoder().decode(encodedDeleteComment));
        user.setCommentMadeDuringModerationRequest(deleteComment);
    }
    try {
        deleteUnneededAttachments(user.getEmail(), projectId);
        ProjectService.Iface client = thriftClients.makeProjectClient();
        return client.deleteProject(projectId, user);
    } catch (TException e) {
        log.error("Error deleting project from backend", e);
    }
    return RequestStatus.FAILURE;
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 33 with Project

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

the class ProjectPortlet method prepareDetailView.

private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    User user = UserCacheHolder.getUserFromRequest(request);
    String id = request.getParameter(PROJECT_ID);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
    request.setAttribute(DOCUMENT_ID, id);
    request.setAttribute(DEFAULT_LICENSE_INFO_HEADER_TEXT, getProjectDefaultLicenseInfoHeaderText());
    if (id != null) {
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            Project project = client.getProjectById(id, user);
            project = getWithFilledClearingStateSummary(project, user);
            request.setAttribute(PROJECT, project);
            setAttachmentsInRequest(request, project.getAttachments());
            List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, user);
            request.setAttribute(PROJECT_LIST, mappedProjectLinks);
            putDirectlyLinkedReleasesInRequest(request, project);
            Set<Project> usingProjects = client.searchLinkingProjects(id, user);
            request.setAttribute(USING_PROJECTS, usingProjects);
            putReleasesAndProjectIntoRequest(request, id, user);
            putVulnerabilitiesInRequest(request, id, user);
            request.setAttribute(VULNERABILITY_RATINGS_EDITABLE, PermissionUtils.makePermission(project, user).isActionAllowed(RequestedAction.WRITE));
            addProjectBreadcrumb(request, response, project);
        } catch (TException e) {
            log.error("Error fetching project from backend!", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
        }
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 34 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project 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 35 with Project

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

the class ProjectPortlet method serveReleasesFromLinkedProjects.

private void serveReleasesFromLinkedProjects(ResourceRequest request, ResourceResponse response, String projectId) throws IOException, PortletException {
    List<Release> searchResult;
    Set<String> releaseIdsFromLinkedProjects = new HashSet<>();
    User user = UserCacheHolder.getUserFromRequest(request);
    try {
        ComponentService.Iface componentClient = thriftClients.makeComponentClient();
        ProjectService.Iface projectClient = thriftClients.makeProjectClient();
        Project project = projectClient.getProjectById(projectId, user);
        Map<String, ProjectRelationship> linkedProjects = CommonUtils.nullToEmptyMap(project.getLinkedProjects());
        for (String linkedProjectId : linkedProjects.keySet()) {
            Project linkedProject = projectClient.getProjectById(linkedProjectId, user);
            if (linkedProject != null) {
                Map<String, ProjectReleaseRelationship> releaseIdToUsage = CommonUtils.nullToEmptyMap(linkedProject.getReleaseIdToUsage());
                releaseIdsFromLinkedProjects.addAll(releaseIdToUsage.keySet());
            }
        }
        if (releaseIdsFromLinkedProjects.size() > 0) {
            searchResult = componentClient.getReleasesById(releaseIdsFromLinkedProjects, user);
        } else {
            searchResult = Collections.emptyList();
        }
    } catch (TException e) {
        log.error("Error searching projects", e);
        searchResult = Collections.emptyList();
    }
    request.setAttribute(PortalConstants.RELEASE_SEARCH, searchResult);
    include("/html/utils/ajax/searchReleasesAjax.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Aggregations

Project (org.eclipse.sw360.datahandler.thrift.projects.Project)87 User (org.eclipse.sw360.datahandler.thrift.users.User)46 Test (org.junit.Test)42 TException (org.apache.thrift.TException)27 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)16 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)12 Release (org.eclipse.sw360.datahandler.thrift.components.Release)12 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)10 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)6 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 HashSet (java.util.HashSet)5 ResponseEntity (org.springframework.http.ResponseEntity)5