Search in sources :

Example 21 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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 22 with Component

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

the class MySubscriptionsPortlet method doView.

@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    List<Component> components = null;
    List<Release> releases = null;
    try {
        final User user = UserCacheHolder.getUserFromRequest(request);
        ComponentService.Iface componentClient = thriftClients.makeComponentClient();
        components = componentClient.getSubscribedComponents(user);
        releases = componentClient.getSubscribedReleases(user);
    } catch (TException e) {
        log.error("Could not fetch your subscriptions from backend", e);
    }
    request.setAttribute(PortalConstants.COMPONENT_LIST, CommonUtils.nullToEmptyList(components));
    request.setAttribute(PortalConstants.RELEASE_LIST, CommonUtils.nullToEmptyList(releases));
    super.doView(request, response);
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 23 with Component

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

the class ComponentPortlet method exportExcel.

private void exportExcel(ResourceRequest request, ResourceResponse response) {
    final User user = UserCacheHolder.getUserFromRequest(request);
    try {
        boolean extendedByReleases = Boolean.valueOf(request.getParameter(PortalConstants.EXTENDED_EXCEL_EXPORT));
        List<Component> components = getFilteredComponentList(request);
        ComponentExporter exporter = new ComponentExporter(thriftClients.makeComponentClient(), components, user, extendedByReleases);
        PortletResponseUtil.sendFile(request, response, "Components.xlsx", exporter.makeExcelExport(components), CONTENT_TYPE_OPENXML_SPREADSHEET);
    } catch (IOException | SW360Exception e) {
        log.error("An error occurred while generating the Excel export", e);
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentExporter(org.eclipse.sw360.exporter.ComponentExporter) IOException(java.io.IOException)

Example 24 with Component

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

the class ComponentPortlet method generateComponentMergeWizardStep0Response.

private void generateComponentMergeWizardStep0Response(ActionRequest request, JsonGenerator jsonGenerator) throws IOException, TException {
    User sessionUser = UserCacheHolder.getUserFromRequest(request);
    ComponentService.Iface cClient = thriftClients.makeComponentClient();
    List<Component> componentSummary = cClient.getComponentSummary(sessionUser);
    jsonGenerator.writeStartObject();
    jsonGenerator.writeArrayFieldStart("components");
    componentSummary.stream().forEach(component -> {
        try {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("id", component.getId());
            jsonGenerator.writeStringField("name", SW360Utils.printName(component));
            jsonGenerator.writeStringField("createdBy", component.getCreatedBy());
            jsonGenerator.writeNumberField("releases", component.getReleaseIdsSize());
            jsonGenerator.writeEndObject();
        } catch (IOException e) {
            log.error("An error occurred while generating wizard response", e);
        }
    });
    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndObject();
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) IOException(java.io.IOException)

Example 25 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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)

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