Search in sources :

Example 56 with RequestStatus

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

the class ProjectDatabaseHandler method deleteProject.

// /////////////////////////////
// DELETE INDIVIDUAL OBJECTS //
// /////////////////////////////
public RequestStatus deleteProject(String id, User user) throws SW360Exception {
    Project project = repository.get(id);
    assertNotNull(project);
    if (checkIfInUse(id)) {
        return RequestStatus.IN_USE;
    }
    // Remove the project if the user is allowed to do it by himself
    if (makePermission(project, user).isActionAllowed(RequestedAction.DELETE)) {
        removeProjectAndCleanUp(project);
        return RequestStatus.SUCCESS;
    } else {
        return moderator.deleteProject(project, user);
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 57 with RequestStatus

use of org.eclipse.sw360.datahandler.thrift.RequestStatus 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 58 with RequestStatus

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

the class ComponentPortlet method updateVulnerabilityVerification.

private void updateVulnerabilityVerification(ResourceRequest request, ResourceResponse response) throws IOException {
    String[] releaseIds = request.getParameterValues(PortalConstants.RELEASE_IDS + "[]");
    String[] vulnerabilityIds = request.getParameterValues(PortalConstants.VULNERABILITY_IDS + "[]");
    User user = UserCacheHolder.getUserFromRequest(request);
    VulnerabilityService.Iface vulClient = thriftClients.makeVulnerabilityClient();
    RequestStatus requestStatus = RequestStatus.SUCCESS;
    try {
        if (vulnerabilityIds.length != releaseIds.length) {
            throw new SW360Exception("Length of vulnerabilities (" + vulnerabilityIds.length + ") does not match the length of releases (" + releaseIds.length + ")!");
        }
        for (int i = 0; i < vulnerabilityIds.length; i++) {
            String vulnerabilityId = vulnerabilityIds[i];
            String releaseId = releaseIds[i];
            Vulnerability dbVulnerability = vulClient.getVulnerabilityByExternalId(vulnerabilityId, user);
            ReleaseVulnerabilityRelation dbRelation = vulClient.getRelationByIds(releaseId, dbVulnerability.getId(), user);
            ReleaseVulnerabilityRelation resultRelation = ComponentPortletUtils.updateReleaseVulnerabilityRelationFromRequest(dbRelation, request);
            requestStatus = vulClient.updateReleaseVulnerabilityRelation(resultRelation, user);
            if (requestStatus != RequestStatus.SUCCESS) {
                break;
            }
        }
    } catch (TException e) {
        log.error("Error updating vulnerability verification in backend.", e);
        requestStatus = RequestStatus.FAILURE;
    }
    JSONObject responseData = JSONFactoryUtil.createJSONObject();
    responseData.put(PortalConstants.REQUEST_STATUS, requestStatus.toString());
    PrintWriter writer = response.getWriter();
    writer.write(responseData.toString());
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) VulnerabilityService(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) JSONObject(com.liferay.portal.kernel.json.JSONObject) ReleaseVulnerabilityRelation(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation) PrintWriter(java.io.PrintWriter)

Example 59 with RequestStatus

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

the class ComponentPortlet method updateComponent.

// ! Actions
@UsedAsLiferayAction
public void updateComponent(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String id = request.getParameter(COMPONENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        if (id != null) {
            Component component = client.getComponentByIdForEdit(id, user);
            ComponentPortletUtils.updateComponentFromRequest(request, component);
            String ModerationRequestCommentMsg = request.getParameter(MODERATION_REQUEST_COMMENT);
            user.setCommentMadeDuringModerationRequest(ModerationRequestCommentMsg);
            RequestStatus requestStatus = client.updateComponent(component, user);
            setSessionMessage(request, requestStatus, "Component", "update", component.getName());
            cleanUploadHistory(user.getEmail(), id);
            response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
            response.setRenderParameter(COMPONENT_ID, request.getParameter(COMPONENT_ID));
        } else {
            Component component = new Component();
            ComponentPortletUtils.updateComponentFromRequest(request, component);
            AddDocumentRequestSummary summary = client.addComponent(component, user);
            AddDocumentRequestStatus status = summary.getRequestStatus();
            switch(status) {
                case SUCCESS:
                    String successMsg = "Component " + component.getName() + " added successfully";
                    SessionMessages.add(request, "request_processed", successMsg);
                    response.setRenderParameter(COMPONENT_ID, summary.getId());
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    break;
                case DUPLICATE:
                    setSW360SessionError(request, ErrorMessages.COMPONENT_DUPLICATE);
                    response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
                    prepareRequestForEditAfterDuplicateError(request, component);
                    break;
                default:
                    setSW360SessionError(request, ErrorMessages.COMPONENT_NOT_ADDED);
                    response.setRenderParameter(PAGENAME, PAGENAME_VIEW);
            }
        }
    } catch (TException e) {
        log.error("Error fetching component from backend!", e);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 60 with RequestStatus

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

the class LicensesPortlet method updateWhiteList.

@UsedAsLiferayAction
public void updateWhiteList(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    // we get a list of todoDatabaseIds and Booleans and we have to update the whiteList of each todo if it changed
    String licenseId = request.getParameter(LICENSE_ID);
    String[] whiteList = request.getParameterValues("whiteList");
    // As empty arrays are not passed as parameters
    if (whiteList == null)
        whiteList = new String[0];
    final User user = UserCacheHolder.getUserFromRequest(request);
    String moderationComment = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
    if (moderationComment != null) {
        user.setCommentMadeDuringModerationRequest(moderationComment);
    }
    try {
        LicenseService.Iface client = thriftClients.makeLicenseClient();
        RequestStatus requestStatus = client.updateWhitelist(licenseId, ImmutableSet.copyOf(whiteList), user);
        setSessionMessage(request, requestStatus, "License", "update");
    } catch (TException e) {
        log.error("Error updating whitelist!", e);
    }
    response.setRenderParameter(LICENSE_ID, licenseId);
    response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
    response.setRenderParameter(SELECTED_TAB, "Todos");
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Aggregations

RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)52 TException (org.apache.thrift.TException)27 User (org.eclipse.sw360.datahandler.thrift.users.User)24 Test (org.junit.Test)16 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)13 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)10 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)5 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)4 AddDocumentRequestStatus (org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)4 VendorService (org.eclipse.sw360.datahandler.thrift.vendors.VendorService)4 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)3 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 Vulnerability (org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)3 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 PrintWriter (java.io.PrintWriter)2 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)2 Component (org.eclipse.sw360.datahandler.thrift.components.Component)2 UpdateType (org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)2