List of usage examples for org.json.simple JSONArray toString
@Override
public String toString()
From source file:org.jitsi.videobridge.VideoChannel.java
private String getJsonString(List<String> strings) { JSONArray array = new JSONArray(); if (strings != null && !strings.isEmpty()) { for (String s : strings) { array.add(s);//from www . j a v a2s . c om } } return array.toString(); }
From source file:org.jolokia.converter.object.StringToObjectConverterTest.java
@Test public void jsonConversion() { JSONObject json = new JSONObject(); json.put("name", "roland"); json.put("kind", "jolokia"); Object object = converter.convertFromString(JSONObject.class.getName(), json.toString()); assertEquals(json, object);// w w w . j a v a 2s . c o m JSONArray array = new JSONArray(); array.add("roland"); array.add("jolokia"); object = converter.convertFromString(JSONArray.class.getName(), array.toString()); assertEquals(array, object); try { converter.convertFromString(JSONObject.class.getName(), "{bla:blub{"); fail(); } catch (IllegalArgumentException exp) { } }
From source file:org.opencastproject.adminui.endpoint.SeriesEndpoint.java
@SuppressWarnings("unchecked") @GET//w ww . j av a 2 s . co m @Produces(MediaType.APPLICATION_JSON) @Path("{id}/properties") @RestQuery(name = "getSeriesProperties", description = "Returns the series properties", returnDescription = "Returns the series properties as JSON", pathParameters = { @RestParameter(name = "id", description = "ID of series", isRequired = true, type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The access control list."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") }) public Response getSeriesPropertiesAsJson(@PathParam("id") String seriesId) throws UnauthorizedException, NotFoundException { if (StringUtils.isBlank(seriesId)) { logger.warn("Series id parameter is blank '{}'.", seriesId); return Response.status(BAD_REQUEST).build(); } try { Map<String, String> properties = seriesService.getSeriesProperties(seriesId); JSONArray jsonProperties = new JSONArray(); for (String name : properties.keySet()) { JSONObject property = new JSONObject(); property.put(name, properties.get(name)); jsonProperties.add(property); } return Response.ok(jsonProperties.toString()).build(); } catch (UnauthorizedException e) { throw e; } catch (NotFoundException e) { throw e; } catch (Exception e) { logger.warn("Could not perform search query: {}", e.getMessage()); } throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); }
From source file:org.opencastproject.scheduler.endpoint.SchedulerRestService.java
@PUT @Produces(MediaType.TEXT_PLAIN)/* w ww . ja v a 2 s . c o m*/ @Path("bulkaction") @RestQuery(name = "bulkaction", description = "Updates the dublin core catalog of a set of recordings.", returnDescription = "No body returned.", restParameters = { @RestParameter(name = "idlist", description = "JSON Array of ids.", isRequired = true, type = Type.STRING), @RestParameter(name = "dublinecore", description = "The dublin core catalog of updated fields", isRequired = true, type = Type.STRING) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_NO_CONTENT, description = "Events were updated successfully.") }) public Response bulkUpdate(@FormParam("idlist") String idList, @FormParam("dublincore") String dublinCore) { JSONParser parser = new JSONParser(); JSONArray ids = new JSONArray(); DublinCoreCatalog eventCatalog; try { if (idList != null && !idList.isEmpty()) { ids = (JSONArray) parser.parse(idList); } } catch (ParseException e) { logger.warn("Unable to parse json id list: {}", e); return Response.status(Status.BAD_REQUEST).build(); } if (StringUtils.isNotEmpty(dublinCore)) { try { eventCatalog = parseDublinCore(dublinCore); } catch (Exception e) { logger.warn("Could not parse Dublin core catalog: {}", e); return Response.status(Status.BAD_REQUEST).build(); } } else { logger.warn("Cannot add event without dublin core catalog."); return Response.status(Status.BAD_REQUEST).build(); } if (!ids.isEmpty() && eventCatalog != null) { try { service.updateEvents(mlist(ids).map(Misc.<Object, Long>cast()).value(), eventCatalog); return Response.noContent().type("").build(); // remove content-type, no message-body. } catch (Exception e) { logger.warn("Unable to update event with id " + ids.toString() + ": {}", e); return Response.serverError().build(); } } else { return Response.status(Status.BAD_REQUEST).build(); } }
From source file:org.pentaho.di.ui.repo.controller.RepositoryConnectController.java
@SuppressWarnings("unchecked") public String getPlugins() { List<PluginInterface> plugins = pluginRegistry.getPlugins(RepositoryPluginType.class); JSONArray list = new JSONArray(); for (PluginInterface pluginInterface : plugins) { if (!pluginInterface.getIds()[0].equals("PentahoEnterpriseRepository")) { JSONObject repoJSON = new JSONObject(); repoJSON.put("id", pluginInterface.getIds()[0]); repoJSON.put("name", pluginInterface.getName()); repoJSON.put("description", pluginInterface.getDescription()); list.add(repoJSON);/*from w w w.jav a 2 s .co m*/ } } return list.toString(); }
From source file:org.pentaho.di.ui.repo.controller.RepositoryConnectController.java
@SuppressWarnings("unchecked") public String getDatabases() { JSONArray list = new JSONArray(); for (int i = 0; i < repositoriesMeta.nrDatabases(); i++) { JSONObject databaseJSON = new JSONObject(); databaseJSON.put("name", repositoriesMeta.getDatabase(i).getName()); list.add(databaseJSON);/*from ww w . j av a 2 s . c o m*/ } return list.toString(); }
From source file:org.pentaho.di.ui.repo.RepositoryConnectController.java
@SuppressWarnings("unchecked") public String getRepositories() { JSONArray list = new JSONArray(); if (repositoriesMeta != null) { for (int i = 0; i < repositoriesMeta.nrRepositories(); i++) { list.add(repositoriesMeta.getRepository(i).toJSONObject()); }/*from w w w . j a v a2 s . c o m*/ } return list.toString(); }
From source file:org.sakaiproject.basiclti.util.SakaiBLTIUtil.java
/** * An LTI 2.0 Reregistration launch/*from w ww .j a v a 2 s . c om*/ * * This must return an HTML message as the [0] in the array * If things are successful - the launch URL is in [1] */ public static String[] postReregisterHTML(Long deployKey, Map<String, Object> deploy, ResourceLoader rb, String placementId) { if (deploy == null) { return postError( "<p>" + getRB(rb, "error.deploy.missing", "Deployment is missing or improperly configured.") + "</p>"); } int status = getInt(deploy.get("reg_state")); if (status == 0) return postError("<p>" + getRB(rb, "error.deploy.badstate", "Deployment is in the wrong state to register") + "</p>"); // Figure out the launch URL to use unless we have been told otherwise String launch_url = (String) deploy.get("reg_launch"); // Find the global message for Reregistration String reg_profile = (String) deploy.get("reg_profile"); ToolProxy toolProxy = null; try { toolProxy = new ToolProxy(reg_profile); } catch (Throwable t) { return postError("<p>" + getRB(rb, "error.deploy.badproxy", "This deployment has a broken reg_profile.") + "</p>"); } JSONObject proxy_message = toolProxy.getMessageOfType("ToolProxyReregistrationRequest"); String re_path = toolProxy.getPathFromMessage(proxy_message); if (re_path != null) launch_url = re_path; if (launch_url == null) return postError("<p>" + getRB(rb, "error.deploy.noreg", "This deployment is has no registration url.") + "</p>"); String consumerkey = (String) deploy.get(LTIService.LTI_CONSUMERKEY); String secret = (String) deploy.get(LTIService.LTI_SECRET); // If secret is encrypted, decrypt it secret = decryptSecret(secret); if (secret == null || consumerkey == null) { return postError( "<p>" + getRB(rb, "error.deploy.partial", "Deployment is incomplete, missing a key and secret.") + "</p>"); } // Start building up the properties Properties ltiProps = new Properties(); setProperty(ltiProps, BasicLTIConstants.LTI_VERSION, LTI2Constants.LTI2_VERSION_STRING); setProperty(ltiProps, BasicLTIUtil.BASICLTI_SUBMIT, getRB(rb, "launch.button", "Press to Launch External Tool")); setProperty(ltiProps, BasicLTIConstants.LTI_MESSAGE_TYPE, BasicLTIConstants.LTI_MESSAGE_TYPE_TOOLPROXY_RE_REGISTRATIONREQUEST); String serverUrl = getOurServerUrl(); setProperty(ltiProps, LTI2Constants.TC_PROFILE_URL, serverUrl + LTI2_PATH + SVC_tc_profile + "/" + consumerkey); setProperty(ltiProps, BasicLTIConstants.LAUNCH_PRESENTATION_RETURN_URL, serverUrl + "/portal/tool/" + placementId + "?panel=PostRegister&id=" + deployKey); int debug = getInt(deploy.get(LTIService.LTI_DEBUG)); // Handle any subsisution variables from the message Properties lti2subst = new Properties(); addGlobalData(null, ltiProps, lti2subst, rb); if (deploy != null) { setProperty(lti2subst, LTI2Vars.TOOLCONSUMERPROFILE_URL, getOurServerUrl() + LTI2_PATH + SVC_tc_profile + "/" + (String) deploy.get(LTIService.LTI_CONSUMERKEY)); ; } Properties custom = new Properties(); JSONArray parameter = toolProxy.getParameterFromMessage(proxy_message); if (parameter != null) { LTI2Util.mergeLTI2Parameters(custom, parameter.toString()); M_log.debug("lti2subst=" + lti2subst); M_log.debug("before custom=" + custom); LTI2Util.substituteCustom(custom, lti2subst); M_log.debug("after custom=" + custom); // Merge the custom values into the launch LTI2Util.addCustomToLaunch(ltiProps, custom); } Map<String, String> extra = new HashMap<String, String>(); ltiProps = BasicLTIUtil.signProperties(ltiProps, launch_url, "POST", consumerkey, secret, null, null, null, extra); M_log.debug("signed ltiProps=" + ltiProps); boolean dodebug = debug == 1; String postData = BasicLTIUtil.postLaunchHTML(ltiProps, launch_url, dodebug, extra); String[] retval = { postData, launch_url }; return retval; }
From source file:org.wso2.carbon.apimgt.core.dao.impl.ApiDAOImpl.java
/** * This returns the json string containing the role permissions for a given API * * @param connection - DB connection/*ww w . ja va 2s . co m*/ * @param apiId - apiId of the API * @return permission string * @throws SQLException - if error occurred while getting permissionMap of API from DB */ private String getPermissionsStringForApi(Connection connection, String apiId) throws SQLException { JSONArray permissionArray = new JSONArray(); Map<String, Integer> permissionMap = getPermissionMapForApi(connection, apiId); for (Map.Entry<String, Integer> entry : permissionMap.entrySet()) { JSONObject jsonObject = new JSONObject(); jsonObject.put(APIMgtConstants.Permission.GROUP_ID, entry.getKey()); jsonObject.put(APIMgtConstants.Permission.PERMISSION, APIUtils.constructApiPermissionsListForValue(entry.getValue())); permissionArray.add(jsonObject); } if (!permissionArray.isEmpty()) { return permissionArray.toString(); } else { return ""; } }
From source file:prodandes.Prodandes.java
@POST @Path("/operarioMasActivo") public JSONObject operarioMasActivo(JSONObject jO) throws Exception { abrirConexion();//from ww w .j a v a 2 s. c o m try { int num_secuencia = Integer.parseInt(jO.get("secuencia").toString()); String query5 = "select * from OPERARIO natural join (" + "select DOCUMENTO_OPERARIO as DOCUMENTO_ID, CUENTA from (" + "select * from (select DOCUMENTO_OPERARIO, count(ID_ETAPA) as cuenta from ETAPAS_OPERARIOS where ID_ETAPA= " + num_secuencia + " group by DOCUMENTO_OPERARIO) " + "where cuenta=(" + "SELECT max(count(ID_ETAPA)) as cuenta from ETAPAS_OPERARIOS " + "where ID_ETAPA= " + num_secuencia + " group by DOCUMENTO_OPERARIO)))"; System.out.println("- - - - - - - - - - - - - - - - - Print Query - - - - - - - - - - - - - - - - -"); System.out.println(query5); Statement st5 = con.createStatement(); ResultSet rs5 = st5.executeQuery(query5); JSONObject operario = new JSONObject(); String documento_id = ""; String nombre = ""; String nacionalidad = ""; String direccion = ""; String email = ""; String telefono = ""; String ciudad = ""; String departamento = ""; String codigo_postal = ""; JSONArray lista = new JSONArray(); int i = 0; while (rs5.next()) { i++; System.out.println("Numero del ciclo: " + i); documento_id = rs5.getString("DOCUMENTO_ID"); nombre = rs5.getString("NOMBRE"); nacionalidad = rs5.getString("NACIONALIDAD"); direccion = rs5.getString("DIRECCION"); email = rs5.getString("EMAIL"); telefono = rs5.getString("TELEFONO"); ciudad = rs5.getString("CIUDAD"); departamento = rs5.getString("DEPARTAMENTO"); codigo_postal = rs5.getString("CODIGO_POSTAL"); operario.put("DOCUMENTO_ID", documento_id); operario.put("NOMBRE", nombre); operario.put("NACIONALIDAD", nacionalidad); operario.put("DIRECCION", direccion); operario.put("EMAIL", email); operario.put("TELEFONO", telefono); operario.put("CIUDAD", ciudad); operario.put("DEPARTAMENTO", departamento); operario.put("CODIGO_POSTAL", codigo_postal); System.out.println("Operario: " + operario); lista.add(operario); } System.out.println("Lista: " + lista); st5.close(); cerrarConexion(); JSONObject resp = new JSONObject(); resp.put("operarios", lista.toString()); System.out.println("Respuesta: " + resp.toString()); return resp; } catch (Exception e) { e.printStackTrace(); rollback(); throw new Exception(""); } }