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();
}
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();
}
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;
}
Aggregations