Advertisement
NLinker

Untitled

Nov 15th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. case class JobResolved(jobId: Int,
  2.                        jobType: JobTypeResolved,
  3.                        fireTime: DateTime,
  4.                        tempFiles: Seq[String],
  5.                        status: Status,
  6.                        retry: Int)
  7.  
  8.  
  9.   def selectAllWithDeps(): scala.List[model.JobTypeDeps] = {
  10.     db.withSession {
  11.       implicit session: Session =>
  12.         session.withTransaction {
  13.           val query = for {
  14.             jobType <- schema.JobTypes if jobType.isDeleted === ACTIVE.value
  15.             template <- schema.JobTemplates if template.jtmId === jobType.jtmId  && template.isDeleted === ACTIVE.value
  16.             source <- schema.DataSources if source.srcId === template.srcId && source.isDeleted === ACTIVE.value
  17.             dest <- schema.DataDestinations if dest.destId === jobType.destId && dest.isDeleted === ACTIVE.value
  18.           } yield (jobType, template, source, dest)
  19.           val f = (model.JobTypeDeps.apply _).tupled
  20.           query.list.map(t => f(t))
  21.         }
  22.     }
  23.   }
  24.  
  25. case class JobTypeDeps(jobType: JobType,
  26.                        jobTemplate: JobTemplate,
  27.                        source: DataSource,
  28.                        destination: DataDestination)
  29.  
  30.   def resolve(deps: JobTypeDeps): Try[JobTypeResolved] = {
  31.       resolve(deps.jobType, deps.jobTemplate, deps.source, deps.destination)
  32.   }
  33.  
  34.   /**
  35.    * The function merges job template and job type and
  36.    * adds source and destination to the resolved object
  37.    */
  38.   def resolve(jobType: JobType,
  39.               jobTemplate: JobTemplate,
  40.               source: DataSource,
  41.               destination: DataDestination): Try[JobTypeResolved] = {
  42.     // this mutable object, that holds all errors after the processing
  43.     val errors = new mutable.StringBuilder()
  44.     // ...
  45.     // inner functions related to overriding logic
  46.     // ...
  47.  
  48.     val src = if (jobTemplate.srcId == get(source.srcId, "DataSource.srcId")) {
  49.       source
  50.     } else {
  51.       errors.append(s"JobTemplate.srcId refers to wrong 'source'.\n")
  52.       null: DataSource
  53.     }
  54.  
  55.     val dest = if (jobType.destId == get(destination.destId, "DataDestination.destId")) {
  56.       destination
  57.     } else {
  58.       errors.append(s"JobType.destId refers to wrong 'destination'.\n")
  59.       null: DataDestination
  60.     }
  61.    
  62.     val result = new JobTypeResolved(
  63.       jtyId = get(jobType.jtyId, "JobType.jtyId"),
  64.       name = jobType.name.getOrElse(jobTemplate.name),
  65.       source = src,
  66.       destination = dest,
  67.       ...
  68.     )
  69.     if (errors.isEmpty) Success(result)
  70.     else Failure(new NoSuchElementException(errors.toString()))
  71.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement