Search in sources :

Example 6 with JSONArray

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);
}
Also used : DataTablesParameters(org.eclipse.sw360.portal.common.datatables.data.DataTablesParameters) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) CommonUtils.nullToEmptyMap(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyMap) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 7 with JSONArray

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;
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 8 with JSONArray

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;
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 9 with JSONArray

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);
    }
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) ImportStatus(org.eclipse.sw360.datahandler.thrift.importstatus.ImportStatus) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Example 10 with JSONArray

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);
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) JSONFactoryUtil.createJSONArray(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray) JSONArray(com.liferay.portal.kernel.json.JSONArray) JSONException(com.liferay.portal.kernel.json.JSONException) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject)

Aggregations

JSONArray (com.liferay.portal.kernel.json.JSONArray)13 JSONObject (com.liferay.portal.kernel.json.JSONObject)13 JSONException (com.liferay.portal.kernel.json.JSONException)4 IOException (java.io.IOException)4 PortalException (com.liferay.portal.kernel.exception.PortalException)3 Role (com.liferay.portal.kernel.model.Role)3 User (com.liferay.portal.kernel.model.User)3 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)3 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 FileReader (java.io.FileReader)3 Gadget (com.liferay.opensocial.model.Gadget)1 JSONFactoryUtil.createJSONArray (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray)1 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)1 Organization (com.liferay.portal.kernel.model.Organization)1 UserGroup (com.liferay.portal.kernel.model.UserGroup)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 Folder (com.liferay.portal.kernel.repository.model.Folder)1 SearchContext (com.liferay.portal.kernel.search.SearchContext)1 FacetConfiguration (com.liferay.portal.kernel.search.facet.config.FacetConfiguration)1