List of usage examples for org.json.simple JSONArray add
public boolean add(E e)
From source file:modelo.ParametrizacionManagers.MotivosVisitas.java
/** * * Obtiene la informacion del tipo de contacto mediante un codigo y * guarda todo en un JSONArray para entregarselo a la vista. * * @return JSONArray//from w w w .ja v a 2s. c om * @throws SQLException */ public JSONArray getMotivoVisita(int codigo) throws Exception { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarMotivosVisitas seleccionar = new SeleccionarMotivosVisitas(); ResultSet rst = seleccionar.getMotivoVisita(codigo); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); while (rst.next()) { //Creamos el objecto JSON jsonObject.put("descripcion", rst.getString("DESCRIPCION")); jsonObject.put("codigo", rst.getString("CODIGO")); //Creamos el Array JSON jsonArray.add(jsonObject.clone()); } seleccionar.desconectar(); return jsonArray; }
From source file:modelo.ParametrizacionManagers.DocumentacionRequerida.java
/** * * Llama al delegate para Eliminar una unidad de medida. * * @param codigo //from w w w. j a v a 2 s. c o m * @throws Exception */ public JSONArray eliminar(int codigo) throws Exception { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); Integer respError; EliminarDocumentacionRequerida delete = new EliminarDocumentacionRequerida(codigo); delete.ejecutar(); respError = delete.getError(); jsonObject.put("error", respError); jsonArray.add(jsonObject); return jsonArray; }
From source file:modelo.ParametrizacionManagers.Laboratorios.java
/** * * Llama al delegate para Eliminar un Laboratorio * * @param codigo /*from w w w. ja va 2 s.com*/ * @throws Exception */ public JSONArray Eliminar(int codigo) throws Exception { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); Integer respError; EliminarLaboratorios delete = new EliminarLaboratorios(codigo); delete.ejecutar(); respError = delete.getError(); jsonObject.put("error", respError); jsonArray.add(jsonObject); return jsonArray; }
From source file:edu.vt.vbi.patric.portlets.CompareRegionViewer.java
@SuppressWarnings("unchecked") private void printRefSeqInfo(ResourceRequest request, ResourceResponse response) throws IOException { String contextType = request.getParameter("cType"); String contextId = request.getParameter("cId"); String pinFeatureSeedId = request.getParameter("feature"); // pin feature String windowSize = request.getParameter("window"); // window size // if pin feature is not given, retrieve from the database based on na_feature_id if (pinFeatureSeedId == null && (contextType != null && contextType.equals("feature") && contextId != null)) { DataApiHandler dataApi = new DataApiHandler(request); GenomeFeature feature = dataApi.getFeature(contextId); pinFeatureSeedId = feature.getPatricId(); }//from www. j ava 2 s . c om if (pinFeatureSeedId != null && !pinFeatureSeedId.equals("") && windowSize != null) { JSONObject seq = new JSONObject(); seq.put("length", (Integer.parseInt(windowSize))); seq.put("name", pinFeatureSeedId); seq.put("seqDir", ""); seq.put("start", 1); seq.put("end", (Integer.parseInt(windowSize))); seq.put("seqChunkSize", 20000); JSONArray json = new JSONArray(); json.add(seq); response.setContentType("application/json"); json.writeJSONString(response.getWriter()); response.getWriter().close(); } else { response.getWriter().write("[]"); } }
From source file:hoot.services.controllers.ogr.ExportResource.java
/** * Generates command params//from w w w.j a va2s . c om * * @param outputType * @param translation * @param input * @return * @throws Exception */ private JSONObject createCommand(String output, String outputType, String translation, String input, String inputType) throws Exception { String outputtype = ""; String jobid = UUID.randomUUID().toString(); if (outputType.equalsIgnoreCase("FGDB")) { outputtype = "gdb"; } else if (outputType.equalsIgnoreCase("SHP")) { outputtype = "shp"; } else { throw new Exception("Invalid file type"); } outputFolderPath = tempOutputPath + "/" + jobid; JSONArray params = new JSONArray(); JSONObject param = new JSONObject(); param = new JSONObject(); param.put("translation", translation); params.add(param); param = new JSONObject(); param.put("input", input); params.add(param); param = new JSONObject(); param.put("inputtype", inputType); params.add(param); param = new JSONObject(); param.put("output", output); params.add(param); param = new JSONObject(); param.put("outputtype", outputtype); params.add(param); param = new JSONObject(); param.put("outputfolder", outputFolderPath); params.add(param); JSONObject command = new JSONObject(); command.put("exectype", "make"); command.put("exec", exportScript); command.put("jobId", jobid); command.put("params", params); return command; }
From source file:ApplicationIntegrationTest.java
@Test public void test1CanCreateBook() { //System.out.println("\n\n\nBOOK:" + _bookDTO.getId() + ":" + _bookDTO.getTitle() + "\n\n\n"); //_userDTO = _userService.readOne(1); _genreDTO1 = _genreService.create(_genreDTO1); _subgenreDTO1 = _subgenreService.create(_subgenreDTO1); _themeDTO1 = _themeService.create(_themeDTO1); _awardDTO1 = _awardService.create(_awardDTO1); _formatDTO1 = _formatService.create(_formatDTO1); _miscDTO1 = _miscService.create(_miscDTO1); JSONObject userJson = new JSONObject(); userJson.put("id", _userDTO.getId()); userJson.put("username", _userDTO.getUsername()); JSONObject genreJson = new JSONObject(); genreJson.put("id", _genreDTO1.getId()); JSONArray genreDTOs = new JSONArray(); genreDTOs.add(genreJson); JSONObject subgenreJson = new JSONObject(); subgenreJson.put("id", _subgenreDTO1.getId()); JSONArray subgenreDTOs = new JSONArray(); subgenreDTOs.add(subgenreJson);/* ww w . j a v a2 s . co m*/ JSONObject themeJson = new JSONObject(); themeJson.put("id", _themeDTO1.getId()); JSONArray themeDTOs = new JSONArray(); themeDTOs.add(themeJson); JSONObject awardJson = new JSONObject(); awardJson.put("id", _awardDTO1.getId()); JSONArray awardDTOs = new JSONArray(); awardDTOs.add(awardJson); JSONObject formatJson = new JSONObject(); formatJson.put("id", _formatDTO1.getId()); JSONArray formatDTOs = new JSONArray(); formatDTOs.add(formatJson); JSONObject miscJson = new JSONObject(); miscJson.put("id", _miscDTO1.getId()); JSONArray miscDTOs = new JSONArray(); miscDTOs.add(miscJson); JSONObject bookJson = new JSONObject(); bookJson.put("title", _bookDTO.getTitle()); bookJson.put("author", _bookDTO.getAuthor()); bookJson.put("publisher", _bookDTO.getPublisher()); bookJson.put("isbn", _bookDTO.getIsbn()); bookJson.put("year", _bookDTO.getYear()); bookJson.put("user", userJson); bookJson.put("genres", genreDTOs); bookJson.put("subgenres", subgenreDTOs); bookJson.put("themes", themeDTOs); bookJson.put("awards", awardDTOs); bookJson.put("formats", formatDTOs); bookJson.put("misc", miscDTOs); System.out.println("\n\n\n\nJSON: \n" + bookJson.toJSONString()); System.out.println("\nJSON: \n" + genreDTOs.toJSONString() + "\n\n\n\n"); Integer bookId = given().contentType(JSON).body(bookJson.toJSONString()).when().post("/createBook").then() .contentType(JSON).statusCode(HttpStatus.SC_OK).body("title", equalTo(_bookDTO.getTitle())) .body("author", equalTo(_bookDTO.getAuthor())).body("publisher", equalTo(_bookDTO.getPublisher())) .body("isbn", equalTo(_bookDTO.getIsbn())).body("year", equalTo(_bookDTO.getYear())). body("genres[0].name", equalTo(_genreDTO1.getName())) .body("genres[0].description", equalTo(_genreDTO1.getDescription())). body("subgenres[0].name", equalTo(_subgenreDTO1.getName())) .body("subgenres[0].description", equalTo(_subgenreDTO1.getDescription())). body("themes[0].name", equalTo(_themeDTO1.getName())) .body("themes[0].description", equalTo(_themeDTO1.getDescription())). body("awards[0].name", equalTo(_awardDTO1.getName())) .body("awards[0].description", equalTo(_awardDTO1.getDescription())). body("formats[0].name", equalTo(_formatDTO1.getName())) .body("formats[0].description", equalTo(_formatDTO1.getDescription())). body("misc[0].name", equalTo(_miscDTO1.getName())) .body("misc[0].description", equalTo(_miscDTO1.getDescription())). log().ifError().extract().path("id"); _bookDTO.setId(bookId); //System.out.println("\n\n\n **" + bookId + "**\n\n\n"); System.out.println("\n\n\n\n CREATED BOOK: \n" + get("/readBook?id=".concat(_bookDTO.getId().toString())).asString() + "\n\n\n\n"); }
From source file:com.tresys.jalop.utils.jnltest.Config.ConfigTest.java
@Before public void setup() throws Exception { jsonCfg = new JSONObject(); jsonCfg.put("address", "127.0.0.1"); jsonCfg.put("port", 1234); JSONArray dataClassArray = new JSONArray(); dataClassArray.add("audit"); sub = new JSONObject(); sub.put("dataClass", dataClassArray); sub.put("pendingDigestMax", 128); sub.put("pendingDigestTimeout", 120); sub.put("output", "./output"); sub.put("sessionTimeout", "00:00:00"); pub = new JSONObject(); pub.put("dataClass", dataClassArray); pub.put("input", "./input"); pub.put("sessionTimeout", "00:00:00"); listener = new JSONObject(); listener.put("pendingDigestMax", 128); listener.put("pendingDigestTimeout", 120); listener.put("output", "./output"); listener.put("input", "./input"); listener.put("peers", new JSONArray()); listener.put("sessionTimeout", "00:00:00"); }
From source file:org.opencastproject.userdirectory.jpa.JpaUserAndRoleProvider.java
/** * Formats a user object to json.//from w ww . ja v a2 s. co m * * @param user * the user * @return the json representation */ @SuppressWarnings("unchecked") protected JSONObject toJson(User user) throws IOException { JSONObject json = new JSONObject(); JSONArray roles = new JSONArray(); for (String role : user.getRoles()) { roles.add(role); } json.put(USERNAME, user.getUserName()); json.put(ROLES, roles); return json; }
From source file:com.facebook.tsdb.tsdash.server.model.Metric.java
@SuppressWarnings("unchecked") private JSONArray encodeCommonTags(HashSet<String> commonTags) { JSONArray commonTagsArray = new JSONArray(); for (String tag : commonTags) { commonTagsArray.add(tag); }// w w w.j av a 2 s .c om return commonTagsArray; }
From source file:gr.iit.demokritos.cru.cps.api.SubmitCreativityExhibit.java
public JSONObject processRequest() throws IOException, ClassNotFoundException, IllegalAccessException, Exception { String response_code = "e0"; long exhibit_id = 0; exhibit = java.net.URLDecoder.decode(exhibit, "UTF-8"); if (exhibit.isEmpty() || exhibit.length() < 2) { response_code = "e104"; }// w w w. ja v a 2 s .co m if (!exhibit.endsWith(".")) { exhibit = exhibit + "."; } if (!((language == "en") || (language == "de") || (language == "el"))) { response_code = "e107"; } ArrayList<Metric> metric = new ArrayList<Metric>(); String location = (String) properties.get("location"); String database_name = (String) properties.get("database_name"); String username = (String) properties.get("username"); String password = (String) properties.get("password"); String database_dir = (String) properties.get("wordnet.database.dir"); String thesaurus_de = (String) properties.get("openthesaurus_DE"); String thesaurus_el = (String) properties.get("openthesaurus_EL"); String stopWordsEN = (String) properties.get("stopWordsFile_EN"); String stopWordsGR = (String) properties.get("stopWordsFile_GR"); String stopWordsDE = (String) properties.get("stopWordsFile_DE"); String offensiveWords = (String) properties.get("offensiveWordsFile"); MySQLConnector mysql = new MySQLConnector(location, database_name, username, password); try { Connection connection = mysql.connectToCPSDatabase(); Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT window FROM windows WHERE current_window=1"); int window = -1; while (rs.next()) { window = rs.getInt(1); } rs.close(); CreativityExhibitModelController cemc = new CreativityExhibitModelController( Long.parseLong(application_key), Long.parseLong(user_id), exhibit, type, window, language); boolean isvalid = false; isvalid = cemc.validateClientApplication(mysql); if (!(response_code.equalsIgnoreCase("e104")) || (response_code.equalsIgnoreCase("e107"))) { if (isvalid == true) { isvalid = cemc.validateUser(mysql); if (isvalid == true) { isvalid = cemc.validateType(mysql); if (isvalid == false) { response_code = "e103"; } } else { response_code = "e102"; } } else { response_code = "e101"; } } if (isvalid == true) { ArrayList<String> thesaurus = new ArrayList<String>(); thesaurus.add(thesaurus_de); thesaurus.add(thesaurus_el); String stopWordsFile = ""; if (language.equalsIgnoreCase("en")) { stopWordsFile = stopWordsEN; } else if (language.equalsIgnoreCase("de")) { stopWordsFile = stopWordsDE; } else { stopWordsFile = stopWordsGR; } metric = cemc.invokeComputationalCreativityMetricsCalculator(mysql, database_dir, thesaurus, stopWordsFile, offensiveWords); if (metric.isEmpty()) { response_code = "e301"; } else { cemc.storeEvidenceandMetrics(mysql); exhibit_id = cemc.getExhibit_id(); response_code = "OK"; } } } catch (NumberFormatException ex) { response_code = "e101"; Logger.getLogger(CreateUser.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(SubmitCreativityExhibit.class.getName()).log(Level.SEVERE, null, ex); } JSONObject obj_metric = new JSONObject(); JSONArray list = new JSONArray(); if (!metric.isEmpty()) { for (Metric temp_metric : metric) { obj_metric.put(temp_metric.getName(), temp_metric.getValue()); } } list.add(obj_metric); JSONObject obj = new JSONObject(); obj.put("application_key", application_key); obj.put("user_id", user_id); obj.put("exhibit_id", Long.toString(exhibit_id)); obj.put("exhibit_type", type); obj.put("metrics", list); obj.put("response_code", response_code); return obj; }