aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2021-08-18 14:43:18 +0530
committerRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2021-08-18 14:43:35 +0530
commita81a05e53871903d43aab71221b8ef2479dc3d58 (patch)
treed22f43b0bd8b1ad9ecaca126caa2c6b1f9c5f3b0
parent1c4ad2b1a689d309d456a6ada894d1e8b1971b3c (diff)
Improve code-coverage for data-provider
Improve code-coverage for data-provider Issue-ID: CCSDK-3424 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> Change-Id: I5a50707c8fcec6c816fe645693b665d33743559c Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java8
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/rpctypehelper/QueryResult.java5
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/rpctypehelper/SqlDBQueryByFilter.java373
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java56
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java6
-rw-r--r--sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java1
-rw-r--r--sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java76
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseEventsService.java9
-rw-r--r--sdnr/wt/data-provider/provider/src/test/resources/TestTree/test3.json180
9 files changed, 274 insertions, 440 deletions
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java
index 94c7dcfc6..4165c85a0 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/SqlDBDataProvider.java
@@ -335,7 +335,7 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa
}
CreateNetworkElementConnectionOutputBuilder builder = new CreateNetworkElementConnectionOutputBuilder();
builder.setId(id).setNodeId(input.getNodeId()).setHost(input.getHost()).setPort(input.getPort())
- .setUsername(input.getUsername()).setPassword(input.getPassword()).setIsRequired(input.isIsRequired())
+ .setUsername(input.getUsername()).setPassword(input.getPassword()).setIsRequired(input.getIsRequired())
.setCoreModelCapability(input.getCoreModelCapability()).setDeviceType(input.getDeviceType());
return builder;
}
@@ -482,17 +482,17 @@ public class SqlDBDataProvider extends HtDatabaseEventsService implements Databa
LOG.info("set controllerId {}", this.controllerId);
String query = String.format("SELECT * FROM `%s` WHERE `id`='%s';", this.controllerTableName,
this.controllerId);
- LOG.info(query);
+ LOG.trace(query);
ResultSet data = this.dbClient.read(query);
if (!data.next()) {
query = String.format("INSERT INTO `%s` (`id`,`desc`) VALUES ('%s','%s')",
this.controllerTableName, this.controllerId, "");
- LOG.info(query);
+ LOG.trace(query);
return this.dbClient.write(query);
}
else {
- LOG.info("controllerId already set");
+ LOG.trace("controllerId already set");
}
return true;
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/rpctypehelper/QueryResult.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/rpctypehelper/QueryResult.java
index ca90e84fb..c81725073 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/rpctypehelper/QueryResult.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/rpctypehelper/QueryResult.java
@@ -21,6 +21,7 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.rpctypehelper;
+import java.util.ArrayList;
import java.util.List;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PaginationOutputG;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.connectionlog.list.output.PaginationBuilder;
@@ -55,6 +56,10 @@ public class QueryResult<T> {
return "QueryResult [result=" + result + ", pagination=" + pagination + "]";
}
+ public static <X> QueryResult<X> createEmpty() {
+ return new QueryResult<X>(new ArrayList<>(), 1, 0, 0);
+ }
+
}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/rpctypehelper/SqlDBQueryByFilter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/rpctypehelper/SqlDBQueryByFilter.java
deleted file mode 100644
index 4354b1647..000000000
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/data/rpctypehelper/SqlDBQueryByFilter.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : ccsdk features
- * ================================================================================
- * Copyright (C) 2019 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.dataprovider.database.sqldb.data.rpctypehelper;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
-import org.eclipse.jdt.annotation.Nullable;
-import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
-import org.onap.ccsdk.features.sdnr.wt.common.database.data.DbFilter;
-import org.onap.ccsdk.features.sdnr.wt.common.database.queries.BoolQueryBuilder;
-import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
-import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
-import org.onap.ccsdk.features.sdnr.wt.common.database.queries.RangeQueryBuilder;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SortOrder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Pagination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Sortorder;
-import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.common.Uint64;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SqlDBQueryByFilter {
-
- private static final Logger LOG = LoggerFactory.getLogger(SqlDBQueryByFilter.class);
- private static final List<String> timestampValueNames = Arrays.asList("timestamp", "time-stamp", "start", "end");
-
- private static List<Sortorder> emptySortOrderList = new ArrayList<>();
- private static List<Filter> emptyFilterList = new ArrayList<>();
-
- // Derived from input
- private long page;
- private long pageSize;
- private long fromPage;
- private List<Filter> filterList;
- private List<Sortorder> sortOrder;
-
- /**
- * Process input from RPC into Queries to database
- *
- * @param input Input from RPC, for test it could be null
- */
- public SqlDBQueryByFilter(EntityInput input) {
- page = -1;
- pageSize = -1;
- if (input != null) {
- @Nullable
- Pagination pagination = input.getPagination();
- if (pagination != null) {
- @Nullable Uint64 pageOrNull = YangHelper2.getUint64(pagination.getPage());
- if (pageOrNull != null) {
- page = pageOrNull.longValue();
- }
- @Nullable Uint32 pageSizeOrNull = YangHelper2.getUint32(pagination.getSize());
- if (pageSizeOrNull != null) {
- pageSize = pageSizeOrNull.longValue();
- }
- }
- }
- if (page < 0)
- page = 1;
- if (pageSize < 0)
- pageSize = 1;
-
- fromPage = (page - 1) * pageSize;
- if (fromPage < 0 || pageSize > 10000)
- throw new IllegalArgumentException("mismatching input parameters. From:" + fromPage + " size:" + pageSize);
-
- filterList = YangHelper.getList(input.getFilter());
- if (filterList == null)
- filterList = emptyFilterList;
- sortOrder = YangHelper.getList(input.getSortorder());
- if (sortOrder == null)
- sortOrder = emptySortOrderList;
-
- }
-
- public QueryBuilder getQueryBuilderByFilter() {
- return getQueryBuilderByFilter("");
- }
-
- public QueryBuilder getQueryBuilderByFilter(String prefix) {
- QueryBuilder queryBuilder = fromFilter(filterList, prefix).from(fromPage).size(pageSize);
- setSortOrder(queryBuilder, sortOrder, prefix);
- return queryBuilder;
- }
-
- public long getPage() {
- return page;
- }
-
- public long getPageSize() {
- return pageSize;
- }
-
- public long getPageStartIndex() {
- return fromPage;
- }
-
- @Override
- public String toString() {
- return "QueryByFilter [page=" + page + ", pageSize=" + pageSize + ", fromPage=" + fromPage + ", filterList="
- + filterList + ", sortOrder=" + sortOrder + "]";
- }
-
- /*
- * Private and static implementations
- */
- private static QueryBuilder setSortOrder(QueryBuilder query, @Nullable List<Sortorder> sortorder, String prefix) {
- if (sortorder != null && sortorder.size() > 0) {
- for (Sortorder so : sortorder) {
- query.sort(handlePrefix(prefix, so.getProperty()), convert(so.getSortorder()));
- }
- }
- return query;
- }
-
- private static org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder convert(SortOrder sortOrder) {
- return sortOrder == SortOrder.Ascending
- ? org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.ASCENDING
- : org.onap.ccsdk.features.sdnr.wt.common.database.queries.SortOrder.DESCENDING;
- };
-
- private static String fillTimeStamp(String value) {
- int idx = value.lastIndexOf("*");
- final String REPLACE = "0000-00-00T00:00:00.0Z";
- String s = value.substring(0, idx) + REPLACE.substring(idx);
- if (Integer.parseInt(s.substring(5, 7)) == 0) {
- s = s.substring(0, 5) + "01-" + s.substring(8);
- }
- if (Integer.parseInt(s.substring(8, 10)) == 0) {
- s = s.substring(0, 8) + "01" + s.substring(10);
- }
-
- return s;
- }
-
- /**
- * convert timestamp with ending placeholder in filter to elasticsearch filter e.g. 2017* => gte:
- * 2017-01-01T00:00:00Z, lt:2018-01-01T00:00:00Z
- *
- * 201* => 2010-01... 2020 .. 2018-* => 2018-01... <=> 2019-01
- *
- */
- private static @Nullable QueryBuilder fromTimestampSearchFilter(String property, String value) {
- if (!value.endsWith("*")) {
- return null;
- }
- int idx = value.lastIndexOf("*");
- String lowerEnd = fillTimeStamp(value);
- String upperEnd = null;
- NetconfTimeStamp converter = NetconfTimeStampImpl.getConverter();
- Date dt = null;
- try {
- dt = converter.getDateFromNetconf(lowerEnd);
- } catch (Exception e) {
-
- }
- if (dt == null) {
- return null;
- }
- // property.substring(0,idx)+REPLACE.substring(idx+1);
- Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- c.setTime(dt);
- int tmpvalue;
- switch (idx) {
- case 1: // (2*)
- c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1000);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 2: // (20*)
- c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 100);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 3: // (200*)
- c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 10);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 4: // (2000*)
- case 5: // (2000-*)
- c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 6: // switch 10 months (2000-0* or 2000-1*)
- tmpvalue = c.get(Calendar.MONTH);
- if (tmpvalue < 9) {
- c.set(Calendar.MONTH, 9);
- } else {
- c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1);
- c.set(Calendar.MONTH, 0);
- }
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
-
- break;
- case 7: // switch one month (2018-01* or 2018-01-*)
- case 8:
- c.add(Calendar.MONTH, 1);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 9: // (2018-01-0*)
- tmpvalue = c.get(Calendar.DAY_OF_MONTH);
- if (tmpvalue == 1) {
- c.set(Calendar.DAY_OF_MONTH, 10);
- } else if (tmpvalue == 10) {
- c.set(Calendar.DAY_OF_MONTH, 20);
- } else if (tmpvalue == 20) {
- if (c.getActualMaximum(Calendar.DAY_OF_MONTH) < 30) {
- c.set(Calendar.DAY_OF_MONTH, 1);
- c.add(Calendar.MONTH, 1);
- } else {
- c.set(Calendar.DAY_OF_MONTH, 30);
- }
- } else if (tmpvalue == 30) {
- c.set(Calendar.DAY_OF_MONTH, 1);
- c.add(Calendar.MONTH, 1);
- } else {
- break;
- }
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 10: // (2018-01-01*)
- case 11: // (2018-01-01T*)
- c.add(Calendar.DAY_OF_MONTH, 1);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 12: // (2018-01-01T1*)
- tmpvalue = c.get(Calendar.HOUR_OF_DAY);
- if (tmpvalue == 20) {
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.add(Calendar.DAY_OF_MONTH, 1);
- } else {
- c.add(Calendar.HOUR_OF_DAY, 10);
- }
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 13: // (2018-01-01T11*)
- case 14: // (2018-01-01T11-*)
- c.add(Calendar.HOUR_OF_DAY, 1);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 15: // (2018-01-01T11-3*)
- c.add(Calendar.MINUTE, 10);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 16: // (2018-01-01T11-32*)
- case 17: // (2018-01-01T11-32-*)
- c.add(Calendar.MINUTE, 1);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 18: // (2018-01-01T11-32-1*)
- c.add(Calendar.SECOND, 10);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
- case 19: // (2018-01-01T11-32-11*)
- case 20: // (2018-01-01T11-32-11.*)
- c.add(Calendar.SECOND, 1);
- upperEnd = converter.getTimeStampAsNetconfString(c.getTime());
- break;
-
- default:
- break;
- }
-
- if (upperEnd == null) {
- return null;
- }
- return QueryBuilders.rangeQuery(property).gte(lowerEnd).lt(upperEnd);
-
- }
-
- private static QueryBuilder fromFilter(@Nullable List<Filter> filters, String prefix) {
- if (filters == null || filters.size() == 0) {
- return QueryBuilders.matchAllQuery();
-
- } else if (filters.size() == 1) {
- QueryBuilder query;
- String p = filters.get(0).getProperty();
- String v = filters.get(0).getFiltervalue();
- if ("id".equals(p)) {
- p = "_id";
- } else {
- // v=v.toLowerCase();
- }
- if (DbFilter.hasSearchParams(v)) {
- if (p != null && timestampValueNames.contains(p.toLowerCase())) {
- query = fromTimestampSearchFilter(p, v);
- if (query != null) {
- return query;
- }
- }
- return QueryBuilders.regex(p, DbFilter.createDatabaseRegex(v));
-
-
- } else if (DbFilter.isComparisonValid(v)) {
- RangeQueryBuilder q = DbFilter.getRangeQuery(handlePrefix(prefix, p), v);
- if (q != null) {
- return q;
- } else {
- return QueryBuilders.matchQuery(handlePrefix(prefix, p), v);
- }
- } else {
- return QueryBuilders.matchQuery(handlePrefix(prefix, p), v);
- }
- } else {
- BoolQueryBuilder query = new BoolQueryBuilder();
- QueryBuilder tmpQuery;
- for (Filter fi : filters) {
- String p = fi.getProperty();
- String v = fi.getFiltervalue();
- if ("id".equals(p)) {
- p = "_id";
- } else {
- // v=v.toLowerCase();
- }
- if (DbFilter.hasSearchParams(v)) {
- if (p != null && timestampValueNames.contains(p.toLowerCase())) {
- tmpQuery = fromTimestampSearchFilter(p, v);
- if (tmpQuery != null) {
- query.must(tmpQuery);
- } else {
- query.must(QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v)));
- }
- } else {
- query.must(QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v)));
- }
- } else if (DbFilter.isComparisonValid(v)) {
- RangeQueryBuilder q = DbFilter.getRangeQuery(handlePrefix(prefix, p), v);
- if (q != null) {
- query.must(q);
- } else {
- query.must(QueryBuilders.matchQuery(handlePrefix(prefix, p), v));
- }
- } else {
- query.must(QueryBuilders.matchQuery(handlePrefix(prefix, p), v));
- }
- }
- LOG.trace("Query result. {}", query.toJSON());
- return query;
- }
- }
-
- private static String handlePrefix(String prefix, String p) {
- return (prefix != null ? prefix : "") + p;
- }
-
-}
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java
index 85d3cfe4b..063fae622 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBMapper.java
@@ -33,7 +33,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.sql.rowset.CachedRowSet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.filters.DBKeyValuePair;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
@@ -336,12 +335,6 @@ public class SqlDBMapper {
return YangToolsMapperHelper.implementsInterface(valueType, Enumeration.class);
}
- public static <T extends DataObject> List<T> read(CachedRowSet data, Class<T> clazz)
- throws JsonMappingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
- InstantiationException, SecurityException, NoSuchMethodException, JsonProcessingException, SQLException {
- return read(data, clazz, null);
- }
-
public static <T extends DataObject> List<T> read(ResultSet data, Class<T> clazz)
throws JsonMappingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
InstantiationException, SecurityException, NoSuchMethodException, JsonProcessingException, SQLException {
@@ -349,34 +342,6 @@ public class SqlDBMapper {
}
@SuppressWarnings("unchecked")
- public static <T> List<T> read(CachedRowSet data, Class<T> clazz, String column) throws IllegalAccessException,
- IllegalArgumentException, InvocationTargetException, SQLException, InstantiationException,
- SecurityException, NoSuchMethodException, JsonMappingException, JsonProcessingException {
-
- List<T> list = new ArrayList<>();
- while (data.next()) {
- if (column == null) {
- Builder<T> builder = findPOJOBuilder(clazz);
- Class<?> argType;
- String col;
- for (Method m : getFilteredMethods(builder.getClass(), false)) {
- argType = m.getParameterTypes()[0];
- col = getColumnName(m);
- m.setAccessible(true);
- m.invoke(builder, getValueOrDefault(data, col, argType, null));
- }
- list.add(builder.build());
- } else {
- Object value = getValueOrDefault(data, column, clazz, null);
- if (value != null) {
- list.add((T) value);
- }
- }
- }
- return list;
- }
-
- @SuppressWarnings("unchecked")
public static <T> List<T> read(ResultSet data, Class<T> clazz, String column) throws IllegalAccessException,
IllegalArgumentException, InvocationTargetException, SQLException, InstantiationException,
SecurityException, NoSuchMethodException, JsonMappingException, JsonProcessingException {
@@ -428,27 +393,6 @@ public class SqlDBMapper {
return null;
}
- private static Object getValueOrDefault(CachedRowSet data, String col, Class<?> dstType, Object defaultValue)
- throws SQLException, JsonMappingException, JsonProcessingException {
- if (isBoolean(dstType)) {
- return data.getBoolean(col);
- } else if (isNumeric(dstType)) {
- return getNumeric(dstType, data.getLong(col));
- } else if (String.class.equals(dstType)) {
- return data.getString(col);
- } else if (isYangEnum(dstType)) {
- return getYangEnum(data.getString(col), dstType);
- } else if (isDateTime(dstType)) {
- String v = data.getString(col);
- return v == null || v.equals("null") ? null : DateAndTime.getDefaultInstance(v.replace(" ", "T") + "Z");
- } else if (isComplex(dstType)) {
- String v = data.getString(col);
-
- return (v == null || v.toLowerCase().equals("null")) ? null : mapper.readValue(v, dstType);
- }
- return defaultValue;
- }
-
private static Object getValueOrDefault(ResultSet data, String col, Class<?> dstType, Object defaultValue)
throws SQLException, JsonMappingException, JsonProcessingException {
if (isBoolean(dstType)) {
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java
index d033e45f7..6cc9e35d0 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/database/SqlDBReaderWriter.java
@@ -104,7 +104,7 @@ public class SqlDBReaderWriter<T extends DataObject> {
public QueryResult<T> getData(EntityInput input) {
SelectQuery query = new SelectQuery(this.tableName, input, this.controllerId);
- LOG.info("query={}", query.toSql());
+ LOG.trace("query={}", query.toSql());
try {
ResultSet data = this.dbService.read(query.toSql());
List<T> mappedData = SqlDBMapper.read(data, clazz);
@@ -115,7 +115,7 @@ public class SqlDBReaderWriter<T extends DataObject> {
| InstantiationException | SecurityException | NoSuchMethodException | JsonProcessingException e) {
LOG.warn("problem reading data {}: ", this.entity, e);
}
- return null;
+ return QueryResult.createEmpty();
}
@@ -172,7 +172,7 @@ public class SqlDBReaderWriter<T extends DataObject> {
UpsertQuery<S> query = new UpsertQuery<S>(this.entity, object, this.controllerId);
query.setId(id);
String insertedId = null;
- LOG.info("query={}", query.toSql());
+ LOG.trace("query={}", query.toSql());
try {
Connection connection = this.dbService.getConnection();
PreparedStatement stmt = connection.prepareStatement(query.toSql());
diff --git a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java
index 800150814..e2cc2177d 100644
--- a/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java
+++ b/sdnr/wt/data-provider/dblib/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/sqldb/query/SelectQuery.java
@@ -40,7 +40,6 @@ public class SelectQuery implements SqlQuery {
private static final long DEFAULT_PAGESIZE = 20;
private static final long DEFAULT_PAGE = 1;
- private static final List<String> TIMESTAMPPROPERTYNAMES = Arrays.asList("timestamp", "time-stamp", "start", "end");
private final String tableName;
private final List<Filter> filters;
private final List<String> sortExpressions;
diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java
new file mode 100644
index 000000000..7a37345f2
--- /dev/null
+++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java
@@ -0,0 +1,76 @@
+/*
+ * ============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.dataprovider.dblib.test;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.DatabaseIdGenerator;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.GranularityPeriodType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.InventoryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.MaintenanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Pmdata15mEntity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Pmdata24hEntity;
+
+public class TestObjectIds {
+
+ private static final String NODEID1 = "nodeid1";
+ private static final String OBJECTID1 = "objectid1";
+ private static final String PROBLEMNAME1 = "problem1";
+ private static final String FAULTCURRENTID1 = String.format("%s/%s/%s", NODEID1, OBJECTID1, PROBLEMNAME1);
+ private static final String EQUIPMENT_UUID1 = "equipment1";
+ private static final String INVENTORY_ID1 = String.format("%s/%s", NODEID1, EQUIPMENT_UUID1);
+ private static final String PM15MUUID1 = "pm15muuid1";
+ private static final String PM24HUUID1 = "pm24huuid1";
+ private static final String TIMESTAMP1 = "2020-05-01T12:55:12.34Z";
+ private static final String PMDATA15MID1 = String.format("%s/%s/%s", NODEID1, PM15MUUID1, TIMESTAMP1);
+ private static final String PMDATA24HID1 = String.format("%s/%s/%s", NODEID1, PM24HUUID1, TIMESTAMP1);
+
+
+ @Test
+ public void testGenerator() {
+ assertEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, OBJECTID1, PROBLEMNAME1));
+ assertEquals(INVENTORY_ID1, DatabaseIdGenerator
+ .getInventoryId(new InventoryBuilder().setNodeId(NODEID1).setUuid(EQUIPMENT_UUID1).build()));
+ assertEquals(NODEID1,
+ DatabaseIdGenerator.getMaintenanceId(new MaintenanceBuilder().setNodeId(NODEID1).build()));
+ assertEquals(NODEID1, DatabaseIdGenerator.getMaintenanceId(NODEID1));
+ assertEquals(NODEID1, DatabaseIdGenerator.getNetworkelementConnectionId(NODEID1));
+ assertEquals(NODEID1, DatabaseIdGenerator
+ .getNetworkelementConnectionId(new NetworkElementConnectionBuilder().setNodeId(NODEID1).build()));
+ Pmdata15mEntity e =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.DataBuilder()
+ .setNodeName(NODEID1).setGranularityPeriod(GranularityPeriodType.Period15Min)
+ .setUuidInterface(PM15MUUID1)
+ .setTimeStamp(NetconfTimeStampImpl.getConverter().getTimeStamp(TIMESTAMP1)).build();
+ assertEquals(PMDATA15MID1, DatabaseIdGenerator.getPmData15mId(e));
+ assertEquals(PMDATA15MID1, DatabaseIdGenerator.getPmData15mId(NODEID1, PM15MUUID1, TIMESTAMP1));
+ Pmdata24hEntity e2 =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._24h.list.output.DataBuilder()
+ .setNodeName(NODEID1).setGranularityPeriod(GranularityPeriodType.Period24Hours)
+ .setUuidInterface(PM24HUUID1)
+ .setTimeStamp(NetconfTimeStampImpl.getConverter().getTimeStamp(TIMESTAMP1)).build();
+ assertEquals(PMDATA24HID1, DatabaseIdGenerator.getPmData24hId(e2));
+ assertEquals(PMDATA24HID1, DatabaseIdGenerator.getPmData24hId(NODEID1, PM24HUUID1, TIMESTAMP1));
+ }
+}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseEventsService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseEventsService.java
index 41e94e3f6..ea3296acb 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseEventsService.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/elasticsearch/data/entity/HtDatabaseEventsService.java
@@ -80,6 +80,8 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid
private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter();
+ private static final int ROOT_TREE_LEVEL = 0;
+
private HtDatabaseClient client;
private EsDataObjectReaderWriter2<EventlogEntity> eventRWEventLogDevicemanager;
private EsDataObjectReaderWriter2<InventoryEntity> eventRWEquipment;
@@ -306,20 +308,21 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid
.setTreeLevel(Uint32.valueOf(0));;
for (Inventory item : list) {
repairedItem = new InventoryBuilder(item);
- // check missing tree-level
+ // check for bad node-id
if (!nodeId.equals(item.getNodeId())) {
failures.add(String.format("missing node-id for equipment(uuid=%s)", item.getUuid()));
repairedItem.setNodeId(nodeId);
failCounter++;
}
+ // check missing tree-level
if (item.getTreeLevel() == null) {
failures.add(String.format("missing tree-level for equipment(uuid=%s)", item.getUuid()));
- repairedItem.setTreeLevel(Uint32.valueOf(1));
+ repairedItem.setTreeLevel(Uint32.valueOf(ROOT_TREE_LEVEL));
failCounter++;
} else {
treeLevel = item.getTreeLevel().longValue();
- if (treeLevel > 0) {
+ if (treeLevel > ROOT_TREE_LEVEL) {
// check non root elem and missing parent
if (item.getParentUuid() == null) {
failures.add(String.format("Non root level element (uuid=%s) has to have a parent element",
diff --git a/sdnr/wt/data-provider/provider/src/test/resources/TestTree/test3.json b/sdnr/wt/data-provider/provider/src/test/resources/TestTree/test3.json
new file mode 100644
index 000000000..833815cd7
--- /dev/null
+++ b/sdnr/wt/data-provider/provider/src/test/resources/TestTree/test3.json
@@ -0,0 +1,180 @@
+[
+{
+"_index": "inventoryequipment-v6",
+"_type": "_doc",
+"_id": "FSP3000-ROADM-2/10.20.4.12/MOD-1-15",
+"_score": 3.465736,
+"_source": {
+"node-id": "FSP3000-ROADM-2",
+"manufacturer-identifier": "ADVA",
+"model-identifier": "4ROADM-C96/0/OPM",
+"parent-uuid": "10.20.4.12/SHELF-1",
+"tree-level": 2,
+"uuid": "10.20.4.12/MOD-1-15",
+"description": "ProductCode: null Mode: NORMAL",
+"date": "N/A",
+"serial": "n/a",
+"type-name": "ROADM",
+"id": "10.20.4.12/MOD-1-15"
+}
+}
+,
+{
+"_index": "inventoryequipment-v6",
+"_type": "_doc",
+"_id": "FSP3000-ROADM-2/10.20.4.12/SHELF-1",
+"_score": 2.358155,
+"_source": {
+"node-id": "FSP3000-ROADM-2",
+"manufacturer-identifier": "ADVA",
+"model-identifier": "FSP 3000R7",
+"parent-uuid": "ADVA-ENC-SDN-40990-rdm",
+"tree-level": 2,
+"uuid": "10.20.4.12/SHELF-1",
+"description": "Position: null State: InService",
+"date": "N/A",
+"serial": "FA71171552617",
+"type-name": "FSP 3000R7",
+"id": "10.20.4.12/SHELF-1"
+}
+}
+,
+{
+"_index": "inventoryequipment-v6",
+"_type": "_doc",
+"_id": "FSP3000-ROADM-2/10.20.4.12/MOD-1-7",
+"_score": 2.358155,
+"_source": {
+"node-id": "FSP3000-ROADM-2",
+"manufacturer-identifier": "ADVA",
+"model-identifier": "4ROADM-C96/0/OPM",
+"parent-uuid": "10.20.4.12/SHELF-1",
+"tree-level": 2,
+"uuid": "10.20.4.12/MOD-1-7",
+"description": "ProductCode: null Mode: NORMAL",
+"date": "N/A",
+"serial": "n/a",
+"type-name": "ROADM",
+"id": "10.20.4.12/MOD-1-7"
+}
+}
+,
+{
+"_index": "inventoryequipment-v6",
+"_type": "_doc",
+"_id": "FSP3000-ROADM-2/ADVA-ENC-SDN-40990-rdm",
+"_score": 2.358155,
+"_source": {
+"node-id": "FSP3000-ROADM-2",
+"manufacturer-identifier": "",
+"parent-uuid": "unbound",
+"part-type-id": "device",
+"tree-level": 1,
+"uuid": "ADVA-ENC-SDN-40990-rdm",
+"description": "org-openroadm-device",
+"date": "",
+"type-name": "rdm",
+"id": "ADVA-ENC-SDN-40990-rdm"
+}
+}
+,
+{
+"_index": "inventoryequipment-v6",
+"_type": "_doc",
+"_id": "FSP3000-ROADM-2/10.20.4.12/MOD-1-14",
+"_score": 2.1238933,
+"_source": {
+"node-id": "FSP3000-ROADM-2",
+"manufacturer-identifier": "ADVA",
+"model-identifier": "EDFA-C-D20-VLGC-DM",
+"parent-uuid": "10.20.4.12/SHELF-1",
+"tree-level": 2,
+"uuid": "10.20.4.12/MOD-1-14",
+"description": "ProductCode: null Mode: NORMAL",
+"date": "N/A",
+"serial": "n/a",
+"type-name": "AMPLIFIER",
+"id": "10.20.4.12/MOD-1-14"
+}
+}
+,
+{
+"_index": "inventoryequipment-v6",
+"_type": "_doc",
+"_id": "FSP3000-ROADM-2/10.20.4.12/MOD-1-13",
+"_score": 2.1238933,
+"_source": {
+"node-id": "FSP3000-ROADM-2",
+"manufacturer-identifier": "ADVA",
+"model-identifier": "EDFA-C-D20-VLGC-DM",
+"parent-uuid": "10.20.4.12/SHELF-1",
+"tree-level": 2,
+"uuid": "10.20.4.12/MOD-1-13",
+"description": "ProductCode: null Mode: NORMAL",
+"date": "N/A",
+"serial": "n/a",
+"type-name": "AMPLIFIER",
+"id": "10.20.4.12/MOD-1-13"
+}
+}
+,
+{
+"_index": "inventoryequipment-v6",
+"_type": "_doc",
+"_id": "FSP3000-ROADM-2/10.20.4.12/MOD-1-17",
+"_score": 2.1238933,
+"_source": {
+"node-id": "FSP3000-ROADM-2",
+"manufacturer-identifier": "ADVA",
+"model-identifier": "EDFA-C-S20-GCB-DM",
+"parent-uuid": "10.20.4.12/SHELF-1",
+"tree-level": 2,
+"uuid": "10.20.4.12/MOD-1-17",
+"description": "ProductCode: null Mode: NORMAL",
+"date": "N/A",
+"serial": "n/a",
+"type-name": "AMPLIFIER",
+"id": "10.20.4.12/MOD-1-17"
+}
+}
+,
+{
+"_index": "inventoryequipment-v6",
+"_type": "_doc",
+"_id": "FSP3000-ROADM-2/10.20.4.12/MOD-1-6",
+"_score": 2.1238933,
+"_source": {
+"node-id": "FSP3000-ROADM-2",
+"manufacturer-identifier": "ADVA",
+"model-identifier": "EDFA-C-S20-GCB-DM",
+"parent-uuid": "10.20.4.12/SHELF-1",
+"tree-level": 2,
+"uuid": "10.20.4.12/MOD-1-6",
+"description": "ProductCode: null Mode: NORMAL",
+"date": "N/A",
+"serial": "n/a",
+"type-name": "AMPLIFIER",
+"id": "10.20.4.12/MOD-1-6"
+}
+}
+,
+{
+"_index": "inventoryequipment-v6",
+"_type": "_doc",
+"_id": "FSP3000-ROADM-2/10.20.4.12/MOD-1-11",
+"_score": 2.1238933,
+"_source": {
+"node-id": "FSP3000-ROADM-2",
+"manufacturer-identifier": "ADVA",
+"model-identifier": "4ROADM-C96/0/OPM",
+"parent-uuid": "10.20.4.12/SHELF-1",
+"tree-level": 2,
+"uuid": "10.20.4.12/MOD-1-11",
+"description": "ProductCode: null Mode: NORMAL",
+"date": "N/A",
+"serial": "n/a",
+"type-name": "ROADM",
+"id": "10.20.4.12/MOD-1-11"
+}
+}
+] \ No newline at end of file