Extend API: Get Module Definitions
[cps.git] / cps-service / src / main / java / org / onap / cps / spi / CpsModulePersistenceService.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020-2024 Nordix Foundation
4  *  Modifications Copyright (C) 2020-2022 Bell Canada.
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.spi;
24
25 import java.util.Collection;
26 import java.util.Map;
27 import org.onap.cps.spi.model.ModuleDefinition;
28 import org.onap.cps.spi.model.ModuleReference;
29 import org.onap.cps.spi.model.SchemaSet;
30
31 /**
32  * Service to manage modules.
33  */
34 public interface CpsModulePersistenceService {
35
36     /**
37      * Stores Schema Set.
38      *
39      * @param dataspaceName                 dataspace name
40      * @param schemaSetName                 schema set name
41      * @param yangResourcesNameToContentMap YANG resources (files) map where key is a name and value is content
42      */
43     void storeSchemaSet(String dataspaceName, String schemaSetName, Map<String, String> yangResourcesNameToContentMap);
44
45     /**
46      * Stores a new schema set from new modules and existing modules.
47      *
48      * @param dataspaceName             Dataspace name
49      * @param schemaSetName             Schema set name
50      * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
51      * @param allModuleReferences       All YANG resources module references
52      */
53     void storeSchemaSetFromModules(String dataspaceName, String schemaSetName,
54         Map<String, String> newModuleNameToContentMap, Collection<ModuleReference> allModuleReferences);
55
56     /**
57      * Update an existing schema set from new modules and existing modules.
58      *
59      * @param dataspaceName             Dataspace name
60      * @param schemaSetName             Schema set name
61      * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
62      * @param allModuleReferences       All YANG resources module references
63      */
64     void updateSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
65                                     final Map<String, String> newModuleNameToContentMap,
66                                     final Collection<ModuleReference> allModuleReferences);
67
68
69     /**
70      * Get all schema sets for a given dataspace.
71      *
72      * @param dataspaceName dataspace name.
73      * @return List of schema sets
74      */
75     Collection<SchemaSet> getSchemaSetsByDataspaceName(String dataspaceName);
76
77     /**
78      * Deletes Schema Set.
79      *
80      * @param dataspaceName dataspace name
81      * @param schemaSetName schema set name
82      */
83     void deleteSchemaSet(String dataspaceName, String schemaSetName);
84
85     /**
86      * Deletes Schema Sets.
87      *
88      * @param dataspaceName  dataspace name
89      * @param schemaSetNames schema set names
90      */
91     void deleteSchemaSets(String dataspaceName, Collection<String> schemaSetNames);
92
93     /**
94      * Returns YANG resources per specific dataspace / schemaSetName.
95      *
96      * @param dataspaceName dataspace name
97      * @param schemaSetName schema set name
98      * @return YANG resources (files) map where key is a name and value is content
99      */
100     Map<String, String> getYangSchemaResources(String dataspaceName, String schemaSetName);
101
102     /**
103      * Returns YANG resources module references for the given dataspace name.
104      *
105      * @param dataspaceName dataspace name
106      * @return Collection of all YANG resources module information in the database
107      */
108     Collection<ModuleReference> getYangResourceModuleReferences(String dataspaceName);
109
110     /**
111      * Get YANG resource module references for the given anchor name and dataspace name.
112      *
113      * @param dataspaceName dataspace name
114      * @param anchorName    anchor name
115      * @return a collection of module reference (moduleName and revision)
116      */
117     Collection<ModuleReference> getYangResourceModuleReferences(String dataspaceName, String anchorName);
118
119     /**
120      * Get YANG resource definitions for the given anchor name and dataspace name.
121      *
122      * @param dataspaceName dataspace name
123      * @param anchorName    anchor name
124      * @return a collection of module definitions (moduleName, revision and yang resource content)
125      */
126     Collection<ModuleDefinition> getYangResourceDefinitions(String dataspaceName, String anchorName);
127
128     /**
129      * Get YANG resource definitions for the given parameters.
130      *
131      * @param dataspaceName  dataspace name
132      * @param anchorName     anchor name
133      * @param moduleName     module name
134      * @param moduleRevision the revision of the module
135      * @return a collection of module definitions (moduleName, revision and yang resource content)
136      */
137     Collection<ModuleDefinition> getYangResourceDefinitionsByAnchorAndModule(String dataspaceName, String anchorName,
138                                                                              String moduleName, String moduleRevision);
139
140     /**
141      * Remove unused Yang Resource Modules.
142      */
143     void deleteUnusedYangResourceModules();
144
145     /**
146      * Identify new module references from those returned by a node compared to what is in CPS already.
147      * The system will ignore the namespace of all module references.
148      *
149      * @param moduleReferencesToCheck the module references ot check
150      * @returns Collection of {@link ModuleReference} (namespace will be always blank)
151      *
152      */
153     Collection<ModuleReference> identifyNewModuleReferences(
154         Collection<ModuleReference> moduleReferencesToCheck);
155
156 }