Search in sources :

Example 41 with JSONObject

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

the class ComponentPortlet method updateVulnerabilityVerification.

private void updateVulnerabilityVerification(ResourceRequest request, ResourceResponse response) throws IOException {
    String[] releaseIds = request.getParameterValues(PortalConstants.RELEASE_IDS + "[]");
    String[] vulnerabilityIds = request.getParameterValues(PortalConstants.VULNERABILITY_IDS + "[]");
    User user = UserCacheHolder.getUserFromRequest(request);
    VulnerabilityService.Iface vulClient = thriftClients.makeVulnerabilityClient();
    RequestStatus requestStatus = RequestStatus.SUCCESS;
    try {
        if (vulnerabilityIds.length != releaseIds.length) {
            throw new SW360Exception("Length of vulnerabilities (" + vulnerabilityIds.length + ") does not match the length of releases (" + releaseIds.length + ")!");
        }
        for (int i = 0; i < vulnerabilityIds.length; i++) {
            String vulnerabilityId = vulnerabilityIds[i];
            String releaseId = releaseIds[i];
            Vulnerability dbVulnerability = vulClient.getVulnerabilityByExternalId(vulnerabilityId, user);
            ReleaseVulnerabilityRelation dbRelation = vulClient.getRelationByIds(releaseId, dbVulnerability.getId(), user);
            ReleaseVulnerabilityRelation resultRelation = ComponentPortletUtils.updateReleaseVulnerabilityRelationFromRequest(dbRelation, request);
            requestStatus = vulClient.updateReleaseVulnerabilityRelation(resultRelation, user);
            if (requestStatus != RequestStatus.SUCCESS) {
                break;
            }
        }
    } catch (TException e) {
        log.error("Error updating vulnerability verification in backend.", e);
        requestStatus = RequestStatus.FAILURE;
    }
    JSONObject responseData = JSONFactoryUtil.createJSONObject();
    responseData.put(PortalConstants.REQUEST_STATUS, requestStatus.toString());
    PrintWriter writer = response.getWriter();
    writer.write(responseData.toString());
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) VulnerabilityService(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) JSONObject(com.liferay.portal.kernel.json.JSONObject) ReleaseVulnerabilityRelation(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation) PrintWriter(java.io.PrintWriter)

Example 42 with JSONObject

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

the class ComponentPortlet method updateVulnerabilitiesRelease.

private void updateVulnerabilitiesRelease(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    String releaseId = request.getParameter(PortalConstants.RELEASE_ID);
    CveSearchService.Iface cveClient = thriftClients.makeCvesearchClient();
    try {
        VulnerabilityUpdateStatus importStatus = cveClient.updateForRelease(releaseId);
        JSONObject responseData = PortletUtils.importStatusToJSON(importStatus);
        PrintWriter writer = response.getWriter();
        writer.write(responseData.toString());
    } catch (TException e) {
        log.error("Error updating CVEs for release 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 43 with JSONObject

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

the class ComponentPortlet 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 44 with JSONObject

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

the class ComponentPortlet method updateVulnerabilitiesComponent.

private void updateVulnerabilitiesComponent(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    String componentId = request.getParameter(PortalConstants.COMPONENT_ID);
    CveSearchService.Iface cveClient = thriftClients.makeCvesearchClient();
    try {
        VulnerabilityUpdateStatus importStatus = cveClient.updateForComponent(componentId);
        JSONObject responseData = PortletUtils.importStatusToJSON(importStatus);
        PrintWriter writer = response.getWriter();
        writer.write(responseData.toString());
    } catch (TException e) {
        log.error("Error updating CVEs for component 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 45 with JSONObject

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

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