aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-04-06 10:33:41 +0200
committerMichael D�rre <michael.duerre@highstreet-technologies.com>2021-04-06 09:01:07 +0000
commit24cac2175588a81a2ebecb5c08b91455cfc24d0b (patch)
tree179e41ba8a16ce579fa679d3283d047a41857b26 /sdnr/wt/data-provider
parent9fb395380431345b7da7a765651185815a9ac91d (diff)
source out odl mapper
put odl mapper code into seperate bundle Issue-ID: CCSDK-3254 Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com> Change-Id: I3debef0be8e44e7c68c95a6d06b7e50813bbea43
Diffstat (limited to 'sdnr/wt/data-provider')
-rwxr-xr-xsdnr/wt/data-provider/installer/pom.xml19
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataInconsistencyException.java (renamed from sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/EnumSerializer.java)24
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java7
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/HtUserdataManager.java38
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEntityDataProvider.java2
-rw-r--r--sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/NetconfTimeStampImpl.java4
-rw-r--r--sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang24
-rw-r--r--sdnr/wt/data-provider/provider/pom.xml10
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtUserdataManagerImpl.java150
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java104
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilter.java109
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java4
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java14
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java26
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java14
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java175
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderImpl.java13
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java8
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java33
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/DataProviderYangToolsMapper.java (renamed from sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper.java)32
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper2.java97
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapperHelper.java244
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/builder/DateAndTimeBuilder.java36
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsBuilderAnnotationIntrospector.java134
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsDeserializerModifier.java117
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsModule.java50
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/BaseIdentityDeserializer.java64
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/ClassDeserializer.java45
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/DateAndTimeSerializer.java51
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/IdentifierDeserializer.java71
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/MapSerializer.java37
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/TypeObjectDeserializer.java87
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/TypeObjectSerializer.java51
-rw-r--r--sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml10
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java81
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java2
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java22
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java4
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java6
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java5
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java94
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java6
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java10
-rw-r--r--sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json13
-rw-r--r--sdnr/wt/data-provider/provider/src/test/resources/userdata/merged.json13
-rw-r--r--sdnr/wt/data-provider/provider/src/test/resources/userdata/networkmap.json11
46 files changed, 882 insertions, 1289 deletions
diff --git a/sdnr/wt/data-provider/installer/pom.xml b/sdnr/wt/data-provider/installer/pom.xml
index cdd1724d2..ee6b2f370 100755
--- a/sdnr/wt/data-provider/installer/pom.xml
+++ b/sdnr/wt/data-provider/installer/pom.xml
@@ -118,27 +118,8 @@
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
- <version>2.6</version>
<executions>
<execution>
- <id>copy-sdnr-data-migration-tool</id>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <phase>validate</phase>
- <configuration>
- <outputDirectory>${project.build.directory}/assembly/system/org/onap/ccsdk/features/sdnr/wt/sdnr-wt-data-provider-setup/${project.version}</outputDirectory>
- <resources>
- <resource>
- <directory>${basedir}/../setup/target</directory>
- <includes>
- <include>sdnr-dmt.jar</include>
- </includes>
- </resource>
- </resources>
- </configuration>
- </execution>
- <execution>
<id>copy-schemas</id>
<goals>
<goal>copy-resources</goal>
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/EnumSerializer.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataInconsistencyException.java
index f8220c2d4..e734a47a3 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/EnumSerializer.java
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataInconsistencyException.java
@@ -19,18 +19,22 @@
* ============LICENSE_END=========================================================
*
*/
-package org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize;
+package org.onap.ccsdk.features.sdnr.wt.dataprovider.model;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import java.io.IOException;
+import java.util.List;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
-@SuppressWarnings("rawtypes")
-public class EnumSerializer extends JsonSerializer<Enum> {
+public class DataInconsistencyException extends Exception {
- @Override
- public void serialize(Enum value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
- gen.writeString(value.name());
+ private static final long serialVersionUID = 1L;
+ private final List<Inventory> repaired;
+
+ public DataInconsistencyException(List<Inventory> repaired, String message) {
+ super(message);
+ this.repaired = repaired;
+ }
+
+ public List<Inventory> getRepairedList() {
+ return this.repaired;
}
}
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java
index 47255fd73..e6eb7a4e8 100644
--- a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/DataProvider.java
@@ -67,10 +67,15 @@ public interface DataProvider extends ArchiveCleanProvider {
/**
* write internal equipment to database
- *
* @param internalEquipment with mandatory fields.
*/
void writeInventory(Inventory internalEquipment);
+ /**
+ * write internal equipment to database
+ * @param nodeId
+ * @param list with mandatory fields.
+ */
+ void writeInventory(String nodeId, List<Inventory> list);
/**
* write GUI Cut through data to database
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/HtUserdataManager.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/HtUserdataManager.java
new file mode 100644
index 000000000..2f580c98b
--- /dev/null
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/HtUserdataManager.java
@@ -0,0 +1,38 @@
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * 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.model;
+
+/**
+ * @author Jack
+ *
+ */
+public interface HtUserdataManager {
+
+ String getUserdata(String username);
+
+ String getUserdata(String username, String key);
+
+ boolean setUserdata(String username, String data);
+
+ boolean setUserdata(String username, String key, String data);
+
+ boolean removeUserdata(String username);
+
+ boolean removeUserdata(String username, String key);
+
+}
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEntityDataProvider.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEntityDataProvider.java
index 9ba10cd0b..2a91d7816 100644
--- a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEntityDataProvider.java
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/IEntityDataProvider.java
@@ -27,6 +27,8 @@ public interface IEntityDataProvider {
/** Get provider to access read/write operations for maintenance **/
public HtDatabaseMaintenance getHtDatabaseMaintenance();
+ public HtUserdataManager getHtDatabaseUserManager();
+
/** Set overall ready status from outside of this data-provider **/
public void setReadyStatus(boolean status);
diff --git a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/NetconfTimeStampImpl.java b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/NetconfTimeStampImpl.java
index bd71d5ba1..2ccebca99 100644
--- a/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/NetconfTimeStampImpl.java
+++ b/sdnr/wt/data-provider/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/model/types/NetconfTimeStampImpl.java
@@ -75,14 +75,14 @@ public class NetconfTimeStampImpl implements NetconfTimeStamp {
/**
* Specify the input format expected from netconf, and from specific devices.
*/
- private static DateTimeFormatter formatterInput =
+ private static final DateTimeFormatter formatterInput =
DateTimeFormatter.ofPattern("" + "[yyyy-MM-dd'T'HH:mm[:ss][.SSS][.SS][.S][xxx][xx][X][Z]]"
+ "[yyyyMMddHHmmss[.SSS][.SS][.S][xxx][xx][X][Z]]").withZone(ZoneOffset.UTC);
/**
* Specify output format that is used internally
*/
- private static DateTimeFormatter formatterOutput =
+ private static final DateTimeFormatter formatterOutput =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.S'Z'").withZone(ZoneOffset.UTC);
/**
diff --git a/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang b/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang
index 8509007e1..84c43d52b 100644
--- a/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang
+++ b/sdnr/wt/data-provider/model/src/main/yang/data-provider@2020-11-10.yang
@@ -104,6 +104,10 @@ module data-provider {
description
"list of GUI Cut through entries";
}
+ enum userdata {
+ description
+ "user specific data. id=username";
+ }
}
description
"Data type and alias for elasticsearch or table name for SQL database.";
@@ -556,7 +560,11 @@ module data-provider {
description
"An object class describing a mediator server entity.";
}
-
+ container mediator-server {
+ description
+ "builder";
+ uses mediator-server-entity;
+ }
grouping pmdata-base {
description
"Performance data base information";
@@ -1260,6 +1268,11 @@ module data-provider {
description
"current connection status. default Disconnected";
}
+ leaf tls-key {
+ type string;
+ description
+ "TLS key-id in MD-SAL";
+ }
description
"An object class defining the NetConf connection towards a
NetConf server. ";
@@ -1324,6 +1337,11 @@ module data-provider {
description
"The filter information for the corresponding property.";
}
+ leaf-list filtervalues {
+ type string;
+ description
+ "The filter information for the corresponding property.";
+ }
description
"List with filter criteria. Not listed means all.";
}
@@ -1406,12 +1424,12 @@ module data-provider {
type string;
mandatory true;
description
- "Unique database id, node-id/uuid";
+ "Unique database id, node-id";
}
leaf name {
type string;
description
- "Mountpoint Name";
+ "Name of the system to which a GUI Cutthrough session will be established";
}
leaf weburi {
type string;
diff --git a/sdnr/wt/data-provider/provider/pom.xml b/sdnr/wt/data-provider/provider/pom.xml
index 9045dfa12..3507d4108 100644
--- a/sdnr/wt/data-provider/provider/pom.xml
+++ b/sdnr/wt/data-provider/provider/pom.xml
@@ -48,7 +48,8 @@
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
- <databaseport>49402</databaseport>
+ <databaseport>49402</databaseport>
+ <initdb>${basedir}/../setup/target/sdnr-dmt.jar</initdb>
</properties>
<dependencies>
@@ -74,6 +75,11 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
+ <artifactId>sdnr-wt-yang-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
<artifactId>sdnr-wt-data-provider-model</artifactId>
<version>${project.version}</version>
</dependency>
@@ -159,7 +165,7 @@
<executable>${basedir}/java.sh</executable>
<arguments>
<argument>-jar</argument>
- <argument>${basedir}/../../data-provider/setup/target/sdnr-dmt.jar</argument>
+ <argument>${initdb}</argument>
<argument>-c</argument>
<argument>pluginfile</argument>
<argument>-of</argument>
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtUserdataManagerImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtUserdataManagerImpl.java
new file mode 100644
index 000000000..73cc1a212
--- /dev/null
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/HtUserdataManagerImpl.java
@@ -0,0 +1,150 @@
+/*
+ * ============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.data;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
+import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit;
+import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
+import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HtUserdataManagerImpl implements HtUserdataManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(HtUserdataManagerImpl.class);
+
+ private static final String USERDATA_DEFAULTS_FILENAME = "etc/userdata-defaults.json";
+ private static final JSONObject USERDATA_DEFAULTS_CONTENT = loadDefaults();
+
+ private static JSONObject loadDefaults() {
+ File f = new File(USERDATA_DEFAULTS_FILENAME);
+ String content;
+ JSONObject o = null;
+ if (f.exists()) {
+ try {
+ content = Files.readString(f.toPath());
+ o = new JSONObject(content);
+ } catch (IOException e) {
+ LOG.warn("problem loading defaults: ", e);
+ } catch (JSONException e) {
+ LOG.warn("problem parsing defaults: ", e);
+ }
+ }
+ return o;
+ }
+
+
+ private final HtDatabaseClient dbClient;
+
+ public HtUserdataManagerImpl(HtDatabaseClient rawClient) {
+ this.dbClient = rawClient;
+ }
+
+ @Override
+ public String getUserdata(String username) {
+ SearchResult<SearchHit> result = this.dbClient.doReadByQueryJsonData(Entity.Userdata.getName(),
+ QueryBuilders.matchQuery("_id", username));
+ String json = result.getHits().size() > 0 ? result.getHits().get(0).getSourceAsString() : "{}";
+ if (USERDATA_DEFAULTS_CONTENT != null) {
+ JSONObject merge = mergeData(new JSONObject(json), USERDATA_DEFAULTS_CONTENT);
+ json = merge.toString();
+ }
+ return json;
+ }
+
+ @Override
+ public String getUserdata(String username, String key) {
+ JSONObject o = new JSONObject(this.getUserdata(username));
+ return o.has(key) ? o.get(key).toString() : "{}";
+ }
+
+ @Override
+ public boolean setUserdata(String username, String data) {
+ JSONObject o = new JSONObject(this.getUserdata(username));
+ JSONObject merge = mergeData(o, new JSONObject(data));
+ return this.dbClient.doWriteRaw(Entity.Userdata.getName(), username, merge.toString()) != null;
+ }
+
+ @Override
+ public boolean setUserdata(String username, String key, String data) {
+ JSONObject o = new JSONObject(this.getUserdata(username));
+ o = mergeData(o, key, new JSONObject(data));
+ return this.dbClient.doWriteRaw(Entity.Userdata.getName(), username, o.toString()) != null;
+ }
+
+ @Override
+ public boolean removeUserdata(String username) {
+ return this.dbClient.doRemove(Entity.Userdata.getName(), username);
+ }
+
+ @Override
+ public boolean removeUserdata(String username, String key) {
+ JSONObject o = new JSONObject(this.getUserdata(username));
+ if (o.has(key)) {
+ o.remove(key);
+ return this.setUserdata(username, o.toString());
+ }
+ return true;
+ }
+
+ private static JSONObject mergeData(JSONObject o, String key, JSONObject subObject) {
+ if (!o.has(key)) {
+ o.put(key, subObject);
+ } else {
+ JSONObject tmp = new JSONObject();
+ tmp.put(key, subObject);
+ o = mergeData(tmp, o);
+ }
+ return o;
+ }
+
+ private static JSONObject mergeData(JSONObject source, JSONObject target) throws JSONException {
+ String[] keys = JSONObject.getNames(source);
+ if (keys == null) {
+ return target;
+ }
+ for (String key : keys) {
+ Object value = source.get(key);
+ if (!target.has(key)) {
+ // new value for "key":
+ target.put(key, value);
+ } else {
+ // existing value for "key" - recursively deep merge:
+ if (value instanceof JSONObject) {
+ JSONObject valueJson = (JSONObject) value;
+ mergeData(valueJson, target.getJSONObject(key));
+ } else {
+ target.put(key, value);
+ }
+ }
+ }
+ return target;
+ }
+
+}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java
index f6cd7491a..f680edddf 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/entity/HtDatabaseEventsService.java
@@ -24,7 +24,10 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.data.entity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import javax.annotation.Nonnull;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
@@ -36,6 +39,7 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.queries.RangeQueryBuilder
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.ArchiveCleanProvider;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataInconsistencyException;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
@@ -62,6 +66,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.UpdateNetworkElementConnectionInputBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -120,8 +125,8 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid
NetworkElementConnectionEntity.class, NetworkElementConnectionBuilder.class, true)
.setEsIdAttributeName("_id");
- guiCutThroughDB = new EsDataObjectReaderWriter2<>(client, Entity.Guicutthrough,
- GuicutthroughEntity.class, GuicutthroughBuilder.class);
+ guiCutThroughDB = new EsDataObjectReaderWriter2<>(client, Entity.Guicutthrough, GuicutthroughEntity.class,
+ GuicutthroughBuilder.class);
pmData15mDB = new EsDataObjectReaderWriter2<>(client, Entity.Historicalperformance15min, PmdataEntity.class,
PmdataEntityBuilder.class);
@@ -259,22 +264,109 @@ public class HtDatabaseEventsService implements ArchiveCleanProvider, DataProvid
*
* @param internalEquipment with mandatory fields.
*/
+
@Override
public void writeInventory(Inventory internalEquipment) {
- if (assertIfClientNullForNodeName(internalEquipment.getNodeId())) {
- return;
- }
if (internalEquipment.getManufacturerIdentifier() == null) {
internalEquipment = new InventoryBuilder(internalEquipment).setManufacturerIdentifier("").build();
}
if (internalEquipment.getDate() == null) {
internalEquipment = new InventoryBuilder(internalEquipment).setDate("").build();
}
-
eventRWEquipment.write(internalEquipment, internalEquipment.getNodeId() + "/" + internalEquipment.getUuid());
}
+ /**
+ * write internal equipment to database
+ *
+ * @param nodeId
+ * @param list
+ */
+ @Override
+ public void writeInventory(String nodeId, List<Inventory> list) {
+
+ try {
+ checkConsistency(nodeId, list);
+ } catch (DataInconsistencyException e) {
+ LOG.warn("inventory list for node {} is not consistent", nodeId, e);
+ list = e.getRepairedList();
+ }
+
+ for (Inventory internalEquipment : list) {
+ this.writeInventory(internalEquipment);
+ }
+ }
+
+ private static void checkConsistency(String nodeId, List<Inventory> list) throws DataInconsistencyException {
+ final String UNBOUND_INVENTORY_UUID = "unbound";
+ List<String> failures = new ArrayList<>();
+ long treeLevel;
+ int failCounter = 0;
+ Map<String, Inventory> repairList = new HashMap<>();
+ InventoryBuilder repairedItem;
+ InventoryBuilder unboundItem = new InventoryBuilder().setNodeId(nodeId).setUuid(UNBOUND_INVENTORY_UUID)
+ .setTreeLevel(Uint32.valueOf(0));;
+ for (Inventory item : list) {
+ repairedItem = new InventoryBuilder(item);
+ //check missing tree-level
+ if (!nodeId.equals(item.getNodeId())) {
+ failures.add(String.format("missing node-id for equipment(uuid=%s)", item.getUuid()));
+ repairedItem.setNodeId(nodeId);
+ failCounter++;
+ }
+ if (item.getTreeLevel() == null) {
+ failures.add(String.format("missing tree-level for equipment(uuid=%s)", item.getUuid()));
+ repairedItem.setTreeLevel(Uint32.valueOf(1));
+ failCounter++;
+
+ } else {
+ treeLevel = item.getTreeLevel().longValue();
+ if (treeLevel > 0) {
+ //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",
+ item.getUuid()));
+ failCounter++;
+ repairedItem.setParentUuid(UNBOUND_INVENTORY_UUID);
+ repairList.put(unboundItem.getUuid(), unboundItem.build());
+ }
+ //check that parent exists in list and is tree-level -1
+ else {
+ Optional<Inventory> parent =
+ list.stream().filter(e -> item.getParentUuid().equals(e.getUuid())).findFirst();
+ if (parent.isEmpty()) {
+ failures.add(String.format("no parent found for uuid=%s with parent-uuid=%s",
+ item.getUuid(), item.getParentUuid()));
+ repairedItem.setParentUuid(UNBOUND_INVENTORY_UUID);
+ failCounter++;
+ }
+ }
+ }
+ //check for duplicated uui
+ Optional<Inventory> duplicate = list
+ .stream().filter(e -> !item.equals(e) && item.getUuid() != null
+ && item.getUuid().equals(e.getUuid()) && repairList.containsKey(e.getUuid()))
+ .findFirst();
+ if (duplicate.isPresent()) {
+ failures.add(String.format("found duplicate uuid=%s", item.getUuid()));
+ failCounter++;
+ continue;
+
+ }
+ if (failCounter > 0) {
+ repairList.put(repairedItem.getUuid(), repairedItem.build());
+ } else {
+ repairList.put(item.getUuid(), item);
+ }
+ }
+ }
+
+ if (failures.size() > 0) {
+ throw new DataInconsistencyException(new ArrayList<>(repairList.values()),
+ "inventory list is not consistent;\n" + String.join("\n", failures));
+ }
+ }
// -- Networkelement
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilter.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilter.java
index 09e48197a..627d125ae 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilter.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/data/rpctypehelper/QueryByFilter.java
@@ -33,7 +33,6 @@ 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.common.database.requests.SearchRequest;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.acessor.DataObjectAcessorPm;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
@@ -76,11 +75,13 @@ public class QueryByFilter {
@Nullable
Pagination pagination = input.getPagination();
if (pagination != null) {
- @Nullable Uint64 pageOrNull = YangHelper2.getUint64(pagination.getPage());
+ @Nullable
+ Uint64 pageOrNull = YangHelper2.getUint64(pagination.getPage());
if (pageOrNull != null) {
page = pageOrNull.longValue();
}
- @Nullable Uint32 pageSizeOrNull = YangHelper2.getUint32(pagination.getSize());
+ @Nullable
+ Uint32 pageSizeOrNull = YangHelper2.getUint32(pagination.getSize());
if (pageSizeOrNull != null) {
pageSize = pageSizeOrNull.longValue();
}
@@ -239,7 +240,7 @@ public class QueryByFilter {
if (dt == null) {
return null;
}
- // property.substring(0,idx)+REPLACE.substring(idx+1);
+ // property.substring(0,idx)+REPLACE.substring(idx+1);
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.setTime(dt);
int tmpvalue;
@@ -348,70 +349,54 @@ public class QueryByFilter {
}
+ private static List<String> collectValues(Filter filter) {
+ List<String> values = new ArrayList<String>();
+ if (filter.getFiltervalue() != null) {
+ values.add(filter.getFiltervalue());
+ }
+ if (filter.getFiltervalues() != null) {
+ values.addAll(filter.getFiltervalues());
+ }
+ return values;
+ }
+
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();
+ String property = filters.get(0).getProperty();
+ List<String> values = collectValues(filters.get(0));
+ if ("id".equals(property)) {
+ property = "_id";
}
- if (DbFilter.hasSearchParams(v)) {
- if (p != null && timestampValueNames.contains(p.toLowerCase())) {
- query = fromTimestampSearchFilter(p, v);
- if (query != null) {
- return query;
- }
+ if (values.size() == 1) {
+ return getSinglePropertyQuery(property, values.get(0), prefix);
+ } else {
+ BoolQueryBuilder bquery = new BoolQueryBuilder();
+ for (String v : values) {
+ bquery.should(getSinglePropertyQuery(property, v, prefix));
}
- return QueryBuilders.regex(p, DbFilter.createDatabaseRegex(v));
+ return bquery;
-
- } 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();
+ List<String> values = collectValues(fi);
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));
- }
+ if (values.size() == 1) {
+ query.must(getSinglePropertyQuery(p, values.get(0), prefix));
} else {
- query.must(QueryBuilders.matchQuery(handlePrefix(prefix, p), v));
+ BoolQueryBuilder tmpQuery = QueryBuilders.boolQuery();
+ for (String v : values) {
+ tmpQuery.should(getSinglePropertyQuery(p, v, prefix));
+ }
+ query.must(tmpQuery);
+ tmpQuery = QueryBuilders.boolQuery();
}
}
LOG.trace("Query result. {}", query.toJSON());
@@ -419,6 +404,28 @@ public class QueryByFilter {
}
}
+ private static QueryBuilder getSinglePropertyQuery(String p, String v, String prefix) {
+ QueryBuilder query = null;
+ if (DbFilter.hasSearchParams(v)) {
+ if (p != null && timestampValueNames.contains(p.toLowerCase())) {
+ query = fromTimestampSearchFilter(p, v);
+ if (query == null) {
+ query = QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v));
+ }
+ } else {
+ query = QueryBuilders.regex(handlePrefix(prefix, p), DbFilter.createDatabaseRegex(v));
+ }
+ } else if (DbFilter.isComparisonValid(v)) {
+ query = DbFilter.getRangeQuery(handlePrefix(prefix, p), v);
+ if (query == null) {
+ query = QueryBuilders.matchQuery(handlePrefix(prefix, p), v);
+ }
+ } else {
+ query = QueryBuilders.matchQuery(handlePrefix(prefix, p), v);
+ }
+ return query;
+ }
+
private static String handlePrefix(String prefix, String p) {
return (prefix != null ? prefix : "") + p;
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java
index 603c25bae..153022b4c 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/database/EsDataObjectReaderWriter2.java
@@ -32,8 +32,8 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.DatabaseClient;
import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit;
import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilder;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper2;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper2;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java
index e34988b4b..91d469700 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeChildObject.java
@@ -26,14 +26,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import org.json.JSONObject;
public class DataTreeChildObject {
private final String label;
- private final String ownSeverity;
- private final String childrenSeveritySummary;
+// private final String ownSeverity;
+// private final String childrenSeveritySummary;
private final boolean isMatch;
private final Map<String, DataTreeChildObject> children;
private final Map<String, Object> properties;
@@ -47,8 +46,8 @@ public class DataTreeChildObject {
this.label = label;
this.isMatch = isMatch;
this.children = children;
- this.ownSeverity = ownSeverity;
- this.childrenSeveritySummary = childrenSeveritySummary;
+// this.ownSeverity = ownSeverity;
+// this.childrenSeveritySummary = childrenSeveritySummary;
this.properties = new HashMap<>();
}
@@ -104,6 +103,7 @@ public class DataTreeChildObject {
itemValue = this.getProperty(childKey, null);
if (itemValue != null && itemValue.equals(itemValueToMatch)) {
this.children.put(id, data);
+ return true;
}
}
return false;
@@ -189,4 +189,8 @@ public class DataTreeChildObject {
this.children.remove(key);
}
}
+
+ public boolean hasChildren() {
+ return this.children!=null && !this.children.isEmpty();
+ }
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java
index bb4023abc..115ff4f40 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeHttpServlet.java
@@ -48,14 +48,6 @@ import org.slf4j.LoggerFactory;
*/
public class DataTreeHttpServlet extends HttpServlet {
- public enum FilterMode {
- Strict, //show only filtered items and their parents
- Lazy //show root items (and all their children) which have matches inside
- }
-
- /**
- *
- */
private static final long serialVersionUID = 1L;
private final DataTreeProviderImpl dataTreeProvider;
private static final Logger LOG = LoggerFactory.getLogger(DataTreeHttpServlet.class);
@@ -116,7 +108,7 @@ public class DataTreeHttpServlet extends HttpServlet {
LOG.info("GET request for {} to e={} with tree={}", uri, e.entity, e.tree);
switch (e.entity) {
case Inventoryequipment:
- DataTreeObject o = this.dataTreeProvider.readInventoryTree(e.tree, null, FilterMode.Lazy);
+ DataTreeObject o = this.dataTreeProvider.readInventoryTree(e.tree, null);
this.doJsonResponse(resp, o);
break;
default:
@@ -132,17 +124,12 @@ public class DataTreeHttpServlet extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final String uri = req.getRequestURI();
String filter = null;
- FilterMode mode = FilterMode.Lazy;
try {
final String body = readPayload(req);
JSONObject data = new JSONObject(body);
if (data.has("query")) {
filter = data.getString("query");
}
- if (data.has("mode")) {
- mode = data.getString("mode").equals("lazy") ? FilterMode.Lazy : FilterMode.Strict;
- }
-
} catch (Exception e) {
LOG.warn("problem reading payload: {}", e);
@@ -152,7 +139,7 @@ public class DataTreeHttpServlet extends HttpServlet {
if (e != null) {
switch (e.entity) {
case Inventoryequipment:
- DataTreeObject o = this.dataTreeProvider.readInventoryTree(e.tree, filter, mode);
+ DataTreeObject o = this.dataTreeProvider.readInventoryTree(e.tree, filter);
this.doJsonResponse(resp, o);
break;
default:
@@ -208,6 +195,15 @@ public class DataTreeHttpServlet extends HttpServlet {
return "EntityWithTree [entity=" + entity + ", tree=" + tree + "]";
}
+ /**
+ *
+ * @param e database enttity to access
+ * @param tree tree description
+ * e.g. nodeA => tree entry for node-id=nodeA
+ * nodeA/key0 => tree entry for node-id=nodeA and uuid=key0 and tree-level=0
+ * nodeA/key0/key1 => tree entry for node-id=nodeA and uuid=key1 and tree-level=1
+ *
+ */
public EntityWithTree(Entity e, String tree) {
this.entity = e;
if (tree != null) {
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java
index d6c8bd7bb..f12ff3deb 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/DataTreeObject.java
@@ -21,8 +21,9 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.http;
+import java.util.ArrayList;
import java.util.HashMap;
-
+import java.util.List;
import org.json.JSONObject;
public class DataTreeObject extends HashMap<String, DataTreeChildObject> {
@@ -95,8 +96,15 @@ public class DataTreeObject extends HashMap<String, DataTreeChildObject> {
*
*/
public void removeUnmatchedPaths() {
- for (DataTreeChildObject entry : this.values()) {
- entry.removeUnmatchedPaths();
+ List<String> toRemove = new ArrayList<>();
+ for (Entry<String,DataTreeChildObject> entry : this.entrySet()) {
+ entry.getValue().removeUnmatchedPaths();
+ if(!entry.getValue().isMatch() && !entry.getValue().hasChildren()) {
+ toRemove.add(entry.getKey());
+ }
+ }
+ for(String toRemoveKey:toRemove) {
+ this.remove(toRemoveKey);
}
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java
new file mode 100644
index 000000000..09a81c381
--- /dev/null
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java
@@ -0,0 +1,175 @@
+/*
+ * ============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.http;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.json.JSONObject;
+import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPClient;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UserdataHttpServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+ private static final Logger LOG = LoggerFactory.getLogger(UserdataHttpServlet.class);
+ private static final String REGEX = "^\\/userdata[\\/]?([a-zA-Z0-9]+)?$";
+ private static final Pattern PATTERN = Pattern.compile(REGEX);
+ private static final String JWT_PAYLOAD_USERNAME_PROPERTYKEY = "sub";
+ private HtUserdataManager dbUserManager;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ final String uri = req.getRequestURI();
+ final Matcher matcher = PATTERN.matcher(uri);
+ if (matcher.find()) {
+ LOG.info("GET found match");
+ this.handleGetRequest(req, resp, matcher.groupCount() > 0 ? matcher.group(1) : null);
+ } else {
+ LOG.info("no valid request");
+ super.doGet(req, resp);
+ }
+ }
+
+ @Override
+ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ final String uri = req.getRequestURI();
+ final Matcher matcher = PATTERN.matcher(uri);
+ if (matcher.find()) {
+ LOG.info("PUT found match");
+ final String payload = getPayload(req);
+ this.handlePutRequest(req, resp, payload, matcher.groupCount() > 0 ? matcher.group(1) : null);
+ } else {
+ LOG.info("no valid request");
+ super.doPut(req, resp);
+ }
+ }
+
+ private String getPayload(HttpServletRequest req) throws IOException {
+ return DataTreeHttpServlet.readPayload(req);
+ }
+
+ @Override
+ protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ final String uri = req.getRequestURI();
+ final Matcher matcher = PATTERN.matcher(uri);
+ if (matcher.find()) {
+ LOG.info("DELETE found match");
+ this.handleDeleteRequest(req, resp, matcher.groupCount() > 0 ? matcher.group(1) : null);
+ } else {
+ LOG.info("no valid request");
+ super.doPut(req, resp);
+ }
+ }
+
+ private void handleGetRequest(HttpServletRequest req, HttpServletResponse resp, String key) {
+ final String username = this.getUsername(req);
+ if(username==null) {
+ resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ return;
+ }
+ sendJsonResponse(resp,
+ key == null ? this.dbUserManager.getUserdata(username) : this.dbUserManager.getUserdata(username, key));
+ }
+
+
+ private void handlePutRequest(HttpServletRequest req, HttpServletResponse resp, String data, String key) {
+ final String username = this.getUsername(req);
+ if(username==null) {
+ resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ return;
+ }
+ boolean success = key == null ? this.dbUserManager.setUserdata(username, data)
+ : this.dbUserManager.setUserdata(username, key, data);
+ resp.setStatus(success ? HttpServletResponse.SC_OK : HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ private void handleDeleteRequest(HttpServletRequest req, HttpServletResponse resp, String key) {
+ final String username = this.getUsername(req);
+ if(username==null) {
+ resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ return;
+ }
+ boolean success = key == null ? this.dbUserManager.removeUserdata(username)
+ : this.dbUserManager.removeUserdata(username, key);
+ resp.setStatus(success ? HttpServletResponse.SC_OK : HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ private String getUsername(HttpServletRequest req) {
+ final String authHeader = req.getHeader("Authorization");
+ if(authHeader==null) {
+ return null;
+ }
+ String username = null;
+ if(authHeader.startsWith("Basic")) {
+ username = BaseHTTPClient.decodeBasicAuthHeaderUsername(authHeader);
+ }
+ else if(authHeader.startsWith("Bearer")) {
+ username = decodeJWTPayloadUsername(authHeader, JWT_PAYLOAD_USERNAME_PROPERTYKEY);
+ }
+ return username;
+ }
+
+ public static String decodeJWTPayloadUsername(String authHeader, String key) {
+ String username = null;
+ if(authHeader.startsWith("Bearer")) {
+ authHeader = authHeader.substring(7);
+ }
+ String[] tmp = authHeader.split("\\.");
+ if(tmp.length==3) {
+ final String decoded = new String(Base64.getDecoder().decode(tmp[1]));
+ JSONObject o = new JSONObject(decoded);
+ if(o.has(key)) {
+ username = o.getString(key);
+ if(username!=null && username.contains("@")) {
+ username = username.split("@")[0];
+ }
+ }
+ }
+ return username;
+ }
+
+ private static void sendJsonResponse(HttpServletResponse resp, String userdata) {
+ resp.setContentType("application/json");
+ resp.setStatus(HttpServletResponse.SC_OK);
+ try {
+
+ resp.getOutputStream().write(userdata.getBytes(StandardCharsets.UTF_8));
+ } catch (IOException e) {
+ LOG.warn("problem sending response: ", e);
+ }
+
+ }
+
+ public void setDatabaseClient(HtUserdataManager dbUserManager) {
+ this.dbUserManager = dbUserManager;
+ }
+
+}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderImpl.java
index 5c1ea98b2..190c78904 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderImpl.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderImpl.java
@@ -26,9 +26,11 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClientException
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.ReadyHttpServlet;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEsConfig;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
@@ -48,6 +50,7 @@ public class DataProviderImpl implements IEntityDataProvider, AutoCloseable {
private DataProviderServiceImpl rpcApiService;
private AboutHttpServlet aboutServlet;
private DataTreeHttpServlet treeServlet;
+ private UserdataHttpServlet userdataServlet;
private HtDatabaseClient dbClient;
// Blueprint 1
@@ -71,7 +74,9 @@ public class DataProviderImpl implements IEntityDataProvider, AutoCloseable {
public void setTreeServlet(DataTreeHttpServlet treeServlet) {
this.treeServlet = treeServlet;
}
-
+ public void setUserdataServlet(UserdataHttpServlet userdataServlet) {
+ this.userdataServlet = userdataServlet;
+ }
public void init() throws Exception {
LOG.info("Session Initiated start {}", APPLICATION_NAME);
@@ -79,6 +84,7 @@ public class DataProviderImpl implements IEntityDataProvider, AutoCloseable {
// Start RPC Service
this.rpcApiService = new DataProviderServiceImpl(rpcProviderService, this.mediatorServerServlet);
this.treeServlet.setDatabaseClient(this.rpcApiService.getRawClient());
+ this.userdataServlet.setDatabaseClient(this.rpcApiService.getHtDatabaseUserManager());
LOG.info("Session Initiated end. Initialization done");
} catch (Exception e) {
if (e instanceof HtDatabaseClientException)
@@ -144,4 +150,9 @@ public class DataProviderImpl implements IEntityDataProvider, AutoCloseable {
}
}
+ @Override
+ public HtUserdataManager getHtDatabaseUserManager() {
+ return this.rpcApiService.getHtDatabaseUserManager();
+ }
+
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java
index 5ef7a0ad9..9e7fc18bc 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataProviderServiceImpl.java
@@ -30,10 +30,12 @@ import org.eclipse.jdt.annotation.NonNull;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtUserdataManagerImpl;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.MediatorServerDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtUserdataManager;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEsConfig;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput;
@@ -107,6 +109,7 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab
private final ConfigurationFileRepresentation configuration;
private final EsConfig esConfig;
private final MediatorServerDataProvider mediatorServerDataProvider;
+ private final HtUserdataManager dbUserManager;
DataProviderServiceImpl(final RpcProviderService rpcProviderService, MsServlet mediatorServerServlet)
throws Exception {
@@ -118,6 +121,7 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab
this.mediatorServerDataProvider = new MediatorServerDataProvider(esConfig.getHosts(),
esConfig.getBasicAuthUsername(), esConfig.getBasicAuthPassword(),esConfig.trustAllCerts());
mediatorServerServlet.setDataProvider(this.mediatorServerDataProvider);
+ this.dbUserManager = new HtUserdataManagerImpl(this.dataProvider.getRawClient());
// Register ourselves as the REST API RPC implementation
LOG.info("Register RPC Service " + DataProviderServiceImpl.class.getSimpleName());
this.rpcReg = rpcProviderService.registerRpcImplementation(DataProviderService.class, this);
@@ -412,4 +416,8 @@ public class DataProviderServiceImpl implements DataProviderService, AutoCloseab
return result;
}
+ public HtUserdataManager getHtDatabaseUserManager() {
+ return this.dbUserManager;
+ }
+
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java
index 4340d8168..e69ddb737 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/impl/DataTreeProviderImpl.java
@@ -36,7 +36,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.requests.SearchRequest;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.AggregationEntries;
import org.onap.ccsdk.features.sdnr.wt.common.database.responses.SearchResponse;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeChildObject;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.FilterMode;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
@@ -48,12 +47,12 @@ public class DataTreeProviderImpl {
private static final long MAXSIZE_PERSEARCH = 10;
private HtDatabaseClient dbClient;
- final String INVENTORY_PROPERTY_TREELEVEL = "tree-level";
- final String INVENTORY_PROPERTY_NODEID = "node-id";
- final String INVENTORY_PROPERTY_UUID = "uuid";
- final String INVENTORY_PROPERTY_PARENTUUID = "parent-uuid";
- final String INVENTORY_PROPERTY_FOR_LABEL_CHILD = "uuid";
- final String INVENTORY_PROPERTY_FOR_LABEL = "uuid";
+ private static final String INVENTORY_PROPERTY_TREELEVEL = "tree-level";
+ private static final String INVENTORY_PROPERTY_NODEID = "node-id";
+ private static final String INVENTORY_PROPERTY_UUID = "uuid";
+ private static final String INVENTORY_PROPERTY_PARENTUUID = "parent-uuid";
+ private static final String INVENTORY_PROPERTY_FOR_LABEL_CHILD = "uuid";
+ private static final String INVENTORY_PROPERTY_FOR_LABEL = "uuid";
private List<SearchHit> search(Entity e, String filter, String propTreeLevel) throws IOException {
return this.search(e, filter, null, null, null, null, null, null, propTreeLevel);
@@ -132,15 +131,15 @@ public class DataTreeProviderImpl {
* @return
* @throws IOException
*/
- public DataTreeObject readInventoryTree(List<String> tree, String filter, FilterMode mode) throws IOException {
+ public DataTreeObject readInventoryTree(List<String> tree, String filter) throws IOException {
//root nodes will be node-information -> below inventory
if (tree == null || tree.size() <= 0) {
- return this.readInventoryTreeWithNode(filter, mode);
+ return this.readInventoryTreeWithNode(filter);
}
//root node will be inventory on tree-level if sliced treePath
else {
- return this.readInventoryTreeForNode(tree.get(0), tree.subList(0, tree.size() - 1), filter, mode);
+ return this.readInventoryTreeForNode(tree.get(0), tree.subList(0, tree.size() - 1), filter);
}
}
@@ -152,7 +151,7 @@ public class DataTreeProviderImpl {
* @param mode
* @return
*/
- private DataTreeObject readInventoryTreeForNode(String nodeId, List<String> list, String filter, FilterMode mode)
+ private DataTreeObject readInventoryTreeForNode(String nodeId, List<String> list, String filter)
throws IOException {
DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID);
final String parentUuid = list.size() > 1 ? list.get(list.size() - 2) : null;
@@ -161,7 +160,8 @@ public class DataTreeProviderImpl {
INVENTORY_PROPERTY_PARENTUUID, parentUuid, INVENTORY_PROPERTY_UUID, uuid, INVENTORY_PROPERTY_TREELEVEL);
//tree.a(subtreePath);
- List<SearchHit> others = this.search(Entity.Inventoryequipment, (String) null, INVENTORY_PROPERTY_TREELEVEL);
+ List<SearchHit> others = this.search(Entity.Inventoryequipment, (String) null, INVENTORY_PROPERTY_NODEID, nodeId,
+ null, null, null, null, INVENTORY_PROPERTY_TREELEVEL);
if (matches.size() > 0) {
int treeLevelToStart = (list == null || list.size() <= 0) ? 0 : list.size() - 1;
//build tree
@@ -208,6 +208,7 @@ public class DataTreeProviderImpl {
hitData.getString(INVENTORY_PROPERTY_PARENTUUID)));
}
}
+ tree.removeUnmatchedPaths();
}
return tree;
}
@@ -216,11 +217,10 @@ public class DataTreeProviderImpl {
* node will be root elements inventory information below from level-1
*
* @param filter
- * @param mode
* @return
* @throws IOException
*/
- private DataTreeObject readInventoryTreeWithNode(String filter, FilterMode mode) throws IOException {
+ private DataTreeObject readInventoryTreeWithNode(String filter) throws IOException {
DataTreeObject tree = new DataTreeObject(INVENTORY_PROPERTY_PARENTUUID, INVENTORY_PROPERTY_UUID);
List<SearchHit> matches = this.search(Entity.Inventoryequipment, filter, INVENTORY_PROPERTY_TREELEVEL);
@@ -302,9 +302,8 @@ public class DataTreeProviderImpl {
}
}
}
- if (mode == FilterMode.Strict) {
- tree.removeUnmatchedPaths();
- }
+ tree.removeUnmatchedPaths();
+
}
return tree;
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/DataProviderYangToolsMapper.java
index e7580c69a..78b032e77 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/DataProviderYangToolsMapper.java
@@ -21,13 +21,11 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.MapperFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.mapperextensions.YangToolsBuilderAnnotationIntrospector;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.mapperextensions.YangToolsModule;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.serialize.IdentifierDeserializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,25 +34,17 @@ import org.slf4j.LoggerFactory;
* deserialization of DataObject to/from JSON TODO ChoiceIn and Credentials deserialization only for
* LoginPasswordBuilder
*/
-public class YangToolsMapper extends ObjectMapper {
+public class DataProviderYangToolsMapper extends YangToolsMapper {
@SuppressWarnings("unused")
- private final Logger LOG = LoggerFactory.getLogger(YangToolsMapper.class);
+ private final Logger LOG = LoggerFactory.getLogger(DataProviderYangToolsMapper.class);
private static final long serialVersionUID = 1L;
- public YangToolsMapper() {
- this(new YangToolsBuilderAnnotationIntrospector());
- }
-
- protected YangToolsMapper(YangToolsBuilderAnnotationIntrospector yangToolsBuilderAnnotationIntrospector) {
+ public DataProviderYangToolsMapper() {
super();
-
- configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE);
- setSerializationInclusion(Include.NON_NULL);
- enable(MapperFeature.USE_GETTERS_AS_SETTERS);
- setAnnotationIntrospector(yangToolsBuilderAnnotationIntrospector);
- registerModule(new YangToolsModule());
+ this.addDeserializer(Credentials.class, LoginPasswordBuilder.class.getName());
+ this.addKeyDeserializer(MeasurementKey.class, new IdentifierDeserializer());
}
+
}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper2.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper2.java
deleted file mode 100644
index a19f114e3..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapper2.java
+++ /dev/null
@@ -1,97 +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.yangtools;
-
-import java.lang.reflect.InvocationTargetException;
-import javax.annotation.Nullable;
-import org.eclipse.jdt.annotation.NonNull;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.mapperextensions.YangToolsBuilderAnnotationIntrospector;
-import org.opendaylight.yangtools.concepts.Builder;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * YangToolsMapper is a specific Jackson mapper configuration for opendaylight yangtools serialization or
- * deserialization of DataObject to/from JSON TODO ChoiceIn and Credentials deserialization only for
- * LoginPasswordBuilder
- */
-public class YangToolsMapper2<T extends DataObject> extends YangToolsMapper {
-
- private static final Logger LOG = LoggerFactory.getLogger(YangToolsMapper2.class);
- private static final long serialVersionUID = 1L;
-
- private @Nullable final Class<? extends Builder<? extends T>> builderClazz;
-
- /**
- * Generic Object creation of yangtools java class builder pattern.
- *
- * @param <X> Class of DataObject
- * @param <B> Builder for the class.
- * @param clazz specifies class to be mapped
- * @param builderClazz is the builder for class with name pattern "clazzBuilder".<br>
- * If null the clazz is expected to support normal jackson build pattern.
- * @throws ClassNotFoundException if builderClazz not available in bundle
- */
- public <X extends T, B extends Builder<X>> YangToolsMapper2(@NonNull Class<T> clazz,
- @Nullable Class<B> builderClazz) throws ClassNotFoundException {
- super(new YangToolsBuilderAnnotationIntrospector(clazz, builderClazz));
-
- this.builderClazz =
- builderClazz != null ? builderClazz : getBuilderClass(YangToolsMapperHelper.getBuilderClassName(clazz));
- }
-
- /**
- * Get Builder object for yang tools interface.
- *
- * @param <T> yang-tools base datatype
- * @param clazz class with interface.
- * @return builder for interface or null if not existing
- */
- public @Nullable Builder<? extends T> getBuilder(Class<T> clazz) {
- try {
- if (builderClazz != null)
- return builderClazz.getDeclaredConstructor().newInstance();
- else
- return null;
- } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | NoSuchMethodException | SecurityException e) {
- LOG.warn("Problem intantiating Builder", e);
- return null;
- }
- }
-
- // --- Private functions
-
- /**
- * Search builder in context
- *
- * @param name
- * @return
- * @throws ClassNotFoundException
- */
- @SuppressWarnings("unchecked")
- private <X extends T, B extends Builder<X>> Class<B> getBuilderClass(String name) throws ClassNotFoundException {
- return (Class<B>) YangToolsMapperHelper.getBuilderClass(name);
- }
-
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapperHelper.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapperHelper.java
deleted file mode 100644
index a2afab0a8..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/YangToolsMapperHelper.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * ============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.yangtools;
-
-import com.fasterxml.jackson.databind.DeserializationContext;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-import javax.annotation.Nullable;
-import org.opendaylight.yangtools.concepts.Builder;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class YangToolsMapperHelper {
-
- private static final Logger LOG = LoggerFactory.getLogger(YangToolsMapperHelper.class);
- private static final String TYPEOBJECT_INSTANCE_METHOD = "getDefaultInstance";
- private static final String BUILDER = "Builder";
-
- private static BundleContext context = getBundleContext();
- private static ConcurrentHashMap<String, Class<?>> cache = new ConcurrentHashMap<>();
-
- private YangToolsMapperHelper() {
- //Make unaccessible
- }
-
- public static Class<?> findClass(String name) throws ClassNotFoundException {
-
- //Try first in cache
- Class<?> res = cache.get(name);
- if (res != null) {
- return res;
- }
- //Try first in actual bundle
- try {
- return loadClass(null, name);
- } catch (ClassNotFoundException e) {
- // No problem, this bundle doesn't have the class
- }
- // Try to find in other bundles
- if (context != null) {
- //OSGi environment
- for (Bundle b : context.getBundles()) {
- try {
- return loadClass(b, name);
- } catch (ClassNotFoundException e) {
- // No problem, this bundle doesn't have the class
- }
- }
- }
- // really not found in any bundle
- throw new ClassNotFoundException("Can not find class '"+name+"'");
- }
-
- private static Class<?> loadClass(Bundle b, String name) throws ClassNotFoundException {
- Class<?> res = b == null ? Class.forName(name) : b.loadClass(name);
- cache.put(name, res);
- return res;
- }
-
- /**
- * Verify if builder is available
- *
- * @throws ClassNotFoundException
- **/
- public static Class<?> assertBuilderClass(Class<?> clazz) throws ClassNotFoundException {
- return getBuilderClass(getBuilderClassName(clazz));
- }
-
- public static Class<?> getBuilderClass(String name) throws ClassNotFoundException {
- return findClass(name);
- }
-
- public static Class<?> getBuilderClass(Class<?> clazz) throws ClassNotFoundException {
- return findClass(getBuilderClassName(clazz));
- }
-
- /**
- * Create name of builder class
- *
- * @param <T>
- * @param clazz
- * @return builders class name
- * @throws ClassNotFoundException
- */
- public static String getBuilderClassName(Class<?> clazz) {
- return clazz.getName() + BUILDER;
- }
-
- @SuppressWarnings("unchecked")
- public static <B extends Builder<?>> Class<B> findBuilderClass(DeserializationContext ctxt, Class<?> clazz) throws ClassNotFoundException {
- return (Class<B>) findClass(getBuilderClassName(clazz));
- }
-
- public static <B extends Builder<?>> Optional<Class<B>> findBuilderClassOptional(DeserializationContext ctxt, Class<?> clazz) {
- try {
- return Optional.of(findBuilderClass(ctxt, clazz));
- } catch (ClassNotFoundException e) {
- return Optional.empty();
- }
- }
-
- public static boolean hasClassDeclaredMethod(Class<?> clazz, String name) {
- Method[] methods = clazz.getDeclaredMethods();
- for (Method m : methods) {
- if (m.getName().equals(name)) {
- return true;
- }
- }
- return false;
- }
-
- @SuppressWarnings("unchecked")
- public static <T> Optional<T> getInstanceByConstructor(Class<?> clazz, String arg) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
- List<Class<?>> ctypes = getConstructorParameterTypes(clazz, String.class);
- Optional<Object> oObj;
- for (Class<?> ctype : ctypes) {
- if (ctype.equals(String.class)) {
- return Optional.of((T) clazz.getConstructor(ctype).newInstance(arg));
- } else if ((oObj = getDefaultInstance(ctype, arg)).isPresent()) {
- return Optional.of((T) clazz.getConstructor(ctype).newInstance(oObj.get()));
- } else {
- // TODO: recursive instantiation down to string constructor or
- // getDefaultInstance method
- LOG.debug("Not implemented arg:'{}' class:'{}'", arg, clazz);
- }
- }
- return Optional.empty();
- }
-
- @SuppressWarnings("unchecked")
- public static <T> Optional<T> getDefaultInstance(@Nullable Class<?> clazz, String arg)
- throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
- InvocationTargetException {
- LOG.trace("arg:'{}' clazz '{}'", arg, clazz.getName());
- if (clazz != null) {
- Method[] methods = clazz.getDeclaredMethods();
- for (Method m : methods) {
- //TODO Verify argument type to avoid exception
- if (m.getName().equals(TYPEOBJECT_INSTANCE_METHOD)) {
- Method method = clazz.getDeclaredMethod(TYPEOBJECT_INSTANCE_METHOD, String.class);
- LOG.trace("Invoke {} available {}",TYPEOBJECT_INSTANCE_METHOD, method != null);
- return Optional.of((T) method.invoke(null, arg));
- }
- }
- }
- return Optional.empty();
- }
-
- public static <T> Optional<T> getDefaultInstance(Optional<Class<T>> optionalClazz, String arg)
- throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
- InvocationTargetException {
- if (optionalClazz.isPresent()) {
- return getDefaultInstance(optionalClazz.get(), arg);
- }
- return Optional.empty();
- }
-
- public static List<Class<?>> getConstructorParameterTypes(Class<?> clazz, Class<?> prefer) {
-
- Constructor<?>[] constructors = clazz.getConstructors();
- List<Class<?>> res = new ArrayList<>();
- for (Constructor<?> c : constructors) {
- Class<?>[] ptypes = c.getParameterTypes();
- if (ptypes.length == 1) {
- res.add(ptypes[0]);
- }
-
- if (prefer != null && ptypes.length == 1 && ptypes[0].equals(prefer)) {
- return Arrays.asList(prefer);
- }
- }
- return res;
- }
-
- public static boolean implementsInterface(Class<?> clz, Class<?> ifToImplement) {
- Class<?>[] ifs = clz.getInterfaces();
- for (Class<?> iff : ifs) {
- if (iff.equals(ifToImplement)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Provide mapping of string to attribute names, generated by yang-tools. "netconf-id" converted to "_netconfId"
- *
- * @param name with attribute name, not null or empty
- * @return converted string or null if name was empty or null
- */
- public @Nullable static String toCamelCaseAttributeName(final String name) {
- if (name == null || name.isEmpty())
- return null;
-
- final StringBuilder ret = new StringBuilder(name.length());
- if (!name.startsWith("_"))
- ret.append('_');
- int start = 0;
- for (final String word : name.split("-")) {
- if (!word.isEmpty()) {
- if (start++ == 0) {
- ret.append(Character.toLowerCase(word.charAt(0)));
- } else {
- ret.append(Character.toUpperCase(word.charAt(0)));
- }
- ret.append(word.substring(1));
- }
- }
- return ret.toString();
- }
-
- private static BundleContext getBundleContext() {
- Bundle bundle = FrameworkUtil.getBundle(YangToolsMapperHelper.class);
- return bundle != null ? bundle.getBundleContext() : null;
- }
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/builder/DateAndTimeBuilder.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/builder/DateAndTimeBuilder.java
deleted file mode 100644
index 8dbaf4ab9..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/builder/DateAndTimeBuilder.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * ============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.yangtools.builder;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
-
-public class DateAndTimeBuilder {
- private final String _value;
-
- public DateAndTimeBuilder(String v) {
- this._value = v;
- }
-
- public DateAndTime build() {
- return new DateAndTime(_value);
- }
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsBuilderAnnotationIntrospector.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsBuilderAnnotationIntrospector.java
deleted file mode 100644
index eb611c602..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsBuilderAnnotationIntrospector.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * ============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.yangtools.mapperextensions;
-
-import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
-import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder.Value;
-import com.fasterxml.jackson.databind.cfg.MapperConfig;
-import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
-import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
-import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
-import java.math.BigInteger;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.builder.DateAndTimeBuilder;
-//import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.builders.rev201110.read.network.element.connection.list.output.DataBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
-import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.common.Uint64;
-import org.opendaylight.yangtools.yang.common.Uint8;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class YangToolsBuilderAnnotationIntrospector extends JacksonAnnotationIntrospector {
-
- private static final Logger LOG = LoggerFactory.getLogger(YangToolsBuilderAnnotationIntrospector.class);
- private static final long serialVersionUID = 1L;
-
- private final Map<Class<?>, String> customDeserializer;
-
- public YangToolsBuilderAnnotationIntrospector() {
- this(null, null);
- }
-
- public YangToolsBuilderAnnotationIntrospector(Class<?> cls, Class<?> builderClass) {
- this.customDeserializer = new HashMap<>();
- if (cls != null && builderClass != null) {
- this.customDeserializer.put(cls, builderClass.getName());
- }
- this.customDeserializer.put(DateAndTime.class, DateAndTimeBuilder.class.getName());
- this.customDeserializer.put(Credentials.class, LoginPasswordBuilder.class.getName());
- }
-
- @Override
- public Class<?> findPOJOBuilder(AnnotatedClass ac) {
- try {
- String builder = null;
- if (this.customDeserializer.containsKey(ac.getRawType())) {
- builder = this.customDeserializer.get(ac.getRawType());
- } else {
- if (ac.getRawType().isInterface()) {
- builder = ac.getName() + "Builder";
- }
- }
- if (builder != null) {
- LOG.trace("map {} with builder {}", ac.getName(), builder);
- Class<?> innerBuilder = YangToolsMapperHelper.findClass(builder);
- return innerBuilder;
- }
- } catch (ClassNotFoundException e) {
- LOG.trace("builder class not found for {}", ac.getName());
- }
- return super.findPOJOBuilder(ac);
- }
-
- @Override
- public Value findPOJOBuilderConfig(AnnotatedClass ac) {
- if (ac.hasAnnotation(JsonPOJOBuilder.class)) {
- return super.findPOJOBuilderConfig(ac);
- }
- return new JsonPOJOBuilder.Value("build", "set");
- }
-
- @Override
- public AnnotatedMethod resolveSetterConflict(MapperConfig<?> config, AnnotatedMethod setter1,
- AnnotatedMethod setter2) {
- Class<?> p1 = setter1.getRawParameterType(0);
- Class<?> p2 = setter2.getRawParameterType(0);
- AnnotatedMethod res = null;
-
- if (this.isAssignable(p1, p2, Map.class, List.class)) {
- res = p1.isAssignableFrom(List.class) ? setter1 : setter2; //prefer List setter
- } else if (this.isAssignable(p1, p2, Uint64.class, BigInteger.class)) {
- res = setter1;
- } else if (this.isAssignable(p1, p2, Uint32.class, Long.class)) {
- res = setter1;
- } else if (this.isAssignable(p1, p2, Uint16.class, Integer.class)) {
- res = setter1;
- } else if (this.isAssignable(p1, p2, Uint8.class, Short.class)) {
- res = setter1;
- }
- if (res == null) {
- res = super.resolveSetterConflict(config, setter1, setter2);
- }
- LOG.debug("{} (m1={} <=> m2={} => result:{})", setter1.getName(), p1.getSimpleName(), p2.getSimpleName(),
- res.getRawParameterType(0).getSimpleName());
-
- return res;
- }
-
- private boolean isAssignable(Class<?> p1, Class<?> p2, Class<?> c1, Class<?> c2) {
- return ((p1.isAssignableFrom(c1) && p2.isAssignableFrom(c2))
- || (p2.isAssignableFrom(c1) && p1.isAssignableFrom(c2)));
-
- }
-
- public void addDeserializer(Class<?> clazz, String builder) {
- this.customDeserializer.put(clazz, builder);
- }
-
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsDeserializerModifier.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsDeserializerModifier.java
deleted file mode 100644
index 634a3bc5b..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsDeserializerModifier.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * ============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.yangtools.mapperextensions;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.BeanDescription;
-import com.fasterxml.jackson.databind.DeserializationConfig;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import com.fasterxml.jackson.databind.KeyDeserializer;
-import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.NoSuchElementException;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.ScalarTypeObject;
-//import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.ScalarTypeObject;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize.BaseIdentityDeserializer;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize.ClassDeserializer;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize.IdentifierDeserializer;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize.TypeObjectDeserializer;
-import org.opendaylight.yangtools.yang.binding.BaseIdentity;
-import org.opendaylight.yangtools.yang.binding.Identifier;
-import org.opendaylight.yangtools.yang.binding.TypeObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class YangToolsDeserializerModifier extends BeanDeserializerModifier {
-
- private static final Logger LOG = LoggerFactory.getLogger(YangToolsDeserializerModifier.class);
- private static final String getEnumMethodName="valueOf";
-
- @Override
- public JsonDeserializer<Enum<?>> modifyEnumDeserializer(DeserializationConfig config, final JavaType type,
- BeanDescription beanDesc, final JsonDeserializer<?> deserializer) {
- return new JsonDeserializer<Enum<?>>() {
-
- @Override
- public Enum<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
- Class<?> clazz = type.getRawClass();
-
- try {
- Method method = clazz.getDeclaredMethod(getEnumMethodName, String.class);
- Enum<?> result = (Enum<?>) method.invoke(null, jp.getValueAsString());
- LOG.debug("Deserialize '{}' with class '{}' to '{}'", jp.getValueAsString(), clazz.getName(), result);
- return result;
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | NoSuchMethodException | NoSuchElementException | SecurityException e) {
- LOG.warn("problem deserializing enum for {} with value {}: {}", clazz.getName(),
- jp.getValueAsString(), e);
- }
- throw new IOException(
- "unable to parse enum (" + type.getRawClass() + ")for value " + jp.getValueAsString());
- }
- };
- }
-
- @Override
- public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc,
- JsonDeserializer<?> deserializer) {
- final JavaType type = beanDesc.getType();
- final Class<?> rawClass = type.getRawClass();
-
- JsonDeserializer<?> deser = super.modifyDeserializer(config, beanDesc, deserializer);
-
- if (YangToolsMapperHelper.implementsInterface(rawClass, TypeObject.class)) {
- deser = new TypeObjectDeserializer<TypeObject>(type, deser);
- } else if (YangToolsMapperHelper.implementsInterface(rawClass, YangHelper2.getScalarTypeObjectClass())) {
- deser = new TypeObjectDeserializer<ScalarTypeObject>(type, deser);
- } else if (YangToolsMapperHelper.implementsInterface(rawClass, BaseIdentity.class)) {
- deser = new BaseIdentityDeserializer<BaseIdentity>(deser);
- } else if (rawClass.equals(Class.class)) {
- deser = new ClassDeserializer(rawClass);
- }
-
- LOG.debug("Deserialize '{}' with deserializer '{}'", rawClass.getName(), deser.getClass().getName());
- return deser;
- }
-
- @Override
- public KeyDeserializer modifyKeyDeserializer(DeserializationConfig config, JavaType type, KeyDeserializer deser) {
- KeyDeserializer res;
- if (YangToolsMapperHelper.implementsInterface(type.getRawClass(), Identifier.class)) {
- res = new IdentifierDeserializer();
- } else {
- res = super.modifyKeyDeserializer(config, type, deser);
- }
- LOG.debug("Keydeserialize '{}' with deserializer '{}'", type.getRawClass().getName(), res.getClass().getName());
- return res;
- }
-
- void test() {
- com.fasterxml.jackson.databind.util.ClassUtil xy;
- }
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsModule.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsModule.java
deleted file mode 100644
index 46f69d4f9..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/mapperextensions/YangToolsModule.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * ============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.yangtools.mapperextensions;
-
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import java.util.Map;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize.DateAndTimeSerializer;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize.EnumSerializer;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize.IdentifierDeserializer;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize.MapSerializer;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.serialize.TypeObjectSerializer;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.pmdata.grp.MeasurementKey;
-import org.opendaylight.yangtools.yang.binding.TypeObject;
-
-public class YangToolsModule extends SimpleModule {
-
- private static final long serialVersionUID = 1L;
-
- public YangToolsModule() {
- super();
- setDeserializerModifier(new YangToolsDeserializerModifier());
-
- addKeyDeserializer(MeasurementKey.class, new IdentifierDeserializer());
- addSerializer(DateAndTime.class, new DateAndTimeSerializer());
- addSerializer(TypeObject.class, new TypeObjectSerializer());
- addSerializer(Enum.class, new EnumSerializer());
- addSerializer(Map.class, new MapSerializer());
- }
-
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/BaseIdentityDeserializer.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/BaseIdentityDeserializer.java
deleted file mode 100644
index 10f18e796..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/BaseIdentityDeserializer.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * ============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.yangtools.serialize;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import java.io.IOException;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class BaseIdentityDeserializer<T> extends JsonDeserializer<T> {
-
- private static final Logger LOG = LoggerFactory.getLogger(BaseIdentityDeserializer.class);
- private final JsonDeserializer<?> deser;
-
- public BaseIdentityDeserializer(final JsonDeserializer<?> deser) {
- this.deser = deser;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
- LOG.debug("BaseIdentityDeserializer class for '{}'",parser.getValueAsString());
- String clazzToSearch = parser.getValueAsString();
- // clazz from Elasticsearch is full qualified
- int lastDot = clazzToSearch.lastIndexOf(".");
- if (lastDot > -1) {
- clazzToSearch = clazzToSearch.substring(lastDot+1);
- } else {
- clazzToSearch = clazzToSearch.substring(0, 1).toUpperCase() + clazzToSearch.substring(1);
- }
- Class<?> clazz;
- try {
- clazz = YangToolsMapperHelper.findClass(clazzToSearch);
- if (clazz != null)
- return (T)clazz;
- } catch (ClassNotFoundException e) {
- LOG.warn("BaseIdentityDeserializer class not found for '"+parser.getValueAsString()+"'",e);
- }
- return (T) deser.deserialize(parser, ctxt);
- }
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/ClassDeserializer.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/ClassDeserializer.java
deleted file mode 100644
index 2627c2ae0..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/ClassDeserializer.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ============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.yangtools.serialize;
-
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer;
-import java.io.IOException;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper;
-
-public class ClassDeserializer extends FromStringDeserializer<Class<?>> {
-
- private static final long serialVersionUID = 1L;
-
- public ClassDeserializer(Class<?> vc) {
- super(vc);
- }
-
- @Override
- protected Class<?> _deserialize(String value, DeserializationContext ctxt) throws IOException {
- try {
- return YangToolsMapperHelper.findClass(value);
- } catch (ClassNotFoundException e) {
- throw new IOException("Can not find class "+value,e);
- }
- }
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/DateAndTimeSerializer.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/DateAndTimeSerializer.java
deleted file mode 100644
index a35aad75a..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/DateAndTimeSerializer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * ============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.yangtools.serialize;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import com.fasterxml.jackson.databind.ser.std.StdSerializer;
-import java.io.IOException;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
-
-/**
- * DateAndTime shouldn't be encapsulated into a json object to be able to use elasticsearch date time query functions.
- */
-public class DateAndTimeSerializer extends StdSerializer<@NonNull DateAndTime> {
-
- private static final long serialVersionUID = 1L;
-
- public DateAndTimeSerializer() {
- this(null);
- }
-
- protected DateAndTimeSerializer(Class<DateAndTime> t) {
- super(t);
- }
-
- @Override
- public void serialize(DateAndTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
- gen.writeString(value.getValue());
- }
-
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/IdentifierDeserializer.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/IdentifierDeserializer.java
deleted file mode 100644
index 0837b8a19..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/IdentifierDeserializer.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * ============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.yangtools.serialize;
-
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.KeyDeserializer;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper;
-import org.opendaylight.yangtools.yang.common.Uint16;
-import org.opendaylight.yangtools.yang.common.Uint32;
-import org.opendaylight.yangtools.yang.common.Uint64;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class IdentifierDeserializer extends KeyDeserializer {
-
- private static final Logger LOG = LoggerFactory.getLogger(IdentifierDeserializer.class);
-
- public IdentifierDeserializer() {}
-
- @Override
- public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException {
- Class<?> clazz = ctxt.getClass();
- final String arg = key;
- LOG.debug("Deserialization for key:{}",key);
- // find constructor argument types
- List<Class<?>> ctypes = YangToolsMapperHelper.getConstructorParameterTypes(clazz, String.class);
- for (Class<?> ctype : ctypes) {
- try {
- if (ctype.equals(String.class)) {
- return clazz.getConstructor(ctype).newInstance(arg);
- } else if (ctype.equals(Uint16.class)) {
- return clazz.getConstructor(ctype).newInstance(Uint16.valueOf(arg));
-
- } else if (ctype.equals(Uint32.class)) {
- return clazz.getConstructor(ctype).newInstance(Uint32.valueOf(arg));
- } else if (ctype.equals(Uint64.class)) {
- return clazz.getConstructor(ctype).newInstance(Uint64.valueOf(arg));
- }
- } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
- | InvocationTargetException | NoSuchMethodException | SecurityException e) {
- LOG.warn("unable to instantiate class {} with arg {}: ", clazz, arg, e);
- throw new IllegalArgumentException(
- "unable to instantiate class " + clazz.getName() + " with arg '" + arg + "' ", e);
- }
- }
- return null;
- }
-
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/MapSerializer.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/MapSerializer.java
deleted file mode 100644
index e5c966a74..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/MapSerializer.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * ============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.yangtools.serialize;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import java.io.IOException;
-import java.util.Map;
-
-@SuppressWarnings("rawtypes")
-public class MapSerializer extends JsonSerializer<Map> {
-
- @Override
- public void serialize(Map value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
- gen.writeObject(value.values());
- }
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/TypeObjectDeserializer.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/TypeObjectDeserializer.java
deleted file mode 100644
index 5beca0d47..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/TypeObjectDeserializer.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * ============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.yangtools.serialize;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.NoSuchElementException;
-import java.util.Optional;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper;
-import org.opendaylight.yangtools.concepts.Builder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TypeObjectDeserializer<T> extends JsonDeserializer<T> {
-
- private static final Logger LOG = LoggerFactory.getLogger(TypeObjectDeserializer.class);
- private final JavaType type;
- private final JsonDeserializer<?> deser;
-
-
- public TypeObjectDeserializer(final JavaType type, final JsonDeserializer<?> deser) {
- this.type = type;
- this.deser = deser;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
-
- Class<T> clazz = (Class<T>) type.getRawClass();
- final String arg = parser.getValueAsString();
- LOG.debug("Try to build arg:'{}' with class {}",arg, clazz);
- Optional<T> oRes = Optional.empty();
- try {
- //try get method for default instance
- if ((oRes = YangToolsMapperHelper.getDefaultInstance(clazz, arg)).isEmpty()) {
- //try to find builder with getDefaultInstance method
- Optional<Class<Builder<?>>> oBuilderClazz = YangToolsMapperHelper.findBuilderClassOptional(ctxt, clazz);
- LOG.debug("Try builder class present:{}",oBuilderClazz.isPresent());
- if (oBuilderClazz.isEmpty()
- || ((oRes = YangToolsMapperHelper.getDefaultInstance(oBuilderClazz.get(), arg)).isEmpty())) {
- //try to find constructor with string
- LOG.debug("Try constructor");
- if ((oRes = YangToolsMapperHelper.getInstanceByConstructor(clazz, arg)).isEmpty()) {
- //forward to standard deserializer or throw if not available
- LOG.debug("Try default deserializer");
- oRes = Optional.of((T) deser.deserialize(parser, ctxt));
- }
- }
- }
- LOG.debug("Deserialize string value:{} for class:{} success:{}", arg, clazz, oRes.isPresent());
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
- | NoSuchElementException | SecurityException | InstantiationException e) {
- LOG.warn("problem deserializing {} with value {}: {}", clazz.getName(), arg, e);
- }
- if (oRes.isPresent()) {
- return oRes.get();
- } else {
- throw new IllegalArgumentException("Could not find constructor for arg:'" + arg + "' and class: " + clazz);
- }
- }
-
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/TypeObjectSerializer.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/TypeObjectSerializer.java
deleted file mode 100644
index 1269d0746..000000000
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/yangtools/serialize/TypeObjectSerializer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * ============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.yangtools.serialize;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.databind.JsonSerializer;
-import com.fasterxml.jackson.databind.SerializerProvider;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import org.opendaylight.yangtools.yang.binding.TypeObject;
-
-public class TypeObjectSerializer extends JsonSerializer<TypeObject> {
-
- @Override
- public void serialize(TypeObject value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
- //stringValue
- Method[] methods = value.getClass().getDeclaredMethods();
- String name;
- for (Method method : methods) {
- name = method.getName();
- if (name.equals("stringValue") || name.equals("getValue")) {
- try {
- gen.writeString((String)method.invoke(value));
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | IOException e) {
- throw new IOException("No String getter method supported TypeObject for "+value.getClass(),e);
- }
- }
- }
- }
-}
diff --git a/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
index ebb20fc7b..686af61d6 100644
--- a/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
+++ b/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
@@ -70,6 +70,15 @@
</service-properties>
</service>
+ <bean id="userdataServlet"
+ class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet">
+ </bean>
+ <service interface="javax.servlet.http.HttpServlet" ref="userdataServlet">
+ <service-properties>
+ <entry key="alias" value="/userdata"/>
+ </service-properties>
+ </service>
+
<bean id="provider"
class="org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderImpl"
init-method="init" destroy-method="close">
@@ -77,6 +86,7 @@
<property name="aboutServlet" ref="aboutServlet"/>
<property name="treeServlet" ref="treeServlet"/>
<property name="mediatorServerServlet" ref="msServlet"/>
+ <property name="userdataServlet" ref="userdataServlet"/>
</bean>
<bean id="yangServlet"
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java
index b7a4db51b..5a8c549d8 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java
@@ -40,9 +40,11 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
import org.onap.ccsdk.features.sdnr.wt.common.database.requests.BaseRequest;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtUserdataManagerImpl;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInputBuilder;
@@ -227,7 +229,8 @@ public class TestCRUDforDatabase {
// ==READ===========================
System.out.println("try to read entry");
ReadMediatorServerListInput readinput = new ReadMediatorServerListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class,new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
.setPagination(getPagination(20, 1)).build();
ReadMediatorServerListOutputBuilder readoutput = dbProvider.readMediatorServerList(readinput);
List<Data> data = readoutput.getData();
@@ -254,7 +257,8 @@ public class TestCRUDforDatabase {
// ==READ============================
System.out.println("try to read entry");
readinput = new ReadMediatorServerListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build()))
.setPagination(getPagination(20, 1)).build();
readoutput = dbProvider.readMediatorServerList(readinput);
data = readoutput.getData();
@@ -277,7 +281,8 @@ public class TestCRUDforDatabase {
// ==READ/VERIFY DELETE============================
System.out.println("try to read entry");
readinput = new ReadMediatorServerListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build()))
.setPagination(getPagination(20, 1)).build();
readoutput = dbProvider.readMediatorServerList(readinput);
data = readoutput.getData();
@@ -322,7 +327,8 @@ public class TestCRUDforDatabase {
// ==READ===========================
ReadNetworkElementConnectionListInput readInput = new ReadNetworkElementConnectionListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
.setPagination(getPagination(20, 1)).build();
ReadNetworkElementConnectionListOutputBuilder readOperation =
@@ -393,7 +399,8 @@ public class TestCRUDforDatabase {
}
readInput = new ReadNetworkElementConnectionListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
.setPagination(getPagination(20, 1)).build();
readOperation = dbProvider.readNetworkElementConnectionList(readInput);
data = readOperation.getData();
@@ -437,7 +444,8 @@ public class TestCRUDforDatabase {
System.out.println("Try read...");
ReadMaintenanceListInput readinput = new ReadMaintenanceListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
.setPagination(getPagination(20, 1)).build();
ReadMaintenanceListOutputBuilder readResult = dbProvider.readMaintenanceList(readinput);
List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> data =
@@ -502,7 +510,8 @@ public class TestCRUDforDatabase {
System.out.println("try to read entry");
ReadFaultlogListInput readinput = new ReadFaultlogListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
.setPagination(getPagination(20, 1)).build();
ReadFaultlogListOutputBuilder readResult = null;
@@ -530,7 +539,8 @@ public class TestCRUDforDatabase {
System.out.println("try to search entry 1");
readinput = new ReadFaultlogListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-id").setFiltervalue("test").build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("node-id").setFiltervalue("test").build()))
.setPagination(getPagination(20, 1)).build();
//== VERIFY UPDATE ================================
@@ -545,7 +555,8 @@ public class TestCRUDforDatabase {
System.out.println("try to search entry 2");
readinput = new ReadFaultlogListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-id").setFiltervalue("test*").build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("node-id").setFiltervalue("test*").build()))
.setPagination(getPagination(20, 1)).build();
readResult = dbProvider.readFaultLogList(readinput);
@@ -589,7 +600,8 @@ public class TestCRUDforDatabase {
ReadFaultcurrentListInput readinput = new ReadFaultcurrentListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
.setPagination(getPagination(20, 1)).build();
ReadFaultcurrentListOutputBuilder readResult = null;
@@ -693,7 +705,8 @@ public class TestCRUDforDatabase {
System.out.println("Try read entry");
ReadConnectionlogListInput readinput = new ReadConnectionlogListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
.setPagination(getPagination(20, 1)).build();
ReadConnectionlogListOutputBuilder readResult = null;
@@ -722,7 +735,8 @@ public class TestCRUDforDatabase {
System.out.println("Try read updated entry");
readinput = new ReadConnectionlogListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("status").setFiltervalue("Connected").build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("status").setFiltervalue("Connected").build()))
.setPagination(getPagination(20, 1)).build();
try {
@@ -782,7 +796,8 @@ public class TestCRUDforDatabase {
// ==READ===========================
ReadEventlogListInput readinput = new ReadEventlogListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
.setPagination(getPagination(20, 1)).build();
ReadEventlogListOutputBuilder readResult = null;
try {
@@ -850,7 +865,8 @@ public class TestCRUDforDatabase {
// ==READ===========================
ReadInventoryListInput readinput = new ReadInventoryListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("id").setFiltervalue(dbId).build()))
.setPagination(getPagination(20, 1)).build();
ReadInventoryListOutputBuilder readResult = null;
try {
@@ -1015,7 +1031,8 @@ public class TestCRUDforDatabase {
System.out.println("read list entries...");
ReadPmdata15mListInput read = new ReadPmdata15mListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build()))
.setPagination(getPagination(20, 1)).build();
ReadPmdata15mListOutputBuilder readResult = null;
@@ -1035,7 +1052,8 @@ public class TestCRUDforDatabase {
System.out.println("read ltp entries with node name set...");
ReadPmdata15mLtpListInput readLtp = new ReadPmdata15mLtpListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build()))
.setPagination(getPagination(20, 1)).build();
ReadPmdata15mLtpListOutputBuilder readltpResult = null;
@@ -1133,7 +1151,8 @@ public class TestCRUDforDatabase {
System.out.println("filter list entries...");
read = new ReadPmdata24hListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build()))
.setPagination(getPagination(20, 1)).build();
readResult = null;
@@ -1152,7 +1171,8 @@ public class TestCRUDforDatabase {
System.out.println("read ltp entries with node name set...");
ReadPmdata24hLtpListInput readLtp = new ReadPmdata24hLtpListInputBuilder()
- .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build()))
+ .setFilter(YangHelper2.getListOrMap(FilterKey.class,
+ new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build()))
.setPagination(getPagination(20, 1)).build();
ReadPmdata24hLtpListOutputBuilder readltpResult = null;
@@ -1363,7 +1383,7 @@ public class TestCRUDforDatabase {
+ "\"implemented-interface\": \"org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultlog\",\n"
+ "\"source-type\": \"Netconf\",\n" + "\"node-id\": \"sim4\",\n" + "\"problem\": \"signalIsLost\"\n"
+ "}";
- YangToolsMapper yangtoolsMapper = new YangToolsMapper();
+ DataProviderYangToolsMapper yangtoolsMapper = new DataProviderYangToolsMapper();
Faultlog log = yangtoolsMapper.readValue(jsonString, Faultlog.class);
System.out.println(yangtoolsMapper.writeValueAsString((new FaultlogBuilder(log).build())));
System.out.println("Check3");
@@ -1374,6 +1394,27 @@ public class TestCRUDforDatabase {
}
+ @Test
+ public void testUserdata() {
+ final String USERNAME = "admin";
+ final String DATA1 = "{\n" + " \"networkMap\":{\n"
+ + " \"startupPosition\": {\"lat\": 52.5095, \"lon\":13.329, \"zoom\": 10},\n"
+ + " \"tileOpacity\": 90,\n" + " \"styling\":{\n" + " \"theme\": \"light\"\n"
+ + " }\n" + " },\n" + " \"dashboard\":{\n" + " \"color\":\"#F00\"\n" + " }\n"
+ + "}";
+ HtUserdataManagerImpl client = new HtUserdataManagerImpl(dbRawProvider);
+ boolean success = client.setUserdata(USERNAME, DATA1);
+ assertTrue(success);
+ String data = client.getUserdata(USERNAME);
+ //JSONAssert.assertEquals(DATA1,data,false);
+
+ assertEquals("admin", UserdataHttpServlet.decodeJWTPayloadUsername(String.format("Bearer %s",
+ "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbkBzZG4iLCJyb2xlcyI6WyJ1c2VyIiwiYWRtaW4iXSwiaXN"
+ + "zIjoiT3BlbmRheWxpZ2h0IiwibmFtZSI6ImFkbWluQHNkbiIsImV4cCI6MTYxNTc5NTg1NywiZmFtaWx5X25hbWUiOiIifQ.wB"
+ + "PdB45_bryU6_kSCu3be3dq3yth24niSXi6b2_1ufc"),
+ "sub"));
+ }
+
private Pagination getPagination(long pageSize, int page) {
return new PaginationBuilder().setPage(YangHelper2.getBigIntegerOrUint64(BigInteger.valueOf(page)))
.setSize(YangHelper2.getLongOrUint32(pageSize)).build();
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java
index eaaa31107..56bc32ce3 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java
@@ -24,7 +24,7 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
import static org.junit.Assert.fail;
import java.io.IOException;
import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper2;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data;
public class TestDataMappings {
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java
index 7e63c183c..56138b0b1 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java
@@ -63,6 +63,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* @author Michael Dürre
@@ -205,6 +206,7 @@ public class TestEventService {
List<NetworkElementConnectionEntity> nes = service.getNetworkElementConnections();
assertEquals(0, nes.size());
service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown), NODEID);
+ service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown), NODEID);
service.updateNetworkConnection22(createNeConnection(NODEID2, NetworkElementDeviceType.ORAN), NODEID2);
nes = service.getNetworkElementConnections();
assertEquals(2, nes.size());
@@ -243,11 +245,9 @@ public class TestEventService {
@Test
public void testInventory() {
clearDbEntity(Entity.Inventoryequipment);
- service.writeInventory(createEquipment(NODEID, "uuid1"));
- service.writeInventory(createEquipment(NODEID, "uuid2"));
- service.writeInventory(createEquipment(NODEID2, "uuid3"));
- service.writeInventory(createEquipment(NODEID2, "uuid4"));
- service.writeInventory(createEquipment(NODEID2, "uuid5"));
+ service.writeInventory(NODEID,Arrays.asList(createEquipment(NODEID, "uuid1"), createEquipment(NODEID, "uuid2"),
+ createEquipment(NODEID, "uuid3"), createEquipment(NODEID, "uuid4"),
+ createEquipment(NODEID, "uuid5")));
assertEquals(5, getDbEntityEntries(Entity.Inventoryequipment).getTotal());
}
@@ -272,19 +272,21 @@ public class TestEventService {
* @return
*/
private Inventory createEquipment(String nodeId, String uuid) {
- return new InventoryBuilder().setNodeId(nodeId).setParentUuid("").setDescription("desc")
- .setManufacturerName("manu").setDate(NetconfTimeStampImpl.getConverter().getTimeStampAsNetconfString()).setUuid(uuid).build();
+ return new InventoryBuilder().setNodeId(nodeId).setParentUuid(null).setDescription("desc")
+ .setTreeLevel(Uint32.valueOf(0)).setManufacturerName("manu")
+ .setDate(NetconfTimeStampImpl.getConverter().getTimeStampAsNetconfString()).setUuid(uuid).build();
}
/**
* @param devType
+ * @param mountMethod
* @param nodename3
* @return
*/
private static NetworkElementConnectionEntity createNeConnection(String nodeId, NetworkElementDeviceType devType) {
- return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host").setPort(YangHelper2.getLongOrUint32(1234L))
- .setCoreModelCapability("123").setStatus(ConnectionLogStatus.Connected).setDeviceType(devType)
- .setIsRequired(true).build();
+ return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host")
+ .setPort(YangHelper2.getLongOrUint32(1234L)).setCoreModelCapability("123")
+ .setStatus(ConnectionLogStatus.Connected).setDeviceType(devType).setIsRequired(true).build();
}
/**
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java
index aa010939d..16dfa0ec6 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java
@@ -22,14 +22,13 @@
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
import static org.junit.Assert.fail;
-
import java.util.Set;
-
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderImpl;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey;
@@ -73,6 +72,7 @@ public class TestImplementation {
impl.setMediatorServerServlet(new MsServlet());
impl.setAboutServlet(new AboutHttpServlet());
impl.setTreeServlet(new DataTreeHttpServlet());
+ impl.setUserdataServlet(new UserdataHttpServlet());
try {
impl.init();
} catch (Exception e) {
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java
index 76286c820..b52e34c49 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java
@@ -24,7 +24,7 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultcurrent;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
@@ -33,7 +33,7 @@ public class TestNuMappings {
@Test
public void testMapObjectToJson() throws IOException {
- YangToolsMapper mapper = new YangToolsMapper();
+ DataProviderYangToolsMapper mapper = new DataProviderYangToolsMapper();
Faultcurrent c = new FaultcurrentBuilder().setSeverity(SeverityType.Critical).build();
String json = mapper.writeValueAsString(c);
@@ -42,7 +42,7 @@ public class TestNuMappings {
@Test
public void testMapJsonToObject() throws IOException {
- YangToolsMapper mapper = new YangToolsMapper();
+ DataProviderYangToolsMapper mapper = new DataProviderYangToolsMapper();
Faultcurrent f = mapper.readValue("{\"severity\":\"Critical\"}", Faultcurrent.class);
assertTrue("Critical expected", f.getSeverity().equals(SeverityType.Critical));
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java
index 53c72115d..e32179122 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java
@@ -36,7 +36,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.EntityWithTree;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.FilterMode;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeObject;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataTreeProviderImpl;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
@@ -91,14 +90,14 @@ public class TestTree {
provider.setDatabaseClient(dbRawProvider);
- DataTreeObject tree = provider.readInventoryTree(null, null, FilterMode.Lazy);
+ DataTreeObject tree = provider.readInventoryTree(null, null);
System.out.println(tree.toJSON());
JSONObject o = new JSONObject(tree.toJSON());
JSONAssert.assertContainsOnlyKey(o, "sim1");
JSONObject children = o.getJSONObject("sim1").getJSONObject("children");
this.assertSim1(children);
- tree = provider.readInventoryTree(Arrays.asList("sim1"), "*", FilterMode.Lazy);
+ tree = provider.readInventoryTree(Arrays.asList("sim1"), "*");
this.assertSim1(new JSONObject(tree.toJSON()));
System.out.println(tree.toJSON());
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java
new file mode 100644
index 000000000..fd397840e
--- /dev/null
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java
@@ -0,0 +1,94 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 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.test;
+
+import static org.junit.Assert.fail;
+import java.io.IOException;
+import org.apache.sshd.common.util.io.IoUtils;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
+import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
+import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtUserdataManagerImpl;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
+
+public class TestUserdata {
+
+ private static final String USERNAME = "admin";
+ private static HtDatabaseClient dbRawProvider;
+ private static HtUserdataManagerImpl userDbProvider;
+
+ @BeforeClass
+ public static void init() throws Exception {
+
+ HostInfo[] hosts = HostInfoForTest.get();
+ dbRawProvider = HtDatabaseClient.getClient(hosts);
+ userDbProvider = new HtUserdataManagerImpl(dbRawProvider);
+ }
+
+ public static void trySleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (Exception e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ @Ignore
+ @Test
+ public void test1() {
+ String fullContent = "";
+ try {
+ fullContent = getFileContent("/userdata/full.json");
+ userDbProvider.setUserdata(USERNAME, fullContent);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ trySleep(2000);
+
+ String userdata = userDbProvider.getUserdata(USERNAME);
+ JSONAssert.assertEquals(fullContent, userdata, false);
+ String networkMapContent = "";
+ String mergedContent = "";
+ try {
+ networkMapContent = getFileContent("/userdata/networkmap.json");
+ mergedContent = getFileContent("/userdata/merged.json");
+ userDbProvider.setUserdata(USERNAME, "networkMap", networkMapContent);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ trySleep(2000);
+
+ userdata = userDbProvider.getUserdata(USERNAME);
+ JSONAssert.assertEquals(mergedContent, userdata, false);
+ }
+
+ private static String getFileContent(String filename) throws IOException {
+ return String.join("\n", IoUtils.readAllLines(TestTree.class.getResourceAsStream(filename)));
+ }
+}
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java
index 3c9d4946b..524659e99 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java
@@ -40,8 +40,8 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteIndexReque
import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
@@ -65,7 +65,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro
public class TestYangGenSalMapping {
// Create mapper for serialization and deserialization
- YangToolsMapper mapper = new YangToolsMapper();
+ DataProviderYangToolsMapper mapper = new DataProviderYangToolsMapper();
@Test
public void test1() throws IOException {
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java
index 56df62819..1345d4edf 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java
@@ -32,8 +32,8 @@ import org.jline.utils.Log;
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper;
-import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper2;
+import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper2;
import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.BIPErrorCounter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.OpticalPowerInputOSCMin;
@@ -74,7 +74,7 @@ public class TestYangGenSalMappingOpenRoadm extends Mockito {
PmdataEntity pmDataType = pmDataEntitybuilder.build();
- YangToolsMapper mapper2 = new YangToolsMapper();
+ DataProviderYangToolsMapper mapper2 = new DataProviderYangToolsMapper();
String jsonString = mapper2.writeValueAsString(pmDataType);
out("Result json after mapping: " + jsonString);
@@ -88,7 +88,7 @@ public class TestYangGenSalMappingOpenRoadm extends Mockito {
public void testOpenroadmPMString1() throws IOException, ClassNotFoundException {
out("Test: " + method());
String jsonString2 = getFileContent("pmdata1.json");
- YangToolsMapper mapper2 = new YangToolsMapper();
+ DataProviderYangToolsMapper mapper2 = new DataProviderYangToolsMapper();
PmdataEntity generatepmdNode = mapper2.readValue(jsonString2.getBytes(), PmdataEntity.class);
out("String1:"+generatepmdNode.toString()); // Print it with specified indentation
assertTrue("GranularityPeriod", generatepmdNode.getGranularityPeriod().equals(GranularityPeriodType.Period15Min));
@@ -105,7 +105,7 @@ public class TestYangGenSalMappingOpenRoadm extends Mockito {
public void testOpenroadmPMString2() throws IOException, ClassNotFoundException {
out("Test: " + method());
String jsonString2 = getFileContent("pmdata2.json");
- YangToolsMapper mapper2 = new YangToolsMapper();
+ DataProviderYangToolsMapper mapper2 = new DataProviderYangToolsMapper();
PmdataEntity generatepmdNode = mapper2.readValue(jsonString2.getBytes(), PmdataEntity.class);
out(generatepmdNode.toString()); // Print it with specified indentation
}
diff --git a/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json b/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json
new file mode 100644
index 000000000..c5b41ec21
--- /dev/null
+++ b/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json
@@ -0,0 +1,13 @@
+{
+ "networkMap": {
+ "styling": {
+ "theme": "dark"
+ },
+ "startupPosition": {
+ "latitude": "52.5",
+ "zoom": "10",
+ "longitude": "13.35"
+ },
+ "tileOpacity": "26"
+ }
+} \ No newline at end of file
diff --git a/sdnr/wt/data-provider/provider/src/test/resources/userdata/merged.json b/sdnr/wt/data-provider/provider/src/test/resources/userdata/merged.json
new file mode 100644
index 000000000..4e283cd6f
--- /dev/null
+++ b/sdnr/wt/data-provider/provider/src/test/resources/userdata/merged.json
@@ -0,0 +1,13 @@
+{
+ "networkMap": {
+ "tileOpacity": "26",
+ "styling": {
+ "theme": "light"
+ },
+ "startupPosition": {
+ "latitude": "52.5",
+ "longitude": "13.35",
+ "zoom": "10"
+ }
+ }
+} \ No newline at end of file
diff --git a/sdnr/wt/data-provider/provider/src/test/resources/userdata/networkmap.json b/sdnr/wt/data-provider/provider/src/test/resources/userdata/networkmap.json
new file mode 100644
index 000000000..20d44f752
--- /dev/null
+++ b/sdnr/wt/data-provider/provider/src/test/resources/userdata/networkmap.json
@@ -0,0 +1,11 @@
+{
+ "tileOpacity": "26",
+ "styling": {
+ "theme": "light"
+ },
+ "startupPosition": {
+ "latitude": "52.5",
+ "longitude": "13.35",
+ "zoom": "10"
+ }
+} \ No newline at end of file