Merge "Fix sonar issues in SchemaGenerator"
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / util / UniquePropertyCheck.java
index ae2cdaa..bfa0f3a 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.util;
 import java.util.HashMap;
@@ -32,15 +30,16 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.onap.aai.exceptions.AAIException;
+import org.onap.aai.logging.LoggingContext;
+import org.onap.aai.logging.LoggingContext.StatusCode;
 import org.slf4j.MDC;
 
 import com.att.eelf.configuration.Configuration;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import com.thinkaurelius.titan.core.TitanFactory;
-import com.thinkaurelius.titan.core.TitanGraph;
-
-
+import org.janusgraph.core.JanusGraphFactory;
+import org.janusgraph.core.JanusGraph;
+import org.onap.aai.dbmap.AAIGraphConfig;
 
 public class UniquePropertyCheck {
 
@@ -61,11 +60,24 @@ public class UniquePropertyCheck {
                props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, "uniquePropertyCheck-logback.xml");
                props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES);
                EELFLogger logger = EELFManager.getInstance().getLogger(UniquePropertyCheck.class.getSimpleName());
+               
+               LoggingContext.init();
+               LoggingContext.partnerName(FROMAPPID);
+               LoggingContext.serviceName(AAIConstants.AAI_RESOURCES_MS);
+               LoggingContext.component(COMPONENT);
+               LoggingContext.targetEntity(AAIConstants.AAI_RESOURCES_MS);
+               LoggingContext.targetServiceName("main");
+               LoggingContext.requestId(TRANSID);
+               LoggingContext.statusCode(StatusCode.COMPLETE);
+               LoggingContext.responseCode(LoggingContext.SUCCESS);
+               
                MDC.put("logFilenameAppender", UniquePropertyCheck.class.getSimpleName());
                
                if( args == null || args.length != 1 ){
                                String msg = "usage:  UniquePropertyCheck propertyName \n";
                                System.out.println(msg);
+                               LoggingContext.statusCode(StatusCode.ERROR);
+                       LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
                                logAndPrint(logger, msg );
                                System.exit(1);
                }
@@ -75,26 +87,34 @@ public class UniquePropertyCheck {
                try {   
                AAIConfig.init();
                System.out.println("    ---- NOTE --- about to open graph (takes a little while)--------\n");
-               TitanGraph tGraph = TitanFactory.open(AAIConstants.REALTIME_DB_CONFIG);
+               JanusGraph tGraph = JanusGraphFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG).forService(UniquePropertyCheck.class.getSimpleName()).withGraphType("realtime").buildConfiguration());
                
                if( tGraph == null ) {
-                       logAndPrint(logger, " Error:  Could not get TitanGraph ");
+                       LoggingContext.statusCode(StatusCode.ERROR);
+                       LoggingContext.responseCode(LoggingContext.AVAILABILITY_TIMEOUT_ERROR);
+                       logAndPrint(logger, " Error:  Could not get JanusGraph ");
                        System.exit(1);
                }
                
                graph = tGraph.newTransaction();
                if( graph == null ){
+                       LoggingContext.statusCode(StatusCode.ERROR);
+                       LoggingContext.responseCode(LoggingContext.AVAILABILITY_TIMEOUT_ERROR);
                        logAndPrint(logger, "could not get graph object in UniquePropertyCheck() \n");
                        System.exit(0);
                }
        }
            catch (AAIException e1) {
                        String msg =  "Threw Exception: [" + e1.toString() + "]";
+                       LoggingContext.statusCode(StatusCode.ERROR);
+                       LoggingContext.responseCode(LoggingContext.UNKNOWN_ERROR);
                        logAndPrint(logger, msg);
                        System.exit(0);
         }
         catch (Exception e2) {
                        String msg =  "Threw Exception: [" + e2.toString() + "]";
+                       LoggingContext.statusCode(StatusCode.ERROR);
+                       LoggingContext.responseCode(LoggingContext.UNKNOWN_ERROR);
                        logAndPrint(logger, msg);
                        System.exit(0);
         }
@@ -180,6 +200,8 @@ public class UniquePropertyCheck {
                }
        }
        catch( Exception e2 ){
+               LoggingContext.statusCode(StatusCode.ERROR);
+                       LoggingContext.responseCode(LoggingContext.DATA_ERROR);
                        logAndPrint(logger, "Threw Exception: [" + e2.toString() + "]");
        } 
        finally {