From 7ed4c6b32e7d55de4a0e8bca44ec7e3cf3f501b4 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Tue, 22 Oct 2024 15:22:52 -0400 Subject: [PATCH] server: Use ITmfConfiguration in create interface for configurations Update ConfigurationManagerService and corresponding tests for that. Signed-off-by: Bernd Hufmann --- .../ConfigurationManagerServiceTest.java | 6 +-- .../views/ConfigurationQueryParameters.java | 51 ++++++++++++++++--- .../services/ConfigurationManagerService.java | 19 +++++-- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/ConfigurationManagerServiceTest.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/ConfigurationManagerServiceTest.java index c521d1e8f..69b31b920 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/ConfigurationManagerServiceTest.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/ConfigurationManagerServiceTest.java @@ -366,7 +366,7 @@ private static Response createConfig(String path, boolean isCorrectType) { parameters.put(PATH, path); } return endpoint.request(MediaType.APPLICATION_JSON) - .post(Entity.json(new ConfigurationQueryParameters(parameters))); + .post(Entity.json(new ConfigurationQueryParameters(null, null, null, parameters))); } private static Response createJsonConfig(String jsonFileName) throws URISyntaxException, IOException { @@ -384,7 +384,7 @@ private static Response createJsonConfig(String jsonFileName) throws URISyntaxEx ObjectMapper mapper = new ObjectMapper(); Map params = mapper.readValue(inputStream, new TypeReference>() {}); return endpoint.request(MediaType.APPLICATION_JSON) - .post(Entity.json(new ConfigurationQueryParameters(params))); + .post(Entity.json(new ConfigurationQueryParameters(null, null, null, params))); } } @@ -417,7 +417,7 @@ private static Response updateConfig(String path, String id, boolean isCorrectTy parameters.put(PATH, path); } return endpoint.request(MediaType.APPLICATION_JSON) - .put(Entity.json(new ConfigurationQueryParameters(parameters))); + .put(Entity.json(new ConfigurationQueryParameters(null, null, null, parameters))); } private static Response deleteConfig(String id) { diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/views/ConfigurationQueryParameters.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/views/ConfigurationQueryParameters.java index f211d3f83..78b208c13 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/views/ConfigurationQueryParameters.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/views/ConfigurationQueryParameters.java @@ -15,44 +15,81 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNull; - -import io.swagger.v3.oas.annotations.Hidden; +import org.eclipse.tracecompass.tmf.core.config.TmfConfiguration; /** * Definition of a parameters object received by the server from a client for configurations. */ public class ConfigurationQueryParameters { + private @NonNull String name; + private @NonNull String description; + private @NonNull String typeId; private @NonNull Map parameters; /** * Constructor for Jackson */ public ConfigurationQueryParameters() { + // Default constructor for Jackson this.parameters = new HashMap<>(); + this.name = TmfConfiguration.UNKNOWN; + this.description = TmfConfiguration.UNKNOWN; + this.typeId = TmfConfiguration.UNKNOWN; } /** * Constructor. * + * @param name + * the name of the configuration + * @param description + * the description of the configuration + * @param typeId + * the typeId of the configuration + * * @param parameters * Map of parameters */ - public ConfigurationQueryParameters(Map parameters) { + public ConfigurationQueryParameters(String name, String description, String typeId, Map parameters) { this.parameters = parameters != null ? parameters : new HashMap<>(); + this.name = name == null ? TmfConfiguration.UNKNOWN : name; + this.description = description == null ? TmfConfiguration.UNKNOWN : description; + this.typeId = typeId == null ? TmfConfiguration.UNKNOWN : typeId; + } + + /** + * @return the name of configuration or {@link TmfConfiguration#UNKNOWN} if not provided + */ + @NonNull public String getName() { + return name; + } + + /** + * @return the description of configuration or {@link TmfConfiguration#UNKNOWN} if not provided + */ + @NonNull public String getDescription() { + return description; + } + + /** + * @return the type ID of configuration or {@link TmfConfiguration#UNKNOWN} if not provided + */ + @NonNull public String getTypeId() { + return typeId; } /** - * @return Map of parameters + * @return Map of parameters or empty map if not provided */ - @Hidden - public @NonNull Map getParameters() { + @NonNull public Map getParameters() { return parameters; } @SuppressWarnings("nls") @Override public String toString() { - return "ConfigurationQueryParameters [parameters=" + parameters + "]"; + return "ConfigurationQueryParameters [name=" + getName() + ", description=" + getDescription() + +", typeId=" + getTypeId() + "parameters=" + getParameters() + "]"; } } diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/ConfigurationManagerService.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/ConfigurationManagerService.java index adc3a335f..947dad6cb 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/ConfigurationManagerService.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/ConfigurationManagerService.java @@ -34,6 +34,7 @@ import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.ConfigurationQueryParameters; import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration; import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSource; +import org.eclipse.tracecompass.tmf.core.config.TmfConfiguration; import org.eclipse.tracecompass.tmf.core.config.TmfConfigurationSourceManager; import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; @@ -151,9 +152,14 @@ public Response postConfiguration(@Parameter(description = CFG_TYPE_ID) @PathPar if (queryParameters == null) { return Response.status(Status.BAD_REQUEST).entity(EndpointConstants.MISSING_PARAMETERS).build(); } - + ITmfConfiguration inputConfig = new TmfConfiguration.Builder() + .setName(queryParameters.getName()) + .setDescription(queryParameters.getDescription()) + .setSourceTypeId(typeId) + .setParameters(queryParameters.getParameters()) + .build(); try { - ITmfConfiguration config = configurationSource.create(queryParameters.getParameters()); + ITmfConfiguration config = configurationSource.create(inputConfig); return Response.ok(config).build(); } catch (TmfConfigurationException e) { return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build(); @@ -232,8 +238,15 @@ public Response putConfiguration(@Parameter(description = CFG_TYPE_ID) @PathPara return Response.status(Status.NOT_FOUND).entity("Configuration instance doesn't exist for type " + typeId).build(); //$NON-NLS-1$ } + ITmfConfiguration inputConfig = new TmfConfiguration.Builder() + .setId(configId) + .setName(queryParameters.getName()) + .setDescription(queryParameters.getDescription()) + .setSourceTypeId(typeId) + .setParameters(queryParameters.getParameters()) + .build(); try { - ITmfConfiguration config = configurationSource.update(configId, queryParameters.getParameters()); + ITmfConfiguration config = configurationSource.update(configId, inputConfig); return Response.ok(config).build(); } catch (TmfConfigurationException e) { return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();