From af1bcb1c89ff2c93a28fb41c6ac9366cfec313a6 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Fri, 24 Jun 2011 15:11:50 +0000
Subject: [PATCH] [LMS-2301] sketch of the framework

SVN: 21843
---
 .../jython/JythonBasedPluginUtils.java        | 133 ++++++++++++++++++
 .../jython/JythonBasedProcessingPlugin.java   |  88 ++++++++++++
 .../jython/JythonBasedReportingPlugin.java    |  86 +++++++++++
 .../server/plugins/jython/api/IDataSet.java   |  68 +++++++++
 4 files changed, 375 insertions(+)
 create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedPluginUtils.java
 create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedProcessingPlugin.java
 create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedReportingPlugin.java
 create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/api/IDataSet.java

diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedPluginUtils.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedPluginUtils.java
new file mode 100644
index 00000000000..8388fdc91d0
--- /dev/null
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedPluginUtils.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2009 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython;
+
+import ch.systemsx.cisd.common.io.IHierarchicalContent;
+import ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython.api.IDataSet;
+import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
+
+/**
+ * Utility methods for reporting and processing plugins delegating the work to a Jython script.
+ * 
+ * @author Piotr Buczek
+ */
+public class JythonBasedPluginUtils
+{
+    /**
+     * @return an instance of {@link IDataSet} based on given {@link DatasetDescription} and
+     *         {@link IHierarchicalContent}
+     */
+    static IDataSet createDataSet(final DatasetDescription description,
+            final IHierarchicalContent content)
+    {
+        return new IDataSet()
+            {
+                public IHierarchicalContent getContent()
+                {
+                    return content;
+                }
+
+                // delegator to description
+
+                public int getSpeedHint()
+                {
+                    return description.getSpeedHint();
+                }
+
+                public String getSpaceCode()
+                {
+                    return description.getSpaceCode();
+                }
+
+                public String getSampleTypeCode()
+                {
+                    return description.getSampleTypeCode();
+                }
+
+                public String getSampleIdentifier()
+                {
+                    return description.getSampleIdentifier();
+                }
+
+                public String getSampleCode()
+                {
+                    return description.getSampleCode();
+                }
+
+                public String getProjectCode()
+                {
+                    return description.getProjectCode();
+                }
+
+                public String getMainDataSetPattern()
+                {
+                    return description.getMainDataSetPattern();
+                }
+
+                public String getMainDataSetPath()
+                {
+                    return description.getMainDataSetPath();
+                }
+
+                public String getInstanceCode()
+                {
+                    return description.getInstanceCode();
+                }
+
+                public String getExperimentTypeCode()
+                {
+                    return description.getExperimentTypeCode();
+                }
+
+                public String getExperimentIdentifier()
+                {
+                    return description.getExperimentIdentifier();
+                }
+
+                public String getExperimentCode()
+                {
+                    return description.getExperimentCode();
+                }
+
+                public String getDatasetTypeCode()
+                {
+                    return description.getDatasetTypeCode();
+                }
+
+                public String getDatabaseInstanceCode()
+                {
+                    return description.getDatabaseInstanceCode();
+                }
+
+                public Long getDataSetSize()
+                {
+                    return description.getDataSetSize();
+                }
+
+                public String getDataSetLocation()
+                {
+                    return description.getDataSetLocation();
+                }
+
+                public String getDataSetCode()
+                {
+                    return description.getDataSetCode();
+                }
+
+            };
+    }
+}
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedProcessingPlugin.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedProcessingPlugin.java
new file mode 100644
index 00000000000..030cc54c81b
--- /dev/null
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedProcessingPlugin.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2009 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython;
+
+import java.io.File;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+
+import ch.systemsx.cisd.common.exceptions.Status;
+import ch.systemsx.cisd.common.io.IHierarchicalContent;
+import ch.systemsx.cisd.common.logging.LogCategory;
+import ch.systemsx.cisd.common.logging.LogFactory;
+import ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython.api.IDataSet;
+import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.IProcessingPluginTask;
+import ch.systemsx.cisd.openbis.dss.generic.shared.DataSetProcessingContext;
+import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider;
+import ch.systemsx.cisd.openbis.dss.generic.shared.ProcessingStatus;
+import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider;
+import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
+
+/**
+ * Processing plugin which delegates the processing to a Jython script.
+ * 
+ * @author Piotr Buczek
+ */
+public class JythonBasedProcessingPlugin implements IProcessingPluginTask
+{
+    private static final long serialVersionUID = 1L;
+
+    private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION,
+            JythonBasedProcessingPlugin.class);
+
+    public JythonBasedProcessingPlugin(Properties properties, File storeRoot)
+    {
+    }
+
+    public ProcessingStatus process(List<DatasetDescription> datasets,
+            DataSetProcessingContext context)
+    {
+        operationLog.info("Processing of the following datasets has been requested: " + datasets);
+        final IHierarchicalContentProvider contentProvider =
+                ServiceProvider.getHierarchicalContentProvider();
+
+        ProcessingStatus result = new ProcessingStatus();
+
+        for (DatasetDescription dataset : datasets)
+        {
+            String dataSetCode = dataset.getDataSetCode();
+            IHierarchicalContent content = null;
+            try
+            {
+                content = contentProvider.asContent(dataSetCode);
+                IDataSet iDataSet = JythonBasedPluginUtils.createDataSet(dataset, content);
+                result.addDatasetStatus(dataSetCode, delegateProcessing(iDataSet));
+            } finally
+            {
+                if (content != null)
+                {
+                    content.close();
+                }
+            }
+        }
+        operationLog.info("Processing done.");
+        return null;
+    }
+
+    private Status delegateProcessing(IDataSet iDataSet)
+    {
+        return Status.OK; // TODO
+    }
+
+}
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedReportingPlugin.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedReportingPlugin.java
new file mode 100644
index 00000000000..ae364e1d1b1
--- /dev/null
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/JythonBasedReportingPlugin.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2009 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython;
+
+import java.io.File;
+import java.util.List;
+import java.util.Properties;
+
+import ch.systemsx.cisd.common.io.IHierarchicalContent;
+import ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython.api.IDataSet;
+import ch.systemsx.cisd.openbis.dss.generic.server.plugins.standard.AbstractTableModelReportingPlugin;
+import ch.systemsx.cisd.openbis.dss.generic.shared.DataSetProcessingContext;
+import ch.systemsx.cisd.openbis.dss.generic.shared.IHierarchicalContentProvider;
+import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
+import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription;
+import ch.systemsx.cisd.openbis.generic.shared.util.SimpleTableModelBuilder;
+
+/**
+ * Reporting plugin which delegates the creation of report to a Jython script.
+ * 
+ * @author Piotr Buczek
+ */
+public class JythonBasedReportingPlugin extends AbstractTableModelReportingPlugin
+{
+    private static final long serialVersionUID = 1L;
+
+    public JythonBasedReportingPlugin(Properties properties, File storeRoot)
+    {
+        super(properties, storeRoot);
+    }
+
+    public TableModel createReport(List<DatasetDescription> datasets,
+            DataSetProcessingContext context)
+    {
+        operationLog.info("Reporting for the following datasets has been requested: " + datasets);
+        IHierarchicalContentProvider contentProvider =
+                ServiceProvider.getHierarchicalContentProvider();
+        SimpleTableModelBuilder builder = new SimpleTableModelBuilder();
+
+        for (DatasetDescription dataset : datasets)
+        {
+            describe(builder, dataset, contentProvider);
+        }
+        return builder.getTableModel();
+    }
+
+    private void describe(SimpleTableModelBuilder builder, DatasetDescription dataset,
+            IHierarchicalContentProvider contentProvider)
+    {
+        String dataSetCode = dataset.getDataSetCode();
+        IHierarchicalContent content = null;
+        try
+        {
+            content = contentProvider.asContent(dataSetCode);
+            IDataSet iDataSet = JythonBasedPluginUtils.createDataSet(dataset, content);
+            delegateDescribe(builder, iDataSet);
+        } finally
+        {
+            if (content != null)
+            {
+                content.close();
+            }
+        }
+    }
+
+    private void delegateDescribe(SimpleTableModelBuilder builder, IDataSet iDataSet)
+    {
+        // TODO Auto-generated method stub
+    }
+
+}
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/api/IDataSet.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/api/IDataSet.java
new file mode 100644
index 00000000000..5b778f574bf
--- /dev/null
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/jython/api/IDataSet.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2011 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython.api;
+
+import ch.systemsx.cisd.common.io.IHierarchicalContent;
+
+/**
+ * @author Piotr Buczek
+ */
+public interface IDataSet
+{
+    // TODO move IHierarchicalContent to an API package
+    IHierarchicalContent getContent();
+
+    // DatasetDescription
+
+    String getDataSetCode();
+
+    String getDatasetTypeCode();
+
+    Long getDataSetSize();
+
+    String getDataSetLocation();
+
+    String getInstanceCode();
+
+    int getSpeedHint();
+
+    String getMainDataSetPattern();
+
+    String getMainDataSetPath();
+
+    String getSpaceCode();
+
+    String getProjectCode();
+
+    String getDatabaseInstanceCode();
+
+    String getExperimentCode();
+
+    String getExperimentIdentifier();
+
+    String getExperimentTypeCode();
+
+    /**
+     * NOTE: below methods may return null
+     */
+
+    String getSampleCode();
+
+    String getSampleIdentifier();
+
+    String getSampleTypeCode();
+}
-- 
GitLab