Merge "Fix: Update OpenSSF Scorecard to RelEng reusable"
[cps.git] / cps-service / src / main / java / org / onap / cps / api / CpsModuleService.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2020-2025 Nordix Foundation
4  *  Modifications Copyright (C) 2020-2021 Pantheon.tech
5  *  Modifications Copyright (C) 2022 TechMahindra Ltd.
6  *  ================================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *
19  *  SPDX-License-Identifier: Apache-2.0
20  *  ============LICENSE_END=========================================================
21  */
22
23 package org.onap.cps.api;
24
25 import java.util.Collection;
26 import java.util.Map;
27 import org.onap.cps.api.exceptions.DataInUseException;
28 import org.onap.cps.api.model.ModuleDefinition;
29 import org.onap.cps.api.model.ModuleReference;
30 import org.onap.cps.api.model.SchemaSet;
31 import org.onap.cps.api.parameters.CascadeDeleteAllowed;
32
33 /**
34  * Responsible for managing module sets.
35  */
36 public interface CpsModuleService {
37
38     /**
39      * Create schema set.
40      *
41      * @param dataspaceName                 dataspace name
42      * @param schemaSetName                 schema set name
43      * @param yangResourceContentPerName yang resources (files) as a mep where key is resource name
44      *                                      and value is content
45      */
46     void createSchemaSet(String dataspaceName, String schemaSetName,
47                          Map<String, String> yangResourceContentPerName);
48
49     /**
50      * Create or upgrade a schema set from new modules and existing modules or only existing modules.
51      * @param dataspaceName              Dataspace name
52      * @param schemaSetName              schema set name
53      * @param yangResourceContentPerName YANG resources map where key is a name and value is content
54      * @param allModuleReferences        All YANG resource module references
55      */
56     void createSchemaSetFromModules(String dataspaceName, String schemaSetName,
57                                     Map<String, String> yangResourceContentPerName,
58                                     Collection<ModuleReference> allModuleReferences);
59
60     /**
61      * Check if a schema set exist in the given dataspace.
62      *
63      * @param dataspaceName  Dataspace name
64      * @param schemaSetName  Schema set name
65      * @return boolean, true if a schema set with the given name exist in the given dataspace
66      */
67     boolean schemaSetExists(String dataspaceName, String schemaSetName);
68
69     /**
70      * Read schema set in the given dataspace.
71      *
72      * @param dataspaceName dataspace name
73      * @param schemaSetName schema set name
74      * @return a SchemaSet
75      */
76     SchemaSet getSchemaSet(String dataspaceName, String schemaSetName);
77
78     /**
79      * Retrieve all schema sets in the given dataspace.
80      *
81      * @param dataspaceName dataspace name
82      * @return all SchemaSets
83      */
84     Collection<SchemaSet> getSchemaSets(String dataspaceName);
85
86     /**
87      * Deletes Schema Set.
88      *
89      * @param dataspaceName        dataspace name
90      * @param schemaSetName        schema set name
91      * @param cascadeDeleteAllowed indicates the allowance to remove associated anchors and data if exist
92      * @throws DataInUseException  if cascadeDeleteAllowed is set to CASCADE_DELETE_PROHIBITED and there
93      *                             is associated anchor record exists in database
94      */
95     void deleteSchemaSet(String dataspaceName, String schemaSetName,
96                          CascadeDeleteAllowed cascadeDeleteAllowed);
97
98     /**
99      * Deletes Schema Sets with cascade.
100      *
101      * @param dataspaceName        dataspace name
102      * @param schemaSetNames       schema set names
103      */
104     void deleteSchemaSetsWithCascade(String dataspaceName, Collection<String> schemaSetNames);
105
106
107     /**
108      * upgrade schema sets with existing or new modules.
109      *
110      * @param dataspaceName             dataspace name
111      * @param schemaSetName             schema set name
112      * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
113      * @param allModuleReferences       All YANG resource module references
114      */
115     void upgradeSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
116                                      final Map<String, String> newModuleNameToContentMap,
117                                      final Collection<ModuleReference> allModuleReferences);
118
119     /**
120      * Retrieve module references for the given dataspace name.
121      *
122      * @param dataspaceName        dataspace name
123      * @return a list of ModuleReference objects
124      */
125     Collection<ModuleReference> getYangResourceModuleReferences(String dataspaceName);
126
127     /**
128      * Retrieve module references for the given dataspace name and anchor name.
129      *
130      * @param dataspaceName dataspace name
131      * @param anchorName    anchor name
132      * @return a list of ModuleReference objects
133      */
134     Collection<ModuleReference> getYangResourcesModuleReferences(String dataspaceName, String anchorName);
135
136     /**
137      * Retrieve module definitions for the given dataspace name and anchor name.
138      *
139      * @param dataspaceName dataspace name
140      * @param anchorName    anchor name
141      * @return a collection of module definitions (moduleName, revision, yang resource content)
142      */
143     Collection<ModuleDefinition> getModuleDefinitionsByAnchorName(String dataspaceName, String anchorName);
144
145     /**
146      * Retrieve module definitions for the given parameters.
147      *
148      * @param dataspaceName     dataspace name
149      * @param anchorName        anchor name
150      * @param moduleName        module name
151      * @param moduleRevision    the revision of the module
152      * @return a collection of module definitions (moduleName, revision, yang resource content)
153      */
154     Collection<ModuleDefinition> getModuleDefinitionsByAnchorAndModule(String dataspaceName, String anchorName,
155                                                                   String moduleName, String moduleRevision);
156
157     /**
158      * Identify previously unknown Yang Resource module references.
159      * The system will ignore the namespace of all module references.
160      *
161      * @param moduleReferencesToCheck the moduleReferencesToCheck
162      * @return collection of module references (namespace will be always blank)
163      */
164     Collection<ModuleReference> identifyNewModuleReferences(Collection<ModuleReference> moduleReferencesToCheck);
165
166     /**
167      * Remove any Yang Resource Modules and Schema Sets from the given dataspace that are no longer referenced
168      * by any anchor.
169      *
170      * @param dataspaceName     dataspace name
171      */
172     void deleteAllUnusedYangModuleData(String dataspaceName);
173
174 }