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