Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: support for customizable data providers (outputs) via data provider factories #80

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading