Skip to content

Commit

Permalink
server: Added DataType to column descriptors and serializer
Browse files Browse the repository at this point in the history
[Added] DataType to column descriptors and serializer

Change-Id: Id3a1e27d73762ab830f4a99b88dc52b00d418810
Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/199989
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
  • Loading branch information
bhufmann committed Mar 21, 2023
1 parent 8aa37f9 commit 3e0763f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public class DataProviderServiceTest extends RestServerTest {
private static final long TABLE_INDEX = 0L;
private static final long TABLE_COUNT = 100L;

private static final List<EntryHeaderStub> EXPECTED_XY_TREE_HEADERS = ImmutableList.of(new EntryHeaderStub("Process", ""), new EntryHeaderStub("TID", ""), new EntryHeaderStub("%", ""), new EntryHeaderStub("Time", ""));
private static final List<EntryHeaderStub> EXPECTED_XY_TREE_HEADERS = ImmutableList.of(new EntryHeaderStub("Process", "", null), new EntryHeaderStub("TID", "", null), new EntryHeaderStub("%", "", null), new EntryHeaderStub("Time", "", null));

private static List<String> STATISTICS_TREE_HEADERS = ImmutableList.of("Label", "Minimum", "Maximum", "Average", "Std Dev", "Count", "Total");
private static List<String> SAMPLE_TOTAL_STATS_LABELS = ImmutableList.of("ust", "1 ns", "5.979 s", "10.845 ms", "196.299 ms", "1948", "21.127 s");
private static List<String> SAMPLE_SELECTION_STATS_LABELS = ImmutableList.of("Selection", "49.665 µs", "5.979 s", "11.388 ms", "201.201 ms", "1854", "21.113 s");
private static List<String> STATISTICS_TREE_HEADERS = ImmutableList.of("Label", "Minimum", "Maximum", "Average", "Std Dev", "Count", "Total", "Min Time Range", "Max Time Range");
private static List<String> SAMPLE_TOTAL_STATS_LABELS = ImmutableList.of("ust", "1 ns", "5.979 s", "10.845 ms", "196.299 ms", "1948", "21.127 s", "[1450193745774189602,1450193745774189603]", "[1450193722283061910,1450193728261604656]");
private static List<String> SAMPLE_SELECTION_STATS_LABELS = ImmutableList.of("Selection", "49.665 µs", "5.979 s", "11.388 ms", "201.201 ms", "1854", "21.113 s", "[1450193730177271075,1450193730177320740]", "[1450193722283061910,1450193728261604656]");

/**
* Test getting the data provider descriptors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class EntryHeaderStub implements Serializable {

private final String fName;
private final String fTooltip;
private final String fDataType;

/**
* {@link JsonCreator} Constructor for final fields
Expand All @@ -36,12 +37,16 @@ public class EntryHeaderStub implements Serializable {
* the name of the header
* @param tooltip
* The tooltip for this header
* @param dataType
* The data type of the column
*/
@JsonCreator
public EntryHeaderStub(@JsonProperty("name") String name,
@JsonProperty("tooltip") String tooltip) {
@JsonProperty("tooltip") String tooltip,
@JsonProperty("dataType") String dataType) {
fName = Objects.requireNonNull(name, "The 'name' json field was not set");
fTooltip = tooltip;
fDataType = dataType;
}

/**
Expand All @@ -61,4 +66,13 @@ public String getName() {
public String getTooltip() {
return fTooltip;
}

/**
* Get the data type of the column
*
* @return The data type of the column
*/
public String getDataType() {
return fDataType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.List;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.tmf.core.dataprovider.DataType;
import org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor;
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
import org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel;
Expand All @@ -38,6 +40,7 @@ public class TreeModelWrapper {
public static class TreeColumnHeader {
private final String fName;
private final String fTooltip;
private final @Nullable String fDataType;

/**
* Constructor with only the name
Expand All @@ -46,10 +49,18 @@ public static class TreeColumnHeader {
* The name of the column
* @param tooltip
* The tooltip text for the column
* @param dataType
* The data type {@link DataType}
*/
public TreeColumnHeader(String name, String tooltip) {
fName =name;
public TreeColumnHeader(String name, String tooltip, DataType dataType) {
fName = name;
fTooltip = tooltip;
if (dataType.equals(DataType.STRING)) {
// Default case
fDataType = null;
} else {
fDataType = dataType.name();
}
}

/**
Expand All @@ -68,6 +79,15 @@ public String getName() {
public String getTooltip() {
return fTooltip;
}

/**
* Gets the data type of the column
*
* @return data type.
*/
public @Nullable String getDataType() {
return fDataType;
}
}

/**
Expand All @@ -78,7 +98,7 @@ public TreeModelWrapper(TmfTreeModel<@NonNull ITmfTreeDataModel> model) {
fModel = model;
List<@NonNull ITableColumnDescriptor> headers = model.getColumnDescriptors();
Builder<@NonNull TreeColumnHeader> builder = ImmutableList.builder();
headers.forEach(column -> builder.add(new TreeColumnHeader(column.getText(), column.getTooltip())));
headers.forEach(column -> builder.add(new TreeColumnHeader(column.getText(), column.getTooltip(), column.getDataType())));
fHeaders = builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.TreeModelWrapper.TreeColumnHeader;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.Experiment;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.Trace;
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.IVirtualTableLine;
Expand Down Expand Up @@ -64,6 +65,7 @@ public ObjectMapper getContext(Class<?> type) {
module.addSerializer(TimeGraphEntryModel.class, new TimeGraphEntryModelSerializer());
module.addSerializer(Annotation.class, new AnnotationSerializer());
module.addSerializer(TmfTreeDataModel.class, new TmfTreeModelSerializer());
module.addSerializer(TreeColumnHeader.class, new TreeColumnHeaderSerializer());
module.addSerializer(OutputElementStyle.class, new OutputElementStyleSerializer());
module.addSerializer(IVirtualTableLine.class, new VirtualTableLineSerializer());
module.addSerializer(VirtualTableCell.class, new VirtualTableCellSerializer());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**********************************************************************
* Copyright (c) 2023 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp;

import java.io.IOException;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.TreeModelWrapper.TreeColumnHeader;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

/**
* Serializer for tmf tree entry model {@link TreeColumnHeader}
*
* @author Bernd Hufmann
*/
public class TreeColumnHeaderSerializer extends StdSerializer<@NonNull TreeColumnHeader> {

/**
* Generated serial UID
*/
private static final long serialVersionUID = 3393902091244330176L;

/**
* Constructor.
*/
protected TreeColumnHeaderSerializer() {
super(TreeColumnHeader.class);
}

@Override
public void serialize(TreeColumnHeader value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartObject();
gen.writeStringField("name", value.getName()); //$NON-NLS-1$
gen.writeStringField("tooltip", value.getTooltip()); //$NON-NLS-1$
if (value.getDataType() != null) {
gen.writeStringField("dataType", value.getDataType()); //$NON-NLS-1$
}
gen.writeEndObject();
}
}

0 comments on commit 3e0763f

Please sign in to comment.