Example usage for com.google.gson JsonObject get

List of usage examples for com.google.gson JsonObject get

Introduction

In this page you can find the example usage for com.google.gson JsonObject get.

Prototype

public JsonElement get(String memberName) 

Source Link

Document

Returns the member with the specified name.

Usage

From source file:com.baidu.rigel.biplatform.ac.model.callback.CallbackServiceInvoker.java

License:Open Source License

/**
 * callback?CallbackResponse404?cache??//w  w  w  .j a va  2s .  c  o  m
 * @param responseStr
 * @param type
 * @return CallbackResponse
 */
private static CallbackResponse convertStrToResponse(String responseStr, CallbackType type) {
    LOG.info("[INFO] --- --- message received from callback server  is {}", responseStr);
    CallbackResponse rs = new CallbackResponse();
    long begin = System.currentTimeMillis();
    if (StringUtils.isEmpty(responseStr)) {
        throw new RuntimeException("???");
    }
    JsonObject json = new JsonParser().parse(responseStr).getAsJsonObject();
    int status = json.get("status").getAsInt();
    String message = json.get("message") == null || json.get("message") == JsonNull.INSTANCE ? "unknown"
            : json.get("message").getAsString();
    String provider = json.get("provider") == null || json.get("provider") == JsonNull.INSTANCE ? "unknown"
            : json.get("provider").getAsString();
    String cost = json.get("cost") == null || json.get("cost") == JsonNull.INSTANCE ? ""
            : json.get("cost").getAsString();
    String version = json.get("version") == null || json.get("version") == JsonNull.INSTANCE ? "unknown"
            : json.get("version").getAsString();
    LOG.info("[INFO] ------------------------------callback response desc -----------------------------------");
    LOG.info("[INFO] --- --- status : {}", status);
    LOG.info("[INFO] --- --- message : {}", message);
    LOG.info("[INFO] --- --- provider : {}", provider);
    LOG.info("[INFO] --- --- cost : {}", cost);
    LOG.info("[INFO] --- --- callback version : {}", version);
    LOG.info("[INFO] -----------------------------end print response desc -----------------------------------");
    LOG.info("[INFO] --- --- package result to CallbackResponse cost {} ms",
            (System.currentTimeMillis() - begin));
    rs.setCost(Integer.valueOf(StringUtils.isEmpty(cost) ? "0" : cost));
    rs.setStatus(getStatus(status));
    rs.setProvider(provider);
    rs.setVersion(version);
    rs.setMessage(getNlsMessage(status));
    if (ResponseStatus.SUCCESS.getValue() == status) {
        rs.setData(getCallbackValue(json.get("data").toString(), type));
    }
    return rs;
}

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.DimensionDeserialize.java

License:Open Source License

@Override
public Dimension deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Dimension dimension = null;/*from  w w  w  . j  a  va  2 s.  c om*/
    if (json.isJsonObject()) {
        JsonObject dimensionObject = json.getAsJsonObject();

        if (dimensionObject.get("type") != null) {
            DimensionType dimensionType = DimensionType.valueOf(dimensionObject.get("type").getAsString());
            if (dimensionType.equals(DimensionType.TIME_DIMENSION)) {
                dimension = context.deserialize(json, TimeDimension.class);
            } else {
                dimension = context.deserialize(json, StandardDimension.class);
            }
            if (dimension != null && MapUtils.isNotEmpty(dimension.getLevels())) {
                for (Level level : dimension.getLevels().values()) {
                    level.setDimension(dimension);
                }
            }
        }
    }
    return dimension;
}

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.LevelDeserialize.java

License:Open Source License

@Override
public Level deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject()) {
        JsonObject levelJsonObj = json.getAsJsonObject();

        if (levelJsonObj.get("type") != null) {
            LevelType levelType = LevelType.valueOf(levelJsonObj.get("type").getAsString());
            if (levelType.equals(LevelType.CALL_BACK)) {
                return context.deserialize(levelJsonObj, CallbackLevel.class);
            } else if (levelType.name().equals(LevelType.USER_CUSTOM)) {
                return context.deserialize(levelJsonObj, UserCustomLevel.class);
            } else {
                return context.deserialize(levelJsonObj, MiniCubeLevel.class);
            }/*from w  ww  . j a va  2  s  . c  om*/

        }
    }

    return null;
}

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.MeasureDeserialize.java

License:Open Source License

@Override
public Measure deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject()) {
        JsonObject jsObj = json.getAsJsonObject();

        String agg = jsObj.get("aggregator").getAsString();
        if (agg.equals(Aggregator.CALCULATED.name())) {
            String type = jsObj.get("type").getAsString();
            if (type.equals(MeasureType.CALLBACK.name())) {
                return context.deserialize(jsObj, CallbackMeasure.class);
            }//  w  w w . j  av  a 2 s.  c  o  m
            return context.deserialize(jsObj, ExtendMinicubeMeasure.class);
        }
        return context.deserialize(jsObj, MiniCubeMeasure.class);
    }
    return null;
}

From source file:com.baidu.rigel.biplatform.ac.util.deserialize.MetaConditionDeserialize.java

License:Open Source License

@Override
public MetaCondition deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    if (json.isJsonObject()) {
        JsonObject conditionObj = json.getAsJsonObject();

        MetaType metaType = context.deserialize(conditionObj.get("metaType"), MetaType.class);
        if (metaType.equals(MetaType.Dimension)) {
            return context.deserialize(json, DimensionCondition.class);
        } else {//w w  w.  j  a  va 2s  . co  m
            return context.deserialize(json, MeasureCondition.class);
        }
    }
    return null;
}

From source file:com.balajeetm.mystique.core.AbstractMystTurn.java

License:Open Source License

public JsonElement transform(List<JsonElement> source, JsonObject deps, JsonObject aces, JsonObject turn,
        JsonObject resultWrapper) {/*from   ww w . ja va 2s  . co  m*/

    Boolean turnExists = mystiqueLever.isNotNull(turn);
    JsonObject updatedAces = new JsonObject();
    if (turnExists) {
        JsonObject localAces = mystiqueLever.asJsonObject(turn.get(MystiqueConstants.ACES), (JsonObject) null);
        if (mystiqueLever.isNotNull(localAces)) {
            // Aces will only work on first source
            JsonElement first = mystiqueLever.getFirst(source);
            updatedAces = mystiqueLever.getUpdatedAces(first, localAces, deps, updatedAces);
        }
    }

    mystiqueLever.simpleMerge(updatedAces, mystiqueLever.asJsonObject(aces, new JsonObject()));

    JsonElement transform = JsonNull.INSTANCE;
    try {
        transform = transmute(source, deps, updatedAces, turn);
    } catch (RuntimeException e) {
        // Any error during transmute, log error
        String msg = String.format("Error transforming input with specification for turn %s - %s", turn,
                e.getMessage());
        logger.info(msg, e);
    }

    if (turnExists) {
        if (mystiqueLever.isNull(transform)) {
            JsonObject defaultJson = mystiqueLever.asJsonObject(turn.get(MystiqueConstants.DEFAULT));
            transform = transformToDefault(defaultJson, source, deps, updatedAces);
        }

        // set the result
        JsonArray to = mystiqueLever.getJpath(turn.get(MystiqueConstants.TO));
        Boolean optional = mystiqueLever.asBoolean(turn.get(MystiqueConstants.OPTIONAL), Boolean.FALSE);

        mystiqueLever.set(resultWrapper, to, transform, updatedAces, optional);
    }

    return transform;
}

From source file:com.balajeetm.mystique.core.AbstractMystTurn.java

License:Open Source License

/**
 * Transform on condition.// w  w  w.  j a  v a  2 s  .c  o  m
 *
 * @param conditionalJson the conditional json
 * @param source the source
 * @param deps the deps
 * @param aces the aces
 * @param resultWrapper the result wrapper
 * @return the json element
 */
protected JsonElement transformToDefault(JsonObject conditionalJson, List<JsonElement> source, JsonObject deps,
        JsonObject aces, JsonObject resultWrapper) {
    JsonElement transform = JsonNull.INSTANCE;
    if (mystiqueLever.isNotNull(conditionalJson)) {
        // Should not be null, can be json null
        JsonElement value = conditionalJson.get(MystiqueConstants.VALUE);
        if (null != value) {
            transform = value;
        } else {
            JsonObject defaultTurn = mystiqueLever.asJsonObject(conditionalJson.get(MystiqueConstants.TURN));
            if (mystiqueLever.isNotNull(defaultTurn)) {
                MystTurn mystique = factory.getMystTurn(defaultTurn);
                transform = mystique.transform(source, deps, aces, defaultTurn, resultWrapper);
            }
        }
    }
    return transform;
}

From source file:com.balajeetm.mystique.core.AbstractMystTurn.java

License:Open Source License

/**
 * Gets the granular source.//from   www  .j  a  va 2 s.co  m
 *
 * @param source the source
 * @param turn the turn
 * @param deps the deps
 * @param aces the aces
 * @return the granular source
 */
protected JsonElement getGranularSource(JsonElement source, JsonObject turn, JsonObject deps, JsonObject aces) {
    JsonArray from = mystiqueLever.isNotNull(turn) ? mystiqueLever.getJpath(turn.get(MystiqueConstants.FROM))
            : null;
    JsonElement conditionSource = mystiqueLever.isNull(from) ? source
            : mystiqueLever.getField(source, from, deps, aces);
    return conditionSource;
}

From source file:com.balajeetm.mystique.core.ArrayToMapMystTurn.java

License:Open Source License

@Override
protected JsonElement transmute(List<JsonElement> source, JsonObject deps, JsonObject aces, JsonObject turn) {
    JsonObject mapJson = new JsonObject();
    JsonElement elementSource = mystiqueLever.getFirst(source);

    if (null != elementSource) {
        turn = mystiqueLever.asJsonObject(turn, new JsonObject());
        JsonElement granularSource = getGranularSource(elementSource, turn, deps, aces);
        JsonArray inputArray = mystiqueLever.asJsonArray(granularSource, new JsonArray());
        JsonArray keyArray = mystiqueLever.getJpath(turn.get(MystiqueConstants.KEY));
        if (mystiqueLever.isNotNull(keyArray)) {
            JsonElement valueElement = turn.get(MystiqueConstants.VALUE);
            valueElement = mystiqueLever.isNull(valueElement) ? new JsonArray() : valueElement;

            for (JsonElement jsonElement : inputArray) {
                JsonElement keyField = mystiqueLever.getField(jsonElement, keyArray, deps, aces);
                String key = mystiqueLever.asString(keyField, MystiqueConstants.EMPTY);

                JsonElement finalValue = mystiqueLever.subset(jsonElement, deps, aces, valueElement);
                mapJson.add(key, finalValue);
            }// w  w  w . j av a2  s  .  c  o  m
        }
    }

    return mapJson;
}

From source file:com.balajeetm.mystique.core.ChainMystTurn.java

License:Open Source License

@Override
public JsonElement transform(List<JsonElement> source, JsonObject deps, JsonObject aces, JsonObject turn,
        JsonObject resultWrapper) {//from  w w  w.  j  av a2  s. c o m

    JsonElement transform = JsonNull.INSTANCE;
    turn = jsonLever.asJsonObject(turn, new JsonObject());
    JsonArray turnArray = jsonLever.asJsonArray(turn.get(MystiqueConstants.TURNS), new JsonArray());

    for (JsonElement turnObject : turnArray) {
        if (jsonLever.isObject(turnObject)) {
            JsonObject asJsonObject = turnObject.getAsJsonObject();
            MystTurn mystique = factory.getMystTurn(asJsonObject);
            if (null != mystique) {
                mystique.transform(source, deps, aces, asJsonObject, resultWrapper);
            }
        }
    }
    return transform;
}