use of com.liferay.portal.kernel.json.JSONObject in project sw360portal by sw360.
the class ProjectImportPortlet method serveResource.
@Override
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
LoginState loginState = new LoginState();
String requestedAction = request.getParameter(ProjectImportConstants.USER_ACTION__IMPORT);
JSONObject responseData = handleRequestedAjaxAction(requestedAction, request, response, loginState);
PrintWriter writer = response.getWriter();
writer.write(responseData.toString());
}
use of com.liferay.portal.kernel.json.JSONObject in project sw360portal by sw360.
the class ProjectImportPortlet method handleRequestedAjaxAction.
public JSONObject handleRequestedAjaxAction(String requestedAction, ResourceRequest request, ResourceResponse response, LoginState loginState) throws IOException, PortletException {
PortletSession session = request.getPortletSession();
RemoteCredentials remoteCredentials = getRemoteCredentialsFromSession(session);
JSONObject responseData = JSONFactoryUtil.createJSONObject();
switch(requestedAction) {
case ProjectImportConstants.USER_ACTION__IMPORT_DATA:
User user = UserCacheHolder.getUserFromRequest(request);
List<String> selectedIds = getProjectIdsForImport(request);
importBdpProjects(user, selectedIds, responseData, remoteCredentials);
break;
case ProjectImportConstants.USER_ACTION__NEW_IMPORT_SOURCE:
RemoteCredentials newCredentials = new RemoteCredentials().setUsername(request.getParameter(ProjectImportConstants.USERNAME)).setPassword(request.getParameter(ProjectImportConstants.PASSWORD)).setServerUrl(request.getParameter(ProjectImportConstants.SERVER_URL));
if (!validateCredentials(newCredentials)) {
responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__UNAUTHORIZED);
} else {
setNewImportSource(newCredentials, session, responseData, loginState);
}
break;
case ProjectImportConstants.USER_ACTION__UPDATE_IMPORTABLES:
String projectName = request.getParameter(ProjectImportConstants.PROJECT_NAME);
updateImportables(responseData, loginState, remoteCredentials, projectName);
break;
case ProjectImportConstants.USER_ACTION__DISCONNECT:
putRemoteCredentialsIntoSession(session, new RemoteCredentials());
loginState.logout();
break;
default:
loginState.logout();
break;
}
return responseData;
}
use of com.liferay.portal.kernel.json.JSONObject in project sw360portal by sw360.
the class ProjectPortlet method updateVulnerabilitiesProject.
private void updateVulnerabilitiesProject(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
String projectId = request.getParameter(PortalConstants.PROJECT_ID);
CveSearchService.Iface cveClient = thriftClients.makeCvesearchClient();
try {
VulnerabilityUpdateStatus importStatus = cveClient.updateForProject(projectId);
JSONObject responseData = PortletUtils.importStatusToJSON(importStatus);
PrintWriter writer = response.getWriter();
writer.write(responseData.toString());
} catch (TException e) {
log.error("Error updating CVEs for project in backend.", e);
}
}
use of com.liferay.portal.kernel.json.JSONObject in project sw360portal by sw360.
the class ProjectPortlet method serveGetClearingStateSummaries.
private void serveGetClearingStateSummaries(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
User user = UserCacheHolder.getUserFromRequest(request);
List<Project> projects;
String[] ids = request.getParameterValues(Project._Fields.ID.toString() + "[]");
if (ids == null || ids.length == 0) {
JSONArray jsonResponse = createJSONArray();
writeJSON(request, response, jsonResponse);
} else {
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
projects = client.getProjectsById(Arrays.asList(ids), user);
} catch (TException e) {
log.error("Could not fetch project summary from backend!", e);
projects = Collections.emptyList();
}
projects = getWithFilledClearingStateSummaryIncludingSubprojects(projects, user);
JSONArray jsonResponse = createJSONArray();
ThriftJsonSerializer thriftJsonSerializer = new ThriftJsonSerializer();
for (Project project : projects) {
try {
JSONObject row = createJSONObject();
row.put("id", project.getId());
row.put("clearing", JsonHelpers.toJson(project.getReleaseClearingStateSummary(), thriftJsonSerializer));
ProjectClearingState clearingState = project.getClearingState();
if (clearingState == null) {
row.put("clearingstate", "Unknown");
} else {
row.put("clearingstate", ThriftEnumUtils.enumToString(clearingState));
}
jsonResponse.put(row);
} catch (JSONException e) {
log.error("cannot serialize json", e);
}
}
writeJSON(request, response, jsonResponse);
}
}
use of com.liferay.portal.kernel.json.JSONObject in project sw360portal by sw360.
the class Sw360Portlet method renderRequestSummary.
protected void renderRequestSummary(PortletRequest request, MimeResponse response, RequestSummary requestSummary) {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("result", requestSummary.requestStatus.toString());
if (requestSummary.isSetTotalAffectedElements())
jsonObject.put("totalAffectedObjects", requestSummary.totalAffectedElements);
if (requestSummary.isSetTotalElements())
jsonObject.put("totalObjects", requestSummary.totalElements);
if (requestSummary.isSetMessage())
jsonObject.put("message", requestSummary.message);
try {
writeJSON(request, response, jsonObject);
} catch (IOException e) {
log.error("Problem rendering RequestStatus", e);
}
}
Aggregations