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