Skip to content
Snippets Groups Projects
Commit 5834ba7f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

api for getting reaction and element types

parent e3964d10
No related branches found
No related tags found
1 merge request!12Resolve "new JS API calls"
......@@ -26,6 +26,8 @@ public class ConfigurationController extends BaseController {
result.put("imageFormats", configurationController.getImageFormats(token));
result.put("modelFormats", configurationController.getModelFormats(token));
result.put("overlayTypes", configurationController.getOverlayTypes(token));
result.put("elementTypes", configurationController.getElementTypes(token));
result.put("reactionTypes", configurationController.getReactionTypes(token));
return result;
}
......
package lcsb.mapviewer.api.configuration;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import javassist.Modifier;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.converter.IConverter;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.ImageGenerators;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.converter.model.sbgnml.SbgnmlXmlConverter;
import lcsb.mapviewer.model.map.AnnotatedObject;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.modelutils.map.ClassTreeNode;
import lcsb.mapviewer.modelutils.map.ElementUtils;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import lcsb.mapviewer.services.interfaces.IUserService;
......@@ -23,6 +34,7 @@ import lcsb.mapviewer.services.view.ConfigurationView;
@Transactional(value = "txManager")
public class ConfigurationRestImpl {
private Logger logger = Logger.getLogger(ConfigurationRestImpl.class);
@Autowired
private IUserService userService;
......@@ -112,4 +124,45 @@ public class ConfigurationRestImpl {
return result;
}
public Set<String> getElementTypes(String token) throws SecurityException {
userService.getToken(token);
return getClassStringTypesList(Element.class);
}
private Set<String> getClassStringTypesList(Class<?> elementClass) {
Set<String> result = new HashSet<>();
ElementUtils elementUtils = new ElementUtils();
ClassTreeNode top = elementUtils.getAnnotatedElementClassTree();
Queue<ClassTreeNode> queue = new LinkedList<>();
queue.add(top);
while (!queue.isEmpty()) {
ClassTreeNode clazz = queue.poll();
for (ClassTreeNode child : clazz.getChildren()) {
queue.add(child);
}
if (elementClass.isAssignableFrom(clazz.getClazz())) {
if (!Modifier.isAbstract(clazz.getClazz().getModifiers())) {
try {
if (elementClass.isAssignableFrom(Reaction.class)) {
result.add(((AnnotatedObject) (clazz.getClazz().getDeclaredConstructor().newInstance())).getStringType());
} else {
result.add(((AnnotatedObject) (clazz.getClazz().getDeclaredConstructor(String.class).newInstance("id"))).getStringType());
}
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| java.lang.SecurityException e) {
throw new RuntimeException(e);
}
}
}
}
return result;
}
public Set<String> getReactionTypes(String token) throws SecurityException {
userService.getToken(token);
return getClassStringTypesList(Reaction.class);
}
}
......@@ -4,7 +4,9 @@ import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
......@@ -12,9 +14,14 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.api.RestTestFunctions;
import lcsb.mapviewer.model.map.reaction.type.StateTransitionReaction;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.services.view.ConfigurationView;
public class ConfigurationRestImplTest extends RestTestFunctions {
private Logger logger = Logger.getLogger(ConfigurationRestImplTest.class);
@Autowired
public ConfigurationRestImpl configurationRestImpl;
......@@ -63,4 +70,30 @@ public class ConfigurationRestImplTest extends RestTestFunctions {
}
}
@Test
public void testGetElementTypes() throws Exception {
try {
Set<String> list = configurationRestImpl.getElementTypes(token.getId());
GenericProtein protein = new GenericProtein("id");
assertTrue(list.contains(protein.getStringType()));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetReactionTypes() throws Exception {
try {
Set<String> list = configurationRestImpl.getReactionTypes(token.getId());
StateTransitionReaction protein = new StateTransitionReaction();
assertTrue(list.contains(protein.getStringType()));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment