From cbbba4baaf3f8ff830ed23b29ec4d5362e124e5c Mon Sep 17 00:00:00 2001
From: jakubs <jakubs>
Date: Thu, 9 Jun 2016 14:22:32 +0000
Subject: [PATCH] SSDM-3678: hierarchical store: rename variable links-only to
 with-meta-data with reverse meaning

SVN: 36666
---
 .../plugins/HierarchicalStorageUpdater.java   | 39 +++++++++++--------
 .../HierarchicalStorageUpdaterTest.java       |  2 +-
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/HierarchicalStorageUpdater.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/HierarchicalStorageUpdater.java
index 999fc351d8c..f2fffcdffa5 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/HierarchicalStorageUpdater.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/HierarchicalStorageUpdater.java
@@ -71,9 +71,9 @@ public class HierarchicalStorageUpdater implements IDataStoreLockingMaintenanceT
     public static final String LINK_FROM_FIRST_CHILD = "link-from-first-child";
 
     /**
-     * Property indicating if only links should be created, rather then directory with link and meta-data file.
+     * Property indicating if directory with link and meta-data file or only links should be created.
      */
-    public static final String LINKS_ONLY = "links-only";
+    public static final String WITH_META_DATA = "with-meta-data";
 
     /**
      * Name of the link to create in a directory in links-only is set to false
@@ -116,7 +116,7 @@ public class HierarchicalStorageUpdater implements IDataStoreLockingMaintenanceT
 
     private File hierarchyRoot;
 
-    private boolean storeLinksOnly;
+    private boolean withMetaData;
 
     private Map<String /* data set type */, LinkSourceDescriptor> linkSourceDescriptors;
 
@@ -137,7 +137,7 @@ public class HierarchicalStorageUpdater implements IDataStoreLockingMaintenanceT
         storeRoot = new File(storeRootFileName);
         hierarchyRoot = new File(hierarchyRootFileName);
         linkSourceDescriptors = initializeLinkSourceDescriptors(pluginProperties);
-        storeLinksOnly = PropertyUtils.getBoolean(pluginProperties, LINKS_ONLY, true);
+        withMetaData = PropertyUtils.getBoolean(pluginProperties, WITH_META_DATA, true);
 
         operationLog.info("Plugin initialized with: store root = " + storeRootFileName
                 + ", hierarchy root = " + hierarchyRootFileName);
@@ -233,12 +233,12 @@ public class HierarchicalStorageUpdater implements IDataStoreLockingMaintenanceT
 
     private void handleNonExistingEntry(DataSetInformation info)
     {
-        if (storeLinksOnly)
+        if (withMetaData)
         {
-            createLink(info.targetFile, info.linkSource);
+            createDataSetFolder(info);
         } else
         {
-            createDataSetFolder(info);
+            createLink(info.targetFile, info.linkSource);
         }
     }
 
@@ -248,21 +248,15 @@ public class HierarchicalStorageUpdater implements IDataStoreLockingMaintenanceT
      */
     private void handleExistingEntry(DataSetInformation info)
     {
-        String errorMsgLinksOnlyModeChanged = "The state of hierarchical store is corrupted or property '" + LINKS_ONLY
+        String errorMsgLinksOnlyModeChanged = "The state of hierarchical store is corrupted or property '" + WITH_META_DATA
                 + "' has been modified after hierarchical store has been built. In this case the hierarchical store directory "
                 + "should be deleted manually. It will be recreated after DSS start up.";
-        if (storeLinksOnly)
+        if (withMetaData)
         {
             if (FileUtilities.isSymbolicLink(info.targetFile))
-            {
-                // nothing to do as the link is already in place
-                return;
-            } else
             {
                 throw new IllegalStateException(errorMsgLinksOnlyModeChanged);
             }
-        } else
-        {
             if (info.targetFile.isDirectory())
             {
                 Date storedModificationDate = getModificationDateFromFile(info);
@@ -274,7 +268,18 @@ public class HierarchicalStorageUpdater implements IDataStoreLockingMaintenanceT
             {
                 throw new IllegalStateException(errorMsgLinksOnlyModeChanged);
             }
+        } else
+        {
+            if (FileUtilities.isSymbolicLink(info.targetFile))
+            {
+                // nothing to do as the link is already in place
+                return;
+            } else
+            {
+                throw new IllegalStateException(errorMsgLinksOnlyModeChanged);
+            }
         }
+
     }
 
     private final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US);
@@ -380,7 +385,9 @@ public class HierarchicalStorageUpdater implements IDataStoreLockingMaintenanceT
                                 dataSetLocationRoot, dataSet.getDataSetType());
                 operationLog.warn(logMessage);
             }
-            if (storeLinksOnly == false || linkSource != null)
+            // we still want a directory with metadata if metadata option is specified
+            // if only links should be created we don't want to create broken links
+            if (withMetaData || linkSource != null)
             {
                 result.add(info);
             }
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/HierarchicalStorageUpdaterTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/HierarchicalStorageUpdaterTest.java
index 4e070b7d22b..22e239de7ff 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/HierarchicalStorageUpdaterTest.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/plugins/HierarchicalStorageUpdaterTest.java
@@ -254,7 +254,7 @@ public class HierarchicalStorageUpdaterTest extends AbstractFileSystemTestCase
                     "" + true);
         }
 
-        properties.put(HierarchicalStorageUpdater.LINKS_ONLY, onlyLinks ? "true" : "false");
+        properties.put(HierarchicalStorageUpdater.WITH_META_DATA, onlyLinks ? "false" : "true");
 
         HierarchicalStorageUpdater updater = new HierarchicalStorageUpdater();
         updater.setUp(pluginName, properties);
-- 
GitLab