aboutsummaryrefslogtreecommitdiffstats
path: root/mdsal-resource/provider/src/main/java/org/openecomp/sdnc/sli/resource/mdsal/ConfigResource.java
blob: 4f5b7f04043e2618cdb983a77659a95ae4ea4609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*-
 * ============LICENSE_START=======================================================
 * openECOMP : SDN-C
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights
 * 							reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdnc.sli.resource.mdsal;

import java.util.Map;

import org.openecomp.sdnc.sli.SvcLogicContext;
import org.openecomp.sdnc.sli.SvcLogicException;
import org.openecomp.sdnc.sli.SvcLogicResource;
import org.openecomp.sdnc.sli.SvcLogicResource.QueryStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;

public class ConfigResource implements SvcLogicResource {

	private static final Logger LOG = LoggerFactory.getLogger(ConfigResource.class);

	private RestService restService;

	public ConfigResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd)
	{
		restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML);
	}

	@Override
	public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException
	{
		return(query(resource, false, null, key, prefix, null, null));
	}

	@Override
	public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException
	{

		return(query(resource, false, null, key, prefix, null, null));

	}

	@Override
	public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix,
			String orderBy, SvcLogicContext ctx) throws SvcLogicException {


		String module = resource;
		StringBuffer restQuery = new StringBuffer();

		String[] keyParts = key.split("/");

		for (String keyPart : keyParts) {
			if (restQuery.length() > 0) {
				restQuery.append("/");
			}
			if (keyPart.startsWith("$")) {

				restQuery.append(ctx.resolve(keyPart.substring(1)));
			} else {
				restQuery.append(keyPart);
			}
		}

		String restQueryStr = restQuery.toString();
		if ((restQueryStr.startsWith("'") && restQueryStr.endsWith("'")) ||
				(restQueryStr.startsWith("\"") && restQueryStr.endsWith("\""))) {
			restQueryStr = restQueryStr.substring(1, restQueryStr.length()-1);
		}

		String urlString = "restconf/config/" + module + ":" + restQueryStr;

                LOG.info("Querying resource: " + resource + ". At URL: " + urlString);

		Document results = restService.get(urlString);


		if (results == null) {
			return(QueryStatus.NOT_FOUND);
		} else {

			if (ctx != null) {
				ctx.mergeDocument(prefix, results);
			}
			return(QueryStatus.SUCCESS);
		}

	}

	@Override
	public QueryStatus reserve(String resource, String select, String key, String prefix,
			SvcLogicContext ctx) throws SvcLogicException {


		return(QueryStatus.SUCCESS);

	}

	@Override
	public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {

		return(QueryStatus.SUCCESS);
	}

	@Override
	public QueryStatus delete(String arg0, String arg1, SvcLogicContext arg2)
			throws SvcLogicException {
		// TODO Auto-generated method stub
		return(QueryStatus.SUCCESS);
	}

	@Override
	public QueryStatus save(String arg0, boolean arg1, boolean localOnly, String arg2,
			Map<String, String> arg3, String arg4, SvcLogicContext arg5)
			throws SvcLogicException {
		// TODO Auto-generated method stub
		return(QueryStatus.SUCCESS);
	}

	@Override
	public QueryStatus notify(String resource, String action, String key,
			SvcLogicContext ctx) throws SvcLogicException {
		return(QueryStatus.SUCCESS);
	}


	public QueryStatus update(String resource, String key,
			Map<String, String> parms, String prefix, SvcLogicContext ctx)
			throws SvcLogicException {
		return(QueryStatus.SUCCESS);
	}



}