Skip to content

Commit

Permalink
Dev new config (#204)
Browse files Browse the repository at this point in the history
* Tidyup configuration

* Tidyup configuration

* bounce postgresql lib version - vulnerable to SQL Injection

* bounce postgresql lib version 4.6.2 - vulnerable to SQL Injection
  • Loading branch information
w-hayes authored Mar 17, 2024
1 parent bd32f54 commit 809ff13
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object CustomLinkerBackEnd {
.mkString(sys.props("line.separator"))
}

/*
def createApplyFunctions(): String = {
def applyFields(): String = {
Expand Down Expand Up @@ -59,8 +60,10 @@ object CustomLinkerBackEnd {
|${" " * 3} interaction.uniqueInteractionData(),
|${" " * 3} new CustomDemographicData(${applyFields()}));
|${" " * 3}}""".stripMargin
}
*/
config.demographicFields
.filter(f => f.linkMetaData.isDefined)
.foreach(f => {
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -73,7 +73,7 @@ private object CustomPatient {
|""".stripMargin
)
}

*/
writer.println(
s"""${" " * indent * 1}public $customClassNameCustomDemographicData() {""".stripMargin
)
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
| }
|
|}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static List<NodeGoldenRecord> 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;
Expand All @@ -175,7 +175,7 @@ public static List<NodeInteraction> 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;
Expand All @@ -192,7 +192,7 @@ private static List<GoldenRecord> 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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 809ff13

Please sign in to comment.