Skip to content

Commit c1f8974

Browse files
committed
Less duplication in Validation streaming
When an action is going to happen regardless of validation outcome (e.g. sending the validated lar to be persisted), do that action before validation.
1 parent bd9c139 commit c1f8974

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

persistence/src/main/scala/hmda/persistence/processing/HmdaFileValidator.scala

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -139,45 +139,42 @@ class HmdaFileValidator(supervisor: ActorRef, validationStats: ActorRef, submiss
139139
override def receiveCommand: Receive = {
140140

141141
case BeginValidation(replyTo) =>
142-
val validationStarted = ValidationStarted(submissionId)
143-
sender() ! validationStarted
142+
sender() ! ValidationStarted(submissionId)
144143
events(parserPersistenceId)
145144
.filter(x => x.isInstanceOf[TsParsed])
146-
.map(e => e.asInstanceOf[TsParsed].ts)
147-
.map(ts => (ts, validateTs(ts, ctx).toEither))
145+
.map { e => e.asInstanceOf[TsParsed].ts }
146+
.map { ts =>
147+
self ! ts
148+
validationStats ! AddSubmissionTaxId(ts.taxId, submissionId)
149+
self ! ValidateAggregate(ts)
150+
validateTs(ts, ctx).toEither
151+
}
148152
.map {
149-
case (_, Right(ts)) =>
150-
validationStats ! AddSubmissionTaxId(ts.taxId, submissionId)
151-
ValidateAggregate(ts)
152-
case (ts, Left(errors)) =>
153-
validationStats ! AddSubmissionTaxId(ts.taxId, submissionId)
154-
self ! ValidateAggregate(ts)
155-
TsValidationErrors(errors.list.toList)
153+
case Right(_) => // do nothing
154+
case Left(errors) => TsValidationErrors(errors.list.toList)
156155
}
157156
.runWith(Sink.actorRef(self, NotUsed))
158157

159158
val larSource: Source[LoanApplicationRegister, NotUsed] = events(parserPersistenceId)
160159
.filter(x => x.isInstanceOf[LarParsed])
161160
.map(e => e.asInstanceOf[LarParsed].lar)
162161

163-
larSource.map(lar => (lar, validateLar(lar, ctx).toEither))
162+
larSource.map { lar =>
163+
self ! lar
164+
validateLar(lar, ctx).toEither
165+
}
164166
.map {
165-
case (_, Right(l)) => l
166-
case (lar, Left(errors)) => {
167-
self ! lar
168-
LarValidationErrors(errors.list.toList)
169-
}
167+
case Right(_) => // do nothing
168+
case Left(errors) => LarValidationErrors(errors.list.toList)
170169
}
171170
.runWith(Sink.actorRef(self, ValidateMacro(larSource, replyTo)))
172171

173172
case ValidateAggregate(ts) =>
174173
performAsyncChecks(ts, ctx)
175174
.map(validations => validations.toEither)
176175
.map {
177-
case Right(_) => self ! ts
178-
case Left(errors) =>
179-
self ! TsValidationErrors(errors.list.toList)
180-
self ! ts
176+
case Right(_) => // do nothing
177+
case Left(errors) => self ! TsValidationErrors(errors.list.toList)
181178
}
182179

183180
case ts: TransmittalSheet =>

0 commit comments

Comments
 (0)