Skip to content

Commit

Permalink
Added Springboot Serialization, Refactored dataset API
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardiksh16 committed Nov 27, 2024
1 parent 05c8ff9 commit acd333a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 26 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
</repositories>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.7.15</version>
</dependency>

<!-- NIF transfer lib -->
<dependency>
<groupId>org.aksw</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

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> {


Expand Down
24 changes: 11 additions & 13 deletions src/main/java/org/aksw/gerbil/web/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -303,27 +304,24 @@ public ModelAndView experiment(@RequestParam(value = "id") String id, HttpServle
}

@RequestMapping("/datasets")
public @ResponseBody Map<String, 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<String>> response = new TreeMap<>();
ObjectMapper mapper = new ObjectMapper();
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;
}
List<String> adapterDetailsJsonList = adapterManager.getDatasetDetailsForExperiment(type);
for (String adapterJson : adapterDetailsJsonList) {
try {
Map<String, String> adapterDetails = mapper.readValue(adapterJson, new TypeReference<Map<String, String>>() {});
String name = adapterDetails.get("name");
String group = adapterDetails.get("group");
response.computeIfAbsent(group, k -> new ArrayList<>()).add(name);
Collections.sort(response.get(group));
} catch (IOException e) {
LOGGER.error("Failed to parse adapter details JSON: {}", adapterJson, e);
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;
}
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/aksw/gerbil/web/config/AdapterList.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,13 @@ public List<String> getAdapterDetailsForExperiment(ExperimentType type) {
List<T> configs = getAdaptersForExperiment(type);
List<String> serializedConfigs = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(AbstractAdapterConfiguration.class, new AdapterConfigSerializer(AbstractAdapterConfiguration.class));
mapper.registerModule(module);
for (T config : configs) {
String json = null;
try {
json = mapper.writeValueAsString(config);
String json = mapper.writeValueAsString(config);
serializedConfigs.add(json);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
serializedConfigs.add(json);
}
return serializedConfigs;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/aksw/gerbil/web/config/AdapterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package org.aksw.gerbil.web.config;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.aksw.gerbil.annotator.AnnotatorConfiguration;
Expand Down Expand Up @@ -67,8 +67,9 @@ public Set<String> getAnnotatorNamesForExperiment(ExperimentType type) {
public Set<String> getDatasetNamesForExperiment(ExperimentType type) {
return datasets.getAdapterNamesForExperiment(type);
}
public List<String> getDatasetDetailsForExperiment(ExperimentType type) {
return datasets.getAdapterDetailsForExperiment(type);

public List<DatasetConfiguration> getDatasetDetailsForExperiment(ExperimentType type) {
return new ArrayList<>(datasets.getAdaptersForExperiment(type));
}

public AnnotatorConfiguration getAnnotatorConfig(String name, ExperimentType type) {
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/aksw/gerbil/web/config/RootConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import java.util.Set;

import org.aksw.gerbil.config.GerbilConfiguration;
import org.aksw.gerbil.dataset.AdapterConfigSerializer;
import org.aksw.gerbil.dataset.check.EntityCheckerManager;
import org.aksw.gerbil.dataset.check.impl.EntityCheckerManagerImpl;
import org.aksw.gerbil.dataset.check.impl.FileBasedCachingEntityCheckerManager;
import org.aksw.gerbil.dataset.check.impl.HttpBasedEntityChecker;
import org.aksw.gerbil.dataset.check.impl.InMemoryCachingEntityCheckerManager;
import org.aksw.gerbil.dataset.check.index.IndexBasedEntityChecker;
import org.aksw.gerbil.datatypes.AbstractAdapterConfiguration;
import org.aksw.gerbil.datatypes.ExperimentType;
import org.aksw.gerbil.evaluate.EvaluatorFactory;
import org.aksw.gerbil.exceptions.GerbilException;
Expand Down Expand Up @@ -61,6 +63,7 @@
import org.apache.commons.configuration.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;
Expand All @@ -80,11 +83,11 @@
* <code>org.aksw.gerbil.web.config</code> searching for other
* {@link Configuration}s</li>
* </ul>
*
*
* @author Michael R&ouml;der ([email protected])
* @author Lars Wesemann
* @author Didier Cherix
*
*
*/
@org.springframework.context.annotation.Configuration
@ComponentScan(basePackages = "org.aksw.gerbil.web.config")
Expand Down Expand Up @@ -147,6 +150,11 @@ public class RootConfig {
return overseer;
}

@Bean
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
return builder -> builder.serializers(new AdapterConfigSerializer(AbstractAdapterConfiguration.class));
}

public static @Bean SubClassInferencer createSubClassInferencer() {
Model classModel = ModelFactory.createDefaultModel();
String hierarchyFiles[] = GerbilConfiguration.getInstance()
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/views/config.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
checkbox.type = 'checkbox';
checkbox.value = item;
label.appendChild(checkbox);
label.appendChild(document.createTextNode(item));
label.appendChild(document.createTextNode(item.name));
optionsContainer.appendChild(label);
});
optgroupDiv.appendChild(optionsContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

public class ErrorCountingAnnotatorDecoratorTest {

private static String UNGROUPED = "Un Grouped";

@Test
public void testErrorCount() {
SimpleLoggingResultStoringDAO4Debugging db = new SimpleLoggingResultStoringDAO4Debugging();
Expand Down Expand Up @@ -77,7 +79,7 @@ public static class ErrorCausingAnnotatorConfig extends AbstractAdapterConfigura
private int errorsPerHundred;

public ErrorCausingAnnotatorConfig(int errorsPerHundred) {
super("Error causing topic system","Un Grouped", false, ExperimentType.ERec);
super("Error causing topic system",UNGROUPED, false, ExperimentType.ERec);
this.errorsPerHundred = errorsPerHundred;
}

Expand Down

0 comments on commit acd333a

Please sign in to comment.