Commit 90b945e6 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

change in public overlays is reflected in the API responses immediatelly

parent 2156f4ee
Pipeline #2625 passed with stage
in 40 seconds
package lcsb.mapviewer.persist.dao.map;
import java.util.List;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.BaseDao;
import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
/**
* Data access object for {@link Layout} class.
*
* @author Piotr Gawron
*
*/
public class LayoutDao extends BaseDao<Layout> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(LayoutDao.class);
/**
* Default constructor.
*/
public LayoutDao() {
super(Layout.class);
}
/**
* Lists layouts for the model.
*
* @param model
* for this model layouts will be listed
* @return list of layouts for the model
*/
public List<Layout> getLayoutsByModel(Model model) {
List<Layout> layouts = getElementsByParameter("model_iddb", model.getId());
// for (Layout layout : layouts) {
// refresh(layout);
// }
return layouts;
}
/**
* Return number of layouts created by the user.
*
* @param user
* the user
* @return number of layouts created by the user
*/
public long getCountByUser(User user) {
Criteria crit = getSession().createCriteria(this.getClazz());
crit.setProjection(Projections.rowCount());
crit.add(Restrictions.eq("creator", user));
crit.createAlias("model", "m");
crit.add(Restrictions.sizeLe("m.parentModels", 0));
return (Long) crit.uniqueResult();
}
/**
* Returns layout identified by name and model.
*
* @param model
* model where the layouts lay on
* @param name
* name of the layout
* @return layout
*/
public Layout getLayoutByName(Model model, String name) {
List<Layout> layouts = getElementsByParameter("model_iddb", model.getId());
for (Layout layout : layouts) {
refresh(layout);
if (layout.getTitle().equals(name)) {
return layout;
}
}
return null;
}
}
package lcsb.mapviewer.persist.dao.map;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.BaseDao;
/**
* Data access object for {@link Layout} class.
*
* @author Piotr Gawron
*
*/
public class LayoutDao extends BaseDao<Layout> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(LayoutDao.class);
/**
* Default constructor.
*/
public LayoutDao() {
super(Layout.class);
}
/**
* Lists layouts for the model.
*
* @param model
* for this model layouts will be listed
* @return list of layouts for the model
*/
public List<Layout> getLayoutsByModel(Model model) {
List<Layout> layouts = getElementsByParameter("model_iddb", model.getId());
for (Layout layout : layouts) {
refresh(layout);
}
return layouts;
}
/**
* Return number of layouts created by the user.
*
* @param user
* the user
* @return number of layouts created by the user
*/
public long getCountByUser(User user) {
Criteria crit = getSession().createCriteria(this.getClazz());
crit.setProjection(Projections.rowCount());
crit.add(Restrictions.eq("creator", user));
crit.createAlias("model", "m");
crit.add(Restrictions.sizeLe("m.parentModels", 0));
return (Long) crit.uniqueResult();
}
/**
* Returns layout identified by name and model.
*
* @param model
* model where the layouts lay on
* @param name
* name of the layout
* @return layout
*/
public Layout getLayoutByName(Model model, String name) {
List<Layout> layouts = getElementsByParameter("model_iddb", model.getId());
for (Layout layout : layouts) {
refresh(layout);
if (layout.getTitle().equals(name)) {
return layout;
}
}
return null;
}
}
......@@ -569,7 +569,6 @@ public class ProjectRestImpl extends BaseRestImpl {
ZipEntryFile entry = null;
String entryType = (String) data.get("zip-entries[" + fileIndex + "][_type]").get(0);
String filename = (String) data.get("zip-entries[" + fileIndex + "][_filename]").get(0);
logger.debug(filename);
if ("MAP".equalsIgnoreCase(entryType)) {
String submodelTypeKey = "zip-entries[" + fileIndex + "][_data][type][id]";
String rootKey = "zip-entries[" + fileIndex + "][_data][root]";
......
package lcsb.mapviewer.api.projects.models;
import java.awt.geom.Point2D;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.primefaces.model.map.LatLng;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.model.ModelSubmodelConnection;
import lcsb.mapviewer.model.map.model.SubmodelType;
import lcsb.mapviewer.services.utils.gmap.CoordinationConverter;
import lcsb.mapviewer.services.view.LayoutView;
import lcsb.mapviewer.services.view.LayoutViewFactory;
public class ModelMetaData implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Version of the model.
*/
private String version;
/**
* Name of the model.
*/
private String name;
private Integer idObject;
/**
* Size in pixels of the single square tile (small image used for graphical
* representation).
*/
private Integer tileSize;
private Integer width;
private Integer height;
/**
* Minimum zoom level that should be allowed by the Google Maps API.
*/
private Integer minZoom;
/**
* Maximum zoom level that should be allowed by the Google Maps API.
*/
private Integer maxZoom;
private List<LayoutView> layouts = new ArrayList<>();
/**
* List of submodels in the model.
*/
private List<ModelMetaData> submodels = new ArrayList<>();
/**
* Where is the center of the map in latituted, longiude format.
*/
private LatLng centerLatLng;
/**
* Top-Left corner of the map (0,0) as a latLng coordinates.
*/
private LatLng topLeftLatLng;
/**
* Bottom-Right corner of the map (width,height) as a latLng coordinates.
*/
private LatLng bottomRightLatLng;
/**
* Type of the submodel.
*/
private SubmodelType submodelType = SubmodelType.UNKNOWN;
/**
* Default constructor.
*/
public ModelMetaData(Model model) {
this(model.getModelData());
}
public ModelMetaData(ModelData model) {
this.setName(model.getName());
this.setIdObject(model.getId());
this.setMinZoom(Configuration.MIN_ZOOM_LEVEL);
this.setMaxZoom(this.getMinZoom() + model.getZoomLevels());
this.setTileSize(model.getTileSize());
this.setWidth((int) (double) model.getWidth());
this.setHeight((int) (double) model.getHeight());
int size = Math.max(width, height);
CoordinationConverter cConverter = new CoordinationConverter(model);
this.setCenterLatLng(cConverter.toLatLng(new Point2D.Double(size / 2, size / 2)));
this.setBottomRightLatLng(cConverter.toLatLng(new Point2D.Double(model.getWidth(), model.getHeight())));
this.setTopLeftLatLng(cConverter.toLatLng(new Point2D.Double(0, 0)));
List<ModelMetaData> submodels = new ArrayList<>();
for (ModelSubmodelConnection connection : model.getSubmodels()) {
ModelMetaData submodelData = new ModelMetaData(connection.getSubmodel());
submodelData.setSubmodelType(connection.getType());
submodels.add(submodelData);
}
LayoutViewFactory factory = new LayoutViewFactory();
for (Layout layout : model.getLayouts()) {
if (layout.isPublicLayout()) {
layouts.add(factory.create(layout));
}
}
this.setSubmodels(submodels);
}
protected ModelMetaData() {
}
/**
* @return the version
* @see #version
*/
public String getVersion() {
return version;
}
/**
* @param version
* the version to set
* @see #version
*/
public void setVersion(String version) {
this.version = version;
}
/**
* @return the tileSize
* @see #tileSize
*/
public Integer getTileSize() {
return tileSize;
}
/**
* @param tileSize
* the tileSize to set
* @see #tileSize
*/
public void setTileSize(Integer tileSize) {
this.tileSize = tileSize;
}
/**
* @return the minZoom
* @see #minZoom
*/
public Integer getMinZoom() {
return minZoom;
}
/**
* @param minZoom
* the minZoom to set
* @see #minZoom
*/
public void setMinZoom(Integer minZoom) {
this.minZoom = minZoom;
}
/**
* @return the maxZoom
* @see #maxZoom
*/
public Integer getMaxZoom() {
return maxZoom;
}
/**
* @param maxZoom
* the maxZoom to set
* @see #maxZoom
*/
public void setMaxZoom(Integer maxZoom) {
this.maxZoom = maxZoom;
}
/**
* @return the centerLatLng
* @see #centerLatLng
*/
public LatLng getCenterLatLng() {
return centerLatLng;
}
/**
* @param centerLatLng
* the centerLatLng to set
* @see #centerLatLng
*/
public void setCenterLatLng(LatLng centerLatLng) {
this.centerLatLng = centerLatLng;
}
/**
* @return the name
* @see #name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
* @see #name
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the topLeftLatLng
* @see #topLeftLatLng
*/
public LatLng getTopLeftLatLng() {
return topLeftLatLng;
}
/**
* @param topLeftLatLng
* the topLeftLatLng to set
* @see #topLeftLatLng
*/
public void setTopLeftLatLng(LatLng topLeftLatLng) {
this.topLeftLatLng = topLeftLatLng;
}
/**
* @return the bottomRightLatLng
* @see #bottomRightLatLng
*/
public LatLng getBottomRightLatLng() {
return bottomRightLatLng;
}
/**
* @param bottomRightLatLng
* the bottomRightLatLng to set
* @see #bottomRightLatLng
*/
public void setBottomRightLatLng(LatLng bottomRightLatLng) {
this.bottomRightLatLng = bottomRightLatLng;
}
/**
* @return the width
* @see #width
*/
public Integer getWidth() {
return width;
}
/**
* @param width
* the width to set
* @see #width
*/
public void setWidth(Integer width) {
this.width = width;
}
/**
* @return the height
* @see #height
*/
public Integer getHeight() {
return height;
}
/**
* @param height
* the height to set
* @see #height
*/
public void setHeight(Integer height) {
this.height = height;
}
/**
* @return the submodels
* @see #submodels
*/
public List<ModelMetaData> getSubmodels() {
return submodels;
}
/**
* @param submodels
* the submodels to set
* @see #submodels
*/
public void setSubmodels(List<ModelMetaData> submodels) {
this.submodels = submodels;
}
/**
* @return the layouts
* @see #layouts
*/
public List<LayoutView> getLayouts() {
return layouts;
}
/**
* @param layouts
* the layouts to set
* @see #layouts
*/
public void setLayouts(List<LayoutView> layouts) {
this.layouts = layouts;
}
/**
* @return the idObject
* @see #idObject
*/
public Integer getIdObject() {
return idObject;
}
/**
* @param idObject
* the idObject to set
* @see #idObject
*/
public void setIdObject(Integer idObject) {
this.idObject = idObject;
}
/**
* @return the submodelType
* @see #submodelType
*/
public SubmodelType getSubmodelType() {
return submodelType;
}
/**
* @param submodelType
* the submodelType to set
* @see #submodelType
*/
public void setSubmodelType(SubmodelType submodelType) {
this.submodelType = submodelType;
}
}
package lcsb.mapviewer.api.projects.models;
import java.awt.geom.Point2D;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.primefaces.model.map.LatLng;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.model.ModelSubmodelConnection;
import lcsb.mapviewer.model.map.model.SubmodelType;
import lcsb.mapviewer.services.utils.gmap.CoordinationConverter;
import lcsb.mapviewer.services.view.LayoutView;
import lcsb.mapviewer.services.view.LayoutViewFactory;
public class ModelMetaData implements Serializable {