Search in sources :

Example 1 with LiferayPortletURL

use of com.liferay.portal.kernel.portlet.LiferayPortletURL 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 2 with LiferayPortletURL

use of com.liferay.portal.kernel.portlet.LiferayPortletURL in project sw360portal by sw360.

the class ComponentPortlet method respondSimilarComponentsResponseJson.

private void respondSimilarComponentsResponseJson(ResourceRequest request, ResourceResponse response, List<Component> similarComponents, List<String> errors) throws IOException {
    response.setContentType(ContentTypes.APPLICATION_JSON);
    JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(response.getWriter());
    jsonGenerator.writeStartObject();
    // adding common title
    jsonGenerator.writeStringField("title", "To avoid duplicate components, check these similar ones! Does yours already exist?");
    // adding errors or empty array if none occured
    jsonGenerator.writeFieldName("errors");
    jsonGenerator.writeStartArray();
    errors.stream().forEach(e -> {
        try {
            jsonGenerator.writeString(e);
        } catch (IOException e1) {
            log.error("Exception while writing errors list to simililar components json", e1);
        }
    });
    jsonGenerator.writeEndArray();
    // adding components or empty array if there are none
    LiferayPortletURL componentUrl = createDetailLinkTemplate(request);
    jsonGenerator.writeFieldName("links");
    jsonGenerator.writeStartArray();
    similarComponents.stream().forEach(c -> {
        componentUrl.setParameter(PortalConstants.COMPONENT_ID, c.getId());
        try {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("target", componentUrl.toString());
            jsonGenerator.writeStringField("text", c.getName());
            jsonGenerator.writeEndObject();
        } catch (IOException e1) {
            log.error("Exception while writing components list to simililar components json", e1);
        }
    });
    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndObject();
    jsonGenerator.close();
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL)

Example 3 with LiferayPortletURL

use of com.liferay.portal.kernel.portlet.LiferayPortletURL in project sw360portal by sw360.

the class ComponentPortlet method createDetailLinkTemplate.

private LiferayPortletURL createDetailLinkTemplate(PortletRequest request) {
    String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);
    ThemeDisplay tD = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long plid = tD.getPlid();
    LiferayPortletURL componentUrl = PortletURLFactoryUtil.create(request, portletId, plid, PortletRequest.RENDER_PHASE);
    componentUrl.setParameter(PortalConstants.PAGENAME, PortalConstants.PAGENAME_DETAIL);
    return componentUrl;
}
Also used : LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Aggregations

LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)1 IOException (java.io.IOException)1 User (org.eclipse.sw360.datahandler.thrift.users.User)1