Skip to content

Commit

Permalink
server: Add serializer for metadata in time graph entry model
Browse files Browse the repository at this point in the history
Also, add metadata and swagger annotation to TimeGraphEntry model.

[Added] metadata to the serializer of time graph entry model.

Change-Id: I0ebc0641ca62ac1cbdfd08808078593b53812cf2
Signed-off-by: Rodrigo Pinto <rodrigo.pinto@calian.ca>
Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/193246
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Marco Miller <marco.miller@ericsson.com>
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
  • Loading branch information
Rodrigoplp-work authored and bhufmann committed Jun 14, 2022
1 parent ef3d897 commit fc169ab
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
**********************************************************************/
package org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -27,6 +29,7 @@ public class TimeGraphEntryStub extends EntryStub {

private final Long fStartTime;
private final Long fEndTime;
private final Map<String, Collection<Object>> fMetadata;

/**
* {@link JsonCreator} Constructor for final fields
Expand All @@ -45,6 +48,8 @@ public class TimeGraphEntryStub extends EntryStub {
* Whether has row model property
* @param style
* The style of this entry
* @param metadata
* The metadata of the entry
*/
@JsonCreator
public TimeGraphEntryStub(@JsonProperty("labels") List<String> labels,
Expand All @@ -53,10 +58,12 @@ public TimeGraphEntryStub(@JsonProperty("labels") List<String> labels,
@JsonProperty("start") Long startTime,
@JsonProperty("end") Long endTime,
@JsonProperty("hasData") boolean hasRowModel,
@JsonProperty("style") OutputElementStyleStub style) {
@JsonProperty("style") OutputElementStyleStub style,
@JsonProperty("metadata") Map<String, Collection<Object>> metadata) {
super(labels, id, parentId, hasRowModel, style);
fStartTime = startTime;
fEndTime = endTime;
fMetadata = metadata;
}

/**
Expand All @@ -77,4 +84,12 @@ public Long getEndTime() {
return fEndTime;
}

/**
* Get the metadata of this entry
*
* @return The metadata of the entry
*/
public Map<String, Collection<Object>> getMetadata() {
return fMetadata;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2021 Ericsson
* Copyright (c) 2021, 2022 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand All @@ -11,6 +11,9 @@

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

import java.util.Collection;
import java.util.Map;

import io.swagger.v3.oas.annotations.media.Schema;

/**
Expand All @@ -30,4 +33,11 @@ public interface TimeGraphEntry {
*/
@Schema(description = "End of the range for which this entry exists")
long getEnd();

/**
* @return The entry's metadata map.
*/
@Schema(description = "Optional metadata map for domain specific data for matching data across data providers. Keys for the same data shall be the same across data providers. "
+ "Only values of type Number or String are allowed. For each key all values shall have the same type.")
Map<String, Collection<Object>> getMetadata();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2020 École Polytechnique de Montréal
* Copyright (c) 2020, 2022 École Polytechnique de Montréal and others
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand All @@ -12,13 +12,18 @@
package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.webapp;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphEntryModel;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.google.common.collect.Multimap;

/**
* Serializer for time graph entry model {@link ITimeGraphEntryModel}
Expand Down Expand Up @@ -53,6 +58,20 @@ public void serialize(ITimeGraphEntryModel value, JsonGenerator gen, SerializerP
gen.writeNumberField("start", value.getStartTime()); //$NON-NLS-1$
gen.writeNumberField("end", value.getEndTime()); //$NON-NLS-1$
gen.writeBooleanField("hasData", value.hasRowModel()); //$NON-NLS-1$
@NonNull Multimap<@NonNull String, @NonNull Object> metadata = value.getMetadata();
if (!metadata.isEmpty()) {
Map<String, Collection<Object>> serializedMap = new HashMap<>();
// Only allow a String or Number in the metadata
for (Entry<@NonNull String, Collection<@NonNull Object>> entry : metadata.asMap().entrySet()) {
Collection<@NonNull Object> collection = entry.getValue();
if ((collection != null) &&
(collection.stream().allMatch(String.class::isInstance) ||
collection.stream().allMatch(Number.class::isInstance))) {
serializedMap.put(entry.getKey(), collection);
}
}
gen.writeObjectField("metadata", serializedMap); //$NON-NLS-1$
}
gen.writeEndObject();
}

Expand Down

0 comments on commit fc169ab

Please sign in to comment.