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());
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations