diff options
Diffstat (limited to 'aai-traversal/src/main')
7 files changed, 311 insertions, 309 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/AAIHeaderProperties.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/AAIHeaderProperties.java index 6801aee..9029366 100644 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/AAIHeaderProperties.java +++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/AAIHeaderProperties.java @@ -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, @@ -20,20 +20,21 @@ package org.onap.aai.interceptors; public final class AAIHeaderProperties { - - private AAIHeaderProperties(){} - - public static final String REQUEST_CONTEXT = "aai-request-context"; - - public static final String HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override"; - - public static final String TRANSACTION_ID = "X-TransactionId"; - - public static final String FROM_APP_ID = "X-FromAppId"; - - public static final String AAI_TX_ID = "X-AAI-TXID"; - - public static final String AAI_REQUEST = "X-REQUEST"; - - public static final String AAI_REQUEST_TS = "X-REQUEST-TS"; + + public static final String REQUEST_CONTEXT = "aai-request-context"; + + public static final String HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override"; + + public static final String TRANSACTION_ID = "X-TransactionId"; + + public static final String FROM_APP_ID = "X-FromAppId"; + + public static final String AAI_TX_ID = "X-AAI-TXID"; + + public static final String AAI_REQUEST = "X-REQUEST"; + + public static final String AAI_REQUEST_TS = "X-REQUEST-TS"; + + private AAIHeaderProperties() { + } } diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/post/AAIResponseFilterPriority.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/post/AAIResponseFilterPriority.java index d91e7f6..90ab047 100644 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/post/AAIResponseFilterPriority.java +++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/post/AAIResponseFilterPriority.java @@ -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, @@ -20,13 +20,13 @@ package org.onap.aai.interceptors.post; public final class AAIResponseFilterPriority { - - private AAIResponseFilterPriority() {} - public static final int HEADER_MANIPULATION = 1000; + public static final int HEADER_MANIPULATION = 1000; - public static final int RESPONSE_TRANS_LOGGING = 2000; + public static final int RESPONSE_TRANS_LOGGING = 2000; - public static final int RESET_LOGGING_CONTEXT = 3000; + public static final int RESET_LOGGING_CONTEXT = 3000; + private AAIResponseFilterPriority() { + } } diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/AAIRequestFilterPriority.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/AAIRequestFilterPriority.java index 5c57932..ae75776 100644 --- a/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/AAIRequestFilterPriority.java +++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/pre/AAIRequestFilterPriority.java @@ -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, @@ -20,18 +20,19 @@ package org.onap.aai.interceptors.pre; public final class AAIRequestFilterPriority { - - private AAIRequestFilterPriority() {} - - public static final int REQUEST_TRANS_LOGGING = 1000; - - public static final int HEADER_VALIDATION = 2000; - public static final int SET_LOGGING_CONTEXT = 3000; + public static final int REQUEST_TRANS_LOGGING = 1000; - public static final int AUTHORIZATION = 4000; + public static final int HEADER_VALIDATION = 2000; - public static final int HEADER_MANIPULATION = 5000; + public static final int SET_LOGGING_CONTEXT = 3000; - public static final int REQUEST_MODIFICATION = 6000; + public static final int AUTHORIZATION = 4000; + + public static final int HEADER_MANIPULATION = 5000; + + public static final int REQUEST_MODIFICATION = 6000; + + private AAIRequestFilterPriority() { + } } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/CustomQueryConfig.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/CustomQueryConfig.java index 2fa7ec1..44420d5 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/CustomQueryConfig.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/CustomQueryConfig.java @@ -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, @@ -22,32 +22,36 @@ package org.onap.aai.rest.search; import java.util.List; public class CustomQueryConfig { - public CustomQueryConfig() { - // used by GetCustomQueryConfig - } - - - private String query; - private List<String> queryOptionalProperties; - private List<String> queryRequiredProperties; - - public void setQuery(String query) { - this.query = query; - } - public String getQuery() { - return this.query; - } - - public void setQueryOptionalProperties( List<String> queryOptionalProperties) { - this.queryOptionalProperties = queryOptionalProperties; - } - public List<String> getQueryOptionalProperties( ) { - return queryOptionalProperties; - } - public void setQueryRequiredProperties( List<String> queryRequiredProperties) { - this.queryRequiredProperties = queryRequiredProperties; - } - public List<String> getQueryRequiredProperties( ) { - return queryRequiredProperties; - } + + private String query; + private List<String> queryOptionalProperties; + private List<String> queryRequiredProperties; + + public CustomQueryConfig() { + // used by GetCustomQueryConfig + } + + public void setQuery(String query) { + this.query = query; + } + + public String getQuery() { + return this.query; + } + + public void setQueryOptionalProperties(List<String> queryOptionalProperties) { + this.queryOptionalProperties = queryOptionalProperties; + } + + public List<String> getQueryOptionalProperties() { + return queryOptionalProperties; + } + + public void setQueryRequiredProperties(List<String> queryRequiredProperties) { + this.queryRequiredProperties = queryRequiredProperties; + } + + public List<String> getQueryRequiredProperties() { + return queryRequiredProperties; + } } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GetCustomQueryConfig.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GetCustomQueryConfig.java index c120f56..2017f10 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GetCustomQueryConfig.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GetCustomQueryConfig.java @@ -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, @@ -57,122 +57,122 @@ import com.google.gson.reflect.TypeToken; public class GetCustomQueryConfig { - 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"; - - 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); - } - - 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); - } - } - - 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); - } - } - } - return toStringList(null); - } - - 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; - } - - 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; - } - } - } - - return customQueryConfig; - - } + private JsonArray storedQueries = null; + private CustomQueryConfig customQueryConfig; + private static final String QUERY_CONFIG = "query"; + private static final String REQUIRED_CONFIG = "required-properties"; + private static final String OPTIONAL_CONFIG = "optional-properties"; + private static final String STORED_QUERIES_CONFIG = "stored-queries"; + private static final 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 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)) { + + 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> 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); + } + + 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; + } + + 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; + } + } + } + + return customQueryConfig; + + } } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java index 2940988..a39bc03 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java @@ -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, @@ -45,21 +45,19 @@ public class GremlinServerSingleton { private Cluster cluster; private boolean timerSet; private Timer timer; - - private GetCustomQueryConfig queryConfig; - private static class Helper { + private static final GremlinServerSingleton INSTANCE = new GremlinServerSingleton(); } - public static GremlinServerSingleton getInstance() { - return Helper.INSTANCE; + private GremlinServerSingleton() { + init(); } - private GremlinServerSingleton(){ - init(); + public static GremlinServerSingleton getInstance() { + return Helper.INSTANCE; } /** @@ -69,71 +67,67 @@ public class GremlinServerSingleton { * Then creates a file watcher to watch the file every ten seconds * and if there is a change in the file, then reloads the file into * the properties object - * */ private void init() { try { cluster = Cluster.build(new File(AAIConstants.AAI_HOME_ETC_APP_PROPERTIES + "gremlin-server-config.yaml")) - .maxContentLength(6537920) - .create(); + .maxContentLength(6537920) + .create(); } catch (FileNotFoundException e) { logger.error("Unable to find the file: " + LogFormatTools.getStackTop(e)); } - try { - String filepath = GetCustomQueryConfig.AAI_HOME_ETC_QUERY_JSON; - Path path = Paths.get(filepath); - String customQueryConfigJson = new String(Files.readAllBytes(path)); - - - queryConfig = new GetCustomQueryConfig(customQueryConfigJson); - } catch (IOException e) { - logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); - } + try { + String filepath = GetCustomQueryConfig.AAI_HOME_ETC_QUERY_JSON; + Path path = Paths.get(filepath); + String customQueryConfigJson = new String(Files.readAllBytes(path)); + queryConfig = new GetCustomQueryConfig(customQueryConfigJson); + } catch (IOException e) { + logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); + } TimerTask task = new FileWatcher(new File(GetCustomQueryConfig.AAI_HOME_ETC_QUERY_JSON)) { @Override protected void onChange(File file) { - try { - String filepath = GetCustomQueryConfig.AAI_HOME_ETC_QUERY_JSON; - Path path = Paths.get(filepath); - String customQueryConfigJson = new String(Files.readAllBytes(path)); - queryConfig = new GetCustomQueryConfig(customQueryConfigJson); - } catch (IOException e) { - logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); - } + try { + String filepath = GetCustomQueryConfig.AAI_HOME_ETC_QUERY_JSON; + Path path = Paths.get(filepath); + String customQueryConfigJson = new String(Files.readAllBytes(path)); + queryConfig = new GetCustomQueryConfig(customQueryConfigJson); + } catch (IOException e) { + logger.error( + "Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); + } } }; if (!timerSet) { timerSet = true; timer = new Timer(); - timer.schedule( task , new Date(), 10000 ); + timer.schedule(task, new Date(), 10000); } } - public Cluster getCluster(){ + public Cluster getCluster() { return cluster; } - + /** * Gets the query using CustomQueryConfig - * @param key - * @return */ - public String getStoredQueryFromConfig(String key){ - CustomQueryConfig customQueryConfig = queryConfig.getStoredQuery(key); - if ( customQueryConfig == null ) { - return null; - } - return customQueryConfig.getQuery(); + public String getStoredQueryFromConfig(String key) { + CustomQueryConfig customQueryConfig = queryConfig.getStoredQuery(key); + if (customQueryConfig == null) { + return null; + } + return customQueryConfig.getQuery(); } - + public CustomQueryConfig getCustomQueryConfig(String key) { - return queryConfig.getStoredQuery(key); + return queryConfig.getStoredQuery(key); } diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/util/ConvertQueryPropertiesToJson.java b/aai-traversal/src/main/java/org/onap/aai/rest/util/ConvertQueryPropertiesToJson.java index 7ef52d2..e8d1547 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/util/ConvertQueryPropertiesToJson.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/util/ConvertQueryPropertiesToJson.java @@ -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, @@ -32,100 +32,102 @@ import java.util.Properties; import org.onap.aai.util.AAIConstants; public class ConvertQueryPropertiesToJson { - - private final static int maxfilesize = 256000; - - private void addStart( StringBuilder sb ) { - sb.append("{\n \"stored-queries\":[{\n"); - } - - private void addRequiredQueryProperties( StringBuilder sb, List<String> rqd ) { - Iterator it = rqd.iterator(); - sb.append(" \"query\":{\n \"required-properties\":["); - while( it.hasNext()) { - sb.append("\"" + it.next() + "\""); - if ( it.hasNext()) { - sb.append(","); - } - } - sb.append("]\n },\n"); - } - - private void addAnotherQuery( StringBuilder sb, String queryName, String query, List<String> rqd ) { - sb.append(" \"" + queryName + "\":{\n"); - if ( !rqd.isEmpty()) { - addRequiredQueryProperties( sb, rqd); - } - sb.append(" \"stored-query\":\"" + query + "\"\n }\n },{\n"); - } - - private void addLastQuery( StringBuilder sb, String queryName, String query, List<String> rqd ) { - sb.append(" \"" + queryName + "\":{\n"); - if ( !rqd.isEmpty() ) { - addRequiredQueryProperties( sb, rqd); - } - sb.append(" \"stored-query\":\"" + query + "\"\n }\n }]\n}\n"); - } - - private String get2ndParameter( String paramString) { - String endParams = paramString.substring(0, paramString.indexOf(')')); - String result = endParams.substring(endParams.indexOf(',') + 1 ); - String lastParam = result.trim(); - if ( lastParam.startsWith("\\") || lastParam.startsWith("'") || lastParam.startsWith("new ") ){ - return null; - } - - return lastParam; - } - - private List<String> findRqdProperties( String query) { - String[] parts = query.split("getVerticesByProperty"); - List<String> result = new ArrayList<String>(); - if ( parts.length == 1 ) - return result; - int count = 0; - String foundRqdProperty; - while ( count++ < parts.length - 1 ) { - foundRqdProperty = get2ndParameter(parts[count]); - if ( foundRqdProperty != null && !result.contains(foundRqdProperty)) { - result.add(foundRqdProperty); - } - } - return result; - } - - public String convertProperties( Properties props ) { - Enumeration<?> e = props.propertyNames(); - StringBuilder sb = new StringBuilder(maxfilesize); - String queryName; - String query; - addStart( sb ); - List<String> rqd; - while ( e.hasMoreElements()) { - queryName = (String)e.nextElement(); - query = props.getProperty(queryName).trim().replace("\"", "\\\""); - rqd = findRqdProperties( query); - if ( e.hasMoreElements()) { - addAnotherQuery( sb, queryName, query, rqd); - } else { - addLastQuery( sb, queryName, query, rqd); - } - } - + + private static final int maxfilesize = 256000; + + private void addStart(StringBuilder sb) { + sb.append("{\n \"stored-queries\":[{\n"); + } + + private void addRequiredQueryProperties(StringBuilder sb, List<String> rqd) { + Iterator it = rqd.iterator(); + sb.append(" \"query\":{\n \"required-properties\":["); + while (it.hasNext()) { + sb.append("\"" + it.next() + "\""); + if (it.hasNext()) { + sb.append(","); + } + } + sb.append("]\n },\n"); + } + + private void addAnotherQuery(StringBuilder sb, String queryName, String query, List<String> rqd) { + sb.append(" \"" + queryName + "\":{\n"); + if (!rqd.isEmpty()) { + addRequiredQueryProperties(sb, rqd); + } + sb.append(" \"stored-query\":\"" + query + "\"\n }\n },{\n"); + } + + private void addLastQuery(StringBuilder sb, String queryName, String query, List<String> rqd) { + sb.append(" \"" + queryName + "\":{\n"); + if (!rqd.isEmpty()) { + addRequiredQueryProperties(sb, rqd); + } + sb.append(" \"stored-query\":\"" + query + "\"\n }\n }]\n}\n"); + } + + private String get2ndParameter(String paramString) { + String endParams = paramString.substring(0, paramString.indexOf(')')); + String result = endParams.substring(endParams.indexOf(',') + 1); + String lastParam = result.trim(); + if (lastParam.startsWith("\\") || lastParam.startsWith("'") || lastParam.startsWith("new ")) { + return null; + } + + return lastParam; + } + + private List<String> findRqdProperties(String query) { + String[] parts = query.split("getVerticesByProperty"); + List<String> result = new ArrayList<String>(); + if (parts.length == 1) { + return result; + } + int count = 0; + String foundRqdProperty; + while (count++ < parts.length - 1) { + foundRqdProperty = get2ndParameter(parts[count]); + if (foundRqdProperty != null && !result.contains(foundRqdProperty)) { + result.add(foundRqdProperty); + } + } + return result; + } + + public String convertProperties(Properties props) { + Enumeration<?> e = props.propertyNames(); + StringBuilder sb = new StringBuilder(maxfilesize); + String queryName; + String query; + addStart(sb); + List<String> rqd; + while (e.hasMoreElements()) { + queryName = (String) e.nextElement(); + query = props.getProperty(queryName).trim().replace("\"", "\\\""); + rqd = findRqdProperties(query); + if (e.hasMoreElements()) { + addAnotherQuery(sb, queryName, query, rqd); + } else { + addLastQuery(sb, queryName, query, rqd); + } + } + return sb.toString(); - } - public static void main(String[] args) { - File queryFile = new File(AAIConstants.AAI_HOME_ETC_QUERY); - Properties properties = new Properties(); - try (FileInputStream fis = new FileInputStream(queryFile)){ + } + + public static void main(String[] args) { + File queryFile = new File(AAIConstants.AAI_HOME_ETC_QUERY); + Properties properties = new Properties(); + try (FileInputStream fis = new FileInputStream(queryFile)) { properties.load(fis); } catch (IOException e) { - e.printStackTrace(); + e.printStackTrace(); System.out.println("Error occurred during the processing of query file: " + e); } ConvertQueryPropertiesToJson c = new ConvertQueryPropertiesToJson(); String json = c.convertProperties(properties); System.out.println("returned json:\n" + json); - } + } } |