summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main
diff options
context:
space:
mode:
authorRenu Kumari <renu.kumari@bell.ca>2022-01-20 13:30:05 -0500
committerRenu Kumari <renu.kumari@bell.ca>2022-02-02 10:31:06 -0500
commitc9af4eac4dc7f86bd3f33d923f9efe4a8523ed57 (patch)
treed10cfe4f1d5b2dcf8d0bf43ea04678262c4a287e /cps-service/src/main
parentcdc85a32069485641b0c8c37f8d7c4e6727e336a (diff)
Refactor Delete Anchor functionality
- Added a delete DataNode functionality in the CpsDataService - CpsAdminService uses CpsDataService to delete DataNodes Issue-ID: CPS-791 Signed-off-by: Renu Kumari <renu.kumari@bell.ca> Change-Id: I090500dbc4a2ccf061dc105f979472137d43b06d
Diffstat (limited to 'cps-service/src/main')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java48
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java12
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java24
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java43
4 files changed, 71 insertions, 56 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
index f455e47efd..d2482d50a6 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
- * Modifications Copyright (C) 2021 Bell Canada
+ * Modifications Copyright (C) 2021-2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
package org.onap.cps.api;
import java.time.OffsetDateTime;
-import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
@@ -40,8 +39,7 @@ public interface CpsDataService {
* @param jsonData json data
* @param observedTimestamp observedTimestamp
*/
- void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String jsonData,
- OffsetDateTime observedTimestamp);
+ void saveData(String dataspaceName, String anchorName, String jsonData, OffsetDateTime observedTimestamp);
/**
* Persists child data fragment under existing data node for the given anchor and dataspace.
@@ -52,8 +50,8 @@ public interface CpsDataService {
* @param jsonData json data
* @param observedTimestamp observedTimestamp
*/
- void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
- @NonNull String jsonData, OffsetDateTime observedTimestamp);
+ void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
+ OffsetDateTime observedTimestamp);
/**
* Persists child data fragment representing one or more list elements under existing data node for the
@@ -65,9 +63,8 @@ public interface CpsDataService {
* @param jsonData json data representing list element(s)
* @param observedTimestamp observedTimestamp
*/
- void saveListElements(@NonNull String dataspaceName, @NonNull String anchorName,
- @NonNull String parentNodeXpath,
- @NonNull String jsonData, OffsetDateTime observedTimestamp);
+ void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
+ OffsetDateTime observedTimestamp);
/**
* Retrieves datanode by XPath for given dataspace and anchor.
@@ -79,8 +76,8 @@ public interface CpsDataService {
* (recursively) as well
* @return data node object
*/
- DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
- @NonNull FetchDescendantsOption fetchDescendantsOption);
+ DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
+ FetchDescendantsOption fetchDescendantsOption);
/**
* Updates data node for given dataspace and anchor using xpath to parent node.
@@ -91,8 +88,8 @@ public interface CpsDataService {
* @param jsonData json data
* @param observedTimestamp observedTimestamp
*/
- void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
- @NonNull String jsonData, OffsetDateTime observedTimestamp);
+ void updateNodeLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
+ OffsetDateTime observedTimestamp);
/**
* Replaces existing data node content including descendants.
@@ -103,8 +100,8 @@ public interface CpsDataService {
* @param jsonData json data
* @param observedTimestamp observedTimestamp
*/
- void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
- @NonNull String jsonData, OffsetDateTime observedTimestamp);
+ void replaceNodeTree(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
+ OffsetDateTime observedTimestamp);
/**
* Replaces list content by removing all existing elements and inserting the given new elements as json
@@ -116,8 +113,8 @@ public interface CpsDataService {
* @param jsonData json data representing the new list elements
* @param observedTimestamp observedTimestamp
*/
- void replaceListContent(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
- @NonNull String jsonData, OffsetDateTime observedTimestamp);
+ void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
+ OffsetDateTime observedTimestamp);
/**
* Deletes data node for given anchor and dataspace.
@@ -127,8 +124,17 @@ public interface CpsDataService {
* @param dataNodeXpath data node xpath
* @param observedTimestamp observed timestamp
*/
- void deleteDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String dataNodeXpath,
- OffsetDateTime observedTimestamp);
+ void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath,
+ OffsetDateTime observedTimestamp);
+
+ /**
+ * Deletes all data nodes for a given anchor in a dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param observedTimestamp observed timestamp
+ */
+ void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp);
/**
* Deletes a list or a list-element under given anchor and dataspace.
@@ -138,8 +144,8 @@ public interface CpsDataService {
* @param listElementXpath list element xpath
* @param observedTimestamp observedTimestamp
*/
- void deleteListOrListElement(@NonNull String dataspaceName, @NonNull String anchorName,
- @NonNull String listElementXpath, OffsetDateTime observedTimestamp);
+ void deleteListOrListElement(String dataspaceName, String anchorName, String listElementXpath,
+ OffsetDateTime observedTimestamp);
/**
* Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java
index d30a6571d8..1013addbe1 100755
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java
@@ -22,19 +22,24 @@
package org.onap.cps.api.impl;
+import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.stream.Collectors;
+import lombok.AllArgsConstructor;
import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsDataService;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.model.Anchor;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Component("CpsAdminServiceImpl")
+@AllArgsConstructor(onConstructor = @__(@Lazy))
public class CpsAdminServiceImpl implements CpsAdminService {
- @Autowired
- private CpsAdminPersistenceService cpsAdminPersistenceService;
+ private final CpsAdminPersistenceService cpsAdminPersistenceService;
+ @Lazy
+ private final CpsDataService cpsDataService;
@Override
public void createDataspace(final String dataspaceName) {
@@ -68,6 +73,7 @@ public class CpsAdminServiceImpl implements CpsAdminService {
@Override
public void deleteAnchor(final String dataspaceName, final String anchorName) {
+ cpsDataService.deleteDataNodes(dataspaceName, anchorName, OffsetDateTime.now());
cpsAdminPersistenceService.deleteAnchor(dataspaceName, anchorName);
}
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
index a23bc95f3e..e292bbe77e 100755
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
@@ -24,6 +24,7 @@ package org.onap.cps.api.impl;
import java.time.OffsetDateTime;
import java.util.Collection;
+import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
@@ -37,26 +38,19 @@ import org.onap.cps.spi.model.DataNodeBuilder;
import org.onap.cps.utils.YangUtils;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
+@AllArgsConstructor
public class CpsDataServiceImpl implements CpsDataService {
private static final String ROOT_NODE_XPATH = "/";
- @Autowired
- private CpsDataPersistenceService cpsDataPersistenceService;
-
- @Autowired
- private CpsAdminService cpsAdminService;
-
- @Autowired
- private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
-
- @Autowired
- private NotificationService notificationService;
+ private final CpsDataPersistenceService cpsDataPersistenceService;
+ private final CpsAdminService cpsAdminService;
+ private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
+ private final NotificationService notificationService;
@Override
public void saveData(final String dataspaceName, final String anchorName, final String jsonData,
@@ -138,6 +132,12 @@ public class CpsDataServiceImpl implements CpsDataService {
}
@Override
+ public void deleteDataNodes(final String dataspaceName, final String anchorName,
+ final OffsetDateTime observedTimestamp) {
+ cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName);
+ }
+
+ @Override
public void deleteListOrListElement(final String dataspaceName, final String anchorName, final String listNodeXpath,
final OffsetDateTime observedTimestamp) {
cpsDataPersistenceService.deleteListDataNode(dataspaceName, anchorName, listNodeXpath);
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
index b8c472f277..fd658861c2 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
* Modifications Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +24,6 @@ package org.onap.cps.spi;
import java.util.Collection;
import java.util.Map;
-import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.spi.model.DataNode;
/*
@@ -40,8 +40,7 @@ public interface CpsDataPersistenceService {
* @param anchorName anchor name
* @param dataNode data node
*/
- void storeDataNode(@NonNull String dataspaceName, @NonNull String anchorName,
- @NonNull DataNode dataNode);
+ void storeDataNode(String dataspaceName, String anchorName, DataNode dataNode);
/**
* Add a child to a Fragment.
@@ -51,8 +50,7 @@ public interface CpsDataPersistenceService {
* @param parentXpath parent xpath
* @param dataNode dataNode
*/
- void addChildDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentXpath,
- @NonNull DataNode dataNode);
+ void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
/**
* Adds list child elements to a Fragment.
@@ -63,8 +61,8 @@ public interface CpsDataPersistenceService {
* @param listElementsCollection collection of data nodes representing list elements
*/
- void addListElements(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
- @NonNull Collection<DataNode> listElementsCollection);
+ void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
+ Collection<DataNode> listElementsCollection);
/**
* Retrieves datanode by XPath for given dataspace and anchor.
@@ -76,8 +74,8 @@ public interface CpsDataPersistenceService {
* (recursively) as well
* @return data node object
*/
- DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
- @NonNull FetchDescendantsOption fetchDescendantsOption);
+ DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
+ FetchDescendantsOption fetchDescendantsOption);
/**
@@ -88,8 +86,7 @@ public interface CpsDataPersistenceService {
* @param xpath xpath
* @param leaves the leaves as a map where key is a leaf name and a value is a leaf value
*/
- void updateDataLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
- @NonNull Map<String, Object> leaves);
+ void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Object> leaves);
/**
* Replaces existing data node content including descendants.
@@ -98,7 +95,7 @@ public interface CpsDataPersistenceService {
* @param anchorName anchor name
* @param dataNode data node
*/
- void replaceDataNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull DataNode dataNode);
+ void replaceDataNodeTree(String dataspaceName, String anchorName, DataNode dataNode);
/**
* Replaces list content by removing all existing elements and inserting the given new elements
@@ -109,8 +106,8 @@ public interface CpsDataPersistenceService {
* @param parentNodeXpath parent node xpath
* @param newListElements collection of data nodes representing the new list content
*/
- void replaceListContent(@NonNull String dataspaceName, @NonNull String anchorName,
- @NonNull String parentNodeXpath, @NonNull Collection<DataNode> newListElements);
+ void replaceListContent(String dataspaceName, String anchorName,
+ String parentNodeXpath, Collection<DataNode> newListElements);
/**
* Deletes any dataNode, yang container or yang list or yang list element.
@@ -119,8 +116,15 @@ public interface CpsDataPersistenceService {
* @param anchorName anchor name
* @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
*/
- void deleteDataNode(@NonNull String dataspaceName, @NonNull String anchorName,
- @NonNull String targetXpath);
+ void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
+
+ /**
+ * Deletes all dataNodes in a given anchor.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ */
+ void deleteDataNodes(String dataspaceName, String anchorName);
/**
* Deletes existing a single list element or the whole list.
@@ -129,8 +133,7 @@ public interface CpsDataPersistenceService {
* @param anchorName anchor name
* @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
*/
- void deleteListDataNode(@NonNull String dataspaceName, @NonNull String anchorName,
- @NonNull String targetXpath);
+ void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
/**
* Get a datanode by cps path.
@@ -142,7 +145,7 @@ public interface CpsDataPersistenceService {
* included in the output
* @return the data nodes found i.e. 0 or more data nodes
*/
- Collection<DataNode> queryDataNodes(@NonNull String dataspaceName, @NonNull String anchorName,
- @NonNull String cpsPath, @NonNull FetchDescendantsOption fetchDescendantsOption);
+ Collection<DataNode> queryDataNodes(String dataspaceName, String anchorName,
+ String cpsPath, FetchDescendantsOption fetchDescendantsOption);
}