From b0087ee4c2ec26b44c27a0de4d4237f52aa4e8dc Mon Sep 17 00:00:00 2001
From: ribeaudc <ribeaudc>
Date: Mon, 24 Nov 2008 15:28:33 +0000
Subject: [PATCH] [LMS-654] change: - Clean DAOs. remove: - 'SamplePropertyDAO'
 as it does not seem to be used.

SVN: 9086
---
 .../business/bo/AbstractBusinessObject.java   |   6 -
 .../server/dataaccess/IDAOFactory.java        |   5 -
 .../server/dataaccess/db/DAOFactory.java      |  12 +-
 .../dataaccess/db/EntityPropertyTypeDAO.java  |   4 +
 .../server/dataaccess/db/EntityTypeDAO.java   |  17 ++-
 .../server/dataaccess/db/PropertyTypeDAO.java |   4 +
 .../dataaccess/db/RoleAssignmentDAO.java      |   7 +-
 .../server/dataaccess/db/SampleDAO.java       |   8 +-
 .../dataaccess/db/SamplePropertyDAO.java      | 111 ------------------
 .../dataaccess/db/SamplePropertyDAOTest.java  |  92 ---------------
 10 files changed, 32 insertions(+), 234 deletions(-)
 delete mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SamplePropertyDAO.java
 delete mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SamplePropertyDAOTest.java

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java
index e509ba53fa0..35aa05107e6 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java
@@ -30,7 +30,6 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IPersonDAO;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.IPropertyTypeDAO;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.IRoleAssignmentDAO;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleDAO;
-import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISamplePropertyDAO;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleTypeDAO;
 import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
@@ -109,11 +108,6 @@ abstract class AbstractBusinessObject implements IDAOFactory
         return daoFactory.getSampleTypeDAO();
     }
 
-    public final ISamplePropertyDAO getSamplePropertyDAO()
-    {
-        return daoFactory.getSamplePropertyDAO();
-    }
-
     public final IExternalDataDAO getExternalDataDAO()
     {
         return daoFactory.getExternalDataDAO();
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDAOFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDAOFactory.java
index 013088b13da..407860d8756 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDAOFactory.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IDAOFactory.java
@@ -36,11 +36,6 @@ public interface IDAOFactory extends IAuthorizationDAOFactory
      */
     public ISampleTypeDAO getSampleTypeDAO();
 
-    /**
-     * Returns the {@link ISamplePropertyDAO} implementation.
-     */
-    public ISamplePropertyDAO getSamplePropertyDAO();
-
     /**
      * Returns the {@link IExternalDataDAO} implementation.
      */
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DAOFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DAOFactory.java
index 3158f5d278d..93fdf095f54 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DAOFactory.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DAOFactory.java
@@ -29,12 +29,14 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IExternalDataDAO;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.IHibernateSearchDAO;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.IPropertyTypeDAO;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleDAO;
-import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISamplePropertyDAO;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleTypeDAO;
 import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE;
 import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind;
 
 /**
+ * {@link IDAOFactory} implementation working with {@link DatabaseConfigurationContext} and
+ * {@link SessionFactory}.
+ * 
  * @author Franz-Josef Elmer
  */
 public final class DAOFactory extends AuthorizationDAOFactory implements IDAOFactory
@@ -43,8 +45,6 @@ public final class DAOFactory extends AuthorizationDAOFactory implements IDAOFac
 
     private final ISampleTypeDAO sampleTypeDAO;
 
-    private final ISamplePropertyDAO samplePropertyDAO;
-
     private final IExternalDataDAO externalDataDAO;
 
     private final IHibernateSearchDAO hibernateSearchDAO;
@@ -64,7 +64,6 @@ public final class DAOFactory extends AuthorizationDAOFactory implements IDAOFac
         final DatabaseInstancePE databaseInstance = getHomeDatabaseInstance();
         sampleDAO = new SampleDAO(sessionFactory, databaseInstance);
         sampleTypeDAO = new SampleTypeDAO(sessionFactory, databaseInstance);
-        samplePropertyDAO = new SamplePropertyDAO(sessionFactory, databaseInstance);
         externalDataDAO = new ExternalDataDAO(sessionFactory, databaseInstance);
         hibernateSearchDAO = new HibernateSearchDAO(sessionFactory);
         propertyTypeDAO = new PropertyTypeDAO(sessionFactory, databaseInstance);
@@ -93,11 +92,6 @@ public final class DAOFactory extends AuthorizationDAOFactory implements IDAOFac
         return sampleTypeDAO;
     }
 
-    public final ISamplePropertyDAO getSamplePropertyDAO()
-    {
-        return samplePropertyDAO;
-    }
-
     public final IExternalDataDAO getExternalDataDAO()
     {
         return externalDataDAO;
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityPropertyTypeDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityPropertyTypeDAO.java
index 534463bdf70..fd9d3cfd166 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityPropertyTypeDAO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityPropertyTypeDAO.java
@@ -58,6 +58,10 @@ final class EntityPropertyTypeDAO extends AbstractDAO implements IEntityProperty
         return entityKind.getEntityTypePropertyTypeAssignmentClass();
     }
 
+    //
+    // IEntityPropertyTypeDAO
+    //
+
     public final List<EntityTypePropertyTypePE> listEntityPropertyTypes(
             final EntityTypePE entityType) throws DataAccessException
     {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityTypeDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityTypeDAO.java
index 5d2327bcdae..d754fa2a7e1 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityTypeDAO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/EntityTypeDAO.java
@@ -31,7 +31,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind;
  * 
  * @author Franz-Josef Elmer
  */
-class EntityTypeDAO extends AbstractTypeDAO<EntityTypePE> implements IEntityTypeDAO
+final class EntityTypeDAO extends AbstractTypeDAO<EntityTypePE> implements IEntityTypeDAO
 {
 
     private final EntityKind entityKind;
@@ -43,18 +43,27 @@ class EntityTypeDAO extends AbstractTypeDAO<EntityTypePE> implements IEntityType
         this.entityKind = entityKind;
     }
 
+    //
+    // AbstractTypeDAO
+    //
+
     @Override
-    Class<?> getEntityClass()
+    final Class<?> getEntityClass()
     {
         return entityKind.getTypeClass();
     }
 
-    public EntityTypePE tryToFindEntityTypeByCode(final String code) throws DataAccessException
+    //
+    // IEntityTypeDAO
+    //
+
+    public final EntityTypePE tryToFindEntityTypeByCode(final String code)
+            throws DataAccessException
     {
         return super.tryFindTypeByCode(code);
     }
 
-    public List<EntityTypePE> listEntityTypes() throws DataAccessException
+    public final List<EntityTypePE> listEntityTypes() throws DataAccessException
     {
         return super.listTypes();
     }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/PropertyTypeDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/PropertyTypeDAO.java
index d8ec8747cd8..66ee5bcdcfb 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/PropertyTypeDAO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/PropertyTypeDAO.java
@@ -50,6 +50,10 @@ final class PropertyTypeDAO extends AbstractDAO implements IPropertyTypeDAO
         super(sessionFactory, databaseInstance);
     }
 
+    //
+    // IPropertyTypeDAO
+    //
+
     public final PropertyTypePE tryFindPropertyTypeByCode(final String code)
             throws DataAccessException
     {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/RoleAssignmentDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/RoleAssignmentDAO.java
index 1a474fa43b5..c07333e19e3 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/RoleAssignmentDAO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/RoleAssignmentDAO.java
@@ -108,8 +108,8 @@ public final class RoleAssignmentDAO extends AbstractDAO implements IRoleAssignm
         }
     }
 
-    public RoleAssignmentPE tryFindGroupRoleAssignment(final RoleCode role, final String group,
-            final String person)
+    public final RoleAssignmentPE tryFindGroupRoleAssignment(final RoleCode role,
+            final String group, final String person)
     {
         List<RoleAssignmentPE> roles;
         roles =
@@ -129,7 +129,8 @@ public final class RoleAssignmentDAO extends AbstractDAO implements IRoleAssignm
 
     }
 
-    public RoleAssignmentPE tryFindInstanceRoleAssignment(final RoleCode role, final String person)
+    public final RoleAssignmentPE tryFindInstanceRoleAssignment(final RoleCode role,
+            final String person)
     {
         List<RoleAssignmentPE> roles;
         roles =
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SampleDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SampleDAO.java
index d4c4f51e607..714afef402b 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SampleDAO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SampleDAO.java
@@ -85,6 +85,10 @@ public class SampleDAO extends AbstractDAO implements ISampleDAO
         }
     }
 
+    //
+    // ISampleDAO
+    //
+
     public final void createSample(final SamplePE sample) throws DataAccessException
     {
         assert sample != null : "Unspecified sample";
@@ -101,10 +105,6 @@ public class SampleDAO extends AbstractDAO implements ISampleDAO
         }
     }
 
-    //
-    // ISampleDAO
-    //
-
     public final List<SamplePE> listSamplesByTypeAndGroup(final SampleTypePE sampleType,
             final GroupPE group) throws DataAccessException
     {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SamplePropertyDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SamplePropertyDAO.java
deleted file mode 100644
index 932b91cc42f..00000000000
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SamplePropertyDAO.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2007 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.generic.server.dataaccess.db;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.hibernate.SessionFactory;
-import org.springframework.dao.DataAccessException;
-
-import ch.rinn.restrictions.Private;
-import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISamplePropertyDAO;
-import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE;
-import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE;
-import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePropertyPE;
-import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE;
-import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleOwnerIdentifier;
-
-/**
- * Data access object for {@link SamplePropertyPE}.
- * 
- * @author Izabela Adamczyk
- */
-final class SamplePropertyDAO extends AbstractDAO implements ISamplePropertyDAO
-{
-
-    SamplePropertyDAO(final SessionFactory sessionFactory, final DatabaseInstancePE databaseInstance)
-    {
-        super(sessionFactory, databaseInstance);
-    }
-
-    public List<SamplePropertyPE> listSampleProperties(SampleOwnerIdentifier ownerIdentifier,
-            SampleTypePE sampleType, List<PropertyTypePE> propertyCodes) throws DataAccessException
-    {
-        String query;
-        Object[] args;
-
-        String joinClouse =
-                "join fetch sp.entityTypePropertyType"
-                        + " join fetch sp.entityTypePropertyType.propertyType"
-                        + " join fetch sp.entity";
-        if (ownerIdentifier.isDatabaseInstanceLevel())
-        {
-            query =
-                    "from %s sp "
-                            + joinClouse
-                            + " where sp.entityTypePropertyType.entityTypeInternal.code = ? and sp.entity.databaseInstance.code = ?"
-                            + " and  %s";
-            args =
-                    new Object[]
-                        {
-                                sampleType.getCode(),
-                                ownerIdentifier.getDatabaseInstanceLevel()
-                                        .getDatabaseInstanceCode() };
-        } else
-        {
-            query =
-                    "from %s sp "
-                            + joinClouse
-                            + " where sp.entityTypePropertyType.entityTypeInternal.code = ? and sp.entity.group.code = ?"
-                            + " and sp.entity.group.databaseInstance.code = ? and %s";
-            args =
-                    new Object[]
-                        { sampleType.getCode(), ownerIdentifier.getGroupLevel().getGroupCode(),
-                                ownerIdentifier.getGroupLevel().getDatabaseInstanceCode() };
-        }
-        final String format =
-                String.format(query, SamplePropertyPE.class.getSimpleName(),
-                        extractCodes(propertyCodes));
-        return cast(getHibernateTemplate().find(format, args));
-    }
-
-    @Private
-    public static String extractCodes(List<PropertyTypePE> propertyCodes)
-    {
-        assert propertyCodes.size() > 0 : "no properties specified";
-        StringBuilder sb = new StringBuilder();
-        sb.append("(");
-        Iterator<PropertyTypePE> it = propertyCodes.iterator();
-        appendNextEncoded(sb, it);
-        while (it.hasNext())
-        {
-            sb.append(" OR ");
-            appendNextEncoded(sb, it);
-        }
-        sb.append(")");
-        return sb.toString();
-    }
-
-    private static void appendNextEncoded(StringBuilder sb, Iterator<PropertyTypePE> it)
-    {
-        final PropertyTypePE next = it.next();
-        sb.append("sp.entityTypePropertyType.propertyType.simpleCode = '" + next.getSimpleCode()
-                + "' AND sp.entityTypePropertyType.propertyType.internalNamespace = "
-                + next.isInternalNamespace() + "");
-    }
-}
\ No newline at end of file
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SamplePropertyDAOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SamplePropertyDAOTest.java
deleted file mode 100644
index 77aeaef972b..00000000000
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/SamplePropertyDAOTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2007 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.generic.server.dataaccess.db;
-
-import static org.testng.AssertJUnit.assertNotNull;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.testng.annotations.Test;
-
-import ch.rinn.restrictions.Friend;
-import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE;
-import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE;
-import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
-import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE;
-import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
-import ch.systemsx.cisd.openbis.generic.shared.dto.types.SampleTypeCode;
-
-/**
- * Test cases for corresponding {@link SamplePropertyDAO} class.
- * 
- * @author Izabela Adamczyk
- */
-@Friend(toClasses = SamplePropertyDAO.class)
-@Test(groups =
-    { "db", "sampleProperty" })
-public final class SamplePropertyDAOTest extends AbstractDAOTest
-{
-
-    @Test
-    public void testListProperties() throws Exception
-    {
-
-        SampleTypePE type =
-                daoFactory.getSampleTypeDAO().tryFindSampleTypeByCode(
-                        SampleTypeCode.MASTER_PLATE.getCode());
-        DatabaseInstancePE instance = daoFactory.getDatabaseInstanceDAO().getHomeInstance();
-        GroupPE group = getTestPerson().getHomeGroup();
-        assertNotNull(group);
-
-        SamplePE instanceSample = createInstanceSample(type, instance);
-        SamplePE groupSample = createGroupSample(type, group);
-
-        final List<String> propertyCodes = new ArrayList<String>();
-        propertyCodes.add("USER.DESCRIPTION");
-
-        List<SampleIdentifier> identifiers = new ArrayList<SampleIdentifier>();
-        identifiers.add(instanceSample.getSampleIdentifier());
-        identifiers.add(groupSample.getSampleIdentifier());
-
-        // TODO 2008-11-11, Franz-Josef Elmer: Incomplete test.
-        // daoFactory.getSamplePropertyDAO().listSampleProperties(identifiers, propertyCodes);
-    }
-
-    private SamplePE createGroupSample(SampleTypePE type, GroupPE group)
-    {
-        SamplePE sample = new SamplePE();
-        sample.setCode("GROUP_SAMPLE");
-        sample.setRegistrator(getSystemPerson());
-        sample.setGroup(group);
-        sample.setSampleType(type);
-        daoFactory.getSampleDAO().createSample(sample);
-        return sample;
-    }
-
-    private SamplePE createInstanceSample(SampleTypePE type, DatabaseInstancePE instance)
-    {
-        SamplePE sample = new SamplePE();
-        sample.setCode("INSTANCE_SAMPLE");
-        sample.setRegistrator(getSystemPerson());
-        sample.setDatabaseInstance(instance);
-        sample.setSampleType(type);
-        daoFactory.getSampleDAO().createSample(sample);
-        return sample;
-    }
-
-}
-- 
GitLab