From 008783c3ae0a9ac882d828a19eefc1e81a75ec9f Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Tue, 29 Mar 2011 09:50:26 +0000
Subject: [PATCH] LMS-2131 Fixed some bugs I discovered.

SVN: 20529
---
 ...ractDataSetRegistrationDetailsFactory.java | 12 ++---
 ...tOmniscientTopLevelDataSetRegistrator.java | 18 ++++++--
 .../DataSetRegistrationService.java           | 46 +++++++++++++++++++
 .../api/gui/DataSetPropertiesPanel.java       | 23 ++++++++++
 .../client/api/gui/DataSetUploadClient.java   |  3 +-
 .../api/gui/DataSetUploadClientModel.java     | 45 +++++++++++++++++-
 .../api/gui/DataSetUploadTableModel.java      |  3 +-
 .../gui/UploadStatusTableCellRenderer.java    |  5 +-
 8 files changed, 142 insertions(+), 13 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractDataSetRegistrationDetailsFactory.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractDataSetRegistrationDetailsFactory.java
index 03493730ffb..00642cc6ddd 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractDataSetRegistrationDetailsFactory.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractDataSetRegistrationDetailsFactory.java
@@ -17,12 +17,13 @@
 package ch.systemsx.cisd.etlserver.registrator;
 
 import java.io.File;
+import java.util.List;
 
 import ch.systemsx.cisd.etlserver.registrator.AbstractOmniscientTopLevelDataSetRegistrator.OmniscientTopLevelDataSetRegistratorState;
 import ch.systemsx.cisd.etlserver.registrator.api.v1.impl.DataSet;
 import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
-import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
+import ch.systemsx.cisd.openbis.generic.shared.dto.NewProperty;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.dto.types.DataSetTypeCode;
@@ -77,8 +78,7 @@ public abstract class AbstractDataSetRegistrationDetailsFactory<T extends DataSe
      */
     protected void applyUserProvidedValues(T dataSetInfo)
     {
-        SampleIdentifier sampleId =
-                userProvidedDataSetInformationOrNull.getSampleIdentifier();
+        SampleIdentifier sampleId = userProvidedDataSetInformationOrNull.getSampleIdentifier();
         if (null != sampleId)
         {
             dataSetInfo.setSampleCode(sampleId.getSampleCode());
@@ -99,10 +99,10 @@ public abstract class AbstractDataSetRegistrationDetailsFactory<T extends DataSe
             dataSetInfo.setDataSetType(type);
         }
 
-        IEntityProperty[] props = userProvidedDataSetInformationOrNull.getProperties();
-        if (0 < props.length)
+        List<NewProperty> props = userProvidedDataSetInformationOrNull.getDataSetProperties();
+        if (false == props.isEmpty())
         {
-            dataSetInfo.setProperties(props);
+            dataSetInfo.setDataSetProperties(props);
         }
     }
 
diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractOmniscientTopLevelDataSetRegistrator.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractOmniscientTopLevelDataSetRegistrator.java
index acba86bb250..5865ef39ca5 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractOmniscientTopLevelDataSetRegistrator.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/AbstractOmniscientTopLevelDataSetRegistrator.java
@@ -264,11 +264,21 @@ public abstract class AbstractOmniscientTopLevelDataSetRegistrator<T extends Dat
             return;
         }
 
-        handle(incomingDataSetFile, callerDataSetInformation, delegate,
-                new DoNothingDelegatedAction());
+        DataSetRegistrationService<T> service =
+                handle(incomingDataSetFile, callerDataSetInformation, delegate,
+                        new DoNothingDelegatedAction());
+        if (service.didErrorsArise())
+        {
+            throw new EnvironmentFailureException("Could not process file "
+                    + incomingDataSetFile.getName(), service.getEncounteredErrors().get(0));
+        }
     }
 
-    private void handle(File incomingDataSetFile,
+    /**
+     * Set up the infrastructure and forward control to subclasses. Clients can query the service
+     * for information about what happened.
+     */
+    private DataSetRegistrationService<T> handle(File incomingDataSetFile,
             DataSetInformation callerDataSetInformationOrNull,
             ITopLevelDataSetRegistratorDelegate delegate,
             final IDelegatedActionWithResult<Boolean> cleanAfterwardsAction)
@@ -286,6 +296,8 @@ public abstract class AbstractOmniscientTopLevelDataSetRegistrator<T extends Dat
             operationLog.error("Could not process file " + incomingDataSetFile, ex);
             rollback(service, ex);
         }
+
+        return service;
     }
 
     public boolean isStopped()
diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetRegistrationService.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetRegistrationService.java
index 4b25703bdd1..2f88d25b8d8 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetRegistrationService.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/DataSetRegistrationService.java
@@ -18,6 +18,7 @@ package ch.systemsx.cisd.etlserver.registrator;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 
 import ch.systemsx.cisd.common.utilities.IDelegatedActionWithResult;
@@ -46,6 +47,27 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.types.DataSetTypeCode;
  * 
  * @author Chandrasekhar Ramakrishnan
  */
+/**
+ * 
+ *
+ * @author Chandrasekhar Ramakrishnan
+ */
+/**
+ * 
+ *
+ * @author Chandrasekhar Ramakrishnan
+ */
+/**
+ * 
+ *
+ * @author Chandrasekhar Ramakrishnan
+ */
+/**
+ * @author Chandrasekhar Ramakrishnan
+ */
+/**
+ * @author Chandrasekhar Ramakrishnan
+ */
 public class DataSetRegistrationService<T extends DataSetInformation> implements
         DataSetRegistrationAlgorithm.IRollbackDelegate, IDataSetRegistrationService
 {
@@ -88,6 +110,11 @@ public class DataSetRegistrationService<T extends DataSetInformation> implements
 
     private final ITopLevelDataSetRegistratorDelegate delegate;
 
+    /**
+     * Keep track of errors we encounter while processing. Clients may want this information.
+     */
+    private final ArrayList<Throwable> encounteredErrors = new ArrayList<Throwable>();
+
     /**
      * All transactions ever created on this service.
      */
@@ -236,6 +263,7 @@ public class DataSetRegistrationService<T extends DataSetInformation> implements
     public void rollbackTransaction(DataSetRegistrationTransaction<T> transaction,
             DataSetStorageAlgorithmRunner<T> algorithm, Throwable ex)
     {
+        encounteredErrors.add(ex);
         registrator.rollbackTransaction(this, transaction, algorithm, ex);
     }
 
@@ -288,6 +316,23 @@ public class DataSetRegistrationService<T extends DataSetInformation> implements
         return new DefaultEntityOperationService<T>(registrator, delegate);
     }
 
+    /**
+     * Return true if errors happend while processing the service.
+     */
+    public boolean didErrorsArise()
+    {
+        return encounteredErrors.isEmpty() == false;
+    }
+
+    /**
+     * Return the list of errors that were encountered. If didErrorsArise is false, this list will
+     * be empty, otherwise there will be at least one element.
+     */
+    public List<Throwable> getEncounteredErrors()
+    {
+        return encounteredErrors;
+    }
+
     protected IDataSetRegistrationDetailsFactory<T> getDataSetRegistrationDetailsFactory()
     {
         return dataSetRegistrationDetailsFactory;
@@ -372,6 +417,7 @@ public class DataSetRegistrationService<T extends DataSetInformation> implements
 
     public void rollback(DataSetRegistrationAlgorithm algorithm, Throwable ex)
     {
+        encounteredErrors.add(ex);
         registrator.rollback(this, algorithm, ex);
     }
 
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetPropertiesPanel.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetPropertiesPanel.java
index 5595c4ef92b..1810e68ab7f 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetPropertiesPanel.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetPropertiesPanel.java
@@ -37,12 +37,14 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 
+import ch.systemsx.cisd.common.utilities.PropertyUtils;
 import ch.systemsx.cisd.openbis.dss.client.api.gui.DataSetUploadClientModel.NewDataSetInfo;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.NewDataSetDTOBuilder;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.NewDataSetMetadataDTO;
@@ -51,6 +53,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.ControlledVocabularyPr
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyType;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyTypeGroup;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode;
 
 /**
  * @author Chandrasekhar Ramakrishnan
@@ -156,6 +159,9 @@ public class DataSetPropertiesPanel extends JPanel
         if (propertyType instanceof ControlledVocabularyPropertyType)
         {
             formField = createComboBox((ControlledVocabularyPropertyType) propertyType);
+        } else if (propertyType.getDataType() == DataTypeCode.BOOLEAN)
+        {
+            formField = createCheckBox(propertyType);
         } else
         {
             formField = createTextField(propertyType);
@@ -212,6 +218,23 @@ public class DataSetPropertiesPanel extends JPanel
         return comboBox;
     }
 
+    private JComponent createCheckBox(final PropertyType propertyType)
+    {
+        final JCheckBox checkBox = new JCheckBox();
+
+        checkBox.addActionListener(new ActionListener()
+            {
+                public void actionPerformed(ActionEvent e)
+                {
+                    setPropertyValue(propertyType,
+                            checkBox.isSelected() ? PropertyUtils.Boolean.TRUE.toString()
+                                    : PropertyUtils.Boolean.FALSE.toString());
+                }
+
+            });
+        return checkBox;
+    }
+
     private String getLabelStringForPropertyType(PropertyType propertyType)
     {
         StringBuilder label = new StringBuilder();
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClient.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClient.java
index df1a83ea9ee..1e1dfad27f1 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClient.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClient.java
@@ -166,6 +166,7 @@ public class DataSetUploadClient extends AbstractSwingGUI
         spacer.setPreferredSize(new Dimension(15, 15));
         window.add(spacer, BorderLayout.SOUTH);
         window.pack();
+        window.setBounds(20, 40, 600, 400);
         window.setLocationByPlatform(true);
         window.setVisible(true);
 
@@ -283,7 +284,7 @@ public class DataSetUploadClient extends AbstractSwingGUI
         column.setPreferredWidth(200);
 
         column = fileTable.getColumnModel().getColumn(DataSetUploadTableModel.UPLOAD_STATUS_COLUMN);
-        column.setPreferredWidth(150);
+        column.setPreferredWidth(200);
         column.setCellRenderer(new UploadStatusTableCellRenderer(tableModel));
         column.setCellEditor(new UploadStatusTableCellEditor(tableModel));
         JScrollPane scrollPane = new JScrollPane(fileTable);
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClientModel.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClientModel.java
index d87b7acebde..174bd497e48 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClientModel.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClientModel.java
@@ -36,10 +36,13 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.FileInfoDssDTO;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.NewDataSetDTO;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.NewDataSetDTOBuilder;
 import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.NewDataSetMetadataDTO;
+import ch.systemsx.cisd.openbis.generic.server.dataaccess.PropertyValidator;
+import ch.systemsx.cisd.openbis.generic.server.dataaccess.PropertyValidator.IDataTypeValidator;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyType;
 import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.PropertyTypeGroup;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode;
 
 /**
  * @author Chandrasekhar Ramakrishnan
@@ -453,7 +456,7 @@ public class DataSetUploadClientModel
         }
     }
 
-    private void validatePropertyType(PropertyType propertyType, String valueOrNull,
+    protected void validatePropertyType(PropertyType propertyType, String valueOrNull,
             ArrayList<ValidationError> errors)
     {
         if (null == valueOrNull || valueOrNull.trim().length() < 1)
@@ -463,7 +466,47 @@ public class DataSetUploadClientModel
                 errors.add(ValidationError.createPropertyValidationError(propertyType.getCode(),
                         "A value must be provided."));
             }
+
+            // Otherwise, we can ignore this.
+            return;
+        }
+
+        if (propertyType.getDataType() == DataTypeCode.INTEGER)
+        {
+            validatePropertyTypeWithValidator(propertyType, valueOrNull, errors,
+                    new PropertyValidator.IntegerValidator());
+        }
+
+        if (propertyType.getDataType() == DataTypeCode.REAL)
+        {
+            validatePropertyTypeWithValidator(propertyType, valueOrNull, errors,
+                    new PropertyValidator.RealValidator());
+        }
+
+        if (propertyType.getDataType() == DataTypeCode.BOOLEAN)
+        {
+            validatePropertyTypeWithValidator(propertyType, valueOrNull, errors,
+                    new PropertyValidator.BooleanValidator());
         }
 
+        if (propertyType.getDataType() == DataTypeCode.TIMESTAMP)
+        {
+            validatePropertyTypeWithValidator(propertyType, valueOrNull, errors,
+                    new PropertyValidator.TimestampValidator());
+        }
+
+    }
+
+    private void validatePropertyTypeWithValidator(PropertyType propertyType, String valueOrNull,
+            ArrayList<ValidationError> errors, IDataTypeValidator validator)
+    {
+        try
+        {
+            validator.validate(valueOrNull);
+        } catch (UserFailureException e)
+        {
+            errors.add(ValidationError.createPropertyValidationError(propertyType.getCode(),
+                    e.getMessage()));
+        }
     }
 }
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadTableModel.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadTableModel.java
index 14d4a4b2e02..bf078000653 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadTableModel.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadTableModel.java
@@ -361,9 +361,10 @@ public class DataSetUploadTableModel extends AbstractTableModel
         {
             return;
         }
+
         NewDataSetInfo dataSetInfoToRemove = getSelectedNewDataSetOrNull();
 
-        int newSelectedRow = Math.max(0, selectedRow - 1);
+        int newSelectedRow = -1;
         ArrayList<Integer> selectedIndices = new ArrayList<Integer>();
         selectedIndices.add(newSelectedRow);
         setSelectedIndices(selectedIndices);
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/UploadStatusTableCellRenderer.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/UploadStatusTableCellRenderer.java
index c2637d54489..28f5c07deab 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/UploadStatusTableCellRenderer.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/UploadStatusTableCellRenderer.java
@@ -41,7 +41,8 @@ public class UploadStatusTableCellRenderer implements TableCellRenderer
 
     private final JPanel uploadPanel = new JPanel();
 
-    private final JLabel fixErrorsLabel = new JLabel("Incomplete (see fields in red)");
+    private final JLabel fixErrorsLabel = new JLabel(
+            "<html>Incomplete<br>(see fields in red)</html>");
 
     private final JPanel fixErrorsPanel = new JPanel();
 
@@ -76,6 +77,8 @@ public class UploadStatusTableCellRenderer implements TableCellRenderer
         fixErrorsPanel.setLayout(new GridLayout(1, 0));
         fixErrorsLabel.setFont(fixErrorsLabel.getFont().deriveFont(Font.PLAIN));
         fixErrorsLabel.setForeground(Color.RED);
+        fixErrorsLabel
+                .setToolTipText("Fields marked in red have not been specified correctly. Place the mouse over the field for a description of the error.");
         fixErrorsPanel.add(fixErrorsLabel);
         fixErrorsPanel.setOpaque(true);
     }
-- 
GitLab