From 2289df24f53a60969f64a74d77e18a0dbd9e54d3 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Mon, 31 Aug 2009 21:07:43 +0000
Subject: [PATCH] [LMS-1121] added attributes for all entity kinds

SVN: 12336
---
 .../DetailedSearchFieldsSelectionWidget.java  | 21 ++---
 .../search/detailed/DetailedQueryBuilder.java |  9 ++-
 .../search/detailed/IndexFieldNameHelper.java | 79 ++++++++++++++-----
 .../AttributeSearchFieldKindProvider.java     | 49 ++++++++++++
 .../dto/DataSetAttributeSearchFieldKind.java  |  4 +-
 .../ExperimentAttributeSearchFieldKind.java   | 53 +++++++++++++
 .../basic/dto/IAttributeSearchFieldKind.java  |  2 +
 .../dto/MaterialAttributeSearchFieldKind.java | 49 ++++++++++++
 .../dto/SampleAttributeSearchFieldKind.java   | 51 ++++++++++++
 9 files changed, 280 insertions(+), 37 deletions(-)
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/AttributeSearchFieldKindProvider.java
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentAttributeSearchFieldKind.java
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/MaterialAttributeSearchFieldKind.java
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchFieldsSelectionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchFieldsSelectionWidget.java
index 37230bc0113..760968ca3ae 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchFieldsSelectionWidget.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchFieldsSelectionWidget.java
@@ -35,18 +35,18 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet;
-import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetAttributeSearchFieldKind;
+import ch.systemsx.cisd.openbis.generic.shared.basic.AttributeSearchFieldKindProvider;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchFieldKind;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IAttributeSearchFieldKind;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
-import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchFieldKind;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind.ObjectKind;
 
 /**
- * {@link ComboBox} containing list of detailed search fields loaded from the server (property types) and
- * static ones.
+ * {@link ComboBox} containing list of detailed search fields loaded from the server (property
+ * types) and static ones.
  * 
  * @author Izabela Adamczyk
  * @author Piotr Buczek
@@ -54,7 +54,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKin
 // TODO 2009-02-13, Tomasz Pylak: fetching of property types is done every time a new widget is
 // created, although all of them are identical. It should be done outside of this class and passed
 // to it.
-// TODO 2009-08-31, Piotr Buczek: write code for remaining entity kinds
 public final class DetailedSearchFieldsSelectionWidget extends
         DropDownList<DetailedSearchFieldComboModel, PropertyType>
 {
@@ -193,7 +192,7 @@ public final class DetailedSearchFieldsSelectionWidget extends
     {
         final List<DetailedSearchFieldComboModel> result =
                 new ArrayList<DetailedSearchFieldComboModel>();
-        for (IAttributeSearchFieldKind attributeFieldKind : getAttributeFieldKinds())
+        for (IAttributeSearchFieldKind attributeFieldKind : getAllAttributeFieldKinds(entityKind))
         {
             DetailedSearchField attributeField =
                     DetailedSearchField.createAttributeField(attributeFieldKind);
@@ -213,15 +212,9 @@ public final class DetailedSearchFieldsSelectionWidget extends
         return result;
     }
 
-    private IAttributeSearchFieldKind[] getAttributeFieldKinds()
+    private static IAttributeSearchFieldKind[] getAllAttributeFieldKinds(EntityKind entityKind)
     {
-        switch (entityKind)
-        {
-            case DATA_SET:
-                return DataSetAttributeSearchFieldKind.values();
-            default:
-                throw new IllegalArgumentException("not yet implemented");
-        }
+        return AttributeSearchFieldKindProvider.getAllAttributeFieldKinds(entityKind);
     }
 
     private void addComplexFieldComboModel(List<DetailedSearchFieldComboModel> result,
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/DetailedQueryBuilder.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/DetailedQueryBuilder.java
index acd6eefa94b..8de3243af65 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/DetailedQueryBuilder.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/DetailedQueryBuilder.java
@@ -32,6 +32,7 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException;
 import ch.systemsx.cisd.common.logging.LogCategory;
 import ch.systemsx.cisd.common.logging.LogFactory;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.LuceneQueryBuilder;
+import ch.systemsx.cisd.openbis.generic.shared.basic.AttributeSearchFieldKindProvider;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField;
@@ -132,8 +133,7 @@ public class DetailedQueryBuilder
     private List<String> getAllAttributeIndexFieldNames()
     {
         List<String> indexFieldNames = new ArrayList<String>();
-        IAttributeSearchFieldKind[] attributeFieldKinds =
-                IndexFieldNameHelper.getAllAttributeFieldKinds(entityKind);
+        IAttributeSearchFieldKind[] attributeFieldKinds = getAllAttributeFieldKinds(entityKind);
         for (IAttributeSearchFieldKind attributeFieldKind : attributeFieldKinds)
         {
             DetailedSearchField attributeField =
@@ -143,6 +143,11 @@ public class DetailedQueryBuilder
         return indexFieldNames;
     }
 
+    private static IAttributeSearchFieldKind[] getAllAttributeFieldKinds(EntityKind entityKind)
+    {
+        return AttributeSearchFieldKindProvider.getAllAttributeFieldKinds(entityKind);
+    }
+
     private List<String> getPropertyIndexFields(DetailedSearchField searchField)
     {
         assert searchField.getKind() != DetailedSearchFieldKind.ATTRIBUTE : "attribute field kind not allowed";
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java
index ec3aea908f4..4aa7e9449fc 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java
@@ -18,10 +18,11 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.detailed;
 
 import static ch.systemsx.cisd.openbis.generic.shared.dto.hibernate.SearchFieldConstants.CODE;
 
-import ch.systemsx.cisd.common.exceptions.InternalErr;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetAttributeSearchFieldKind;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
-import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IAttributeSearchFieldKind;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentAttributeSearchFieldKind;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialAttributeSearchFieldKind;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleAttributeSearchFieldKind;
 import ch.systemsx.cisd.openbis.generic.shared.dto.hibernate.SearchFieldConstants;
 
 /**
@@ -29,7 +30,6 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.hibernate.SearchFieldConstant
  * 
  * @author Piotr Buczek
  */
-// TODO 2009-08-31, Piotr Buczek: write code for remaining entity kinds
 class IndexFieldNameHelper
 {
     // properties
@@ -42,17 +42,6 @@ class IndexFieldNameHelper
 
     // attributes
 
-    static IAttributeSearchFieldKind[] getAllAttributeFieldKinds(EntityKind entityKind)
-    {
-        switch (entityKind)
-        {
-            case DATA_SET:
-                return DataSetAttributeSearchFieldKind.values();
-            default:
-                throw new IllegalArgumentException("not implemented yet");
-        }
-    }
-
     static String getAttributeIndexField(EntityKind entityKind, String attributeCode)
     {
         switch (entityKind)
@@ -60,9 +49,17 @@ class IndexFieldNameHelper
             case DATA_SET:
                 return getDataSetAttributeIndexField(DataSetAttributeSearchFieldKind
                         .valueOf(attributeCode));
-            default:
-                throw new IllegalArgumentException("not implemented yet");
+            case EXPERIMENT:
+                return getExperimentAttributeIndexField(ExperimentAttributeSearchFieldKind
+                        .valueOf(attributeCode));
+            case MATERIAL:
+                return getMaterialAttributeIndexField(MaterialAttributeSearchFieldKind
+                        .valueOf(attributeCode));
+            case SAMPLE:
+                return getSampleAttributeIndexField(SampleAttributeSearchFieldKind
+                        .valueOf(attributeCode));
         }
+        return null; // cannot happen
     }
 
     private static String getDataSetAttributeIndexField(
@@ -70,14 +67,58 @@ class IndexFieldNameHelper
     {
         switch (attributeKind)
         {
-            case DATA_SET_CODE:
+            case CODE:
                 return CODE;
             case DATA_SET_TYPE:
                 return SearchFieldConstants.PREFIX_ENTITY_TYPE + CODE;
             case FILE_TYPE:
                 return SearchFieldConstants.PREFIX_FILE_FORMAT_TYPE + CODE;
-            default:
-                throw InternalErr.error("unknown enum " + attributeKind);
         }
+        return null; // cannot happen
+    }
+
+    private static String getExperimentAttributeIndexField(
+            ExperimentAttributeSearchFieldKind attributeKind)
+    {
+        switch (attributeKind)
+        {
+            case CODE:
+                return CODE;
+            case EXPERIMENT_TYPE:
+                return SearchFieldConstants.PREFIX_ENTITY_TYPE + CODE;
+            case PROJECT:
+                return SearchFieldConstants.PREFIX_PROJECT + CODE;
+            case PROJECT_GROUP:
+                return SearchFieldConstants.PREFIX_PROJECT + SearchFieldConstants.PREFIX_GROUP
+                        + CODE;
+        }
+        return null; // cannot happen
+    }
+
+    private static String getMaterialAttributeIndexField(
+            MaterialAttributeSearchFieldKind attributeKind)
+    {
+        switch (attributeKind)
+        {
+            case CODE:
+                return CODE;
+            case MATERIAL_TYPE:
+                return SearchFieldConstants.PREFIX_ENTITY_TYPE + CODE;
+        }
+        return null; // cannot happen
+    }
+
+    private static String getSampleAttributeIndexField(SampleAttributeSearchFieldKind attributeKind)
+    {
+        switch (attributeKind)
+        {
+            case CODE:
+                return CODE;
+            case SAMPLE_TYPE:
+                return SearchFieldConstants.PREFIX_ENTITY_TYPE + CODE;
+            case GROUP:
+                return SearchFieldConstants.PREFIX_GROUP + CODE;
+        }
+        return null; // cannot happen
     }
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/AttributeSearchFieldKindProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/AttributeSearchFieldKindProvider.java
new file mode 100644
index 00000000000..176f2df862e
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/AttributeSearchFieldKindProvider.java
@@ -0,0 +1,49 @@
+/*
+ * 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.generic.shared.basic;
+
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetAttributeSearchFieldKind;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentAttributeSearchFieldKind;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IAttributeSearchFieldKind;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialAttributeSearchFieldKind;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleAttributeSearchFieldKind;
+
+/**
+ * Common {@link IAttributeSearchFieldKind} provider used both on client and server side.
+ * 
+ * @author Piotr Buczek
+ */
+public class AttributeSearchFieldKindProvider
+{
+
+    public static IAttributeSearchFieldKind[] getAllAttributeFieldKinds(EntityKind entityKind)
+    {
+        switch (entityKind)
+        {
+            case DATA_SET:
+                return DataSetAttributeSearchFieldKind.values();
+            case EXPERIMENT:
+                return ExperimentAttributeSearchFieldKind.values();
+            case MATERIAL:
+                return MaterialAttributeSearchFieldKind.values();
+            case SAMPLE:
+                return SampleAttributeSearchFieldKind.values();
+        }
+        return null; // cannot happen
+    }
+}
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java
index 94d2c890d71..c7696fe1b9b 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java
@@ -19,13 +19,13 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
 import com.google.gwt.user.client.rpc.IsSerializable;
 
 /**
- * Kinds of fields connected with data set attributes that can be used in detailed text queries.
+ * Kinds of fields connected with Data Set attributes that can be used in detailed text queries.
  * 
  * @author Piotr Buczek
  */
 public enum DataSetAttributeSearchFieldKind implements IsSerializable, IAttributeSearchFieldKind
 {
-    DATA_SET_CODE("Code"),
+    CODE("Code"),
 
     DATA_SET_TYPE("Data Set Type"),
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentAttributeSearchFieldKind.java
new file mode 100644
index 00000000000..83b65a33283
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentAttributeSearchFieldKind.java
@@ -0,0 +1,53 @@
+/*
+ * 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.generic.shared.basic.dto;
+
+import com.google.gwt.user.client.rpc.IsSerializable;
+
+/**
+ * Kinds of fields connected with Experiment attributes that can be used in detailed text queries.
+ * 
+ * @author Piotr Buczek
+ */
+public enum ExperimentAttributeSearchFieldKind implements IsSerializable, IAttributeSearchFieldKind
+{
+    CODE("Code"),
+
+    EXPERIMENT_TYPE("Experiment Type"),
+
+    PROJECT("Group"),
+
+    PROJECT_GROUP("Project Group");
+
+    private final String description;
+
+    private ExperimentAttributeSearchFieldKind(String description)
+    {
+        this.description = description;
+    }
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public String getCode()
+    {
+        return name();
+    }
+
+}
\ No newline at end of file
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IAttributeSearchFieldKind.java
index 526be5d27a3..8ba9da25dd3 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IAttributeSearchFieldKind.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/IAttributeSearchFieldKind.java
@@ -17,6 +17,8 @@
 package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
 
 /**
+ * Kind of field connected with an entity attribute that can be used in detailed text queries.
+ * 
  * @author Piotr Buczek
  */
 public interface IAttributeSearchFieldKind
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/MaterialAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/MaterialAttributeSearchFieldKind.java
new file mode 100644
index 00000000000..f556bd293e6
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/MaterialAttributeSearchFieldKind.java
@@ -0,0 +1,49 @@
+/*
+ * 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.generic.shared.basic.dto;
+
+import com.google.gwt.user.client.rpc.IsSerializable;
+
+/**
+ * Kinds of fields connected with Material attributes that can be used in detailed text queries.
+ * 
+ * @author Piotr Buczek
+ */
+public enum MaterialAttributeSearchFieldKind implements IsSerializable, IAttributeSearchFieldKind
+{
+    CODE("Code"),
+
+    MATERIAL_TYPE("Material Type");
+
+    private final String description;
+
+    private MaterialAttributeSearchFieldKind(String description)
+    {
+        this.description = description;
+    }
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public String getCode()
+    {
+        return name();
+    }
+
+}
\ No newline at end of file
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java
new file mode 100644
index 00000000000..e7ecdff06ad
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java
@@ -0,0 +1,51 @@
+/*
+ * 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.generic.shared.basic.dto;
+
+import com.google.gwt.user.client.rpc.IsSerializable;
+
+/**
+ * Kinds of fields connected with Sample attributes that can be used in detailed text queries.
+ * 
+ * @author Piotr Buczek
+ */
+public enum SampleAttributeSearchFieldKind implements IsSerializable, IAttributeSearchFieldKind
+{
+    CODE("Code"),
+
+    SAMPLE_TYPE("Sample Type"),
+
+    GROUP("Group");
+
+    private final String description;
+
+    private SampleAttributeSearchFieldKind(String description)
+    {
+        this.description = description;
+    }
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public String getCode()
+    {
+        return name();
+    }
+
+}
\ No newline at end of file
-- 
GitLab