Search in sources :

Example 61 with User

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

the class ScheduleAdminPortlet method prepareStandardView.

private void prepareStandardView(RenderRequest request, RenderResponse response) {
    try {
        User user = UserCacheHolder.getUserFromRequest(request);
        ScheduleService.Iface scheduleClient = new ThriftClients().makeScheduleClient();
        boolean isCveSearchScheduled = isCveSearchScheduled(scheduleClient, user);
        request.setAttribute(PortalConstants.CVESEARCH_IS_SCHEDULED, isCveSearchScheduled);
        boolean isAnyServiceScheduled = isAnyServiceScheduled(scheduleClient, user);
        request.setAttribute(PortalConstants.ANY_SERVICE_IS_SCHEDULED, isAnyServiceScheduled);
        int offsetInSeconds = scheduleClient.getFirstRunOffset(ThriftClients.CVESEARCH_SERVICE);
        request.setAttribute(PortalConstants.CVESEARCH_OFFSET, CommonUtils.formatTime(offsetInSeconds));
        int intervalInSeconds = scheduleClient.getInterval(ThriftClients.CVESEARCH_SERVICE);
        request.setAttribute(PortalConstants.CVESEARCH_INTERVAL, CommonUtils.formatTime(intervalInSeconds));
        String nextSync = scheduleClient.getNextSync(ThriftClients.CVESEARCH_SERVICE);
        request.setAttribute(PortalConstants.CVESEARCH_NEXT_SYNC, nextSync);
    } catch (TException te) {
        log.error(te.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ScheduleService(org.eclipse.sw360.datahandler.thrift.schedule.ScheduleService)

Example 62 with User

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

the class VendorPortlet method prepareStandardView.

private void prepareStandardView(RenderRequest request) throws IOException {
    List<Vendor> vendorList;
    try {
        final User user = UserCacheHolder.getUserFromRequest(request);
        VendorService.Iface vendorClient = thriftClients.makeVendorClient();
        vendorList = vendorClient.getAllVendors();
    } catch (TException e) {
        log.error("Could not get Vendors from backend ", e);
        vendorList = Collections.emptyList();
    }
    request.setAttribute(VENDOR_LIST, vendorList);
}
Also used : VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor)

Example 63 with User

use of org.eclipse.sw360.datahandler.thrift.users.User 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 64 with User

use of org.eclipse.sw360.datahandler.thrift.users.User 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 65 with User

use of org.eclipse.sw360.datahandler.thrift.users.User 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

User (org.eclipse.sw360.datahandler.thrift.users.User)169 TException (org.apache.thrift.TException)100 Release (org.eclipse.sw360.datahandler.thrift.components.Release)58 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)44 Test (org.junit.Test)30 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)27 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)26 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)20 ResponseEntity (org.springframework.http.ResponseEntity)20 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)19 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)18 IOException (java.io.IOException)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)16 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)16 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)13 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)12 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)12 Before (org.junit.Before)12 ArrayList (java.util.ArrayList)11