List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:io.personium.test.jersey.cell.ctl.CellCtlUtils.java
/** * ???????ExtRole??./*from ww w .jav a2 s .co m*/ * @param cellName ?? * @param testExtRoleName ?? * @param relationName ?? * @param relationBoxName ?? * @param relationNameEmpty _Relation.Name??? * @param relationBoxNameEmpty _Relation._Box.Name??? */ @SuppressWarnings({ "unchecked", "unused" }) public static void createExtRole(String cellName, String testExtRoleName, String relationName, String relationBoxName, boolean relationNameEmpty, boolean relationBoxNameEmpty) { JSONObject body = new JSONObject(); body.put("ExtRole", testExtRoleName); if (!relationNameEmpty) { body.put("_Relation.Name", relationName); } if (!relationBoxNameEmpty) { body.put("_Relation._Box.Name", relationBoxName); } TResponse response = Http.request("cell/extRole/extRole-create.txt") .with("token", AbstractCase.MASTER_TOKEN_NAME).with("cellPath", cellName) .with("body", body.toString()).returns().statusCode(HttpStatus.SC_CREATED); }
From source file:com.lifetime.util.TimeOffUtil.java
public static HttpEntity getTimeoffRequestEntity(int page, int pagesize) { if ((page <= 0) || (pagesize <= 0)) { return null; }/*from w w w . jav a2 s. c o m*/ JSONObject jsonObject = new JSONObject(); jsonObject.put("page", String.valueOf(page)); jsonObject.put("pagesize", String.valueOf(pagesize)); JSONArray columnUris = new JSONArray(); columnUris.add("urn:replicon:time-off-list-column:time-off"); columnUris.add("urn:replicon:time-off-list-column:time-off-type"); columnUris.add("urn:replicon:time-off-list-column:department-of-time-off-owner"); jsonObject.put("columnUris", columnUris); JSONArray sort = new JSONArray(); JSONObject sortObject = new JSONObject(); sortObject.put("columnUri", "urn:replicon:time-off-list-column:time-off"); sortObject.put("isAscending", "false"); sort.add(sortObject); JSONObject filter = new JSONObject(); JSONObject leftExpression = new JSONObject(); leftExpression.put("filterDefinitionUri", "urn:replicon:time-off-list-filter:time-off-type"); filter.put("leftExpression", leftExpression); filter.put("operatorUri", "urn:replicon:filter-operator:equal"); JSONObject value = new JSONObject(); value.put("string", "us-pto"); JSONObject rightExpression = new JSONObject(); rightExpression.put("value", value); filter.put("rightExpression", rightExpression); jsonObject.put("filterExpression", filter); HttpEntity entity = null; String jsonString = jsonObject.toJSONString(); try { entity = new StringEntity(jsonString); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return entity; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.DomainObjectJSONSerializer.java
public static JSONObject getDomainObject(DomainObject obj) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { final JSONObject jsonObject = new JSONObject(); final Class<? extends DomainObject> clazz = obj.getClass(); final String objClassName = clazz.getName(); jsonObject.put("externalId", obj.getExternalId()); jsonObject.put("className", objClassName); final DomainClass domainClass = getDomainClass(objClassName); if (domainClass == null) { return jsonObject; }/*ww w . java 2 s. c o m*/ for (Slot slot : getAllSlots(domainClass)) { final String slotName = slot.getName(); final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName)); final Object result = method.invoke(obj); jsonObject.put(slotName, result == null ? null : result.toString()); } for (Role roleSlot : getAllRoleSlots(domainClass)) { final String slotName = roleSlot.getName(); if (roleSlot.getMultiplicityUpper() == 1) { final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName)); final AbstractDomainObject singleRelationObj = (AbstractDomainObject) method.invoke(obj); final JSONArray oneRelation = new JSONArray(); if (singleRelationObj != null) { oneRelation.add(singleRelationObj.getExternalId()); } jsonObject.put(slotName, oneRelation); } else { final Method method = clazz.getMethod("get" + StringUtils.capitalize(slotName) + "Set"); final Set<? extends AbstractDomainObject> result = (Set<? extends AbstractDomainObject>) method .invoke(obj); jsonObject.put(slotName, serializeRelation(result)); } } return jsonObject; }
From source file:at.ait.dme.yuma.suite.apps.core.server.annotation.JSONAnnotationHandler.java
@SuppressWarnings("unchecked") private static JSONArray serializeSemanticTags(List<SemanticTag> tags) { JSONArray jsonArray = new JSONArray(); for (SemanticTag t : tags) { JSONObject jsonObj = new JSONObject(); jsonObj.put(KEY_TAG_URI, t.getURI()); jsonObj.put(KEY_TAG_LABEL, t.getPrimaryLabel()); jsonObj.put(KEY_TAG_DESCRIPTION, t.getPrimaryDescription()); jsonObj.put(KEY_TAG_LANG, t.getPrimaryLanguage()); jsonObj.put(KEY_TAG_TYPE, t.getType()); JSONArray altLabels = new JSONArray(); for (PlainLiteral p : t.getAlternativeLabels()) { JSONObject label = new JSONObject(); label.put(KEY_ALT_LABEL_LANG, p.getLanguage()); label.put(KEY_ALT_LABEL_VAL, p.getValue()); altLabels.add(label);//from ww w.j av a 2s .c o m } jsonObj.put(KEY_TAG_ALT_LABELS, altLabels); jsonArray.add(jsonObj); } return jsonArray; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void editarUsuario(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println(request.getParameter("5")); ArrayList r = CtrlAdmin.editarUsuario(Integer.parseInt(request.getParameter("0")), //IdUsuario request.getParameter("1"), //Nombre request.getParameter("2"), //Apellidos request.getParameter("3"), //Tipo de documento request.getParameter("4"), //documento request.getParameter("5"), //Correo= usuario request.getParameter("6"), //passworld request.getParameter("7").charAt(0)//rol );/* ww w . j a va 2 s . c om*/ response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); if (r.get(0) == "error") { obj.put("isError", true); boolean errorSerio = false; if (r.get(1) == "usuario") { obj.put("errorDescrip", "El usuario ya existe"); } else if (r.get(1) == "contrasena") { obj.put("errorDescrip", "La contrasea es invalida"); } else if (r.get(1) == "documento") { obj.put("errorDescrip", "El documento ya est registrado"); } else if (r.get(1) == "tipoDocumento") { obj.put("errorDescrip", "El tipo de documento es invalido"); } else if (r.get(1) == "correo") { obj.put("errorDescrip", "El correo ya est registrado"); } else if (r.get(1) == "correo1") { obj.put("errorDescrip", "El correo no es valido"); } else if (r.get(1) == "nombre") { obj.put("errorDescrip", "Los nombres o apellidos son incorrectos"); } else if (r.get(1) == "rol") { obj.put("errorDescrip", "El rol es invalido, los posibles valores son: E, P y A"); } else { Util.errordeRespuesta(r, out); errorSerio = true; } if (!errorSerio) { out.print(obj); } } else if (r.get(0) == "isExitoso") { obj.put("Exitoso", true); out.print(obj); } else Util.errordeRespuesta(r, out); }
From source file:com.opensoc.json.serialization.JSONDecoderHelper.java
@SuppressWarnings("unchecked") public static JSONObject getJSON(DataInputStream data) throws IOException { // TODO Auto-generated method stub JSONObject output = new JSONObject(); int size = data.readInt(); for (int i = 0; i < size; i++) { String key = (String) getObject(data); Object value = getObject(data); output.put(key, value); }/*from w w w . ja v a 2s .co m*/ return output; }
From source file:com.jts.rest.profileservice.utils.RestServiceHelper.java
/** * Uses MemberChallenge service to get all the associated challenge information for a user * Sorts the challenge information with end date * Returns all the active challenges and 3 most recent past challenge * @param sessionId//from w ww . jav a 2 s . c o m * @param username * @return * @throws MalformedURLException * @throws IOException */ @SuppressWarnings("unchecked") public static JSONObject getProcessedChallengesM1(String sessionId, String username) throws MalformedURLException, IOException { //get all challenges JSONArray challenges = getChallenges(sessionId, username); JSONArray activeChallenges = new JSONArray(); JSONArray pastChallenges = new JSONArray(); SortedMap<Long, JSONObject> pastChallengesByDate = new TreeMap<Long, JSONObject>(); Iterator<JSONObject> iterator = challenges.iterator(); DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-ddhh:mm:ss"); while (iterator.hasNext()) { JSONObject challenge = iterator.next(); //identify active challenge with status if (challenge.get("Status__c").equals(PSContants.STATUS_CREATED)) { activeChallenges.add(challenge); } else { String endDateStr = ((String) challenge.get("End_Date__c")).replace("T", ""); Date date = new Date(); try { date = dateFormat.parse(endDateStr); } catch (ParseException pe) { logger.log(Level.SEVERE, "Error occurent while parsing date " + endDateStr); } pastChallengesByDate.put(date.getTime(), challenge); } } //from the sorted map extract the recent challenge int pastChallengeSize = pastChallengesByDate.size(); if (pastChallengeSize > 0) { Object[] challengeArr = (Object[]) pastChallengesByDate.values().toArray(); int startIndex = pastChallengeSize > 3 ? pastChallengeSize - 3 : 0; for (int i = startIndex; i < pastChallengeSize; i++) { pastChallenges.add(challengeArr[i]); } } JSONObject resultChallenges = new JSONObject(); resultChallenges.put("activeChallenges", activeChallenges); resultChallenges.put("pastChallenges", pastChallenges); resultChallenges.put("totalChallenges", challenges.size()); return resultChallenges; }
From source file:gov.nih.nci.caintegrator.application.lists.ajax.CommonListFunctions.java
public static String getListAsList(ListType ty) { JSONObject res = new JSONObject(); res.put("listType", ty.toString()); String results = ""; HttpSession session = ExecutionContext.get().getSession(false); UserListBeanHelper helper = new UserListBeanHelper(session); List patientLists = helper.getLists(ty); if (!patientLists.isEmpty()) { for (int i = 0; i < patientLists.size(); i++) { UserList list = (UserList) patientLists.get(i); ListManager uploadManager = (ListManager) ListManager.getInstance(); Map paramMap = uploadManager.getParams(list); String commas = StringUtils.join(list.getList().toArray(), ","); String sty = list.getListOrigin() != null && !list.getListOrigin().equals(ListOrigin.Default) ? "color:#A90101" : "color:#000"; results += ("<li id='" + paramMap.get("listName") + "' title='" + commas + "' style='" + sty + "'>" + paramMap.get("listName") + "</li>"); }/*from w w w .j a va2 s . co m*/ } else { results = ""; } res.put("LIs", results); return res.toString(); }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void crearUsuario(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println(request.getParameter("5")); ArrayList r = CtrlAdmin.crearUsuario(request.getParameter("1"), //Nombre request.getParameter("2"), //Apellidos request.getParameter("3"), //Tipo de documento request.getParameter("4"), //documento request.getParameter("5"), //Correo= usuario request.getParameter("6"), //passworld request.getParameter("7").charAt(0)//rol );/*from ww w. jav a 2 s. com*/ response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); if (r.get(0) == "error") { JSONObject obj = new JSONObject(); if (r.get(1) == "usuario") { obj.put("isError", true); obj.put("errorDescrip", "El usuario ya existe"); } else if (r.get(1) == "contrasena") { obj.put("isError", true); obj.put("errorDescrip", "La contrasea es invalida"); } else if (r.get(1) == "documento") { obj.put("isError", true); obj.put("errorDescrip", "El documento ya est registrado"); } else if (r.get(1) == "tipoDocumento") { obj.put("isError", true); obj.put("errorDescrip", "El tipo de documento es invalido"); } else if (r.get(1) == "correo") { obj.put("isError", true); obj.put("errorDescrip", "El correo ya est registrado"); } else if (r.get(1) == "correo1") { obj.put("isError", true); obj.put("errorDescrip", "El correo no es valido"); } else if (r.get(1) == "nombre") { obj.put("isError", true); obj.put("errorDescrip", "Los nombres o apellidos son incorrectos"); } else if (r.get(1) == "rol") { obj.put("isError", true); obj.put("errorDescrip", "El rol es invalido, los posibles valores son: E, P y A"); } else Util.errordeRespuesta(r, out); out.print(obj); } else if (r.get(0) == "isExitoso") { JSONObject obj = new JSONObject(); obj.put("Exitoso", true); out.print(obj); } else Util.errordeRespuesta(r, out); }
From source file:edu.usc.polar.CompositeNERAgreementParser.java
public static void CompositeNER(String doc, String args[]) { try {//from w w w.j a v a 2 s . co m String text; AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); InputStream stream = new FileInputStream(doc); // System.out.println(stream.toString()); parser.parse(stream, handler, metadata); // return handler.toString(); text = handler.toString(); String metaValue = metadata.toString(); System.out.println(metaValue + "Desc:: " + metadata.get("description")); String[] example = new String[1]; example[0] = text; String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu"); name = name.replace("\\", "."); Map<String, Set<String>> list = getCoreNLP(text); Map<String, Set<String>> list1 = getOpenNLP(text); Map<String, Set<String>> list2 = getNLTKRest(text); Set<String> NLTKRestSet = combineSets(list2); Set<String> coreNLPSet = combineSets(list); Set<String> openNLPSet = combineSets(list1); /* System.out.println("list coreNLP"+JSONStringify(coreNLPSet).toJSONString()); System.out.println("list openNLPSet"+openNLPSet); System.out.println("list NLTKRestSet"+NLTKRestSet); */ JSONObject jsonObj = new JSONObject(); jsonObj.put("DOI", name); jsonObj.put("OpenNLP", JSONStringify(openNLPSet)); jsonObj.put("NLTKRest", JSONStringify(NLTKRestSet)); jsonObj.put("CoreNLP", JSONStringify(coreNLPSet)); Set<String> union = new HashSet(); union.addAll(NLTKRestSet); union.addAll(coreNLPSet); union.addAll(openNLPSet); jsonObj.put("Union", JSONStringify(union)); Set<String> intersection = new HashSet(); intersection.addAll(union); intersection.retainAll(coreNLPSet); intersection.retainAll(openNLPSet); intersection.retainAll(NLTKRestSet); jsonObj.put("Agreement", JSONStringify(intersection)); /* System.out.println(name+"\n"+openNLPSet.size()+openNLPSet.toString()+ "\n"+coreNLPSet.size()+coreNLPSet.toString()+ "\n"+NLTKRestSet.size()+NLTKRestSet.toArray()+ "\n"+intersection.size()+intersection.toArray()+ "\n"+union.size()+union.toArray()); */ //jsonObj.put("metadata",metaValue.replaceAll("\\s\\s+|\n|\t"," ")); jsonArray.add(jsonObj); if (intersection.size() > 0) { jsonAgree.add(jsonObj); JSONArray jArr = new JSONArray(); jArr.add(jsonObj); metadata.add("CompositeNER", jArr.toJSONString()); } } catch (Exception e) { System.out.println("ERROR : OpenNLP" + "|File Name" + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString()); } }