private static boolean isEqual(JsonArray arrayOriginal, JsonArray arrayNew) { if (arrayOriginal == null && arrayNew == null) { return true; }else if (arrayOriginal == null || arrayNew == null) { return false; }else { // check the number of element if (arrayOriginal.size() != arrayNew.size()) { return false; }else if (arrayOriginal.size() == 0) { return true; } else { for (int i = 0; i < arrayOriginal.size(); i++) { JsonElement valueOrig = arrayOriginal.get(i); JsonElement valueNew = arrayNew.get(i); if (valueOrig instanceof JsonObject && valueNew instanceof JsonObject) { if (!isEqual((JsonObject) valueOrig, (JsonObject) valueNew)) { return false; } }else if (valueOrig instanceof JsonPrimitive && valueNew instanceof JsonPrimitive) { if (!isEqual((JsonPrimitive) valueOrig, (JsonPrimitive) valueNew)) { return false; } } } } } return true; }
public static void saveJSON(JsonElement jsonElement, File file) throws IOException { IOUtil.writeToFile(jsonElementToString(jsonElement), file); }
public static JsonObject loadJSON(File file) throws IOException { return loadJSON(new FileReader(file)); }
/** * @param graphString * @return the graph created * @throws GraphException */ public static WSGraph createGraph(String graphString) throws GraphException { XmlElement graphElement; JsonObject graphElementJSON; try { // graphElement = XMLUtil.stringToXmlElement(graphString); graphElementJSON = JSONUtil.stringToJSONObject(graphString); } catch (RuntimeException e) { throw new GraphException(MessageConstants.XML_ERROR, e); } return createGraph(graphElementJSON); }
private void saveWorkflow(Workflow workflow, File file) { try { // XMLUtil.saveXML(workflow.toXML(), file); JSONUtil.saveJSON(workflow.toJSON(), file); } catch (IOException e) { this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e); } catch (RuntimeException e) { this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_SAVE_ERROR, e); } catch (Error e) { this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e); } }
/** * Constructs a Workflow. * * @param workflowString * Workflow XML in String. * @throws GraphException * @throws ComponentException */ public Workflow(String workflowString) throws GraphException, ComponentException { this(); try { // XmlElement workflowElement = XMLUtil.stringToXmlElement(workflowString); JsonObject workflowElement = JSONUtil.stringToJSONObject(workflowString); parse(workflowElement); } catch (RuntimeException e) { throw new GraphException(e); } }
public static boolean isEqual(JsonObject originalJsonObject, JsonObject newJsonObject) { // TODO - Implement this method if (originalJsonObject == null && newJsonObject == null) { return true; }else if (originalJsonObject == null || newJsonObject == null) { return false; } else { // check the number of childs Set<Map.Entry<String , JsonElement>> entrySetOfOriginalJson = originalJsonObject.entrySet(); Set<Map.Entry<String , JsonElement>> entrySetOfNewJson = newJsonObject.entrySet(); if (entrySetOfOriginalJson.size() != entrySetOfNewJson.size()) { return false; } for (Map.Entry<String, JsonElement> keyString : entrySetOfOriginalJson) { JsonElement valueOrig = keyString.getValue(); JsonElement valueNew = newJsonObject.get(keyString.getKey()); if (valueOrig instanceof JsonObject && valueNew instanceof JsonObject && !isEqual((JsonObject) valueOrig, (JsonObject) valueNew)) { return false; }else if (valueOrig instanceof JsonArray && valueNew instanceof JsonArray && !isEqual((JsonArray) valueOrig, (JsonArray) valueNew)) { return false; }else if (valueOrig instanceof JsonPrimitive && valueNew instanceof JsonPrimitive && !isEqual((JsonPrimitive) valueOrig, (JsonPrimitive) valueNew)) { return false; } } } return true; }
workflow = Workflow.graphToWorkflow(graph); } else { JsonObject workflowObject = JSONUtil.loadJSON(file);
org.apache.airavata.model.Workflow w = new org.apache.airavata.model.Workflow(); w.setName(workflowClone.getName()); w.setGraph(JSONUtil.jsonElementToString(workflowClone.toJSON())); w.setTemplateId(airavataClient.registerWorkflow(w)); String instanceName = this.instanceNameTextField.getText();
public boolean isWorkflowChanged(){ try { if (originalWorkflowElementJson==null){ updateOriginalWorkflowElement(); } // return !XMLUtil.isEqual(originalWorkflowElement, getWorkflow().toXML()); return !JSONUtil.isEqual(originalWorkflowElementJson, getWorkflow().toJSON()); } catch (Exception e) { e.printStackTrace(); return true; } }