Skip to content

Commit

Permalink
Load specified SimDataset in Constraints
Browse files Browse the repository at this point in the history
- Close `GetValidConstraintRunsAction`
  • Loading branch information
Mythicaeda committed Oct 2, 2023
1 parent 9fdc699 commit 7ceb437
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public void insertConstraintRuns(

@Override
public Map<Long, ConstraintRunRecord> getValidConstraintRuns(List<Long> 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<Long, ConstraintRunRecord>();

for (final var constraintRun : constraintRuns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -48,10 +48,16 @@ public ConstraintAction(
}

public List<ConstraintResult> getViolations(final PlanId planId, final Optional<SimulationDatasetId> 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<SimulationResultsHandle> resultsHandle$;
if(simulationDatasetId.isPresent()){
resultsHandle$ = this.simulationService.get(planId, simulationDatasetId.get());
} else {
resultsHandle$ = this.simulationService.get(planId);
}


final var constraintCode = new HashMap<Long, Constraint>();

try {
Expand All @@ -61,10 +67,9 @@ public List<ConstraintResult> 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<Long, ConstraintResult>();

final var validConstraintRuns = this.constraintService.getValidConstraintRuns(constraintCode.values().stream().toList(), simDatasetId);
Expand Down

0 comments on commit 7ceb437

Please sign in to comment.