1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.client;
\r
25 import java.net.HttpURLConnection;
\r
26 import java.util.HashMap;
\r
27 import java.util.Map;
\r
29 import org.onap.aaf.cadi.Access;
\r
30 import org.onap.aaf.cadi.config.Config;
\r
31 import org.onap.aaf.cadi.config.SecurityInfoC;
\r
32 import org.onap.aaf.cadi.http.HBasicAuthSS;
\r
33 import org.onap.aaf.cadi.http.HMangr;
\r
34 import org.onap.aaf.cadi.locator.DME2Locator;
\r
36 import com.att.aft.dme2.api.DME2Manager;
\r
37 import org.onap.aaf.inno.env.APIException;
\r
38 import org.onap.aaf.rosetta.env.RosettaDF;
\r
39 import org.onap.aaf.rosetta.env.RosettaEnv;
\r
41 public class AAFClient {
\r
42 private RosettaEnv env;
\r
43 private Map<Class<?>,RosettaDF<?>> map = new HashMap<Class<?>,RosettaDF<?>>();
\r
47 public AAFClient(RosettaEnv env) throws Exception {
\r
49 Access access = new EnvAccess(env);
\r
50 String user = access.getProperty(Config.AAF_MECHID,null);
\r
51 String password = access.decrypt(access.getProperty(Config.AAF_MECHPASS,null), true);
\r
53 SecurityInfoC<HttpURLConnection> si = new SecurityInfoC<HttpURLConnection>(access);
\r
54 DME2Manager dm = new DME2Manager("APIclient DME2Manager", System.getProperties());
\r
55 DME2Locator loc = new DME2Locator(access, dm, access.getProperty(Config.AAF_URL,null));
\r
57 int TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, "30000"));
\r
59 hman = new HMangr(access, loc).readTimeout(TIMEOUT).apiVersion("2.0");
\r
60 ss = new HBasicAuthSS(user, password, si);
\r
63 public AAFClient(RosettaEnv env, DME2Manager dm) throws Exception {
\r
65 Access access = new EnvAccess(env);
\r
66 String user = access.getProperty(Config.AAF_MECHID,null);
\r
67 String password = access.decrypt(access.getProperty(Config.AAF_MECHPASS,null), true);
\r
69 SecurityInfoC<HttpURLConnection> si = new SecurityInfoC<HttpURLConnection>(access);
\r
70 DME2Locator loc = new DME2Locator(access, dm, access.getProperty(Config.AAF_URL,null));
\r
72 int TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, "30000"));
\r
74 hman = new HMangr(access, loc).readTimeout(TIMEOUT).apiVersion("2.0");
\r
75 ss = new HBasicAuthSS(user, password, si);
\r
78 @SuppressWarnings("unchecked")
\r
79 private synchronized<T> RosettaDF<T> getDF(Class<T> cls) throws APIException {
\r
81 synchronized (env) {
\r
84 rdf = env.newDataFactory(cls);
\r
88 return (RosettaDF<T>)rdf;
\r
91 // Package on purpose
\r
92 static class Call<T> {
\r
93 protected final static String VOID_CONTENT_TYPE="application/Void+json;version=2.0";
\r
95 protected RosettaDF<T> df;
\r
96 protected AAFClient client;
\r
98 public Call(AAFClient ac, RosettaDF<T> df) {
\r
105 /////////// Calls /////////////////
\r
107 * Returns a Get Object... same as "get"
\r
111 * @throws APIException
\r
113 public<T> Get<T> read(Class<T> cls) throws APIException {
\r
114 return new Get<T>(this,getDF(cls));
\r
118 * Returns a Get Object... same as "read"
\r
122 * @throws APIException
\r
124 public<T> Get<T> get(Class<T> cls) throws APIException {
\r
125 return new Get<T>(this,getDF(cls));
\r
129 * Returns a Post Object... same as "create"
\r
133 * @throws APIException
\r
135 public<T> Post<T> post(Class<T> cls) throws APIException {
\r
136 return new Post<T>(this,getDF(cls));
\r
140 * Returns a Post Object... same as "post"
\r
144 * @throws APIException
\r
146 public<T> Post<T> create(Class<T> cls) throws APIException {
\r
147 return new Post<T>(this,getDF(cls));
\r
151 * Returns a Put Object... same as "update"
\r
155 * @throws APIException
\r
157 public<T> Put<T> put(Class<T> cls) throws APIException {
\r
158 return new Put<T>(this,getDF(cls));
\r
162 * Returns a Put Object... same as "put"
\r
166 * @throws APIException
\r
168 public<T> Put<T> update(Class<T> cls) throws APIException {
\r
169 return new Put<T>(this,getDF(cls));
\r
173 * Returns a Delete Object
\r
177 * @throws APIException
\r
179 public<T> Delete<T> delete(Class<T> cls) throws APIException {
\r
180 return new Delete<T>(this,getDF(cls));
\r
184 * Returns a Delete Object
\r
188 * @throws APIException
\r
190 public Delete<Void> delete() throws APIException {
\r
191 return new Delete<Void>(this,null);
\r
194 public Put<Void> put() {
\r
195 return new Put<Void>(this,null);
\r