Implant vid-app-common org.onap.vid.job (main and test)
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / impl / JobSharedData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.job.impl;
22
23 import com.fasterxml.jackson.annotation.JsonTypeInfo;
24 import org.onap.vid.job.JobAdapter;
25
26 import java.util.Objects;
27 import java.util.UUID;
28
29 public class JobSharedData {
30
31     protected UUID jobUuid;
32     protected String userId;
33     protected Class requestType;
34     protected UUID rootJobId;
35     protected String testApi;
36
37     @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, property="class")
38     protected JobAdapter.AsyncJobRequest request;
39
40     public JobSharedData() {
41     }
42
43     public JobSharedData(UUID jobUuid, String userId, JobAdapter.AsyncJobRequest request, String testApi) {
44         this.jobUuid = jobUuid;
45         this.userId = userId;
46         this.requestType = request.getClass();
47         this.request = request;
48         this.rootJobId = jobUuid;
49         this.testApi = testApi;
50     }
51
52     public JobSharedData(UUID jobUuid, JobAdapter.AsyncJobRequest request, JobSharedData parentData) {
53         this(jobUuid, parentData.getUserId(), request, parentData.getTestApi());
54         rootJobId = parentData.getRootJobId() != null ? parentData.getRootJobId() : parentData.getJobUuid();
55     }
56
57
58     public UUID getJobUuid() {
59         return jobUuid;
60     }
61
62     public String getUserId() {
63         return userId;
64     }
65
66     public void setUserId(String userId) {
67         this.userId = userId;
68     }
69
70     public Class getRequestType() {
71         return requestType;
72     }
73
74     public void setRequestType(Class requestType) {
75         this.requestType = requestType;
76     }
77
78     public JobAdapter.AsyncJobRequest getRequest() {
79         return request;
80     }
81
82     public void setRequest(JobAdapter.AsyncJobRequest request) {
83         this.request = request;
84     }
85
86     public UUID getRootJobId() {
87         return rootJobId;
88     }
89
90     public String getTestApi() {
91         return testApi;
92     }
93
94     public void setTestApi(String testApi) {
95         this.testApi = testApi;
96     }
97
98     @Override
99     public boolean equals(Object o) {
100         if (this == o) return true;
101         if (!(o instanceof JobSharedData)) return false;
102         JobSharedData that = (JobSharedData) o;
103         return Objects.equals(getJobUuid(), that.getJobUuid()) &&
104                 Objects.equals(getUserId(), that.getUserId()) &&
105                 Objects.equals(getRequestType(), that.getRequestType()) &&
106                 Objects.equals(getRootJobId(), that.getRootJobId()) &&
107                 Objects.equals(getRequest(), that.getRequest());
108     }
109
110     @Override
111     public int hashCode() {
112         return Objects.hash(getJobUuid(), getUserId(), getRequestType(), getRootJobId(), getRequest());
113     }
114 }