List of usage examples for org.json.simple JSONArray toJSONString
public String toJSONString()
From source file:mml.handler.get.MMLGetAnnotationsHandler.java
/** * Handle a request for options/* w ww . j av a 2 s . com*/ * @param request the http request * @param response the http response * @param urn the urn (ignored) * @throws MMLException */ @Override public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException { try { JSONArray annotations = new JSONArray(); docid = request.getParameter(Params.DOCID); version1 = request.getParameter(Params.VERSION1); if (docid != null && version1 != null) { Connection conn = Connector.getConnection(); String[] docids = conn.listDocuments(Database.SCRATCH, docid + ".*", JSONKeys.DOCID); if (docids != null && docids.length > 0) { for (int i = 0; i < docids.length; i++) { JSONObject jObj = fetchAnnotation(conn, Database.SCRATCH, docids[i]); if (jObj != null) annotations.add(jObj); } } if (annotations.isEmpty()) // nothing in SCRATCH space { docids = conn.listDocuments(Database.ANNOTATIONS, docid + ".*", JSONKeys.DOCID); if (docids != null && docids.length > 0) { for (int i = 0; i < docids.length; i++) { JSONObject jObj = fetchAnnotation(conn, Database.ANNOTATIONS, docids[i]); if (jObj != null) annotations.add(jObj); } } } } String res = annotations.toJSONString(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); response.getWriter().write(res); } catch (Exception e) { throw new MMLException(e); } }
From source file:mypackage.products.java
private String getResults(String query, String... params) { JSONArray jArray = new JSONArray(); StringBuilder sb = new StringBuilder(); Boolean isSingle = false;// w w w . j a va2 s . c o m try (Connection cn = Credentials.getConnection()) { PreparedStatement pstmt = cn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); isSingle = true; } ResultSet rs = pstmt.executeQuery(); if (isSingle == false) { while (rs.next()) { JSONObject json = new JSONObject(); json.put("productId", rs.getInt("productId")); json.put("name", rs.getString("name")); json.put("description", rs.getString("description")); json.put("quantity", rs.getInt("quantity")); jArray.add(json); } } else { while (rs.next()) { JsonObject jsonObj = Json.createObjectBuilder().add("productId", rs.getInt("productId")) .add("name", rs.getString("name")).add("description", rs.getString("description")) .add("quantity", rs.getInt("quantity")).build(); return jsonObj.toString(); } } } catch (SQLException ex) { Logger.getLogger(products.class.getName()).log(Level.SEVERE, null, ex); } return jArray.toJSONString(); }
From source file:com.imagelake.control.UserDAOImp.java
public String getJSONAllUserTypeList() { JSONArray ja = new JSONArray(); try {//from w ww. j a v a2s . c o m String sql = "SELECT * FROM user_type WHERE user_type_id>3"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { JSONObject jo = new JSONObject(); jo.put("tid", rs.getInt(1)); jo.put("ttype", rs.getString(2)); ja.add(jo); } } catch (Exception e) { e.printStackTrace(); } return ja.toJSONString(); }
From source file:com.imagelake.android.uploadmanagement.Servlet_UploadManagement.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String date = sdf.format(d);/*from w w w . j a va 2 s.co m*/ SimpleDateFormat sdf2 = new SimpleDateFormat("hh:mm:ss"); String Time = sdf2.format(d); String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()); try { String type = request.getParameter("type"); System.out.println("type:" + type); if (type != null && !type.equals("")) { if (type.equals("all")) { ja = new JSONArray(); String category; String seller; List<Images> allList = idi.getNewUploadList(); if (!allList.isEmpty()) { for (Images images : allList) { JSONObject jo = new JSONObject(); jo.put("img_id", images.getImages_id()); jo.put("title", images.getTitle()); jo.put("date", images.getDate()); jo.put("url", images.getImg_url()); category = idi.getCategoryName(images.getCategories_category_id()); jo.put("cat", category); seller = idi.getSellerName(images.getUser_user_id()); jo.put("sel", seller); ja.add(jo); } System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else { out.write("msg=No item found."); } } else if (type.equals("single_details")) { ja = new JSONArray(); String imgid = request.getParameter("imgid"); System.out.println("imgid:" + imgid); if (imgid != null && !imgid.equals("")) { Images im = idi.getImageDetail(Integer.parseInt(imgid)); if (im.getImage_state_image_state_id() == 3 || im.getImage_state_image_state_id() == 1 || im.getImage_state_image_state_id() == 5) { JSONObject jo = new JSONObject(); jo.put("img_id", im.getImages_id()); jo.put("title", im.getTitle()); jo.put("url", im.getImg_url()); //-------------------------------- List<ImagesSub> sublist = idi.getImagedescription(Integer.parseInt(imgid)); JSONArray jk = new JSONArray(); if (!sublist.isEmpty()) { for (ImagesSub imagesSub : sublist) { String dim = imagesSub.getDimention(); String dimArray[] = dim.split(" x "); String width = dimArray[0]; if (!width.equals("400")) { JSONObject jso = new JSONObject(); jso.put("dimention", dim); Credits c = crdi.getCreditDetails(imagesSub.getCredits()); jso.put("size", c.getSize()); jso.put("crd", c.getCredits()); jk.add(jso); } jo.put("subs", jk.toJSONString()); } } else { jo.put("subs", jk.toJSONString()); } //-------------------------------- List<Images> imgList = new ImageRec().imgDiff(im); JSONArray na = new JSONArray(); if (!imgList.isEmpty()) { for (Images images : imgList) { if (images.getImage_state_image_state_id() != 3) { JSONObject jso = new JSONObject(); jso.put("equaltitle", images.getTitle()); jso.put("equalurl", images.getImg_url()); jso.put("equalseller", idi.getSellerName(images.getUser_user_id())); jso.put("equalstate", images.getImage_state_image_state_id()); na.add(jso); } } jo.put("equal", na.toJSONString()); } else { jo.put("equal", na.toJSONString()); } ja.add(jo); System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else { System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } //-------------------------------- } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("keywords")) { String imgid = request.getParameter("imgid"); System.out.println("imgid:" + imgid); if (imgid != null && !imgid.equals("")) { List<KeyWords> listKeyWords = new KeyWordsDAOImp().getkeyWordList(Integer.parseInt(imgid)); JSONArray jsa = new JSONArray(); if (!listKeyWords.isEmpty()) { for (KeyWords keyWords : listKeyWords) { JSONObject jso = new JSONObject(); jso.put("kid", keyWords.getKey_words_id()); jso.put("key", keyWords.getKey_word()); jsa.add(jso); } System.out.println(jsa.toJSONString()); out.write("json=" + jsa.toJSONString()); } else { out.write("json" + jsa.toJSONString()); } } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("add_keywords")) { String key = request.getParameter("key"); String imgId = request.getParameter("imgid"); System.out.println("key:" + key); System.out.println("img ID:" + imgId); if (key != null && !key.equals("") && imgId != null && !imgId.equals("")) { String mx[] = key.trim().split(","); String nk = ""; for (int i = 0; i < mx.length; i++) { if (i == (mx.length - 1)) { nk += mx[i]; } else { nk += mx[i] + " "; } } key = nk; boolean duplicate = new KeyWordsDAOImp().getKeyWords(key, Integer.parseInt(imgId)); if (duplicate) { boolean add = new KeyWordsDAOImp().addKeyWords(Integer.parseInt(imgId), key); if (add) { out.write("msg=Key_Successful..."); } else { out.write("msg=Unable to complete,Please try again later."); } } else { out.write("msg=The keyword is already entered."); } } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("confirem")) { String imgid = request.getParameter("imgid"); String userid = request.getParameter("userid"); if (imgid != null && !imgid.equals("") && userid != null && !userid.equals("")) { User user = udi.getUser(Integer.parseInt(userid)); Images im = idi.getImageDetail(Integer.parseInt(imgid)); boolean k = new ImageRec().isDuplicate(im); if (k) { if (im.getImage_state_image_state_id() != 1) { List<KeyWords> keyList = new KeyWordsDAOImp() .getkeyWordList(Integer.parseInt(imgid)); if (!keyList.isEmpty()) { System.out.println(imgid + "llll"); System.out.println(userid + "kkkkkkkkkk"); System.out.println(""); boolean ok = idi.adminUpdateImages(Integer.parseInt(imgid), 1); System.out.println(ok + " admin update image"); if (ok) { //boolean notified = new NotificationDAOImp().addNotification(noti, date, Time, im.getUser_user_id(), 1, 4); System.out.println("image title:" + im.getTitle()); System.out.println("(((((((((((((" + im.getUser_user_id() + ")))))))))))"); String noti = "Admin " + user.getUser_name() + " has Confirmed your upload " + im.getTitle() + " image."; boolean notiok = ndi.addNotification(noti, date, Time, im.getUser_user_id(), 1, 4); AdminNotification a = new AdminNotification(); a.setUser_id(user.getUser_id()); a.setDate(timeStamp); a.setShow(1); a.setType(1); String not = "Admin " + user.getUser_name() + " has Confirmed upload " + im.getTitle() + " image."; a.setNotification(not); int an = andi.insertNotificaation(a); System.out.println("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP " + an); boolean kl = ahndi.insertNotification(udi.notMeList(user.getUser_id()), an, 1); if (notiok && kl) { out.write("msg=Con_Successful..."); } else { out.write("msg=Unable to send notifications."); } } else { out.write("msg=Unable to confirem upload."); } } else { out.write("msg=Key words are empty."); } } else { out.write("msg=This image is already uploaded."); } } else { out.write("msg=This image has a duplicate."); } } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("cancel")) { String imgid = request.getParameter("imgid"); String userid = request.getParameter("userid"); if (imgid != null && !imgid.equals("") && userid != null && !userid.equals("")) { User user = udi.getUser(Integer.parseInt(userid)); Images im = idi.getImageDetail(Integer.parseInt(imgid)); if (im != null) { //if(imok){ List<ImagesSub> imsub = new ImagesDAOImp().getImagedescription(Integer.parseInt(imgid)); System.out.println(imsub.isEmpty()); /* for (ImagesSub imagesSub : imsub) { boolean subok=new DeleteImage().deleteImage(imagesSub.getImg_url()); System.gc(); }*/ boolean ok = new ImagesDAOImp().removeAdminImage(Integer.parseInt(imgid)); if (ok) { System.out.println("image title:" + im.getTitle()); System.out.println("(((((((((((((" + im.getUser_user_id() + ")))))))))))"); String noti = "Admin " + user.getUser_name() + " has canceled your upload " + im.getTitle() + " image."; boolean notiok = ndi.addNotification(noti, date, Time, im.getUser_user_id(), 1, 3); AdminNotification a = new AdminNotification(); a.setUser_id(user.getUser_id()); a.setDate(timeStamp); a.setShow(1); a.setType(1); String not = "Admin " + user.getUser_name() + " has canceled upload " + im.getTitle() + " image."; a.setNotification(not); int an = andi.insertNotificaation(a); System.out.println("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP " + an); boolean kl = ahndi.insertNotification(udi.notMeList(user.getUser_id()), an, 1); if (notiok && kl) { out.write("msg=Can_Successful..."); } else { out.write("msg=Unable to send notifications."); } } else { out.write("msg=Unable to cancel upload."); } } else { out.write("msg=Unable to find image."); } } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("state")) { String imid = request.getParameter("imgid"); String state = request.getParameter("state"); String userid = request.getParameter("userid"); System.out.println("imid:" + imid); System.out.println("usid:" + userid); System.out.println("state:" + state); User user = udi.getUser(Integer.parseInt(userid)); Images im = idi.getImageDetail(Integer.parseInt(imid)); if (!imid.equals("") && !imid.equals(null) && !state.equals("") && !state.equals(null)) { boolean b = idi.updateState(Integer.parseInt(imid), Integer.parseInt(state)); if (b) { System.out.println("image title:" + im.getTitle()); System.out.println("(((((((((((((" + im.getUser_user_id() + ")))))))))))"); boolean notiok = false; if (state.equals("5")) { String noti = "Admin " + user.getUser_name() + " has blocked your " + im.getTitle() + " image."; notiok = ndi.addNotification(noti, date, Time, im.getUser_user_id(), 1, 2); } else if (state.equals("1")) { String noti = "Admin " + user.getUser_name() + " has activated your " + im.getTitle() + " image."; notiok = ndi.addNotification(noti, date, Time, im.getUser_user_id(), 1, 4); } AdminNotification a = new AdminNotification(); a.setUser_id(user.getUser_id()); a.setDate(timeStamp); a.setShow(1); if (state.equals("5")) { a.setType(2); String not = "Admin " + user.getUser_name() + " has blocked " + im.getTitle() + " image."; a.setNotification(not); } else if (state.equals("1")) { a.setType(4); String not = "Admin " + user.getUser_name() + " has activated " + im.getTitle() + " image."; a.setNotification(not); } int an = andi.insertNotificaation(a); System.out.println("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP " + an); boolean kl = ahndi.insertNotification(udi.notMeList(user.getUser_id()), an, 1); if (notiok && kl) { out.write("msg=Sta_Successful..."); } else { out.write("msg=Unable to send notifications."); } } else { out.write("msg=Unable to update state."); } } else { out.write("msg=Internal server error,Please try again later."); } } } else { out.write("msg=Internal server error,Please try again later."); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.googlecode.fascinator.transformer.basicVersioning.ExtensionBasicVersioningTransformer.java
private void createVersionIndex(String rootPath, String payloadName, String source) { String jsonPath = rootPath + "/" + FilenameUtils.getExtension(source) + "_Version_Index.json"; log.debug("Indexing a version into: " + jsonPath); JSONArray jArr = null; try {// w w w .j a va 2s.c om File oldf = new File(jsonPath); if (oldf.exists()) { log.debug("Need to update a version index file: " + jsonPath); JsonSimple js = new JsonSimple(oldf); jArr = js.getJsonArray(); } else { log.debug("Need to create a new version index file: " + jsonPath); jArr = new JSONArray(); } // since the transformer is firing off multiple times, as seen from the logs, we need to check if there's a version recorded already... String timestamp = getTimestamp(); for (Object curEntryObj : jArr) { JsonObject curEntry = (JsonObject) curEntryObj; String curTs = (String) curEntry.get("timestamp"); if (timestamp.equalsIgnoreCase(curTs)) { log.debug("A duplicate of the timestamp " + timestamp + " is already found in the version index, ignoring."); return; } } JsonObject newVer = new JsonObject(); newVer.put("timestamp", timestamp); newVer.put("file_name", payloadName); // adding the payloadName as a parameter in the event that calls between payloadname() takes too long try { jArr.add(newVer); try { FileWriter fw = new FileWriter(jsonPath); fw.write(jArr.toJSONString()); fw.flush(); fw.close(); } catch (IOException e) { log.error("Failed to save versioning property file.", e); } } catch (Exception eStrange) { log.error("Failed to add a new version.", eStrange); } } catch (Exception eOther) { log.error("Failed to create/edit versioning property file.", eOther); } }
From source file:de.fhg.fokus.odp.middleware.ckan.CKANGatewayUtil.java
/** * Submit comment for a package.//w ww . j a va 2 s .c om * * @param dataSetId * the id of the dataset. * @param userId * the user ID. * @param date * the date of the commenting * @param comment * the comment. * @return true if everything is fine, false otherwise. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static boolean postDatasetComment(String dataSetId, String userId, Date date, String comment) { // check the parameters if (dataSetId == null || dataSetId.equals("") || userId == null || userId.equals("") || comment == null || comment.equals("")) { return false; } // get the package details Object obj = CKANGatewayCore.getDataSetDetails(dataSetId); if (obj == null) { return false; } // prepare the extras string // pick the extras Map mMap = (Map) obj; String resource = mMap.get("resources").toString(); Map eMap = (Map) mMap.get("extras"); JSONArray tArray = (JSONArray) mMap.get("tags"); JSONArray gArray = (JSONArray) mMap.get("groups"); // check weather extras is defined if (eMap != null) { JSONArray comments = null; try { if (eMap.get("comments") instanceof java.lang.String) { JSONParser parser = new JSONParser(); comments = (JSONArray) parser.parse((String) eMap.get("comments")); } else { comments = (JSONArray) eMap.get("comments"); } } catch (ParseException e) { log.log(Level.SEVERE, "Failed to parse result" + (String) eMap.get("comments")); } if (comments == null) { comments = new JSONArray(); } Map<String, String> toadd = new HashMap<String, String>(); toadd.put("userId", userId); toadd.put("comment", comment); toadd.put("date", date.toString()); comments.add(toadd); eMap.put("comments", comments); } // prepare the hash map for the update method HashMap<String, String> hm = new HashMap<String, String>(); hm.put("extras", eMap.toString()); hm.put("resources", resource); hm.put("tags", tArray.toJSONString()); hm.put("groups", gArray.toJSONString()); // update the meta data set HashMap<String, HashMap> res = CKANGatewayCore.updateDataSet(dataSetId, hm); boolean toreturn = (res != null); return toreturn; }
From source file:de.fhg.fokus.odp.middleware.ckan.CKANGatewayUtil.java
/** * Submit rating for a package [rating: number of stars, 1..5] * // ww w . j av a 2s . com * @param dataSetId * the id of the dataset to rate. * @param userId * the ID of the user submitting the rating. * @param date * the date at which the rating takes place. * @param rating * the rating value. * @return true in case of success, false otherwise. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static boolean postDataSetRating(String dataSetId, String userId, Date date, int rating) { // check the parameters if (dataSetId == null || dataSetId.equals("") || userId == null || userId.equals("") || rating < 0 || rating > 5) { return false; } // get the package details Object obj = CKANGatewayCore.getDataSetDetails(dataSetId); if (obj == null) { return false; } // prepare the extras string // pick the extras Map mMap = (Map) obj; Map eMap = (Map) mMap.get("extras"); String resource = mMap.get("resources").toString(); JSONArray tArray = (JSONArray) mMap.get("tags"); JSONArray gArray = (JSONArray) mMap.get("groups"); // check weather extras is defined if (eMap != null) { JSONArray ratings = null; try { if (eMap.get("ratings") instanceof java.lang.String) { JSONParser parser = new JSONParser(); ratings = (JSONArray) parser.parse((String) eMap.get("ratings")); } else { ratings = (JSONArray) eMap.get("ratings"); } } catch (ParseException e) { log.log(Level.SEVERE, "Failed to parse result" + (String) eMap.get("ratings")); } if (ratings == null) { ratings = new JSONArray(); } Map<String, String> toadd = new HashMap<String, String>(); toadd.put("userId", userId); toadd.put("ratingValue", Integer.valueOf(rating).toString()); toadd.put("date", date.toString()); ratings.add(toadd); eMap.put("ratings", ratings); } // prepare the hash map for the update method HashMap<String, String> hm = new HashMap<String, String>(); hm.put("extras", eMap.toString()); hm.put("resources", resource); hm.put("tags", tArray.toJSONString()); hm.put("groups", gArray.toJSONString()); // update the meta data set HashMap<String, HashMap> res = CKANGatewayCore.updateDataSet(dataSetId, hm); boolean toreturn = (res != null); return toreturn; }
From source file:com.photon.phresco.framework.rest.api.ParameterService.java
@GET @Path(GET_PUBLICATIONS)// ww w. j a va 2s . co m @Produces(MediaType.APPLICATION_JSON) public Response getPublications(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName) throws PhrescoException { try { ResponseInfo<String> responseData = new ResponseInfo<String>(); JSONObject publicationItem1 = new JSONObject(); publicationItem1.put("tcm:0-1-1", "000 - Empty Master"); JSONObject publicationItem2 = new JSONObject(); publicationItem2.put("tcm:0-1-1", "010 - Schema Master"); JSONArray jsonArray = new JSONArray(); jsonArray.add(publicationItem1); jsonArray.add(publicationItem2); String publicationJson = jsonArray.toJSONString(); responseData = responseDataEvaluation(responseData, null, publicationJson, RESPONSE_STATUS_SUCCESS, PHRTR0003); return Response.ok(responseData).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER).build(); } catch (Exception e) { return Response.status(Status.EXPECTATION_FAILED).entity(PUBLICATIONS_NOT_FOUND) .header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER).build(); } }
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);/*www .jav a 2 s . co m*/ JSONObject subgenreJson = new JSONObject(); subgenreJson.put("id", _subgenreDTO1.getId()); JSONArray subgenreDTOs = new JSONArray(); subgenreDTOs.add(subgenreJson); 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:net.sourceforge.fenixedu.webServices.jersey.services.JerseyServices.java
protected static String getRegistrationsAsJSON(Set<Registration> registrations) { JSONArray infos = new JSONArray(); int i = 0;//from ww w . ja v a 2 s. c om for (Registration registration : registrations) { JSONObject studentInfoForJobBank = new JSONObject(); studentInfoForJobBank.put("username", registration.getPerson().getUsername()); studentInfoForJobBank.put("hasPersonalDataAuthorization", registration.getStudent().hasPersonalDataAuthorizationForProfessionalPurposesAt().toString()); Person person = registration.getStudent().getPerson(); studentInfoForJobBank.put("dateOfBirth", person.getDateOfBirthYearMonthDay() == null ? null : person.getDateOfBirthYearMonthDay().toString()); studentInfoForJobBank.put("nationality", person.getCountry() == null ? null : person.getCountry().getName()); PhysicalAddress defaultPhysicalAddress = person.getDefaultPhysicalAddress(); studentInfoForJobBank.put("address", defaultPhysicalAddress == null ? null : defaultPhysicalAddress.getAddress()); studentInfoForJobBank.put("area", defaultPhysicalAddress == null ? null : defaultPhysicalAddress.getArea()); studentInfoForJobBank.put("areaCode", defaultPhysicalAddress == null ? null : defaultPhysicalAddress.getAreaCode()); studentInfoForJobBank.put("districtSubdivisionOfResidence", defaultPhysicalAddress == null ? null : defaultPhysicalAddress.getDistrictSubdivisionOfResidence()); studentInfoForJobBank.put("mobilePhone", person.getDefaultMobilePhoneNumber()); studentInfoForJobBank.put("phone", person.getDefaultPhoneNumber()); studentInfoForJobBank.put("email", person.getEmailForSendingEmails()); studentInfoForJobBank.put("remoteRegistrationOID", registration.getExternalId()); studentInfoForJobBank.put("number", registration.getNumber().toString()); studentInfoForJobBank.put("degreeOID", registration.getDegree().getExternalId()); studentInfoForJobBank.put("isConcluded", String.valueOf(registration.isRegistrationConclusionProcessed())); studentInfoForJobBank.put("curricularYear", String.valueOf(registration.getCurricularYear())); for (CycleCurriculumGroup cycleCurriculumGroup : registration.getLastStudentCurricularPlan() .getCycleCurriculumGroups()) { studentInfoForJobBank.put(cycleCurriculumGroup.getCycleType().name(), cycleCurriculumGroup.getAverage().toString()); } infos.add(studentInfoForJobBank); } return infos.toJSONString(); }