Skip to content

Commit

Permalink
Merge pull request #33 from DiSSCo/feature/mas-input
Browse files Browse the repository at this point in the history
MasInput
  • Loading branch information
southeo authored Jan 15, 2024
2 parents 7344cdf + 68596ad commit 26ee9b3
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 26 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<mockito-inline.version>5.2.0</mockito-inline.version>
<json-patch.version>1.13</json-patch.version>
<sonar.organization>dissco</sonar.organization>
<logback.version>1.4.12</logback.version>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.coverage.jacoco.xmlReportPaths>
../app-it/target/site/jacoco-aggregate/jacoco.xml
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public final class MachineAnnotationService {
private final String slaDocumentation;
private String topicName;
private int maxReplicas;
private MasInput masInput;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package eu.dissco.orchestration.backend.domain;

public record MasInput(
String inputField,
String targetField
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import eu.dissco.orchestration.backend.database.jooq.tables.records.MachineAnnotationServicesRecord;
import eu.dissco.orchestration.backend.domain.MachineAnnotationService;
import eu.dissco.orchestration.backend.domain.MachineAnnotationServiceRecord;
import eu.dissco.orchestration.backend.domain.MasInput;
import eu.dissco.orchestration.backend.exception.DisscoJsonBMappingException;
import java.time.Instant;
import java.util.Arrays;
Expand Down Expand Up @@ -57,9 +58,18 @@ public void createMachineAnnotationService(MachineAnnotationServiceRecord masRec
.set(MACHINE_ANNOTATION_SERVICES.TOPICNAME, masRecord.mas().getTopicName())
.set(MACHINE_ANNOTATION_SERVICES.MAXREPLICAS, masRecord.mas().getMaxReplicas())
.set(MACHINE_ANNOTATION_SERVICES.DELETED_ON, masRecord.deleted())
.set(MACHINE_ANNOTATION_SERVICES.MAS_INPUT, setToJSONB(masRecord.mas().getMasInput()))
.execute();
}

private JSONB setToJSONB(MasInput masInput) {
try {
return masInput != null ? JSONB.jsonb(mapper.writeValueAsString(masInput)) : null;
} catch (JsonProcessingException e) {
throw new DisscoJsonBMappingException("Failed to parse field to jsonb: " + masInput, e);
}
}

public Optional<MachineAnnotationServiceRecord> getActiveMachineAnnotationService(String id) {
return context.selectFrom(MACHINE_ANNOTATION_SERVICES)
.where(MACHINE_ANNOTATION_SERVICES.ID.eq(id))
Expand Down Expand Up @@ -90,12 +100,22 @@ private MachineAnnotationServiceRecord mapToMasRecord(
machineAnnotationServicesRecord.getSupportContact(),
machineAnnotationServicesRecord.getSlaDocumentation(),
machineAnnotationServicesRecord.getTopicname(),
machineAnnotationServicesRecord.getMaxreplicas()
machineAnnotationServicesRecord.getMaxreplicas(),
mapToMasInput(machineAnnotationServicesRecord.getMasInput())
),
machineAnnotationServicesRecord.getDeletedOn()
);
}

private MasInput mapToMasInput(JSONB masInput) {
try {
return masInput != null ? mapper.readValue(masInput.data(), MasInput.class) : null;
} catch (JsonProcessingException e) {
throw new DisscoJsonBMappingException("Failed to parse masInput to json: " + masInput.data(),
e);
}
}

private JsonNode mapToJson(JSONB jsonb) {
try {
if (jsonb != null) {
Expand Down Expand Up @@ -161,6 +181,7 @@ public void updateMachineAnnotationService(MachineAnnotationServiceRecord masRec
.set(MACHINE_ANNOTATION_SERVICES.TOPICNAME, masRecord.mas().getTopicName())
.set(MACHINE_ANNOTATION_SERVICES.MAXREPLICAS, masRecord.mas().getMaxReplicas())
.set(MACHINE_ANNOTATION_SERVICES.DELETED_ON, masRecord.deleted())
.set(MACHINE_ANNOTATION_SERVICES.MAS_INPUT, setToJSONB(masRecord.mas().getMasInput()))
.where(MACHINE_ANNOTATION_SERVICES.ID.eq(masRecord.id()))
.execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static eu.dissco.orchestration.backend.testutils.TestUtils.MAPPER;
import static eu.dissco.orchestration.backend.testutils.TestUtils.OBJECT_CREATOR;
import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMas;
import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMasInput;
import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMasRecord;
import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -45,6 +46,20 @@ void testCreateMas() {
assertThat(result).containsOnly(masRecord);
}

@Test
void testCreateMasNoMasInput() {
// Given
var masRecord = givenMasRecord(1, null);

// When
repository.createMachineAnnotationService(masRecord);
var result = repository.getMachineAnnotationServices(1, 10);

// Then
assertThat(result).containsOnly(masRecord);
}


@Test
void testUpdateMas() {
// Given
Expand Down Expand Up @@ -73,6 +88,19 @@ void testGetMasById() {
assertThat(result).isEqualTo(expected);
}

@Test
void testGetMasByIdNoMasInput() {
// Given
var expected = givenMasRecord(1, null);
postMass(List.of(expected));

// When
var result = repository.getMachineAnnotationService(HANDLE);

// Then
assertThat(result).isEqualTo(expected);
}

@Test
void testGetMass() {
// Given
Expand Down Expand Up @@ -186,7 +214,8 @@ private MachineAnnotationServiceRecord givenUpdatedRecord() {
"[email protected]",
"https://www.know.dissco.tech/no_sla",
"fancy-topic-name",
2
2,
givenMasInput()
),
null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static eu.dissco.orchestration.backend.testutils.TestUtils.OBJECT_CREATOR;
import static eu.dissco.orchestration.backend.testutils.TestUtils.SUFFIX;
import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMas;
import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMasInput;
import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMasRecord;
import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMasRecordResponse;
import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMasSingleJsonApiWrapper;
Expand Down Expand Up @@ -641,7 +642,7 @@ private Optional<MachineAnnotationServiceRecord> buildOptionalPrevRecord() {
OBJECT_CREATOR,
new MachineAnnotationService("Another name", "public.ecr.aws/dissco/fancy-mas",
"less-fancy", MAPPER.createObjectNode(), null, null, null, null, null, null, null, null,
null, "another-topic-name", 1),
null, "another-topic-name", 1, givenMasInput()),
null
));
}
Expand Down
Loading

0 comments on commit 26ee9b3

Please sign in to comment.