Fix macro flow resource blocks processing order
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / workflow / tasks / Resource.java
index 692d8bc..0d2844d 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2021 Orange
+ * ================================================================================
  * 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
 
 package org.onap.so.bpmn.infrastructure.workflow.tasks;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Comparator;
+import java.util.List;
 
 public class Resource {
 
@@ -32,14 +37,24 @@ public class Resource {
     private String vnfCustomizationId;
     private String vfModuleCustomizationId;
     private String cvnfModuleCustomizationId;
+    private int processingPriority;
+    private Resource parent;
+    private List<Resource> children;
 
-    public static final Comparator<Resource> sortBaseFirst = Comparator.comparingInt(x -> x.isBaseVfModule() ? 0 : 1);
-    public static final Comparator<Resource> sortBaseLast = Comparator.comparingInt(x -> x.isBaseVfModule() ? 1 : 0);
+    public static final Comparator<Resource> sortByPriorityAsc =
+            Comparator.comparingInt(Resource::getProcessingPriority);
+    public static final Comparator<Resource> sortByPriorityDesc =
+            Comparator.comparingInt(x -> -x.getProcessingPriority());
 
-    public Resource(WorkflowType resourceType, String resourceId, boolean generated) {
+    public Resource(WorkflowType resourceType, String resourceId, boolean generated, Resource parent) {
         this.resourceId = resourceId;
         this.resourceType = resourceType;
         this.generated = generated;
+        this.processingPriority = 0;
+        this.children = new ArrayList<>();
+        this.parent = parent;
+        if (parent != null)
+            this.parent.children.add(this);
     }
 
     public String getResourceId() {
@@ -105,4 +120,20 @@ public class Resource {
     public void setCvnfModuleCustomizationId(String cvnfModuleCustomizationId) {
         this.cvnfModuleCustomizationId = cvnfModuleCustomizationId;
     }
+
+    public int getProcessingPriority() {
+        return processingPriority == 0 ? (isBaseVfModule() ? Integer.MIN_VALUE + 1 : 0) : processingPriority;
+    }
+
+    public void setProcessingPriority(int processingPriority) {
+        this.processingPriority = processingPriority;
+    }
+
+    public Resource getParent() {
+        return this.parent;
+    }
+
+    public List<Resource> getChildren() {
+        return this.children;
+    }
 }