Commit 68ef09bc authored by Piotr Gawron's avatar Piotr Gawron
Browse files

get background by id moved to controller

parent b4c9eaf3
......@@ -277,7 +277,11 @@ public class ProjectController extends BaseController {
public ProjectBackground getBackgroundById(
@PathVariable(value = "projectId") String projectId,
@PathVariable(value = "backgroundId") Integer backgroundId) throws QueryException {
return projectController.getBackgroundById(projectId, backgroundId);
ProjectBackground background = projectService.getBackgroundById(projectId, backgroundId, true);
if (background == null) {
throw new ObjectNotFoundException("Background does not exist");
}
return background;
}
@PreAuthorize("hasAuthority('IS_ADMIN')" +
......@@ -286,7 +290,7 @@ public class ProjectController extends BaseController {
public Object removeBackground(
@PathVariable(value = "projectId") String projectId,
@PathVariable(value = "backgroundId") Integer backgroundId) throws QueryException, IOException {
ProjectBackground projectBackground = projectController.getBackgroundById(projectId, backgroundId);
ProjectBackground projectBackground = getBackgroundById(projectId, backgroundId);
if (projectBackground == null) {
throw new ObjectNotFoundException("Background does not exist");
}
......@@ -339,7 +343,7 @@ public class ProjectController extends BaseController {
}
background.setCreator(user);
}
projectService.updateProject(background.getProject());
projectService.updateBackground(background);
return getBackgroundById(projectId, backgroundId);
}
......
......@@ -61,10 +61,7 @@ import lcsb.mapviewer.services.utils.CreateProjectParams;
public class ProjectRestImpl extends BaseRestImpl {
public static enum ZipEntryFileType {
MAP,
OVERLAY,
IMAGE,
GLYPH;
MAP, OVERLAY, IMAGE, GLYPH;
public static ZipEntryFileType getType(String entryType) {
for (ZipEntryFileType type : ZipEntryFileType.values()) {
......@@ -243,36 +240,36 @@ public class ProjectRestImpl extends BaseRestImpl {
throw new QueryException("Unknown type for zip entry: zip-entries[" + fileIndex + "]");
}
switch (type) {
case MAP:
String submodelTypeKey = "zip-entries[" + fileIndex + "][_data][type][id]";
String rootKey = "zip-entries[" + fileIndex + "][_data][root]";
String mappingKey = "zip-entries[" + fileIndex + "][_data][mapping]";
String mapTypeString = getStringValue(data.get(submodelTypeKey), SubmodelType.UNKNOWN.name());
SubmodelType mapType = SubmodelType.valueOf(mapTypeString);
name = (String) data.get("zip-entries[" + fileIndex + "][_data][name]").get(0);
Boolean root = getBoolValue(data.get(rootKey), false);
Boolean mapping = getBoolValue(data.get(mappingKey), false);
entry = new ModelZipEntryFile(filename, name, root, mapping, mapType);
break;
case OVERLAY:
name = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][name]");
String description = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][description]");
if (name == null || name.trim().isEmpty()) {
throw new QueryException("zip-entries[" + fileIndex + "][_data][name] cannot be empty");
}
entry = new LayoutZipEntryFile(filename, name, description);
break;
case IMAGE:
entry = new ImageZipEntryFile(filename);
break;
case GLYPH:
entry = new GlyphZipEntryFile(filename);
break;
default:
throw new QueryException("Unknown entry type: " + entryType);
case MAP:
String submodelTypeKey = "zip-entries[" + fileIndex + "][_data][type][id]";
String rootKey = "zip-entries[" + fileIndex + "][_data][root]";
String mappingKey = "zip-entries[" + fileIndex + "][_data][mapping]";
String mapTypeString = getStringValue(data.get(submodelTypeKey), SubmodelType.UNKNOWN.name());
SubmodelType mapType = SubmodelType.valueOf(mapTypeString);
name = (String) data.get("zip-entries[" + fileIndex + "][_data][name]").get(0);
Boolean root = getBoolValue(data.get(rootKey), false);
Boolean mapping = getBoolValue(data.get(mappingKey), false);
entry = new ModelZipEntryFile(filename, name, root, mapping, mapType);
break;
case OVERLAY:
name = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][name]");
String description = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][description]");
if (name == null || name.trim().isEmpty()) {
throw new QueryException("zip-entries[" + fileIndex + "][_data][name] cannot be empty");
}
entry = new LayoutZipEntryFile(filename, name, description);
break;
case IMAGE:
entry = new ImageZipEntryFile(filename);
break;
case GLYPH:
entry = new GlyphZipEntryFile(filename);
break;
default:
throw new QueryException("Unknown entry type: " + entryType);
}
fileIndex++;
result.add(entry);
......@@ -533,14 +530,8 @@ public class ProjectRestImpl extends BaseRestImpl {
}
private enum LogSortColumn {
ID("id"),
LEVEL("level"),
TYPE("type"),
OBJECT_IDENTIFIER("objectIdentifier"),
OBJECT_CLASS("objectClass"),
MAP_NAME("mapName"),
SOURCE("source"),
CONTENT("content");
ID("id"), LEVEL("level"), TYPE("type"), OBJECT_IDENTIFIER("objectIdentifier"), OBJECT_CLASS("objectClass"), MAP_NAME("mapName"), SOURCE("source"), CONTENT(
"content");
private String commonName;
......@@ -583,14 +574,4 @@ public class ProjectRestImpl extends BaseRestImpl {
return result;
}
public ProjectBackground getBackgroundById(String projectId, Integer backgroundId) throws ObjectNotFoundException {
List<ProjectBackground> backgrounds = getProjectByProjectId(projectId).getProjectBackgrounds();
for (ProjectBackground projectBackground : backgrounds) {
if (Objects.equals(projectBackground.getId(), backgroundId)) {
Hibernate.initialize(projectBackground.getProjectBackgroundImageLayer());
return projectBackground;
}
}
throw new ObjectNotFoundException("Background does not exist");
}
}
......@@ -12,6 +12,7 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
......@@ -1302,7 +1303,7 @@ public class ProjectService implements IProjectService {
public Project getProjectByProjectId(String projectId, boolean initializeLazy) {
Project result = getProjectByProjectId(projectId);
if (result != null && initializeLazy) {
for (ModelData model: result.getModels()) {
for (ModelData model : result.getModels()) {
Hibernate.initialize(model);
}
Hibernate.initialize(result.getLogEntries());
......@@ -1314,7 +1315,7 @@ public class ProjectService implements IProjectService {
public List<Project> getAllProjects(boolean initializeLazy) {
List<Project> result = getAllProjects();
for (Project project : result) {
for (ModelData model: project.getModels()) {
for (ModelData model : project.getModels()) {
Hibernate.initialize(model);
}
Hibernate.initialize(project.getLogEntries());
......@@ -1325,6 +1326,26 @@ public class ProjectService implements IProjectService {
@Override
public void removeBackground(ProjectBackground projectBackground) {
projectBackgroundDao.delete(projectBackground);
}
@Override
public ProjectBackground getBackgroundById(String projectId, Integer backgroundId, boolean initializeLazy) {
for (ProjectBackground projectBackground : projectBackgroundDao.getProjectBackgroundsByProject(projectId)) {
if (Objects.equals(projectBackground.getId(), backgroundId)) {
if (initializeLazy) {
Hibernate.initialize(projectBackground.getProjectBackgroundImageLayer());
Hibernate.initialize(projectBackground.getProject());
}
return projectBackground;
}
}
return null;
}
@Override
public void updateBackground(ProjectBackground background) {
projectBackgroundDao.update(background);
}
}
......@@ -113,4 +113,8 @@ public interface IProjectService {
UserAnnotationSchema prepareUserAnnotationSchema(User user);
void removeBackground(ProjectBackground projectBackground);
ProjectBackground getBackgroundById(String projectId, Integer backgroundId, boolean b);
void updateBackground(ProjectBackground background);
}
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