Skip to content

Commit

Permalink
server: support for customizable data providers
Browse files Browse the repository at this point in the history
Signed-off-by: Bernd Hufmann <[email protected]>
  • Loading branch information
bhufmann committed Oct 22, 2024
1 parent ee587b0 commit ea062d8
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -384,7 +384,7 @@ private static Response createJsonConfig(String jsonFileName) throws URISyntaxEx
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> params = mapper.readValue(inputStream, new TypeReference<Map<String, Object>>() {});
return endpoint.request(MediaType.APPLICATION_JSON)
.post(Entity.json(new ConfigurationQueryParameters(params)));
.post(Entity.json(new ConfigurationQueryParameters(null, null, null, params)));
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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<String, Object> parameters) {
public ConfigurationQueryParameters(String name, String description, String typeId, Map<String, Object> 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<String, Object> getParameters() {
@NonNull public Map<String, Object> getParameters() {
return parameters;
}

@SuppressWarnings("nls")
@Override
public String toString() {
return "ConfigurationQueryParameters [parameters=" + parameters + "]";
return "ConfigurationQueryParameters [name=" + getName() + ", description=" + getDescription()
+", typeId=" + getTypeId() + "parameters=" + getParameters() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit ea062d8

Please sign in to comment.