use of com.liferay.portal.kernel.json.JSONArray in project sw360portal by sw360.
the class FossologyAwarePortlet method serveFossologyStatus.
protected void serveFossologyStatus(ResourceRequest request, ResourceResponse response) throws IOException {
DataTablesParameters parameters = DataTablesParser.parametersFrom(request);
Release release = getReleaseForFossologyStatus(request);
Map<String, FossologyStatus> fossologyStatus = getFossologyStatus(release);
JSONObject jsonResponse = JSONFactoryUtil.createJSONObject();
JSONArray data = JSONFactoryUtil.createJSONArray();
for (Map.Entry<String, FossologyStatus> entry : fossologyStatus.entrySet()) {
JSONObject row = JSONFactoryUtil.createJSONObject();
row.put("0", entry.getKey());
row.put("1", ThriftEnumUtils.enumToString(entry.getValue()));
data.put(row);
}
jsonResponse.put("attachment", getFossologyUploadableAttachment(release));
jsonResponse.put("data", data);
jsonResponse.put("draw", parameters.getDraw());
jsonResponse.put("recordsTotal", fossologyStatus.size());
jsonResponse.put("recordsFiltered", fossologyStatus.size());
writeJSON(request, response, jsonResponse);
}
use of com.liferay.portal.kernel.json.JSONArray in project sw360portal by sw360.
the class PortletUtils method importStatusToJSON.
public static JSONObject importStatusToJSON(VulnerabilityUpdateStatus updateStatus) {
JSONObject responseData = JSONFactoryUtil.createJSONObject();
if (!updateStatus.isSetStatusToVulnerabilityIds() || !updateStatus.isSetRequestStatus()) {
responseData.put(PortalConstants.REQUEST_STATUS, PortalConstants.RESPONSE__IMPORT_GENERAL_FAILURE);
return responseData;
}
if (updateStatus.getRequestStatus().equals(RequestStatus.FAILURE) && nullToEmptyList(updateStatus.getStatusToVulnerabilityIds().get(UpdateType.FAILED)).size() == 0) {
responseData.put(PortalConstants.REQUEST_STATUS, PortalConstants.RESPONSE__IMPORT_GENERAL_FAILURE);
return responseData;
}
responseData.put(PortalConstants.REQUEST_STATUS, updateStatus.getRequestStatus().toString());
JSONArray jsonFailedIds = JSONFactoryUtil.createJSONArray();
JSONArray jsonNewIds = JSONFactoryUtil.createJSONArray();
JSONArray jsonUpdatedIds = JSONFactoryUtil.createJSONArray();
updateStatus.getStatusToVulnerabilityIds().get(UpdateType.FAILED).forEach(jsonFailedIds::put);
updateStatus.getStatusToVulnerabilityIds().get(UpdateType.NEW).forEach(jsonNewIds::put);
updateStatus.getStatusToVulnerabilityIds().get(UpdateType.UPDATED).forEach(jsonUpdatedIds::put);
responseData.put(PortalConstants.UPDATE_VULNERABILITIES__FAILED_IDS, jsonFailedIds);
responseData.put(PortalConstants.UPDATE_VULNERABILITIES__NEW_IDS, jsonNewIds);
responseData.put(PortalConstants.UPDATE_VULNERABILITIES__UPDATED_IDS, jsonUpdatedIds);
return responseData;
}
use of com.liferay.portal.kernel.json.JSONArray in project liferay-ide by liferay.
the class LiferayActivityService method getTemplateParams.
protected JSONArray getTemplateParams(Map<String, String> map) {
if (map == null) {
return null;
}
JSONArray templateParamsJSONArray = JSONFactoryUtil.createJSONArray();
for (Entry<String, String> entry : map.entrySet()) {
JSONObject templateParamJSONObject = JSONFactoryUtil.createJSONObject();
String name = entry.getKey();
String value = entry.getValue();
templateParamJSONObject.put(name, value);
templateParamsJSONArray.put(templateParamJSONObject);
}
return templateParamsJSONArray;
}
use of com.liferay.portal.kernel.json.JSONArray in project sw360portal by sw360.
the class ProjectImportPortlet method importBdpProjects.
private void importBdpProjects(User user, List<String> selectedIds, JSONObject responseData, RemoteCredentials remoteCredentials) throws PortletException, IOException {
ImportStatus importStatus = importDatasources(selectedIds, user, remoteCredentials);
JSONObject jsonFailedIds = JSONFactoryUtil.createJSONObject();
JSONArray jsonSuccessfulIds = JSONFactoryUtil.createJSONArray();
if (importStatus.isSetRequestStatus() && importStatus.getRequestStatus().equals(RequestStatus.SUCCESS)) {
importStatus.getFailedIds().forEach(jsonFailedIds::put);
importStatus.getSuccessfulIds().forEach(jsonSuccessfulIds::put);
responseData.put(ProjectImportConstants.RESPONSE__FAILED_IDS, jsonFailedIds);
responseData.put(ProjectImportConstants.RESPONSE__SUCCESSFUL_IDS, jsonSuccessfulIds);
}
if (isImportSuccessful(importStatus)) {
responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__SUCCESS);
} else if (importStatus.isSetRequestStatus() && importStatus.getRequestStatus().equals(RequestStatus.SUCCESS)) {
responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__FAILURE);
} else {
responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__GENERAL_FAILURE);
}
}
use of com.liferay.portal.kernel.json.JSONArray 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);
}
}
Aggregations