Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
Link data sets fix - null link
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbanda committed Jun 20, 2019
1 parent c7bbfd6 commit 1a8e6fc
Show file tree
Hide file tree
Showing 21 changed files with 270 additions and 77 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ organization := "org.adada"

name := "ada-server"

version := "0.7.3.RC.10.SNAPSHOT.2"
version := "0.7.3.RC.10.SNAPSHOT.7"

description := "Server side of Ada Discovery Analytics containing a persistence layer, stats and data import/transformation services, and util classes."

Expand Down
16 changes: 16 additions & 0 deletions src/main/scala/org/ada/server/models/ScheduledTime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ case class ScheduledTime(
second: Option[Int]
)

object ScheduledTime {

def fillZeroes(scheduledTime: ScheduledTime): ScheduledTime = {
def value(int: Option[Int]) = Some(int.getOrElse(0))

if (scheduledTime.weekDay.isDefined) {
scheduledTime.copy(hour = value(scheduledTime.hour), minute = value(scheduledTime.minute), second = value(scheduledTime.second))
} else if (scheduledTime.hour.isDefined) {
scheduledTime.copy(minute = value(scheduledTime.minute), second = value(scheduledTime.second))
} else if (scheduledTime.minute.isDefined) {
scheduledTime.copy(second = value(scheduledTime.second))
} else
scheduledTime
}
}

object WeekDay extends Enumeration {

case class Val(day: Int) extends super.Val
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ case class CsvDataSetImport(
dataView: Option[DataView] = None,
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetImport
) extends DataSetImport {

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ trait DataSetImport extends Schedulable {
val setting: Option[DataSetSetting]

val dataView: Option[DataView]

def copyCore(
_id: Option[BSONObjectID],
timeCreated: Date,
timeLastExecuted: Option[Date],
scheduled: Boolean,
scheduledTime: Option[ScheduledTime]
): DataSetImport
}

object DataSetImport {
Expand All @@ -43,26 +51,6 @@ object DataSetImport {
def of(entity: DataSetImport): Option[BSONObjectID] = entity._id

protected def set(entity: DataSetImport, id: Option[BSONObjectID]) =
entity match {
case x: CsvDataSetImport => x.copy(_id = id)
case x: JsonDataSetImport => x.copy(_id = id)
case x: SynapseDataSetImport => x.copy(_id = id)
case x: TranSmartDataSetImport => x.copy(_id = id)
case x: RedCapDataSetImport => x.copy(_id = id)
case x: EGaitDataSetImport => x.copy(_id = id)
}
}

implicit class DataSetImportExt(val dataSetImport: DataSetImport) extends AnyVal {

def copyWithTimestamps(timeCreated: Date, timeLastExecuted: Option[Date]): DataSetImport =
dataSetImport match {
case x: CsvDataSetImport => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: JsonDataSetImport => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: SynapseDataSetImport => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: TranSmartDataSetImport => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: RedCapDataSetImport => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: EGaitDataSetImport => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
}
entity.copyCore(id, entity.timeCreated, entity.timeLastExecuted, entity.scheduled, entity.scheduledTime)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,19 @@ case class EGaitDataSetImport(
dataView: Option[DataView] = None,
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetImport
) extends DataSetImport {

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,19 @@ case class JsonDataSetImport(
dataView: Option[DataView] = None,
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetImport
) extends DataSetImport {

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,19 @@ case class RedCapDataSetImport(
dataView: Option[DataView] = None,
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetImport
) extends DataSetImport {

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,19 @@ case class SynapseDataSetImport(
dataView: Option[DataView] = None,
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetImport
) extends DataSetImport {

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,19 @@ case class TranSmartDataSetImport(
dataView: Option[DataView] = None,
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetImport
) extends DataSetImport {

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,20 @@ case class ChangeFieldEnumsTransformation(
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetMetaTransformation {

override val sourceDataSetIds = Seq(sourceDataSetId)

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,20 @@ case class CopyDataSetTransformation(
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetTransformation {

override val sourceDataSetIds = Seq(sourceDataSetId)

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ trait DataSetMetaTransformation extends Schedulable {
val timeLastExecuted: Option[Date]

val sourceDataSetIds: Seq[String]

def copyCore(
_id: Option[BSONObjectID],
timeCreated: Date,
timeLastExecuted: Option[Date],
scheduled: Boolean,
scheduledTime: Option[ScheduledTime]
): DataSetMetaTransformation
}

trait DataSetTransformation extends DataSetMetaTransformation {
Expand Down Expand Up @@ -60,28 +68,6 @@ object DataSetTransformation {
def of(entity: DataSetMetaTransformation): Option[BSONObjectID] = entity._id

protected def set(entity: DataSetMetaTransformation, id: Option[BSONObjectID]) =
entity match {
case x: CopyDataSetTransformation => x.copy(_id = id)
case x: DropFieldsTransformation => x.copy(_id = id)
case x: RenameFieldsTransformation => x.copy(_id = id)
case x: ChangeFieldEnumsTransformation => x.copy(_id = id)
case x: MatchGroupsWithConfoundersTransformation => x.copy(_id = id)
case x: LinkTwoDataSetsTransformation => x.copy(_id = id)
case x: LinkMultiDataSetsTransformation => x.copy(_id = id)
}
}

implicit class DataSetMetaTransformationExt(val dataSetImport: DataSetMetaTransformation) extends AnyVal {

def copyWithTimestamps(timeCreated: Date, timeLastExecuted: Option[Date]) =
dataSetImport match {
case x: CopyDataSetTransformation => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: DropFieldsTransformation => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: RenameFieldsTransformation => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: ChangeFieldEnumsTransformation => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: MatchGroupsWithConfoundersTransformation => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: LinkTwoDataSetsTransformation => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
case x: LinkMultiDataSetsTransformation => x.copy(timeCreated = timeCreated, timeLastExecuted = timeLastExecuted)
}
entity.copyCore(id, entity.timeCreated, entity.timeLastExecuted, entity.scheduled, entity.scheduledTime)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,20 @@ case class DropFieldsTransformation(
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetTransformation {

override val sourceDataSetIds = Seq(sourceDataSetId)

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@ case class LinkMultiDataSetsTransformation(
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetTransformation {

override val sourceDataSetIds = linkedDataSetSpecs.map(_.dataSetId)

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}

case class LinkedDataSetSpec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,20 @@ case class LinkTwoDataSetsTransformation(
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetTransformation {

override val sourceDataSetIds = Seq(leftSourceDataSetId, rightSourceDataSetId)

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,20 @@ case class MatchGroupsWithConfoundersTransformation(
timeCreated: Date = new Date(),
timeLastExecuted: Option[Date] = None
) extends DataSetTransformation {

override val sourceDataSetIds = Seq(sourceDataSetId)

override def copyCore(
__id: Option[BSONObjectID],
_timeCreated: Date,
_timeLastExecuted: Option[Date],
_scheduled: Boolean,
_scheduledTime: Option[ScheduledTime]
) = copy(
_id = __id,
timeCreated = _timeCreated,
timeLastExecuted = _timeLastExecuted,
scheduled = _scheduled,
scheduledTime = _scheduledTime
)
}
Loading

0 comments on commit 1a8e6fc

Please sign in to comment.