Changed dbus add report interface

- metric parameters now take single sensor instead of list
- added interface support for new operation types

Tested:
- All telemetry tests are passing.

Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: Id3a41c48e81a287e7d205ae1c747daa36d4cdb29
diff --git a/src/report_factory.cpp b/src/report_factory.cpp
index 2cd5da3..9dfdbb0 100644
--- a/src/report_factory.cpp
+++ b/src/report_factory.cpp
@@ -3,6 +3,7 @@
 #include "metric.hpp"
 #include "report.hpp"
 #include "sensor.hpp"
+#include "utils/conversion.hpp"
 #include "utils/dbus_mapper.hpp"
 #include "utils/transform.hpp"
 
@@ -41,7 +42,7 @@
         [this](const LabeledMetricParameters& param)
             -> std::shared_ptr<interfaces::Metric> {
             return std::make_shared<Metric>(
-                getSensors(param.at_index<0>()), param.at_index<1>(),
+                getSensor(param.at_index<0>()), param.at_index<1>(),
                 param.at_index<2>(), param.at_index<3>());
         });
 
@@ -51,19 +52,14 @@
         reportManager, reportStorage, std::move(metrics));
 }
 
-std::vector<std::shared_ptr<interfaces::Sensor>> ReportFactory::getSensors(
-    const std::vector<LabeledSensorParameters>& sensorPaths) const
+std::shared_ptr<interfaces::Sensor>
+    ReportFactory::getSensor(const LabeledSensorParameters& sensorPath) const
 {
-    return utils::transform(sensorPaths,
-                            [this](const LabeledSensorParameters& param)
-                                -> std::shared_ptr<interfaces::Sensor> {
-                                using namespace utils::tstring;
+    using namespace utils::tstring;
 
-                                return sensorCache.makeSensor<Sensor>(
-                                    param.at_label<Service>(),
-                                    param.at_label<Path>(),
-                                    bus->get_io_context(), bus);
-                            });
+    return sensorCache.makeSensor<Sensor>(sensorPath.at_label<Service>(),
+                                          sensorPath.at_label<Path>(),
+                                          bus->get_io_context(), bus);
 }
 
 std::vector<LabeledMetricParameters> ReportFactory::convertMetricParams(
@@ -73,24 +69,22 @@
     auto tree = utils::getSubTreeSensors(yield, bus);
 
     return utils::transform(metricParams, [&tree](const auto& item) {
-        std::vector<LabeledSensorParameters> sensors;
+        const auto& [sensorPath, operationType, id, metadata] = item;
 
-        for (const auto& sensorPath : std::get<0>(item))
+        auto it = std::find_if(
+            tree.begin(), tree.end(),
+            [&sensorPath](const auto& v) { return v.first == sensorPath; });
+
+        if (it != tree.end() && it->second.size() == 1)
         {
-            auto it = std::find_if(
-                tree.begin(), tree.end(),
-                [&sensorPath](const auto& v) { return v.first == sensorPath; });
-
-            if (it != tree.end())
-            {
-                for (const auto& [service, ifaces] : it->second)
-                {
-                    sensors.emplace_back(service, sensorPath);
-                }
-            }
+            const auto& [service, ifaces] = it->second.front();
+            return LabeledMetricParameters(
+                LabeledSensorParameters(service, sensorPath),
+                utils::stringToOperationType(operationType), id, metadata);
         }
 
-        return LabeledMetricParameters(std::move(sensors), std::get<1>(item),
-                                       std::get<2>(item), std::get<3>(item));
+        throw sdbusplus::exception::SdBusError(
+            static_cast<int>(std::errc::invalid_argument),
+            "Could not find service for provided sensors");
     });
 }