Search in sources :

Example 86 with Project

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

the class ProjectPortlet method serveGetClearingStateSummaries.

private void serveGetClearingStateSummaries(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
    User user = UserCacheHolder.getUserFromRequest(request);
    List<Project> projects;
    String[] ids = request.getParameterValues(Project._Fields.ID.toString() + "[]");
    if (ids == null || ids.length == 0) {
        JSONArray jsonResponse = createJSONArray();
        writeJSON(request, response, jsonResponse);
    } else {
        try {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            projects = client.getProjectsById(Arrays.asList(ids), user);
        } catch (TException e) {
            log.error("Could not fetch project summary from backend!", e);
            projects = Collections.emptyList();
        }
        projects = getWithFilledClearingStateSummaryIncludingSubprojects(projects, user);
        JSONArray jsonResponse = createJSONArray();
        ThriftJsonSerializer thriftJsonSerializer = new ThriftJsonSerializer();
        for (Project project : projects) {
            try {
                JSONObject row = createJSONObject();
                row.put("id", project.getId());
                row.put("clearing", JsonHelpers.toJson(project.getReleaseClearingStateSummary(), thriftJsonSerializer));
                ProjectClearingState clearingState = project.getClearingState();
                if (clearingState == null) {
                    row.put("clearingstate", "Unknown");
                } else {
                    row.put("clearingstate", ThriftEnumUtils.enumToString(clearingState));
                }
                jsonResponse.put(row);
            } catch (JSONException e) {
                log.error("cannot serialize json", e);
            }
        }
        writeJSON(request, response, jsonResponse);
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) JSONFactoryUtil.createJSONArray(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray) JSONArray(com.liferay.portal.kernel.json.JSONArray) JSONException(com.liferay.portal.kernel.json.JSONException) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject)

Example 87 with Project

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

the class ProjectPortlet method update.

@UsedAsLiferayAction
public void update(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String id = request.getParameter(PROJECT_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    RequestStatus requestStatus;
    try {
        ProjectService.Iface client = thriftClients.makeProjectClient();
        if (id != null) {
            Project project = client.getProjectByIdForEdit(id, user);
            ProjectPortletUtils.updateProjectFromRequest(request, project);
            String ModerationRequestCommentMsg = request.getParameter(MODERATION_REQUEST_COMMENT);
            user.setCommentMadeDuringModerationRequest(ModerationRequestCommentMsg);
            requestStatus = client.updateProject(project, user);
            setSessionMessage(request, requestStatus, "Project", "update", printName(project));
            cleanUploadHistory(user.getEmail(), id);
            response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
            response.setRenderParameter(PROJECT_ID, request.getParameter(PROJECT_ID));
        } else {
            // Add project
            Project project = new Project();
            ProjectPortletUtils.updateProjectFromRequest(request, project);
            AddDocumentRequestSummary summary = client.addProject(project, user);
            AddDocumentRequestStatus status = summary.getRequestStatus();
            switch(status) {
                case SUCCESS:
                    String successMsg = "Project " + printName(project) + " added successfully";
                    SessionMessages.add(request, "request_processed", successMsg);
                    response.setRenderParameter(PROJECT_ID, summary.getId());
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    break;
                case DUPLICATE:
                    setSW360SessionError(request, ErrorMessages.PROJECT_DUPLICATE);
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    prepareRequestForEditAfterDuplicateError(request, project, user);
                    break;
                default:
                    setSW360SessionError(request, ErrorMessages.PROJECT_NOT_ADDED);
                    response.setRenderParameter(PAGENAME, PAGENAME_VIEW);
            }
        }
    } catch (TException e) {
        log.error("Error updating project in backend!", e);
        setSW360SessionError(request, ErrorMessages.DEFAULT_ERROR_MESSAGE);
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 88 with Project

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

the class ProjectPortlet method serveNewTableRowLinkedProjects.

private void serveNewTableRowLinkedProjects(ResourceRequest request, ResourceResponse response, String[] linkedIds) throws IOException, PortletException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    List<ProjectLink> linkedProjects = new ArrayList<>();
    try {
        ProjectService.Iface client = thriftClients.makeProjectClient();
        for (String linkedId : linkedIds) {
            Project project = client.getProjectById(linkedId, user);
            ProjectLink linkedProject = new ProjectLink(linkedId, project.getName());
            linkedProject.setRelation(ProjectRelationship.CONTAINED);
            linkedProject.setVersion(project.getVersion());
            linkedProjects.add(linkedProject);
        }
    } catch (TException e) {
        log.error("Error getting projects!", e);
        throw new PortletException("cannot get projects " + Arrays.toString(linkedIds), e);
    }
    request.setAttribute(PROJECT_LIST, linkedProjects);
    include("/html/projects/ajax/linkedProjectsAjax.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 89 with Project

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

the class ProjectPortlet method getFilteredProjectList.

private List<Project> getFilteredProjectList(PortletRequest request) throws IOException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    Map<String, Set<String>> filterMap = loadFilterMapFromRequest(request);
    loadAndStoreStickyProjectGroup(request, user, filterMap);
    String id = request.getParameter(Project._Fields.ID.toString());
    return findProjectsByFiltersOrId(filterMap, id, user);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 90 with Project

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

the class ProjectPortlet method prepareProjectDuplicate.

private void prepareProjectDuplicate(RenderRequest request) {
    User user = UserCacheHolder.getUserFromRequest(request);
    String id = request.getParameter(PROJECT_ID);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
    try {
        if (id != null) {
            ProjectService.Iface client = thriftClients.makeProjectClient();
            String emailFromRequest = LifeRayUserSession.getEmailFromRequest(request);
            String department = user.getDepartment();
            Project newProject = PortletUtils.cloneProject(emailFromRequest, department, client.getProjectById(id, user));
            setAttachmentsInRequest(request, newProject.getAttachments());
            request.setAttribute(PROJECT, newProject);
            putDirectlyLinkedProjectsInRequest(request, newProject, user);
            putDirectlyLinkedReleasesInRequest(request, newProject);
            request.setAttribute(USING_PROJECTS, Collections.emptySet());
        } else {
            Project project = new Project();
            project.setBusinessUnit(user.getDepartment());
            setAttachmentsInRequest(request, project.getAttachments());
            request.setAttribute(PROJECT, project);
            putDirectlyLinkedProjectsInRequest(request, project, user);
            putDirectlyLinkedReleasesInRequest(request, project);
            request.setAttribute(USING_PROJECTS, Collections.emptySet());
        }
    } catch (TException e) {
        log.error("Error fetching project from backend!", e);
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

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