diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinBindings.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinBindings.java index ac2ee5c9e3..9b4575e8ce 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinBindings.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinBindings.java @@ -6,6 +6,7 @@ import gov.nasa.jpl.aerie.merlin.protocol.types.InstantiationException; import gov.nasa.jpl.aerie.merlin.server.exceptions.NoSuchPlanDatasetException; import gov.nasa.jpl.aerie.merlin.server.exceptions.NoSuchPlanException; +import gov.nasa.jpl.aerie.merlin.server.exceptions.SimulationDatasetMismatchException; import gov.nasa.jpl.aerie.merlin.server.services.ConstraintAction; import gov.nasa.jpl.aerie.merlin.server.models.HasuraAction; import gov.nasa.jpl.aerie.merlin.server.models.PlanId; @@ -250,6 +251,8 @@ private void getConstraintViolations(final Context ctx) { ctx.status(404).result(ExceptionSerializers.serializeNoSuchPlanException(ex).toString()); } catch (final InputMismatchException ex) { ctx.status(404).result(ResponseSerializers.serializeInputMismatchException(ex).toString()); + } catch (SimulationDatasetMismatchException ex) { + ctx.status(404).result(ResponseSerializers.serializeSimulationDatasetMismatchException(ex).toString()); } catch (final PermissionsServiceException ex) { ctx.status(503).result(ExceptionSerializers.serializePermissionsServiceException(ex).toString()); } catch (final Unauthorized ex) { diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/postgres/PostgresConstraintRepository.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/postgres/PostgresConstraintRepository.java index ef5d823dc2..13a29000d5 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/postgres/PostgresConstraintRepository.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/postgres/PostgresConstraintRepository.java @@ -35,8 +35,9 @@ public void insertConstraintRuns( @Override public Map getValidConstraintRuns(List constraintIds, SimulationDatasetId simulationDatasetId) { - try (final var connection = this.dataSource.getConnection()) { - final var constraintRuns = new GetValidConstraintRunsAction(connection, constraintIds, simulationDatasetId).get(); + try (final var connection = this.dataSource.getConnection(); + final var validConstraintRunAction = new GetValidConstraintRunsAction(connection, constraintIds, simulationDatasetId)) { + final var constraintRuns = validConstraintRunAction.get(); final var validConstraintRuns = new HashMap(); for (final var constraintRun : constraintRuns) { diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintAction.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintAction.java index fbe49780d3..3cdeb271cd 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintAction.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintAction.java @@ -9,6 +9,7 @@ import gov.nasa.jpl.aerie.constraints.time.Interval; import gov.nasa.jpl.aerie.constraints.tree.Expression; import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; +import gov.nasa.jpl.aerie.merlin.server.exceptions.SimulationDatasetMismatchException; import gov.nasa.jpl.aerie.merlin.server.models.SimulationDatasetId; import gov.nasa.jpl.aerie.merlin.server.models.SimulationResultsHandle; import gov.nasa.jpl.aerie.merlin.server.exceptions.NoSuchPlanException; @@ -23,7 +24,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Optional; public class ConstraintAction { @@ -48,10 +48,16 @@ public ConstraintAction( } public List getViolations(final PlanId planId, final Optional simulationDatasetId) - throws NoSuchPlanException, MissionModelService.NoSuchMissionModelException - { + throws NoSuchPlanException, MissionModelService.NoSuchMissionModelException, SimulationDatasetMismatchException { final var plan = this.planService.getPlanForValidation(planId); - final var revisionData = this.planService.getPlanRevisionData(planId); + final Optional resultsHandle$; + if(simulationDatasetId.isPresent()){ + resultsHandle$ = this.simulationService.get(planId, simulationDatasetId.get()); + } else { + resultsHandle$ = this.simulationService.get(planId); + } + + final var constraintCode = new HashMap(); try { @@ -61,10 +67,9 @@ public List getViolations(final PlanId planId, final Optional< throw new RuntimeException("Assumption falsified -- mission model for existing plan does not exist"); } - final var resultsHandle$ = this.simulationService.get(planId, revisionData); - final var simDatasetId = simulationDatasetId.orElseGet(() -> resultsHandle$ + final var simDatasetId = resultsHandle$ .map(SimulationResultsHandle::getSimulationDatasetId) - .orElseThrow(() -> new InputMismatchException("no simulation datasets found for plan id " + planId.id()))); + .orElseThrow(() -> new InputMismatchException("no simulation datasets found for plan id " + planId.id())); final var violations = new HashMap(); final var validConstraintRuns = this.constraintService.getValidConstraintRuns(constraintCode.values().stream().toList(), simDatasetId);