Mercurial > dive4elements > gnv-client
changeset 52:4d6a82b96059
First Implementation of the GNV-Artifacts
gnv-artifacts/trunk@32 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/gnv-artifacts/Changelog Fri Sep 04 15:23:51 2009 +0000 +++ b/gnv-artifacts/Changelog Mon Sep 07 15:29:24 2009 +0000 @@ -1,3 +1,24 @@ +2009-09-07 Tim Englich <tim.englich@intevation.de> + + * src/test/ressources/GNVArtifactsTestCase_Configuration.xml, + src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java: ADD + TestClass for GNV-Artifacts an TimeSeriesArtifacs + + * src/main/java/de/intevation/gnv/transition/TransitionFactory.java, + src/main/java/de/intevation/gnv/transition/TransitionBase.java, + src/main/java/de/intevation/gnv/transition/Transition.java, + src/main/java/de/intevation/gnv/transition/DefaultTransition.java: ADD + Transitionimplementation for handling the substeps of an Artifact Livecycle + + * src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java: ADD + The Artifact for handling the TimeSeries + * src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java, + src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java, + src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: + The Basic-Classes for providing GNC Artifacts. this Classes should be the Fundament + for the Implementation of Specialized Artifacts e.g. TimeSeries + * pom: Edited Projectreferences to the other GNV-Projects added + 2009-09-04 Tim Englich <tim.englich@intevation.de> * src/main/java/de/intevation/gnv/artifacts/ArtifactFactoryBase.java:
--- a/gnv-artifacts/pom.xml Fri Sep 04 15:23:51 2009 +0000 +++ b/gnv-artifacts/pom.xml Mon Sep 07 15:29:24 2009 +0000 @@ -42,5 +42,10 @@ <version>3.8.1</version> <scope>test</scope> </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>[1.2,)</version> + </dependency> </dependencies> </project>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ArtifactFactoryBase.java Fri Sep 04 15:23:51 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/** - * - */ -package de.intevation.gnv.artifacts; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import de.intevation.artifacts.Artifact; -import de.intevation.artifacts.ArtifactFactory; - -/** - * @author Tim Englich <tim.englich@intevation.de> - * - */ -public abstract class ArtifactFactoryBase implements ArtifactFactory { - - /** - * The Name of the ArtifactFactory - */ - protected String name = "undefined"; - - /** - * The description of the ArtifactFactory - */ - protected String description = "undefined"; - - /** - * Constructor - */ - public ArtifactFactoryBase() { - super(); - } - - /** - * @see de.intevation.artifacts.ArtifactFactory#createArtifact(java.lang.String, java.lang.Object) - */ - public Artifact createArtifact(String identifier, Object context) { - - return null; - } - - /** - * @see de.intevation.artifacts.ArtifactFactory#getDescription() - */ - public String getDescription() { - - return this.description; - } - - /** - * @see de.intevation.artifacts.ArtifactFactory#getName() - */ - public String getName() { - - return this.name; - } - - /** - * @see de.intevation.artifacts.ArtifactFactory#setup(org.w3c.dom.Document) - */ - public void setup(Document config, Node factoryNode) { - - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,87 @@ +/** + * + */ +package de.intevation.gnv.artifacts; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.DefaultArtifact; +import de.intevation.gnv.artifacts.context.GNVArtifactContext; +import de.intevation.gnv.transition.Transition; +import de.intevation.gnv.transition.TransitionFactory; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public abstract class GNVArtifactBase extends DefaultArtifact { + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(GNVArtifactBase.class); + /** + * The UID of this Class + */ + private static final long serialVersionUID = -8907096744400741458L; + + public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER"; + /** + * The XPATH to the XML-Fragment that should be used for the Configuration + */ + public static final String XPATH_ARTIFACT_CONFIGURATION= "/artifact-database/artifacts/artifact[@name='"+XPATH_IDENTIFIER_REPLACE+"']"; + + protected Transition current = null; + + protected Map<String, Transition> transitions = null; + + protected String name = null; + /** + * Constructor + */ + public GNVArtifactBase() { + super(); + } + + protected Node getConfigurationFragment(Document document){ + log.debug("GNVArtifactBase.getConfigurationFragment"); + String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(XPATH_IDENTIFIER_REPLACE, this.name); + log.debug(xpathQuery); + return Config.getNodeXPath(document,xpathQuery); + + } + + /** + * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, java.lang.Object) + */ + @Override + public void setup(String identifier, Object context) { + log.debug("GNVArtifactBase.setup"); + super.setup(identifier, context); + if (context instanceof GNVArtifactContext){ + GNVArtifactContext gnvContext = (GNVArtifactContext)context; + Document doc = gnvContext.getConfig(); + Node artifactNode = this.getConfigurationFragment(doc); + NodeList transitionList = Config.getNodeSetXPath(artifactNode, "transitions/transition"); + this.transitions = new HashMap<String, Transition>(transitionList.getLength()); + for (int i = 0 ; i < transitionList.getLength(); i++){ + Transition tmpTransition = TransitionFactory.getInstance().createTransition(transitionList.item(i)); + if (tmpTransition != null){ + this.transitions.put(tmpTransition.getID(), tmpTransition); + if (this.current == null){ + this.current = tmpTransition; + } + } + } + + } + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,32 @@ +/** + * + */ +package de.intevation.gnv.artifacts.context; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; + +import de.intevation.artifactdatabase.DefaultArtifactContext; + + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class GNVArtifactContext extends DefaultArtifactContext{ + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(GNVArtifactContext.class); + + public GNVArtifactContext(){ + super(); + log.debug("GNVArtifactContext.Constructor"); + } + + public GNVArtifactContext(Document config) { + super(config); + log.debug("GNVArtifactContext.Constructor(config)"); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,86 @@ +/** + * + */ +package de.intevation.gnv.artifacts.context; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; + +import de.intevation.artifactdatabase.Config; +import de.intevation.artifacts.ArtifactContextFactory; +import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory; +import de.intevation.gnv.geobackend.base.query.container.QueryContainerFactory; +import de.intevation.gnv.geobackend.base.query.container.exception.QueryContainerException; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class GNVArtifactContextFactory implements ArtifactContextFactory { + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(GNVArtifactContext.class); + + public static final String XPATH_GEOBACKEND_CONFIGURATION= "artifact-database/geo-backend/backend-configuration"; + + public static final String XPATH_GEOBACKEND_QUERYCONFIGURATION= "artifact-database/geo-backend/query-configuration"; + + /** + * Constructor + */ + public GNVArtifactContextFactory() { + super(); + log.debug("GNVArtifactContextFactory.Constructor"); + } + + /** + * @see de.intevation.artifacts.ArtifactContextFactory#createArtifactContext(org.w3c.dom.Document) + */ + public Object createArtifactContext(Document config) { + Object returnValue = null; + try { + log.debug("GNVArtifactContextFactory.createArtifactContext"); + log.info("Initialisation of the Geo-BackendConnectionPool"); + String backendConfigurationFile = Config.getStringXPath(config, XPATH_GEOBACKEND_CONFIGURATION); + Properties properties = getProperties(backendConfigurationFile); + ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance(); + cpf.initializeConnectionPool(properties); + + log.info("Initialisation of the QueryContainer"); + String queryConfigurationFile = Config.getStringXPath(config, XPATH_GEOBACKEND_QUERYCONFIGURATION); + Properties queryProperties = getProperties(queryConfigurationFile); + QueryContainerFactory qcf = QueryContainerFactory.getInstance(); + qcf.initializeQueryContainer(queryProperties); + + returnValue = new GNVArtifactContext(config); + } catch (FileNotFoundException e) { + log.error(e,e); + } catch (IOException e) { + log.error(e,e); + } catch (QueryContainerException e){ + log.error(e,e); + } + return returnValue; + } + + /** + * @param filePath + * @return + * @throws FileNotFoundException + * @throws IOException + */ + private Properties getProperties(String filePath) + throws FileNotFoundException, IOException { + InputStream inputStream = new FileInputStream(filePath); + Properties properties = new Properties(); + properties.load(inputStream); + return properties; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,73 @@ +/** + * + */ +package de.intevation.gnv.timeseries; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import de.intevation.gnv.artifacts.GNVArtifactBase; +import de.intevation.gnv.artifacts.context.GNVArtifactContext; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class TimeSeriesArtifact extends GNVArtifactBase { + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(TimeSeriesArtifact.class); + + + /** + * The UID of this class + */ + private static final long serialVersionUID = -8291547966693867205L; + + /** + * Constructor + */ + public TimeSeriesArtifact(){ + super(); + log.debug("TimeSeriesArtifact.Constructor"); + this.name = "timeSeries"; + } + + /** + * @see de.intevation.artifactdatabase.DefaultArtifact#describe(java.lang.Object) + */ + @Override + public Document describe(Object context) { + log.debug("TimeSeriesArtifact.describe"); + return super.describe(context); + } + + /** + * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, java.lang.Object) + */ + @Override + public Document feed(Document target, Object context) { + log.debug("TimeSfeederiesArtifact.feed"); + return super.feed(target, context); + } + + /** + * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document, java.lang.Object) + */ + @Override + public byte[] out(Document format, Object context) { + log.debug("TimeSeriesArtifact.out"); + return super.out(format, context); + } + + /** + * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, java.lang.Object) + */ + @Override + public void setup(String identifier, Object context) { + log.debug("TimeSeriesArtifact.setup"); + super.setup(identifier, context); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultTransition.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,36 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import org.w3c.dom.Document; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class DefaultTransition extends TransitionBase { + + /** + * Constructor + */ + public DefaultTransition() { + } + + /** + * @see de.intevation.gnv.transition.Transition#describe() + */ + public Document describe() { + + return null; + } + + /** + * @see de.intevation.gnv.transition.Transition#validate() + */ + public boolean validate() { + // TODO Validation einbauen + return true; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,31 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import java.util.Collection; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public interface Transition { + + public void setup(Node configuration); + + public Collection<String> reachableTransitions(); + + public String getID(); + + public boolean validate(); + + public Document describe(); + + public void setParent(Transition transition); + + public Transition getParent(); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,88 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import de.intevation.artifactdatabase.Config; +import de.intevation.gnv.artifacts.GNVArtifactBase; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public abstract class TransitionBase implements Transition { + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(GNVArtifactBase.class); + + private String id = null; + + protected String queryID = null; + + private Collection<String> reachableTransitions = null; + + private Transition parent = null; + /** + * Constructor + */ + public TransitionBase() { + super(); + } + + /** + * @see de.intevation.gnv.transition.Transition#getID() + */ + public String getID() { + return this.id; + } + + /** + * @see de.intevation.gnv.transition.Transition#reachableTransitions() + */ + public Collection<String> reachableTransitions() { + return this.reachableTransitions; + } + + /** + * @see de.intevation.gnv.transition.Transition#setup(org.w3c.dom.Node) + */ + public void setup(Node configuration) { + + this.id = Config.getStringXPath(configuration,"@id"); + log.info("Transition-ID = "+ this.id); + NodeList nodes = Config.getNodeSetXPath(configuration,"reachableTransitions/transition"); + this.reachableTransitions = new ArrayList<String>(nodes.getLength()); + for (int i = 0 ; i < nodes.getLength(); i++){ + String reachableTransition = nodes.item(i).getTextContent(); + log.info("ReachableTransition ==> "+ reachableTransition); + this.reachableTransitions.add(reachableTransition); + + } + this.queryID = Config.getStringXPath(configuration,"queryID"); + log.info("QueryID ==>"+ this.queryID); + + } + + /** + * @see de.intevation.gnv.transition.Transition#getParent() + */ + public Transition getParent() { + return this.parent; + } + + /** + * @see de.intevation.gnv.transition.Transition#setParent(de.intevation.gnv.transition.Transition) + */ + public void setParent(Transition transition) { + this.parent = transition; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionFactory.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,56 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import org.apache.log4j.Logger; +import org.w3c.dom.Node; + +import de.intevation.artifactdatabase.Config; +import de.intevation.gnv.artifacts.GNVArtifactBase; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class TransitionFactory { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(GNVArtifactBase.class); + + private static TransitionFactory instance = null; + /** + * Constructor + */ + public TransitionFactory() { + super(); + } + + public static TransitionFactory getInstance(){ + if (instance == null){ + instance = new TransitionFactory(); + } + return instance; + } + + + public Transition createTransition(Node configuration){ + log.debug("TransitionFactory.createTransition"); + Transition transition = null; + try { + String classname = Config.getStringXPath(configuration, "@transition"); + transition = (Transition)(Class.forName(classname).newInstance()); + transition.setup(configuration); + } catch (InstantiationException e) { + log.error(e,e); + } catch (IllegalAccessException e) { + log.error(e,e); + } catch (ClassNotFoundException e) { + log.error(e,e); + } + return transition; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,112 @@ +/** + * + */ +package de.intevation.gnv.artifacts; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Logger; +import org.w3c.dom.Document; + +import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.FactoryBootstrap; +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactFactory; +import de.intevation.gnv.artifacts.context.GNVArtifactContext; +import de.intevation.gnv.artifacts.context.GNVArtifactContextFactory; +import junit.framework.TestCase; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class GNVArtifactsTestCase extends TestCase { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = null; + + static { + BasicConfigurator.configure(); + log = Logger.getLogger(GNVArtifactContext.class); + } + + private String configurationFile = "src/test/ressources/GNVArtifactsTestCase_Configuration.xml"; + + private FactoryBootstrap bootstrap = null; + /** + * Constructor + * @param name + */ + public GNVArtifactsTestCase(String name) { + super(name); + } + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + log.debug("GNVArtifactsTestCase.setUp"); + super.setUp(); + log.info(Config.CONFIG_PROPERTY + " ==> "+configurationFile); + System.setProperty(Config.CONFIG_PROPERTY, configurationFile); + log.info("Bootstrap wird initialisiert."); + bootstrap = new FactoryBootstrap(); + bootstrap.boot(); + } + + public void testTimeSeriesArtifact(){ + log.debug("GNVArtifactsTestCase.testTimeSeriesArtifact"); + String artefactName = "timeSeries"; + ArtifactFactory artifactFactory = this.getArtifactFactory(artefactName); + assertNotNull(artifactFactory); + log.debug("TimeSeries-ArtifactFactory is available"); + Artifact artifact = artifactFactory.createArtifact(""+System.currentTimeMillis(),bootstrap.getContext()); + assertNotNull(artifact); + log.debug("TimeSeries-Artifact is available"); + + Document indata = this.getDocument(); + Document outData = this.createOutputDocument(); + artifact.feed(indata, bootstrap.getContext()); + artifact.advance(outData, bootstrap.getContext()); + Document outputData = artifact.describe(bootstrap.getContext()); + + + + } + private Document getDocument(){ + return this.createOutputDocument(); + } + + private Document createOutputDocument(){ + try { + return DocumentBuilderFactory + .newInstance() + .newDocumentBuilder() + .newDocument(); + } + catch (ParserConfigurationException e) { + log.error(e,e); + } + return null; + } + + /** + * @param artefactName + */ + private ArtifactFactory getArtifactFactory(String artefactName){ + log.debug("GNVArtifactsTestCase.getArtifactFactory"); + ArtifactFactory[] artifactFactories = bootstrap.getArtifactFactories(); + for (int i = 0; i < artifactFactories.length; i++){ + if (artifactFactories[i].getName().equals(artefactName)){ + log.debug("ArtifactFactory wurde gefunden."); + return artifactFactories[i]; + } + } + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/GNVArtifactsTestCase_Configuration.xml Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<artifact-database> + <factories> + <context-factory>de.intevation.gnv.artifacts.context.GNVArtifactContextFactory</context-factory> + <artifact-factories> + <artifact-factory + name="timeSeries" description="Artiefactfactory for instantiating TimeSeriesArtifacts" ttl="60000" + artifact="de.intevation.gnv.timeseries.TimeSeriesArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory> + </artifact-factories> + </factories> + <artifacts> + <artifact name="timeSeries"> + <transitions> + <transition id="timeSeries.start" transition="de.intevation.gnv.transition.DefaultTransition"> + <queryID>mesh</queryID> + <reachableTransitions> + <transition>timeSeries.end</transition> + </reachableTransitions> + </transition> + <transition id="timeSeries.end" transition="de.intevation.gnv.transition.DefaultTransition"> + <queryID>mesh</queryID> + </transition> + </transitions> + </artifact> + </artifacts> + <geo-backend> + <backend-configuration>../geo-backend/src/test/ressources/ArcSDEConnectionPoolTestCase.properties</backend-configuration> + <query-configuration>../geo-backend/src/test/ressources/QueryExecutorTestCase.properties</query-configuration> + </geo-backend> + <database> + <user></user> + <password></password> + <!-- <url>jdbc:h2:artifacts.db</url> --> + <!-- <driver>org.h2.Driver</driver> --> + <!-- <sql></sql> --> + </database> +</artifact-database>