Search in sources :

Example 16 with JSONObject

use of com.liferay.portal.kernel.json.JSONObject in project sw360portal by sw360.

the class ProjectPortlet method updateVulnerabilityRating.

private void updateVulnerabilityRating(ResourceRequest request, ResourceResponse response) throws IOException {
    String projectId = request.getParameter(PortalConstants.PROJECT_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    VulnerabilityService.Iface vulClient = thriftClients.makeVulnerabilityClient();
    RequestStatus requestStatus = RequestStatus.FAILURE;
    try {
        Optional<ProjectVulnerabilityRating> projectVulnerabilityRatings = wrapThriftOptionalReplacement(vulClient.getProjectVulnerabilityRatingByProjectId(projectId, user));
        ProjectVulnerabilityRating link = ProjectPortletUtils.updateProjectVulnerabilityRatingFromRequest(projectVulnerabilityRatings, request);
        requestStatus = vulClient.updateProjectVulnerabilityRating(link, user);
    } catch (TException e) {
        log.error("Error updating vulnerability ratings for project in backend.", e);
    }
    JSONObject responseData = JSONFactoryUtil.createJSONObject();
    responseData.put(PortalConstants.REQUEST_STATUS, requestStatus.toString());
    PrintWriter writer = response.getWriter();
    writer.write(responseData.toString());
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject) PrintWriter(java.io.PrintWriter)

Example 17 with JSONObject

use of com.liferay.portal.kernel.json.JSONObject in project sw360portal by sw360.

the class Sw360Portlet method renderRemoveModerationRequestStatus.

protected void renderRemoveModerationRequestStatus(PortletRequest request, MimeResponse response, RemoveModeratorRequestStatus status) {
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
    jsonObject.put("result", status.toString());
    try {
        writeJSON(request, response, jsonObject);
    } catch (IOException e) {
        log.error("Problem rendering RemoveModerationRequestStatus", e);
    }
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) IOException(java.io.IOException)

Example 18 with JSONObject

use of com.liferay.portal.kernel.json.JSONObject in project sw360portal by sw360.

the class BulkReleaseEdit method serveAddVendor.

private void serveAddVendor(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
    final Vendor vendor = new Vendor();
    ComponentPortletUtils.updateVendorFromRequest(request, vendor);
    try {
        VendorService.Iface client = thriftClients.makeVendorClient();
        String vendorId = client.addVendor(vendor);
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        jsonObject.put("id", vendorId);
        try {
            writeJSON(request, response, jsonObject);
        } catch (IOException e) {
            log.error("Problem rendering VendorId", e);
        }
    } catch (TException e) {
        log.error("Error adding vendor", e);
    }
}
Also used : VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) TException(org.apache.thrift.TException) JSONObject(com.liferay.portal.kernel.json.JSONObject) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) IOException(java.io.IOException)

Example 19 with JSONObject

use of com.liferay.portal.kernel.json.JSONObject in project sw360portal by sw360.

the class ComponentPortlet method updateAllVulnerabilities.

private void updateAllVulnerabilities(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    CveSearchService.Iface cveClient = thriftClients.makeCvesearchClient();
    try {
        VulnerabilityUpdateStatus importStatus = cveClient.fullUpdate();
        JSONObject responseData = PortletUtils.importStatusToJSON(importStatus);
        PrintWriter writer = response.getWriter();
        writer.write(responseData.toString());
    } catch (TException e) {
        log.error("Error occurred with full update of CVEs in backend.", e);
    }
}
Also used : CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) TException(org.apache.thrift.TException) JSONObject(com.liferay.portal.kernel.json.JSONObject) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) PrintWriter(java.io.PrintWriter)

Example 20 with JSONObject

use of com.liferay.portal.kernel.json.JSONObject 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)

Aggregations

JSONObject (com.liferay.portal.kernel.json.JSONObject)54 JSONArray (com.liferay.portal.kernel.json.JSONArray)13 IOException (java.io.IOException)10 TException (org.apache.thrift.TException)9 PrintWriter (java.io.PrintWriter)7 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)5 ServiceContext (com.liferay.portal.service.ServiceContext)5 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)5 PortalException (com.liferay.portal.kernel.exception.PortalException)4 JSONException (com.liferay.portal.kernel.json.JSONException)4 Folder (com.liferay.portal.kernel.repository.model.Folder)4 Date (java.util.Date)4 CveSearchService (org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService)4 VulnerabilityUpdateStatus (org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus)4 User (org.eclipse.sw360.datahandler.thrift.users.User)4 JSONFactoryUtil.createJSONObject (com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject)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 User (com.liferay.portal.model.User)3