Example usage for com.google.gson JsonObject getAsJsonPrimitive

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

Introduction

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

Prototype

public JsonPrimitive getAsJsonPrimitive(String memberName) 

Source Link

Document

Convenience method to get the specified member as a JsonPrimitive element.

Usage

From source file:org.apache.airavata.workflow.model.graph.impl.EdgeImpl.java

License:Apache License

protected void parse(JsonObject edgeObject) {
    this.fromPortID = edgeObject.getAsJsonPrimitive(GraphSchema.EDGE_FROM_PORT_TAG).getAsString();
    this.toPortID = edgeObject.getAsJsonPrimitive(GraphSchema.EDGE_TO_PORT_TAG).getAsString();
}

From source file:org.apache.airavata.workflow.model.graph.impl.GraphImpl.java

License:Apache License

protected void parse(JsonObject graphObject) throws GraphException {
    JsonPrimitive jsonPrimitive = graphObject.getAsJsonPrimitive(GraphSchema.GRAPH_ID_TAG);
    if (jsonPrimitive != null) {
        this.id = jsonPrimitive.getAsString();
    }// w w w.ja  v a 2  s.com
    jsonPrimitive = graphObject.getAsJsonPrimitive(GraphSchema.GRAPH_NAME_TAG);
    if (jsonPrimitive != null) {
        this.name = jsonPrimitive.getAsString();
    }
    jsonPrimitive = graphObject.getAsJsonPrimitive(GraphSchema.GRAPH_DESCRIPTION_TAG);
    if (jsonPrimitive != null) {
        this.description = jsonPrimitive.getAsString();
    }

    JsonArray jArray = graphObject.getAsJsonArray(GraphSchema.NODE_TAG);
    for (JsonElement jsonElement : jArray) {
        addNode(this.factory.createNode((JsonObject) jsonElement));
    }

    jArray = graphObject.getAsJsonArray(GraphSchema.PORT_TAG);
    for (JsonElement jsonElement : jArray) {
        addPort(this.factory.createPort((JsonObject) jsonElement));
    }

    jArray = graphObject.getAsJsonArray(GraphSchema.EDGE_TAG);
    for (JsonElement jsonElement : jArray) {
        addEdge(this.factory.createEdge((JsonObject) jsonElement));
    }

    indexToPointer();
}

From source file:org.apache.airavata.workflow.model.graph.impl.NodeImpl.java

License:Apache License

protected void parse(JsonObject nodeObject) {
    this.id = nodeObject.getAsJsonPrimitive(GraphSchema.NODE_ID_TAG).getAsString();
    this.name = nodeObject.getAsJsonPrimitive(GraphSchema.NODE_NAME_TAG).getAsString();

    JsonArray jArray;/*from w ww .ja  va2  s  .co  m*/
    if (nodeObject.get(GraphSchema.NODE_INPUT_PORT_TAG) != null) {
        jArray = nodeObject.getAsJsonArray(GraphSchema.NODE_INPUT_PORT_TAG);
        for (JsonElement jsonElement : jArray) {
            this.inputPortIDs.add(jsonElement.getAsString());
        }

    }

    if (nodeObject.get(GraphSchema.NODE_OUTPUT_PORT_TAG) != null) {
        jArray = nodeObject.getAsJsonArray(GraphSchema.NODE_OUTPUT_PORT_TAG);
        for (JsonElement jsonElement : jArray) {
            this.outputPortIDs.add(jsonElement.getAsString());
        }

    }

    JsonElement jElement = nodeObject.get(GraphSchema.NODE_CONTROL_IN_PORT_TAG);
    if (jElement != null) {
        this.controlInPortID = jElement.getAsString();
    }

    if (nodeObject.get(GraphSchema.NODE_CONTROL_OUT_PORT_TAG) != null) {
        jArray = nodeObject.getAsJsonArray(GraphSchema.NODE_CONTROL_OUT_PORT_TAG);
        for (JsonElement jsonElement : jArray) {
            this.controlOutPortIDs.add(jsonElement.getAsString());
        }
    }

    jElement = nodeObject.get(GraphSchema.NODE_EPR_PORT_TAG);
    if (jElement != null) {
        this.eprPortID = jElement.getAsString();
    }

    this.position.x = nodeObject.get(GraphSchema.NODE_X_LOCATION_TAG).getAsInt();
    this.position.y = nodeObject.get(GraphSchema.NODE_Y_LOCATION_TAG).getAsInt();

    // Parse config element not sure why we used it.
    // Parse component element.
    JsonObject configObject = nodeObject.getAsJsonObject(GraphSchema.NODE_CONFIG_TAG);
    if (configObject != null) {
        parseConfiguration(configObject);
    }

}

From source file:org.apache.airavata.workflow.model.graph.impl.PortImpl.java

License:Apache License

protected void parse(JsonObject portObject) {
    this.id = portObject.getAsJsonPrimitive(GraphSchema.PORT_ID_TAG).getAsString();

    JsonPrimitive jPrimitive = portObject.getAsJsonPrimitive(GraphSchema.PORT_NAME_TAG);
    if (jPrimitive != null) {
        this.name = jPrimitive.getAsString();
    }/*from ww w .j a  va2 s .  co  m*/

    this.nodeID = portObject.getAsJsonPrimitive(GraphSchema.PORT_NODE_TAG).getAsString();
}

From source file:org.apache.airavata.workflow.model.graph.ws.WSGraphFactory.java

License:Apache License

public NodeImpl createNode(JsonObject nodeObject) throws GraphException {

    String type = nodeObject.getAsJsonPrimitive(GraphSchema.NODE_TYPE_ATTRIBUTE).getAsString();

    NodeImpl node;//w w  w .ja  va  2s  .  co  m
    if (GraphSchema.NODE_TYPE_WS.equals(type)) {
        node = new WSNode(nodeObject);
    } else if (GraphSchema.NODE_TYPE_WORKFLOW.equals(type)) {
        node = new WorkflowNode(nodeObject);
    } else if (GraphSchema.NODE_TYPE_INPUT.equals(type)) {
        node = new InputNode(nodeObject);
    } else if (GraphSchema.NODE_TYPE_OUTPUT.equals(type)) {
        node = new OutputNode(nodeObject);
        /*        } else if (GraphSchema.NODE_TYPE_STREAM_SOURCE.equals(type)) {
                    node = new StreamSourceNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_CONSTANT.equals(type)) {
                    node = new ConstantNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_SPLIT.equals(type)) {
                    node = new ForEachNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_MERGE.equals(type)) {
                    node = new EndForEachNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_IF.equals(type)) {
                    node = new IfNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_ENDIF.equals(type)) {
                    node = new EndifNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_DOWHILE.equals(type)) {
                    node = new DoWhileNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_ENDDOWHILE.equals(type)) {
                    node = new EndDoWhileNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_MEMO.equals(type)) {
                    node = new MemoNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_RECEIVE.equals(type)) {
                    node = new ReceiveNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_BLOCK.equals(type)) {
                    node = new BlockNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_ENDBLOCK.equals(type)) {
                    node = new EndBlockNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_INSTANCE.equals(type)) {
                    node = new InstanceNode(nodeElement);
                } else if (GraphSchema.NODE_TYPE_TERMINATE.equals(type)) {
                    node = new TerminateInstanceNode(nodeElement);*/
    } else {
        // Default is WsNode for backward compatibility.
        node = new WSNode(nodeObject);
    }

    return node;
}

From source file:org.apache.airavata.workflow.model.graph.ws.WSGraphFactory.java

License:Apache License

/**
 * @see org.apache.airavata.workflow.model.graph.GraphFactory#createPort(org.xmlpull.infoset.XmlElement)
 *///from  w w w  .  ja  v  a2s .  c o m
public PortImpl createPort(JsonObject portObject) {

    String type = portObject.getAsJsonPrimitive(GraphSchema.PORT_TYPE_ATTRIBUTE).getAsString();
    PortImpl port;
    if (GraphSchema.PORT_TYPE_WS_DATA.equals(type)) {
        port = new WSPort(portObject);
    } else if (GraphSchema.PORT_TYPE_SYSTEM_DATA.equals(type)) {
        port = new SystemDataPort(portObject);
    } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
        port = new ControlPort(portObject);
        /*        } else if (GraphSchema.PORT_TYPE_EPR.equals(type)) {
                    port = new EPRPort(portElement);
                } else if (GraphSchema.PORT_TYPE_INSTANCE.equals(type)) {
                    port = new InstanceDataPort(portElement);*/
    } else {
        // Default is WsPort because of backword compatibility
        port = new WSPort(portObject);
    }
    return port;
}

From source file:org.apache.airavata.workflow.model.graph.ws.WSGraphFactory.java

License:Apache License

public EdgeImpl createEdge(JsonObject edgeObject) {
    String type = edgeObject.getAsJsonPrimitive(GraphSchema.EDGE_TYPE_ATTRIBUTE).getAsString();
    EdgeImpl edge;//from w ww .  j a va 2s  . com
    if (GraphSchema.EDGE_TYPE_DATA.equals(type)) {
        edge = new DataEdge(edgeObject);
    } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
        edge = new ControlEdge(edgeObject);
    } else {
        // Default is WsPort because of backword compatibility
        edge = new DataEdge(edgeObject);
    }
    return edge;
}

From source file:org.apache.airavata.workflow.model.wf.Workflow.java

License:Apache License

private void parse(JsonObject workflowObject) throws GraphException, ComponentException {
    // Graph/*from   w ww .j ava 2  s  .  c  o m*/
    if (workflowObject.getAsJsonObject(WORKFLOW_TAG) == null) {
        throw new GraphException("Failed to parse the json object, workflow object doesn't exist");
    }
    JsonObject workflowObj = workflowObject.getAsJsonObject(WORKFLOW_TAG);
    JsonObject graphObject = workflowObj.getAsJsonObject(GraphSchema.GRAPH_TAG);
    this.graph = WSGraphFactory.createGraph(graphObject);

    bindComponents();

    // Image
    JsonPrimitive imagePrimitive = workflowObj.getAsJsonPrimitive(IMAGE_TAG);
    if (imagePrimitive != null) {
        String base64 = imagePrimitive.getAsString();
        byte[] bytes = Base64.decodeBase64(base64.getBytes());

        try {
            this.image = ImageIO.read(new ByteArrayInputStream(bytes));
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:org.apache.edgent.test.apps.iot.EchoIotDevice.java

License:Apache License

private static String getCommandIdFromEvent(String eventId, JsonObject evPayload) {
    if (evPayload.has(EVENT_CMD_ID))
        return evPayload.getAsJsonPrimitive(EVENT_CMD_ID).getAsString();
    else//from w  ww  .  ja v a 2s .  c o m
        return eventId;
}

From source file:org.apache.fineract.portfolio.loanaccount.service.LoanAssembler.java

License:Apache License

public Set<LoanDisbursementDetails> fetchDisbursementData(final JsonObject command) {
    final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(command);
    final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(command);
    Set<LoanDisbursementDetails> disbursementDatas = new HashSet<>();
    if (command.has(LoanApiConstants.disbursementDataParameterName)) {
        final JsonArray disbursementDataArray = command
                .getAsJsonArray(LoanApiConstants.disbursementDataParameterName);
        if (disbursementDataArray != null && disbursementDataArray.size() > 0) {
            int i = 0;
            do {/*  w  w  w  .j ava2  s . c  om*/
                final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject();
                Date expectedDisbursementDate = null;
                Date actualDisbursementDate = null;
                BigDecimal principal = null;

                if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) {
                    LocalDate date = this.fromApiJsonHelper.extractLocalDateNamed(
                            LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale);
                    if (date != null) {
                        expectedDisbursementDate = date.toDate();
                    }
                }
                if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName)
                        && jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive()
                        && StringUtils.isNotBlank((jsonObject
                                .get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) {
                    principal = jsonObject
                            .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName)
                            .getAsBigDecimal();
                }

                disbursementDatas.add(new LoanDisbursementDetails(expectedDisbursementDate,
                        actualDisbursementDate, principal));
                i++;
            } while (i < disbursementDataArray.size());
        }
    }
    return disbursementDatas;
}