summaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri')
-rw-r--r--cps-ri/pom.xml11
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntity.java2
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java24
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java6
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepository.java1
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepositoryImpl.java33
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java3
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java17
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java5
-rw-r--r--cps-ri/src/main/resources/changelog/changelog-master.yaml2
-rw-r--r--cps-ri/src/main/resources/changelog/db/changes/18-cascade-delete-fragment-children.yaml34
11 files changed, 70 insertions, 68 deletions
diff --git a/cps-ri/pom.xml b/cps-ri/pom.xml
index 7ce24d960b..0e3bb633f0 100644
--- a/cps-ri/pom.xml
+++ b/cps-ri/pom.xml
@@ -3,7 +3,7 @@
============LICENSE_START=======================================================
Copyright (C) 2020-2021 Pantheon.tech
Modifications Copyright (C) 2020-2021 Bell Canada
- Modifications Copyright (C) 2020-2022 Nordix Foundation
+ Modifications Copyright (C) 2020-2023 Nordix Foundation
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.cps</groupId>
<artifactId>cps-parent</artifactId>
- <version>3.3.0-SNAPSHOT</version>
+ <version>3.3.1-SNAPSHOT</version>
<relativePath>../cps-parent/pom.xml</relativePath>
</parent>
@@ -67,10 +67,10 @@
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
- <!-- Add Hibernate support for Postgres datatype JSONB -->
+ <!-- Add Hibernate support for Postgres datatype JSONB and Postgres arrays -->
<dependency>
- <groupId>com.vladmihalcea</groupId>
- <artifactId>hibernate-types-52</artifactId>
+ <groupId>io.hypersistence</groupId>
+ <artifactId>hypersistence-utils-hibernate-52</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
@@ -79,7 +79,6 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
- <version>4.14.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntity.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntity.java
index 82afc5a818..05befc8711 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntity.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/FragmentEntity.java
@@ -21,7 +21,7 @@
package org.onap.cps.spi.entities;
-import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
+import io.hypersistence.utils.hibernate.type.json.JsonBinaryType;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.CascadeType;
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
index 46b0fec1c2..f7b586d7b3 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java
@@ -22,7 +22,6 @@ package org.onap.cps.spi.repository;
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.DataspaceEntity;
import org.onap.cps.spi.entities.SchemaSetEntity;
@@ -35,25 +34,24 @@ import org.springframework.stereotype.Repository;
@Repository
public interface AnchorRepository extends JpaRepository<AnchorEntity, Integer> {
- Optional<AnchorEntity> findByDataspaceAndName(@NotNull DataspaceEntity dataspaceEntity, @NotNull String name);
+ Optional<AnchorEntity> findByDataspaceAndName(DataspaceEntity dataspaceEntity, String name);
- default AnchorEntity getByDataspaceAndName(@NotNull DataspaceEntity dataspace,
- @NotNull String anchorName) {
+ default AnchorEntity getByDataspaceAndName(DataspaceEntity dataspace, String anchorName) {
return findByDataspaceAndName(dataspace, anchorName)
.orElseThrow(() -> new AnchorNotFoundException(anchorName, dataspace.getName()));
}
- Collection<AnchorEntity> findAllByDataspace(@NotNull DataspaceEntity dataspaceEntity);
+ Collection<AnchorEntity> findAllByDataspace(DataspaceEntity dataspaceEntity);
- Collection<AnchorEntity> findAllBySchemaSet(@NotNull SchemaSetEntity schemaSetEntity);
+ Collection<AnchorEntity> findAllBySchemaSet(SchemaSetEntity schemaSetEntity);
- Collection<AnchorEntity> findAllByDataspaceAndNameIn(@NotNull DataspaceEntity dataspaceEntity,
- @NotNull Collection<String> anchorNames);
+ Collection<AnchorEntity> findAllByDataspaceAndNameIn(DataspaceEntity dataspaceEntity,
+ Collection<String> anchorNames);
- Collection<AnchorEntity> findAllByDataspaceAndSchemaSetNameIn(@NotNull DataspaceEntity dataspaceEntity,
- @NotNull Collection<String> schemaSetNames);
+ Collection<AnchorEntity> findAllByDataspaceAndSchemaSetNameIn(DataspaceEntity dataspaceEntity,
+ Collection<String> schemaSetNames);
- Integer countByDataspace(@NotNull DataspaceEntity dataspaceEntity);
+ Integer countByDataspace(DataspaceEntity dataspaceEntity);
@Query(value = "SELECT anchor.* FROM yang_resource\n"
+ "JOIN schema_set_yang_resources ON schema_set_yang_resources.yang_resource_id = yang_resource.id\n"
@@ -65,6 +63,6 @@ public interface AnchorRepository extends JpaRepository<AnchorEntity, Integer> {
Collection<AnchorEntity> getAnchorsByDataspaceIdAndModuleNames(@Param("dataspaceId") int dataspaceId,
@Param("moduleNames") Collection<String> moduleNames, @Param("sizeOfModuleNames") int sizeOfModuleNames);
- void deleteAllByDataspaceAndNameIn(@NotNull DataspaceEntity dataspaceEntity,
- @NotNull Collection<String> anchorNames);
+ void deleteAllByDataspaceAndNameIn(DataspaceEntity dataspaceEntity,
+ Collection<String> anchorNames);
}
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 10c6541d0c..b1ce127c4a 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
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +21,6 @@
package org.onap.cps.spi.repository;
import java.util.Optional;
-import javax.validation.constraints.NotNull;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -29,7 +29,7 @@ import org.springframework.stereotype.Repository;
@Repository
public interface DataspaceRepository extends JpaRepository<DataspaceEntity, Integer> {
- Optional<DataspaceEntity> findByName(@NotNull String name);
+ Optional<DataspaceEntity> findByName(String name);
/**
* Get a dataspace by name.
@@ -38,7 +38,7 @@ public interface DataspaceRepository extends JpaRepository<DataspaceEntity, Inte
* @param name the name of the dataspace
* @return the Dataspace found
*/
- default DataspaceEntity getByName(@NotNull final String name) {
+ default DataspaceEntity getByName(final String name) {
return findByName(name).orElseThrow(() -> new DataspaceNotFoundException(name));
}
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepository.java
index 13320bf763..bad68f7e58 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepository.java
@@ -26,7 +26,6 @@ import java.util.Collection;
* This interface is used in delete fragment entity by id with child using native sql queries.
*/
public interface FragmentNativeRepository {
- void deleteFragmentEntity(long fragmentEntityId);
/**
* Delete fragment entities for each supplied xpath.
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepositoryImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepositoryImpl.java
index 5c5458a039..04b7080def 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepositoryImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentNativeRepositoryImpl.java
@@ -31,30 +31,13 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class FragmentNativeRepositoryImpl implements FragmentNativeRepository {
- private static final String DROP_FRAGMENT_CONSTRAINT
- = "ALTER TABLE fragment DROP CONSTRAINT fragment_parent_id_fkey;";
- private static final String ADD_FRAGMENT_CONSTRAINT_WITH_CASCADE
- = "ALTER TABLE fragment ADD CONSTRAINT fragment_parent_id_fkey FOREIGN KEY (parent_id) "
- + "REFERENCES fragment (id) ON DELETE CASCADE;";
- private static final String ADD_ORIGINAL_FRAGMENT_CONSTRAINT
- = "ALTER TABLE fragment ADD CONSTRAINT fragment_parent_id_fkey FOREIGN KEY (parent_id) "
- + "REFERENCES fragment (id) ON DELETE NO ACTION;";
-
@PersistenceContext
private final EntityManager entityManager;
@Override
- public void deleteFragmentEntity(final long fragmentEntityId) {
- entityManager.createNativeQuery(
- addFragmentConstraintWithDeleteCascade("DELETE FROM fragment WHERE id = ?"))
- .setParameter(1, fragmentEntityId)
- .executeUpdate();
- }
-
- @Override
public void deleteByAnchorIdAndXpaths(final int anchorId, final Collection<String> xpaths) {
- final String queryString = addFragmentConstraintWithDeleteCascade(
- "DELETE FROM fragment f WHERE f.anchor_id = ? AND (f.xpath IN (:parameterPlaceholders))");
+ final String queryString =
+ "DELETE FROM fragment f WHERE f.anchor_id = ? AND (f.xpath IN (:parameterPlaceholders))";
executeUpdateWithAnchorIdAndCollection(queryString, anchorId, xpaths);
}
@@ -62,8 +45,8 @@ public class FragmentNativeRepositoryImpl implements FragmentNativeRepository {
public void deleteListsByAnchorIdAndXpaths(final int anchorId, final Collection<String> listXpaths) {
final Collection<String> listXpathPatterns =
listXpaths.stream().map(listXpath -> listXpath + "[%").collect(Collectors.toSet());
- final String queryString = addFragmentConstraintWithDeleteCascade(
- "DELETE FROM fragment f WHERE f.anchor_id = ? AND (f.xpath LIKE ANY (array[:parameterPlaceholders]))");
+ final String queryString =
+ "DELETE FROM fragment f WHERE f.anchor_id = ? AND (f.xpath LIKE ANY (array[:parameterPlaceholders]))";
executeUpdateWithAnchorIdAndCollection(queryString, anchorId, listXpathPatterns);
}
@@ -86,12 +69,4 @@ public class FragmentNativeRepositoryImpl implements FragmentNativeRepository {
}
}
- private static String addFragmentConstraintWithDeleteCascade(final String queryString) {
- return DROP_FRAGMENT_CONSTRAINT
- + ADD_FRAGMENT_CONSTRAINT_WITH_CASCADE
- + queryString + ";"
- + DROP_FRAGMENT_CONSTRAINT
- + ADD_ORIGINAL_FRAGMENT_CONSTRAINT;
- }
-
}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java
index ab9c02e888..212eb93cb2 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentQueryBuilder.java
@@ -31,7 +31,6 @@ import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
import org.onap.cps.cpspath.parser.CpsPathPrefixType;
import org.onap.cps.cpspath.parser.CpsPathQuery;
import org.onap.cps.spi.entities.FragmentEntity;
@@ -91,7 +90,7 @@ public class FragmentQueryBuilder {
cpsPathQuery.getLeavesData().entrySet().forEach(entry -> {
sqlStringBuilder.append(" attributes @> ");
sqlStringBuilder.append("'" + jsonObjectMapper.asJsonString(entry) + "'");
- if (!CollectionUtils.isEmpty(booleanOperatorsQueue)) {
+ if (!(booleanOperatorsQueue == null || booleanOperatorsQueue.isEmpty())) {
sqlStringBuilder.append(" " + booleanOperatorsQueue.poll() + " ");
}
});
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 98d4420101..3263f34473 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
@@ -25,7 +25,6 @@ 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;
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
@@ -38,17 +37,16 @@ import org.springframework.stereotype.Repository;
@Repository
public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Integer> {
- Optional<SchemaSetEntity> findByDataspaceAndName(@NotNull DataspaceEntity dataspaceEntity,
- @NotNull String schemaSetName);
+ Optional<SchemaSetEntity> findByDataspaceAndName(DataspaceEntity dataspaceEntity, String schemaSetName);
/**
* Gets schema sets by dataspace.
* @param dataspaceEntity dataspace entity
* @return list of schema set entity
*/
- Collection<SchemaSetEntity> findByDataspace(@NotNull DataspaceEntity dataspaceEntity);
+ Collection<SchemaSetEntity> findByDataspace(DataspaceEntity dataspaceEntity);
- Integer countByDataspace(@NotNull DataspaceEntity dataspaceEntity);
+ Integer countByDataspace(DataspaceEntity dataspaceEntity);
/**
* Gets a schema set by dataspace and schema set name.
@@ -58,8 +56,7 @@ public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Inte
* @return schema set entity
* @throws SchemaSetNotFoundException if SchemaSet not found
*/
- default SchemaSetEntity getByDataspaceAndName(@NotNull final DataspaceEntity dataspaceEntity,
- @NotNull final String schemaSetName) {
+ default SchemaSetEntity getByDataspaceAndName(final DataspaceEntity dataspaceEntity, final String schemaSetName) {
return findByDataspaceAndName(dataspaceEntity, schemaSetName)
.orElseThrow(() -> new SchemaSetNotFoundException(dataspaceEntity.getName(), schemaSetName));
}
@@ -71,7 +68,7 @@ public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Inte
* @return list of schema set entity
* @throws SchemaSetNotFoundException if SchemaSet not found
*/
- default List<SchemaSetEntity> getByDataspace(@NotNull final DataspaceEntity dataspaceEntity) {
+ default List<SchemaSetEntity> getByDataspace(final DataspaceEntity dataspaceEntity) {
return findByDataspace(dataspaceEntity).stream().collect(Collectors.toList());
}
@@ -82,6 +79,6 @@ public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Inte
*/
@Modifying
@Query("DELETE FROM SchemaSetEntity s WHERE s.dataspace = :dataspaceEntity AND s.name IN (:schemaSetNames)")
- void deleteByDataspaceAndNameIn(@NotNull @Param("dataspaceEntity") final DataspaceEntity dataspaceEntity,
- @NotNull @Param("schemaSetNames") final Collection<String> schemaSetNames);
+ void deleteByDataspaceAndNameIn(@Param("dataspaceEntity") DataspaceEntity dataspaceEntity,
+ @Param("schemaSetNames") Collection<String> schemaSetNames);
}
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
index 6ca4fff4f4..fff0a6a037 100644
--- 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
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Pantheon.tech
- * Modifications Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2021-2023 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ package org.onap.cps.spi.repository;
import java.util.Collection;
import java.util.List;
import java.util.Set;
-import javax.validation.constraints.NotNull;
import org.onap.cps.spi.entities.YangResourceEntity;
import org.onap.cps.spi.entities.YangResourceModuleReference;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -36,7 +35,7 @@ import org.springframework.stereotype.Repository;
public interface YangResourceRepository extends JpaRepository<YangResourceEntity, Long>,
YangResourceNativeRepository, SchemaSetYangResourceRepository {
- List<YangResourceEntity> findAllByChecksumIn(@NotNull Set<String> checksum);
+ List<YangResourceEntity> findAllByChecksumIn(Set<String> checksum);
@Query(value = "SELECT DISTINCT\n"
+ "yang_resource.module_name AS module_name,\n"
diff --git a/cps-ri/src/main/resources/changelog/changelog-master.yaml b/cps-ri/src/main/resources/changelog/changelog-master.yaml
index 43a54caf64..bf172d8eae 100644
--- a/cps-ri/src/main/resources/changelog/changelog-master.yaml
+++ b/cps-ri/src/main/resources/changelog/changelog-master.yaml
@@ -50,3 +50,5 @@ databaseChangeLog:
file: changelog/db/changes/16-insert-cm-handle-state.yaml
- include:
file: changelog/db/changes/17-add-index-to-schema-set-yang-resources.yaml
+ - include:
+ file: changelog/db/changes/18-cascade-delete-fragment-children.yaml
diff --git a/cps-ri/src/main/resources/changelog/db/changes/18-cascade-delete-fragment-children.yaml b/cps-ri/src/main/resources/changelog/db/changes/18-cascade-delete-fragment-children.yaml
new file mode 100644
index 0000000000..62a9e2f636
--- /dev/null
+++ b/cps-ri/src/main/resources/changelog/db/changes/18-cascade-delete-fragment-children.yaml
@@ -0,0 +1,34 @@
+databaseChangeLog:
+ - changeSet:
+ author: cps
+ id: 18
+ changes:
+ - dropForeignKeyConstraint:
+ baseTableName: fragment
+ constraintName: fragment_parent_id_fkey
+ - addForeignKeyConstraint:
+ baseColumnNames: parent_id
+ baseTableName: fragment
+ constraintName: fragment_parent_id_fkey
+ deferrable: false
+ initiallyDeferred: false
+ onDelete: CASCADE
+ onUpdate: NO ACTION
+ referencedColumnNames: id
+ referencedTableName: fragment
+ validate: true
+ rollback:
+ - dropForeignKeyConstraint:
+ baseTableName: fragment
+ constraintName: fragment_parent_id_fkey
+ - addForeignKeyConstraint:
+ baseColumnNames: parent_id
+ baseTableName: fragment
+ constraintName: fragment_parent_id_fkey
+ deferrable: false
+ initiallyDeferred: false
+ onDelete: NO ACTION
+ onUpdate: NO ACTION
+ referencedColumnNames: id
+ referencedTableName: fragment
+ validate: true