summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java/org/onap
diff options
context:
space:
mode:
authorrajesh.kumar <rk00747546@techmahindra.com>2022-09-14 05:11:32 +0000
committerrajesh.kumar <rk00747546@techmahindra.com>2022-12-09 09:57:44 +0000
commit71e4f8339e0240f90ad0a42a9360be52553f0d82 (patch)
tree8fe47799cde6365d40ee84de568b224fcdff22f5 /cps-ri/src/main/java/org/onap
parentfdaccbf398d84b7b19a95e11c017b5c6d2019ffe (diff)
Added API to get all schema sets for a given dataspace.
Issue-ID: CPS-1187 Change-ID: I73f97f986a817d423f93a8d922dcd9647b0914aa Signed-off-by: rajesh.kumar <rk00747546@techmahindra.com>
Diffstat (limited to 'cps-ri/src/main/java/org/onap')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java15
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java22
2 files changed, 37 insertions, 0 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
index 400e9b3e83..fdb1442b5f 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
@@ -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;
@@ -155,6 +157,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
// can occur in case of specific concurrent requests.
@@ -359,4 +369,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();
+ }
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java
index a15ce622c2..8cecb0a8e3 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 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.
@@ -19,7 +20,10 @@
package org.onap.cps.spi.repository;
+import java.util.Collection;
+import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
import javax.validation.constraints.NotNull;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.SchemaSetEntity;
@@ -33,6 +37,13 @@ public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Inte
Optional<SchemaSetEntity> findByDataspaceAndName(@NotNull DataspaceEntity dataspaceEntity,
@NotNull String schemaSetName);
+ /**
+ * Gets schema sets by dataspace.
+ * @param dataspaceEntity dataspace entity
+ * @return list of schema set entity
+ */
+ Collection<SchemaSetEntity> findByDataspace(@NotNull DataspaceEntity dataspaceEntity);
+
Integer countByDataspace(@NotNull DataspaceEntity dataspaceEntity);
/**
@@ -48,4 +59,15 @@ public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Inte
return findByDataspaceAndName(dataspaceEntity, schemaSetName)
.orElseThrow(() -> new SchemaSetNotFoundException(dataspaceEntity.getName(), schemaSetName));
}
+
+ /**
+ * Gets all schema sets for a given dataspace.
+ *
+ * @param dataspaceEntity dataspace entity
+ * @return list of schema set entity
+ * @throws SchemaSetNotFoundException if SchemaSet not found
+ */
+ default List<SchemaSetEntity> getByDataspace(@NotNull final DataspaceEntity dataspaceEntity) {
+ return findByDataspace(dataspaceEntity).stream().collect(Collectors.toList());
+ }
}