Search in sources :

Example 21 with RequestStatus

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

the class MyTaskSubmissionsPortlet method serveDeleteModerationRequest.

private void serveDeleteModerationRequest(ResourceRequest request, ResourceResponse response) throws IOException {
    RequestStatus requestStatus = ModerationPortletUtils.deleteModerationRequest(request, log);
    serveRequestStatus(request, response, requestStatus, "Problem removing moderation request", log);
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 22 with RequestStatus

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

the class ComponentPortlet method generateComponentMergeWizardStep3Response.

private void generateComponentMergeWizardStep3Response(ActionRequest request, JsonGenerator jsonGenerator) throws IOException, TException {
    ObjectMapper om = new ObjectMapper();
    ComponentService.Iface cClient = thriftClients.makeComponentClient();
    // extract request data
    User sessionUser = UserCacheHolder.getUserFromRequest(request);
    Component componentSelection = om.readValue(request.getParameter(COMPONENT_SELECTION), Component.class);
    String componentSourceId = request.getParameter(COMPONENT_SOURCE_ID);
    // perform the real merge, update merge target and delete merge source
    RequestStatus status = cClient.mergeComponents(componentSelection.getId(), componentSourceId, componentSelection, sessionUser);
    // generate redirect url
    LiferayPortletURL componentUrl = createDetailLinkTemplate(request);
    componentUrl.setParameter(PortalConstants.PAGENAME, PortalConstants.PAGENAME_DETAIL);
    componentUrl.setParameter(PortalConstants.COMPONENT_ID, componentSelection.getId());
    // write response JSON
    jsonGenerator.writeStartObject();
    jsonGenerator.writeStringField("redirectUrl", componentUrl.toString());
    if (status == RequestStatus.IN_USE) {
        jsonGenerator.writeStringField("error", "Cannot merge when one of the components has an active moderation request.");
    } else if (status == RequestStatus.FAILURE) {
        jsonGenerator.writeStringField("error", "You do not have sufficient permissions.");
    }
    jsonGenerator.writeEndObject();
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with RequestStatus

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

the class ComponentPortlet method updateRelease.

@UsedAsLiferayAction
public void updateRelease(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String id = request.getParameter(COMPONENT_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    if (id != null) {
        try {
            ComponentService.Iface client = thriftClients.makeComponentClient();
            Component component = client.getComponentById(id, user);
            Release release;
            String releaseId = request.getParameter(RELEASE_ID);
            if (releaseId != null) {
                release = client.getReleaseByIdForEdit(releaseId, user);
                ComponentPortletUtils.updateReleaseFromRequest(request, release);
                String ModerationRequestCommentMsg = request.getParameter(MODERATION_REQUEST_COMMENT);
                user.setCommentMadeDuringModerationRequest(ModerationRequestCommentMsg);
                RequestStatus requestStatus = client.updateRelease(release, user);
                setSessionMessage(request, requestStatus, "Release", "update", printName(release));
                cleanUploadHistory(user.getEmail(), releaseId);
                response.setRenderParameter(PAGENAME, PAGENAME_RELEASE_DETAIL);
                response.setRenderParameter(COMPONENT_ID, request.getParameter(COMPONENT_ID));
                response.setRenderParameter(RELEASE_ID, request.getParameter(RELEASE_ID));
            } else {
                release = new Release();
                release.setComponentId(component.getId());
                release.setClearingState(ClearingState.NEW_CLEARING);
                ComponentPortletUtils.updateReleaseFromRequest(request, release);
                AddDocumentRequestSummary summary = client.addRelease(release, user);
                AddDocumentRequestStatus status = summary.getRequestStatus();
                switch(status) {
                    case SUCCESS:
                        response.setRenderParameter(RELEASE_ID, summary.getId());
                        String successMsg = "Release " + printName(release) + " added successfully";
                        SessionMessages.add(request, "request_processed", successMsg);
                        response.setRenderParameter(PAGENAME, PAGENAME_EDIT_RELEASE);
                        break;
                    case DUPLICATE:
                        setSW360SessionError(request, ErrorMessages.RELEASE_DUPLICATE);
                        response.setRenderParameter(PAGENAME, PAGENAME_EDIT_RELEASE);
                        prepareRequestForReleaseEditAfterDuplicateError(request, release);
                        break;
                    default:
                        setSW360SessionError(request, ErrorMessages.RELEASE_NOT_ADDED);
                        response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
                }
                response.setRenderParameter(COMPONENT_ID, request.getParameter(COMPONENT_ID));
            }
        } catch (TException e) {
            log.error("Error fetching release from backend!", e);
        }
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 24 with RequestStatus

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

the class LicensesPortlet method delete.

@UsedAsLiferayAction
public void delete(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    RequestStatus requestStatus = deleteLicense(request);
    setSessionMessage(request, requestStatus, "License", "remove");
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 25 with RequestStatus

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

the class LicensesPortlet method update.

@UsedAsLiferayAction
public void update(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    LicenseService.Iface client = thriftClients.makeLicenseClient();
    String licenseId = request.getParameter(LICENSE_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    License license = prepareLicenseForUpdate(request, client, licenseId, user);
    boolean isNewLicense = isNullOrEmpty(licenseId);
    boolean isAttemptToOverwriteExistingByNew = isAttemptToOverwriteExistingByNew(license, user, isNewLicense, client);
    RequestStatus requestStatus = updateLicense(license, user, isAttemptToOverwriteExistingByNew, client);
    if (isAttemptToOverwriteExistingByNew) {
        response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
        setSW360SessionError(request, ErrorMessages.LICENSE_SHORTNAME_TAKEN);
        request.setAttribute(KEY_LICENSE_DETAIL, license);
    } else if (isNewLicense) {
        response.setRenderParameter(PAGENAME, PAGENAME_VIEW);
        setSessionMessage(request, requestStatus, "License", "adde");
    } else {
        response.setRenderParameter(LICENSE_ID, licenseId);
        response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
        response.setRenderParameter(SELECTED_TAB, "Details");
        setSessionMessage(request, requestStatus, "License", "update");
    }
}
Also used : 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