From 809ff13961dca8bfc3b284a176da98d1561c51ca Mon Sep 17 00:00:00 2001 From: w-hayes <54031103+w-hayes@users.noreply.github.com> Date: Sun, 17 Mar 2024 20:31:50 +0200 Subject: [PATCH] Dev new config (#204) * Tidyup configuration * Tidyup configuration * bounce postgresql lib version - vulnerable to SQL Injection * bounce postgresql lib version 4.6.2 - vulnerable to SQL Injection --- .../configuration/CustomLinkerBackEnd.scala | 15 +++--- .../scala/configuration/CustomPatient.scala | 18 ++++++- .../CustomPostgresqlGoldenRecord.scala | 11 +--- .../CustomPostgresqlInteraction.scala | 8 +-- .../src/main/scala/configuration/Main.scala | 4 +- .../postgresql/CustomGoldenRecordData.java | 18 ------- .../postgresql/CustomInteractionData.java | 18 ------- .../libmpi/postgresql/GoldenRecordData.java | 11 ++++ .../libmpi/postgresql/InteractionData.java | 12 +++++ .../libmpi/postgresql/NodeGoldenRecord.java | 4 +- .../libmpi/postgresql/NodeInteraction.java | 4 +- .../libmpi/postgresql/PostgresqlQueries.java | 10 ++-- .../shared/models/CustomDemographicData.java | 38 ++++---------- .../linker/backend/CustomLinkerBackEnd.java | 50 +++++++++++-------- .../jembi/jempi/linker/backend/LinkerCR.java | 9 +++- .../jembi/jempi/linker/backend/LinkerDWH.java | 15 ++---- JeMPI_Apps/pom.xml | 2 +- 17 files changed, 114 insertions(+), 133 deletions(-) delete mode 100644 JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/CustomGoldenRecordData.java delete mode 100644 JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/CustomInteractionData.java create mode 100644 JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/GoldenRecordData.java create mode 100644 JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/InteractionData.java diff --git a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomLinkerBackEnd.scala b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomLinkerBackEnd.scala index f3660d3ec..2ba5dbbf0 100644 --- a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomLinkerBackEnd.scala +++ b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomLinkerBackEnd.scala @@ -29,6 +29,7 @@ object CustomLinkerBackEnd { .mkString(sys.props("line.separator")) } + /* def createApplyFunctions(): String = { def applyFields(): String = { @@ -59,8 +60,10 @@ object CustomLinkerBackEnd { |${" " * 3} interaction.uniqueInteractionData(), |${" " * 3} new CustomDemographicData(${applyFields()})); |${" " * 3}}""".stripMargin + } + */ config.demographicFields .filter(f => f.linkMetaData.isDefined) .foreach(f => { @@ -87,14 +90,12 @@ object CustomLinkerBackEnd { | |${createGenerateFunctions()} | - | ${createApplyFunctions()} - | | static void updateGoldenRecordFields( | final LibMPI libMPI, | final float threshold, | final String interactionId, | final String goldenId) { - | final var expandedGoldenRecord = libMPI.findExpandedGoldenRecords(List.of(goldenId)).get(0); + | final var expandedGoldenRecord = libMPI.findExpandedGoldenRecords(List.of(goldenId)).getFirst(); | final var goldenRecord = expandedGoldenRecord.goldenRecord(); | final var demographicData = goldenRecord.demographicData(); | var k = 0; @@ -105,13 +106,15 @@ object CustomLinkerBackEnd { val fieldName = Utils.snakeCaseToCamelCase(field_name) writer.println( s"""${" " * 6}k += LinkerDWH.helperUpdateGoldenRecordField(libMPI, interactionId, expandedGoldenRecord, - |${" " * 6} "$fieldName", demographicData.$fieldName, CustomDemographicData::get${fieldName - .charAt(0) - .toUpper}${fieldName.substring(1)}) + |${" " * 6} "$fieldName", demographicData.$fieldName, + |${" " * 6} expandedGoldenRecord.interactionsWithScore() + |${" " * 6} .stream() + |${" " * 6} .map(rec -> rec.interaction().demographicData().$fieldName)) |${" " * 12}? 1 |${" " * 12}: 0;""".stripMargin ) }) + writer.println(s""" |${" " * 6}if (k > 0) { |${" " * 6} LinkerDWH.helperUpdateInteractionsScore(libMPI, threshold, expandedGoldenRecord); diff --git a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPatient.scala b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPatient.scala index afdb2f8b5..08dfee961 100644 --- a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPatient.scala +++ b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPatient.scala @@ -61,7 +61,7 @@ private object CustomPatient { ) } writer.println() - for (field <- config.demographicFields) { + /* for (field <- config.demographicFields) { val typeString = field.fieldType val fieldName = Utils.snakeCaseToCamelCase(field.fieldName) writer.println( @@ -73,7 +73,7 @@ private object CustomPatient { |""".stripMargin ) } - + */ writer.println( s"""${" " * indent * 1}public $customClassNameCustomDemographicData() {""".stripMargin ) @@ -83,6 +83,20 @@ private object CustomPatient { |""".stripMargin ) + writer.print( + s"""${" " * indent * 1}public $customClassNameCustomDemographicData(final $customClassNameCustomDemographicData demographicData) {""" + ) + config.demographicFields.zipWithIndex.foreach { case (field, idx) => + val fieldName = Utils.snakeCaseToCamelCase(field.fieldName) + writer.print( + s""" + |${" " * indent * 2}this.$fieldName = demographicData.$fieldName;""".stripMargin + ) + } + writer.println(s""" + |${" " * indent * 1}} + |""".stripMargin) + writer.println( s"""${" " * indent * 1}public $customClassNameCustomDemographicData(""".stripMargin ) diff --git a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPostgresqlGoldenRecord.scala b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPostgresqlGoldenRecord.scala index 0a24eebdd..1f35838c6 100644 --- a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPostgresqlGoldenRecord.scala +++ b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPostgresqlGoldenRecord.scala @@ -23,17 +23,10 @@ private object CustomPostgresqlGoldenRecord { |final class $customClassName extends CustomDemographicData implements NodeData { | | $customClassName(final CustomDemographicData customDemographicData) { - | super(${fields - .map(field => - s"""customDemographicData.${Utils.snakeCaseToCamelCase( - field.fieldName - )}""" - ) - .mkString(s",${sys.props("line.separator")} ")}); + | super(customDemographicData); | } | - |} - |""".stripMargin + |}""".stripMargin ) writer.close() } diff --git a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPostgresqlInteraction.scala b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPostgresqlInteraction.scala index 3b0edefa4..76a023149 100644 --- a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPostgresqlInteraction.scala +++ b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/CustomPostgresqlInteraction.scala @@ -23,13 +23,7 @@ private object CustomPostgresqlInteraction { |final class $customClassName extends CustomDemographicData implements NodeData { | | $customClassName(final CustomDemographicData customDemographicData) { - | super(${fields - .map(field => - s"""customDemographicData.${Utils.snakeCaseToCamelCase( - field.fieldName - )}""" - ) - .mkString(s",${sys.props("line.separator")} ")}); + | super(customDemographicData); | } | |} diff --git a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/Main.scala b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/Main.scala index 3ca922627..286531091 100644 --- a/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/Main.scala +++ b/JeMPI_Apps/JeMPI_Configuration/src/main/scala/configuration/Main.scala @@ -44,8 +44,8 @@ object Main { CustomLinkerProbabilistic.generate(config) CustomLinkerBackEnd.generate(config) CustomLinkerMU.generate(config) - CustomPostgresqlInteraction.generate(config.demographicFields) - CustomPostgresqlGoldenRecord.generate(config.demographicFields) +// CustomPostgresqlInteraction.generate(config.demographicFields) +// CustomPostgresqlGoldenRecord.generate(config.demographicFields) CustomAsyncHelper.generate(config) CustomPatient.generate(config) CustomFieldTallies.generate(config) diff --git a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/CustomGoldenRecordData.java b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/CustomGoldenRecordData.java deleted file mode 100644 index dbac16877..000000000 --- a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/CustomGoldenRecordData.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.jembi.jempi.libmpi.postgresql; - -import org.jembi.jempi.shared.models.CustomDemographicData; - -final class CustomGoldenRecordData extends CustomDemographicData implements NodeData { - - CustomGoldenRecordData(final CustomDemographicData customDemographicData) { - super(customDemographicData.givenName, - customDemographicData.familyName, - customDemographicData.gender, - customDemographicData.dob, - customDemographicData.city, - customDemographicData.phoneNumber, - customDemographicData.nationalId); - } - -} - diff --git a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/CustomInteractionData.java b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/CustomInteractionData.java deleted file mode 100644 index 38ae49ac7..000000000 --- a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/CustomInteractionData.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.jembi.jempi.libmpi.postgresql; - -import org.jembi.jempi.shared.models.CustomDemographicData; - -final class CustomInteractionData extends CustomDemographicData implements NodeData { - - CustomInteractionData(final CustomDemographicData customDemographicData) { - super(customDemographicData.givenName, - customDemographicData.familyName, - customDemographicData.gender, - customDemographicData.dob, - customDemographicData.city, - customDemographicData.phoneNumber, - customDemographicData.nationalId); - } - -} - diff --git a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/GoldenRecordData.java b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/GoldenRecordData.java new file mode 100644 index 000000000..067e9784e --- /dev/null +++ b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/GoldenRecordData.java @@ -0,0 +1,11 @@ +package org.jembi.jempi.libmpi.postgresql; + +import org.jembi.jempi.shared.models.CustomDemographicData; + +final class GoldenRecordData extends CustomDemographicData implements NodeData { + + GoldenRecordData(final CustomDemographicData customDemographicData) { + super(customDemographicData); + } + +} diff --git a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/InteractionData.java b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/InteractionData.java new file mode 100644 index 000000000..573631e57 --- /dev/null +++ b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/InteractionData.java @@ -0,0 +1,12 @@ +package org.jembi.jempi.libmpi.postgresql; + +import org.jembi.jempi.shared.models.CustomDemographicData; + +final class InteractionData extends CustomDemographicData implements NodeData { + + InteractionData(final CustomDemographicData customDemographicData) { + super(customDemographicData); + } + +} + diff --git a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/NodeGoldenRecord.java b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/NodeGoldenRecord.java index 762cc621a..9454057e0 100644 --- a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/NodeGoldenRecord.java +++ b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/NodeGoldenRecord.java @@ -7,10 +7,10 @@ record NodeGoldenRecord( NodeType type, UUID uid, - CustomGoldenRecordData data) implements Node { + GoldenRecordData data) implements Node { NodeGoldenRecord(final CustomDemographicData demographicData) { - this(NodeType.GOLDEN_RECORD, null, new CustomGoldenRecordData(demographicData)); + this(NodeType.GOLDEN_RECORD, null, new GoldenRecordData(demographicData)); } public NodeType getType() { diff --git a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/NodeInteraction.java b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/NodeInteraction.java index 9e11b507c..3d88b624b 100644 --- a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/NodeInteraction.java +++ b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/NodeInteraction.java @@ -7,10 +7,10 @@ record NodeInteraction( NodeType type, UUID uid, - CustomInteractionData data) implements Node { + InteractionData data) implements Node { NodeInteraction(final CustomDemographicData demographicData) { - this(NodeType.INTERACTION, null, new CustomInteractionData(demographicData)); + this(NodeType.INTERACTION, null, new InteractionData(demographicData)); } public NodeType getType() { diff --git a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/PostgresqlQueries.java b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/PostgresqlQueries.java index 5c4c36a4b..4c03708f6 100644 --- a/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/PostgresqlQueries.java +++ b/JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/postgresql/PostgresqlQueries.java @@ -153,7 +153,7 @@ public static List getGoldenRecordsOfInteraction(final UUID ei while (rs.next()) { final var id = rs.getString("id"); final var json = rs.getString("fields"); - final var goldenRecordData = new CustomGoldenRecordData(OBJECT_MAPPER.readValue(json, CustomDemographicData.class)); + final var goldenRecordData = new GoldenRecordData(OBJECT_MAPPER.readValue(json, CustomDemographicData.class)); list.add(new NodeGoldenRecord(Node.NodeType.valueOf(rs.getString("type")), UUID.fromString(id), goldenRecordData)); } return list; @@ -175,7 +175,7 @@ public static List getGoldenRecordInteractions(final UUID gid) while (rs.next()) { final var id = rs.getString("id"); final var json = rs.getString("fields"); - final var interactionData = new CustomInteractionData(OBJECT_MAPPER.readValue(json, CustomDemographicData.class)); + final var interactionData = new InteractionData(OBJECT_MAPPER.readValue(json, CustomDemographicData.class)); list.add(new NodeInteraction(Node.NodeType.valueOf(rs.getString("type")), UUID.fromString(id), interactionData)); } return list; @@ -192,7 +192,7 @@ private static List findCandidatesWorker(final String sql) { while (rs.next()) { final var id = rs.getString("id"); final var json = rs.getString("fields"); - final var goldenRecordData = new CustomGoldenRecordData(OBJECT_MAPPER.readValue(json, CustomDemographicData.class)); + final var goldenRecordData = new GoldenRecordData(OBJECT_MAPPER.readValue(json, CustomDemographicData.class)); list.add(new GoldenRecord(id, null, new CustomUniqueGoldenRecordData(null), goldenRecordData)); } return list; @@ -228,7 +228,7 @@ public static NodeGoldenRecord getGoldenRecord(final UUID gid) { if (rs.next()) { final var id = rs.getString("id"); final var goldenRecordData = - new CustomGoldenRecordData(OBJECT_MAPPER.readValue(rs.getString("fields"), CustomDemographicData.class)); + new GoldenRecordData(OBJECT_MAPPER.readValue(rs.getString("fields"), CustomDemographicData.class)); return new NodeGoldenRecord(Node.NodeType.valueOf(rs.getString("type")), UUID.fromString(id), goldenRecordData); } return null; @@ -248,7 +248,7 @@ static NodeInteraction getInteraction(final UUID iid) { if (rs.next()) { final var id = rs.getString("id"); final var interactionData = - new CustomInteractionData(OBJECT_MAPPER.readValue(rs.getString("fields"), CustomDemographicData.class)); + new InteractionData(OBJECT_MAPPER.readValue(rs.getString("fields"), CustomDemographicData.class)); return new NodeInteraction(Node.NodeType.valueOf(rs.getString("type")), UUID.fromString(id), interactionData); } return null; diff --git a/JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/CustomDemographicData.java b/JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/CustomDemographicData.java index 3971ad7e9..e40b55748 100644 --- a/JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/CustomDemographicData.java +++ b/JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/CustomDemographicData.java @@ -12,38 +12,20 @@ public class CustomDemographicData { public final String phoneNumber; public final String nationalId; - public final String getGivenName() { - return givenName; - } - - public final String getFamilyName() { - return familyName; - } - - public final String getGender() { - return gender; - } - - public final String getDob() { - return dob; - } - - public final String getCity() { - return city; - } - - public final String getPhoneNumber() { - return phoneNumber; - } - - public final String getNationalId() { - return nationalId; - } - public CustomDemographicData() { this(null, null, null, null, null, null, null); } + public CustomDemographicData(final CustomDemographicData demographicData) { + this.givenName = demographicData.givenName; + this.familyName = demographicData.familyName; + this.gender = demographicData.gender; + this.dob = demographicData.dob; + this.city = demographicData.city; + this.phoneNumber = demographicData.phoneNumber; + this.nationalId = demographicData.nationalId; + } + public CustomDemographicData( final String givenName, final String familyName, diff --git a/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/CustomLinkerBackEnd.java b/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/CustomLinkerBackEnd.java index 874caa2cf..487c859ef 100644 --- a/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/CustomLinkerBackEnd.java +++ b/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/CustomLinkerBackEnd.java @@ -15,55 +15,63 @@ private CustomLinkerBackEnd() { - public static Interaction applyAutoCreateFunctions(final Interaction interaction) { - return new Interaction(interaction.interactionId(), - interaction.sourceId(), - interaction.uniqueInteractionData(), - new CustomDemographicData(interaction.demographicData().givenName, - interaction.demographicData().familyName, - interaction.demographicData().gender, - interaction.demographicData().dob, - interaction.demographicData().city, - interaction.demographicData().phoneNumber, - interaction.demographicData().nationalId)); - } - static void updateGoldenRecordFields( final LibMPI libMPI, final float threshold, final String interactionId, final String goldenId) { - final var expandedGoldenRecord = libMPI.findExpandedGoldenRecords(List.of(goldenId)).get(0); + final var expandedGoldenRecord = libMPI.findExpandedGoldenRecords(List.of(goldenId)).getFirst(); final var goldenRecord = expandedGoldenRecord.goldenRecord(); final var demographicData = goldenRecord.demographicData(); var k = 0; k += LinkerDWH.helperUpdateGoldenRecordField(libMPI, interactionId, expandedGoldenRecord, - "givenName", demographicData.givenName, CustomDemographicData::getGivenName) + "givenName", demographicData.givenName, + expandedGoldenRecord.interactionsWithScore() + .stream() + .map(rec -> rec.interaction().demographicData().givenName)) ? 1 : 0; k += LinkerDWH.helperUpdateGoldenRecordField(libMPI, interactionId, expandedGoldenRecord, - "familyName", demographicData.familyName, CustomDemographicData::getFamilyName) + "familyName", demographicData.familyName, + expandedGoldenRecord.interactionsWithScore() + .stream() + .map(rec -> rec.interaction().demographicData().familyName)) ? 1 : 0; k += LinkerDWH.helperUpdateGoldenRecordField(libMPI, interactionId, expandedGoldenRecord, - "gender", demographicData.gender, CustomDemographicData::getGender) + "gender", demographicData.gender, + expandedGoldenRecord.interactionsWithScore() + .stream() + .map(rec -> rec.interaction().demographicData().gender)) ? 1 : 0; k += LinkerDWH.helperUpdateGoldenRecordField(libMPI, interactionId, expandedGoldenRecord, - "dob", demographicData.dob, CustomDemographicData::getDob) + "dob", demographicData.dob, + expandedGoldenRecord.interactionsWithScore() + .stream() + .map(rec -> rec.interaction().demographicData().dob)) ? 1 : 0; k += LinkerDWH.helperUpdateGoldenRecordField(libMPI, interactionId, expandedGoldenRecord, - "city", demographicData.city, CustomDemographicData::getCity) + "city", demographicData.city, + expandedGoldenRecord.interactionsWithScore() + .stream() + .map(rec -> rec.interaction().demographicData().city)) ? 1 : 0; k += LinkerDWH.helperUpdateGoldenRecordField(libMPI, interactionId, expandedGoldenRecord, - "phoneNumber", demographicData.phoneNumber, CustomDemographicData::getPhoneNumber) + "phoneNumber", demographicData.phoneNumber, + expandedGoldenRecord.interactionsWithScore() + .stream() + .map(rec -> rec.interaction().demographicData().phoneNumber)) ? 1 : 0; k += LinkerDWH.helperUpdateGoldenRecordField(libMPI, interactionId, expandedGoldenRecord, - "nationalId", demographicData.nationalId, CustomDemographicData::getNationalId) + "nationalId", demographicData.nationalId, + expandedGoldenRecord.interactionsWithScore() + .stream() + .map(rec -> rec.interaction().demographicData().nationalId)) ? 1 : 0; diff --git a/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerCR.java b/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerCR.java index aee93b4cd..fbb56b57e 100644 --- a/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerCR.java +++ b/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerCR.java @@ -60,6 +60,13 @@ private static List crMatchedCandidates( } } + static Interaction applyAutoCreateFunctions(final Interaction interaction) { + return new Interaction(interaction.interactionId(), + interaction.sourceId(), + interaction.uniqueInteractionData(), + new CustomDemographicData(interaction.demographicData())); + } + static Either crRegister( final LibMPI libMPI, final ApiModels.ApiCrRegisterRequest crRegister) { @@ -74,7 +81,7 @@ static Either crRegister( final var interaction = new Interaction(null, crRegister.sourceId(), crRegister.uniqueInteractionData(), crRegister.demographicData()); final var linkInfo = - libMPI.createInteractionAndLinkToClonedGoldenRecord(CustomLinkerBackEnd.applyAutoCreateFunctions(interaction), + libMPI.createInteractionAndLinkToClonedGoldenRecord(applyAutoCreateFunctions(interaction), 1.0F); return Either.right(linkInfo); } else { diff --git a/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerDWH.java b/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerDWH.java index 6f4f4025d..362161941 100644 --- a/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerDWH.java +++ b/JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerDWH.java @@ -17,9 +17,9 @@ import java.util.*; import java.util.concurrent.ExecutionException; -import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.IntStream; +import java.util.stream.Stream; import static java.lang.Math.abs; import static org.jembi.jempi.shared.models.CustomFieldTallies.CUSTOM_FIELD_TALLIES_SUM_IDENTITY; @@ -48,18 +48,15 @@ static boolean helperUpdateGoldenRecordField( final ExpandedGoldenRecord expandedGoldenRecord, final String fieldName, final String goldenRecordFieldValue, - final Function getDemographicField) { + final Stream interactionFieldValues) { boolean changed = false; if (expandedGoldenRecord == null) { LOGGER.error("expandedGoldenRecord cannot be null"); } else { - final var mpiInteractions = expandedGoldenRecord.interactionsWithScore(); - final var freqMapGroupedByField = mpiInteractions.stream() - .map(mpiInteraction -> getDemographicField.apply(mpiInteraction.interaction() - .demographicData())) - .collect(Collectors.groupingBy(e -> e, Collectors.counting())); + final var freqMapGroupedByField = interactionFieldValues.collect(Collectors.groupingBy(e -> e, Collectors.counting())); + freqMapGroupedByField.remove(StringUtils.EMPTY); if (!freqMapGroupedByField.isEmpty()) { final var count = freqMapGroupedByField.getOrDefault(goldenRecordFieldValue, 0L); @@ -126,10 +123,6 @@ public static Either> linkInteraction( final float matchThreshold_, final String envelopStan) { -// if (LOGGER.isTraceEnabled()) { -// LOGGER.trace("{}", envelopStan); -// } - LinkStatsMeta.ConfusionMatrix confusionMatrix; CustomFieldTallies customFieldTallies = CUSTOM_FIELD_TALLIES_SUM_IDENTITY; diff --git a/JeMPI_Apps/pom.xml b/JeMPI_Apps/pom.xml index ca3b3141d..961a9d7e1 100644 --- a/JeMPI_Apps/pom.xml +++ b/JeMPI_Apps/pom.xml @@ -291,7 +291,7 @@ org.postgresql postgresql - 42.6.0 + 42.6.2