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 com.att.cadi.client;
\r
25 import java.net.HttpURLConnection;
\r
26 import java.util.HashMap;
\r
27 import java.util.Map;
\r
29 import com.att.aft.dme2.api.DME2Manager;
\r
30 import com.att.cadi.Access;
\r
31 import com.att.cadi.config.Config;
\r
32 import com.att.cadi.config.SecurityInfoC;
\r
33 import com.att.cadi.http.HBasicAuthSS;
\r
34 import com.att.cadi.http.HMangr;
\r
35 import com.att.cadi.locator.DME2Locator;
\r
36 import com.att.inno.env.APIException;
\r
37 import com.att.rosetta.env.RosettaDF;
\r
38 import com.att.rosetta.env.RosettaEnv;
\r
40 public class AAFClient {
\r
41 private RosettaEnv env;
\r
42 private Map<Class<?>,RosettaDF<?>> map = new HashMap<Class<?>,RosettaDF<?>>();
\r
46 public AAFClient(RosettaEnv env) throws Exception {
\r
48 Access access = new EnvAccess(env);
\r
49 String user = access.getProperty(Config.AAF_MECHID,null);
\r
50 String password = access.decrypt(access.getProperty(Config.AAF_MECHPASS,null), true);
\r
52 SecurityInfoC<HttpURLConnection> si = new SecurityInfoC<HttpURLConnection>(access);
\r
53 DME2Manager dm = new DME2Manager("APIclient DME2Manager", System.getProperties());
\r
54 DME2Locator loc = new DME2Locator(access, dm, access.getProperty(Config.AAF_URL,null));
\r
56 int TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, "30000"));
\r
58 hman = new HMangr(access, loc).readTimeout(TIMEOUT).apiVersion("2.0");
\r
59 ss = new HBasicAuthSS(user, password, si);
\r
62 public AAFClient(RosettaEnv env, DME2Manager dm) throws Exception {
\r
64 Access access = new EnvAccess(env);
\r
65 String user = access.getProperty(Config.AAF_MECHID,null);
\r
66 String password = access.decrypt(access.getProperty(Config.AAF_MECHPASS,null), true);
\r
68 SecurityInfoC<HttpURLConnection> si = new SecurityInfoC<HttpURLConnection>(access);
\r
69 DME2Locator loc = new DME2Locator(access, dm, access.getProperty(Config.AAF_URL,null));
\r
71 int TIMEOUT = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, "30000"));
\r
73 hman = new HMangr(access, loc).readTimeout(TIMEOUT).apiVersion("2.0");
\r
74 ss = new HBasicAuthSS(user, password, si);
\r
77 @SuppressWarnings("unchecked")
\r
78 private synchronized<T> RosettaDF<T> getDF(Class<T> cls) throws APIException {
\r
80 synchronized (env) {
\r
83 rdf = env.newDataFactory(cls);
\r
87 return (RosettaDF<T>)rdf;
\r
90 // Package on purpose
\r
91 static class Call<T> {
\r
92 protected final static String VOID_CONTENT_TYPE="application/Void+json;version=2.0";
\r
94 protected RosettaDF<T> df;
\r
95 protected AAFClient client;
\r
97 public Call(AAFClient ac, RosettaDF<T> df) {
\r
104 /////////// Calls /////////////////
\r
106 * Returns a Get Object... same as "get"
\r
110 * @throws APIException
\r
112 public<T> Get<T> read(Class<T> cls) throws APIException {
\r
113 return new Get<T>(this,getDF(cls));
\r
117 * Returns a Get Object... same as "read"
\r
121 * @throws APIException
\r
123 public<T> Get<T> get(Class<T> cls) throws APIException {
\r
124 return new Get<T>(this,getDF(cls));
\r
128 * Returns a Post Object... same as "create"
\r
132 * @throws APIException
\r
134 public<T> Post<T> post(Class<T> cls) throws APIException {
\r
135 return new Post<T>(this,getDF(cls));
\r
139 * Returns a Post Object... same as "post"
\r
143 * @throws APIException
\r
145 public<T> Post<T> create(Class<T> cls) throws APIException {
\r
146 return new Post<T>(this,getDF(cls));
\r
150 * Returns a Put Object... same as "update"
\r
154 * @throws APIException
\r
156 public<T> Put<T> put(Class<T> cls) throws APIException {
\r
157 return new Put<T>(this,getDF(cls));
\r
161 * Returns a Put Object... same as "put"
\r
165 * @throws APIException
\r
167 public<T> Put<T> update(Class<T> cls) throws APIException {
\r
168 return new Put<T>(this,getDF(cls));
\r
172 * Returns a Delete Object
\r
176 * @throws APIException
\r
178 public<T> Delete<T> delete(Class<T> cls) throws APIException {
\r
179 return new Delete<T>(this,getDF(cls));
\r
183 * Returns a Delete Object
\r
187 * @throws APIException
\r
189 public Delete<Void> delete() throws APIException {
\r
190 return new Delete<Void>(this,null);
\r
193 public Put<Void> put() {
\r
194 return new Put<Void>(this,null);
\r