Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add institution state to serialization.conf #4965

Open
wants to merge 1 commit into
base: post-filing-2025
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions common/src/main/protobuf/institution.institutionstate.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

option java_package = "hmda.persistence.serialization";
option optimize_for = SPEED;

import "institution.proto";
import "filing.proto";

message InstitutionStateMessage {
InstitutionMessage institution = 1;
repeated FilingMessage filings = 2;
}
2 changes: 2 additions & 0 deletions common/src/main/resources/serialization.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ akka {
institution-commands = "hmda.serialization.institution.InstitutionCommandsSerializer"
institution-events = "hmda.serialization.institution.InstitutionEventsSerializer"
institution-detail = "hmda.serialization.institution.InstitutionDetailSerializer"
institution-state = "hmda.serialization.institution.InstitutionStateSerializer"

submission-manager-commands = "hmda.serialization.submission.SubmissionManagerCommandsSerializer"
submission-commands = "hmda.serialization.submission.SubmissionCommandsSerializer"
Expand Down Expand Up @@ -133,6 +134,7 @@ akka {
"hmda.model.filing.FilingDetails" = filing-details
"hmda.persistence.filing.FilingState" = filing-state
"hmda.model.institution.InstitutionDetail" = institution-detail
"hmda.persistence.institution.InstitutionState" = institution-state

"hmda.messages.submission.HmdaRawDataCommands$AddLines" = hmda-raw-commands
"hmda.messages.submission.HmdaRawDataEvents$LineAdded" = hmda-raw-events
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hmda.serialization.institution

import hmda.persistence.institution.InstitutionState
import hmda.persistence.serialization.institution.InstitutionMessage
import hmda.persistence.serialization.institution.institutionstate.InstitutionStateMessage
import hmda.serialization.filing.FilingProtobufConverter._
import hmda.serialization.institution.InstitutionProtobufConverter._

object InstitutionStateProtobufConverter {

def institutionStateToProtobuf(institutionState: InstitutionState): InstitutionStateMessage =
InstitutionStateMessage(
if (institutionState.institution.isEmpty) None
else Some(institutionToProtobuf(institutionState.institution.get)),
institutionState.filings.map(s => filingToProtobuf(s))
)

def institutionStateFromProtobuf(institutionStateMessage: InstitutionStateMessage): InstitutionState =
InstitutionState(
institution = Some(institutionFromProtobuf(institutionStateMessage.institution.getOrElse(InstitutionMessage()))),
filings = institutionStateMessage.filings
.map(s => filingFromProtobuf(s))
.toList
)

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package hmda.serialization.institution

import java.io.NotSerializableException

import akka.serialization.SerializerWithStringManifest
import hmda.persistence.institution.InstitutionState
import hmda.persistence.serialization.institution.institutionstate.InstitutionStateMessage
import hmda.serialization.institution.InstitutionStateProtobufConverter._
// $COVERAGE-OFF$
class InstitutionStateSerializer extends SerializerWithStringManifest {
override def identifier: Int = 120

final val InstitutionStateManifest = classOf[InstitutionState].getName

override def manifest(o: AnyRef): String = o.getClass.getName

override def toBinary(o: AnyRef): Array[Byte] = o match {
case evt: InstitutionState =>
institutionStateToProtobuf(evt).toByteArray
case _ =>
throw new IllegalArgumentException(s"Cannot serialize object of type [${o.getClass.getName}]")
}

override def fromBinary(bytes: Array[Byte], manifest: String): AnyRef =
manifest match {
case InstitutionStateManifest =>
institutionStateFromProtobuf(InstitutionStateMessage.parseFrom(bytes))
case _ =>
throw new NotSerializableException(s"Unimplemented deserialization of message with manifest [$manifest] in [${getClass.getName}]")
}

}
// $COVERAGE-OFF$
Loading