aboutsummaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main/java/org/onap/aai/rest/util/ConvertQueryPropertiesToJson.java
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2022-10-05 09:55:45 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2022-10-05 09:55:45 +0200
commite632cf8afa27bdedf8b2044c430cd604ab7d4987 (patch)
tree85cf35932109fd858e09f4bf1a0a5d0724057697 /aai-traversal/src/main/java/org/onap/aai/rest/util/ConvertQueryPropertiesToJson.java
parent20ea11d8067c57fe47d9bdc64663b8cc8a5742ca (diff)
Run the formatter for the traversal service
When building the traversal service with mvn install, the spotless and formatter plugins are invoked to verify the formatting. This results in 40000 lines of format violations that are printed out to the console. By invoking mvn formatter:format spotless:apply process-sources this number can be reduced to 2000 lines of format violations. Issue-ID: AAI-3543 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de> Change-Id: Id0011b3e0a626369c79fd0656cd44455347b7fde
Diffstat (limited to 'aai-traversal/src/main/java/org/onap/aai/rest/util/ConvertQueryPropertiesToJson.java')
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/util/ConvertQueryPropertiesToJson.java164
1 files changed, 83 insertions, 81 deletions
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 f16e700..f3ec5f8 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,
@@ -26,86 +26,88 @@ import java.util.List;
import java.util.Properties;
public class ConvertQueryPropertiesToJson {
-
- private static final int MAX_FILE_SIZE = 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<>();
- 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(MAX_FILE_SIZE);
- 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 MAX_FILE_SIZE = 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<>();
+ 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(MAX_FILE_SIZE);
+ 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();
- }
+ }
}