2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.appc.executor.objects;
25 import org.apache.commons.lang3.StringUtils;
28 public class UniqueRequestIdentifier {
29 private static final String IDENTIFIER_DELIMITER = "@";
31 private String originatorID;
32 private String requestID;
33 private String subRequestID;
35 private UniqueRequestIdentifier(){
38 public UniqueRequestIdentifier(String originatorID,
40 String subRequestID) {
42 this.originatorID = originatorID;
43 this.requestID = requestID;
44 this.subRequestID = subRequestID;
47 public String toIdentifierString(){
48 StringBuilder stringBuilder = new StringBuilder();
49 if(originatorID != null){
50 stringBuilder.append(originatorID);
52 stringBuilder.append(IDENTIFIER_DELIMITER);
54 if(requestID != null){
55 stringBuilder.append(requestID);
57 stringBuilder.append(IDENTIFIER_DELIMITER);
59 if(subRequestID != null){
60 stringBuilder.append(subRequestID);
62 return stringBuilder.toString();
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);
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);
75 public String toString(){
76 return "originatorID = " + originatorID +
77 " , requestID = " + requestID +
78 " , subRequestID = " + subRequestID;
81 public boolean equals(Object obj){
85 if(!(obj instanceof UniqueRequestIdentifier)){
88 UniqueRequestIdentifier identifier = (UniqueRequestIdentifier)obj;
89 if(this.originatorID == null){
90 if(identifier.originatorID !=null)
93 else if(!this.originatorID.equals(identifier.originatorID))
96 if(this.requestID == null){
97 if(identifier.requestID !=null)
100 else if(!this.requestID.equals(identifier.requestID))
103 if(this.subRequestID == null){
104 if(identifier.subRequestID !=null)
107 else if(!this.subRequestID.equals(identifier.subRequestID))
113 public int hashCode(){
114 final int prime = 31;
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());