Search in sources :

Example 46 with JSONObject

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

the class ProjectImportPortlet method serveResource.

@Override
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
    LoginState loginState = new LoginState();
    String requestedAction = request.getParameter(ProjectImportConstants.USER_ACTION__IMPORT);
    JSONObject responseData = handleRequestedAjaxAction(requestedAction, request, response, loginState);
    PrintWriter writer = response.getWriter();
    writer.write(responseData.toString());
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) PrintWriter(java.io.PrintWriter)

Example 47 with JSONObject

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

the class ProjectImportPortlet method handleRequestedAjaxAction.

public JSONObject handleRequestedAjaxAction(String requestedAction, ResourceRequest request, ResourceResponse response, LoginState loginState) throws IOException, PortletException {
    PortletSession session = request.getPortletSession();
    RemoteCredentials remoteCredentials = getRemoteCredentialsFromSession(session);
    JSONObject responseData = JSONFactoryUtil.createJSONObject();
    switch(requestedAction) {
        case ProjectImportConstants.USER_ACTION__IMPORT_DATA:
            User user = UserCacheHolder.getUserFromRequest(request);
            List<String> selectedIds = getProjectIdsForImport(request);
            importBdpProjects(user, selectedIds, responseData, remoteCredentials);
            break;
        case ProjectImportConstants.USER_ACTION__NEW_IMPORT_SOURCE:
            RemoteCredentials newCredentials = new RemoteCredentials().setUsername(request.getParameter(ProjectImportConstants.USERNAME)).setPassword(request.getParameter(ProjectImportConstants.PASSWORD)).setServerUrl(request.getParameter(ProjectImportConstants.SERVER_URL));
            if (!validateCredentials(newCredentials)) {
                responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__UNAUTHORIZED);
            } else {
                setNewImportSource(newCredentials, session, responseData, loginState);
            }
            break;
        case ProjectImportConstants.USER_ACTION__UPDATE_IMPORTABLES:
            String projectName = request.getParameter(ProjectImportConstants.PROJECT_NAME);
            updateImportables(responseData, loginState, remoteCredentials, projectName);
            break;
        case ProjectImportConstants.USER_ACTION__DISCONNECT:
            putRemoteCredentialsIntoSession(session, new RemoteCredentials());
            loginState.logout();
            break;
        default:
            loginState.logout();
            break;
    }
    return responseData;
}
Also used : RemoteCredentials(org.eclipse.sw360.datahandler.thrift.projectimport.RemoteCredentials) User(org.eclipse.sw360.datahandler.thrift.users.User) JSONObject(com.liferay.portal.kernel.json.JSONObject)

Example 48 with JSONObject

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

the class ProjectPortlet method updateVulnerabilitiesProject.

private void updateVulnerabilitiesProject(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
    String projectId = request.getParameter(PortalConstants.PROJECT_ID);
    CveSearchService.Iface cveClient = thriftClients.makeCvesearchClient();
    try {
        VulnerabilityUpdateStatus importStatus = cveClient.updateForProject(projectId);
        JSONObject responseData = PortletUtils.importStatusToJSON(importStatus);
        PrintWriter writer = response.getWriter();
        writer.write(responseData.toString());
    } catch (TException e) {
        log.error("Error updating CVEs for project in backend.", e);
    }
}
Also used : CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) JSONObject(com.liferay.portal.kernel.json.JSONObject) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) PrintWriter(java.io.PrintWriter)

Example 49 with JSONObject

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

Example 50 with JSONObject

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

the class Sw360Portlet method renderRequestSummary.

protected void renderRequestSummary(PortletRequest request, MimeResponse response, RequestSummary requestSummary) {
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
    jsonObject.put("result", requestSummary.requestStatus.toString());
    if (requestSummary.isSetTotalAffectedElements())
        jsonObject.put("totalAffectedObjects", requestSummary.totalAffectedElements);
    if (requestSummary.isSetTotalElements())
        jsonObject.put("totalObjects", requestSummary.totalElements);
    if (requestSummary.isSetMessage())
        jsonObject.put("message", requestSummary.message);
    try {
        writeJSON(request, response, jsonObject);
    } catch (IOException e) {
        log.error("Problem rendering RequestStatus", e);
    }
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) IOException(java.io.IOException)

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