-
Notifications
You must be signed in to change notification settings - Fork 58
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
Modified backend and frontend for handling grouping of datasets #460
base: master
Are you sure you want to change the base?
Changes from all commits
d550337
8a0fe16
6130c24
0431bd9
6aac61e
66014cf
4e15ef8
05c8ff9
acd333a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.aksw.gerbil.dataset; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
import org.aksw.gerbil.datatypes.AbstractAdapterConfiguration; | ||
|
||
import java.io.IOException; | ||
|
||
@JsonSerialize(using = AdapterConfigSerializer.class) | ||
public class AdapterConfigSerializer extends StdSerializer<AbstractAdapterConfiguration> { | ||
|
||
|
||
public AdapterConfigSerializer(Class<AbstractAdapterConfiguration> t) { | ||
super(AbstractAdapterConfiguration.class); | ||
} | ||
|
||
@Override | ||
public void serialize(AbstractAdapterConfiguration value, JsonGenerator gen, SerializerProvider provider) throws IOException { | ||
gen.writeStartObject(); | ||
gen.writeStringField("name", value.getName()); | ||
gen.writeStringField("group", value.getGroup()); | ||
gen.writeEndObject(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,21 +18,19 @@ | |
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.*; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import org.aksw.gerbil.Experimenter; | ||
import org.aksw.gerbil.config.GerbilConfiguration; | ||
import org.aksw.gerbil.database.ExperimentDAO; | ||
import org.aksw.gerbil.dataid.DataIDGenerator; | ||
import org.aksw.gerbil.dataset.DatasetConfiguration; | ||
import org.aksw.gerbil.datatypes.ExperimentTaskConfiguration; | ||
import org.aksw.gerbil.datatypes.ExperimentTaskStatus; | ||
import org.aksw.gerbil.datatypes.ExperimentType; | ||
|
@@ -306,18 +304,26 @@ public ModelAndView experiment(@RequestParam(value = "id") String id, HttpServle | |
} | ||
|
||
@RequestMapping("/datasets") | ||
public @ResponseBody List<String> datasets(@RequestParam(value = "experimentType") String experimentType) { | ||
public @ResponseBody Map<String, List<DatasetConfiguration>> datasets(@RequestParam(value = "experimentType") String experimentType) { | ||
ExperimentType type = null; | ||
Map<String, List<DatasetConfiguration>> response = new TreeMap<>(); | ||
try { | ||
type = ExperimentType.valueOf(experimentType); | ||
} catch (IllegalArgumentException e) { | ||
LOGGER.warn("Got a request containing a wrong ExperimentType (\"{}\"). Ignoring it.", experimentType); | ||
return null; | ||
} | ||
Set<String> datasets = adapterManager.getDatasetNamesForExperiment(type); | ||
List<String> list = Lists.newArrayList(datasets); | ||
Collections.sort(list); | ||
return list; | ||
try { | ||
List<DatasetConfiguration> datasetConfigurations = adapterManager.getDatasetDetailsForExperiment(type); | ||
for (DatasetConfiguration config : datasetConfigurations) { | ||
response.computeIfAbsent(config.getGroup(), k -> new ArrayList<>()).add(config); | ||
} | ||
response.values().forEach(newList -> newList.sort(Comparator.naturalOrder())); | ||
} catch (Exception e) { | ||
LOGGER.error("Error fetching datasets for ExperimentType: {}", experimentType, e); | ||
return null; | ||
} | ||
return response; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part should simply look like: public @ResponseBody Map<String, List<DatasetConfiguration>> datasets(@RequestParam(value = "experimentType") String experimentType) {
ExperimentType type = null;
Map<String, List<DatasetConfiguration>> response = new TreeMap<>();
try {
type = ExperimentType.valueOf(experimentType);
} catch (IllegalArgumentException e) {
LOGGER.warn("Got a request containing a wrong ExperimentType (\"{}\"). Ignoring it.", experimentType);
return null;
}
return adapterManager.getDatasetDetailsForExperiment(type);
} Actually, the |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,11 @@ | |
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import org.aksw.gerbil.dataset.AdapterConfigSerializer; | ||
import org.aksw.gerbil.datatypes.AbstractAdapterConfiguration; | ||
import org.aksw.gerbil.datatypes.AdapterConfiguration; | ||
import org.aksw.gerbil.datatypes.ExperimentType; | ||
|
||
|
@@ -85,6 +90,21 @@ public Set<String> getAdapterNamesForExperiment(ExperimentType type) { | |
return names; | ||
} | ||
|
||
public List<String> getAdapterDetailsForExperiment(ExperimentType type) { | ||
List<T> configs = getAdaptersForExperiment(type); | ||
List<String> serializedConfigs = new ArrayList<>(); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
for (T config : configs) { | ||
try { | ||
String json = mapper.writeValueAsString(config); | ||
serializedConfigs.add(json); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
return serializedConfigs; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This serialization is actually not necessary. See comment further above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove it, if it is not used anymore. |
||
|
||
public List<T> getAdaptersForName(String name) { | ||
if (nameToAdapterMapping.containsKey(name)) { | ||
return nameToAdapterMapping.get(name); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please move this dependency to the other Spring dependencies? Just search for the
<!-- SPRING -->
line to find them.