From 6853322369ad578f47c7c451cc88378c97e9110c Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 21 Nov 2017 09:32:39 +0100 Subject: [PATCH] default field for the data overlay added --- .../mapviewer/model/map/layout/Layout.java | 912 +++++++++--------- persist/src/db/12.0.0/fix_db_20171121.sql | 2 + .../projects/overlays/OverlayRestImpl.java | 654 ++++++------- .../mapviewer/services/view/LayoutView.java | 532 +++++----- .../services/view/LayoutViewFactory.java | 177 ++-- 5 files changed, 1157 insertions(+), 1120 deletions(-) create mode 100644 persist/src/db/12.0.0/fix_db_20171121.sql diff --git a/model/src/main/java/lcsb/mapviewer/model/map/layout/Layout.java b/model/src/main/java/lcsb/mapviewer/model/map/layout/Layout.java index f919988d80..672b1feca4 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/layout/Layout.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/layout/Layout.java @@ -1,450 +1,462 @@ -package lcsb.mapviewer.model.map.layout; - -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.OneToOne; - -import org.apache.log4j.Logger; -import org.hibernate.annotations.Cascade; -import org.hibernate.annotations.CascadeType; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.cache.UploadedFileEntry; -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.map.model.ModelData; -import lcsb.mapviewer.model.user.User; - -/** - * This object represents type of visualization for the model. - * - * @author Piotr Gawron - * - */ -@Entity -public class Layout implements Serializable { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(Layout.class); - - /** - * Unique database identifier. - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "idDb", unique = true, nullable = false) - private int id; - - /** - * Directory where the images for this layout are stored. - */ - private String directory; - - /** - * Title of this layout. - */ - private String title; - - /** - * Is the layout publically available. - */ - private boolean publicLayout = false; - - /** - * Does the layout present data in hierarchical view. - */ - private boolean hierarchicalView = false; - - /** - * If overlay contain hierarchical view then it might be fixed on some - * specific level. This parameter defines the level at which it's fixed or - * contains null if it's general hierarchical view. - */ - private Integer hierarchyViewLevel; - - /** - * ModelData to which layout is assigend. - */ - @ManyToOne(fetch = FetchType.LAZY) - private ModelData model; - - /** - * Whou created the layout. - */ - @ManyToOne(fetch = FetchType.LAZY) - private User creator; - - /** - * Describes progress of layout uploading process. - */ - private LayoutStatus status = LayoutStatus.UNKNOWN; - - /** - * What is the progress. - */ - private double progress = 0.0; - - /** - * List of layouts for submodels. - */ - @Cascade({ CascadeType.ALL }) - @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentLayout", orphanRemoval = true) - private Set<Layout> layouts = new HashSet<Layout>(); - - /** - * If the layout is connected to a submap then this object determine layout of - * the super {@link lcsb.mapviewer.model.map.model.Model}. - */ - @ManyToOne(fetch = FetchType.LAZY) - private Layout parentLayout = null; - - /** - * Short description used for this layout. - */ - @Column(columnDefinition = "TEXT") - private String description; - - /** - * Here we store input file. - */ - @Cascade({ CascadeType.SAVE_UPDATE }) - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "file_entry_iddb") - private UploadedFileEntry inputData; - - /** - * Default constructor. - */ - public Layout() { - - } - - /** - * Constructor that initializes object with basic parameters. - * - * @param title - * title of the layout - * @param directory - * directory where the images are stored - * @param publicLayout - * is the layout publically available - */ - public Layout(String title, String directory, boolean publicLayout) { - this.title = title; - this.directory = directory; - this.publicLayout = publicLayout; - } - - /** - * Constructor that initializes object with the copy od the data from - * parameter. - * - * @param layout - * from this object the data will be initialized - */ - public Layout(Layout layout) { - this.directory = layout.getDirectory(); - this.description = layout.getDescription(); - this.title = layout.getTitle(); - this.publicLayout = layout.publicLayout; - this.status = layout.status; - this.progress = layout.progress; - this.hierarchicalView = layout.hierarchicalView; - if (layout.inputData != null) { - this.inputData = new UploadedFileEntry(layout.getInputData()); - } - this.hierarchyViewLevel = layout.hierarchyViewLevel; - - } - - /** - * Prepares a copy of layout. - * - * @return copy of layout - */ - public Layout copy() { - if (this.getClass() == Layout.class) { - return new Layout(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - - /** - * @return the hierarchicalView - * @see #hierarchicalView - */ - public boolean isHierarchicalView() { - return hierarchicalView; - } - - /** - * @param hierarchicalView - * the hierarchicalView to set - * @see #hierarchicalView - */ - public void setHierarchicalView(boolean hierarchicalView) { - this.hierarchicalView = hierarchicalView; - } - - /** - * @return the id - * @see #id - */ - public int getId() { - return id; - } - - /** - * @param id - * the id to set - * @see #id - */ - public void setId(int id) { - this.id = id; - } - - /** - * @return the directory - * @see #directory - */ - public String getDirectory() { - return directory; - } - - /** - * @param directory - * the directory to set - * @see #directory - */ - public void setDirectory(String directory) { - this.directory = directory; - } - - /** - * @return the title - * @see #title - */ - public String getTitle() { - return title; - } - - /** - * @param title - * the title to set - * @see #title - */ - public void setTitle(String title) { - this.title = title; - } - - /** - * @return the publicLayout - * @see #publicLayout - */ - public boolean isPublicLayout() { - return publicLayout; - } - - /** - * @param publicLayout - * the publicLayout to set - * @see #publicLayout - */ - public void setPublicLayout(boolean publicLayout) { - this.publicLayout = publicLayout; - } - - /** - * @return the model - * @see #model - */ - public ModelData getModel() { - return model; - } - - /** - * @param model - * the model to set - * @see #model - */ - public void setModel(ModelData model) { - this.model = model; - } - - /** - * @return the creator - * @see #creator - */ - public User getCreator() { - return creator; - } - - /** - * @param creator - * the creator to set - * @see #creator - */ - public void setCreator(User creator) { - this.creator = creator; - } - - /** - * @return the status - * @see #status - */ - public LayoutStatus getStatus() { - return status; - } - - /** - * @param status - * the status to set - * @see #status - */ - public void setStatus(LayoutStatus status) { - this.status = status; - } - - /** - * @return the progress - * @see #progress - */ - public double getProgress() { - return progress; - } - - /** - * @param progress - * the progress to set - * @see #progress - */ - public void setProgress(double progress) { - this.progress = progress; - } - - /** - * @return the description - * @see #description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - * @see #description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the layouts - * @see #layouts - */ - public Set<Layout> getLayouts() { - return layouts; - } - - /** - * @param layouts - * the layouts to set - * @see #layouts - */ - public void setLayouts(Set<Layout> layouts) { - this.layouts = layouts; - } - - /** - * @return the parentLayout - * @see #parentLayout - */ - public Layout getParentLayout() { - return parentLayout; - } - - /** - * @param parentLayout - * the parentLayout to set - * @see #parentLayout - */ - public void setParentLayout(Layout parentLayout) { - this.parentLayout = parentLayout; - } - - /** - * When this layout is connected to the top model in complex models then this - * method adds layout of a submodel. - * - * @param layout - * layout of a submodel - */ - public void addLayout(Layout layout) { - this.layouts.add(layout); - layout.setParentLayout(this); - } - - /** - * Sets {@link #model}. - * - * @param model - * new {@link #model} value - */ - public void setModel(Model model) { - setModel(model.getModelData()); - } - - /** - * @return the inputData - * @see #inputData - */ - public UploadedFileEntry getInputData() { - return inputData; - } - - /** - * @param inputData - * the inputData to set - * @see #inputData - */ - public void setInputData(UploadedFileEntry inputData) { - this.inputData = inputData; - } - - /** - * @return the hierarchyViewLevel - * @see #hierarchyViewLevel - */ - public Integer getHierarchyViewLevel() { - return hierarchyViewLevel; - } - - /** - * @param hierarchyViewLevel - * the hierarchyViewLevel to set - * @see #hierarchyViewLevel - */ - public void setHierarchyViewLevel(Integer hierarchyViewLevel) { - this.hierarchyViewLevel = hierarchyViewLevel; - } - -} +package lcsb.mapviewer.model.map.layout; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; + +import org.apache.log4j.Logger; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.cache.UploadedFileEntry; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelData; +import lcsb.mapviewer.model.user.User; + +/** + * This object represents type of visualization for the model. + * + * @author Piotr Gawron + * + */ +@Entity +public class Layout implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(Layout.class); + + /** + * Unique database identifier. + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "idDb", unique = true, nullable = false) + private int id; + + /** + * Directory where the images for this layout are stored. + */ + private String directory; + + /** + * Title of this layout. + */ + private String title; + + /** + * Is the layout publicly available. + */ + private boolean publicLayout = false; + + /** + * Is the overlay considered as default (should it be open on startup). + */ + private boolean defaultOverlay = false; + + /** + * Does the layout present data in hierarchical view. + */ + private boolean hierarchicalView = false; + + /** + * If overlay contain hierarchical view then it might be fixed on some specific + * level. This parameter defines the level at which it's fixed or contains null + * if it's general hierarchical view. + */ + private Integer hierarchyViewLevel; + + /** + * ModelData to which layout is assigned. + */ + @ManyToOne(fetch = FetchType.LAZY) + private ModelData model; + + /** + * Who created the layout. + */ + @ManyToOne(fetch = FetchType.LAZY) + private User creator; + + /** + * Describes progress of layout uploading process. + */ + private LayoutStatus status = LayoutStatus.UNKNOWN; + + /** + * What is the progress. + */ + private double progress = 0.0; + + /** + * List of layouts for submodels. + */ + @Cascade({ CascadeType.ALL }) + @OneToMany(fetch = FetchType.LAZY, mappedBy = "parentLayout", orphanRemoval = true) + private Set<Layout> layouts = new HashSet<Layout>(); + + /** + * If the layout is connected to a submap then this object determine layout of + * the super {@link lcsb.mapviewer.model.map.model.Model}. + */ + @ManyToOne(fetch = FetchType.LAZY) + private Layout parentLayout = null; + + /** + * Short description used for this layout. + */ + @Column(columnDefinition = "TEXT") + private String description; + + /** + * Here we store input file. + */ + @Cascade({ CascadeType.SAVE_UPDATE }) + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "file_entry_iddb") + private UploadedFileEntry inputData; + + /** + * Default constructor. + */ + public Layout() { + + } + + /** + * Constructor that initializes object with basic parameters. + * + * @param title + * title of the layout + * @param directory + * directory where the images are stored + * @param publicLayout + * is the layout publicly available + */ + public Layout(String title, String directory, boolean publicLayout) { + this.title = title; + this.directory = directory; + this.publicLayout = publicLayout; + } + + /** + * Constructor that initializes object with the copy of the data from parameter. + * + * @param layout + * from this object the data will be initialized + */ + public Layout(Layout layout) { + this.directory = layout.getDirectory(); + this.description = layout.getDescription(); + this.title = layout.getTitle(); + this.publicLayout = layout.publicLayout; + this.status = layout.status; + this.progress = layout.progress; + this.hierarchicalView = layout.hierarchicalView; + if (layout.inputData != null) { + this.inputData = new UploadedFileEntry(layout.getInputData()); + } + this.hierarchyViewLevel = layout.hierarchyViewLevel; + + } + + /** + * Prepares a copy of layout. + * + * @return copy of layout + */ + public Layout copy() { + if (this.getClass() == Layout.class) { + return new Layout(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + + /** + * @return the hierarchicalView + * @see #hierarchicalView + */ + public boolean isHierarchicalView() { + return hierarchicalView; + } + + /** + * @param hierarchicalView + * the hierarchicalView to set + * @see #hierarchicalView + */ + public void setHierarchicalView(boolean hierarchicalView) { + this.hierarchicalView = hierarchicalView; + } + + /** + * @return the id + * @see #id + */ + public int getId() { + return id; + } + + /** + * @param id + * the id to set + * @see #id + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the directory + * @see #directory + */ + public String getDirectory() { + return directory; + } + + /** + * @param directory + * the directory to set + * @see #directory + */ + public void setDirectory(String directory) { + this.directory = directory; + } + + /** + * @return the title + * @see #title + */ + public String getTitle() { + return title; + } + + /** + * @param title + * the title to set + * @see #title + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return the publicLayout + * @see #publicLayout + */ + public boolean isPublicLayout() { + return publicLayout; + } + + /** + * @param publicLayout + * the publicLayout to set + * @see #publicLayout + */ + public void setPublicLayout(boolean publicLayout) { + this.publicLayout = publicLayout; + } + + /** + * @return the model + * @see #model + */ + public ModelData getModel() { + return model; + } + + /** + * @param model + * the model to set + * @see #model + */ + public void setModel(ModelData model) { + this.model = model; + } + + /** + * @return the creator + * @see #creator + */ + public User getCreator() { + return creator; + } + + /** + * @param creator + * the creator to set + * @see #creator + */ + public void setCreator(User creator) { + this.creator = creator; + } + + /** + * @return the status + * @see #status + */ + public LayoutStatus getStatus() { + return status; + } + + /** + * @param status + * the status to set + * @see #status + */ + public void setStatus(LayoutStatus status) { + this.status = status; + } + + /** + * @return the progress + * @see #progress + */ + public double getProgress() { + return progress; + } + + /** + * @param progress + * the progress to set + * @see #progress + */ + public void setProgress(double progress) { + this.progress = progress; + } + + /** + * @return the description + * @see #description + */ + public String getDescription() { + return description; + } + + /** + * @param description + * the description to set + * @see #description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the layouts + * @see #layouts + */ + public Set<Layout> getLayouts() { + return layouts; + } + + /** + * @param layouts + * the layouts to set + * @see #layouts + */ + public void setLayouts(Set<Layout> layouts) { + this.layouts = layouts; + } + + /** + * @return the parentLayout + * @see #parentLayout + */ + public Layout getParentLayout() { + return parentLayout; + } + + /** + * @param parentLayout + * the parentLayout to set + * @see #parentLayout + */ + public void setParentLayout(Layout parentLayout) { + this.parentLayout = parentLayout; + } + + /** + * When this layout is connected to the top model in complex models then this + * method adds layout of a submodel. + * + * @param layout + * layout of a submodel + */ + public void addLayout(Layout layout) { + this.layouts.add(layout); + layout.setParentLayout(this); + } + + /** + * Sets {@link #model}. + * + * @param model + * new {@link #model} value + */ + public void setModel(Model model) { + setModel(model.getModelData()); + } + + /** + * @return the inputData + * @see #inputData + */ + public UploadedFileEntry getInputData() { + return inputData; + } + + /** + * @param inputData + * the inputData to set + * @see #inputData + */ + public void setInputData(UploadedFileEntry inputData) { + this.inputData = inputData; + } + + /** + * @return the hierarchyViewLevel + * @see #hierarchyViewLevel + */ + public Integer getHierarchyViewLevel() { + return hierarchyViewLevel; + } + + /** + * @param hierarchyViewLevel + * the hierarchyViewLevel to set + * @see #hierarchyViewLevel + */ + public void setHierarchyViewLevel(Integer hierarchyViewLevel) { + this.hierarchyViewLevel = hierarchyViewLevel; + } + + public boolean isDefaultOverlay() { + return defaultOverlay; + } + + public void setDefaultOverlay(boolean defaultOverlay) { + this.defaultOverlay = defaultOverlay; + } + +} diff --git a/persist/src/db/12.0.0/fix_db_20171121.sql b/persist/src/db/12.0.0/fix_db_20171121.sql new file mode 100644 index 0000000000..98a7685a7e --- /dev/null +++ b/persist/src/db/12.0.0/fix_db_20171121.sql @@ -0,0 +1,2 @@ +-- column which indicates that this overlay should be shown on startup +alter table layout add column defaultoverlay boolean default false; diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java index 767e2a174d..0b0d3f1137 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java @@ -1,324 +1,330 @@ -package lcsb.mapviewer.api.projects.overlays; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -import lcsb.mapviewer.api.BaseRestImpl; -import lcsb.mapviewer.api.ObjectNotFoundException; -import lcsb.mapviewer.api.QueryException; -import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.model.cache.FileEntry; -import lcsb.mapviewer.model.cache.UploadedFileEntry; -import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException; -import lcsb.mapviewer.model.map.layout.Layout; -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.user.PrivilegeType; -import lcsb.mapviewer.model.user.User; -import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao; -import lcsb.mapviewer.persist.dao.map.LayoutDao; -import lcsb.mapviewer.services.SecurityException; -import lcsb.mapviewer.services.interfaces.ILayoutService; -import lcsb.mapviewer.services.interfaces.ILayoutService.CreateLayoutParams; -import lcsb.mapviewer.services.search.data.ElementIdentifier.ElementIdentifierType; -import lcsb.mapviewer.services.search.layout.FullLayoutAliasView; -import lcsb.mapviewer.services.search.layout.FullLayoutReactionView; -import lcsb.mapviewer.services.search.layout.LightLayoutAliasView; -import lcsb.mapviewer.services.search.layout.LightLayoutReactionView; -import lcsb.mapviewer.services.utils.data.ColorSchemaType; -import lcsb.mapviewer.services.view.AuthenticationToken; -import lcsb.mapviewer.services.view.LayoutView; - -@Transactional(value = "txManager") -public class OverlayRestImpl extends BaseRestImpl { - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(OverlayRestImpl.class); - - @Autowired - private ILayoutService layoutService; - - @Autowired - private UploadedFileEntryDao uploadedFileEntryDao; - - @Autowired - private LayoutDao layoutDao; - - public List<LayoutView> getOverlayList(String token, String projectId, String creatorLogin, String publicOverlay) - throws SecurityException, QueryException { - AuthenticationToken authenticationToken = getUserService().getToken(token); - Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); - if (model == null) { - return new ArrayList<>(); - } - User creator = null; - if (creatorLogin != null && !creatorLogin.isEmpty()) { - creator = getUserService().getUserByLogin(creatorLogin); - if (creator == null) { - throw new ObjectNotFoundException("User with given id doesn't exist: " + creatorLogin); - } - } - Boolean publicData = null; - if (publicOverlay != null && !publicOverlay.isEmpty()) { - publicData = publicOverlay.equalsIgnoreCase("true"); - } - return layoutService.getCustomLayouts(model, token, publicData, creator); - } - - /** - * @return the layoutService - * @see #layoutService - */ - public ILayoutService getLayoutService() { - return layoutService; - } - - /** - * @param layoutService - * the layoutService to set - * @see #layoutService - */ - public void setLayoutService(ILayoutService layoutService) { - this.layoutService = layoutService; - } - - public List<Map<String, Object>> getOverlayElements(String token, String projectId, int overlayId, String columns) - throws QueryException, SecurityException { - List<Map<String, Object>> result = new ArrayList<>(); - AuthenticationToken authenticationToken = getUserService().getToken(token); - - Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); - if (model == null) { - throw new QueryException("Project with given id doesn't exist"); - } - List<LightLayoutAliasView> speciesList = layoutService.getAliasesForLayout(model, overlayId, authenticationToken); - for (LightLayoutAliasView lightLayoutAliasView : speciesList) { - Map<String, Object> element = new HashMap<>(); - element.put("type", ElementIdentifierType.ALIAS); - element.put("overlayContent", lightLayoutAliasView); - result.add(element); - } - - List<LightLayoutReactionView> reactions = layoutService.getReactionsForLayout(model, overlayId, - authenticationToken); - for (LightLayoutReactionView lightReactionView : reactions) { - Map<String, Object> element = new HashMap<>(); - element.put("type", ElementIdentifierType.REACTION); - element.put("overlayContent", lightReactionView); - result.add(element); - } - return result; - } - - public LayoutView getOverlayById(String token, String projectId, String overlayId) - throws SecurityException, QueryException { - AuthenticationToken authenticationToken = getUserService().getToken(token); - Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); - if (model == null) { - throw new QueryException("Project with given id doesn't exist"); - } - return layoutService.getLayoutById(Integer.valueOf(overlayId), authenticationToken); - } - - public FileEntry getOverlaySource(String token, String projectId, String overlayId) - throws SecurityException, QueryException { - AuthenticationToken authenticationToken = getUserService().getToken(token); - Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); - if (model == null) { - throw new QueryException("Project with given id doesn't exist"); - } - try { - Integer id = Integer.valueOf(overlayId); - Layout layout = layoutService.getLayoutDataById(id, authenticationToken); - if (layout == null) { - throw new QueryException("Invalid overlay id"); - } - // lazy initialization issue - layout.getInputData().getFileContent(); - return layout.getInputData(); - } catch (NumberFormatException e) { - throw new QueryException("Invalid overlay id"); - } - } - - public LayoutView updateOverlay(String token, String projectId, String overlayId, Map<String, Object> overlayData) - throws QueryException, SecurityException { - AuthenticationToken authenticationToken = getUserService().getToken(token); - if (overlayData == null) { - throw new QueryException("overlay field cannot be undefined"); - } - try { - Integer id = Integer.valueOf(overlayId); - Layout layout = layoutService.getLayoutDataById(id, authenticationToken); - if (layout == null) { - throw new ObjectNotFoundException("overlay doesn't exist"); - } - boolean isAdmin = getUserService().userHasPrivilege(authenticationToken, PrivilegeType.LAYOUT_MANAGEMENT, - layout.getModel().getProject()); - if (layout.isPublicLayout() && !isAdmin) { - throw new SecurityException("You cannot modify given overlay"); - } - for (String key : overlayData.keySet()) { - Object value = overlayData.get(key); - if (key.equalsIgnoreCase("description")) { - layout.setDescription((String) value); - } else if (key.equalsIgnoreCase("name")) { - layout.setTitle((String) value); - } else if (key.equalsIgnoreCase("publicOverlay")) { - if (value instanceof Boolean) { - layout.setPublicLayout((Boolean) value); - } else { - layout.setPublicLayout("true".equalsIgnoreCase((String) value)); - } - } else if (key.equalsIgnoreCase("creator")) { - if ("".equals(value)) { - layout.setCreator(null); - } else { - layout.setCreator(getUserService().getUserByLogin((String) value)); - } - } else { - throw new QueryException("Unknown parameter: " + key); - } - } - layoutDao.update(layout); - return layoutService.getLayoutById(Integer.valueOf(overlayId), authenticationToken); - } catch (NumberFormatException e) { - throw new ObjectNotFoundException("overlay doesn't exist"); - } - } - - public Map<String, Object> removeOverlay(String token, String projectId, String overlayId) - throws QueryException, SecurityException, IOException { - AuthenticationToken authenticationToken = getUserService().getToken(token); - Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); - if (model == null) { - throw new ObjectNotFoundException("Project with given id doesn't exist"); - } - try { - Integer id = Integer.valueOf(overlayId); - LayoutView layout = layoutService.getLayoutById(id, authenticationToken); - if (layout == null) { - throw new ObjectNotFoundException("Overlay doesn't exist"); - } - if (layoutService.userCanRemoveLayout(layout, authenticationToken)) { - layoutService.removeLayout(layout, null); - return okStatus(); - } else { - throw new SecurityException("You cannot remove given overlay"); - } - } catch (NumberFormatException e) { - throw new QueryException("Invalid overlay id: " + overlayId); - } - } - - /** - * @return the layoutDao - * @see #layoutDao - */ - public LayoutDao getLayoutDao() { - return layoutDao; - } - - /** - * @param layoutDao - * the layoutDao to set - * @see #layoutDao - */ - public void setLayoutDao(LayoutDao layoutDao) { - this.layoutDao = layoutDao; - } - - public LayoutView addOverlay(String token, String projectId, String name, String description, String content, - String fileId, String filename, String type) throws SecurityException, QueryException, IOException { - AuthenticationToken authenticationToken = getUserService().getToken(token); - User user = getUserService().getUserByToken(token); - if (Configuration.ANONYMOUS_LOGIN.equals(user.getLogin())) { - throw new SecurityException("You have no privileges to add overlay"); - } - Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); - if (model == null) { - throw new QueryException("Project with given id doesn't exist"); - } - ColorSchemaType colorSchemaType = ColorSchemaType.GENERIC; - if (type != null && !type.equals("")) { - try { - colorSchemaType = ColorSchemaType.valueOf(type); - } catch (IllegalArgumentException e) { - throw new QueryException("Invalid type of overlay: " + type, e); - } - } - if (content.isEmpty() && fileId.isEmpty()) { - throw new QueryException("Either content or fileId must be provided"); - } - - try { - InputStream stream = null; - if (!content.isEmpty()) { - stream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); - } else { - try { - int id = Integer.valueOf(fileId); - UploadedFileEntry file = uploadedFileEntryDao.getById(id); - if (file == null) { - throw new QueryException("Invalid file id: " + fileId); - } - if (file.getOwner() == null || !file.getOwner().getLogin().equals(user.getLogin())) { - throw new SecurityException("Access denied to source file"); - } - stream = new ByteArrayInputStream(file.getFileContent()); - } catch (NumberFormatException e) { - throw new QueryException("Invalid fileId: " + fileId); - } - } - - LayoutView layout = layoutService.createLayout(new CreateLayoutParams().async(false).colorInputStream(stream) - .description(description).layoutFileName(filename).model(model).name(name).user(user) - .colorSchemaType(colorSchemaType).directory(".")); - return layoutService.getLayoutById(Integer.valueOf(layout.getIdObject()), authenticationToken); - } catch (InvalidColorSchemaException e) { - throw new QueryException(e.getMessage(), e); - } - - } - - public Map<String, Object> getOverlayElement(String token, String projectId, Integer modelId, Integer overlayId, - Integer elementId, String elementType, String columns) throws QueryException, SecurityException { - AuthenticationToken authenticationToken = getUserService().getToken(token); - - Model topModel = getModelService().getLastModelByProjectId(projectId, authenticationToken); - if (topModel == null) { - throw new QueryException("Project with given id doesn't exist"); - } - Model model = topModel.getSubmodelById(modelId); - - Map<String, Object> result = new HashMap<>(); - if (ElementIdentifierType.ALIAS.getJsName().equals(elementType)) { - FullLayoutAliasView layoutAliasView = layoutService.getFullAliasForLayout(model, elementId, overlayId, - authenticationToken); - result.put("type", ElementIdentifierType.ALIAS); - result.put("overlayContent", layoutAliasView); - return result; - } else if (ElementIdentifierType.REACTION.getJsName().equals(elementType)) { - FullLayoutReactionView layoutAliasView = layoutService.getFullReactionForLayout(model, elementId, overlayId, - authenticationToken); - result.put("type", ElementIdentifierType.REACTION); - result.put("overlayContent", layoutAliasView); - return result; - } else { - throw new QueryException("Unknown element type: " + elementType); - } - } - -} +package lcsb.mapviewer.api.projects.overlays; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import lcsb.mapviewer.api.BaseRestImpl; +import lcsb.mapviewer.api.ObjectNotFoundException; +import lcsb.mapviewer.api.QueryException; +import lcsb.mapviewer.common.Configuration; +import lcsb.mapviewer.model.cache.FileEntry; +import lcsb.mapviewer.model.cache.UploadedFileEntry; +import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException; +import lcsb.mapviewer.model.map.layout.Layout; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.user.PrivilegeType; +import lcsb.mapviewer.model.user.User; +import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao; +import lcsb.mapviewer.persist.dao.map.LayoutDao; +import lcsb.mapviewer.services.SecurityException; +import lcsb.mapviewer.services.interfaces.ILayoutService; +import lcsb.mapviewer.services.interfaces.ILayoutService.CreateLayoutParams; +import lcsb.mapviewer.services.search.data.ElementIdentifier.ElementIdentifierType; +import lcsb.mapviewer.services.search.layout.FullLayoutAliasView; +import lcsb.mapviewer.services.search.layout.FullLayoutReactionView; +import lcsb.mapviewer.services.search.layout.LightLayoutAliasView; +import lcsb.mapviewer.services.search.layout.LightLayoutReactionView; +import lcsb.mapviewer.services.utils.data.ColorSchemaType; +import lcsb.mapviewer.services.view.AuthenticationToken; +import lcsb.mapviewer.services.view.LayoutView; + +@Transactional(value = "txManager") +public class OverlayRestImpl extends BaseRestImpl { + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(OverlayRestImpl.class); + + @Autowired + private ILayoutService layoutService; + + @Autowired + private UploadedFileEntryDao uploadedFileEntryDao; + + @Autowired + private LayoutDao layoutDao; + + public List<LayoutView> getOverlayList(String token, String projectId, String creatorLogin, String publicOverlay) + throws SecurityException, QueryException { + AuthenticationToken authenticationToken = getUserService().getToken(token); + Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); + if (model == null) { + return new ArrayList<>(); + } + User creator = null; + if (creatorLogin != null && !creatorLogin.isEmpty()) { + creator = getUserService().getUserByLogin(creatorLogin); + if (creator == null) { + throw new ObjectNotFoundException("User with given id doesn't exist: " + creatorLogin); + } + } + Boolean publicData = null; + if (publicOverlay != null && !publicOverlay.isEmpty()) { + publicData = publicOverlay.equalsIgnoreCase("true"); + } + return layoutService.getCustomLayouts(model, token, publicData, creator); + } + + /** + * @return the layoutService + * @see #layoutService + */ + public ILayoutService getLayoutService() { + return layoutService; + } + + /** + * @param layoutService + * the layoutService to set + * @see #layoutService + */ + public void setLayoutService(ILayoutService layoutService) { + this.layoutService = layoutService; + } + + public List<Map<String, Object>> getOverlayElements(String token, String projectId, int overlayId, String columns) + throws QueryException, SecurityException { + List<Map<String, Object>> result = new ArrayList<>(); + AuthenticationToken authenticationToken = getUserService().getToken(token); + + Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); + if (model == null) { + throw new QueryException("Project with given id doesn't exist"); + } + List<LightLayoutAliasView> speciesList = layoutService.getAliasesForLayout(model, overlayId, authenticationToken); + for (LightLayoutAliasView lightLayoutAliasView : speciesList) { + Map<String, Object> element = new HashMap<>(); + element.put("type", ElementIdentifierType.ALIAS); + element.put("overlayContent", lightLayoutAliasView); + result.add(element); + } + + List<LightLayoutReactionView> reactions = layoutService.getReactionsForLayout(model, overlayId, + authenticationToken); + for (LightLayoutReactionView lightReactionView : reactions) { + Map<String, Object> element = new HashMap<>(); + element.put("type", ElementIdentifierType.REACTION); + element.put("overlayContent", lightReactionView); + result.add(element); + } + return result; + } + + public LayoutView getOverlayById(String token, String projectId, String overlayId) + throws SecurityException, QueryException { + AuthenticationToken authenticationToken = getUserService().getToken(token); + Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); + if (model == null) { + throw new QueryException("Project with given id doesn't exist"); + } + return layoutService.getLayoutById(Integer.valueOf(overlayId), authenticationToken); + } + + public FileEntry getOverlaySource(String token, String projectId, String overlayId) + throws SecurityException, QueryException { + AuthenticationToken authenticationToken = getUserService().getToken(token); + Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); + if (model == null) { + throw new QueryException("Project with given id doesn't exist"); + } + try { + Integer id = Integer.valueOf(overlayId); + Layout layout = layoutService.getLayoutDataById(id, authenticationToken); + if (layout == null) { + throw new QueryException("Invalid overlay id"); + } + // lazy initialization issue + layout.getInputData().getFileContent(); + return layout.getInputData(); + } catch (NumberFormatException e) { + throw new QueryException("Invalid overlay id"); + } + } + + public LayoutView updateOverlay(String token, String projectId, String overlayId, Map<String, Object> overlayData) + throws QueryException, SecurityException { + AuthenticationToken authenticationToken = getUserService().getToken(token); + if (overlayData == null) { + throw new QueryException("overlay field cannot be undefined"); + } + try { + Integer id = Integer.valueOf(overlayId); + Layout layout = layoutService.getLayoutDataById(id, authenticationToken); + if (layout == null) { + throw new ObjectNotFoundException("overlay doesn't exist"); + } + boolean isAdmin = getUserService().userHasPrivilege(authenticationToken, PrivilegeType.LAYOUT_MANAGEMENT, + layout.getModel().getProject()); + if (layout.isPublicLayout() && !isAdmin) { + throw new SecurityException("You cannot modify given overlay"); + } + for (String key : overlayData.keySet()) { + Object value = overlayData.get(key); + if (key.equalsIgnoreCase("description")) { + layout.setDescription((String) value); + } else if (key.equalsIgnoreCase("name")) { + layout.setTitle((String) value); + } else if (key.equalsIgnoreCase("publicOverlay")) { + layout.setPublicLayout(parseBoolean(value)); + } else if (key.equalsIgnoreCase("defaultOverlay")) { + layout.setDefaultOverlay(parseBoolean(value)); + } else if (key.equalsIgnoreCase("creator")) { + if ("".equals(value)) { + layout.setCreator(null); + } else { + layout.setCreator(getUserService().getUserByLogin((String) value)); + } + } else { + throw new QueryException("Unknown parameter: " + key); + } + } + layoutDao.update(layout); + return layoutService.getLayoutById(Integer.valueOf(overlayId), authenticationToken); + } catch (NumberFormatException e) { + throw new ObjectNotFoundException("overlay doesn't exist"); + } + } + + private boolean parseBoolean(Object value) { + if (value instanceof Boolean) { + return (Boolean) value; + } else { + return "true".equalsIgnoreCase((String) value); + } + } + + public Map<String, Object> removeOverlay(String token, String projectId, String overlayId) + throws QueryException, SecurityException, IOException { + AuthenticationToken authenticationToken = getUserService().getToken(token); + Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); + if (model == null) { + throw new ObjectNotFoundException("Project with given id doesn't exist"); + } + try { + Integer id = Integer.valueOf(overlayId); + LayoutView layout = layoutService.getLayoutById(id, authenticationToken); + if (layout == null) { + throw new ObjectNotFoundException("Overlay doesn't exist"); + } + if (layoutService.userCanRemoveLayout(layout, authenticationToken)) { + layoutService.removeLayout(layout, null); + return okStatus(); + } else { + throw new SecurityException("You cannot remove given overlay"); + } + } catch (NumberFormatException e) { + throw new QueryException("Invalid overlay id: " + overlayId); + } + } + + /** + * @return the layoutDao + * @see #layoutDao + */ + public LayoutDao getLayoutDao() { + return layoutDao; + } + + /** + * @param layoutDao + * the layoutDao to set + * @see #layoutDao + */ + public void setLayoutDao(LayoutDao layoutDao) { + this.layoutDao = layoutDao; + } + + public LayoutView addOverlay(String token, String projectId, String name, String description, String content, + String fileId, String filename, String type) throws SecurityException, QueryException, IOException { + AuthenticationToken authenticationToken = getUserService().getToken(token); + User user = getUserService().getUserByToken(token); + if (Configuration.ANONYMOUS_LOGIN.equals(user.getLogin())) { + throw new SecurityException("You have no privileges to add overlay"); + } + Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); + if (model == null) { + throw new QueryException("Project with given id doesn't exist"); + } + ColorSchemaType colorSchemaType = ColorSchemaType.GENERIC; + if (type != null && !type.equals("")) { + try { + colorSchemaType = ColorSchemaType.valueOf(type); + } catch (IllegalArgumentException e) { + throw new QueryException("Invalid type of overlay: " + type, e); + } + } + if (content.isEmpty() && fileId.isEmpty()) { + throw new QueryException("Either content or fileId must be provided"); + } + + try { + InputStream stream = null; + if (!content.isEmpty()) { + stream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); + } else { + try { + int id = Integer.valueOf(fileId); + UploadedFileEntry file = uploadedFileEntryDao.getById(id); + if (file == null) { + throw new QueryException("Invalid file id: " + fileId); + } + if (file.getOwner() == null || !file.getOwner().getLogin().equals(user.getLogin())) { + throw new SecurityException("Access denied to source file"); + } + stream = new ByteArrayInputStream(file.getFileContent()); + } catch (NumberFormatException e) { + throw new QueryException("Invalid fileId: " + fileId); + } + } + + LayoutView layout = layoutService.createLayout(new CreateLayoutParams().async(false).colorInputStream(stream) + .description(description).layoutFileName(filename).model(model).name(name).user(user) + .colorSchemaType(colorSchemaType).directory(".")); + return layoutService.getLayoutById(Integer.valueOf(layout.getIdObject()), authenticationToken); + } catch (InvalidColorSchemaException e) { + throw new QueryException(e.getMessage(), e); + } + + } + + public Map<String, Object> getOverlayElement(String token, String projectId, Integer modelId, Integer overlayId, + Integer elementId, String elementType, String columns) throws QueryException, SecurityException { + AuthenticationToken authenticationToken = getUserService().getToken(token); + + Model topModel = getModelService().getLastModelByProjectId(projectId, authenticationToken); + if (topModel == null) { + throw new QueryException("Project with given id doesn't exist"); + } + Model model = topModel.getSubmodelById(modelId); + + Map<String, Object> result = new HashMap<>(); + if (ElementIdentifierType.ALIAS.getJsName().equals(elementType)) { + FullLayoutAliasView layoutAliasView = layoutService.getFullAliasForLayout(model, elementId, overlayId, + authenticationToken); + result.put("type", ElementIdentifierType.ALIAS); + result.put("overlayContent", layoutAliasView); + return result; + } else if (ElementIdentifierType.REACTION.getJsName().equals(elementType)) { + FullLayoutReactionView layoutAliasView = layoutService.getFullReactionForLayout(model, elementId, overlayId, + authenticationToken); + result.put("type", ElementIdentifierType.REACTION); + result.put("overlayContent", layoutAliasView); + return result; + } else { + throw new QueryException("Unknown element type: " + elementType); + } + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/view/LayoutView.java b/service/src/main/java/lcsb/mapviewer/services/view/LayoutView.java index a85a32ed3b..67a7bf92a7 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/LayoutView.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/LayoutView.java @@ -1,258 +1,274 @@ -package lcsb.mapviewer.services.view; - -import java.io.Serializable; -import java.util.Comparator; - -import lcsb.mapviewer.model.map.layout.Layout; - -/** - * This class is a client view that represents {@link Layout} class. - * - * @author Piotr Gawron - * - */ -public class LayoutView extends AbstractView<Layout> implements Serializable { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Comparator for {@link LayoutView} that use database identifier as a key for - * comparison. - */ - public static final Comparator<LayoutView> ID_COMPARATOR = new Comparator<LayoutView>() { - - @Override - public int compare(LayoutView arg0, LayoutView arg1) { - if (arg0 == null) { - return -1; - } else if (arg1 == null) { - return 1; - } else if (arg0.getIdObject() == null) { - return -1; - } else if (arg1.getIdObject() == null) { - return 1; - } else { - return arg0.getIdObject() - arg1.getIdObject(); - } - } - - }; - - /** - * Database identifier of the model to which layout belongs to. - */ - private Integer modelId; - - /** - * Name of the layout. - */ - private String name; - - /** - * Short description of the layout. - */ - private String description; - - /** - * Status of processing the layout. - * {@link lcsb.mapviewer.db.model.map.layout.LayoutStatus LayoutStatus} - * defines possible values. - */ - private String status; - - private Boolean publicOverlay; - - /** - * Processing progress (value between 0..100). - */ - private String progress; - - /** - * Where the files generated for this layout are stored. - */ - private String directory; - - /** - * Who created the layout. - */ - private String creator; - - /** - * "true" if input file from which layout was created is available, "false" - * otherwise. - */ - private String inputDataAvailable; - - /** - * Default constructor. - */ - public LayoutView() { - super(null); - } - - /** - * Constructor that reates view from the original layout. - * - * @param layout - * original layout - */ - protected LayoutView(Layout layout) { - super(layout); - } - - /** - * @return the modelId - * @see #modelId - */ - public Integer getModelId() { - return modelId; - } - - /** - * @param modelId - * the modelId to set - * @see #modelId - */ - public void setModelId(Integer modelId) { - this.modelId = modelId; - } - - /** - * @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 description - * @see #description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - * @see #description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the status - * @see #status - */ - public String getStatus() { - return status; - } - - /** - * @param status - * the status to set - * @see #status - */ - public void setStatus(String status) { - this.status = status; - } - - /** - * @return the progress - * @see #progress - */ - public String getProgress() { - return progress; - } - - /** - * @param progress - * the progress to set - * @see #progress - */ - public void setProgress(String progress) { - this.progress = progress; - } - - /** - * @return the directory - * @see #directory - */ - public String getDirectory() { - return directory; - } - - /** - * @param directory - * the directory to set - * @see #directory - */ - public void setDirectory(String directory) { - this.directory = directory; - } - - /** - * @return the creator - * @see #creator - */ - public String getCreator() { - return creator; - } - - /** - * @param creator - * the creator to set - * @see #creator - */ - public void setCreator(String creator) { - this.creator = creator; - } - - /** - * @return the inputDataAvailable - * @see #inputDataAvailable - */ - public String getInputDataAvailable() { - return inputDataAvailable; - } - - /** - * @param inputDataAvailable - * the inputDataAvailable to set - * @see #inputDataAvailable - */ - public void setInputDataAvailable(String inputDataAvailable) { - this.inputDataAvailable = inputDataAvailable; - } - - /** - * @return the publicOverlay - * @see #publicOverlay - */ - public Boolean getPublicOverlay() { - return publicOverlay; - } - - /** - * @param publicOverlay - * the publicOverlay to set - * @see #publicOverlay - */ - public void setPublicOverlay(Boolean publicOverlay) { - this.publicOverlay = publicOverlay; - } - -} +package lcsb.mapviewer.services.view; + +import java.io.Serializable; +import java.util.Comparator; + +import lcsb.mapviewer.model.map.layout.Layout; + +/** + * This class is a client view that represents {@link Layout} class. + * + * @author Piotr Gawron + * + */ +public class LayoutView extends AbstractView<Layout> implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Comparator for {@link LayoutView} that use database identifier as a key for + * comparison. + */ + public static final Comparator<LayoutView> ID_COMPARATOR = new Comparator<LayoutView>() { + + @Override + public int compare(LayoutView arg0, LayoutView arg1) { + if (arg0 == null) { + return -1; + } else if (arg1 == null) { + return 1; + } else if (arg0.getIdObject() == null) { + return -1; + } else if (arg1.getIdObject() == null) { + return 1; + } else { + return arg0.getIdObject() - arg1.getIdObject(); + } + } + + }; + + /** + * Database identifier of the model to which layout belongs to. + */ + private Integer modelId; + + /** + * Name of the layout. + */ + private String name; + + /** + * Short description of the layout. + */ + private String description; + + /** + * Status of processing the layout. + * {@link lcsb.mapviewer.db.model.map.layout.LayoutStatus LayoutStatus} defines + * possible values. + */ + private String status; + + /** + * Should the data overlay be accessible by everybody. + */ + private Boolean publicOverlay; + + /** + * Should the data overlay be shown on start. + */ + private Boolean defaultOverlay; + + /** + * Processing progress (value between 0..100). + */ + private String progress; + + /** + * Where the files generated for this layout are stored. + */ + private String directory; + + /** + * Who created the layout. + */ + private String creator; + + /** + * "true" if input file from which layout was created is available, "false" + * otherwise. + */ + private String inputDataAvailable; + + /** + * Default constructor. + */ + public LayoutView() { + super(null); + } + + /** + * Constructor that creates view from the original layout. + * + * @param layout + * original layout + */ + protected LayoutView(Layout layout) { + super(layout); + } + + /** + * @return the modelId + * @see #modelId + */ + public Integer getModelId() { + return modelId; + } + + /** + * @param modelId + * the modelId to set + * @see #modelId + */ + public void setModelId(Integer modelId) { + this.modelId = modelId; + } + + /** + * @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 description + * @see #description + */ + public String getDescription() { + return description; + } + + /** + * @param description + * the description to set + * @see #description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the status + * @see #status + */ + public String getStatus() { + return status; + } + + /** + * @param status + * the status to set + * @see #status + */ + public void setStatus(String status) { + this.status = status; + } + + /** + * @return the progress + * @see #progress + */ + public String getProgress() { + return progress; + } + + /** + * @param progress + * the progress to set + * @see #progress + */ + public void setProgress(String progress) { + this.progress = progress; + } + + /** + * @return the directory + * @see #directory + */ + public String getDirectory() { + return directory; + } + + /** + * @param directory + * the directory to set + * @see #directory + */ + public void setDirectory(String directory) { + this.directory = directory; + } + + /** + * @return the creator + * @see #creator + */ + public String getCreator() { + return creator; + } + + /** + * @param creator + * the creator to set + * @see #creator + */ + public void setCreator(String creator) { + this.creator = creator; + } + + /** + * @return the inputDataAvailable + * @see #inputDataAvailable + */ + public String getInputDataAvailable() { + return inputDataAvailable; + } + + /** + * @param inputDataAvailable + * the inputDataAvailable to set + * @see #inputDataAvailable + */ + public void setInputDataAvailable(String inputDataAvailable) { + this.inputDataAvailable = inputDataAvailable; + } + + /** + * @return the publicOverlay + * @see #publicOverlay + */ + public Boolean getPublicOverlay() { + return publicOverlay; + } + + /** + * @param publicOverlay + * the publicOverlay to set + * @see #publicOverlay + */ + public void setPublicOverlay(Boolean publicOverlay) { + this.publicOverlay = publicOverlay; + } + + public Boolean getDefaultOverlay() { + return defaultOverlay; + } + + public void setDefaultOverlay(Boolean defaultOverlay) { + this.defaultOverlay = defaultOverlay; + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/view/LayoutViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/view/LayoutViewFactory.java index b5ca397459..912f7066cb 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/LayoutViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/LayoutViewFactory.java @@ -1,88 +1,89 @@ -package lcsb.mapviewer.services.view; - -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.Project; -import lcsb.mapviewer.model.map.layout.Layout; - -import org.apache.log4j.Logger; - -import com.google.gson.Gson; - -/** - * Factory class for {@link LayoutView} class. - * - * @author Piotr Gawron - * - */ -public class LayoutViewFactory extends AbstractViewFactory<Layout, LayoutView> { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(LayoutViewFactory.class); - - @Override - public LayoutView create(Layout layout) { - LayoutView result = new LayoutView(layout); - if (layout == null) { - return result; - } - if (layout.getModel() != null) { - result.setModelId(layout.getModel().getId()); - } - result.setName(layout.getTitle()); - Project project = getProjectForLayout(layout); - if (project != null && project.getDirectory() != null) { - result.setDirectory(project.getDirectory() + "/" + layout.getDirectory()); - } else { - result.setDirectory(layout.getDirectory()); - } - if (layout.getCreator() != null) { - result.setCreator(layout.getCreator().getLogin()); - } else { - result.setCreator(""); - } - result.setStatus(layout.getStatus().getCommonName()); - result.setPublicOverlay(layout.isPublicLayout()); - result.setProgress(String.format("%1$,.2f", layout.getProgress())); - - result.setDescription(layout.getDescription()); - if (layout.getInputData() != null) { - result.setInputDataAvailable("true"); - } else { - result.setInputDataAvailable("false"); - } - return result; - } - - /** - * Returns projects associated with model. It might be tricky, because some - * layouts are connected to models that are not directly attached to project - * (they are attached by parent or grand-parent). - * - * @param layout - * layout for which project will be returned - * @return {@link Project} to which {@link Layout layout} belongs to - */ - protected Project getProjectForLayout(Layout layout) { - if (layout.getModel() != null) { - if (layout.getModel().getProject() != null) { - return layout.getModel().getProject(); - } - } - if (layout.getParentLayout() != null) { - return getProjectForLayout(layout.getParentLayout()); - } - return null; - } - - @Override - public String createGson(LayoutView object) { - return new Gson().toJson(object); - } - - @Override - public Layout viewToObject(LayoutView view) { - throw new NotImplementedException(); - } -} +package lcsb.mapviewer.services.view; + +import org.apache.log4j.Logger; + +import com.google.gson.Gson; + +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.Project; +import lcsb.mapviewer.model.map.layout.Layout; + +/** + * Factory class for {@link LayoutView} class. + * + * @author Piotr Gawron + * + */ +public class LayoutViewFactory extends AbstractViewFactory<Layout, LayoutView> { + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(LayoutViewFactory.class); + + @Override + public LayoutView create(Layout layout) { + LayoutView result = new LayoutView(layout); + if (layout == null) { + return result; + } + if (layout.getModel() != null) { + result.setModelId(layout.getModel().getId()); + } + result.setName(layout.getTitle()); + Project project = getProjectForLayout(layout); + if (project != null && project.getDirectory() != null) { + result.setDirectory(project.getDirectory() + "/" + layout.getDirectory()); + } else { + result.setDirectory(layout.getDirectory()); + } + if (layout.getCreator() != null) { + result.setCreator(layout.getCreator().getLogin()); + } else { + result.setCreator(""); + } + result.setStatus(layout.getStatus().getCommonName()); + result.setPublicOverlay(layout.isPublicLayout()); + result.setDefaultOverlay(layout.isDefaultOverlay()); + result.setProgress(String.format("%1$,.2f", layout.getProgress())); + + result.setDescription(layout.getDescription()); + if (layout.getInputData() != null) { + result.setInputDataAvailable("true"); + } else { + result.setInputDataAvailable("false"); + } + return result; + } + + /** + * Returns projects associated with model. It might be tricky, because some + * layouts are connected to models that are not directly attached to project + * (they are attached by parent or grand-parent). + * + * @param layout + * layout for which project will be returned + * @return {@link Project} to which {@link Layout layout} belongs to + */ + protected Project getProjectForLayout(Layout layout) { + if (layout.getModel() != null) { + if (layout.getModel().getProject() != null) { + return layout.getModel().getProject(); + } + } + if (layout.getParentLayout() != null) { + return getProjectForLayout(layout.getParentLayout()); + } + return null; + } + + @Override + public String createGson(LayoutView object) { + return new Gson().toJson(object); + } + + @Override + public Layout viewToObject(LayoutView view) { + throw new NotImplementedException(); + } +} -- GitLab