66a04996e686d62a1146383cb6ceff6e6c4b0655
[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
36     @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, property="class")
37     protected JobAdapter.AsyncJobRequest request;
38
39     public JobSharedData() {
40     }
41
42     public JobSharedData(UUID jobUuid, String userId, JobAdapter.AsyncJobRequest request) {
43         this.jobUuid = jobUuid;
44         this.userId = userId;
45         this.requestType = request.getClass();
46         this.request = request;
47         this.rootJobId = jobUuid;
48     }
49
50     public JobSharedData(UUID jobUuid, JobAdapter.AsyncJobRequest request, JobSharedData parentData) {
51         this(jobUuid, parentData.getUserId(), request);
52         rootJobId = parentData.getRootJobId() != null ? parentData.getRootJobId() : parentData.getJobUuid();
53     }
54
55
56     public UUID getJobUuid() {
57         return jobUuid;
58     }
59
60     public String getUserId() {
61         return userId;
62     }
63
64     public void setUserId(String userId) {
65         this.userId = userId;
66     }
67
68     public Class getRequestType() {
69         return requestType;
70     }
71
72     public void setRequestType(Class requestType) {
73         this.requestType = requestType;
74     }
75
76     public JobAdapter.AsyncJobRequest getRequest() {
77         return request;
78     }
79
80     public void setRequest(JobAdapter.AsyncJobRequest request) {
81         this.request = request;
82     }
83
84     public UUID getRootJobId() {
85         return rootJobId;
86     }
87
88     @Override
89     public boolean equals(Object o) {
90         if (this == o) return true;
91         if (!(o instanceof JobSharedData)) return false;
92         JobSharedData that = (JobSharedData) o;
93         return Objects.equals(getJobUuid(), that.getJobUuid()) &&
94                 Objects.equals(getUserId(), that.getUserId()) &&
95                 Objects.equals(getRequestType(), that.getRequestType()) &&
96                 Objects.equals(getRootJobId(), that.getRootJobId()) &&
97                 Objects.equals(getRequest(), that.getRequest());
98     }
99
100     @Override
101     public int hashCode() {
102         return Objects.hash(getJobUuid(), getUserId(), getRequestType(), getRootJobId(), getRequest());
103     }
104 }