From 5f1a6a0ab09ea3fa4199a8d413af75d4378e2a8e Mon Sep 17 00:00:00 2001 From: Instrumental Date: Tue, 26 Jun 2018 09:11:08 -0500 Subject: Initial Interface for remote Configuration Issue-ID: AAF-378 Change-Id: I320b0c23ece63199a49a5d8b1706868d2c4e5355 Signed-off-by: Instrumental --- .../java/org/onap/aaf/auth/locate/AAF_Locate.java | 15 +- .../onap/aaf/auth/locate/api/API_AAFAccess.java | 24 ++++ .../onap/aaf/auth/locate/facade/LocateFacade.java | 9 ++ .../auth/locate/facade/LocateFacadeFactory.java | 12 +- .../aaf/auth/locate/facade/LocateFacadeImpl.java | 34 ++++- .../aaf/auth/locate/facade/LocateFacade_1_0.java | 40 ------ .../aaf/auth/locate/facade/LocateFacade_1_1.java | 41 ++++++ .../org/onap/aaf/auth/locate/mapper/Mapper.java | 4 +- .../onap/aaf/auth/locate/mapper/Mapper_1_0.java | 150 -------------------- .../onap/aaf/auth/locate/mapper/Mapper_1_1.java | 153 +++++++++++++++++++++ .../aaf/auth/locate/service/LocateService.java | 5 +- .../aaf/auth/locate/service/LocateServiceImpl.java | 43 +++++- 12 files changed, 313 insertions(+), 217 deletions(-) delete mode 100644 auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_0.java create mode 100644 auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_1.java delete mode 100644 auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_0.java create mode 100644 auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java (limited to 'auth/auth-locate/src/main/java') diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java index efda67f7..9986c60a 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java @@ -30,6 +30,7 @@ import javax.servlet.Filter; import org.onap.aaf.auth.cache.Cache; import org.onap.aaf.auth.cache.Cache.Dated; import org.onap.aaf.auth.dao.CassAccess; +import org.onap.aaf.auth.dao.cass.ConfigDAO; import org.onap.aaf.auth.dao.cass.LocateDAO; import org.onap.aaf.auth.direct.DirectLocatorCreator; import org.onap.aaf.auth.direct.DirectRegistrar; @@ -41,7 +42,7 @@ import org.onap.aaf.auth.locate.api.API_Api; import org.onap.aaf.auth.locate.api.API_Find; import org.onap.aaf.auth.locate.api.API_Proxy; import org.onap.aaf.auth.locate.facade.LocateFacadeFactory; -import org.onap.aaf.auth.locate.facade.LocateFacade_1_0; +import org.onap.aaf.auth.locate.facade.LocateFacade_1_1; import org.onap.aaf.auth.locate.mapper.Mapper.API; import org.onap.aaf.auth.rserv.HttpMethods; import org.onap.aaf.auth.server.AbsService; @@ -68,8 +69,8 @@ public class AAF_Locate extends AbsService { private static final String DOT_LOCATOR = ".locator"; private static final String USER_PERMS = "userPerms"; - private LocateFacade_1_0 facade; // this is the default Facade - private LocateFacade_1_0 facade_1_0_XML; + private LocateFacade_1_1 facade; // this is the default Facade + private LocateFacade_1_1 facade_1_1_XML; public Map cacheUser; public final AAFAuthn aafAuthn; public final AAFLurPerm aafLurPerm; @@ -77,6 +78,7 @@ public class AAF_Locate extends AbsService { public final long expireIn; private final Cluster cluster; public final LocateDAO locateDAO; + public final ConfigDAO configDAO; private Locator dal; private final String aaf_service_name; private final String aaf_gui_name; @@ -103,6 +105,7 @@ public class AAF_Locate extends AbsService { cluster = org.onap.aaf.auth.dao.CassAccess.cluster(env,null); locateDAO = new LocateDAO(trans,cluster,CassAccess.KEYSPACE); + configDAO = new ConfigDAO(trans,locateDAO); // same stuff // Have AAFLocator object Create DirectLocators for Location needs AbsAAFLocator.setCreator(new DirectLocatorCreator(env, locateDAO)); @@ -112,8 +115,8 @@ public class AAF_Locate extends AbsService { aafAuthn = aafCon().newAuthn(aafLurPerm); - facade = LocateFacadeFactory.v1_0(env,locateDAO,trans,Data.TYPE.JSON); // Default Facade - facade_1_0_XML = LocateFacadeFactory.v1_0(env,locateDAO,trans,Data.TYPE.XML); + facade = LocateFacadeFactory.v1_1(env,this,trans,Data.TYPE.JSON); // Default Facade + facade_1_1_XML = LocateFacadeFactory.v1_1(env,this,trans,Data.TYPE.XML); synchronized(env) { if(cacheUser == null) { @@ -166,7 +169,7 @@ public class AAF_Locate extends AbsService { // setup Application API HTML ContentTypes for XML and Route application = applicationXML(respCls, version); - route(env,meth,path,code.clone(facade_1_0_XML,false),application,"text/xml;version="+version); + route(env,meth,path,code.clone(facade_1_1_XML,false),application,"text/xml;version="+version); // Add other Supported APIs here as created } diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_AAFAccess.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_AAFAccess.java index 9de92d14..af7611a3 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_AAFAccess.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/api/API_AAFAccess.java @@ -21,6 +21,8 @@ package org.onap.aaf.auth.locate.api; +import static org.onap.aaf.auth.layer.Result.OK; + import java.io.IOException; import java.net.ConnectException; import java.net.URI; @@ -222,6 +224,28 @@ public class API_AAFAccess { } } }); + + /** + * Configuration + */ + gwAPI.route(HttpMethods.GET,"/configure/:id/:type",API.CONFIG,new LocateCode(facade,"Deliver Configuration Properties to AAF", true) { + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + try { + Result r = facade.getConfig(trans, req, resp, pathParam(req, ":id"),pathParam(req,":type")); + switch(r.status) { + case OK: + resp.setStatus(HttpStatus.OK_200); + break; + default: + context.error(trans,resp,r); + } + + } catch (Exception e) { + context.error(trans, resp, Result.ERR_General, e.getMessage()); + } + } + }); } private static void redirect(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, LocateFacade context, Locator loc, String path) throws IOException { diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade.java index 817fcc58..8fb719fe 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade.java @@ -103,4 +103,13 @@ public interface LocateFacade { */ public abstract Result removeMgmtEndpoints(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp); + /** + * + * @param trans + * @param req + * @param resp + * @return + */ + public Result getConfig(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, String id, String type); + } \ No newline at end of file diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeFactory.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeFactory.java index ea20df5a..cff70f03 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeFactory.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeFactory.java @@ -1,5 +1,5 @@ /** - * ============LICENSE_START==================================================== +\\ * ============LICENSE_START==================================================== * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. @@ -21,10 +21,10 @@ package org.onap.aaf.auth.locate.facade; -import org.onap.aaf.auth.dao.cass.LocateDAO; import org.onap.aaf.auth.env.AuthzEnv; import org.onap.aaf.auth.env.AuthzTrans; -import org.onap.aaf.auth.locate.mapper.Mapper_1_0; +import org.onap.aaf.auth.locate.AAF_Locate; +import org.onap.aaf.auth.locate.mapper.Mapper_1_1; import org.onap.aaf.auth.locate.service.LocateServiceImpl; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Data; @@ -35,13 +35,13 @@ import locate_local.v1_0.Out; public class LocateFacadeFactory { - public static LocateFacade_1_0 v1_0(AuthzEnv env, LocateDAO locateDAO, AuthzTrans trans, Data.TYPE type) throws APIException { - return new LocateFacade_1_0( + public static LocateFacade_1_1 v1_1(AuthzEnv env, AAF_Locate locate, AuthzTrans trans, Data.TYPE type) throws APIException { + return new LocateFacade_1_1( env, new LocateServiceImpl< InRequest, Out, - Error>(trans,locateDAO,new Mapper_1_0()), + Error>(trans,locate,new Mapper_1_1()), type); } diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java index fdb02c70..af6ad1c1 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacadeImpl.java @@ -54,9 +54,9 @@ import org.onap.aaf.auth.rserv.doc.ApiDoc; import org.onap.aaf.cadi.aaf.client.Examples; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Data; +import org.onap.aaf.misc.env.Data.TYPE; import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.TimeTaken; -import org.onap.aaf.misc.env.Data.TYPE; import org.onap.aaf.misc.rosetta.env.RosettaDF; import org.onap.aaf.misc.rosetta.env.RosettaData; @@ -82,28 +82,30 @@ import locate_local.v1_0.Api; * @author Jonathan * */ -public abstract class LocateFacadeImpl extends FacadeImpl implements LocateFacade +public abstract class LocateFacadeImpl extends FacadeImpl implements LocateFacade { - private LocateService service; + private LocateService service; private final RosettaDF errDF; private final RosettaDF apiDF; private final RosettaDF epDF; private final RosettaDF mepDF; + private final RosettaDF confDF; private static long cacheClear = 0L, emptyCheck=0L; private final static Map epsCache = new HashMap(); // protected manually, in getEndpoints - public LocateFacadeImpl(AuthzEnv env, LocateService service, Data.TYPE dataType) throws APIException { + public LocateFacadeImpl(AuthzEnv env, LocateService service, Data.TYPE dataType) throws APIException { this.service = service; (errDF = env.newDataFactory(mapper().getClass(API.ERROR))).in(dataType).out(dataType); (apiDF = env.newDataFactory(Api.class)).in(dataType).out(dataType); (epDF = env.newDataFactory(mapper().getClass(API.ENDPOINTS))).in(dataType).out(dataType); (mepDF = env.newDataFactory(mapper().getClass(API.MGMT_ENDPOINTS))).in(dataType).out(dataType); + (confDF = env.newDataFactory(mapper().getClass(API.CONFIG))).in(dataType).out(dataType); } - public Mapper mapper() { + public Mapper mapper() { return service.mapper(); } @@ -391,4 +393,26 @@ public abstract class LocateFacadeImpl ex } } + private static final String GET_CONFIG = "Get Configuration"; + @Override + public Result getConfig(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp, final String id, final String type) { + TimeTaken tt = trans.start(GET_CONFIG, Env.SUB|Env.ALWAYS); + try { + Result rp = service.getConfig(trans, id, type); + switch(rp.status) { + case OK: + setContentType(resp,mepDF.getOutType()); + confDF.newData(trans).load(rp.value).to(resp.getOutputStream()); + return Result.ok(); + default: + return Result.err(rp); + } + } catch (Exception e) { + trans.error().log(e,IN,GET_CONFIG); + return Result.err(e); + } finally { + tt.done(); + } + } + } \ No newline at end of file diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_0.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_0.java deleted file mode 100644 index e2d2c9f6..00000000 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_0.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * ============LICENSE_START==================================================== - * org.onap.aaf - * =========================================================================== - * Copyright (c) 2018 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.onap.aaf.auth.locate.facade; - -import org.onap.aaf.auth.env.AuthzEnv; -import org.onap.aaf.auth.locate.service.LocateService; -import org.onap.aaf.misc.env.APIException; -import org.onap.aaf.misc.env.Data; - -import locate.v1_0.Endpoints; -import locate.v1_0.MgmtEndpoints; -import locate_local.v1_0.InRequest; -import locate_local.v1_0.Out; -import locate_local.v1_0.Error; - -public class LocateFacade_1_0 extends LocateFacadeImpl -{ - public LocateFacade_1_0(AuthzEnv env, LocateService service, Data.TYPE type) throws APIException { - super(env, service, type); - } -} diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_1.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_1.java new file mode 100644 index 00000000..d044b731 --- /dev/null +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/facade/LocateFacade_1_1.java @@ -0,0 +1,41 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 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.onap.aaf.auth.locate.facade; + +import org.onap.aaf.auth.env.AuthzEnv; +import org.onap.aaf.auth.locate.service.LocateService; +import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.env.Data; + +import locate.v1_0.Endpoints; +import locate.v1_0.MgmtEndpoints; +import locate_local.v1_0.Error; +import locate_local.v1_0.InRequest; +import locate_local.v1_0.Out; +import locate_local.v1_1.Configuration; + +public class LocateFacade_1_1 extends LocateFacadeImpl +{ + public LocateFacade_1_1(AuthzEnv env, LocateService service, Data.TYPE type) throws APIException { + super(env, service, type); + } +} diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper.java index 685d096f..7e012f2d 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper.java @@ -28,9 +28,9 @@ import org.onap.aaf.auth.layer.Result; import locate.v1_0.MgmtEndpoint; -public interface Mapper +public interface Mapper { - public enum API{IN_REQ,OUT,ENDPOINTS,MGMT_ENDPOINTS,ERROR,VOID}; + public enum API{IN_REQ,OUT,ENDPOINTS,MGMT_ENDPOINTS,CONFIG,ERROR,VOID}; public Class getClass(API api); public A newInstance(API api); diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_0.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_0.java deleted file mode 100644 index 50839b73..00000000 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_0.java +++ /dev/null @@ -1,150 +0,0 @@ -/** - * ============LICENSE_START==================================================== - * org.onap.aaf - * =========================================================================== - * Copyright (c) 2018 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.onap.aaf.auth.locate.mapper; - -import java.util.List; - -import org.onap.aaf.auth.dao.cass.LocateDAO.Data; -import org.onap.aaf.auth.layer.Result; -import org.onap.aaf.cadi.util.Vars; -import org.onap.aaf.misc.env.util.Split; - -import locate.v1_0.Endpoint; -import locate.v1_0.Endpoints; -import locate.v1_0.MgmtEndpoint; -import locate.v1_0.MgmtEndpoints; -import locate_local.v1_0.Error; -import locate_local.v1_0.InRequest; -import locate_local.v1_0.Out; - -public class Mapper_1_0 implements Mapper { - - @Override - public Class getClass(API api) { - switch(api) { - case IN_REQ: return InRequest.class; - case OUT: return Out.class; - case ERROR: return Error.class; - case VOID: return Void.class; - case ENDPOINTS: return Endpoints.class; - case MGMT_ENDPOINTS: return MgmtEndpoints.class; - } - return null; - } - - @SuppressWarnings("unchecked") - @Override - public A newInstance(API api) { - switch(api) { - case IN_REQ: return (A) new InRequest(); - case OUT: return (A) new Out(); - case ERROR: return (A)new Error(); - case ENDPOINTS: return (A) new Endpoints(); - case MGMT_ENDPOINTS: return (A) new MgmtEndpoints(); - case VOID: return null; - } - return null; - } - - ////////////// Mapping Functions ///////////// - @Override - public locate_local.v1_0.Error errorFromMessage(StringBuilder holder, String msgID, String text,String... var) { - Error err = new Error(); - err.setMessageId(msgID); - // AT&T Restful Error Format requires numbers "%" placements - err.setText(Vars.convert(holder, text, var)); - for(String s : var) { - err.getVariables().add(s); - } - return err; - } - - /* (non-Javadoc) - * @see org.onap.aaf.auth.locate.mapper.Mapper#endpoints(org.onap.aaf.auth.layer.test.Result, java.lang.String, java.lang.String) - */ - @Override - public Result endpoints(Result> resultDB, String version, String other) { - if(resultDB.notOK()) { - return Result.err(resultDB); - } - int major=-1, minor=-1, patch=-1, pkg=-1; - if(version!=null) { - try { - String[] v = Split.split('.',version); - if(v.length>0) {major = Integer.parseInt(v[0]);} - if(v.length>1) {minor = Integer.parseInt(v[1]);} - if(v.length>2) {patch = Integer.parseInt(v[2]);} - if(v.length>3) {pkg = Integer.parseInt(v[3]);} - } catch (NumberFormatException e) { - return Result.err(Result.ERR_BadData,"Invalid Version String " + version); - } - } - Endpoints eps = new Endpoints(); - List leps = eps.getEndpoint(); - for(Data d : resultDB.value) { - if((major<0 || major==d.major) && - (minor<0 || minor<=d.minor) && - (patch<0 || patch==d.patch) && - (pkg<0 || pkg ==d.pkg)) { - Endpoint ep = new Endpoint(); - ep.setName(d.name); - ep.setHostname(d.hostname); - ep.setPort(d.port); - ep.setMajor(d.major); - ep.setMinor(d.minor); - ep.setPatch(d.patch); - ep.setPkg(d.pkg); - ep.setLatitude(d.latitude); - ep.setLongitude(d.longitude); - ep.setProtocol(d.protocol); - for(String s : d.subprotocol(false)) { - ep.getSubprotocol().add(s); - } - leps.add(ep); - } - } - return Result.ok(eps); - } - - /* (non-Javadoc) - * @see org.onap.aaf.auth.locate.mapper.Mapper#locateData(locate.v1_0.MgmtEndpoint) - */ - @Override - public Data locateData(MgmtEndpoint me) { - Data data = new Data(); - data.name = me.getName(); - data.port = me.getPort(); - data.hostname = me.getHostname(); - data.major = me.getMajor(); - data.minor = me.getMinor(); - data.patch = me.getPatch(); - data.pkg = me.getPkg(); - data.latitude = me.getLatitude(); - data.longitude = me.getLongitude(); - data.protocol = me.getProtocol(); - for(String s : me.getSubprotocol()) { - data.subprotocol(true).add(s); - } - return data; - } - -} \ No newline at end of file diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java new file mode 100644 index 00000000..61178951 --- /dev/null +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/mapper/Mapper_1_1.java @@ -0,0 +1,153 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 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.onap.aaf.auth.locate.mapper; + +import java.util.List; + +import org.onap.aaf.auth.dao.cass.LocateDAO.Data; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.cadi.util.Vars; +import org.onap.aaf.misc.env.util.Split; + +import locate.v1_0.Endpoint; +import locate.v1_0.Endpoints; +import locate.v1_0.MgmtEndpoint; +import locate.v1_0.MgmtEndpoints; +import locate_local.v1_0.Error; +import locate_local.v1_0.InRequest; +import locate_local.v1_0.Out; +import locate_local.v1_1.Configuration; + +public class Mapper_1_1 implements Mapper { + + @Override + public Class getClass(API api) { + switch(api) { + case IN_REQ: return InRequest.class; + case OUT: return Out.class; + case ERROR: return Error.class; + case VOID: return Void.class; + case ENDPOINTS: return Endpoints.class; + case MGMT_ENDPOINTS: return MgmtEndpoints.class; + case CONFIG: return Configuration.class; + } + return null; + } + + @SuppressWarnings("unchecked") + @Override + public A newInstance(API api) { + switch(api) { + case IN_REQ: return (A) new InRequest(); + case OUT: return (A) new Out(); + case ERROR: return (A)new Error(); + case ENDPOINTS: return (A) new Endpoints(); + case MGMT_ENDPOINTS: return (A) new MgmtEndpoints(); + case CONFIG: return (A) new Configuration(); + case VOID: return null; + } + return null; + } + + ////////////// Mapping Functions ///////////// + @Override + public locate_local.v1_0.Error errorFromMessage(StringBuilder holder, String msgID, String text,String... var) { + Error err = new Error(); + err.setMessageId(msgID); + // AT&T Restful Error Format requires numbers "%" placements + err.setText(Vars.convert(holder, text, var)); + for(String s : var) { + err.getVariables().add(s); + } + return err; + } + + /* (non-Javadoc) + * @see org.onap.aaf.auth.locate.mapper.Mapper#endpoints(org.onap.aaf.auth.layer.test.Result, java.lang.String, java.lang.String) + */ + @Override + public Result endpoints(Result> resultDB, String version, String other) { + if(resultDB.notOK()) { + return Result.err(resultDB); + } + int major=-1, minor=-1, patch=-1, pkg=-1; + if(version!=null) { + try { + String[] v = Split.split('.',version); + if(v.length>0) {major = Integer.parseInt(v[0]);} + if(v.length>1) {minor = Integer.parseInt(v[1]);} + if(v.length>2) {patch = Integer.parseInt(v[2]);} + if(v.length>3) {pkg = Integer.parseInt(v[3]);} + } catch (NumberFormatException e) { + return Result.err(Result.ERR_BadData,"Invalid Version String " + version); + } + } + Endpoints eps = new Endpoints(); + List leps = eps.getEndpoint(); + for(Data d : resultDB.value) { + if((major<0 || major==d.major) && + (minor<0 || minor<=d.minor) && + (patch<0 || patch==d.patch) && + (pkg<0 || pkg ==d.pkg)) { + Endpoint ep = new Endpoint(); + ep.setName(d.name); + ep.setHostname(d.hostname); + ep.setPort(d.port); + ep.setMajor(d.major); + ep.setMinor(d.minor); + ep.setPatch(d.patch); + ep.setPkg(d.pkg); + ep.setLatitude(d.latitude); + ep.setLongitude(d.longitude); + ep.setProtocol(d.protocol); + for(String s : d.subprotocol(false)) { + ep.getSubprotocol().add(s); + } + leps.add(ep); + } + } + return Result.ok(eps); + } + + /* (non-Javadoc) + * @see org.onap.aaf.auth.locate.mapper.Mapper#locateData(locate.v1_0.MgmtEndpoint) + */ + @Override + public Data locateData(MgmtEndpoint me) { + Data data = new Data(); + data.name = me.getName(); + data.port = me.getPort(); + data.hostname = me.getHostname(); + data.major = me.getMajor(); + data.minor = me.getMinor(); + data.patch = me.getPatch(); + data.pkg = me.getPkg(); + data.latitude = me.getLatitude(); + data.longitude = me.getLongitude(); + data.protocol = me.getProtocol(); + for(String s : me.getSubprotocol()) { + data.subprotocol(true).add(s); + } + return data; + } + +} \ No newline at end of file diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateService.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateService.java index d2a37348..ac2e3c46 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateService.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateService.java @@ -25,9 +25,10 @@ import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.layer.Result; import org.onap.aaf.auth.locate.mapper.Mapper; -public interface LocateService { - public Mapper mapper(); +public interface LocateService { + public Mapper mapper(); public Result getEndPoints(AuthzTrans trans, String service, String version, String other); public Result putMgmtEndPoints(AuthzTrans trans, MGMT_ENDPOINTS meps); public Result removeMgmtEndPoints(AuthzTrans trans, MGMT_ENDPOINTS meps); + public Result getConfig(AuthzTrans trans, String id, String type); } diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateServiceImpl.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateServiceImpl.java index d1a03cdc..9789ad0e 100644 --- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateServiceImpl.java +++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/service/LocateServiceImpl.java @@ -21,11 +21,15 @@ package org.onap.aaf.auth.locate.service; +import java.util.List; import java.util.UUID; +import org.onap.aaf.auth.dao.cass.ConfigDAO; +import org.onap.aaf.auth.dao.cass.ConfigDAO.Data; import org.onap.aaf.auth.dao.cass.LocateDAO; import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.auth.locate.AAF_Locate; import org.onap.aaf.auth.locate.mapper.Mapper; import org.onap.aaf.auth.locate.validation.LocateValidator; import org.onap.aaf.cadi.aaf.AAFPermission; @@ -34,20 +38,24 @@ import org.onap.aaf.misc.env.APIException; import locate.v1_0.Endpoints; import locate.v1_0.MgmtEndpoint; import locate.v1_0.MgmtEndpoints; +import locate_local.v1_1.Configuration; +import locate_local.v1_1.Configuration.Props; public class LocateServiceImpl - implements LocateService { - private Mapper mapper; - private LocateDAO locateDAO; + implements LocateService { + private Mapper mapper; + protected LocateDAO locateDAO; + private ConfigDAO configDAO; private boolean permToRegister; - public LocateServiceImpl(AuthzTrans trans, LocateDAO locateDAO, Mapper mapper) throws APIException { + public LocateServiceImpl(AuthzTrans trans, AAF_Locate locate, Mapper mapper) throws APIException { this.mapper = mapper; - this.locateDAO = locateDAO; + this.locateDAO = locate.locateDAO; + this.configDAO = locate.configDAO; permToRegister = false; //TODO Setup a Configuration for this } - public Mapper mapper() {return mapper;} + public Mapper mapper() {return mapper;} @Override public Result getEndPoints(AuthzTrans trans, String service, String version, String other) { @@ -117,6 +125,29 @@ public class LocateServiceImpl } } + ///// ADDED v1_1 + /* (non-Javadoc) + * @see org.onap.aaf.auth.locate.service.LocateService#getConfig(org.onap.aaf.auth.env.AuthzTrans, java.lang.String, java.lang.String) + */ + @Override + public Result getConfig(AuthzTrans trans, String id, String type) { + Result> dr = configDAO.readName(trans, type); + Configuration c = new Configuration(); + c.setName(type); + Props p; + + if(dr.isOKhasData()) { + for(ConfigDAO.Data data : dr.value) { + p = new Props(); + p.setTag(data.tag); + p.setValue(data.value); + c.getProps().add(p); + } + } + return Result.ok(c); + //return Result.err(Result.ERR_NotImplemented,"not done yet"); + } + //////////////// APIs /////////////////// }; -- cgit 1.2.3-korg