Search in sources :

Example 81 with Project

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

the class ProjectDatabaseHandler method updateProjectFromAdditionsAndDeletions.

public RequestStatus updateProjectFromAdditionsAndDeletions(Project projectAdditions, Project projectDeletions, User user) {
    try {
        Project project = getProjectById(projectAdditions.getId(), user);
        project = moderator.updateProjectFromModerationRequest(project, projectAdditions, projectDeletions);
        return updateProject(project, user);
    } catch (SW360Exception e) {
        log.error("Could not get original project when updating from moderation request.");
        return RequestStatus.FAILURE;
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 82 with Project

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

the class ProjectImportPortlet method doView.

@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    List<Project> importables = new ArrayList<>();
    Boolean loggedIn = false;
    String loggedInServer = "";
    RemoteCredentials reCred = getRemoteCredentialsFromSession(request.getPortletSession());
    String projectName = request.getParameter(ProjectImportConstants.PROJECT_NAME);
    if (!nullToEmpty(reCred.getServerUrl()).isEmpty()) {
        importables = loadImportables(reCred, projectName);
        loggedIn = true;
        loggedInServer = reCred.getServerUrl();
    }
    String idName = getIdName();
    request.setAttribute("idName", idName);
    request.setAttribute("importables", importables);
    request.setAttribute("loggedIn", loggedIn);
    request.setAttribute("loggedInServer", loggedInServer);
    super.doView(request, response);
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) RemoteCredentials(org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials) ArrayList(java.util.ArrayList)

Example 83 with Project

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

the class ProjectPortlet method prepareSourceCodeBundle.

private void prepareSourceCodeBundle(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_SOURCE_BUNDLE);
    if (id != null) {
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            Project project = client.getProjectById(id, user);
            request.setAttribute(PROJECT, project);
            request.setAttribute(DOCUMENT_ID, id);
            List<ProjectLink> mappedProjectLinks = createLinkedProjects(project, filterAndSortAttachments(SW360Constants.SOURCE_CODE_ATTACHMENT_TYPES), true, user);
            request.setAttribute(PROJECT_LIST, mappedProjectLinks);
            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 84 with Project

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

the class ProjectPortlet method updateVulnerabilitiesProject.

private void updateVulnerabilitiesProject(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    String projectId = request.getParameter(PortalConstants.PROJECT_ID);
    CveSearchService.Iface cveClient = thriftClients.makeCvesearchClient();
    try {
        VulnerabilityUpdateStatus importStatus = cveClient.updateForProject(projectId);
        JSONObject responseData = PortletUtils.importStatusToJSON(importStatus);
        PrintWriter writer = response.getWriter();
        writer.write(responseData.toString());
    } catch (TException e) {
        log.error("Error updating CVEs for project in backend.", e);
    }
}
Also used : CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) PrintWriter(java.io.PrintWriter)

Example 85 with Project

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

the class ProjectPortlet method exportReleasesSpreadsheet.

private void exportReleasesSpreadsheet(ResourceRequest request, ResourceResponse response) {
    final User user = UserCacheHolder.getUserFromRequest(request);
    try {
        String id = request.getParameter(PROJECT_ID);
        ProjectService.Iface client = thriftClients.makeProjectClient();
        Project project = null;
        if (!isNullOrEmpty(id)) {
            project = client.getProjectById(id, user);
        }
        if (project != null) {
            List<ReleaseClearingStatusData> releaseStringMap = client.getReleaseClearingStatuses(id, user);
            List<Release> releases = releaseStringMap.stream().map(ReleaseClearingStatusData::getRelease).sorted(Comparator.comparing(SW360Utils::printFullname)).collect(Collectors.toList());
            ReleaseExporter exporter = new ReleaseExporter(thriftClients.makeComponentClient(), releases, user, releaseStringMap);
            PortletResponseUtil.sendFile(request, response, String.format("releases-%s-%s-%s.xlsx", project.getName(), project.getVersion(), SW360Utils.getCreatedOn()), exporter.makeExcelExport(releases), CONTENT_TYPE_OPENXML_SPREADSHEET);
        }
    } catch (IOException | TException e) {
        log.error("An error occurred while generating the Excel export", e);
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ReleaseClearingStatusData(org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStatusData) IOException(java.io.IOException) ReleaseExporter(org.eclipse.sw360.exporter.ReleaseExporter) 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