List of usage examples for com.google.gson.reflect TypeToken getType
public final Type getType()
From source file:masterController.ModelMasterController.java
public void getData() { Call<JsonObject> call = typeAPI.getTypeMaster(); lb.addGlassPane(this); call.enqueue(new Callback<JsonObject>() { @Override/*from w w w. ja v a2 s. com*/ public void onResponse(Call<JsonObject> call, Response<JsonObject> rspns) { lb.removeGlassPane(ModelMasterController.this); if (rspns.isSuccessful()) { JsonObject result = rspns.body(); if (result.get("result").getAsInt() == 1) { TypeToken<List<TypeMasterModel>> token = new TypeToken<List<TypeMasterModel>>() { }; typeList = new Gson().fromJson(result.get("data"), token.getType()); jcmbType.removeAllItems(); jcmbType.addItem("Select Type"); for (int i = 0; i < typeList.size(); i++) { jcmbType.addItem(typeList.get(i).getTYPE_NAME()); } formLoad = true; } else { lb.showMessageDailog(rspns.body().get("Cause").getAsString()); } } else { lb.showMessageDailog(rspns.message()); } } @Override public void onFailure(Call<JsonObject> call, Throwable thrwbl) { lb.removeGlassPane(ModelMasterController.this); } }); }
From source file:masterController.SeriesMasterController.java
public void setData(final String sr_cd, final String sr_alias, final String sr_name, final String brand_name, final String model_name, final String memory_name, final String color_name) { Call<JsonObject> call = seriesAPI.getSetUpData(sr_cd); lb.addGlassPane(this); call.enqueue(new Callback<JsonObject>() { @Override//from w w w. ja va2s.c om public void onResponse(Call<JsonObject> call, Response<JsonObject> rspns) { lb.removeGlassPane(SeriesMasterController.this); if (rspns.isSuccessful()) { if (rspns.body().get("result").getAsInt() == 1) { model_cd = rspns.body().get("MODEL_CD").getAsString(); memory_cd = rspns.body().get("MEMORY_CD").getAsString(); color_cd = rspns.body().get("COLOUR_CD").getAsString(); SeriesMasterController.this.sr_cd = sr_cd; jtxtItemName.setText(sr_name); jtxtSeriesAlias.setText(sr_alias); jtxtBrandName.setText(brand_name); jtxtModelName.setText(model_name); jtxtMemoryName.setText(memory_name); jtxtColorName.setText(color_name); jtxtQty.setText(rspns.body().get("OPB_QTY").getAsString()); jtxtVal.setText(rspns.body().get("OPB_VAL").getAsString()); final String detailJson = rspns.body().get("data").getAsString(); TypeToken<List<OPBSrVal>> token = new TypeToken<List<OPBSrVal>>() { }; List<OPBSrVal> detail = new Gson().fromJson(detailJson, token.getType()); dtmDetail.setRowCount(0); for (int i = 0; i < detail.size(); i++) { Vector row = new Vector(); row.add(detail.get(i).getTag_no()); row.add(detail.get(i).getImei()); row.add(detail.get(i).getSerial()); row.add(detail.get(i).getP_rate()); jcmbBranch.setSelectedIndex(Integer.parseInt(detail.get(i).getBranch_cd()) - 1); row.add(jcmbBranch.getSelectedItem().toString()); row.add(detail.get(i).getRef_no()); dtmDetail.addRow(row); } setTotal(); } } else { lb.showMessageDailog(rspns.message()); } } @Override public void onFailure(Call<JsonObject> call, Throwable thrwbl) { lb.removeGlassPane(SeriesMasterController.this); } }); }
From source file:masterController.TaxMasterController.java
public void setTaxMasterData(String tax_cd) { try {/* w ww . j av a 2 s. com*/ if (tax_cd.equalsIgnoreCase("")) { setVisible(true); return; } JsonObject result = taxMasterAPI.GetTaxMaster(tax_cd).execute().body(); if (result.get("result").getAsInt() == 1) { TypeToken<List<TaxMasterModel>> token = new TypeToken<List<TaxMasterModel>>() { }; ArrayList<TaxMasterModel> detail = new Gson().fromJson(result.get("data"), token.getType()); for (int i = 0; i < detail.size(); i++) { tax_cd = detail.get(i).getTAXCD(); jtxtTaxName.setText(detail.get(i).getTAXNAME()); jtxtSgst.setText(detail.get(i).getTAXPER() + ""); jtxtCgst.setText(detail.get(i).getADDTAXPER() + ""); jtxtIgst.setText(detail.get(i).getIGST() + ""); jlblUser.setText(detail.get(i).getUSERID() + ""); jlblEditNo.setText(detail.get(i).getEDITNO() + ""); jlblTimeStamp.setText(detail.get(i).getTIMESTAMP()); this.setVisible(true); } } else { lb.showMessageDailog(result.get("Cause").getAsString()); } } catch (IOException ex) { lb.printToLogFile("setTaxMaster", ex); } }
From source file:masterController.UserMasterController.java
private void getData() { try {/* ww w. j ava2s . c o m*/ JsonObject call = userAPI.GetUserGrpMaster().execute().body(); if (call != null) { JsonObject result = call; if (result.get("result").getAsInt() == 1) { TypeToken<List<UserGrpMstModel>> token = new TypeToken<List<UserGrpMstModel>>() { }; userGrpList = new Gson().fromJson(result.get("data"), token.getType()); jcmbType.removeAllItems(); for (int i = 0; i < userGrpList.size(); i++) { jcmbType.addItem(userGrpList.get(i).getUSER_GRP()); typeMap.put(userGrpList.get(i).getUSER_GRP(), userGrpList.get(i).getUSER_GRP_CD()); } } else { lb.showMessageDailog(call.get("Cause").getAsString()); } } } catch (IOException ex) { Logger.getLogger(UserMasterController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:moe.tristan.Lyrical.model.configuration.ApplicationConfigurationReader.java
License:Open Source License
public static ApplicationConfiguration readDefaultConfiguration() { InputStream profileStream = ApplicationConfigurationReader.class.getClassLoader() .getResourceAsStream("DefaultProfile.json"); //noinspection Convert2Diamond TypeToken<HashMap<String, String>> hashMapTypeToken = new TypeToken<HashMap<String, String>>() { };//w w w .j ava 2 s. co m log.debug("Reading the default configuration profile."); final HashMap<String, String> configMap = gson.fromJson(new InputStreamReader(profileStream), hashMapTypeToken.getType()); Arrays.stream(ConfigurationKey.values()).forEach(key -> configMap.putIfAbsent(key.value, "")); log.debug("Read configuration is : " + configMap); return ApplicationConfiguration.builder().configMap(configMap).build(); }
From source file:ms.dew.devops.kernel.helper.KubeOpt.java
License:Apache License
/** * Watch.//from w ww. j av a 2 s. co m * <p> * * @param <T> the type parameter * @param call the call * @param callback the callback * @param clazz the clazz * @return watch Id * @throws ApiException the api exception */ public <T> String watch(KubeWatchCall call, Consumer<Watch.Response<T>> callback, Class<T> clazz) throws ApiException { String watchId = $.field.createShortUUID(); TypeToken typeToken = null; if (clazz == V1Namespace.class) { typeToken = new TypeToken<Watch.Response<V1Namespace>>() { }; } else if (clazz == V1beta1Ingress.class) { typeToken = new TypeToken<Watch.Response<V1beta1Ingress>>() { }; } else if (clazz == V1Service.class) { typeToken = new TypeToken<Watch.Response<V1Service>>() { }; } else if (clazz == V1ServiceAccount.class) { typeToken = new TypeToken<Watch.Response<V1ServiceAccount>>() { }; } else if (clazz == ExtensionsV1beta1Deployment.class) { typeToken = new TypeToken<Watch.Response<ExtensionsV1beta1Deployment>>() { }; } else if (clazz == V1Pod.class) { typeToken = new TypeToken<Watch.Response<V1Pod>>() { }; } else if (clazz == V1Secret.class) { typeToken = new TypeToken<Watch.Response<V1Secret>>() { }; } else if (clazz == V1ConfigMap.class) { typeToken = new TypeToken<Watch.Response<V1ConfigMap>>() { }; } else if (clazz == V1beta1DaemonSet.class) { typeToken = new TypeToken<Watch.Response<V1beta1DaemonSet>>() { }; } else if (clazz == V1Role.class) { typeToken = new TypeToken<Watch.Response<V1Role>>() { }; } else if (clazz == V1RoleBinding.class) { typeToken = new TypeToken<Watch.Response<V1RoleBinding>>() { }; } else if (clazz == V1ClusterRole.class) { typeToken = new TypeToken<Watch.Response<V1ClusterRole>>() { }; } else if (clazz == V1ClusterRoleBinding.class) { typeToken = new TypeToken<Watch.Response<V1ClusterRoleBinding>>() { }; } Watch<T> watch = Watch.createWatch(client, call.call(coreApi, extensionsApi, rbacAuthorizationApi, autoscalingApi), typeToken.getType()); watchMap.put(watchId, watch); executorService.execute(() -> { try { watch.forEach(callback); } catch (RuntimeException e) { if (!watchMap.containsKey(watchId)) { if (e instanceof IllegalStateException && e.getMessage() != null && e.getMessage().equalsIgnoreCase("closed") || e.getMessage() != null && e.getMessage().equals("IO Exception during hasNext method.")) { // https://github.com/kubernetes-client/java/issues/259 } else { throw e; } } else { throw e; } } }); return watchId; }
From source file:org.androidpn.client.NotificationReceiver.java
License:Apache License
private void logic(String notificationMessage) { // TODO Auto-generated method stub // System.out.println("notificationMessage" + notificationMessage); // split[0] ???? logic // split[1]? parameter // split[2]setup ??log? ConfigTest.CASE_LIST = new ArrayList<List<ActionBean>>(); String[] split = notificationMessage.split("###"); String logic = split[0];/* www . ja v a 2 s . c o m*/ // ??split[0] Gson gson = new Gson(); // TypeToken<List<List<ActionBean>>> actionLogic = new // TypeToken<List<List<ActionBean>>>() { // }; TypeToken<List<CaseBean>> actionLogic = new TypeToken<List<CaseBean>>() { }; // ConfigTest.CASE_LIST = gson.fromJson(logic, // actionLogic.getType()); List<CaseBean> behaviorList = gson.fromJson(logic, actionLogic.getType()); for (int i = 0; i < behaviorList.size(); i++) { CaseBean caseBean = behaviorList.get(i); List<ActionBean> behavior = caseBean.getBehavior(); ConfigTest.CASE_LIST.add(behavior); } // Intent logicIntent = new Intent(context, LogicService.class); // context.startService(logicIntent); String parameter = split[1]; // ?split[1]?sdcard try { JSONArray jsonArray = new JSONArray(parameter); for (int i = 0; i < jsonArray.length(); i++) { IOUtil.writeStringToFile("[" + jsonArray.getString(i) + "]", "sdcard/testcase", "sdcard/testcase/parameter" + i + ".json", false); } } catch (JSONException e) { e.printStackTrace(); } String setUp = split[2]; // setUp.json ? // ConfigTest.SETUP_PATH = setUp.substring(13, setUp.length() - // "\"}]".length());// [{"logpath":"/sdcard/testcase/"}] // split[2]json? Gson setupGson = new Gson(); TypeToken<SetupBean> setupType = new TypeToken<SetupBean>() { }; SetupBean setupBean = setupGson.fromJson(split[2], setupType.getType()); // TelephonyManager tm = (TelephonyManager) context // .getSystemService(context.TELEPHONY_SERVICE); // ? // long time = Long.parseLong(setupBean.getTime()); // SimpleDateFormat sdf = new // SimpleDateFormat("yyyyMMddHHmmss"); // String sDateTime = sdf.format(time); // 08/31/2006 // ?? String setupJson = "[{\"logpath\":\"" + setupBean.getLogpath() + context.getSharedPreferences(ConfigSP.SP_reseach, Context.MODE_PRIVATE).getString( ConfigSP.SP_phone_id, "12345") + "_" + setupBean.getCasename() + "_" + setupBean.getTime() + "_file" + "\"," + "\"testcaseparafile\":\"" + setupBean.getLogpath() + "parameter.json\"}]"; // log?? ConfigTest.LOG_FILE_NAME = context.getSharedPreferences(ConfigSP.SP_reseach, Context.MODE_PRIVATE) .getString(ConfigSP.SP_phone_id, "12345") + "_" + setupBean.getCasename() + "_" + setupBean.getTime() + "_file"; Log.i("--info--time--", setupBean.getTime()); // action?? ConfigTest.ACTION_NAME = setupBean.getCasename(); // log ConfigTest.LOG_FILE_TIME = setupBean.getTime(); // ConfigTest.CLOCK = setupBean.getClock(); IOUtil.writeStringToFile(setupJson, "sdcard/testcase", "sdcard/testcase/setup.json", false); if (setupBean.getDoubleroute().equals("0")) {// wifi // ServiceManager serviceManager = new ServiceManager(context); // serviceManager.startService(); /** * ???ID?PN? */ // Intent intent = new Intent(context, BatteryService.class); // context.stopService(intent);// ??? // Intent intent1 = new Intent(context, SignalService.class); // context.stopService(intent1);// ??? // ?WifiManager mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // ?WifiInfo mWifiInfo = mWifiManager.getConnectionInfo(); // WiFi // if (mWifiManager.isWifiEnabled()) { // mWifiManager.setWifiEnabled(false); // } /** * PN? */ // NotificationService.getinstance().getXmppManager().setIsTesting(true); // ? Intent logicIntent = new Intent(context, LogicService.class); context.startService(logicIntent); } else {// ?? // ? Intent logicIntent = new Intent(context, LogicService.class); context.startService(logicIntent); } /* * //jar try { IOUtil.writeStreamToFile("sdcard/testcase", * contextParam.getResources().getAssets().open("testcase.jar"), new * File("sdcard/testcase/testcase.jar")); } catch (IOException e) { * e.printStackTrace(); } */ /* * String[] cmd = new String[] { "su", "uiautomator runtest " + * "/sdcard" + "/" + "testcase" + "/" + "testcase.jar" + * " -c com.testcase." + taskArr[i] }; CMDUtil.execShellCMD(cmd); */ /* * String[] cmd = new String[] { "su", * "uiautomator runtest /sdcard/testcase/UiAutomatorPrjDemo.jar -c com.WeiXinText" * }; try { CMDUtil.execShellCMD(cmd); } catch (IOException e) { * e.printStackTrace(); } catch (InterruptedException e) { * e.printStackTrace(); } */ /* * String[] taskArr = {"TelCaseUI", "SMSCaseUI", "WeiXinTextCase"}; try * { String[] cmd; for (int i = 0; i < taskArr.length; i++) { cmd = new * String[] { "su", "uiautomator runtest " + "/sdcard" + "/" + * "testcase" + "/" + "testcase.jar" + " -c com.testcase." + taskArr[i] * }; CMDUtil.execShellCMD(cmd); switch (i) { case 0: Thread * .sleep(Integer.parseInt(terminalConfigVO.getDialDuration())* * Integer.parseInt(terminalConfigVO.getDialRepeatTimes())*1000+ * 10*1000); break; case 1: Thread.sleep(20*1000); break; case 2: * * break; default: break; } // Thread.sleep(30*1000); } } catch * (IOException e) { e.printStackTrace(); } catch (InterruptedException * e) { e.printStackTrace(); } */ // // ?###{} // // // /// // String[] split = notificationMessage.split("###"); // Gson gson = new Gson(); // if ("\"?\"".equals(split[0])) { // // // TypeToken<ArrayList<ConfigMsgBean>> ruleToken = new // TypeToken<ArrayList<ConfigMsgBean>>(){}; // ArrayList<ConfigMsgBean> configList = gson.fromJson(split[1], // ruleToken.getType()); // SharedPreferences sp = // context.getSharedPreferences(ConfigPN.SP_SET, // Context.MODE_PRIVATE); // Editor editor = sp.edit(); // for (int i = 0; i < configList.size(); i++) { // ConfigMsgBean ConfigMsgBean = configList.get(i); // editor.putString(ConfigMsgBean.getStrEnKey(), // ConfigMsgBean.getStrParameter()); // } // editor.commit(); // return; // } // // // // // if ("".equals(split[0])) { // // // TypeToken<CalibrationBean> calibrationToken = new // TypeToken<CalibrationBean>(){}; // CalibrationBean calibrationBean = gson.fromJson(split[1], // calibrationToken.getType()); // Intent correctIntent = new Intent(contextParam, AcCorrect.class); // correctIntent.putExtra("strProject", // calibrationBean.getStrProject()); // correctIntent.putExtra("dateTime", // calibrationBean.getStrDateTime()); // correctIntent.putExtra("strBands", // calibrationBean.getStrBands()); // correctIntent.putExtra("signalWaitTime", // calibrationBean.getSignalWaitTime()+""); // correctIntent.putExtra("executeWaitTime", // calibrationBean.getExecuteWaitTime()+""); // correctIntent.putExtra("upWaitTime", // calibrationBean.getUpWaitTime()+""); // correctIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // contextParam.startActivity(correctIntent); // return; // } // // // // // TypeToken<List<RelationBean>> relationToken = new // TypeToken<List<RelationBean>>(){}; // List<RelationBean> relationJson = gson.fromJson(split[0], // relationToken.getType()); // IntentData.getInstance().setIntent_Testing_relationList(relationJson); // // // // TypeToken<Map<String, ArrayList<RuleBean>>> ruleToken = new // TypeToken<Map<String, ArrayList<RuleBean>>>(){}; // Map<String, ArrayList<RuleBean>> ruleJson = // gson.fromJson(split[1], ruleToken.getType()); // IntentData.getInstance().setIntent_Testing_ruleMap(ruleJson); // // //? // String dateTimeServer = split[2]; // SharedPreferences sp = // contextParam.getSharedPreferences(ConfigPN.SP_PN, // Context.MODE_PRIVATE); // Editor editor = sp.edit(); // editor.putString("dateTimeServer", dateTimeServer); // editor.commit(); // // //?/ // String taskType = split[3]; // // // // int testTimes = relationJson.get(0).getIntTestTimes(); // IntentData.getInstance().setIntent_Testing_times(testTimes); // // // // // //??||??? // String interactionAPID = // contextParam.getSharedPreferences(ConfigPN.SP_SET, // Context.MODE_PRIVATE).getString(ConfigPN.SP_SET_GLOBALAPID, ""); // String interactionAPPW = // contextParam.getSharedPreferences(ConfigPN.SP_SET, // Context.MODE_PRIVATE).getString(ConfigPN.SP_SET_GLOBALAPPW, ""); // if (interactionAPID.equals("") || interactionAPPW.equals("")) { // Toast.makeText(contextParam, "", // Toast.LENGTH_LONG).show(); // } else { // // // if (taskType.equals("normalTask")) { // Intent skipAcTestingIntent = new Intent(contextParam, // AcTesting.class); // skipAcTestingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // contextParam.startActivity(skipAcTestingIntent); // // // } else if (taskType.equals("terminalTask")) { // // SimpleDateFormat sdf = new // SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // Date date = new Date(Long.parseLong(dateTimeServer)); // // // AlarmManager am = (AlarmManager) // context.getSystemService(Context.ALARM_SERVICE); // Intent intent_broadcast = new Intent(context, // TimerReceiver.class); // PendingIntent pendingIntent = PendingIntent.getBroadcast(context, // 0, intent_broadcast, 0); // System.out.println(Long.parseLong(dateTimeServer)+ " - "+ // System.currentTimeMillis()); // am.set(AlarmManager.RTC_WAKEUP, Long.parseLong(dateTimeServer), // pendingIntent); //???? // } // } }
From source file:org.commonjava.badgr.web.rest.PermissionAdminResource.java
License:Apache License
@GET @Path("/list") @Produces({ MediaType.APPLICATION_JSON }) public Response getAll() { SecurityUtils.getSubject().isPermitted(Permission.name(Permission.NAMESPACE, Permission.ADMIN)); try {//w w w. jav a 2s . c om final Listing<Permission> listing = new Listing<Permission>(dataManager.getAllPermissions()); final TypeToken<Listing<Permission>> tt = new TypeToken<Listing<Permission>>() { }; return Response.ok().entity(jsonSerializer.toString(listing, tt.getType())).build(); } catch (final BadgrDataException e) { logger.error(e.getMessage(), e); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } }
From source file:org.commonjava.badgr.web.rest.RoleAdminResource.java
License:Apache License
@GET @Path("/list") @Produces({ MediaType.APPLICATION_JSON }) public Response getAll() { SecurityUtils.getSubject().isPermitted(Permission.name(Role.NAMESPACE, Permission.ADMIN)); try {/* w w w. j a va 2 s . c o m*/ final Listing<Role> listing = new Listing<Role>(dataManager.getAllRoles()); final TypeToken<Listing<Role>> tt = new TypeToken<Listing<Role>>() { }; return Response.ok().entity(jsonSerializer.toString(listing, tt.getType())).build(); } catch (final BadgrDataException e) { logger.error(e.getMessage(), e); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } }
From source file:org.commonjava.badgr.web.rest.UserAdminResource.java
License:Apache License
@GET @Path("/list") @Produces({ MediaType.APPLICATION_JSON }) public Response getAll() { SecurityUtils.getSubject().isPermitted(Permission.name(User.NAMESPACE, Permission.ADMIN)); try {// www. j a va 2 s .co m final Listing<User> listing = new Listing<User>(dataManager.getAllUsers()); final TypeToken<Listing<User>> tt = new TypeToken<Listing<User>>() { }; return Response.ok().entity(jsonSerializer.toString(listing, tt.getType())).build(); } catch (final BadgrDataException e) { logger.error(e.getMessage(), e); throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } }