Skip to content
Snippets Groups Projects
Commit a20361dd authored by Piotr Gawron's avatar Piotr Gawron
Browse files

every dataOverlay is connected to not empty project

parent 92591d63
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!497Resolve "overlays should be defined per project not per map"
Pipeline #7325 failed
...@@ -13,6 +13,7 @@ import org.apache.log4j.Logger; ...@@ -13,6 +13,7 @@ import org.apache.log4j.Logger;
import lcsb.mapviewer.converter.zip.ImageZipEntryFile; import lcsb.mapviewer.converter.zip.ImageZipEntryFile;
import lcsb.mapviewer.converter.zip.ZipEntryFile; import lcsb.mapviewer.converter.zip.ZipEntryFile;
import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
public class ProjectFactory { public class ProjectFactory {
...@@ -42,6 +43,13 @@ public class ProjectFactory { ...@@ -42,6 +43,13 @@ public class ProjectFactory {
models.addAll(model.getSubmodels()); models.addAll(model.getSubmodels());
project.addModel(model); project.addModel(model);
for (Model m: models) {
for (Layout layout: m.getLayouts()) {
layout.setProject(project);
}
}
ZipFile zipFile = params.getZipFile(); ZipFile zipFile = params.getZipFile();
Enumeration<? extends ZipEntry> entries; Enumeration<? extends ZipEntry> entries;
......
...@@ -23,6 +23,7 @@ import org.hibernate.annotations.Cascade; ...@@ -23,6 +23,7 @@ import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType; import org.hibernate.annotations.CascadeType;
import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.cache.UploadedFileEntry; import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.model.ModelData;
...@@ -110,6 +111,12 @@ public class Layout implements Serializable { ...@@ -110,6 +111,12 @@ public class Layout implements Serializable {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
private ModelData model; private ModelData model;
/**
* Project to which this data overlay is assigned.
*/
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private Project project;
/** /**
* Who created the layout. * Who created the layout.
*/ */
...@@ -498,4 +505,12 @@ public class Layout implements Serializable { ...@@ -498,4 +505,12 @@ public class Layout implements Serializable {
this.googleLicenseConsent = googleLicenseConsent; this.googleLicenseConsent = googleLicenseConsent;
} }
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
} }
...@@ -355,6 +355,9 @@ public class ModelData implements Serializable { ...@@ -355,6 +355,9 @@ public class ModelData implements Serializable {
public void addLayout(Layout layout) { public void addLayout(Layout layout) {
layouts.add(layout); layouts.add(layout);
layout.setModel(this); layout.setModel(this);
if (project != null) {
layout.setProject(project);
}
} }
/** /**
...@@ -704,6 +707,9 @@ public class ModelData implements Serializable { ...@@ -704,6 +707,9 @@ public class ModelData implements Serializable {
public void addLayout(int index, Layout layout) { public void addLayout(int index, Layout layout) {
layouts.add(index, layout); layouts.add(index, layout);
layout.setModel(this); layout.setModel(this);
if (project != null) {
layout.setProject(project);
}
} }
public Double getDefaultCenterX() { public Double getDefaultCenterX() {
......
...@@ -562,8 +562,7 @@ public class ModelFullIndexed implements Model { ...@@ -562,8 +562,7 @@ public class ModelFullIndexed implements Model {
@Override @Override
public void addLayout(int index, Layout layout) { public void addLayout(int index, Layout layout) {
this.modelData.getLayouts().add(index, layout); this.modelData.addLayout(index, layout);
layout.setModel(this);
} }
@Override @Override
......
alter table layout_table add column project_id integer;
update layout_table set project_id = (select project_id from model_data_table where model_data_table.id = layout_table.model_id);
update layout_table child set project_id = (select project_id from model_data_table where model_data_table.id = (select model_id from layout_table parent where child.parent_layout_id = parent.id)) where child.parent_layout_id is not null;
-- just in case we have some artifacts in database
delete from layout_table where project_id is null;
-- and now we can add foreign key
ALTER TABLE layout_table ADD CONSTRAINT layout_table_project FOREIGN KEY (project_id)
REFERENCES public.project_table (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
...@@ -384,14 +384,14 @@ public class ModelDaoTest extends PersistTestFunctions { ...@@ -384,14 +384,14 @@ public class ModelDaoTest extends PersistTestFunctions {
@Test @Test
public void testLayoutsInModel() throws Exception { public void testLayoutsInModel() throws Exception {
try { try {
Project project = new Project("test_porject_id");
Model model = createModel(); Model model = createModel();
project.addModel(model);
Layout layout = new Layout(); Layout layout = new Layout();
layout.setDirectory("tmp"); layout.setDirectory("tmp");
layout.setTitle("temporary name"); layout.setTitle("temporary name");
model.addLayout(layout); model.addLayout(layout);
Project project = new Project("test_porject_id");
project.addModel(model);
projectDao.add(project); projectDao.add(project);
modelDao.evict(model); modelDao.evict(model);
......
...@@ -443,6 +443,7 @@ public class LayoutService implements ILayoutService { ...@@ -443,6 +443,7 @@ public class LayoutService implements ILayoutService {
layout.setStatus(LayoutStatus.OK); layout.setStatus(LayoutStatus.OK);
layout.setProgress(0.0); layout.setProgress(0.0);
connection.getSubmodel().getModel().addLayout(layout); connection.getSubmodel().getModel().addLayout(layout);
layout.setProject(params.getModel().getProject());
layout.setCreator(params.getUser()); layout.setCreator(params.getUser());
layout.setPublicLayout(false); layout.setPublicLayout(false);
topLayout.addLayout(layout); topLayout.addLayout(layout);
......
...@@ -636,6 +636,7 @@ public class ProjectService implements IProjectService { ...@@ -636,6 +636,7 @@ public class ProjectService implements IProjectService {
semanticOverlay.setProgress(0.0); semanticOverlay.setProgress(0.0);
semanticOverlay.setHierarchicalView(buildInLayout.isNested()); semanticOverlay.setHierarchicalView(buildInLayout.isNested());
semanticOverlay.setHierarchyViewLevel(i); semanticOverlay.setHierarchyViewLevel(i);
semanticOverlay.setProject(topModel.getProject());
semanticLevelOverlays.add(semanticOverlay); semanticLevelOverlays.add(semanticOverlay);
topModel.addLayout(1, semanticOverlay); topModel.addLayout(1, semanticOverlay);
} }
...@@ -648,6 +649,7 @@ public class ProjectService implements IProjectService { ...@@ -648,6 +649,7 @@ public class ProjectService implements IProjectService {
layout.setHierarchicalView(buildInLayout.isNested()); layout.setHierarchicalView(buildInLayout.isNested());
layout.setParentLayout(topLayout); layout.setParentLayout(topLayout);
connection.getSubmodel().addLayout(0, layout); connection.getSubmodel().addLayout(0, layout);
layout.setProject(topModel.getProject());
connection.getSubmodel().setZoomLevels(generator.computeZoomLevels(connection.getSubmodel().getModel())); connection.getSubmodel().setZoomLevels(generator.computeZoomLevels(connection.getSubmodel().getModel()));
connection.getSubmodel().setTileSize(MapGenerator.TILE_SIZE); connection.getSubmodel().setTileSize(MapGenerator.TILE_SIZE);
...@@ -661,13 +663,16 @@ public class ProjectService implements IProjectService { ...@@ -661,13 +663,16 @@ public class ProjectService implements IProjectService {
semanticOverlay.setHierarchicalView(buildInLayout.isNested()); semanticOverlay.setHierarchicalView(buildInLayout.isNested());
semanticOverlay.setParentLayout(semanticLevelOverlays.get(i)); semanticOverlay.setParentLayout(semanticLevelOverlays.get(i));
semanticOverlay.setHierarchyViewLevel(i); semanticOverlay.setHierarchyViewLevel(i);
semanticOverlay.setProject(topModel.getProject());
connection.getSubmodel().addLayout(1, semanticOverlay); connection.getSubmodel().addLayout(1, semanticOverlay);
} }
} }
submodelId++; submodelId++;
} }
} }
projectDao.update(project);
if (params.isUpdateAnnotations()) { if (params.isUpdateAnnotations()) {
Map<Class<?>, List<ElementAnnotator>> annotators = null; Map<Class<?>, List<ElementAnnotator>> annotators = null;
if (params.getAnnotatorsMap() != null) { if (params.getAnnotatorsMap() != null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment