X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ri%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fspi%2Frepository%2FAnchorRepository.java;h=5870fd9e9b5c9ce5c29feba0096474c74e657757;hb=6804157f3ee5b1268e53ae86e4767ee267d48eec;hp=cc9c2e09c7eeb4a5122f52609b9c145a3d3d5a40;hpb=a16c3fb5f7f0bbe7bda9e4f21f71a3e958ed523f;p=cps.git 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 cc9c2e09c..5870fd9e9 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 @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2021 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +25,11 @@ 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; import org.onap.cps.spi.exceptions.AnchorNotFoundException; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface AnchorRepository extends JpaRepository { @@ -38,4 +42,16 @@ public interface AnchorRepository extends JpaRepository { } Collection findAllByDataspace(@NotNull DataspaceEntity dataspaceEntity); + + Collection findAllBySchemaSet(@NotNull SchemaSetEntity schemaSetEntity); + + @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" + + "JOIN schema_set ON schema_set.id = schema_set_yang_resources.schema_set_id\n" + + "JOIN anchor ON anchor.schema_set_id = schema_set.id\n" + + "WHERE schema_set.dataspace_id = :dataspaceId AND module_name IN (:moduleNames)\n" + + "GROUP BY anchor.id, anchor.name, anchor.dataspace_id, anchor.schema_set_id\n" + + "HAVING COUNT(DISTINCT module_name) = :sizeOfModuleNames", nativeQuery = true) + Collection getAnchorsByDataspaceIdAndModuleNames(@Param("dataspaceId") int dataspaceId, + @Param("moduleNames") Collection moduleNames, @Param("sizeOfModuleNames") int sizeOfModuleNames); } \ No newline at end of file