package com.microsoft.partnercatalyst.fortis.spark.analyzer

import java.util.UUID.randomUUID

import com.github.catalystcode.fortis.spark.streaming.facebook.dto.FacebookPost
import com.microsoft.partnercatalyst.fortis.spark.logging.Loggable
import com.microsoft.partnercatalyst.fortis.spark.transforms.image.ImageAnalyzer

@SerialVersionUID(100L)
class FacebookPostAnalyzer extends Analyzer[FacebookPost] with Serializable with Loggable
  with AnalysisDefaults.EnableAll[FacebookPost] {
  override def toSchema(item: FacebookPost, locationFetcher: LocationFetcher, imageAnalyzer: ImageAnalyzer): ExtendedDetails[FacebookPost] = {
    ExtendedDetails(
      eventid = randomUUID().toString,
      sourceeventid = item.post.getId,
      eventtime = item.post.getUpdatedTime.getTime,
      body = item.post.getMessage,
      title = item.post.getCaption,
      externalsourceid = item.post.getSource.toString,
      pipelinekey = "Facebook",
      sharedLocations = Option(item.post.getPlace).map(_.getLocation) match {
        case Some(location) => locationFetcher(location.getLatitude, location.getLongitude).toList
        case None =>
          val errorMsg = "Empty PageIds argument for Facebook connector stream"
          logFatalError(errorMsg)
          throw new IllegalArgumentException(errorMsg)
      },
      sourceurl = item.post.getPermalinkUrl.toString,
      original = item
    )
  }
}
package com.microsoft.partnercatalyst.fortis.spark.analyzer

import java.util.UUID.randomUUID

import com.github.catalystcode.fortis.spark.streaming.facebook.dto.FacebookPost
import com.microsoft.partnercatalyst.fortis.spark.logging.Loggable
import com.microsoft.partnercatalyst.fortis.spark.transforms.image.ImageAnalyzer

@SerialVersionUID(100L)
class FacebookPostAnalyzer extends Analyzer[FacebookPost] with Serializable with Loggable
  with AnalysisDefaults.EnableAll[FacebookPost] {
  override def toSchema(item: FacebookPost, locationFetcher: LocationFetcher, imageAnalyzer: ImageAnalyzer): ExtendedDetails[FacebookPost] = {
    ExtendedDetails(
      eventid = randomUUID().toString,
      sourceeventid = item.post.getId,
      eventtime = item.post.getUpdatedTime.getTime,
      body = item.post.getMessage,
      title = item.post.getCaption,
      externalsourceid = item.post.getSource.toString,
      pipelinekey = "Facebook",
      sharedLocations = Option(item.post.getPlace).map(_.getLocation) match {
        case Some(location) => locationFetcher(location.getLatitude, location.getLongitude).toList
        case None => List()
      },
      sourceurl = item.post.getPermalinkUrl.toString,
      original = item
    )
  }
}
Remove bad exception for unset shared locations
Remove bad exception for unset shared locations

This looks like the results of a bad merge; what reason would we have to
throw an exception regarding pageIds when checking the shared locations
in a Facebook post? Seems more sensible to simply treat posts without a
tagged location as not having shared locations.
