Example usage for javax.json JsonObject getString

List of usage examples for javax.json JsonObject getString

Introduction

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

Prototype

String getString(String name, String defaultValue);

Source Link

Document

Returns the string value of the associated JsonString mapping for the specified name.

Usage

From source file:com.oncore.calorders.rest.service.extension.OrderHistoryFacadeRESTExtension.java

/**
 * Creates an order, containing the ordered products and related services.
 *
 * @param orderjson The order, represented as a JSON string
 * @throws DataAccessException//from ww  w.  ja v  a  2  s .  c  om
 */
@POST
@Path("createOrder")
@Consumes({ MediaType.APPLICATION_JSON })
public void createOrder(String orderjson) throws DataAccessException {

    try {
        JsonReader reader = Json.createReader(new StringReader(orderjson));
        JsonObject orderObject = reader.readObject();
        reader.close();

        OrderHistory order = new OrderHistory();

        order.setUpdateTs(new Date());
        order.setUpdateUserId(orderObject.getString("updateUserId", null));
        order.setCreateTs(new Date());
        order.setCreateUserId(orderObject.getString("createUserId", null));

        OrdStatusCd ordStatusCd = this.ordStatusCdFacadeREST.find(orderObject.getString("orderStatusCd", null));

        if (ordStatusCd == null) {
            throw new DataAccessException(ErrorCode.DATAACCESSERROR.toString());
        } else {
            order.setOrdStatusCd(ordStatusCd);
        }

        Party party = this.partyFacadeRESTExtension.find(Integer.valueOf(orderObject.getString("partyUid")));

        if (party == null) {
            throw new DataAccessException(ErrorCode.DATAACCESSERROR.toString());
        } else {
            order.setPtyUidFk(party);

            order.setDepUidFk(
                    party.getGroupPartyAssocCollection().iterator().next().getGrpUidFk().getDepUidFk());
        }

        order.setOrderProductAssocCollection(new ArrayList<OrderProductAssoc>());

        JsonArray productList = orderObject.getJsonArray("products");

        for (int i = 0; i < productList.size(); i++) {
            JsonObject productObject = productList.getJsonObject(i);
            OrderProductAssoc orderProductAssoc = new OrderProductAssoc();

            Product product = this.productFacadeRESTExtension.find(productObject.getInt("prdUid"));

            orderProductAssoc.setPrdUidFk(product);
            orderProductAssoc.setOrdUidFk(order);
            orderProductAssoc.setUpdateTs(new Date());
            orderProductAssoc.setUpdateUserId(productObject.getString("updateUserId", null));
            orderProductAssoc.setCreateTs(new Date());
            orderProductAssoc.setCreateUserId(productObject.getString("createUserId", null));
            orderProductAssoc.setOpaQuantity(productObject.getInt("quantity"));
            orderProductAssoc.setOpaPrice(product.getPrdCntrUnitPrice()
                    .multiply(BigDecimal.valueOf(productObject.getInt("quantity"))));

            order.getOrderProductAssocCollection().add(orderProductAssoc);
        }

        super.create(order);
    } catch (Exception ex) {
        Logger.error(LOG, FormatHelper.getStackTrace(ex));
        throw new DataAccessException(ex, ErrorCode.DATAACCESSERROR);
    }

}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public String jsonId(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return "";
    }//from  ww  w.jav a  2  s  .  c  o m
    return object.getString(JSONRPC_ID, "");
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcCoinbase jsonCoinbase(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }/*from w w  w. j  a va  2 s  .c  o m*/
    BtcCoinbase coin = new BtcCoinbase();
    Map<String, String> auxiliary = new HashMap<String, String>();
    JsonValue aux = object.get(BTCOBJ_COIN_AUX);
    if ((aux != null) && (aux.getValueType() == JsonValue.ValueType.OBJECT) && (aux instanceof JsonObject)) {
        JsonObject auxObject = (JsonObject) aux;
        for (String key : auxObject.keySet()) {
            auxiliary.put(key, auxObject.getString(key, ""));
        }
    }
    coin.setAux(auxiliary);
    coin.setValue(jsonDouble(object, BTCOBJ_COIN_VALUE));
    return coin;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcNode jsonNode(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }// w  w w. j  av a2  s  . co  m
    BtcNode node = new BtcNode();
    node.setAddress(object.getString(BTCOBJ_NODE_ADDRESS, ""));
    node.setConnected(object.getString(BTCOBJ_NODE_CONNECTED, ""));
    return node;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcWork jsonWork(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }//from www. j  a  v  a2s  .  co m
    BtcWork work = new BtcWork();
    work.setMidState(object.getString(BTCOBJ_WORK_MIDSTATE, ""));
    work.setData(object.getString(BTCOBJ_WORK_DATA, ""));
    work.setHash(object.getString(BTCOBJ_WORK_HASH, ""));
    work.setTarget(object.getString(BTCOBJ_WORK_TARGET, ""));
    return work;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcOutputPart jsonOutputPart(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }//w  w w .j  ava 2s.c  o  m
    BtcOutput output = new BtcOutput();
    output.setTransaction(object.getString(BTCOBJ_TX_OUTPUT_TRANSACTION, ""));
    output.setOutput(jsonLong(object, BTCOBJ_TX_OUTPUT_OUTPUT));
    return output;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcAccount jsonAccount(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }/*  ww w.  j a  va 2  s . c om*/
    BtcAccount account = new BtcAccount();
    account.setAccount(object.getString(BTCOBJ_ACCOUNT_ACCOUNT, ""));
    account.setAmount(jsonDouble(object, BTCOBJ_ACCOUNT_AMOUNT));
    account.setConfirmations(jsonLong(object, BTCOBJ_ACCOUNT_CONFIRMATIONS));
    return account;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcInput jsonInput(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }//from   w w  w  .j  a v  a  2s.  c o m
    BtcInput input = new BtcInput();
    input.setTransaction(object.getString(BTCOBJ_TX_INPUT_TRANSACTION, ""));
    input.setOutput(jsonLong(object, BTCOBJ_TX_INPUT_OUTPUT));
    JsonValue script = object.get(BTCOBJ_TX_INPUT_SCRIPT_SIGNATURE);
    if ((script != null) && (script.getValueType() == JsonValue.ValueType.OBJECT)
            && (script instanceof JsonObject)) {
        input.setScript(jsonScript(script));
    }
    input.setSequence(jsonLong(object, BTCOBJ_TX_INPUT_SEQUENCE));
    return input;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcScript jsonScript(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }/*w w  w.  j a v a  2 s  . co  m*/
    BtcScript script = new BtcScript();
    script.setAsm(object.getString(BTCOBJ_SCRIPT_ASM, ""));
    script.setPublicKey(object.getString(BTCOBJ_SCRIPT_PUBLIC_KEY, ""));
    script.setRequiredSignatures(jsonLong(object, BTCOBJ_SCRIPT_REQUIRED_SIGNATURES));
    script.setType(BtcScript.Type.getValue(object.getString(BTCOBJ_SCRIPT_TYPE, "")));
    List<String> addresses = new ArrayList<String>();
    JsonValue addrs = object.get(BTCOBJ_SCRIPT_ADDRESSES);
    if ((addrs) != null && (addrs.getValueType() == JsonValue.ValueType.ARRAY)
            && (addrs instanceof JsonArray)) {
        JsonArray addrsArray = (JsonArray) addrs;
        for (JsonValue addr : addrsArray.getValuesAs(JsonValue.class)) {
            addresses.add(jsonString(addr));
        }
    }
    script.setAddresses(addresses);
    return script;
}

From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java

public BtcPeer jsonPeer(JsonValue value) throws BtcException {
    JsonObject object = jsonObject(value);
    if (object == null) {
        return null;
    }// w  ww.  j a  v  a  2  s  .c om
    BtcPeer peer = new BtcPeer();
    peer.setNetworkAddress(object.getString(BTCOBJ_PEER_ADDRESS, ""));
    peer.setServices(object.getString(BTCOBJ_PEER_SERVICES, ""));
    peer.setLastSend(jsonLong(object, BTCOBJ_PEER_LAST_SEND));
    peer.setLastReceived(jsonLong(object, BTCOBJ_PEER_LAST_RECEIVED));
    peer.setBytesSent(jsonLong(object, BTCOBJ_PEER_BYTES_SENT));
    peer.setBytesReceived(jsonLong(object, BTCOBJ_PEER_BYTES_RECEIVED));
    peer.setConnectionTime(jsonLong(object, BTCOBJ_PEER_CONNECTION_TIME));
    peer.setVersion(jsonLong(object, BTCOBJ_PEER_VERSION));
    peer.setSubVersion(object.getString(BTCOBJ_PEER_SUBVERSION, ""));
    peer.setInbound(object.getBoolean(BTCOBJ_PEER_INBOUND, false));
    peer.setStartingHeight(jsonLong(object, BTCOBJ_PEER_START_HEIGHT));
    peer.setBanScore(jsonLong(object, BTCOBJ_PEER_BAN_SCORE));
    peer.setSyncNode(object.getBoolean(BTCOBJ_PEER_SYNC_NODE, false));
    return peer;
}