Fix SubTreePathsById when given ID is invalid

The commit 7a93d51 makes `getAssociatedSubTreePathsById()` to return
empty paths if there are no associated subtrees.  However, it also
returns empty paths as a success, even if the given id is not valid.

This is to check the invalid case and to return NotFound.

For example, currently, this gives the success
- GET /redfish/v1/Chassis/INVALID/PowerSubsystem/PowerSupplies

Tested:
- GET with the invalid id and check the return condition.

```
busctl call -j  "xyz.openbmc_project.ObjectMapper"   "/xyz/openbmc_project/object_mapper" \
  "xyz.openbmc_project.ObjectMapper" "GetAssociatedSubTreePathsById" ssassas \
   "InvalidChassis" \
   "/xyz/openbmc_project/inventory"  \
   1 "xyz.openbmc_project.Inventory.Item.Chassis" \
    "powered_by" \
   1  "xyz.openbmc_project.Inventory.Item.PowerSupply"

-->
Call failed: The resource is not found.
```

Change-Id: If4f621e105bc1a5c443c1ec8b7762f57748e1d10
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/src/handler.cpp b/src/handler.cpp
index 7705e3c..8caba42 100644
--- a/src/handler.cpp
+++ b/src/handler.cpp
@@ -361,18 +361,26 @@
             ResourceNotFound();
     }
 
+    bool validId = false;
     std::vector<std::string> output;
     for (const auto& path : interfaceMap)
     {
         const auto& thisPath = path.first;
 
-        // Skip exact match on stripped search term or
-        // the path does not end with the id
-        if (thisPath == objectPathStripped || !thisPath.ends_with("/" + id))
+        // Skip the path does not end with the id
+        if (!thisPath.ends_with("/" + id))
         {
             continue;
         }
 
+        // Valid if id is matching
+        validId = true;
+
+        // Skip exact match on stripped search term
+        if (thisPath == objectPathStripped)
+        {
+            continue;
+        }
         if (thisPath.starts_with(objectPath))
         {
             for (const auto& interfaceMap : path.second)
@@ -390,6 +398,11 @@
             }
         }
     }
+    if (!validId)
+    {
+        throw sdbusplus::xyz::openbmc_project::Common::Error::
+            ResourceNotFound();
+    }
     return output;
 }