diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelRestImpl.java index 6ec57b25d1e2fb2af55cedf2a60a900a05fda911..78c6e8a518283853d4616af260f59264de0ff694 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/ModelRestImpl.java @@ -5,7 +5,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import org.apache.log4j.Logger; import org.springframework.transaction.annotation.Transactional; @@ -82,25 +81,20 @@ public class ModelRestImpl extends BaseRestImpl { public Map<String, Object> updateModel(String projectId, String modelId, Map<String, Object> data, String token) throws SecurityException, QueryException { - Project project = getProjectService().getProjectByProjectId(projectId, token); - if (project == null) { - throw new ObjectNotFoundException("Project with given id doesn't exist"); - } boolean canModify = getUserService().userHasPrivilege(token, PrivilegeType.ADD_MAP); if (!canModify) { throw new SecurityException("You cannot update projects"); } - ModelData model = null; - Integer id = Integer.valueOf(modelId); - for (ModelData m : project.getModels()) { - if (m.getId().equals(id)) { - model = m; - } + + if (modelId.equals("*")) { + throw new QueryException("Invalid model id: " + modelId); } - if (model == null) { + List<Model> models = super.getModels(projectId, modelId, token); + if (models.size() != 1) { throw new ObjectNotFoundException("Model with given id doesn't exist"); } + ModelData model = models.get(0).getModelData(); Set<String> fields = data.keySet(); for (String fieldName : fields) { Object value = data.get(fieldName); diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/ModelService.java b/service/src/main/java/lcsb/mapviewer/services/impl/ModelService.java index e99042cdee151017ef546fd9527b63503c7175b3..e1b62c352d317471e24f07386a374b9adb5c1479 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/ModelService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/ModelService.java @@ -19,11 +19,14 @@ import lcsb.mapviewer.commands.CopyCommand; import lcsb.mapviewer.common.IProgressUpdater; import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.model.ModelFullIndexed; +import lcsb.mapviewer.model.map.model.ModelSubmodelConnection; +import lcsb.mapviewer.model.map.model.SubmodelConnection; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.user.PrivilegeType; @@ -389,7 +392,19 @@ public class ModelService implements IModelService { @Override public void updateModel(ModelData model, String token) throws lcsb.mapviewer.services.SecurityException { - Model topCachedData = getLastModelByProjectId(model.getProject().getProjectId(), token); + Project project = model.getProject(); + if (project == null) { + for (SubmodelConnection sc : model.getParentModels()) { + if (sc instanceof ModelSubmodelConnection) { + project = ((ModelSubmodelConnection) sc).getParentModel().getModel().getProject(); + if (project != null) { + break; + } + } + } + } + + Model topCachedData = getLastModelByProjectId(project.getProjectId(), token); Model cachedData = topCachedData.getSubmodelById(model.getId()); cachedData.setDefaultCenterX(model.getDefaultCenterX()); cachedData.setDefaultCenterY(model.getDefaultCenterY());