Я близок к последнему шагу.Все еще работает над объединением IssueStatus на основе resourceId.Проверьте это.
scala> case class Issue(
| resourceId: String,
| Category: String,
| Severity: String,
| incidentType: String
| )
defined class Issue
scala> case class IssueStatus(
| resourceId:String,
| Hardware: Option[String],
| Network: Option[String],
| Software: Option[String]
| )
defined class IssueStatus
scala>
scala> val issueList = List(
| Issue("r1", "Network", "Critical", "incident1"),
| Issue("r1", "Network", "Major", "incident2"),
| Issue("r1", "Hardware", "Minor", "incident 3"),
| Issue("r2", "Hardware", "Major", "incident 3"),
| Issue("r3", "Software", "Minor", "incident 1")
| )
issueList: List[Issue] = List(Issue(r1,Network,Critical,incident1), Issue(r1,Network,Major,incident2), Issue(r1,Hardware,Minor,incident 3), Issue(r2,Hardware,Major,incident 3), Issue(r3,Software,Minor,incident 1))
scala> val proc1 = issueList.groupBy( x=> (x.resourceId,x.Category)).map( x=>(x._1,(x._2).sortWith( (p,q) => p.Category > q.Category)(0))).map( x=> (x._1._1,x._1._2,x._2.Severity))
proc1: scala.collection.immutable.Iterable[(String, String, String)] = List((r1,Hardware,Minor), (r3,Software,Minor), (r2,Hardware,Major), (r1,Network,Critical))
scala> val proc2 = proc1.map( x => x match { case(a,"Hardware",c) => IssueStatus(a,Some(c),None,None) case(a,"Network",c) => IssueStatus(a,None,Some(c),None) case(a,"Software",c) => IssueStatus(a,None,None,Some(c)) } )
proc2: scala.collection.immutable.Iterable[IssueStatus] = List(IssueStatus(r1,Some(Minor),None,None), IssueStatus(r3,None,None,Some(Minor)), IssueStatus(r2,Some(Major),None,None), IssueStatus(r1,None,Some(Critical),None))
scala>
scala> proc2.foreach(println)
IssueStatus(r1,Some(Minor),None,None)
IssueStatus(r3,None,None,Some(Minor))
IssueStatus(r2,Some(Major),None,None)
IssueStatus(r1,None,Some(Critical),None)
scala>