Commit df041ebc authored by Piotr Gawron's avatar Piotr Gawron
Browse files

remove project moved to controller

parent b06a07d8
......@@ -45,6 +45,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.api.OperationNotAllowedException;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.Converter;
......@@ -56,10 +57,12 @@ import lcsb.mapviewer.model.graphics.MapCanvasType;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.ObjectExistsException;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import lcsb.mapviewer.services.interfaces.IElementService;
import lcsb.mapviewer.services.interfaces.IFileService;
import lcsb.mapviewer.services.interfaces.IMeshService;
......@@ -78,6 +81,7 @@ public class ProjectController extends BaseController {
private ServletContext context;
private ProjectRestImpl projectController;
private IProjectService projectService;
private IConfigurationService configurationService;
private IModelService modelService;
private IElementService elementService;
private IReactionService reactionService;
......@@ -91,7 +95,7 @@ public class ProjectController extends BaseController {
@Autowired
public ProjectController(ServletContext context, ProjectRestImpl projectController, IUserService userService, IProjectService projectService,
IMeshService meshService, List<Converter> modelConverters, IFileService fileService, IElementService elementService, IReactionService reactionService,
IModelService modelService) {
IModelService modelService, IConfigurationService configurationService) {
this.context = context;
this.projectController = projectController;
this.userService = userService;
......@@ -102,6 +106,7 @@ public class ProjectController extends BaseController {
this.elementService = elementService;
this.modelService = modelService;
this.reactionService = reactionService;
this.configurationService = configurationService;
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......@@ -424,12 +429,18 @@ public class ProjectController extends BaseController {
@DeleteMapping(value = "/{projectId:.+}")
public Project removeProject(@PathVariable(value = "projectId") String projectId)
throws QueryException {
Project response = projectController.removeProject(projectId, context.getRealPath("/"));
String path = context.getRealPath("/");
if (configurationService.getConfigurationValue(ConfigurationElementType.DEFAULT_MAP).equals(projectId)) {
throw new OperationNotAllowedException("You cannot remove default map");
}
Project project = getProject(projectId);
projectService.removeProject(project, path, true);
userService.revokeObjectDomainPrivilegesForAllUsers(PrivilegeType.WRITE_PROJECT, projectId);
userService.revokeObjectDomainPrivilegesForAllUsers(PrivilegeType.READ_PROJECT, projectId);
return response;
return project;
}
@PostFilter("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + filterObject['projectId'])")
......
......@@ -12,11 +12,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.OperationNotAllowedException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.persist.dao.map.species.ElementProperty;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
......@@ -28,13 +26,10 @@ import lcsb.mapviewer.services.interfaces.IReactionService;
public class ProjectRestImpl extends BaseRestImpl {
private IElementService elementService;
private IReactionService reactionService;
public ProjectRestImpl(
IElementService elementService,
IReactionService reactionService) {
IElementService elementService) {
this.elementService = elementService;
this.reactionService = reactionService;
}
public Project getProject(String projectId) throws ObjectNotFoundException {
......@@ -49,16 +44,6 @@ public class ProjectRestImpl extends BaseRestImpl {
return project;
}
public Project removeProject(String projectId, String path) throws QueryException {
Project project = getProjectByProjectId(projectId);
if (getConfigurationService().getConfigurationValue(ConfigurationElementType.DEFAULT_MAP)
.equals(project.getProjectId())) {
throw new OperationNotAllowedException("You cannot remove default map");
}
getProjectService().removeProject(project, path, true);
return getProject(projectId);
}
public List<Map<String, Object>> getSubmapConnections(String projectId) throws QueryException {
Project project = getProjectByProjectId(projectId);
Map<ElementProperty, List<? extends Object>> properties = new HashMap<>();
......
......@@ -52,21 +52,6 @@ public class ProjectRestImplTest extends RestTestFunctions {
projectRest = _projectRest;
}
@Test(expected = ObjectNotFoundException.class)
public void testRemoveNonExistentProject() throws Exception {
projectRest.removeProject("blabla", null);
}
@Test
public void testRemoveProject() throws Exception {
String projectId = "test";
Project project = new Project();
project.setProjectId(projectId);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
projectRest.removeProject(projectId, null);
}
@Test(expected = ObjectNotFoundException.class)
public void testGetInvalidMetaData() throws Exception {
projectRest.getProject("unknown_model_id");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment