Re: Workflow in Database

"Philipp Hug" <[email protected]>
Newsgroups gmane.comp.java.open-symphony.devel
Message-ID <01f101c31323$a6b97160$3c0112ac@chimera>
I implemented the JDBCWorkflowFactory, and it seems to work ;-)
Ok, how does it work:
At the moment it uses one table with 2 fields (WF_NAME; WF_DEFINITION)
the first contains the name of the workflow and the second contains
the whole workflow definition xml as a blob.

problems:
1. osworkflow doesn't correctly encode strings in xml,
if you have && in a beanshell script it'll just write it down like that,
instead of escaping it. (e.g. with CDATA) (--> see jira bug WF-152)
this causes problems when you try to save the example workflow into
database.
2. patch for ConfigLoader required:
persistence properties must be loaded before the JDBCWorkflowFactory is initialized,
because I load the DB settings from the persistence properties.
I could change it to load the setting from a property in the factory section of osworkflow.xml,
but this would just create yet another place where you have to set the datasource. :-(

If nobody disagrees, I'll put this patch and JDBCWorkflowFactory.java in jira.

philipp

Index: java/com/opensymphony/workflow/config/ConfigLoader.java
===================================================================
RCS file:
/cvs/apps/flow/opensymphony/osworkflow/src/java/com/opensymphony/workflow/config/ConfigLoader.java,v
retrieving revision 1.2
diff -r1.2 ConfigLoader.java
77a78,87
> persistence = p.getAttribute("class");
>
> NodeList args = p.getElementsByTagName("property");
> persistenceArgs = new HashMap();
>
> for (int i = 0; i < args.getLength(); i++) {
> Element e = (Element) args.item(i);
> persistenceArgs.put(e.getAttribute("key"), e.getAttribute("value"));
> }
>
98,107d107
< }
<
< persistence = p.getAttribute("class");
<
< NodeList args = p.getElementsByTagName("property");
< persistenceArgs = new HashMap();
<
< for (int i = 0; i < args.getLength(); i++) {
< Element e = (Element) args.item(i);
< persistenceArgs.put(e.getAttribute("key"), e.getAttribute("value"));


----- Original Message ----- 
From: "Hani Suleiman" <[email protected]>
To: <[email protected]>
Sent: Thursday, May 01, 2003 6:15 PM
Subject: Re: [Opensymphony-developers] Workflow in Database


> I've added the load(InputStream) method, it's in CVS now.
>
> For the other issue, I don't think it's a good idea to add that. The
> reason is that the way it is set up currently, the save method is free
> to choose any way of saving. It doesn't need to store it as an xml file
> either. It could persist the workflow descriptor to a set of database
> tables which model its structure, or to a swing JTree model.
>
> The WorkflowLoader is a convenience class, and so I don't think it's
> such a big deal to duplicate the small amount of code it is to write
> out the xml file. You could always have your jdbc factory subclass
> XMLWorkflowFactory, and use its writing method. Okok, so this wasn't
> possible before, but I just fixed it in XMLWorkflowFactory.
>
> You can subclass it (JDBCXMLWorkflowFactory) and override the
> saveWorkflow method, then use the writeXML method to write out your
> workflow to whatever Writer you want.
>
> Let me know if you have any problems with your implementation!
>
> Hani
>
> On Thursday, May 1, 2003, at 10:03 AM, Philipp Hug wrote:
>
> > I wrote a class to put workflow definitions in a JDBC database,
> > but I need some patches in osWorkflow to prevent code duplication:
> >
> > 1. WorkflowLoader.java
> > --> add an additional load method that takes an InputStream instead of
> > an
> > URL
> >     /**
> >      * Load a workflow descriptor from a URL
> >      */
> >     public static WorkflowDescriptor load(final URL url) throws
> > SAXException, IOException {
> >         return load(url.openStream());
> >     }
> >
> >     /**
> >      * Load a workflow descriptor from an InputStream
> >      */
> >     public static WorkflowDescriptor load(final InputStream is) throws
> > SAXException, IOException {
> > ----
> >
> > 2. Move save() code from XMLWorkflowFactory into a new class similar to
> > WorkflowLoader, otherwise the code
> > would need to be duplicated. It's just a small part of code but anyway:
> >
> > the code could look like that:
> > public static save(OutputStream os) {
> >         Writer out = new OutputStreamWriter(os);
> >
> >         PrintWriter writer = new PrintWriter(new BufferedWriter(out));
> >         writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
> >
> >         writer.println("<!DOCTYPE workflow PUBLIC \"-//OpenSymphony
> > Group//DTD OSWorkflow 2.5//EN\"
> > \"http://www.opensymphony.com/osworkflow/workflow.dtd\">");
> >         descriptor.writeXML(writer, 0);
> >         writer.flush();
> >         writer.close();
> > }
> >
> > What do you think? Should I submit a feature request/bug in JIRA?
> >
> > philipp
> >
> >
> >
> > -------------------------------------------------------
> > This sf.net email is sponsored by:ThinkGeek
> > Welcome to geek heaven.
> > http://thinkgeek.com/sf
> > _______________________________________________
> > Opensymphony-developers mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/opensymphony-developers
> >
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Opensymphony-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/opensymphony-developers
>
>



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.