@@ -49,11 +49,7 @@ class FilingPersistence(institutionId: String) extends HmdaPersistentActor {
49
49
override def receiveCommand : Receive = super .receiveCommand orElse {
50
50
case CreateFiling (f) =>
51
51
if (! state.filings.map(_.period).contains(f.period)) {
52
- persist(FilingCreated (f)) { e =>
53
- log.debug(s " Persisted: $f" )
54
- updateState(e)
55
- sender() ! Some (f)
56
- }
52
+ persistFilingEvent(FilingCreated (f), f)
57
53
} else {
58
54
sender() ! None
59
55
log.warning(s " Could not create Filing. Filing period ${f.period} already exists for institution $institutionId. " )
@@ -65,11 +61,7 @@ class FilingPersistence(institutionId: String) extends HmdaPersistentActor {
65
61
val startTime = if (newStatus == InProgress ) System .currentTimeMillis else filing.start
66
62
val endTime = if (newStatus == Completed ) System .currentTimeMillis else filing.end
67
63
val updatedFiling = filing.copy(status = newStatus, start = startTime, end = endTime)
68
- persist(FilingStatusUpdated (updatedFiling)) { e =>
69
- log.debug(s " persisted: $updatedFiling" )
70
- updateState(e)
71
- sender() ! Some (updatedFiling)
72
- }
64
+ persistFilingEvent(FilingStatusUpdated (updatedFiling), updatedFiling)
73
65
case None =>
74
66
sender() ! None
75
67
log.warning(s " Could not update filing status. Institution $institutionId, filing period $period" )
@@ -87,4 +79,12 @@ class FilingPersistence(institutionId: String) extends HmdaPersistentActor {
87
79
sender() ! state.filings
88
80
89
81
}
82
+
83
+ private def persistFilingEvent (event : Event , filing : Filing ) = {
84
+ persist(event) { e =>
85
+ log.debug(s " persisted: $filing" )
86
+ updateState(e)
87
+ sender() ! Some (filing)
88
+ }
89
+ }
90
90
}
0 commit comments