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

rest api for sbml functions

parent 1678d950
No related branches found
No related tags found
1 merge request!186Resolve "upload of sbml"
...@@ -146,4 +146,8 @@ public class SbmlFunction implements Serializable, SbmlArgument { ...@@ -146,4 +146,8 @@ public class SbmlFunction implements Serializable, SbmlArgument {
this.model = model; this.model = model;
} }
public int getId() {
return id;
}
} }
2018-02-08 12:13:41,962 INFO o.r.Reflections [main] Reflections took 57 ms to scan 1 urls, producing 34 keys and 433 values
package lcsb.mapviewer.api.projects.models.functions;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.services.SecurityException;
@RestController
public class FunctionsController extends BaseController {
@Autowired
private FunctionsRestImpl functionController;
@RequestMapping(value = "/projects/{projectId}/models/{modelId}/functions/{functionId}", method = {
RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Map<String, Object> getFunction(//
@PathVariable(value = "projectId") String projectId, //
@PathVariable(value = "modelId") String modelId, //
@PathVariable(value = "functionId") String functionId, //
@CookieValue(value = Configuration.AUTH_TOKEN) String token //
) throws QueryException, SecurityException {
return functionController.getFunction(projectId, modelId, token, functionId);
}
@RequestMapping(value = "/projects/{projectId}/models/{modelId}/functions/", method = {
RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public List<Map<String, Object>> getFunctions(//
@PathVariable(value = "projectId") String projectId, //
@PathVariable(value = "modelId") String modelId, //
@CookieValue(value = Configuration.AUTH_TOKEN) String token //
) throws QueryException, SecurityException {
return functionController.getFunctions(projectId, modelId, token);
}
}
\ No newline at end of file
package lcsb.mapviewer.api.projects.models.functions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.ObjectNotFoundException;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.model.map.kinetics.SbmlFunction;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.services.SecurityException;
@Transactional(value = "txManager")
public class FunctionsRestImpl extends BaseRestImpl {
/**
* Default class logger.
*/
private Logger logger = Logger.getLogger(FunctionsRestImpl.class);
public Map<String, Object> getFunction(String projectId, String modelId, String token, String functionId)
throws SecurityException, QueryException {
List<Model> models = getModels(projectId, modelId, token);
int id = Integer.valueOf(functionId);
for (Model model : models) {
for (SbmlFunction function : model.getFunctions()) {
if (function.getId() == id) {
return functionToMap(function);
}
}
}
throw new ObjectNotFoundException("Function with given id doesn't exist");
}
private Map<String, Object> functionToMap(SbmlFunction function) {
Map<String, Object> result = new HashMap<>();
result.put("id", function.getId());
result.put("functionId", function.getFunctionId());
result.put("name", function.getName());
result.put("definition", function.getDefinition());
result.put("arguments", function.getArguments());
return result;
}
public List<Map<String, Object>> getFunctions(String projectId, String modelId, String token) throws SecurityException {
List<Map<String, Object>> result = new ArrayList<>();
List<Model> models = getModels(projectId, modelId, token);
for (Model model : models) {
for (SbmlFunction function : model.getFunctions()) {
result.add(functionToMap(function));
}
}
return result;
}
}
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
<bean id="BioEntitiesRestImpl" class="lcsb.mapviewer.api.projects.models.bioEntities.BioEntitiesRestImpl"/> <bean id="BioEntitiesRestImpl" class="lcsb.mapviewer.api.projects.models.bioEntities.BioEntitiesRestImpl"/>
<bean id="ChemicalRestImpl" class="lcsb.mapviewer.api.projects.chemicals.ChemicalRestImpl"/> <bean id="ChemicalRestImpl" class="lcsb.mapviewer.api.projects.chemicals.ChemicalRestImpl"/>
<bean id="ElementsRestImpl" class="lcsb.mapviewer.api.projects.models.bioEntities.elements.ElementsRestImpl"/> <bean id="ElementsRestImpl" class="lcsb.mapviewer.api.projects.models.bioEntities.elements.ElementsRestImpl"/>
<bean id="FunctionsRestImpl" class="lcsb.mapviewer.api.projects.models.functions.FunctionsRestImpl"/>
<bean id="DrugRestImpl" class="lcsb.mapviewer.api.projects.drugs.DrugRestImpl"/> <bean id="DrugRestImpl" class="lcsb.mapviewer.api.projects.drugs.DrugRestImpl"/>
<bean id="MiRnaRestImpl" class="lcsb.mapviewer.api.projects.mirnas.MiRnaRestImpl"/> <bean id="MiRnaRestImpl" class="lcsb.mapviewer.api.projects.mirnas.MiRnaRestImpl"/>
<bean id="OverlayRestImpl" class="lcsb.mapviewer.api.projects.overlays.OverlayRestImpl"/> <bean id="OverlayRestImpl" class="lcsb.mapviewer.api.projects.overlays.OverlayRestImpl"/>
......
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