added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / camunda / workflow / WorkflowRequest.java
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 package org.oran.otf.camunda.workflow;\r
18 \r
19 import org.oran.otf.common.model.local.ParallelFlowInput;\r
20 import org.oran.otf.common.utility.gson.Convert;\r
21 import com.fasterxml.jackson.annotation.JsonCreator;\r
22 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;\r
23 import com.fasterxml.jackson.annotation.JsonProperty;\r
24 import com.fasterxml.jackson.databind.annotation.JsonSerialize;\r
25 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;\r
26 import java.io.Serializable;\r
27 import java.util.Map;\r
28 import org.bson.types.ObjectId;\r
29 \r
30 @JsonIgnoreProperties(ignoreUnknown = true)\r
31 public class WorkflowRequest implements Serializable {\r
32 \r
33   private static final long serialVersionUID = 1L;\r
34 \r
35   private boolean async = false;\r
36   @JsonSerialize(using = ToStringSerializer.class)\r
37   private ObjectId executorId = null;\r
38 \r
39   @JsonSerialize(using = ToStringSerializer.class)\r
40   private ObjectId testInstanceId = null;\r
41 \r
42   private Map<String, ParallelFlowInput> pfloInput = null;\r
43   private Map<String, Object> testData = null;\r
44   private Map<String, Object> vthInput = null;\r
45   private long maxExecutionTimeInMillis = 0L;\r
46 \r
47   public WorkflowRequest() throws Exception {\r
48     //this.validate();\r
49   }\r
50 \r
51   public WorkflowRequest(\r
52       boolean async,\r
53       String executorId,\r
54       String testInstanceId,\r
55       long maxExecutionTimeInMillis) {\r
56     this.async = async;\r
57     this.executorId = new ObjectId(executorId);\r
58     this.testInstanceId = new ObjectId(testInstanceId);\r
59     this.maxExecutionTimeInMillis = maxExecutionTimeInMillis;\r
60   }\r
61 \r
62   public WorkflowRequest(\r
63       boolean async,\r
64       ObjectId executorId,\r
65       ObjectId testInstanceId,\r
66       Map<String, ParallelFlowInput> pfloInput,\r
67       Map<String, Object> testData,\r
68       Map<String, Object> vthInput,\r
69       int maxExecutionTimeInMillis)\r
70       throws Exception {\r
71     this.async = async;\r
72     this.executorId = executorId;\r
73     this.testInstanceId = testInstanceId;\r
74     this.pfloInput = pfloInput;\r
75     this.testData = testData;\r
76     this.vthInput = vthInput;\r
77     this.maxExecutionTimeInMillis = maxExecutionTimeInMillis;\r
78 \r
79     this.validate();\r
80   }\r
81 \r
82   @JsonCreator\r
83   public WorkflowRequest(\r
84       @JsonProperty(value = "async", required = false) boolean async,\r
85       @JsonProperty(value = "executorId", required = true) String executorId,\r
86       @JsonProperty(value = "testInstanceId", required = true) String testInstanceId,\r
87       @JsonProperty(value = "pfloInput", required = false) Map<String, ParallelFlowInput> pfloInput,\r
88       @JsonProperty(value = "testData", required = false) Map<String, Object> testData,\r
89       @JsonProperty(value = "vthInput", required = false) Map<String, Object> vthInput,\r
90       @JsonProperty(value = "maxExecutionTimeInMillis", required = false)\r
91           int maxExecutionTimeInMillis) throws Exception {\r
92     this.async = async;\r
93     this.executorId = new ObjectId(executorId);\r
94     this.testInstanceId = new ObjectId(testInstanceId);\r
95     this.pfloInput = pfloInput;\r
96     this.testData = testData;\r
97     this.vthInput = vthInput;\r
98     this.maxExecutionTimeInMillis = maxExecutionTimeInMillis;\r
99 \r
100     this.validate();\r
101   }\r
102 \r
103   private void validate() throws Exception {\r
104     String missingFieldFormat = "Missing required field %s.";\r
105 //    if (this.executorId == null) {\r
106 //      throw new Exception(String.format(missingFieldFormat, "executorId"));\r
107 //    }\r
108 \r
109     if (this.testInstanceId == null) {\r
110       throw new Exception(String.format(missingFieldFormat, "testInstanceId"));\r
111     }\r
112 \r
113     if (this.maxExecutionTimeInMillis < 0L) {\r
114       this.maxExecutionTimeInMillis = 0L;\r
115     }\r
116   }\r
117 \r
118   public boolean isAsync() {\r
119     return async;\r
120   }\r
121 \r
122   public void setAsync(boolean async) {\r
123     this.async = async;\r
124   }\r
125 \r
126   public ObjectId getExecutorId() {\r
127     return executorId;\r
128   }\r
129 \r
130   public void setExecutorId(ObjectId executorId) {\r
131     this.executorId = executorId;\r
132   }\r
133 \r
134   public ObjectId getTestInstanceId() {\r
135     return testInstanceId;\r
136   }\r
137 \r
138   public void setTestInstanceId(String testInstanceId) {\r
139     this.testInstanceId = new ObjectId(testInstanceId);\r
140   }\r
141 \r
142   public void setTestInstanceId(ObjectId testInstanceId) {\r
143     this.testInstanceId = testInstanceId;\r
144   }\r
145 \r
146   public Map<String, ParallelFlowInput> getPfloInput() {\r
147     return pfloInput;\r
148   }\r
149 \r
150   public void setPfloInput(Map<String, ParallelFlowInput> pfloInput) {\r
151     this.pfloInput = pfloInput;\r
152   }\r
153 \r
154   public Map<String, Object> getTestData() {\r
155     return testData;\r
156   }\r
157 \r
158   public void setTestData(Map<String, Object> testData) {\r
159     this.testData = testData;\r
160   }\r
161 \r
162   public Map<String, Object> getVthInput() {\r
163     return vthInput;\r
164   }\r
165 \r
166   public void setVthInput(Map<String, Object> vthInput) {\r
167     this.vthInput = vthInput;\r
168   }\r
169 \r
170   public long getMaxExecutionTimeInMillis() {\r
171     return maxExecutionTimeInMillis;\r
172   }\r
173 \r
174   public void setMaxExecutionTimeInMillis(long maxExecutionTimeInMillis) {\r
175     this.maxExecutionTimeInMillis = maxExecutionTimeInMillis;\r
176   }\r
177 \r
178   @Override\r
179   public String toString() {\r
180     return Convert.objectToJson(this);\r
181   }\r
182 }\r