Adding support for external microservice
[aai/data-router.git] / src / main / java / org / openecomp / datarouter / util / AaiUiSvcPolicyUtil.java
1 /**
2  * ============LICENSE_START=======================================================
3  * DataRouter
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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  * ============LICENSE_END=========================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.openecomp.datarouter.util;
26
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
29
30 import com.fasterxml.jackson.databind.JsonNode;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32
33
34 public class AaiUiSvcPolicyUtil {
35
36   static ObjectMapper mapper = new ObjectMapper();
37   
38   public static JsonNode getOriginPayload(JsonNode payload) throws Exception{
39     /*
40      *{
41         "origin-uri": "/routerService/1search1",
42         "origin-payload": {}
43       }
44      */
45     JsonNode origPayload = null;
46     
47     if (payload.has("origin-payload")){
48       origPayload = payload.get("origin-payload");
49     }
50     return origPayload;
51   }
52   
53   public static String getOriginUri ( JsonNode payload ) throws Exception {
54     String originUri = "";
55     if (payload.has("origin-uri")){
56       originUri = payload.get("origin-uri").textValue();
57     }
58     return originUri;
59   }
60   
61   public static String getTargetUri(JsonNode payload) throws Exception{
62     /*
63      *{
64         "origin-uri": "/routerService/1search1",
65         "origin-payload": {}
66       }
67      */
68     String uri = "";
69     String originUri = getOriginUri(payload);
70     final Matcher m = Pattern.compile("/routerService/(.*)").matcher(originUri);
71     if ( m.find() ) {
72       uri = m.group(1);
73     } 
74     return uri;
75   }
76   
77 }