Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case class JobResolved(jobId: Int,
- jobType: JobTypeResolved,
- fireTime: DateTime,
- tempFiles: Seq[String],
- status: Status,
- retry: Int)
- def selectAllWithDeps(): scala.List[model.JobTypeDeps] = {
- db.withSession {
- implicit session: Session =>
- session.withTransaction {
- val query = for {
- jobType <- schema.JobTypes if jobType.isDeleted === ACTIVE.value
- template <- schema.JobTemplates if template.jtmId === jobType.jtmId && template.isDeleted === ACTIVE.value
- source <- schema.DataSources if source.srcId === template.srcId && source.isDeleted === ACTIVE.value
- dest <- schema.DataDestinations if dest.destId === jobType.destId && dest.isDeleted === ACTIVE.value
- } yield (jobType, template, source, dest)
- val f = (model.JobTypeDeps.apply _).tupled
- query.list.map(t => f(t))
- }
- }
- }
- case class JobTypeDeps(jobType: JobType,
- jobTemplate: JobTemplate,
- source: DataSource,
- destination: DataDestination)
- def resolve(deps: JobTypeDeps): Try[JobTypeResolved] = {
- resolve(deps.jobType, deps.jobTemplate, deps.source, deps.destination)
- }
- /**
- * The function merges job template and job type and
- * adds source and destination to the resolved object
- */
- def resolve(jobType: JobType,
- jobTemplate: JobTemplate,
- source: DataSource,
- destination: DataDestination): Try[JobTypeResolved] = {
- // this mutable object, that holds all errors after the processing
- val errors = new mutable.StringBuilder()
- // ...
- // inner functions related to overriding logic
- // ...
- val src = if (jobTemplate.srcId == get(source.srcId, "DataSource.srcId")) {
- source
- } else {
- errors.append(s"JobTemplate.srcId refers to wrong 'source'.\n")
- null: DataSource
- }
- val dest = if (jobType.destId == get(destination.destId, "DataDestination.destId")) {
- destination
- } else {
- errors.append(s"JobType.destId refers to wrong 'destination'.\n")
- null: DataDestination
- }
- val result = new JobTypeResolved(
- jtyId = get(jobType.jtyId, "JobType.jtyId"),
- name = jobType.name.getOrElse(jobTemplate.name),
- source = src,
- destination = dest,
- ...
- )
- if (errors.isEmpty) Success(result)
- else Failure(new NoSuchElementException(errors.toString()))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement