Search in sources :

Example 61 with Component

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

the class ComponentPortlet method prepareReleaseDuplicate.

private void prepareReleaseDuplicate(RenderRequest request, RenderResponse response) throws PortletException {
    String id = request.getParameter(COMPONENT_ID);
    String releaseId = request.getParameter(RELEASE_ID);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_RELEASE);
    final User user = UserCacheHolder.getUserFromRequest(request);
    if (isNullOrEmpty(releaseId)) {
        throw new PortletException("Release ID not set!");
    }
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        String emailFromRequest = LifeRayUserSession.getEmailFromRequest(request);
        Release release = PortletUtils.cloneRelease(emailFromRequest, client.getReleaseById(releaseId, user));
        if (isNullOrEmpty(id)) {
            id = release.getComponentId();
        }
        Component component = client.getComponentById(id, user);
        addComponentBreadcrumb(request, response, component);
        request.setAttribute(COMPONENT, component);
        request.setAttribute(RELEASE_LIST, Collections.emptyList());
        setUsingDocs(request, null, user, client);
        request.setAttribute(RELEASE, release);
        request.setAttribute(PortalConstants.ATTACHMENTS, Collections.emptySet());
    } 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 62 with Component

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

the class ComponentPortlet method updateVulnerabilitiesComponent.

private void updateVulnerabilitiesComponent(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    String componentId = request.getParameter(PortalConstants.COMPONENT_ID);
    CveSearchService.Iface cveClient = thriftClients.makeCvesearchClient();
    try {
        VulnerabilityUpdateStatus importStatus = cveClient.updateForComponent(componentId);
        JSONObject responseData = PortletUtils.importStatusToJSON(importStatus);
        PrintWriter writer = response.getWriter();
        writer.write(responseData.toString());
    } catch (TException e) {
        log.error("Error updating CVEs for component in backend.", e);
    }
}
Also used : CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) TException(org.apache.thrift.TException) JSONObject(com.liferay.portal.kernel.json.JSONObject) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) PrintWriter(java.io.PrintWriter)

Example 63 with Component

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

the class ComponentPortletUtils method unsubscribeComponent.

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

Example 64 with Component

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

the class ComponentPortletUtils method subscribeComponent.

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

Example 65 with Component

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

the class MyComponentsPortlet method doView.

@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    List<Component> components;
    try {
        final User user = UserCacheHolder.getUserFromRequest(request);
        components = thriftClients.makeComponentClient().getMyComponents(user);
    } catch (TException e) {
        log.error("Could not fetch your components from backend", e);
        components = new ArrayList<>();
    }
    request.setAttribute("components", CommonUtils.nullToEmptyList(components));
    super.doView(request, response);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ArrayList(java.util.ArrayList) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Aggregations

Component (org.eclipse.sw360.datahandler.thrift.components.Component)38 User (org.eclipse.sw360.datahandler.thrift.users.User)30 TException (org.apache.thrift.TException)23 Release (org.eclipse.sw360.datahandler.thrift.components.Release)23 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)10 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)8 Before (org.junit.Before)7 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)6 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)5 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)5 IOException (java.io.IOException)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Test (org.junit.Test)4 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)3 FluentIterable (com.google.common.collect.FluentIterable)2 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2