List of usage examples for org.json.simple JSONArray addAll
public boolean addAll(Collection<? extends E> c)
From source file:org.fao.fenix.wds.core.utils.Wrapper.java
@SuppressWarnings("unchecked") public static StringBuilder wrapAsJSON(List<List<String>> table) throws WDSException { try {/*from w ww . j a v a2 s . co m*/ JSONArray json = new JSONArray(); for (List<String> l : table) { JSONArray row = new JSONArray(); row.addAll(l); json.add(row); } return new StringBuilder(json.toJSONString()); } catch (Exception e) { throw new WDSException(e.getMessage()); } }
From source file:org.jolokia.client.request.J4pReadRequest.java
/** {@inheritDoc} */ @Override//from w ww. j a va2 s. c om JSONObject toJson() { JSONObject ret = super.toJson(); if (hasSingleAttribute()) { ret.put("attribute", attributes.get(0)); } else if (!hasAllAttributes()) { JSONArray attrs = new JSONArray(); attrs.addAll(attributes); ret.put("attribute", attrs); } if (path != null) { ret.put("path", path); } return ret; }
From source file:org.kuali.kpme.tklm.leave.calendar.web.LeaveCalendarWSAction.java
/** * This is an ajax call triggered after a user submits the leave entry form. * If there is any error, it will return error messages as a json object. * * @param mapping//from w w w . j a v a 2 s . co m * @param form * @param request * @param response * @return jsonObj * @throws Exception */ @SuppressWarnings("unchecked") public ActionForward validateLeaveEntry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LeaveCalendarWSForm lcf = (LeaveCalendarWSForm) form; JSONArray errorMsgList = new JSONArray(); errorMsgList.addAll(LeaveCalendarValidationUtil.validateLeaveEntry(lcf)); lcf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.leave.request.approval.web.LeaveRequestApprovalAction.java
public ActionForward validateNewActions(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LeaveRequestApprovalActionForm lraaForm = (LeaveRequestApprovalActionForm) form; JSONArray errorMsgList = new JSONArray(); List<String> errors = new ArrayList<String>(); if (StringUtils.isEmpty(lraaForm.getActionList())) { errors.add("No Actions selected. Please try again."); } else {//from ww w . java 2 s . c om if (StringUtils.isNotEmpty(lraaForm.getActionList())) { String[] actionList = lraaForm.getActionList().split(DOC_SEPARATOR); for (String docId : actionList) { if (StringUtils.isNotEmpty(docId) && !StringUtils.equals(docId, DOC_SEPARATOR)) { LeaveRequestDocument lrd = LmServiceLocator.getLeaveRequestDocumentService() .getLeaveRequestDocument(docId); if (lrd == null) { errors.add(DOC_NOT_FOUND + docId); break; } else { LeaveBlock lb = LmServiceLocator.getLeaveBlockService() .getLeaveBlock(lrd.getLmLeaveBlockId()); if (lb == null) { errors.add(LEAVE_BLOCK_NOT_FOUND + docId); break; } } } } } } errorMsgList.addAll(errors); lraaForm.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); }
From source file:org.kuali.kpme.tklm.time.detail.web.TimeDetailWSAction.java
/** * This is an ajax call triggered after a user submits the time entry form. * If there is any error, it will return error messages as a json object. * * @param mapping// w w w . j a v a 2 s.c o m * @param form * @param request * @param response * @return jsonObj * @throws Exception */ @SuppressWarnings("unchecked") public ActionForward validateTimeEntry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { TimeDetailActionFormBase tdaf = (TimeDetailActionFormBase) form; JSONArray errorMsgList = new JSONArray(); List<String> errors; // validates the selected earn code exists on every day within the date range errors = TimeDetailValidationUtil.validateEarnCode(tdaf.getSelectedEarnCode(), tdaf.getStartDate(), tdaf.getEndDate()); if (errors.isEmpty()) { EarnCode ec = HrServiceLocator.getEarnCodeService().getEarnCode(tdaf.getSelectedEarnCode(), TKUtils.formatDateTimeStringNoTimezone(tdaf.getEndDate()).toLocalDate()); if (ec != null && StringUtils.isNotEmpty(ec.getLeavePlan())) { // leave blocks changes errors = TimeDetailValidationUtil.validateLeaveEntry(tdaf); } else { // time blocks changes errors = TimeDetailValidationUtil.validateTimeEntryDetails(tdaf); } } errorMsgList.addAll(errors); tdaf.setOutputString(JSONValue.toJSONString(errorMsgList)); return mapping.findForward("ws"); }
From source file:org.mozilla.gecko.sync.repositories.domain.BookmarkRecord.java
@SuppressWarnings("unchecked") protected JSONArray copyChildren() { if (this.children == null) { return null; }//from w ww . j a v a 2 s .c o m JSONArray children = new JSONArray(); children.addAll(this.children); return children; }
From source file:org.mozilla.gecko.sync.repositories.domain.BookmarkRecord.java
@SuppressWarnings("unchecked") protected JSONArray copyTags() { if (this.tags == null) { return null; }// w w w. ja va2 s . com JSONArray tags = new JSONArray(); tags.addAll(this.tags); return tags; }
From source file:org.mozilla.gecko.sync.repositories.domain.HistoryRecord.java
@SuppressWarnings("unchecked") private JSONArray copyVisits() { if (this.visits == null) { return null; }/* www.ja v a 2 s . c o m*/ JSONArray out = new JSONArray(); out.addAll(this.visits); return out; }
From source file:org.opencastproject.adminui.endpoint.ServerEndpoint.java
@GET @Path("servers.json") @Produces(MediaType.APPLICATION_JSON)/*from ww w. j a v a2 s .co m*/ @RestQuery(description = "Returns the list of servers", name = "servers", restParameters = { @RestParameter(name = "limit", description = "The maximum number of items to return per page", isRequired = false, type = INTEGER), @RestParameter(name = "offset", description = "The offset", isRequired = false, type = INTEGER), @RestParameter(name = "online", isRequired = false, description = "Filter results by server current online status", type = BOOLEAN), @RestParameter(name = "offline", isRequired = false, description = "Filter results by server current offline status", type = BOOLEAN), @RestParameter(name = "maintenance", isRequired = false, description = "Filter results by server current maintenance status", type = BOOLEAN), @RestParameter(name = "q", isRequired = false, description = "Filter results by free text query", type = STRING), @RestParameter(name = "types", isRequired = false, description = "Filter results by sevices types registred on the server", type = STRING), @RestParameter(name = "ipaddress", isRequired = false, description = "Filter results by the server ip address", type = STRING), @RestParameter(name = "cores", isRequired = false, description = "Filter results by the number of cores", type = INTEGER, defaultValue = "-1"), @RestParameter(name = "memory", isRequired = false, description = "Filter results by the server memory available in bytes", type = INTEGER), @RestParameter(name = "path", isRequired = false, description = "Filter results by the server path", type = STRING), @RestParameter(name = "maxjobs", isRequired = false, description = "Filter results by the maximum of jobs that can be run at the same time", type = INTEGER, defaultValue = "-1"), @RestParameter(name = "sort", isRequired = false, description = "The sort order. May include any " + "of the following: STATUS, NAME, CORES, COMPLETED (jobs), RUNNING (jobs), QUEUED (jobs), QUEUETIME (mean for jobs), MAINTENANCE, RUNTIME (mean for jobs)." + "Add '_DESC' to reverse the sort order (e.g. NAME_DESC).", type = STRING) }, reponses = { @RestResponse(description = "Returns the list of jobs from Matterhorn", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "The list ") public Response getServers(@QueryParam("limit") final int limit, @QueryParam("offset") final int offset, @QueryParam("online") boolean fOnline, @QueryParam("offline") boolean fOffline, @QueryParam("q") String fText, @QueryParam("maintenance") boolean fMaintenance, @QueryParam("types") List<String> fTypes, @QueryParam("ipaddress") String ipAddress, @QueryParam("cores") Integer fCores, @QueryParam("memory") Integer fMemory, @QueryParam("path") String fPath, @QueryParam("maxjobs") int fMaxJobs, @QueryParam("sort") String sort, @Context HttpHeaders headers) throws Exception { JSONArray jsonList = new JSONArray(); List<HostRegistration> allServers = serviceRegistry.getHostRegistrations(); List<JSONObject> sortedServers = new ArrayList<JSONObject>(); int i = 0; for (HostRegistration server : allServers) { if (i++ < offset) { continue; } else if (limit != 0 && sortedServers.size() == limit) { break; } else { // Get all the services statistics pro host // TODO improve the service registry to get service statistics by host List<ServiceStatistics> servicesStatistics = serviceRegistry.getServiceStatistics(); int jobsCompleted = 0; int jobsRunning = 0; int jobsQueued = 0; int sumMeanRuntime = 0; int sumMeanQueueTime = 0; int totalServiceOnHost = 0; Set<String> serviceTypes = new HashSet<String>(); for (ServiceStatistics serviceStat : servicesStatistics) { if (server.getBaseUrl().equals(serviceStat.getServiceRegistration().getHost())) { totalServiceOnHost++; jobsCompleted += serviceStat.getFinishedJobs(); jobsRunning += serviceStat.getRunningJobs(); jobsQueued += serviceStat.getQueuedJobs(); sumMeanRuntime += serviceStat.getMeanRunTime(); sumMeanQueueTime += serviceStat.getQueuedJobs(); serviceTypes.add(serviceStat.getServiceRegistration().getServiceType()); } } int meanRuntime = sumMeanRuntime / totalServiceOnHost; int meanQueueTime = sumMeanQueueTime / totalServiceOnHost; boolean vOnline = server.isOnline(); boolean vMaintenance = server.isMaintenanceMode(); String vName = server.getBaseUrl(); int vCores = server.getCores(); int vRunning = jobsRunning; int vQueued = jobsQueued; int vCompleted = jobsCompleted; if (fOffline && vOnline) continue; if (fOnline && !vOnline) continue; if (fMaintenance && !vMaintenance) continue; if (fMaxJobs > 0 && fMaxJobs < (vRunning + vQueued + vCompleted)) continue; if (fCores != null && fCores > 0 && fCores != vCores) continue; if (fMemory != null && fMemory > 0 && ((Integer) fMemory).longValue() != server.getMemory()) continue; if (StringUtils.isNotBlank(fPath) && !vName.toLowerCase().contains(fPath.toLowerCase())) continue; if (StringUtils.isNotBlank(fText) && !vName.toLowerCase().contains(fText.toLowerCase())) { String allString = vName.toLowerCase().concat(server.getIpAddress().toLowerCase()); if (!allString.contains(fText.toLowerCase())) continue; } JSONObject jsonServer = new JSONObject(); jsonServer.put(KEY_ONLINE, server.isOnline()); jsonServer.put(KEY_MAINTENANCE, server.isMaintenanceMode()); jsonServer.put(KEY_NAME, server.getBaseUrl()); jsonServer.put(KEY_CORES, server.getCores()); jsonServer.put(KEY_RUNNING, jobsRunning); jsonServer.put(KEY_QUEUED, jobsQueued); jsonServer.put(KEY_COMPLETED, jobsCompleted); jsonServer.put(KEY_MEAN_RUN_TIME, meanRuntime); jsonServer.put(KEY_MEAN_QUEUE_TIME, meanQueueTime); sortedServers.add(jsonServer); } } // Sorting SORT sortKey = SORT.HOSTNAME; Boolean ascending = true; if (StringUtils.isNotBlank(sort)) { // Parse the sort field and direction Sort sortField = null; if (sort.endsWith(DESCENDING_SUFFIX)) { ascending = false; String enumKey = sort.substring(0, sort.length() - DESCENDING_SUFFIX.length()).toUpperCase(); try { sortKey = SORT.valueOf(enumKey); } catch (IllegalArgumentException e) { logger.warn("No sort enum matches '{}'", enumKey); } } else { try { sortKey = SORT.valueOf(sort); } catch (IllegalArgumentException e) { logger.warn("No sort enum matches '{}'", sort); } } } Collections.sort(sortedServers, new ServerComparator(sortKey, ascending)); jsonList.addAll(sortedServers); JSONObject response = new JSONObject(); response.put("results", jsonList); response.put("count", jsonList.size()); response.put("offset", offset); response.put("limit", limit); response.put("total", allServers.size()); return Response.ok(response.toString()).build(); }
From source file:org.openlegacy.ide.eclipse.actions.DeployToServerAction.java
@SuppressWarnings("unchecked") private static JSONArray loadServersList(IProject project) { JSONArray serversList = new JSONArray(); // get servers list String jsonServersList = EclipseDesignTimeExecuter.instance().getPreference(project, "SERVERS_LIST"); if (!StringUtils.isEmpty(jsonServersList)) { Object obj = JSONValue.parse(jsonServersList); serversList.clear();//from w w w. j av a 2 s. c om serversList.addAll((JSONArray) obj); } else { serversList.clear(); } return serversList; }