Change nexus values to properties
[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  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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  */
21
22 package org.openecomp.appc.executor.objects;
23
24
25 import org.apache.commons.lang3.StringUtils;
26
27
28 public class UniqueRequestIdentifier {
29     private static final String IDENTIFIER_DELIMITER = "@";
30
31     private String originatorID;
32     private String requestID;
33     private String subRequestID;
34
35     private UniqueRequestIdentifier(){
36
37     }
38     public UniqueRequestIdentifier(String originatorID,
39                                    String requestID,
40                                    String subRequestID) {
41         this();
42         this.originatorID = originatorID;
43         this.requestID = requestID;
44         this.subRequestID = subRequestID;
45     }
46
47     public String toIdentifierString(){
48         StringBuilder stringBuilder = new StringBuilder();
49         if(originatorID != null){
50             stringBuilder.append(originatorID);
51         }
52         stringBuilder.append(IDENTIFIER_DELIMITER);
53
54         if(requestID != null){
55             stringBuilder.append(requestID);
56         }
57         stringBuilder.append(IDENTIFIER_DELIMITER);
58
59         if(subRequestID != null){
60             stringBuilder.append(subRequestID);
61         }
62         return stringBuilder.toString();
63     }
64
65     public static UniqueRequestIdentifier getUniqueRequestIdentifier(String identifierString){
66         String[] splitIdentifier = identifierString.split(IDENTIFIER_DELIMITER);
67         if(splitIdentifier == null || splitIdentifier.length <2){
68             throw new IllegalArgumentException("input identifierString is not valid "+identifierString);
69         }
70         String originatorID = splitIdentifier[0];
71         String requestID = StringUtils.isEmpty(splitIdentifier[1])? null :splitIdentifier[1];
72         String subRequestID = splitIdentifier.length>=3 ? splitIdentifier[2] : null;
73         return new UniqueRequestIdentifier(originatorID,requestID,subRequestID);
74     }
75     public String toString(){
76         return "originatorID = " + originatorID +
77                 " , requestID = " + requestID +
78                 " , subRequestID = " + subRequestID;
79     }
80     @Override
81     public boolean equals(Object obj){
82         if(obj ==null){
83             return false;
84         }
85         if(!(obj instanceof UniqueRequestIdentifier)){
86             return false;
87         }
88         UniqueRequestIdentifier identifier = (UniqueRequestIdentifier)obj;
89         if(this.originatorID == null){
90             if(identifier.originatorID !=null)
91                 return false;
92         }
93         else if(!this.originatorID.equals(identifier.originatorID))
94             return false;
95
96         if(this.requestID == null){
97             if(identifier.requestID !=null)
98                 return false;
99         }
100         else if(!this.requestID.equals(identifier.requestID))
101             return false;
102
103         if(this.subRequestID == null){
104             if(identifier.subRequestID !=null)
105                 return false;
106         }
107         else if(!this.subRequestID.equals(identifier.subRequestID))
108             return false;
109
110         return true;
111     }
112     @Override
113     public int hashCode(){
114         final int prime = 31;
115         int result = 1;
116         result = result * prime + (this.originatorID == null ? 0 :this.originatorID.hashCode());
117         result = result * prime + (this.requestID == null ? 0 :this.requestID.hashCode());
118         result = result * prime + (this.subRequestID == null ? 0 :this.subRequestID.hashCode());
119         return result;
120     }
121
122
123 }