]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
First slc execution JCR mapping
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 21 Feb 2010 18:07:18 +0000 (18:07 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 21 Feb 2010 18:07:18 +0000 (18:07 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@3374 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.jcr/.classpath
runtime/org.argeo.slc.support.jcr/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
runtime/org.argeo.slc.support.jcr/.settings/org.eclipse.pde.core.prefs [new file with mode: 0644]
runtime/org.argeo.slc.support.jcr/build.properties [new file with mode: 0644]
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/dao/SlcExecutionDaoJcr.java [new file with mode: 0644]
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/process/SlcExecutionDaoJcr.java [deleted file]
runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/dao/mapping.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.jcr/src/test/java/org/argeo/slc/jcr/dao/SlcExecutionDaoJcrTest.java [new file with mode: 0644]
runtime/org.argeo.slc.support.jcr/src/test/resources/org/argeo/slc/jcr/dao/applicationContext.xml [new file with mode: 0644]

index fc460145a4b82500722cb922fc76d370cbfc9f2e..5f5491004c9590df22a19fcf7964071515522e69 100644 (file)
@@ -1,6 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+       <classpathentry kind="src" path="src/main/java"/>
+       <classpathentry kind="src" path="src/main/resources"/>
+       <classpathentry kind="src" path="src/test/java"/>
+       <classpathentry kind="src" path="src/test/resources"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        <classpathentry kind="output" path="bin"/>
diff --git a/runtime/org.argeo.slc.support.jcr/.settings/org.eclipse.jdt.core.prefs b/runtime/org.argeo.slc.support.jcr/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..64aed8e
--- /dev/null
@@ -0,0 +1,12 @@
+#Sun Feb 21 12:26:27 CET 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/runtime/org.argeo.slc.support.jcr/.settings/org.eclipse.pde.core.prefs b/runtime/org.argeo.slc.support.jcr/.settings/org.eclipse.pde.core.prefs
new file mode 100644 (file)
index 0000000..79b086b
--- /dev/null
@@ -0,0 +1,3 @@
+#Thu Feb 18 16:48:02 CET 2010
+eclipse.preferences.version=1
+resolve.requirebundle=false
diff --git a/runtime/org.argeo.slc.support.jcr/build.properties b/runtime/org.argeo.slc.support.jcr/build.properties
new file mode 100644 (file)
index 0000000..ba373b6
--- /dev/null
@@ -0,0 +1,8 @@
+additional.bundles = org.springframework.core,\
+                     org.argeo.server.jackrabbit,\
+                     com.springsource.junit,\
+                     org.argeo.slc.unit,\
+                     org.argeo.slc.support.castor,\
+                     com.springsource.javax.xml.stream,\
+                     com.springsource.org.apache.xerces
+                     
\ No newline at end of file
diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/dao/SlcExecutionDaoJcr.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/dao/SlcExecutionDaoJcr.java
new file mode 100644 (file)
index 0000000..63cada0
--- /dev/null
@@ -0,0 +1,125 @@
+package org.argeo.slc.jcr.dao;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+
+import org.apache.commons.io.IOUtils;
+import org.argeo.jcr.BeanNodeMapper;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.dao.process.SlcExecutionDao;
+import org.argeo.slc.process.SlcExecution;
+import org.argeo.slc.process.SlcExecutionStep;
+import org.springframework.oxm.Marshaller;
+import org.springframework.xml.transform.StringResult;
+
+public class SlcExecutionDaoJcr implements SlcExecutionDao {
+       private Session session;
+
+       private Marshaller marshaller;
+
+       private BeanNodeMapper beanNodeMapper = new BeanNodeMapper();
+
+       public void addSteps(String slcExecutionId,
+                       List<SlcExecutionStep> additionalSteps) {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void create(SlcExecution slcExecution) {
+               StringResult result = new StringResult();
+               InputStream in = null;
+               try {
+                       beanNodeMapper.saveOrUpdate(getSession(), basePath(slcExecution),
+                                       slcExecution);
+
+                       // TODO: optimize with piped streams
+                       // marshaller.marshal(slcExecution, result);
+                       // in = new ByteArrayInputStream(result.toString().getBytes());
+                       //
+                       // String basePath = basePath(slcExecution);
+                       // JcrUtils.mkdirs(getSession(), basePath);
+                       //
+                       // session.importXML(basePath(slcExecution), in,
+                       // ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
+
+                       JcrUtils.debug(session.getRootNode());
+                       session.save();
+               } catch (Exception e) {
+                       throw new SlcException("Cannot import " + slcExecution, e);
+               } finally {
+                       IOUtils.closeQuietly(in);
+               }
+       }
+
+       protected String basePath(SlcExecution slcExecution) {
+               Calendar cal = new GregorianCalendar();
+               cal.setTime(new Date());
+               // cal.setTime(slcExecution.getStartDate());
+               return "/slc/processes/" + slcExecution.getHost().replace('.', '/')
+                               + '/' + JcrUtils.dateAsPath(cal) + slcExecution.getUuid();
+       }
+
+       public SlcExecution getSlcExecution(String uuid) {
+               try {
+                       Workspace workspace = session.getWorkspace();
+                       QueryManager qm = workspace.getQueryManager();
+
+                       String queryString = "//*[@uuid='" + uuid + "']";
+                       Query query = qm.createQuery(queryString, Query.XPATH);
+                       QueryResult queryResult = query.execute();
+                       NodeIterator nodeIterator = queryResult.getNodes();
+                       Node node;
+                       if (nodeIterator.hasNext())
+                               node = nodeIterator.nextNode();
+                       else
+                               throw new SlcException("Query returned no node.");
+
+                       if (nodeIterator.hasNext())
+                               throw new SlcException("Query returned more than one node.");
+
+                       return (SlcExecution) beanNodeMapper.nodeToBean(node);
+               } catch (Exception e) {
+                       throw new SlcException("Cannot load SLC execution " + uuid, e);
+               }
+       }
+
+       public List<SlcExecution> listSlcExecutions() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public void merge(SlcExecution slcExecution) {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void update(SlcExecution slcExecution) {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void setSession(Session session) {
+               this.session = session;
+       }
+
+       public void setMarshaller(Marshaller marshaller) {
+               this.marshaller = marshaller;
+       }
+
+       protected Session getSession() {
+               return session;
+       }
+
+}
diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/process/SlcExecutionDaoJcr.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/process/SlcExecutionDaoJcr.java
deleted file mode 100644 (file)
index b83b9fa..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.argeo.slc.jcr.process;
-
-public class SlcExecutionDaoJcr {
-
-}
diff --git a/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/dao/mapping.xml b/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/dao/mapping.xml
new file mode 100644 (file)
index 0000000..a5c2c29
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jackrabbit-ocm PUBLIC "-//The Apache Software Foundation//DTD Repository//EN" "http://jackrabbit.apache.org/dtd/jackrabbit-ocm-1.5.dtd">
+<jackrabbit-ocm>
+       <class-descriptor className="Type" jcrType="my:type"
+               jcrSuperTypes="nt:base" jcrMixinTypes="mix:referenceable">
+               <field-descriptor fieldName="path" path="true" />
+               <field-descriptor fieldName="uuid" uuid="true" />
+               <field-descriptor fieldName="name" jcrName="my:name"
+                       jcrMandatory="true" />
+               <field-descriptor fieldName="description" jcrName="my:description" />
+       </class-descriptor>
+       <class-descriptor className="Element" jcrType="my:element"
+               jcrSuperTypes="nt:base" jcrMixinTypes="mix:versionable">
+               <field-descriptor fieldName="path" path="true" />
+               <field-descriptor fieldName="uuid" uuid="true" />
+               <field-descriptor fieldName="name" jcrName="my:name"
+                       jcrMandatory="true" />
+               <field-descriptor fieldName="description" jcrName="my:description" />
+               <bean-descriptor fieldName="type" jcrName="my:type"
+                       proxy="false" jcrType="my:type" jcrMandatory="true"
+                       jcrOnParentVersion="IGNORE"
+                       converter="org.apache.jackrabbit.ocm.manager.beanconverter.impl.ReferenceBeanConverterImpl" />
+       </class-descriptor>
+</jackrabbit-ocm> 
\ No newline at end of file
diff --git a/runtime/org.argeo.slc.support.jcr/src/test/java/org/argeo/slc/jcr/dao/SlcExecutionDaoJcrTest.java b/runtime/org.argeo.slc.support.jcr/src/test/java/org/argeo/slc/jcr/dao/SlcExecutionDaoJcrTest.java
new file mode 100644 (file)
index 0000000..fe07d2c
--- /dev/null
@@ -0,0 +1,27 @@
+package org.argeo.slc.jcr.dao;
+
+import java.net.InetAddress;
+
+import org.argeo.slc.dao.process.SlcExecutionDao;
+import org.argeo.slc.process.SlcExecution;
+import org.argeo.slc.unit.AbstractSpringTestCase;
+import org.argeo.slc.unit.process.SlcExecutionTestUtils;
+
+public class SlcExecutionDaoJcrTest extends AbstractSpringTestCase {
+       public void testCreate() throws Exception {
+               SlcExecutionDao slcExecutionDao = getBean(SlcExecutionDao.class);
+
+               // SlcExecution slcExecution = SlcExecutionTestUtils
+               // .createSimpleSlcExecution();
+               SlcExecution slcExecution = SlcExecutionTestUtils
+                               .createSlcExecutionWithRealizedFlows();
+               slcExecution.setHost(InetAddress.getLocalHost().getCanonicalHostName());
+               String uuid = slcExecution.getUuid();
+               slcExecutionDao.create(slcExecution);
+
+               SlcExecution slcExecutionPersist = slcExecutionDao
+                               .getSlcExecution(uuid);
+               SlcExecutionTestUtils.assertSlcExecution(slcExecution,
+                               slcExecutionPersist);
+       }
+}
diff --git a/runtime/org.argeo.slc.support.jcr/src/test/resources/org/argeo/slc/jcr/dao/applicationContext.xml b/runtime/org.argeo.slc.support.jcr/src/test/resources/org/argeo/slc/jcr/dao/applicationContext.xml
new file mode 100644 (file)
index 0000000..ce0d1e5
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
+\r
+       <import resource="classpath:/org/argeo/slc/castor/spring.xml" />\r
+\r
+       <bean id="slcExecutionDao" class="org.argeo.slc.jcr.dao.SlcExecutionDaoJcr">\r
+               <property name="marshaller" ref="slcDefault.castor.marshaller" />\r
+               <property name="session" ref="argeo.jcr.session.inMemory" />\r
+       </bean>\r
+\r
+       <bean id="argeo.jcr.session.inMemory" factory-bean="argeo.jcr.repository.inMemory"\r
+               factory-method="login">\r
+               <constructor-arg>\r
+                       <bean class="javax.jcr.SimpleCredentials">\r
+                               <constructor-arg value="demo" />\r
+                               <constructor-arg value="demo" />\r
+                       </bean>\r
+               </constructor-arg>\r
+       </bean>\r
+\r
+       <bean id="argeo.jcr.repository.inMemory" class="org.argeo.server.jackrabbit.JackrabbitContainer">\r
+               <property name="homeDirectory" value="${java.io.tmpdir}/jackrabbit-slc-unit" />\r
+               <property name="configuration"\r
+                       value="classpath:/org/argeo/server/jackrabbit/repository-inMemory.xml" />\r
+       </bean>\r
+\r
+</beans>
\ No newline at end of file