Implement ends with cps path query to support multiple attributes with 'and' condition
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / repository / FragmentRepository.java
index eb2e82b..b896fe8 100755 (executable)
@@ -1,7 +1,7 @@
 /*-\r
  * ============LICENSE_START=======================================================\r
  *  Copyright (C) 2020-201 Nordix Foundation. All rights reserved.\r
- *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.\r
+ *  Modifications Copyright (C) 2020-2021 Bell Canada. 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
@@ -66,4 +66,11 @@ public interface FragmentRepository extends JpaRepository<FragmentEntity, Long>
     // Above query will match the anchor id and last descendant name\r
     List<FragmentEntity> getByAnchorAndXpathEndsInDescendantName(@Param("anchor") int anchorId,\r
                                                                  @Param("descendantName") String descendantName);\r
+\r
+    @Query(value = "SELECT * FROM FRAGMENT WHERE anchor_id = :anchor AND xpath LIKE CONCAT('%/',:descendantName) "\r
+        + "AND attributes @>  :leafDataAsJson\\:\\:jsonb", nativeQuery = true)\r
+    // Above query will match the anchor id, last descendant name and all parameters passed into leafDataASJson with the\r
+    // attribute values of the requested data node eg: {"leaf_name":"value", "another_leaf_name":"another value"}​​​​​​\r
+    List<FragmentEntity> getByAnchorAndDescendentNameAndLeafValues(@Param("anchor") int anchorId,\r
+        @Param("descendantName") String descendantName, @Param("leafDataAsJson") String leafDataAsJson);\r
 }\r