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

remove background moved to controller

parent 4a1890e9
......@@ -5,6 +5,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.TreeMap;
import javax.servlet.ServletContext;
......@@ -282,10 +283,15 @@ public class ProjectController extends BaseController {
@PreAuthorize("hasAuthority('IS_ADMIN')" +
"or hasAuthority('IS_CURATOR') and hasAuthority('WRITE_PROJECT:' + #projectId)")
@DeleteMapping(value = "/{projectId}/backgrounds/{backgroundId}")
public Map<String, Object> removeBackground(
public Object removeBackground(
@PathVariable(value = "projectId") String projectId,
@PathVariable(value = "backgroundId") Integer backgroundId) throws QueryException, IOException {
return projectController.removeBackground(projectId, backgroundId);
ProjectBackground projectBackground = projectController.getBackgroundById(projectId, backgroundId);
if (projectBackground == null) {
throw new ObjectNotFoundException("Background does not exist");
}
projectService.removeBackground(projectBackground);
return new TreeMap<>();
}
static class BackgroundDTO {
......@@ -334,7 +340,7 @@ public class ProjectController extends BaseController {
background.setCreator(user);
}
projectService.updateProject(background.getProject());
return getBackgroundById(projectId, backgroundId);
}
......
......@@ -593,17 +593,4 @@ public class ProjectRestImpl extends BaseRestImpl {
}
throw new ObjectNotFoundException("Background does not exist");
}
public Map<String, Object> removeBackground(String projectId, Integer backgroundId) throws ObjectNotFoundException {
Project project = getProjectByProjectId(projectId);
for (ProjectBackground projectBackground : project.getProjectBackgrounds()) {
if (projectBackground.getId() == backgroundId) {
project.removeProjectBackground(projectBackground);
projectDao.update(project);
return okStatus();
}
}
throw new ObjectNotFoundException("Background does not exist");
}
}
......@@ -1321,4 +1321,10 @@ public class ProjectService implements IProjectService {
}
return result;
}
@Override
public void removeBackground(ProjectBackground projectBackground) {
projectBackgroundDao.delete(projectBackground);
}
}
......@@ -5,6 +5,7 @@ import java.util.List;
import org.primefaces.model.TreeNode;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.model.user.UserAnnotationSchema;
import lcsb.mapviewer.services.utils.CreateProjectParams;
......@@ -110,4 +111,6 @@ public interface IProjectService {
void updateProject(Project project);
UserAnnotationSchema prepareUserAnnotationSchema(User user);
void removeBackground(ProjectBackground projectBackground);
}
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