From 451b617946f18b5bc128b4957e93e895ff92f89b Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Thu, 15 Nov 2018 15:28:08 +0000
Subject: [PATCH] SW-35: processed review comments

---
 .../radb/sql/add_functions_and_triggers.sql                 | 6 ++----
 .../radb/sql/add_resource_allocation_statics.sql            | 2 ++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql
index a3c5cd70295..2242ac5e375 100644
--- a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql
+++ b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_functions_and_triggers.sql
@@ -520,14 +520,12 @@ BEGIN
         RETURN max_resource_at_or_before_starttime;
     END IF;
 
-    IF max_resource_usage_in_time_window.as_of_timestamp > _lower THEN
+    IF max_resource_usage_in_time_window.as_of_timestamp > _lower THEN -- Skips as_of_timestamp = _lower on purpose
         -- check if the usage at_or_before_starttime is higher then in_time_window
         SELECT * FROM resource_allocation.get_resource_usage_at_or_before(_resource_id, _claim_status_id, _lower, false, false, false) INTO max_resource_at_or_before_starttime;
         IF max_resource_at_or_before_starttime IS NOT NULL THEN
             IF max_resource_at_or_before_starttime.usage > max_resource_usage_in_time_window.usage THEN
                 RETURN max_resource_at_or_before_starttime;
-            ELSE
-                RETURN max_resource_usage_in_time_window;
             END IF;
         END IF;
     END IF;
@@ -727,7 +725,7 @@ BEGIN
                 -- when a claim goes to conflict, then so does it's task, and we don't want that for running/finished/aborted tasks
                 IF EXISTS (SELECT 1 FROM resource_allocation.task
                             WHERE id=NEW.task_id
-                            AND status_id = ANY(ARRAY[300, 335, 350, 400, 500])) THEN -- hardcoded tasks statuses <= queued
+                            AND status_id = ANY(ARRAY[task_approved_status_id, task_conflict_status_id, task_prescheduled_status_id, task_scheduled_status_id, task_queued_status_id])) THEN -- hardcoded tasks statuses <= queued
                     -- conflict with others, so set claim status to conflict
                     NEW.status_id := claim_conflict_status_id;
                 END IF;
diff --git a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_resource_allocation_statics.sql b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_resource_allocation_statics.sql
index e56bd04d19e..8b18e25d296 100644
--- a/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_resource_allocation_statics.sql
+++ b/SAS/ResourceAssignment/ResourceAssignmentDatabase/radb/sql/add_resource_allocation_statics.sql
@@ -2,6 +2,8 @@
 -- psql resourceassignment -U resourceassignment -f add_resource_allocation_statics.sql -W
 BEGIN;
 
+
+-- General Warning: if you change any of these values, make sure you update the hardcoded values in add_functions_and_triggers.sql too.
 INSERT INTO resource_allocation.task_status VALUES (200, 'prepared'), (300, 'approved'), (320, 'on_hold'), (335, 'conflict'),
 (350, 'prescheduled'), (400, 'scheduled'), (500, 'queued'), (600, 'active'), (900, 'completing'), (1000, 'finished'), (1100, 'aborted'),
 (1150, 'error'), (1200, 'obsolete'); -- This is the list from OTDB, we'll need to merge it with the list from MoM in the future, might use different indexes?
-- 
GitLab