diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java index 0b38db5eebaf53003688e31fe21e0612c9e2900a..6b2b55b27bd43158620dd883ade602832c65dc5b 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/BaseRestImpl.java @@ -46,6 +46,7 @@ import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.services.SecurityException; +import lcsb.mapviewer.services.interfaces.IConfigurationService; import lcsb.mapviewer.services.interfaces.IModelService; import lcsb.mapviewer.services.interfaces.IProjectService; import lcsb.mapviewer.services.interfaces.IUserService; @@ -68,6 +69,9 @@ public abstract class BaseRestImpl { @Autowired private IUserService userService; + @Autowired + private IConfigurationService configurationService; + @Autowired private MiriamConnector miriamConnector; @@ -375,4 +379,12 @@ public abstract class BaseRestImpl { } } + public IConfigurationService getConfigurationService() { + return configurationService; + } + + public void setConfigurationService(IConfigurationService configurationService) { + this.configurationService = configurationService; + } + } diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java index 186bd31e2c0900d7f53e84e4f387af0d7d0a1933..f7201f9c88f8ac79c7d04cf054f8ab66d01d69dc 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/ProjectRestImpl.java @@ -24,7 +24,6 @@ import java.util.TreeMap; import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; -import org.primefaces.model.map.LatLng; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.MultiValueMap; @@ -73,6 +72,7 @@ import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.SubmodelType; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.species.Element; +import lcsb.mapviewer.model.user.ConfigurationElementType; import lcsb.mapviewer.model.user.PrivilegeType; import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.persist.dao.ProjectDao; @@ -362,11 +362,11 @@ public class ProjectRestImpl extends BaseRestImpl { List<Point2D> points = new ArrayList<>(); for (String string : stringPointArray) { - if (!string.trim().equals("")) { - double x = Double.valueOf(string.split(",")[0]); - double y= Double.valueOf(string.split(",")[1]); - points.add(new Point2D.Double(x, y)); - } + if (!string.trim().equals("")) { + double x = Double.valueOf(string.split(",")[0]); + double y = Double.valueOf(string.split(",")[1]); + points.add(new Point2D.Double(x, y)); + } } if (points.size() <= 2) { @@ -375,13 +375,13 @@ public class ProjectRestImpl extends BaseRestImpl { points.add(new Point2D.Double(colorModel.getWidth(), 0)); points.add(new Point2D.Double(colorModel.getWidth(), colorModel.getHeight())); points.add(new Point2D.Double(0, colorModel.getHeight())); - } + } Path2D polygon = new Path2D.Double(); polygon.moveTo(points.get(0).getX(), points.get(0).getY()); for (int i = 1; i < points.size(); i++) { - Point2D point = points.get(i); - polygon.lineTo(point.getX(), point.getY()); + Point2D point = points.get(i); + polygon.lineTo(point.getX(), point.getY()); } polygon.closePath(); return polygon; @@ -736,8 +736,11 @@ public class ProjectRestImpl extends BaseRestImpl { } public Map<String, Object> removeProject(String token, String projectId, String path) - throws ObjectNotFoundException, SecurityException { + throws SecurityException, QueryException { Project project = getProjectService().getProjectByProjectId(projectId, token); + if (getConfigurationService().getConfigurationValue(ConfigurationElementType.DEFAULT_MAP).equals(project.getProjectId())) { + throw new QueryException("You cannot remove default map"); + } getProjectService().removeProject(project, path, true, token); return getProject(projectId, token); }