EventService : Send event for ConfigFile updation

The commit implements the sending of push style events to the IBM's management client
when a configFile is updated.

Tested-By:
    1. Create a subscription by passing "ResourceTypes" as ["IBMConfigFile"]
       POST -D headers.txt https://${bmc}/redfish/v1/EventService/Subscriptions
       -d '{"Destination" : "https://<host:port>,"ResourceTypes":["IBMConfigFile"],"Protocol":"Redfish"}'
    2. Update an existing ConfigFile
       PUT https://${bmc}/ibm/v1/Host/ConfigFiles/<filename> --data-binary "@<local_path>"
    3. Verify the event is generated and posted to the subscriber as the following example:

       bodydata: {
         "@odata.type":"#Event.v1_4_0.Event",
         "Events":[
           {
             "EventId":1,
             "EventTimestamp":"2020-06-26T08:40:04+00:00",
             "EventType":"ResourceChanged",
             "MemberId":0,
             "Message" :"One or more resource properties have changed.",
             "MessageArgs":null,
             "MessageId":"ResourceEvent.1.0.3.ResourceChanged",
             "OriginOfCondition":"/ibm/v1/Host/ConfigFiles/<filename>",
             "MessageSeverity":"OK"
           }
         ],
         "Id":1,
         "Name":"Event Log"
       }
    4. Verified the event is sent to the subscriber when the resourceType list is empty.
    5. Verified the client subscribes for other resource - not ConfigFile ; then
       the event is not sent to the subscriber.

Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: I785c2a5a6e4e721cf722e94693db3a832f69fa50
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index af87b76..88f2fc6 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -116,7 +116,13 @@
             "File size exceeds maximum allowed size[500KB]";
         return;
     }
-    BMCWEB_LOG_DEBUG << "Creating file " << loc;
+    BMCWEB_LOG_DEBUG << "Writing to the file: " << loc;
+
+    bool fileExists = false;
+    if (std::filesystem::exists(loc))
+    {
+        fileExists = true;
+    }
     file.open(loc, std::ofstream::out);
     if (file.fail())
     {
@@ -128,12 +134,24 @@
     else
     {
         file << data;
-        BMCWEB_LOG_DEBUG << "save-area file is created";
-        res.jsonValue["Description"] = "File Created";
-        // Push an event
         std::string origin = "/ibm/v1/Host/ConfigFiles/" + fileID;
-        redfish::EventServiceManager::getInstance().sendEvent(
-            redfish::messages::ResourceCreated(), origin, "IBMConfigFile");
+        // Push an event
+        if (fileExists)
+        {
+            BMCWEB_LOG_DEBUG << "config file is updated";
+            res.jsonValue["Description"] = "File Updated";
+
+            redfish::EventServiceManager::getInstance().sendEvent(
+                redfish::messages::ResourceChanged(), origin, "IBMConfigFile");
+        }
+        else
+        {
+            BMCWEB_LOG_DEBUG << "config file is created";
+            res.jsonValue["Description"] = "File Created";
+
+            redfish::EventServiceManager::getInstance().sendEvent(
+                redfish::messages::ResourceCreated(), origin, "IBMConfigFile");
+        }
     }
 }