Project

General

Profile

Actions

Architecture #16603

closed

Clarify code of rollback events parsing

Added by Vincent MEMBRÉ almost 5 years ago. Updated over 4 years ago.

Status:
Released
Priority:
N/A
Category:
Architecture - Code maintenance
Target version:
Effort required:
Name check:
To do
Fix check:
Checked
Regression:

Description

Something is fishy in parsing of rollback events

  def getRollbackDetails(xml:NodeSeq) : Box[RollbackInfo] = {
  def getEvents(xml:NodeSeq)= {
    for{
      event     <- xml
      eventlogs <- event.child
      entry     <- eventlogs \ "rollbackedEvent" 
      id        <- (entry \ "id").headOption.map(_.text.toInt) ?~! ("Entry type is not a 'rollback': %s".format(entry))
      evtType   <-(entry \ "type").headOption.map(_.text) ?~! ("Entry type is not a 'rollback': %s".format(entry))
      author    <-(entry \ "author").headOption.map(_.text) ?~! ("Entry type is not a 'rollback': %s".format(entry))
      date      <-(entry \ "date").headOption.map(_.text) ?~! ("Entry type is not a 'rollback': %s".format(entry))
    } yield {
      RollbackedEvent(id,date,evtType,author)
    }
  }

 val rollbackInfo =  for{
      event        <- xml
      eventlogs    <- event.child
      entry        <- (eventlogs \ "main").headOption
      id           <- (entry \ "id").headOption.map(_.text.toInt) ?~! ("Entry type is not a 'rollback': %s".format(entry))
      evtType      <- (entry \ "type").headOption.map(_.text) ?~! ("Entry type is not a 'rollback': %s".format(entry))
      author       <- (entry \ "author").headOption.map(_.text) ?~! ("Entry type is not a 'rollback': %s".format(entry))
      date         <- (entry \ "date").headOption.map(_.text) ?~! ("Entry type is not a 'rollback': %s".format(entry))
      rollbackType <- (entry \ "rollbackType").headOption.map(_.text) ?~! ("Entry type is not a 'rollback': %s".format(entry))
    } yield {
      val target = RollbackedEvent(id,date,evtType,author)
      RollbackInfo(target,rollbackType,getEvents(xml))
    }
   rollbackInfo.headOption
  }

rollbackinfo is a Seq, that we take head, andwe implictly convert to box, it should directlybe a box

getEvents should be a Box[Seq[RollbackedEvents]]

moreover, identation is broken, and error message useless

Actions

Also available in: Atom PDF