diff --git a/deployment/hasura/metadata/actions.graphql b/deployment/hasura/metadata/actions.graphql index f8514eba4f..314b6374ba 100644 --- a/deployment/hasura/metadata/actions.graphql +++ b/deployment/hasura/metadata/actions.graphql @@ -53,12 +53,12 @@ type Mutation { } type Query { - getModelEffectiveArguments(missionModelId: ID!, modelArguments: ModelArguments!): EffectiveArgumentsResponse + getModelEffectiveArguments(missionModelId: Int!, modelArguments: ModelArguments!): EffectiveArgumentsResponse } type Query { getActivityEffectiveArguments( - missionModelId: ID! + missionModelId: Int! activityTypeName: String! activityArguments: ActivityArguments! ): EffectiveArgumentsResponse @@ -67,7 +67,7 @@ type Query { type Query { getActivityEffectiveArgumentsBulk( - missionModelId: ID! + missionModelId: Int! activities: [EffectiveArgumentsInput!]! ): [EffectiveArgumentsResponse!]! } @@ -81,7 +81,7 @@ type Query { } type Query { - resourceTypes(missionModelId: ID!): [ResourceType!]! + resourceTypes(missionModelId: Int!): [ResourceType!]! } type Query { @@ -93,7 +93,7 @@ type Query { } type Query { - constraintsDslTypescript(missionModelId: ID!, planId: Int): DslTypescriptResponse + constraintsDslTypescript(missionModelId: Int!, planId: Int): DslTypescriptResponse } type Query { @@ -111,13 +111,13 @@ type Query { type Query { validateActivityArguments( activityTypeName: String! - missionModelId: ID! + missionModelId: Int! activityArguments: ActivityArguments! ): ValidationResponse } type Query { - validateModelArguments(missionModelId: ID!, modelArguments: ModelArguments!): ValidationResponse + validateModelArguments(missionModelId: Int!, modelArguments: ModelArguments!): ValidationResponse } type Query { diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/AutomaticValidationTests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/AutomaticValidationTests.java index b86b03fe57..17d618e627 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/AutomaticValidationTests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/AutomaticValidationTests.java @@ -150,7 +150,7 @@ void noSuchMissionModelError() throws IOException, InterruptedException { final var activityValidations = hasura.getActivityValidations(planId); final ActivityValidation activityValidation = activityValidations.get((long) activityId); assertEquals( - new ActivityValidation.NoSuchMissionModelFailure("no such mission model", "0"), + new ActivityValidation.NoSuchMissionModelFailure("no such mission model", 0), activityValidation ); } diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/BindingsTests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/BindingsTests.java index 36e9244035..4e3ae03126 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/BindingsTests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/BindingsTests.java @@ -559,7 +559,7 @@ void invalidMissionModelId() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "validateActivityArguments")) .add("input", Json.createObjectBuilder() - .add("missionModelId", String.valueOf(-1)) + .add("missionModelId", -1) .add("activityTypeName", "BiteBanana") .add("activityArguments", JsonValue.EMPTY_JSON_OBJECT)) .add("request_query", "") @@ -577,7 +577,7 @@ void valid() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "validateActivityArguments")) .add("input", Json.createObjectBuilder() - .add("missionModelId", String.valueOf(modelId)) + .add("missionModelId", modelId) .add("activityTypeName", "BiteBanana") .add("activityArguments", JsonValue.EMPTY_JSON_OBJECT)) .add("request_query", "") @@ -599,7 +599,7 @@ void invalidMissionModelId() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "validateModelArguments")) .add("input", Json.createObjectBuilder() - .add("missionModelId", String.valueOf(-1)) + .add("missionModelId", -1) .add("modelArguments", JsonValue.EMPTY_JSON_OBJECT)) .add("request_query", "") .add("session_variables", admin.getSession()) @@ -616,7 +616,7 @@ void valid() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "validateModelArguments")) .add("input", Json.createObjectBuilder() - .add("missionModelId", String.valueOf(modelId)) + .add("missionModelId", modelId) .add("modelArguments", JsonValue.EMPTY_JSON_OBJECT)) .add("request_query", "") .add("session_variables", admin.getSession()) @@ -671,7 +671,7 @@ void invalidMissionModelId() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "getModelEffectiveArguments")) .add("input", Json.createObjectBuilder() - .add("missionModelId", "-1") + .add("missionModelId", -1) .add("modelArguments", JsonValue.EMPTY_JSON_OBJECT)) .add("request_query", "") .add("session_variables", admin.getSession()) @@ -688,7 +688,7 @@ void valid() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "getModelEffectiveArguments")) .add("input", Json.createObjectBuilder() - .add("missionModelId", String.valueOf(modelId)) + .add("missionModelId", modelId) .add("modelArguments", JsonValue.EMPTY_JSON_OBJECT)) .add("request_query", "") .add("session_variables", admin.getSession()) @@ -723,7 +723,7 @@ void invalidMissionModelId() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "getActivityEffectiveArgumentsBulk")) .add("input", Json.createObjectBuilder() - .add("missionModelId", "-1") + .add("missionModelId", -1) .add("activities", JsonValue.EMPTY_JSON_ARRAY)) .add("request_query", "") .add("session_variables", admin.getSession()) @@ -748,7 +748,7 @@ void valid() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "getActivityEffectiveArgumentsBulk")) .add("input", Json.createObjectBuilder() - .add("missionModelId", String.valueOf(modelId)) + .add("missionModelId", modelId) .add("activities", activitiesBuilder)) .add("request_query", "") .add("session_variables", admin.getSession()) @@ -912,7 +912,7 @@ void invalidMissionModelId() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "constraintsDslTypescript")) .add("input", Json.createObjectBuilder() - .add("missionModelId", "-1") + .add("missionModelId", -1) .add("planId", JsonValue.NULL)) .add("request_query", "") .add("session_variables", admin.getSession()) @@ -942,7 +942,7 @@ void invalidPlanId() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "constraintsDslTypescript")) .add("input", Json.createObjectBuilder() - .add("missionModelId", String.valueOf(modelId)) + .add("missionModelId", modelId) .add("planId", -1)) .add("request_query", "") .add("session_variables", admin.getSession()) @@ -963,7 +963,7 @@ void valid() { final String data = Json.createObjectBuilder() .add("action", Json.createObjectBuilder().add("name", "constraintsDslTypescript")) .add("input", Json.createObjectBuilder() - .add("missionModelId", String.valueOf(modelId)) + .add("missionModelId", modelId) .add("planId", JsonValue.NULL)) .add("request_query", "") .add("session_variables", admin.getSession()) diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ActivityValidation.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ActivityValidation.java index 63fd59f92d..d5e379496b 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ActivityValidation.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ActivityValidation.java @@ -11,7 +11,7 @@ record Success() implements ActivityValidation {} record InstantiationFailure(List extraneousArguments, List missingArguments, List unconstructableArguments) implements ActivityValidation {} record ValidationFailure(List notices) implements ActivityValidation {} record NoSuchActivityTypeFailure(String message, String activityType) implements ActivityValidation {} - record NoSuchMissionModelFailure(String message, String modelId) implements ActivityValidation {} + record NoSuchMissionModelFailure(String message, long modelId) implements ActivityValidation {} record ValidationNotice(List subjects, String message) { } record UnconstructableArgument(String name, String failure) { } @@ -47,7 +47,7 @@ static ActivityValidation fromJSON(JsonObject obj) { case "NO_SUCH_ACTIVITY_TYPE" -> new NoSuchActivityTypeFailure(errors.getJsonObject("noSuchActivityError").getString("message"), errors.getJsonObject("noSuchActivityError").getString("activity_type")); case "NO_SUCH_MISSION_MODEL" -> new NoSuchMissionModelFailure( errors.getJsonObject("noSuchMissionModelError").getString("message"), - errors.getJsonObject("noSuchMissionModelError").getString("mission_model_id") + errors.getJsonObject("noSuchMissionModelError").getJsonNumber("mission_model_id").longValue() ); default -> throw new RuntimeException("Unhandled error type: " + type); }; diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GQL.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GQL.java index 93e4909dfa..0a53c0ef67 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GQL.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GQL.java @@ -217,7 +217,7 @@ query getConstraintRuns($simulationDatasetId: Int!) { } }"""), GET_EFFECTIVE_ACTIVITY_ARGUMENTS_BULK(""" - query GetEffectiveActivityArgumentsBulk($modelId: ID!, $activities: [EffectiveArgumentsInput!]!) { + query GetEffectiveActivityArgumentsBulk($modelId: Int!, $activities: [EffectiveArgumentsInput!]!) { getActivityEffectiveArgumentsBulk( missionModelId: $modelId, activities: $activities @@ -239,7 +239,7 @@ query GetActivityValidations($planId: Int!) { } }"""), GET_EFFECTIVE_MODEL_ARGUMENTS(""" - query GetEffectiveModelArguments($modelId: ID!, $modelArgs: ModelArguments!) { + query GetEffectiveModelArguments($modelId: Int!, $modelArgs: ModelArguments!) { getModelEffectiveArguments(missionModelId: $modelId, modelArguments: $modelArgs) { arguments errors diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/HasuraParsers.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/HasuraParsers.java index cb3aa1bcea..ef0ab785ca 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/HasuraParsers.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/HasuraParsers.java @@ -9,7 +9,6 @@ import static gov.nasa.jpl.aerie.json.BasicParsers.boolP; import static gov.nasa.jpl.aerie.json.BasicParsers.listP; -import static gov.nasa.jpl.aerie.json.BasicParsers.longP; import static gov.nasa.jpl.aerie.json.BasicParsers.mapP; import static gov.nasa.jpl.aerie.json.BasicParsers.nullableP; import static gov.nasa.jpl.aerie.json.BasicParsers.productP; @@ -18,6 +17,7 @@ import static gov.nasa.jpl.aerie.json.Uncurry.untuple; import static gov.nasa.jpl.aerie.merlin.driver.json.SerializedValueJsonParser.serializedValueP; import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.datasetIdP; +import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.missionModelIdP; import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.planIdP; import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.simulationDatasetIdP; import static gov.nasa.jpl.aerie.merlin.server.http.MerlinParsers.timestampP; @@ -47,7 +47,7 @@ private static JsonParser> hasura public static final JsonParser> hasuraMissionModelActionP = hasuraActionF(productP - .field("missionModelId", stringP) + .field("missionModelId", missionModelIdP) .map(HasuraAction.MissionModelInput::new, HasuraAction.MissionModelInput::missionModelId)); public static final JsonParser> hasuraPlanActionP @@ -82,7 +82,7 @@ private static JsonParser> hasura public static final JsonParser> hasuraConstraintsCodeAction = hasuraActionF( productP - .field("missionModelId", stringP) + .field("missionModelId", missionModelIdP) .optionalField("planId", nullableP(planIdP)) .map( untuple((modelId, planId) -> new HasuraAction.ConstraintsInput(modelId, planId.flatMap($ -> $))), @@ -95,18 +95,18 @@ private static JsonParser> hasura .field("event", productP .field("data", productP .field("new", productP - .field("id", longP) + .field("id", missionModelIdP) .rest()) .rest()) .rest()) .rest() .map( - untuple(missionModelId -> new HasuraMissionModelEvent(String.valueOf(missionModelId))), - $ -> tuple(Long.parseLong($.missionModelId()))); + untuple(HasuraMissionModelEvent::new), + $ -> tuple($.missionModelId())); private static final JsonParser hasuraMissionModelArgumentsInputP = productP - .field("missionModelId", stringP) + .field("missionModelId", missionModelIdP) .field("modelArguments", mapP(serializedValueP)) .map( untuple(HasuraAction.MissionModelArgumentsInput::new), @@ -117,7 +117,7 @@ private static JsonParser> hasura private static final JsonParser hasuraActivityInputP = productP - .field("missionModelId", stringP) + .field("missionModelId", missionModelIdP) .field("activityTypeName", stringP) .field("activityArguments", mapP(serializedValueP)) .map( @@ -135,7 +135,7 @@ private static JsonParser> hasura public static final JsonParser> hasuraActivityBulkActionP = hasuraActionF( productP - .field("missionModelId", stringP) + .field("missionModelId", missionModelIdP) .field("activities", listP(hasuraActivityBulkItemP)) .map( untuple(HasuraAction.ActivityBulkInput::new), diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinParsers.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinParsers.java index f419bf0585..3b0e903e3b 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinParsers.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinParsers.java @@ -1,6 +1,5 @@ package gov.nasa.jpl.aerie.merlin.server.http; -import gov.nasa.jpl.aerie.constraints.model.Violation; import gov.nasa.jpl.aerie.json.JsonParseResult; import gov.nasa.jpl.aerie.json.JsonParser; import gov.nasa.jpl.aerie.json.SchemaCache; @@ -8,6 +7,7 @@ import gov.nasa.jpl.aerie.merlin.driver.SimulationFailure; import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; import gov.nasa.jpl.aerie.merlin.server.models.DatasetId; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.PlanId; import gov.nasa.jpl.aerie.merlin.server.models.SimulationDatasetId; import gov.nasa.jpl.aerie.merlin.server.models.Timestamp; @@ -69,6 +69,12 @@ public JsonValue unparse(final Timestamp value) { ActivityDirectiveId::new, ActivityDirectiveId::id); + public static final JsonParser missionModelIdP + = longP + . map( + MissionModelId::new, + MissionModelId::id); + public static final JsonParser planIdP = longP . map( diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/ResponseSerializers.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/ResponseSerializers.java index 42148295cd..8e16964305 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/ResponseSerializers.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/http/ResponseSerializers.java @@ -587,7 +587,7 @@ public static JsonValue serializeNoSuchPlanDatasetException(final NoSuchPlanData public static JsonValue serializeNoSuchMissionModelException(final MissionModelService.NoSuchMissionModelException ex) { return Json.createObjectBuilder() .add("message", "no such mission model") - .add("mission_model_id", ex.missionModelId) + .add("mission_model_id", ex.missionModelId.id()) .build(); } diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/HasuraAction.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/HasuraAction.java index a35d29d106..26a1f4fd17 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/HasuraAction.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/HasuraAction.java @@ -13,15 +13,15 @@ public record Session(String hasuraRole, String hasuraUserId) { } public sealed interface Input { } - public record MissionModelInput(String missionModelId) implements Input { } + public record MissionModelInput(MissionModelId missionModelId) implements Input { } public record PlanInput(PlanId planId) implements Input { } public record SimulateInput(PlanId planId, Optional force) implements Input {} public record ConstraintViolationsInput(PlanId planId, Optional simulationDatasetId) implements Input { } - public record ActivityInput(String missionModelId, + public record ActivityInput(MissionModelId missionModelId, String activityTypeName, Map arguments) implements Input {} - public record ActivityBulkInput(String missionModelId, List activities) implements Input {} - public record MissionModelArgumentsInput(String missionModelId, + public record ActivityBulkInput(MissionModelId missionModelId, List activities) implements Input {} + public record MissionModelArgumentsInput(MissionModelId missionModelId, Map arguments) implements Input {} public record UploadExternalDatasetInput(PlanId planId, Optional simulationDatasetId, @@ -30,5 +30,5 @@ public record UploadExternalDatasetInput(PlanId planId, public record ExtendExternalDatasetInput(DatasetId datasetId, ProfileSet profileSet) implements Input {} - public record ConstraintsInput(String missionModelId, Optional planId) implements Input {} + public record ConstraintsInput(MissionModelId missionModelId, Optional planId) implements Input {} } diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/HasuraMissionModelEvent.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/HasuraMissionModelEvent.java index e6297a2cdc..9ba33e4c5e 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/HasuraMissionModelEvent.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/HasuraMissionModelEvent.java @@ -1,3 +1,3 @@ package gov.nasa.jpl.aerie.merlin.server.models; -public record HasuraMissionModelEvent(String missionModelId) { } +public record HasuraMissionModelEvent(MissionModelId missionModelId) { } diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/Plan.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/Plan.java index 2f40220fef..2406dd8b69 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/Plan.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/models/Plan.java @@ -10,7 +10,7 @@ public final class Plan { public String name; - public String missionModelId; + public MissionModelId missionModelId; public Timestamp startTimestamp; public Timestamp endTimestamp; public Map activityDirectives; @@ -38,12 +38,11 @@ public Plan(final Plan other) { public Plan( final String name, - final String missionModelId, + final MissionModelId missionModelId, final Timestamp startTimestamp, final Timestamp endTimestamp, final Map activityDirectives - ) - { + ) { this.name = name; this.missionModelId = missionModelId; this.startTimestamp = startTimestamp; @@ -56,7 +55,7 @@ public Plan( public Plan( final String name, - final String missionModelId, + final MissionModelId missionModelId, final Timestamp startTimestamp, final Timestamp endTimestamp, final Map activityDirectives, diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/MissionModelRepository.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/MissionModelRepository.java index 506f6739f7..9be6348e9e 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/MissionModelRepository.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/MissionModelRepository.java @@ -4,7 +4,6 @@ import gov.nasa.jpl.aerie.merlin.protocol.model.Resource; import gov.nasa.jpl.aerie.merlin.server.models.ActivityDirectiveForValidation; import gov.nasa.jpl.aerie.merlin.server.models.ActivityType; -import gov.nasa.jpl.aerie.merlin.server.models.Constraint; import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.MissionModelJar; import gov.nasa.jpl.aerie.merlin.server.services.MissionModelService.BulkArgumentValidationResponse; @@ -15,14 +14,14 @@ public interface MissionModelRepository { // Queries - Map getAllMissionModels(); - MissionModelJar getMissionModel(String id) throws NoSuchMissionModelException; - Map getActivityTypes(String missionModelId) throws NoSuchMissionModelException; + Map getAllMissionModels(); + MissionModelJar getMissionModel(MissionModelId id) throws NoSuchMissionModelException; + Map getActivityTypes(MissionModelId missionModelId) throws NoSuchMissionModelException; // Mutations - void updateModelParameters(String missionModelId, final List modelParameters) throws NoSuchMissionModelException; - void updateActivityTypes(String missionModelId, final Map activityTypes) throws NoSuchMissionModelException; - void updateResourceTypes(String missionModelId, final Map> resourceTypes) throws NoSuchMissionModelException; + void updateModelParameters(MissionModelId missionModelId, final List modelParameters) throws NoSuchMissionModelException; + void updateActivityTypes(MissionModelId missionModelId, final Map activityTypes) throws NoSuchMissionModelException; + void updateResourceTypes(MissionModelId missionModelId, final Map> resourceTypes) throws NoSuchMissionModelException; Map> getUnvalidatedDirectives(); void updateDirectiveValidations(List> updates); diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/postgres/PostgresMissionModelRepository.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/postgres/PostgresMissionModelRepository.java index 530c9fed15..f2e9d9ffda 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/postgres/PostgresMissionModelRepository.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/remotes/postgres/PostgresMissionModelRepository.java @@ -25,7 +25,7 @@ public PostgresMissionModelRepository(final DataSource dataSource) { } @Override - public Map getAllMissionModels() { + public Map getAllMissionModels() { try (final var connection = this.dataSource.getConnection()) { try (final var getAllMissionModelsAction = new GetAllModelsAction(connection)) { return getAllMissionModelsAction @@ -33,7 +33,7 @@ public Map getAllMissionModels() { .entrySet() .stream() .collect(Collectors.toMap( - e -> Long.toString(e.getKey()), + e -> new MissionModelId(e.getKey()), e -> missionModelRecordToMissionModelJar(e.getValue()))); } } catch (final SQLException ex) { @@ -42,11 +42,11 @@ public Map getAllMissionModels() { } @Override - public MissionModelJar getMissionModel(final String missionModelId) throws NoSuchMissionModelException { + public MissionModelJar getMissionModel(final MissionModelId missionModelId) throws NoSuchMissionModelException { try (final var connection = this.dataSource.getConnection()) { try (final var getMissionModelAction = new GetModelAction(connection)) { return getMissionModelAction - .get(toMissionModelId(missionModelId)) + .get(missionModelId.id()) .map(PostgresMissionModelRepository::missionModelRecordToMissionModelJar) .orElseThrow(NoSuchMissionModelException::new); } @@ -56,10 +56,10 @@ public MissionModelJar getMissionModel(final String missionModelId) throws NoSuc } @Override - public Map getActivityTypes(final String missionModelId) throws NoSuchMissionModelException { + public Map getActivityTypes(final MissionModelId missionModelId) throws NoSuchMissionModelException { try (final var connection = this.dataSource.getConnection()) { try (final var getActivityTypesAction = new GetActivityTypesAction(connection)) { - final var id = toMissionModelId(missionModelId); + final var id = missionModelId.id(); final var result = new HashMap(); for (final var activityType: getActivityTypesAction.get(id)) { result.put(activityType.name(), activityType); @@ -73,11 +73,11 @@ public Map getActivityTypes(final String missionModelId) t } @Override - public void updateModelParameters(final String missionModelId, final List modelParameters) + public void updateModelParameters(final MissionModelId missionModelId, final List modelParameters) throws NoSuchMissionModelException { try (final var connection = this.dataSource.getConnection()) { try (final var createModelParametersAction = new CreateModelParametersAction(connection)) { - final var id = toMissionModelId(missionModelId); + final var id = missionModelId.id(); createModelParametersAction.apply(id, modelParameters); } } catch (final SQLException ex) { @@ -87,11 +87,11 @@ public void updateModelParameters(final String missionModelId, final List activityTypes) + public void updateActivityTypes(final MissionModelId missionModelId, final Map activityTypes) throws NoSuchMissionModelException { try (final var connection = this.dataSource.getConnection()) { try (final var insertActivityTypesAction = new InsertActivityTypesAction(connection)) { - final var id = toMissionModelId(missionModelId); + final var id = missionModelId.id(); insertActivityTypesAction.apply((int) id, activityTypes.values()); } } catch (final SQLException ex) { @@ -101,7 +101,7 @@ public void updateActivityTypes(final String missionModelId, final Map> resources) + public void updateResourceTypes(final MissionModelId missionModelId, final Map> resources) throws NoSuchMissionModelException { final var resourceTypes = resources.entrySet() .stream() @@ -111,7 +111,7 @@ public void updateResourceTypes(final String missionModelId, final Map getAllPlans() { plans.put(planId, new Plan( record.name(), - Long.toString(record.missionModelId()), + new MissionModelId(record.missionModelId()), record.startTime(), record.endTime(), activities @@ -88,7 +89,7 @@ public Plan getPlanForSimulation(final PlanId planId) throws NoSuchPlanException return new Plan( planRecord.name(), - Long.toString(planRecord.missionModelId()), + new MissionModelId(planRecord.missionModelId()), planRecord.startTime(), planRecord.endTime(), activities, @@ -109,7 +110,7 @@ public Plan getPlanForValidation(final PlanId planId) throws NoSuchPlanException return new Plan( planRecord.name(), - Long.toString(planRecord.missionModelId()), + new MissionModelId(planRecord.missionModelId()), planRecord.startTime(), planRecord.endTime(), activities diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintsDSLCompilationService.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintsDSLCompilationService.java index 31510ca1b4..f99a0f440c 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintsDSLCompilationService.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintsDSLCompilationService.java @@ -8,6 +8,7 @@ import gov.nasa.jpl.aerie.merlin.server.http.InvalidJsonException; import gov.nasa.jpl.aerie.merlin.server.models.ConstraintsCompilationError; import gov.nasa.jpl.aerie.constraints.json.ConstraintParsers; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.PlanId; import gov.nasa.jpl.aerie.merlin.server.models.SimulationDatasetId; @@ -55,7 +56,7 @@ public void close() { * NOTE: This method is not re-entrant (assumes only one call to this method is running at any given time) */ synchronized public ConstraintsDSLCompilationResult compileConstraintsDSL( - final String missionModelId, + final MissionModelId missionModelId, final Optional planId, final Optional simulationDatasetId, final String constraintTypescript diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/CreateSimulationMessage.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/CreateSimulationMessage.java index 07f444b759..ac6697fe58 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/CreateSimulationMessage.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/CreateSimulationMessage.java @@ -1,6 +1,7 @@ package gov.nasa.jpl.aerie.merlin.server.services; import gov.nasa.jpl.aerie.merlin.driver.ActivityDirectiveId; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; import gov.nasa.jpl.aerie.merlin.driver.ActivityDirective; @@ -10,7 +11,7 @@ import java.util.Objects; public record CreateSimulationMessage( - String missionModelId, + MissionModelId missionModelId, Instant simulationStartTime, Duration simulationDuration, Instant planStartTime, diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/GenerateConstraintsLibAction.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/GenerateConstraintsLibAction.java index 441dc940c9..7210b5f1c6 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/GenerateConstraintsLibAction.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/GenerateConstraintsLibAction.java @@ -1,6 +1,7 @@ package gov.nasa.jpl.aerie.merlin.server.services; import gov.nasa.jpl.aerie.merlin.server.exceptions.NoSuchPlanException; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.PlanId; import java.io.IOException; @@ -28,7 +29,7 @@ record Success(Map files) implements Response {} * * @return a response object wrapping the results of generating the code (either successful or not) */ - public Response run(final String missionModelId, final Optional planId) { + public Response run(final MissionModelId missionModelId, final Optional planId) { try { final var constraintsDslCompilerRoot = System.getenv("CONSTRAINTS_DSL_COMPILER_ROOT"); diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/LocalMissionModelService.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/LocalMissionModelService.java index 36ad50e637..538fe398de 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/LocalMissionModelService.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/LocalMissionModelService.java @@ -61,21 +61,21 @@ public LocalMissionModelService( } @Override - public Map getMissionModels() { + public Map getMissionModels() { return this.missionModelRepository.getAllMissionModels(); } @Override - public MissionModelJar getMissionModelById(final String id) throws NoSuchMissionModelException { + public MissionModelJar getMissionModelById(final MissionModelId missionModelId) throws NoSuchMissionModelException { try { - return this.missionModelRepository.getMissionModel(id); + return this.missionModelRepository.getMissionModel(missionModelId); } catch (MissionModelRepository.NoSuchMissionModelException ex) { - throw new NoSuchMissionModelException(id, ex); + throw new NoSuchMissionModelException(missionModelId, ex); } } @Override - public Map getResourceSchemas(final String missionModelId) + public Map getResourceSchemas(final MissionModelId missionModelId) throws NoSuchMissionModelException, MissionModelLoadException { // TODO: [AERIE-1516] Teardown the missionModel after use to release any system resources (e.g. threads). @@ -98,7 +98,7 @@ public Map getResourceSchemas(final String missionModelId) * @throws NoSuchMissionModelException If no mission model is known by the given ID. */ @Override - public Map getActivityTypes(final String missionModelId) + public Map getActivityTypes(final MissionModelId missionModelId) throws NoSuchMissionModelException { try { @@ -119,7 +119,7 @@ public Map getActivityTypes(final String missionModelId) * it contains may not abide by the expected contract at load time. */ @Override - public List validateActivityArguments(final String missionModelId, final SerializedActivity activity) + public List validateActivityArguments(final MissionModelId missionModelId, final SerializedActivity activity) throws NoSuchMissionModelException, MissionModelLoadException, InstantiationException { // TODO: [AERIE-1516] Teardown the missionModel after use to release any system resources (e.g. threads). @@ -131,12 +131,12 @@ public List validateActivityArguments(final String missionMode } public List validateActivityArgumentsBulk( - final MissionModelId modelId, + final MissionModelId missionModelId, final List activities) { // load mission model once for all activities ModelType modelType; try { - modelType = this.loadMissionModelType(modelId.toString()); + modelType = this.loadMissionModelType(missionModelId); // try and catch NoSuchMissionModel here, so we can serialize it out to each activity validation // rather than catching it at a higher level in the workerLoop itself } catch (NoSuchMissionModelException e) { @@ -188,7 +188,7 @@ public void updateDirectiveValidations(List - validateActivityInstantiations(final String missionModelId, + validateActivityInstantiations(final MissionModelId missionModelId, final Map activities) throws NoSuchMissionModelException, MissionModelLoadException { @@ -218,7 +218,7 @@ public void updateDirectiveValidations(List getActivityEffectiveArgumentsBulk( - final String missionModelId, + final MissionModelId missionModelId, final List serializedActivities) throws NoSuchMissionModelException, MissionModelLoadException { final var modelType = this.loadMissionModelType(missionModelId); @@ -249,7 +249,7 @@ public List getActivityEffectiveArgumentsBulk( } @Override - public List validateModelArguments(final String missionModelId, final Map arguments) + public List validateModelArguments(final MissionModelId missionModelId, final Map arguments) throws NoSuchMissionModelException, MissionModelLoadException, InstantiationException @@ -260,14 +260,14 @@ public List validateModelArguments(final String missionModelId } @Override - public List getModelParameters(final String missionModelId) + public List getModelParameters(final MissionModelId missionModelId) throws NoSuchMissionModelException, MissionModelLoadException { return this.loadMissionModelType(missionModelId).getConfigurationType().getParameters(); } @Override - public Map getModelEffectiveArguments(final String missionModelId, final Map arguments) + public Map getModelEffectiveArguments(final MissionModelId missionModelId, final Map arguments) throws NoSuchMissionModelException, MissionModelLoadException, InstantiationException @@ -315,7 +315,7 @@ public SimulationResults runSimulation( } @Override - public void refreshModelParameters(final String missionModelId) + public void refreshModelParameters(final MissionModelId missionModelId) throws NoSuchMissionModelException { try { @@ -326,7 +326,7 @@ public void refreshModelParameters(final String missionModelId) } @Override - public void refreshActivityTypes(final String missionModelId) + public void refreshActivityTypes(final MissionModelId missionModelId) throws NoSuchMissionModelException { try { @@ -349,7 +349,7 @@ public void refreshActivityTypes(final String missionModelId) } @Override - public void refreshResourceTypes(final String missionModelId) + public void refreshResourceTypes(final MissionModelId missionModelId) throws NoSuchMissionModelException, MissionModelLoadException { try { final var model = this.loadAndInstantiateMissionModel(missionModelId); @@ -359,7 +359,7 @@ public void refreshResourceTypes(final String missionModelId) } } - private ModelType loadMissionModelType(final String missionModelId) + private ModelType loadMissionModelType(final MissionModelId missionModelId) throws NoSuchMissionModelException, MissionModelLoadException { try { @@ -381,7 +381,7 @@ public void refreshResourceTypes(final String missionModelId) * it contains may not abide by the expected contract at load time. * @throws NoSuchMissionModelException If no mission model is known by the given ID. */ - private MissionModel loadAndInstantiateMissionModel(final String missionModelId) + private MissionModel loadAndInstantiateMissionModel(final MissionModelId missionModelId) throws NoSuchMissionModelException, MissionModelLoadException { return loadAndInstantiateMissionModel(missionModelId, untruePlanStart, SerializedValue.of(Map.of())); @@ -398,7 +398,7 @@ private MissionModel loadAndInstantiateMissionModel(final String missionModel * @throws NoSuchMissionModelException If no mission model is known by the given ID. */ private MissionModel loadAndInstantiateMissionModel( - final String missionModelId, + final MissionModelId missionModelId, final Instant planStart, final SerializedValue configuration) throws NoSuchMissionModelException, MissionModelLoadException diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/MissionModelService.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/MissionModelService.java index 8cf8535409..673c053b75 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/MissionModelService.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/MissionModelService.java @@ -13,7 +13,7 @@ import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; import gov.nasa.jpl.aerie.merlin.protocol.types.ValueSchema; import gov.nasa.jpl.aerie.merlin.server.models.ActivityType; -import gov.nasa.jpl.aerie.merlin.server.models.Constraint; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.MissionModelJar; import java.util.HashMap; @@ -23,44 +23,44 @@ import java.util.function.Supplier; public interface MissionModelService { - Map getMissionModels(); + Map getMissionModels(); - MissionModelJar getMissionModelById(String missionModelId) + MissionModelJar getMissionModelById(MissionModelId missionModelId) throws NoSuchMissionModelException; - Map getResourceSchemas(String missionModelId) + Map getResourceSchemas(MissionModelId missionModelId) throws NoSuchMissionModelException; /** * getActivityTypes uses the cached result of refreshActivityTypes. For this reason, refreshActivityTypes * should be called first. */ - Map getActivityTypes(String missionModelId) + Map getActivityTypes(MissionModelId missionModelId) throws NoSuchMissionModelException; // TODO: Provide a finer-scoped validation return type. Mere strings make all validations equally severe. - List validateActivityArguments(String missionModelId, SerializedActivity activity) + List validateActivityArguments(MissionModelId missionModelId, SerializedActivity activity) throws NoSuchMissionModelException, InstantiationException; Map validateActivityInstantiations( - String missionModelId, + MissionModelId missionModelId, Map activities ) throws NoSuchMissionModelException, LocalMissionModelService.MissionModelLoadException; List getActivityEffectiveArgumentsBulk( - String missionModelId, + MissionModelId missionModelId, List serializedActivities) throws NoSuchMissionModelException; - List validateModelArguments(String missionModelId, Map arguments) + List validateModelArguments(MissionModelId missionModelId, Map arguments) throws NoSuchMissionModelException, LocalMissionModelService.MissionModelLoadException, InstantiationException; - List getModelParameters(String missionModelId) + List getModelParameters(MissionModelId missionModelId) throws NoSuchMissionModelException, MissionModelLoader.MissionModelLoadException; - Map getModelEffectiveArguments(String missionModelId, Map arguments) + Map getModelEffectiveArguments(MissionModelId missionModelId, Map arguments) throws NoSuchMissionModelException, LocalMissionModelService.MissionModelLoadException, InstantiationException; @@ -72,9 +72,9 @@ SimulationResults runSimulation( final SimulationResourceManager resourceManager ) throws NoSuchMissionModelException, MissionModelService.NoSuchActivityTypeException; - void refreshModelParameters(String missionModelId) throws NoSuchMissionModelException; - void refreshActivityTypes(String missionModelId) throws NoSuchMissionModelException; - void refreshResourceTypes(String missionModelId) throws NoSuchMissionModelException; + void refreshModelParameters(MissionModelId missionModelId) throws NoSuchMissionModelException; + void refreshActivityTypes(MissionModelId missionModelId) throws NoSuchMissionModelException; + void refreshResourceTypes(MissionModelId missionModelId) throws NoSuchMissionModelException; sealed interface ActivityInstantiationFailure { record NoSuchActivityType(NoSuchActivityTypeException ex) implements ActivityInstantiationFailure { } @@ -82,14 +82,14 @@ record InstantiationFailure(InstantiationException ex) implements ActivityInstan } final class NoSuchMissionModelException extends Exception { - public final String missionModelId; + public final MissionModelId missionModelId; - public NoSuchMissionModelException(final String missionModelId, final Throwable cause) { + public NoSuchMissionModelException(final MissionModelId missionModelId, final Throwable cause) { super("No mission model exists with id `" + missionModelId + "`", cause); this.missionModelId = missionModelId; } - public NoSuchMissionModelException(final String missionModelId) { this(missionModelId, null); } + public NoSuchMissionModelException(final MissionModelId missionModelId) { this(missionModelId, null); } } final class NoSuchActivityTypeException extends Exception { diff --git a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/TypescriptCodeGenerationServiceAdapter.java b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/TypescriptCodeGenerationServiceAdapter.java index d3dabb8214..18bc66d273 100644 --- a/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/TypescriptCodeGenerationServiceAdapter.java +++ b/merlin-server/src/main/java/gov/nasa/jpl/aerie/merlin/server/services/TypescriptCodeGenerationServiceAdapter.java @@ -4,6 +4,7 @@ import gov.nasa.jpl.aerie.constraints.TypescriptCodeGenerationService; import gov.nasa.jpl.aerie.merlin.protocol.types.ValueSchema; import gov.nasa.jpl.aerie.merlin.server.exceptions.NoSuchPlanException; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.PlanId; import gov.nasa.jpl.aerie.merlin.server.models.SimulationDatasetId; @@ -21,7 +22,7 @@ public TypescriptCodeGenerationServiceAdapter(final MissionModelService missionM this.planService = planService; } - public String generateTypescriptTypes(final String missionModelId, final Optional planId, final Optional simulationDatasetId) + public String generateTypescriptTypes(final MissionModelId missionModelId, final Optional planId, final Optional simulationDatasetId) throws MissionModelService.NoSuchMissionModelException, NoSuchPlanException { return TypescriptCodeGenerationService @@ -30,7 +31,7 @@ public String generateTypescriptTypes(final String missionModelId, final Optiona resourceSchemas(missionModelService, missionModelId, planService, planId, simulationDatasetId)); } - static Map activityTypes(final MissionModelService missionModelService, final String missionModelId) + static Map activityTypes(final MissionModelService missionModelService, final MissionModelId missionModelId) throws MissionModelService.NoSuchMissionModelException { return missionModelService @@ -50,7 +51,7 @@ static Map activityTypes(f } static Map resourceSchemas( final MissionModelService missionModelService, - final String modelId, + final MissionModelId modelId, final PlanService planService, final Optional planId, final Optional simulationDatasetId diff --git a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinParsersTest.java b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinParsersTest.java index aefa2be6ec..3c09fdb901 100644 --- a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinParsersTest.java +++ b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/http/MerlinParsersTest.java @@ -4,6 +4,7 @@ import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; import gov.nasa.jpl.aerie.merlin.server.models.HasuraAction; import gov.nasa.jpl.aerie.merlin.server.models.HasuraMissionModelEvent; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import org.junit.jupiter.api.Test; import javax.json.Json; @@ -83,7 +84,7 @@ public void testHasuraActionParsers() { .build()) .add("input", Json .createObjectBuilder() - .add("missionModelId", "1") + .add("missionModelId", 1) .build()) .add("session_variables", Json .createObjectBuilder() @@ -94,7 +95,7 @@ public void testHasuraActionParsers() { final var expected = new HasuraAction<>( "testAction", - new HasuraAction.MissionModelInput("1"), + new HasuraAction.MissionModelInput(new MissionModelId(1L)), new HasuraAction.Session("aerie_admin", null)); assertEquals(expected, hasuraMissionModelActionP.parse(json).getSuccessOrThrow()); @@ -109,7 +110,7 @@ public void testHasuraActionParsers() { .build()) .add("input", Json .createObjectBuilder() - .add("missionModelId", "1") + .add("missionModelId", 1) .build()) .add("session_variables", Json .createObjectBuilder() @@ -121,7 +122,7 @@ public void testHasuraActionParsers() { final var expected = new HasuraAction<>( "testAction", - new HasuraAction.MissionModelInput("1"), + new HasuraAction.MissionModelInput(new MissionModelId(1L)), new HasuraAction.Session("aerie_admin", "userId")); assertEquals(expected, hasuraMissionModelActionP.parse(json).getSuccessOrThrow()); @@ -147,7 +148,7 @@ public void testHasuraMissionModelEventParser() { .add("id", "8907a407-28a5-440a-8de6-240b80c58a8b") .build(); - final var expected = new HasuraMissionModelEvent("1"); + final var expected = new HasuraMissionModelEvent(new MissionModelId(1L)); assertEquals(expected, hasuraMissionModelEventTriggerP.parse(json).getSuccessOrThrow()); } diff --git a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/mocks/StubMissionModelService.java b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/mocks/StubMissionModelService.java index 058435f323..93f28b5a9e 100644 --- a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/mocks/StubMissionModelService.java +++ b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/mocks/StubMissionModelService.java @@ -10,6 +10,7 @@ import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; import gov.nasa.jpl.aerie.merlin.protocol.types.ValueSchema; import gov.nasa.jpl.aerie.merlin.server.models.ActivityType; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.MissionModelJar; import gov.nasa.jpl.aerie.merlin.server.services.CreateSimulationMessage; import gov.nasa.jpl.aerie.merlin.server.services.LocalMissionModelService; @@ -26,8 +27,8 @@ import java.util.function.Supplier; public final class StubMissionModelService implements MissionModelService { - public static final String EXISTENT_MISSION_MODEL_ID = "abc"; - public static final String NONEXISTENT_MISSION_MODEL_ID = "def"; + public static final MissionModelId EXISTENT_MISSION_MODEL_ID = new MissionModelId(1L); + public static final MissionModelId NONEXISTENT_MISSION_MODEL_ID = new MissionModelId(-1L); public static final MissionModelJar EXISTENT_MISSION_MODEL; public static final String EXISTENT_ACTIVITY_TYPE = "activity"; @@ -102,12 +103,12 @@ public final class StubMissionModelService implements MissionModelService { } @Override - public Map getMissionModels() { + public Map getMissionModels() { return Map.of(EXISTENT_MISSION_MODEL_ID, EXISTENT_MISSION_MODEL); } @Override - public MissionModelJar getMissionModelById(final String missionModelId) throws NoSuchMissionModelException { + public MissionModelJar getMissionModelById(final MissionModelId missionModelId) throws NoSuchMissionModelException { if (!Objects.equals(missionModelId, EXISTENT_MISSION_MODEL_ID)) { throw new NoSuchMissionModelException(missionModelId); } @@ -116,7 +117,7 @@ public MissionModelJar getMissionModelById(final String missionModelId) throws N } @Override - public Map getResourceSchemas(final String missionModelId) throws NoSuchMissionModelException { + public Map getResourceSchemas(final MissionModelId missionModelId) throws NoSuchMissionModelException { if (!Objects.equals(missionModelId, EXISTENT_MISSION_MODEL_ID)) { throw new NoSuchMissionModelException(missionModelId); } @@ -125,7 +126,7 @@ public Map getResourceSchemas(final String missionModelId) } @Override - public Map getActivityTypes(final String missionModelId) throws NoSuchMissionModelException { + public Map getActivityTypes(final MissionModelId missionModelId) throws NoSuchMissionModelException { if (!Objects.equals(missionModelId, EXISTENT_MISSION_MODEL_ID)) { throw new NoSuchMissionModelException(missionModelId); } @@ -137,7 +138,7 @@ public Map getActivityTypes(final String missionModelId) t } @Override - public List validateActivityArguments(final String missionModelId, final SerializedActivity activity) + public List validateActivityArguments(final MissionModelId missionModelId, final SerializedActivity activity) throws NoSuchMissionModelException { if (!Objects.equals(missionModelId, EXISTENT_MISSION_MODEL_ID)) { @@ -157,7 +158,7 @@ public List validateActivityArguments(final String missionMode @Override public Map validateActivityInstantiations( - final String missionModelId, + final MissionModelId missionModelId, final Map activities) throws LocalMissionModelService.MissionModelLoadException { @@ -166,26 +167,26 @@ public Map validateActivityIn @Override public List getActivityEffectiveArgumentsBulk( - String missionModelId, + MissionModelId missionModelId, List serializedActivities) { return List.of(); } @Override - public List validateModelArguments(final String missionModelId, final Map arguments) + public List validateModelArguments(final MissionModelId missionModelId, final Map arguments) throws LocalMissionModelService.MissionModelLoadException { return List.of(); } @Override - public List getModelParameters(final String missionModelId) { + public List getModelParameters(final MissionModelId missionModelId) { return List.of(); } @Override public Map getModelEffectiveArguments( - final String missionModelId, + final MissionModelId missionModelId, final Map arguments) throws LocalMissionModelService.MissionModelLoadException { @@ -207,11 +208,11 @@ public SimulationResults runSimulation( } @Override - public void refreshModelParameters(final String missionModelId) throws NoSuchMissionModelException {} + public void refreshModelParameters(final MissionModelId missionModelId) throws NoSuchMissionModelException {} @Override - public void refreshActivityTypes(final String missionModelId) throws NoSuchMissionModelException {} + public void refreshActivityTypes(final MissionModelId missionModelId) throws NoSuchMissionModelException {} @Override - public void refreshResourceTypes(final String missionModelId) throws NoSuchMissionModelException {} + public void refreshResourceTypes(final MissionModelId missionModelId) throws NoSuchMissionModelException {} } diff --git a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/mocks/StubPlanService.java b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/mocks/StubPlanService.java index 94a66b0d08..8026660c38 100644 --- a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/mocks/StubPlanService.java +++ b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/mocks/StubPlanService.java @@ -8,6 +8,7 @@ import gov.nasa.jpl.aerie.merlin.server.exceptions.NoSuchPlanException; import gov.nasa.jpl.aerie.merlin.server.models.Constraint; import gov.nasa.jpl.aerie.merlin.server.models.DatasetId; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.Plan; import gov.nasa.jpl.aerie.merlin.server.models.PlanId; import gov.nasa.jpl.aerie.merlin.server.models.ProfileSet; @@ -48,7 +49,7 @@ public MatchResult matches(final RevisionData other) { EXISTENT_PLAN = new Plan(); EXISTENT_PLAN.name = "existent"; - EXISTENT_PLAN.missionModelId = "abc"; + EXISTENT_PLAN.missionModelId = new MissionModelId(1); EXISTENT_PLAN.activityDirectives = Map.of(EXISTENT_ACTIVITY_ID, EXISTENT_ACTIVITY); } @@ -80,7 +81,7 @@ public RevisionData getPlanRevisionData(final PlanId planId) throws NoSuchPlanEx @Override public Map getConstraintsForPlan(final PlanId planId) - throws NoSuchPlanException { + { return Map.of(); } @@ -90,7 +91,6 @@ public long addExternalDataset( final Optional simulationDatasetId, final Timestamp datasetStart, final ProfileSet profileSet) - throws NoSuchPlanException { return 0; } @@ -104,13 +104,13 @@ public void extendExternalDataset(final DatasetId datasetId, final ProfileSet pr public List> getExternalDatasets( final PlanId planId, final SimulationDatasetId simulationDatasetId - ) throws NoSuchPlanException + ) { return List.of(); } @Override - public Map getExternalResourceSchemas(final PlanId planId, final Optional simulationDatasetId) throws NoSuchPlanException { + public Map getExternalResourceSchemas(final PlanId planId, final Optional simulationDatasetId) { return Map.of("external resource", ValueSchema.BOOLEAN); } diff --git a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintsDSLCompilationServiceTests.java b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintsDSLCompilationServiceTests.java index b628ee153b..8b0276f15c 100644 --- a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintsDSLCompilationServiceTests.java +++ b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/services/ConstraintsDSLCompilationServiceTests.java @@ -52,6 +52,7 @@ import gov.nasa.jpl.aerie.merlin.protocol.types.SerializedValue; import gov.nasa.jpl.aerie.merlin.server.mocks.StubMissionModelService; import gov.nasa.jpl.aerie.merlin.server.mocks.StubPlanService; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.PlanId; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -73,7 +74,7 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) class ConstraintsDSLCompilationServiceTests { - private static final String MISSION_MODEL_ID = "abc"; + private static final MissionModelId MISSION_MODEL_ID = new MissionModelId(1L); private static final PlanId PLAN_ID = new PlanId(1L); ConstraintsDSLCompilationService constraintsDSLCompilationService; diff --git a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/services/TypescriptCodeGenerationServiceTest.java b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/services/TypescriptCodeGenerationServiceTest.java index 1418f8f7e4..33cfdaae2f 100644 --- a/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/services/TypescriptCodeGenerationServiceTest.java +++ b/merlin-server/src/test/java/gov/nasa/jpl/aerie/merlin/server/services/TypescriptCodeGenerationServiceTest.java @@ -3,6 +3,7 @@ import gov.nasa.jpl.aerie.merlin.server.exceptions.NoSuchPlanException; import gov.nasa.jpl.aerie.merlin.server.mocks.StubMissionModelService; import gov.nasa.jpl.aerie.merlin.server.mocks.StubPlanService; +import gov.nasa.jpl.aerie.merlin.server.models.MissionModelId; import gov.nasa.jpl.aerie.merlin.server.models.PlanId; import org.junit.jupiter.api.Test; @@ -15,7 +16,8 @@ class TypescriptCodeGenerationServiceTest { @Test void testCodeGen() throws MissionModelService.NoSuchMissionModelException, NoSuchPlanException { final var codeGenService = new TypescriptCodeGenerationServiceAdapter(new StubMissionModelService(), new StubPlanService()); - final var expected = codeGenService.generateTypescriptTypes("abc", Optional.of(new PlanId(1L)), Optional.empty()); + final var expected = codeGenService.generateTypescriptTypes(new MissionModelId(1L), + Optional.of(new PlanId(1L)), Optional.empty()); assertEquals(expected, """ /** Start Codegen */