Example usage for javax.json JsonObject getInt

List of usage examples for javax.json JsonObject getInt

Introduction

In this page you can find the example usage for javax.json JsonObject getInt.

Prototype

int getInt(String name, int defaultValue);

Source Link

Document

Returns the int value of the associated JsonNumber mapping for the specified name.

Usage

From source file:io.hakbot.util.JsonUtil.java

/**
 * Returns the value for the specified parameter name included in the specified json object. If json
 * object is null or specified name cannot be found, method returns the specified default value.
 *//*from   w  ww .j  a  va2s.  c om*/
public static int getInt(JsonObject json, String name, int defaultValue) {
    return (json != null && json.containsKey(name)) ? json.getInt(name, defaultValue) : defaultValue;
}

From source file:com.amazon.alexa.avs.config.DeviceConfigUtils.java

/**
 * Reads the {@link DeviceConfig} from disk. Pass in the name of the config file
 *
 * @return The configuration./*from  w  ww .  ja  va2  s  .  c  o m*/
 */
public static DeviceConfig readConfigFile(String filename) {
    FileInputStream file = null;
    try {
        deviceConfigName = filename.trim();
        file = new FileInputStream(deviceConfigName);
        JsonReader json = Json.createReader(file);
        JsonObject configObject = json.readObject();

        JsonObject companionServiceObject = configObject.getJsonObject(DeviceConfig.COMPANION_SERVICE);
        CompanionServiceInformation companionServiceInfo = null;
        if (companionServiceObject != null) {
            String serviceUrl = companionServiceObject
                    .getString(DeviceConfig.CompanionServiceInformation.SERVICE_URL, null);
            String sessionId = companionServiceObject
                    .getString(DeviceConfig.CompanionServiceInformation.SESSION_ID, null);
            String sslClientKeyStore = companionServiceObject
                    .getString(DeviceConfig.CompanionServiceInformation.SSL_CLIENT_KEYSTORE, null);
            String sslClientKeyStorePassphrase = companionServiceObject
                    .getString(DeviceConfig.CompanionServiceInformation.SSL_CLIENT_KEYSTORE_PASSPHRASE, null);
            String sslCaCert = companionServiceObject
                    .getString(DeviceConfig.CompanionServiceInformation.SSL_CA_CERT, null);

            companionServiceInfo = new CompanionServiceInformation(serviceUrl, sslClientKeyStore,
                    sslClientKeyStorePassphrase, sslCaCert);
            companionServiceInfo.setSessionId(sessionId);
        }

        JsonObject companionAppObject = configObject.getJsonObject(DeviceConfig.COMPANION_APP);
        CompanionAppInformation companionAppInfo = null;
        if (companionAppObject != null) {
            int localPort = companionAppObject.getInt(DeviceConfig.CompanionAppInformation.LOCAL_PORT, -1);
            String lwaUrl = companionAppObject.getString(DeviceConfig.CompanionAppInformation.LWA_URL, null);
            String clientId = companionAppObject.getString(DeviceConfig.CompanionAppInformation.CLIENT_ID,
                    null);
            String refreshToken = companionAppObject
                    .getString(DeviceConfig.CompanionAppInformation.REFRESH_TOKEN, null);
            String sslKeyStore = companionAppObject.getString(DeviceConfig.CompanionAppInformation.SSL_KEYSTORE,
                    null);
            String sslKeyStorePassphrase = companionAppObject
                    .getString(DeviceConfig.CompanionAppInformation.SSL_KEYSTORE_PASSPHRASE, null);

            companionAppInfo = new CompanionAppInformation(localPort, lwaUrl, sslKeyStore,
                    sslKeyStorePassphrase);
            companionAppInfo.setClientId(clientId);
            companionAppInfo.setRefreshToken(refreshToken);
        }

        String productId = configObject.getString(DeviceConfig.PRODUCT_ID, null);
        String dsn = configObject.getString(DeviceConfig.DSN, null);
        String provisioningMethod = configObject.getString(DeviceConfig.PROVISIONING_METHOD, null);
        String avsHost = configObject.getString(DeviceConfig.AVS_HOST, null);
        boolean wakeWordAgentEnabled = configObject.getBoolean(DeviceConfig.WAKE_WORD_AGENT_ENABLED, false);
        String locale = configObject.getString(DeviceConfig.LOCALE, null);

        DeviceConfig deviceConfig = new DeviceConfig(productId, dsn, provisioningMethod, wakeWordAgentEnabled,
                locale, companionAppInfo, companionServiceInfo, avsHost);

        return deviceConfig;
    } catch (FileNotFoundException e) {
        throw new RuntimeException("The required file " + deviceConfigName + " could not be opened.", e);
    } finally {
        IOUtils.closeQuietly(file);
    }
}

From source file:com.buffalokiwi.aerodrome.jet.orders.OrderItemRec.java

/**
 * Create an OrderItemRec from jet json 
 * @param json jet json//from  www.  jav  a2 s.  c  o  m
 * @return instance
 */
public static OrderItemRec fromJson(final JsonObject json) throws JetException {

    final Builder b = (new Builder()).setOrderItemId(json.getString("order_item_id", ""))
            .setAltOrderItemId(json.getString("alt_order_item_id", ""))
            .setMerchantSku(json.getString("merchant_sku", "")).setTitle(json.getString("product_title", ""))
            .setRequestOrderQty(json.getInt("request_order_quantity", 0))

            //..This appears to have been removed.  I don't know if jet still returns this value or not.
            .setRequestOrderCancelQty(json.getInt("request_order_cancel_qty", 0))

            .setAdjReason(json.getString("adjustment_reason", ""))
            .setTaxCode(json.getString("item_tax_code", "")).setUrl(json.getString("url", ""))
            .setPriceAdj(Utils.jsonNumberToMoney(json, "price_adjustment"))
            .setFees(Utils.jsonNumberToMoney(json, "item_fees")).setTaxInfo(json.getString("tax_info", "")) //..This might not work...
            .setRegFees(Utils.jsonNumberToMoney(json, "regulatory_fees"))
            .setAdjustments(jsonToFeeAdj(json.getJsonArray("fee_adjustments")))
            .setItemAckStatus(ItemAckStatus.fromText(json.getString("order_item_acknowledgement_status", "")));

    final JsonObject price = json.getJsonObject("item_price");
    if (price != null)
        b.setItemPrice(ItemPriceRec.fromJson(price));

    return b.build();
}

From source file:com.amazon.alexa.avs.auth.companionservice.CompanionServiceClient.java

/**
 * Request the companion service's information once the user has registered. Once the user has
 * registered and we've received the {@link CompanionAppProvisioningInfo} we can then exchange
 * that information for tokens.//from w w w  . j a  v  a2 s  . com
 *
 * @param sessionId
 * @return accessToken
 * @throws IOException
 *             If an I/O exception occurs.
 */
public OAuth2AccessToken getAccessToken(String sessionId) throws IOException {
    Map<String, String> queryParameters = new HashMap<String, String>();
    queryParameters.put(AuthConstants.SESSION_ID, sessionId);

    JsonObject response = callService("/provision/accessToken", queryParameters);

    String accessToken = response.getString(AuthConstants.OAuth2.ACCESS_TOKEN, null);
    int expiresIn = response.getInt(AuthConstants.OAuth2.EXPIRES_IN, -1);

    return new OAuth2AccessToken(accessToken, expiresIn);
}

From source file:wsserver.EKF1TimerSessionBean.java

private void callT3() {
    Runnable r3 = new Runnable() {

        public void run() {
            int badCnt3 = 0;
            int crcnt = 0;
            int allcnt = -1;
            boolean success_sql_operation = false;
            StringBuilder insert_sql_values_sb = new StringBuilder();
            int insert_sql_cnt = 0;
            try {

                String url = systemURL + "bitrix/ekflibraries/corpbus/get_json_data.php?ENTITY=1CPROD";

                //try {
                //    cbLogsFacade.insertLog("INFO", "Start load bx_1cprod", "Start load bx_1cprod, url="+systemURL);
                //} catch(Exception lge)  {

                //}

                URL obj = new URL(url);
                HttpURLConnection con = (HttpURLConnection) obj.openConnection();

                // optional default is GET
                con.setRequestMethod("GET");
                con.setConnectTimeout(180000);
                con.setReadTimeout(180000);

                //add request header
                con.setRequestProperty("User-Agent", "Mozilla-Firefox");

                int responseCode = con.getResponseCode();
                System.out.println("\nSending 'GET' request to URL : " + url);
                System.out.println("Response Code : " + responseCode);

                BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();

                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }/*from  ww  w  . ja v a2 s  .c  o  m*/
                in.close();

                try {
                    cbLogsFacade.insertLog("INFO", "Complete load bx_1cprod urldata",
                            "Complete load bx_1cprod urldata, url=" + systemURL);
                } catch (Exception lge) {

                }
                JsonReader jsonReader = Json.createReader(new StringReader(response.toString()));

                //int icnt = 0;//bx1CProdFacade.insertBx1ProdMultiply();

                //try {
                //    cbLogsFacade.insertLog("INFO", "Complete persist test bx_1cprod urldata ", "Complete persist test bx_1cprod urldata "+icnt);
                //} catch(Exception lge)  {
                //}

                bx1CProdFacade.clearBx1CProd();

                JsonArray jarray = jsonReader.readArray();

                boolean hasCrashes = false;
                String saveBxDataLog = "";
                for (int i = 0; i < jarray.size(); i++) {
                    JsonObject jobject = jarray.getJsonObject(i);
                    Bx1CProd b1cprodObj = new Bx1CProd();

                    b1cprodObj.setId(-1);
                    if (insert_sql_cnt > 0)
                        insert_sql_values_sb.append(" ,");
                    insert_sql_values_sb.append("( ");
                    try {
                        b1cprodObj.setBxId(Tools.parseInt(jobject.getString("ID", "-1"), -1));
                    } catch (Exception e) {
                        b1cprodObj.setBxId(-1);
                    }

                    try {
                        String f1cId = jobject.getString("1C_ID", "NULL");
                        if (f1cId.length() == 36)
                            b1cprodObj.setF1cId(f1cId);
                        else
                            b1cprodObj.setF1cId("NULL");
                    } catch (Exception e) {
                        b1cprodObj.setF1cId("NULL");
                    }
                    try {
                        b1cprodObj.setParentBxId(Tools.parseInt(jobject.getString("PARENT_ID", "-1"), -1));
                    } catch (Exception e) {
                        b1cprodObj.setParentBxId(-1);
                    }

                    try {
                        String parent1cId = jobject.getString("PARENT_1CID", "NULL");
                        if (parent1cId.length() == 36)
                            b1cprodObj.setParent1cId(parent1cId);
                        else
                            b1cprodObj.setParent1cId("NULL");
                    } catch (Exception e) {
                        b1cprodObj.setParent1cId("NULL");
                    }

                    try {
                        b1cprodObj.setName(StringEscapeUtils.unescapeHtml4(StringEscapeUtils
                                .unescapeJson(jobject.getString("NAME", "NULL")).replace("&quot;", "\"")));
                    } catch (Exception e) {
                        b1cprodObj.setName("NULL");
                    }

                    try {
                        b1cprodObj.setArtikul(StringEscapeUtils.unescapeHtml4(
                                StringEscapeUtils.unescapeJson(jobject.getString("ARTICUL", "NULL"))));
                    } catch (Exception e) {
                        b1cprodObj.setArtikul("NULL");
                    }

                    insert_sql_values_sb.append(b1cprodObj.getBxId());
                    insert_sql_values_sb.append(",'");
                    insert_sql_values_sb.append(b1cprodObj.getName().replace("'", "''"));
                    insert_sql_values_sb.append("',");
                    insert_sql_values_sb.append(b1cprodObj.getParentBxId());
                    insert_sql_values_sb.append(",'");
                    insert_sql_values_sb.append(b1cprodObj.getF1cId().replace("'", "''"));
                    insert_sql_values_sb.append("','");
                    insert_sql_values_sb.append(b1cprodObj.getParent1cId().replace("'", "''"));
                    insert_sql_values_sb.append("','");
                    insert_sql_values_sb.append(b1cprodObj.getArtikul().replace("'", "''"));

                    insert_sql_values_sb.append("',");

                    try {
                        b1cprodObj.setPrice(new BigDecimal(jobject.getString("PRICE", "0")));
                        insert_sql_values_sb.append(jobject.getString("PRICE", "0").replace(",", "."));
                    } catch (Exception e) {
                        b1cprodObj.setPrice(new BigDecimal(0));
                        insert_sql_values_sb.append("0");
                    }
                    insert_sql_values_sb.append(",");

                    try {
                        b1cprodObj.setAmount(new BigDecimal(jobject.getString("QUANTITY", "0")));
                        insert_sql_values_sb.append(jobject.getString("QUANTITY", "0").replace(",", "."));
                    } catch (Exception e) {
                        b1cprodObj.setAmount(new BigDecimal(0));
                        insert_sql_values_sb.append("0");
                    }
                    insert_sql_values_sb.append(",");

                    try {
                        b1cprodObj.setBprice(new BigDecimal(jobject.getString("BPRICE", "0")));
                        insert_sql_values_sb.append(jobject.getString("BPRICE", "0").replace(",", "."));
                    } catch (Exception e) {
                        b1cprodObj.setBprice(new BigDecimal(0));
                        insert_sql_values_sb.append("0");
                    }
                    insert_sql_values_sb.append(",");

                    try {
                        //b1cprodObj.setBprice(new BigDecimal(jobject.getString("SORT_ORDER", "0")));
                        insert_sql_values_sb.append(jobject.getString("SORT_ORDER", "0").replace(",", "."));
                    } catch (Exception e) {
                        //b1cprodObj.setBprice(new BigDecimal(0));
                        insert_sql_values_sb.append("0");
                    }
                    insert_sql_values_sb.append(",'");
                    try {
                        insert_sql_values_sb.append(StringEscapeUtils
                                .unescapeHtml4(
                                        StringEscapeUtils.unescapeJson(jobject.getString("MAIN_PICT", "")))
                                .replace("'", "''"));
                    } catch (Exception e) {
                    }

                    insert_sql_values_sb.append("',");

                    try {
                        //b1cprodObj.setBprice(new BigDecimal(jobject.getString("SORT_ORDER", "0")));
                        insert_sql_values_sb.append("" + jobject.getInt("PROP_CNT", 0));
                    } catch (Exception e) {
                        //b1cprodObj.setBprice(new BigDecimal(0));
                        insert_sql_values_sb.append("0");
                    }

                    insert_sql_values_sb.append(")");

                    int try_cnt = 0;
                    boolean notSucc = true;
                    String err = "";
                    while (try_cnt < 10 && notSucc) {
                        try {
                            //bx1CSectFacade.
                            //bx1CProdFacade.create(b1cprodObj);
                            crcnt++;
                            notSucc = false;
                        } catch (Exception e) {
                            notSucc = true;
                            badCnt3++;
                            try_cnt++;
                            err += "[[" + Tools.parseInt(jobject.getString("ID", "-1"), -1)
                                    + "]]<<==!!||||||!!==>>Error of bx1CProdFacade.create " + e;
                        }
                    }

                    try {
                        if (try_cnt > 0) {
                            cbLogsFacade.insertLog("ERROR", "Error of bx1CProdFacade", err);
                        }
                    } catch (Exception lge) {

                    }
                    hasCrashes = hasCrashes | notSucc;

                    insert_sql_cnt++;
                    if (insert_sql_cnt >= 500 || i >= (jarray.size() - 1)) {
                        try {
                            success_sql_operation = bx1CProdFacade
                                    .insertBx1ProdMultiply(insert_sql_values_sb.toString(), insert_sql_cnt);
                        } catch (Exception lgesq) {
                            success_sql_operation = false;
                            try {
                                cbLogsFacade.insertLog("INFO",
                                        "!!!Unsuccess sending complex sql instruct to bx_1cprod",
                                        "Err " + lgesq);
                            } catch (Exception lge) {

                            }
                        }

                        if (!success_sql_operation) {
                            try {
                                cbLogsFacade.insertLog("INFO", "!!!Unsuccess complex sql instruct to bx_1cprod",
                                        "Count record to bx_1cprods " + insert_sql_cnt);
                            } catch (Exception lge) {

                            }
                            break;
                        } else {
                            saveBxDataLog += ("Succ " + insert_sql_cnt);//complex sql instruct to bx_1cprod. "+
                            //        "Count record to bx_1cprods "+insert_sql_cnt);
                            //try {
                            //    cbLogsFacade.insertLog("INFO", "Success complex sql instruct to bx_1cprod", "Count record to bx_1cprods "+insert_sql_cnt);
                            //} catch(Exception lge)  {

                            //}
                        }
                        insert_sql_cnt = 0;
                        insert_sql_values_sb.setLength(0);
                    }
                }

                try {
                    allcnt = jarray.size();
                    cbLogsFacade.insertLog("INFO", "Complete load bx_1cprod",
                            saveBxDataLog + " Complete load bx_1cprods " + ", all=" + allcnt + ",succ=" + crcnt
                                    + ",errcnt=" + badCnt3);
                } catch (Exception lge) {

                }

                if (badCnt3 <= 20 && (allcnt == crcnt) && success_sql_operation) {
                    //sendCompareData();
                    //sendCompareSectDataDel();
                    //sendCompareSectDataUpd();
                    boolean repeat_load = true;
                    int repeat_counter = 0;
                    while (repeat_load && repeat_counter < 10) {
                        repeat_counter++;
                        String selectExchngDataLog = "";
                        try {

                            if (tablesOperatingStateFacade.getEkfGrExchDataCorrupt() && false) {
                                Thread.sleep(30000);
                                try {
                                    cbLogsFacade.insertLog("INFO", "getEkfGrExchDataCorrupt",
                                            "Wait on 30 sec, attempt " + repeat_counter + " of 10...");
                                } catch (Exception lgex) {

                                }
                            } else {
                                repeat_load = false;
                                int ekfProdCount = cbLogsFacade.ekfProdCount();
                                int ekfProdSectCount = cbLogsFacade.ekfProdSectCount();
                                if (ekfProdCount >= 1000 && ekfProdCount <= 100000 && ekfProdSectCount >= 200
                                        && ekfProdSectCount <= 10000) {
                                    if (tablesOperatingStateFacade.setEkfGrExchDataCorrupt()) {

                                        //try {
                                        //    cbLogsFacade.insertLog("INFO", "Start of request cbNewPrFrom1cWpropsFacade", "Start of request cbNewPrFrom1cWpropsFacade");
                                        //} catch(Exception lge)  { }
                                        selectExchngDataLog += "Start of request cbNewPrFrom1cWpropsFacade ";
                                        npwps_ = cbNewPrFrom1cWpropsFacade.findAll();

                                        //try {
                                        //    cbLogsFacade.insertLog("INFO", "Start of request cbEkfgroupDel1csectFromBxFacade", "Complete prev, Start of request cbEkfgroupDel1csectFromBxFacade");
                                        //} catch(Exception lge)  { }
                                        selectExchngDataLog += "Complete prev, Start of request cbEkfgroupDel1csectFromBxFacade ";
                                        dswps_ = cbEkfgroupDel1csectFromBxFacade.findAll();

                                        //try {
                                        //    cbLogsFacade.insertLog("INFO", "Start of request cbEkfgroupUpd1csectToBxFacade", "Complete prev, Start of request cbEkfgroupUpd1csectToBxFacade");
                                        //} catch(Exception lge)  { }
                                        selectExchngDataLog += "Complete prev, Start of request cbEkfgroupUpd1csectToBxFacade ";
                                        uswps_ = cbEkfgroupUpd1csectToBxFacade.findAll();

                                        //try {
                                        //    cbLogsFacade.insertLog("INFO", "Start of request cbEkfgroupAdd1csectToBxFacade", "Complete prev, Start of request cbEkfgroupAdd1csectToBxFacade");
                                        //} catch(Exception lge)  { }
                                        selectExchngDataLog += "Complete prev, Start of request cbEkfgroupAdd1csectToBxFacade ";
                                        nswps_ = cbEkfgroupAdd1csectToBxFacade.findAll();

                                        //try {
                                        //    cbLogsFacade.insertLog("INFO", "Start of request cbEkfroupDelFromBxViewFacade", "Complete prev, Start of request cbEkfroupDelFromBxViewFacade");
                                        //} catch(Exception lge)  { }
                                        selectExchngDataLog += "Complete prev, Start of request cbEkfroupDelFromBxViewFacade ";
                                        dpwps_ = cbEkfroupDelFromBxViewFacade.findAll();

                                        //try {
                                        //    cbLogsFacade.insertLog("INFO", "Start of request CbEkfgroupToUpdatedBx1cFacade", "Complete prev, Start of request CbEkfgroupToUpdatedBx1cFacade");
                                        //} catch(Exception lge)  { }
                                        selectExchngDataLog += "Complete prev, Start of request CbEkfgroupToUpdatedBx1cFacade ";
                                        upwps_ = cbEkfgroupToUpdatedBx1cFacade.findAll();
                                        try {
                                            cbLogsFacade.insertLog("INFO",
                                                    "End of request CbEkfgroupToUpdatedBx1cFacade",
                                                    selectExchngDataLog
                                                            + " End of request CbEkfgroupToUpdatedBx1cFacade");
                                        } catch (Exception lge) {
                                        }

                                        if (npwps_.size() == 0 && upwps_.size() == 0 && dpwps_.size() == 0) {
                                            if (cbSettingsFacade.updExchanheLastDt()) {
                                                //try {
                                                //    cbLogsFacade.insertLog("INFO", "Success update exchange last datetime", 
                                                //            "Success update exchange last datetime");
                                                //} catch(Exception lge)  {

                                                //}
                                            } else {
                                                try {
                                                    cbLogsFacade.insertLog("ERROR",
                                                            "Unsuccess update exchange last datetime",
                                                            "Unsuccess update exchange last datetime");
                                                } catch (Exception lge) {

                                                }
                                            }
                                        }

                                        if (tablesOperatingStateFacade.setEkfGrExchDataUnCorrupt()) {
                                            sendCompareSectDataAdd();
                                        } else {
                                            exchangeInProcess = false;
                                            try {
                                                cbLogsFacade.insertLog("ERROR",
                                                        "Unsuccess setEkfGrExchDataCorrupt 0",
                                                        "Unsuccess setEkfGrExchDataCorrupt 0");
                                            } catch (Exception lgex) {

                                            }

                                        }

                                    } else {
                                        exchangeInProcess = false;
                                        try {
                                            cbLogsFacade.insertLog("ERROR",
                                                    "Unsuccess setEkfGrExchDataCorrupt 1",
                                                    "Unsuccess setEkfGrExchDataCorrupt 1");
                                        } catch (Exception lgex) {

                                        }
                                    }
                                } else {
                                    exchangeInProcess = false;
                                    try {
                                        cbLogsFacade.insertLog("ERROR", "Invalid data sizes, exchange stopped",
                                                "Data sizes mismatch conditions 200<=ekfProdSectCount<=10000, "
                                                        + "1000<=ekfProdCount<=100000");
                                    } catch (Exception lgex) {

                                    }
                                }
                            }
                        } catch (Exception lge) {
                            exchangeInProcess = false;
                            repeat_load = false;
                            try {
                                cbLogsFacade.insertLog("ERROR",
                                        "Error of getEkfGrExchDataCorrupt or setEkfGrExchDataCorrupt or MDS data load",
                                        "Error of getEkfGrExchDataCorrupt, detail: " + selectExchngDataLog);
                            } catch (Exception lgex) {

                            }
                        }
                    }

                    if (repeat_load) {
                        hasLong1CWait = true;
                        exchangeInProcess = false;
                    }

                } else
                    exchangeInProcess = false;

            } catch (Exception e) {
                exchangeInProcess = false;
                System.out.println("<<==!!||||||!!==>>Error of get-parse bx_1cprod json " + e);
                try {
                    cbLogsFacade.insertLog("ERROR", "Error of get-parse json bx_1cprod",
                            "<<==!!||||||!!==>>Error of get-parse json " + e);
                } catch (Exception lge) {

                }
            } finally {
                try {
                    //tablesOperatingStateFacade.setEkfGrExchDataUnDelta();
                    if (tablesOperatingStateFacade.setEkfGrExchDataUnCorrupt()) {

                    } else {
                        try {
                            cbLogsFacade.insertLog("ERROR", "Unsuccess setEkfGrExchDataCorrupt 0",
                                    "Unsuccess setEkfGrExchDataCorrupt 0");
                        } catch (Exception lgex) {

                        }
                    }
                } catch (Exception lgex) {

                }
            }
        }

    };

    Thread t3 = new Thread(r3);
    t3.start();
}