Commit 16e25275 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

modelConverters and imageConverters moved to controller

parent 8fcfe4c0
......@@ -18,6 +18,10 @@ import org.springframework.web.bind.annotation.*;
import lcsb.mapviewer.annotation.services.dapi.DapiConnectionException;
import lcsb.mapviewer.annotation.services.dapi.dto.UserDto;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.ImageGenerators;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.ConfigurationOption;
import lcsb.mapviewer.services.QueryException;
......@@ -33,12 +37,16 @@ public class ConfigurationController extends BaseController {
private IConfigurationService configurationService;
private ServletContext context;
private List<Converter> modelConverters;
@Autowired
public ConfigurationController(ConfigurationRestImpl configurationController,
IConfigurationService configurationService,
ServletContext context) {
ServletContext context,
List<Converter> modelConverters) {
this.configurationRestImpl = configurationController;
this.configurationService = configurationService;
this.modelConverters = modelConverters;
this.context = context;
}
......@@ -46,8 +54,8 @@ public class ConfigurationController extends BaseController {
public Map<String, Object> getConfiguration(Authentication authentication) {
Map<String, Object> result = new TreeMap<>();
result.put("options", getOptions(authentication));
result.put("imageFormats", configurationRestImpl.getImageFormats());
result.put("modelFormats", configurationRestImpl.getModelFormats());
result.put("imageFormats", getImageFormats());
result.put("modelFormats", getModelFormats());
result.put("overlayTypes", configurationRestImpl.getOverlayTypes());
result.put("elementTypes", configurationRestImpl.getElementTypes());
result.put("reactionTypes", configurationRestImpl.getReactionTypes());
......@@ -110,4 +118,34 @@ public class ConfigurationController extends BaseController {
Map<String, Object> data = getData(node, "option");
return configurationRestImpl.updateOption(option, data);
}
public List<Map<String, Object>> getImageFormats() {
List<Map<String, Object>> result = new ArrayList<>();
ImageGenerators imageGenerators = new ImageGenerators();
List<Pair<String, Class<? extends AbstractImageGenerator>>> imageGeneratorList = imageGenerators
.getAvailableImageGenerators();
for (Pair<String, Class<? extends AbstractImageGenerator>> element : imageGeneratorList) {
Map<String, Object> row = new TreeMap<>();
row.put("name", element.getLeft());
row.put("handler", element.getRight().getCanonicalName());
row.put("extension", imageGenerators.getExtension(element.getRight()));
result.add(row);
}
return result;
}
public List<Map<String, Object>> getModelFormats() {
List<Map<String, Object>> result = new ArrayList<>();
for (Converter converter : modelConverters) {
Map<String, Object> row = new TreeMap<>();
row.put("name", converter.getCommonName());
row.put("handler", converter.getClass().getCanonicalName());
row.put("extension", converter.getFileExtension());
result.add(row);
}
return result;
}
}
\ No newline at end of file
......@@ -16,11 +16,7 @@ import lcsb.mapviewer.annotation.services.dapi.DapiConnector;
import lcsb.mapviewer.annotation.services.dapi.dto.ReleaseDto;
import lcsb.mapviewer.annotation.services.dapi.dto.UserDto;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.ImageGenerators;
import lcsb.mapviewer.model.graphics.MapCanvasType;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.kinetics.SbmlUnitType;
......@@ -78,37 +74,6 @@ public class ConfigurationRestImpl extends BaseRestImpl {
this.configurationService = configurationService;
}
public List<Map<String, Object>> getImageFormats() {
List<Map<String, Object>> result = new ArrayList<>();
ImageGenerators imageGenerators = new ImageGenerators();
List<Pair<String, Class<? extends AbstractImageGenerator>>> imageGeneratorList = imageGenerators
.getAvailableImageGenerators();
for (Pair<String, Class<? extends AbstractImageGenerator>> element : imageGeneratorList) {
Map<String, Object> row = new TreeMap<>();
row.put("name", element.getLeft());
row.put("handler", element.getRight().getCanonicalName());
row.put("extension", imageGenerators.getExtension(element.getRight()));
result.add(row);
}
return result;
}
public List<Map<String, Object>> getModelFormats() {
List<Converter> converters = getModelConverters();
List<Map<String, Object>> result = new ArrayList<>();
for (Converter converter : converters) {
Map<String, Object> row = new TreeMap<>();
row.put("name", converter.getCommonName());
row.put("handler", converter.getClass().getCanonicalName());
row.put("extension", converter.getFileExtension());
result.add(row);
}
return result;
}
public List<Map<String, Object>> getOverlayTypes() {
List<Map<String, Object>> result = new ArrayList<>();
for (DataOverlayType type : DataOverlayType.values()) {
......
......@@ -53,18 +53,6 @@ public class ConfigurationRestImplTest extends RestTestFunctions {
assertNotNull(result);
}
@Test
public void testImageFormats() throws Exception {
List<Map<String, Object>> list = configurationRestImpl.getImageFormats();
assertTrue(list.size() > 0);
}
@Test
public void testModelFormats() throws Exception {
List<Map<String, Object>> list = configurationRestImpl.getModelFormats();
assertTrue(list.size() > 0);
}
@Test
public void testGetElementTypes() throws Exception {
Set<Map<String, String>> list = configurationRestImpl.getElementTypes();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment