- final Map<String, String> yangResourceNameToContent =
- cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName);
- final YangTextSchemaSourceSet yangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder
- .of(yangResourceNameToContent);
- return SchemaSet.builder()
- .name(schemaSetName)
- .dataspaceName(dataspaceName)
- .moduleReferences(yangTextSchemaSourceSet.getModuleReferences())
- .build();
+ final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache
+ .get(dataspaceName, schemaSetName);
+ return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName)
+ .extendedModuleReferences(yangTextSchemaSourceSet.getModuleReferences()).build();
+ }
+
+ @Override
+ @Transactional
+ public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
+ final CascadeDeleteAllowed 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);
+ yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName);
+ cpsModulePersistenceService.deleteUnusedYangResourceModules();
+ }
+
+ @Override
+ public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) {
+ return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName);
+ }
+
+ @Override
+ public Collection<ModuleReference> getYangResourcesModuleReferences(final String dataspaceName,
+ final String anchorName) {
+ return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName, anchorName);
+ }
+
+ private boolean isCascadeDeleteProhibited(final CascadeDeleteAllowed cascadeDeleteAllowed) {
+ return CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED == cascadeDeleteAllowed;