Merge "Added API to get all schema sets for a given dataspace."
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / impl / CpsModulePersistenceServiceImpl.java
index 8008e03..03f021e 100755 (executable)
@@ -3,6 +3,7 @@
  *  Copyright (C) 2020-2022 Nordix Foundation
  *  Modifications Copyright (C) 2020-2022 Bell Canada.
  *  Modifications Copyright (C) 2021 Pantheon.tech
+ *  Modifications Copyright (C) 2022 TechMahindra Ltd.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -55,6 +56,7 @@ import org.onap.cps.spi.exceptions.DuplicatedYangResourceException;
 import org.onap.cps.spi.exceptions.ModelValidationException;
 import org.onap.cps.spi.model.ModuleDefinition;
 import org.onap.cps.spi.model.ModuleReference;
+import org.onap.cps.spi.model.SchemaSet;
 import org.onap.cps.spi.repository.DataspaceRepository;
 import org.onap.cps.spi.repository.ModuleReferenceRepository;
 import org.onap.cps.spi.repository.SchemaSetRepository;
@@ -154,6 +156,14 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
         }
     }
 
+    @Override
+    public Collection<SchemaSet> getSchemaSetsByDataspaceName(final String dataspaceName) {
+        final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+        final List<SchemaSetEntity> schemaSetEntities = schemaSetRepository.getByDataspace(dataspaceEntity);
+        return schemaSetEntities.stream()
+                .map(CpsModulePersistenceServiceImpl::toSchemaSet).collect(Collectors.toList());
+    }
+
     @Override
     @Transactional
     // A retry is made to store the schema set if it fails because of duplicated yang resource exception that
@@ -364,4 +374,9 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
                 yangResourceEntity.getRevision(),
                 yangResourceEntity.getContent());
     }
+
+    private static SchemaSet toSchemaSet(final SchemaSetEntity schemaSetEntity) {
+        return SchemaSet.builder().name(schemaSetEntity.getName())
+                .dataspaceName(schemaSetEntity.getDataspace().getName()).build();
+    }
 }