summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/common/src/main')
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/DbFilter.java20
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java8
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletInputStreamFromByteArrayInputStream.java45
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToByteArrayOutputStream.java43
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToStringWriter.java43
5 files changed, 153 insertions, 6 deletions
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/DbFilter.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/DbFilter.java
index 2a8f04df3..82c036406 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/DbFilter.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/DbFilter.java
@@ -21,10 +21,14 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common.database.data;
+import java.util.Arrays;
+import java.util.List;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.RangeQueryBuilder;
public class DbFilter {
+ private static final List<String> timestampValueNames = Arrays.asList("timestamp", "start", "end", "date");
+
public static String createDatabaseRegex(String restFilterValue) {
return restFilterValue == null ? null : restFilterValue.replace("?", ".{1,1}").replace("*", ".*");
}
@@ -36,18 +40,21 @@ public class DbFilter {
public static boolean isComparisonValid(String restFilterValue) {
return restFilterValue == null ? false : restFilterValue.contains(">") || restFilterValue.contains("<");
}
+ public static boolean isDatetimeKeyValue(String key, String value) {
+ return timestampValueNames.contains(key.toLowerCase());
+ }
public static RangeQueryBuilder getRangeQuery(String key, String restFilterValue) {
RangeQueryBuilder query = new RangeQueryBuilder(key);
restFilterValue = restFilterValue.trim();
if (restFilterValue.startsWith(">=")) {
- query.gte(getObjectFromString(restFilterValue.substring(2).trim()));
+ query.gte(getObjectFromString(key,restFilterValue.substring(2).trim()));
} else if (restFilterValue.startsWith(">")) {
- query.gt(getObjectFromString(restFilterValue.substring(1).trim()));
+ query.gt(getObjectFromString(key,restFilterValue.substring(1).trim()));
} else if (restFilterValue.startsWith("<=")) {
- query.lte(getObjectFromString(restFilterValue.substring(2).trim()));
+ query.lte(getObjectFromString(key,restFilterValue.substring(2).trim()));
} else if (restFilterValue.startsWith("<")) {
- query.lt(getObjectFromString(restFilterValue.substring(1).trim()));
+ query.lt(getObjectFromString(key,restFilterValue.substring(1).trim()));
} else {
return null;
}
@@ -55,7 +62,10 @@ public class DbFilter {
return query;
}
- private static Object getObjectFromString(String str) {
+ private static Object getObjectFromString(String key, String str) {
+ if(isDatetimeKeyValue(key, str)) {
+ return str;
+ }
try {
return Double.parseDouble(str);
} catch (NumberFormatException | NullPointerException nfe) {
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java
index 1dd1c3d53..e1fd02de0 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/data/EsVersion.java
@@ -22,7 +22,6 @@
package org.onap.ccsdk.features.sdnr.wt.common.database.data;
import java.text.ParseException;
-
import org.eclipse.jdt.annotation.NonNull;
@@ -104,6 +103,9 @@ public class EsVersion {
if (this.equals(v)) {
return true;
}
+ return this.isNewerThan(v);
+ }
+ public boolean isNewerThan(EsVersion v) {
if (this.major > v.major) {
return true;
} else if (this.major < v.major) {
@@ -124,6 +126,10 @@ public class EsVersion {
if (this.equals(v)) {
return true;
}
+ return this.isOlderThan(v);
+ }
+
+ public boolean isOlderThan(EsVersion v) {
if (this.major < v.major) {
return true;
} else if (this.major > v.major) {
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletInputStreamFromByteArrayInputStream.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletInputStreamFromByteArrayInputStream.java
new file mode 100644
index 000000000..b926ff65c
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletInputStreamFromByteArrayInputStream.java
@@ -0,0 +1,45 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH 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.
+ * You may obtain a copy of the License at
+ *
+ * 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,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import javax.servlet.ServletInputStream;
+
+public class ServletInputStreamFromByteArrayInputStream extends ServletInputStream {
+
+ // variables
+ private ByteArrayInputStream bis;
+ // end of variables
+
+ // constructors
+ public ServletInputStreamFromByteArrayInputStream(byte[] data) {
+ bis = new ByteArrayInputStream(data);
+ }
+ // end of constructors
+
+ @Override
+ public int read() throws IOException {
+ return bis.read();
+ }
+
+}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToByteArrayOutputStream.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToByteArrayOutputStream.java
new file mode 100644
index 000000000..1914d9b67
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToByteArrayOutputStream.java
@@ -0,0 +1,43 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH 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.
+ * You may obtain a copy of the License at
+ *
+ * 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,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import javax.servlet.ServletOutputStream;
+
+public class ServletOutputStreamToByteArrayOutputStream extends ServletOutputStream {
+
+ // variables
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ // end of variables
+
+ @Override
+ public void write(int arg0) throws IOException {
+ out.write(arg0);
+ }
+
+ public ByteArrayOutputStream getByteArrayOutputStream() {
+ return out;
+ }
+}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToStringWriter.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToStringWriter.java
new file mode 100644
index 000000000..57ed596ae
--- /dev/null
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToStringWriter.java
@@ -0,0 +1,43 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2020 highstreet technologies GmbH 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.
+ * You may obtain a copy of the License at
+ *
+ * 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,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.common.test;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import javax.servlet.ServletOutputStream;
+
+public class ServletOutputStreamToStringWriter extends ServletOutputStream {
+
+ // variables
+ private StringWriter out = new StringWriter();
+ // end of variables
+
+ @Override
+ public void write(int arg0) throws IOException {
+ out.write(arg0);
+ }
+
+ public StringWriter getStringWriter() {
+ return out;
+ }
+
+}