From f2cf8ce11bdf87a46e7e32a0a8ec3f00f3554624 Mon Sep 17 00:00:00 2001
From: vkovtun <viktor.kovtun@id.ethz.ch>
Date: Mon, 27 Nov 2023 11:43:19 +0100
Subject: [PATCH] SSDM-14216: Not doing update for frozen entities to avoid
 errors.

---
 .../openbis/generic/server/hotfix/ELNFixes.java | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/server-application-server/source/java/ch/systemsx/cisd/openbis/generic/server/hotfix/ELNFixes.java b/server-application-server/source/java/ch/systemsx/cisd/openbis/generic/server/hotfix/ELNFixes.java
index c252f97b559..72a91ed2c67 100644
--- a/server-application-server/source/java/ch/systemsx/cisd/openbis/generic/server/hotfix/ELNFixes.java
+++ b/server-application-server/source/java/ch/systemsx/cisd/openbis/generic/server/hotfix/ELNFixes.java
@@ -46,9 +46,9 @@ public class ELNFixes {
         storageValidationLevelFix(sessionToken, api);
         nameNoRTFFix(sessionToken, api);
         // TODO(alaskowski): SSDM-13831: Do migration here!!!
-        fixProperties("sample_properties", "sample_type_property_types", "stpt_id");
-        fixProperties("experiment_properties", "experiment_type_property_types", "etpt_id");
-        fixProperties("data_set_properties", "data_set_type_property_types", "dstpt_id");
+        fixProperties("sample_properties", "sample_type_property_types", "stpt_id", "samp_frozen");
+        fixProperties("experiment_properties", "experiment_type_property_types", "etpt_id", "expe_frozen");
+        fixProperties("data_set_properties", "data_set_type_property_types", "dstpt_id", "dase_frozen");
         operationLog.info("ELNFixes beforeUpgrade FINISH");
     }
 
@@ -135,23 +135,24 @@ public class ELNFixes {
     }
 
     private static void fixProperties(final String propertiesTable, final String entityTypePropertyTypesTable,
-            final String entityTypePropertyTypesColumn) {
+            final String entityTypePropertyTypesColumn, final String frozenColumn) {
         ELNCollectionTypeMigration.executeNativeUpdate(
             String.format("UPDATE %s prop\n"
                     + "SET value = null\n"
                     + "FROM %s etpt\n"
                     + "INNER JOIN property_types prty ON etpt.prty_id = prty.id\n"
                     + "INNER JOIN data_types daty ON prty.daty_id = daty.id\n"
-                    + "WHERE prop.%s IS NOT NULL AND prop.%s = etpt.id AND daty.code = 'CONTROLLEDVOCABULARY'",
-                    propertiesTable, entityTypePropertyTypesTable, entityTypePropertyTypesColumn, entityTypePropertyTypesColumn));
+                    + "WHERE prop.%s IS NOT NULL AND prop.%s = etpt.id AND daty.code = 'CONTROLLEDVOCABULARY' AND prop.%s = false",
+                    propertiesTable, entityTypePropertyTypesTable, entityTypePropertyTypesColumn, entityTypePropertyTypesColumn, frozenColumn));
         ELNCollectionTypeMigration.executeNativeUpdate(
             String.format("UPDATE %s prop\n"
                 + "SET cvte_id = null\n"
                 + "FROM %s etpt\n"
                 + "INNER JOIN property_types prty ON etpt.prty_id = prty.id\n"
                 + "INNER JOIN data_types daty ON prty.daty_id = daty.id\n"
-                + "WHERE prop.%s IS NOT NULL AND prop.%s = etpt.id AND daty.code != 'CONTROLLEDVOCABULARY'",
-                propertiesTable, entityTypePropertyTypesTable, entityTypePropertyTypesColumn, entityTypePropertyTypesColumn));
+                + "WHERE prop.%s IS NOT NULL AND prop.%s = etpt.id AND daty.code != 'CONTROLLEDVOCABULARY' AND prop.%s = false",
+                propertiesTable, entityTypePropertyTypesTable, entityTypePropertyTypesColumn, entityTypePropertyTypesColumn, frozenColumn));
+        operationLog.info(String.format("ELNFixes fixProperties for propertiesTable %s", propertiesTable));
     }
 
 }
-- 
GitLab