package com.sap.cloud.lm.sl.cf.web.api.model;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;

public class OperationMetadata {

    protected Set<ParameterMetadata> parameters;
    protected String activitiDiagramId;
    protected List<String> versions;

    public static OperationMetadataBuilder builder() {
        return new OperationMetadataBuilder();
    }

    public static class OperationMetadataBuilder {

        protected Set<ParameterMetadata> parameters;
        protected String activitiDiagramId;
        protected List<String> versions;

        public OperationMetadata build() {
            OperationMetadata metadata = new OperationMetadata();
            metadata.parameters = parameters;
            metadata.activitiDiagramId = activitiDiagramId;
            metadata.versions = versions != null ? versions : Collections.emptyList();
            return metadata;
        }

        public OperationMetadataBuilder parameters(Set<ParameterMetadata> parameters) {
            this.parameters = parameters;
            return this;
        }

        public OperationMetadataBuilder activitiDiagramId(String activitiDiagramId) {
            this.activitiDiagramId = activitiDiagramId;
            return this;
        }
        
        public OperationMetadataBuilder versions(String... versions) {
            this.versions = Arrays.asList(versions);
            return this;
        }

    }

    public Set<ParameterMetadata> getParameters() {
        return parameters;
    }

    public String getActivitiDiagramId() {
        return activitiDiagramId;
    }

    public List<String> getVersions() {
        return versions;
    }

}

@@ -141,16 +141,68 @@
 l.Set;%0A%0A
+import com.sap.cloud.lm.sl.common.util.CommonUtil;%0A%0A
 public c
@@ -312,24 +312,228 @@
 iDiagramId;%0A
+    /**%0A     * Can be used to ensure backwards compatibility when trying to find processes started with an older version of the application.%0A     */%0A    protected List%3CString%3E previousActivitiDiagramIds;%0A
     protecte
@@ -808,32 +808,91 @@
 ivitiDiagramId;%0A
+        protected List%3CString%3E previousActivitiDiagramIds;%0A
         protecte
@@ -1153,27 +1153,153 @@
 etadata.
-versions = 
+previousActivitiDiagramIds = CommonUtil.getOrDefault(previousActivitiDiagramIds, Collections.%3CString%3E emptyList());%0A            metadata.
 versions
@@ -1303,26 +1303,42 @@
 ons 
-!
 = 
-null ? 
+CommonUtil.getOrDefault(
 versions
  : C
@@ -1337,10 +1337,9 @@
 ions
- :
+,
  Col
@@ -1347,16 +1347,25 @@
 ections.
+%3CString%3E 
 emptyLis
@@ -1367,16 +1367,17 @@
 tyList()
+)
 ;%0A      
@@ -1753,24 +1753,25 @@
       %7D%0A
+%0A
         
 %0A       
@@ -1762,16 +1762,239 @@
         
+public OperationMetadataBuilder previousActivitiDiagramIds(String... previousActivitiDiagramIds) %7B%0A            this.previousActivitiDiagramIds = Arrays.asList(previousActivitiDiagramIds);%0A            return this;%0A        %7D%0A
 %0A       
@@ -2278,24 +2278,24 @@
 agramId() %7B%0A
-
         retu
@@ -2315,32 +2315,140 @@
 agramId;%0A    %7D%0A%0A
+    public List%3CString%3E getPreviousActivitiDiagramIds() %7B%0A        return previousActivitiDiagramIds;%0A    %7D%0A%0A
     public List%3C

Store previous diagram IDs in operations metadata