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

rest API for sbml functions

parent a046d06b
No related branches found
No related tags found
1 merge request!186Resolve "upload of sbml"
......@@ -115,4 +115,8 @@ public class SbmlParameter implements Serializable, SbmlArgument {
return getParameterId();
}
public int getId() {
return id;
}
}
......@@ -121,4 +121,8 @@ public class SbmlUnit implements Serializable {
return new SbmlUnit(this);
}
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
......@@ -21,6 +21,7 @@ public class FunctionsRestImpl extends BaseRestImpl {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private Logger logger = Logger.getLogger(FunctionsRestImpl.class);
public Map<String, Object> getFunction(String projectId, String modelId, String token, String functionId)
......
package lcsb.mapviewer.api.projects.models.parameters;
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 ParametersController extends BaseController {
@Autowired
private ParametersRestImpl parameterController;
@RequestMapping(value = "/projects/{projectId}/models/{modelId}/parameters/{parameterId}", method = {
RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Map<String, Object> getParameter(//
@PathVariable(value = "projectId") String projectId, //
@PathVariable(value = "modelId") String modelId, //
@PathVariable(value = "parameterId") String parameterId, //
@CookieValue(value = Configuration.AUTH_TOKEN) String token //
) throws QueryException, SecurityException {
return parameterController.getParameter(projectId, modelId, token, parameterId);
}
@RequestMapping(value = "/projects/{projectId}/models/{modelId}/parameters/", method = {
RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public List<Map<String, Object>> getParameters(//
@PathVariable(value = "projectId") String projectId, //
@PathVariable(value = "modelId") String modelId, //
@CookieValue(value = Configuration.AUTH_TOKEN) String token //
) throws QueryException, SecurityException {
return parameterController.getParameters(projectId, modelId, token);
}
}
\ No newline at end of file
package lcsb.mapviewer.api.projects.models.parameters;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
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.SbmlParameter;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.services.SecurityException;
@Transactional(value = "txManager")
public class ParametersRestImpl extends BaseRestImpl {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private Logger logger = Logger.getLogger(ParametersRestImpl.class);
public Map<String, Object> getParameter(String projectId, String modelId, String token, String parameterId)
throws SecurityException, QueryException {
Set<SbmlParameter> globalParameters = getGlobalParametersFromProject(projectId, modelId, token);
Set<SbmlParameter> parameters = getParametersFromProject(projectId, modelId, token);
int id = Integer.valueOf(parameterId);
for (SbmlParameter parameter : parameters) {
if (parameter.getId() == id) {
return parameterToMap(parameter, globalParameters.contains(parameter));
}
}
throw new ObjectNotFoundException("Parameter with given id doesn't exist");
}
private Set<SbmlParameter> getParametersFromProject(String projectId, String modelId, String token)
throws SecurityException {
List<Model> models = getModels(projectId, modelId, token);
Set<SbmlParameter> parameters = new HashSet<>();
for (Model model : models) {
parameters.addAll(model.getParameters());
for (Reaction reaction : model.getReactions()) {
if (reaction.getKinetics() != null) {
parameters.addAll(reaction.getKinetics().getParameters());
}
}
}
return parameters;
}
private Set<SbmlParameter> getGlobalParametersFromProject(String projectId, String modelId, String token)
throws SecurityException {
List<Model> models = getModels(projectId, modelId, token);
Set<SbmlParameter> parameters = new HashSet<>();
for (Model model : models) {
parameters.addAll(model.getParameters());
}
return parameters;
}
private Map<String, Object> parameterToMap(SbmlParameter parameter, boolean global) {
Map<String, Object> result = new HashMap<>();
result.put("id", parameter.getId());
result.put("parameterId", parameter.getParameterId());
result.put("name", parameter.getName());
result.put("value", parameter.getValue());
result.put("global", global);
if (parameter.getUnits() != null) {
result.put("unitsId", parameter.getUnits().getId());
} else {
result.put("unitsId", null);
}
return result;
}
public List<Map<String, Object>> getParameters(String projectId, String modelId, String token)
throws SecurityException {
List<Map<String, Object>> result = new ArrayList<>();
Set<SbmlParameter> globalParameters = getGlobalParametersFromProject(projectId, modelId, token);
Set<SbmlParameter> parameters = getParametersFromProject(projectId, modelId, token);
for (SbmlParameter parameter : parameters) {
result.add(parameterToMap(parameter, globalParameters.contains(parameter)));
}
return result;
}
}
......@@ -22,6 +22,7 @@
<bean id="ChemicalRestImpl" class="lcsb.mapviewer.api.projects.chemicals.ChemicalRestImpl"/>
<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="ParametersRestImpl" class="lcsb.mapviewer.api.projects.models.parameters.ParametersRestImpl"/>
<bean id="DrugRestImpl" class="lcsb.mapviewer.api.projects.drugs.DrugRestImpl"/>
<bean id="MiRnaRestImpl" class="lcsb.mapviewer.api.projects.mirnas.MiRnaRestImpl"/>
<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