From 24cac2175588a81a2ebecb5c08b91455cfc24d0b Mon Sep 17 00:00:00 2001 From: Michael DÜrre Date: Tue, 6 Apr 2021 10:33:41 +0200 Subject: source out odl mapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit put odl mapper code into seperate bundle Issue-ID: CCSDK-3254 Signed-off-by: Michael DÜrre Change-Id: I3debef0be8e44e7c68c95a6d06b7e50813bbea43 --- .../sdnr/wt/common/database/ExtRestClient.java | 55 +--------------------- .../sdnr/wt/common/database/data/DbFilter.java | 19 ++++++++ .../wt/common/database/queries/QueryBuilders.java | 14 ++++++ .../sdnr/wt/common/http/BaseHTTPClient.java | 9 ++++ sdnr/wt/common/src/test/resources/testpom.xml | 6 +-- 5 files changed, 46 insertions(+), 57 deletions(-) (limited to 'sdnr/wt/common/src') diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java index f8734d5a6..1f67e5ef8 100644 --- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/ExtRestClient.java @@ -29,10 +29,8 @@ import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.security.spec.InvalidKeySpecException; import java.text.ParseException; - import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSession; - import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -140,57 +138,6 @@ public class ExtRestClient { } } - // private class SSLCercAuthHttpClientConfigCallback implements HttpClientConfigCallback { - // - // private final String certFilename; - // - // SSLCercAuthHttpClientConfigCallback(String certfile) { - // this.certFilename = certfile; - // } - // - // @Override - // public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) { - // if (this.certFilename == null) { - // return httpClientBuilder; - // } - // - // char[] keystorePass = "MY PASSWORD".toCharArray(); - // - // FileInputStream fis = null; - // - // // Loading KEYSTORE in JKS format - // KeyStore keyStorePci = null; - // try { - // keyStorePci = KeyStore.getInstance(KeyStore.getDefaultType()); - // } catch (KeyStoreException e1) { - // LOG.warn("unable to load keystore: {}",e1); - // } - // if (keyStorePci != null) { - // try { - // fis = new FileInputStream(this.certFilename); - // keyStorePci.load(fis, keystorePass); - // } catch (Exception e) { - // LOG.error("Error loading keystore: " + this.certFilename); - // } finally { - // if (fis != null) { - // try { - // fis.close(); - // } catch (IOException e) { - // - // } - // } - // } - // } - // SSLContext sslcontext=null; - // try { - // sslcontext = SSLContexts.custom().loadKeyMaterial(keyStorePci, keystorePass).build(); - // } catch (KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException - // | KeyStoreException e) { - // LOG.warn("unable to load sslcontext: {}",e); - // } - // return httpClientBuilder.setSSLContext(sslcontext); - // } - // } private final RestClient client; private final boolean isES7; @@ -298,7 +245,7 @@ public class ExtRestClient { /** * Search for database entries - * + * * @param request inputRequest * @param ignoreParseException especially for usercreated filters which may cause ES server response exceptions * @return Response with related entries 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 82c036406..70e41c280 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 @@ -37,9 +37,28 @@ public class DbFilter { return restFilterValue == null ? false : restFilterValue.contains("*") || restFilterValue.contains("?"); } + public static boolean hasSearchParams(List restFilterValues) { + for (String restFilterValue : restFilterValues) { + if (!hasSearchParams(restFilterValue)) { + return false; + } + } + return true; + } + public static boolean isComparisonValid(String restFilterValue) { return restFilterValue == null ? false : restFilterValue.contains(">") || restFilterValue.contains("<"); } + + public static boolean isComparisonValid(List restFilterValues) { + for (String restFilterValue : restFilterValues) { + if (!isComparisonValid(restFilterValue)) { + return false; + } + } + return true; + } + public static boolean isDatetimeKeyValue(String key, String value) { return timestampValueNames.contains(key.toLowerCase()); } diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/queries/QueryBuilders.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/queries/QueryBuilders.java index 7b22fd5e7..582d749d5 100644 --- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/queries/QueryBuilders.java +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/queries/QueryBuilders.java @@ -21,6 +21,7 @@ */ package org.onap.ccsdk.features.sdnr.wt.common.database.queries; +import java.util.List; import org.json.JSONObject; public class QueryBuilders { @@ -34,6 +35,11 @@ public class QueryBuilders { o.put(key, value); return new QueryBuilder().setQuery("term", o); } + public static QueryBuilder multiTermQuery(String key, List value) { + JSONObject o = new JSONObject(); + o.put(key, value); + return new QueryBuilder().setQuery("terms", o); + } public static QueryBuilder matchQuery(String key, Object value) { JSONObject o = new JSONObject(); @@ -41,6 +47,14 @@ public class QueryBuilders { return new QueryBuilder().setQuery("match", o); } + public static QueryBuilder matchQuery(String key, List values) { + BoolQueryBuilder query = boolQuery(); + for (Object value : values) { + query.should(matchQuery(key, value)); + } + return query; + } + public static BoolQueryBuilder boolQuery() { return new BoolQueryBuilder(); } diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java index 937e2d898..ffb31c676 100644 --- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java @@ -370,6 +370,15 @@ public class BaseHTTPClient { return SSLCERT_PEM; } + public static String decodeBasicAuthHeaderUsername(String authHeader) { + if(authHeader.startsWith("Basic")) { + authHeader = authHeader.substring(6); + } + final String decoded = new String(Base64.getDecoder().decode(authHeader)); + String[] tmp = decoded.split(":"); + return tmp.length > 0 ? tmp[0] : null; + } + } diff --git a/sdnr/wt/common/src/test/resources/testpom.xml b/sdnr/wt/common/src/test/resources/testpom.xml index e57fed436..6fba87af9 100644 --- a/sdnr/wt/common/src/test/resources/testpom.xml +++ b/sdnr/wt/common/src/test/resources/testpom.xml @@ -29,13 +29,13 @@ org.onap.ccsdk.parent binding-parent - 2.1.0-SNAPSHOT + 2.0.0-SNAPSHOT org.onap.ccsdk.features.sdnr.wt sdnr-wt-common - 1.1.1-SNAPSHOT + 1.0.0-SNAPSHOT jar ccsdk-features :: ${project.artifactId} @@ -63,7 +63,7 @@ javax.servlet - javax.servlet-api + servlet-api org.osgi -- cgit 1.2.3-korg