<?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"/>
--- /dev/null
+#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
--- /dev/null
+#Thu Feb 18 16:48:02 CET 2010
+eclipse.preferences.version=1
+resolve.requirebundle=false
--- /dev/null
+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
--- /dev/null
+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;
+ }
+
+}
+++ /dev/null
-package org.argeo.slc.jcr.process;
-
-public class SlcExecutionDaoJcr {
-
-}
--- /dev/null
+<?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
--- /dev/null
+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);
+ }
+}
--- /dev/null
+<?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