Advertisement
NLinker

Question on flat models –vs- tuple conversion

Nov 15th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 3.10 KB | None | 0 0
  1. case class JobTemplate(jtmId: Option[Int],
  2.                        srcId: Int,
  3.                        name: String,
  4.                        schedule: Option[String],
  5.                        timeZone: Option[String],
  6.                        extractionSQL: String,
  7.                        handler: Option[String],
  8.                        headerTemplate: Option[String],
  9.                        footerTemplate: Option[String],
  10.                        rowTemplate: Option[String],
  11.                        compressor: Option[String],
  12.                        filenameTemplates: Map[String, String],
  13.                        columnTypes: Map[String, String],
  14.                        paramValidators: Map[String, String],
  15.                        createdAt: DateTime,
  16.                        updatedAt: DateTime,
  17.                        isDeleted: Boolean) extends EditableEntity
  18.  
  19. new JobTemplate(None, "Nielsen", 1, Some(schedule), Some(scheduleTz), selectStatement, Some("DLX"), Some(header), Some(footer), Some(row), Some("bzip2"), .... )
  20.  
  21.  
  22. case class JobTemplate(jtmId: Option[Int],
  23.                        srcId: Int,
  24.                        name: String,
  25.                        schedule: Option[Schedule],
  26.                        extractionSQL: String,
  27.                        outputData: OutputData,
  28.                        columnTypes: Map[String, String],
  29.                        paramValidators: Map[String, String],
  30.                        createdAt: DateTime,
  31.                        updatedAt: DateTime,
  32.                        isDeleted: Boolean) extends EditableEntity
  33.  
  34.  
  35.   def toObject(row: Tuple17[Option[Int], String, Int, Option[String],
  36.     Option[String], String, Option[String], Option[String], Option[String],
  37.     Option[String], Option[String], Map[String, String],
  38.     Map[String, String], Map[String, String], DateTime, DateTime, Boolean]): JobTemplate =
  39.     row match {
  40.       case (jtmId, name, srcId, schedule, timeZone, extractionSQL, handler,
  41.       headerTemplate, footerTemplate, rowTemplate, compressor, filenameTemplates,
  42.       columnTypes, paramValidators, createdAt, updatedAt, isDeleted) => {
  43.         val outputData = new OutputData(handler, headerTemplate,
  44.           footerTemplate, rowTemplate, compressor, filenameTemplates)
  45.         val schedule = for {
  46.           sh <- schedule
  47.           tz <- timeZone
  48.         } yield new Schedule(sh, tz)
  49.         new JobTemplate(jtmId, name, srcId, schedule, extractionSQL, outputData,
  50.           columnTypes, paramValidators, createdAt, updatedAt, isDeleted)
  51.       }
  52.     }
  53.  
  54.  
  55.   val jobTemplate = new model.JobTemplate(
  56.     jtmId = None,
  57.     name = "Nielsen",
  58.     srcId = 1,
  59.     schedule = Some(schedule),
  60.     timeZone = Some(scheduleTz),
  61.     extractionSQL = selectStatement,
  62.     handler = Some("DLX"),
  63.     headerTemplate = Some(header),
  64.     footerTemplate = Some(footer),
  65.     rowTemplate = Some(row),
  66.     compressor = Some("bzip2"),
  67.     filenameTemplates = Map("log" -> logFileName, "meta" -> metaFileName),
  68.     columnTypes = colTypes,
  69.     paramValidators = parValidators,
  70.     createdAt = now,
  71.     updatedAt = now,
  72.     isDeleted = ACTIVE.value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement