You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2011/08/09 17:13:28 UTC
svn commit: r1155392 - in /oodt/trunk: ./
app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/
app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/
app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/repo/
Author: mattmann
Date: Tue Aug 9 15:13:27 2011
New Revision: 1155392
URL: http://svn.apache.org/viewvc?rev=1155392&view=rev
Log:
- fix for OODT-308 WEditor save feature is not implemented
Modified:
oodt/trunk/CHANGES.txt
oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/WorkflowGUI.java
oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/ModelNode.java
oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/repo/XmlWorkflowModelRepository.java
Modified: oodt/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1155392&r1=1155391&r2=1155392&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Tue Aug 9 15:13:27 2011
@@ -4,6 +4,8 @@ Apache OODT Change Log
Release 0.4: Current Development
--------------------------------------------
+* OODT-308 WEditor save feature is not implemented (bfoster via mattmann)
+
* OODT-296 Workflow Editor GUI (mattmann, bfoster, ahart)
* OODT-294 Updated website to announce release of 0.3 (goodale)
Modified: oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/WorkflowGUI.java
URL: http://svn.apache.org/viewvc/oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/WorkflowGUI.java?rev=1155392&r1=1155391&r2=1155392&view=diff
==============================================================================
--- oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/WorkflowGUI.java (original)
+++ oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/WorkflowGUI.java Tue Aug 9 15:13:27 2011
@@ -36,6 +36,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
//OODT imports
import org.apache.oodt.cas.workflow.gui.menu.EditMenu;
@@ -77,6 +78,8 @@ public class WorkflowGUI extends JFrame
private File workspace;
+ private XmlWorkflowModelRepository repo;
+
public WorkflowGUI() throws Exception {
this.addWindowFocusListener(new WindowFocusListener() {
@@ -170,7 +173,7 @@ public class WorkflowGUI extends JFrame
try {
XmlWorkflowModelRepositoryFactory factory = new XmlWorkflowModelRepositoryFactory();
factory.setWorkspace(this.workspace.getAbsolutePath());
- XmlWorkflowModelRepository repo = factory.createModelRepository();
+ repo = factory.createModelRepository();
repo.loadGraphs(new HashSet<String>(Arrays.asList("sequential",
"parallel", "task", "condition")));
for (File file : repo.getFiles()) {
@@ -270,7 +273,11 @@ public class WorkflowGUI extends JFrame
});
fileMenu.getSave().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
- // TODO: add file save code
+ try {
+ repo.save();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
});
EditMenu editMenu = new EditMenu();
Modified: oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/ModelNode.java
URL: http://svn.apache.org/viewvc/oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/ModelNode.java?rev=1155392&r1=1155391&r2=1155392&view=diff
==============================================================================
--- oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/ModelNode.java (original)
+++ oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/ModelNode.java Tue Aug 9 15:13:27 2011
@@ -39,6 +39,7 @@ import org.apache.oodt.cas.metadata.Meta
public class ModelNode {
private String id;
+ private String alias;
private boolean isRef;
private File file;
private boolean textVisible;
@@ -82,6 +83,14 @@ public class ModelNode {
return this.id;
}
+ public void setAlias(String alias) {
+ this.alias = alias;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
public void setIsRef(boolean isRef) {
this.isRef = isRef;
}
Modified: oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/repo/XmlWorkflowModelRepository.java
URL: http://svn.apache.org/viewvc/oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/repo/XmlWorkflowModelRepository.java?rev=1155392&r1=1155391&r2=1155392&view=diff
==============================================================================
--- oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/repo/XmlWorkflowModelRepository.java (original)
+++ oodt/trunk/app/weditor/src/main/java/org/apache/oodt/cas/workflow/gui/model/repo/XmlWorkflowModelRepository.java Tue Aug 9 15:13:27 2011
@@ -21,9 +21,12 @@ package org.apache.oodt.cas.workflow.gui
import org.apache.oodt.cas.metadata.Metadata;
import org.apache.oodt.cas.workflow.gui.model.ModelGraph;
import org.apache.oodt.cas.workflow.gui.model.ModelNode;
+import org.apache.oodt.commons.xml.XMLUtils;
//JDK imports
import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -37,11 +40,14 @@ import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -110,13 +116,17 @@ public class XmlWorkflowModelRepository
return this.globalConfigGroups;
}
+ public void setGlobalConfigGroups(Map<String, ConfigGroup> globalConfigGroups) {
+ this.globalConfigGroups = new HashMap<String, ConfigGroup>(globalConfigGroups);
+ }
+
public List<File> getFiles() {
return this.files;
}
- public void save(List<ModelGraph> graphs,
- Map<String, Metadata> globalConfigGroups) throws Exception {
+ public void save() throws Exception {
this.backupCurrentFiles();
+ this.saveGraphs();
}
private void backupCurrentFiles() throws Exception {
@@ -128,6 +138,136 @@ public class XmlWorkflowModelRepository
this.files.clear();
}
+ private void saveGraphs() throws FileNotFoundException, ParserConfigurationException {
+ Map<File, Document> documents = new HashMap<File, Document>();
+ for (ModelGraph graph : this.graphs) {
+ Document document = documents.get(graph.getModel().getFile());
+ if (document == null) {
+ document = createDocument();
+ document.appendChild(document.createElement("workflows"));
+ documents.put(graph.getModel().getFile(), document);
+ }
+ saveGraph(graph, document.getDocumentElement(), document);
+ }
+ saveGlobalConfigGroups(documents);
+ writeOutDocuments(documents);
+ this.files = new ArrayList<File>(documents.keySet());
+ }
+
+ private void writeOutDocuments(Map<File, Document> documents) {
+ for (File file : documents.keySet()) {
+ XMLUtils.writeXmlFile(documents.get(file), file.getAbsolutePath());
+ }
+ }
+
+ private void saveGlobalConfigGroups(Map<File, Document> documents) throws ParserConfigurationException {
+ File globalConfigGroupsFile = new File(workspace, "shared-configuration.xml");
+ Document document = documents.get(globalConfigGroupsFile);
+ if (document == null) {
+ document = createDocument();
+ document.appendChild(document.createElement("workflows"));
+ documents.put(globalConfigGroupsFile, document);
+ }
+ for (String configName : this.globalConfigGroups.keySet()) {
+ ConfigGroup globalConfig = this.globalConfigGroups.get(configName);
+ Element configElem = document.createElement("configuration");
+ document.getDocumentElement().appendChild(configElem);
+ configElem.setAttribute("name", globalConfig.getName());
+ if (!globalConfig.getExtends().isEmpty()) {
+ configElem.setAttribute("extends", StringUtils.join(globalConfig.getExtends(), ", "));
+ }
+
+ String[] properties = globalConfig.getMetadata().getAllKeys().toArray(new String[globalConfig.getMetadata().getAllKeys().size()]);
+ Arrays.sort(properties);
+ for (String property : properties) {
+ Element propElem = document.createElement("property");
+ configElem.appendChild(propElem);
+ propElem.setAttribute("name", property);
+ propElem.setAttribute("value", globalConfig.getMetadata().getMetadata(property));
+ }
+ }
+ }
+
+ private void saveGraph(ModelGraph graph, Element parentElem, Document document) throws FileNotFoundException, ParserConfigurationException {
+ ModelNode node = graph.getModel();
+
+ Element workflowElem = document.createElement(node.getExecutionType());
+ parentElem.appendChild(workflowElem);
+
+ if (node.isRef()) {
+ workflowElem.setAttribute("id-ref", node.getModelId());
+ if (node.getAlias() != null) {
+ workflowElem.setAttribute("alias", node.getAlias());
+ }
+ saveConfiguration(node, workflowElem, document);
+ } else {
+ workflowElem.setAttribute("id", node.getModelId());
+ workflowElem.setAttribute("name", node.getModelName());
+ if (node.getInstanceClass() != null) {
+ workflowElem.setAttribute("class", node.getInstanceClass());
+ }
+
+ saveConfiguration(node, workflowElem, document);
+
+ // handle preconditions
+ if (graph.getPreConditions() != null) {
+ Element preConditions = document.createElement("conditions");
+ workflowElem.appendChild(preConditions);
+ preConditions.setAttribute("type", "pre");
+ preConditions.setAttribute("execution", graph.getPreConditions().getModel().getExecutionType());
+ for (ModelGraph preCondition : graph.getPreConditions().getChildren()) {
+ saveGraph(preCondition, preConditions, document);
+ }
+ }
+
+ // handle subprocessors
+ for (ModelGraph subProcessor : graph.getChildren()) {
+ saveGraph(subProcessor, workflowElem, document);
+ }
+
+ // handle postconditions
+ if (graph.getPostConditions() != null) {
+ Element postConditions = document.createElement("conditions");
+ workflowElem.appendChild(postConditions);
+ postConditions.setAttribute("type", "post");
+ postConditions.setAttribute("execution", graph.getPostConditions().getModel().getExecutionType());
+ for (ModelGraph postCondition : graph.getPostConditions().getChildren()) {
+ saveGraph(postCondition, postConditions, document);
+ }
+ }
+ }
+ if (!node.getExcusedSubProcessorIds().isEmpty()) {
+ workflowElem.setAttribute("excused", StringUtils.join(node.getExcusedSubProcessorIds(), ","));
+ }
+ if (node.isEntryPoint()) {
+ workflowElem.setAttribute("entryPoint", "true");
+ }
+ }
+
+ private void saveConfiguration(ModelNode node, Element workflowElem, Document document) {
+ if (!node.getStaticMetadata().getAllKeys().isEmpty()) {
+ Element configElem = document.createElement("configuration");
+ workflowElem.appendChild(configElem);
+ if (!node.getExtendsConfig().isEmpty()) {
+ configElem.setAttribute("extends", StringUtils.join(node.getExtendsConfig(), ", "));
+ }
+ String[] properties = node.getStaticMetadata().getAllKeys().toArray(new String[node.getStaticMetadata().getAllKeys().size()]);
+ Arrays.sort(properties);
+ for (String property : properties) {
+ Element propElem = document.createElement("property");
+ configElem.appendChild(propElem);
+ propElem.setAttribute("name", property);
+ propElem.setAttribute("value", node.getStaticMetadata().getMetadata(property));
+ }
+ }
+ }
+
+ private Document createDocument() throws ParserConfigurationException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ return factory.newDocumentBuilder().newDocument();
+ }
+
private void ensureUniqueIds(Set<ModelGraph> graphs) {
for (ModelGraph graph : graphs) {
HashSet<String> names = new HashSet<String>();
@@ -262,8 +402,7 @@ public class XmlWorkflowModelRepository
graph.getModel().setStaticMetadata(new Metadata());
loadConfiguration(rootElements, workflowNode, graph.getModel(),
globalConfGroups);
- if (alias != null)
- graph.getModel().setModelId(alias);
+ graph.getModel().setAlias(alias);
}
if (entryPoint && graph.getParent() != null) {