Search in sources :

Example 16 with RequestStatus

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

the class ScheduleAdminPortlet method unscheduleAllServices.

@UsedAsLiferayAction
public void unscheduleAllServices(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    try {
        User user = UserCacheHolder.getUserFromRequest(request);
        RequestStatus requestStatus = new ThriftClients().makeScheduleClient().unscheduleAllServices(user);
        setSessionMessage(request, requestStatus, "Every task", "unschedule");
    } catch (TException e) {
        log.error(e);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 17 with RequestStatus

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

the class VendorPortlet method removeVendor.

private void removeVendor(PortletRequest request, ResourceResponse response) throws IOException {
    final RequestStatus requestStatus = ComponentPortletUtils.deleteVendor(request, log);
    serveRequestStatus(request, response, requestStatus, "Problem removing vendor", log);
}
Also used : RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Example 18 with RequestStatus

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

the class ComponentPortletUtils method subscribeRelease.

public static RequestStatus subscribeRelease(ResourceRequest request, Logger log) {
    String id = request.getParameter(PortalConstants.RELEASE_ID);
    if (id != null) {
        try {
            ComponentService.Iface client = new ThriftClients().makeComponentClient();
            User user = UserCacheHolder.getUserFromRequest(request);
            return client.subscribeRelease(id, user);
        } catch (TException e) {
            log.error("Could not subscribe to release", e);
        }
    }
    return RequestStatus.FAILURE;
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 19 with RequestStatus

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

the class ComponentPortletUtils method deleteComponent.

public static RequestStatus deleteComponent(PortletRequest request, Logger log) {
    String id = request.getParameter(PortalConstants.COMPONENT_ID);
    if (id != null) {
        try {
            String deleteCommentEncoded = request.getParameter(PortalConstants.MODERATION_REQUEST_COMMENT);
            User user = UserCacheHolder.getUserFromRequest(request);
            if (deleteCommentEncoded != null) {
                String deleteComment = new String(Base64.getDecoder().decode(deleteCommentEncoded));
                user.setCommentMadeDuringModerationRequest(deleteComment);
            }
            ComponentService.Iface client = new ThriftClients().makeComponentClient();
            return client.deleteComponent(id, user);
        } catch (TException e) {
            log.error("Could not delete component from DB", e);
        }
    }
    return RequestStatus.FAILURE;
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 20 with RequestStatus

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

the class ComponentPortletUtils method deleteVendor.

public static RequestStatus deleteVendor(PortletRequest request, Logger log) {
    String vendorId = request.getParameter(PortalConstants.VENDOR_ID);
    if (vendorId != null) {
        try {
            User user = UserCacheHolder.getUserFromRequest(request);
            ThriftClients thriftClients = new ThriftClients();
            ComponentService.Iface componentClient = thriftClients.makeComponentClient();
            VendorService.Iface client = thriftClients.makeVendorClient();
            RequestStatus global_status = RequestStatus.SUCCESS;
            List<Release> releases = componentClient.getReleasesFromVendorId(vendorId, user);
            boolean mayWriteToAllReleases = true;
            for (Release release : releases) {
                Map<RequestedAction, Boolean> permissions = release.getPermissions();
                mayWriteToAllReleases &= permissions.get(RequestedAction.WRITE);
            }
            if (!mayWriteToAllReleases) {
                return RequestStatus.FAILURE;
            }
            for (Release release : releases) {
                release.unsetVendorId();
                RequestStatus local_status = componentClient.updateRelease(release, user);
                if (local_status != RequestStatus.SUCCESS)
                    global_status = local_status;
            }
            if (global_status == RequestStatus.SUCCESS) {
                return client.deleteVendor(vendorId, user);
            } else {
                return global_status;
            }
        } catch (TException e) {
            log.error("Could not delete release from DB", e);
        }
    }
    return RequestStatus.FAILURE;
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction) VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService)

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