summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/main')
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/CpsAdminService.java29
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java7
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java45
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java26
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java41
5 files changed, 93 insertions, 55 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
index 7ba95995a5..44f7f77152 100755
--- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation
- * Modifications Copyright (C) 2020 Bell Canada.
+ * Modifications Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,6 @@
package org.onap.cps.api;
import java.util.Collection;
-import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.model.Anchor;
@@ -39,14 +38,14 @@ public interface CpsAdminService {
* @param dataspaceName dataspace name
* @throws AlreadyDefinedException if dataspace with same name already exists
*/
- void createDataspace(@NonNull String dataspaceName);
+ void createDataspace(String dataspaceName);
/**
* Delete dataspace.
*
* @param dataspaceName the name of the dataspace to delete
*/
- void deleteDataspace(@NonNull String dataspaceName);
+ void deleteDataspace(String dataspaceName);
/**
* Create an Anchor.
@@ -56,7 +55,7 @@ public interface CpsAdminService {
* @param anchorName anchor name
* @throws CpsException if input data is invalid.
*/
- void createAnchor(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull String anchorName);
+ void createAnchor(String dataspaceName, String schemaSetName, String anchorName);
/**
* Read all anchors in the given dataspace.
@@ -64,8 +63,16 @@ public interface CpsAdminService {
* @param dataspaceName dataspace name
* @return a collection of anchors
*/
- @NonNull
- Collection<Anchor> getAnchors(@NonNull String dataspaceName);
+ Collection<Anchor> getAnchors(String dataspaceName);
+
+ /**
+ * Read all anchors associated the given schema-set in the given dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema-set name
+ * @return a collection of anchors
+ */
+ Collection<Anchor> getAnchors(String dataspaceName, String schemaSetName);
/**
* Get an anchor in the given dataspace using the anchor name.
@@ -74,8 +81,7 @@ public interface CpsAdminService {
* @param anchorName anchor name
* @return an anchor
*/
- @NonNull
- Anchor getAnchor(@NonNull String dataspaceName, @NonNull String anchorName);
+ Anchor getAnchor(String dataspaceName, String anchorName);
/**
* Delete anchor by name in given dataspace.
@@ -83,14 +89,13 @@ public interface CpsAdminService {
* @param dataspaceName dataspace name
* @param anchorName anchor name
*/
- void deleteAnchor(@NonNull String dataspaceName, @NonNull String anchorName);
+ void deleteAnchor(String dataspaceName, String anchorName);
/**
* Query anchor names for the given module names in the provided dataspace.
*
- *
* @param dataspaceName dataspace name
- * @param moduleNames a collection of module names
+ * @param moduleNames a collection of module names
* @return a collection of anchor names in the given dataspace. The schema set for each anchor must include all the
* given module names
*/
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 d831793264..d30a6571d8 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
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation
- * Modifications Copyright (C) 2020 Bell Canada.
+ * Modifications Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -57,6 +57,11 @@ public class CpsAdminServiceImpl implements CpsAdminService {
}
@Override
+ public Collection<Anchor> getAnchors(final String dataspaceName, final String schemaSetName) {
+ return cpsAdminPersistenceService.getAnchors(dataspaceName, schemaSetName);
+ }
+
+ @Override
public Anchor getAnchor(final String dataspaceName, final String anchorName) {
return cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName);
}
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
index 10326413c3..e967817867 100644
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2020-2021 Nordix Foundation
* Modifications Copyright (C) 2020-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.
@@ -24,23 +25,38 @@ package org.onap.cps.api.impl;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.spi.CascadeDeleteAllowed;
import org.onap.cps.spi.CpsModulePersistenceService;
+import org.onap.cps.spi.exceptions.SchemaSetInUseException;
+import org.onap.cps.spi.model.Anchor;
import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.spi.model.SchemaSet;
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
@Service("CpsModuleServiceImpl")
public class CpsModuleServiceImpl implements CpsModuleService {
- @Autowired
private CpsModulePersistenceService cpsModulePersistenceService;
-
- @Autowired
private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
+ private CpsAdminService cpsAdminService;
+
+ /**
+ * Create an instance of CpsModuleServiceImpl.
+ *
+ * @param cpsModulePersistenceService cpsModulePersistenceService
+ * @param yangTextSchemaSourceSetCache yangTextSchemaSourceSetCache
+ * @param cpsAdminService cpsAdminService
+ */
+ public CpsModuleServiceImpl(final CpsModulePersistenceService cpsModulePersistenceService,
+ final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache, final CpsAdminService cpsAdminService) {
+ this.cpsModulePersistenceService = cpsModulePersistenceService;
+ this.yangTextSchemaSourceSetCache = yangTextSchemaSourceSetCache;
+ this.cpsAdminService = cpsAdminService;
+ }
@Override
public void createSchemaSet(final String dataspaceName, final String schemaSetName,
@@ -53,10 +69,10 @@ public class CpsModuleServiceImpl implements CpsModuleService {
@Override
public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
- final Map<String, String> newYangResourcesModuleNameToContentMap,
- final List<ModuleReference> moduleReferences) {
+ final Map<String, String> newYangResourcesModuleNameToContentMap,
+ final List<ModuleReference> moduleReferences) {
cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName,
- newYangResourcesModuleNameToContentMap, moduleReferences);
+ newYangResourcesModuleNameToContentMap, moduleReferences);
}
@@ -69,9 +85,18 @@ public class CpsModuleServiceImpl implements CpsModuleService {
}
@Override
+ @Transactional
public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
final CascadeDeleteAllowed cascadeDeleteAllowed) {
- cpsModulePersistenceService.deleteSchemaSet(dataspaceName, schemaSetName, cascadeDeleteAllowed);
+ final Collection<Anchor> anchors = cpsAdminService.getAnchors(dataspaceName, schemaSetName);
+ if (!anchors.isEmpty() && isCascadeDeleteProhibited(cascadeDeleteAllowed)) {
+ throw new SchemaSetInUseException(dataspaceName, schemaSetName);
+ }
+ for (final Anchor anchor : anchors) {
+ cpsAdminService.deleteAnchor(dataspaceName, anchor.getName());
+ }
+ cpsModulePersistenceService.deleteSchemaSet(dataspaceName, schemaSetName);
+ cpsModulePersistenceService.deleteUnusedYangResourceModules();
}
@Override
@@ -84,4 +109,8 @@ public class CpsModuleServiceImpl implements CpsModuleService {
final String anchorName) {
return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName, anchorName);
}
+
+ private boolean isCascadeDeleteProhibited(final CascadeDeleteAllowed cascadeDeleteAllowed) {
+ return CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED == cascadeDeleteAllowed;
+ }
}
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java
index 95537006a7..dd4059d88c 100755
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
- * Modifications Copyright (C) 2020 Bell Canada.
+ * Modifications Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,6 @@
package org.onap.cps.spi;
import java.util.Collection;
-import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.model.Anchor;
@@ -38,14 +37,14 @@ public interface CpsAdminPersistenceService {
* @param dataspaceName dataspace name
* @throws AlreadyDefinedException if dataspace with same name already exists
*/
- void createDataspace(@NonNull String dataspaceName);
+ void createDataspace(String dataspaceName);
/**
* Delete dataspace.
*
* @param dataspaceName the name of the dataspace to delete
*/
- void deleteDataspace(@NonNull String dataspaceName);
+ void deleteDataspace(String dataspaceName);
/**
* Create an Anchor.
@@ -54,7 +53,16 @@ public interface CpsAdminPersistenceService {
* @param schemaSetName schema set name
* @param anchorName anchor name
*/
- void createAnchor(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull String anchorName);
+ void createAnchor(String dataspaceName, String schemaSetName, String anchorName);
+
+ /**
+ * Read all anchors associated the given schema-set in the given dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema-set name
+ * @return a collection of anchors
+ */
+ Collection<Anchor> getAnchors(String dataspaceName, String schemaSetName);
/**
* Read all anchors in the given a dataspace.
@@ -62,8 +70,7 @@ public interface CpsAdminPersistenceService {
* @param dataspaceName dataspace name
* @return a collection of anchors
*/
- @NonNull
- Collection<Anchor> getAnchors(@NonNull String dataspaceName);
+ Collection<Anchor> getAnchors(String dataspaceName);
/**
* Query anchor names for the given module names in the provided dataspace.
@@ -83,8 +90,7 @@ public interface CpsAdminPersistenceService {
* @param anchorName anchor name
* @return an anchor
*/
- @NonNull
- Anchor getAnchor(@NonNull String dataspaceName, @NonNull String anchorName);
+ Anchor getAnchor(String dataspaceName, String anchorName);
/**
* Delete anchor by name in given dataspace.
@@ -92,5 +98,5 @@ public interface CpsAdminPersistenceService {
* @param dataspaceName dataspace name
* @param anchorName anchor name
*/
- void deleteAnchor(@NonNull String dataspaceName, @NonNull String anchorName);
+ void deleteAnchor(String dataspaceName, String anchorName);
}
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java
index 9b50f9e917..e082734417 100755
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation
- * Modifications Copyright (C) 2020 Bell Canada.
+ * Modifications Copyright (C) 2020-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.
@@ -24,8 +24,6 @@ package org.onap.cps.spi;
import java.util.Collection;
import java.util.List;
import java.util.Map;
-import org.checkerframework.checker.nullness.qual.NonNull;
-import org.onap.cps.spi.exceptions.DataInUseException;
import org.onap.cps.spi.model.ModuleReference;
/**
@@ -40,8 +38,7 @@ public interface CpsModulePersistenceService {
* @param schemaSetName schema set name
* @param yangResourcesNameToContentMap YANG resources (files) map where key is a name and value is content
*/
- void storeSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName,
- @NonNull Map<String, String> yangResourcesNameToContentMap);
+ void storeSchemaSet(String dataspaceName, String schemaSetName, Map<String, String> yangResourcesNameToContentMap);
/**
* Stores a schema set from new modules and existing modules.
@@ -49,45 +46,36 @@ public interface CpsModulePersistenceService {
* @param dataspaceName Dataspace name
* @param schemaSetName Schema set name
* @param newYangResourcesModuleNameToContentMap YANG resources map where key is a module name and value is content
- * @param moduleReferences List of YANG resources module references
+ * @param moduleReferences List of YANG resources module references
*/
- void storeSchemaSetFromModules(@NonNull String dataspaceName, @NonNull String schemaSetName,
- @NonNull Map<String, String> newYangResourcesModuleNameToContentMap,
- @NonNull List<ModuleReference> moduleReferences);
+ void storeSchemaSetFromModules(String dataspaceName, String schemaSetName,
+ Map<String, String> newYangResourcesModuleNameToContentMap, List<ModuleReference> moduleReferences);
/**
* Deletes Schema Set.
*
- * @param dataspaceName dataspace name
- * @param schemaSetName schema set name
- * @param cascadeDeleteAllowed indicates the allowance to remove associated anchors and data if exist
- * @throws DataInUseException if cascadeDeleteAllowed is set to CASCADE_DELETE_PROHIBITED and there
- * is associated anchor record exists in database
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema set name
*/
- void deleteSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName,
- @NonNull CascadeDeleteAllowed cascadeDeleteAllowed);
+ void deleteSchemaSet(String dataspaceName, String schemaSetName);
/**
* Returns YANG resources per specific dataspace / schemaSetName.
*
- * @param dataspaceName dataspace name
+ * @param dataspaceName dataspace name
* @param schemaSetName schema set name
* @return YANG resources (files) map where key is a name and value is content
*/
- @NonNull
- Map<String, String> getYangSchemaResources(@NonNull String dataspaceName,
- @NonNull String schemaSetName);
+ Map<String, String> getYangSchemaResources(String dataspaceName, String schemaSetName);
/**
* Returns YANG resources per specific dataspace / anchorName.
*
* @param dataspaceName dataspace name
- * @param anchorName anchor name
+ * @param anchorName anchor name
* @return YANG resources (files) map where key is a name and value is content
*/
- @NonNull
- Map<String, String> getYangSchemaSetResources(@NonNull String dataspaceName,
- @NonNull String anchorName);
+ Map<String, String> getYangSchemaSetResources(String dataspaceName, String anchorName);
/**
* Returns YANG resources module references for the given dataspace name.
@@ -105,4 +93,9 @@ public interface CpsModulePersistenceService {
* @return a collection of module names and revisions
*/
Collection<ModuleReference> getYangResourceModuleReferences(String dataspaceName, String anchorName);
+
+ /**
+ * Remove unused Yang Resource Modules.
+ */
+ void deleteUnusedYangResourceModules();
}