summaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/entities/SchemaSet.java71
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java63
-rw-r--r--[-rwxr-xr-x]cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java (renamed from cps-ri/src/main/java/org/onap/cps/spi/impl/FragmentPersistenceServiceImpl.java)145
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java111
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java58
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java4
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java36
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java34
-rwxr-xr-xcps-ri/src/main/resources/schema.sql26
9 files changed, 415 insertions, 133 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/SchemaSet.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/SchemaSet.java
new file mode 100644
index 0000000000..fe67a6089d
--- /dev/null
+++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/SchemaSet.java
@@ -0,0 +1,71 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Pantheon.tech
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.entities;
+
+import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.validation.constraints.NotNull;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * Entity to store a Schema Set.
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@Entity
+@Table(name = "schema_set")
+public class SchemaSet implements Serializable {
+
+ private static final long serialVersionUID = 6665056955069047269L;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+
+ @NotNull
+ @Column
+ private String name;
+
+ @NotNull
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "dataspace_id", referencedColumnName = "ID")
+ private Dataspace dataspace;
+
+ @NotNull
+ @ManyToMany(fetch = FetchType.LAZY)
+ @JoinTable(name = "schema_set_yang_resources",
+ joinColumns = @JoinColumn(name = "schema_set_id"),
+ inverseJoinColumns = @JoinColumn(name = "yang_resource_id"))
+ private Set<YangResource> yangResources;
+}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java
new file mode 100644
index 0000000000..862b7aea64
--- /dev/null
+++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java
@@ -0,0 +1,63 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Pantheon.tech
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.entities;
+
+import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+import javax.validation.constraints.NotNull;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * Entity to store a Yang files.
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@Entity
+@Table(name = "yang_resource")
+public class YangResource implements Serializable {
+
+ private static final long serialVersionUID = -4496883162142106774L;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ @NotNull
+ @Column
+ private String checksum;
+
+ @NotNull
+ @Column
+ private String content;
+
+ @ManyToMany(mappedBy = "yangResources")
+ private Set<SchemaSet> moduleSets;
+
+}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/FragmentPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
index 82554b3d0a..684750c459 100755..100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/FragmentPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
@@ -1,72 +1,73 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.spi.impl;
-
-import org.onap.cps.api.model.AnchorDetails;
-import org.onap.cps.exceptions.CpsNotFoundException;
-import org.onap.cps.exceptions.CpsValidationException;
-import org.onap.cps.spi.FragmentPersistenceService;
-import org.onap.cps.spi.entities.Dataspace;
-import org.onap.cps.spi.entities.Fragment;
-import org.onap.cps.spi.entities.Module;
-import org.onap.cps.spi.repository.DataspaceRepository;
-import org.onap.cps.spi.repository.FragmentRepository;
-import org.onap.cps.spi.repository.ModuleRepository;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataIntegrityViolationException;
-import org.springframework.stereotype.Component;
-
-@Component
-public class FragmentPersistenceServiceImpl implements FragmentPersistenceService {
-
- @Autowired
- private DataspaceRepository dataspaceRepository;
-
- @Autowired
- private FragmentRepository fragmentRepository;
-
- @Autowired
- private ModuleRepository moduleRepository;
-
- @Override
- public String createAnchor(final AnchorDetails anchorDetails) {
- try {
- final Dataspace dataspace = dataspaceRepository.getByName(anchorDetails.getDataspace());
- final Module module =
- moduleRepository.getByDataspaceAndNamespaceAndRevision(dataspace,
- anchorDetails.getNamespace(), anchorDetails.getRevision());
-
- final Fragment fragment = Fragment.builder().xpath(anchorDetails.getAnchorName())
- .anchorName(anchorDetails.getAnchorName())
- .dataspace(dataspace).module(module).build();
-
- fragmentRepository.save(fragment);
- return anchorDetails.getAnchorName();
- } catch (final CpsNotFoundException ex) {
- throw new CpsValidationException("Validation Error",
- "Dataspace and/or Module do not exist.");
- } catch (final DataIntegrityViolationException ex) {
- throw new CpsValidationException("Duplication Error",
- String.format("Anchor with name %s already exist in dataspace %s.",
- anchorDetails.getAnchorName(), anchorDetails.getDataspace()));
- }
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.impl;
+
+import org.onap.cps.exceptions.CpsNotFoundException;
+import org.onap.cps.exceptions.CpsValidationException;
+import org.onap.cps.spi.CpsAdminPersistenceService;
+import org.onap.cps.spi.entities.Dataspace;
+import org.onap.cps.spi.entities.Fragment;
+import org.onap.cps.spi.entities.Module;
+import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.repository.DataspaceRepository;
+import org.onap.cps.spi.repository.FragmentRepository;
+import org.onap.cps.spi.repository.ModuleRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.stereotype.Component;
+
+@Component
+public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceService {
+
+ @Autowired
+ private DataspaceRepository dataspaceRepository;
+
+ @Autowired
+ private FragmentRepository fragmentRepository;
+
+ @Autowired
+ private ModuleRepository moduleRepository;
+
+ @Override
+ public String createAnchor(final Anchor anchor) {
+ final String anchorName = anchor.getAnchorName();
+ try {
+ final Dataspace dataspace = dataspaceRepository.getByName(anchor.getDataspaceName());
+ final Module module =
+ moduleRepository.getByDataspaceAndNamespaceAndRevision(dataspace,
+ anchor.getNamespace(), anchor.getRevision());
+
+ final Fragment fragment = Fragment.builder().xpath(anchorName)
+ .anchorName(anchorName)
+ .dataspace(dataspace).module(module).build();
+
+ fragmentRepository.save(fragment);
+ return anchorName;
+ } catch (final CpsNotFoundException ex) {
+ throw new CpsValidationException("Validation Error",
+ "Dataspace and/or Module do not exist.");
+ } catch (final DataIntegrityViolationException ex) {
+ throw new CpsValidationException("Duplication Error",
+ String.format("Anchor with name %s already exist in dataspace %s.",
+ anchorName, anchor.getDataspaceName()));
+ }
+ }
+}
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
new file mode 100644
index 0000000000..52f8034575
--- /dev/null
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
@@ -0,0 +1,111 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.impl;
+
+import static org.onap.cps.exceptions.CpsExceptionBuilder.duplicateSchemaSetException;
+import static org.onap.cps.exceptions.CpsExceptionBuilder.invalidDataspaceException;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.transaction.Transactional;
+import org.onap.cps.spi.CpsModulePersistenceService;
+import org.onap.cps.spi.entities.Dataspace;
+import org.onap.cps.spi.entities.SchemaSet;
+import org.onap.cps.spi.entities.YangResource;
+import org.onap.cps.spi.repository.DataspaceRepository;
+import org.onap.cps.spi.repository.SchemaSetRepository;
+import org.onap.cps.spi.repository.YangResourceRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.stereotype.Component;
+import org.springframework.util.DigestUtils;
+
+@Component
+public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceService {
+
+ @Autowired
+ private YangResourceRepository yangResourceRepository;
+
+ @Autowired
+ private SchemaSetRepository schemaSetRepository;
+
+ @Autowired
+ private DataspaceRepository dataspaceRepository;
+
+ @Override
+ public void storeModule(final String namespace, final String moduleContent, final String revision,
+ final String dataspaceName) {
+ // TODO this method should be removed as obsolete.
+ // Modules to be processed within schema sets only.
+ }
+
+ @Override
+ @Transactional
+ public void storeSchemaSet(final String dataspaceName, final String schemaSetName,
+ final Set<String> yangResourcesAsStrings) {
+
+ final Dataspace dataspace = dataspaceRepository.findByName(dataspaceName)
+ .orElseThrow(() -> invalidDataspaceException(dataspaceName));
+
+ final Set<YangResource> yangResources = synchronizeYangResources(yangResourcesAsStrings);
+ final SchemaSet schemaSet = new SchemaSet();
+ schemaSet.setName(schemaSetName);
+ schemaSet.setDataspace(dataspace);
+ schemaSet.setYangResources(yangResources);
+ try {
+ schemaSetRepository.save(schemaSet);
+ } catch (final DataIntegrityViolationException e) {
+ throw duplicateSchemaSetException(dataspaceName, schemaSetName);
+ }
+ }
+
+ private Set<YangResource> synchronizeYangResources(final Set<String> yangResourcesAsStrings) {
+ final Map<String, String> checksumToContentMap = yangResourcesAsStrings.stream()
+ .collect(Collectors.toMap(
+ content -> DigestUtils.md5DigestAsHex(content.getBytes()),
+ content -> content)
+ );
+
+ final List<YangResource> existingYangResources =
+ yangResourceRepository.findAllByChecksumIn(checksumToContentMap.keySet());
+ existingYangResources.forEach(yangFile -> checksumToContentMap.remove(yangFile.getChecksum()));
+
+ final List<YangResource> newYangResources = checksumToContentMap.entrySet().stream()
+ .map(entry -> {
+ final YangResource yangResource = new YangResource();
+ yangResource.setChecksum(entry.getKey());
+ yangResource.setContent(entry.getValue());
+ return yangResource;
+ }).collect(Collectors.toList());
+ if (!newYangResources.isEmpty()) {
+ yangResourceRepository.saveAll(newYangResources);
+ }
+
+ return ImmutableSet.<YangResource>builder()
+ .addAll(existingYangResources)
+ .addAll(newYangResources)
+ .build();
+ }
+
+}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java
deleted file mode 100755
index 03679b3160..0000000000
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistenceServiceImpl.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.spi.impl;
-
-import org.onap.cps.exceptions.CpsValidationException;
-import org.onap.cps.spi.ModelPersistenceService;
-import org.onap.cps.spi.entities.Dataspace;
-import org.onap.cps.spi.entities.Module;
-import org.onap.cps.spi.repository.DataspaceRepository;
-import org.onap.cps.spi.repository.ModuleRepository;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataIntegrityViolationException;
-import org.springframework.stereotype.Component;
-
-@Component
-public class ModelPersistenceServiceImpl implements ModelPersistenceService {
-
- @Autowired
- private ModuleRepository moduleRepository;
-
- @Autowired
- private DataspaceRepository dataspaceRepository;
-
- @Override
- public void storeModule(final String namespace, final String moduleContent, final String revision,
- final String dataspaceName) {
- final Dataspace dataspace = new Dataspace(dataspaceName);
- if (Boolean.FALSE.equals(dataspaceRepository.existsByName(dataspaceName))) {
- dataspaceRepository.save(dataspace);
- }
- dataspace.setId(dataspaceRepository.getByName(dataspaceName).getId());
- final Module module = new Module(namespace, moduleContent, revision, dataspace);
- try {
- moduleRepository.save(module);
- } catch (final DataIntegrityViolationException ex) {
- throw new CpsValidationException("Duplicate Entry",
- String.format("Module already exist in dataspace %s.", dataspaceName));
- }
- }
-}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java
index daf0b716b7..4b649167f3 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java
@@ -21,7 +21,7 @@ package org.onap.cps.spi.repository;
import java.util.Optional;
import javax.validation.constraints.NotNull;
-import org.onap.cps.exceptions.CpsNotFoundException;
+import org.onap.cps.exceptions.DataspaceNotFoundException;
import org.onap.cps.spi.entities.Dataspace;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -34,6 +34,6 @@ public interface DataspaceRepository extends JpaRepository<Dataspace, Integer> {
default Dataspace getByName(@NotNull String name) {
return findByName(name).orElseThrow(
- () -> new CpsNotFoundException("Not Found", "Dataspace " + name + " does not exist."));
+ () -> new DataspaceNotFoundException("Dataspace " + name + " does not exist."));
}
} \ No newline at end of file
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
new file mode 100644
index 0000000000..f9746972f3
--- /dev/null
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Pantheon.tech
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.repository;
+
+import java.util.List;
+import java.util.Optional;
+import javax.validation.constraints.NotNull;
+import org.onap.cps.spi.entities.Dataspace;
+import org.onap.cps.spi.entities.SchemaSet;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface SchemaSetRepository extends JpaRepository<SchemaSet, Integer> {
+
+ List<SchemaSet> findAllByDataspace(@NotNull Dataspace dataspace);
+
+ Optional<SchemaSet> findByDataspaceAndName(@NotNull Dataspace dataspace, @NotNull String name);
+}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
new file mode 100644
index 0000000000..47d3ea32cf
--- /dev/null
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
@@ -0,0 +1,34 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Pantheon.tech
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.repository;
+
+import java.util.List;
+import java.util.Set;
+import javax.validation.constraints.NotNull;
+import org.onap.cps.spi.entities.YangResource;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface YangResourceRepository extends JpaRepository<YangResource, Long> {
+
+ List<YangResource> findAllByChecksumIn(@NotNull Set<String> checksum);
+
+}
diff --git a/cps-ri/src/main/resources/schema.sql b/cps-ri/src/main/resources/schema.sql
index 3fabc6c9f9..d47f261add 100755
--- a/cps-ri/src/main/resources/schema.sql
+++ b/cps-ri/src/main/resources/schema.sql
@@ -17,6 +17,30 @@ CREATE TABLE IF NOT EXISTS SCHEMA_NODE
ID SERIAL PRIMARY KEY
);
+CREATE TABLE IF NOT EXISTS SCHEMA_SET
+(
+ ID SERIAL PRIMARY KEY,
+ NAME TEXT NOT NULL,
+ DATASPACE_ID BIGINT NOT NULL,
+ UNIQUE (NAME, DATASPACE_ID),
+ CONSTRAINT SCHEMA_SET_DATASPACE FOREIGN KEY (DATASPACE_ID) REFERENCES DATASPACE(ID) ON UPDATE CASCADE ON DELETE CASCADE
+);
+
+CREATE TABLE IF NOT EXISTS YANG_RESOURCE
+(
+ ID SERIAL PRIMARY KEY,
+ CHECKSUM TEXT NOT NULL,
+ CONTENT TEXT NOT NULL,
+ UNIQUE (CHECKSUM)
+);
+
+CREATE TABLE IF NOT EXISTS SCHEMA_SET_YANG_RESOURCES
+(
+ SCHEMA_SET_ID BIGINT NOT NULL,
+ YANG_RESOURCE_ID BIGINT NOT NULL REFERENCES YANG_RESOURCE(ID),
+ CONSTRAINT SCHEMA_SET_RESOURCE FOREIGN KEY (SCHEMA_SET_ID) REFERENCES SCHEMA_SET(ID) ON DELETE CASCADE
+);
+
CREATE TABLE IF NOT EXISTS MODULE
(
ID SERIAL PRIMARY KEY,
@@ -62,4 +86,4 @@ CREATE INDEX IF NOT EXISTS "FKI_RELATION_TYPE_ID_FK" ON RELATION USING
CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_FROM_ID_FK" ON RELATION USING BTREE(FROM_FRAGMENT_ID);
CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_TO_ID_FK" ON RELATION USING BTREE(TO_FRAGMENT_ID);
CREATE INDEX IF NOT EXISTS "PERF_MODULE_MODULE_CONTENT" ON MODULE USING BTREE(MODULE_CONTENT);
-CREATE UNIQUE INDEX IF NOT EXISTS "UQ_FRAGMENT_XPATH"ON FRAGMENT USING btree(xpath COLLATE pg_catalog."default" text_pattern_ops, dataspace_id); \ No newline at end of file
+CREATE UNIQUE INDEX IF NOT EXISTS "UQ_FRAGMENT_XPATH"ON FRAGMENT USING btree(xpath COLLATE pg_catalog."default" text_pattern_ops, dataspace_id);