Merge "Rename entity artifacts, remove obsolete entities"
authorToine Siebelink <toine.siebelink@est.tech>
Wed, 13 Jan 2021 16:25:54 +0000 (16:25 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 13 Jan 2021 16:25:54 +0000 (16:25 +0000)
17 files changed:
cps-ri/src/main/java/org/onap/cps/spi/entities/AnchorEntity.java
cps-ri/src/main/java/org/onap/cps/spi/entities/DataspaceEntity.java [moved from cps-ri/src/main/java/org/onap/cps/spi/entities/Dataspace.java with 94% similarity]
cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntity.java [moved from cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java with 92% similarity]
cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java [deleted file]
cps-ri/src/main/java/org/onap/cps/spi/entities/Module.java [deleted file]
cps-ri/src/main/java/org/onap/cps/spi/entities/SchemaSetEntity.java [moved from cps-ri/src/main/java/org/onap/cps/spi/entities/SchemaSet.java with 93% similarity]
cps-ri/src/main/java/org/onap/cps/spi/entities/YangResourceEntity.java [moved from cps-ri/src/main/java/org/onap/cps/spi/entities/YangResource.java with 94% similarity]
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java
cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java [deleted file]
cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java
cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
cps-ri/src/test/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceTest.java

index e7e9c97..b893428 100644 (file)
@@ -61,10 +61,10 @@ public class AnchorEntity implements Serializable {
     @NotNull
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "schema_set_id")
-    private SchemaSet schemaSet;
+    private SchemaSetEntity schemaSet;
 
     @NotNull
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "dataspace_id")
-    private Dataspace dataspace;
+    private DataspaceEntity dataspace;
 }
@@ -42,7 +42,7 @@ import lombok.Setter;
 @AllArgsConstructor
 @NoArgsConstructor
 @Table(name = "dataspace")
-public class Dataspace implements Serializable {
+public class DataspaceEntity implements Serializable {
 
     private static final long serialVersionUID = 8395254649813051882L;
 
@@ -59,7 +59,7 @@ public class Dataspace implements Serializable {
      *
      * @param name the Dataspace name.
      */
-    public Dataspace(final String name) {
+    public DataspaceEntity(final String name) {
         this.name = name;
     }
 }
\ No newline at end of file
@@ -1,82 +1,82 @@
-/*-\r
- * ============LICENSE_START=======================================================\r
- *  Copyright (C) 2020 Nordix Foundation. All rights reserved.\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * SPDX-License-Identifier: Apache-2.0\r
- * ============LICENSE_END=========================================================\r
- */\r
-\r
-package org.onap.cps.spi.entities;\r
-\r
-import com.vladmihalcea.hibernate.type.json.JsonBinaryType;\r
-import java.io.Serializable;\r
-import javax.persistence.Column;\r
-import javax.persistence.Entity;\r
-import javax.persistence.FetchType;\r
-import javax.persistence.GeneratedValue;\r
-import javax.persistence.GenerationType;\r
-import javax.persistence.Id;\r
-import javax.persistence.JoinColumn;\r
-import javax.persistence.ManyToOne;\r
-import javax.persistence.OneToOne;\r
-import javax.validation.constraints.NotNull;\r
-import lombok.AllArgsConstructor;\r
-import lombok.Builder;\r
-import lombok.Getter;\r
-import lombok.NoArgsConstructor;\r
-import lombok.Setter;\r
-import org.hibernate.annotations.Type;\r
-import org.hibernate.annotations.TypeDef;\r
-import org.hibernate.annotations.TypeDefs;\r
-\r
-/**\r
- * Entity to store a fragment.\r
- */\r
-@Getter\r
-@Setter\r
-@AllArgsConstructor\r
-@NoArgsConstructor\r
-@Builder\r
-@Entity\r
-@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)})\r
-public class Fragment implements Serializable {\r
-\r
-    private static final long serialVersionUID = 7737669789097119667L;\r
-\r
-    @Id\r
-    @GeneratedValue(strategy = GenerationType.IDENTITY)\r
-    private Long id;\r
-\r
-    @NotNull\r
-    @Column(columnDefinition = "text")\r
-    private String xpath;\r
-\r
-    @Type(type = "jsonb")\r
-    @Column(columnDefinition = "jsonb")\r
-    private String attributes;\r
-\r
-    @NotNull\r
-    @ManyToOne(fetch = FetchType.LAZY)\r
-    @JoinColumn(name = "dataspace_id")\r
-    private Dataspace dataspace;\r
-\r
-    @OneToOne(fetch = FetchType.LAZY)\r
-    @JoinColumn(name = "anchor_id")\r
-    private AnchorEntity anchor;\r
-\r
-    @OneToOne(fetch = FetchType.LAZY)\r
-    @JoinColumn(name = "parent_id")\r
-    private Fragment parentFragment;\r
-}\r
+/*-
+ * ============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.entities;
+
+import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
+import java.io.Serializable;
+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.ManyToOne;
+import javax.persistence.OneToOne;
+import javax.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.TypeDefs;
+
+/**
+ * Entity to store a fragment.
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@Entity
+@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)})
+public class FragmentEntity implements Serializable {
+
+    private static final long serialVersionUID = 7737669789097119667L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Long id;
+
+    @NotNull
+    @Column(columnDefinition = "text")
+    private String xpath;
+
+    @Type(type = "jsonb")
+    @Column(columnDefinition = "jsonb")
+    private String attributes;
+
+    @NotNull
+    @ManyToOne(fetch = FetchType.LAZY)
+    @JoinColumn(name = "dataspace_id")
+    private DataspaceEntity dataspace;
+
+    @OneToOne(fetch = FetchType.LAZY)
+    @JoinColumn(name = "anchor_id")
+    private AnchorEntity anchor;
+
+    @OneToOne(fetch = FetchType.LAZY)
+    @JoinColumn(name = "parent_id")
+    private FragmentEntity parentFragment;
+}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java
deleted file mode 100644 (file)
index bd147bf..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2020 Nordix Foundation
- *  ================================================================================
- *  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 javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-/**
- * Entity to store a JSON data structure.
- */
-@Getter
-@Setter
-@Entity
-@AllArgsConstructor
-@NoArgsConstructor
-@Table(name = "JsonData")
-public class JsonDataEntity {
-
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    private Integer id;
-
-    @Column
-    private String jsonStructure;
-
-    public JsonDataEntity(final String jsonStructure) {
-        this.jsonStructure = jsonStructure;
-    }
-}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/Module.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/Module.java
deleted file mode 100755 (executable)
index 7043c73..0000000
+++ /dev/null
@@ -1,87 +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.entities;
-
-import java.io.Serializable;
-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.ManyToOne;
-import javax.persistence.Table;
-import javax.validation.constraints.NotNull;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-/**
- * Entity to store a yang module.
- */
-@Getter
-@Setter
-@Entity
-@AllArgsConstructor
-@NoArgsConstructor
-@Table(name = "module")
-public class Module implements Serializable {
-
-    private static final long serialVersionUID = -748666970938314895L;
-
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    private Integer id;
-
-    @NotNull
-    @Column
-    private String moduleContent;
-
-    @NotNull
-    @Column
-    private String revision;
-
-    @ManyToOne(fetch = FetchType.LAZY)
-    @JoinColumn(name = "dataspace_id", referencedColumnName = "ID")
-    private Dataspace dataspace;
-
-    @NotNull
-    @Column
-    private String namespace;
-
-    /**
-     * Initialize a module entity.
-     *
-     * @param namespace     the module namespace.
-     * @param moduleContent the module content.
-     * @param revision      the revision number of the module.
-     * @param dataspace     the dataspace related to the module.
-     */
-    public Module(final String namespace, final String moduleContent, final String revision,
-            final Dataspace dataspace) {
-        this.namespace = namespace;
-        this.moduleContent = moduleContent;
-        this.revision = revision;
-        this.dataspace = dataspace;
-    }
-}
\ No newline at end of file
@@ -45,7 +45,7 @@ import lombok.Setter;
 @NoArgsConstructor
 @Entity
 @Table(name = "schema_set")
-public class SchemaSet implements Serializable {
+public class SchemaSetEntity implements Serializable {
 
     private static final long serialVersionUID = 6665056955069047269L;
 
@@ -60,12 +60,12 @@ public class SchemaSet implements Serializable {
     @NotNull
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "dataspace_id", referencedColumnName = "ID")
-    private Dataspace dataspace;
+    private DataspaceEntity 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;
+    private Set<YangResourceEntity> yangResources;
 }
@@ -41,7 +41,7 @@ import lombok.Setter;
 @NoArgsConstructor
 @Entity
 @Table(name = "yang_resource")
-public class YangResource implements Serializable {
+public class YangResourceEntity implements Serializable {
 
     private static final long serialVersionUID = -4496883162142106774L;
 
@@ -62,6 +62,6 @@ public class YangResource implements Serializable {
     private String content;
 
     @ManyToMany(mappedBy = "yangResources")
-    private Set<SchemaSet> moduleSets;
+    private Set<SchemaSetEntity> schemaSets;
 
 }
index fdb446c..dfe3ecc 100644 (file)
@@ -25,8 +25,8 @@ import java.util.Collection;
 import java.util.stream.Collectors;
 import org.onap.cps.spi.CpsAdminPersistenceService;
 import org.onap.cps.spi.entities.AnchorEntity;
-import org.onap.cps.spi.entities.Dataspace;
-import org.onap.cps.spi.entities.SchemaSet;
+import org.onap.cps.spi.entities.DataspaceEntity;
+import org.onap.cps.spi.entities.SchemaSetEntity;
 import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
 import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException;
 import org.onap.cps.spi.model.Anchor;
@@ -52,7 +52,7 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
     @Override
     public void createDataspace(final String dataspaceName) {
         try {
-            dataspaceRepository.save(new Dataspace(dataspaceName));
+            dataspaceRepository.save(new DataspaceEntity(dataspaceName));
         } catch (final DataIntegrityViolationException e) {
             throw new DataspaceAlreadyDefinedException(dataspaceName, e);
         }
@@ -60,12 +60,13 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
 
     @Override
     public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
-        final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
-        final SchemaSet schemaSet = schemaSetRepository.getByDataspaceAndName(dataspace, schemaSetName);
+        final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+        final SchemaSetEntity schemaSetEntity =
+            schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
         final AnchorEntity anchorEntity = AnchorEntity.builder()
             .name(anchorName)
-            .dataspace(dataspace)
-            .schemaSet(schemaSet)
+            .dataspace(dataspaceEntity)
+            .schemaSet(schemaSetEntity)
             .build();
         try {
             anchorRepository.save(anchorEntity);
@@ -76,8 +77,8 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
 
     @Override
     public Collection<Anchor> getAnchors(final String dataspaceName) {
-        final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
-        final Collection<AnchorEntity> anchorEntities = anchorRepository.findAllByDataspace(dataspace);
+        final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+        final Collection<AnchorEntity> anchorEntities = anchorRepository.findAllByDataspace(dataspaceEntity);
         return anchorEntities.stream().map(CpsAdminPersistenceServiceImpl::toAnchor).collect(Collectors.toList());
     }
 
index 0832930..cbc945d 100644 (file)
@@ -29,9 +29,9 @@ 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.entities.DataspaceEntity;
+import org.onap.cps.spi.entities.SchemaSetEntity;
+import org.onap.cps.spi.entities.YangResourceEntity;
 import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException;
 import org.onap.cps.spi.repository.DataspaceRepository;
 import org.onap.cps.spi.repository.SchemaSetRepository;
@@ -58,53 +58,55 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
     public void storeSchemaSet(final String dataspaceName, final String schemaSetName,
         final Map<String, String> yangResourcesNameToContentMap) {
 
-        final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
-        final Set<YangResource> yangResources = synchronizeYangResources(yangResourcesNameToContentMap);
-        final SchemaSet schemaSet = new SchemaSet();
-        schemaSet.setName(schemaSetName);
-        schemaSet.setDataspace(dataspace);
-        schemaSet.setYangResources(yangResources);
+        final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+        final Set<YangResourceEntity> yangResourceEntities = synchronizeYangResources(yangResourcesNameToContentMap);
+        final SchemaSetEntity schemaSetEntity = new SchemaSetEntity();
+        schemaSetEntity.setName(schemaSetName);
+        schemaSetEntity.setDataspace(dataspaceEntity);
+        schemaSetEntity.setYangResources(yangResourceEntities);
         try {
-            schemaSetRepository.save(schemaSet);
+            schemaSetRepository.save(schemaSetEntity);
         } catch (final DataIntegrityViolationException e) {
             throw new SchemaSetAlreadyDefinedException(dataspaceName, schemaSetName, e);
         }
     }
 
-    private Set<YangResource> synchronizeYangResources(final Map<String, String> yangResourcesNameToContentMap) {
-        final Map<String, YangResource> checksumToEntityMap = yangResourcesNameToContentMap.entrySet().stream()
+    private Set<YangResourceEntity> synchronizeYangResources(final Map<String, String> yangResourcesNameToContentMap) {
+        final Map<String, YangResourceEntity> checksumToEntityMap = yangResourcesNameToContentMap.entrySet().stream()
             .map(entry -> {
-                final YangResource yangResource = new YangResource();
-                yangResource.setName(entry.getKey());
-                yangResource.setContent(entry.getValue());
-                yangResource.setChecksum(DigestUtils.md5DigestAsHex(entry.getValue().getBytes(StandardCharsets.UTF_8)));
-                return yangResource;
+                final String checksum = DigestUtils.md5DigestAsHex(entry.getValue().getBytes(StandardCharsets.UTF_8));
+                final YangResourceEntity yangResourceEntity = new YangResourceEntity();
+                yangResourceEntity.setName(entry.getKey());
+                yangResourceEntity.setContent(entry.getValue());
+                yangResourceEntity.setChecksum(checksum);
+                return yangResourceEntity;
             })
             .collect(Collectors.toMap(
-                YangResource::getChecksum,
+                YangResourceEntity::getChecksum,
                 entity -> entity
             ));
 
-        final List<YangResource> existingYangResources =
+        final List<YangResourceEntity> existingYangResourceEntities =
             yangResourceRepository.findAllByChecksumIn(checksumToEntityMap.keySet());
-        existingYangResources.forEach(yangFile -> checksumToEntityMap.remove(yangFile.getChecksum()));
+        existingYangResourceEntities.forEach(yangFile -> checksumToEntityMap.remove(yangFile.getChecksum()));
 
-        final Collection<YangResource> newYangResources = checksumToEntityMap.values();
-        if (!newYangResources.isEmpty()) {
-            yangResourceRepository.saveAll(newYangResources);
+        final Collection<YangResourceEntity> newYangResourceEntities = checksumToEntityMap.values();
+        if (!newYangResourceEntities.isEmpty()) {
+            yangResourceRepository.saveAll(newYangResourceEntities);
         }
 
-        return ImmutableSet.<YangResource>builder()
-            .addAll(existingYangResources)
-            .addAll(newYangResources)
+        return ImmutableSet.<YangResourceEntity>builder()
+            .addAll(existingYangResourceEntities)
+            .addAll(newYangResourceEntities)
             .build();
     }
 
     @Override
     public Map<String, String> getYangSchemaResources(final String dataspaceName, final String schemaSetName) {
-        final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
-        final SchemaSet schemaSet = schemaSetRepository.getByDataspaceAndName(dataspace, schemaSetName);
-        return schemaSet.getYangResources().stream().collect(
-            Collectors.toMap(YangResource::getName, YangResource::getContent));
+        final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+        final SchemaSetEntity schemaSetEntity =
+            schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
+        return schemaSetEntity.getYangResources().stream().collect(
+            Collectors.toMap(YangResourceEntity::getName, YangResourceEntity::getContent));
     }
 }
index df665f9..318b4da 100644 (file)
@@ -23,11 +23,12 @@ import java.util.Collection;
 import java.util.Optional;
 import javax.validation.constraints.NotNull;
 import org.onap.cps.spi.entities.AnchorEntity;
-import org.onap.cps.spi.entities.Dataspace;
+import org.onap.cps.spi.entities.DataspaceEntity;
 import org.springframework.data.jpa.repository.JpaRepository;
 
 public interface AnchorRepository extends JpaRepository<AnchorEntity, Integer> {
-    Optional<AnchorEntity> findByDataspaceAndName(@NotNull Dataspace dataspace, @NotNull String name);
 
-    Collection<AnchorEntity> findAllByDataspace(@NotNull Dataspace dataspace);
+    Optional<AnchorEntity> findByDataspaceAndName(@NotNull DataspaceEntity dataspaceEntity, @NotNull String name);
+
+    Collection<AnchorEntity> findAllByDataspace(@NotNull DataspaceEntity dataspaceEntity);
 }
index ce231c9..10c6541 100755 (executable)
@@ -21,16 +21,15 @@ package org.onap.cps.spi.repository;
 
 import java.util.Optional;
 import javax.validation.constraints.NotNull;
-import org.onap.cps.spi.entities.Dataspace;
+import org.onap.cps.spi.entities.DataspaceEntity;
 import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
 
 @Repository
-public interface DataspaceRepository extends JpaRepository<Dataspace, Integer> {
-    Boolean existsByName(String name); //Checks if there are any records by name()
+public interface DataspaceRepository extends JpaRepository<DataspaceEntity, Integer> {
 
-    Optional<Dataspace> findByName(@NotNull String name);
+    Optional<DataspaceEntity> findByName(@NotNull String name);
 
     /**
      * Get a dataspace by name.
@@ -39,7 +38,7 @@ public interface DataspaceRepository extends JpaRepository<Dataspace, Integer> {
      * @param name the name of the dataspace
      * @return the Dataspace found
      */
-    default Dataspace getByName(@NotNull final String name) {
+    default DataspaceEntity getByName(@NotNull final String name) {
         return findByName(name).orElseThrow(() -> new DataspaceNotFoundException(name));
     }
 }
index 4521d09..28585f8 100755 (executable)
 \r
 package org.onap.cps.spi.repository;\r
 \r
-import org.onap.cps.spi.entities.Fragment;\r
+import org.onap.cps.spi.entities.FragmentEntity;\r
 import org.springframework.data.jpa.repository.JpaRepository;\r
 import org.springframework.stereotype.Repository;\r
 \r
 @Repository\r
-public interface FragmentRepository extends JpaRepository<Fragment, Long> {\r
+public interface FragmentRepository extends JpaRepository<FragmentEntity, Long> {\r
 \r
 }
\ No newline at end of file
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java
deleted file mode 100755 (executable)
index cab7e19..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2020 Nordix Foundation
- *  ================================================================================
- *  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.Optional;
-import javax.validation.constraints.NotNull;
-import org.onap.cps.spi.entities.Dataspace;
-import org.onap.cps.spi.entities.Module;
-import org.onap.cps.spi.exceptions.NotFoundInDataspaceException;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
-
-@Repository
-public interface ModuleRepository extends JpaRepository<Module, Integer> {
-
-    Optional<Module> findByDataspaceAndNamespaceAndRevision(@NotNull Dataspace dataspace,
-            @NotNull String namespace,
-            @NotNull String revision);
-
-    /**
-     * This method gets a Module by dataspace, namespace and revision.
-     *
-     * @param dataspace the dataspace
-     * @param namespace the namespace
-     * @param revision  the revision
-     * @return the Module
-     * @throws NotFoundInDataspaceException if Module not found
-     */
-    default Module getByDataspaceAndNamespaceAndRevision(@NotNull final Dataspace dataspace,
-            @NotNull final String namespace,
-            @NotNull final String revision) {
-        return findByDataspaceAndNamespaceAndRevision(dataspace, namespace, revision)
-                .orElseThrow(() -> new NotFoundInDataspaceException("Validation Error", String.format(
-                        "Module with dataspace %s, revision %s does not exist in namespace %s.",
-                        dataspace.getName(), revision, namespace)));
-    }
-}
index 9b9d706..7b56f93 100644 (file)
@@ -22,29 +22,31 @@ 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.onap.cps.spi.entities.DataspaceEntity;
+import org.onap.cps.spi.entities.SchemaSetEntity;
 import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
 
 @Repository
-public interface SchemaSetRepository extends JpaRepository<SchemaSet, Integer> {
+public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Integer> {
 
-    List<SchemaSet> findAllByDataspace(@NotNull Dataspace dataspace);
+    List<SchemaSetEntity> findAllByDataspace(@NotNull DataspaceEntity dataspaceEntity);
 
-    Optional<SchemaSet> findByDataspaceAndName(@NotNull Dataspace dataspace, @NotNull String schemaSetName);
+    Optional<SchemaSetEntity> findByDataspaceAndName(@NotNull DataspaceEntity dataspaceEntity,
+        @NotNull String schemaSetName);
 
     /**
      * Gets a schema set by dataspace and schema set name.
      *
-     * @param dataspace     dataspace entity
-     * @param schemaSetName schema set name
+     * @param dataspaceEntity dataspace entity
+     * @param schemaSetName   schema set name
      * @return schema set entity
      * @throws SchemaSetNotFoundException if SchemaSet not found
      */
-    default SchemaSet getByDataspaceAndName(@NotNull final Dataspace dataspace, @NotNull final String schemaSetName) {
-        return findByDataspaceAndName(dataspace, schemaSetName)
-            .orElseThrow(() -> new SchemaSetNotFoundException(dataspace.getName(), schemaSetName));
+    default SchemaSetEntity getByDataspaceAndName(@NotNull final DataspaceEntity dataspaceEntity,
+        @NotNull final String schemaSetName) {
+        return findByDataspaceAndName(dataspaceEntity, schemaSetName)
+            .orElseThrow(() -> new SchemaSetNotFoundException(dataspaceEntity.getName(), schemaSetName));
     }
 }
index 47d3ea3..8e57f63 100644 (file)
@@ -22,13 +22,13 @@ 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.onap.cps.spi.entities.YangResourceEntity;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.stereotype.Repository;
 
 @Repository
-public interface YangResourceRepository extends JpaRepository<YangResource, Long> {
+public interface YangResourceRepository extends JpaRepository<YangResourceEntity, Long> {
 
-    List<YangResource> findAllByChecksumIn(@NotNull Set<String> checksum);
+    List<YangResourceEntity> findAllByChecksumIn(@NotNull Set<String> checksum);
 
 }
index e5aac1e..0248707 100644 (file)
@@ -30,7 +30,7 @@ import org.junit.runner.RunWith;
 import org.onap.cps.DatabaseTestContainer;
 import org.onap.cps.spi.CpsAdminPersistenceService;
 import org.onap.cps.spi.entities.AnchorEntity;
-import org.onap.cps.spi.entities.Dataspace;
+import org.onap.cps.spi.entities.DataspaceEntity;
 import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
 import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException;
 import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
@@ -83,10 +83,10 @@ public class CpsAdminPersistenceServiceTest {
         final String dataspaceName = "DATASPACE-NEW";
         cpsAdminPersistenceService.createDataspace(dataspaceName);
 
-        final Dataspace dataspace = dataspaceRepository.findByName(dataspaceName).orElseThrow();
-        assertNotNull(dataspace);
-        assertNotNull(dataspace.getId());
-        assertEquals(dataspaceName, dataspace.getName());
+        final DataspaceEntity dataspaceEntity = dataspaceRepository.findByName(dataspaceName).orElseThrow();
+        assertNotNull(dataspaceEntity);
+        assertNotNull(dataspaceEntity.getId());
+        assertEquals(dataspaceName, dataspaceEntity.getName());
     }
 
     @Test(expected = DataspaceAlreadyDefinedException.class)
@@ -101,9 +101,9 @@ public class CpsAdminPersistenceServiceTest {
         cpsAdminPersistenceService.createAnchor(DATASPACE_NAME, SCHEMA_SET_NAME2, ANCHOR_NAME_NEW);
 
         // validate anchor persisted
-        final Dataspace dataspace = dataspaceRepository.findByName(DATASPACE_NAME).orElseThrow();
+        final DataspaceEntity dataspaceEntity = dataspaceRepository.findByName(DATASPACE_NAME).orElseThrow();
         final AnchorEntity anchorEntity =
-            anchorRepository.findByDataspaceAndName(dataspace, ANCHOR_NAME_NEW).orElseThrow();
+            anchorRepository.findByDataspaceAndName(dataspaceEntity, ANCHOR_NAME_NEW).orElseThrow();
 
         assertNotNull(anchorEntity.getId());
         assertEquals(ANCHOR_NAME_NEW, anchorEntity.getName());
index 77c8003..e813d26 100644 (file)
@@ -30,9 +30,9 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.onap.cps.DatabaseTestContainer;
 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.entities.DataspaceEntity;
+import org.onap.cps.spi.entities.SchemaSetEntity;
+import org.onap.cps.spi.entities.YangResourceEntity;
 import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
 import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException;
 import org.onap.cps.spi.repository.DataspaceRepository;
@@ -124,33 +124,33 @@ public class CpsModulePersistenceServiceTest {
                                           final String expectedYangResourceChecksum) {
 
         // assert the schema set is persisted
-        final SchemaSet schemaSet = getSchemaSetFromDatabase(expectedDataspaceName, expectedSchemaSetName);
-        assertEquals(expectedDataspaceName, schemaSet.getDataspace().getName());
-        assertEquals(expectedSchemaSetName, schemaSet.getName());
+        final SchemaSetEntity schemaSetEntity = getSchemaSetFromDatabase(expectedDataspaceName, expectedSchemaSetName);
+        assertEquals(expectedDataspaceName, schemaSetEntity.getDataspace().getName());
+        assertEquals(expectedSchemaSetName, schemaSetEntity.getName());
 
         // assert the attached yang resource is persisted
-        final Set<YangResource> yangResources = schemaSet.getYangResources();
-        assertNotNull(yangResources);
-        assertEquals(1, yangResources.size());
+        final Set<YangResourceEntity> yangResourceEntities = schemaSetEntity.getYangResources();
+        assertNotNull(yangResourceEntities);
+        assertEquals(1, yangResourceEntities.size());
 
         // assert the attached yang resource content
-        final YangResource yangResource = yangResources.iterator().next();
-        assertNotNull(yangResource.getId());
+        final YangResourceEntity yangResourceEntity = yangResourceEntities.iterator().next();
+        assertNotNull(yangResourceEntity.getId());
         if (expectedYangResourceId != NEW_RESOURCE_ABSTRACT_ID) {
             // existing resource with known id
-            assertEquals(expectedYangResourceId, yangResource.getId());
+            assertEquals(expectedYangResourceId, yangResourceEntity.getId());
         }
-        assertEquals(expectedYangResourceName, yangResource.getName());
-        assertEquals(expectedYangResourceContent, yangResource.getContent());
-        assertEquals(expectedYangResourceChecksum, yangResource.getChecksum());
+        assertEquals(expectedYangResourceName, yangResourceEntity.getName());
+        assertEquals(expectedYangResourceContent, yangResourceEntity.getContent());
+        assertEquals(expectedYangResourceChecksum, yangResourceEntity.getChecksum());
     }
 
     private static Map<String, String> toMap(final String key, final String value) {
         return ImmutableMap.<String, String>builder().put(key, value).build();
     }
 
-    private SchemaSet getSchemaSetFromDatabase(final String dataspaceName, final String schemaSetName) {
-        final Dataspace dataspace = dataspaceRepository.findByName(dataspaceName).orElseThrow();
-        return schemaSetRepository.findByDataspaceAndName(dataspace, schemaSetName).orElseThrow();
+    private SchemaSetEntity getSchemaSetFromDatabase(final String dataspaceName, final String schemaSetName) {
+        final DataspaceEntity dataspaceEntity = dataspaceRepository.findByName(dataspaceName).orElseThrow();
+        return schemaSetRepository.findByDataspaceAndName(dataspaceEntity, schemaSetName).orElseThrow();
     }
 }