List of usage examples for com.google.gson JsonObject get
public JsonElement get(String memberName)
From source file:co.com.powersoft.lab.databaselab.controller.PlantaGeneralServlet.java
/** * Metodo que permite modificar/*from w w w . ja v a2 s.c o m*/ * * @autor Leonardo Solano * @param request contiene los datos pasados por AJAX * @param response contiene 1 si fue exitoso o 0 si no lo fue * @exception IOException */ public void modificarPersonaPlanta(HttpServletRequest request, HttpServletResponse response) throws IOException { //Nombre de la operacin String OPERACION = OperationConstants.MODIFICAR_PERSONA_PLANTA_GENERAL; int resp = 0; try { //Objetos JSON String jsonElementos = request.getParameter("jsonElementos") == null ? "{}" : request.getParameter("jsonElementos"); //Validamos que no sea vacio if (jsonElementos != null && !jsonElementos.equals("{}")) { Gson gson = new Gson(); JsonObject result = gson.fromJson(jsonElementos, JsonElement.class).getAsJsonObject(); //Nombre del prefijo del formulario String prefijo = "personaPlanta_"; JsonArray arrayIdPersonalPlanta = (JsonArray) result.get(prefijo + "idPersonaPlanta"); JsonArray arrayPersonaGeneralId = (JsonArray) result.get(prefijo + "idPersonaGeneral"); JsonArray arrayTipoDocumento = (JsonArray) result.get(prefijo + "comboTipoDocumento"); JsonArray arrayDocumento = (JsonArray) result.get(prefijo + "documento"); JsonArray arrayPNombre = (JsonArray) result.get(prefijo + "pNombre"); JsonArray arraySNombre = (JsonArray) result.get(prefijo + "sNombre"); JsonArray arrayPApellido = (JsonArray) result.get(prefijo + "pApellido"); JsonArray arraySApellido = (JsonArray) result.get(prefijo + "sApellido"); JsonArray arrayCelular = (JsonArray) result.get(prefijo + "celular"); JsonArray arrayTelFijo = (JsonArray) result.get(prefijo + "telFijo"); JsonArray arrayFechaNacimiento = (JsonArray) result.get(prefijo + "fechaNacimiento"); JsonArray arraySexo = (JsonArray) result.get(prefijo + "radioSexo"); JsonArray arrayEmail = (JsonArray) result.get(prefijo + "email"); JsonArray arrayDireccion = (JsonArray) result.get(prefijo + "direccion"); JsonArray arrayCiudad = (JsonArray) result.get(prefijo + "comboCiudad"); JsonArray arrayCodigoPostal = (JsonArray) result.get(prefijo + "codigoPostal"); JsonArray arrayProfesion = (JsonArray) result.get(prefijo + "profesion"); JsonArray arrayLicenciaProfesional = (JsonArray) result.get(prefijo + "licenciaProfesional"); JsonArray arrayNumeroAutorizacion = (JsonArray) result.get(prefijo + "numeroAutorizacion"); JsonArray arrayFechaAutorizacion = (JsonArray) result.get(prefijo + "fechaAutorizacion"); JsonArray arrayAutoridadSuperior = (JsonArray) result.get(prefijo + "idAutoridadSuperior"); JsonArray arrayIdPlantaGeneral = (JsonArray) result.get(prefijo + "idPlantaNew"); JsonArray arrayTipoCargoGeneral = (JsonArray) result.get(prefijo + "radioTipoCargo"); //Organizamos el objeto a agregar PersonaPlantaGeneral personaPlantaGeneral = new PersonaPlantaGeneral(); for (int i = 0; i < arrayIdPersonalPlanta.size(); i++) { //Persona Planta personaPlantaGeneral.setId(Integer.parseInt(HashEncripter.getInstance() .desencrypterKey(arrayIdPersonalPlanta.get(i).getAsString()))); //PlantaGeneral PlantaGeneral plantaGeneral = new PlantaGeneral(); plantaGeneral.setId(Integer.parseInt(HashEncripter.getInstance() .desencrypterKey(arrayIdPlantaGeneral.get(i).getAsString()))); personaPlantaGeneral.setPlantaGeneral(plantaGeneral); //TipoCargoPlantaGeneral TipoCargoPlantaGeneral tipoCargoPlantaGeneral = new TipoCargoPlantaGeneral(); tipoCargoPlantaGeneral.setId(arrayTipoCargoGeneral.get(i).getAsInt()); personaPlantaGeneral.setTipoCargoPlantaGeneral(tipoCargoPlantaGeneral); //Persona General PersonaGeneral personaGeneral = new PersonaGeneral(); personaGeneral.setId(Integer.parseInt(HashEncripter.getInstance() .desencrypterKey(arrayPersonaGeneralId.get(i).getAsString()))); //TipoDocumento TipoDocumento tipoDocumento = new TipoDocumento(); tipoDocumento.setId(arrayTipoDocumento.get(i).getAsInt()); personaGeneral.setTipoDocumento(tipoDocumento); personaGeneral.setDocumento(arrayDocumento.get(i).getAsString().isEmpty() ? "" : arrayDocumento.get(i).getAsString()); personaGeneral.setpNombre( arrayPNombre.get(i).getAsString().isEmpty() ? "" : arrayPNombre.get(i).getAsString()); personaGeneral.setsNombre( arraySNombre.get(i).getAsString().isEmpty() ? "" : arraySNombre.get(i).getAsString()); personaGeneral.setpApellido(arrayPApellido.get(i).getAsString().isEmpty() ? "" : arrayPApellido.get(i).getAsString()); personaGeneral.setsApellido(arraySApellido.get(i).getAsString().isEmpty() ? "" : arraySApellido.get(i).getAsString()); personaGeneral.setCelular( arrayCelular.get(i).getAsString().isEmpty() ? "" : arrayCelular.get(i).getAsString()); personaGeneral.setTelFijo( arrayTelFijo.get(i).getAsString().isEmpty() ? "" : arrayTelFijo.get(i).getAsString()); personaGeneral.setFechaNacimiento(arrayFechaNacimiento.get(i).getAsString().isEmpty() ? "" : arrayFechaNacimiento.get(i).getAsString()); personaGeneral.setSexo(arraySexo.get(i).getAsString().isEmpty() ? "" : arraySexo.get(i).getAsString().toUpperCase()); personaGeneral.setEmail( arrayEmail.get(i).getAsString().isEmpty() ? "" : arrayEmail.get(i).getAsString()); personaGeneral.setDireccion(arrayDireccion.get(i).getAsString().isEmpty() ? "" : arrayDireccion.get(i).getAsString()); personaGeneral.setCodigoPostal(arrayCodigoPostal.get(i).getAsString().isEmpty() ? "" : arrayCodigoPostal.get(i).getAsString()); //Ciudad Ciudad ciudad = new Ciudad(); ciudad.setId(arrayCiudad.get(i).getAsInt()); personaGeneral.setCiudad(ciudad); personaPlantaGeneral.setPersonaGeneral(personaGeneral); //Profesion personaPlantaGeneral.setProfesion(arrayProfesion.get(i).getAsString().isEmpty() ? "" : arrayProfesion.get(i).getAsString()); personaPlantaGeneral .setLicenciaProfesional(arrayLicenciaProfesional.get(i).getAsString().isEmpty() ? "" : arrayLicenciaProfesional.get(i).getAsString()); personaPlantaGeneral .setNumeroAutorizacion(arrayNumeroAutorizacion.get(i).getAsString().isEmpty() ? "" : arrayNumeroAutorizacion.get(i).getAsString()); if (!arrayFechaAutorizacion.get(i).getAsString().isEmpty()) { Date fecha = Utilidades.getInstance() .convertirFecha(arrayFechaAutorizacion.get(i).getAsString(), "yyyy-MM-dd"); personaPlantaGeneral.setFechaAutorizacion(fecha); } //Validamos si tiene autoridad superior if (tipoCargoPlantaGeneral.getId() != 1) { PersonaPlantaGeneral autoridadSuperior = new PersonaPlantaGeneral(); autoridadSuperior.setId(Integer.parseInt(HashEncripter.getInstance() .desencrypterKey(arrayAutoridadSuperior.get(i).getAsString()))); personaPlantaGeneral.setAutoridadSuperior(autoridadSuperior); } } //Modificamos el objeto a la BD resp = ServiceFactory.getInstance().getServiceBeanLab().modificarPersonaPlantaGeneral(usuario, personaPlantaGeneral); } //Retornamos la respuesta al JSP respuestaServer(response, resp); } catch (NumberFormatException | JsonSyntaxException | NamingException e) { //Retornamos la respuesta al JSP respuestaServer(response, resp); logger.error(ErrorUtil.getInstance().getErrorData(e, OPERACION, INFO_ADICIONAL), e); } catch (Exception e) { //Retornamos la respuesta al JSP respuestaServer(response, resp); logger.error(ErrorUtil.getInstance().getErrorData(e, OPERACION, INFO_ADICIONAL), e); } }
From source file:co.edu.poli.util.jqgrid.JqGridData.java
public void getJsonObject(String j) { /*String j = "{groupOp:OR,rules:[{field:id_encabezado,op:cn,data:prueba}," + "{field:modulo,op:cn,data:prueba}," + "{field:norma,op:cn,data:prueba}," + "{field:resultado,op:cn,data:prueba}," + "{field:evidencia,op:cn,data:prueba}," + "{field:elemento,op:cn,data:prueba}," + "{field:descripcion_encab,op:cn,data:prueba98}]}";*/ filtersArr = new HashMap(); Gson gson = new Gson(); JsonElement jelement = new JsonParser().parse(j); JsonObject jobject = jelement.getAsJsonObject(); filtersArr.put("groupOp", jobject.get("groupOp")); JsonArray array = jobject.getAsJsonArray("rules"); ArrayList<filter> f = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { {// ww w . ja v a 2 s.com JsonObject cont = array.get(i).getAsJsonObject(); f.add(new filter(cont.get("field").getAsString(), cont.get("op").getAsString(), cont.get("data").getAsString())); } } filtersArr.put("rules", f); // System.out.println(System.out.printf(searchOperation.get("cn").toString(),"oscar","mesa").toString()); }
From source file:co.edu.uniandes.csw.miso4204.reward.service.RewardService.java
License:MIT License
@POST @Path("/save") public RewardDTO saveReward(@Context HttpHeaders httpHeaders, RewardDTO reward) { try {/*from w w w. j a v a 2 s .com*/ String path = new File(".").getCanonicalPath(); } catch (Exception e) { } String token = httpHeaders.getRequestHeader("X_REST_USER").get(0); ClientConfig config = new ClientConfig(); Client client = ClientBuilder.newClient(config); String entity = client.target(URL_SERVICIO).path(reward.getBuyerId().toString()) .request(MediaType.APPLICATION_JSON).header("X_REST_USER", token).get(String.class); System.out.println(entity); JsonParser parser = new JsonParser(); JsonObject object = (JsonObject) parser.parse(entity); JsonElement column = object.get("id"); String id = column.getAsString(); System.out.println(id); reward.setBuyerId(Long.parseLong(id)); createReward(reward); return reward; }
From source file:co.edu.uniandes.csw.miso4204.wishlistitem.service._WishListItemService.java
License:MIT License
@GET @Path("validate/{token}") public Long validateUser(@PathParam("token") String token) { String respuesta;/* w w w. java 2s . c o m*/ String id = "-1"; try { Gson gsonUtil = new Gson(); respuesta = JsonWebToken.decode(token.replace("\"", ""), "Un14nd3s2014@", true); JsonElement jsonPayload = gsonUtil.fromJson(respuesta, JsonElement.class); JsonObject jobjPayload = jsonPayload.getAsJsonObject(); id = (String) jobjPayload.get("id").getAsString(); } catch (Exception ex) { return Long.parseLong("-1"); } return Long.parseLong(id); }
From source file:co.mcme.barry.UrlWatcher.java
License:MIT License
public static YoutubeVideo getYoutubeInfo(String daturl) { JsonObject obj = getRawYoutubeInfo(daturl); obj = obj.get("entry").getAsJsonObject(); String title = obj.get("title").getAsJsonObject().get("$t").getAsString(); int views = obj.get("yt$statistics").getAsJsonObject().get("viewCount").getAsInt(); JsonArray authora = obj.get("author").getAsJsonArray(); JsonObject authorobj = authora.get(0).getAsJsonObject(); String author = authorobj.get("name").getAsJsonObject().get("$t").getAsString(); JsonObject mg = obj.get("media$group").getAsJsonObject(); JsonArray mediacontent = mg.get("media$content").getAsJsonArray(); JsonObject inner = mediacontent.get(0).getAsJsonObject(); int duration = inner.get("duration").getAsInt(); int hours = duration / 3600; int minutes = (duration % 3600) / 60; int seconds = duration % 60; String prettyduration;//from w w w . ja va2s .c o m if (hours > 0) { prettyduration = hours + "h" + minutes + "m" + seconds + "s"; } else { prettyduration = minutes + "m" + seconds + "s"; } YoutubeVideo video = new YoutubeVideo(title, author, prettyduration, views, duration); return video; }
From source file:co.uk.mattredmond.basewatcher.handlers.APIHandler.java
License:Open Source License
/** * Parsing of the returned JSON from the server * * @param rawJson Raw JSON string from server *///from ww w. j a v a 2s . com private JsonObject parseJson(String rawJson) { JsonObject rawObject = new Gson().fromJson(rawJson, JsonObject.class); JsonObject baseWatcherObject = rawObject.get("BaseWatcher").getAsJsonObject(); JsonObject dataInner = baseWatcherObject.get("data").getAsJsonObject(); if (dataInner.has("error")) { BaseWatcher.logger.error(dataInner.get("error").getAsString()); return null; } else { return dataInner; } }
From source file:co.vaughnvernon.tradercommon.media.AbstractJSONMediaReader.java
License:Apache License
protected JsonElement elementFrom(JsonObject aJsonObject, String aKey) { JsonElement element = aJsonObject.get(aKey); if (element == null) { element = aJsonObject.get("@" + aKey); }/*from w w w . java2s . co m*/ return element; }
From source file:cocacola.cocacola.controller.MemberController.java
License:Apache License
public void gerarVideos() throws Exception { CocaCola coca = new CocaCola(); Calendar cal = Calendar.getInstance(); Date date = cal.getTime();/*from w w w . j a v a2s . c om*/ CocaCola c = new CocaCola(cal, "asdasdasdasd", "url1", "Paul", Status.RECEBIDA); ClientRequest request = new ClientRequest( "http://festivaldomeujeito.com.br/server/index.php/festival/user/format/json"); ClientResponse<String> response = request.get(String.class); try { Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray jArray = parser.parse(response.getEntity()).getAsJsonArray(); for (JsonElement obj : jArray) { JsonElement jelem = gson.fromJson(obj, JsonElement.class); JsonObject jobj = jelem.getAsJsonObject(); System.out.println(jobj.get("mon_pergunta_1")); ClasseJsonCoca cocaJson = gson.fromJson(obj, ClasseJsonCoca.class); cocaJson.setMonPergunta1("decarrao"); cocaJson.setUsuGender("female"); c.setJsonCoca(cocaJson); VideoManager vm = new VideoManager(); vm.gerarVideos(c); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:cocacola.cocacola.controller.MemberController.java
License:Apache License
public void testarRestCoca() { try {/*from w ww .j a v a 2s .c o m*/ Calendar cal = Calendar.getInstance(); Date date = cal.getTime(); CocaCola c = new CocaCola(cal, "asdasdasdasd", "url1", "Paul", Status.RECEBIDA); c.setCor(cocaCola.getCor()); c.setNome(cocaCola.getNome()); c.setSexo(cocaCola.getSexo()); System.out.println(cocaCola.toString()); VideoGerado vg = new VideoGerado(); VideoManager vm = new VideoManager(); ClientRequest request = new ClientRequest( "http://festivaldomeujeito.com.br/server/index.php/festival/user/format/json"); ClientResponse<String> response = request.get(String.class); Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray jArray = parser.parse(response.getEntity()).getAsJsonArray(); for (JsonElement obj : jArray) { System.out.println(obj.toString()); JsonElement jelem = gson.fromJson(obj, JsonElement.class); JsonObject jobj = jelem.getAsJsonObject(); System.out.println(jobj.get("mon_pergunta_1")); ClasseJsonCoca coca = gson.fromJson(obj, ClasseJsonCoca.class); System.out.println(coca.getMonPergunta1()); c.setJsonCoca(coca); vg.setCocaCola(c); System.out.println(vg.getUrlCena2()); System.out.println(vg.getUrlCena3()); System.out.println(vg.getUrlCena4()); System.out.println(vg.getUrlCena5()); System.out.println(vg.getUrlCena6()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.aapkatrade.buyer.seller.registration.SellerRegistrationActivity.java
private void callWebServiceForSellerRegistration() { String URL = getResources().getString(R.string.webservice_base_url) + "/sellerregister"; if (docFile.getAbsolutePath().equals("/")) { Log.e("reach", "NUL_______DOCCCCCCCLICENCE"); showmessage("Please Upload Company Document"); } else {/*from w ww . j av a 2 s . co m*/ if (formSellerData.getBusinessType().contains("1")) { Log.e("work1", "work1"); if (compIncorpFile.getAbsolutePath().equals("/")) { Log.e("reach", "NUL_______compDOCCCCCCCLiCENSE"); showmessage("Please Upload Company Incorporation ( PDF Only )"); } else { progressBarHandler.show(); Ion.with(SellerRegistrationActivity.this).load(URL) .setHeader("authorization", "xvfdbgfdhbfdhtrh54654h54ygdgerwer3") .progress(new ProgressCallback() { @Override public void onProgress(long downloaded, long total) { Log.e("status", downloaded + " * " + total); } }).setMultipartFile("personal_doc", "image*//*", docFile) //.setMultipartFile("personal_doc", "image*//*", docFile) .setMultipartFile("comp_incorporation", "image*//*", compIncorpFile) .setMultipartParameter("authorization", "xvfdbgfdhbfdhtrh54654h54ygdgerwer3") .setMultipartParameter("business_type", formSellerData.getBusinessType()) .setMultipartParameter("business_id", business_id) .setMultipartParameter("companyname", formSellerData.getCompanyName()) .setMultipartParameter("name", formSellerData.getFirstName()) .setMultipartParameter("lastname", formSellerData.getLastName()) .setMultipartParameter("dob", formSellerData.getDOB()) .setMultipartParameter("mobile", formSellerData.getMobile()) .setMultipartParameter("email", formSellerData.getEmail()) .setMultipartParameter("password", formSellerData.getPassword()) .setMultipartParameter("country_id", formSellerData.getCountryId()) .setMultipartParameter("state_id", formSellerData.getStateId()) .setMultipartParameter("city_id", formSellerData.getCityId()) .setMultipartParameter("client_id", formSellerData.getClientId()) .setMultipartParameter("shopname", formSellerData.getShopName()) .setMultipartParameter("tin_number", "521651") .setMultipartParameter("tan_number", "13546848").setMultipartParameter("tc", "fdssd") .setMultipartParameter("platform", "Android") .setMultipartParameter("device_id", AppConfig.getCurrentDeviceId(context)) .asJsonObject().setCallback(new FutureCallback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject result) { progressBarHandler.hide(); AndroidUtils.showErrorLog(context, "work1 response" + result); if (result != null) { Log.e("registration_seller", result.toString()); if (result.get("error").getAsString().equals("false")) { Log.e("registration_seller", "done"); AndroidUtils.showSnackBar(registrationLayout, result.get("message").getAsString()); if (ConnetivityCheck.isNetworkAvailable(context)) { Intent call_to_startactivity = new Intent( SellerRegistrationActivity.this, ActivityOTPVerify.class); call_to_startactivity.putExtra("class_name", "SellerRegistrationActivity"); startActivity(call_to_startactivity); } else { AndroidUtils.showToast(context, "!Internet not available. Check your internet connection."); } } else { AndroidUtils.showSnackBar(registrationLayout, result.get("message").getAsString()); } } else { Log.e("result_seller_error", e.toString()); showmessage(e.toString()); } } }); } } else { Log.e("work2", "work2"); progressBarHandler.show(); Ion.with(SellerRegistrationActivity.this).load(URL) .setHeader("authorization", "xvfdbgfdhbfdhtrh54654h54ygdgerwer3") .progress(new ProgressCallback() { @Override public void onProgress(long downloaded, long total) { Log.e("status", downloaded + " * " + total); } }) //.setMultipartFile("company_doc", "image*//*", docFile) .setMultipartFile("personal_doc", "image*//*", docFile) .setMultipartParameter("authorization", "xvfdbgfdhbfdhtrh54654h54ygdgerwer3") .setMultipartParameter("business_type", formSellerData.getBusinessType()) .setMultipartParameter("business_id", business_id) .setMultipartParameter("companyname", formSellerData.getCompanyName()) .setMultipartParameter("name", formSellerData.getFirstName()) .setMultipartParameter("lastname", formSellerData.getLastName()) .setMultipartParameter("dob", formSellerData.getDOB()) .setMultipartParameter("mobile", formSellerData.getMobile()) .setMultipartParameter("email", formSellerData.getEmail()) .setMultipartParameter("password", formSellerData.getPassword()) .setMultipartParameter("country_id", formSellerData.getCountryId()) .setMultipartParameter("state_id", formSellerData.getStateId()) .setMultipartParameter("city_id", formSellerData.getCityId()) .setMultipartParameter("client_id", formSellerData.getClientId()) .setMultipartParameter("shopname", formSellerData.getShopName()) .setMultipartParameter("tin_number", "521651") .setMultipartParameter("tan_number", "13546848").setMultipartParameter("tc", "fdssd") .setMultipartParameter("platform", "Android") .setMultipartParameter("device_id", AppConfig.getCurrentDeviceId(context)).asJsonObject() .setCallback(new FutureCallback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject result) { progressBarHandler.hide(); if (result != null) { Log.e("registration_seller", result.toString()); if (result.get("error").getAsString().equals("false")) { AndroidUtils.showSnackBar(registrationLayout, result.get("message").getAsString()); Log.e("registration_seller", "done"); Intent call_to_startactivity = new Intent(SellerRegistrationActivity.this, ActivityOTPVerify.class); call_to_startactivity.putExtra("class_name", "SellerRegistrationActivity"); startActivity(call_to_startactivity); } else { AndroidUtils.showSnackBar(registrationLayout, result.get("message").getAsString()); } } else { Log.e("result_seller_error", e.toString()); showmessage(e.toString()); } } }); } } }