List of usage examples for com.google.gson JsonArray add
public void add(JsonElement element)
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private JsonElement domains2JSON() { BlockingDeque<Domain> domains = Database.getInstance().getAll(Domain.class); JsonArray jsD = new JsonArray(); for (Domain d : domains) { IncidenceMatrix mat = d.getMapping(); Map<FCAObject, Set<FCAAttribute>> mapping = mat.getObjects(); JsonObject jso = prepare(d);//from w w w . j a v a2s . com JsonObject jsM = new JsonObject(); for (long mId : mat.getItemMetadata().keySet()) { jsM.addProperty(Long.toString(mId), mat.getItemMetadata().get(mId).getId()); } jso.add(SECTION_M, jsM); List<Long> ownerIDs = new LinkedList<Long>(); for (User o : d.getOwners()) { ownerIDs.add(o.getId()); } jso.add(OWNER, gson.toJsonTree(ownerIDs, new TypeToken<List<Long>>() { }.getType())); jso.addProperty(GLOBAL, d.isGlobal()); jso.addProperty(APPROVED, d.isApproved()); JsonObject jsMapping = new JsonObject(); for (FCAObject o : mapping.keySet()) { LinkedList<Long> aIds = new LinkedList<Long>(); for (FCAAttribute a : mapping.get(o)) { aIds.add(a.getId()); } jsMapping.add(Long.toString(o.getId()), gson.toJsonTree(aIds, new TypeToken<List<Long>>() { }.getType())); } jso.add(MAPPING, jsMapping); jsD.add(jso); } return jsD; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private JsonElement courses2JSON() { BlockingDeque<Course> courses = Database.getInstance().getAll(Course.class); JsonArray jsC = new JsonArray(); for (Course o : courses) { JsonObject jso = prepare(o);// w w w .j a v a2 s .com Set<Domain> domains = o.getDomains(); LinkedList<Long> dIds = new LinkedList<Long>(); for (Domain d : domains) dIds.add(d.getId()); jso.add(SECTION_D, gson.toJsonTree(dIds, new TypeToken<List<Long>>() { }.getType())); jso.addProperty(E_CID, o.getExternalCourseID()); List<Long> participants = new LinkedList<Long>(); for (User u : o.getParticipants()) participants.add(u.getId()); jso.add(PARTICIPANTS, gson.toJsonTree(participants, new TypeToken<List<Long>>() { }.getType())); jsC.add(jso); } return jsC; }
From source file:at.yawk.buycraft.BuycraftApi.java
License:Mozilla Public License
/** * @see #commands(String, String, String) *//*w w w . j av a 2s . c om*/ default List<Command> commands(Collection<String> players, boolean offlineCommands, int offlineCommandLimit) throws IOException { JsonArray array = new JsonArray(); players.forEach(p -> array.add(new JsonPrimitive(p))); return commands(array.toString(), Boolean.toString(offlineCommands), Integer.toString(offlineCommandLimit)); }
From source file:at.yawk.buycraft.BuycraftApi.java
License:Mozilla Public License
/** * @see #removeCommands(String)//ww w .ja va 2 s . c o m */ default void removeCommands(Collection<Integer> commandIds) throws IOException { JsonArray array = new JsonArray(); commandIds.forEach(i -> array.add(new JsonPrimitive(i))); removeCommands(array.toString()); }
From source file:au.edu.unsw.cse.soc.federatedcloud.cloudRessourceBase.RecommenderAPI.java
License:Open Source License
private JsonObject returnDummyObject() { JsonObject json = new JsonObject(); JsonArray descriptionsJsonArray = new JsonArray(); JsonObject desciption1 = new JsonObject(); desciption1.addProperty("Id", "1"); desciption1.addProperty("Name", "SE-Bucket"); desciption1.addProperty("TargetEnv", "IaaS"); desciption1.addProperty("Deployer", "au.edu.unsw.cse.soc.federatedcloud.deployers.aws.AWSS3Deployer"); descriptionsJsonArray.add(desciption1); JsonObject desciption2 = new JsonObject(); desciption2.addProperty("Id", "2"); desciption2.addProperty("Name", "Rackspace-VM"); desciption2.addProperty("TargetEnv", "IaaS"); desciption2.addProperty("Deployer", "au.edu.unsw.cse.soc.federatedcloud.deployers.rackspace.RackspaceDeployer"); descriptionsJsonArray.add(desciption2); JsonObject desciption3 = new JsonObject(); desciption3.addProperty("Id", "3"); desciption3.addProperty("Name", "GoogleDrive"); desciption3.addProperty("TargetEnv", "SaaS"); desciption3.addProperty("Deployer", "au.edu.unsw.cse.soc.federatedcloud.deployers.GoogleDriveDeployer"); descriptionsJsonArray.add(desciption3); json.add("CloudResourceDescriptions", descriptionsJsonArray); return json;/*from ww w . j av a 2s.c o m*/ }
From source file:bank.GetBankPaymentHeader.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w . j av a2s . com*/ * * @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 { Connection dataConnection = null; final JsonObject jResultObj = new JsonObject(); final String from_date = request.getParameter("from_date"); final String to_date = request.getParameter("to_date"); final String v_type = request.getParameter("v_type"); final String branch_cd = request.getParameter("branch_cd"); if (dataConnection == null) { dataConnection = helper.getConnMpAdmin(); } if (dataConnection != null) { try { String sql = "select c.AC_CD,c.REF_NO,VDATE,a.FNAME,c1.BAL,c1.REMARK,c.cheque_no,c.branch_cd from bprhd c left join bprdt c1 on c.REF_NO=c1.REF_NO" + " left join ACNTMST a on c.AC_CD=a.AC_CD where VDATE>=? and VDATE<=? and CTYPE=? "; if (!branch_cd.equalsIgnoreCase("0")) { sql += " and branch_cd=" + branch_cd; } sql += " order by VDATE,ref_no"; PreparedStatement pstLocal = dataConnection.prepareStatement(sql); pstLocal.setString(1, from_date); pstLocal.setString(2, to_date); pstLocal.setString(3, v_type); ResultSet rsLocal = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (rsLocal.next()) { JsonObject object = new JsonObject(); object.addProperty("REF_NO", rsLocal.getString("REF_NO")); object.addProperty("VDATE", rsLocal.getString("VDATE")); object.addProperty("FNAME", rsLocal.getString("FNAME")); object.addProperty("BAL", rsLocal.getString("BAL")); object.addProperty("REMARK", rsLocal.getString("REMARK")); object.addProperty("AC_CD", rsLocal.getString("AC_CD")); object.addProperty("CHEQUE_NO", rsLocal.getString("CHEQUE_NO")); object.addProperty("BRANCH_CD", rsLocal.getString("BRANCH_CD")); array.add(object); } jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } } response.getWriter().print(jResultObj); }
From source file:be.iminds.iot.dianne.builder.DianneBuilder.java
License:Open Source License
private void getAvailableModules(PrintWriter writer) { List<ModuleTypeDTO> moduleTypes = new ArrayList<ModuleTypeDTO>(); synchronized (factories) { for (ModuleFactory f : factories) { moduleTypes.addAll(f.getAvailableModuleTypes()); }//from ww w.j a va2s . com } JsonArray jsonModules = new JsonArray(); for (ModuleTypeDTO moduleType : moduleTypes) { JsonObject jsonModule = new JsonObject(); jsonModule.add("type", new JsonPrimitive(moduleType.type)); jsonModule.add("category", new JsonPrimitive(moduleType.category)); if (moduleType.trainable) { jsonModule.add("trainable", new JsonPrimitive(true)); } jsonModules.add(jsonModule); } writer.write(jsonModules.toString()); writer.flush(); }
From source file:be.iminds.iot.dianne.builder.DianneBuilder.java
License:Open Source License
private void getModuleProperties(String type, PrintWriter writer) { ModuleTypeDTO module = null;//from ww w .ja va2 s . co m synchronized (factories) { for (ModuleFactory f : factories) { module = f.getModuleType(type); if (module != null) break; } } if (module == null) { // return; } JsonArray jsonProperties = new JsonArray(); for (ModulePropertyDTO p : module.properties) { JsonObject jsonProperty = new JsonObject(); jsonProperty.addProperty("id", p.id); jsonProperty.addProperty("name", p.name); jsonProperties.add(jsonProperty); } writer.write(jsonProperties.toString()); writer.flush(); }
From source file:be.iminds.iot.dianne.builder.DianneData.java
License:Open Source License
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); String action = request.getParameter("action"); if (action.equals("available-datasets")) { JsonArray result = new JsonArray(); synchronized (datasets) { for (DatasetDTO d : datasets.getDatasets()) { JsonObject r = new JsonObject(); r.add("dataset", new JsonPrimitive(d.name)); r.add("size", new JsonPrimitive(d.size)); if (d.inputType != null) r.add("inputType", new JsonPrimitive(d.inputType)); if (d.targetType != null) r.add("targetType", new JsonPrimitive(d.targetType)); String[] ll = d.labels; if (ll != null) { JsonArray labels = new JsonArray(); for (String l : ll) { labels.add(new JsonPrimitive(l)); }/*from w w w .j a va 2 s . com*/ r.add("labels", labels); } result.add(r); } } response.getWriter().println(result.toString()); response.getWriter().flush(); } else if (action.equals("sample")) { String dataset = request.getParameter("dataset"); Dataset d = datasets.getDataset(dataset); if (d != null && d.size() > 0) { int index = rand.nextInt(d.size()); Sample s = d.getSample(index); JsonObject sample = converter.toJson(s.input); sample.add("index", new JsonPrimitive(index)); String[] labels = d.getLabels(); if (labels != null) { sample.add("target", new JsonPrimitive(labels[TensorOps.argmax(s.target)])); } else { if (s.target.size() < 10) { JsonObject target = converter.toJson(s.target); sample.add("target", target.get("data").getAsJsonArray()); } } response.getWriter().println(sample.toString()); response.getWriter().flush(); } } }
From source file:be.iminds.iot.dianne.builder.DianneDatasets.java
License:Open Source License
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action = request.getParameter("action"); if (action.equals("available-datasets")) { JsonArray result = new JsonArray(); synchronized (datasets) { for (Dataset d : datasets.values()) { JsonObject r = new JsonObject(); r.add("dataset", new JsonPrimitive(d.getName())); r.add("size", new JsonPrimitive(d.size())); JsonArray labels = new JsonArray(); for (String l : d.getLabels()) { labels.add(new JsonPrimitive(l)); }//from ww w . j a v a2 s . c om r.add("labels", labels); result.add(r); } } response.getWriter().println(result.toString()); response.getWriter().flush(); } else if (action.equals("sample")) { String dataset = request.getParameter("dataset"); Dataset d = datasets.get(dataset); if (d != null) { JsonObject sample = new JsonObject(); Tensor t = d.getInputSample(rand.nextInt(d.size())); if (t.dims().length == 3) { sample.add("channels", new JsonPrimitive(t.dims()[0])); sample.add("height", new JsonPrimitive(t.dims()[1])); sample.add("width", new JsonPrimitive(t.dims()[2])); } else { sample.add("channels", new JsonPrimitive(1)); sample.add("height", new JsonPrimitive(t.dims()[0])); sample.add("width", new JsonPrimitive(t.dims()[1])); } sample.add("data", parser.parse(Arrays.toString(t.get()))); response.getWriter().println(sample.toString()); response.getWriter().flush(); } } }