Skip to content

Commit 00e858a

Browse files
authored
Job template/Notification/Workflow revert (#585)
* Job template/Notification/Workflow revert (#585)
1 parent ad4cae1 commit 00e858a

File tree

48 files changed

+572
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+572
-19
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: build
22

33
on:
44
pull_request:
5-
branches: [develop]
5+
branches:
6+
- '**'
67

78
jobs:
89
build:

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/controllers/JobTemplateHistoryController.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class JobTemplateHistoryController @Inject()(jobTemplateHistoryService: JobTempl
3232
jobTemplateHistoryService.getHistoryForJobTemplate(jobTemplateId).toJava.toCompletableFuture
3333
}
3434

35+
@GetMapping(path = Array("/jobTemplateFromHistory"))
36+
def getJobTemplateFromHistory(@RequestParam jobTemplateHistoryId: Long): CompletableFuture[JobTemplate] = {
37+
jobTemplateHistoryService.getJobTemplateFromHistory(jobTemplateHistoryId).toJava.toCompletableFuture
38+
}
39+
3540
@GetMapping(path = Array("/jobTemplatesFromHistory"))
3641
def getJobTemplatesFromHistory(@RequestParam leftJobTemplateHistoryId: Long, @RequestParam rightJobTemplateHistoryId: Long): CompletableFuture[HistoryPair[JobTemplateHistory]] = {
3742
jobTemplateHistoryService.getJobTemplatesFromHistory(leftJobTemplateHistoryId, rightJobTemplateHistoryId).toJava.toCompletableFuture

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/controllers/NotificationRuleHistoryController.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class NotificationRuleHistoryController @Inject()(notificationRuleHistoryService
3232
notificationRuleHistoryService.getHistoryForNotificationRule(notificationRuleId).toJava.toCompletableFuture
3333
}
3434

35+
@GetMapping(path = Array("/notificationRuleFromHistory"))
36+
def getNotificationRuleFromHistory(@RequestParam notificationRuleHistoryId: Long): CompletableFuture[NotificationRule] = {
37+
notificationRuleHistoryService.getNotificationRuleFromHistory(notificationRuleHistoryId).toJava.toCompletableFuture
38+
}
39+
3540
@GetMapping(path = Array("/notificationRulesFromHistory"))
3641
def getNotificationRulesFromHistory(@RequestParam leftHistoryId: Long, @RequestParam rightHistoryId: Long): CompletableFuture[HistoryPair[NotificationRuleHistory]] = {
3742
notificationRuleHistoryService.getNotificationRulesFromHistory(leftHistoryId, rightHistoryId).toJava.toCompletableFuture

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/controllers/WorkflowHistoryController.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class WorkflowHistoryController @Inject()(workflowHistoryService: WorkflowHistor
3333
workflowHistoryService.getHistoryForWorkflow(workflowId).toJava.toCompletableFuture
3434
}
3535

36+
@GetMapping(path = Array("/workflowFromHistory"))
37+
def getWorkflowFromHistory(@RequestParam workflowHistoryId: Long): CompletableFuture[WorkflowJoined] = {
38+
workflowHistoryService.getWorkflowFromHistory(workflowHistoryId).toJava.toCompletableFuture
39+
}
40+
3641
@GetMapping(path = Array("/workflowsFromHistory"))
3742
def getWorkflowsFromHistory(@RequestParam leftWorkflowHistoryId: Long, @RequestParam rightWorkflowHistoryId: Long): CompletableFuture[HistoryPair[WorkflowHistory]] = {
3843
workflowHistoryService.getWorkflowsFromHistory(leftWorkflowHistoryId, rightWorkflowHistoryId).toJava.toCompletableFuture

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/services/JobTemplateHistoryService.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
package za.co.absa.hyperdrive.trigger.api.rest.services
1717

1818
import org.springframework.stereotype.Service
19-
import za.co.absa.hyperdrive.trigger.models.{History, HistoryPair, JobTemplateHistory, WorkflowHistory}
20-
import za.co.absa.hyperdrive.trigger.persistance.{JobTemplateHistoryRepository, WorkflowHistoryRepository}
19+
import za.co.absa.hyperdrive.trigger.models.{History, HistoryPair, JobTemplate, JobTemplateHistory}
20+
import za.co.absa.hyperdrive.trigger.persistance.JobTemplateHistoryRepository
2121

2222
import scala.concurrent.{ExecutionContext, Future}
2323

2424
trait JobTemplateHistoryService {
2525
val jobTemplateHistoryRepository: JobTemplateHistoryRepository
2626

2727
def getHistoryForJobTemplate(jobTemplateId: Long)(implicit ec: ExecutionContext): Future[Seq[History]]
28+
def getJobTemplateFromHistory(jobTemplateHistoryId: Long)(implicit ec: ExecutionContext): Future[JobTemplate]
2829
def getJobTemplatesFromHistory(leftJobTemplateHistoryId: Long, rightJobTemplateHistoryId: Long)(implicit ec: ExecutionContext): Future[HistoryPair[JobTemplateHistory]]
2930
}
3031

@@ -34,6 +35,10 @@ class JobTemplateHistoryServiceImpl(override val jobTemplateHistoryRepository: J
3435
jobTemplateHistoryRepository.getHistoryForJobTemplate(jobTemplateId)
3536
}
3637

38+
override def getJobTemplateFromHistory(jobTemplateHistoryId: Long)(implicit ec: ExecutionContext): Future[JobTemplate] = {
39+
jobTemplateHistoryRepository.getJobTemplateFromHistory(jobTemplateHistoryId)
40+
}
41+
3742
override def getJobTemplatesFromHistory(leftJobTemplateHistoryId: Long, rightJobTemplateHistoryId: Long)(implicit ec: ExecutionContext): Future[HistoryPair[JobTemplateHistory]] = {
3843
jobTemplateHistoryRepository.getJobTemplatesFromHistory(leftJobTemplateHistoryId, rightJobTemplateHistoryId)
3944
}

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/services/NotificationRuleHistoryService.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package za.co.absa.hyperdrive.trigger.api.rest.services
1717

1818
import org.springframework.stereotype.Service
19-
import za.co.absa.hyperdrive.trigger.models.{History, HistoryPair, NotificationRuleHistory}
19+
import za.co.absa.hyperdrive.trigger.models.{History, HistoryPair, NotificationRule, NotificationRuleHistory}
2020
import za.co.absa.hyperdrive.trigger.persistance.NotificationRuleHistoryRepository
2121

2222
import scala.concurrent.{ExecutionContext, Future}
@@ -25,6 +25,7 @@ trait NotificationRuleHistoryService {
2525
val historyRepository: NotificationRuleHistoryRepository
2626

2727
def getHistoryForNotificationRule(workflowId: Long)(implicit ec: ExecutionContext): Future[Seq[History]]
28+
def getNotificationRuleFromHistory(notificationRuleHistoryId: Long)(implicit ec: ExecutionContext): Future[NotificationRule]
2829
def getNotificationRulesFromHistory(leftHistoryId: Long, rightHistoryId: Long)(implicit ec: ExecutionContext): Future[HistoryPair[NotificationRuleHistory]]
2930
}
3031

@@ -35,6 +36,10 @@ class NotificationRuleHistoryServiceImpl(override val historyRepository: Notific
3536
historyRepository.getHistoryForNotificationRule(notificationRuleId)
3637
}
3738

39+
override def getNotificationRuleFromHistory(notificationRuleHistoryId: Long)(implicit ec: ExecutionContext): Future[NotificationRule] = {
40+
historyRepository.getNotificationRuleFromHistory(notificationRuleHistoryId)
41+
}
42+
3843
override def getNotificationRulesFromHistory(leftHistoryId: Long, rightHistoryId: Long)(implicit ec: ExecutionContext): Future[HistoryPair[NotificationRuleHistory]] = {
3944
historyRepository.getNotificationRulesFromHistory(leftHistoryId, rightHistoryId)
4045
}

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/services/WorkflowHistoryService.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package za.co.absa.hyperdrive.trigger.api.rest.services
1717

1818
import org.springframework.stereotype.Service
19-
import za.co.absa.hyperdrive.trigger.models.{History, HistoryPair, WorkflowHistory}
19+
import za.co.absa.hyperdrive.trigger.models.{History, HistoryPair, WorkflowHistory, WorkflowJoined}
2020
import za.co.absa.hyperdrive.trigger.persistance.WorkflowHistoryRepository
2121

2222
import scala.concurrent.{ExecutionContext, Future}
@@ -25,6 +25,7 @@ trait WorkflowHistoryService {
2525
val workflowHistoryRepository: WorkflowHistoryRepository
2626

2727
def getHistoryForWorkflow(workflowId: Long)(implicit ec: ExecutionContext): Future[Seq[History]]
28+
def getWorkflowFromHistory(workflowHistoryId: Long)(implicit ec: ExecutionContext): Future[WorkflowJoined]
2829
def getWorkflowsFromHistory(leftWorkflowHistoryId: Long, rightWorkflowHistoryId: Long)(implicit ec: ExecutionContext): Future[HistoryPair[WorkflowHistory]]
2930
}
3031

@@ -35,6 +36,10 @@ class WorkflowHistoryServiceImpl(override val workflowHistoryRepository: Workflo
3536
workflowHistoryRepository.getHistoryForWorkflow(workflowId)
3637
}
3738

39+
override def getWorkflowFromHistory(workflowHistoryId: Long)(implicit ec: ExecutionContext): Future[WorkflowJoined] = {
40+
workflowHistoryRepository.getWorkflowFromHistory(workflowHistoryId)
41+
}
42+
3843
override def getWorkflowsFromHistory(leftWorkflowHistoryId: Long, rightWorkflowHistoryId: Long)(implicit ec: ExecutionContext): Future[HistoryPair[WorkflowHistory]] = {
3944
workflowHistoryRepository.getWorkflowsFromHistory(leftWorkflowHistoryId, rightWorkflowHistoryId)
4045
}

src/main/scala/za/co/absa/hyperdrive/trigger/models/tables/HistoryTableQuery.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ trait HistoryTableQuery {
3838
)
3939
}
4040

41+
def getHistoryEntity(id: Long)(implicit ec: ExecutionContext): DBIOAction[T#TableElementType, NoStream, Effect.Read] = {
42+
val queryResult = tableQuery
43+
.filter(_.id === id)
44+
.result
45+
46+
queryResult.map(
47+
_.headOption.getOrElse(
48+
throw new Exception(s"Entity with #${id} doesn't exist on ${ru.typeOf[T]}.")
49+
)
50+
)
51+
}
52+
4153
def getEntitiesFromHistory(leftId: Long, rightId: Long)(implicit ec: ExecutionContext): DBIOAction[HistoryPair[T#TableElementType], NoStream, Effect.Read] = {
4254
val queryResult = tableQuery
4355
.join(tableQuery).on(_.id === leftId && _.id === rightId)

src/main/scala/za/co/absa/hyperdrive/trigger/persistance/JobTemplateHistoryRepository.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ trait JobTemplateHistoryRepository extends Repository {
3131
private[persistance] def delete(jobTemplate: JobTemplate, user: String)(implicit ec: ExecutionContext): DBIO[Long]
3232

3333
def getHistoryForJobTemplate(jobTemplateId: Long)(implicit ec: ExecutionContext): Future[Seq[History]]
34+
def getJobTemplateFromHistory(jobTemplateHistoryId: Long)(implicit ec: ExecutionContext): Future[JobTemplate]
3435
def getJobTemplatesFromHistory(leftJobTemplateHistoryId: Long, rightJobTemplateHistoryId: Long)(implicit ec: ExecutionContext): Future[HistoryPair[JobTemplateHistory]]
3536
}
3637

@@ -68,6 +69,10 @@ class JobTemplateHistoryRepositoryImpl @Inject()(val dbProvider: DatabaseProvide
6869
db.run(jobTemplateHistoryTable.getHistoryForEntity(jobTemplateId))
6970
}
7071

72+
override def getJobTemplateFromHistory(jobTemplateHistoryId: Long)(implicit ec: ExecutionContext): Future[JobTemplate] = {
73+
db.run(jobTemplateHistoryTable.getHistoryEntity(jobTemplateHistoryId).map(_.jobTemplate))
74+
}
75+
7176
override def getJobTemplatesFromHistory(leftJobTemplateHistoryId: Long, rightJobTemplateHistoryId: Long)(implicit ec: ExecutionContext): Future[HistoryPair[JobTemplateHistory]] = {
7277
db.run(jobTemplateHistoryTable.getEntitiesFromHistory(leftJobTemplateHistoryId, rightJobTemplateHistoryId))
7378
}

src/main/scala/za/co/absa/hyperdrive/trigger/persistance/NotificationRuleHistoryRepository.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ trait NotificationRuleHistoryRepository extends Repository {
3131
private[persistance] def delete(notificationRule: NotificationRule, user: String)(implicit ec: ExecutionContext): DBIO[Long]
3232

3333
def getHistoryForNotificationRule(notificationRuleId: Long)(implicit ec: ExecutionContext): Future[Seq[History]]
34+
def getNotificationRuleFromHistory(notificationRuleHistoryId: Long)(implicit ec: ExecutionContext): Future[NotificationRule]
3435
def getNotificationRulesFromHistory(leftNotificationRuleHistoryId: Long, rightNotificationRuleHistoryId: Long)(implicit ec: ExecutionContext): Future[HistoryPair[NotificationRuleHistory]]
3536
}
3637

@@ -68,6 +69,10 @@ class NotificationRuleHistoryRepositoryImpl @Inject()(val dbProvider: DatabasePr
6869
db.run(notificationRuleHistoryTable.getHistoryForEntity(notificationRuleId))
6970
}
7071

72+
override def getNotificationRuleFromHistory(notificationRuleHistoryId: Long)(implicit ec: ExecutionContext): Future[NotificationRule] = {
73+
db.run(notificationRuleHistoryTable.getHistoryEntity(notificationRuleHistoryId).map(_.notificationRule))
74+
}
75+
7176
override def getNotificationRulesFromHistory(leftNotificationRuleHistoryId: Long, rightNotificationRuleHistoryId: Long)
7277
(implicit ec: ExecutionContext): Future[HistoryPair[NotificationRuleHistory]] = {
7378
db.run(notificationRuleHistoryTable.getEntitiesFromHistory(

0 commit comments

Comments
 (0)