Integrate aai-schema-ingest library into aai-core
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / audit / ListEndpoints.java
index 5ee973a..c56fdd7 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-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.
@@ -16,8 +16,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
 package org.onap.aai.audit;
 
@@ -32,17 +30,21 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.commons.lang.StringUtils;
-
+import org.onap.aai.config.SpringContextAware;
 import org.onap.aai.db.props.AAIProperties;
 import org.onap.aai.introspection.Introspector;
 import org.onap.aai.introspection.Loader;
 import org.onap.aai.introspection.LoaderFactory;
 import org.onap.aai.introspection.ModelType;
-import org.onap.aai.introspection.Version;
+import org.onap.aai.setup.SchemaVersion;
 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
+import org.onap.aai.logging.LogFormatTools;
+
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.google.common.base.CaseFormat;
+import org.onap.aai.setup.SchemaVersions;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 
 /**
  * The Class ListEndpoints.
@@ -63,10 +65,24 @@ public class ListEndpoints {
         * @param args the arguments
         */
        public static void main(String[] args) {
-               ListEndpoints endPoints = new ListEndpoints(AAIProperties.LATEST);
 
-               System.out.println(endPoints.toString("relationship-list"));
+               AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
+                       "org.onap.aai.config",
+                       "org.onap.aai.setup"
+               );
+
+               String schemaUriBasePath =  context.getEnvironment().getProperty("schema.uri.base.path");
+
+               if(schemaUriBasePath == null){
+                       System.err.println("Unable to find the property schema.uri.base.path,"
+                               +" please check if specified in system property or in schema-ingest.properties"
+                       );
+               }
+
+               SchemaVersions schemaVersions = context.getBean(SchemaVersions.class);
+               ListEndpoints endPoints = new ListEndpoints(schemaUriBasePath, schemaVersions.getDefaultVersion());
 
+               LOGGER.info(endPoints.toString("relationship-list"));
        }
 
        /**
@@ -74,14 +90,14 @@ public class ListEndpoints {
         *
         * @param version the version
         */
-       public ListEndpoints(Version version) {
+       public ListEndpoints(String basePath, SchemaVersion version) {
 
-               Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, version);
+               Loader loader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(ModelType.MOXY, version);
 
                try {
                        final Introspector start = loader.introspectorFromName(this.start);
                        Set<String> startMap = new HashSet<>();
-                       beginAudit(start, "/aai/" + version, startMap);
+                       beginAudit(start, basePath + "/" + version, startMap);
                } catch (AAIUnknownObjectException e) {
                        throw new RuntimeException("Failed to find object " + this.start + ", cannot run ListEndpoints audit");
                }
@@ -121,7 +137,7 @@ public class ListEndpoints {
                                        try {
                                                endpoints.add(currentUri + obj.getLoader().introspectorFromName(key).getGenericURI());
                                        } catch (AAIUnknownObjectException e) {
-                                               LOGGER.warn("Skipping endpoint for " + key + " (Unknown object)", e);
+                                               LOGGER.warn("Skipping endpoint for " + key + " (Unknown object) " + LogFormatTools.getStackTop(e));
                                        }
                                }
                        }
@@ -147,7 +163,7 @@ public class ListEndpoints {
                                                                newVisited
                                                                );
                                        } catch (AAIUnknownObjectException e) {
-                                               LOGGER.warn("Skipping nested endpoint for " + propName + " (Unknown Object)", e);
+                                               LOGGER.warn("Skipping nested endpoint for " + propName + " (Unknown Object) " + LogFormatTools.getStackTop(e));
                                        }
                                }
                        } else if (obj.isComplexType(propName)) {
@@ -161,7 +177,7 @@ public class ListEndpoints {
                                                        visited
                                                        );
                                } catch (AAIUnknownObjectException e) {
-                                       LOGGER.warn("Skipping nested enpoint for " + propName + " (Unknown Object)", e);
+                                       LOGGER.warn("Skipping nested enpoint for " + propName + " (Unknown Object) "+ LogFormatTools.getStackTop(e));
                                }
                        }
                }