Add instructions to invoke the linter and code formatter plugins to the README and...
[aai/schema-service.git] / aai-queries / src / main / java / org / onap / aai / queries / GetCustomQueryConfig.java
index c726c76..07f7724 100644 (file)
@@ -8,7 +8,7 @@
  * 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
+ * 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,
@@ -17,6 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.queries;
 
 import com.google.gson.*;
@@ -28,122 +29,119 @@ import java.util.List;
 
 public class GetCustomQueryConfig {
 
-  private JsonArray storedQueries = null;
-  private CustomQueryConfig customQueryConfig;
+    private JsonArray storedQueries = null;
+    private CustomQueryConfig customQueryConfig;
 
+    private final static String QUERY_CONFIG = "query";
+    private final static String REQUIRED_CONFIG = "required-properties";
+    private final static String OPTIONAL_CONFIG = "optional-properties";
+    private final static String STORED_QUERIES_CONFIG = "stored-queries";
+    private final static String STORED_QUERY_CONFIG = "stored-query";
 
-  private final static String QUERY_CONFIG = "query";
-  private final static String REQUIRED_CONFIG = "required-properties";
-  private final static String OPTIONAL_CONFIG = "optional-properties";
-  private final static String STORED_QUERIES_CONFIG = "stored-queries";
-  private final static String STORED_QUERY_CONFIG = "stored-query";
+    // public static final String AAI_HOME_ETC_QUERY_JSON = AAIConstants.AAI_HOME_ETC + "query" +
+    // AAIConstants.AAI_FILESEP + "stored-queries.json";
 
-//  public static final String AAI_HOME_ETC_QUERY_JSON = AAIConstants.AAI_HOME_ETC + "query" + AAIConstants.AAI_FILESEP + "stored-queries.json";
+    public GetCustomQueryConfig(String customQueryJson) {
+        init(customQueryJson);
+    }
 
-  public GetCustomQueryConfig(String customQueryJson ) {
-    init(customQueryJson);
-  }
+    private void init(String customQueryJson) {
+        JsonParser parser = new JsonParser();
+        JsonObject queriesObject = parser.parse(customQueryJson).getAsJsonObject();
+        if (queriesObject.has(STORED_QUERIES_CONFIG)) {
 
-  private void init( String customQueryJson) {
-    JsonParser parser = new JsonParser();
-    JsonObject queriesObject = parser.parse(customQueryJson).getAsJsonObject();
-    if (queriesObject.has(STORED_QUERIES_CONFIG)) {
+            storedQueries = queriesObject.getAsJsonArray(STORED_QUERIES_CONFIG);
+        }
+    }
 
-      storedQueries = queriesObject.getAsJsonArray(STORED_QUERIES_CONFIG);
+    private List<String> toStringList(JsonArray array) {
+        Gson converter = new Gson();
+        Type listType = new TypeToken<List<String>>() {}.getType();
+        return converter.fromJson(array, listType);
     }
-  }
-
-  private List<String> toStringList(JsonArray array) {
-     Gson converter = new Gson();
-     Type listType = new TypeToken<List<String>>() {}.getType();
-     return converter.fromJson(array, listType);
-  }
-
-  private List<String> getPropertyList(JsonObject configObject, String config ) {
-    JsonElement subqueryConfig;
-    JsonArray props;
-
-    if ( configObject.has(config)) {
-      subqueryConfig = configObject.get(config);
-      if ( subqueryConfig != null && !subqueryConfig.isJsonNull() ) {
-        props = subqueryConfig.getAsJsonArray();
-        if ( props != null ) {
-          return toStringList(props);
+
+    private List<String> getPropertyList(JsonObject configObject, String config) {
+        JsonElement subqueryConfig;
+        JsonArray props;
+
+        if (configObject.has(config)) {
+            subqueryConfig = configObject.get(config);
+            if (subqueryConfig != null && !subqueryConfig.isJsonNull()) {
+                props = subqueryConfig.getAsJsonArray();
+                if (props != null) {
+                    return toStringList(props);
+                }
+            }
         }
-      }
+        return toStringList(null);
     }
-    return toStringList(null);
-  }
 
-  private String getPropertyString(JsonObject configObject, String config) {
-    JsonElement subqueryConfig;
+    private String getPropertyString(JsonObject configObject, String config) {
+        JsonElement subqueryConfig;
 
-    if ( configObject.has(config)) {
-      subqueryConfig = configObject.get(config);
-      if ( subqueryConfig != null && !subqueryConfig.isJsonNull() ) {
-        return subqueryConfig.getAsString();
-      }
-    }
-    return null;
-  }
-
-  private void getStoredQueryBlock( JsonObject configObject, String config ) {
-    if ( !configObject.has(config)) {
-      customQueryConfig.setQueryRequiredProperties( new ArrayList<String>() );
-      customQueryConfig.setQueryOptionalProperties( new ArrayList<String>()  );
-      return;
+        if (configObject.has(config)) {
+            subqueryConfig = configObject.get(config);
+            if (subqueryConfig != null && !subqueryConfig.isJsonNull()) {
+                return subqueryConfig.getAsString();
+            }
+        }
+        return null;
     }
 
-    JsonElement queryConfig;
-    JsonObject subObject;
-    String multipleStartNodes;
-    List<String> propertyList;
+    private void getStoredQueryBlock(JsonObject configObject, String config) {
+        if (!configObject.has(config)) {
+            customQueryConfig.setQueryRequiredProperties(new ArrayList<String>());
+            customQueryConfig.setQueryOptionalProperties(new ArrayList<String>());
+            return;
+        }
+
+        JsonElement queryConfig;
+        JsonObject subObject;
+        String multipleStartNodes;
+        List<String> propertyList;
 
-    queryConfig = configObject.get(config);
-    subObject = queryConfig.getAsJsonObject();
-    propertyList = getPropertyList(subObject, REQUIRED_CONFIG);
-    if ( propertyList == null ) {
-      propertyList = new ArrayList<String>();
-    }
-    customQueryConfig.setQueryRequiredProperties( propertyList );
-    propertyList = getPropertyList(subObject, OPTIONAL_CONFIG);
-    if ( propertyList == null ) {
-      propertyList = new ArrayList<String>();
-    }
-    customQueryConfig.setQueryOptionalProperties( propertyList );
-
-  }
-
-
-  public CustomQueryConfig getStoredQuery(String queryName ) {
-
-    customQueryConfig = null;
-    JsonObject configObject;
-    JsonElement query;
-    JsonElement queryConfig;
-    String queryString;
-
-    for (JsonElement storedQuery : storedQueries) {
-      if (storedQuery.isJsonObject()) {
-        JsonObject queryObject = storedQuery.getAsJsonObject();
-        query = queryObject.get(queryName);
-        if ( query != null ) {
-          customQueryConfig = new CustomQueryConfig();
-          configObject = query.getAsJsonObject();
-          getStoredQueryBlock(configObject, QUERY_CONFIG);
-          if ( configObject.has(STORED_QUERY_CONFIG)) {
-            queryConfig = configObject.get(STORED_QUERY_CONFIG);
-            customQueryConfig.setQuery(queryConfig.getAsString());
-          }
-          break;
+        queryConfig = configObject.get(config);
+        subObject = queryConfig.getAsJsonObject();
+        propertyList = getPropertyList(subObject, REQUIRED_CONFIG);
+        if (propertyList == null) {
+            propertyList = new ArrayList<String>();
         }
-      }
-    }
+        customQueryConfig.setQueryRequiredProperties(propertyList);
+        propertyList = getPropertyList(subObject, OPTIONAL_CONFIG);
+        if (propertyList == null) {
+            propertyList = new ArrayList<String>();
+        }
+        customQueryConfig.setQueryOptionalProperties(propertyList);
 
-    return customQueryConfig;
+    }
 
-  }
+    public CustomQueryConfig getStoredQuery(String queryName) {
+
+        customQueryConfig = null;
+        JsonObject configObject;
+        JsonElement query;
+        JsonElement queryConfig;
+        String queryString;
+
+        for (JsonElement storedQuery : storedQueries) {
+            if (storedQuery.isJsonObject()) {
+                JsonObject queryObject = storedQuery.getAsJsonObject();
+                query = queryObject.get(queryName);
+                if (query != null) {
+                    customQueryConfig = new CustomQueryConfig();
+                    configObject = query.getAsJsonObject();
+                    getStoredQueryBlock(configObject, QUERY_CONFIG);
+                    if (configObject.has(STORED_QUERY_CONFIG)) {
+                        queryConfig = configObject.get(STORED_QUERY_CONFIG);
+                        customQueryConfig.setQuery(queryConfig.getAsString());
+                    }
+                    break;
+                }
+            }
+        }
 
+        return customQueryConfig;
 
+    }
 
 }