From 1bceb63f40e3bd569ba12bd746d455fbc7250aba Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Tue, 9 Jun 2009 11:56:12 +0000
Subject: [PATCH] LMS-916 introducing IPhosphoNetXDAOFactory,
 IPhosphoNetXServer and implementations.

SVN: 11296
---
 rtd_phosphonetx/.classpath                    |  2 +
 .../phosphonetx/server/PhosphoNetXServer.java | 62 +++++++++++++++++
 .../server/PhosphoNetXServerLogger.java       | 66 +++++++++++++++++++
 .../dataaccess/IPhosphoNetXDAOFactory.java    | 27 ++++++++
 .../dataaccess/db/PhosphoNetXDAOFactory.java  | 65 ++++++++++++++++++
 .../shared/IPhosphoNetXServer.java            | 29 ++++++++
 .../phosphonetx/shared/ResourceNames.java     | 36 ++++++++++
 .../java/phosphonetx-applicationContext.xml   |  6 +-
 8 files changed, 291 insertions(+), 2 deletions(-)
 create mode 100644 rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java
 create mode 100644 rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServerLogger.java
 create mode 100644 rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IPhosphoNetXDAOFactory.java
 create mode 100644 rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/db/PhosphoNetXDAOFactory.java
 create mode 100644 rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/IPhosphoNetXServer.java
 create mode 100644 rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/ResourceNames.java

diff --git a/rtd_phosphonetx/.classpath b/rtd_phosphonetx/.classpath
index 66d17f9b5b7..605f3fd7c87 100644
--- a/rtd_phosphonetx/.classpath
+++ b/rtd_phosphonetx/.classpath
@@ -22,5 +22,7 @@
 			<attribute name="javadoc_location" value="jar:platform:/resource/libraries/ext-gwt/gxt-api.zip!/"/>
 		</attributes>
 	</classpathentry>
+	<classpathentry kind="lib" path="/libraries/restrictionchecker/restrictions.jar"/>
+	<classpathentry kind="lib" path="/libraries/spring/spring.jar" sourcepath="/libraries/spring/src.jar"/>
 	<classpathentry kind="output" path="targets/classes"/>
 </classpath>
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java
new file mode 100644
index 00000000000..96e5fb1c2dc
--- /dev/null
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java
@@ -0,0 +1,62 @@
+/*
+ * 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.plugin.phosphonetx.server;
+
+import org.springframework.stereotype.Component;
+
+import ch.rinn.restrictions.Private;
+import ch.systemsx.cisd.authentication.ISessionManager;
+import ch.systemsx.cisd.openbis.generic.server.AbstractServer;
+import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
+import ch.systemsx.cisd.openbis.generic.server.plugin.IDataSetTypeSlaveServerPlugin;
+import ch.systemsx.cisd.openbis.generic.server.plugin.ISampleTypeSlaveServerPlugin;
+import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
+import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.IPhosphoNetXServer;
+import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.ResourceNames;
+
+/**
+ * @author Franz-Josef Elmer
+ */
+@Component(ResourceNames.PHOSPHONETX_PLUGIN_SERVER)
+public class PhosphoNetXServer extends AbstractServer<IPhosphoNetXServer> implements
+        IPhosphoNetXServer
+{
+    public PhosphoNetXServer()
+    {
+        super();
+    }
+
+    @Private
+    PhosphoNetXServer(ISessionManager<Session> sessionManager, IDAOFactory daoFactory,
+            ISampleTypeSlaveServerPlugin sampleTypeSlaveServerPlugin,
+            IDataSetTypeSlaveServerPlugin dataSetTypeSlaveServerPlugin)
+    {
+        super(sessionManager, daoFactory, sampleTypeSlaveServerPlugin, dataSetTypeSlaveServerPlugin);
+    }
+
+    @Override
+    protected Class<IPhosphoNetXServer> getProxyInterface()
+    {
+        return IPhosphoNetXServer.class;
+    }
+
+    public IPhosphoNetXServer createLogger(boolean invocationSuccessful)
+    {
+        return new PhosphoNetXServerLogger(getSessionManager(), invocationSuccessful);
+    }
+    
+}
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServerLogger.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServerLogger.java
new file mode 100644
index 00000000000..c6e8456d400
--- /dev/null
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServerLogger.java
@@ -0,0 +1,66 @@
+/*
+ * 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.plugin.phosphonetx.server;
+
+import java.util.List;
+
+import ch.systemsx.cisd.authentication.ISessionManager;
+import ch.systemsx.cisd.common.exceptions.UserFailureException;
+import ch.systemsx.cisd.openbis.generic.server.AbstractServerLogger;
+import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
+import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentPE;
+import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO;
+import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
+import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
+import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.IPhosphoNetXServer;
+
+/**
+ * 
+ *
+ * @author Franz-Josef Elmer
+ */
+public class PhosphoNetXServerLogger extends AbstractServerLogger implements IPhosphoNetXServer
+{
+    PhosphoNetXServerLogger(final ISessionManager<Session> sessionManager,
+            final boolean invocationSuccessful)
+    {
+        super(sessionManager, invocationSuccessful);
+    }
+
+    public SampleGenerationDTO getSampleInfo(String sessionToken, SampleIdentifier sampleIdentifier)
+            throws UserFailureException
+    {
+        logAccess(sessionToken, "get_sample_info", "CODE(%s)", sampleIdentifier);
+        return null;
+    }
+
+    public SampleGenerationDTO getSampleInfo(String sessionToken, TechId sampleId)
+            throws UserFailureException
+    {
+        logAccess(sessionToken, "get_sample_info", "ID(%s)", sampleId);
+        return null;
+    }
+
+    public void registerSample(String sessionToken, NewSample newSample,
+            List<AttachmentPE> attachments)
+    {
+        logTracking(sessionToken, "register_sample", "SAMPLE_TYPE(%s) SAMPLE(%s) ATTACHMENTS(%s)",
+                newSample.getSampleType(), newSample.getIdentifier(), attachments.size());
+    }
+
+}
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IPhosphoNetXDAOFactory.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IPhosphoNetXDAOFactory.java
new file mode 100644
index 00000000000..f7f64dea176
--- /dev/null
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IPhosphoNetXDAOFactory.java
@@ -0,0 +1,27 @@
+/*
+ * 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.plugin.phosphonetx.server.dataaccess;
+
+/**
+ * 
+ *
+ * @author Franz-Josef Elmer
+ */
+public interface IPhosphoNetXDAOFactory
+{
+
+}
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/db/PhosphoNetXDAOFactory.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/db/PhosphoNetXDAOFactory.java
new file mode 100644
index 00000000000..2bdb0da0e79
--- /dev/null
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/db/PhosphoNetXDAOFactory.java
@@ -0,0 +1,65 @@
+/*
+ * 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.plugin.phosphonetx.server.dataaccess.db;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import net.lemnik.eodsql.QueryTool;
+
+import org.apache.log4j.Logger;
+
+import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
+import ch.systemsx.cisd.common.logging.LogCategory;
+import ch.systemsx.cisd.common.logging.LogFactory;
+import ch.systemsx.cisd.dbmigration.DBMigrationEngine;
+import ch.systemsx.cisd.dbmigration.DatabaseConfigurationContext;
+import ch.systemsx.cisd.openbis.plugin.phosphonetx.server.dataaccess.IPhosphoNetXDAOFactory;
+import ch.systemsx.cisd.phosphonetx.db.IProtDAO;
+
+/**
+ * 
+ *
+ * @author Franz-Josef Elmer
+ */
+public class PhosphoNetXDAOFactory implements IPhosphoNetXDAOFactory
+{
+    /** Current version of the database. */
+    public static final String DATABASE_VERSION = "001";
+    
+    private static final Logger operationLog =
+        LogFactory.getLogger(LogCategory.OPERATION, PhosphoNetXDAOFactory.class);
+
+    public PhosphoNetXDAOFactory(DatabaseConfigurationContext context)
+    {
+        DBMigrationEngine.createOrMigrateDatabaseAndGetScriptProvider(context, DATABASE_VERSION);
+        Connection connection = null;
+        try
+        {
+            connection = context.getDataSource().getConnection();
+        } catch (SQLException ex)
+        {
+            throw CheckedExceptionTunnel.wrapIfNecessary(ex);
+        }
+        QueryTool.getQuery(connection, IProtDAO.class);
+        if (operationLog.isInfoEnabled())
+        {
+            operationLog.info("DAO factory for PhosphoNetX created.");
+        }
+    }
+
+}
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/IPhosphoNetXServer.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/IPhosphoNetXServer.java
new file mode 100644
index 00000000000..e72021c36f8
--- /dev/null
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/IPhosphoNetXServer.java
@@ -0,0 +1,29 @@
+/*
+ * 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.plugin.phosphonetx.shared;
+
+import ch.systemsx.cisd.openbis.generic.shared.IServer;
+
+/**
+ * 
+ *
+ * @author Franz-Josef Elmer
+ */
+public interface IPhosphoNetXServer extends IServer
+{
+
+}
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/ResourceNames.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/ResourceNames.java
new file mode 100644
index 00000000000..e12af898d9c
--- /dev/null
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/shared/ResourceNames.java
@@ -0,0 +1,36 @@
+/*
+ * 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.plugin.phosphonetx.shared;
+
+/**
+ * 
+ *
+ * @author Franz-Josef Elmer
+ */
+public class ResourceNames
+{
+    private ResourceNames()
+    {
+    }
+
+    public final static String PHOSPHONETX_PLUGIN_SERVICE = "phosphonetx-plugin-service";
+
+    public final static String PHOSPHONETX_PLUGIN_SERVER = "phosphonetx-plugin-server";
+    
+    public final static String PHOSPHONETX_DAO_FACTORY = "phosphonetx-dao-factory";
+
+}
diff --git a/rtd_phosphonetx/source/java/phosphonetx-applicationContext.xml b/rtd_phosphonetx/source/java/phosphonetx-applicationContext.xml
index c056a6b647b..c68cbeee9d4 100644
--- a/rtd_phosphonetx/source/java/phosphonetx-applicationContext.xml
+++ b/rtd_phosphonetx/source/java/phosphonetx-applicationContext.xml
@@ -29,6 +29,8 @@
         <property name="databaseInstance" value="${phosphonetx.database-instance}" />
     </bean>
     
-    <bean id="phosphonetx-data-source" factory-bean="phosphonetx-db-configuration-context" factory-method="getDataSource" />
-
+    <bean id="phosphonetx-dao-factory"
+          class="ch.systemsx.cisd.openbis.plugin.phosphonetx.server.dataaccess.db.PhosphoNetXDAOFactory">
+        <constructor-arg ref="phosphonetx-db-configuration-context"/>
+    </bean>
 </beans>
\ No newline at end of file
-- 
GitLab