public function RunWorkflow($json, $key)
 {
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Parsing JSON input]", \PEAR_LOG_DEBUG);
     try {
         $contentId = $this->ParseJSONToContentID($json);
         $tagsRemoved = $this->ParseJSONToTags($json, "tagsRemoved");
         $tagsAdded = $this->ParseJSONToTags($json, "tagsAdded");
         if (\count($tagsRemoved) < 1 && \count($tagsAdded) < 1) {
             throw new \InvalidArgumentException("No tagsRemoved or tagsAdded were supplied");
         }
     } catch (\Exception $e) {
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [An exception was thrown:]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         $message = $e->getMessage();
         return parent::FormatErrorMessage("An exception was thrown: {$message})");
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Parsing JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Constructing the repository]", \PEAR_LOG_DEBUG);
     try {
         //Get the content repository
         $repository = new \Swiftriver\Core\DAL\Repositories\ContentRepository();
     } catch (\Exception $e) {
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         $message = $e->getMessage();
         return parent::FormatErrorMessage("An exception was thrown: {$message})");
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Constructing the repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Getting the subject content]", \PEAR_LOG_DEBUG);
     try {
         //get the content array for the repo
         $contentArray = $repository->GetContent(array($contentId));
         //try and get the first item
         $content = reset($contentArray);
         //check that its not null
         if (!isset($content) || $content == null) {
             throw new \Exception("No content was returned for the ID: {$contentId}");
         }
     } catch (\Exception $e) {
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         $message = $e->getMessage();
         return parent::FormatErrorMessage("An exception was thrown: {$message})");
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Getting the subject content]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Making Tagging Changes]", \PEAR_LOG_DEBUG);
     $originalTags = $content->tags;
     $content->tags = array();
     foreach ($originalTags as $originalTag) {
         $shouldBeRemoved = false;
         foreach ($tagsRemoved as $tagRemoved) {
             if ($tagRemoved->text == $originalTag->text) {
                 $shouldBeRemoved = true;
             }
         }
         if (!$shouldBeRemoved) {
             $content->tags[] = $originalTag;
         }
     }
     foreach ($tagsAdded as $tag) {
         $content->tags[] = $tag;
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Making Tagging Changes]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Saving Content]", \PEAR_LOG_DEBUG);
     try {
         $repository->SaveContent(array($content));
     } catch (\Exception $e) {
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [{$e}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         $message = $e->getMessage();
         return parent::FormatErrorMessage("An exception was thrown: {$message})");
     }
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Saving Content]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [START: Event Distribution]", \PEAR_LOG_DEBUG);
     $eventArguments = array("originalTags" => $originalTags, "tagsAdded" => $tagsAdded, "tagsRemoved" => $tagsRemoved);
     $event = new \Swiftriver\Core\EventDistribution\GenericEvent(\Swiftriver\Core\EventDistribution\EventEnumeration::$UpdateContentTagging, $eventArguments);
     $eventDistributor = new \Swiftriver\Core\EventDistribution\EventDistributor();
     $eventDistributor->RaiseAndDistributeEvent($event);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [END: Event Distribution]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::UpdateContentTagging::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatMessage("OK");
 }
 /**
  *
  */
 public function RunWorkflow($json, $key)
 {
     //Setup the logger
     $logger = \Swiftriver\Core\Setup::GetLogger();
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [Method invoked]", \PEAR_LOG_INFO);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [START: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     try {
         //call the parser to get the ID
         $id = parent::ParseJSONToContentID($json);
         $markerId = parent::ParseJSONToMarkerID($json);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [END: Parsing the JSON input]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [START: Constructing the repository]", \PEAR_LOG_DEBUG);
     try {
         //Get the content repository
         $repository = new \Swiftriver\Core\DAL\Repositories\ContentRepository();
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [END: Constructing the repository]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [START: Getting the subject content]", \PEAR_LOG_DEBUG);
     try {
         //get the content array for the repo
         $contentArray = $repository->GetContent(array($id));
         //try and get the first item
         $content = reset($contentArray);
         //check that its not null
         if (!isset($content) || $content == null) {
             throw new \Exception("No content was returned for the ID: {$id}");
         }
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [END: Getting the subject content]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [START: Setting the state to acurate]", \PEAR_LOG_DEBUG);
     //Use the state controller to change the state of the the content to acurate
     $content = \Swiftriver\Core\StateTransition\StateController::MarkContentChatter($content);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [END: Setting the state to acurate]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [START: Decrement source score]", \PEAR_LOG_DEBUG);
     //get the source from the content
     $source = $content->source;
     //if the score is null - not yet rated, then set it
     if (!isset($source->score) || $source->score == null) {
         $source->score = 0;
         //baseline of 0%
     }
     //if the scoure is not already at the min
     if ($source->score > 1) {
         //increment the score of the source
         $source->score = $source->score - 2;
     }
     //set the scource back to the content
     $content->source = $source;
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [END: Decrement source score]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [START: Saving the content and source]", \PEAR_LOG_DEBUG);
     try {
         //save the content to the repo
         $repository->SaveContent(array($content));
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [END: Saving the content and source]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [START: Recording the transaction]", \PEAR_LOG_DEBUG);
     try {
         //get the trust log repo
         $trustLogRepo = new \Swiftriver\Core\DAL\Repositories\TrustLogRepository();
         //get the source id
         $sourceId = $content->source->id;
         //record the new entry
         $trustLogRepo->RecordSourceScoreChange($sourceId, $markerId, -2);
     } catch (\Exception $e) {
         //get the exception message
         $message = $e->getMessage();
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [An exception was thrown]", \PEAR_LOG_DEBUG);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [{$message}]", \PEAR_LOG_ERR);
         $logger->log("Core::ServiceAPI::ChannelProcessingJobs::MarkContentAsChatter::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
         return parent::FormatErrorMessage("An exception was thrown: {$message}");
     }
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [END: Recording the transaction]", \PEAR_LOG_DEBUG);
     $logger->log("Core::ServiceAPI::ContentServices::MarkContentAsChatter::RunWorkflow [Method finished]", \PEAR_LOG_INFO);
     return parent::FormatMessage("OK");
 }