First part of onap rename
[appc.git] / appc-dispatcher / appc-command-executor / appc-command-executor-api / src / main / java / org / openecomp / appc / executor / objects / UniqueRequestIdentifier.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.executor.objects;
26
27
28 import org.apache.commons.lang3.StringUtils;
29
30
31 public class UniqueRequestIdentifier {
32     private static final String IDENTIFIER_DELIMITER = "@";
33
34     private String originatorID;
35     private String requestID;
36     private String subRequestID;
37
38     private UniqueRequestIdentifier(){
39
40     }
41     public UniqueRequestIdentifier(String originatorID,
42                                    String requestID,
43                                    String subRequestID) {
44         this();
45         this.originatorID = originatorID;
46         this.requestID = requestID;
47         this.subRequestID = subRequestID;
48     }
49
50     public String toIdentifierString(){
51         StringBuilder stringBuilder = new StringBuilder();
52         if(originatorID != null){
53             stringBuilder.append(originatorID);
54         }
55         stringBuilder.append(IDENTIFIER_DELIMITER);
56
57         if(requestID != null){
58             stringBuilder.append(requestID);
59         }
60         stringBuilder.append(IDENTIFIER_DELIMITER);
61
62         if(subRequestID != null){
63             stringBuilder.append(subRequestID);
64         }
65         return stringBuilder.toString();
66     }
67
68     public static UniqueRequestIdentifier getUniqueRequestIdentifier(String identifierString){
69         String[] splitIdentifier = identifierString.split(IDENTIFIER_DELIMITER);
70         if(splitIdentifier == null || splitIdentifier.length <2){
71             throw new IllegalArgumentException("input identifierString is not valid "+identifierString);
72         }
73         String originatorID = splitIdentifier[0];
74         String requestID = StringUtils.isEmpty(splitIdentifier[1])? null :splitIdentifier[1];
75         String subRequestID = splitIdentifier.length>=3 ? splitIdentifier[2] : null;
76         return new UniqueRequestIdentifier(originatorID,requestID,subRequestID);
77     }
78     public String toString(){
79         return "originatorID = " + originatorID +
80                 " , requestID = " + requestID +
81                 " , subRequestID = " + subRequestID;
82     }
83     @Override
84     public boolean equals(Object obj){
85         if(obj ==null){
86             return false;
87         }
88         if(!(obj instanceof UniqueRequestIdentifier)){
89             return false;
90         }
91         UniqueRequestIdentifier identifier = (UniqueRequestIdentifier)obj;
92         if(this.originatorID == null){
93             if(identifier.originatorID !=null)
94                 return false;
95         }
96         else if(!this.originatorID.equals(identifier.originatorID))
97             return false;
98
99         if(this.requestID == null){
100             if(identifier.requestID !=null)
101                 return false;
102         }
103         else if(!this.requestID.equals(identifier.requestID))
104             return false;
105
106         if(this.subRequestID == null){
107             if(identifier.subRequestID !=null)
108                 return false;
109         }
110         else if(!this.subRequestID.equals(identifier.subRequestID))
111             return false;
112
113         return true;
114     }
115     @Override
116     public int hashCode(){
117         final int prime = 31;
118         int result = 1;
119         result = result * prime + (this.originatorID == null ? 0 :this.originatorID.hashCode());
120         result = result * prime + (this.requestID == null ? 0 :this.requestID.hashCode());
121         result = result * prime + (this.subRequestID == null ? 0 :this.subRequestID.hashCode());
122         return result;
123     }
124
125
126 }