Changed to unmaintained
[appc.git] / appc-config / appc-flow-controller / provider / src / main / java / org / onap / appc / flow / controller / node / ResourceUriExtractor.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2018 Nokia. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2018-2019 AT&T Intellectual Property. 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 package org.onap.appc.flow.controller.node;
23
24 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.HTTP;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS_ALT;
28 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
29 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL;
30 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PORT;
31 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_CONTEXT_URL;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34 import org.apache.commons.lang.StringUtils;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36
37 /**
38  * Helper class for RestServiceNode
39  */
40 class ResourceUriExtractor {
41
42     private static final EELFLogger log = EELFManager.getInstance().getLogger(RestServiceNode.class);
43
44     String extractResourceUri(SvcLogicContext ctx) throws Exception {
45         String resourceUri = ctx.getAttribute(INPUT_URL);
46
47         if (StringUtils.isBlank(resourceUri)) {
48             resourceUri = getAddress(ctx);
49             log.info("resourceUri= " + resourceUri);
50             resourceUri += getContext(ctx);
51             log.info("resourceUri= " + resourceUri);
52
53         }
54         log.info("resourceUri= " + resourceUri);
55
56         return resourceUri;
57     }
58
59     private String getAddress(SvcLogicContext ctx) {
60         String address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS);
61         if (address == null || address.length() == 0)
62             address = ctx.getAttribute(INPUT_HOST_IP_ADDRESS_ALT);
63         String port = ctx.getAttribute(REST_PORT);
64         return HTTP + address + ":" + port;
65     }
66
67     private String getContext(SvcLogicContext ctx) throws Exception {
68         String context;
69         if (StringUtils.isNotBlank(ctx.getAttribute(INPUT_CONTEXT))) {
70             context = "/" + ctx.getAttribute(INPUT_CONTEXT);
71         } else if (StringUtils.isNotBlank(ctx.getAttribute(REST_CONTEXT_URL))) {
72             context = "/" + ctx.getAttribute(REST_CONTEXT_URL);
73         } else {
74             throw new Exception("Could not find the context for operation " + ctx.getAttribute(INPUT_REQUEST_ACTION));
75         }
76         return context;
77     }
78
79 }