List of usage examples for com.google.gson JsonObject add
public void add(String property, JsonElement value)
From source file:ch.epfl.leb.sass.simulator.internal.DefaultSimulator.java
License:Open Source License
/** * Returns information on the simulation's current state as a JSON object. * //from w ww . j a v a 2 s . c o m * Unlike {@link #toJsonMessages() toJsonMessages()}, which returns * information about previous changes in the simulation's state, this method * reports on the current state of the simulation. * * @return A JSON object containing information on the simulation state. */ @Override public JsonElement toJsonState() { JsonObject json = new JsonObject(); json.add(CAMERA_MEMBER_NAME, this.microscope.toJsonCamera()); json.add(FLUOR_MEMBER_NAME, this.microscope.toJsonFluorescence()); json.add(LASER_MEMBER_NAME, this.microscope.toJsonLaser()); json.add(OBJECTIVE_MEMBER_NAME, this.microscope.toJsonObjective()); json.add(STAGE_MEMBER_NAME, this.microscope.toJsonStage()); return json; }
From source file:ch.ethz.coss.nervous.pulse.sql.SqlRequestWorker.java
License:Open Source License
@Override public void run() { try {//from w ww . jav a2 s. co m JsonObject feature = null; JsonArray features = null; JsonObject featureCollection = null; try { /***** SQL get ********/ // Fetch data PreparedStatement datastmt = sqlse.getSensorValuesFetchStatement(connection, ptmRequest.readingType, ptmRequest.startTime, ptmRequest.endTime); ResultSet rs = datastmt.executeQuery(); featureCollection = new JsonObject(); features = new JsonArray(); // System.out.println("SQL query result size = // "+rs.getFetchSize()); long currentTimeMillis = System.currentTimeMillis(); while (rs.next()) { long volatility = rs.getLong("Volatility"); long recordTime = rs.getLong("RecordTime"); // System.out.println("Volatility = " + volatility); // System.out.println("currentTimeMillis = " + currentTimeMillis); // System.out.println("left time = " + (currentTimeMillis - (recordTime + (volatility * 1000)))); if (volatility != -1) if (volatility == 0 || currentTimeMillis > (recordTime + (volatility * 1000))) { // System.out.println("Continue"); continue; } String lat = rs.getString("lat"); String lon = rs.getString("lon"); feature = new JsonObject(); feature.addProperty("type", "Feature"); JsonObject point = new JsonObject(); point.addProperty("type", "Point"); JsonArray coord = new JsonArray(); coord.add(new JsonPrimitive(lat)); coord.add(new JsonPrimitive(lon)); point.add("coordinates", coord); feature.add("geometry", point); JsonObject properties = new JsonObject(); properties.addProperty("volatility", volatility); if (ptmRequest.readingType == 0) { String luxVal = rs.getString("Light"); // System.out.println("Reading instance of light"); properties.addProperty("readingType", "" + 0); properties.addProperty("level", luxVal); } else if (ptmRequest.readingType == 1) { String soundVal = rs.getString("Decibel"); properties.addProperty("readingType", "" + 1); properties.addProperty("level", soundVal); } else if (ptmRequest.readingType == 2) { String message = rs.getString("Message"); message = message.trim(); properties.addProperty("readingType", "" + 2); if (message.length() <= 0) { message = "***Empty Message***"; continue; } properties.addProperty("message", message); } else { // System.out.println("Reading instance not known"); } feature.add("properties", properties); features.add(feature); // if((features.getAsJsonArray()).size() >= 60000){ // featureCollection.add("features", features); // pSocketServer.sendToSocket(ptmRequest.webSocket, // ptmRequest.requestID, featureCollection.toString(), // false); // featureCollection = new JsonObject(); // featureCollection = new JsonObject(); // features = new JsonArray(); // try { // Thread.sleep(10); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // break; // } } featureCollection.add("features", features); // System.out.println("Feature collection + // "+featureCollection.toString()); pSocketServer.sendToSocket(ptmRequest.webSocket, ptmRequest.requestID, featureCollection.toString(), true); /*************/ } catch (JsonParseException e) { System.out.println("can't save json object: " + e.toString()); } } catch (Exception e) { e.printStackTrace(); Log.getInstance().append(Log.FLAG_WARNING, "Generic error"); } finally { cleanup(); } }
From source file:ch.ethz.coss.nervous.pulse.sql.SqlUploadWorker.java
License:Open Source License
@SuppressWarnings("deprecation") @Override// w w w.j a v a 2 s . c om public void run() { // InputStream is; DataInputStream in = null; try { in = new DataInputStream(socket.getInputStream()); boolean connected = true; while (connected) { connected &= !socket.isClosed(); Visual reading = null; JsonObject featureCollection = new JsonObject(); JsonArray features = new JsonArray(); JsonObject feature = null; try { // String json = in.readUTF(); // StringBuffer json = new StringBuffer(); // String tmp; String json = null; try { // while ((tmp = in.read()) != null) { // json.append(tmp); // } ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte buffer[] = new byte[1024]; for (int s; (s = in.read(buffer)) != -1;) { baos.write(buffer, 0, s); } byte result[] = baos.toByteArray(); json = new String(result); // use inputLine.toString(); here it would have whole // source in.close(); } catch (MalformedURLException me) { System.out.println("MalformedURLException: " + me); } catch (IOException ioe) { System.out.println("IOException: " + ioe); } System.out.println("JSON STRING = " + json); System.out.println("JSON Length = " + json.length()); if (json.length() <= 0) continue; reading = new JSONDeserializer<Visual>().deserialize(json, Visual.class); feature = new JsonObject(); feature.addProperty("type", "Feature"); // JsonArray featureList = new JsonArray(); // iterate through your list // for (ListElement obj : list) { // {"geometry": {"type": "Point", "coordinates": // [-94.149, 36.33]} JsonObject point = new JsonObject(); point.addProperty("type", "Point"); // construct a JSONArray from a string; can also use an // array or list JsonArray coord = new JsonArray(); if (reading == null || reading.location == null) continue; else if (reading.location.latnLong[0] == 0 && reading.location.latnLong[1] == 0) continue; coord.add(new JsonPrimitive(new String("" + reading.location.latnLong[0]))); coord.add(new JsonPrimitive(new String("" + reading.location.latnLong[1]))); point.add("coordinates", coord); feature.add("geometry", point); JsonObject properties = new JsonObject(); if (reading.type == 0) { // System.out.println("Reading instance of light"); properties.addProperty("readingType", "" + 0); properties.addProperty("level", "" + ((LightReading) reading).lightVal); } else if (reading.type == 1) { properties.addProperty("readingType", "" + 1); properties.addProperty("level", "" + ((NoiseReading) reading).soundVal); } else if (reading.type == 2) { properties.addProperty("readingType", "" + 2); properties.addProperty("message", "" + ((TextVisual) reading).textMsg); } else { // System.out.println("Reading instance not known"); } properties.addProperty("recordTime", reading.timestamp); properties.addProperty("volatility", reading.volatility); feature.add("properties", properties); features.add(feature); featureCollection.add("features", features); if (reading.volatility != 0) { /***** SQL insert ********/ // Insert data System.out.println("before uploading SQL - reading uuid = " + reading.uuid); System.out.println("Reading volatility = " + reading.volatility); PreparedStatement datastmt = sqlse.getSensorInsertStatement(connection, reading.type); if (datastmt != null) { // System.out.println("datastmt - " + // datastmt.toString()); List<Integer> types = sqlse.getArgumentExpectation((long) reading.type); datastmt.setString(1, reading.uuid); if (reading.type == 0) { datastmt.setLong(2, reading.timestamp); datastmt.setLong(3, reading.volatility); datastmt.setDouble(4, ((LightReading) reading).lightVal); datastmt.setDouble(5, reading.location.latnLong[0]); datastmt.setDouble(6, reading.location.latnLong[1]); } else if (reading.type == 1) { datastmt.setLong(2, reading.timestamp); datastmt.setLong(3, reading.volatility); datastmt.setDouble(4, ((NoiseReading) reading).soundVal); datastmt.setDouble(5, reading.location.latnLong[0]); datastmt.setDouble(6, reading.location.latnLong[1]); } else if (reading.type == 2) { datastmt.setLong(2, reading.timestamp); datastmt.setLong(3, reading.volatility); datastmt.setString(4, ((TextVisual) reading).textMsg); datastmt.setDouble(5, reading.location.latnLong[0]); datastmt.setDouble(6, reading.location.latnLong[1]); } // System.out.println("datastmt after populating - " // + datastmt.toString()); datastmt.addBatch(); datastmt.executeBatch(); datastmt.close(); } /*************/ } } catch (JsonParseException e) { System.out.println("can't save json object: " + e.toString()); } // output the result // System.out.println("featureCollection=" + // featureCollection.toString()); String message = featureCollection.toString(); pSocketServer.sendToAll(message); } } catch (EOFException e) { e.printStackTrace(); Log.getInstance().append(Log.FLAG_WARNING, "EOFException occurred, but ignored it for now."); } catch (IOException e) { e.printStackTrace(); Log.getInstance().append(Log.FLAG_WARNING, "Opening data stream from socket failed"); } catch (Exception e) { e.printStackTrace(); Log.getInstance().append(Log.FLAG_WARNING, "Generic error"); } finally { cleanup(); try { in.close(); in = null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); ; } } }
From source file:ch.ethz.coss.nervous.pulse.WriteJSON.java
License:Open Source License
public static void sendGeoJSON(Socket socket, Object o) { try {//from w w w . j ava 2 s. c o m Scanner in = new Scanner(socket.getInputStream()); while (!in.nextLine().isEmpty()) ; PrintWriter out = new PrintWriter(socket.getOutputStream()); Visual reading = (Visual) o; JsonObject feature = new JsonObject(); try { feature.addProperty("type", "Feature"); // JsonArray featureList = new JsonArray(); // iterate through your list // for (ListElement obj : list) { // {"geometry": {"type": "Point", "coordinates": [-94.149, // 36.33]} JsonObject point = new JsonObject(); point.addProperty("type", "Point"); // construct a JSONArray from a string; can also use an array or // list JsonArray coord = new JsonArray(); coord.add(new JsonPrimitive(reading.location.latnLong[0])); coord.add(new JsonPrimitive(reading.location.latnLong[1])); point.add("coordinates", coord); feature.add("geometry", point); JsonObject properties = new JsonObject(); if (reading.type == 0) { // System.out.println("Reading instance of light"); properties.addProperty("readingType", "" + 0); properties.addProperty("lightLevel", "" + ((LightReading) reading).lightVal); } else if (reading.type == 1) { properties.addProperty("readingType", "" + 1); properties.addProperty("noiseLevel", "" + ((NoiseReading) reading).soundVal); } else if (reading.type == 2) { properties.addProperty("readingType", "" + 2); properties.addProperty("message", "" + ((TextVisual) reading).textMsg); } else { // System.out.println("Reading instance not known"); } feature.add("properties", properties); // } } catch (JsonParseException e) { // System.out.println("can't save json object: " + // e.toString()); } // output the result // System.out.println("featureCollection=" + feature.toString()); String message = feature.toString(); out.println("HTTP/1.0 200 OK"); out.println("Content-Type: text/json"); out.printf("Content-Length: %d%n", message.length()); out.println("Access-Control-Allow-Origin: *"); out.println(); out.println(message); out.flush(); socket.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ch.ethz.inf.vs.hypermedia.corehal.block.CoREHalResourceFuture.java
License:Open Source License
public static JsonElement serializeToJsonTree(CoREHalBase base) { Class<? extends CoREHalBase> type = base.getClass(); if (ProxyFactory.isProxyClass(type)) { type = (Class<? extends CoREHalBase>) type.getSuperclass(); }// ww w . j ava 2 s . com JsonElement s = CoREHalResourceFuture.getGson().toJsonTree(base, type); if (s.isJsonObject() && base.json() != null) { JsonObject json = s.getAsJsonObject(); base.json().entrySet().forEach((el) -> { if (!json.has(el.getKey())) { json.add(el.getKey(), el.getValue()); } }); } return s; }
From source file:ch.gaps.slasher.views.main.MainController.java
License:Open Source License
/** * To save the state of the software, the tab, the servers and the databases. *//*w w w. j a va2 s . c o m*/ public void saveState() { try { os = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("save.json"))); Gson jsonEngine = new GsonBuilder().setPrettyPrinting().create(); JsonArray mainArray = new JsonArray(); for (Server s : servers) { JsonObject server = new JsonObject(); server.addProperty("serverDescription", s.getDescription()); server.addProperty("serverDriver", s.getDiverName()); server.addProperty("serverHost", s.getHost()); server.addProperty("serverPort", s.getPort()); JsonArray databases = new JsonArray(); for (Database db : s.getDatabases()) { JsonObject database = new JsonObject(); database.addProperty("databaseDescritpion", db.getDescritpion()); database.addProperty("databaseName", db.getName()); database.addProperty("databaseUsername", db.getUsername()); JsonArray tabsJson = new JsonArray(); tabs.forEach(editorTab -> { if (editorTab.getDatabase() == db) { JsonObject tabJson = new JsonObject(); tabJson.addProperty("tabName", "name"); tabJson.addProperty("moduleName", editorTab.getModuleName()); tabJson.addProperty("content", editorTab.getEditorController().getContent()); tabsJson.add(tabJson); } }); database.add("tabs", tabsJson); databases.add(database); } server.add("databases", databases); mainArray.add(server); } os.write(jsonEngine.toJson(mainArray)); os.flush(); } catch (IOException e) { addToUserCommunication(e.getMessage()); } }
From source file:cl.expertchoice.svl.Svl_RiskTier.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j ava 2 s.c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException { response.setContentType("text/html;charset=UTF-8"); try { String accion = request.getParameter("accion"); JsonObject json = new JsonObject(); switch (accion) { case "listar": { ArrayList<RiskTier> arr = new BnRiskTier().listar(); //ArrayList<RiskTier> arr = null; if (arr != null) { json.addProperty("estado", D.EST_OK); json.add("datos", new Gson().toJsonTree(arr)); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Sin datos"); } response.getWriter().print(json); break; } case "listar-riskindicator": { ArrayList<TablaRiskIndicator> arr = new BnTablaRiskIndicator().listar2(); ArrayList<ValorTablaCore> vtc = new BnValorTablaCore().listar(); if (arr != null) { json.addProperty("estado", D.EST_OK); json.add("datos", new Gson().toJsonTree(arr)); json.add("def", new Gson().toJsonTree(vtc)); // json.add("def", vtc); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Sin datos"); } response.getWriter().print(json); break; } case "guardar-risktier": { JSONObject jsonRiskTier = new JSONObject(request.getParameter("obRiskTier")); int idTipoRiskTier = jsonRiskTier.getInt("tipoRiskTier"); int numFilas = jsonRiskTier.getInt("filas"); int numCols = jsonRiskTier.getInt("columnas"); int idOrigenX = jsonRiskTier.getJSONObject("variableX").getInt("id"); int idOrigenY = jsonRiskTier.getJSONObject("variableY").getInt("id"); JSONArray origenX = jsonRiskTier.getJSONObject("variableX").getJSONArray("datos"); JSONArray origenY = jsonRiskTier.getJSONObject("variableY").getJSONArray("datos"); JSONArray jsonClasificacion = jsonRiskTier.getJSONArray("datos"); TablaRiskIndicator riskIndicator = new TablaRiskIndicator(BigInteger.ZERO, new Variable(idOrigenX, null), new Variable(idOrigenY, null), numFilas, numCols); json = new JsonObject(); if (new BnTablaRiskIndicator().guardarRiskInidcator(riskIndicator, origenX, origenY, jsonClasificacion, idTipoRiskTier)) { json.addProperty("estado", D.EST_OK); json.add("datos", new JsonObject()); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Error al guardar Risk Tier"); } response.getWriter().print(json); break; } case "listar-admin-risktier": { json = new JsonObject(); ArrayList<AdminRiskTier> arr = new BnAdminRiskTier().listar(); if (arr.size() > 0) { json.addProperty("estado", D.EST_OK); json.add("datos", new Gson().toJsonTree(arr)); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Sin datos"); } response.getWriter().print(json); break; } case "update-detalle-admin": { JSONArray jsonData = new JSONArray(request.getParameter("detalles")); for (int i = 0; i < jsonData.length(); i++) { JSONObject ob = jsonData.getJSONObject(i); new BnAdminRiskTier().actualizar(ob.getString("valor"), ob.getInt("idDetalleAdminRiskTier")); } json = new JsonObject(); json.addProperty("estado", D.EST_OK); response.getWriter().print(json); break; } case "listar-detalle-admin-risktier": { json = new JsonObject(); int idAdminRiskTier = Integer.parseInt(request.getParameter("idAdminRiskTier")); ArrayList<DetalleAdminRiskTier> arr = new BnAdminRiskTier().listarDetalles(idAdminRiskTier); if (arr.size() > 0) { json.addProperty("estado", D.EST_OK); json.add("datos", new Gson().toJsonTree(arr)); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Error al listar Risk Tier"); } response.getWriter().print(json); break; } case "listar-depuracion-renta": { json = new JsonObject(); // ArrayList<DepuracionRenta> arr = new BnDepuracionRenta().listar(); // if (arr.size() > 0) { // json.addProperty("estado", D.EST_OK); // json.add("datos", new Gson().toJsonTree(arr)); // } else { // json.addProperty("estado", D.EST_NORESULTADO); // json.addProperty("descripcion", "No data"); // } // response.getWriter().print(json); break; } case "guardar-depuracion-renta": { json = new JsonObject(); // ArrayList<DepuracionRenta> arr = new ArrayList<>(); // // DepuracionRenta dr = new DepuracionRenta(); // dr.setId(Integer.parseInt(request.getParameter("id_deuda_cred_hipotecario"))); // dr.setPorcentajeRenta(request.getParameter("deuda_cred_hipotecario")); // arr.add(dr); // // dr = new DepuracionRenta(); // dr.setId(Integer.parseInt(request.getParameter("id_deuda_comercial"))); // dr.setPorcentajeRenta(request.getParameter("deuda_comercial")); // arr.add(dr); // // dr = new DepuracionRenta(); // dr.setId(Integer.parseInt(request.getParameter("id_deuda_credito_consumo"))); // dr.setPorcentajeRenta(request.getParameter("deuda_credito_consumo")); // arr.add(dr); // // boolean flag = new BnDepuracionRenta().actualizar(arr); // if (flag) { // json.addProperty("estado", D.EST_OK); // } else { // json.addProperty("estado", D.EST_NORESULTADO); // json.addProperty("descripcion", "Error al guardar datos"); // } // // response.getWriter().print(json); break; } case "arbol-risk-tier": { json = new JsonObject(); JsonObject resp = new BnRiskTier().listarArbol2(); if (resp != null) { json.addProperty("estado", D.EST_OK); json.add("datos", resp); } else { json.addProperty("estado", D.EST_NORESULTADO); json.addProperty("descripcion", "Sin datos"); } response.getWriter().print(json); break; } } } catch (JSONException ex) { Logger.getLogger(Svl_RiskTier.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:cl.expertchoice.svl.Svl_Scoring.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//ww w. ja v a 2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try { String accion = request.getParameter("accion"); JsonObject json = new JsonObject(); switch (accion) { case "scoring": { int rut = Integer.parseInt(request.getParameter("rut")); String dv = request.getParameter("dv"); JsonObject jsonCalculos = new JsonObject(); int mesActual = BnScore.obtenerScoring(rut, dv, 0); int mes2 = BnScore.obtenerScoring(rut, dv, 1); int mes3 = BnScore.obtenerScoring(rut, dv, 2); int mes4 = BnScore.obtenerScoring(rut, dv, 3); jsonCalculos.addProperty("mes1", mesActual); jsonCalculos.addProperty("mes2", mes2); jsonCalculos.addProperty("mes3", mes3); jsonCalculos.addProperty("mes4", mes4); json.addProperty("estado", 200); json.add("datos", jsonCalculos); response.getWriter().print(json); break; } //Codigo A.M: case "ObtenerScore": { int score = Integer.parseInt(request.getParameter("score")); JsonObject jsonCalculos = new JsonObject(); Metodos metodo = new Metodos(); String scoreText = metodo.ObtenerScore(score); jsonCalculos.addProperty("scoreText", scoreText); json.addProperty("estado", 200); json.add("datos", jsonCalculos); response.getWriter().print(json); break; } } } catch (Exception ex) { // response.getWriter().print("{ \"estado\" : " + D.EST_ERROR + ", \"descripcion\" : \"" + ex + "\" }"); // D.escribirLog(ex, "Svl_Cliente"); // ex.printStackTrace(); } }
From source file:classes.analysis.Analysis.java
License:Open Source License
private static Analysis parseAnalysisGalaxyData(String origin, String emsuser, JsonObject analysisData) { JsonParser parser = new JsonParser(); JsonArray provenance = (JsonArray) parser.parse(analysisData.get("provenance").getAsString()); //STEP 1. Find the associations between the steps (inputs and outputs) HashMap<String, JsonElement> outputs = new HashMap<String, JsonElement>(); JsonObject stepJSONobject; for (JsonElement step_json : provenance) { stepJSONobject = step_json.getAsJsonObject(); for (JsonElement output : stepJSONobject.getAsJsonArray("outputs")) { outputs.put(output.getAsJsonObject().get("id").getAsString(), step_json); }/* w w w. j a va 2 s .c om*/ if ("upload1".equalsIgnoreCase(stepJSONobject.get("tool_id").getAsString())) { stepJSONobject.remove("step_type"); stepJSONobject.add("step_type", new JsonPrimitive("external_source")); } else { stepJSONobject.add("step_type", new JsonPrimitive("processed_data")); } } for (JsonElement step_json : provenance) { stepJSONobject = step_json.getAsJsonObject(); for (JsonElement input : stepJSONobject.getAsJsonArray("inputs")) { String id = input.getAsJsonObject().get("id").getAsString(); if (outputs.containsKey(id)) { if (!"external_source" .equalsIgnoreCase(outputs.get(id).getAsJsonObject().get("step_type").getAsString())) { outputs.get(id).getAsJsonObject().remove("step_type"); outputs.get(id).getAsJsonObject().add("step_type", new JsonPrimitive("intermediate_data")); } if (!stepJSONobject.has("used_data")) { stepJSONobject.add("used_data", new JsonArray()); } ((JsonArray) stepJSONobject.get("used_data")).add(new JsonPrimitive( "STxxxx." + outputs.get(id).getAsJsonObject().get("id").getAsString())); } } } //STEP 2. Create the instances for the steps ArrayList<NonProcessedData> nonProcessedDataList = new ArrayList<NonProcessedData>(); ArrayList<ProcessedData> processedDataList = new ArrayList<ProcessedData>(); for (JsonElement step_json : provenance) { stepJSONobject = step_json.getAsJsonObject(); if ("external_source".equalsIgnoreCase(stepJSONobject.get("step_type").getAsString())) { nonProcessedDataList.add(ExternalData.parseStepGalaxyData(stepJSONobject, analysisData, emsuser)); } else if ("intermediate_data".equalsIgnoreCase(stepJSONobject.get("step_type").getAsString())) { nonProcessedDataList .add(IntermediateData.parseStepGalaxyData(stepJSONobject, analysisData, emsuser)); } else if ("processed_data".equalsIgnoreCase(stepJSONobject.get("step_type").getAsString())) { processedDataList.add(ProcessedData.parseStepGalaxyData(stepJSONobject, analysisData, emsuser)); } else { throw new InstantiationError("Unknown step type"); } } Collections.sort(nonProcessedDataList); Collections.sort(processedDataList); //STEP 3. Create the instance of analysis Analysis analysis = new Analysis(); analysis.setAnalysisName(analysisData.get("ems_analysis_name").getAsString()); analysis.setAnalysisType("Galaxy workflow"); analysis.setNonProcessedData(nonProcessedDataList.toArray(new NonProcessedData[] {})); analysis.setProcessedData(processedDataList.toArray(new ProcessedData[] {})); analysis.setTags(new String[] { "imported" }); analysis.setStatus("pending"); return analysis; }
From source file:client.commands.TwitchAPICommands.java
License:Apache License
@Override public void run() { if (!this.isAllowed()) return;/*from w w w. java 2 s .c o m*/ if (this.m.getMessage().startsWith("!game")) { String[] arr = this.m.getMessage().split(" ", 2); if (arr.length > 1) { JsonObject innerbody = new JsonObject(); innerbody.addProperty("game", this.m.getMessage().split(" ", 2)[1]); JsonObject obj = new JsonObject(); obj.add("channel", innerbody); System.out.println(obj.toString()); TwitchAPI api = new TwitchAPI(s.getClientid(), s.getOauth()); api.PUT("https://api.twitch.tv/kraken/channels/" + this.m.getChannel(), obj.toString()); } else { TwitchAPI api = new TwitchAPI(s.getClientid(), s.getOauth()); this.mq.offer(new MessageOut(this.m.getChannel().toLowerCase(), api.GET("https://api.twitch.tv/kraken/channels/" + this.m.getChannel()).get("game") .toString())); } } }