diff --git a/components/blitz/src/pojos/DataObject.java b/components/blitz/src/pojos/DataObject.java index 190f71eabda..deb830275b1 100644 --- a/components/blitz/src/pojos/DataObject.java +++ b/components/blitz/src/pojos/DataObject.java @@ -391,6 +391,17 @@ public Timestamp getUpdated() { return timeOfEvent(getDetails().getUpdateEvent()); } + /** + * Returns the id of the group. + * + * @return See above. + */ + public long getGroupId() { + Details d = getDetails(); + if (d == null) return -1; + if (d.getGroup() == null) return -1; + return d.getGroup().getId().getValue(); + } // ~ VIEWS // ========================================================================= // These methods should never a null value diff --git a/components/blitz/src/pojos/ExperimenterData.java b/components/blitz/src/pojos/ExperimenterData.java index 5299fec6a33..122ccb66e1c 100644 --- a/components/blitz/src/pojos/ExperimenterData.java +++ b/components/blitz/src/pojos/ExperimenterData.java @@ -294,4 +294,14 @@ public boolean isActive() return false; } + /** + * Overridden to return the id of the default group. + * @see DataObject#getGroupId() + */ + public long getGroupId() { + GroupData g = getDefaultGroup(); + if (g == null) return -1; + return g.getId(); + } + } diff --git a/components/blitz/src/pojos/GroupData.java b/components/blitz/src/pojos/GroupData.java index fb31d9678af..b7994f41301 100644 --- a/components/blitz/src/pojos/GroupData.java +++ b/components/blitz/src/pojos/GroupData.java @@ -182,6 +182,13 @@ && asGroup().sizeOfGroupExperimenterMap() >= 0) { return experimenters == null ? null : new HashSet(experimenters); } + /** + * Overridden to return the id of the object. + * @see DataObject#getGroupId() + */ + public long getGroupId() { + return getId(); + } // Link mutations /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/AnnotatedFilter.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/AnnotatedFilter.java index 0438ec900f9..a9f3fcdb85d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/AnnotatedFilter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/AnnotatedFilter.java @@ -37,6 +37,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.TagAnnotationData; @@ -98,6 +99,7 @@ private void checkType(Class value) * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param type One of the annotation type. * Mustn't be null. * @param annotated Pass true to filter the annotated nodes, @@ -105,10 +107,10 @@ private void checkType(Class value) * @param nodes The collection of objects to filter. * Mustn't be null. */ - public AnnotatedFilter(DataBrowser viewer, Class type, boolean annotated, - Collection nodes) + public AnnotatedFilter(DataBrowser viewer, SecurityContext ctx, Class type, + boolean annotated, Collection nodes) { - super(viewer); + super(viewer, ctx); if (nodes == null || nodes.size() == 0) throw new IllegalArgumentException("No nodes to filter."); checkType(type); @@ -139,8 +141,8 @@ public AnnotatedFilter(DataBrowser viewer, Class type, boolean annotated, public void load() { long userID = -1;//DataBrowserAgent.getUserDetails().getId(); - handle = mhView.filterByAnnotated(nodeType, nodeIds, annotationType, - annotated, userID, this); + handle = mhView.filterByAnnotated(ctx, nodeType, nodeIds, + annotationType, annotated, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/CommentsFilter.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/CommentsFilter.java index f157afc3f89..893f3613b97 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/CommentsFilter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/CommentsFilter.java @@ -35,6 +35,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.TextualAnnotationData; @@ -78,16 +79,17 @@ public class CommentsFilter * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param comments The collection of comments to filter by. * If null or empty * retrieve the uncommented objects. * @param nodes The collection of objects to filter. * Mustn't be null. */ - public CommentsFilter(DataBrowser viewer, List comments, - Collection nodes) + public CommentsFilter(DataBrowser viewer, SecurityContext ctx, + List comments, Collection nodes) { - super(viewer); + super(viewer, ctx); if (nodes == null || nodes.size() == 0) throw new IllegalArgumentException("No nodes to filter."); this.comments = comments; @@ -116,8 +118,8 @@ public CommentsFilter(DataBrowser viewer, List comments, public void load() { long userID = -1;//DataBrowserAgent.getUserDetails().getId(); - handle = mhView.filterByAnnotation(nodeType, nodeIds, - TextualAnnotationData.class, comments, userID, this); + handle = mhView.filterByAnnotation(ctx, nodeType, nodeIds, + TextualAnnotationData.class, comments, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserAgent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserAgent.java index a6dfaf7397b..815480f5cfe 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserAgent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserAgent.java @@ -78,6 +78,16 @@ public class DataBrowserAgent */ public static Registry getRegistry() { return registry; } + /** + * Returns the available user groups. + * + * @return See above. + */ + public static Set getAvailableUserGroups() + { + return (Set) registry.lookup(LookupNames.USER_GROUP_DETAILS); + } + /** * Helper method returning the current user's details. * diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserLoader.java index 7972926c152..b11b5b30e01 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserLoader.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.DataHandlerView; import org.openmicroscopy.shoola.env.data.views.DataManagerView; import org.openmicroscopy.shoola.env.data.views.HierarchyBrowsingView; @@ -65,33 +66,39 @@ public abstract class DataBrowserLoader { /** The viewer this data loader is for. */ - protected final DataBrowser viewer; + protected final DataBrowser viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final HierarchyBrowsingView hiBrwView; + protected final HierarchyBrowsingView hiBrwView; /** Convenience reference for subclasses. */ - protected final DataHandlerView dhView; + protected final DataHandlerView dhView; /** Convenience reference for subclasses. */ - protected final MetadataHandlerView mhView; + protected final MetadataHandlerView mhView; /** Convenience reference for subclasses. */ - protected final DataManagerView dmView; + protected final DataManagerView dmView; + + /** The security context.*/ + protected final SecurityContext ctx; /** * Creates a new instance. * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - protected DataBrowserLoader(DataBrowser viewer) + protected DataBrowserLoader(DataBrowser viewer, SecurityContext ctx) { - if (viewer == null) throw new NullPointerException("No viewer."); + if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null) throw new NullPointerException("No security context."); this.viewer = viewer; + this.ctx = ctx; registry = DataBrowserAgent.getRegistry(); hiBrwView = (HierarchyBrowsingView) registry.getDataServicesView(HierarchyBrowsingView.class); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserTranslator.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserTranslator.java index 82f54d8f533..afc62b4ed73 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserTranslator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataBrowserTranslator.java @@ -44,6 +44,7 @@ import pojos.DatasetData; import pojos.ExperimenterData; import pojos.FileData; +import pojos.GroupData; import pojos.ImageData; import pojos.MultiImageData; import pojos.PermissionData; @@ -565,6 +566,36 @@ else if (ho instanceof ImageData) { return results; } + /** + * Transforms a set of {@link DataObject}s into their corresponding + * visualization objects. The elements of the set only be {@link ImageData}. + * The {@link ImageData}s are added to a {@link ImageSet}. + * + * @param dataObjects The {@link DataObject}s to transform. + * Mustn't be null. + * @param userID The id of the current user. + * @param group The the group the current user selects when + * retrieving the data. + * @return See above. + */ + public static ImageSet transformObjects(Collection dataObjects, long userID, + GroupData group) + { + if (dataObjects == null) + throw new IllegalArgumentException("No objects."); + Set results = new HashSet(); + DataObject ho; + Iterator i = dataObjects.iterator(); + long groupId = group.getId(); + ImageSet groupNode = new ImageSet(group.getName(), group); + while (i.hasNext()) { + ho = (DataObject) i.next(); + if (isReadable(ho, userID, groupId) && ho instanceof ImageData) + linkImageTo((ImageData) ho, groupNode); + } + return groupNode; + } + /** * Transforms a set of {@link DataObject}s into their corresponding * visualization objects. The elements of the set only be {@link ImageData}. @@ -573,26 +604,25 @@ else if (ho instanceof ImageData) { * @param dataObjects The {@link DataObject}s to transform. * Mustn't be null. * @param userID The id of the current user. - * @param groupID The id of the group the current user selects when - * retrieving the data. + * @param groupId The id of the group the current user selects when + * retrieving the data. * @return See above. */ - public static Set transformObjects(Collection dataObjects, long userID, - long groupID) + public static Set transformObjects(Collection dataObjects, + long userID, long groupId) { if (dataObjects == null) throw new IllegalArgumentException("No objects."); - Set results = new HashSet(); + Set results = new HashSet(); DataObject ho; Iterator i = dataObjects.iterator(); while (i.hasNext()) { ho = (DataObject) i.next(); - if (isReadable(ho, userID, groupID) && ho instanceof ImageData) + if (isReadable(ho, userID, groupId) && ho instanceof ImageData) results.add(linkImageTo((ImageData) ho, null)); } return results; } - /** * Transforms a set of {@link DataObject}s into their corresponding * visualization objects. The elements of the set only be {@link ImageData}. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataFilter.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataFilter.java index 63b4acd8df0..0a1bd4e1def 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataFilter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataFilter.java @@ -36,6 +36,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.env.data.util.FilterContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; @@ -78,14 +79,15 @@ public class DataFilter * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param context The filtering context. Mustn't be null. * @param nodes The collection of objects to filter. * Mustn't be null. */ - public DataFilter(DataBrowser viewer, FilterContext context, - Collection nodes) + public DataFilter(DataBrowser viewer, SecurityContext ctx, + FilterContext context, Collection nodes) { - super(viewer); + super(viewer, ctx); if (nodes == null || nodes.size() == 0) throw new IllegalArgumentException("No nodes to filter."); if (context == null) @@ -116,7 +118,8 @@ public DataFilter(DataBrowser viewer, FilterContext context, public void load() { long userID = -1;//DataBrowserAgent.getUserDetails().getId(); - handle = mhView.filterData(nodeType, nodeIds, context, userID, this); + handle = mhView.filterData(ctx, nodeType, nodeIds, context, userID, + this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataObjectCreator.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataObjectCreator.java index 3086c811974..0e4ad55ce69 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataObjectCreator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataObjectCreator.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; @@ -70,16 +71,17 @@ public class DataObjectCreator * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param parent The parent of the DataObject to create * or null. * @param data The DataObject to create. * Mustn't be null. * @param children The nodes to add to the newly created object. */ - public DataObjectCreator(DataBrowser viewer, DataObject parent, - DataObject data, Collection children) + public DataObjectCreator(DataBrowser viewer, SecurityContext ctx, + DataObject parent, DataObject data, Collection children) { - super(viewer); + super(viewer, ctx); if (data == null) throw new IllegalArgumentException("No object to create."); this.data = data; @@ -99,7 +101,7 @@ public DataObjectCreator(DataBrowser viewer, DataObject parent, */ public void load() { - handle = mhView.createDataObject(parent, data, children, this); + handle = mhView.createDataObject(ctx, parent, data, children, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataObjectSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataObjectSaver.java index e2bd8b71dc1..08bf288be9b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataObjectSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DataObjectSaver.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -63,14 +64,15 @@ public class DataObjectSaver * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param datasets The datasets to add the images to. * Mustn't be null. * @param images The images to add. Mustn't be null. */ - public DataObjectSaver(DataBrowser viewer, Collection datasets, - Collection images) + public DataObjectSaver(DataBrowser viewer, SecurityContext ctx, + Collection datasets, Collection images) { - super(viewer); + super(viewer, ctx); if (datasets == null || datasets.size() == 0) throw new IllegalArgumentException("No datasets to add the images" + " to."); @@ -93,7 +95,7 @@ public DataObjectSaver(DataBrowser viewer, Collection datasets, public void load() { - handle = dmView.addExistingObjects(datasets, images, this); + handle = dmView.addExistingObjects(ctx, datasets, images, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DatasetsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DatasetsLoader.java index 9d4847cc093..66d43257862 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DatasetsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/DatasetsLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.agents.metadata.MetadataViewerAgent; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DatasetData; import pojos.ExperimenterData; @@ -62,10 +63,11 @@ public class DatasetsLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - public DatasetsLoader(DataBrowser viewer) + public DatasetsLoader(DataBrowser viewer, SecurityContext ctx) { - super(viewer); + super(viewer, ctx); } /** @@ -86,7 +88,7 @@ public void load() ExperimenterData exp = MetadataViewerAgent.getUserDetails(); GroupData group = exp.getDefaultGroup(); - handle = dmView.loadContainerHierarchy(DatasetData.class, null, + handle = dmView.loadContainerHierarchy(ctx, DatasetData.class, null, false, exp.getId(), group.getId(), this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/IconManager.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/IconManager.java index 25138677e45..f3ec4ae7b0e 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/IconManager.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/IconManager.java @@ -209,13 +209,28 @@ public class IconManager public static final int FILTER_BY_MENU = 50; /** The Send comment icon. */ - public static final int SEND_COMMENT = 51; + public static final int SEND_COMMENT = 51; + + /** The Personal icon. */ + public static final int PERSONAL = 52; + + /** The Private Group icon. */ + public static final int PRIVATE_GROUP = 53; + + /** The Read Group icon. */ + public static final int READ_GROUP = 54; + + /** The Read Link Group icon. */ + public static final int READ_LINK_GROUP = 55; + + /** The Public Group icon. */ + public static final int PUBLIC_GROUP = 56; /** * The maximum ID used for the icon IDs. * Allows to correctly build arrays for direct indexing. */ - private static final int MAX_ID = 51; + private static final int MAX_ID = 56; /** Paths of the icon files. */ private static String[] relPaths = new String[MAX_ID+1]; @@ -274,6 +289,11 @@ public class IconManager relPaths[TAG_FILTER] = "eclipse_filter_ps16.png"; relPaths[FILTER_BY_MENU] = "eclipse_view_menu16.png"; relPaths[SEND_COMMENT] = "nuvola_mail_send16.png"; + relPaths[PRIVATE_GROUP] = "nuvola_ledred16.png"; + relPaths[READ_GROUP] = "nuvola_ledorange_readOnly16.png"; + relPaths[READ_LINK_GROUP] = "nuvola_ledorange16.png"; + relPaths[PUBLIC_GROUP] = "nuvola_ledgreen16.png"; + relPaths[PERSONAL] = "nuvola_personal16.png"; } /** The sole instance. */ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/PlateSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/PlateSaver.java index 29774ae60d6..b23eb5c4e93 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/PlateSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/PlateSaver.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; @@ -61,11 +62,13 @@ public class PlateSaver * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param toUpdate The collection of objects to update. */ - public PlateSaver(DataBrowser viewer, List toUpdate) + public PlateSaver(DataBrowser viewer, SecurityContext ctx, + List toUpdate) { - super(viewer); + super(viewer, ctx); if (toUpdate == null || toUpdate.size() == 0) throw new IllegalArgumentException("No objects to update."); this.toUpdate = toUpdate; @@ -83,7 +86,7 @@ public PlateSaver(DataBrowser viewer, List toUpdate) */ public void load() { - handle = mhView.updateDataObjects(toUpdate, this); + handle = mhView.updateDataObjects(ctx, toUpdate, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/RateFilter.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/RateFilter.java index 87d1058df79..291cbea4a04 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/RateFilter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/RateFilter.java @@ -35,6 +35,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.RatingAnnotationData; @@ -136,14 +137,15 @@ private RatingAnnotationData getAnnotation(List ratings) * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param rate One of the constants defined by this class. * @param nodes The collection of objects to filter. * Mustn't be null. */ - public RateFilter(DataBrowser viewer, int rate, + public RateFilter(DataBrowser viewer, SecurityContext ctx, int rate, Collection nodes) { - super(viewer); + super(viewer, ctx); if (nodes == null || nodes.size() == 0) throw new IllegalArgumentException("No nodes to filter."); checkRate(rate); @@ -173,7 +175,7 @@ public RateFilter(DataBrowser viewer, int rate, public void load() { long userID = -1;//DataBrowserAgent.getUserDetails().getId(); - handle = mhView.loadRatings(nodeType, nodeIds, userID, this); + handle = mhView.loadRatings(ctx, nodeType, nodeIds, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ReportLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ReportLoader.java index 91c80b7d9d9..df7f5a62396 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ReportLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ReportLoader.java @@ -39,6 +39,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageNode; import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StructuredDataResults; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; @@ -83,14 +84,15 @@ public class ReportLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param types The types of annotation to add to the report. * @param images The images the report is for. * @param path The name of the report file. */ - public ReportLoader(DataBrowser viewer, List types, - Collection images, String path) + public ReportLoader(DataBrowser viewer, SecurityContext ctx, + List types, Collection images, String path) { - super(viewer); + super(viewer, ctx); if (images == null || images.size() == 0) throw new IllegalArgumentException("No images specified."); if (path == null || path.trim().length() == 0) @@ -122,7 +124,7 @@ public ReportLoader(DataBrowser viewer, List types, */ public void load() { - handle = mhView.loadStructuredData(nodes, -1, false, this); + handle = mhView.loadStructuredData(ctx, nodes, -1, false, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TabularDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TabularDataLoader.java index 47ba1cd2e1e..5d016cc8a71 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TabularDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TabularDataLoader.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.env.data.model.TableParameters; import org.openmicroscopy.shoola.env.data.model.TableResult; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.PlateData; @@ -65,11 +66,13 @@ public class TabularDataLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param ids The identifier of the files hosting the tabular data. */ - public TabularDataLoader(DataBrowser viewer, List ids) + public TabularDataLoader(DataBrowser viewer, SecurityContext ctx, + List ids) { - super(viewer); + super(viewer, ctx); if (ids == null || ids.size() <= 0) throw new IllegalArgumentException("No file to retrieve."); parameters = new TableParameters(ids); @@ -80,11 +83,13 @@ public TabularDataLoader(DataBrowser viewer, List ids) * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param object The object to handle. Mustn't be null. */ - public TabularDataLoader(DataBrowser viewer, DataObject object) + public TabularDataLoader(DataBrowser viewer, SecurityContext ctx, + DataObject object) { - super(viewer); + super(viewer, ctx); if (object == null) throw new IllegalArgumentException("No file to retrieve."); if (!(object instanceof PlateData || object instanceof ScreenData)) { @@ -99,7 +104,7 @@ public TabularDataLoader(DataBrowser viewer, DataObject object) */ public void load() { - handle = mhView.loadTabularData(parameters, -1, this); + handle = mhView.loadTabularData(ctx, parameters, -1, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TagsFilter.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TagsFilter.java index 453b0ff33fa..ed9e41a899c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TagsFilter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TagsFilter.java @@ -35,6 +35,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.TagAnnotationData; @@ -78,16 +79,17 @@ public class TagsFilter * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param tags The collection of tags to filter by. * If null or empty * retrieve the uncommented objects. * @param nodes The collection of objects to filter. * Mustn't be null. */ - public TagsFilter(DataBrowser viewer, List tags, - Collection nodes) + public TagsFilter(DataBrowser viewer, SecurityContext ctx, + List tags, Collection nodes) { - super(viewer); + super(viewer, ctx); if (nodes == null || nodes.size() == 0) throw new IllegalArgumentException("No nodes to filter."); this.tags = tags; @@ -116,7 +118,7 @@ public TagsFilter(DataBrowser viewer, List tags, public void load() { long userID = -1;//DataBrowserAgent.getUserDetails().getId(); - handle = mhView.filterByAnnotation(nodeType, nodeIds, + handle = mhView.filterByAnnotation(ctx, nodeType, nodeIds, TagAnnotationData.class, tags, userID, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TagsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TagsLoader.java index 294a93b53ca..50e0ac22f9b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TagsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/TagsLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; import pojos.TagAnnotationData; @@ -62,10 +63,11 @@ public class TagsLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - public TagsLoader(DataBrowser viewer) + public TagsLoader(DataBrowser viewer, SecurityContext ctx) { - super(viewer); + super(viewer, ctx); } /** @@ -97,7 +99,7 @@ public void load() userID = -1; } - handle = mhView.loadExistingAnnotations(TagAnnotationData.class, + handle = mhView.loadExistingAnnotations(ctx, TagAnnotationData.class, userID, groupID, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ThumbnailFieldsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ThumbnailFieldsLoader.java index 1267eb6796d..6266d7d7b3a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ThumbnailFieldsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ThumbnailFieldsLoader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; @@ -72,16 +73,17 @@ public class ThumbnailFieldsLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param images The ImageData objects for the images whose * thumbnails have to be fetched. * Mustn't be null. * @param row The row identifying the well. * @param column The column identifying the well. */ - public ThumbnailFieldsLoader(DataBrowser viewer, + public ThumbnailFieldsLoader(DataBrowser viewer, SecurityContext ctx, Collection images, int row, int column) { - super(viewer); + super(viewer, ctx); if (images == null) throw new IllegalArgumentException("Collection shouldn't be null."); this.images = images; @@ -96,7 +98,7 @@ public ThumbnailFieldsLoader(DataBrowser viewer, public void load() { long userID = DataBrowserAgent.getUserDetails().getId(); - handle = hiBrwView.loadThumbnails(images, + handle = hiBrwView.loadThumbnails(ctx, images, ThumbnailProvider.THUMB_MAX_WIDTH, ThumbnailProvider.THUMB_MAX_HEIGHT, userID, ThumbnailLoader.IMAGE, this); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ThumbnailLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ThumbnailLoader.java index 8d6c12d73c6..52a591ab4ba 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ThumbnailLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/ThumbnailLoader.java @@ -35,6 +35,7 @@ import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.model.ThumbnailData; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.HierarchyBrowsingView; import pojos.DataObject; @@ -102,13 +103,14 @@ public class ThumbnailLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param objects The DataObjects associated to the images * to fetch. Mustn't be null. */ - public ThumbnailLoader(DataBrowser viewer, Collection objects, - int type) + public ThumbnailLoader(DataBrowser viewer, SecurityContext ctx, + Collection objects, int type) { - this(viewer, objects, true, type); + this(viewer, ctx, objects, true, type); } /** @@ -116,12 +118,14 @@ public ThumbnailLoader(DataBrowser viewer, Collection objects, * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param objects The DataObjects associated to the images * to fetch. Mustn't be null. */ - public ThumbnailLoader(DataBrowser viewer, Collection objects) + public ThumbnailLoader(DataBrowser viewer, SecurityContext ctx, + Collection objects) { - this(viewer, objects, true, IMAGE); + this(viewer, ctx, objects, true, IMAGE); } /** @@ -129,16 +133,17 @@ public ThumbnailLoader(DataBrowser viewer, Collection objects) * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param objects The DataObjects associated to the images * to fetch. Mustn't be null. * @param thumbnail Pass true to retrieve image at a thumbnail * size, false otherwise. * @param type The type of thumbnails to load. */ - public ThumbnailLoader(DataBrowser viewer, Collection objects, - boolean thumbnail, int type) + public ThumbnailLoader(DataBrowser viewer, SecurityContext ctx, + Collection objects, boolean thumbnail, int type) { - super(viewer); + super(viewer, ctx); if (objects == null) throw new IllegalArgumentException("Collection shouldn't be null."); if (type < 0) this.type = IMAGE; @@ -156,12 +161,12 @@ public void load() { long userID = DataBrowserAgent.getUserDetails().getId(); if (thumbnail) - handle = hiBrwView.loadThumbnails(objects, + handle = hiBrwView.loadThumbnails(ctx, objects, ThumbnailProvider.THUMB_MAX_WIDTH, ThumbnailProvider.THUMB_MAX_HEIGHT, userID, type, this); else - handle = hiBrwView.loadThumbnails(objects, + handle = hiBrwView.loadThumbnails(ctx, objects, 3*ThumbnailProvider.THUMB_MAX_WIDTH, 3*ThumbnailProvider.THUMB_MAX_HEIGHT, userID, type, this); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/actions/MoveToAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/actions/MoveToAction.java new file mode 100644 index 00000000000..d605db1a77e --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/actions/MoveToAction.java @@ -0,0 +1,139 @@ +/* + * org.openmicroscopy.shoola.agents.treeviewer.actions.MoveToAction + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.agents.dataBrowser.actions; + + + +//Java imports +import java.awt.event.ActionEvent; +import java.util.List; + +import javax.swing.Action; +import javax.swing.Icon; + + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.agents.dataBrowser.DataBrowserAgent; +import org.openmicroscopy.shoola.agents.dataBrowser.IconManager; +import org.openmicroscopy.shoola.agents.dataBrowser.browser.Browser; +import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.agents.events.treeviewer.MoveToEvent; +import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.util.ui.UIUtilities; + +import pojos.DataObject; +import pojos.GroupData; + +/** + * Indicates to move the data to the selected group. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class MoveToAction + extends DataBrowserAction +{ + + /** The name of the action.*/ + public static final String NAME = "Move to"; + + /** The name of the action.*/ + public static final String DESCRIPTION = "Select the group where to" + + " move the data."; + + /** The group to move the data to.*/ + private GroupData group; + + /** + * Sets the icon and tool tip text according to the permissions of the + * group. + */ + private void setPermissions() + { + IconManager im = IconManager.getInstance(); + Icon icon = im.getIcon(IconManager.PERSONAL); + int level = + DataBrowserAgent.getRegistry().getAdminService().getPermissionLevel( + group); + String desc = ""; + switch (level) { + case AdminObject.PERMISSIONS_PRIVATE: + desc = AdminObject.PERMISSIONS_PRIVATE_TEXT; + icon = im.getIcon(IconManager.PRIVATE_GROUP); + break; + case AdminObject.PERMISSIONS_GROUP_READ: + desc = AdminObject.PERMISSIONS_GROUP_READ_TEXT; + icon = im.getIcon(IconManager.READ_GROUP); + break; + case AdminObject.PERMISSIONS_GROUP_READ_LINK: + desc = AdminObject.PERMISSIONS_GROUP_READ_LINK_TEXT; + icon = im.getIcon(IconManager.READ_LINK_GROUP); + break; + case AdminObject.PERMISSIONS_PUBLIC_READ: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_TEXT; + icon = im.getIcon(IconManager.PUBLIC_GROUP); + break; + case AdminObject.PERMISSIONS_PUBLIC_READ_WRITE: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_WRITE_TEXT; + icon = im.getIcon(IconManager.PUBLIC_GROUP); + } + + putValue(Action.SMALL_ICON, icon); + putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(desc)); + } + + /** + * Creates a new instance. + * + * @param model Reference to the Model. Mustn't be null. + * @param group The selected group. + */ + public MoveToAction(DataBrowser model, GroupData group) + { + super(model); + if (group == null) + throw new IllegalArgumentException("No group."); + this.group = group; + setEnabled(true); + putValue(Action.NAME, group.getName()+"..."); + setPermissions(); + } + + /** + * Moves the selected objects to the group. + * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + Browser b = model.getBrowser(); + if (b == null) return; + MoveToEvent evt = new MoveToEvent(group, (List) + b.getSelectedDataObjects()); + DataBrowserAgent.getRegistry().getEventBus().post(evt); + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/actions/TaggingAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/actions/TaggingAction.java index df8c78c0912..f583863325f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/actions/TaggingAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/actions/TaggingAction.java @@ -25,6 +25,11 @@ //Java imports import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + import javax.swing.Action; //Third-party libraries @@ -35,6 +40,7 @@ import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.DataObject; import pojos.DatasetData; import pojos.ImageData; import pojos.PlateData; @@ -74,11 +80,22 @@ protected void onDisplayChange(ImageDisplay node) setEnabled(false); return; } - Object object = node.getHierarchyObject(); - if (object instanceof ImageData || object instanceof DatasetData || - object instanceof ProjectData || object instanceof ScreenData || - object instanceof PlateData) { - setEnabled(model.isWritable(object)); + Object ho = node.getHierarchyObject(); + if (ho instanceof ImageData || ho instanceof DatasetData || + ho instanceof ProjectData || ho instanceof ScreenData || + ho instanceof PlateData) { + if (model.isWritable(ho)) { + Collection l = model.getBrowser().getSelectedDataObjects(); + List ids = new ArrayList(); + Iterator i = l.iterator(); + DataObject data; + while (i.hasNext()) { + data = (DataObject) i.next(); + if (!ids.contains(data.getGroupId())) + ids.add(data.getGroupId()); + } + setEnabled(ids.size() == 1); + } else setEnabled(false); } else setEnabled(false); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/BrowserControl.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/BrowserControl.java index c4224bd0771..8c6e61fcf29 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/BrowserControl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/BrowserControl.java @@ -530,7 +530,7 @@ public void mousePressed(MouseEvent me) ctrl = me.isControlDown(); if (UIUtilities.isMacOS()) ctrl = me.isMetaDown(); leftMouseButton = SwingUtilities.isLeftMouseButton(me); - if (UIUtilities.isMacOS() || UIUtilities.isLinuxOS()) + if (!UIUtilities.isWindowsOS()) onClick(me, false); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/BrowserModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/BrowserModel.java index dba496f12ea..e2eeef86d44 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/BrowserModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/BrowserModel.java @@ -263,33 +263,40 @@ void setSelectedCell(CellDisplay cell) String currentPathString(ImageDisplay parent) { StringBuffer buf = new StringBuffer(); - StringBuffer titleBuf = new StringBuffer(); + List titleBuf = new ArrayList(); while (parent != null && !(parent instanceof RootDisplay)) { if (parent instanceof CellDisplay) { int type = ((CellDisplay) parent).getType(); if (type == CellDisplay.TYPE_HORIZONTAL) - titleBuf.append("column: "+parent.getTitle()); - else titleBuf.append("row: "+parent.getTitle()); + titleBuf.add("column: "+parent.getTitle()); + else titleBuf.add("row: "+parent.getTitle()); } else if (parent instanceof WellImageSet) { WellImageSet wiNode = (WellImageSet) parent; - titleBuf.append(wiNode.getTitle()); + titleBuf.add(wiNode.getTitle()); } else if (parent instanceof WellSampleNode) { Object o = ((WellSampleNode) parent).getParentObject(); if (o instanceof WellData) { - titleBuf.append(((WellData) o).getPlate().getName()); - if (titleBuf.length() != 0) - titleBuf.append(" > "); - titleBuf.append(parent.getTitle()); - if (titleBuf.length() == 0) titleBuf.append("[..]"); + titleBuf.add(((WellData) o).getPlate().getName()); + //if (titleBuf.s() != 0) + // titleBuf.append(" > "); + titleBuf.add(parent.getTitle()); + if (titleBuf.size() == 0) titleBuf.add("[..]"); + //if (titleBuf.length() == 0) titleBuf.append("[..]"); } } else { - titleBuf.append(parent.getTitle()); - if (titleBuf.length() == 0) titleBuf.append("[..]"); - if (parent instanceof ImageSet) buf.insert(0, " > "); + //titleBuf.append(parent.getTitle()); + titleBuf.add(parent.getTitle()); + //if (titleBuf.length() == 0) titleBuf.append("[..]"); + //if (parent instanceof ImageSet) buf.insert(0, " > "); } - buf.insert(0, titleBuf.toString()); + //buf.insert(0, titleBuf.toString()); parent = parent.getParentDisplay(); } + int n = titleBuf.size(); + for (int i = 0; i < n; i++) { + buf.append(titleBuf.get(n-1-i)); + if (i != (n-1)) buf.append(">"); + } return buf.toString(); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/ImageSet.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/ImageSet.java index c0b8ac5fbfc..00b5bc802b8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/ImageSet.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/browser/ImageSet.java @@ -22,10 +22,10 @@ */ package org.openmicroscopy.shoola.agents.dataBrowser.browser; -import java.awt.event.KeyListener; //Java imports +import java.awt.event.KeyListener; //Third-party libraries diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledgreen16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledgreen16.png new file mode 100644 index 00000000000..08b9c9d4d00 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledgreen16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledorange16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledorange16.png new file mode 100644 index 00000000000..f8545721c98 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledorange16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledorange_readLink16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledorange_readLink16.png new file mode 100644 index 00000000000..4d35a7cad83 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledorange_readLink16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledorange_readOnly16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledorange_readOnly16.png new file mode 100644 index 00000000000..ab94ebb4cc3 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledorange_readOnly16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledred16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledred16.png new file mode 100644 index 00000000000..bdb53d4e571 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_ledred16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_personal16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_personal16.png new file mode 100644 index 00000000000..4aeaa1d3b6f Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/graphx/nuvola_personal16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserComponent.java index 4a79e23ec0f..d7b73c6d66e 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserComponent.java @@ -68,6 +68,7 @@ import org.openmicroscopy.shoola.env.data.model.TableResult; import org.openmicroscopy.shoola.env.data.model.ThumbnailData; import org.openmicroscopy.shoola.env.data.util.FilterContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StructuredDataResults; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -1545,6 +1546,18 @@ public void viewDisplay(ImageDisplay node) Object go; ViewImageObject object; if (uo instanceof ImageData) { + if (model instanceof SearchModel) { + ImageData img = (ImageData) uo; + SecurityContext ctx = new SecurityContext(img.getGroupId()); + object = new ViewImageObject(img); + go = view.getParentOfNodes(); + if (go instanceof DataObject) + data = (DataObject) go; + object.setContext(data, null); + bus.post(new ViewImage(ctx, object, null)); + } else { + firePropertyChange(VIEW_IMAGE_NODE_PROPERTY, null, uo); + } /* object = new ViewImageObject((ImageData) uo); go = view.getParentOfNodes(); @@ -1554,18 +1567,19 @@ public void viewDisplay(ImageDisplay node) bus.post(new ViewImage(object, null)); if (go instanceof DataObject) data = (DataObject) go; */ - firePropertyChange(VIEW_IMAGE_NODE_PROPERTY, null, uo); + } else if (uo instanceof WellSampleData) { object = new ViewImageObject((WellSampleData) uo); WellSampleNode wsn = (WellSampleNode) node; Object parent = wsn.getParentObject(); + if (parent instanceof DataObject) { go = view.getGrandParentOfNodes(); if (go instanceof DataObject) data = (DataObject) go; object.setContext((DataObject) parent, data); } - bus.post(new ViewImage(object, null)); + bus.post(new ViewImage(model.getSecurityContext(), object, null)); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserControl.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserControl.java index 305e9e06c20..59e33b39007 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserControl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserControl.java @@ -43,10 +43,12 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.agents.dataBrowser.DataBrowserAgent; import org.openmicroscopy.shoola.agents.dataBrowser.actions.CreateExperimentAction; import org.openmicroscopy.shoola.agents.dataBrowser.actions.FieldsViewAction; import org.openmicroscopy.shoola.agents.dataBrowser.actions.ManageObjectAction; import org.openmicroscopy.shoola.agents.dataBrowser.actions.ManageRndSettingsAction; +import org.openmicroscopy.shoola.agents.dataBrowser.actions.MoveToAction; import org.openmicroscopy.shoola.agents.dataBrowser.actions.RefreshAction; import org.openmicroscopy.shoola.agents.dataBrowser.actions.SaveAction; import org.openmicroscopy.shoola.agents.dataBrowser.actions.SendFeedbackAction; @@ -62,6 +64,7 @@ import org.openmicroscopy.shoola.agents.dataBrowser.util.FilteringDialog; import org.openmicroscopy.shoola.agents.dataBrowser.util.QuickFiltering; import org.openmicroscopy.shoola.agents.util.SelectionWizard; +import org.openmicroscopy.shoola.agents.util.ViewerSorter; import org.openmicroscopy.shoola.agents.util.ui.EditorDialog; import org.openmicroscopy.shoola.agents.util.ui.RollOverThumbnailManager; import org.openmicroscopy.shoola.env.data.model.ApplicationData; @@ -73,6 +76,7 @@ import org.openmicroscopy.shoola.util.ui.search.SearchObject; import pojos.DataObject; import pojos.DatasetData; +import pojos.GroupData; /** * The DataBrowser's Controller. @@ -158,6 +162,9 @@ class DataBrowserControl /** Maps actions ids onto actual Action object. */ private Map actionsMap; + /** One per group.*/ + private List moveActions; + /** Helper method to create all the UI actions. */ private void createActions() { @@ -309,6 +316,25 @@ void initialize(DataBrowser model, DataBrowserUI view) */ Action getAction(Integer id) { return actionsMap.get(id); } + /** + * Returns the actions used to move data between groups. + * + * @return See abo.ve + */ + List getMoveAction() + { + if (moveActions != null) return moveActions; + Set l = DataBrowserAgent.getAvailableUserGroups(); + ViewerSorter sorter = new ViewerSorter(); + List values = sorter.sort(l); + moveActions = new ArrayList(l.size()); + Iterator i = values.iterator(); + while (i.hasNext()) { + moveActions.add(new MoveToAction(model, (GroupData) i.next())); + } + return moveActions; + } + /** * Views the selected well sample field while browsing a plate. * diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserFactory.java index 1a36b80d6f4..32037ee2511 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserFactory.java @@ -35,11 +35,9 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; - -import omero.model.PlateAcquisition; - import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; //Third-party libraries @@ -103,8 +101,8 @@ public static final void discardAll() * @param result The value to set. * @return See above. */ - public static final DataBrowser getSearchBrowser(Collection - result) + public static final DataBrowser getSearchBrowser( + Map> result) { return singleton.createSearchDataBrowser(result); } @@ -122,6 +120,7 @@ public static final DataBrowser getSearchBrowser() /** * Creates a new {@link DataBrowser} for the passed collection of images. * + * @param ctx The security context. * @param ancestors Map containing the ancestors of the node. * @param parent The parent's node. * @param wells The collection to set. @@ -129,84 +128,93 @@ public static final DataBrowser getSearchBrowser() * false otherwise. * @return See above. */ - public static final DataBrowser getWellsDataBrowser(Map - ancestors, Object parent, Set wells, boolean withThumbnails) + public static final DataBrowser getWellsDataBrowser( + SecurityContext ctx, Map ancestors, Object parent, + Set wells, boolean withThumbnails) { - return singleton.createWellsDataBrowser(ancestors, parent, wells, + return singleton.createWellsDataBrowser(ctx, ancestors, parent, wells, withThumbnails); } /** * Creates a new {@link DataBrowser} for the passed collection of images. * + * @param ctx The security context. * @param grandParent The grandparent of the node. * @param parent The parent's node. * @param images The collection to set. * @param node The node to handle. * @return See above. */ - public static final DataBrowser getDataBrowser(Object grandParent, + public static final DataBrowser getDataBrowser( + SecurityContext ctx, Object grandParent, Object parent, Collection images, TreeImageDisplay node) { - return singleton.createImagesDataBrowser(grandParent, parent, images, - node); + return singleton.createImagesDataBrowser(ctx, grandParent, parent, + images, node); } /** * Creates a new {@link DataBrowser} for the passed collection of images. * + * @param ctx The security context. * @param parent The parent's node. * @param nodes The collection to set. * @param withImages Pass true to indicate that the images * are loaded, false otherwise. * @return See above. */ - public static final DataBrowser getTagsBrowser(TagAnnotationData parent, + public static final DataBrowser getTagsBrowser( + SecurityContext ctx, TagAnnotationData parent, Collection nodes, boolean withImages) { - return singleton.createTagsDataBrowser(parent, nodes, withImages); + return singleton.createTagsDataBrowser(ctx, parent, nodes, withImages); } /** * Creates a new {@link DataBrowser} for the passed collection of * experimenters. * + * @param ctx The security context. * @param parent The parent's node. * @param experimenters The collection to set. * @return See above. */ - public static final DataBrowser getGroupsBrowser(GroupData parent, - Collection experimenters) + public static final DataBrowser getGroupsBrowser( + SecurityContext ctx, GroupData parent, + Collection experimenters) { - return singleton.createGroupsBrowser(parent, experimenters); + return singleton.createGroupsBrowser(ctx, parent, experimenters); } /** * Creates a new {@link DataBrowser} for the passed collection of * files. * + * @param ctx The security context. * @param parent The parent's node. * @param experimenters The collection to set. * @return See above. */ - public static final DataBrowser getFSFolderBrowser(FileData parent, - Collection files) + public static final DataBrowser getFSFolderBrowser( + SecurityContext ctx, FileData parent, Collection files) { - return singleton.createFSFolderBrowser(parent, files); + return singleton.createFSFolderBrowser(ctx, parent, files); } /** * Creates a new {@link DataBrowser} for the passed collection of datasets. * + * @param ctx The security context. * @param parent The parent's node. * @param nodes The collection to set. * @return See above. */ - public static final DataBrowser getDataBrowser(ProjectData parent, - Set nodes) + public static final DataBrowser getDataBrowser(SecurityContext ctx, + ProjectData parent, Set nodes) { - return singleton.createDatasetsDataBrowser(parent, nodes); + return singleton.createDatasetsDataBrowser(ctx, parent, nodes); } /** @@ -389,6 +397,7 @@ private DataBrowserFactory() /** * Creates a new {@link DataBrowser} for the passed collection of wells. * + * @param ctx The security context. * @param ancestors Map containing the ancestors of the node. * @param parent The parent's node. * @param wells The collection to set. @@ -396,7 +405,8 @@ private DataBrowserFactory() * false otherwise. * @return See above. */ - private DataBrowser createWellsDataBrowser(Map ancestors, + private DataBrowser createWellsDataBrowser(SecurityContext ctx, + Map ancestors, Object parent, Set wells, boolean withThumbnails) { Object p = parent; @@ -415,7 +425,7 @@ private DataBrowser createWellsDataBrowser(Map ancestors, break; } } - DataBrowserModel model = new WellsModel(p, wells, withThumbnails); + DataBrowserModel model = new WellsModel(ctx, p, wells, withThumbnails); model.setGrandParent(go); DataBrowserComponent comp = new DataBrowserComponent(model); model.initialize(comp); @@ -440,17 +450,19 @@ private DataBrowser createWellsDataBrowser(Map ancestors, /** * Creates a new {@link DataBrowser} for the passed collection of images. * + * @param ctx The security context. * @param grandParent The grandParent of the node. * @param parent The parent's node. * @param images The collection to set. * @param experimenter The experimenter associated to the node. * @return See above. */ - private DataBrowser createImagesDataBrowser(Object grandParent, + private DataBrowser createImagesDataBrowser( + SecurityContext ctx, Object grandParent, Object parent, Collection images, TreeImageDisplay node) { - DataBrowserModel model = new ImagesModel(parent, images); + DataBrowserModel model = new ImagesModel(ctx, parent, images); model.setGrandParent(grandParent); DataBrowserComponent comp = new DataBrowserComponent(model); model.initialize(comp); @@ -466,14 +478,15 @@ private DataBrowser createImagesDataBrowser(Object grandParent, /** * Creates a new {@link DataBrowser} for the passed collection of datasets. * + * @param ctx The security context. * @param parent The parent's node. * @param datasets The collection to set. * @return See above. */ - private DataBrowser createDatasetsDataBrowser(DataObject parent, - Set datasets) + private DataBrowser createDatasetsDataBrowser(SecurityContext ctx, + DataObject parent, Set datasets) { - DataBrowserModel model = new DatasetsModel(parent, datasets); + DataBrowserModel model = new DatasetsModel(ctx, parent, datasets); DataBrowserComponent comp = new DataBrowserComponent(model); model.initialize(comp); comp.initialize(); @@ -499,16 +512,19 @@ private DataBrowser createDatasetsDataBrowser(DataObject parent, /** * Creates a new {@link DataBrowser} for the passed collection of tags. * + * @param ctx The security context. * @param parent The parent's node. * @param dataObjects The collection to set. * @param withImages Pass true to indicate that the images * are loaded, false otherwise. * @return See above. */ - private DataBrowser createTagsDataBrowser(DataObject parent, - Collection dataObjects, boolean withImages) + private DataBrowser createTagsDataBrowser(SecurityContext ctx, + DataObject parent, Collection dataObjects, + boolean withImages) { - DataBrowserModel model = new TagsModel(parent, dataObjects, withImages); + DataBrowserModel model = new TagsModel(ctx, parent, dataObjects, + withImages); DataBrowserComponent comp = new DataBrowserComponent(model); model.initialize(comp); comp.initialize(); @@ -521,14 +537,15 @@ private DataBrowser createTagsDataBrowser(DataObject parent, * Creates a new {@link DataBrowser} for the passed collection of * experimenters. * + * @param ctx The security context. * @param parent The parent's node. * @param experimenters The collection to set. * @return See above. */ - private DataBrowser createGroupsBrowser(GroupData parent, - Collection experimenters) + private DataBrowser createGroupsBrowser(SecurityContext ctx, + GroupData parent, Collection experimenters) { - DataBrowserModel model = new GroupModel(parent, experimenters); + DataBrowserModel model = new GroupModel(ctx, parent, experimenters); DataBrowserComponent comp = new DataBrowserComponent(model); model.initialize(comp); comp.initialize(); @@ -540,14 +557,15 @@ private DataBrowser createGroupsBrowser(GroupData parent, /** * Creates a new {@link DataBrowser} for the passed collection of files. * + * @param ctx The security context. * @param parent The parent's node. * @param files The collection to set. * @return See above. */ - private DataBrowser createFSFolderBrowser(FileData parent, - Collection files) + private DataBrowser createFSFolderBrowser(SecurityContext ctx, + FileData parent, Collection files) { - DataBrowserModel model = new FSFolderModel(parent, files); + DataBrowserModel model = new FSFolderModel(ctx, parent, files); DataBrowserComponent comp = new DataBrowserComponent(model); model.initialize(comp); comp.initialize(); @@ -559,11 +577,11 @@ private DataBrowser createFSFolderBrowser(FileData parent, /** * Creates a new {@link DataBrowser} for the passed result. * - * @param result The result of the search. + * @param result The result of the search. * @return See above. */ - private DataBrowser createSearchDataBrowser(Collection - result) + private DataBrowser createSearchDataBrowser( + Map> result) { DataBrowserModel model = new SearchModel(result); DataBrowserComponent comp = new DataBrowserComponent(model); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserModel.java index 8636c6207d9..14bd500fd6d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserModel.java @@ -57,7 +57,6 @@ import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageNode; import org.openmicroscopy.shoola.agents.dataBrowser.layout.Layout; import org.openmicroscopy.shoola.agents.dataBrowser.layout.LayoutFactory; -import org.openmicroscopy.shoola.agents.dataBrowser.layout.LayoutUtils; import org.openmicroscopy.shoola.agents.dataBrowser.visitor.ResetThumbnailVisitor; import org.openmicroscopy.shoola.agents.metadata.MetadataViewerAgent; import org.openmicroscopy.shoola.agents.util.EditorUtil; @@ -66,6 +65,8 @@ import org.openmicroscopy.shoola.env.data.model.ApplicationData; import org.openmicroscopy.shoola.env.data.model.TableResult; import org.openmicroscopy.shoola.env.data.util.FilterContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.DataObject; import pojos.DatasetData; import pojos.ExperimenterData; @@ -130,7 +131,7 @@ abstract class DataBrowserModel static final int FS_FOLDER = 9; /** Holds one of the state flags defined by {@link DataBrowser}. */ - private int state; + protected int state; /** Maps an image id to the list of thumbnail providers for that image. */ private ThumbnailsManager thumbsManager; @@ -183,11 +184,19 @@ abstract class DataBrowserModel /** The grandparent of the node. Used as back pointer. */ protected Object grandParent; - /** Creates a new instance. */ - DataBrowserModel() + /** The security context.*/ + protected SecurityContext ctx; + + /** + * Creates a new instance. + * + * @param ctx The security context. + */ + DataBrowserModel(SecurityContext ctx) { sorter = new ViewerSorter(); - state = DataBrowser.NEW; + state = DataBrowser.NEW; + this.ctx = ctx; } /** @@ -431,7 +440,7 @@ void cancelSlideShow() void fireFilteringByRate(int rate, Set nodes) { state = DataBrowser.FILTERING; - RateFilter loader = new RateFilter(component, rate, nodes); + RateFilter loader = new RateFilter(component, ctx, rate, nodes); loader.load(); } @@ -444,7 +453,7 @@ void fireFilteringByRate(int rate, Set nodes) void fireFilteringByTags(List tags, Set nodes) { state = DataBrowser.FILTERING; - TagsFilter loader = new TagsFilter(component, tags, nodes); + TagsFilter loader = new TagsFilter(component, ctx, tags, nodes); loader.load(); } @@ -457,7 +466,8 @@ void fireFilteringByTags(List tags, Set nodes) void fireFilteringByComments(List comments, Set nodes) { state = DataBrowser.FILTERING; - CommentsFilter loader = new CommentsFilter(component, comments, nodes); + CommentsFilter loader = new CommentsFilter(component, ctx, comments, + nodes); loader.load(); } @@ -470,7 +480,7 @@ void fireFilteringByComments(List comments, Set nodes) void fireFilteringByContext(FilterContext context, Set nodes) { state = DataBrowser.FILTERING; - DataFilter loader = new DataFilter(component, context, nodes); + DataFilter loader = new DataFilter(component, ctx, context, nodes); loader.load(); } @@ -488,8 +498,8 @@ void fireFilteringByAnnotated(Class annotationType, boolean annotated, Set nodes) { state = DataBrowser.FILTERING; - AnnotatedFilter loader = new AnnotatedFilter(component, annotationType, - annotated, nodes); + AnnotatedFilter loader = new AnnotatedFilter(component, ctx, + annotationType, annotated, nodes); loader.load(); } @@ -497,14 +507,14 @@ void fireFilteringByAnnotated(Class annotationType, boolean annotated, void fireTagsLoading() { state = DataBrowser.LOADING; - TagsLoader loader = new TagsLoader(component); + TagsLoader loader = new TagsLoader(component, ctx); loader.load(); } /** Starts an asynchronous call to load the existing datasets. */ void fireExisitingDatasetsLoading() { - DatasetsLoader loader = new DatasetsLoader(component); + DatasetsLoader loader = new DatasetsLoader(component, ctx); loader.load(); } @@ -529,9 +539,8 @@ void fireFullSizeLoading(Collection images) if (nodes.size() > 0) { fullSizeThumbsManager = new ThumbnailsManager(toKeep, toKeep.size()); - ThumbnailLoader loader = new ThumbnailLoader(component, nodes, - false, - ThumbnailLoader.IMAGE); + ThumbnailLoader loader = new ThumbnailLoader(component, ctx, + nodes, false, ThumbnailLoader.IMAGE); loader.load(); state = DataBrowser.LOADING_SLIDE_VIEW; } @@ -561,8 +570,8 @@ void fireDataSaving(DataObject data, Collection images) p = null; } } - DataObjectCreator loader = new DataObjectCreator(component, p, data, - images); + DataObjectCreator loader = new DataObjectCreator(component, ctx, + p, data, images); loader.load(); } @@ -574,7 +583,7 @@ void fireDataSaving(DataObject data, Collection images) */ void fireDataSaving(Collection datasets, Collection images) { - DataObjectSaver loader = new DataObjectSaver(component, datasets, + DataObjectSaver loader = new DataObjectSaver(component, ctx, datasets, images); loader.load(); } @@ -589,7 +598,7 @@ void fireDataSaving(Collection datasets, Collection images) void fireReportLoading(Collection images, List types, String name) { - ReportLoader loader = new ReportLoader(component, types, + ReportLoader loader = new ReportLoader(component, ctx, types, sorter.sort(images), name); loader.load(); } @@ -743,10 +752,10 @@ void fireTabularDataLoading(List data) if (data == null) { if (this instanceof WellsModel) { if (grandParent instanceof ScreenData) { - loader = new TabularDataLoader(component, + loader = new TabularDataLoader(component, ctx, (DataObject) grandParent); } else if (parent instanceof PlateData) { - loader = new TabularDataLoader(component, + loader = new TabularDataLoader(component, ctx, (DataObject) parent); } } @@ -758,7 +767,7 @@ void fireTabularDataLoading(List data) fa = i.next(); ids.add(fa.getFileID()); } - loader = new TabularDataLoader(component, ids); + loader = new TabularDataLoader(component, ctx, ids); } if (loader != null) loader.load(); } @@ -789,6 +798,25 @@ int getLayoutIndex() return layout.getIndex(); } + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext() { return ctx; } + + /** + * Returns true if the user belongs to only one group, + * false otherwise. + * + * @return See above. + */ + boolean isSingleGroup() + { + Set l = DataBrowserAgent.getAvailableUserGroups(); + return l.size() <= 1; + } + /** * Creates a data loader that can retrieve the hierarchy objects needed * by this model. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserUI.java index 1bfd8b8b4fe..c639c8b7698 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DataBrowserUI.java @@ -532,7 +532,9 @@ void viewSelectedNode() if (!(node instanceof ImageNode)) return; ImageData data = (ImageData) node.getHierarchyObject(); EventBus bus = DataBrowserAgent.getRegistry().getEventBus(); - bus.post(new ViewImage(new ViewImageObject(data), null)); + + bus.post(new ViewImage(model.getSecurityContext(), + new ViewImageObject(data), null)); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DatasetsModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DatasetsModel.java index f0c86cf8588..7101ad2c314 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DatasetsModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/DatasetsModel.java @@ -41,6 +41,8 @@ import org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageDisplay; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageNode; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.DatasetData; import pojos.ImageData; @@ -65,12 +67,13 @@ class DatasetsModel /** * Creates a new instance. * + * @param ctx The security context. * @param parent The parent of the datasets. * @param datasets The collection to datasets the model is for. */ - DatasetsModel(Object parent, Set datasets) + DatasetsModel(SecurityContext ctx, Object parent, Set datasets) { - super(); + super(ctx); if (datasets == null) throw new IllegalArgumentException("No datasets."); this.parent = parent; @@ -97,9 +100,7 @@ class DatasetsModel img.getDefaultPixels(); ids.add(img.getId()); numberOfImages++; - } catch (Exception e) { - - } + } catch (Exception e) {} } } } @@ -154,13 +155,12 @@ protected DataBrowserLoader createDataLoader(boolean refresh, loaded.add(img.getId()); imagesLoaded++; } catch (Exception e) {} - } } } } if (imgs.size() == 0) return null; - return new ThumbnailLoader(component, sorter.sort(imgs)); + return new ThumbnailLoader(component, ctx, sorter.sort(imgs)); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/FSFolderModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/FSFolderModel.java index 1c8d34f9fad..87b29388bc2 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/FSFolderModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/FSFolderModel.java @@ -38,6 +38,8 @@ import org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageDisplay; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageNode; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.DataObject; import pojos.ImageData; import pojos.MultiImageData; @@ -62,12 +64,14 @@ class FSFolderModel /** * Creates a new instance. * + * @param ctx The security context. * @param parent The parent of the experimenters. * @param datasets The collection to experimenters the model is for. */ - FSFolderModel(Object parent, Collection files) + FSFolderModel(SecurityContext ctx, Object parent, + Collection files) { - super(); + super(ctx); if (files == null) throw new IllegalArgumentException("No files."); this.parent = parent; @@ -151,7 +155,7 @@ protected DataBrowserLoader createDataLoader(boolean refresh, } } if (imgs.size() == 0) return null; - return new ThumbnailLoader(component, sorter.sort(imgs), + return new ThumbnailLoader(component, ctx, sorter.sort(imgs), ThumbnailLoader.FS_FILE); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/GroupModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/GroupModel.java index d9fb29af674..ce19325245b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/GroupModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/GroupModel.java @@ -39,6 +39,8 @@ import org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageDisplay; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageNode; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.DataObject; import pojos.ExperimenterData; import pojos.ImageData; @@ -63,13 +65,15 @@ class GroupModel /** * Creates a new instance. - * + * + * @param ctx The security context. * @param parent The parent of the experimenters. * @param datasets The collection to experimenters the model is for. */ - GroupModel(Object parent, Collection experimenters) + GroupModel(SecurityContext ctx, Object parent, + Collection experimenters) { - super(); + super(ctx); if (experimenters == null) throw new IllegalArgumentException("No experimenters."); this.parent = parent; @@ -132,7 +136,7 @@ protected DataBrowserLoader createDataLoader(boolean refresh, } } if (imgs.size() == 0) return null; - return new ThumbnailLoader(component, sorter.sort(imgs), + return new ThumbnailLoader(component, ctx, sorter.sort(imgs), ThumbnailLoader.EXPERIMENTER); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/ImagesModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/ImagesModel.java index 129a62a36ec..3936fe26dcb 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/ImagesModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/ImagesModel.java @@ -39,6 +39,8 @@ import org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageDisplay; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageNode; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.ImageData; /** @@ -64,12 +66,14 @@ class ImagesModel /** * Creates a new instance. * + * @param ctx The security context. * @param parent The parent. * @param images The collection to images the model is for. */ - ImagesModel(Object parent, Collection images) + ImagesModel(SecurityContext ctx, Object parent, + Collection images) { - super(); + super(ctx); if (images == null) throw new IllegalArgumentException("No images."); this.images = images; @@ -131,7 +135,7 @@ protected DataBrowserLoader createDataLoader(boolean refresh, } } if (imgs.size() == 0) return null; - return new ThumbnailLoader(component, sorter.sort(imgs)); + return new ThumbnailLoader(component, ctx, sorter.sort(imgs)); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/PlatesModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/PlatesModel.java index 34d24f43402..857fc5aad53 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/PlatesModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/PlatesModel.java @@ -38,6 +38,8 @@ import org.openmicroscopy.shoola.agents.dataBrowser.DataBrowserTranslator; import org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageDisplay; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.PlateData; /** @@ -60,12 +62,13 @@ class PlatesModel /** * Creates a new instance. * + * @param ctx The security context. * @param parent The parent of the plates. * @param datasets The collection to plates the model is for. */ - PlatesModel(Object parent, Set plates) + PlatesModel(SecurityContext ctx, Object parent, Set plates) { - super(); + super(ctx); if (plates == null) throw new IllegalArgumentException("No plates."); this.parent = parent; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/PopupMenu.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/PopupMenu.java index a5d44240703..885b99042d5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/PopupMenu.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/PopupMenu.java @@ -26,7 +26,6 @@ //Java imports import java.util.Iterator; import java.util.List; - import javax.swing.BorderFactory; import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -34,12 +33,13 @@ import javax.swing.JSeparator; import javax.swing.border.BevelBorder; -import org.openmicroscopy.shoola.agents.dataBrowser.IconManager; -import org.openmicroscopy.shoola.agents.dataBrowser.actions.ViewOtherAction; //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.agents.dataBrowser.IconManager; +import org.openmicroscopy.shoola.agents.dataBrowser.actions.MoveToAction; +import org.openmicroscopy.shoola.agents.dataBrowser.actions.ViewOtherAction; /** * Pop-up menu for nodes in the browser display. @@ -103,6 +103,23 @@ class PopupMenu /** Reference to the control. */ private DataBrowserControl controller; + /** + * Creates a menu if the various groups the data can be moved to. + * + * @return See above. + */ + private JMenu createMoveToMenu() + { + List actions = controller.getMoveAction(); + if (actions.size() <= 1) return null; + JMenu menu = new JMenu(MoveToAction.NAME); + Iterator i = actions.iterator(); + while (i.hasNext()) { + menu.add(new JMenuItem(i.next())); + } + return menu; + } + /** * Initializes the menu items with the given actions. * @@ -159,6 +176,8 @@ private void buildGUI() add(cutElement); add(copyElement); add(pasteElement); + JMenu m = createMoveToMenu(); + if (m != null) add(m); add(removeElement); add(new JSeparator(JSeparator.HORIZONTAL)); add(tagElement); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/ProjectsModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/ProjectsModel.java index 8f9a83fce80..2c655278748 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/ProjectsModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/ProjectsModel.java @@ -35,6 +35,8 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.DataBrowserLoader; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageDisplay; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.ProjectData; /** @@ -54,6 +56,16 @@ class ProjectsModel extends DataBrowserModel { + /** + * Creates a new instance. + * + * @param ctx The security context. + */ + ProjectsModel(SecurityContext ctx) + { + super(ctx); + } + protected DataBrowserLoader createDataLoader(boolean refresh, Collection ids) { diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/SearchModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/SearchModel.java index 51f3b615547..8f0ee72bbe0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/SearchModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/SearchModel.java @@ -26,9 +26,13 @@ //Java imports import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.Map.Entry; //Third-party libraries @@ -40,7 +44,10 @@ import org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageDisplay; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageNode; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.DataObject; +import pojos.GroupData; import pojos.ImageData; /** @@ -60,44 +67,83 @@ class SearchModel extends DataBrowserModel { - /** The images to lay out. */ - private Collection results; + /** The result to display. */ + private Map> results; + + /** + * Returns the group corresponding to the specified id. + * + * @param groupId The id of the group. + * @return See above. + */ + private GroupData getGroup(long groupId) + { + Set groups = DataBrowserAgent.getAvailableUserGroups(); + Iterator i = groups.iterator(); + GroupData g; + while (i.hasNext()) { + g = (GroupData) i.next(); + if (g.getId() == groupId) return g; + } + return null; + } /** * Creates a new instance. * * @param results The results to display. */ - SearchModel(Collection results) + SearchModel(Map> results) { - super(); + super(null); if (results == null) throw new IllegalArgumentException("No results."); this.results = results; - numberOfImages = results.size(); + numberOfImages = 0; long userID = DataBrowserAgent.getUserDetails().getId(); - Set vis = DataBrowserTranslator.transformObjects(results, userID, 0); - browser = BrowserFactory.createBrowser(vis); - //layoutBrowser(); + Set vis = new HashSet(); + Iterator i = results.entrySet().iterator(); + Entry e; + SecurityContext ctx; + GroupData g; + Collection objects; + boolean singleGroup = isSingleGroup(); + while (i.hasNext()) { + e = (Entry) i.next(); + ctx = (SecurityContext) e.getKey(); + + objects = (Collection) e.getValue(); + numberOfImages += objects.size(); + if (singleGroup) { + vis.addAll(DataBrowserTranslator.transformObjects(objects, + userID, ctx.getGroupID())); + } else { + g = getGroup(ctx.getGroupID()); + if (g != null && objects != null && objects.size() > 0) + vis.add(DataBrowserTranslator.transformObjects(objects, + userID, g)); + } + } + browser = BrowserFactory.createBrowser(vis); } /** - * Creates a concrete loader. - * @see DataBrowserModel#createDataLoader(boolean, Collection) + * Overridden to start several loaders. */ - protected DataBrowserLoader createDataLoader(boolean refresh, - Collection ids) + void loadData(boolean refresh, Collection ids) { if (refresh) imagesLoaded = 0; if (imagesLoaded != 0 && ids != null) imagesLoaded = imagesLoaded-ids.size(); - if (imagesLoaded == numberOfImages) return null; - //only load thumbnails not loaded. + if (imagesLoaded == numberOfImages) return; + Map> map = new HashMap>(); List nodes = browser.getVisibleImageNodes(); - if (nodes == null || nodes.size() == 0) return null; + if (nodes == null || nodes.size() == 0) return; Iterator i = nodes.iterator(); ImageNode node; - List imgs = new ArrayList(); + ImageData image; + long groupId; + List imgs; if (ids != null) { ImageData img; while (i.hasNext()) { @@ -105,7 +151,13 @@ protected DataBrowserLoader createDataLoader(boolean refresh, img = (ImageData) node.getHierarchyObject(); if (ids.contains(img.getId())) { if (node.getThumbnail().getFullScaleThumb() == null) { - imgs.add((ImageData) node.getHierarchyObject()); + image = (ImageData) node.getHierarchyObject(); + groupId = image.getGroupId(); + if (!map.containsKey(groupId)) { + map.put(groupId, new ArrayList()); + } + imgs = map.get(groupId); + imgs.add(image); imagesLoaded++; } } @@ -114,12 +166,38 @@ protected DataBrowserLoader createDataLoader(boolean refresh, while (i.hasNext()) { node = i.next(); if (node.getThumbnail().getFullScaleThumb() == null) { - imgs.add((ImageData) node.getHierarchyObject()); + image = (ImageData) node.getHierarchyObject(); + groupId = image.getGroupId(); + if (!map.containsKey(groupId)) { + map.put(groupId, new ArrayList()); + } + imgs = map.get(groupId); + imgs.add(image); imagesLoaded++; } } } - return new ThumbnailLoader(component, sorter.sort(imgs)); + if (map.size() == 0) return; + Entry e; + Iterator j = map.entrySet().iterator(); + DataBrowserLoader loader; + while (j.hasNext()) { + e = (Entry) j.next(); + loader = new ThumbnailLoader(component, new SecurityContext( + (Long) e.getKey()), sorter.sort((List) e.getValue())); + loader.load(); + } + state = DataBrowser.LOADING; + } + + /** + * Creates a concrete loader. + * @see DataBrowserModel#createDataLoader(boolean, Collection) + */ + protected DataBrowserLoader createDataLoader(boolean refresh, + Collection ids) + { + return null; } /** @@ -133,5 +211,5 @@ protected DataBrowserLoader createDataLoader(boolean refresh, * @see DataBrowserModel#getNodes() */ protected List getNodes() { return null; } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/SlideShowView.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/SlideShowView.java index a7f34c59532..ff7ae64feb7 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/SlideShowView.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/SlideShowView.java @@ -615,13 +615,14 @@ public void mousePressed(MouseEvent e) public void mouseReleased(MouseEvent e) { Object src = e.getSource(); + /* ImageDisplay d = findParentDisplay(src); if (d instanceof ImageNode && !(d.getTitleBar() == src) && e.getClickCount() == 2) { EventBus bus = DataBrowserAgent.getRegistry().getEventBus(); bus.post(new ViewImage(new ViewImageObject( (ImageData) d.getHierarchyObject()), null)); - } + }*/ } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/TagSetsModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/TagSetsModel.java index 9ca3d940182..4b7aacc9ba5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/TagSetsModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/TagSetsModel.java @@ -40,6 +40,7 @@ import org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageDisplay; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageNode; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import pojos.DataObject; import pojos.DatasetData; @@ -70,12 +71,14 @@ class TagSetsModel /** * Creates a new instance. * + * @param ctx The security context. * @param parent The parent of the datasets. * @param tagSets The collection to datasets the model is for. */ - TagSetsModel(Object parent, Set tagSets) + TagSetsModel(SecurityContext ctx, Object parent, + Set tagSets) { - super(); + super(ctx); if (tagSets == null) throw new IllegalArgumentException("No images."); this.tagSets = tagSets; @@ -153,7 +156,7 @@ protected DataBrowserLoader createDataLoader(boolean refresh, } } if (imgs.size() == 0) return null; - return new ThumbnailLoader(component, sorter.sort(imgs)); + return new ThumbnailLoader(component, ctx, sorter.sort(imgs)); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/TagsModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/TagsModel.java index c8c12a397ca..e423cc235cc 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/TagsModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/TagsModel.java @@ -40,6 +40,8 @@ import org.openmicroscopy.shoola.agents.dataBrowser.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageDisplay; import org.openmicroscopy.shoola.agents.dataBrowser.browser.ImageNode; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.DataObject; import pojos.DatasetData; import pojos.ImageData; @@ -68,15 +70,16 @@ public class TagsModel /** * Creates a new instance. * + * @param ctx The security context. * @param parent The parent of the datasets. * @param tagSets The collection to datasets the model is for. * @param withImages Pass true to indicate that the images * are loaded, false otherwise. */ - TagsModel(Object parent, Collection dataObjects, - boolean withImages) + TagsModel(SecurityContext ctx, Object parent, + Collection dataObjects, boolean withImages) { - super(); + super(ctx); if (dataObjects == null) throw new IllegalArgumentException("No dataObjects."); this.dataObjects = dataObjects; @@ -213,7 +216,7 @@ protected DataBrowserLoader createDataLoader(boolean refresh, } } if (imgs.size() == 0) return null; - return new ThumbnailLoader(component, sorter.sort(imgs)); + return new ThumbnailLoader(component, ctx, sorter.sort(imgs)); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/WellsModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/WellsModel.java index 4e3c1f250f3..267f246cd3b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/WellsModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/dataBrowser/view/WellsModel.java @@ -57,6 +57,7 @@ import org.openmicroscopy.shoola.agents.dataBrowser.browser.WellSampleNode; import org.openmicroscopy.shoola.agents.dataBrowser.layout.LayoutFactory; import org.openmicroscopy.shoola.env.data.model.TableResult; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.image.geom.Factory; import org.openmicroscopy.shoola.util.ui.PlateGrid; import org.openmicroscopy.shoola.util.ui.UIUtilities; @@ -229,14 +230,16 @@ private void handleCellSelection(CellDisplay cell, WellImageSet well, /** * Creates a new instance. * + * @param ctx The security context. * @param parent The parent of the wells. * @param wells The collection to wells the model is for. * @param withThumbnails Pass true to load the thumbnails, * false otherwise. */ - WellsModel(Object parent, Set wells, boolean withThumbnails) + WellsModel(SecurityContext ctx, Object parent, Set wells, + boolean withThumbnails) { - super(); + super(ctx); if (wells == null) throw new IllegalArgumentException("No wells."); this.withThumbnails = withThumbnails; @@ -501,7 +504,7 @@ void viewField(int index) plate.setDefaultSample(selectedField); List list = new ArrayList(); list.add(plate); - DataBrowserLoader loader = new PlateSaver(component, list); + DataBrowserLoader loader = new PlateSaver(component, ctx, list); loader.load(); } } @@ -553,7 +556,7 @@ void setSelectedCell(CellDisplay cell) } } if (results.size() > 0) { - DataBrowserLoader loader = new PlateSaver(component, results); + DataBrowserLoader loader = new PlateSaver(component, ctx, results); loader.load(); } } @@ -663,7 +666,7 @@ DataBrowserLoader createFieldsLoader(int row, int column) } if (images.size() == 0) return null; - return new ThumbnailFieldsLoader(component, images, row, column); + return new ThumbnailFieldsLoader(component, ctx, images, row, column); } /** @@ -699,7 +702,7 @@ protected DataBrowserLoader createDataLoader(boolean refresh, } if (images.size() == 0) return null; - return new ThumbnailLoader(component, images); + return new ThumbnailLoader(component, ctx, images); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/BrowserLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/BrowserLoader.java index b21ab7bf267..ec850341d79 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/BrowserLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/BrowserLoader.java @@ -31,6 +31,7 @@ import org.openmicroscopy.shoola.agents.editor.browser.Browser; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.MetadataHandlerView; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -60,24 +61,30 @@ public abstract class BrowserLoader { /** The browser this data loader is for. */ - protected final Browser viewer; + protected final Browser viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final MetadataHandlerView mhView; + protected final MetadataHandlerView mhView; + /** The security context.*/ + protected final SecurityContext ctx; + /** * Creates a new instance. * * @param viewer The browser this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - protected BrowserLoader(Browser viewer) + protected BrowserLoader(Browser viewer, SecurityContext ctx) { - if (viewer == null) throw new NullPointerException("No viewer."); + if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null) throw new NullPointerException("No security context."); this.viewer = viewer; + this.ctx = ctx; registry = EditorAgent.getRegistry(); mhView = (MetadataHandlerView) registry.getDataServicesView(MetadataHandlerView.class); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/EditorAgent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/EditorAgent.java index 644b30feef3..bc0aa23d7d1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/EditorAgent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/EditorAgent.java @@ -24,8 +24,11 @@ //Java imports +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; import java.util.List; +import java.util.Set; import javax.swing.JButton; import javax.swing.JMenuItem; @@ -40,6 +43,8 @@ import org.openmicroscopy.shoola.agents.events.editor.CopyEvent; import org.openmicroscopy.shoola.agents.events.editor.EditFileEvent; import org.openmicroscopy.shoola.agents.events.editor.ShowEditorEvent; +import org.openmicroscopy.shoola.agents.events.importer.LoadImporter; +import org.openmicroscopy.shoola.agents.events.treeviewer.ChangeUserGroupEvent; import org.openmicroscopy.shoola.agents.util.EditorUtil; import org.openmicroscopy.shoola.env.Agent; import org.openmicroscopy.shoola.env.Environment; @@ -50,6 +55,7 @@ import org.openmicroscopy.shoola.env.data.model.ApplicationData; import org.openmicroscopy.shoola.env.data.model.DownloadActivityParam; import org.openmicroscopy.shoola.env.data.util.AgentSaveInfo; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.AgentEvent; import org.openmicroscopy.shoola.env.event.AgentEventListener; import org.openmicroscopy.shoola.env.event.EventBus; @@ -57,6 +63,7 @@ import org.openmicroscopy.shoola.env.ui.UserNotifier; import pojos.ExperimenterData; import pojos.FileAnnotationData; +import pojos.GroupData; /** * The Editor agent. @@ -76,7 +83,10 @@ public class EditorAgent { /** Reference to the registry. */ - private static Registry registry; + private static Registry registry; + + /** The group id if set.*/ + private long groupId; /** * Helper method. @@ -96,6 +106,16 @@ public static ExperimenterData getUserDetails() LookupNames.CURRENT_USER_DETAILS); } + /** + * Returns the available user groups. + * + * @return See above. + */ + public static Set getAvailableUserGroups() + { + return (Set) registry.lookup(LookupNames.USER_GROUP_DETAILS); + } + /** * Returns true if an OMERO server is available, * false otherwise. @@ -165,14 +185,19 @@ public static String getEditorAutosave() public static Editor openLocalFile(File file) { - if (file == null) return null; - if (!file.exists()) return null; + if (file == null) return null; + if (!file.exists()) return null; // gets a blank editor (one that has been created with a 'blank' model), // OR an existing editor if one has the same // file ID (will be 0 if editor file is local) and same file name, OR // creates a new editor model and editor with this new file. - Editor editor = EditorFactory.getEditor(file); + + ExperimenterData exp = getUserDetails(); + SecurityContext ctx = null; + if (exp != null) + ctx = new SecurityContext(exp.getDefaultGroup().getId()); + Editor editor = EditorFactory.getEditor(ctx, file); // activates the editor // if the editor is 'blank' or has just been created (above), @@ -205,7 +230,8 @@ private void handleFileEdition(EditFileEvent event) FileAnnotationData data = event.getFileAnnotation(); if (data == null) { if (event.getFileAnnotationID() > 0) - editor = EditorFactory.getEditor(event.getFileAnnotationID()); + editor = EditorFactory.getEditor(event.getSecurityContext(), + event.getFileAnnotationID()); } else { if (data.getId() <= 0) return; String name = data.getFileName(); @@ -215,7 +241,8 @@ private void handleFileEdition(EditFileEvent event) FileAnnotationData.EDITOR_PROTOCOL_NS.equals(ns) || FileAnnotationData.COMPANION_FILE_NS.equals(ns) || EditorUtil.isEditorFile(name)) - editor = EditorFactory.getEditor(data); + editor = EditorFactory.getEditor(event.getSecurityContext(), + data); else { ApplicationData app = new ApplicationData(""); UserNotifier un = getRegistry().getUserNotifier(); @@ -235,12 +262,12 @@ private void handleFileEdition(EditFileEvent event) new File(path), null); } activity.setApplicationData(app); - un.notifyActivity(activity); + un.notifyActivity(event.getSecurityContext(), activity); return; } } if (editor != null) - editor.activate(); // starts file downloading + editor.activate();// starts file downloading } /** @@ -254,18 +281,19 @@ private void handleShowEditor(ShowEditorEvent evt) AutosaveRecovery autosaveRecovery = new AutosaveRecovery(); Editor editor = null; if (evt == null) { - editor = EditorFactory.getEditor(); + editor = EditorFactory.getEditor(null); if (editor != null) editor.activate(); autosaveRecovery.checkForRecoveredFiles(); // now check return; } if (evt.getParent() == null) - editor = EditorFactory.getEditor(); + editor = EditorFactory.getEditor(evt.getSecurityContext()); else { int editorType = Editor.PROTOCOL; if (evt.getType() == ShowEditorEvent.EXPERIMENT) editorType = Editor.EXPERIMENT; - editor = EditorFactory.getEditor(evt.getParent(), evt.getName(), + editor = EditorFactory.getEditor(evt.getSecurityContext(), + evt.getParent(), evt.getName(), editorType); } autosaveRecovery.checkForRecoveredFiles(); // now check @@ -310,12 +338,35 @@ private void handleCopyData(CopyEvent evt) private void register() { TaskBar tb = registry.getTaskBar(); - RegisterAction a = new RegisterAction(); - //register with tool bar - JButton b = new JButton(a); + IconManager icons = IconManager.getInstance(); + JButton b = new JButton(icons.getIcon(IconManager.EDITOR)); + b.setToolTipText(RegisterAction.DESCRIPTION); + ActionListener l = new ActionListener() { + + /** Posts an event to start the agent.*/ + public void actionPerformed(ActionEvent e) { + EventBus bus = registry.getEventBus(); + ExperimenterData exp = (ExperimenterData) registry.lookup( + LookupNames.CURRENT_USER_DETAILS); + if (exp == null) return; + GroupData gp = null; + try { + gp = exp.getDefaultGroup(); + } catch (Exception ex) { + //No default group + } + long id = -1; + if (gp != null) id = gp.getId(); + if (groupId == -1) groupId = id; + bus.post(new ShowEditorEvent(new SecurityContext(groupId))); + } + }; + b.addActionListener(l); tb.addToToolBar(TaskBar.AGENTS, b); //register with File menu - JMenuItem item = new JMenuItem(a); + JMenuItem item = new JMenuItem(icons.getIcon(IconManager.EDITOR)); + item.setToolTipText(RegisterAction.DESCRIPTION); + item.addActionListener(l); item.setText(RegisterAction.NAME); tb.addToMenu(TaskBar.FILE_MENU, item); } @@ -352,6 +403,7 @@ public void setContext(Registry ctx) bus.register(this, CopyEvent.class); bus.register(this, UserGroupSwitched.class); bus.register(this, ReconnectedEvent.class); + bus.register(this, ChangeUserGroupEvent.class); //Register itself for the toolbar. register(); } @@ -403,6 +455,10 @@ else if (e instanceof UserGroupSwitched) handleUserGroupSwitched((UserGroupSwitched) e); else if (e instanceof ReconnectedEvent) handleReconnectedEvent((ReconnectedEvent) e); + else if (e instanceof ChangeUserGroupEvent) { + ChangeUserGroupEvent evt = (ChangeUserGroupEvent) e; + groupId = evt.getGroupID(); + } } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/EditorLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/EditorLoader.java index 7c56ebf8a7f..d60ae7c999e 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/EditorLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/EditorLoader.java @@ -31,6 +31,7 @@ import org.openmicroscopy.shoola.agents.editor.view.Editor; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.MetadataHandlerView; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -60,24 +61,30 @@ public abstract class EditorLoader { /** The browser this data loader is for. */ - protected final Editor viewer; + protected final Editor viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final MetadataHandlerView mhView; + protected final MetadataHandlerView mhView; + /** The security context.*/ + protected final SecurityContext ctx; + /** * Creates a new instance. * * @param viewer The browser this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - protected EditorLoader(Editor viewer) + protected EditorLoader(Editor viewer, SecurityContext ctx) { - if (viewer == null) throw new NullPointerException("No viewer."); + if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null) throw new NullPointerException("No security context."); this.viewer = viewer; + this.ctx = ctx; registry = EditorAgent.getRegistry(); mhView = (MetadataHandlerView) registry.getDataServicesView(MetadataHandlerView.class); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileAnnotationLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileAnnotationLoader.java index c0dcd26192d..b9ea9e6ed20 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileAnnotationLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileAnnotationLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.editor.browser.Browser; import org.openmicroscopy.shoola.agents.editor.preview.AnnotationHandler; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.FileAnnotationData; @@ -52,27 +53,29 @@ public class FileAnnotationLoader { /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** The id of the file annotation to load. */ - private long fileAnnotationID; + private long fileAnnotationID; /** * The handler of the annotation. Don't want this to be Editor since * it would be tricky to handle which class requested the annotation. */ - private AnnotationHandler annotationHandler; + private AnnotationHandler annotationHandler; /** * Creates a new instance. * * @param viewer The Editor this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param fileAnnotationID The Id of the file annotation to load. */ - public FileAnnotationLoader(Browser viewer, long fileAnnotationID) + public FileAnnotationLoader(Browser viewer, SecurityContext ctx, + long fileAnnotationID) { - super(viewer); + super(viewer, ctx); if (fileAnnotationID < 0) throw new IllegalArgumentException("ID not valid."); this.fileAnnotationID = fileAnnotationID; @@ -94,7 +97,7 @@ public void setAnnotationHandler(AnnotationHandler handler) */ public void load() { - handle = mhView.loadAnnotation(fileAnnotationID, this); + handle = mhView.loadAnnotation(ctx, fileAnnotationID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileLoader.java index fc64d42bbb8..cc394439f15 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileLoader.java @@ -35,6 +35,7 @@ import org.openmicroscopy.shoola.agents.editor.view.Editor; import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -60,31 +61,32 @@ public class FileLoader { /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** The id of the file to load. */ - private long fileID; + private long fileID; /** The size of the file to load. */ - private long fileSize; + private long fileSize; /** Utility file where the raw data are loaded. */ - private File file; + private File file; /** * Creates a new instance. * * @param viewer The Editor this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param fileName The name of the file to edit. * @param fileID The id of the file to load OR * of the fileAnnotation if fileName is null. * @param fileSize The size of the file to load. */ - public FileLoader(Editor viewer, String fileName, long fileID, - long fileSize) + public FileLoader(Editor viewer, SecurityContext ctx, String fileName, + long fileID, long fileSize) { - super(viewer); + super(viewer, ctx); if (fileID < 0) throw new IllegalArgumentException("ID not valid."); this.fileID = fileID; @@ -98,7 +100,7 @@ public FileLoader(Editor viewer, String fileName, long fileID, */ public void load() { - handle = mhView.loadFile(file, fileID, fileSize, this); + handle = mhView.loadFile(ctx, file, fileID, fileSize, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileSaver.java index 6ad3efb582a..2a83fbed430 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/FileSaver.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.editor.view.Editor; import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.MetadataHandlerView; @@ -58,45 +59,46 @@ public class FileSaver { /** Identifies that the file is of type protocol. */ - public static final int PROTOCOL = MetadataHandlerView.EDITOR_PROTOCOL; + public static final int PROTOCOL = MetadataHandlerView.EDITOR_PROTOCOL; /** Identifies that the file is of type experiment. */ - public static final int EXPERIMENT = + public static final int EXPERIMENT = MetadataHandlerView.EDITOR_EXPERIMENT; /** Identifies that the file is of type other. */ - public static final int OTHER = MetadataHandlerView.OTHER; + public static final int OTHER = MetadataHandlerView.OTHER; /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** Utility file where the raw data are loaded. */ - private File file; + private File file; /** The fileAnnotation data. */ - private FileAnnotationData fileAnnotationData; + private FileAnnotationData fileAnnotationData; /** One of the constants defined by this class. */ - private int index; + private int index; /** The DataObject to link the file annotation to. */ - private DataObject linkTo; + private DataObject linkTo; /** * Creates a new instance. * * @param viewer The Editor this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param file The file to save back to the server. * @param data The id of the file if previously saved, or * -1 if not previously saved. * @param index One of the constants defined by this class. * @param linkTo The */ - public FileSaver(Editor viewer, File file, FileAnnotationData data, - int index, DataObject linkTo) + public FileSaver(Editor viewer, SecurityContext ctx, File file, + FileAnnotationData data, int index, DataObject linkTo) { - super(viewer); + super(viewer, ctx); if (file == null) throw new IllegalArgumentException("No file to save."); if (data == null) @@ -121,7 +123,8 @@ public FileSaver(Editor viewer, File file, FileAnnotationData data, */ public void load() { - handle = mhView.saveFile(fileAnnotationData, file, index, linkTo, this); + handle = mhView.saveFile(ctx, fileAnnotationData, file, index, linkTo, + this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/IconManager.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/IconManager.java index 010e3aef3f7..2d6b4d58fb8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/IconManager.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/IconManager.java @@ -332,11 +332,23 @@ public class IconManager /** The Clear Values icon */ public static final int CLEAR_VALUES_ICON = 91; + /** The 12x12 Private Group Drop Down icon. */ + public static final int PRIVATE_GROUP_DD_12 = 92; + + /** The 12x12 Read Group Drop Down icon. */ + public static final int READ_GROUP_DD_12 = 93; + + /** The 12x12 Read Link Group Drop Down icon. */ + public static final int READ_LINK_GROUP_DD_12 = 94; + + /** The 12x12 Public Group Drop Down icon. */ + public static final int PUBLIC_GROUP_DD_12 = 95; + /** * The maximum ID used for the icon IDs. * Allows to correctly build arrays for direct indexing. */ - private static final int MAX_ID = 91; + private static final int MAX_ID = 95; /** Paths of the icon files. */ @@ -442,6 +454,10 @@ public class IconManager relPaths[ADD_STEP_NOTE_ICON] = "addStepNote.png"; relPaths[STEP_NOTE_ICON] = "stepNote.png"; relPaths[CLEAR_VALUES_ICON] = "nuvola_news_unsubscribe16.png"; + relPaths[PRIVATE_GROUP_DD_12] = "nuvola_permission_private_dd12.png"; + relPaths[READ_GROUP_DD_12] = "nuvola_permission_readOnly_dd12.png"; + relPaths[READ_LINK_GROUP_DD_12] = "nuvola_permission_read_dd12.png"; + relPaths[PUBLIC_GROUP_DD_12] = "nuvola_permission_public_dd12.png"; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/GroupSelectionAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/GroupSelectionAction.java new file mode 100644 index 00000000000..e2bcd816ba3 --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/GroupSelectionAction.java @@ -0,0 +1,130 @@ +/* + * org.openmicroscopy.shoola.agents.editor.actions.GroupSelectionAction + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.agents.editor.actions; + + +//Java imports +import java.awt.event.ActionEvent; +import javax.swing.Action; + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.agents.editor.EditorAgent; +import org.openmicroscopy.shoola.agents.editor.view.Editor; +import org.openmicroscopy.shoola.agents.treeviewer.IconManager; +import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.GroupData; + +/** + * Selects the group out of the list of groups the user is member of + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class GroupSelectionAction + extends EditorAction +{ + + /** The group the logged in user is member of. */ + private GroupData group; + + /** + * Sets the icon and tool tip text according to the permissions of the + * group. + */ + private void setPermissions() + { + int iconID = IconManager.PERSONAL; + int level = + EditorAgent.getRegistry().getAdminService().getPermissionLevel( + group); + String desc = ""; + switch (level) { + case AdminObject.PERMISSIONS_PRIVATE: + desc = AdminObject.PERMISSIONS_PRIVATE_TEXT; + iconID = IconManager.PRIVATE_GROUP_DD_12; + break; + case AdminObject.PERMISSIONS_GROUP_READ: + desc = AdminObject.PERMISSIONS_GROUP_READ_TEXT; + iconID = IconManager.READ_GROUP_DD_12; + break; + case AdminObject.PERMISSIONS_GROUP_READ_LINK: + desc = AdminObject.PERMISSIONS_GROUP_READ_LINK_TEXT; + iconID = IconManager.READ_LINK_GROUP_DD_12; + break; + case AdminObject.PERMISSIONS_PUBLIC_READ: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_TEXT; + iconID = IconManager.PUBLIC_GROUP_DD_12; + break; + case AdminObject.PERMISSIONS_PUBLIC_READ_WRITE: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_WRITE_TEXT; + iconID = IconManager.PUBLIC_GROUP_DD_12; + } + + + setIcon(iconID); + putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(desc)); + } + + /** + * Creates a new instance. + * + * @param model Reference to the Model. Mustn't be null. + * @param group The group the logged in user is a member of. + */ + public GroupSelectionAction(Editor model, GroupData group) + { + super(model); + if (group == null) + throw new IllegalArgumentException("No group specified."); + this.group = group; + putValue(Action.NAME, group.getName()); + setPermissions(); + } + + /** + * Returns true if the passed id corresponds to the group + * hosted by this component, false otherwise. + * + * @param groupID The id to check. + * @return See above. + */ + public boolean isSameGroup(long groupID) + { + return group.getId() == groupID; + } + + /** + * Sets the default group for the currently logged in user. + * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + model.setUserGroup(group.getId()); + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/PersonalManagementAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/PersonalManagementAction.java new file mode 100644 index 00000000000..b055c5fb208 --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/PersonalManagementAction.java @@ -0,0 +1,152 @@ +/* + * org.openmicroscopy.shoola.agents.editor.actions.PersonalManagementAction + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.agents.editor.actions; + + +//Java imports +import java.awt.Component; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import javax.swing.Action; + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.agents.editor.EditorAgent; +import org.openmicroscopy.shoola.agents.editor.IconManager; +import org.openmicroscopy.shoola.agents.editor.view.Editor; +import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.GroupData; + +/** + * Brings up the menu with available group. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class PersonalManagementAction + extends EditorAction + implements MouseListener +{ + + /** The description of the action. */ + private static final String DESCRIPTION = "Select your current group."; + + /** The location of the mouse pressed. */ + private Point point; + + /** + * Creates a new instance. + * + * @param model Reference to the Model. Mustn't be null. + */ + public PersonalManagementAction(Editor model) + { + super(model); + setEnabled(true); + setPermissions(); + } + + /** Sets the name, description and the icon depending on the permissions. */ + public void setPermissions() + { + GroupData group = model.getSelectedGroup(); + String name = ""; + String desc = DESCRIPTION; + int iconID = IconManager.UP_DOWN_9_12; + if (group != null) { + name = group.getName(); + int level = + EditorAgent.getRegistry().getAdminService().getPermissionLevel( + group); + switch (level) { + case AdminObject.PERMISSIONS_PRIVATE: + desc = AdminObject.PERMISSIONS_PRIVATE_TEXT; + iconID = IconManager.PRIVATE_GROUP_DD_12; + break; + case AdminObject.PERMISSIONS_GROUP_READ: + desc = AdminObject.PERMISSIONS_GROUP_READ_TEXT; + iconID = IconManager.READ_GROUP_DD_12; + break; + case AdminObject.PERMISSIONS_GROUP_READ_LINK: + desc = AdminObject.PERMISSIONS_GROUP_READ_LINK_TEXT; + iconID = IconManager.READ_LINK_GROUP_DD_12; + break; + case AdminObject.PERMISSIONS_PUBLIC_READ: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_TEXT; + iconID = IconManager.PUBLIC_GROUP_DD_12; + break; + case AdminObject.PERMISSIONS_PUBLIC_READ_WRITE: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_WRITE_TEXT; + iconID = IconManager.PUBLIC_GROUP_DD_12; + } + } + putValue(Action.NAME, name); + setIcon(iconID); + putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(desc)); + } + /** + * Sets the location of the point where the mousePressed + * event occurred. + * @see MouseListener#mousePressed(MouseEvent) + */ + public void mousePressed(MouseEvent me) { point = me.getPoint(); } + + /** + * Brings up the menu. + * @see MouseListener#mouseReleased(MouseEvent) + */ + public void mouseReleased(MouseEvent me) + { + Object source = me.getSource(); + if (point == null) point = me.getPoint(); + if (source instanceof Component && isEnabled()) + model.showMenu(Editor.GROUP_MENU, (Component) source, point); + } + + /** + * Required by {@link MouseListener} I/F but not actually needed in our + * case, no-operation implementation. + * @see MouseListener#mouseEntered(MouseEvent) + */ + public void mouseEntered(MouseEvent e) {} + + /** + * Required by {@link MouseListener} I/F but not actually needed in our + * case, no-operation implementation. + * @see MouseListener#mouseExited(MouseEvent) + */ + public void mouseExited(MouseEvent e) {} + + /** + * Required by {@link MouseListener} I/F but not actually needed in our + * case, no-operation implementation. + * @see MouseListener#mouseClicked(MouseEvent) + */ + public void mouseClicked(MouseEvent e) {} + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/RegisterAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/RegisterAction.java index 1a507fc0b73..685c16e38ef 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/RegisterAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/actions/RegisterAction.java @@ -36,9 +36,13 @@ import org.openmicroscopy.shoola.agents.editor.EditorAgent; import org.openmicroscopy.shoola.agents.editor.IconManager; import org.openmicroscopy.shoola.agents.events.editor.ShowEditorEvent; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.ExperimenterData; +import pojos.GroupData; + /** * Registers the agent. * @@ -54,7 +58,7 @@ public class RegisterAction public static final String NAME = "Editor..."; /** The description of the action. */ - private static final String DESCRIPTION = "Open the Editor."; + public static final String DESCRIPTION = "Open the Editor."; /** * Creates a new instance. @@ -71,9 +75,13 @@ public RegisterAction() * Posts an event on the bus to open the editor. * @see AbstractAction#actionPerformed(ActionEvent) */ - public void actionPerformed(ActionEvent evt) { + public void actionPerformed(ActionEvent evt) + { + ExperimenterData exp = EditorAgent.getUserDetails(); + GroupData group = exp.getDefaultGroup(); + if (group == null) return; EventBus bus = EditorAgent.getRegistry().getEventBus(); - bus.post(new ShowEditorEvent()); + bus.post(new ShowEditorEvent(new SecurityContext(group.getId()))); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/Browser.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/Browser.java index 71e82771a9f..9d6c27bcf98 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/Browser.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/Browser.java @@ -31,6 +31,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.agents.editor.preview.AnnotationHandler; import org.openmicroscopy.shoola.util.ui.component.ObservableComponent; @@ -191,4 +192,12 @@ public interface Browser */ public void deleteExperimentInfo(); + /** + * Loads the file annotation. + * + * @param fileID The fileID you want the annotation for. + * @param handler The handler used when the annotation is returned. + */ + void getFileAnnotation(long fileID, AnnotationHandler handler); + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserComponent.java index af3588f7b5a..335fad744d7 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserComponent.java @@ -33,6 +33,7 @@ //Application-internal dependencies +import org.openmicroscopy.shoola.agents.editor.preview.AnnotationHandler; import org.openmicroscopy.shoola.util.ui.component.AbstractComponent; /** @@ -212,5 +213,14 @@ public void deleteExperimentInfo() { controller.deleteExperimentInfo(model.getTreeModel()); } + + /** + * Implemented as specified by the {@link Browser} interface. + * @see Browser#getFileAnnotation(long, AnnotationHandler) + */ + public void getFileAnnotation(long fileID, AnnotationHandler handler) + { + model.getFileAnnotation(fileID, handler); + } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserControl.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserControl.java index 2cf6b1740c6..b1fff2b1345 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserControl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserControl.java @@ -652,9 +652,7 @@ public void removeFieldTable(IField field, JTree tree, TreeNode node) public void getFileAnnotation(long fileID, AnnotationHandler handler) { if (handler == null) return; - FileAnnotationLoader fal = new FileAnnotationLoader(model, fileID); - fal.setAnnotationHandler(handler); - fal.load(); + model.getFileAnnotation(fileID, handler); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserFactory.java index 090195ba9e7..a2466e0f5a5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserFactory.java @@ -29,6 +29,8 @@ //Application-internal dependencies package org.openmicroscopy.shoola.agents.editor.browser; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + /** * Factory to create {@link Browser} objects. * @@ -44,17 +46,18 @@ public class BrowserFactory { /** - * Creates a new {@link Browser}, with a UI either for disply or editing + * Creates a new {@link Browser}, with a UI either for display or editing * of the Tree data. * + * @param ctx The security context. * @param editingMode Either {@link Browser#FILE_LOCKED}, * {@link Browser#EDIT_EXPERIMENT}, or {@link Browser#EDIT_PROTOCOL}. - * * @return A browser component. */ - public static Browser createBrowser(int editingMode, int type) + public static Browser createBrowser(SecurityContext ctx, + int editingMode, int type) { - BrowserModel model = new BrowserModel(editingMode, type); + BrowserModel model = new BrowserModel(ctx, editingMode, type); BrowserComponent component = new BrowserComponent(model); model.initialize(component); component.initialize(); @@ -64,19 +67,17 @@ public static Browser createBrowser(int editingMode, int type) /** * Creates a new {@link Browser}, with a UI either in the Display mode. * + * @param ctx The security context. * @param type Either {@link Browser#PROTOCOL} or {@link Browser#EXPERIMENT}. * @return A browser component. * */ - public static Browser createBrowser(int type) + public static Browser createBrowser(SecurityContext ctx, int type) { - int editingMode; + int editingMode = Browser.EDIT_PROTOCOL; if (type == Browser.EXPERIMENT) editingMode = Browser.EDIT_EXPERIMENT; - else - editingMode = Browser.EDIT_PROTOCOL; - - return createBrowser(editingMode, type); + return createBrowser(ctx, editingMode, type); } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserModel.java index 8fc4cf6b9bd..fe90700bc9a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/BrowserModel.java @@ -31,9 +31,12 @@ import javax.swing.tree.TreeModel; import javax.swing.tree.TreeNode; +import org.openmicroscopy.shoola.agents.editor.FileAnnotationLoader; import org.openmicroscopy.shoola.agents.editor.model.CPEimport; import org.openmicroscopy.shoola.agents.editor.model.ExperimentInfo; import org.openmicroscopy.shoola.agents.editor.model.IAttributes; +import org.openmicroscopy.shoola.agents.editor.preview.AnnotationHandler; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; //Third-party libraries @@ -77,16 +80,21 @@ class BrowserModel /** The type of browser. */ private int type; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates an instance. * + * @param ctx The security context. * @param state The editing mode of the browser. * Either {@link Browser#EDIT_EXPERIMENT} or * {@link Browser#EDIT_PROTOCOL} * @param type */ - BrowserModel(int state, int type) + BrowserModel(SecurityContext ctx, int state, int type) { + this.ctx = ctx; setEditingMode(state); this.savedState = Browser.TREE_SAVED; this.type = type; @@ -256,4 +264,18 @@ Date getLastSavedDate() */ int getType() { return type; } + /** + * Loads the file annotation. + * + * @param fileID The id of the file to load. + * @param handler The handler used when the annotation is returned. + */ + void getFileAnnotation(long fileID, AnnotationHandler handler) + { + FileAnnotationLoader fal = new FileAnnotationLoader(component, ctx, + fileID); + fal.setAnnotationHandler(handler); + fal.load(); + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/paramUIs/ProtocolLinkEditor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/paramUIs/ProtocolLinkEditor.java index 0230d6b4236..bc3e3f6588b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/paramUIs/ProtocolLinkEditor.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/browser/paramUIs/ProtocolLinkEditor.java @@ -315,11 +315,11 @@ public void actionPerformed(ActionEvent e) { // if link to local file that exists, open in Editor. if (f.exists()) EditorAgent.openLocalFile(f); - - } - else if (fileID > 0) { + } else if (fileID > 0) { + /*TODO: review that work EventBus bus = MetadataViewerAgent.getRegistry().getEventBus(); bus.post(new EditFileEvent(fileID)); + */ } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_private_dd12.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_private_dd12.png new file mode 100644 index 00000000000..4e28faa4ee5 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_private_dd12.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_public_dd12.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_public_dd12.png new file mode 100644 index 00000000000..10a631b1622 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_public_dd12.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_readLink_dd12.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_readLink_dd12.png new file mode 100644 index 00000000000..905c5754b61 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_readLink_dd12.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_readOnly_dd12.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_readOnly_dd12.png new file mode 100644 index 00000000000..8ad32dbfd53 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_readOnly_dd12.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_read_dd12.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_read_dd12.png new file mode 100644 index 00000000000..462fd95e1ad Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/graphx/nuvola_permission_read_dd12.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/preview/EditorPreview.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/preview/EditorPreview.java index b4c292adf1d..16c1a8ad853 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/preview/EditorPreview.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/preview/EditorPreview.java @@ -150,7 +150,7 @@ public EditorPreview(long fileID, BrowserControl controller) void loadPreviewData() { if (fileID != 0) { - if (! EditorAgent.isServerAvailable()) { + if (!EditorAgent.isServerAvailable()) { annotationDesc = "File ID: " + fileID + " on server" + "Can't show the preview of this file because " + diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/Editor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/Editor.java index 88ef82acf38..e5636f22537 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/Editor.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/Editor.java @@ -24,9 +24,10 @@ //Java imports +import java.awt.Component; +import java.awt.Point; import java.beans.PropertyChangeListener; import java.io.File; - import javax.swing.JFrame; //Third-party libraries @@ -36,6 +37,7 @@ import org.openmicroscopy.shoola.agents.events.editor.ShowEditorEvent; import org.openmicroscopy.shoola.util.ui.component.ObservableComponent; import pojos.FileAnnotationData; +import pojos.GroupData; /** * Defines the interface provided by the editor component. @@ -85,6 +87,9 @@ public interface Editor /** Flag to denote the Saving state. */ public static final int SAVING = 5; + /** Identifies the group menu. */ + public static final int GROUP_MENU = 100; + /** * Starts the data loading process when the current state is {@link #NEW} * and puts the window on screen. @@ -243,5 +248,30 @@ public interface Editor * @return See above. */ public JFrame getUI(); + + /** + * Returns the group corresponding to the security context. + * + * @return See above. + */ + public GroupData getSelectedGroup(); + /** + * Brings up the menu on top of the specified component at + * the specified location. + * + * @param menuID The id of the menu. + * @param invoker The component that requested the pop-up menu. + * @param loc The point at which to display the menu, relative to the + * component's coordinates. + */ + public void showMenu(int menuID, Component c, Point p); + + /** + * Sets the group to used if the file is saved back to the server. + * + * @param groupID The id of the group. + */ + void setUserGroup(long groupID); + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorComponent.java index a06b16694b7..0c92df6380b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorComponent.java @@ -23,12 +23,16 @@ package org.openmicroscopy.shoola.agents.editor.view; //Java imports +import java.awt.Component; +import java.awt.Point; import java.beans.PropertyChangeListener; import java.io.File; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.Iterator; +import java.util.Set; import javax.swing.JCheckBox; import javax.swing.JFrame; @@ -42,11 +46,13 @@ import org.openmicroscopy.shoola.agents.editor.actions.SaveNewCmd; import org.openmicroscopy.shoola.agents.editor.browser.Browser; import org.openmicroscopy.shoola.env.data.events.ExitApplication; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.ui.UserNotifier; import org.openmicroscopy.shoola.util.ui.MessageBox; import org.openmicroscopy.shoola.util.ui.component.AbstractComponent; import pojos.FileAnnotationData; +import pojos.GroupData; /** * Implements the {@link Editor} interface to provide the functionality @@ -332,7 +338,8 @@ public void openLocalFile(File file) { public void newBlankFile() { // gets a new editor - Editor editor = EditorFactory.getNewBlankEditor(); + Editor editor = EditorFactory.getNewBlankEditor( + model.getSecurityContext()); // primes the editor to open new file and activates the editor if (editor != null) { @@ -522,13 +529,14 @@ public void onFileSave(FileAnnotationData data) { UserNotifier un = EditorAgent.getRegistry().getUserNotifier(); String message = - "An error occured while saving the file to the server."; + "An error occurred while saving the file to the server."; if (data != null) { long id = data.getId(); message = "The File has been saved to the server. \nID = " + id; model.setFileAnnotationData(data); model.getBrowser().setId(id); } + view.setGroupInformation(); un.notifyInfo("File Saved", message); model.setState(READY); view.setTitle(model.getFileName()); @@ -585,6 +593,25 @@ public boolean isUserOwner() { return model.isUserOwner(); } + + /** + * Implemented as specified by the {@link Editor} interface. + * @see Editor#isUserOwner() + */ + public GroupData getSelectedGroup() + { + SecurityContext ctx = model.getSecurityContext(); + if (ctx == null) return null; + Set groups = EditorAgent.getAvailableUserGroups(); + Iterator i = groups.iterator(); + GroupData g; + while (i.hasNext()) { + g = (GroupData) i.next(); + if (g.getId() == ctx.getGroupID()) + return g; + } + return null; + } /** * Implemented as specified by the {@link Editor} interface. @@ -592,10 +619,37 @@ public boolean isUserOwner() */ public JFrame getUI() { return view; } + /** + * Implemented as specified by the {@link Editor} interface. + * @see Editor#showMenu(int, Component, Point) + */ + public void showMenu(int menuID, Component c, Point p) + { + switch (menuID) { + case GROUP_MENU: + view.showMenu(menuID, c, p); + break; + } + } + + /** + * Implemented as specified by the {@link Editor} interface. + * @see Editor#showMenu(int, Component, Point) + */ + public void setUserGroup(long groupID) + { + SecurityContext ctx = model.getSecurityContext(); + if (ctx.getGroupID() == groupID) return; + model.setSecurityContext(groupID); + view.setGroupInformation(); + } + /** * Overridden to return the name of the instance to save. * @see #toString() */ public String toString() { return view.getTitle(); } + + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorControl.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorControl.java index 0f92513aafc..c46354d6ce5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorControl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorControl.java @@ -25,8 +25,13 @@ //Java imports import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Set; + import javax.swing.JMenu; import javax.swing.WindowConstants; import javax.swing.event.ChangeEvent; @@ -39,15 +44,21 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.agents.editor.EditorAgent; import org.openmicroscopy.shoola.agents.editor.actions.CloseEditorAction; import org.openmicroscopy.shoola.agents.editor.actions.EditorAction; +import org.openmicroscopy.shoola.agents.editor.actions.GroupSelectionAction; import org.openmicroscopy.shoola.agents.editor.actions.NewBlankFileAction; import org.openmicroscopy.shoola.agents.editor.actions.OpenLocalFileAction; import org.openmicroscopy.shoola.agents.editor.actions.OpenWwwFileAction; +import org.openmicroscopy.shoola.agents.editor.actions.PersonalManagementAction; import org.openmicroscopy.shoola.agents.editor.actions.SaveAsProtocolAction; import org.openmicroscopy.shoola.agents.editor.actions.SaveFileLocallyAction; import org.openmicroscopy.shoola.agents.editor.actions.SaveFileAction; import org.openmicroscopy.shoola.agents.editor.actions.SaveFileServerAction; +import org.openmicroscopy.shoola.agents.util.ViewerSorter; + +import pojos.GroupData; /** * The {@link Editor}'s controller. @@ -90,6 +101,9 @@ class EditorControl /** Identifies the SaveFileAsProtocol Action. */ static final Integer SAVE_AS_PROTOCOL = Integer.valueOf(8); + /** Identifies the SaveFileAsProtocol Action. */ + static final Integer PERSONAL = Integer.valueOf(9); + /** * Reference to the {@link Editor} component, which, in this context, * is regarded as the Model. @@ -113,6 +127,7 @@ private void createActions() actionsMap.put(OPEN_WWW_FILE, new OpenWwwFileAction(model)); actionsMap.put(SAVE_FILE_SERVER, new SaveFileServerAction(model)); actionsMap.put(SAVE_AS_PROTOCOL, new SaveAsProtocolAction(model)); + actionsMap.put(PERSONAL, new PersonalManagementAction(model)); } /** @@ -225,6 +240,26 @@ void initialize(EditorUI view) */ EditorAction getAction(Integer id) { return actionsMap.get(id); } + /** + * Returns the list of group the user is a member of. + * + * @return See above. + */ + List getUserGroupAction() + { + List l = new ArrayList(); + Set m = EditorAgent.getAvailableUserGroups(); + if (m == null || m.size() == 0) return l; + ViewerSorter sorter = new ViewerSorter(); + Iterator i = sorter.sort(m).iterator(); + GroupData group; + while (i.hasNext()) { + group = (GroupData) i.next(); + l.add(new GroupSelectionAction(model, group)); + } + return l; + } + /** * Reacts to state changes in the {@link Editor}. * @see ChangeListener#stateChanged(ChangeEvent) diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorFactory.java index 78849e06580..178c45a7b6b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorFactory.java @@ -40,6 +40,7 @@ import org.openmicroscopy.shoola.agents.editor.EditorAgent; import org.openmicroscopy.shoola.agents.editor.actions.ActivationAction; import org.openmicroscopy.shoola.env.data.events.ExitApplication; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.ui.TaskBar; @@ -77,40 +78,45 @@ public class EditorFactory /** * Returns the {@link Editor}. * + * @param ctx The security context. * @param fileAnnotation The annotation hosting the information about * the file to edit. * @return See above. */ - public static Editor getEditor(FileAnnotationData fileAnnotation) + public static Editor getEditor(SecurityContext ctx, + FileAnnotationData fileAnnotation) { - EditorModel model = new EditorModel(fileAnnotation); + EditorModel model = new EditorModel(ctx, fileAnnotation); return singleton.getEditor(model); } /** * Returns the {@link Editor}. * - * @param fileID The id of the file to edit. + * @param ctx The security context. + * @param fileID The id of the file to edit. * @return See above. */ - public static Editor getEditor(long fileID) + public static Editor getEditor(SecurityContext ctx, long fileID) { - EditorModel model = new EditorModel(fileID); + EditorModel model = new EditorModel(ctx, fileID); return singleton.getEditor(model); } /** * Returns the {@link Editor} for the passed data object. * + * @param ctx The security context. * @param parent The data object that the file should be linked to. * @param name The name of the editor file. * @param type Either {@link Editor#PROTOCOL} or * {@link Editor#EXPERIMENT}. * @return See above. */ - public static Editor getEditor(DataObject parent, String name, int type) + public static Editor getEditor(SecurityContext ctx, DataObject parent, + String name, int type) { - EditorModel model = new EditorModel(parent, name, type); + EditorModel model = new EditorModel(ctx, parent, name, type); Editor editor = singleton.getEditor(model); if (editor != null) { ((EditorComponent) editor).setNewExperiment(); @@ -122,15 +128,15 @@ public static Editor getEditor(DataObject parent, String name, int type) /** * Returns the {@link Editor} created to display a particular file. * - * - * @param file The file to open in Editor. + * @param ctx The security context. + * @param file The file to open in Editor. * @return See above. */ - public static Editor getEditor(File file) + public static Editor getEditor(SecurityContext ctx, File file) { - if (file == null) return getEditor(); // just in case. Never used! + if (file == null) return getEditor(ctx); // just in case. Never used! - EditorModel model = new EditorModel(file); + EditorModel model = new EditorModel(ctx, file); // if a "blank" editor is open, with a "blank" model, this is returned // or, if the model matches the model in an existing editor, return this, @@ -146,13 +152,14 @@ public static Editor getEditor(File file) * This provides the functionality for handling a "show editor", where * it doesn't matter which editor/file you show. * + * @param ctx The security context. * @return See above. */ - public static Editor getEditor() + public static Editor getEditor(SecurityContext ctx) { EditorModel model; if (singleton.editors.isEmpty()) - return getNewBlankEditor(); + return getNewBlankEditor(ctx); Editor e = singleton.editors.iterator().next(); if (e == null) return e; model = ((EditorComponent) e).getModel(); @@ -184,12 +191,13 @@ public static void setCopiedData(Object copiedData) * This has a similar functionality to getEditor method, * except this method always returns a new editor * (never an existing editor). - * + * + * @param ctx The security context. * @return A new Editor, with a new EditorModel */ - public static Editor getNewBlankEditor() + public static Editor getNewBlankEditor(SecurityContext ctx) { - EditorModel model = new EditorModel(); + EditorModel model = new EditorModel(ctx); // this will return any existing editors with a 'blank' model, or // create an editor with the blank model above, if none exist. Editor editor = singleton.getEditor(model); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorModel.java index 86954132e54..8567ce5201f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorModel.java @@ -43,6 +43,7 @@ import org.openmicroscopy.shoola.agents.util.EditorUtil; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.OmeroMetadataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.env.ui.UserNotifier; import org.openmicroscopy.shoola.util.file.IOUtil; @@ -76,16 +77,16 @@ class EditorModel { /** Holds one of the state flags defined by {@link Editor}. */ - private int state; + private int state; /** The name of the file to edit. */ - private String fileName; + private String fileName; /** The annotation object hosting information about the file. */ - private FileAnnotationData fileAnnotation; + private FileAnnotationData fileAnnotation; /** The id of the file to edit. Will not be set if editing local file */ - private long fileID; + private long fileID; /** * The ID of the annotation for the file on the server, as returned by @@ -94,32 +95,35 @@ class EditorModel * {@link #EditorModel(long)} constructor has been used, before * {@link #setFileAnnotationData(FileAnnotationData)} has been called. */ - private long annotationID; + private long annotationID; /** A string that defines the type of file we're editing. eg protocol */ - private String nameSpace; + private String nameSpace; /** The file retrieved either from the DB or local machine. */ - private File fileToEdit; + private File fileToEdit; /** The browser component */ - private Browser browser; + private Browser browser; /** The DataObject to link the editor file to. */ - private DataObject parent; + private DataObject parent; /** Either {@link Editor#PROTOCOL} or {@link Editor#EXPERIMENT}. */ - private int type; + private int type; /** * Will either be a data loader or null depending on the * current state. */ - private EditorLoader currentLoader; + private EditorLoader currentLoader; /** Reference to the component that embeds this model. */ - private Editor component; + private Editor component; + /** The security context.*/ + private SecurityContext ctx; + /** * Saves the {@link TreeModel} from the {@link Browser} as an XML file. * Returns true if the file can be parsed, false @@ -140,25 +144,29 @@ private boolean saveFile(File file) /** * Creates a new instance and sets the state to {@link Editor#NEW}. * + * @param ctx The security context. * @param fileAnnotationData The annotation hosting the file to edit. */ - EditorModel(FileAnnotationData fileAnnotationData) + EditorModel(SecurityContext ctx, FileAnnotationData fileAnnotationData) { state = Editor.NEW; if (fileAnnotationData == null) throw new IllegalArgumentException("No file annotation specified."); setFileAnnotationData(fileAnnotationData); + this.ctx = ctx; type = Editor.PROTOCOL; } /** * Creates a new instance and sets the state to {@link Editor#NEW}. * + * @param ctx The security context. * @param annotationID The id of the original file to edit. */ - EditorModel(long annotationID) + EditorModel(SecurityContext ctx, long annotationID) { state = Editor.NEW; + this.ctx = ctx; this.annotationID = annotationID; // this sets the fileID with the annotationID so that when @@ -172,24 +180,29 @@ private boolean saveFile(File file) * {@link #fileSize} and {@link #fileID} are not set. * File is not opened. To do this, call {@link Editor#setFileToEdit(File)} * + * @param ctx The security context. * @param file The file to open. Sets the {@link #fileName} to the * name of this file but does not open file. */ - EditorModel(File file) + EditorModel(SecurityContext ctx, File file) { if (file == null) throw new NullPointerException("No file."); state = Editor.NEW; + this.ctx = ctx; fileName = file.getName(); type = Editor.PROTOCOL; } /** * Creates a new instance and sets the state to {@link Editor#NEW}. - * The {@link #fileSize} and {@link #fileID} are not set. + * The {@link #fileSize} and {@link #fileID} are not set. + * + * @param ctx The security context. */ - EditorModel() + EditorModel(SecurityContext ctx) { state = Editor.NEW; + this.ctx = ctx; fileName = EditorFactory.BLANK_MODEL; type = Editor.PROTOCOL; } @@ -198,14 +211,16 @@ private boolean saveFile(File file) * Creates a new instance and sets the state to {@link Editor#NEW}. * The {@link #fileSize} and {@link #fileID} are not set. * + * @param ctx The security context. * @param parent The object to link the file to. * @param name The name of the file. * @param type Either {@link Editor#PROTOCOL} or * {@link Editor#EXPERIMENT}. */ - EditorModel(DataObject parent, String name, int type) + EditorModel(SecurityContext ctx, DataObject parent, String name, int type) { state = Editor.NEW; + this.ctx = ctx; if (name == null || name.length() == 0) name = EditorFactory.BLANK_MODEL; fileName = name; @@ -225,7 +240,7 @@ private boolean saveFile(File file) void initialize(Editor component) { this.component = component; - browser = BrowserFactory.createBrowser(type); + browser = BrowserFactory.createBrowser(ctx, type); } /** @@ -233,7 +248,7 @@ void initialize(Editor component) * * @return One of the flags defined by the {@link Editor} interface. */ - int getState() { return state; } + int getState() { return state; } /** * Sets the object in the {@link Editor#DISCARDED} state. @@ -290,7 +305,7 @@ void fireFileLoading() // fileID can be annotationID if fileName is null // E.g. if EditorModel(long annotationID) was the constructor. - currentLoader = new FileLoader(component, fileName, fileID, size); + currentLoader = new FileLoader(component, ctx, fileName, fileID, size); currentLoader.load(); state = Editor.LOADING; } @@ -357,6 +372,9 @@ boolean setFileToEdit(File file) "original file will erase the original XML format."); // must avoid overwriting the original file... // 'Save' won't work. + if (fileID > 0) { //try to read a file downloaded + file.delete(); + } fileToEdit = null; setFileAnnotationData(null); @@ -477,7 +495,7 @@ void fireFileSaving(File file, boolean asynch) if (description != null) data.setDescription(description); if (asynch) { - currentLoader = new FileSaver(component, file, data, fileType, + currentLoader = new FileSaver(component, ctx, file, data, fileType, linkTo); currentLoader.load(); state = Editor.SAVING; @@ -485,7 +503,7 @@ void fireFileSaving(File file, boolean asynch) OmeroMetadataService svc = EditorAgent.getRegistry().getMetadataService(); try { - svc.archivedFile(fileAnnotation, file, fileType, linkTo); + svc.archivedFile(ctx, fileAnnotation, file, fileType, linkTo); } catch (Exception e) { LogMessage msg = new LogMessage(); msg.print("State: "+state); @@ -605,5 +623,22 @@ boolean isUserOwner() return EditorUtil.isUserOwner(fileAnnotation, userID); } + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext() { return ctx; } + /** + * Sets the security context. + * + * @param groupId The id of the group. + */ + void setSecurityContext(long groupId) + { + if (ctx.getGroupID() != groupId) + ctx = new SecurityContext(groupId); + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorToolBar.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorToolBar.java index 2b1944ae97a..2e324520a4d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorToolBar.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorToolBar.java @@ -24,18 +24,26 @@ //Java imports +import java.awt.Color; +import java.awt.FlowLayout; +import java.util.Set; + import javax.swing.Action; +import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JToolBar; - -import org.openmicroscopy.shoola.agents.editor.uiComponents.CustomButton; +import javax.swing.border.EmptyBorder; //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.agents.editor.EditorAgent; +import org.openmicroscopy.shoola.agents.editor.actions.PersonalManagementAction; +import org.openmicroscopy.shoola.agents.editor.uiComponents.CustomButton; /** * The tool bar of {@link Editor}. @@ -62,9 +70,26 @@ class EditorToolBar EditorControl.SAVE_FILE }; + /** The text indicating that the file is saved in the specified group.*/ + static final String SAVED = "Saved in"; + + /** The text indicating to select the group where to select the group.*/ + static final String SAVE = "Save to"; + /** Reference to the Control. */ private EditorControl controller; + /** Reference to the View. */ + private EditorUI view; + + /** + * The label indicating where to save the file or where the file is saved. + */ + private JLabel groupLabel; + + /** The component used to display the name of the group.*/ + private JButton groupButton; + /** * Creates the bar. * @@ -83,13 +108,37 @@ private JToolBar createBar() return bar; } + /** + * Creates the management bar. + * + * @return See above. + */ + private JPanel createManagementBar() + { + groupLabel = new JLabel(); + PersonalManagementAction a = (PersonalManagementAction) + controller.getAction(EditorControl.PERSONAL); + groupButton = new JButton(a); + BorderFactory.createCompoundBorder(new EmptyBorder(2, 2, 2, 2), + BorderFactory.createLineBorder(Color.GRAY)); + Set l = EditorAgent.getAvailableUserGroups(); + if (l.size() > 1) + groupButton.addMouseListener(a); + JPanel bar = new JPanel(); + bar.setLayout(new FlowLayout(FlowLayout.LEFT)); + bar.add(groupLabel); + bar.add(groupButton); + setGroupInformation(); + return bar; + } + /** * Convenience method for getting an {@link Action} from the * {@link #controller}, creating a {@link CustomButton} and adding * it to the component; * - * @param actionId Action ID, e.g. {@link EditorControl#CLOSE_EDITOR} - * @param comp The component to add the button. + * @param actionId Action ID, e.g. {@link EditorControl#CLOSE_EDITOR} + * @param comp The component to add the button. */ private void addAction(int actionId, JComponent comp) { @@ -97,7 +146,7 @@ private void addAction(int actionId, JComponent comp) b.setText(""); comp.add(b); } - + /** Builds and lays out the UI. */ private void buildGUI() { @@ -105,6 +154,9 @@ private void buildGUI() toolBars.setBorder(null); toolBars.setLayout(new BoxLayout(toolBars, BoxLayout.X_AXIS)); toolBars.add(createBar()); + Set l = EditorAgent.getAvailableUserGroups(); + if (!view.isStandalone() && l.size() > 1) + toolBars.add(createManagementBar()); setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); add(toolBars); /* @@ -131,15 +183,38 @@ private void buildGUI() /** * Creates a new instance. * - * @param controller Reference to the control. - * Mustn't be null. + * @param controller Reference to the control. Mustn't be null. + * @param view Reference to the view. Mustn't be null. */ - EditorToolBar(EditorControl controller) + EditorToolBar(EditorControl controller, EditorUI view) { if (controller == null) throw new NullPointerException("No controller."); + if (view == null) + throw new NullPointerException("No view."); this.controller = controller; + this.view = view; buildGUI(); } + /** + * Sets the information about the group depending on the context and if the + * file has been saved or not. + */ + void setGroupInformation() + { + if (view.isStandalone()) return; + if (groupLabel == null || groupButton == null) return; + long id = view.getFileID(); + PersonalManagementAction a = (PersonalManagementAction) + controller.getAction(EditorControl.PERSONAL); + if (id <= 0) { + groupLabel.setText(SAVE); + a.setPermissions(); + } else { + groupLabel.setText(SAVED); + groupButton.removeMouseListener(a); + } + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorUI.java index 3771be027ec..f6e002c966d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/editor/view/EditorUI.java @@ -24,22 +24,32 @@ //Java imports import java.awt.BorderLayout; +import java.awt.Component; import java.awt.Container; import java.awt.Dimension; +import java.awt.Point; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import javax.swing.BorderFactory; import javax.swing.Box; +import javax.swing.ButtonGroup; +import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; +import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JSeparator; import javax.swing.JTextPane; import javax.swing.KeyStroke; import javax.swing.SwingConstants; +import javax.swing.border.BevelBorder; import javax.swing.border.EmptyBorder; //Third-party libraries @@ -47,10 +57,14 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.editor.EditorAgent; import org.openmicroscopy.shoola.agents.editor.actions.EditorAction; +import org.openmicroscopy.shoola.agents.editor.actions.GroupSelectionAction; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.ui.TaskBar; import org.openmicroscopy.shoola.env.ui.TopWindow; import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.ExperimenterData; + /** * The {@link Editor}'s View. * @@ -86,7 +100,10 @@ class EditorUI * A Panel to display in the center of this window if there is no file * to show. */ - private JPanel splashScreen; + private JPanel splashScreen; + + /** The menu displaying the available groups.*/ + private JPopupMenu groupMenu; /** * Creates the file menu. @@ -212,7 +229,7 @@ void initialize(EditorControl controller, EditorModel model) if (model == null) throw new NullPointerException("No model."); this.controller = controller; this.model = model; - toolBar = new EditorToolBar(controller); + toolBar = new EditorToolBar(controller, this); statusBar = new EditorStatusBar(); setJMenuBar(createMenuBar()); buildGUI(); @@ -249,6 +266,24 @@ void displayFile(String contents) repaint(); } + /** + * Returns true if the editor is not connected to the server, + * false otherwise. + * + * @return See above. + */ + boolean isStandalone() + { + return model.getSecurityContext() == null; + } + + /** + * Returns the id of the file saved on the server. + * + * @return See above. + */ + long getFileID() { return model.getFileID(); } + /** Displays the browser by adding it to this UI. */ void displayFile() { @@ -262,6 +297,58 @@ void displayFile() repaint(); } + /** + * Brings up the menu on top of the specified component at + * the specified location. + * + * @param menuID The id of the menu. + * @param invoker The component that requested the pop-up menu. + * @param loc The point at which to display the menu, relative to the + * component's coordinates. + */ + void showMenu(int menuID, Component c, Point p) + { + switch (menuID) { + case Editor.GROUP_MENU: + if (groupMenu == null) { + groupMenu = new JPopupMenu(); + groupMenu.setBorder( + BorderFactory.createBevelBorder(BevelBorder.RAISED)); + Set groups = EditorAgent.getAvailableUserGroups(); + List l = + controller.getUserGroupAction(); + Iterator i = l.iterator(); + GroupSelectionAction a; + JCheckBoxMenuItem item; + ButtonGroup buttonGroup = new ButtonGroup(); + SecurityContext ctx = model.getSecurityContext(); + long gid = -1; + if (ctx != null) gid = ctx.getGroupID(); + while (i.hasNext()) { + a = i.next(); + item = new JCheckBoxMenuItem(a); + item.setEnabled(true); + item.setSelected(a.isSameGroup(gid)); + item.setBorder(null); + buttonGroup.add(item); + groupMenu.add(item); + } + } + groupMenu.show(c, p.x, p.y); + break; + + default: + break; + } + + } + + /** + * Sets the information about the group depending on the context and if the + * file has been saved or not. + */ + void setGroupInformation() { toolBar.setGroupInformation(); } + /** * Overrides the {@link #setOnScreen() setOnScreen} method. * Does not make the window visible, since this only occurs after diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/editor/EditFileEvent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/editor/EditFileEvent.java index 434c0351b34..ac67a86d14d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/editor/EditFileEvent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/editor/EditFileEvent.java @@ -28,6 +28,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.RequestEvent; import pojos.FileAnnotationData; @@ -53,29 +54,37 @@ public class EditFileEvent private FileAnnotationData fileAnnotation; /** The id of the annotation to edit. */ - private long fileAnnotationID; + private long fileAnnotationID; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a new instance. * - * @param fileAnnotation The annotation hosting the information about - * the file to edit. + * @param ctx The security context. + * @param fileAnnotation The annotation hosting the information about + * the file to edit. */ - public EditFileEvent(FileAnnotationData fileAnnotation) + public EditFileEvent(SecurityContext ctx, + FileAnnotationData fileAnnotation) { if (fileAnnotation == null) throw new IllegalArgumentException("No file annotation."); + this.ctx = ctx; this.fileAnnotation = fileAnnotation; } /** * Creates a new instance. * + * @param ctx The security context. * @param fileAnnotationID The id of the annotation to edit. */ - public EditFileEvent(long fileAnnotationID) + public EditFileEvent(SecurityContext ctx, long fileAnnotationID) { this.fileAnnotationID = fileAnnotationID; + this.ctx = ctx; } /** @@ -92,4 +101,11 @@ public EditFileEvent(long fileAnnotationID) */ public long getFileAnnotationID() { return fileAnnotationID; } -} + /** + * Returns the security context. + * + * @return See above. + */ + public SecurityContext getSecurityContext() { return ctx; } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/editor/ShowEditorEvent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/editor/ShowEditorEvent.java index 3377b863d55..f9b5d77c978 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/editor/ShowEditorEvent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/editor/ShowEditorEvent.java @@ -28,6 +28,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.RequestEvent; import pojos.DataObject; @@ -61,32 +62,42 @@ public class ShowEditorEvent private DataObject parent; /** The name of the file. */ - private String name; + private String name; /** The type of editor file to create. */ - private int type; + private int type; - /** Creates a new instance. */ - public ShowEditorEvent() + /** The security context.*/ + private SecurityContext ctx; + + /** + * Creates a new instance. + * + * @param ctx The security context. + */ + public ShowEditorEvent(SecurityContext ctx) { type = PROTOCOL; parent = null; + this.ctx = ctx; } /** * Creates a new instance. * + * @param ctx The security context. * @param parent The data object the new experiment should be linked to. * @param name The name to give to the experiment. * @param type One of the constants defined by this class. */ - public ShowEditorEvent(DataObject parent, String name, int type) + public ShowEditorEvent(SecurityContext ctx, DataObject parent, String name, + int type) { this.parent = parent; this.name = name; - if (type == PROTOCOL || type == EXPERIMENT) - this.type = type; + if (type == PROTOCOL || type == EXPERIMENT) this.type = type; else this.type = PROTOCOL; + this.ctx = ctx; } /** @@ -110,5 +121,11 @@ public ShowEditorEvent(DataObject parent, String name, int type) */ public int getType() { return type; } + /** + * Returns the security context. + * + * @return See above. + */ + public SecurityContext getSecurityContext() { return ctx; } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/importer/LoadImporter.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/importer/LoadImporter.java index 96d9a6944f8..e8bb714c1b6 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/importer/LoadImporter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/importer/LoadImporter.java @@ -24,7 +24,8 @@ //Java imports -import java.util.Collection; +import java.util.List; +import java.util.Map; //Third-party libraries @@ -54,11 +55,14 @@ public class LoadImporter private TreeImageDisplay selectedContainer; /** The objects used for selection. */ - private Collection objects; + private Map>> objects; /** The type of the import to handle. */ private int type; + /** The group context.*/ + private long groupId; + /** * Creates a new instance. * @@ -67,9 +71,24 @@ public class LoadImporter public LoadImporter(TreeImageDisplay selectedContainer, int type) { this.selectedContainer = selectedContainer; + groupId = -1; this.type = type; } + /** + * Sets the identifier of the group. + * + * @param groupId The id of the group. + */ + public void setGroup(long groupId) { this.groupId = groupId; } + + /** + * Returns the id of the group. + * + * @return See above. + */ + public long getGroup() { return groupId; } + /** * Returns the container. * @@ -89,14 +108,17 @@ public LoadImporter(TreeImageDisplay selectedContainer, int type) * * @return See above. */ - public Collection getObjects() { return objects; } + public Map>> getObjects() + { + return objects; + } /** * Returns the top nodes. * * @param datasets The values to set. */ - public void setObjects(Collection objects) + public void setObjects(Map>> objects) { this.objects = objects; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/iviewer/MeasurementTool.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/iviewer/MeasurementTool.java index 00a546b4e20..6647e9bcfad 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/iviewer/MeasurementTool.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/iviewer/MeasurementTool.java @@ -32,6 +32,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.RequestEvent; import pojos.ChannelData; @@ -103,24 +104,28 @@ public class MeasurementTool /** The size along the Y-axis.*/ private int sizeY; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a new instance. * - * @param imageID The image ID. - * @param pixels The pixels set the measurement tool is for. - * @param name The name of the image. - * @param defaultZ The currently selected z-section. - * @param defaultT The currently selected timepoint. - * @param activeChannels Collection of pairs - * (channel's index, channel's color). - * @param magnification The magnification factor. - * @param bounds The bounds of the component posting the event. - * @param channelData The channel metadata. + * @param ctx The security context. + * @param imageID The image ID. + * @param pixels The pixels set the measurement tool is for. + * @param name The name of the image. + * @param defaultZ The currently selected z-section. + * @param defaultT The currently selected timepoint. + * @param activeChannels Collection of pairs + * (channel's index, channel's color). + * @param magnification The magnification factor. + * @param bounds The bounds of the component posting the event. + * @param channelData The channel metadata. */ - public MeasurementTool(long imageID, PixelsData pixels, String name, - int defaultZ, int defaultT, Map activeChannels, - double magnification, Rectangle bounds, - List channelData) + public MeasurementTool(SecurityContext ctx, long imageID, PixelsData pixels, + String name, int defaultZ, int defaultT, Map activeChannels, + double magnification, Rectangle bounds, + List channelData) { if (pixels == null) throw new IllegalArgumentException("Pixels set not valid."); @@ -128,6 +133,7 @@ public MeasurementTool(long imageID, PixelsData pixels, String name, throw new IllegalArgumentException("Image ID not valid."); if (channelData == null || channelData.size() == 0) throw new IllegalArgumentException("Channel data not valid."); + this.ctx = ctx; this.channelData = channelData; this.pixels = pixels; this.imageID = imageID; @@ -317,4 +323,11 @@ public void setRenderedImage(BufferedImage renderedImage) */ public List getChannelData() { return channelData; } + /** + * Returns the security context. + * + * @return See above. + */ + public SecurityContext getSecurityContext() { return ctx; } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/iviewer/ViewImage.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/iviewer/ViewImage.java index 889fc5c4e0d..c4932251c1b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/iviewer/ViewImage.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/iviewer/ViewImage.java @@ -34,6 +34,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.RequestEvent; /** @@ -56,27 +57,35 @@ public class ViewImage { /** The images to view. */ - private List images; + private List images; /** The bounds of the component posting the event. */ - private Rectangle requesterBounds; + private Rectangle requesterBounds; /** * Flag indicating if the viewer should be opened as a separate window * or not. The default value is true. */ - private boolean separateWindow; + private boolean separateWindow; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a new instance. * - * @param image The id of the image to view. - * @param bounds The bounds of the component posting the event. + * @param ctx The security context. + * @param image The id of the image to view. + * @param bounds The bounds of the component posting the event. */ - public ViewImage(ViewImageObject image, Rectangle bounds) + public ViewImage(SecurityContext ctx, + ViewImageObject image, Rectangle bounds) { if (image == null) throw new IllegalArgumentException("Image not null."); + if (ctx == null) + throw new IllegalArgumentException("No security context."); + this.ctx = ctx; images = new ArrayList(); images.add(image); requesterBounds = bounds; @@ -128,5 +137,12 @@ public void setSeparateWindow(boolean separateWindow) { this.separateWindow = separateWindow; } + + /** + * Returns the security context. + * + * @return See above. + */ + public SecurityContext getSecurityContext() { return ctx; } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/measurement/MeasurementToolLoaded.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/measurement/MeasurementToolLoaded.java index ece9e337b9d..f08699b022d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/measurement/MeasurementToolLoaded.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/measurement/MeasurementToolLoaded.java @@ -29,6 +29,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.RequestEvent; import org.openmicroscopy.shoola.env.event.ResponseEvent; @@ -59,7 +60,10 @@ public class MeasurementToolLoaded private JComponent view; /** One of the constants defined by this class. */ - private int index; + private int index; + + /** The security context.*/ + private SecurityContext ctx; /** * Controls if the passed index is valid. @@ -81,16 +85,19 @@ private void checkIndex(int i) /** * Creates a new instance. * - * @param act The original request. - * @param view The component to add to the display. + * @param act The original request. + * @param ctx The security context. + * @param view The component to add to the display. * @param index One of the constants defined by this class. */ - public MeasurementToolLoaded(RequestEvent act, JComponent view, int index) + public MeasurementToolLoaded(RequestEvent act, SecurityContext ctx, + JComponent view, int index) { super(act); checkIndex(index); this.index = index; this.view = view; + this.ctx = ctx; } /** @@ -107,4 +114,11 @@ public MeasurementToolLoaded(RequestEvent act, JComponent view, int index) */ public int getIndex() { return index; } + /** + * Returns the security context. + * + * @return See above. + */ + public SecurityContext getSecurityContext() { return ctx; } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/measurement/SelectPlane.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/measurement/SelectPlane.java index fc0546d968a..1b3737fe497 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/measurement/SelectPlane.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/measurement/SelectPlane.java @@ -47,13 +47,13 @@ public class SelectPlane { /** The ID of the pixels set. */ - private long pixelsID; + private long pixelsID; /** The currently selected z-section. */ - private int defaultZ; + private int defaultZ; /** The currently selected timepoint. */ - private int defaultT; + private int defaultT; /* The bounds of the ROI for big image.*/ private Rectangle bounds; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/treeviewer/ExperimenterLoadedDataEvent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/treeviewer/ExperimenterLoadedDataEvent.java index 37d3cef62af..7e50a0c408c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/treeviewer/ExperimenterLoadedDataEvent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/treeviewer/ExperimenterLoadedDataEvent.java @@ -46,14 +46,15 @@ public class ExperimenterLoadedDataEvent { /** Map hosting the data objects owned by users displayed.*/ - private Map> data; + private Map>> data; /** * Creates a new instance. * * @param data The data to store. */ - public ExperimenterLoadedDataEvent(Map> data) + public ExperimenterLoadedDataEvent( + Map>> data) { this.data = data; } @@ -63,6 +64,9 @@ public ExperimenterLoadedDataEvent(Map> data) * * @return See above. */ - public Map> getData() { return data; } + public Map>> getData() + { + return data; + } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/events/treeviewer/MoveToEvent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/treeviewer/MoveToEvent.java new file mode 100644 index 00000000000..5fb2eb2b65d --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/events/treeviewer/MoveToEvent.java @@ -0,0 +1,80 @@ +/* + * org.openmicroscopy.shoola.agents.events.treeviewer.MoveToEvent + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.agents.events.treeviewer; + + +//Java imports +import java.util.List; + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.env.event.RequestEvent; +import pojos.DataObject; +import pojos.GroupData; + +/** + * Posts an event indicating to move the passed objects to the selectd group. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class MoveToEvent + extends RequestEvent +{ + + /** The group to move the data to.*/ + private GroupData group; + + /** The objects to move.*/ + private List objects; + + /** + * Creates a new instance. + * + * @param group The group to move the data to. + * @param objects The objects to move. + */ + public MoveToEvent(GroupData group, List objects) + { + this.objects = objects; + this.group = group; + } + + /** + * Returns the group to move the data to. + * + * @return See above. + */ + public GroupData getGroup() { return group; } + + /** + * Returns the objects to move. + * + * @return See above. + */ + public List getObjects() { return objects; } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataImporterLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataImporterLoader.java index f7bface1cc6..38a026c2013 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataImporterLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataImporterLoader.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.AdminView; import org.openmicroscopy.shoola.env.data.views.DataManagerView; import org.openmicroscopy.shoola.env.data.views.ImageDataView; @@ -64,28 +65,31 @@ public abstract class DataImporterLoader { /** The Importer this data loader is for. */ - protected final Importer viewer; + protected final Importer viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final ImageDataView ivView; + protected final ImageDataView ivView; /** Convenience reference for subclasses. */ - protected final MetadataHandlerView mhView; + protected final MetadataHandlerView mhView; /** Convenience reference for subclasses. */ - protected final AdminView adminView; + protected final AdminView adminView; /** Convenience reference for subclasses. */ - protected final DataManagerView dmView; + protected final DataManagerView dmView; /** The id of the user or -1. */ - protected long userID; + protected long userID; /** The id of the group or -1. */ - protected long groupID; + protected long groupID; + + /** The security context.*/ + protected final SecurityContext ctx; /** * Helper method to return the ID of the currently logged in user. @@ -117,11 +121,13 @@ void setIds() * * @param viewer The Importer this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - protected DataImporterLoader(Importer viewer) + protected DataImporterLoader(Importer viewer, SecurityContext ctx) { if (viewer == null) throw new NullPointerException("No viewer."); - this.viewer = viewer; + this.viewer = viewer; + this.ctx = ctx; registry = ImporterAgent.getRegistry(); ivView = (ImageDataView) registry.getDataServicesView(ImageDataView.class); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataLoader.java index 093ca5c82a3..86b35e70492 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.fsimporter.view.Importer; import org.openmicroscopy.shoola.agents.treeviewer.DataBrowserLoader; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ProjectData; import pojos.ScreenData; @@ -65,14 +66,16 @@ public class DataLoader /** * Creates a new instance. * - * @param viewer The Importer this data loader is for. - * Mustn't be null. - * @param rootType Either Project or Screen. + * @param viewer The Importer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param rootType Either Project or Screen. * @param refreshImport Flag indicating to refresh the on-going import. */ - public DataLoader(Importer viewer, Class rootType, boolean refreshImport) + public DataLoader(Importer viewer, SecurityContext ctx, Class rootType, + boolean refreshImport) { - super(viewer); + super(viewer, ctx); if (!(ProjectData.class.equals(rootType) || ScreenData.class.equals(rootType))) throw new IllegalArgumentException("Type not supported."); @@ -86,7 +89,7 @@ public DataLoader(Importer viewer, Class rootType, boolean refreshImport) */ public void load() { - handle = dmView.loadContainerHierarchy(rootType, null, false, + handle = dmView.loadContainerHierarchy(ctx, rootType, null, false, getCurrentUserID(), groupID, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataObjectCreator.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataObjectCreator.java index eae4314b7ed..8b0eb6d67c4 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataObjectCreator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DataObjectCreator.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.fsimporter.view.Importer; import org.openmicroscopy.shoola.agents.treeviewer.DataBrowserLoader; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; @@ -65,16 +66,17 @@ public class DataObjectCreator /** * Creates a new instance. * - * @param viewer The Importer this data loader is for. - * Mustn't be null. - * @param child The {@link DataObject} to handle. - * @param parent The parent of the object to create, - * null if no parent. + * @param viewer The Importer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param child The {@link DataObject} to handle. + * @param parent The parent of the object to create, + * null if no parent. */ - public DataObjectCreator(Importer viewer, DataObject child, - DataObject parent) + public DataObjectCreator(Importer viewer, SecurityContext ctx, + DataObject child, DataObject parent) { - super(viewer); + super(viewer, ctx); if (child == null) throw new IllegalArgumentException("No object to create."); this.parent = parent; @@ -87,7 +89,7 @@ public DataObjectCreator(Importer viewer, DataObject child, */ public void load() { - handle = dmView.createDataObject(child, parent, this); + handle = dmView.createDataObject(ctx, child, parent, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DirectoryMonitor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DirectoryMonitor.java index 5202529750d..f4d269542b8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DirectoryMonitor.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DirectoryMonitor.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.fsimporter.view.Importer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; @@ -66,13 +67,14 @@ public class DirectoryMonitor * * @param viewer The Importer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param directory The directory to monitor. * @param container The container where to import the image to. */ - public DirectoryMonitor(Importer viewer, File directory, - DataObject container) + public DirectoryMonitor(Importer viewer, SecurityContext ctx, + File directory, DataObject container) { - super(viewer); + super(viewer, ctx); if (directory == null) throw new IllegalArgumentException("No directory to monitor."); this.directory = directory; @@ -85,7 +87,7 @@ public DirectoryMonitor(Importer viewer, File directory, */ public void load() { - handle = ivView.monitorDirectory(directory, container, + handle = ivView.monitorDirectory(ctx, directory, container, getCurrentUserID(), -1, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DiskSpaceLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DiskSpaceLoader.java index 77d488a37fc..88ff44488e8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DiskSpaceLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/DiskSpaceLoader.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.agents.fsimporter.view.Importer; import org.openmicroscopy.shoola.agents.metadata.EditorLoader; import org.openmicroscopy.shoola.env.data.model.DiskQuota; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; @@ -59,10 +60,11 @@ public class DiskSpaceLoader * Creates a new instance. * * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. */ - public DiskSpaceLoader(Importer viewer) + public DiskSpaceLoader(Importer viewer, SecurityContext ctx) { - super(viewer); + super(viewer, ctx); } /** @@ -71,7 +73,7 @@ public DiskSpaceLoader(Importer viewer) */ public void load() { - handle = adminView.getDiskSpace(ExperimenterData.class, + handle = adminView.getDiskSpace(ctx, ExperimenterData.class, getCurrentUserID(), this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/ImagesImporter.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/ImagesImporter.java index cfde366b49e..9c3d206dcb2 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/ImagesImporter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/ImagesImporter.java @@ -39,6 +39,7 @@ import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.model.ImportableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -75,13 +76,14 @@ public class ImagesImporter * * @param viewer The Importer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param context The context of the import. * @param loaderID The identifier of the loader. */ - public ImagesImporter(Importer viewer, ImportableObject context, - Integer loaderID) + public ImagesImporter(Importer viewer, + ImportableObject context, Integer loaderID) { - super(viewer); + super(viewer, null); if (context == null || context.getFiles() == null || context.getFiles().size() == 0) throw new IllegalArgumentException("No Files to import."); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/ImporterAgent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/ImporterAgent.java index 5c3876fa56a..c992b86bfc1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/ImporterAgent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/ImporterAgent.java @@ -39,6 +39,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.events.importer.LoadImporter; import org.openmicroscopy.shoola.agents.events.treeviewer.BrowserSelectionEvent; +import org.openmicroscopy.shoola.agents.events.treeviewer.ChangeUserGroupEvent; import org.openmicroscopy.shoola.agents.events.treeviewer.ExperimenterLoadedDataEvent; import org.openmicroscopy.shoola.agents.fsimporter.view.Importer; import org.openmicroscopy.shoola.agents.fsimporter.view.ImporterFactory; @@ -75,13 +76,16 @@ public class ImporterAgent { /** Reference to the registry. */ - private static Registry registry; + private static Registry registry; /** The selected browser type.*/ private int browserType; /** The objects displayed.*/ - private List objects; + private Map>> objects; + + /** The group id if set.*/ + private long groupId; /** * Helper method. @@ -148,7 +152,8 @@ private int getDefaultBrowser() private void handleLoadImporter(LoadImporter evt) { if (evt == null) return; - Importer importer = ImporterFactory.getImporter(); + long groupId = evt.getGroup(); + Importer importer = ImporterFactory.getImporter(groupId); if (importer != null) { int t; switch (evt.getType()) { @@ -162,7 +167,12 @@ private void handleLoadImporter(LoadImporter evt) t = browserType; else t = getDefaultBrowser(); } - importer.activate(t, evt.getSelectedContainer(), evt.getObjects()); + // + //objects = evt.getObjects(); + Map> data = objects.get(groupId); + List l = null; + if (data != null) l = data.get(getUserDetails().getId()); + importer.activate(t, evt.getSelectedContainer(), l); } } @@ -189,6 +199,26 @@ private void handleReconnectedEvent(ReconnectedEvent evt) ImporterFactory.onReconnected(); } + /** + * Returns the containers if available for the specified group. + * + * @param groupId The id of the group. + */ + private List handleContainers(long groupId) + { + if (objects == null) return null; + Map> data = objects.get(groupId); + if (data == null) return null; + List l = data.get(getUserDetails().getId()); + if (l == null) return null; + Iterator i = l.iterator(); + List values = new ArrayList(); + while (i.hasNext()) { + values.add(i.next().getUserObject()); + } + return values; + } + /** * Handles the fact that data were loaded. * @@ -198,19 +228,17 @@ private void handleExperimenterLoadedDataEvent( ExperimenterLoadedDataEvent evt) { if (evt == null) return; - Importer importer = ImporterFactory.getImporter(); - Map> map = evt.getData(); - if (map == null || map.size() == 0) return; - List l = map.get(getUserDetails().getId()); - objects = l; - if (importer != null && objects != null) { - Iterator i = objects.iterator(); - List values = new ArrayList(); - while (i.hasNext()) { - values.add(i.next().getUserObject()); - } - importer.setContainers(values, true, browserType); - } + + Map>> map = evt.getData(); + objects = map; + if (!ImporterFactory.doesImporterExist()) return; + Importer importer = ImporterFactory.getImporter(-1); + if (importer == null || map == null || map.size() == 0) return; + GroupData group = importer.getSelectedGroup(); + if (group == null) return; + List l = handleContainers(group.getId()); + if (l == null || l.size() == 0) return; + importer.setContainers(l, true, browserType); } /** Registers the agent with the tool bar.*/ @@ -226,7 +254,20 @@ private void register() /** Posts an event to start the agent.*/ public void actionPerformed(ActionEvent e) { EventBus bus = registry.getEventBus(); + ExperimenterData exp = (ExperimenterData) registry.lookup( + LookupNames.CURRENT_USER_DETAILS); + if (exp == null) return; + GroupData gp = null; + try { + gp = exp.getDefaultGroup(); + } catch (Exception ex) { + //No default group + } + long id = -1; + if (gp != null) id = gp.getId(); + if (groupId == -1) groupId = id; LoadImporter event = new LoadImporter(null, browserType); + event.setGroup(groupId); event.setObjects(objects); bus.post(event); } @@ -261,7 +302,7 @@ public void activate(boolean master) } long id = -1; if (gp != null) id = gp.getId(); - Importer importer = ImporterFactory.getImporter(id); + Importer importer = ImporterFactory.getImporter(id, true); if (importer != null) { Environment env = (Environment) registry.lookup(LookupNames.ENV); int type = Importer.PROJECT_TYPE; @@ -298,7 +339,9 @@ public void setContext(Registry ctx) bus.register(this, ReconnectedEvent.class); bus.register(this, BrowserSelectionEvent.class); bus.register(this, ExperimenterLoadedDataEvent.class); + bus.register(this, ChangeUserGroupEvent.class); browserType = getDefaultBrowser(); + groupId = -1; register(); } @@ -309,7 +352,7 @@ public void setContext(Registry ctx) public boolean canTerminate() { if (!ImporterFactory.doesImporterExist()) return true; - Importer importer = ImporterFactory.getImporter(); + Importer importer = ImporterFactory.getImporter(-1); if (importer == null) return true; return !importer.hasOnGoingImport(); } @@ -344,6 +387,9 @@ else if (e instanceof BrowserSelectionEvent) { browserType = evt.getType(); } else if (e instanceof ExperimenterLoadedDataEvent) { handleExperimenterLoadedDataEvent((ExperimenterLoadedDataEvent) e); + } else if (e instanceof ChangeUserGroupEvent) { + ChangeUserGroupEvent evt = (ChangeUserGroupEvent) e; + groupId = evt.getGroupID(); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/TagsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/TagsLoader.java index f8a8f94e5cd..eeb96a72dd3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/TagsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/TagsLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.fsimporter.view.Importer; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -63,10 +64,11 @@ public class TagsLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - public TagsLoader(Importer viewer) + public TagsLoader(Importer viewer, SecurityContext ctx) { - super(viewer); + super(viewer, ctx); setIds(); } @@ -76,7 +78,7 @@ public TagsLoader(Importer viewer) */ public void load() { - handle = mhView.loadExistingAnnotations(TagAnnotationData.class, + handle = mhView.loadExistingAnnotations(ctx, TagAnnotationData.class, userID, groupID, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/actions/PersonalManagementAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/actions/PersonalManagementAction.java index 0a7887e9c59..3249a7224d3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/actions/PersonalManagementAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/actions/PersonalManagementAction.java @@ -63,7 +63,8 @@ public class PersonalManagementAction { /** The description of the action. */ - private static final String DESCRIPTION = "Select your current group."; + private static final String DESCRIPTION = "Select the group " + + "you wish to import the data to."; /** The location of the mouse pressed. */ private Point point; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/FileElement.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/FileElement.java index 02ebc620bf2..c96c8e278e9 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/FileElement.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/FileElement.java @@ -35,6 +35,8 @@ import org.openmicroscopy.shoola.agents.fsimporter.view.Importer; import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.GroupData; + /** * Hosts information about the file to import. * @@ -69,6 +71,9 @@ class FileElement /** The type when the file was added.*/ private int type; + /** The group where the file will be imported.*/ + private GroupData group; + /** * Determines the length of the directory depending on the actual * level reached and the scanning depth. @@ -98,12 +103,14 @@ private void determineLength(File file, int depth, int level) * * @param file The file to import. * @param type The type of container when the file was added. + * @param group The group where to import the data. */ - FileElement(File file, int type) + FileElement(File file, int type, GroupData group) { if (file == null) throw new IllegalArgumentException("No file set"); this.file = file; + this.group = group; length = -1; this.type = type; if (type == Importer.SCREEN_TYPE) @@ -228,6 +235,13 @@ String getName() */ public File getFile() { return file; } + /** + * Returns the group. + * + * @return See above. + */ + public GroupData getGroup() { return group; } + /** * Overridden to return the name to give to the imported file. * @see Object#toString() diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/FileSelectionTable.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/FileSelectionTable.java index a9c962e28ee..e57d5426310 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/FileSelectionTable.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/FileSelectionTable.java @@ -62,6 +62,7 @@ import org.openmicroscopy.shoola.util.ui.TooltipTableHeader; import org.openmicroscopy.shoola.util.ui.UIUtilities; import pojos.DatasetData; +import pojos.GroupData; /** * Component displaying the files to import. @@ -108,26 +109,31 @@ class FileSelectionTable */ static final int CONTAINER_INDEX = 2; + /** + * The index of the column indicating the group where to import data. + */ + static final int GROUP_INDEX = 3; + /** * The index of the column indicating to use the folder * as a dataset. */ - static final int FOLDER_AS_CONTAINER_INDEX = 3; + static final int FOLDER_AS_CONTAINER_INDEX = 4; /** The index of the column indicating to archive the file. */ - private static final int ARCHIVED_INDEX = 4; + private static final int ARCHIVED_INDEX = 5; /** The columns of the table. */ private static final Vector COLUMNS; - /** The columns of the table. */ - private static final Vector COLUMNS_NO_FOLDER_AS_CONTAINER; - + /** The columns of the table w/o group information */ + private static final Vector COLUMNS_NO_GROUP; + /** The tool-tip of the columns. */ private static final String[] COLUMNS_TOOLTIP; - /** The tool-tip of the columns if no folder specified. */ - private static final String[] COLUMNS_NO_FOLDER_AS_CONTAINER_TOOLTIP; + /** The tool-tip of the columns. */ + private static final String[] COLUMNS_NO_GROUP_TOOLTIP; /** String used to retrieve if the value of the archived flag. */ private static final String ARCHIVED = "/options/Archived"; @@ -138,22 +144,25 @@ class FileSelectionTable /** The text displayed to use the folder as container. */ private static final String FAD_TEXT = "Folder as\nDataset"; - /** The text displayed to archived the files. */ + /** Indicate to archive or not the files. */ private static final String ARCHIVED_TEXT = "Archive"; - /** The text displayed to select the files. */ + /** Indicate to select the files. */ private static final String FILE_TEXT = "File or\nFolder"; - /** The text displayed to indicate the size of the file or folder. */ + /** The text indicating the size of the file or folder. */ private static final String SIZE_TEXT = "Size"; /** - * The text displayed where to import the data to if importing + * The text displaying where to import the data to if importing * to Project/Dataset or Screen. */ private static final String CONTAINER_PROJECT_TEXT = "Project/Dataset\nor Screen"; + /** The group where the files will be imported.*/ + private static final String GROUP_TEXT = "Group"; + /** * The text displayed where to import the data to if importing * to Screen. @@ -161,11 +170,12 @@ class FileSelectionTable private static final String CONTAINER_SCREEN_TEXT = "Screen"; static { - int n = 5; + int n = 6; COLUMNS = new Vector(n); COLUMNS.add(FILE_TEXT); COLUMNS.add(SIZE_TEXT); COLUMNS.add(CONTAINER_PROJECT_TEXT); + COLUMNS.add(GROUP_TEXT); COLUMNS.add(FAD_TEXT); COLUMNS.add(ARCHIVED_TEXT); COLUMNS_TOOLTIP = new String[n]; @@ -173,26 +183,25 @@ class FileSelectionTable COLUMNS_TOOLTIP[SIZE_INDEX] = "Size of File or Folder."; COLUMNS_TOOLTIP[CONTAINER_INDEX] = "The container where to import the data."; + COLUMNS_TOOLTIP[GROUP_INDEX] = "The group where to import data."; COLUMNS_TOOLTIP[FOLDER_AS_CONTAINER_INDEX] = "Convert the folder as dataset."; COLUMNS_TOOLTIP[ARCHIVED_INDEX] = "Archive the data."; - n = 4; - COLUMNS_NO_FOLDER_AS_CONTAINER = new Vector(n); - COLUMNS_NO_FOLDER_AS_CONTAINER.add(FILE_TEXT); - COLUMNS_NO_FOLDER_AS_CONTAINER.add(SIZE_TEXT); - COLUMNS_NO_FOLDER_AS_CONTAINER.add(CONTAINER_PROJECT_TEXT); - COLUMNS_NO_FOLDER_AS_CONTAINER.add(ARCHIVED_TEXT); - - COLUMNS_NO_FOLDER_AS_CONTAINER_TOOLTIP = new String[n]; - COLUMNS_NO_FOLDER_AS_CONTAINER_TOOLTIP[FILE_INDEX] = - COLUMNS_TOOLTIP[FILE_INDEX]; - COLUMNS_NO_FOLDER_AS_CONTAINER_TOOLTIP[SIZE_INDEX] = - COLUMNS_TOOLTIP[SIZE_INDEX]; - COLUMNS_NO_FOLDER_AS_CONTAINER_TOOLTIP[CONTAINER_INDEX] = + COLUMNS_NO_GROUP = new Vector(n-1); + COLUMNS_NO_GROUP.add(FILE_TEXT); + COLUMNS_NO_GROUP.add(SIZE_TEXT); + COLUMNS_NO_GROUP.add(CONTAINER_PROJECT_TEXT); + COLUMNS_NO_GROUP.add(FAD_TEXT); + COLUMNS_NO_GROUP.add(ARCHIVED_TEXT); + COLUMNS_NO_GROUP_TOOLTIP = new String[n-1]; + COLUMNS_NO_GROUP_TOOLTIP[FILE_INDEX] = COLUMNS_TOOLTIP[FILE_INDEX]; + COLUMNS_NO_GROUP_TOOLTIP[SIZE_INDEX] = COLUMNS_TOOLTIP[SIZE_INDEX]; + COLUMNS_NO_GROUP_TOOLTIP[CONTAINER_INDEX] = COLUMNS_TOOLTIP[CONTAINER_INDEX]; - COLUMNS_NO_FOLDER_AS_CONTAINER_TOOLTIP[ARCHIVED_INDEX-1] = - COLUMNS_TOOLTIP[ARCHIVED_INDEX]; + COLUMNS_NO_GROUP_TOOLTIP[FOLDER_AS_CONTAINER_INDEX-1] = + COLUMNS_TOOLTIP[FOLDER_AS_CONTAINER_INDEX]; + COLUMNS_NO_GROUP_TOOLTIP[ARCHIVED_INDEX-1] = COLUMNS_TOOLTIP[ARCHIVED_INDEX]; } /** The button to move an item from the remaining items to current items. */ @@ -233,24 +242,35 @@ private void formatTableModel() tc.setCellRenderer(new FileTableRenderer()); tc = tcm.getColumn(CONTAINER_INDEX); - tc.setCellRenderer(new FileTableRenderer()); - - tc = tcm.getColumn(FOLDER_AS_CONTAINER_INDEX); - tc.setCellEditor(table.getDefaultEditor(Boolean.class)); - tc.setCellRenderer(table.getDefaultRenderer(Boolean.class)); tc.setCellRenderer(new FileTableRenderer()); - tc.setResizable(false); - + String[] tips; - int n = table.getColumnCount(); - if (n == COLUMNS.size()) { + boolean single = model.isSingleGroup(); + if (!single) { + tc = tcm.getColumn(GROUP_INDEX); + tc.setCellRenderer(new FileTableRenderer()); + tc = tcm.getColumn(FOLDER_AS_CONTAINER_INDEX); + tc.setCellEditor(table.getDefaultEditor(Boolean.class)); + tc.setCellRenderer(table.getDefaultRenderer(Boolean.class)); + //tc.setCellRenderer(new FileTableRenderer()); + tc.setResizable(false); tc = tcm.getColumn(ARCHIVED_INDEX); tc.setCellEditor(table.getDefaultEditor(Boolean.class)); tc.setCellRenderer(table.getDefaultRenderer(Boolean.class)); tc.setResizable(false); tips = COLUMNS_TOOLTIP; - } else - tips = COLUMNS_NO_FOLDER_AS_CONTAINER_TOOLTIP; + } else { + tc = tcm.getColumn(FOLDER_AS_CONTAINER_INDEX-1); + tc.setCellEditor(table.getDefaultEditor(Boolean.class)); + tc.setCellRenderer(table.getDefaultRenderer(Boolean.class)); + //tc.setCellRenderer(new FileTableRenderer()); + tc.setResizable(false); + tc = tcm.getColumn(ARCHIVED_INDEX-1); + tc.setCellEditor(table.getDefaultEditor(Boolean.class)); + tc.setCellRenderer(table.getDefaultRenderer(Boolean.class)); + tc.setResizable(false); + tips = COLUMNS_NO_GROUP_TOOLTIP; + } TooltipTableHeader header = new TooltipTableHeader(tcm, tips); table.setTableHeader(header); @@ -263,15 +283,20 @@ private void formatTableModel() tc.setHeaderRenderer(new MultilineHeaderSelectionRenderer()); tc = tcm.getColumn(CONTAINER_INDEX); tc.setHeaderRenderer(new MultilineHeaderSelectionRenderer()); - if (n == COLUMNS.size()) { + if (!single) { + tc = tcm.getColumn(GROUP_INDEX); + tc.setHeaderRenderer(new MultilineHeaderSelectionRenderer()); tc = tcm.getColumn(FOLDER_AS_CONTAINER_INDEX); - tc.setCellRenderer(new FileTableRenderer()); + //tc.setCellRenderer(new FileTableRenderer()); tc.setHeaderRenderer(new MultilineHeaderSelectionRenderer()); tcm.getColumn(ARCHIVED_INDEX).setHeaderRenderer( new MultilineHeaderSelectionRenderer(table, archivedBox)); } else { - tcm.getColumn(FOLDER_AS_CONTAINER_INDEX).setHeaderRenderer( + tcm.getColumn(ARCHIVED_INDEX-1).setHeaderRenderer( new MultilineHeaderSelectionRenderer(table, archivedBox)); + tc = tcm.getColumn(FOLDER_AS_CONTAINER_INDEX-1); + //tc.setCellRenderer(new FileTableRenderer()); + tc.setHeaderRenderer(new MultilineHeaderSelectionRenderer()); } /* String text = CONTAINER_PROJECT_TEXT; @@ -309,8 +334,10 @@ private void initComponents() if (b != null) archived = b.booleanValue(); b = (Boolean) ImporterAgent.getRegistry().lookup(ARCHIVED_AVAILABLE); if (b != null) archivedTunable = b.booleanValue(); + if (model.isSingleGroup()) selectedColumns = COLUMNS_NO_GROUP; + else selectedColumns = COLUMNS; //if (model.useFolderAsContainer()) { - selectedColumns = COLUMNS; + //} else { // selectedColumns = COLUMNS_NO_FOLDER_AS_CONTAINER; //} @@ -466,7 +493,7 @@ List getFilesToImport() FileElement element; File file; ImportableFile importable; - int columns = table.getColumnCount(); + boolean single = model.isSingleGroup(); boolean b; DataNodeElement dne; DatasetData dataset; @@ -475,25 +502,24 @@ List getFilesToImport() dne = (DataNodeElement) dtm.getValueAt(i, CONTAINER_INDEX); file = element.getFile(); dataset = dne.getLocation(); - if (columns == COLUMNS_NO_FOLDER_AS_CONTAINER.size()) { + if (single) { + b = Boolean.valueOf((Boolean) dtm.getValueAt(i, + FOLDER_AS_CONTAINER_INDEX-1)); importable = new ImportableFile(file, Boolean.valueOf((Boolean) dtm.getValueAt(i, - FOLDER_AS_CONTAINER_INDEX))); + ARCHIVED_INDEX-1)), b); } else { - /* - if (file.isFile()) b = false; - else b = Boolean.valueOf((Boolean) dtm.getValueAt(i, - FOLDER_AS_CONTAINER_INDEX)); - */ b = Boolean.valueOf((Boolean) dtm.getValueAt(i, FOLDER_AS_CONTAINER_INDEX)); importable = new ImportableFile(file, Boolean.valueOf((Boolean) dtm.getValueAt(i, ARCHIVED_INDEX)), b); - if (b) dataset = null; } + + if (b) dataset = null; importable.setLocation(dne.getParent(), dataset); importable.setRefNode(dne.getRefNode()); + importable.setGroup(element.getGroup()); files.add(importable); } return files; @@ -507,8 +533,8 @@ List getFilesToImport() void reset(boolean value) { allowAddition(value); - if (model.useFolderAsContainer()) selectedColumns = COLUMNS; - else selectedColumns = COLUMNS_NO_FOLDER_AS_CONTAINER; + if (model.isSingleGroup()) selectedColumns = COLUMNS_NO_GROUP; + else selectedColumns = COLUMNS; table.setModel(new FileTableModel(selectedColumns)); formatTableModel(); } @@ -544,8 +570,9 @@ void removeAllFiles() * @param files The files to add. * @param fad Pass true to indicate to mark the folder as * a dataset, false otherwise. + * @param group The group where to import the file. */ - void addFiles(List files, boolean fad) + void addFiles(List files, boolean fad, GroupData group) { if (files == null || files.size() == 0) return; addButton.setEnabled(false); @@ -560,8 +587,7 @@ void addFiles(List files, boolean fad) inQueue.add(element.getFile().getAbsolutePath()); } Iterator i = files.iterator(); - int n = dtm.getColumnCount(); - boolean b = n == COLUMNS.size(); + boolean multi = !model.isSingleGroup(); DataNode node = model.getImportLocation(); if (node.isDefaultNode() && model.getType() != Importer.SCREEN_TYPE) node.setParent(model.getParentImportLocation()); @@ -571,33 +597,35 @@ void addFiles(List files, boolean fad) while (i.hasNext()) { f = i.next(); if (!inQueue.contains(f.getAbsolutePath())) { - element = new FileElement(f, model.getType()); + element = new FileElement(f, model.getType(), group); element.setName(f.getName()); value = null; v = false; - if (b) { - if (f.isDirectory()) { - value = f.getName(); - v = fad; - if (model.getType() == Importer.SCREEN_TYPE) { - //v = false; - value = null; - } - } else { - if (model.isParentFolderAsDataset()) { - value = f.getParentFile().getName(); - v = true; - element.setToggleContainer(v); - } + if (f.isDirectory()) { + value = f.getName(); + v = fad; + if (model.getType() == Importer.SCREEN_TYPE) { + //v = false; + value = null; + } + } else { + if (model.isParentFolderAsDataset()) { + value = f.getParentFile().getName(); + v = true; + element.setToggleContainer(v); } + } + if (multi) { + dtm.addRow(new Object[] {element, + element.getFileLengthAsString(), + new DataNodeElement(node, value), group.getName(), + Boolean.valueOf(v), Boolean.valueOf(a)}); + } else { dtm.addRow(new Object[] {element, element.getFileLengthAsString(), new DataNodeElement(node, value), Boolean.valueOf(v), Boolean.valueOf(a)}); - } else dtm.addRow(new Object[] {element, - element.getFileLengthAsString(), - new DataNodeElement(node, null), - Boolean.valueOf(a)}); + } } } model.onSelectionChanged(); @@ -630,14 +658,14 @@ void markFolderAsDataset(boolean fad) { int n = table.getRowCount(); if (n == 0) return; - int m = table.getColumnCount(); - if (COLUMNS_NO_FOLDER_AS_CONTAINER.size() == m) return; - DefaultTableModel model = (DefaultTableModel) table.getModel(); + DefaultTableModel dtm = (DefaultTableModel) table.getModel(); FileElement element; + int j = 0; + if (model.isSingleGroup()) j = -1; for (int i = 0; i < n; i++) { - element = (FileElement) model.getValueAt(i, FILE_INDEX); + element = (FileElement) dtm.getValueAt(i, FILE_INDEX); if (element.isDirectory()) - model.setValueAt(fad, i, FOLDER_AS_CONTAINER_INDEX); + dtm.setValueAt(fad, i, FOLDER_AS_CONTAINER_INDEX+j); } } @@ -651,13 +679,12 @@ void markFileToArchive(boolean archive) { int n = table.getRowCount(); if (n == 0) return; - DefaultTableModel model = (DefaultTableModel) table.getModel(); - int m = table.getColumnCount(); + DefaultTableModel dtm = (DefaultTableModel) table.getModel(); int index = ARCHIVED_INDEX; - if (COLUMNS_NO_FOLDER_AS_CONTAINER.size() == m) + if (model.isSingleGroup()) index = index-1; for (int i = 0; i < n; i++) { - model.setValueAt(archive, i, index); + dtm.setValueAt(archive, i, index); } } @@ -739,7 +766,7 @@ public boolean isCellEditable(int row, int column) return false; case FOLDER_AS_CONTAINER_INDEX: if (getColumnCount() == - COLUMNS_NO_FOLDER_AS_CONTAINER.size()) + COLUMNS_NO_GROUP.size()) return archivedTunable; FileElement f = (FileElement) getValueAt(row, FILE_INDEX); if (f.getType() == Importer.SCREEN_TYPE) @@ -758,7 +785,7 @@ public void setValueAt(Object value, int row, int col) { if (value instanceof Boolean) { if (col == FOLDER_AS_CONTAINER_INDEX) { - DataNodeElement element = (DataNodeElement) getValueAt(row, + DataNodeElement element = (DataNodeElement) getValueAt(row, CONTAINER_INDEX); FileElement f = (FileElement) getValueAt(row, FILE_INDEX); if (f.isDirectory() || (!f.isDirectory() && diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/ImportDialog.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/ImportDialog.java index dfd26bc59c5..805ea47c601 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/ImportDialog.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/chooser/ImportDialog.java @@ -101,6 +101,7 @@ import pojos.DataObject; import pojos.DatasetData; +import pojos.GroupData; import pojos.ProjectData; import pojos.ScreenData; import pojos.TagAnnotationData; @@ -190,6 +191,9 @@ public class ImportDialog private static final String MESSAGE_LOCATION = "Select where to import " + "the data"; + /** The message to display in the header. */ + private static final String MESSAGE_GROUP = "Group"; + /** Warning when de-selecting the name overriding option. */ private static final List WARNING; @@ -405,6 +409,12 @@ public class ImportDialog /** The number of items before adding new elements to the tool bar.*/ private int tbItems; + /** The selected group.*/ + private GroupData group; + + /** The component used to select the group.*/ + private JComponent groupSelection; + /** * Creates the dataset. * @@ -567,7 +577,7 @@ private void addFiles() checkFile(files[i], l); } chooser.setSelectedFile(new File(".")); - table.addFiles(l, isParentFolderAsDataset());//fadBox.isSelected()); + table.addFiles(l, isParentFolderAsDataset(), group); importButton.setEnabled(table.hasFilesToImport()); } @@ -800,24 +810,6 @@ private void handleLocationSwitch() */ private void initComponents(FileFilter[] filters) { - /* - List tips = new ArrayList(); - tips.add("If selected, when adding images to queue, "); - tips.add("the folder containing the images will be "); - tips.add("marked to be turned into dataset."); - folderAsDatasetBox = new JCheckBox(); - folderAsDatasetBox.setToolTipText(UIUtilities.formatToolTipText(tips)); - folderAsDatasetBox.setBackground(UIUtilities.BACKGROUND_COLOR); - folderAsDatasetBox.setText("New Dataset from folder's name"); - folderAsDatasetBox.addChangeListener(new ChangeListener() { - - public void stateChanged(ChangeEvent e) { - boolean b = !folderAsDatasetBox.isSelected(); - datasetsBox.setEnabled(b); - addButton.setEnabled(b); - } - }); - */ canvas = new QuotaCanvas(); sizeImportLabel = new JLabel(); //sizeImportLabel.setText(UIUtilities.formatFileSize(0)); @@ -839,30 +831,6 @@ public void stateChanged(ChangeEvent e) { } b = (Boolean) ImporterAgent.getRegistry().lookup( FOLDER_AS_DATASET); - - /* - fadBox = new JCheckBox("Folder As Dataset"); - tips = new ArrayList(); - tips.add("If selected, folders added to the import queue "); - tips.add("will be marked to be turned into dataset."); - fadBox.setToolTipText(UIUtilities.formatToolTipText(tips)); - //fadBox.setVisible(type != Importer.SCREEN_TYPE); - fadBox.setBackground(UIUtilities.BACKGROUND); - fadBox.setSelected(true); - fadBox.addChangeListener(new ChangeListener() { - - public void stateChanged(ChangeEvent e) { - // - int n = handleFilesSelection(chooser.getSelectedFiles()); - if (n == 0) { - datasetsBox.setEnabled(true); - folderAsDatasetBox.setEnabled(true); - } - } - }); - if (b != null) fadBox.setSelected(b.booleanValue()); - */ - if (!isFastConnection()) //slow connection showThumbnails.setSelected(false); reference = null; @@ -875,16 +843,6 @@ public void actionPerformed(ActionEvent e) { }; parentsBox.addActionListener(parentsBoxListener); datasetsBox = new JComboBox(); - /* - datasetsBoxListener = new ActionListener() { - - public void actionPerformed(ActionEvent e) { - DataNode node = (DataNode) datasetsBox.getSelectedItem(); - folderAsDatasetBox.setSelected(node != null && - node.isDefaultNode()); - } - }; - */ sorter = new ViewerSorter(); datasets = new ArrayList(); addProjectButton = new JButton("New..."); @@ -1614,6 +1572,13 @@ private void buildLocationPane() locationPane.add(row); locationPane.add(Box.createVerticalStrut(2)); locationPane.add(new JSeparator()); + if (groupSelection != null) { + row = createRow(null); + row.add(UIUtilities.setTextFont(MESSAGE_GROUP)); + row.add(groupSelection); + locationPane.add(row); + locationPane.add(Box.createVerticalStrut(2)); + } row = createRow(null); row.add(UIUtilities.setTextFont(message)); row.add(parentsBox); @@ -2021,8 +1986,6 @@ public ImportDialog(JFrame owner, FileFilter[] filters, initComponents(filters); installListeners(); buildGUI(); - //Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - //setSize(7*(screenSize.width/10), 7*(screenSize.height/10)); } /** @@ -2032,6 +1995,18 @@ public ImportDialog(JFrame owner, FileFilter[] filters, */ public int getType() { return type; } + /** + * Returns true if only one group for the user, + * false otherwise. + * + * @return See above. + */ + boolean isSingleGroup() + { + Set l = ImporterAgent.getAvailableUserGroups(); + return (l.size() <= 1); + } + /** Display the size of files to add. */ void onSelectionChanged() { @@ -2316,7 +2291,9 @@ public void setDiskSpace(DiskQuota quota) public void addToolBar(JComponent bar) { if (bar == null) return; - toolBar.add(bar); + groupSelection = bar; + buildLocationPane(); + //toolBar.add(bar); //invoke when master cancelButton.setVisible(false); } @@ -2368,7 +2345,14 @@ public void onDataObjectSaved(DataObject d, DataObject parent) * @return See above. */ public boolean reloadHierarchies() { return reload; } - + + /** + * Sets the selected group. + * + * @param group The group to set. + */ + public void setSelectedGroup(GroupData group) { this.group = group; } + /** * Reacts to property fired by the table. * @see PropertyChangeListener#propertyChange(PropertyChangeEvent) diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/util/FileImportComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/util/FileImportComponent.java index 3678d1a85e4..68a2b5c63b5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/util/FileImportComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/util/FileImportComponent.java @@ -74,6 +74,7 @@ import org.openmicroscopy.shoola.env.data.model.DeleteActivityParam; import org.openmicroscopy.shoola.env.data.model.ImportableObject; import org.openmicroscopy.shoola.env.data.model.ThumbnailData; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StatusLabel; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.ui.UserNotifier; @@ -81,6 +82,7 @@ import org.openmicroscopy.shoola.util.ui.UIUtilities; import pojos.DataObject; import pojos.DatasetData; +import pojos.GroupData; import pojos.ImageData; import pojos.PlateData; import pojos.ProjectData; @@ -226,7 +228,7 @@ public class FileImportComponent /** The component displaying the result. */ private JLabel resultLabel; - + /** The component displaying the imported image. */ private ThumbnailLabel imageLabel; @@ -320,6 +322,15 @@ public class FileImportComponent /** Flag indicating that the file should be reimported.*/ private boolean toReImport; + /** The group in which to import the file.*/ + private GroupData group; + + /** The component displaying the group where the file is imported. */ + private JLabel groupLabel; + + /** Flag indicating the the user is member of one group only.*/ + private boolean singleGroup; + /** Displays the error box at the specified location. * * @param p The location where to show the box. @@ -394,7 +405,8 @@ private void deleteImage() icons.getIcon(IconManager.APPLY_22), l); p.setFailureIcon(icons.getIcon(IconManager.DELETE_22)); UserNotifier un = MeasurementAgent.getRegistry().getUserNotifier(); - un.notifyActivity(p); + //TODO: review + //un.notifyActivity(p); //the row enabled deleteButton.setEnabled(false); errorBox.setEnabled(false); @@ -423,7 +435,9 @@ public void mousePressed(MouseEvent e) EventBus bus = ImporterAgent.getRegistry().getEventBus(); if (data.getImage() != null) { - bus.post(new ViewImage(new ViewImageObject( + bus.post(new ViewImage( + new SecurityContext(group.getId()), + new ViewImageObject( data.getImage()), null)); } } else if (image instanceof ImageData) { @@ -431,7 +445,9 @@ public void mousePressed(MouseEvent e) EventBus bus = ImporterAgent.getRegistry().getEventBus(); if (data != null) { - bus.post(new ViewImage(new ViewImageObject( + bus.post(new ViewImage( + new SecurityContext(group.getId()), + new ViewImageObject( data), null)); } } else if (image instanceof PlateData) { @@ -475,6 +491,8 @@ public void mousePressed(MouseEvent e) containerLabel = new JLabel(); containerLabel.setVisible(false); + groupLabel = new JLabel("Group: "+group.getName()); + groupLabel.setVisible(false); namePane = new JPanel(); namePane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); @@ -548,6 +566,7 @@ private void buildGUI() add(Box.createHorizontalStrut(15)); add(containerLabel); add(browseButton); + add(groupLabel); add(reimportedLabel); } @@ -614,7 +633,8 @@ private void insertFiles(Map files) while (i.hasNext()) { entry = (Entry) i.next(); f = (File) entry.getKey(); - c = new FileImportComponent(f, folderAsContainer, browsable); + c = new FileImportComponent(f, folderAsContainer, browsable, group, + singleGroup); if (f.isFile()) { c.setLocation(data, d, node); c.setParent(this); @@ -656,13 +676,20 @@ private void insertFiles(Map files) * has to be used as a container, * false otherwise. * @param browsable Flag indicating that the container can be browsed or not. + * @param group The group in which to import the file. + * @param singleGroup Passes true if the user is member of + * only one group, false otherwise. */ public FileImportComponent(File file, boolean folderAsContainer, boolean - browsable) + browsable, GroupData group, boolean singleGroup) { if (file == null) throw new IllegalArgumentException("No file specified."); + if (group == null) + throw new IllegalArgumentException("No group specified."); this.file = file; + this.group = group; + this.singleGroup = singleGroup; importCount = 0; this.browsable = browsable; this.folderAsContainer = folderAsContainer; @@ -826,9 +853,11 @@ public void setStatus(boolean status, Object image) browseButton.setVisible(showContainerLabel); containerLabel.setVisible(showContainerLabel); } + groupLabel.setVisible(!singleGroup); } } else if (image instanceof ThumbnailData) { ThumbnailData thumbnail = (ThumbnailData) image; + groupLabel.setVisible(!singleGroup); if (thumbnail.isValidImage()) { imageLabel.setData(thumbnail); @@ -864,6 +893,7 @@ public void setStatus(boolean status, Object image) resultLabel.setVisible(true); errorButton.setVisible(false); errorBox.setVisible(false); + groupLabel.setVisible(!singleGroup); /* errorButton.setToolTipText( UIUtilities.formatExceptionForToolTip( @@ -879,6 +909,7 @@ public void setStatus(boolean status, Object image) } else if (image instanceof PlateData) { imageLabel.setData((PlateData) image); statusLabel.setVisible(false); + groupLabel.setVisible(!singleGroup); if (browsable) { resultLabel.setText(BROWSE_TEXT); resultLabel.setForeground(UIUtilities.HYPERLINK_COLOR); @@ -897,6 +928,7 @@ public void setStatus(boolean status, Object image) } } else if (image instanceof List) { statusLabel.setVisible(false); + groupLabel.setVisible(!singleGroup); List list = (List) image; int m = list.size(); imageLabel.setData(list.get(0)); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/util/ThumbnailLabel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/util/ThumbnailLabel.java index 42d98d15de7..65ce5b5a6c8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/util/ThumbnailLabel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/util/ThumbnailLabel.java @@ -86,6 +86,7 @@ class ThumbnailLabel /** Posts an event to view the object. */ private void view() { + /* TODO: review EventBus bus = ImporterAgent.getRegistry().getEventBus(); if (data instanceof ThumbnailData) { ThumbnailData thumbnail = (ThumbnailData) data; @@ -98,6 +99,7 @@ private void view() } else if (data instanceof PlateData) { firePropertyChange(BROWSE_PLATE_PROPERTY, null, data); } + */ } /** Rolls over the node. */ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterComponent.java index adbde9ba950..525fed287cb 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterComponent.java @@ -47,7 +47,6 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.ExitApplication; import org.openmicroscopy.shoola.env.data.events.LogOff; -import org.openmicroscopy.shoola.env.data.events.SwitchUserGroup; import org.openmicroscopy.shoola.env.data.model.DiskQuota; import org.openmicroscopy.shoola.env.data.model.ImportableObject; import org.openmicroscopy.shoola.env.event.EventBus; @@ -221,6 +220,7 @@ public void activate(int type, TreeImageDisplay selectedContainer, chooser.requestFocusInWindow(); view.selectChooser(); } + chooser.setSelectedGroup(getSelectedGroup()); if (model.isMaster() || objects == null || objects.size() == 0) refreshContainers(type); //load available disk space @@ -699,8 +699,16 @@ public void setUserGroup(GroupData group) ExperimenterData exp = ImporterAgent.getUserDetails(); long oldId = model.getGroupId(); if (group.getId() == oldId) return; + /* Registry reg = ImporterAgent.getRegistry(); reg.getEventBus().post(new SwitchUserGroup(exp, group.getId())); + */ + //Load data for + + model.setGroupId(group.getId()); + chooser.setSelectedGroup(getSelectedGroup()); + refreshContainers(chooser.getType()); + firePropertyChange(CHANGED_GROUP_PROPERTY, oldId, group.getId()); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterFactory.java index f3173136f2b..41e1acd8024 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterFactory.java @@ -63,18 +63,7 @@ public class ImporterFactory /** The sole instance. */ private static final ImporterFactory singleton = new ImporterFactory(); - - /** - * Returns a {@link Importer}. - * - * @return See above. - */ - public static Importer getImporter() - { - ImporterModel model = new ImporterModel(); - return singleton.getImporter(model); - } - + /** * Returns true if the importer already exists, * false otherwise. @@ -92,13 +81,25 @@ public static boolean doesImporterExist() * @param groupId The identifier of the current group. * @return See above. */ - public static Importer getImporter(long groupId) + public static Importer getImporter(long groupId, boolean master) { - ImporterModel model = new ImporterModel(groupId); + ImporterModel model = new ImporterModel(groupId, master); return singleton.getImporter(model); } - + /** + * Returns a {@link Importer}. + * + * @param groupId The identifier of the current group. + * @param master Pass true if the importer is used a + * stand-alone application, false otherwise. + * @return See above. + */ + public static Importer getImporter(long groupId) + { + return getImporter(groupId, false); + } + /** * Notifies the model that the user's group has successfully be modified * if the passed value is true, unsuccessfully diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java index 68613773cdd..bb817a45e4a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java @@ -27,6 +27,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Set; + import javax.swing.filechooser.FileFilter; //Third-party libraries @@ -39,6 +41,8 @@ import org.openmicroscopy.shoola.agents.fsimporter.ImporterAgent; import org.openmicroscopy.shoola.agents.fsimporter.TagsLoader; import org.openmicroscopy.shoola.env.data.model.ImportableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.DataObject; import pojos.ProjectData; import pojos.ScreenData; @@ -83,6 +87,12 @@ class ImporterModel /** The id of the user currently logged in.*/ private long experimenterId; + /** The security context.*/ + private SecurityContext ctx; //to be initialized. + + /** Returns true if it is opened as a standalone app.*/ + private boolean master; + /** Initializes the model.*/ private void initialize() { @@ -91,20 +101,27 @@ private void initialize() state = Importer.NEW; loaders = new HashMap(); } - - /** Creates a new instance.*/ - ImporterModel() + + /** + * Creates a new instance. + * + * @param groupID The id to the group selected for the current user. + */ + ImporterModel(long groupId) { - initialize(); + this(groupId, false); } /** * Creates a new instance. * - * @param groupID The id to the group selected for the current user. + * @param groupID The id to the group selected for the current user. + * @param master Pass true if the importer is used a stand-alone + * application, false otherwise. */ - ImporterModel(long groupId) + ImporterModel(long groupId, boolean master) { + this.master = master; initialize(); setGroupId(groupId); } @@ -117,6 +134,7 @@ private void initialize() void setGroupId(long groupId) { this.groupId = groupId; + ctx = new SecurityContext(groupId); experimenterId = ImporterAgent.getUserDetails().getId(); } @@ -140,7 +158,7 @@ void setGroupId(long groupId) * * @return See above. */ - boolean isMaster() { return groupId >= 0; } + boolean isMaster() { return master; } /** * Called by the FSImporter after creation to allow this @@ -266,14 +284,14 @@ void setTags(Collection tags) void fireTagsLoading() { if (tags != null) return; //already loading tags - TagsLoader loader = new TagsLoader(component); + TagsLoader loader = new TagsLoader(component, ctx); loader.load(); } /** Starts an asynchronous call to load the available disk space. */ void fireDiskSpaceLoading() { - DiskSpaceLoader loader = new DiskSpaceLoader(component); + DiskSpaceLoader loader = new DiskSpaceLoader(component, ctx); loader.load(); } @@ -287,7 +305,8 @@ void fireContainerLoading(Class rootType, boolean refreshImport) { if (!(ProjectData.class.equals(rootType) || ScreenData.class.equals(rootType))) return; - DataLoader loader = new DataLoader(component, rootType, refreshImport); + DataLoader loader = new DataLoader(component, ctx, rootType, + refreshImport); loader.load(); state = Importer.LOADING_CONTAINER; } @@ -300,10 +319,21 @@ void fireContainerLoading(Class rootType, boolean refreshImport) */ void fireDataCreation(DataObject child, DataObject parent) { - DataObjectCreator loader = new DataObjectCreator(component, child, - parent); + DataObjectCreator loader = new DataObjectCreator(component, ctx, + child, parent); loader.load(); //state = Importer.CREATING_CONTAINER; } + /** + * Returns true if only one group for the user, + * false otherwise. + * + * @return See above. + */ + boolean isSingleGroup() + { + Set l = ImporterAgent.getAvailableUserGroups(); + return (l.size() <= 1); + } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUI.java index 43439140848..b766de4b191 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUI.java @@ -24,8 +24,6 @@ //Java imports -import info.clearthought.layout.TableLayout; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -69,6 +67,7 @@ import javax.swing.text.StyledDocument; //Third-party libraries +import info.clearthought.layout.TableLayout; import org.jdesktop.swingx.JXLabel; import org.jdesktop.swingx.JXPanel; @@ -87,7 +86,6 @@ import org.openmicroscopy.shoola.util.ui.ClosableTabbedPaneComponent; import org.openmicroscopy.shoola.util.ui.TitlePanel; import org.openmicroscopy.shoola.util.ui.UIUtilities; -import pojos.ExperimenterData; /** * The {@link Importer}'s View. Displays the on-going import and the finished @@ -225,8 +223,8 @@ private void showPersonalMenu(Component c, Point p) GroupSelectionAction a; JCheckBoxMenuItem item; ButtonGroup buttonGroup = new ButtonGroup(); - ExperimenterData exp = ImporterAgent.getUserDetails(); - long id = exp.getDefaultGroup().getId(); + //ExperimenterData exp = ImporterAgent.getUserDetails(); + long id = model.getGroupId();//exp.getDefaultGroup().getId(); while (i.hasNext()) { a = i.next(); item = new JCheckBoxMenuItem(a); @@ -399,7 +397,8 @@ void initialize(ImporterModel model, ImporterControl controller) void addComponent(ImportDialog chooser) { if (chooser == null) return; - if (model.isMaster()) chooser.addToolBar(buildToolBar()); + //if (model.isMaster()) chooser.addToolBar(buildToolBar()); + chooser.addToolBar(buildToolBar()); tabs.insertTab("Select Data to Import", null, chooser, "", 0); //if in debug mode insert the debug section Boolean b = (Boolean) @@ -459,7 +458,7 @@ ImporterUIElement addImporterElement(ImportableObject object) if (object == null) return null; int n = tabs.getComponentCount(); String title = "Import #"+total; - ImporterUIElement element = new ImporterUIElement(controller, + ImporterUIElement element = new ImporterUIElement(controller, model, uiElementID, n, title, object); //IconManager icons = IconManager.getInstance(); tabs.insertTab(title, element.getImportIcon(), element, "", total); @@ -668,7 +667,7 @@ void appendDebugText(String text) JComponent buildToolBar() { Set set = ImporterAgent.getAvailableUserGroups(); - if (set == null || set.size() == 0) return null; + if (set == null || set.size() <= 1) return null; ImporterAction a = controller.getAction(ImporterControl.GROUP_BUTTON); a.setEnabled(set.size() > 1); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUIElement.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUIElement.java index 5fe01b92fb7..9a919a9b04b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUIElement.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterUIElement.java @@ -164,6 +164,9 @@ class ImporterUIElement /** Reference to the controller. */ private ImporterControl controller; + /** Reference to the controller. */ + private ImporterModel model; + /** The components displaying the components. */ private Map containerComponents; @@ -385,11 +388,12 @@ public void mousePressed(MouseEvent e) } JLabel l; int count = 0; + boolean single = model.isSingleGroup(); while (i.hasNext()) { importable = i.next(); f = (File) importable.getFile(); c = new FileImportComponent(f, importable.isFolderAsContainer(), - !controller.isMaster()); + !controller.isMaster(), importable.getGroup(), single); c.setLocation(importable.getParent(), importable.getDataset(), importable.getRefNode()); c.setType(type); @@ -689,20 +693,24 @@ private boolean topContainerToRefresh() * Creates a new instance. * * @param controller Reference to the control. Mustn't be null. + * @param model Reference to the model. Mustn't be null. * @param id The identifier of the component. * @param index The index of the component. * @param name The name of the component. * @param object the object to handle. Mustn't be null. */ - ImporterUIElement(ImporterControl controller, int id, int index, - String name, ImportableObject object) + ImporterUIElement(ImporterControl controller, ImporterModel model, + int id, int index, String name, ImportableObject object) { super(index, name, DESCRIPTION); if (object == null) throw new IllegalArgumentException("No object specified."); if (controller == null) - throw new IllegalArgumentException("No controller."); + throw new IllegalArgumentException("No Control."); + if (model == null) + throw new IllegalArgumentException("No Model."); this.controller = controller; + this.model = model; this.id = id; this.object = object; initialize(); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/BirdEyeLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/BirdEyeLoader.java index 25a88afedb3..31cc72df8e8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/BirdEyeLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/BirdEyeLoader.java @@ -31,6 +31,9 @@ import omero.romio.PlaneDef; import org.openmicroscopy.shoola.agents.dataBrowser.DataBrowserLoader; import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; +import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; +import org.openmicroscopy.shoola.env.data.model.ThumbnailData; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.util.image.geom.Factory; import pojos.ImageData; @@ -78,13 +81,14 @@ public class BirdEyeLoader * * @param viewer The view this loader is for. * Mustn't be null. + * @param ctx The security context. * @param image The image to handle. * @param ratio The ratio by with to scale the image. */ - public BirdEyeLoader(ImViewer viewer, ImageData image, + public BirdEyeLoader(ImViewer viewer, SecurityContext ctx, ImageData image, PlaneDef plane, double ratio) { - super(viewer); + super(viewer, ctx); if (image == null) throw new IllegalArgumentException("No image to load."); this.image = image; @@ -100,7 +104,7 @@ public BirdEyeLoader(ImViewer viewer, ImageData image, */ public void load() { - handle = ivView.render(image.getDefaultPixels().getId(), + handle = ivView.render(ctx, image.getDefaultPixels().getId(), plane, false, true, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ContainerLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ContainerLoader.java index c83c7a4761e..d913debce85 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ContainerLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ContainerLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; @@ -55,31 +56,33 @@ public class ContainerLoader { /** The id of the image. */ - private long imageID; + private long imageID; /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** * Creates a new instance. * - * @param model Reference to the model. + * @param model Reference to the model. + * @param ctx The security context. * @param imageID The id of the image. */ - public ContainerLoader(ImViewer model, long imageID) + public ContainerLoader(ImViewer model, SecurityContext ctx, long imageID) { - super(model); + super(model, ctx); this.imageID = imageID; } /** * Creates a new instance. * - * @param model Reference to the model. + * @param model Reference to the model. + * @param ctx The security context. */ - public ContainerLoader(ImViewer model) + public ContainerLoader(ImViewer model, SecurityContext ctx) { - super(model); + super(model, ctx); this.imageID = -1; } @@ -90,7 +93,7 @@ public ContainerLoader(ImViewer model) public void load() { ExperimenterData exp = ImViewerAgent.getUserDetails(); - handle = dmView.loadContainerHierarchy(ProjectData.class, null, + handle = dmView.loadContainerHierarchy(ctx, ProjectData.class, null, false, exp.getId(), exp.getDefaultGroup().getId(), this); //handle = mhView.loadContainers(ImageData.class, imageID, userID, this); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/DataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/DataLoader.java index aa198226834..ccf800edfa9 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/DataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/DataLoader.java @@ -34,6 +34,7 @@ import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.DataHandlerView; import org.openmicroscopy.shoola.env.data.views.DataManagerView; import org.openmicroscopy.shoola.env.data.views.ImageDataView; @@ -73,30 +74,36 @@ public abstract class DataLoader protected final ImViewer viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final ImageDataView ivView; + protected final ImageDataView ivView; /** Convenience reference for subclasses. */ - protected final DataHandlerView dhView; + protected final DataHandlerView dhView; /** Convenience reference for subclasses. */ - protected final MetadataHandlerView mhView; + protected final MetadataHandlerView mhView; /** Convenience reference for subclasses. */ - protected final DataManagerView dmView; + protected final DataManagerView dmView; + + /** The security context.*/ + protected final SecurityContext ctx; /** * Creates a new instance. * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - protected DataLoader(ImViewer viewer) + protected DataLoader(ImViewer viewer, SecurityContext ctx) { if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null) throw new NullPointerException("No security context."); this.viewer = viewer; + this.ctx = ctx; registry = ImViewerAgent.getRegistry(); ivView = (ImageDataView) registry.getDataServicesView(ImageDataView.class); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/IconManager.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/IconManager.java index c9f595c0047..16f43fae5bc 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/IconManager.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/IconManager.java @@ -278,11 +278,23 @@ public class IconManager /** The 22x22 Split view figure icon. */ public static final int SPLIT_VIEW_FIGURE_22 = 74; + /** The Private Group icon. */ + public static final int PRIVATE_GROUP = 75; + + /** The Read Group icon. */ + public static final int READ_GROUP = 76; + + /** The Read Link Group icon. */ + public static final int READ_LINK_GROUP = 77; + + /** The Public Group icon. */ + public static final int PUBLIC_GROUP = 78; + /** * The maximum ID used for the icon IDs. * Allows to correctly build arrays for direct indexing. */ - private static final int MAX_ID = 74; + private static final int MAX_ID = 78; /** Paths of the icon files. */ private static String[] relPaths = new String[MAX_ID+1]; @@ -362,6 +374,10 @@ public class IconManager relPaths[DOWNLOAD_48] = "nuvola_download_manager48.png"; relPaths[DOWNLOAD_22] = "nuvola_download_manager22.png"; relPaths[SPLIT_VIEW_FIGURE_22] = "splitViewFigure22.png"; + relPaths[PRIVATE_GROUP] = "nuvola_ledred16.png"; + relPaths[READ_GROUP] = "nuvola_ledorange_readOnly16.png"; + relPaths[READ_LINK_GROUP] = "nuvola_ledorange16.png"; + relPaths[PUBLIC_GROUP] = "nuvola_ledgreen16.png"; } /** The sole instance. */ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImViewerAgent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImViewerAgent.java index 8bab4531793..94aa8778010 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImViewerAgent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImViewerAgent.java @@ -162,9 +162,11 @@ private void handleViewImage(ViewImage evt) pixels = ((WellSampleData) image).getImage().getDefaultPixels(); } if (pixels != null) - view = ImViewerFactory.getImageViewer(image, r, b); + view = ImViewerFactory.getImageViewer(evt.getSecurityContext(), + image, r, b); } else - view = ImViewerFactory.getImageViewer(object.getImageID(), r, b); + view = ImViewerFactory.getImageViewer(evt.getSecurityContext(), + object.getImageID(), r, b); if (view != null) { view.activate(object.getSettings(), object.getSelectedUserID()); view.setContext(object.getParent(), object.getGrandParent()); @@ -194,7 +196,9 @@ private void handleMeasurementToolLoaded(MeasurementToolLoaded evt) PixelsData pixels = request.getPixels(); if (pixels == null) return; long pixelsID = pixels.getId(); - ImViewer view = ImViewerFactory.getImageViewer(pixelsID); + //TODO: review + ImViewer view = ImViewerFactory.getImageViewer(evt.getSecurityContext(), + pixelsID); if (view != null) { switch (evt.getIndex()) { case MeasurementToolLoaded.ADD: @@ -215,7 +219,7 @@ private void handleSelectPlane(SelectPlane evt) { if (evt == null) return; long pixelsID = evt.getPixelsID(); - ImViewer view = ImViewerFactory.getImageViewer(pixelsID); + ImViewer view = ImViewerFactory.getImageViewer(null, pixelsID); if (view != null && !view.isPlayingMovie()) { Rectangle r = evt.getBounds(); if (r != null) { @@ -256,6 +260,7 @@ public void handleRndSettingsSavedEvent(RndSettingsSaved evt) */ private void handleFocusGainedEvent(FocusGainedEvent evt) { + /* ImViewer viewer = ImViewerFactory.getImageViewer( evt.getPixelsID()); if (viewer == null) return; @@ -263,6 +268,7 @@ private void handleFocusGainedEvent(FocusGainedEvent evt) evt.getIndex() != FocusGainedEvent.VIEWER_FOCUS) { //viewer.toFront(); } + */ } /** @@ -273,7 +279,7 @@ private void handleFocusGainedEvent(FocusGainedEvent evt) private void handleImageViewportEvent(ImageViewport evt) { if (evt == null) return; - ImViewer viewer = ImViewerFactory.getImageViewer( + ImViewer viewer = ImViewerFactory.getImageViewer(null, evt.getPixelsID()); if (viewer == null) return; viewer.scrollToViewport(evt.getBounds()); @@ -314,7 +320,8 @@ private void handleViewObjectEvent(ViewObjectEvent evt) if (evt.browseObject()) return; if (o instanceof ImageData) { ImViewer view = ImViewerFactory.getImageViewer( - ((ImageData) o).getId(), null, true); + evt.getSecurityContext(), ((ImageData) o).getId(), + null, true); if (view != null) { view.activate(null, getUserDetails().getId()); JComponent src = evt.getSource(); @@ -331,7 +338,7 @@ private void handleViewObjectEvent(ViewObjectEvent evt) private void handleRendererUnloadedEvent(RendererUnloadedEvent evt) { if (evt == null) return; - ImViewer viewer = ImViewerFactory.getImageViewer( + ImViewer viewer = ImViewerFactory.getImageViewer(null, evt.getPixelsID()); if (viewer == null) return; viewer.discard(); @@ -370,7 +377,7 @@ private void handleFLIMResultsEvent(FLIMResultsEvent evt) { if (evt == null) return; ImageData image = evt.getImage(); - ImViewer viewer = ImViewerFactory.getImageViewer( + ImViewer viewer = ImViewerFactory.getImageViewer(null, image.getDefaultPixels().getId()); if (viewer != null) { viewer.displayFLIMResults(evt.getResults()); @@ -393,7 +400,7 @@ private void handleReloadRenderingEngineEvent(ReloadRenderingEngine evt) UserNotifier un = registry.getUserNotifier(); while (i.hasNext()) { id = i.next(); - viewer = ImViewerFactory.getImageViewer(id); + viewer = ImViewerFactory.getImageViewer(null, id); if (viewer != null) { un.notifyInfo("Reload", "The rendering engine could not be " + "reloaded for " + viewer.getUI().getTitle()+ @@ -413,7 +420,7 @@ private void checkImageForDelete(ImageData image) if (image.getId() < 0) return; PixelsData pixels = image.getDefaultPixels(); if (pixels == null) return; - ImViewer viewer = ImViewerFactory.getImageViewer(pixels.getId()); + ImViewer viewer = ImViewerFactory.getImageViewer(null, pixels.getId()); if (viewer != null) viewer.discard(); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImageDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImageDataLoader.java index 2cd4c08594d..10a5ff74c60 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImageDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImageDataLoader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -51,7 +52,7 @@ * * @since 3.0-Beta4 */ -public class ImageDataLoader +public class ImageDataLoader extends DataLoader { @@ -66,11 +67,12 @@ public class ImageDataLoader * * @param viewer The view this loader is for. * Mustn't be null. + * @param ctx The security context. * @param imageID The id of the image. */ - public ImageDataLoader(ImViewer viewer, long imageID) + public ImageDataLoader(ImViewer viewer, SecurityContext ctx, long imageID) { - super(viewer); + super(viewer, ctx); this.imageID = imageID; } @@ -80,7 +82,7 @@ public ImageDataLoader(ImViewer viewer, long imageID) */ public void load() { - handle = ivView.loadImage(imageID, getCurrentUserID(), this); + handle = ivView.loadImage(ctx, imageID, getCurrentUserID(), this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImageLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImageLoader.java index 8d9f572498c..c344c3fbfa3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImageLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ImageLoader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import omero.romio.PlaneDef; import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -55,16 +56,16 @@ public class ImageLoader { /** The ID of the pixels set. */ - private long pixelsID; + private long pixelsID; /** The plane to render. */ - private PlaneDef pd; + private PlaneDef pd; /** Flag indicating if the image is large or not. */ - private boolean largeImage; + private boolean largeImage; /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** Indicates that the rendering of that image has been cancelled.*/ private boolean cancelled; @@ -79,10 +80,10 @@ public class ImageLoader * @param largeImae Pass true to render a large image, * false otherwise. */ - public ImageLoader(ImViewer viewer, long pixelsID, PlaneDef pd, boolean - largeImage) + public ImageLoader(ImViewer viewer, SecurityContext ctx, long pixelsID, + PlaneDef pd, boolean largeImage) { - super(viewer); + super(viewer, ctx); this.pixelsID = pixelsID; this.pd = pd; this.largeImage = largeImage; @@ -95,7 +96,7 @@ public ImageLoader(ImViewer viewer, long pixelsID, PlaneDef pd, boolean public void load() { boolean asTexture = ImViewerAgent.hasOpenGLSupport(); - handle = ivView.render(pixelsID, pd, asTexture, largeImage, this); + handle = ivView.render(ctx, pixelsID, pd, asTexture, largeImage, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/MeasurementsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/MeasurementsLoader.java index ef25b0ce24a..87c6ef368b0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/MeasurementsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/MeasurementsLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.ImageData; @@ -53,10 +54,10 @@ public class MeasurementsLoader { /** The object to handle. */ - private DataObject object; + private DataObject object; /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** * Checks the passed type if supported. @@ -73,12 +74,14 @@ private void checkType(DataObject value) /** * Creates a new instance. * - * @param model Reference to the model. - * @param object The object. + * @param model Reference to the model. + * @param ctx The security context. + * @param object The object. */ - public MeasurementsLoader(ImViewer model, DataObject object) + public MeasurementsLoader(ImViewer model, SecurityContext ctx, + DataObject object) { - super(model); + super(model, ctx); checkType(object); this.object = object; } @@ -90,7 +93,7 @@ public MeasurementsLoader(ImViewer model, DataObject object) public void load() { long userID = ImViewerAgent.getUserDetails().getId(); - handle = mhView.loadROIMeasurement(object, userID, this); + handle = mhView.loadROIMeasurement(ctx, object, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/OverlaysRenderer.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/OverlaysRenderer.java index 2db50df7a9f..14959dfe0ac 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/OverlaysRenderer.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/OverlaysRenderer.java @@ -30,6 +30,7 @@ //Application-internal dependencies import omero.romio.PlaneDef; import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -50,13 +51,13 @@ public class OverlaysRenderer { /** The ID of the pixels set. */ - private long pixelsID; + private long pixelsID; /** The plane to render. */ - private PlaneDef pd; + private PlaneDef pd; /** The id of the table. */ - private long tableID; + private long tableID; /** The overlays to render. */ private Map overlays; @@ -67,17 +68,17 @@ public class OverlaysRenderer /** * Creates a new instance * - * @param viewer The view this loader is for. - * Mustn't be null. - * @param pixelsID The id of the pixels set. - * @param pd The plane to render. - * @param tableID The id of the table. - * @param overlays The overlays to render. + * @param viewer The view this loader is for. Mustn't be null. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param pd The plane to render. + * @param tableID The id of the table. + * @param overlays The overlays to render. */ - public OverlaysRenderer(ImViewer viewer, long pixelsID, PlaneDef pd, - long tableID, Map overlays) + public OverlaysRenderer(ImViewer viewer, SecurityContext ctx, + long pixelsID, PlaneDef pd, long tableID, Map overlays) { - super(viewer); + super(viewer, ctx); this.pixelsID = pixelsID; this.pd = pd; this.tableID = tableID; @@ -91,7 +92,7 @@ public OverlaysRenderer(ImViewer viewer, long pixelsID, PlaneDef pd, public void load() { boolean asTexture = ImViewerAgent.hasOpenGLSupport(); - handle = ivView.renderOverLays(pixelsID, pd, tableID, overlays, + handle = ivView.renderOverLays(ctx, pixelsID, pd, tableID, overlays, asTexture, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/PlaneInfoLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/PlaneInfoLoader.java index 8d29d53f9a4..d5242b7192e 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/PlaneInfoLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/PlaneInfoLoader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -56,30 +57,30 @@ public class PlaneInfoLoader { /** The ID of the pixels set. */ - private long pixelsID; + private long pixelsID; /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** The selected z-section or -1. */ - private int defaultZ; + private int defaultZ; /** The selected timepoint or -1. */ - private int defaultT; + private int defaultT; /** * Creates a new instance * - * @param viewer The view this loader is for. - * Mustn't be null. + * @param viewer The view this loader is for. Mustn't be null. + * @param ctx The security context. * @param pixelsID The id of pixels set. * @param defaultZ The selected z-section. * @param defaultT The selected timepoint. */ - public PlaneInfoLoader(ImViewer viewer, long pixelsID, + public PlaneInfoLoader(ImViewer viewer, SecurityContext ctx, long pixelsID, int defaultZ, int defaultT) { - super(viewer); + super(viewer, ctx); this.pixelsID = pixelsID; this.defaultZ = defaultZ; this.defaultT = defaultT; @@ -88,13 +89,13 @@ public PlaneInfoLoader(ImViewer viewer, long pixelsID, /** * Creates a new instance * - * @param viewer The view this loader is for. - * Mustn't be null. + * @param viewer The view this loader is for. Mustn't be null. + * @param ctx The security context. * @param pixelsID The id of pixels set. */ - public PlaneInfoLoader(ImViewer viewer, long pixelsID) + public PlaneInfoLoader(ImViewer viewer, SecurityContext ctx, long pixelsID) { - this(viewer, pixelsID, -1, -1); + this(viewer, ctx, pixelsID, -1, -1); } /** @@ -104,7 +105,7 @@ public PlaneInfoLoader(ImViewer viewer, long pixelsID) public void load() { if (defaultT < 0 || defaultZ < 0) - handle = ivView.loadPlaneInfo(pixelsID, -1, -1, -1, this); + handle = ivView.loadPlaneInfo(ctx, pixelsID, -1, -1, -1, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ProjectionSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ProjectionSaver.java index baf7ca41b98..bb8af2e5667 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ProjectionSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/ProjectionSaver.java @@ -33,6 +33,7 @@ import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; import org.openmicroscopy.shoola.env.data.model.ProjectionParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.log.LogMessage; import pojos.DataObject; @@ -101,30 +102,32 @@ private void checkIndex(int value) /** * Creates a new instance. * - * @param model Reference to the model. Mustn't be null. - * @param ref The object hosting the projection's parameters. - * @param index One of the constants defined by this class. + * @param model Reference to the model. Mustn't be null. + * @param ctx The security context. + * @param ref The object hosting the projection's parameters. + * @param index One of the constants defined by this class. */ - public ProjectionSaver(ImViewer model, ProjectionParam ref, int index) + public ProjectionSaver(ImViewer model, SecurityContext ctx, + ProjectionParam ref, int index) { - this(model, ref, index, false); + this(model, ctx, ref, index, false); } /** * Creates a new instance. * - * @param model Reference to the model. - * Mustn't be null. - * @param ref The object hosting the projection's parameters. - * @param index One of the constants defined by this class. + * @param model Reference to the model. Mustn't be null. + * @param ctx The security context. + * @param ref The object hosting the projection's parameters. + * @param index One of the constants defined by this class. * @param applySettings Pass true to set the rendering settings * of the original image to the new pixels set, * false otherwise. */ - public ProjectionSaver(ImViewer model, ProjectionParam ref, int index, - boolean applySettings) + public ProjectionSaver(ImViewer model, SecurityContext ctx, + ProjectionParam ref, int index, boolean applySettings) { - super(model); + super(model, ctx); if (ref == null) throw new IllegalArgumentException("Parameters not specified."); checkIndex(index); @@ -142,13 +145,13 @@ public void load() switch (index) { case PREVIEW: boolean b = ImViewerAgent.hasOpenGLSupport(); - handle = ivView.renderProjected(ref.getPixelsID(), - ref.getStartZ(), ref.getEndZ(), ref.getStepping(), + handle = ivView.renderProjected(ctx, ref.getPixelsID(), + ref.getStartZ(), ref.getEndZ(), ref.getStepping(), ref.getAlgorithm(), ref.getChannels(), b, this); break; case PROJECTION: - handle = ivView.projectImage(ref, this); + handle = ivView.projectImage(ctx, ref, this); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/RenderingSettingsCreator.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/RenderingSettingsCreator.java index 4b8daa2137f..d467cea7142 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/RenderingSettingsCreator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/RenderingSettingsCreator.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; import pojos.ImageData; @@ -72,18 +73,17 @@ public class RenderingSettingsCreator /** * Creates a new instance * - * @param viewer The view this loader is for. - * Mustn't be null. - * @param image The projected image. + * @param viewer The view this loader is for.Mustn't be null. + * @param ctx The security context. + * @param image The projected image. * @param rndToCopy The rendering settings of the original image. - * @param indexes Collection of channel's indexes. + * @param indexes Collection of channel's indexes. * Mustn't be null. */ - public RenderingSettingsCreator(ImViewer viewer, ImageData image, - RndProxyDef rndToCopy, - List indexes) + public RenderingSettingsCreator(ImViewer viewer, SecurityContext ctx, + ImageData image, RndProxyDef rndToCopy, List indexes) { - super(viewer); + super(viewer, ctx); if (image == null) throw new IllegalArgumentException("No image specified."); this.image = image; @@ -97,7 +97,7 @@ public RenderingSettingsCreator(ImViewer viewer, ImageData image, */ public void load() { - handle = ivView.createRndSetting(image.getDefaultPixels().getId(), + handle = ivView.createRndSetting(ctx, image.getDefaultPixels().getId(), rndToCopy, indexes, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/RenderingSettingsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/RenderingSettingsLoader.java index e5dbb3ca37a..afcf5af2e21 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/RenderingSettingsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/RenderingSettingsLoader.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; @@ -76,28 +77,29 @@ public class RenderingSettingsLoader /** * Creates a new instance * - * @param viewer The view this loader is for. - * Mustn't be null. - * @param pixelsID The id of the pixels set. + * @param viewer The view this loader is for. Mustn't be null. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. */ - public RenderingSettingsLoader(ImViewer viewer, long pixelsID) + public RenderingSettingsLoader(ImViewer viewer, SecurityContext ctx, + long pixelsID) { - this(viewer, pixelsID, false); + this(viewer, ctx, pixelsID, false); } /** * Creates a new instance * - * @param viewer The view this loader is for. - * Mustn't be null. - * @param pixelsID The id of the pixels set. - * @param single Pass true to indicate that the rendering - * settings are only for the current user. + * @param viewer The view this loader is for. Mustn't be null. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param single Pass true to indicate that the rendering + * settings are only for the current user. */ - public RenderingSettingsLoader(ImViewer viewer, long pixelsID, - boolean single) + public RenderingSettingsLoader(ImViewer viewer, SecurityContext ctx, + long pixelsID, boolean single) { - super(viewer); + super(viewer, ctx); if (pixelsID < 0) throw new IllegalArgumentException("Pixels ID not valid."); this.pixelsID = pixelsID; @@ -120,8 +122,9 @@ public void load() { if (single) { ExperimenterData exp = ImViewerAgent.getUserDetails(); - handle = ivView.getRenderingSettings(pixelsID, exp.getId(), this); - } else handle = ivView.getRenderingSettings(pixelsID, this); + handle = ivView.getRenderingSettings(ctx, pixelsID, exp.getId(), + this); + } else handle = ivView.getRenderingSettings(ctx, pixelsID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/TileLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/TileLoader.java index 47a75fc4109..663a5ca02ba 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/TileLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/TileLoader.java @@ -34,6 +34,7 @@ import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.rnd.data.Tile; @@ -72,16 +73,16 @@ public class TileLoader /** * Creates a new instance. * - * @param viewer The view this loader is for. - * Mustn't be null. - * @param pixelsID The id of the pixels set. - * @param pDef The plane to render. - * @param tiles The tiles to handle. + * @param viewer The view this loader is for. Mustn't be null. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param pDef The plane to render. + * @param tiles The tiles to handle. */ - public TileLoader(ImViewer viewer, long pixelsID, PlaneDef pDef, - Collection tiles) + public TileLoader(ImViewer viewer, SecurityContext ctx, long pixelsID, + PlaneDef pDef, Collection tiles) { - super(viewer); + super(viewer, ctx); if (tiles == null || tiles.size() == 0) throw new IllegalArgumentException("No tiles to load."); if (pDef == null) @@ -100,7 +101,7 @@ public TileLoader(ImViewer viewer, long pixelsID, PlaneDef pDef, public void load() { boolean asTexture = ImViewerAgent.hasOpenGLSupport(); - handle = ivView.loadTiles(pixelsID, pDef, tiles, asTexture, this); + handle = ivView.loadTiles(ctx, pixelsID, pDef, tiles, asTexture, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/actions/ActivateRecentAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/actions/ActivateRecentAction.java index 6f23abfba8c..03c2b25dae0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/actions/ActivateRecentAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/actions/ActivateRecentAction.java @@ -86,7 +86,7 @@ public ActivateRecentAction(ImViewerRecentObject recent) public void actionPerformed(ActionEvent e) { EventBus bus = ImViewerAgent.getRegistry().getEventBus(); - ViewImage event = new ViewImage( + ViewImage event = new ViewImage(recent.getSecurityContext(), new ViewImageObject(recent.getImageID()), null); bus.post(event); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledgreen16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledgreen16.png new file mode 100644 index 00000000000..08b9c9d4d00 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledgreen16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledorange16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledorange16.png new file mode 100644 index 00000000000..f8545721c98 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledorange16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledorange_readLink16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledorange_readLink16.png new file mode 100644 index 00000000000..4d35a7cad83 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledorange_readLink16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledorange_readOnly16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledorange_readOnly16.png new file mode 100644 index 00000000000..ab94ebb4cc3 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledorange_readOnly16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledred16.png b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledred16.png new file mode 100644 index 00000000000..bdb53d4e571 Binary files /dev/null and b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/graphx/nuvola_ledred16.png differ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewer.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewer.java index 3f62bbee2b4..6c45c4c51d0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewer.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewer.java @@ -43,6 +43,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.imviewer.util.proj.ProjectionRef; import org.openmicroscopy.shoola.agents.metadata.rnd.Renderer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; import org.openmicroscopy.shoola.env.rnd.data.Tile; @@ -1262,4 +1263,11 @@ public void setProjectedImage(ImageData image, List indexes, */ boolean isCompressed(); + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext(); + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerComponent.java index b7fd9e27d44..bc59ca4665a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerComponent.java @@ -83,6 +83,7 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.env.data.model.ProjectionParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.env.log.Logger; @@ -434,7 +435,8 @@ private void notifyProjection(String message, ImageData image) int option = msg.centerMsgBox(); if (option == MessageBox.YES_OPTION) { EventBus bus = ImViewerAgent.getRegistry().getEventBus(); - bus.post(new ViewImage(new ViewImageObject(image), null)); + bus.post(new ViewImage(model.getSecurityContext(), + new ViewImageObject(image), null)); } } @@ -481,7 +483,8 @@ private void postMeasurementEvent(List measurements) double f = model.getZoomFactor()*model.getOriginalRatio(); if (model.isBigImage()) f = view.getBigImageMagnificationFactor(); - MeasurementTool request = new MeasurementTool(model.getImageID(), + MeasurementTool request = new MeasurementTool( + model.getSecurityContext(), model.getImageID(), model.getPixelsData(), model.getImageName(), model.getDefaultZ(), model.getDefaultT(), model.getActiveChannelsColorMap(),f, @@ -3096,8 +3099,9 @@ public void close(boolean notifyUser) if (notifyUser) { postViewerState(ViewerState.CLOSE); ImViewerRecentObject object = new ImViewerRecentObject( - model.getImageID(), model.getImageTitle(), - getImageIcon()); + model.getSecurityContext(), + model.getImageID(), model.getImageTitle(), + getImageIcon()); firePropertyChange(RECENT_VIEWER_PROPERTY, null, object); } @@ -3376,6 +3380,16 @@ public void cancelInit() fireStateChange(); } } + + /** + * Returns the security context. + * + * @return See above. + */ + public SecurityContext getSecurityContext() + { + return model.getSecurityContext(); + } /** * Implemented as specified by the {@link ImViewer} interface. @@ -3392,5 +3406,4 @@ public boolean isCompressed() */ public String toString() { return getTitle(); } - } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerControl.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerControl.java index da6b91e4ad9..4eb6ea54b9c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerControl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerControl.java @@ -560,6 +560,7 @@ public void windowIconified(WindowEvent e) /** Uploads the script.*/ private void uploadScript() { + /* Map map; Registry reg = ImViewerAgent.getRegistry(); try { @@ -595,6 +596,7 @@ public void propertyChange(PropertyChangeEvent evt) { } }); UIUtilities.centerAndShow(dialog); + */ } /** * Downloads the possible script. @@ -625,7 +627,7 @@ public void propertyChange(PropertyChangeEvent evt) { folder, icons.getIcon(IconManager.DOWNLOAD_22)); UserNotifier un = ImViewerAgent.getRegistry().getUserNotifier(); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); } } }); @@ -1077,11 +1079,12 @@ public void propertyChange(PropertyChangeEvent pce) p.getScript().getScriptID(), DownloadActivityParam.ORIGINAL_FILE, f, null); activity.setApplicationData(new ApplicationData("")); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); } else if (index == ScriptActivityParam.DOWNLOAD) { downloadScript(p); } else { - un.notifyActivity(pce.getNewValue()); + un.notifyActivity(model.getSecurityContext(), + pce.getNewValue()); } } else if (MetadataViewer.UPLOAD_SCRIPT_PROPERTY.equals(pName)) { uploadScript(); @@ -1113,7 +1116,7 @@ public void propertyChange(PropertyChangeEvent pce) activity = new FigureActivityParam(object, ids, klass, FigureActivityParam.SPLIT_VIEW_FIGURE); activity.setIcon(icon); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerFactory.java index d4802321d37..ec05f237d57 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerFactory.java @@ -50,6 +50,7 @@ import org.openmicroscopy.shoola.agents.imviewer.ImViewerAgent; import org.openmicroscopy.shoola.agents.imviewer.actions.ActivateRecentAction; import org.openmicroscopy.shoola.agents.imviewer.actions.ActivationAction; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; import org.openmicroscopy.shoola.env.ui.TaskBar; import pojos.DataObject; @@ -166,17 +167,20 @@ public static void onGroupSwitched(boolean success) /** * Returns a viewer to display the image corresponding to the specified id. * + * @param ctx The security context. * @param image The image or wellSample to view. * @param bounds The bounds of the component invoking the * {@link ImViewer}. * @param separateWindow Pass true to open the viewer in a - * separate window, false otherwise. + * separate window, false otherwise. * @return See above. */ - public static ImViewer getImageViewer(DataObject image, Rectangle bounds, + public static ImViewer getImageViewer(SecurityContext ctx, + DataObject image, Rectangle bounds, boolean separateWindow) { - ImViewerModel model = new ImViewerModel(image, bounds, separateWindow); + ImViewerModel model = new ImViewerModel(ctx, image, bounds, + separateWindow); return singleton.getViewer(model); } @@ -190,10 +194,10 @@ public static ImViewer getImageViewer(DataObject image, Rectangle bounds, * separate window, false otherwise. * @return See above. */ - public static ImViewer getImageViewer(long imageID, Rectangle bounds, - boolean separateWindow) + public static ImViewer getImageViewer(SecurityContext ctx, + long imageID, Rectangle bounds, boolean separateWindow) { - ImViewerModel model = new ImViewerModel(imageID, bounds, + ImViewerModel model = new ImViewerModel(ctx, imageID, bounds, separateWindow); return singleton.getViewer(model); } @@ -204,13 +208,14 @@ public static ImViewer getImageViewer(long imageID, Rectangle bounds, * @param pixelsID The Identifier of the pixels set. * @return See above. */ - public static ImViewer getImageViewer(long pixelsID) + public static ImViewer getImageViewer(SecurityContext ctx, long pixelsID) { Iterator v = singleton.viewers.iterator(); ImViewerComponent comp; while (v.hasNext()) { comp = (ImViewerComponent) v.next(); - if (comp.getModel().getPixelsID() == pixelsID) return comp; + if (comp.getModel().isSame(pixelsID, ctx)) return comp; + //if (comp.getModel().getPixelsID() == pixelsID)return comp; } return null; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerModel.java index d8164e41665..89dd6ea57e7 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerModel.java @@ -41,6 +41,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; //Third-party libraries import com.sun.opengl.util.texture.TextureData; @@ -80,6 +81,7 @@ import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.env.data.model.ProjectionParam; import org.openmicroscopy.shoola.env.data.model.TableResult; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.env.rnd.RenderingServiceException; @@ -92,6 +94,7 @@ import pojos.ChannelData; import pojos.DataObject; import pojos.ExperimenterData; +import pojos.GroupData; import pojos.ImageData; import pojos.PixelsData; import pojos.WellData; @@ -302,6 +305,9 @@ class ImViewerModel /** Flag indicating that the image is loaded for the first time.*/ private boolean firstTime; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates the plane to retrieve. * @@ -495,20 +501,24 @@ private void initializeMetadataViewer() { metadataViewer = MetadataViewerFactory.getViewer("", MetadataViewer.RND_SPECIFIC); - metadataViewer.setRootObject(image, metadataViewer.getUserID()); + metadataViewer.setRootObject(image, metadataViewer.getUserID(), + getSecurityContext()); } /** * Creates a new instance. * + * @param ctx The security context. * @param imageID The id of the image. * @param bounds The bounds of the component invoking the * {@link ImViewer}. * @param separateWindow Pass true to open the viewer in a * separate window, false otherwise. */ - ImViewerModel(long imageID, Rectangle bounds, boolean separateWindow) + ImViewerModel(SecurityContext ctx, long imageID, Rectangle bounds, + boolean separateWindow) { + this.ctx = ctx; this.imageID = imageID; initialize(bounds, separateWindow); } @@ -528,15 +538,18 @@ ImageData getImage() /** * Creates a new object and sets its state to {@link ImViewer#NEW}. * - * @param image The image or well sample to view. - * @param bounds The bounds of the component invoking the + * @param ctx The security context. + * @param image The image or well sample to view. + * @param bounds The bounds of the component invoking the * {@link ImViewer}. * @param separateWindow Pass true to open the viewer in a - * separate window, false otherwise. + * separate window, false otherwise. */ - ImViewerModel(DataObject image, Rectangle bounds, boolean separateWindow) + ImViewerModel(SecurityContext ctx, DataObject image, Rectangle bounds, + boolean separateWindow) { this.image = image; + this.ctx = ctx; initialize(bounds, separateWindow); numberOfRows = 1; numberOfColumns = 1; @@ -648,8 +661,15 @@ String getImageName() */ String getImageTitle() { - return "[ID: "+getImageID()+"] "+ - EditorUtil.getPartialName(getImageName()); + GroupData group = getSelectedGroup(); + StringBuffer buffer = new StringBuffer(); + if (group != null) { + buffer.append("Group: "); + buffer.append(group.getName()); + } + buffer.append(" [ID: "+getImageID()+"] "); + buffer.append(EditorUtil.getPartialName(getImageName())); + return buffer.toString(); } /** @@ -679,7 +699,12 @@ void discard() { state = ImViewer.DISCARDED; if (imageIcon != null) imageIcon.flush(); - // + browser.discard(); + if (image == null) return; + //Shut down the service + OmeroImageService svr = ImViewerAgent.getRegistry().getImageService(); + long pixelsID = getImage().getDefaultPixels().getId(); + svr.shutDown(ctx, pixelsID); Iterator i = loaders.keySet().iterator(); Integer index; while (i.hasNext()) { @@ -853,7 +878,8 @@ void firePlaneInfoRetrieval() if (planeInfos != null && planeInfos.size() > 0) return; int size = getMaxT()*getMaxC()*getMaxZ(); if (size > OmeroImageService.MAX_PLANE_INFO) return; - PlaneInfoLoader loader = new PlaneInfoLoader(component, getPixelsID()); + PlaneInfoLoader loader = new PlaneInfoLoader(component, ctx, + getPixelsID()); loader.load(); } @@ -867,8 +893,8 @@ void fireImageRetrieval() if (firstTime) { browser.setUnitBar(true); long pixelsID = getImage().getDefaultPixels().getId(); - ImageLoader loader = new ImageLoader(component, pixelsID, pDef, - false); + ImageLoader loader = new ImageLoader(component, ctx, + pixelsID, pDef, false); loader.load(); loaders.put(IMAGE, loader); } else { @@ -1155,7 +1181,7 @@ boolean isBigImage() try { Boolean b = ImViewerAgent.getRegistry().getImageService().isLargeImage( - getImage().getDefaultPixels().getId()); + ctx, getImage().getDefaultPixels().getId()); if (b != null) return b.booleanValue(); } catch (Exception e) {} //ingore @@ -1681,7 +1707,7 @@ void fireLoadRndSettingsToPaste() long id = ImViewerFactory.getRefImage().getDefaultPixels().getId(); if (id < 0) return; RenderingSettingsLoader loader = new RenderingSettingsLoader(component, - id, true); + ctx, id, true); loader.load(); state = ImViewer.PASTING; } @@ -1779,7 +1805,7 @@ int getCompressionLevel() */ void fireRenderingSettingsRetrieval() { - DataLoader loader = new RenderingSettingsLoader(component, + DataLoader loader = new RenderingSettingsLoader(component, ctx, getImage().getDefaultPixels().getId()); loader.load(); if (loaders.get(SETTINGS) != null) @@ -1794,7 +1820,7 @@ void fireRenderingSettingsRetrieval() void fireOwnerSettingsRetrieval() { RenderingSettingsLoader loader = new RenderingSettingsLoader(component, - getImage().getDefaultPixels().getId()); + ctx, getImage().getDefaultPixels().getId()); loader.setOwner(getOwnerID()); loader.load(); if (loaders.get(SETTINGS) != null) @@ -1897,7 +1923,7 @@ void fireRenderProjected(int startZ, int endZ, int stepping, int type) param.setChannels(getActiveChannels()); lastProjRef = param; lastProjDef = metadataViewer.getRenderer().getRndSettingsCopy(); - ProjectionSaver loader = new ProjectionSaver(component, param, + ProjectionSaver loader = new ProjectionSaver(component, ctx, param, ProjectionSaver.PREVIEW); loader.load(); } @@ -1940,7 +1966,7 @@ void fireImageProjection(int startZ, int endZ, int stepping, int type, param.setDatasets(ref.getDatasets()); param.setDatasetParent(ref.getProject()); param.setChannels(getActiveChannels()); - ProjectionSaver loader = new ProjectionSaver(component, param, + ProjectionSaver loader = new ProjectionSaver(component, ctx, param, ProjectionSaver.PROJECTION, ref.isApplySettings()); loader.load(); } @@ -1952,7 +1978,8 @@ void fireImageProjection(int startZ, int endZ, int stepping, int type, void fireContainersLoading() { state = ImViewer.LOADING_PROJECTION_DATA; - ContainerLoader loader = new ContainerLoader(component, getImageID()); + ContainerLoader loader = new ContainerLoader(component, ctx, + getImageID()); loader.load(); } @@ -1979,8 +2006,8 @@ void fireProjectedRndSettingsCreation(List indexes, Renderer rnd = metadataViewer.getRenderer(); if (rnd == null) return; RndProxyDef def = rnd.getRndSettingsCopy(); - RenderingSettingsCreator l = new RenderingSettingsCreator(component, - image, def, indexes); + RenderingSettingsCreator l = new RenderingSettingsCreator(component, + ctx, image, def, indexes); l.load(); } @@ -2062,7 +2089,8 @@ PlaneInfo getPlane(int z, int c, int t) void fireImageLoading() { state = ImViewer.LOADING_IMAGE_DATA; - ImageDataLoader loader = new ImageDataLoader(component, getImageID()); + ImageDataLoader loader = new ImageDataLoader(component, ctx, + getImageID()); loader.load(); } @@ -2196,7 +2224,7 @@ PixelsData getPixelsData() /** Loads all the available datasets. */ void loadAllContainers() { - ContainerLoader loader = new ContainerLoader(component); + ContainerLoader loader = new ContainerLoader(component, ctx); loader.load(); } @@ -2298,7 +2326,8 @@ void fireMeasurementsLoading() if (parent instanceof WellData) { //PlateData p = ((WellData) parent).getPlate(); ImageData p = getImage(); - MeasurementsLoader loader = new MeasurementsLoader(component, p); + MeasurementsLoader loader = new MeasurementsLoader(component, ctx, + p); loader.load(); } } @@ -2424,8 +2453,8 @@ void renderOverlays(Map overlays) pDef.z = getDefaultZ(); pDef.slice = omero.romio.XY.value; state = ImViewer.LOADING_IMAGE; - OverlaysRenderer loader = new OverlaysRenderer(component, getPixelsID(), - pDef, overlayTableID, overlays); + OverlaysRenderer loader = new OverlaysRenderer(component, ctx, + getPixelsID(), pDef, overlayTableID, overlays); loader.load(); } @@ -2576,8 +2605,8 @@ void fireBirdEyeViewRetrieval() } if (ratio < BirdEyeLoader.MIN_RATIO) ratio = BirdEyeLoader.MIN_RATIO; state = ImViewer.LOADING_BIRD_EYE_VIEW; - BirdEyeLoader loader = new BirdEyeLoader(component, getImage(), pDef, - ratio); + BirdEyeLoader loader = new BirdEyeLoader(component, ctx, getImage(), + pDef, ratio); loader.load(); loaders.put(BIRD_EYE_BVIEW, loader); /* @@ -2587,7 +2616,8 @@ void fireBirdEyeViewRetrieval() else newImage = image; component.setBirdEyeView(newImage); } else { - BirdEyeLoader loader = new BirdEyeLoader(component, getImage()); + BirdEyeLoader loader = new BirdEyeLoader(component, ctx, + getImage()); loader.load(); } */ @@ -2652,8 +2682,8 @@ void fireTileLoading(List selection) list = selection; sortTilesByIndex(list); state = ImViewer.LOADING_TILES; - TileLoader loader = new TileLoader(component, currentPixelsID, pDef, - list); + TileLoader loader = new TileLoader(component, ctx, currentPixelsID, + pDef, list); loader.load(); } @@ -2770,6 +2800,7 @@ void cancelRendering() } /** +<<<<<<< HEAD * Sets the image for the bird eye view. * * @param image The image to set. @@ -2780,4 +2811,47 @@ void setBirdEyeView(BufferedImage image) getBrowser().setBirdEyeView(image); } + /** + * Returns true if it is the same viewer, false + * otherwise. + * + * @param pixelsID The id of the pixels set. + * @param ctx + * @return + */ + boolean isSame(long pixelsID, SecurityContext ctx) + { + if (getPixelsID() == pixelsID) //add server check + return true; + return false; + } + + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext() { return ctx; } + + /** + * Returns the group the image belongs to. + * + * @return See above. + */ + GroupData getSelectedGroup() + { + Set set = (Set) ImViewerAgent.getRegistry().lookup( + LookupNames.USER_GROUP_DETAILS); + if (set == null || set.size() <= 1) + return null; + Iterator i = set.iterator(); + GroupData g; + while (i.hasNext()) { + g = (GroupData) i.next(); + if (g.getId() == ctx.getGroupID()) + return g; + } + return null; + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerRecentObject.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerRecentObject.java index 92c07494dc1..4a6a395b90a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerRecentObject.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerRecentObject.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.imviewer.IconManager; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; /** * Utility class where details about a recenlty viewed image are stored. @@ -57,17 +58,23 @@ public class ImViewerRecentObject /** A thumbnail representation of the image. */ private ImageIcon icon; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a new instance. * - * @param imageID The id of image viewed. + * @param ctx The security context. + * @param imageID The id of image viewed. * @param imageName The name of image viewed - * @param icon A icon of the last image. + * @param icon A icon of the last image. */ - ImViewerRecentObject(long imageID, String imageName, ImageIcon icon) + ImViewerRecentObject(SecurityContext ctx, long imageID, String imageName, + ImageIcon icon) { this.imageID = imageID; this.imageName = imageName; + this.ctx = ctx; if (icon == null) { IconManager im = IconManager.getInstance(); icon = im.getImageIcon(IconManager.VIEWER); @@ -96,4 +103,10 @@ public class ImViewerRecentObject */ public ImageIcon getImageIcon() { return icon; } + /** + * Returns the security context. + * + * @return See above. + */ + public SecurityContext getSecurityContext() { return ctx; } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerUI.java index 5e0cd292588..0ce5c740663 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ImViewerUI.java @@ -102,6 +102,7 @@ import org.openmicroscopy.shoola.util.ui.tdialog.TinyDialog; import pojos.ChannelData; import pojos.DataObject; +import pojos.GroupData; import pojos.ImageData; /** @@ -2625,6 +2626,13 @@ void setImageData() statusBar.formatToolTip(); } + /** + * Returns the group the image belongs to. + * + * @return See above. + */ + GroupData getSelectedGroup() { return model.getSelectedGroup(); } + /** * Overridden to the set the location of the {@link ImViewer}. * @see TopWindow#setOnScreen() diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ToolBar.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ToolBar.java index 2649967a0bd..cee8968f6b0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ToolBar.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/imviewer/view/ToolBar.java @@ -43,13 +43,17 @@ import org.jdesktop.swingx.JXBusyLabel; //Application-internal dependencies +import org.openmicroscopy.shoola.agents.imviewer.IconManager; import org.openmicroscopy.shoola.agents.imviewer.ImViewerAgent; import org.openmicroscopy.shoola.agents.imviewer.actions.ActivityImageAction; import org.openmicroscopy.shoola.agents.imviewer.actions.ROIToolAction; import org.openmicroscopy.shoola.agents.util.EditorUtil; import org.openmicroscopy.shoola.env.LookupNames; +import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.GroupData; + /** * Presents the variable drawing controls. @@ -153,6 +157,32 @@ class ToolBar /** The index of the Metadata component. */ private static final int METADATA_INDEX = 1; + /** + * Returns the icon corresponding to the permissions of the group. + * + * @param g The group to handle. + * @return See above. + */ + private Icon getPermissionsIcon(GroupData g) + { + int level = + ImViewerAgent.getRegistry().getAdminService().getPermissionLevel(g); + IconManager icons = IconManager.getInstance(); + switch (level) { + case AdminObject.PERMISSIONS_PRIVATE: + return icons.getIcon(IconManager.PRIVATE_GROUP); + case AdminObject.PERMISSIONS_GROUP_READ: + return icons.getIcon(IconManager.READ_GROUP); + case AdminObject.PERMISSIONS_GROUP_READ_LINK: + return icons.getIcon(IconManager.READ_LINK_GROUP); + case AdminObject.PERMISSIONS_PUBLIC_READ: + return icons.getIcon(IconManager.PUBLIC_GROUP); + case AdminObject.PERMISSIONS_PUBLIC_READ_WRITE: + return icons.getIcon(IconManager.PUBLIC_GROUP); + } + return null; + } + /** Helper method to create the tool bar hosting the buttons. */ private void createControlsBar() { @@ -306,6 +336,15 @@ private void buildGUI() bars.setBorder(null); bars.add(bar); if (p != null) bars.add(p); + GroupData g = view.getSelectedGroup(); + if (g != null) { + p = new JPanel(); + l = new JLabel(g.getName()); + l.setIcon(getPermissionsIcon(g)); + //indicate color using icon + p.add(l); + bars.add(p); + } //add(UIUtilities.buildComponentPanel(bar)); add(UIUtilities.buildComponentPanel(bars)); add(UIUtilities.buildComponentPanelRight(busyLabel)); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/Analyser.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/Analyser.java index 15ed74b7570..f28a749fd5a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/Analyser.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/Analyser.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.ui.UserNotifier; @@ -80,16 +81,17 @@ public class Analyser * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param pixels The pixels set to analyze. * @param channels Collection of active channels. * Mustn't be null. * @param shapes Collection of shapes to analyze. * Mustn't be null. */ - public Analyser(MeasurementViewer viewer, PixelsData pixels, - List channels, List shapes) + public Analyser(MeasurementViewer viewer, SecurityContext ctx, + PixelsData pixels, List channels, List shapes) { - super(viewer); + super(viewer, ctx); if (channels == null || channels.size() == 0) throw new IllegalArgumentException("No channels specified."); if (shapes == null || shapes.size() == 0) @@ -108,10 +110,12 @@ public void load() { switch (index) { case SHAPE: - handle = idView.analyseShapes(pixels, channels, shapes, this); + handle = idView.analyseShapes(ctx, pixels, channels, shapes, + this); break; case ROI: - handle = idView.analyseShapes(pixels, channels, shapes, this); + handle = idView.analyseShapes(ctx, pixels, channels, shapes, + this); break; } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/MeasurementAgent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/MeasurementAgent.java index 6de27a9df28..6e4e6024c79 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/MeasurementAgent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/MeasurementAgent.java @@ -85,10 +85,11 @@ private void handleMeasurementToolEvent(MeasurementTool evt) { PixelsData pixels = evt.getPixels(); if (pixels == null) return; - MeasurementViewer viewer = MeasurementViewerFactory.getViewer( + MeasurementViewer viewer = MeasurementViewerFactory.getViewer(null, pixels.getId()); if (viewer == null) { viewer = MeasurementViewerFactory.getViewer( + evt.getSecurityContext(), evt.getPixels(), evt.getImageID(), evt.getName(), evt.getRequesterBounds(), evt.getDefaultZ(), evt.getDefaultT(), evt.getMagnification(), @@ -110,7 +111,7 @@ private void handleMeasurementToolEvent(MeasurementTool evt) */ private void handleMeasurePlaneEvent(MeasurePlane evt) { - MeasurementViewer viewer = MeasurementViewerFactory.getViewer( + MeasurementViewer viewer = MeasurementViewerFactory.getViewer(null, evt.getPixelsID()); if (viewer != null) viewer.setMagnifiedPlane(evt.getDefaultZ(), evt.getDefaultT(), @@ -124,7 +125,7 @@ private void handleMeasurePlaneEvent(MeasurePlane evt) */ private void handleViewerStateEvent(ViewerState evt) { - MeasurementViewer viewer = MeasurementViewerFactory.getViewer( + MeasurementViewer viewer = MeasurementViewerFactory.getViewer(null, evt.getPixelsID()); if (viewer != null) { switch (evt.getIndex()) { @@ -147,7 +148,7 @@ private void handleViewerStateEvent(ViewerState evt) */ private void handleFocusGainedEvent(FocusGainedEvent evt) { - MeasurementViewer viewer = MeasurementViewerFactory.getViewer( + MeasurementViewer viewer = MeasurementViewerFactory.getViewer(null, evt.getPixelsID()); if (viewer == null) return; if (viewer.getState() != MeasurementViewer.DISCARDED || @@ -163,7 +164,7 @@ private void handleFocusGainedEvent(FocusGainedEvent evt) */ private void handleChannelSelectionEvent(ChannelSelection evt) { - MeasurementViewer viewer = MeasurementViewerFactory.getViewer( + MeasurementViewer viewer = MeasurementViewerFactory.getViewer(null, evt.getPixelsID()); if (viewer != null) { switch (evt.getIndex()) { @@ -184,7 +185,7 @@ private void handleChannelSelectionEvent(ChannelSelection evt) */ private void handleSaveData(SaveData evt) { - MeasurementViewer viewer = MeasurementViewerFactory.getViewer( + MeasurementViewer viewer = MeasurementViewerFactory.getViewer(null, evt.getPixelsID()); if (viewer != null && evt.getType() == SaveData.MEASUREMENT_TYPE) { viewer.saveROIToServer(); @@ -199,7 +200,7 @@ private void handleSaveData(SaveData evt) */ private void handleImageRenderedEvent(ImageRendered evt) { - MeasurementViewer viewer = MeasurementViewerFactory.getViewer( + MeasurementViewer viewer = MeasurementViewerFactory.getViewer(null, evt.getPixelsID()); if (viewer != null) { viewer.setIconImage(evt.getThumbnail()); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/MeasurementViewerLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/MeasurementViewerLoader.java index a73de5dc43b..aaaf4cc0cf1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/MeasurementViewerLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/MeasurementViewerLoader.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewer; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.ImageDataView; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -63,23 +64,30 @@ public abstract class MeasurementViewerLoader { /** The MeasurementViewer this data loader is for. */ - protected final MeasurementViewer viewer; + protected final MeasurementViewer viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final ImageDataView idView; + protected final ImageDataView idView; + + /** The security context.*/ + protected final SecurityContext ctx; /** * Creates a new instance. * * @param viewer The MeasurementViewer this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - protected MeasurementViewerLoader(MeasurementViewer viewer) + protected MeasurementViewerLoader(MeasurementViewer viewer, + SecurityContext ctx) { if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null) throw new NullPointerException("No security context."); + this.ctx = ctx; this.viewer = viewer; registry = MeasurementAgent.getRegistry(); idView = (ImageDataView) diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ROILoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ROILoader.java index 72639036cdf..65246ec44bf 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ROILoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ROILoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -65,16 +66,17 @@ public class ROILoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param imageID The id of the image the ROIs are related to. - * @param fileID The id of the file to load. - * @param userID The id of the user. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param imageID The id of the image the ROIs are related to. + * @param fileID The id of the file to load. + * @param userID The id of the user. */ - public ROILoader(MeasurementViewer viewer, long imageID, List fileID, - long userID) + public ROILoader(MeasurementViewer viewer, SecurityContext ctx, + long imageID, List fileID, long userID) { - super(viewer); + super(viewer, ctx); if (imageID < 0) throw new IllegalArgumentException("No image specified."); this.imageID = imageID; @@ -89,12 +91,14 @@ public ROILoader(MeasurementViewer viewer, long imageID, List fileID, * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param imageID The id of the image the ROIs are related to. * @param userID The id of the user. */ - public ROILoader(MeasurementViewer viewer, long imageID, long userID) + public ROILoader(MeasurementViewer viewer, SecurityContext ctx, + long imageID, long userID) { - super(viewer); + super(viewer, ctx); if (imageID < 0) throw new IllegalArgumentException("No image specified."); this.imageID = imageID; @@ -107,7 +111,7 @@ public ROILoader(MeasurementViewer viewer, long imageID, long userID) */ public void load() { - handle = idView.loadROI(imageID, fileID, userID, this); + handle = idView.loadROI(ctx, imageID, fileID, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ROISaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ROISaver.java index d13d96d7555..d4873469f4e 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ROISaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ROISaver.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ROIData; @@ -70,14 +71,15 @@ public class ROISaver * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param imageID The id of the image the ROIs are related to. * @param userID The id of the user. * @param roiList The list of the roi id's to load. */ - public ROISaver(MeasurementViewer viewer, long imageID, long userID, - List roiList) + public ROISaver(MeasurementViewer viewer, SecurityContext ctx, + long imageID, long userID, List roiList) { - super(viewer); + super(viewer, ctx); if (imageID < 0) throw new IllegalArgumentException("No image specified."); this.imageID = imageID; @@ -91,7 +93,7 @@ public ROISaver(MeasurementViewer viewer, long imageID, long userID, */ public void load() { - handle = idView.saveROI(imageID, userID, roiList , this); + handle = idView.saveROI(ctx, imageID, userID, roiList , this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ServerSideROILoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ServerSideROILoader.java index 7f65c31f10a..2b505359028 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ServerSideROILoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/ServerSideROILoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewer; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -69,13 +70,14 @@ public class ServerSideROILoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param imageID The id of the image the ROIs are related to. * @param userID The id of the user. */ - public ServerSideROILoader(MeasurementViewer viewer, long imageID, - long userID) + public ServerSideROILoader(MeasurementViewer viewer, SecurityContext ctx, + long imageID, long userID) { - super(viewer); + super(viewer, ctx); if (imageID < 0) throw new IllegalArgumentException("No image specified."); this.imageID = imageID; @@ -88,7 +90,7 @@ public ServerSideROILoader(MeasurementViewer viewer, long imageID, */ public void load() { - handle = idView.loadROIFromServer(imageID, userID, this); + handle = idView.loadROIFromServer(ctx, imageID, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/WorkflowLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/WorkflowLoader.java index e996a062cb1..4e4cba82c23 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/WorkflowLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/WorkflowLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.WorkflowData; @@ -58,12 +59,14 @@ public class WorkflowLoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * @param userID The id of the user. + * @param viewer The viewer this data loader is for. + * @param ctx The security context. + * @param userID The id of the user. */ - public WorkflowLoader(MeasurementViewer viewer, long userID) + public WorkflowLoader(MeasurementViewer viewer, SecurityContext ctx, + long userID) { - super(viewer); + super(viewer, ctx); this.userID = userID; } @@ -73,7 +76,7 @@ public WorkflowLoader(MeasurementViewer viewer, long userID) */ public void load() { - handle = idView.retrieveWorkflows(userID, this); + handle = idView.retrieveWorkflows(ctx, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/WorkflowSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/WorkflowSaver.java index fb7572cbcf4..f97b8404b1e 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/WorkflowSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/WorkflowSaver.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.WorkflowData; @@ -64,13 +65,14 @@ public class WorkflowSaver * Creates a new instance. * * @param viewer The viewer this data loader is for. + * @param ctx The security context. * @param workflows The list of workflows to save. * @param userID The id of the user. */ - public WorkflowSaver(MeasurementViewer viewer, List workflows, - long userID) + public WorkflowSaver(MeasurementViewer viewer, SecurityContext ctx, + List workflows, long userID) { - super(viewer); + super(viewer, ctx); this.userID = userID; this.workflows = workflows; } @@ -81,7 +83,7 @@ public WorkflowSaver(MeasurementViewer viewer, List workflows, */ public void load() { - handle = idView.storeWorkflows(workflows, userID, this); + handle = idView.storeWorkflows(ctx, workflows, userID, this); } /** @@ -99,5 +101,4 @@ public void handleResult(Object result) if (viewer.getState() == MeasurementViewer.DISCARDED) return; //Async cancel. } -} - +} \ No newline at end of file diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerComponent.java index 6ef382f5809..e1d199fd5f0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerComponent.java @@ -101,13 +101,13 @@ class MeasurementViewerComponent { /** The Model sub-component. */ - private MeasurementViewerModel model; + private MeasurementViewerModel model; /** The Control sub-component. */ - private MeasurementViewerControl controller; + private MeasurementViewerControl controller; /** The View sub-component. */ - private MeasurementViewerUI view; + private MeasurementViewerUI view; /** * Posts an event to indicating to add or remove the component @@ -120,7 +120,8 @@ private void postEvent(int index) { MeasurementToolLoaded response = new MeasurementToolLoaded( - MeasurementViewerFactory.getRequest(model.getPixelsID()), + MeasurementViewerFactory.getRequest(model.getPixelsID()), + model.getSecurityContext(), model.getDrawingView(), index); EventBus bus = MeasurementAgent.getRegistry().getEventBus(); bus.post(response); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerFactory.java index 75765ec6a9e..78606b97f92 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerFactory.java @@ -42,6 +42,7 @@ import org.openmicroscopy.shoola.agents.events.iviewer.MeasurementTool; import org.openmicroscopy.shoola.agents.measurement.MeasurementAgent; import org.openmicroscopy.shoola.agents.measurement.actions.ActivationAction; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.ui.TaskBar; import pojos.ChannelData; import pojos.PixelsData; @@ -110,25 +111,25 @@ static void register(JMenu menu) * Returns a viewer to display the image corresponding to the specified id. * Recycles or creates a viewer. * - * @param pixels The pixels set the measurement tool is for. - * @param imageID The id of the image. - * @param name The name of the image. - * @param bounds The bounds of the component invoking the - * {@link MeasurementViewer}. - * @param z The selected z-section. - * @param t The selected time-point. - * @param magnification The image's magnification factor. - * @param activeChannels Collection of active channels. - * @param channelsData The channels metadata. + * @param ctx The security context. + * @param pixels The pixels set the measurement tool is for. + * @param imageID The id of the image. + * @param name The name of the image. + * @param bounds The bounds of the component invoking the + * {@link MeasurementViewer}. + * @param z The selected z-section. + * @param t The selected time-point. + * @param magnification The image's magnification factor. + * @param activeChannels Collection of active channels. + * @param channelsData The channels metadata. * @return See above. */ - public static MeasurementViewer getViewer(PixelsData pixels, long imageID, - String name, Rectangle bounds, - int z, int t, double magnification, - Map activeChannels, List - channelsData) + public static MeasurementViewer getViewer(SecurityContext ctx, + PixelsData pixels, long imageID, String name, Rectangle bounds, + int z, int t, double magnification, + Map activeChannels, List channelsData) { - MeasurementViewerModel model = new MeasurementViewerModel(imageID, + MeasurementViewerModel model = new MeasurementViewerModel(ctx, imageID, pixels, name, bounds, channelsData); model.setPlane(z, t); model.setMagnification(magnification); @@ -139,10 +140,12 @@ public static MeasurementViewer getViewer(PixelsData pixels, long imageID, /** * Returns a viewer or null if not previously created. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @return See above. */ - public static MeasurementViewer getViewer(long pixelsID) + public static MeasurementViewer getViewer(SecurityContext ctx, + long pixelsID) { Iterator v = singleton.viewers.iterator(); MeasurementViewerComponent comp; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerModel.java index d54c50bb103..b71045beef0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/measurement/view/MeasurementViewerModel.java @@ -70,6 +70,7 @@ import org.openmicroscopy.shoola.env.data.model.DeletableObject; import org.openmicroscopy.shoola.env.data.model.DeleteActivityParam; import org.openmicroscopy.shoola.env.data.model.ROIResult; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.log.Logger; import org.openmicroscopy.shoola.env.ui.UserNotifier; @@ -208,6 +209,9 @@ class MeasurementViewerModel /** Flag indicating if it is a big image or not.*/ private boolean bigImage; + /** The security context.*/ + private SecurityContext ctx; + /** * Sorts the passed nodes by row. * @@ -273,16 +277,18 @@ private void checkIfHasROIToDelete() /** * Creates a new instance. * - * @param imageID The image's id. - * @param pixels The pixels set the measurement tool is for. - * @param name The image's name. - * @param bounds The bounds of the component requesting the model. - * @param channelsData The channel metadata. + * @param ctx The security context. + * @param imageID The image's id. + * @param pixels The pixels set the measurement tool is for. + * @param name The image's name. + * @param bounds The bounds of the component requesting the model. + * @param channelsData The channel metadata. */ - MeasurementViewerModel(long imageID, PixelsData pixels, String name, - Rectangle bounds, List channelsData) + MeasurementViewerModel(SecurityContext ctx, long imageID, PixelsData pixels, + String name, Rectangle bounds, List channelsData) { metadata = channelsData; + this.ctx = ctx; this.imageID = imageID; this.pixels = pixels; this.name = name; @@ -973,8 +979,8 @@ void fireLoadROIFromServer(List measurements) state = MeasurementViewer.LOADING_ROI; ExperimenterData exp = (ExperimenterData) MeasurementAgent.getUserDetails(); - currentLoader = new ROILoader(component, getImageID(), files, - exp.getId()); + currentLoader = new ROILoader(component, getSecurityContext(), + getImageID(), files, exp.getId()); currentLoader.load(); } @@ -989,8 +995,8 @@ void fireLoadROIServerOrClient(boolean dataChanged) state = MeasurementViewer.LOADING_ROI; ExperimenterData exp = (ExperimenterData) MeasurementAgent.getUserDetails(); - currentLoader = new ServerSideROILoader(component, getImageID(), - exp.getId()); + currentLoader = new ServerSideROILoader(component, getSecurityContext(), + getImageID(), exp.getId()); currentLoader.load(); notifyDataChanged(dataChanged); } @@ -1002,7 +1008,8 @@ void fireLoadWorkflow() { ExperimenterData exp = (ExperimenterData) MeasurementAgent.getUserDetails(); - currentLoader = new WorkflowLoader(component, exp.getId()); + currentLoader = new WorkflowLoader(component, getSecurityContext(), + exp.getId()); currentLoader.load(); } @@ -1017,7 +1024,8 @@ void retrieveWorkflowsFromServer() MeasurementAgent.getRegistry().getImageService(); try { - List result = svc.retrieveWorkflows(exp.getId()); + List result = svc.retrieveWorkflows( + getSecurityContext(), exp.getId()); workflows.clear(); component.setWorkflowList(result); } catch (DSAccessException e) @@ -1142,15 +1150,16 @@ void saveROIToServer(boolean async) if (roiList.size() == 0) return; roiComponent.reset(); if (async) { - currentSaver = new ROISaver(component, getImageID(), - exp.getId(), roiList); + currentSaver = new ROISaver(component, getSecurityContext(), + getImageID(), exp.getId(), roiList); currentSaver.load(); state = MeasurementViewer.SAVING_ROI; notifyDataChanged(false); } else { OmeroImageService svc = MeasurementAgent.getRegistry().getImageService(); - svc.saveROI(getImageID(), exp.getId(), roiList); + svc.saveROI(getSecurityContext(), getImageID(), exp.getId(), + roiList); event = null; } checkIfHasROIToDelete(); @@ -1202,14 +1211,15 @@ void saveWorkflowToServer(boolean async) ExperimenterData exp = (ExperimenterData) MeasurementAgent.getUserDetails(); if (async) { - currentSaver = new WorkflowSaver(component, - workflowList, exp.getId()); + currentSaver = new WorkflowSaver(component, + getSecurityContext(), workflowList, exp.getId()); currentSaver.load(); notifyDataChanged(false); } else { OmeroImageService svc = MeasurementAgent.getRegistry().getImageService(); - svc.storeWorkflows(workflowList, exp.getId()); + svc.storeWorkflows(getSecurityContext(), workflowList, + exp.getId()); event = null; } } catch (Exception e) { @@ -1301,7 +1311,8 @@ void fireAnalyzeShape(List shapeList) List channels = new ArrayList(activeChannels.size()); channels.addAll(activeChannels.keySet()); if (currentLoader != null) currentLoader.cancel(); - currentLoader = new Analyser(component, pixels, channels, shapeList); + currentLoader = new Analyser(component, getSecurityContext(), pixels, + channels, shapeList); currentLoader.load(); } @@ -1742,7 +1753,7 @@ void deleteAllROIs(List list) p.setImageID(imageID); p.setFailureIcon(icons.getIcon(IconManager.DELETE_22)); UserNotifier un = MeasurementAgent.getRegistry().getUserNotifier(); - un.notifyActivity(p); + un.notifyActivity(getSecurityContext(), p); } /** @@ -1750,7 +1761,7 @@ void deleteAllROIs(List list) * * @param value The value to set. */ - public void setBigImage(boolean value) { bigImage = value; } + void setBigImage(boolean value) { bigImage = value; } /** * Returns true if big image data, false @@ -1758,6 +1769,13 @@ void deleteAllROIs(List list) * * @return See above. */ - public boolean isBigImage() { return bigImage; } + boolean isBigImage() { return bigImage; } + + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext() { return ctx; } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AcquisitionDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AcquisitionDataLoader.java index 3f91eda5aa1..ba95c2c8896 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AcquisitionDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AcquisitionDataLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ChannelAcquisitionData; @@ -54,20 +55,22 @@ public class AcquisitionDataLoader { /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** Either an image or a channel. */ - private Object refObject; + private Object refObject; /** * Creates a new instance. * - * @param viewer Reference to the viewer. Mustn't be null. + * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. * @param refObject Either an image or a channel. */ - public AcquisitionDataLoader(Editor viewer, Object refObject) + public AcquisitionDataLoader(Editor viewer, SecurityContext ctx, + Object refObject) { - super(viewer); + super(viewer, ctx); if (refObject == null) throw new IllegalArgumentException("Ref Object cannot be null."); this.refObject = refObject; @@ -79,7 +82,7 @@ public AcquisitionDataLoader(Editor viewer, Object refObject) */ public void load() { - handle = imView.loadAcquisitionData(refObject, this); + handle = imView.loadAcquisitionData(ctx, refObject, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AcquisitionDataSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AcquisitionDataSaver.java index a8a4d585b9b..e6ec7fa5b8a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AcquisitionDataSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AcquisitionDataSaver.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ImageAcquisitionData; @@ -61,12 +62,14 @@ public class AcquisitionDataSaver /** * Creates a new instance. * - * @param viewer Reference to the viewer. Mustn't be null. + * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. * @param refObject Either an image or a channel. */ - public AcquisitionDataSaver(Editor viewer, Object refObject) + public AcquisitionDataSaver(Editor viewer, SecurityContext ctx, + Object refObject) { - super(viewer); + super(viewer, ctx); if (refObject == null) throw new IllegalArgumentException("Ref Object cannot be null."); this.refObject = refObject; @@ -78,7 +81,7 @@ public AcquisitionDataSaver(Editor viewer, Object refObject) */ public void load() { - handle = imView.saveAcquisitionData(refObject, this); + handle = imView.saveAcquisitionData(ctx, refObject, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AdminEditor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AdminEditor.java index 8c8ba78c749..7ffbcf0c3c7 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AdminEditor.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AdminEditor.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; import org.openmicroscopy.shoola.env.data.login.UserCredentials; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; import pojos.GroupData; @@ -66,13 +67,14 @@ public class AdminEditor * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param group The group to handle. * @param details The experimenters to update. Mustn't be null. */ - public AdminEditor(MetadataViewer viewer, GroupData group, - Map details) + public AdminEditor(MetadataViewer viewer, SecurityContext ctx, + GroupData group, Map details) { - super(viewer, null); + super(viewer, ctx, null); if (details == null) throw new IllegalArgumentException("No eperimenters to update."); this.details = details; @@ -85,7 +87,7 @@ public AdminEditor(MetadataViewer viewer, GroupData group, */ public void load() { - handle = adminView.updateExperimenters(group, details, this); + handle = adminView.updateExperimenters(ctx, group, details, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AnalysisResultsFileLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AnalysisResultsFileLoader.java index 87e748a15c0..8ee26849a2a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AnalysisResultsFileLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AnalysisResultsFileLoader.java @@ -37,6 +37,7 @@ import org.openmicroscopy.shoola.agents.metadata.editor.Editor; import org.openmicroscopy.shoola.agents.metadata.util.AnalysisResultsItem; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.FileAnnotationData; @@ -53,12 +54,12 @@ * * @since 3.0-Beta4 */ -public class AnalysisResultsFileLoader +public class AnalysisResultsFileLoader extends EditorLoader { /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** The files to load. */ private Map results; @@ -74,12 +75,13 @@ public class AnalysisResultsFileLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param item The object hosting information about the results to load. */ - public AnalysisResultsFileLoader(Editor viewer, + public AnalysisResultsFileLoader(Editor viewer, SecurityContext ctx, AnalysisResultsItem item) { - super(viewer); + super(viewer, ctx); if (item == null) throw new IllegalArgumentException("No files to load"); this.item = item; @@ -120,7 +122,7 @@ public void load() f.deleteOnExit(); map.put(fa, f); } - handle = mhView.loadFiles(map, this); + handle = mhView.loadFiles(ctx, map, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AttachmentsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AttachmentsLoader.java index f6d3adda98a..d16d2c4a19b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AttachmentsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/AttachmentsLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.FileAnnotationData; @@ -60,12 +61,13 @@ public class AttachmentsLoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. */ - public AttachmentsLoader(Editor viewer) + public AttachmentsLoader(Editor viewer, SecurityContext ctx) { - super(viewer); + super(viewer, ctx); } /** @@ -75,7 +77,7 @@ public AttachmentsLoader(Editor viewer) public void load() { setIds(); - handle = mhView.loadExistingAnnotations(FileAnnotationData.class, + handle = mhView.loadExistingAnnotations(ctx, FileAnnotationData.class, userID, groupID, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ChannelDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ChannelDataLoader.java index 411dd4af1a6..7d1cf2d2992 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ChannelDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ChannelDataLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -53,24 +54,26 @@ public class ChannelDataLoader { /** The id of the pixels set. */ - private long pixelsID; + private long pixelsID; /** The id of the user. */ - private long userID; + private long userID; /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** * Creates a new instance. * - * @param viewer Reference to the viewer. Mustn't be null. - * @param pixelsID The id of the pixels set. - * @param userID The id of the user. + * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param userID The id of the user. */ - public ChannelDataLoader(Editor viewer, long pixelsID, long userID) + public ChannelDataLoader(Editor viewer, SecurityContext ctx, long pixelsID, + long userID) { - super(viewer); + super(viewer, ctx); this.pixelsID = pixelsID; this.userID = userID; } @@ -81,7 +84,7 @@ public ChannelDataLoader(Editor viewer, long pixelsID, long userID) */ public void load() { - handle = dmView.loadChannelsData(pixelsID, userID, this); + handle = dmView.loadChannelsData(ctx, pixelsID, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ContainersLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ContainersLoader.java index 8586c3df3e3..95420e75df4 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ContainersLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ContainersLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.browser.TreeBrowserSet; import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -47,32 +48,33 @@ * * @since OME3.0 */ -public class ContainersLoader +public class ContainersLoader extends MetadataLoader { /** The type of DataObject. */ - private Class type; + private Class type; /** The ID of the parent of the {@link #refNode}. */ - private long id; + private long id; /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param refNode The node of reference. Mustn't be null. - * @param type The type of the parent of the {@link #refNode}. - * @param id The ID of the parent of the reference node. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param refNode The node of reference. Mustn't be null. + * @param type The type of the parent of the {@link #refNode}. + * @param id The ID of the parent of the reference node. */ - public ContainersLoader(MetadataViewer viewer, TreeBrowserSet refNode, - Class type, long id) + public ContainersLoader(MetadataViewer viewer, SecurityContext ctx, + TreeBrowserSet refNode, Class type, long id) { - super(viewer, refNode); + super(viewer, ctx, refNode); this.type = type; this.id = id; } @@ -82,12 +84,14 @@ public ContainersLoader(MetadataViewer viewer, TreeBrowserSet refNode, * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param type The data type of the edited object. * @param id The id of the currently edited object. */ - public ContainersLoader(MetadataViewer viewer, Class type, long id) + public ContainersLoader(MetadataViewer viewer, SecurityContext ctx, + Class type, long id) { - super(viewer, null); + super(viewer, ctx); this.type = type; this.id = id; } @@ -98,7 +102,7 @@ public ContainersLoader(MetadataViewer viewer, Class type, long id) */ public void load() { - handle = mhView.loadContainers(type, id, -1L, this); + handle = mhView.loadContainers(ctx, type, id, -1L, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DataBatchSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DataBatchSaver.java index edca4353e59..715e9a14b70 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DataBatchSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DataBatchSaver.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.AnnotationData; import pojos.DataObject; @@ -50,7 +51,7 @@ * * @since OME3.0 */ -public class DataBatchSaver +public class DataBatchSaver extends MetadataLoader { @@ -72,15 +73,17 @@ public class DataBatchSaver /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param data The objects the data are related to. - * Mustn't be null. - * @param toAdd The collection of annotations to add. - * @param toRemove The collection of annotations to remove. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param data The objects the data are related to. + * Mustn't be null. + * @param toAdd The collection of annotations to add. + * @param toRemove The collection of annotations to remove. */ - public DataBatchSaver(MetadataViewer viewer, Collection data, - List toAdd, List toRemove) + public DataBatchSaver(MetadataViewer viewer, SecurityContext ctx, + Collection data, List toAdd, + List toRemove) { super(viewer, null); if (data == null) @@ -93,15 +96,17 @@ public DataBatchSaver(MetadataViewer viewer, Collection data, /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. * @param timeRefObject The object hosting the time period. * Mustn't be null. * @param toAdd The collection of annotations to add. * @param toRemove The collection of annotations to remove. */ - public DataBatchSaver(MetadataViewer viewer, TimeRefObject timeRefObject, - List toAdd, List toRemove) + public DataBatchSaver(MetadataViewer viewer, SecurityContext ctx, + TimeRefObject timeRefObject, List toAdd, + List toRemove) { super(viewer, null); if (timeRefObject == null) @@ -119,10 +124,11 @@ public void load() { long userID = MetadataViewerAgent.getUserDetails().getId(); if (timeRefObject != null) - handle = mhView.saveBatchData(timeRefObject, toAdd, toRemove, + handle = mhView.saveBatchData(ctx, timeRefObject, toAdd, toRemove, userID, this); else - handle = mhView.saveBatchData(data, toAdd, toRemove, userID, this); + handle = mhView.saveBatchData(ctx, data, toAdd, toRemove, userID, + this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DataSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DataSaver.java index 04660095b76..98f702475c5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DataSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DataSaver.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.AnnotationData; import pojos.DataObject; @@ -72,19 +73,20 @@ public class DataSaver /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param data The objects the data are related to. - * Mustn't be null. - * @param toAdd The collection of annotations to add. - * @param toRemove The collection of annotations to remove. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param data The objects the data are related to. + * Mustn't be null. + * @param toAdd The collection of annotations to add. + * @param toRemove The collection of annotations to remove. * @param acquisitionMetadata */ - public DataSaver(MetadataViewer viewer, Collection data, - List toAdd, List toRemove, - List acquisitionMetadata) + public DataSaver(MetadataViewer viewer, SecurityContext ctx, + Collection data, List toAdd, + List toRemove, List acquisitionMetadata) { - super(viewer, null); + super(viewer, ctx, null); if (data == null) throw new IllegalArgumentException("No object specified."); this.data = data; @@ -100,7 +102,7 @@ public DataSaver(MetadataViewer viewer, Collection data, public void load() { long userID = MetadataViewerAgent.getUserDetails().getId(); - handle = mhView.saveData(data, toAdd, toRemove, + handle = mhView.saveData(ctx, data, toAdd, toRemove, acquisitionMetadata, userID, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DiskSpaceLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DiskSpaceLoader.java index bbc41cc9389..d10a993db01 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DiskSpaceLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/DiskSpaceLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; import org.openmicroscopy.shoola.env.data.model.DiskQuota; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; import pojos.GroupData; @@ -64,13 +65,15 @@ public class DiskSpaceLoader * Creates a new instance. * * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. * @param type Either ExperimenterData or * GroupData. * @param id The identifier of the user or the group. */ - public DiskSpaceLoader(Editor viewer, Class type, long id) + public DiskSpaceLoader(Editor viewer, SecurityContext ctx, Class type, + long id) { - super(viewer); + super(viewer, ctx); if (!(ExperimenterData.class.equals(type) || GroupData.class.equals(type))) throw new IllegalArgumentException("Type can only by " + @@ -85,7 +88,7 @@ public DiskSpaceLoader(Editor viewer, Class type, long id) */ public void load() { - handle = adminView.getDiskSpace(type, id, this); + handle = adminView.getDiskSpace(ctx, type, id, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/EditorLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/EditorLoader.java index db89596e6c1..382c1325422 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/EditorLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/EditorLoader.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.AdminView; import org.openmicroscopy.shoola.env.data.views.DataManagerView; import org.openmicroscopy.shoola.env.data.views.ImageDataView; @@ -67,28 +68,31 @@ public abstract class EditorLoader { /** The viewer this data loader is for. */ - protected final Editor viewer; + protected final Editor viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final MetadataHandlerView mhView; + protected final MetadataHandlerView mhView; /** Convenience reference for subclasses. */ - protected final DataManagerView dmView; + protected final DataManagerView dmView; /** Convenience reference for subclasses. */ - protected final ImageDataView imView; + protected final ImageDataView imView; /** Convenience reference for subclasses. */ - protected final AdminView adminView; + protected final AdminView adminView; /** The id of the user or -1. */ - protected long userID; + protected long userID; /** The id of the group or -1. */ - protected long groupID; + protected long groupID; + + /** The security context.*/ + protected final SecurityContext ctx; /** Sets the identifiers of the group and user. */ void setIds() @@ -108,23 +112,27 @@ void setIds() /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. */ - public EditorLoader(Editor viewer) + public EditorLoader(Editor viewer, SecurityContext ctx) { - if (viewer == null) throw new NullPointerException("No viewer."); - this.viewer = viewer; - registry = MetadataViewerAgent.getRegistry(); - mhView = (MetadataHandlerView) - registry.getDataServicesView(MetadataHandlerView.class); - dmView = (DataManagerView) - registry.getDataServicesView(DataManagerView.class); - imView = (ImageDataView) - registry.getDataServicesView(ImageDataView.class); - adminView = (AdminView) registry.getDataServicesView(AdminView.class); - userID = -1; - groupID = -1; + if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null) + throw new NullPointerException("No security context."); + this.ctx = ctx; + this.viewer = viewer; + registry = MetadataViewerAgent.getRegistry(); + mhView = (MetadataHandlerView) + registry.getDataServicesView(MetadataHandlerView.class); + dmView = (DataManagerView) + registry.getDataServicesView(DataManagerView.class); + imView = (ImageDataView) + registry.getDataServicesView(ImageDataView.class); + adminView = (AdminView) registry.getDataServicesView(AdminView.class); + userID = -1; + groupID = -1; } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/EnumerationLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/EnumerationLoader.java index 80dc1e9ae45..8945cd1bc72 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/EnumerationLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/EnumerationLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -66,11 +67,12 @@ public class EnumerationLoader * Creates a new instance. * * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. * @param index One of the constants defined by this class. */ - public EnumerationLoader(Editor viewer, int index) + public EnumerationLoader(Editor viewer, SecurityContext ctx, int index) { - super(viewer); + super(viewer, ctx); this.index = index; } @@ -81,8 +83,8 @@ public EnumerationLoader(Editor viewer, int index) public void load() { if (index == IMAGE) - handle = imView.loadImageMetadataEnumerations(this); - else handle = imView.loadChannelMetadataEnumerations(this); + handle = imView.loadImageMetadataEnumerations(ctx, this); + else handle = imView.loadChannelMetadataEnumerations(ctx, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ExperimenterEditor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ExperimenterEditor.java index 020ba905442..32b47ae724a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ExperimenterEditor.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ExperimenterEditor.java @@ -28,6 +28,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; @@ -61,11 +62,13 @@ public class ExperimenterEditor * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param exp The experimenter to update. Mustn't be null. */ - public ExperimenterEditor(MetadataViewer viewer, ExperimenterData exp) + public ExperimenterEditor(MetadataViewer viewer, SecurityContext ctx, + ExperimenterData exp) { - super(viewer, null); + super(viewer, ctx, null); if (exp == null) throw new IllegalArgumentException("No experimenter to edit."); this.exp = exp; @@ -77,7 +80,7 @@ public ExperimenterEditor(MetadataViewer viewer, ExperimenterData exp) */ public void load() { - handle = adminView.updateExperimenter(exp, this); + handle = adminView.updateExperimenter(ctx, exp, this); } /** @@ -95,5 +98,5 @@ public void handleResult(Object result) if (viewer.getState() == MetadataViewer.DISCARDED) return; //Async cancel. viewer.onAdminUpdated((ExperimenterData) result); } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/FileLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/FileLoader.java index 0cba022a0e9..6797c650f24 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/FileLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/FileLoader.java @@ -38,6 +38,7 @@ import omero.model.OriginalFile; import org.openmicroscopy.shoola.agents.metadata.editor.Editor; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.FileAnnotationData; @@ -79,14 +80,16 @@ public class FileLoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param data The annotation hosting the file to load. - * @param uiView The object to handle. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param data The annotation hosting the file to load. + * @param uiView The object to handle. */ - public FileLoader(Editor viewer, FileAnnotationData data, Object uiView) + public FileLoader(Editor viewer, SecurityContext ctx, + FileAnnotationData data, Object uiView) { - super(viewer); + super(viewer, ctx); if (data == null) throw new IllegalArgumentException("No data set."); this.data = data; @@ -99,13 +102,15 @@ public FileLoader(Editor viewer, FileAnnotationData data, Object uiView) /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. * @param files The files to load. */ - public FileLoader(Editor viewer, Map files) + public FileLoader(Editor viewer, SecurityContext ctx, + Map files) { - super(viewer); + super(viewer, ctx); if (files == null) throw new IllegalArgumentException("No data set."); this.files = files; @@ -140,7 +145,7 @@ public void load() if (data != null) { OriginalFile f = ((FileAnnotation) data.asAnnotation()).getFile(); if (f.isLoaded()) { - handle = mhView.loadFile(file, f.getId().getValue(), + handle = mhView.loadFile(ctx, file, f.getId().getValue(), f.getSize().getValue(), this); } } else { @@ -159,9 +164,8 @@ public void load() f.deleteOnExit(); filesMap.put(fa, f); } - handle = mhView.loadFiles(filesMap, this); + handle = mhView.loadFiles(ctx, filesMap, this); } - } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/GroupEditor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/GroupEditor.java index 70785a5b4fb..9104621ae55 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/GroupEditor.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/GroupEditor.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.GroupData; @@ -65,10 +66,12 @@ public class GroupEditor * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param group The group to update. Mustn't be null. * @param permissions The desired permissions level or -1. */ - public GroupEditor(MetadataViewer viewer, GroupData group, int permissions) + public GroupEditor(MetadataViewer viewer, SecurityContext ctx, + GroupData group, int permissions) { super(viewer, null); if (group == null) @@ -83,7 +86,7 @@ public GroupEditor(MetadataViewer viewer, GroupData group, int permissions) */ public void load() { - handle = adminView.updateGroup(group, permissions, this); + handle = adminView.updateGroup(ctx, group, permissions, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/InstrumentDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/InstrumentDataLoader.java index 90b65124791..41ee6704592 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/InstrumentDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/InstrumentDataLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.InstrumentData; @@ -46,7 +47,7 @@ * * @since 3.0-Beta4 */ -public class InstrumentDataLoader +public class InstrumentDataLoader extends EditorLoader { @@ -59,12 +60,14 @@ public class InstrumentDataLoader /** * Creates a new instance. * - * @param viewer Reference to the viewer. Mustn't be null. + * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. * @param instrumentID The id of the instrument. */ - public InstrumentDataLoader(Editor viewer, long instrumentID) + public InstrumentDataLoader(Editor viewer, SecurityContext ctx, + long instrumentID) { - super(viewer); + super(viewer, ctx); if (instrumentID <= 0) throw new IllegalArgumentException("Instrument id not valid."); this.instrumentID = instrumentID; @@ -76,7 +79,7 @@ public InstrumentDataLoader(Editor viewer, long instrumentID) */ public void load() { - handle = imView.loadInstrumentData(instrumentID, this); + handle = imView.loadInstrumentData(ctx, instrumentID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/MetadataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/MetadataLoader.java index 4787950f64b..afa903dfb21 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/MetadataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/MetadataLoader.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.AdminView; import org.openmicroscopy.shoola.env.data.views.DataManagerView; import org.openmicroscopy.shoola.env.data.views.ImageDataView; @@ -65,57 +66,66 @@ public abstract class MetadataLoader { /** The node of reference i.e. where to feed back the results. */ - protected final TreeBrowserDisplay refNode; + protected final TreeBrowserDisplay refNode; /** The viewer this data loader is for. */ - protected final MetadataViewer viewer; + protected final MetadataViewer viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final MetadataHandlerView mhView; + protected final MetadataHandlerView mhView; /** Convenience reference for subclasses. */ - protected final DataManagerView dmView; + protected final DataManagerView dmView; /** Convenience reference for subclasses. */ - protected final ImageDataView ivView; + protected final ImageDataView ivView; /** Convenience reference for subclasses. */ - protected final AdminView adminView; + protected final AdminView adminView; + + /** The security context.*/ + protected final SecurityContext ctx; /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. */ - public MetadataLoader(MetadataViewer viewer) + public MetadataLoader(MetadataViewer viewer, SecurityContext ctx) { - this(viewer, null); + this(viewer, ctx, null); } /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param refNode The node of reference. Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param refNode The node of reference. Mustn't be null. */ - public MetadataLoader(MetadataViewer viewer, TreeBrowserDisplay refNode) + public MetadataLoader(MetadataViewer viewer, SecurityContext ctx, + TreeBrowserDisplay refNode) { - if (viewer == null) throw new NullPointerException("No viewer."); - this.viewer = viewer; - this.refNode = refNode; - registry = MetadataViewerAgent.getRegistry(); - mhView = (MetadataHandlerView) - registry.getDataServicesView(MetadataHandlerView.class); - dmView = (DataManagerView) - registry.getDataServicesView(DataManagerView.class); - ivView = (ImageDataView) - registry.getDataServicesView(ImageDataView.class); - adminView = (AdminView) registry.getDataServicesView(AdminView.class); + if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null) + throw new NullPointerException("No security context."); + this.ctx = ctx; + this.viewer = viewer; + this.refNode = refNode; + registry = MetadataViewerAgent.getRegistry(); + mhView = (MetadataHandlerView) + registry.getDataServicesView(MetadataHandlerView.class); + dmView = (DataManagerView) + registry.getDataServicesView(DataManagerView.class); + ivView = (ImageDataView) + registry.getDataServicesView(ImageDataView.class); + adminView = (AdminView) registry.getDataServicesView(AdminView.class); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/MetadataViewerAgent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/MetadataViewerAgent.java index ad99adbac49..2d42d89a777 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/MetadataViewerAgent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/MetadataViewerAgent.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewerFactory; +import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; import org.openmicroscopy.shoola.env.Agent; import org.openmicroscopy.shoola.env.Environment; import org.openmicroscopy.shoola.env.LookupNames; @@ -40,10 +41,12 @@ import org.openmicroscopy.shoola.env.data.events.ReconnectedEvent; import org.openmicroscopy.shoola.env.data.events.UserGroupSwitched; import org.openmicroscopy.shoola.env.data.util.AgentSaveInfo; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.AgentEvent; import org.openmicroscopy.shoola.env.event.AgentEventListener; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import pojos.ExperimenterData; +import pojos.GroupData; /** * The MetadataViewerAgent agent. This agent displays metadata related to @@ -107,6 +110,25 @@ public static boolean isAdministrator() return b.booleanValue(); } + /** + * Returns the context for an administrator. + * + * @return See above. + */ + public static SecurityContext getAdminContext() + { + if (!isAdministrator()) return null; + Set groups = TreeViewerAgent.getAvailableUserGroups(); + Iterator i = groups.iterator(); + GroupData g; + while (i.hasNext()) { + g = (GroupData) i.next(); + if (g.getName().equals(GroupData.SYSTEM)) { + return new SecurityContext(g.getId()); + } + } + return null; + } /** * Helper method returning true if the connection is fast, * false otherwise. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/PasswordEditor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/PasswordEditor.java index b412d4046cc..7a6b50573f0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/PasswordEditor.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/PasswordEditor.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -63,16 +64,16 @@ public class PasswordEditor /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param oldPassword The logged in password. - * Mustn't be null. - * @param newPassword The new password. Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param oldPassword The logged in password. Mustn't be null. + * @param newPassword The new password. Mustn't be null. */ - public PasswordEditor(Editor viewer, String oldPassword, - String newPassword) + public PasswordEditor(Editor viewer, SecurityContext ctx, + String oldPassword, String newPassword) { - super(viewer); + super(viewer, ctx); if (oldPassword == null) throw new IllegalArgumentException("Password not valid."); if (newPassword == null) @@ -87,7 +88,7 @@ public PasswordEditor(Editor viewer, String oldPassword, */ public void load() { - handle = adminView.changePassword(oldPassword, newPassword, this); + handle = adminView.changePassword(ctx, oldPassword, newPassword, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/PlaneInfoLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/PlaneInfoLoader.java index 47771a6b430..82b3fbfb65f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/PlaneInfoLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/PlaneInfoLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -64,16 +65,16 @@ public class PlaneInfoLoader /** * Creates a new instance. * - * @param viewer The view this loader is for. - * Mustn't be null. + * @param viewer The view this loader is for. Mustn't be null. + * @param ctx The security context. * @param pixelsID The id of pixels set. * @param defaultZ The selected z-section. * @param channel The selected channel. */ - public PlaneInfoLoader(Editor viewer, long pixelsID, int channel, - int defaultZ) + public PlaneInfoLoader(Editor viewer, SecurityContext ctx, long pixelsID, + int channel, int defaultZ) { - super(viewer); + super(viewer, ctx); this.pixelsID = pixelsID; this.channel = channel; this.defaultZ = defaultZ; @@ -82,13 +83,13 @@ public PlaneInfoLoader(Editor viewer, long pixelsID, int channel, /** * Creates a new instance. * - * @param viewer The view this loader is for. - * Mustn't be null. + * @param viewer The view this loader is for. Mustn't be null. + * @param ctx The security context. * @param pixelsID The id of pixels set. */ - public PlaneInfoLoader(Editor viewer, long pixelsID) + public PlaneInfoLoader(Editor viewer, SecurityContext ctx, long pixelsID) { - super(viewer); + super(viewer, ctx); this.pixelsID = pixelsID; this.channel = -1; this.defaultZ = -1; @@ -100,7 +101,8 @@ public PlaneInfoLoader(Editor viewer, long pixelsID) */ public void load() { - handle = imView.loadPlaneInfo(pixelsID, defaultZ, -1, channel, this); + handle = imView.loadPlaneInfo(ctx, pixelsID, defaultZ, -1, channel, + this); } /** @@ -118,6 +120,5 @@ public void handleResult(Object result) //if (viewer.getState() == ImViewer.DISCARDED) return; //Async cancel. viewer.setPlaneInfo((Collection) result, pixelsID, channel); } - - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ROILoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ROILoader.java index b06497bbfc4..d83fe111d6a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ROILoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ROILoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -65,13 +66,15 @@ public class ROILoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param imageID The id of the image the ROIs are related to. * @param userID The id of the user. * @param index The index of the figure to create. */ - public ROILoader(Editor viewer, long imageID, long userID, int index) + public ROILoader(Editor viewer, SecurityContext ctx, long imageID, + long userID, int index) { - super(viewer); + super(viewer, ctx); if (imageID < 0) throw new IllegalArgumentException("No image specified."); this.imageID = imageID; @@ -85,7 +88,7 @@ public ROILoader(Editor viewer, long imageID, long userID, int index) */ public void load() { - handle = imView.loadROIFromServer(imageID, userID, this); + handle = imView.loadROIFromServer(ctx, imageID, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingControlLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingControlLoader.java index 16cd2a76af8..e5b1ec7eb79 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingControlLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingControlLoader.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.agents.metadata.editor.Editor; import org.openmicroscopy.shoola.env.data.FSAccessException; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.ImageDataView; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -96,14 +97,15 @@ private void checkIndex(int value) /** * Creates a new instance * - * @param viewer The view this loader is for. - * Mustn't be null. + * @param viewer The view this loader is for. Mustn't be null. + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param index One of the constants defined by this class. */ - public RenderingControlLoader(Editor viewer, long pixelsID, int index) + public RenderingControlLoader(Editor viewer, SecurityContext ctx, + long pixelsID, int index) { - super(viewer); + super(viewer, ctx); checkIndex(index); this.pixelsID = pixelsID; this.index = index; @@ -115,7 +117,7 @@ public RenderingControlLoader(Editor viewer, long pixelsID, int index) */ public void load() { - handle = imView.loadRenderingControl(pixelsID, index, this); + handle = imView.loadRenderingControl(ctx, pixelsID, index, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingControlShutDown.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingControlShutDown.java index 9ab1e5b5adb..62badfceea5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingControlShutDown.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingControlShutDown.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.ImageDataView; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -59,14 +60,19 @@ public class RenderingControlShutDown /** Handle to the asynchronous call so that we can cancel it. */ private CallHandle handle; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a new instance. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. */ - public RenderingControlShutDown(long pixelsID) + public RenderingControlShutDown(SecurityContext ctx, long pixelsID) { this.pixelsID = pixelsID; + this.ctx = ctx; registry = MetadataViewerAgent.getRegistry(); imView = (ImageDataView) registry.getDataServicesView(ImageDataView.class); @@ -78,7 +84,7 @@ public RenderingControlShutDown(long pixelsID) */ public void load() { - handle = imView.shutDownRenderingControl(pixelsID, this); + handle = imView.shutDownRenderingControl(ctx, pixelsID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingSettingsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingSettingsLoader.java index a1907a43dec..e025b3b8571 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingSettingsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/RenderingSettingsLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -58,13 +59,15 @@ public class RenderingSettingsLoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. * @param pixelsID The identifier of the pixels set. */ - public RenderingSettingsLoader(MetadataViewer viewer, long pixelsID) + public RenderingSettingsLoader(MetadataViewer viewer, SecurityContext ctx, + long pixelsID) { - super(viewer); + super(viewer, ctx); this.pixelsID = pixelsID; } @@ -74,7 +77,7 @@ public RenderingSettingsLoader(MetadataViewer viewer, long pixelsID) */ public void load() { - handle = ivView.getRenderingSettings(pixelsID, this); + handle = ivView.getRenderingSettings(ctx, pixelsID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ScriptLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ScriptLoader.java index f4b515d7cbd..69474d25e99 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ScriptLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ScriptLoader.java @@ -33,6 +33,7 @@ import org.openmicroscopy.shoola.env.data.ProcessException; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -63,12 +64,13 @@ public class ScriptLoader /** * Creates a new instance. * - * @param viewer Reference to the viewer. Mustn't be null. + * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. * @param scriptID The script's identifier. */ - public ScriptLoader(Editor viewer, long scriptID) + public ScriptLoader(Editor viewer, SecurityContext ctx, long scriptID) { - super(viewer); + super(viewer, ctx); if (scriptID < 0) throw new IllegalArgumentException("No script specified."); this.scriptID = scriptID; @@ -80,7 +82,7 @@ public ScriptLoader(Editor viewer, long scriptID) */ public void load() { - handle = mhView.loadScript(scriptID, this); + handle = mhView.loadScript(ctx, scriptID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ScriptsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ScriptsLoader.java index 283e1caaa25..5c9df9739b5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ScriptsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ScriptsLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -63,12 +64,13 @@ public class ScriptsLoader * Creates a new instance. * * @param viewer Reference to the viewer. Mustn't be null. - * @param all Pass true to retrieve all the scripts uploaded - * ones and the default ones, false. + * @param ctx The security context. + * @param all Pass true to retrieve all the scripts uploaded + * ones and the default ones, false. */ - public ScriptsLoader(Editor viewer, boolean all) + public ScriptsLoader(Editor viewer, SecurityContext ctx, boolean all) { - super(viewer); + super(viewer, ctx); this.all = all; } @@ -78,7 +80,7 @@ public ScriptsLoader(Editor viewer, boolean all) */ public void load() { - handle = mhView.loadScripts(-1, all, this); + handle = mhView.loadScripts(ctx, -1, all, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/StructuredDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/StructuredDataLoader.java index 8e826e3aedf..2b655e59e28 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/StructuredDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/StructuredDataLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.browser.TreeBrowserDisplay; import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -60,16 +61,17 @@ public class StructuredDataLoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param node The node of reference. - * @param dataObject The object the data are related to. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param node The node of reference. + * @param dataObject The object the data are related to. + * Mustn't be null. */ - public StructuredDataLoader(MetadataViewer viewer, TreeBrowserDisplay node, - Object dataObject) + public StructuredDataLoader(MetadataViewer viewer, SecurityContext ctx, + TreeBrowserDisplay node, Object dataObject) { - super(viewer, node); + super(viewer, ctx, node); if (dataObject == null) throw new IllegalArgumentException("No object specified."); this.dataObject = dataObject; @@ -81,7 +83,7 @@ public StructuredDataLoader(MetadataViewer viewer, TreeBrowserDisplay node, */ public void load() { - handle = mhView.loadStructuredData(dataObject, -1, this); + handle = mhView.loadStructuredData(ctx, dataObject, -1, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/TabularDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/TabularDataLoader.java index d66219e1d3f..07b97b2de72 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/TabularDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/TabularDataLoader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; import org.openmicroscopy.shoola.env.data.model.TableParameters; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -62,10 +63,13 @@ public class TabularDataLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. + * @param originalID The identifier of the table. */ - public TabularDataLoader(Editor viewer, long originalFileID) + public TabularDataLoader(Editor viewer, SecurityContext ctx, + long originalFileID) { - super(viewer); + super(viewer, ctx); if (originalFileID < 0) throw new IllegalArgumentException("No file to retrieve."); List ids = new ArrayList(); @@ -80,7 +84,7 @@ public TabularDataLoader(Editor viewer, long originalFileID) public void load() { setIds(); - handle = mhView.loadTabularData(parameters, userID, this); + handle = mhView.loadTabularData(ctx, parameters, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/TagsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/TagsLoader.java index ae57d0090b6..8b537eade80 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/TagsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/TagsLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.TagAnnotationData; @@ -60,10 +61,11 @@ public class TagsLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - public TagsLoader(Editor viewer) + public TagsLoader(Editor viewer, SecurityContext ctx) { - super(viewer); + super(viewer, ctx); } /** @@ -73,7 +75,7 @@ public TagsLoader(Editor viewer) public void load() { setIds(); - handle = mhView.loadExistingAnnotations(TagAnnotationData.class, + handle = mhView.loadExistingAnnotations(ctx, TagAnnotationData.class, userID, groupID, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ThumbnailLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ThumbnailLoader.java index 2dd21be2c37..056b5f876c1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ThumbnailLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/ThumbnailLoader.java @@ -36,6 +36,7 @@ import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.model.ThumbnailData; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.util.image.geom.Factory; @@ -75,15 +76,16 @@ public class ThumbnailLoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. * @param image The image. * @param userIDs The node of reference. Mustn't be null. */ - public ThumbnailLoader(MetadataViewer viewer, ImageData image, - Set userIDs) + public ThumbnailLoader(MetadataViewer viewer, SecurityContext ctx, + ImageData image, Set userIDs) { - super(viewer); + super(viewer, ctx); this.image = image; this.userIDs = userIDs; thumbnails = new HashMap(); @@ -95,8 +97,8 @@ public ThumbnailLoader(MetadataViewer viewer, ImageData image, */ public void load() { - handle = mhView.loadThumbnails(image, userIDs, - Factory.THUMB_DEFAULT_WIDTH, Factory.THUMB_DEFAULT_HEIGHT, + handle = mhView.loadThumbnails(ctx, image, userIDs, + Factory.THUMB_DEFAULT_WIDTH, Factory.THUMB_DEFAULT_HEIGHT, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/UserPhotoLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/UserPhotoLoader.java index 118407cddcb..69fa6941e93 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/UserPhotoLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/UserPhotoLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; @@ -59,13 +60,15 @@ public class UserPhotoLoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param experimenter The experimenter to handle. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param experimenter The experimenter to handle. */ - public UserPhotoLoader(Editor viewer, ExperimenterData experimenter) + public UserPhotoLoader(Editor viewer, SecurityContext ctx, + ExperimenterData experimenter) { - super(viewer); + super(viewer, ctx); if (experimenter == null) throw new IllegalArgumentException("No experimenter specified."); this.experimenter = experimenter; @@ -83,7 +86,7 @@ public void handleNullResult() {} */ public void load() { - handle = adminView.loadExperimenterPhoto(experimenter, this); + handle = adminView.loadExperimenterPhoto(ctx, experimenter, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/UserPhotoUploader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/UserPhotoUploader.java index 931eceae4e4..231b243b115 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/UserPhotoUploader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/UserPhotoUploader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.metadata.editor.Editor; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; @@ -53,29 +54,30 @@ public class UserPhotoUploader { /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** The experimenter to handle. */ private ExperimenterData experimenter; /** The photo to upload. */ - private File photo; + private File photo; /** The format of the photo to upload. */ - private String format; + private String format; /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. * @param experimenter The experimenter to handle. - * @param photo The photo to upload. + * @param photo The photo to upload. */ - public UserPhotoUploader(Editor viewer, ExperimenterData experimenter, - File photo, String format) + public UserPhotoUploader(Editor viewer, SecurityContext ctx, + ExperimenterData experimenter, File photo, String format) { - super(viewer); + super(viewer, ctx); if (experimenter == null) throw new IllegalArgumentException("No experimenter specified."); if (photo == null) @@ -91,7 +93,7 @@ public UserPhotoUploader(Editor viewer, ExperimenterData experimenter, */ public void load() { - handle = adminView.uploadExperimenterPhoto(experimenter, photo, + handle = adminView.uploadExperimenterPhoto(ctx, experimenter, photo, format, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/actions/ViewAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/actions/ViewAction.java index 663b0aff916..6d3dacb8da8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/actions/ViewAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/actions/ViewAction.java @@ -31,14 +31,9 @@ //Third-party libraries //Application-internal dependencies -import org.openmicroscopy.shoola.agents.events.iviewer.ViewImage; -import org.openmicroscopy.shoola.agents.events.iviewer.ViewImageObject; import org.openmicroscopy.shoola.agents.metadata.IconManager; -import org.openmicroscopy.shoola.agents.metadata.MetadataViewerAgent; import org.openmicroscopy.shoola.agents.metadata.rnd.Renderer; -import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.util.ui.UIUtilities; -import pojos.ImageData; /** * Opens the viewer. @@ -58,7 +53,7 @@ public class ViewAction { /** The description of the action. */ - private static final String DESCRIPTION = "Launch the viewer."; + private static final String DESCRIPTION = "Open the viewer."; /** * Creates a new instance. @@ -81,10 +76,7 @@ public ViewAction(Renderer model) */ public void actionPerformed(ActionEvent e) { - ImageData image = model.getRefImage(); - if (image == null) return; - EventBus bus = MetadataViewerAgent.getRegistry().getEventBus(); - bus.post(new ViewImage(new ViewImageObject(image), null)); + model.viewImage(); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/AnnotationDataUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/AnnotationDataUI.java index bd5d46e2704..fa5cec6d763 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/AnnotationDataUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/AnnotationDataUI.java @@ -905,27 +905,47 @@ protected void buildUI() count += v.size(); } */ - count += l.size(); - layoutAttachments(l); + + //Viewed by if (!model.isMultiSelection()) { l = model.getTags(); if (l != null) count += l.size(); layoutTags(l); + l = model.getAttachments(); + if (l != null) count += l.size(); + layoutAttachments(l); + } else { + layoutTags(null); + layoutAttachments(null); } filterButton.setEnabled(count > 0); //Allow to handle annotation. boolean enabled = model.isWritable(); + if (enabled && model.isMultiSelection()) { + enabled = !model.isAcrossGroups(); + } rating.setEnabled(enabled); addTagsButton.setEnabled(enabled); addDocsButton.setEnabled(enabled); - unrateButton.setEnabled(enabled); removeTagsButton.setEnabled(enabled); removeDocsButton.setEnabled(enabled); + unrateButton.setEnabled(enabled); buildGUI(); } + /** Updates the UI when the related nodes have been set.*/ + void onRelatedNodesSet() + { + if (!addTagsButton.isEnabled()) return; + boolean b = model.isAnnotationAllowed(); + addTagsButton.setEnabled(b); + addDocsButton.setEnabled(b); + removeTagsButton.setEnabled(b); + removeDocsButton.setEnabled(b); + } + /** * Returns true if the passed value corresponds to * a name space for Editor. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/DocComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/DocComponent.java index 8a041b056bb..edbe330e535 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/DocComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/DocComponent.java @@ -255,7 +255,8 @@ private void openFile() { if (!(data instanceof FileAnnotationData)) return; EventBus bus = MetadataViewerAgent.getRegistry().getEventBus(); - bus.post(new EditFileEvent((FileAnnotationData) data)); + bus.post(new EditFileEvent(model.getSecurityContext(), + (FileAnnotationData) data)); } /** @@ -417,7 +418,8 @@ private void postFileClicked() if (data instanceof FileAnnotationData) { FileAnnotationData f = (FileAnnotationData) data; Registry reg = MetadataViewerAgent.getRegistry(); - reg.getEventBus().post(new EditFileEvent(f)); + reg.getEventBus().post(new EditFileEvent(model.getSecurityContext(), + f)); } } @@ -456,8 +458,7 @@ private void initButtons() public void mousePressed(MouseEvent e) { - Point p = e.getPoint(); - showMenu(menuButton, p); + showMenu(menuButton, e.getPoint()); } }); infoButton = new JMenuItem(icons.getIcon(IconManager.INFO)); @@ -466,8 +467,7 @@ public void mousePressed(MouseEvent e) public void mousePressed(MouseEvent e) { - Point p = e.getPoint(); - displayInformation(label, p); + displayInformation(label, e.getPoint()); } }); unlinkButton = new JMenuItem(icons.getIcon(IconManager.MINUS_12)); @@ -653,6 +653,8 @@ private void buildGUI() if (openButton != null) count++; if (deleteButton != null) count++; if (count > 0) { + menuButton.setEnabled(true); + if (model.isAcrossGroups()) menuButton.setEnabled(false); bar.add(menuButton); if (!b) bar.add(Box.createHorizontalStrut(8)); add(bar); @@ -881,7 +883,7 @@ public void propertyChange(PropertyChangeEvent evt) folder, icons.getIcon(IconManager.DOWNLOAD_22)); //Check Name space activity.setLegend(fa.getDescription()); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); //un.notifyDownload((FileAnnotationData) data, folder); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/Editor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/Editor.java index 5f7400d4408..02534a931d5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/Editor.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/Editor.java @@ -40,6 +40,7 @@ import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.model.DiskQuota; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.util.ui.component.ObservableComponent; import pojos.AnnotationData; @@ -464,4 +465,11 @@ public void setLoadedFile(FileAnnotationData data, File file, * otherwise. */ void onGroupSwitched(boolean success); + + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext(); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorComponent.java index c3f88a71463..5c799600170 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorComponent.java @@ -59,6 +59,7 @@ import org.openmicroscopy.shoola.env.data.model.ExportActivityParam; import org.openmicroscopy.shoola.env.data.model.ROIResult; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.env.ui.UserNotifier; import org.openmicroscopy.shoola.util.ui.MessageBox; @@ -715,7 +716,7 @@ else if (refObject instanceof WellSampleData) { IconManager icons = IconManager.getInstance(); param.setIcon(icons.getIcon(IconManager.EXPORT_22)); UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier(); - un.notifyActivity(param); + un.notifyActivity(model.getSecurityContext(), param); } /** @@ -1052,4 +1053,13 @@ public void onGroupSwitched(boolean success) } } + /** + * Implemented as specified by the {@link Editor} interface. + * @see Editor#getSecurityContext() + */ + public SecurityContext getSecurityContext() + { + return model.getSecurityContext(); + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorControl.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorControl.java index ab1cd7817ec..c58c65236f6 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorControl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorControl.java @@ -267,7 +267,8 @@ private void selectFileToAttach() private void viewImage(long imageID) { EventBus bus = MetadataViewerAgent.getRegistry().getEventBus(); - bus.post(new ViewImage(new ViewImageObject(imageID), null)); + bus.post(new ViewImage(model.getSecurityContext(), + new ViewImageObject(imageID), null)); } /** @@ -289,7 +290,7 @@ private void viewImage(String imageName) private void viewProtocol(long protocolID) { EventBus bus = MetadataViewerAgent.getRegistry().getEventBus(); - bus.post(new EditFileEvent(protocolID)); + bus.post(new EditFileEvent(model.getSecurityContext(), protocolID)); } /** Brings up the folder chooser. */ @@ -583,9 +584,11 @@ else if (data instanceof TagAnnotationData) figureDialog = null; } else if (MetadataViewer.CLOSE_RENDERER_PROPERTY.equals(name)) { view.discardRenderer(evt.getNewValue()); + } else if (MetadataViewer.RELATED_NODES_PROPERTY.equals(name)) { + view.onRelatedNodesSet(); } else if (ScriptingDialog.RUN_SELECTED_SCRIPT_PROPERTY.equals(name)) { - view.manageScript((ScriptObject) evt.getNewValue(), - MetadataViewer.RUN); + //view.manageScript((ScriptObject) evt.getNewValue(), + // MetadataViewer.RUN); } else if (ScriptingDialog.DOWNLOAD_SELECTED_SCRIPT_PROPERTY.equals( name)) { Object value = evt.getNewValue(); @@ -746,7 +749,7 @@ public void actionPerformed(ActionEvent e) if (img != null) { ViewImageObject vio = new ViewImageObject(img); EditorAgent.getRegistry().getEventBus().post( - new ViewImage(vio, null)); + new ViewImage(model.getSecurityContext(), vio, null)); } } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java index fa4c82c65bf..69e80270ca2 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java @@ -77,7 +77,6 @@ import org.openmicroscopy.shoola.env.Environment; import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.data.AdminService; -import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.env.data.model.DeletableObject; @@ -87,8 +86,8 @@ import org.openmicroscopy.shoola.env.data.model.EnumerationObject; import org.openmicroscopy.shoola.env.data.model.SaveAsParam; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StructuredDataResults; -import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.env.ui.UserNotifier; import org.openmicroscopy.shoola.util.ui.component.ObservableComponent; @@ -240,7 +239,7 @@ private void downloadFiles(File folder) DownloadActivityParam activity = new DownloadActivityParam(f, folder, icons.getIcon(IconManager.DOWNLOAD_22)); - un.notifyActivity(activity); + un.notifyActivity(getSecurityContext(), activity); Collection l = parent.getRelatedNodes(); if (l == null) return; @@ -266,7 +265,7 @@ private void downloadFiles(File folder) icons.getIcon(IconManager.DOWNLOAD_22)); } activity.setFileName(fa.getFileName()); - un.notifyActivity(activity); + un.notifyActivity(getSecurityContext(), activity); } } } @@ -308,7 +307,7 @@ private void downloadImages(File folder) img = i.next(); p = new DownloadArchivedActivityParam(path, img, icons.getIcon(IconManager.DOWNLOAD_22)); - un.notifyActivity(p); + un.notifyActivity(getSecurityContext(), p); } } } @@ -401,7 +400,8 @@ private void fireExperimenterPhotoLoading() if (refObject instanceof ExperimenterData) { ExperimenterData exp = (ExperimenterData) refObject; if (usersPhoto == null || !usersPhoto.containsKey(exp.getId())) { - UserPhotoLoader loader = new UserPhotoLoader(component, exp); + UserPhotoLoader loader = new UserPhotoLoader(component, + parent.getSecurityContext(), exp); loader.load(); } } @@ -649,6 +649,55 @@ boolean isWritable() return false; } + /** + * Returns true if the selected objects belong to several + * groups, false otherwise. + * + * @return See above. + */ + boolean isAcrossGroups() + { + List l = getSelectedObjects(); + if (l == null || l.size() == 0) return false; + List ids = new ArrayList(); + Iterator i = l.iterator(); + DataObject data; + while (i.hasNext()) { + data = i.next(); + if (!ids.contains(data.getGroupId())) + ids.add(data.getGroupId()); + } + return ids.size() > 1; + } + + /** + * Returns true if the annotation can be added, should + * only be invoked for tagging or adding attachments, false + * otherwise. + * + * @return See above. + */ + boolean isAnnotationAllowed() + { + if (!isWritable()) return false; + if (!isMultiSelection()) return true; + //multi selection. + List l = parent.getRelatedNodes(); + if (l == null) return false; + Iterator i = l.iterator(); + DataObject data; + List ids = new ArrayList(); + while (i.hasNext()) { + data = (DataObject) i.next(); + if (!(data instanceof GroupData || + data instanceof ExperimenterData)) { + if (!ids.contains(data.getGroupId())) + ids.add(data.getGroupId()); + } + } + return ids.size() <= 1; + } + /** * Returns true if the group's name is valid, * false otherwise. @@ -1507,7 +1556,8 @@ void loadExistingTags() } } if (exist) return; - TagsLoader loader = new TagsLoader(component); + TagsLoader loader = new TagsLoader(component, + parent.getSecurityContext()); loader.load(); loaders.add(loader); } @@ -1529,7 +1579,8 @@ void loadExistingAttachments() } } if (exist) return; - AttachmentsLoader loader = new AttachmentsLoader(component); + AttachmentsLoader loader = new AttachmentsLoader(component, + parent.getSecurityContext()); loader.load(); loaders.add(loader); } @@ -1565,6 +1616,7 @@ else if (refObject instanceof WellSampleData) { try { PixelsData pixs = data.getDefaultPixels(); ChannelDataLoader loader = new ChannelDataLoader(component, + parent.getSecurityContext(), pixs.getId(), parent.getUserID()); loader.load(); loaders.add(loader); @@ -1795,7 +1847,8 @@ void download(File folder) */ void loadDiskSpace(Class type, long id) { - DiskSpaceLoader loader = new DiskSpaceLoader(component, type, id); + DiskSpaceLoader loader = new DiskSpaceLoader(component, + parent.getSecurityContext(), type, id); loader.load(); loaders.add(loader); } @@ -1819,12 +1872,13 @@ void cancelDiskSpaceLoading() /** * Fires an asynchronous call to modify the password. * - * @param old The old password. - * @param confirm The new password. + * @param old The old password. + * @param confirm The new password. */ void changePassword(String old, String confirm) { - EditorLoader loader = new PasswordEditor(component, old, confirm); + EditorLoader loader = new PasswordEditor(component, + parent.getSecurityContext(), old, confirm); loader.load(); loaders.add(loader); } @@ -1884,7 +1938,7 @@ boolean hasBeenViewedBy() void fireImageEnumerationsLoading() { EnumerationLoader loader = new EnumerationLoader(component, - EnumerationLoader.IMAGE); + parent.getSecurityContext(), EnumerationLoader.IMAGE); loader.load(); } @@ -1892,7 +1946,7 @@ void fireImageEnumerationsLoading() void fireChannelEnumerationsLoading() { EnumerationLoader loader = new EnumerationLoader(component, - EnumerationLoader.CHANNEL); + parent.getSecurityContext(), EnumerationLoader.CHANNEL); loader.load(); } @@ -1908,7 +1962,8 @@ void fireImagAcquisitionDataLoading() } if (data == null) return; AcquisitionDataLoader - loader = new AcquisitionDataLoader(component, data); + loader = new AcquisitionDataLoader(component, + parent.getSecurityContext(), data); loader.load(); } @@ -1920,7 +1975,8 @@ void fireImagAcquisitionDataLoading() void fireChannelAcquisitionDataLoading(ChannelData channel) { AcquisitionDataLoader - loader = new AcquisitionDataLoader(component, channel); + loader = new AcquisitionDataLoader(component, + parent.getSecurityContext(), channel); loader.load(); } @@ -1932,7 +1988,7 @@ void fireChannelAcquisitionDataLoading(ChannelData channel) void fireInstrumentDataLoading(long instrumentID) { InstrumentDataLoader loader = new InstrumentDataLoader(component, - instrumentID); + parent.getSecurityContext(), instrumentID); loader.load(); } @@ -1957,7 +2013,7 @@ ImageAcquisitionData getImageAcquisitionData() } /** - * Sets the acquisition data for the specifed channel. + * Sets the acquisition data for the specified channel. * * @param index The index of the channel. * @param data The value to set. @@ -2184,7 +2240,8 @@ void firePlaneInfoLoading(int channel, int z) if (!(ref instanceof ImageData)) return; ImageData img = (ImageData) ref; PlaneInfoLoader loader = new PlaneInfoLoader(component, - img.getDefaultPixels().getId(), channel, z); + parent.getSecurityContext(), img.getDefaultPixels().getId(), + channel, z); loader.load(); } @@ -2231,7 +2288,7 @@ boolean fireRenderingControlLoading(long pixelsID, int index) if (isRendererLoaded() && index == RenderingControlLoader.LOAD) return false; RenderingControlLoader loader = new RenderingControlLoader(component, - pixelsID, index); + parent.getSecurityContext(), pixelsID, index); loader.load(); return true; } @@ -2246,8 +2303,8 @@ void setRenderingControl(RenderingControl rndControl) if (renderer != null) { renderer.onSettingsApplied(rndControl); } else { - renderer = RendererFactory.createRenderer(rndControl, getImage(), - getRndIndex()); + renderer = RendererFactory.createRenderer(getSecurityContext(), + rndControl, getImage(), getRndIndex()); } } @@ -2286,7 +2343,8 @@ boolean hasBeenPublished() */ void loadFile(FileAnnotationData data, Object uiView) { - FileLoader loader = new FileLoader(component, data, uiView); + FileLoader loader = new FileLoader(component, + parent.getSecurityContext(), data, uiView); loader.load(); } @@ -2298,7 +2356,8 @@ void loadFile(FileAnnotationData data, Object uiView) void loadFiles(Map files) { if (!MetadataViewerAgent.isBinaryAvailable()) return; - FileLoader loader = new FileLoader(component, files); + FileLoader loader = new FileLoader(component, + parent.getSecurityContext(), files); loader.load(); } @@ -2488,7 +2547,8 @@ void fireROILoading(int index) ImageData img = getImage(); if (img == null) return; long userID = MetadataViewerAgent.getUserDetails().getId(); - ROILoader loader = new ROILoader(component, img.getId(), userID, index); + ROILoader loader = new ROILoader(component, parent.getSecurityContext(), + img.getId(), userID, index); loader.load(); } @@ -2543,7 +2603,8 @@ Collection getScripts() */ void loadScript(long scriptID) { - ScriptLoader loader = new ScriptLoader(component, scriptID); + ScriptLoader loader = new ScriptLoader(component, + parent.getSecurityContext(), scriptID); loader.load(); loaders.add(loader); } @@ -2574,7 +2635,8 @@ ScriptObject getScript(long scriptID) /** Loads the scripts. */ void loadScripts() { - ScriptsLoader loader = new ScriptsLoader(component, false); + ScriptsLoader loader = new ScriptsLoader(component, + parent.getSecurityContext(), false); loader.load(); loaders.add(loader); } @@ -2635,8 +2697,8 @@ void uploadPicture(File photo, String format) if (refObject instanceof ExperimenterData) { //ExperimenterData exp = (ExperimenterData) refObject; ExperimenterData exp = MetadataViewerAgent.getUserDetails(); - UserPhotoUploader loader = new UserPhotoUploader(component, exp, - photo, format); + UserPhotoUploader loader = new UserPhotoUploader(component, + parent.getSecurityContext(), exp, photo, format); loader.load(); } } @@ -2650,7 +2712,9 @@ void deletePicture() if (usersPhoto != null) usersPhoto.remove(exp.getId()); OmeroMetadataService svc = MetadataViewerAgent.getRegistry().getMetadataService(); - Collection photos = svc.loadAnnotations(FileAnnotationData.class, + Collection photos = svc.loadAnnotations( + parent.getSecurityContext(), + FileAnnotationData.class, FileAnnotationData.EXPERIMENTER_PHOTO_NS, exp.getId(), -1); if (photos == null || photos.size() == 0) return; @@ -2665,7 +2729,7 @@ void deletePicture() p.setFailureIcon(icons.getIcon(IconManager.DELETE_22)); UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); - un.notifyActivity(p); + un.notifyActivity(getSecurityContext(), p); } catch (Exception e) { // TODO: handle exception } @@ -2685,6 +2749,7 @@ void uploadScript() */ private List getScriptsWithUI() { + /* if (scriptsWithUI != null) return scriptsWithUI; try { OmeroImageService svc = @@ -2697,6 +2762,7 @@ private List getScriptsWithUI() msg.print(e); MetadataViewerAgent.getRegistry().getLogger().error(this, msg); } + */ return new ArrayList(); } @@ -2726,6 +2792,7 @@ ScriptObject getScriptFromName(String name) */ GroupData loadGroup(long groupID) { + /* try { AdminService svc = MetadataViewerAgent.getRegistry().getAdminService(); @@ -2739,6 +2806,7 @@ GroupData loadGroup(long groupID) } catch (Exception e) { //ignore } + */ return null; } @@ -2752,7 +2820,7 @@ void loadAnalysisResults(AnalysisResultsItem analysis) if (resultsLoader == null) resultsLoader = new HashMap(); AnalysisResultsFileLoader loader = new AnalysisResultsFileLoader( - component, analysis); + component, parent.getSecurityContext(), analysis); resultsLoader.put(analysis, loader); loader.load(); } @@ -2856,7 +2924,7 @@ void saveAs(File folder) p.setIcon(icons.getIcon(IconManager.SAVE_AS_22)); UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier(); - un.notifyActivity(p); + un.notifyActivity(getSecurityContext(), p); } } @@ -2903,7 +2971,7 @@ boolean isLargeImage() PixelsData data = img.getDefaultPixels(); b = MetadataViewerAgent.getRegistry().getImageService().isLargeImage( - data.getId()); + parent.getSecurityContext(), data.getId()); } catch (Exception e) {} if (b != null) return b.booleanValue(); return false; @@ -2941,4 +3009,32 @@ BufferedImage getUserPhoto(long expId) return usersPhoto.get(expId); } + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext() { return parent.getSecurityContext(); } + + /** + * Returns true if the name of the group already exists, + * false otherwise. + * + * @param data The group to handle. + * @param name The name to check. + * @return + */ + boolean doesGroupExist(GroupData data, String name) + { + if (data == null) return false; + AdminService svc = MetadataViewerAgent.getRegistry().getAdminService(); + try { + GroupData g = svc.lookupGroup(getSecurityContext(), name); + if (g != null && data.getId() != g.getId()) { + return true; + } + } catch (Exception e) {} + return false; + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorUI.java index 619e6bb4dd7..b5ed1c0a23d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/EditorUI.java @@ -465,6 +465,7 @@ boolean hasDataToSave() return userUI.hasDataToSave(); else if (ref instanceof GroupData) return groupUI.hasDataToSave(); + boolean b = generalPane.hasDataToSave(); if (b) return b; //Check metadata. @@ -476,6 +477,7 @@ void clearData() { saved = false; userUI.clearData(); + groupUI.clearData(); generalPane.clearData(); tabPane.setComponentAt(RND_INDEX, dummyPanel); tabPane.repaint(); @@ -700,7 +702,8 @@ void createNewExperiment() if (name != null && name.trim().length() > 0) { name += ShowEditorEvent.EXPERIMENT_EXTENSION; ShowEditorEvent event = new ShowEditorEvent( - (DataObject) object, name, + model.getSecurityContext(), + (DataObject) object, name, ShowEditorEvent.EXPERIMENT); bus.post(event); } @@ -929,5 +932,11 @@ boolean checkIfTabEnabled(int index) tabPane.setSelectedIndex(GENERAL_INDEX); return false; } - + + /** Updates the UI when the related nodes have been set.*/ + void onRelatedNodesSet() + { + generalPane.onRelatedNodesSet(); + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/GeneralPaneUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/GeneralPaneUI.java index 402dc79688e..89e87e0c170 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/GeneralPaneUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/GeneralPaneUI.java @@ -588,4 +588,10 @@ void handleObjectsSelection(Class type, Collection objects) annotationUI.handleObjectsSelection(type, objects, true); } + /** Updates the UI when the related nodes have been set.*/ + void onRelatedNodesSet() + { + annotationUI.onRelatedNodesSet(); + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/GroupProfile.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/GroupProfile.java index d6281dd10d3..48f60d9587c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/GroupProfile.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/GroupProfile.java @@ -51,7 +51,6 @@ import org.openmicroscopy.shoola.agents.metadata.MetadataViewerAgent; import org.openmicroscopy.shoola.agents.util.EditorUtil; import org.openmicroscopy.shoola.agents.util.ui.PermissionsPane; -import org.openmicroscopy.shoola.env.data.AdminService; import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.env.ui.UserNotifier; import org.openmicroscopy.shoola.util.ui.UIUtilities; @@ -78,55 +77,63 @@ class GroupProfile { /** The name of the Group. */ - private JTextField namePane; + private JTextField namePane; /** The description of the Group. */ - private JTextField descriptionPane; + private JTextField descriptionPane; /** Component displaying the permissions status. */ - private PermissionsPane permissionsPane; + private PermissionsPane permissionsPane; /** The original permissions level. */ - private int level; + private int level; + + /** Flag indicating if the name can be edited or not.*/ + private boolean canEdit; + + /** The group object displayed.*/ + private GroupData ref; /** Initializes the components composing this display. */ private void initComponents() { - GroupData data = (GroupData) model.getRefObject(); - + ref = (GroupData) model.getRefObject(); + namePane = new JTextField(); + descriptionPane = new JTextField(); //permission level - permissionsPane = new PermissionsPane(data.getPermissions(), + permissionsPane = new PermissionsPane(ref.getPermissions(), UIUtilities.BACKGROUND_COLOR); level = permissionsPane.getPermissions(); permissionsPane.setBorder( BorderFactory.createTitledBorder("Permissions")); permissionsPane.displayWarningText(); permissionsPane.addPropertyChangeListener(this); - namePane = new JTextField(); - - namePane.setText(data.getName()); - descriptionPane = new JTextField(); - descriptionPane.setText(data.getDescription()); + namePane.setText(ref.getName()); + descriptionPane.setText(ref.getDescription()); GroupData group = (GroupData) model.getRefObject(); ExperimenterData exp = MetadataViewerAgent.getUserDetails(); Set l = group.getLeaders(); ExperimenterData leader; - boolean edit = false; + canEdit = false; if (l != null) { Iterator i = l.iterator(); while (i.hasNext()) { leader = (ExperimenterData) i.next(); if (leader.getId() == exp.getId()) { - edit = true; + canEdit = true; break; } } } - if (!edit) edit = MetadataViewerAgent.isAdministrator(); - namePane.setEditable(edit); - if (edit) namePane.getDocument().addDocumentListener(this); - descriptionPane.getDocument().addDocumentListener(this); + if (!canEdit) canEdit = MetadataViewerAgent.isAdministrator(); + namePane.setEditable(canEdit); + descriptionPane.setEditable(canEdit); + permissionsPane.setEnabled(canEdit); + if (canEdit) { + namePane.getDocument().addDocumentListener(this); + descriptionPane.getDocument().addDocumentListener(this); + } } /** @@ -215,7 +222,7 @@ private JPanel buildOwnersPane() * Creates a new instance. * * @param model Reference to the model. Mustn't be null. - * @param view Reference to the control. Mustn't be null. + * @param view Reference to the control. Mustn't be null. */ GroupProfile(EditorModel model) { @@ -230,23 +237,18 @@ private JPanel buildOwnersPane() */ AdminObject getAdminObject() { + if (!canEdit) return null; GroupData data = (GroupData) model.getRefObject(); String v = namePane.getText(); v = v.trim(); if (!data.getName().equals(v)) { - AdminService svc = - MetadataViewerAgent.getRegistry().getAdminService(); - try { - GroupData g = svc.lookupGroup(v); - if (g != null && data.getId() != g.getId()) { - UserNotifier un = + if (model.doesGroupExist(data, v)) { + UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier(); un.notifyInfo("Update Group", "A group with the " + "same name already exists."); return null; - } - } catch (Exception e) {} - + } data.setName(v); } //check description @@ -303,7 +305,9 @@ protected void clearData() * @see AnnotationUI#clearDisplay() */ protected void clearDisplay() - { + { + if (namePane != null) namePane.setText(""); + if (descriptionPane != null) descriptionPane.setText(""); revalidate(); repaint(); } @@ -339,17 +343,16 @@ protected List getAnnotationToSave() */ protected boolean hasDataToSave() { - GroupData data = (GroupData) model.getRefObject(); if (namePane == null) return false; String v = namePane.getText(); v = v.trim(); - if (!data.getName().equals(v)) return true; + if (!ref.getName().equals(v)) return true; //check description v = descriptionPane.getText(); v = v.trim(); - String description = data.getDescription(); + String description = ref.getDescription(); if (description == null) description = ""; - if (!description.equals(v)) return true; + if (!description.equals(v)) return true; return level != permissionsPane.getPermissions(); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/OriginalMetadataComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/OriginalMetadataComponent.java index 3d384ed3043..6760b447467 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/OriginalMetadataComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/OriginalMetadataComponent.java @@ -408,7 +408,7 @@ public void propertyChange(PropertyChangeEvent evt) DownloadActivityParam activity = new DownloadActivityParam(f, folder, icons.getIcon(IconManager.DOWNLOAD_22)); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); //un.notifyDownload(model.getOriginalMetadata(), folder); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/PropertiesUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/PropertiesUI.java index b9c9b6b973c..7cbd4d3e707 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/PropertiesUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/PropertiesUI.java @@ -1443,10 +1443,12 @@ public void propertyChange(PropertyChangeEvent evt) switch (object.getIndex()) { case WikiDataObject.IMAGE: if (id > 0) - bus.post(new ViewImage(new ViewImageObject(id), null)); + bus.post(new ViewImage(model.getSecurityContext(), + new ViewImageObject(id), null)); break; case WikiDataObject.PROTOCOL: - bus.post(new EditFileEvent(id)); + bus.post(new EditFileEvent(model.getSecurityContext(), + id)); break; } } else if (OMEWikiComponent.WIKI_DATA_OBJECT_ONE_CLICK_PROPERTY.equals( diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/TextualAnnotationsUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/TextualAnnotationsUI.java index cb2f85da107..9c2705695d1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/TextualAnnotationsUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/TextualAnnotationsUI.java @@ -354,7 +354,11 @@ private void displayAnnotations(List list) setAreaText(DEFAULT_TEXT_COMMENT, true); } - commentArea.setEnabled(model.isWritable()); + boolean enabled = model.isWritable(); + if (enabled && model.isMultiSelection()) { + enabled = !model.isAcrossGroups(); + } + commentArea.setEnabled(enabled); if (hasPrevious) { TextualAnnotationData data = (TextualAnnotationData) list.get(0); String text = data.getText(); @@ -438,7 +442,11 @@ protected void buildUI() buildGUI(); init = true; //} - displayAnnotations(model.getTextualAnnotationsByDate()); + if (model.isMultiSelection()) { + displayAnnotations(null); + } else { + displayAnnotations(model.getTextualAnnotationsByDate()); + } revalidate(); repaint(); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/UserProfile.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/UserProfile.java index 61add7510de..e834ed66b4b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/UserProfile.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/editor/UserProfile.java @@ -570,7 +570,9 @@ private void uploadPicture() */ private boolean setGroupOwner(GroupData group) { - ExperimenterData ref = (ExperimenterData) model.getRefObject(); + Object refObject = model.getRefObject(); + if (!(refObject instanceof ExperimenterData)) return false; + ExperimenterData ref = (ExperimenterData) refObject; long userID = MetadataViewerAgent.getUserDetails().getId(); Set leaders = group.getLeaders(); ExperimenterData exp; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/Renderer.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/Renderer.java index 2d0e41e86ac..95171bd9856 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/Renderer.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/Renderer.java @@ -688,5 +688,8 @@ BufferedImage createSingleChannelImage(boolean color, int channel, * @return See above. */ boolean isBigImage(); - + + /** Posts an event to view the image.*/ + void viewImage(); + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererComponent.java index b00dfd2bec7..008a6999b0c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererComponent.java @@ -44,9 +44,13 @@ //Application-internal dependencies import omero.romio.PlaneDef; + +import org.openmicroscopy.shoola.agents.events.iviewer.ViewImage; +import org.openmicroscopy.shoola.agents.events.iviewer.ViewImageObject; import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer; import org.openmicroscopy.shoola.agents.metadata.MetadataViewerAgent; import org.openmicroscopy.shoola.env.data.DSOutOfServiceException; +import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.env.log.Logger; import org.openmicroscopy.shoola.env.rnd.RenderingControl; @@ -1153,12 +1157,23 @@ public void setSelectedResolutionLevel(int level) } } - /** - * Returns true if it is a large image, - * false otherwise. - * - * @return See above. + /** + * Implemented as specified by the {@link ImViewer} interface. + * @see Renderer#isBigImage() */ public boolean isBigImage() { return model.isBigImage(); } + /** + * Implemented as specified by the {@link ImViewer} interface. + * @see Renderer#viewImage() + */ + public void viewImage() + { + ImageData image = model.getRefImage(); + if (image == null) return; + EventBus bus = MetadataViewerAgent.getRegistry().getEventBus(); + bus.post(new ViewImage(model.getSecurityContext(), + new ViewImageObject(image), null)); + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererFactory.java index 0221d40700f..82fa315c81a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererFactory.java @@ -28,6 +28,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import pojos.ImageData; @@ -58,10 +59,11 @@ public class RendererFactory * @param rndIndex The index of the renderer. * @return See above. */ - public static Renderer createRenderer(RenderingControl rndControl, + public static Renderer createRenderer(SecurityContext ctx, + RenderingControl rndControl, ImageData image, int rndIndex) { - RendererModel model = new RendererModel(rndControl, rndIndex); + RendererModel model = new RendererModel(ctx, rndControl, rndIndex); model.setImage(image); RendererComponent rnd = new RendererComponent(model); rnd.initialize(); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererModel.java index 6e4124c0316..2f10c5c9a73 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/rnd/RendererModel.java @@ -38,12 +38,12 @@ //Application-internal dependencies import omero.romio.PlaneDef; -import org.openmicroscopy.shoola.agents.metadata.MetadataViewerAgent; import org.openmicroscopy.shoola.agents.metadata.RenderingControlShutDown; import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; import org.openmicroscopy.shoola.agents.util.ViewerSorter; import org.openmicroscopy.shoola.env.data.DSOutOfServiceException; import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.env.rnd.RenderingServiceException; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; @@ -162,18 +162,24 @@ class RendererModel /** Reference to the image. */ private ImageData image; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a new instance. * + * @param ctx The security context. * @param rndControl Reference to the component that controls the * rendering settings. Mustn't be null. * @param rndIndex The index associated to the renderer. */ - RendererModel(RenderingControl rndControl, int rndIndex) + RendererModel(SecurityContext ctx, RenderingControl rndControl, + int rndIndex) { if (rndControl == null) throw new NullPointerException("No rendering control."); setRenderingControl(rndControl); + this.ctx = ctx; this.rndIndex = rndIndex; visible = false; globalMaxChannels = null; @@ -182,6 +188,13 @@ class RendererModel plane.slice = omero.romio.XY.value; } + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext() { return ctx; } + /** * Sets the image the component is for. * @@ -270,7 +283,7 @@ void discard() { if (rndControl == null) return; RenderingControlShutDown loader = - new RenderingControlShutDown(rndControl.getPixelsID()); + new RenderingControlShutDown(ctx, rndControl.getPixelsID()); loader.load(); rndControl = null; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/util/AnalysisResultsItem.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/util/AnalysisResultsItem.java index 61162c1236d..daad8cd8d74 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/util/AnalysisResultsItem.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/util/AnalysisResultsItem.java @@ -441,7 +441,8 @@ public void propertyChange(PropertyChangeEvent evt) IconManager icons = IconManager.getInstance(); DownloadAndZipParam param = new DownloadAndZipParam(attachments, folder, icons.getIcon(IconManager.DOWNLOAD_22)); - un.notifyActivity(param); + //TODO: review + //un.notifyActivity(param); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewer.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewer.java index 2ac72ff161e..69ef3a4134d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewer.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewer.java @@ -43,6 +43,7 @@ import org.openmicroscopy.shoola.agents.metadata.editor.Editor; import org.openmicroscopy.shoola.agents.metadata.rnd.Renderer; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StructuredDataResults; import org.openmicroscopy.shoola.util.ui.component.ObservableComponent; import pojos.AnnotationData; @@ -171,6 +172,11 @@ public interface MetadataViewer /** Bound property indicating to reset password. */ public static final String RESET_PASSWORD_PROPERTY = "resetPassword"; + /** + * Bound property indicating the related nodes have been set. + */ + public static final String RELATED_NODES_PROPERTY = "relatedNodes"; + /** Flag to denote the New state. */ public static final int NEW = 1; @@ -274,8 +280,9 @@ public interface MetadataViewer * * @param root The object to set. * @param userID The id of the user. + * @param ctx The security context. */ - public void setRootObject(Object root, long userID); + public void setRootObject(Object root, long userID, SecurityContext ctx); /** * Loads the parent containers of the object hosted by the passed node. @@ -637,4 +644,12 @@ public void setThumbnails(Map thumbnails, /** Refreshes the view. */ void refresh(); + + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext(); + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerComponent.java index f62aa0813d1..898b678f60b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerComponent.java @@ -74,6 +74,7 @@ import org.openmicroscopy.shoola.env.data.model.FigureParam; import org.openmicroscopy.shoola.env.data.model.ScriptActivityParam; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StructuredDataResults; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -150,7 +151,7 @@ else if (refObject instanceof WellSampleData) { MovieActivityParam activity = new MovieActivityParam(parameters, img); IconManager icons = IconManager.getInstance(); activity.setIcon(icons.getIcon(IconManager.MOVIE_22)); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); } /** @@ -172,7 +173,7 @@ private void deleteAnnotations(List toDelete) p.setFailureIcon(icons.getIcon(IconManager.DELETE_22)); UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); - un.notifyActivity(p); + un.notifyActivity(model.getSecurityContext(), p); } /** @@ -215,7 +216,8 @@ public void activate(Map channelData) switch (model.getState()) { case NEW: model.getEditor().setChannelsData(channelData, false); - setRootObject(model.getRefObject(), model.getUserID()); + setRootObject(model.getRefObject(), model.getUserID(), + model.getSecurityContext()); break; case DISCARDED: throw new IllegalStateException( @@ -364,9 +366,9 @@ public JFrame getParentUI() /** * Implemented as specified by the {@link MetadataViewer} interface. - * @see MetadataViewer#setRootObject(Object, long) + * @see MetadataViewer#setRootObject(Object, long, ctx) */ - public void setRootObject(Object root, long userID) + public void setRootObject(Object root, long userID, SecurityContext ctx) { if (root instanceof WellSampleData) { WellSampleData ws = (WellSampleData) root; @@ -377,7 +379,7 @@ public void setRootObject(Object root, long userID) userID = -1; } //Previewed the image. - model.setRootObject(root); + model.setRootObject(root, ctx); view.setRootObject(); //reset the parent. model.setUserID(userID); @@ -555,7 +557,8 @@ public void onDataSave(List data) DataObject dataObject = null; if (data.size() == 1) dataObject = data.get(0); if (dataObject != null && model.isSameObject(dataObject)) { - setRootObject(model.getRefObject(), model.getUserID()); + setRootObject(model.getRefObject(), model.getUserID(), + model.getSecurityContext()); firePropertyChange(ON_DATA_SAVE_PROPERTY, null, dataObject); } else firePropertyChange(ON_DATA_SAVE_PROPERTY, null, data); @@ -590,6 +593,8 @@ public void setRelatedNodes(List nodes) //model.setSelectionMode(false); //setRootObject(model.getRefObject(), model.getUserID()); model.setRelatedNodes(nodes); + firePropertyChange(RELATED_NODES_PROPERTY, Boolean.valueOf(false), + Boolean.valueOf(true)); } /** @@ -625,8 +630,8 @@ public void onAdminUpdated(Object data) un.notifyInfo("Update experimenters", buf.toString()); } firePropertyChange(CLEAR_SAVE_DATA_PROPERTY, null, data); - setRootObject(null, -1); - } else setRootObject(o, model.getUserID()); + setRootObject(null, -1, null); + } else setRootObject(o, model.getUserID(), model.getSecurityContext()); firePropertyChange(ADMIN_UPDATED_PROPERTY, null, data); /* @@ -771,7 +776,7 @@ public void uploadMovie(FileAnnotationData data, File folder) DownloadActivityParam activity = new DownloadActivityParam(f, folder, icons.getIcon(IconManager.DOWNLOAD_22)); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); //un.notifyDownload(data, folder); } firePropertyChange(CREATING_MOVIE_PROPERTY, Boolean.valueOf(true), @@ -935,7 +940,7 @@ public void uploadFret(FileAnnotationData data, File folder) DownloadActivityParam activity = new DownloadActivityParam(f, folder, icons.getIcon(IconManager.DOWNLOAD_22)); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); } firePropertyChange(ANALYSE_PROPERTY, Boolean.valueOf(true), Boolean.valueOf(false)); @@ -1163,7 +1168,9 @@ public void saveSettings() def = rnd.saveCurrentSettings(); } catch (Exception e) { try { - reg.getImageService().resetRenderingService(pixelsID); + + reg.getImageService().resetRenderingService( + model.getSecurityContext(), pixelsID); def = rnd.saveCurrentSettings(); } catch (Exception ex) { String s = "Data Retrieval Failure: "; @@ -1194,12 +1201,19 @@ public void onGroupSwitched(boolean success) model.getEditor().onGroupSwitched(success); } + /** + * Implemented as specified by the {@link MetadataViewer} interface. + * @see MetadataViewer#onGroupSwitched(boolean) + */ + public SecurityContext getSecurityContext() + { + return model.getSecurityContext(); + + } /** * Overridden to return the name of the instance to save. * @see #toString() */ public String toString() { return model.getRefObjectName(); } - - } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerControl.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerControl.java index bc0f163f257..31c29e288c3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerControl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerControl.java @@ -175,7 +175,7 @@ void analyseFRAP(int channelIndex) AnalysisActivityParam activity = new AnalysisActivityParam(param, icons.getIcon(IconManager.ANALYSE_FRAP_22)); UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier(); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerModel.java index b22a75cc3d0..45f61a95f1f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/metadata/view/MetadataViewerModel.java @@ -59,6 +59,7 @@ import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.env.data.model.MovieExportParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StructuredDataResults; import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; @@ -98,58 +99,61 @@ class MetadataViewerModel { /** Holds one of the state flags defined by {@link MetadataViewer}. */ - private int state; + private int state; /** Reference to the component that embeds this model. */ - private MetadataViewer component; + private MetadataViewer component; /** The object of reference for the viewer i.e. the root. */ - private Object refObject; + private Object refObject; /** The object of reference for the viewer i.e. the root. */ - private Object parentRefObject; + private Object parentRefObject; /** The object hosting the various annotations linked to an object. */ - private StructuredDataResults data; + private StructuredDataResults data; /** The object hosting the various annotations linked to an object. */ - private StructuredDataResults parentData; + private StructuredDataResults parentData; /** Reference to the browser. */ - private Browser browser; + private Browser browser; /** Reference to the editor. */ - private Editor editor; + private Editor editor; /** The active data loaders. */ - private Map loaders; + private Map loaders; /** Only used when it is a batch call. */ - private Class dataType; + private Class dataType; /** * Flag indicating the selection mode, true * if single selection, false otherwise. */ - private boolean singleMode; + private boolean singleMode; /** Collection of nodes related to the node of reference. */ - private List relatedNodes; + private List relatedNodes; /** * One of the Rendering constants defined by the * MetadataViewer interface. */ - private int index; + private int index; /** * The id of the possible owner, this should only be used * to handle unregistered objects. */ - private long userID; + private long userID; /** The collection of rendering settings related to the image. */ - private Map viewedBy; + private Map viewedBy; + + /** The security context.*/ + private SecurityContext ctx; /** * Returns the collection of the attachments linked to the @@ -257,11 +261,18 @@ void discard() /** * Sets the object of reference. * - * @param refObject The value to set. + * @param refObject The value to set. + * @param ctx The security context. */ - void setRootObject(Object refObject) + void setRootObject(Object refObject, SecurityContext ctx) { - this.refObject = refObject; + this.refObject = refObject; + this.ctx = ctx; + if (ctx == null && refObject instanceof DataObject) { + DataObject data = (DataObject) refObject; + if (data.getId() >= 0) + this.ctx = new SecurityContext(data.getGroupId()); + } browser.setRootObject(refObject); editor.setRootObject(refObject); data = null; @@ -364,7 +375,7 @@ void fireParentLoading(TreeBrowserSet refNode) Object ho = refNode.getUserObject(); if (ho instanceof DataObject) { ContainersLoader loader = new ContainersLoader( - component, refNode, ho.getClass(), + component, ctx, refNode, ho.getClass(), ((DataObject) ho).getId()); loaders.put(refNode, loader); loader.load(); @@ -394,15 +405,15 @@ void fireStructuredDataLoading(TreeBrowserDisplay refNode) if (!loaders.containsKey(refNode) && parentData == null && parentRefObject != null) { StructuredDataLoader l = new StructuredDataLoader(component, - refNode, parentRefObject); + ctx, refNode, parentRefObject); loaders.put(refNode, l); l.load(); state = MetadataViewer.LOADING_METADATA; return; } } - StructuredDataLoader loader = new StructuredDataLoader(component, - refNode, uo); + StructuredDataLoader loader = new StructuredDataLoader(component, + ctx, refNode, uo); loaders.put(refNode, loader); loader.load(); state = MetadataViewer.LOADING_METADATA; @@ -487,8 +498,8 @@ void fireSaving(List toAdd, List toRemove, List metadata, Collection data, boolean asynch) { if (asynch) { - DataSaver loader = new DataSaver(component, data, toAdd, toRemove, - metadata); + DataSaver loader = new DataSaver(component, ctx, data, toAdd, + toRemove, metadata); loader.load(); state = MetadataViewer.SAVING; } else { @@ -498,9 +509,9 @@ void fireSaving(List toAdd, List toRemove, if (metadata != null) { Iterator i = metadata.iterator(); while (i.hasNext()) - os.saveAcquisitionData(i.next()) ; + os.saveAcquisitionData(ctx, i.next()) ; } - os.saveData(data, toAdd, toRemove, userID); + os.saveData(ctx, data, toAdd, toRemove, userID); } catch (Exception e) { LogMessage msg = new LogMessage(); msg.print("Unable to save annotation and/or edited data"); @@ -520,14 +531,15 @@ void fireSaving(List toAdd, List toRemove, void fireExperimenterSaving(ExperimenterData data, boolean async) { if (async) { - ExperimenterEditor loader = new ExperimenterEditor(component, data); + ExperimenterEditor loader = new ExperimenterEditor(component, ctx, + data); loader.load(); state = MetadataViewer.SAVING; } else { AdminService svc = MetadataViewerAgent.getRegistry().getAdminService(); try { - svc.updateExperimenter(data, null); + svc.updateExperimenter(ctx, data, null); } catch (Exception e) { LogMessage msg = new LogMessage(); msg.print("Unable to update the experimenter"); @@ -551,11 +563,11 @@ void fireAdminSaving(AdminObject data, boolean asynch) switch (data.getIndex()) { case AdminObject.UPDATE_GROUP: GroupData group = data.getGroup(); - loader = new GroupEditor(component, group, + loader = new GroupEditor(component, ctx, group, data.getPermissions()); break; case AdminObject.UPDATE_EXPERIMENTER: - loader = new AdminEditor(component, data.getGroup(), + loader = new AdminEditor(component, ctx, data.getGroup(), data.getExperimenters()); } if (loader != null) { @@ -570,9 +582,9 @@ void fireAdminSaving(AdminObject data, boolean asynch) case AdminObject.UPDATE_GROUP: try { GroupData group = data.getGroup(); - GroupData g = svc.lookupGroup(group.getName()); + GroupData g = svc.lookupGroup(ctx, group.getName()); if (g == null || group.getId() == g.getId()) - svc.updateGroup(data.getGroup(), + svc.updateGroup(ctx, data.getGroup(), data.getPermissions()); else { UserNotifier un = @@ -589,7 +601,7 @@ void fireAdminSaving(AdminObject data, boolean asynch) break; case AdminObject.UPDATE_EXPERIMENTER: try { - svc.updateExperimenters(data.getGroup(), + svc.updateExperimenters(ctx, data.getGroup(), data.getExperimenters()); } catch (Exception e) { msg.print("Unable to update experimenters"); @@ -597,7 +609,7 @@ void fireAdminSaving(AdminObject data, boolean asynch) MetadataViewerAgent.getRegistry().getLogger().error( this, msg); } - } + } } } @@ -667,8 +679,8 @@ boolean isArchived() void fireBatchSaving(List toAdd, List toRemove, Collection toSave) { - DataBatchSaver loader = new DataBatchSaver(component, toSave, toAdd, - toRemove); + DataBatchSaver loader = new DataBatchSaver(component, ctx, + toSave, toAdd, toRemove); loader.load(); state = MetadataViewer.BATCH_SAVING; } @@ -726,7 +738,7 @@ void setRelatedNodes(List relatedNodes) */ void loadParents(Class type, long id) { - ContainersLoader loader = new ContainersLoader(component, type, id); + ContainersLoader loader = new ContainersLoader(component, ctx, type, id); loader.load(); } @@ -841,7 +853,7 @@ else if (refObject instanceof WellSampleData) if (img == null) return; getEditor().getRenderer().loadRndSettings(false, null); RenderingSettingsLoader loader = new RenderingSettingsLoader(component, - img.getDefaultPixels().getId()); + ctx, img.getDefaultPixels().getId()); loader.load(); } @@ -859,7 +871,7 @@ else if (refObject instanceof WellSampleData) ids.add(((ExperimenterData) i.next()).getId()); } if (ids.size() == 0) return; - ThumbnailLoader loader = new ThumbnailLoader(component, image, ids); + ThumbnailLoader loader = new ThumbnailLoader(component, ctx, image, ids); loader.load(); } @@ -885,5 +897,17 @@ boolean isWritable() if (editor == null) return false; return editor.isWritable(); } + + /** + * Returns the security context. + * + * @return See above. + */ + SecurityContext getSecurityContext() + { + if (MetadataViewerAgent.isAdministrator()) + return MetadataViewerAgent.getAdminContext(); + return ctx; + } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/AdminCreator.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/AdminCreator.java index b23f5fcf1f3..e2a7469ee9f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/AdminCreator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/AdminCreator.java @@ -38,6 +38,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.ui.UserNotifier; @@ -72,11 +73,13 @@ public class AdminCreator * Creates a new instance. * * @param viewer Reference to the Model. Mustn't be null. + * @param ctx The security context. * @param object The object hosting details about object to create. */ - public AdminCreator(TreeViewer viewer, AdminObject object) + public AdminCreator(TreeViewer viewer, SecurityContext ctx, + AdminObject object) { - super(viewer); + super(viewer, ctx); if (object == null) throw new IllegalArgumentException("No object"); this.object = object; @@ -90,16 +93,16 @@ public void load() { switch (object.getIndex()) { case AdminObject.CREATE_GROUP: - handle = adminView.createGroup(object, this); + handle = adminView.createGroup(ctx, object, this); break; case AdminObject.CREATE_EXPERIMENTER: - handle = adminView.createExperimenters(object, this); + handle = adminView.createExperimenters(ctx,object, this); break; case AdminObject.RESET_PASSWORD: - handle = adminView.resetExperimentersPassword(object, this); + handle = adminView.resetExperimentersPassword(ctx, object, this); break; case AdminObject.ACTIVATE_USER: - handle = adminView.activateExperimenters(object, this); + handle = adminView.activateExperimenters(ctx, object, this); break; case AdminObject.ADD_EXPERIMENTER_TO_GROUP: long userID = getCurrentUserID(); @@ -139,7 +142,7 @@ public void load() m.put(group, toAdd); Map m1 = new HashMap(); m1.put(group, toRemove); - handle = dmView.addExistingObjects(m, m1, this); + handle = dmView.addExistingObjects(ctx, m, m1, this); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/AdminLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/AdminLoader.java index 00cd4fdb947..9e11fb5ce43 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/AdminLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/AdminLoader.java @@ -34,6 +34,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.GroupData; @@ -65,11 +66,12 @@ public class AdminLoader * Creates a new instance. * * @param viewer Reference to the Model. Mustn't be null. + * @param ctx The security context. * @param group The node to attach the result to or null. */ - public AdminLoader(Browser viewer, TreeImageSet group) + public AdminLoader(Browser viewer, SecurityContext ctx, TreeImageSet group) { - super(viewer); + super(viewer, ctx); this.group = group; } @@ -84,7 +86,7 @@ public void load() GroupData g = (GroupData) group.getUserObject(); id = g.getId(); } - handle = adminView.loadExperimenterGroups(id, this); + handle = adminView.loadExperimenterGroups(ctx, id, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ContainerCounterLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ContainerCounterLoader.java index 0f6dbf25249..71ba4ff25dc 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ContainerCounterLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ContainerCounterLoader.java @@ -35,6 +35,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -69,14 +70,15 @@ public class ContainerCounterLoader * Creates a new instance. * * @param viewer Reference to the Model. Mustn't be null. + * @param ctx The security context. * @param rootIDs The collection of DataObjects * we want to analyze. * @param nodes The collection of corresponding nodes. */ - public ContainerCounterLoader(Browser viewer, Set rootIDs, - Set nodes) + public ContainerCounterLoader(Browser viewer, SecurityContext ctx, + Set rootIDs, Set nodes) { - super(viewer); + super(viewer, ctx); if (rootIDs == null) throw new IllegalArgumentException("Collection shouldn't be null."); this.rootIDs = rootIDs; @@ -89,7 +91,7 @@ public ContainerCounterLoader(Browser viewer, Set rootIDs, */ public void load() { - handle = dmView.countContainerItems(rootIDs, this); + handle = dmView.countContainerItems(ctx, rootIDs, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataBrowserLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataBrowserLoader.java index 66b5029668a..37d9d9594e8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataBrowserLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataBrowserLoader.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.AdminView; import org.openmicroscopy.shoola.env.data.views.DataHandlerView; import org.openmicroscopy.shoola.env.data.views.DataManagerView; @@ -83,16 +84,22 @@ public abstract class DataBrowserLoader /** Convenience reference for subclasses. */ protected final AdminView adminView; + /** The security context.*/ + protected final SecurityContext ctx; + /** * Creates a new instance. * * @param viewer The browser this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - protected DataBrowserLoader(Browser viewer) + protected DataBrowserLoader(Browser viewer, SecurityContext ctx) { if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null) throw new NullPointerException("No security context."); this.viewer = viewer; + this.ctx = ctx; registry = TreeViewerAgent.getRegistry(); dmView = (DataManagerView) registry.getDataServicesView(DataManagerView.class); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectCreator.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectCreator.java index 3d30377d989..2f51958116f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectCreator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectCreator.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; @@ -70,14 +71,15 @@ public class DataObjectCreator * * @param viewer The Editor this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param userObject The {@link DataObject} to handle. * @param parent The parent of the object to create, * null if no parent. */ - public DataObjectCreator(TreeViewer viewer, DataObject userObject, - DataObject parent) + public DataObjectCreator(TreeViewer viewer, SecurityContext ctx, + DataObject userObject, DataObject parent) { - this(viewer, userObject, parent, null); + this(viewer, ctx, userObject, parent, null); } /** @@ -85,14 +87,15 @@ public DataObjectCreator(TreeViewer viewer, DataObject userObject, * * @param viewer The Editor this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param userObject The {@link DataObject} to handle. * @param parent The parent of the object to create, * null if no parent. */ - public DataObjectCreator(TreeViewer viewer, DataObject userObject, - DataObject parent, Collection children) + public DataObjectCreator(TreeViewer viewer, SecurityContext ctx, + DataObject userObject, DataObject parent, Collection children) { - super(viewer); + super(viewer, ctx); if (userObject == null) throw new IllegalArgumentException("No object to create."); this.parent = parent; @@ -107,9 +110,10 @@ public DataObjectCreator(TreeViewer viewer, DataObject userObject, public void load() { if (children == null || children.size() == 0) - handle = dmView.createDataObject(userObject, parent, this); + handle = dmView.createDataObject(ctx, userObject, parent, this); else - handle = mhView.createDataObject(parent, userObject, children, this); + handle = mhView.createDataObject(ctx, parent, userObject, children, + this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectRemover.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectRemover.java index 2f5c5632273..1f1c7f54370 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectRemover.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectRemover.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; @@ -63,11 +64,13 @@ public class DataObjectRemover * * @param viewer The Editor this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param values The groups or experimenters to delete. */ - public DataObjectRemover(TreeViewer viewer, List values) + public DataObjectRemover(TreeViewer viewer, SecurityContext ctx, + List values) { - super(viewer); + super(viewer, ctx); if (values == null) throw new IllegalArgumentException("No object to delete"); this.values = values; @@ -79,7 +82,7 @@ public DataObjectRemover(TreeViewer viewer, List values) */ public void load() { - handle = adminView.deleteObjects(values, this); + handle = adminView.deleteObjects(ctx, values, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectUpdater.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectUpdater.java index 8c035ff8d33..557a86ee2f7 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectUpdater.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataObjectUpdater.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; @@ -102,14 +103,16 @@ private void checkIndex(int i) /** * Creates a new instance. * - * @param viewer The Editor this data loader is for. - * Mustn't be null. - * @param objects The objects to update. - * @param index One of the constants defined by this class. + * @param viewer The Editor this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param objects The objects to update. + * @param index One of the constants defined by this class. */ - public DataObjectUpdater(TreeViewer viewer, Map objects, int index) + public DataObjectUpdater(TreeViewer viewer, SecurityContext ctx, + Map objects, int index) { - super(viewer); + super(viewer, ctx); if (objects == null) throw new IllegalArgumentException("No DataObject"); checkIndex(index); @@ -120,16 +123,17 @@ public DataObjectUpdater(TreeViewer viewer, Map objects, int index) /** * Creates a new instance. * - * @param viewer The Editor this data loader is for. - * Mustn't be null. - * @param objects The objects to update. - * @param toRemove The objects to remove. - * @param index One of the constants defined by this class. + * @param viewer The Editor this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param objects The objects to update. + * @param toRemove The objects to remove. + * @param index One of the constants defined by this class. */ - public DataObjectUpdater(TreeViewer viewer, Map objects, Map toRemove, - int index) + public DataObjectUpdater(TreeViewer viewer,SecurityContext ctx, + Map objects, Map toRemove, int index) { - super(viewer); + super(viewer, ctx); if (objects == null) throw new IllegalArgumentException("No DataObject"); checkIndex(index); @@ -145,13 +149,14 @@ public DataObjectUpdater(TreeViewer viewer, Map objects, Map toRemove, public void load() { if (index == COPY_AND_PASTE) - handle = dmView.addExistingObjects(objectsToUpdate, null, this); + handle = dmView.addExistingObjects(ctx, objectsToUpdate, null, + this); else if ((index == CUT_AND_PASTE) || (index == CUT)) { boolean admin = false; Browser browser = viewer.getSelectedBrowser(); if (browser != null) admin = browser.getBrowserType() == Browser.ADMIN_EXPLORER; - handle = dmView.cutAndPaste(objectsToUpdate, objectsToRemove, + handle = dmView.cutAndPaste(ctx, objectsToUpdate, objectsToRemove, admin, this); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataTreeViewerLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataTreeViewerLoader.java index e3dfa4077a6..1d05a8dbf5f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataTreeViewerLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/DataTreeViewerLoader.java @@ -34,6 +34,7 @@ import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.AdminView; import org.openmicroscopy.shoola.env.data.views.DataHandlerView; import org.openmicroscopy.shoola.env.data.views.DataManagerView; @@ -67,28 +68,31 @@ public abstract class DataTreeViewerLoader { /** The TreeViewer this data loader is for. */ - protected final TreeViewer viewer; + protected final TreeViewer viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final DataManagerView dmView; + protected final DataManagerView dmView; /** Convenience reference for subclasses. */ - protected final DataHandlerView dhView; + protected final DataHandlerView dhView; /** Convenience reference for subclasses. */ - protected final HierarchyBrowsingView hiBrwView; + protected final HierarchyBrowsingView hiBrwView; /** Convenience reference for subclasses. */ - protected final ImageDataView ivView; + protected final ImageDataView ivView; /** Convenience reference for subclasses. */ - protected final MetadataHandlerView mhView; + protected final MetadataHandlerView mhView; /** Convenience reference for subclasses. */ - protected final AdminView adminView; + protected final AdminView adminView; + + /** The security context.*/ + protected final SecurityContext ctx; /** * Converts the UI rootLevel into its corresponding class. @@ -112,11 +116,14 @@ protected long getCurrentUserID() * * @param viewer The TreeViewer this data loader is for. * Mustn't be null. + * @param ctx The security context. */ - protected DataTreeViewerLoader(TreeViewer viewer) + protected DataTreeViewerLoader(TreeViewer viewer, SecurityContext ctx) { if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null) throw new NullPointerException("No security context."); this.viewer = viewer; + this.ctx = ctx; registry = TreeViewerAgent.getRegistry(); dmView = (DataManagerView) registry.getDataServicesView(DataManagerView.class); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExistingObjectsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExistingObjectsLoader.java index 8368a174ad0..1ef9889d9ca 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExistingObjectsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExistingObjectsLoader.java @@ -25,15 +25,13 @@ //Java imports -import java.util.Collection; -import java.util.HashSet; import java.util.List; -import java.util.Set; //Third-party libraries //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.DatasetData; @@ -81,13 +79,15 @@ private void checkObject(DataObject o) /** * Creates a new instance. * - * @param viewer The TreeViewer this data loader is for. - * Mustn't be null. - * @param ho The object the nodes has to be added to. + * @param viewer The TreeViewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param ho The object the nodes has to be added to. */ - public ExistingObjectsLoader(TreeViewer viewer, DataObject ho) + public ExistingObjectsLoader(TreeViewer viewer, SecurityContext ctx, + DataObject ho) { - super(viewer); + super(viewer, ctx); checkObject(ho); this.ho = ho; } @@ -99,7 +99,7 @@ public ExistingObjectsLoader(TreeViewer viewer, DataObject ho) public void load() { if (ho instanceof GroupData) { - handle = adminView.loadExperimenters(-1, this); + handle = adminView.loadExperimenters(ctx, -1, this); } //handle = dmView.loadExistingObjects(ho.getClass(), nodes, // viewer.getRootID(), this); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExistingObjectsSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExistingObjectsSaver.java index 306189ab3a0..b57e6d2c940 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExistingObjectsSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExistingObjectsSaver.java @@ -35,6 +35,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.DatasetData; @@ -85,13 +86,14 @@ private void checkParent(DataObject o) * * @param viewer The TreeViewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param parent The data object to update. * @param children The items to add to the data object. */ - public ExistingObjectsSaver(TreeViewer viewer, DataObject parent, - Set children) + public ExistingObjectsSaver(TreeViewer viewer, SecurityContext ctx, + DataObject parent, Set children) { - super(viewer); + super(viewer, ctx); if (parent == null) throw new IllegalArgumentException("Data object cannot be null"); if (children == null || children.size() == 0) @@ -109,7 +111,7 @@ public void load() { List l = new ArrayList(); l.add(parent); - handle = dmView.addExistingObjects(l, children, this); + handle = dmView.addExistingObjects(ctx, l, children, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterDataLoader.java index 29919d837ac..40bebf9dcf8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterDataLoader.java @@ -24,11 +24,9 @@ //Java imports -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; -import java.util.List; import java.util.Set; //Third-party libraries @@ -37,6 +35,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; import org.openmicroscopy.shoola.env.data.FSFileSystemView; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.DatasetData; @@ -142,13 +141,14 @@ private Class getClassType(int type) * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param containerType One of the type defined by this class. * @param expNode The node hosting the experimenter the data are for. */ - public ExperimenterDataLoader(Browser viewer, int containerType, - TreeImageSet expNode) + public ExperimenterDataLoader(Browser viewer, SecurityContext ctx, + int containerType, TreeImageSet expNode) { - this(viewer, containerType, expNode, null); + this(viewer, ctx, containerType, expNode, null); } /** @@ -156,15 +156,16 @@ public ExperimenterDataLoader(Browser viewer, int containerType, * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param containerType One of the type defined by this class. * @param expNode The node hosting the experimenter the data are for. * Mustn't be null. * @param parent The parent the nodes are for. */ - public ExperimenterDataLoader(Browser viewer, int containerType, - TreeImageSet expNode, TreeImageSet parent) + public ExperimenterDataLoader(Browser viewer, SecurityContext ctx, + int containerType, TreeImageSet expNode, TreeImageSet parent) { - super(viewer); + super(viewer, ctx); if (expNode == null || !(expNode.getUserObject() instanceof ExperimenterData)) throw new IllegalArgumentException("Experimenter node not valid."); @@ -190,24 +191,23 @@ public void load() id = parent.getUserObjectId(); } boolean top = type == TAG_SET; - handle = dmView.loadTags(id, withImages, top, exp.getId(), - viewer.getUserGroupID(), this); + handle = dmView.loadTags(ctx, id, withImages, top, exp.getId(), + ctx.getGroupID(), this); } else if (FileAnnotationData.class.equals(rootNodeType)) { - handle = mhView.loadExistingAnnotations(rootNodeType, exp.getId(), - viewer.getUserGroupID(), this); + handle = mhView.loadExistingAnnotations(ctx, + rootNodeType, exp.getId(), ctx.getGroupID(), this); } else { if (viewer.getBrowserType() == Browser.FILE_SYSTEM_EXPLORER) { - handle = dmView.loadRepositories(exp.getId(), this); + handle = dmView.loadRepositories(ctx, exp.getId(), this); } else { if (parent == null) { - handle = dmView.loadContainerHierarchy(rootNodeType, null, - withImages, exp.getId(), viewer.getUserGroupID(), - this); + handle = dmView.loadContainerHierarchy(ctx, + rootNodeType, null, withImages, exp.getId(), + ctx.getGroupID(), this); } else { - handle = dmView.loadContainerHierarchy(rootNodeType, + handle = dmView.loadContainerHierarchy(ctx, rootNodeType, Arrays.asList(parent.getUserObjectId()), - withImages, exp.getId(), viewer.getUserGroupID(), - this); + withImages, exp.getId(), ctx.getGroupID(), this); } } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterImageLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterImageLoader.java index c147a94e2e2..675b9c1cd6d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterImageLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterImageLoader.java @@ -35,6 +35,7 @@ import org.openmicroscopy.shoola.agents.util.browser.TreeFileSet; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; @@ -69,18 +70,18 @@ public class ExperimenterImageLoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param expNode The node hosting the experimenter the data are - * for. - * Mustn't be null. - * @param smartFolderNode The node hosting the information about - * the smart folder. Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param expNode The node hosting the experimenter the data are for. + * Mustn't be null. + * @param smartFolderNode The node hosting the information about + * the smart folder. Mustn't be null. */ - public ExperimenterImageLoader(Browser viewer, TreeImageSet expNode, - TreeImageSet smartFolderNode) + public ExperimenterImageLoader(Browser viewer, SecurityContext ctx, + TreeImageSet expNode, TreeImageSet smartFolderNode) { - super(viewer); + super(viewer, ctx); if (expNode == null || !(expNode.getUserObject() instanceof ExperimenterData)) throw new IllegalArgumentException("Experimenter node not valid."); @@ -99,11 +100,11 @@ public void load() ExperimenterData exp = (ExperimenterData) expNode.getUserObject(); if (smartFolderNode instanceof TreeImageTimeSet) { TreeImageTimeSet time = (TreeImageTimeSet) smartFolderNode; - handle = dhView.loadImages(time.getStartTime(), + handle = dhView.loadImages(ctx, time.getStartTime(), time.getEndTime(), exp.getId(), this); } else if (smartFolderNode instanceof TreeFileSet) { - handle = dhView.loadFiles(((TreeFileSet) smartFolderNode).getType(), - exp.getId(), this); + handle = dhView.loadFiles(ctx, + ((TreeFileSet) smartFolderNode).getType(), exp.getId(), this); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterImagesCounter.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterImagesCounter.java index 7bdf973e1c2..b7c3388cdaf 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterImagesCounter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ExperimenterImagesCounter.java @@ -41,6 +41,7 @@ import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.MetadataHandlerView; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -80,14 +81,15 @@ public class ExperimenterImagesCounter * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param expNode The node hosting the experimenter the data are for. * Mustn't be null. * @param nodes The time nodes. Mustn't be null. */ - public ExperimenterImagesCounter(Browser viewer, TreeImageSet expNode, - List nodes) + public ExperimenterImagesCounter(Browser viewer, SecurityContext ctx, + TreeImageSet expNode, List nodes) { - super(viewer); + super(viewer, ctx); if (expNode == null || !(expNode.getUserObject() instanceof ExperimenterData)) throw new IllegalArgumentException("Experimenter node not valid."); @@ -147,7 +149,7 @@ public void load() m.put(file.getType(), ref); } } - handle = dmView.countExperimenterImages(userID, m, this); + handle = dmView.countExperimenterImages(ctx, userID, m, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/FilesChecker.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/FilesChecker.java index dc310bb33bb..f1262d69d52 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/FilesChecker.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/FilesChecker.java @@ -36,6 +36,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.util.browser.TreeImageNode; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; @@ -70,11 +71,13 @@ public class FilesChecker * * @param viewer The viewer this data loader is for. * Mustn't be null. - * @param nodes The collection of nodes to handles. + * @param ctx The security context. + * @param nodes The collection of nodes to handles. */ - public FilesChecker(Browser viewer, List nodes) + public FilesChecker(Browser viewer, SecurityContext ctx, + List nodes) { - super(viewer); + super(viewer, ctx); if (nodes == null) throw new IllegalArgumentException("No nodes specified."); this.nodes = nodes; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/IconManager.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/IconManager.java index 5ff7a28eaba..1abeff13acc 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/IconManager.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/IconManager.java @@ -532,12 +532,21 @@ public class IconManager /** The 48x48 Analysis icon. */ public static final int ANALYSIS_48 = 159; - + + /** The 22x22 Move icon. */ + public static final int MOVE_22 = 160; + + /** The 22x22 Move failure icon. */ + public static final int MOVE_FAILED_22 = 161; + + /** The 48x48 Move icon. */ + public static final int MOVE_48 = 162; + /** * The maximum ID used for the icon IDs. * Allows to correctly build arrays for direct indexing. */ - private static final int MAX_ID = 159; + private static final int MAX_ID = 162; /** Paths of the icon files. */ private static String[] relPaths = new String[MAX_ID+1]; @@ -714,6 +723,9 @@ public class IconManager relPaths[ANALYSIS_RUN] = "nuvola_script_run16.png"; relPaths[ANALYSIS_48] = "nuvola_kcmsystem48.png"; relPaths[ANALYSIS] = "nuvola_kcmsystem16.png"; + relPaths[MOVE_22] = "nuvola_download_manager22.png"; + relPaths[MOVE_FAILED_22] = "nuvola_download_manager22.png"; + relPaths[MOVE_48] = "nuvola_folder_image48.png"; } /** The sole instance. */ diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ImageDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ImageDataLoader.java index 2f218765089..19c4a3a75df 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ImageDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ImageDataLoader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; @@ -63,11 +64,13 @@ public class ImageDataLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param expNode The node hosting the experimenter the data are for. */ - public ImageDataLoader(Browser viewer, TreeImageSet expNode) + public ImageDataLoader(Browser viewer, SecurityContext ctx, + TreeImageSet expNode) { - super(viewer); + super(viewer, ctx); this.expNode = expNode; } @@ -82,7 +85,7 @@ public void load() ExperimenterData exp = (ExperimenterData) expNode.getUserObject(); userID = exp.getId(); } - handle = dmView.loadImages(userID, this); + handle = dmView.loadImages(ctx, userID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/MoveDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/MoveDataLoader.java new file mode 100644 index 00000000000..01b60595efd --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/MoveDataLoader.java @@ -0,0 +1,105 @@ +/* + * org.openmicroscopy.shoola.agents.treeviewer.MoveDataLoader + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.agents.treeviewer; + +//Java imports +import java.util.Collection; + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; +import org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog; +import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; +import org.openmicroscopy.shoola.env.data.views.CallHandle; +import pojos.ExperimenterData; + +/** + * Loads the data for the currently selected user. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class MoveDataLoader + extends DataTreeViewerLoader +{ + + /** The dialog where to add the loaded data.*/ + private MoveGroupSelectionDialog dialog; + + /** Handle to the asynchronous call so that we can cancel it. */ + private CallHandle handle; + + /** The type.*/ + private Class type; + + /** + * Creates a new instance. + * + * @param viewer Reference to the Model. Mustn't be null. + * @param ctx The security context. + * @param type The root node type. + * @param dialog The component where to display the result. + */ + public MoveDataLoader(TreeViewer viewer, SecurityContext ctx, + Class type, MoveGroupSelectionDialog dialog) + { + super(viewer, ctx); + if (dialog == null) + throw new IllegalArgumentException("No dialog set."); + this.dialog = dialog; + this.type = type; + } + + /** + * Retrieves the data. + * @see DataTreeViewerLoader#load() + */ + public void load() + { + ExperimenterData exp = TreeViewerAgent.getUserDetails(); + handle = dmView.loadContainerHierarchy(ctx, type, null, false, + exp.getId(), ctx.getGroupID(), this); + } + + /** + * Cancels the data loading. + * @see DataTreeViewerLoader#cancel() + */ + public void cancel() { handle.cancel(); } + + /** + * Feeds the result back to the viewer. + * @see DataTreeViewerLoader#handleResult(Object) + */ + public void handleResult(Object result) + { + if (viewer.getState() == Browser.DISCARDED) return; //Async cancel. + if (dialog.getStatus() != MoveGroupSelectionDialog.CANCEL) + dialog.setTargets((Collection) result); + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/OriginalFileLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/OriginalFileLoader.java index 0a8dddd815c..494b61977ba 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/OriginalFileLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/OriginalFileLoader.java @@ -33,6 +33,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.model.ApplicationData; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -69,14 +70,15 @@ public class OriginalFileLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param pixelsID The collection of the pixels set to handle. * @param folder The folder where to save the files. * @param data The third party application or null. */ - public OriginalFileLoader(TreeViewer viewer, Collection pixelsID, - File folder, ApplicationData data) + public OriginalFileLoader(TreeViewer viewer, SecurityContext ctx, + Collection pixelsID, File folder, ApplicationData data) { - super(viewer); + super(viewer, ctx); this.pixelsID = pixelsID; this.folder = folder; this.data = data; @@ -88,7 +90,7 @@ public OriginalFileLoader(TreeViewer viewer, Collection pixelsID, */ public void load() { - handle = mhView.loadOriginalFiles(pixelsID, this); + handle = mhView.loadOriginalFiles(ctx, pixelsID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ParentLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ParentLoader.java index c0eaa99beb6..7f2cac6e883 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ParentLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ParentLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.FileAnnotationData; @@ -55,11 +56,13 @@ public class ParentLoader * * @param viewer The Editor this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param values The groups or experimenters to delete. */ - public ParentLoader(TreeViewer viewer, FileAnnotationData data) + public ParentLoader(TreeViewer viewer, SecurityContext ctx, + FileAnnotationData data) { - super(viewer); + super(viewer, ctx); if (data == null) throw new IllegalArgumentException("No object to handle"); this.data = data; @@ -71,7 +74,7 @@ public ParentLoader(TreeViewer viewer, FileAnnotationData data) */ public void load() { - handle = dmView.loadParentsOfAnnotation(data.getId(), this); + handle = dmView.loadParentsOfAnnotation(ctx, data.getId(), this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/PlateMeasurementLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/PlateMeasurementLoader.java index 9f6c5c1055d..8bd16b31da1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/PlateMeasurementLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/PlateMeasurementLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.ExperimenterData; @@ -66,12 +67,13 @@ public class PlateMeasurementLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param node The node hosting the plate. */ - public PlateMeasurementLoader(Browser viewer, TreeImageSet expNode, - TreeImageSet node) + public PlateMeasurementLoader(Browser viewer, SecurityContext ctx, + TreeImageSet expNode, TreeImageSet node) { - super(viewer); + super(viewer, ctx); if (node == null) throw new IllegalArgumentException("No node set."); this.expNode = expNode; this.node = node; @@ -85,7 +87,7 @@ public void load() { ExperimenterData exp = (ExperimenterData) expNode.getUserObject(); DataObject object = (DataObject) node.getUserObject(); - handle = mhView.loadROIMeasurement(object, exp.getId(), this); + handle = mhView.loadROIMeasurement(ctx, object, exp.getId(), this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/PlateWellsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/PlateWellsLoader.java index e7333e11b12..45515ad567a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/PlateWellsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/PlateWellsLoader.java @@ -37,6 +37,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DataObject; import pojos.ExperimenterData; @@ -83,14 +84,15 @@ public class PlateWellsLoader * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param plates The parent the nodes are for. * @param withThumbnails Pass true to load the thumbnails, * false otherwise. */ - public PlateWellsLoader(TreeViewer viewer, List plates, - boolean withThumbnails) + public PlateWellsLoader(TreeViewer viewer, SecurityContext ctx, + List plates, boolean withThumbnails) { - super(viewer); + super(viewer, ctx); if (plates == null || plates.size() == 0) throw new IllegalArgumentException("No plates specified."); this.withThumbnails = withThumbnails; @@ -126,7 +128,7 @@ public PlateWellsLoader(TreeViewer viewer, List plates, public void load() { ExperimenterData exp = TreeViewerAgent.getUserDetails(); - handle = dmView.loadPlateWells(ids, exp.getId(), this); + handle = dmView.loadPlateWells(ctx, ids, exp.getId(), this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ProjectsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ProjectsLoader.java index c42a4e7f4e8..51a38ae4db4 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ProjectsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ProjectsLoader.java @@ -34,6 +34,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ProjectData; @@ -65,28 +66,24 @@ public class ProjectsLoader /** The user's identifier. */ private long userID; - /** The group's identifier. */ - private long groupID; - /** * Creates a new instance. * - * @param viewer The viewer this loader is for. - * Mustn't be null. + * @param viewer The viewer this loader is for. Mustn't be null. + * @param ctx The security context. * @param node The node hosting the project to browse. * Mustn't be null. * @param userID The user's identifier. - * @param groupID The group's identifier. + * @param groupID The group's identifier. */ - public ProjectsLoader(TreeViewer viewer, TreeImageDisplay node, long userID, - long groupID) + public ProjectsLoader(TreeViewer viewer, SecurityContext ctx, + TreeImageDisplay node, long userID) { - super(viewer); + super(viewer, ctx); if (node == null) throw new IllegalArgumentException("No node of reference."); this.node = node; this.userID = userID; - this.groupID = groupID; } /** @@ -99,8 +96,8 @@ public void load() long id = node.getUserObjectId(); List ids = new ArrayList(); ids.add(id); - handle = hiBrwView.loadHierarchy(ProjectData.class, ids, userID, groupID, - this); + handle = hiBrwView.loadHierarchy(ctx, ProjectData.class, ids, userID, + ctx.getGroupID(), this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/RefreshExperimenterDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/RefreshExperimenterDataLoader.java index 2393857596b..02180ed288b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/RefreshExperimenterDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/RefreshExperimenterDataLoader.java @@ -43,6 +43,7 @@ import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.MetadataHandlerView; @@ -84,7 +85,7 @@ public class RefreshExperimenterDataLoader private Class rootNodeType; /** Collection of {@link RefreshExperimenterDef} objects. */ - private Map expNodes; + private Map expNodes; /** Handle to the asynchronous call so that we can cancel it. */ private CallHandle handle; @@ -96,7 +97,7 @@ public class RefreshExperimenterDataLoader private DataObject toBrowse; /** The smart folder for tags.*/ - private Map smartFolders; + private Map smartFolders; /** * Controls if the passed class is supported. @@ -120,9 +121,9 @@ private void checkClass(Class klass) * @param expId The user's id. * @param result The result of the call for the passed user. */ - private void setExperimenterResult(long expId, Object result) + private void setExperimenterResult(SecurityContext ctx, Object result) { - RefreshExperimenterDef node = expNodes.get(expId); + RefreshExperimenterDef node = expNodes.get(ctx); Map map; Map expandedNodes = node.getExpandedTopNodes(); if (expandedNodes == null || expandedNodes.size() == 0 @@ -138,7 +139,7 @@ private void setExperimenterResult(long expId, Object result) parent = j.next(); if (parent instanceof TimeRefObject) { //for tag support. if (smartFolders != null) { - display = smartFolders.get(expId); + display = smartFolders.get(ctx); if (display != null) { display.removeAllChildren(); display.removeAllChildrenDisplay(); @@ -195,6 +196,7 @@ private void formatSmartFolderResult(long expId, List result) * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param rootNodeType The root node either Project or * Screen. * @param expNodes Collection of nodes hosting information about @@ -203,11 +205,12 @@ private void formatSmartFolderResult(long expId, List result) * @param refNode The node of reference. * @param toBrowse The node to browse. */ - public RefreshExperimenterDataLoader(Browser viewer, - Class rootNodeType, Map expNodes, + public RefreshExperimenterDataLoader(Browser viewer, SecurityContext ctx, + Class rootNodeType, + Map expNodes, Class type, long id, Object refNode, DataObject toBrowse) { - super(viewer); + super(viewer, ctx); if (expNodes == null || expNodes.size() == 0) throw new IllegalArgumentException("Experimenter nodes not valid."); checkClass(rootNodeType); @@ -234,14 +237,18 @@ public void load() List times; Iterator j; TreeImageSet node; - Map m = new HashMap(expNodes.size()); + Map + m = new HashMap(expNodes.size()); + SecurityContext ctx; if (ImageData.class.equals(rootNodeType) || FileAnnotationData.class.equals(rootNodeType)) { TreeImageTimeSet time; TreeFileSet file; while (i.hasNext()) { entry = (Entry) i.next(); - userID = (Long) entry.getKey(); + ctx = (SecurityContext) entry.getKey(); + //userID = (Long) entry.getKey(); + userID = ctx.getExperimenter(); def = (RefreshExperimenterDef) entry.getValue(); nodes = def.getExpandedNodes(); j = nodes.iterator(); @@ -261,7 +268,7 @@ public void load() } if (ref != null) times.add(ref); } - m.put(userID, times); + m.put(ctx, times); } } else { List l; @@ -270,12 +277,13 @@ public void load() Object ob; while (i.hasNext()) { entry = (Entry) i.next(); - userID = (Long) entry.getKey(); + ctx = (SecurityContext) entry.getKey(); + userID = ctx.getExperimenter(); def = (RefreshExperimenterDef) entry.getValue(); if (GroupData.class.equals(rootNodeType)) { l = (List) def.getExpandedTopNodes().get(GroupData.class); if (l == null) l = new ArrayList(); - m.put(userID, l); + m.put(ctx, l); } else { if (TagAnnotationData.class.equals(rootNodeType)) { l = def.getExpandedNodes(); @@ -291,12 +299,12 @@ public void load() nl.add(ref); if (smartFolders == null) smartFolders = new - HashMap(); - smartFolders.put(userID, (TreeImageSet) ob); + HashMap(); + smartFolders.put(ctx, (TreeImageSet) ob); } else nl.add(ob); } - m.put(userID, nl); - } else m.put(userID, def.getExpandedNodes()); + m.put(ctx, nl); + } else m.put(ctx, def.getExpandedNodes()); } } } @@ -344,10 +352,11 @@ public void handleResult(Object result) formatSmartFolderResult(expId, (List) entry.getValue()); } } else { + SecurityContext ctx; while (i.hasNext()) { entry = (Entry) i.next(); - expId = (Long) entry.getKey(); - setExperimenterResult(expId, entry.getValue()); + ctx = (SecurityContext) entry.getKey(); + setExperimenterResult(ctx, entry.getValue()); } } viewer.setRefreshExperimenterData(expNodes, type, id); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/RndSettingsSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/RndSettingsSaver.java index 0299e4c169b..4b896eef595 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/RndSettingsSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/RndSettingsSaver.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.DatasetData; import pojos.ImageData; @@ -134,6 +135,7 @@ private void checkRootType(Class type) * * @param viewer The TreeViewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param rootType The type of nodes. Supported type * ImageData, DatasetData, * ProjectData, PlateData @@ -145,10 +147,10 @@ private void checkRootType(Class type) * to the images contained in the specified containers. * @param index One of the constants defined by this class. */ - public RndSettingsSaver(TreeViewer viewer, Class rootType, List ids, - int index) + public RndSettingsSaver(TreeViewer viewer, SecurityContext ctx, + Class rootType, List ids, int index) { - super(viewer); + super(viewer, ctx); checkRootType(rootType); checkIndex(index); this.index = index; @@ -164,12 +166,14 @@ public RndSettingsSaver(TreeViewer viewer, Class rootType, List ids, * * @param viewer The TreeViewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param ref The time reference object. * @param index One of the constants defined by this class. */ - public RndSettingsSaver(TreeViewer viewer, TimeRefObject ref, int index) + public RndSettingsSaver(TreeViewer viewer, SecurityContext ctx, + TimeRefObject ref, int index) { - super(viewer); + super(viewer, ctx); checkIndex(index); this.index = index; if (ref == null) @@ -182,6 +186,7 @@ public RndSettingsSaver(TreeViewer viewer, TimeRefObject ref, int index) * * @param viewer The TreeViewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param rootType The type of nodes. Supported type * ImageData, DatasetData, * ProjectData, PlateData @@ -193,10 +198,10 @@ public RndSettingsSaver(TreeViewer viewer, TimeRefObject ref, int index) * to the images contained in the specified containers. * @param pixelsID The id of the pixels of reference. */ - public RndSettingsSaver(TreeViewer viewer, Class rootType, List ids, - long pixelsID) + public RndSettingsSaver(TreeViewer viewer, + SecurityContext ctx, Class rootType, List ids, long pixelsID) { - super(viewer); + super(viewer, ctx); checkRootType(rootType); this.index = PASTE; if (ids == null || ids.size() == 0) @@ -212,14 +217,16 @@ public RndSettingsSaver(TreeViewer viewer, Class rootType, List ids, /** * Creates a new instance. * - * @param viewer The TreeViewer this data loader is for. - * Mustn't be null. - * @param ref The time reference object. - * @param pixelsID The id of the pixels of reference. + * @param viewer The TreeViewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param ref The time reference object. + * @param pixelsID The id of the pixels of reference. */ - public RndSettingsSaver(TreeViewer viewer, TimeRefObject ref, long pixelsID) + public RndSettingsSaver(TreeViewer viewer, SecurityContext ctx, + TimeRefObject ref, long pixelsID) { - super(viewer); + super(viewer, ctx); this.index = PASTE; if (pixelsID < 0) throw new IllegalArgumentException("Pixels ID not valid."); @@ -244,28 +251,29 @@ public void load() switch (index) { case PASTE: if (ref == null) - handle = dhView.pasteRndSettings(pixelsID, rootType, ids, - this); + handle = dhView.pasteRndSettings(ctx, pixelsID, rootType, + ids, this); else - handle = dhView.pasteRndSettings(pixelsID, ref, this); + handle = dhView.pasteRndSettings(ctx, pixelsID, ref, this); break; case RESET: if (ref == null) - handle = dhView.resetRndSettings(rootType, ids, this); + handle = dhView.resetRndSettings(ctx, rootType, ids, this); else - handle = dhView.resetRndSettings(ref, this); + handle = dhView.resetRndSettings(ctx, ref, this); break; case SET_MIN_MAX: if (ref == null) - handle = dhView.setMinMaxSettings(rootType, ids, this); + handle = dhView.setMinMaxSettings(ctx, rootType, ids, this); else - handle = dhView.setMinMaxSettings(ref, this); + handle = dhView.setMinMaxSettings(ctx, ref, this); break; case SET_OWNER: if (ref == null) - handle = dhView.setOwnerRndSettings(rootType, ids, this); + handle = dhView.setOwnerRndSettings(ctx, rootType, ids, + this); else - handle = dhView.setOwnerRndSettings(ref, this); + handle = dhView.setOwnerRndSettings(ctx, ref, this); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScreenPlateLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScreenPlateLoader.java index 37f83dad020..4b2cf097d4c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScreenPlateLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScreenPlateLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; import pojos.PlateData; @@ -95,15 +96,16 @@ private Class getClassType(int type) * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param expNode The node hosting the experimenter the data are for. * Mustn't be null. * @param type The type of the root node. * @param parent The parent the nodes are for. */ - public ScreenPlateLoader(Browser viewer, TreeImageSet expNode, int type, - TreeImageSet parent) + public ScreenPlateLoader(Browser viewer, SecurityContext ctx, + TreeImageSet expNode, int type, TreeImageSet parent) { - super(viewer); + super(viewer, ctx); if (expNode == null || !(expNode.getUserObject() instanceof ExperimenterData)) throw new IllegalArgumentException("Experimenter node not valid."); @@ -117,13 +119,15 @@ public ScreenPlateLoader(Browser viewer, TreeImageSet expNode, int type, * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param expNode The node hosting the experimenter the data are for. * Mustn't be null. * @param type The type of the root node. */ - public ScreenPlateLoader(Browser viewer, TreeImageSet expNode, int type) + public ScreenPlateLoader(Browser viewer, SecurityContext ctx, + TreeImageSet expNode, int type) { - this(viewer, expNode, type, null); + this(viewer, ctx, expNode, type, null); } /** @@ -134,8 +138,8 @@ public void load() { ExperimenterData exp = (ExperimenterData) expNode.getUserObject(); if (parent == null) - handle = dmView.loadContainerHierarchy(ScreenData.class, null, - false, exp.getId(), viewer.getUserGroupID(), this); + handle = dmView.loadContainerHierarchy(ctx, ScreenData.class, null, + false, exp.getId(), ctx.getGroupID(), this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScriptLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScriptLoader.java index bd21ac7e703..09650fc136f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScriptLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScriptLoader.java @@ -33,6 +33,7 @@ import org.openmicroscopy.shoola.env.data.ProcessException; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -57,11 +58,12 @@ public class ScriptLoader * Creates a new instance. * * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. * @param scriptID The script's identifier. */ - public ScriptLoader(TreeViewer viewer, long scriptID) + public ScriptLoader(TreeViewer viewer, SecurityContext ctx, long scriptID) { - super(viewer); + super(viewer, ctx); if (scriptID < 0) throw new IllegalArgumentException("No script specified."); this.scriptID = scriptID; @@ -73,7 +75,7 @@ public ScriptLoader(TreeViewer viewer, long scriptID) */ public void load() { - handle = mhView.loadScript(scriptID, this); + handle = mhView.loadScript(ctx, scriptID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScriptsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScriptsLoader.java index 47abf818b9c..0d87a8167e9 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScriptsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/ScriptsLoader.java @@ -34,10 +34,9 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; -import org.openmicroscopy.shoola.env.data.ProcessException; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; -import org.openmicroscopy.shoola.env.log.LogMessage; /** * Loads the scripts. This class calls the loadScripts @@ -63,28 +62,41 @@ public class ScriptsLoader /** The location of the mouse click.*/ private Point location; + /** Flag indicating to load the scripts with a given UI.*/ + private boolean ui; + /** * Creates a new instance. * * @param viewer Reference to the viewer. Mustn't be null. + * @param ctx The security context. * @param all Pass true to retrieve all the scripts uploaded * ones and the default ones, false. * @param location The location of the mouse click. */ - public ScriptsLoader(TreeViewer viewer, boolean all, Point location) + public ScriptsLoader(TreeViewer viewer, SecurityContext ctx, boolean all, + Point location) { - super(viewer); + super(viewer, ctx); this.all = all; this.location = location; } + /** + * Indicates to load the scripts with a UI. + * + * @param ui Pass true to load scripts with UI, + * false otherwise. + */ + public void setUI(boolean ui) { this.ui = ui; } + /** * Loads the scripts. * @see DataTreeViewerLoader#load() */ public void load() { - handle = mhView.loadScripts(-1, all, this); + handle = mhView.loadScripts(ctx, -1, all, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TagHierarchyLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TagHierarchyLoader.java index e5d0db71e8b..08e00d9f9dd 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TagHierarchyLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TagHierarchyLoader.java @@ -31,6 +31,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -68,14 +69,15 @@ public class TagHierarchyLoader * * @param viewer The viewer this loader is for. * Mustn't be null. + * @param ctx The security context. * @param node The node hosting the project to browse. * Mustn't be null. * @param userID The id of the user the annotation belongs to. */ - public TagHierarchyLoader(TreeViewer viewer, TreeImageDisplay node, - long userID) + public TagHierarchyLoader(TreeViewer viewer, SecurityContext ctx, + TreeImageDisplay node, long userID) { - super(viewer); + super(viewer, ctx); if (node == null) throw new IllegalArgumentException("No node of reference."); this.node = node; @@ -88,8 +90,8 @@ public TagHierarchyLoader(TreeViewer viewer, TreeImageDisplay node, */ public void load() { - handle = dmView.loadTags(node.getUserObjectId(), true, false, userID, - viewer.getUserGroupID(), this); + handle = dmView.loadTags(ctx, node.getUserObjectId(), true, false, + userID, ctx.getGroupID(), this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TimeIntervalsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TimeIntervalsLoader.java index 0564d640276..c041f3c0051 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TimeIntervalsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TimeIntervalsLoader.java @@ -31,6 +31,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -63,12 +64,14 @@ public class TimeIntervalsLoader * * @param viewer The viewer this loader is for. * Mustn't be null. + * @param ctx The security context. * @param node The node hosting the time interval to browse. * Mustn't be null. */ - public TimeIntervalsLoader(TreeViewer viewer, TreeImageTimeSet node) + public TimeIntervalsLoader(TreeViewer viewer, SecurityContext ctx, + TreeImageTimeSet node) { - super(viewer); + super(viewer, ctx); if (node == null) throw new IllegalArgumentException("No node of reference."); this.node = node; @@ -82,7 +85,7 @@ public void load() { long id = TreeViewerAgent.getUserDetails().getId(); TimeRefObject ref = node.getTimeObject(id); - handle = dhView.loadImages(ref.getStartTime(), ref.getEndTime(), + handle = dhView.loadImages(ctx, ref.getStartTime(), ref.getEndTime(), ref.getUserID(), this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TreeViewerAgent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TreeViewerAgent.java index 1a150fb4a13..3bf883a855f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TreeViewerAgent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/TreeViewerAgent.java @@ -41,6 +41,7 @@ import org.openmicroscopy.shoola.agents.events.iviewer.RndSettingsCopied; import org.openmicroscopy.shoola.agents.events.iviewer.ViewerCreated; import org.openmicroscopy.shoola.agents.events.treeviewer.DataObjectSelectionEvent; +import org.openmicroscopy.shoola.agents.events.treeviewer.MoveToEvent; import org.openmicroscopy.shoola.agents.events.treeviewer.NodeToRefreshEvent; import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; @@ -53,6 +54,7 @@ import org.openmicroscopy.shoola.env.data.events.SaveEventRequest; import org.openmicroscopy.shoola.env.data.events.UserGroupSwitched; import org.openmicroscopy.shoola.env.data.util.AgentSaveInfo; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.AgentEvent; import org.openmicroscopy.shoola.env.event.AgentEventListener; import org.openmicroscopy.shoola.env.event.EventBus; @@ -135,6 +137,26 @@ public static boolean isAdministrator() return b.booleanValue(); } + /** + * Returns the context for an administrator. + * + * @return See above. + */ + public static SecurityContext getAdminContext() + { + if (!isAdministrator()) return null; + Set groups = TreeViewerAgent.getAvailableUserGroups(); + Iterator i = groups.iterator(); + GroupData g; + while (i.hasNext()) { + g = (GroupData) i.next(); + if (g.getName().equals(GroupData.SYSTEM)) { + return new SecurityContext(g.getId()); + } + } + return null; + } + /** * Returns true if the binary data are available, * false otherwise. @@ -206,6 +228,19 @@ public static boolean isLeaderOfCurrentGroup() return false; } + /** + * Returns true if all groups are displayed at the same time + * false otherwise. + * + * @return See above. + */ + public static boolean isMultiGroups() + { + Boolean b = (Boolean) registry.lookup("MutliGroup"); + if (b == null) return false; + return b.booleanValue(); + } + /** * Returns the default hierarchy i.e. P/D, HCS etc. * @@ -272,15 +307,7 @@ private void handleActivityFinished(ActivityProcessEvent evt) ExperimenterData exp = (ExperimenterData) registry.lookup( LookupNames.CURRENT_USER_DETAILS); if (exp == null) return; - GroupData gp = null; - try { - gp = exp.getDefaultGroup(); - } catch (Exception e) { - //No default group - } - long id = -1; - if (gp != null) id = gp.getId(); - TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp, id); + TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp); if (viewer != null) { viewer.onActivityProcessed(evt.getActivity(), evt.isFinished()); } @@ -307,15 +334,7 @@ private void handleDataObjectSelectionEvent(DataObjectSelectionEvent evt) ExperimenterData exp = (ExperimenterData) registry.lookup( LookupNames.CURRENT_USER_DETAILS); if (exp == null) return; - GroupData gp = null; - try { - gp = exp.getDefaultGroup(); - } catch (Exception e) { - //No default group - } - long id = -1; - if (gp != null) id = gp.getId(); - TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp, id); + TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp); if (viewer != null) viewer.findDataObject(evt.getDataType(), evt.getID(), evt.isSelectTab()); @@ -354,15 +373,7 @@ private void handleViewObjectEvent(ViewObjectEvent evt) ExperimenterData exp = (ExperimenterData) registry.lookup( LookupNames.CURRENT_USER_DETAILS); if (exp == null) return; - GroupData gp = null; - try { - gp = exp.getDefaultGroup(); - } catch (Exception e) { - //No default group - } - long id = -1; - if (gp != null) id = gp.getId(); - TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp, id); + TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp); if (viewer != null) { viewer.browseContainer(data, null); } @@ -385,15 +396,7 @@ public void handleImportStatusEvent(ImportStatusEvent evt) ExperimenterData exp = (ExperimenterData) registry.lookup( LookupNames.CURRENT_USER_DETAILS); if (exp == null) return; - GroupData gp = null; - try { - gp = exp.getDefaultGroup(); - } catch (Exception e) { - //No default group - } - long id = -1; - if (gp != null) id = gp.getId(); - TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp, id); + TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp); if (viewer != null) viewer.setImporting(evt.isImporting(), evt.getContainers(), evt.isToRefresh()); @@ -412,15 +415,7 @@ private void handleBrowseContainer(BrowseContainer evt) ExperimenterData exp = (ExperimenterData) registry.lookup( LookupNames.CURRENT_USER_DETAILS); if (exp == null) return; - GroupData gp = null; - try { - gp = exp.getDefaultGroup(); - } catch (Exception e) { - //No default group - } - long id = -1; - if (gp != null) id = gp.getId(); - TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp, id); + TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp); if (viewer != null) viewer.browseContainer(evt.getData(), evt.getNode()); } @@ -438,15 +433,7 @@ private void handleNodeToRefreshEvent(NodeToRefreshEvent evt) ExperimenterData exp = (ExperimenterData) registry.lookup( LookupNames.CURRENT_USER_DETAILS); if (exp == null) return; - GroupData gp = null; - try { - gp = exp.getDefaultGroup(); - } catch (Exception e) { - //No default group - } - long id = -1; - if (gp != null) id = gp.getId(); - TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp, id); + TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp); if (viewer != null) viewer.indicateToRefresh(evt.getObjects(), evt.getRefresh()); } @@ -460,7 +447,21 @@ private void handleReconnectedEvent(ReconnectedEvent evt) { Environment env = (Environment) registry.lookup(LookupNames.ENV); if (!env.isServerAvailable()) return; - TreeViewerFactory.onGroupSwitched(true); + TreeViewerFactory.onReconnected(); + } + + /** + * Indicates to move the data. + * + * @param evt The event to handle. + */ + private void handleMoveToEvent(MoveToEvent evt) + { + ExperimenterData exp = (ExperimenterData) registry.lookup( + LookupNames.CURRENT_USER_DETAILS); + if (exp == null) return; + TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp); + if (viewer != null) viewer.moveTo(evt.getGroup(), evt.getObjects()); } /** @@ -476,15 +477,7 @@ public void activate(boolean master) ExperimenterData exp = (ExperimenterData) registry.lookup( LookupNames.CURRENT_USER_DETAILS); if (exp == null) return; - GroupData gp = null; - try { - gp = exp.getDefaultGroup(); - } catch (Exception e) { - //No default group - } - long id = -1; - if (gp != null) id = gp.getId(); - TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp, id); + TreeViewer viewer = TreeViewerFactory.getTreeViewer(exp); if (viewer != null) viewer.activate(); } @@ -514,6 +507,7 @@ public void setContext(Registry ctx) bus.register(this, NodeToRefreshEvent.class); bus.register(this, ViewObjectEvent.class); bus.register(this, ReconnectedEvent.class); + bus.register(this, MoveToEvent.class); } /** @@ -568,6 +562,8 @@ else if (e instanceof NodeToRefreshEvent) handleNodeToRefreshEvent((NodeToRefreshEvent) e); else if (e instanceof ReconnectedEvent) handleReconnectedEvent((ReconnectedEvent) e); + else if (e instanceof MoveToEvent) + handleMoveToEvent((MoveToEvent) e); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/BrowserImportAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/BrowserImportAction.java index bbb2b1955c8..d2de5bde4e9 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/BrowserImportAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/BrowserImportAction.java @@ -163,8 +163,9 @@ public void actionPerformed(ActionEvent e) type = BrowserSelectionEvent.SCREEN_TYPE; } event = new LoadImporter(display, type); - long id = TreeViewerAgent.getUserDetails().getId(); - event.setObjects(model.getNodesForUser(id)); + event.setGroup(model.getSecurityContext(display).getGroupID()); + //long id = TreeViewerAgent.getUserDetails().getId(); + //event.setObjects(model.getNodesForUser(id, display)); EventBus bus = TreeViewerAgent.getRegistry().getEventBus(); bus.post(event); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/CreateObjectWithChildren.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/CreateObjectWithChildren.java index 9dbe97d6174..ef9e63313c8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/CreateObjectWithChildren.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/CreateObjectWithChildren.java @@ -66,7 +66,7 @@ public class CreateObjectWithChildren /** * Name of the action if the selected node is a Dataset. */ - private static final String NAME_DATASET = "New Dataset..."; + private static final String NAME_DATASET = "New Dataset From Selection..."; /** * Description of the action if the selected node is a Dataset. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/EditorAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/EditorAction.java index 940c4fe3cfd..7e60502545c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/EditorAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/EditorAction.java @@ -73,13 +73,13 @@ public class EditorAction TreeViewer.NEW_WITH_SELECTION; /** The name of the action. */ - private static final String NAME = "Launch Editor..."; + private static final String NAME = "Editor..."; /** The name of the action. */ private static final String NAME_EXPERIMENT = "New Experiment..."; /** The description of the action. */ - private static final String DESCRIPTION = "Launch the Editor."; + private static final String DESCRIPTION = "Open the Editor."; /** One of the constants defined by this class. */ private int index; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/ExitApplicationAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/ExitApplicationAction.java index 4c42c7a6097..1e3d074bf08 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/ExitApplicationAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/ExitApplicationAction.java @@ -39,6 +39,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.env.data.events.ExitApplication; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.util.ui.UIUtilities; @@ -93,7 +94,10 @@ public void actionPerformed(ActionEvent e) { model.cancel(); EventBus bus = TreeViewerAgent.getRegistry().getEventBus(); - bus.post(new ExitApplication()); + ExitApplication a = new ExitApplication(); + a.setSecurityContext(new SecurityContext( + model.getSelectedGroup().getId())); + bus.post(a); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/GroupSelectionAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/GroupSelectionAction.java index 26c86a50541..28567bbf399 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/GroupSelectionAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/GroupSelectionAction.java @@ -59,9 +59,26 @@ public class GroupSelectionAction extends TreeViewerAction { + /** The name of the action. */ + public static final String NAME = "Switch Group"; + + /** The name of the action. */ + public static final String NAME_ADD = "Add Group..."; + + /** The name of the action. */ + public static final String DESCRIPTION = "Select the sole group to " + + "display in the tree."; + + /** The name of the action. */ + public static final String DESCRIPTION_ADD = "Select the group to " + + "add to the tree."; + /** The group the logged in user is member of. */ private GroupData group; + /** Flag indicating to add the group or to switch.*/ + private boolean add; + /** * Sets the icon and tool tip text according to the permissions of the * group. @@ -115,13 +132,16 @@ protected void onBrowserStateChange(Browser browser) * * @param model Reference to the Model. Mustn't be null. * @param group The group the logged in user is a member of. + * @param add Passes true to add the group, false + * to switch. */ - public GroupSelectionAction(TreeViewer model, GroupData group) + public GroupSelectionAction(TreeViewer model, GroupData group, boolean add) { super(model); if (group == null) throw new IllegalArgumentException("No group specified."); this.group = group; + this.add = add; name = group.getName(); putValue(Action.NAME, name); setPermissions(); @@ -139,10 +159,20 @@ public boolean isSameGroup(long groupID) return group.getId() == groupID; } + /** + * Returns the id of the group hosted by this component. + * + * @return See above. + */ + public long getGroupId() { return group.getId(); } + /** * Sets the default group for the currently logged in user. * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */ - public void actionPerformed(ActionEvent e) { model.setUserGroup(group); } + public void actionPerformed(ActionEvent e) + { + model.setUserGroup(group, add); + } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/ManageObjectAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/ManageObjectAction.java index cb452c01cc1..27e793017a3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/ManageObjectAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/ManageObjectAction.java @@ -25,6 +25,8 @@ //Java imports import java.awt.event.ActionEvent; +import java.util.Iterator; +import java.util.List; import javax.swing.Action; //Third-party libraries @@ -38,8 +40,11 @@ import org.openmicroscopy.shoola.agents.treeviewer.cmd.DeleteCmd; import org.openmicroscopy.shoola.agents.treeviewer.cmd.PasteCmd; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.agents.util.EditorUtil; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; import org.openmicroscopy.shoola.util.ui.UIUtilities; + +import pojos.DataObject; import pojos.DatasetData; import pojos.ExperimenterData; import pojos.FileAnnotationData; @@ -114,6 +119,9 @@ public class ManageObjectAction /** Helper reference to the icons manager. */ private IconManager icons; + /** The id of the user currently logged in.*/ + private long userID; + /** * Checks if the passed index is supported. * @@ -178,28 +186,21 @@ protected void onBrowserStateChange(Browser browser) * Returns true if the pasting action is valid, * false otherwise. * - * @param ho The selected data object. - * @param klass The type identifying the objects to copy. + * @param ho The selected data object. + * @param list The objects to copy. * @return See above. */ - private boolean isPasteValid(Object ho, Class klass) + private boolean isPasteValid(Object ho, Listlist) { - if (ho instanceof ProjectData && DatasetData.class.equals(klass)) - return true; - else if (ho instanceof ScreenData && PlateData.class.equals(klass)) - return true; - else if (ho instanceof DatasetData && ImageData.class.equals(klass)) - return true; - else if (ho instanceof GroupData && - ExperimenterData.class.equals(klass)) - return true; - else if (ho instanceof TagAnnotationData && - TagAnnotationData.class.equals(klass)) { - TagAnnotationData tag = (TagAnnotationData) ho; - if (TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace())) - return true; + Iterator i = list.iterator(); + DataObject os; + int count = 0; + while (i.hasNext()) { + os = i.next(); + if (!EditorUtil.isTransferable(ho, os, userID)) return false; + count++; } - return false; + return count == list.size(); } /** @@ -225,8 +226,8 @@ protected void onDisplayChange(TreeImageDisplay selectedDisplay) if (parentDisplay != null) parent = parentDisplay.getUserObject(); switch (index) { case PASTE: - Class klass = model.hasDataToCopy(); - if (klass == null) { + List list = model.getDataToCopy(); + if (list == null || list.size() == 0) { setEnabled(false); return; } @@ -236,7 +237,7 @@ protected void onDisplayChange(TreeImageDisplay selectedDisplay) selected = browser.getSelectedDisplays(); for (int i = 0; i < selected.length; i++) { ho = selected[i].getUserObject(); - if (isPasteValid(ho, klass)) { + if (isPasteValid(ho, list)) { if (ho instanceof GroupData) { count++; } else { @@ -245,6 +246,16 @@ protected void onDisplayChange(TreeImageDisplay selectedDisplay) } } setEnabled(count == selected.length); + } else if (ho instanceof ExperimenterData || + ho instanceof GroupData) { + if (browser.getBrowserType() != Browser.ADMIN_EXPLORER) { + selected = browser.getSelectedDisplays(); + for (int i = 0; i < selected.length; i++) { + ho = selected[i].getUserObject(); + if (isPasteValid(ho, list)) count++; + } + setEnabled(count == selected.length); + } } else setEnabled(false); break; case REMOVE: @@ -355,6 +366,7 @@ public ManageObjectAction(TreeViewer model, int index) icons = IconManager.getInstance(); checkIndex(index); this.index = index; + userID = model.getUserDetails().getId(); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/MoveToAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/MoveToAction.java new file mode 100644 index 00000000000..762333349e9 --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/MoveToAction.java @@ -0,0 +1,133 @@ +/* + * org.openmicroscopy.shoola.agents.treeviewer.actions.MoveToAction + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.agents.treeviewer.actions; + + + +//Java imports +import java.awt.event.ActionEvent; +import javax.swing.Action; +import javax.swing.Icon; + + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.agents.treeviewer.IconManager; +import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; +import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; +import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.GroupData; + +/** + * Indicates to move the data to the selected group. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class MoveToAction + extends TreeViewerAction +{ + + /** The name of the action.*/ + public static final String NAME = "Move to"; + + /** The name of the action.*/ + public static final String DESCRIPTION = "Select the group where to" + + " move the data."; + + /** The group to move the data to.*/ + private GroupData group; + + /** + * Sets the icon and tool tip text according to the permissions of the + * group. + */ + private void setPermissions() + { + IconManager im = IconManager.getInstance(); + Icon icon = im.getIcon(IconManager.PERSONAL); + int level = + TreeViewerAgent.getRegistry().getAdminService().getPermissionLevel( + group); + String desc = ""; + switch (level) { + case AdminObject.PERMISSIONS_PRIVATE: + desc = AdminObject.PERMISSIONS_PRIVATE_TEXT; + icon = im.getIcon(IconManager.PRIVATE_GROUP); + break; + case AdminObject.PERMISSIONS_GROUP_READ: + desc = AdminObject.PERMISSIONS_GROUP_READ_TEXT; + icon = im.getIcon(IconManager.READ_GROUP); + break; + case AdminObject.PERMISSIONS_GROUP_READ_LINK: + desc = AdminObject.PERMISSIONS_GROUP_READ_LINK_TEXT; + icon = im.getIcon(IconManager.READ_LINK_GROUP); + break; + case AdminObject.PERMISSIONS_PUBLIC_READ: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_TEXT; + icon = im.getIcon(IconManager.PUBLIC_GROUP); + break; + case AdminObject.PERMISSIONS_PUBLIC_READ_WRITE: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_WRITE_TEXT; + icon = im.getIcon(IconManager.PUBLIC_GROUP); + } + + putValue(Action.SMALL_ICON, icon); + putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(desc)); + } + + /** + * Creates a new instance. + * + * @param model Reference to the Model. Mustn't be null. + * @param group The selected group. + */ + public MoveToAction(TreeViewer model, GroupData group) + { + super(model); + if (group == null) + throw new IllegalArgumentException("No group."); + this.group = group; + setEnabled(true); + name = group.getName()+"..."; + putValue(Action.NAME, name); + setPermissions(); + } + + /** + * Moves the selected objects to the group. + * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + Browser browser = model.getSelectedBrowser(); + if (browser == null) return; + model.moveTo(group, browser.getSelectedDataObjects()); + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/RemoveExperimenterNode.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/RemoveExperimenterNode.java index b72d483e2e5..e5e71f31ae5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/RemoveExperimenterNode.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/RemoveExperimenterNode.java @@ -34,6 +34,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.IconManager; +import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; @@ -66,8 +67,8 @@ public class RemoveExperimenterNode /** * Sets the action enabled depending on the browser's type and - * the currenlty selected node. Sets the name of the action depending on - * the DataObject hosted by the currenlty selected node. + * the currently selected node. Sets the name of the action depending on + * the DataObject hosted by the currently selected node. * @see TreeViewerAction#onDisplayChange(TreeImageDisplay) */ protected void onDisplayChange(TreeImageDisplay selectedDisplay) @@ -85,8 +86,10 @@ protected void onDisplayChange(TreeImageDisplay selectedDisplay) if (browser.getSelectedDisplays().length > 1) { setEnabled(false); } else { + ExperimenterData loggedIn = + TreeViewerAgent.getUserDetails(); ExperimenterData exp = (ExperimenterData) ho; - setEnabled(exp.getId() != browser.getRootID()); + setEnabled(exp.getId() != loggedIn.getId()); } } else setEnabled(false); } @@ -116,5 +119,5 @@ public void actionPerformed(ActionEvent e) { model.removeExperimenterData(); } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/RemoveGroupNode.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/RemoveGroupNode.java new file mode 100644 index 00000000000..d2d177bd99a --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/RemoveGroupNode.java @@ -0,0 +1,107 @@ +/* + * org.openmicroscopy.shoola.agents.treeviewer.actions.RemoveGroupNode + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.agents.treeviewer.actions; + +//Java imports +import java.awt.event.ActionEvent; +import javax.swing.Action; + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.agents.treeviewer.IconManager; +import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; +import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; +import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; +import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.GroupData; + +/** + * Remove a group from the display. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class RemoveGroupNode + extends TreeViewerAction +{ + + /** The name of the action. */ + private static final String NAME = "Remove Group"; + + /** The description of the action. */ + private static final String DESCRIPTION = "Remove the data of the" + + "selected group from the display."; + + /** + * Sets the action enabled depending on the browser's type and + * the currently selected node. Sets the name of the action depending on + * the DataObject hosted by the currently selected node. + * @see TreeViewerAction#onDisplayChange(TreeImageDisplay) + */ + protected void onDisplayChange(TreeImageDisplay selectedDisplay) + { + if (selectedDisplay == null || + selectedDisplay.getParentDisplay() == null) { + setEnabled(false); + return; + } + Object ho = selectedDisplay.getUserObject(); + if (ho == null || !(ho instanceof GroupData)) setEnabled(false); + else { + Browser browser = model.getSelectedBrowser(); + if (browser != null) { + if (browser.getSelectedDisplays().length > 1) { + setEnabled(false); + } else { + setEnabled(true); + } + } else setEnabled(false); + } + } + + /** + * Creates a new instance. + * + * @param model Reference to the Model. Mustn't be null. + */ + public RemoveGroupNode(TreeViewer model) + { + super(model); + name = NAME; + putValue(Action.SHORT_DESCRIPTION, + UIUtilities.formatToolTipText(DESCRIPTION)); + IconManager im = IconManager.getInstance(); + putValue(Action.SMALL_ICON, im.getIcon(IconManager.DELETE)); + } + + /** + * Removes the selected node a group. + * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) + */ + public void actionPerformed(ActionEvent e) { model.removeGroup(); } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/SwitchUserAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/SwitchUserAction.java index d5a8d7601af..ebb090f242e 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/SwitchUserAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/SwitchUserAction.java @@ -29,7 +29,7 @@ import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; - +import java.util.Collection; import javax.swing.Action; import javax.swing.SwingUtilities; @@ -39,6 +39,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.IconManager; import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; +import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.util.ui.UIUtilities; import pojos.GroupData; @@ -62,7 +63,7 @@ public class SwitchUserAction { /** The name of the action. */ - private static final String NAME = "Switch User..."; + public static final String NAME = "Add User..."; /** The description of the action. */ private static final String DESCRIPTION = "Select another " + @@ -71,6 +72,59 @@ public class SwitchUserAction /** The location of the mouse pressed. */ private Point point; + /** + * Handles the group. + * + * @param group The group to handle. + */ + private void handleGroupSelection(GroupData group) + { + if (group == null) { + setEnabled(false); + return; + } + Collection l = group.getExperimenters(); + if (l == null) return; + int level = model.getGroupPermissions(group); + boolean b = false; + if (level == AdminObject.PERMISSIONS_PRIVATE) { + if (model.isLeaderOfGroup(group)) + b = l.size() > 1; + } else { + b = l.size() > 1; + } + setEnabled(b); + } + + /** + * Sets the action enabled depending on the selected type. + * @see TreeViewerAction#onDisplayChange(TreeImageDisplay) + */ + protected void onDisplayChange(TreeImageDisplay selectedDisplay) + { + if (selectedDisplay == null) { + setEnabled(false); + return; + } + handleGroupSelection(model.getSelectedGroup()); + /* + Browser browser = model.getSelectedBrowser(); + if (browser == null) { + setEnabled(false); + return; + } + TreeImageDisplay[] selection = browser.getSelectedDisplays(); + if (selection.length == 1) { + Object ho = selectedDisplay.getUserObject(); + if (ho instanceof GroupData) { + handleGroupSelection((GroupData) ho); + } else setEnabled(false); + } else { + setEnabled(false); + } + */ + } + /** * Enables the action if the browser is not ready. * @see TreeViewerAction#onBrowserStateChange(Browser) @@ -83,21 +137,9 @@ protected void onBrowserStateChange(Browser browser) return; } if (browser.getState() == Browser.READY) { - boolean enabled = false; - GroupData group = model.getSelectedGroup(); - if (group == null) { - setEnabled(false); - return; - } - int level = model.getSelectedGroupPermissions(); - if (level == AdminObject.PERMISSIONS_PRIVATE) { - if (model.isLeaderOfSelectedGroup()) { - enabled = group.getExperimenters().size() > 1; - } - } else { - enabled = group.getExperimenters().size() > 1; - } - setEnabled(enabled); + //boolean enabled = false; + TreeImageDisplay display = browser.getLastSelectedDisplay(); + onDisplayChange(display); } else setEnabled(false); } @@ -118,6 +160,7 @@ protected void onBrowserSelection(Browser browser) public SwitchUserAction(TreeViewer model) { super(model); + setEnabled(true); name = NAME; putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION)); @@ -131,8 +174,10 @@ public SwitchUserAction(TreeViewer model) */ public void actionPerformed(ActionEvent e) { - SwingUtilities.convertPointToScreen(point, - (Component) e.getSource()); + if (point != null) { + SwingUtilities.convertPointToScreen(point, + ((Component) e.getSource())); + } model.retrieveUserGroups(point); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/TaggingAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/TaggingAction.java index 2ba201a3c16..e71539d4050 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/TaggingAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/TaggingAction.java @@ -25,6 +25,10 @@ //Java imports import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + import javax.swing.Action; //Third-party libraries @@ -35,9 +39,13 @@ import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; import org.openmicroscopy.shoola.util.ui.UIUtilities; + +import pojos.DataObject; import pojos.DatasetData; import pojos.ImageData; +import pojos.PlateData; import pojos.ProjectData; +import pojos.ScreenData; /** * Action to launch the available tags. @@ -97,9 +105,21 @@ protected void onDisplayChange(TreeImageDisplay selectedDisplay) } Object ho = selectedDisplay.getUserObject(); - if ((ho instanceof DatasetData) || (ho instanceof ProjectData) || - (ho instanceof ImageData)) { - setEnabled(model.isObjectWritable(ho)); + if (ho instanceof DatasetData || ho instanceof ProjectData || + ho instanceof ImageData || ho instanceof ScreenData || + ho instanceof PlateData) { + if (model.isObjectWritable(ho)) { + List selected = browser.getSelectedDataObjects(); + List ids = new ArrayList(); + Iterator i = selected.iterator(); + DataObject data; + while (i.hasNext()) { + data = (DataObject) i.next(); + if (!ids.contains(data.getGroupId())) + ids.add(data.getGroupId()); + } + setEnabled(ids.size() == 1); + } else setEnabled(false); } else setEnabled(false); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/UploadScriptAction.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/UploadScriptAction.java index e26858c1dc6..86e5a739b36 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/UploadScriptAction.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/actions/UploadScriptAction.java @@ -101,7 +101,8 @@ public void propertyChange(PropertyChangeEvent evt) { } ScriptActivityParam p = new ScriptActivityParam(script, ScriptActivityParam.UPLOAD); - un.notifyActivity(p); + //TODO:review + //un.notifyActivity(p); } } }); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/Browser.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/Browser.java index 2e000b7775e..e20d8ea9beb 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/Browser.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/Browser.java @@ -46,9 +46,11 @@ import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; import org.openmicroscopy.shoola.env.data.FSFileSystemView; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.ui.component.ObservableComponent; import pojos.DataObject; import pojos.ExperimenterData; +import pojos.GroupData; import pojos.ImageData; /** @@ -312,9 +314,11 @@ public void setLeaves(Collection leaves, TreeImageSet parent, * Returns the nodes linked to the specified user. * * @param userID The identifier of the user. + * @param node The selected node. * @return See above. */ - public List getNodesForUser(long userID); + public List getNodesForUser(long userID, TreeImageDisplay + node); /** * Collapses the specified node. @@ -395,13 +399,6 @@ public void setLeaves(Collection leaves, TreeImageSet parent, */ public void refreshTree(Object refNode, DataObject toBrowse); - /** - * The id of the root level. - * - * @return See above. - */ - public long getRootID(); - /** * Sets the number of items contained in the specified container. * @@ -521,12 +518,11 @@ public void loadExperimenterData(TreeImageDisplay expNode, /** * Adds the passed experimenter to the display. * - * @param experimenter The experimenter to add. - * Mustn't be null. - * @param load Pass true to load the data, - * false otherwise. + * @param experimenter The experimenter to add. Mustn't be null. + * @param groupID The identifier of the group the experimenter has to be + * added. */ - public void addExperimenter(ExperimenterData experimenter, boolean load); + public void addExperimenter(ExperimenterData experimenter, long groupID); /** * Removes the experimenter's data from the display. @@ -545,8 +541,9 @@ public void loadExperimenterData(TreeImageDisplay expNode, * @param type The type of data object to select or null. * @param id The identifier of the data object. */ - public void setRefreshExperimenterData(Map - def, Class type, long id); + public void setRefreshExperimenterData( + Map def, Class type, + long id); /** Refreshes the data used by the currently logged in user. */ public void refreshLoggedExperimenterData(); @@ -577,7 +574,7 @@ public void setRefreshExperimenterData(Map * @return See above. */ ExperimenterData getNodeOwner(TreeImageDisplay node); - + /** * Sets the node the user wished to save before being prompt with * the Save data message box. @@ -727,13 +724,6 @@ public void onDeselectedNode(Object parent, Object selected, */ void setExperimenters(TreeImageSet node, List result); - /** - * Returns the id to the group selected for the current user. - * - * @return See above. - */ - long getUserGroupID(); - /** * Returns true if the user currently logged in is the * owner of the object, false otherwise. @@ -796,4 +786,26 @@ public void onDeselectedNode(Object parent, Object selected, /** Indicates that the transfer has been rejected.*/ void rejectTransfer(); + /** + * Returns the security context. + * + * @param node The node to handle + * @return See above. + */ + SecurityContext getSecurityContext(TreeImageDisplay node); + + /** + * Adds the specified group to the tree. + * + * @param group The selected group. + */ + void setUserGroup(GroupData group, boolean add); + + /** + * Removes the specified group from the display + * + * @param group The group to remove. + */ + void removeGroup(GroupData group); + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserComponent.java index 415fa6ee450..ec73df456f1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserComponent.java @@ -28,6 +28,7 @@ import java.awt.Cursor; import java.awt.Point; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -51,6 +52,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.RefreshExperimenterDef; import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; import org.openmicroscopy.shoola.agents.treeviewer.cmd.EditVisitor; +import org.openmicroscopy.shoola.agents.treeviewer.cmd.ExperimenterVisitor; import org.openmicroscopy.shoola.agents.treeviewer.cmd.ParentVisitor; import org.openmicroscopy.shoola.agents.treeviewer.cmd.RefreshVisitor; import org.openmicroscopy.shoola.agents.treeviewer.view.TreeViewer; @@ -68,6 +70,7 @@ import org.openmicroscopy.shoola.agents.util.dnd.DnDTree; import org.openmicroscopy.shoola.env.data.FSAccessException; import org.openmicroscopy.shoola.env.data.FSFileSystemView; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.util.ui.component.AbstractComponent; @@ -116,6 +119,81 @@ class BrowserComponent /** The node to select after saving data. */ private TreeImageDisplay toSelectAfterSave; + /** + * Reloads the data for the specified experimenters. + * + * @param ids The id of the experimenters. + */ + private void refreshExperimenterData(List ids) + { + RefreshExperimenterDef def; + RefreshVisitor v = new RefreshVisitor(this); + TreeImageDisplay root = view.getTreeRoot(); + //root.setToRefresh(false); + int n = root.getChildCount(); + Map + m = new HashMap(n); + Collection foundNodes; + Map topNodes; + int type = model.getBrowserType(); + Iterator j; + TreeImageSet expNode, groupNode; + List children; + long gid; + SecurityContext ctx; + if (model.isSingleGroup()) { + gid = model.getUserDetails().getDefaultGroup().getId(); + for (int i = 0; i < n; i++) { + expNode = (TreeImageSet) root.getChildAt(i); + if (expNode.isExpanded() && expNode.isChildrenLoaded()) { + expNode.accept(v, + TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + foundNodes = v.getFoundNodes(); + topNodes = v.getExpandedTopNodes(); + //reset the flag + if (type == Browser.IMAGES_EXPLORER) + countExperimenterImages(expNode); + def = new RefreshExperimenterDef(expNode, + v.getFoundNodes(), + v.getExpandedTopNodes()); + ctx = new SecurityContext(gid); + ctx.setExperimenter(expNode.getUserObjectId()); + m.put(ctx, def); + } + } + } else { + for (int i = 0; i < n; i++) { + groupNode = (TreeImageSet) root.getChildAt(i); + if (groupNode.isExpanded()) { + gid = groupNode.getUserObjectId(); + children = groupNode.getChildrenDisplay(); + j = children.iterator(); + while (j.hasNext()) { + expNode = (TreeImageSet) j.next(); + if (expNode.isChildrenLoaded() && + ids.contains(expNode.getUserObjectId())) { + expNode.accept(v, + TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + foundNodes = v.getFoundNodes(); + topNodes = v.getExpandedTopNodes(); + //reset the flag + if (type == Browser.IMAGES_EXPLORER) + countExperimenterImages(expNode); + def = new RefreshExperimenterDef(expNode, + v.getFoundNodes(), + v.getExpandedTopNodes()); + ctx = new SecurityContext(gid); + ctx.setExperimenter(expNode.getUserObjectId()); + m.put(ctx, def); + } + } + } + } + } + model.loadRefreshExperimenterData(m, null, -1, null, null); + fireStateChange(); + } + /** * Helper method to remove the collection of the specified nodes. * @@ -148,26 +226,18 @@ private void createNodes(List nodes, TreeImageDisplay display, setSelectedDisplay(display); Object ho = display.getUserObject(); if ((ho instanceof ProjectData) || (ho instanceof ScreenData)) - display.setChildrenLoaded(Boolean.TRUE); + display.setChildrenLoaded(Boolean.valueOf(true)); else if (ho instanceof TagAnnotationData) { TagAnnotationData tag = (TagAnnotationData) ho; if (TagAnnotationData.INSIGHT_TAGSET_NS.equals(tag.getNameSpace())) - display.setChildrenLoaded(Boolean.TRUE); - else display.setChildrenLoaded(Boolean.FALSE); + display.setChildrenLoaded(Boolean.valueOf(true)); + else display.setChildrenLoaded(Boolean.valueOf(false)); } else { - display.setChildrenLoaded(Boolean.FALSE); + display.setChildrenLoaded(Boolean.valueOf(false)); } view.createNodes(nodes, display, parentDisplay); //Object o = display.getUserObject(); - countItems(null); - /* - if (o instanceof DatasetData) {// || o instanceof TagAnnotationData) { - Set ids = new HashSet(); - ids.add((DataObject) o); - //countItems(ids); - - //model.fireContainerCountLoading(ids); - }*/ + countItems(null, display); } /** @@ -217,8 +287,9 @@ private void countExperimenterDataInFolders() * Retrieves the nodes to count the value for. * * @param rootType The type of node to track. + * @param node The node to visit. */ - private void countItems(List rootType) + private void countItems(List rootType, TreeImageDisplay node) { if (rootType == null) { int type = model.getBrowserType(); @@ -238,11 +309,23 @@ private void countItems(List rootType) return; } ContainerFinder finder = new ContainerFinder(rootType); - accept(finder, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); - Set items = finder.getContainers(); - Set nodes = finder.getContainerNodes(); - if (items.size() == 0 && nodes.size() == 0) return; - model.fireContainerCountLoading(items, nodes); + Set items; + Set nodes; + if (node != null) { + node.accept(finder, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + items = finder.getContainers(); + nodes = finder.getContainerNodes(); + if (items.size() == 0 && nodes.size() == 0) return; + model.fireContainerCountLoading(items, nodes, node); + } else { + // + TreeImageDisplay root = view.getTreeRoot(); + List l = root.getChildrenDisplay(); + Iterator i = l.iterator(); + while (i.hasNext()) { + countItems(rootType, (TreeImageDisplay) i.next()); + } + } } /** @@ -260,11 +343,11 @@ private void countItemsInAnnotation(TreeImageSet node) } if (types.size() == 0) return; ContainerFinder finder = new ContainerFinder(types); - accept(finder, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + node.accept(finder, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); Set items = finder.getContainers(); Set nodes = finder.getContainerNodes(); if (items.size() == 0 && nodes.size() == 0) return; - model.fireContainerCountLoading(items, nodes); + model.fireContainerCountLoading(items, nodes, node); } /** @@ -363,7 +446,14 @@ public void activate() int state = model.getState(); switch (state) { case NEW: - view.loadExperimenterData(); + if (model.getBrowserType() == ADMIN_EXPLORER) { + model.fireExperimenterDataLoading(null); + return; + } + TreeImageDisplay node = getLoggedExperimenterNode(); + if (model.isSingleGroup()) node.setExpanded(true); + else node.getParentDisplay().setExpanded(true); + view.expandNode(node, true); break; case READY: refreshBrowser(); //do we want to automatically refresh? @@ -467,10 +557,9 @@ public void setLeaves(Collection leaves, TreeImageSet parent, } ExperimenterData exp = (ExperimenterData) ho; long userID = exp.getId(); - long groupID = exp.getDefaultGroup().getId(); - + Set visLeaves = TreeViewerTranslator.transformHierarchy(leaves, userID, - groupID); + -1); view.setLeavesViews(visLeaves, parent); model.setState(READY); @@ -482,7 +571,7 @@ public void setLeaves(Collection leaves, TreeImageSet parent, parent instanceof TreeFileSet) { List types = new ArrayList(); types.add(TagAnnotationData.class); - countItems(types); + countItems(types, expNode); } Object p = null; if (parent != null && @@ -666,19 +755,6 @@ public void sortTreeNodes(int sortType) view.sortNodes(sortType); view.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } - - /** - * Implemented as specified by the {@link Browser} interface. - * @see Browser#getRootID() - */ - public long getRootID() - { - if (model.getState() == DISCARDED) - throw new IllegalStateException( - "This method can't only be invoked in the DISCARDED " + - "state."); - return model.getRootID(); - } /** * Implemented as specified by the {@link Browser} interface. @@ -810,7 +886,7 @@ public void refreshEdition(DataObject object, DataObject parent, int op) Object o = object; List nodes = null; TreeImageDisplay parentDisplay = null; - TreeImageDisplay loggedUser = view.getLoggedExperimenterNode(); + TreeImageDisplay loggedUser = getLoggedExperimenterNode(); if (op == TreeViewer.CREATE_OBJECT) { TreeImageDisplay node = getLastSelectedDisplay(); if ((object instanceof ProjectData) || @@ -841,13 +917,12 @@ public void refreshEdition(DataObject object, DataObject parent, int op) else if (op == TreeViewer.REMOVE_OBJECT) removeNodes(nodes); else if (op == TreeViewer.CREATE_OBJECT) { long userID = model.getUserID(); - long groupID = model.getUserGroupID(); //Get the user node. if (parentDisplay == null) parentDisplay = getLastSelectedDisplay(); TreeImageDisplay newNode = TreeViewerTranslator.transformDataObject(object, userID, - groupID); + -1); createNodes(nodes, newNode, parentDisplay); } @@ -866,15 +941,14 @@ public void onOrphanDataObjectCreated(DataObject data) } else if (data instanceof TagAnnotationData) { if (type != TAGS_EXPLORER) return; } - TreeImageDisplay loggedUser = view.getLoggedExperimenterNode(); + TreeImageDisplay loggedUser = getLoggedExperimenterNode(); List nodes = new ArrayList(1); nodes.add(loggedUser); long userID = model.getUserID(); //long model.get - long groupID = model.getUserGroupID(); createNodes(nodes, TreeViewerTranslator.transformDataObject(data, userID, - groupID), loggedUser); + -1), loggedUser); setSelectedNode(); } @@ -991,7 +1065,7 @@ public void setRefreshedHierarchy(Map nodes, Map expandedTopNodes) //long groupID = model.getUserGroupID(); //view.setViews(TreeViewerTranslator.refreshHierarchy(nodes, // expandedTopNodes, userID, groupID)); - countItems(null); + countItems(null, null); model.getParentModel().setStatus(false, "", true); PartialNameVisitor v = new PartialNameVisitor(view.isPartialName()); accept(v, TreeImageDisplayVisitor.TREEIMAGE_NODE_ONLY); @@ -1106,13 +1180,14 @@ public void setExperimenterData(TreeImageDisplay expNode, Collection nodes) view.setExperimenterData(convertedNodes, expNode); model.setState(READY); - countItems(null); + countItems(null, expNode); countExperimenterDataInFolders(); model.getParentModel().setStatus(false, "", true); //Visit the tree and switch(model.getBrowserType()) { case Browser.PROJECTS_EXPLORER: case Browser.SCREENS_EXPLORER: + //TODO: review that code to indicate the context. ParentVisitor visitor = new ParentVisitor(); accept(visitor, ParentVisitor.TREEIMAGE_SET_ONLY); EventBus bus = TreeViewerAgent.getRegistry().getEventBus(); @@ -1123,21 +1198,35 @@ public void setExperimenterData(TreeImageDisplay expNode, Collection nodes) /** * Implemented as specified by the {@link Browser} interface. - * @see Browser#addExperimenter(ExperimenterData, boolean) + * @see Browser#addExperimenter(ExperimenterData, long) */ - public void addExperimenter(ExperimenterData experimenter, boolean load) + public void addExperimenter(ExperimenterData experimenter, long groupID) { if (experimenter == null) throw new IllegalArgumentException("Experimenter cannot be null."); + if (model.getBrowserType() == ADMIN_EXPLORER) return; + TreeImageDisplay node = model.getLastSelectedDisplay(); + if (model.isSingleGroup()) { + node = view.getTreeRoot(); + } else { + //Find the group + System.err.println("group:"+groupID); + ExperimenterVisitor v = new ExperimenterVisitor(this, groupID); + accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + List list = v.getNodes(); + if (list.size() == 0) return; + node = list.get(0); + } + //Make sure the user is not already display List nodes = new ArrayList(1); nodes.add(new TreeImageSet(experimenter)); SimilarNodesVisitor visitor = new SimilarNodesVisitor(nodes); - accept(visitor, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + node.accept(visitor, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); if (visitor.getFoundNodes().size() > 0) return; setSelectedDisplay(null); - view.addExperimenter(experimenter, load); + view.addExperimenter(experimenter, node); } /** @@ -1172,22 +1261,24 @@ public void refreshExperimenterData() if (model.getBrowserType() == ADMIN_EXPLORER) { display = view.getTreeRoot(); id = TreeViewerAgent.getUserDetails().getId(); + //review for admin. + display.accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + RefreshExperimenterDef def = new RefreshExperimenterDef( + (TreeImageSet) display, v.getFoundNodes(), + v.getExpandedTopNodes()); + Map + m = new HashMap(1); + m.put(id, def); + fireStateChange(); + //model.loadRefreshExperimenterData(m, null, -1, null, null); + } else { display = model.getLastSelectedDisplay(); if (display == null) return; Object ho = display.getUserObject(); if (!(ho instanceof ExperimenterData)) return; - id = display.getUserObjectId(); + refreshExperimenterData(Arrays.asList(display.getUserObjectId())); } - display.accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); - RefreshExperimenterDef def = new RefreshExperimenterDef( - (TreeImageSet) display, - v.getFoundNodes(), v.getExpandedTopNodes()); - Map - m = new HashMap(1); - m.put(id, def); - model.loadRefreshExperimenterData(m, null, -1, null, null); - fireStateChange(); } /** @@ -1196,9 +1287,18 @@ public void refreshExperimenterData() */ public TreeImageDisplay getLoggedExperimenterNode() { - return view.getLoggedExperimenterNode(); + SecurityContext ctx = model.getSecurityContext(null); + long id = ctx.getGroupID(); + if (model.isSingleGroup()) id = -1; + ExperimenterVisitor visitor = new ExperimenterVisitor(this, + model.getUserID(), id); + accept(visitor, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + List nodes = visitor.getNodes(); + if (nodes.size() != 1) return null; + return nodes.get(0); } + /** * Implemented as specified by the {@link Browser} interface. * @see Browser#refreshLoggedExperimenterData() @@ -1214,20 +1314,11 @@ public void refreshLoggedExperimenterData() //ignore return; } - TreeImageDisplay node = view.getLoggedExperimenterNode(); + TreeImageDisplay node = getLoggedExperimenterNode(); if (node == null) return; Object ho = node.getUserObject(); if (!(ho instanceof ExperimenterData)) return; - // - RefreshVisitor v = new RefreshVisitor(this); - node.accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); - RefreshExperimenterDef def = new RefreshExperimenterDef( - (TreeImageSet) node, - v.getFoundNodes(), v.getExpandedTopNodes()); - Map - m = new HashMap(1); - m.put(node.getUserObjectId(), def); - model.loadRefreshExperimenterData(m, null, -1, null, null); + refreshExperimenterData(Arrays.asList(node.getUserObjectId())); fireStateChange(); } @@ -1258,28 +1349,70 @@ public void refreshTree(Object refNode, DataObject toBrowse) TreeImageDisplay root = view.getTreeRoot(); //root.setToRefresh(false); - TreeImageSet expNode; + RefreshExperimenterDef def; RefreshVisitor v = new RefreshVisitor(this); int n = root.getChildCount(); - Map - m = new HashMap(n); + Map + m = new HashMap(n); Collection foundNodes; Map topNodes; int type = model.getBrowserType(); Iterator j; - for (int i = 0; i < n; i++) { - expNode = (TreeImageSet) root.getChildAt(i); - expNode.accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); - foundNodes = v.getFoundNodes(); - topNodes = v.getExpandedTopNodes(); - //reset the flag - if (type == Browser.IMAGES_EXPLORER) - countExperimenterImages(expNode); - def = new RefreshExperimenterDef(expNode, v.getFoundNodes(), - v.getExpandedTopNodes()); - m.put(expNode.getUserObjectId(), def); - } + TreeImageSet expNode, groupNode; + List children; + long gid; + SecurityContext ctx; + if (model.isSingleGroup()) { + gid = model.getUserDetails().getDefaultGroup().getId(); + for (int i = 0; i < n; i++) { + expNode = (TreeImageSet) root.getChildAt(i); + if (expNode.isExpanded() && expNode.isChildrenLoaded()) { + expNode.accept(v, + TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + foundNodes = v.getFoundNodes(); + topNodes = v.getExpandedTopNodes(); + //reset the flag + if (type == Browser.IMAGES_EXPLORER) + countExperimenterImages(expNode); + def = new RefreshExperimenterDef(expNode, + v.getFoundNodes(), + v.getExpandedTopNodes()); + ctx = new SecurityContext(gid); + ctx.setExperimenter(expNode.getUserObjectId()); + m.put(ctx, def); + } + } + } else { + for (int i = 0; i < n; i++) { + groupNode = (TreeImageSet) root.getChildAt(i); + if (groupNode.isExpanded()) { + gid = groupNode.getUserObjectId(); + children = groupNode.getChildrenDisplay(); + j = children.iterator(); + while (j.hasNext()) { + expNode = (TreeImageSet) j.next(); + if (expNode.isChildrenLoaded()) { + expNode.accept(v, + TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + foundNodes = v.getFoundNodes(); + topNodes = v.getExpandedTopNodes(); + //reset the flag + if (type == Browser.IMAGES_EXPLORER) + countExperimenterImages(expNode); + def = new RefreshExperimenterDef(expNode, + v.getFoundNodes(), + v.getExpandedTopNodes()); + ctx = new SecurityContext(gid); + ctx.setExperimenter(expNode.getUserObjectId()); + m.put(ctx, def); + } + } + } + } + } + + if (m.size() == 0) return; model.loadRefreshExperimenterData(m, null, -1, refNode, toBrowse); fireStateChange(); } @@ -1288,30 +1421,35 @@ public void refreshTree(Object refNode, DataObject toBrowse) * Implemented as specified by the {@link Browser} interface. * @see Browser#setRefreshExperimenterData(Map, Class, long) */ - public void setRefreshExperimenterData(Map + public void setRefreshExperimenterData( + Map nodes, Class type, long id) { //TODO: Should reselect the node previously selected. if (nodes == null || nodes.size() == 0) { model.setSelectedDisplay(null, true); model.setState(READY); - countItems(null); + countItems(null, null); if (model.getBrowserType() == TAGS_EXPLORER) countExperimenterDataInFolders(); model.getParentModel().setStatus(false, "", true); return; } - Iterator i = nodes.keySet().iterator(); + Iterator i = nodes.entrySet().iterator(); RefreshExperimenterDef node; TreeImageSet expNode; ExperimenterData exp; Set convertedNodes; long userId; + Entry entry; int browserType = model.getBrowserType(); Map results; + SecurityContext ctx; while (i.hasNext()) { - userId = (Long) i.next(); - node = nodes.get(userId); + entry = (Entry) i.next(); + ctx = (SecurityContext) entry.getKey(); + //userId = (Long) + node = (RefreshExperimenterDef) entry.getValue(); expNode = node.getExperimenterNode(); exp = (ExperimenterData) expNode.getUserObject(); if (browserType == IMAGES_EXPLORER || browserType == FILES_EXPLORER) @@ -1327,18 +1465,21 @@ public void setRefreshExperimenterData(Map } } //expand the nodes. - i = nodes.keySet().iterator(); + i = nodes.entrySet().iterator(); Map m; - Entry entry; Iterator j; + Entry e; NodesFinder finder; if (type == null) { List l; Iterator k; Set found; while (i.hasNext()) { - userId = (Long) i.next(); - node = nodes.get(userId); + //userId = (Long) i.next(); + //node = nodes.get(userId); + entry = (Entry) i.next(); + //userId = (Long) + node = (RefreshExperimenterDef) entry.getValue(); expNode = node.getExperimenterNode(); if (expNode.isExpanded()) { m = node.getExpandedTopNodes(); @@ -1346,9 +1487,9 @@ public void setRefreshExperimenterData(Map node.getExpandedNodes().size() == 0) { j = m.entrySet().iterator(); while (j.hasNext()) { - entry = (Entry) j.next(); - finder = new NodesFinder((Class) entry.getKey(), - (List) entry.getValue()); + e = (Entry) j.next(); + finder = new NodesFinder((Class) e.getKey(), + (List) e.getValue()); accept(finder); found = finder.getNodes(); if (found.size() > 0) { @@ -1365,15 +1506,27 @@ public void setRefreshExperimenterData(Map model.setSelectedDisplay(null, true); model.setState(READY); - - if (model.getBrowserType() == TAGS_EXPLORER) { - List types = new ArrayList(); - types.add(TagAnnotationData.class); - types.add(DatasetData.class); - countItems(types); - countExperimenterDataInFolders(); - } else countItems(null); - + switch (model.getBrowserType()) { + case TAGS_EXPLORER: + List types = new ArrayList(); + types.add(TagAnnotationData.class); + types.add(DatasetData.class); + countItems(types, null); + countExperimenterDataInFolders(); + break; + case ADMIN_EXPLORER: + countItems(null, null); + break; + default: + TreeImageDisplay root = view.getTreeRoot(); + TreeImageSet groupNode; + for (int k = 0; k < root.getChildCount(); k++) { + groupNode = (TreeImageSet) root.getChildAt(k); + if (groupNode.isExpanded()) { + countItems(null, groupNode); + } + } + } model.getParentModel().setStatus(false, "", true); PartialNameVisitor v = new PartialNameVisitor(view.isPartialName()); accept(v, TreeImageDisplayVisitor.TREEIMAGE_NODE_ONLY); @@ -1468,7 +1621,16 @@ public ExperimenterData getNodeOwner(TreeImageDisplay node) if (n == null) return model.getUserDetails(); return (ExperimenterData) n.getUserObject(); } - + + /** + * Implemented as specified by the {@link Browser} interface. + * @see Browser#getSecurityContext(TreeImageDisplay) + */ + public SecurityContext getSecurityContext(TreeImageDisplay node) + { + return model.getSecurityContext(node); + } + /** * Implemented as specified by the {@link Browser} interface. * @see Browser#getClickComponent() @@ -1505,7 +1667,20 @@ public void refreshAdmin(Object data) refreshBrowser(); setSelectedDisplay(node, true); } else { - if (data instanceof ExperimenterData) view.refreshExperimenter(); + if (data instanceof ExperimenterData) { + ExperimenterData exp = (ExperimenterData) data; + ExperimenterVisitor v = new ExperimenterVisitor(this, + exp.getId(), -1); + accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + List l = v.getNodes(); + Iterator i = l.iterator(); + TreeImageDisplay n; + while (i.hasNext()) { + n = i.next(); + n.setUserObject(model.getUserDetails()); + view.reloadNode(n); + } + } } } @@ -1696,14 +1871,15 @@ public void removeTreeNodes(Collection nodes) /** * Implemented as specified by the {@link Browser} interface. - * @see Browser#removeTreeNodes(List) + * @see Browser#reActivate() */ public void reActivate() { view.reActivate(); if (!model.isSelected()) return; //Reload data. - view.loadExperimenterData(); + //TreeImageDisplay node = getLoggedExperimenterNode(); + //view.expandNode(node, true); } /** @@ -1729,7 +1905,7 @@ public void setRepositories(TreeImageDisplay expNode, throw new IllegalArgumentException("Experimenter node not valid."); model.setRepositories(systemView); view.loadFileSystem(expNode); - countItems(null); + countItems(null, expNode); model.getParentModel().setStatus(false, "", true); fireStateChange(); } @@ -1751,7 +1927,7 @@ public void setGroups(Collection groups, List expanded) Set nodes = TreeViewerTranslator.transformGroups(groups); view.setGroups(nodes, expanded); model.setState(READY); - countItems(null); + countItems(null, null); model.getParentModel().setStatus(false, "", true); fireStateChange(); } @@ -1817,18 +1993,6 @@ public void setExperimenters(TreeImageSet node, List result) fireStateChange(); } - /** - * Implemented as specified by the {@link Browser} interface. - * @see Browser#getUserGroupID() - */ - public long getUserGroupID() - { - if (model.getState() == DISCARDED) - throw new IllegalStateException( - "This method cannot be invoked in the DISCARDED state."); - return model.getUserGroupID(); - } - /** * Implemented as specified by the {@link Browser} interface. * @see Browser#isObjectWritable(Object) @@ -1854,7 +2018,16 @@ public boolean canDeleteObject(Object ho) public void expandUser() { if (model.getState() == DISCARDED) return; - view.expandUser(); + SecurityContext ctx = model.getSecurityContext( + model.getLastSelectedDisplay()); + long id = model.getUserID(); + ExperimenterVisitor v = new ExperimenterVisitor(this, id, + ctx.getGroupID()); + accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + List values = v.getNodes(); + if (values.size() != 1) return; + TreeImageDisplay n = values.get(0); + if (!n.isExpanded()) view.expandNode(n); } /** @@ -1876,29 +2049,16 @@ public void refreshBrowser(Class type, long id) if (ProjectData.class.equals(type) || DatasetData.class.equals(type) || ScreenData.class.equals(type)) { - TreeImageDisplay root = view.getTreeRoot(); - TreeImageSet expNode; - RefreshExperimenterDef def; - RefreshVisitor v = new RefreshVisitor(this); - int n = root.getChildCount(); - Map - m = new HashMap(n); - Collection foundNodes; - Map topNodes; - int index = model.getBrowserType(); - for (int i = 0; i < n; i++) { - expNode = (TreeImageSet) root.getChildAt(i); - expNode.accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); - foundNodes = v.getFoundNodes(); - topNodes = v.getExpandedTopNodes(); - if (index == Browser.IMAGES_EXPLORER) - countExperimenterImages(expNode); - def = new RefreshExperimenterDef(expNode, v.getFoundNodes(), - v.getExpandedTopNodes()); - m.put(expNode.getUserObjectId(), def); + ExperimenterVisitor visitor = new ExperimenterVisitor(this, -1, -1); + accept(visitor, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + List nodes = visitor.getNodes(); + if (nodes.size() == 0) return; + Iterator i = nodes.iterator(); + List ids = new ArrayList(nodes.size()); + while (i.hasNext()) { + ids.add(i.next().getUserObjectId()); } - model.loadRefreshExperimenterData(m, type, id, null, null); - fireStateChange(); + refreshExperimenterData(ids); } } @@ -1931,13 +2091,21 @@ public void loadDirectory(TreeImageDisplay display) /** * Implemented as specified by the {@link Browser} interface. - * @see Browser#getNodesForUser(long) + * @see Browser#getNodesForUser(long, TreeImageDisplay) */ - public List getNodesForUser(long userID) + public List getNodesForUser(long userID, TreeImageDisplay + node) { if (model.getState() == DISCARDED) return null; if (userID < 0) return null; - return view.getNodesForUser(userID); + SecurityContext context = model.getSecurityContext(node); + ExperimenterVisitor v = new ExperimenterVisitor(this, userID, + context.getGroupID()); + accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + List nodes = v.getNodes(); + if (nodes .size() != 1) return new ArrayList(); + TreeImageDisplay n = nodes.get(0); + return n.getChildrenDisplay(); } /** @@ -1952,4 +2120,25 @@ public void rejectTransfer() } } + /** + * Implemented as specified by the {@link Browser} interface. + * @see Browser#setUserGroup(GroupData, boolean) + */ + public void setUserGroup(GroupData group, boolean add) + { + if (group == null) + throw new IllegalArgumentException("Group cannot be null."); + view.setUserGroup(group, add); + } + + /** + * Implemented as specified by the {@link Browser} interface. + * @see Browser#removeGroup(GroupData) + */ + public void removeGroup(GroupData group) + { + if (group == null) return; + view.removeGroup(group); + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserControl.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserControl.java index 0dffb4845bb..179e09cd6aa 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserControl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserControl.java @@ -273,21 +273,33 @@ void onNodeNavigation(TreeImageDisplay display, boolean expanded) if (display.getNumberOfItems() == 0) return; } - view.loadAction(display); + if ((display instanceof TreeImageTimeSet) || (display instanceof TreeFileSet)) { + view.loadAction(display); model.loadExperimenterData(BrowserFactory.getDataOwner(display), display); return; } if ((ho instanceof DatasetData) || (ho instanceof TagAnnotationData) ) {//|| (ho instanceof PlateData)) { + view.loadAction(display); model.loadExperimenterData(BrowserFactory.getDataOwner(display), display); } else if (ho instanceof ExperimenterData) { + view.loadAction(display); model.loadExperimenterData(display, null); } else if (ho instanceof GroupData) { - model.loadExperimenterData(display, display); + if (browserType == Browser.ADMIN_EXPLORER) { + view.loadAction(display); + model.loadExperimenterData(display, display); + } else { + //Load the data of the logged in user. + List l = display.getChildrenDisplay(); + if (l != null & l.size() > 0) { + view.expandNode((TreeImageDisplay) l.get(0), true); + } + } } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserModel.java index 6ffaeec1877..76d9063937b 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserModel.java @@ -46,7 +46,6 @@ import org.openmicroscopy.shoola.agents.treeviewer.ExperimenterDataLoader; import org.openmicroscopy.shoola.agents.treeviewer.ExperimenterImageLoader; import org.openmicroscopy.shoola.agents.treeviewer.ExperimenterImagesCounter; -import org.openmicroscopy.shoola.agents.treeviewer.FilesChecker; import org.openmicroscopy.shoola.agents.treeviewer.RefreshExperimenterDataLoader; import org.openmicroscopy.shoola.agents.treeviewer.RefreshExperimenterDef; import org.openmicroscopy.shoola.agents.treeviewer.ScreenPlateLoader; @@ -56,12 +55,12 @@ import org.openmicroscopy.shoola.agents.util.EditorUtil; import org.openmicroscopy.shoola.agents.util.browser.TreeFileSet; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; -import org.openmicroscopy.shoola.agents.util.browser.TreeImageNode; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.data.FSAccessException; import org.openmicroscopy.shoola.env.data.FSFileSystemView; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.log.LogMessage; import pojos.DataObject; import pojos.DatasetData; @@ -154,6 +153,9 @@ class BrowserModel /** Reference to the component that embeds this model. */ protected Browser component; + /** The security context for the administrator.*/ + //private SecurityContext adminContext; + /** * Checks if the specified browser is valid. * @@ -181,7 +183,7 @@ private void checkBrowserType(int type) * @param browserType The browser's type. One of the type defined by * the {@link Browser}. * @param parent Reference to the parent. - * @param experimenter The experimenter this browser is for. + * @param experimenter The experimenter this browser is for. */ protected BrowserModel(int browserType, TreeViewer parent) { @@ -193,6 +195,7 @@ protected BrowserModel(int browserType, TreeViewer parent) foundNodeIndex = -1; selectedNodes = new ArrayList(); displayed = true; + //adminContext = TreeViewerAgent.getAdminContext(); } /** @@ -217,21 +220,6 @@ protected BrowserModel(int browserType, TreeViewer parent) * One of the state constants defined by the {@link Browser}. */ void setState(int state) { this.state = state; } - - /** - * Returns the root ID. - * - * @return See above. - */ - long getRootID() { return parent.getUserDetails().getId(); } - - /** - * Returns the id to the group selected for the current user. - * - * @return See above. - */ - long getGroupID() { return parent.getUserGroupID(); } - /** * Returns the currently selected node. * @@ -337,24 +325,27 @@ void addFoundNode(TreeImageDisplay selectedDisplay) void fireLeavesLoading(TreeImageDisplay expNode, TreeImageDisplay node) { state = Browser.LOADING_LEAVES; + SecurityContext ctx = getSecurityContext(expNode); if (node instanceof TreeImageTimeSet || node instanceof TreeFileSet) { - currentLoader = new ExperimenterImageLoader(component, + currentLoader = new ExperimenterImageLoader(component, ctx, (TreeImageSet) expNode, (TreeImageSet) node); currentLoader.load(); } else { Object ho = node.getUserObject(); if (ho instanceof DatasetData) { - currentLoader = new ExperimenterDataLoader(component, + currentLoader = new ExperimenterDataLoader(component, ctx, ExperimenterDataLoader.DATASET, (TreeImageSet) expNode, (TreeImageSet) node); currentLoader.load(); } else if (ho instanceof TagAnnotationData) { - currentLoader = new ExperimenterDataLoader(component, + currentLoader = new ExperimenterDataLoader(component, ctx, ExperimenterDataLoader.TAG, (TreeImageSet) expNode, (TreeImageSet) node); currentLoader.load(); } else if (ho instanceof GroupData) { - currentLoader = new AdminLoader(component, + if (TreeViewerAgent.isAdministrator()) + ctx = TreeViewerAgent.getAdminContext();; + currentLoader = new AdminLoader(component, ctx, (TreeImageSet) expNode); currentLoader.load(); } else if (ho instanceof FileData) { @@ -375,15 +366,20 @@ void fireLeavesLoading(TreeImageDisplay expNode, TreeImageDisplay node) * @param containers The collection of DataObjects. * @param nodes The corresponding nodes. */ - void fireContainerCountLoading(Set containers, Set nodes) + void fireContainerCountLoading(Set containers, Set nodes, + TreeImageDisplay refNode) { if (containers == null || containers.size() == 0) { state = Browser.READY; return; } //state = Browser.COUNTING_ITEMS; - numberLoader = new ContainerCounterLoader(component, containers, nodes); - numberLoader.load(); + SecurityContext ctx = getSecurityContext(refNode); + if (TreeViewerAgent.isAdministrator()) + ctx = TreeViewerAgent.getAdminContext();; + ContainerCounterLoader loader = new ContainerCounterLoader(component, + ctx, containers, nodes); + loader.load(); } /** @@ -488,13 +484,6 @@ boolean setContainerCountValue(JTree tree, long containerID, long value, * @return See above. */ long getUserID() { return parent.getUserDetails().getId(); } - - /** - * Returns the id to the group selected for the current user. - * - * @return See above. - */ - long getUserGroupID() { return parent.getUserGroupID(); } /** * Returns the details of the user currently logged in. @@ -552,17 +541,17 @@ void fireExperimenterDataLoading(TreeImageSet expNode) state = Browser.LOADING_DATA; //Depending on user roles. if (TreeViewerAgent.isAdministrator()) { - currentLoader = new AdminLoader(component, null); + currentLoader = new AdminLoader(component, + TreeViewerAgent.getAdminContext(), null); currentLoader.load(); - return; } else { component.setGroups(TreeViewerAgent.getGroupsLeaderOf(), null); - return; } - + return; } + SecurityContext ctx = getSecurityContext(expNode); if (browserType == Browser.SCREENS_EXPLORER) { - currentLoader = new ScreenPlateLoader(component, expNode, + currentLoader = new ScreenPlateLoader(component, ctx, expNode, ScreenPlateLoader.SCREEN); currentLoader.load(); state = Browser.LOADING_DATA; @@ -585,7 +574,8 @@ void fireExperimenterDataLoading(TreeImageSet expNode) //index = ExperimenterDataLoader.FILE; } if (index == -1) return; - currentLoader = new ExperimenterDataLoader(component, index, expNode); + currentLoader = new ExperimenterDataLoader(component, ctx, index, + expNode); currentLoader.load(); state = Browser.LOADING_DATA; } @@ -599,7 +589,8 @@ void fireExperimenterDataLoading(TreeImageSet expNode) * @param refNode The node to hosting the data object to browse. * @param toBrowse The data object to browse. */ - void loadRefreshExperimenterData(Map nodes, + void loadRefreshExperimenterData( + Map nodes, Class type, long id, Object refNode, DataObject toBrowse) { Class klass = null; @@ -624,9 +615,10 @@ void loadRefreshExperimenterData(Map nodes, } state = Browser.LOADING_DATA; if (klass == null) return; - currentLoader = new RefreshExperimenterDataLoader(component, klass, + currentLoader = new RefreshExperimenterDataLoader(component, + getSecurityContext(null), klass, nodes, type, id, refNode, toBrowse); - currentLoader.load(); + currentLoader.load(); } /** @@ -637,6 +629,7 @@ void loadRefreshExperimenterData(Map nodes, */ void fireCountExperimenterImages(TreeImageSet expNode) { + SecurityContext ctx = getSecurityContext(expNode); List n = expNode.getChildrenDisplay(); Iterator i = n.iterator(); Set indexes = new HashSet(); @@ -665,7 +658,8 @@ void fireCountExperimenterImages(TreeImageSet expNode) if (containersManagerWithIndexes == null) containersManagerWithIndexes = new ContainersManager(indexes); state = Browser.COUNTING_ITEMS; - numberLoader = new ExperimenterImagesCounter(component, expNode, n); + numberLoader = new ExperimenterImagesCounter(component, ctx, + expNode, n); numberLoader.load(); } @@ -713,34 +707,6 @@ void browser(TreeImageDisplay node) { if (node == null) return; Object object = node.getUserObject(); - //if ((object instanceof ImageData) || (object instanceof PlateData)) { - /* - ImageData image = (ImageData) node.getUserObject(); - TreeImageDisplay pNode = node.getParentDisplay(); - DataObject pObject = null; - DataObject gpObject = null; - if (pNode != null) { - Object p = pNode.getUserObject(); - if (p instanceof DataObject) - pObject = (DataObject) p; - TreeImageDisplay gpNode = pNode.getParentDisplay(); - if (gpNode != null) { - p = gpNode.getUserObject(); - if (p instanceof DataObject) { - if (!((p instanceof ExperimenterData) || - (p instanceof GroupData))) - gpObject = (DataObject) p; - } - - } - } - Rectangle r = parent.getUI().getBounds(); - ViewImage evt = new ViewImage(image, r); - evt.setContext(pObject, gpObject); - TreeViewerAgent.getRegistry().getEventBus().post(evt); - */ - //parent.browse(node, true); - //} if (object instanceof ImageData) parent.browse(node, null, true); else if (object instanceof PlateData) { if (!node.hasChildrenDisplay() || @@ -759,7 +725,7 @@ void openFile(TreeImageDisplay node) { if (node == null) return; FileAnnotationData data = (FileAnnotationData) node.getUserObject(); - EditFileEvent evt = new EditFileEvent(data); + EditFileEvent evt = new EditFileEvent(getSecurityContext(node), data); TreeViewerAgent.getRegistry().getEventBus().post(evt); } @@ -858,19 +824,6 @@ boolean isFileImported(String path) return importedImages.get(name) != null; } - /** - * Starts an asynchronous call to check if the files hosted by the - * passed nodes can be imported. - * - * @param nodes The nodes to handle. - */ - void fireFilesCheck(List nodes) - { - if (nodes == null || nodes.size() == 0) return; - FilesChecker loader = new FilesChecker(component, nodes); - loader.load(); - } - /** Creates a {@link DeleteCmd} command to execute the action. */ void delete() { @@ -887,31 +840,6 @@ void delete() } } - /** - * Returns true if the image file format is supported, - * false otherwise. - * - * @param path The path to the file. - * @return See above. - */ - boolean isSupportedImageFormat(String path) - { - /* - if (path == null) return false; - if (path.endsWith(OmeroImageService.ZIP_EXTENSION)) return true; - - List filters = parent.getSupportedFormats(); - Iterator i = filters.iterator(); - FileFilter filter; - while (i.hasNext()) { - filter = i.next(); - if (filter.accept(new File(path))) return true; - } - return false; - */ - return false; - } - /** * Returns the object within the specified directory. * @@ -961,4 +889,54 @@ void transfer(TreeImageDisplay target, List nodes, parent.transfer(target, nodes, transferAction); } + /** + * Returns the security context. + * + * @param node The node to handle. + * @return See above + */ + SecurityContext getSecurityContext(TreeImageDisplay node) + { + if (node == null || isSingleGroup()) { + return new SecurityContext( + TreeViewerAgent.getUserDetails().getDefaultGroup().getId()); + } + if (node.getUserObject() instanceof ExperimenterData) { + TreeImageDisplay parent = node.getParentDisplay(); + GroupData group = (GroupData) parent.getUserObject(); + return new SecurityContext(group.getId()); + } + if (node.getUserObject() instanceof GroupData) { + GroupData group = (GroupData) node.getUserObject(); + return new SecurityContext(group.getId()); + } + TreeImageDisplay n = BrowserFactory.getDataOwner(node); + if (n == null || isSingleGroup()) { + return new SecurityContext( + TreeViewerAgent.getUserDetails().getDefaultGroup().getId()); + } + TreeImageDisplay parent = n.getParentDisplay(); + GroupData group = (GroupData) parent.getUserObject(); + return new SecurityContext(group.getId()); + } + + /** + * Returns the selected group. + * + * @return See above. + */ + GroupData getSelectedGroup() { return parent.getSelectedGroup(); } + + /** + * Returns true if the user belongs to one group only, + * false otherwise. + * + * @return See above + */ + boolean isSingleGroup() + { + Set l = TreeViewerAgent.getAvailableUserGroups(); + return l.size() <= 1; + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserUI.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserUI.java index 50ac6a2eaa2..36b7ad9bf48 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserUI.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/browser/BrowserUI.java @@ -410,9 +410,11 @@ private void rollOver(MouseEvent e) * Creates an experimenter node hosting the passed experimenter. * * @param exp The experimenter to add. + * @param groupNode The node to attach the experimenter to. * @return See above. */ - private TreeImageSet createExperimenterNode(ExperimenterData exp) + private TreeImageSet createExperimenterNode(ExperimenterData exp, + TreeImageDisplay groupNode) { DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); TreeImageSet node = new TreeImageSet(exp); @@ -429,9 +431,11 @@ private TreeImageSet createExperimenterNode(ExperimenterData exp) default: buildEmptyNode(node); } - TreeImageDisplay root = getTreeRoot(); - root.addChildDisplay(node); - tm.insertNodeInto(node, root, root.getChildCount()); + //TreeImageDisplay root = getTreeRoot(); + //root.addChildDisplay(node); + //tm.insertNodeInto(node, root, root.getChildCount()); + groupNode.addChildDisplay(node); + tm.insertNodeInto(node, groupNode, groupNode.getChildCount()); return node; } @@ -782,6 +786,96 @@ private void handleMultiSelection() } } + /** + * Builds the top nodes of the tree. + * + * @param exp The experimenter to attach. + * @return See above. + */ + private TreeImageDisplay buildTreeNodes(ExperimenterData exp) + { + TreeImageDisplay root = getTreeRoot(); + TreeImageDisplay node = null; + if (model.isSingleGroup()) { + node = root; + node = createExperimenterNode(exp, node); + } else { + if (TreeViewerAgent.isMultiGroups()) { + GroupData group = model.getSelectedGroup(); + List nodes = createGroups(group); + Iterator i = nodes.iterator(); + TreeImageSet n; + GroupData g; + while (i.hasNext()) { + n = i.next(); + g = (GroupData) n.getUserObject(); + n = createExperimenterNode(exp, n); + if (g.getId() == group.getId()) + node = n; + } + } else { + node = createGroup(model.getSelectedGroup()); + node = createExperimenterNode(exp, node); + } + } + return node; + } + + /** + * Creates the group nodes. + * + * @param defaultGroup The default group + * @return See above. + */ + private List createGroups(GroupData defaultGroup) + { + TreeImageDisplay root = getTreeRoot(); + DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); + //root.addChildDisplay(node); + //tm.insertNodeInto(node, root, root.getChildCount()); + + List l = new ArrayList(); + List groups = sorter.sort(TreeViewerAgent.getAvailableUserGroups()); + //sort the group first. + Iterator i = groups.iterator(); + GroupData group; + TreeImageSet n = new TreeImageSet(defaultGroup); + TreeViewerTranslator.formatToolTipFor(n); + l.add(n); + root.addChildDisplay(n); + tm.insertNodeInto(n, root, root.getChildCount()); + while (i.hasNext()) { + group = (GroupData) i.next(); + if (group.getId() != defaultGroup.getId()) { + n = new TreeImageSet(group); + TreeViewerTranslator.formatToolTipFor(n); + l.add(n); + root.addChildDisplay(n); + tm.insertNodeInto(n, root, root.getChildCount()); + } + } + return l; + } + + /** + * Creates the group node. + * + * @param group The group to add. + * @return See above. + */ + private TreeImageSet createGroup(GroupData group) + { + TreeImageDisplay root = getTreeRoot(); + DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); + //root.addChildDisplay(node); + //tm.insertNodeInto(node, root, root.getChildCount()); + TreeImageSet n = new TreeImageSet(group); + TreeViewerTranslator.formatToolTipFor(n); + root.addChildDisplay(n); + tm.insertNodeInto(n, root, root.getChildCount()); + return n; + } + /** * Helper method to create the trees hosting the display. * @@ -803,8 +897,11 @@ private void createTrees(ExperimenterData exp) treeDisplay.setShowsRootHandles(true); TreeImageSet root = new TreeImageSet(""); treeDisplay.setModel(new DefaultTreeModel(root)); - TreeImageSet node = createExperimenterNode(exp); - treeDisplay.collapsePath(new TreePath(node.getPath())); + if (model.getBrowserType() != Browser.ADMIN_EXPLORER) { + TreeImageDisplay node = buildTreeNodes(exp); + if (node != null) + treeDisplay.collapsePath(new TreePath(node.getPath())); + } //Add Listeners //treeDisplay.requestFocus(); treeDisplay.addMouseListener(new MouseAdapter() { @@ -1441,7 +1538,7 @@ void removeNodes(List nodes, TreeImageDisplay parentDisplay) * @param newNode The node to add to the parent. * @param parentDisplay The selected parent. */ - void createNodes(List nodes, TreeImageDisplay newNode, + void createNodes(List nodes, TreeImageDisplay newNode, TreeImageDisplay parentDisplay) { if (parentDisplay == null) parentDisplay = getTreeRoot(); @@ -1558,17 +1655,9 @@ void sortNodes(int type) while (j.hasNext()) { setExpandedParent((TreeImageDisplay) j.next(), true); } - } + } } } - - /** Loads the children of the currently logged in experimenter. */ - void loadExperimenterData() - { - TreeImageDisplay root = getTreeRoot(); - TreeImageDisplay child = (TreeImageDisplay) root.getFirstChild(); - treeDisplay.expandPath(new TreePath(child.getPath())); - } /** * Reacts to state change. @@ -1682,11 +1771,24 @@ void setExperimenterData(Set nodes, TreeImageDisplay expNode) while (i.hasNext()) setExpandedParent((TreeImageDisplay) i.next(), true); TreeImageDisplay root = getTreeRoot(); - TreeImageDisplay element; + TreeImageDisplay element, child; + Object ho; + List children; for (int j = 0; j < root.getChildCount(); j++) { element = (TreeImageDisplay) root.getChildAt(j); - if (element.getUserObject() instanceof ExperimenterData) { - if (element.isExpanded()) expandNode(element); + ho = element.getUserObject(); + if (ho instanceof GroupData && element.isExpanded()) { + expandNode(element); + children = element.getChildrenDisplay(); + if (children != null) { + i = children.iterator(); + while (i.hasNext()) { + child = (TreeImageDisplay) i.next(); + if (child.getUserObject() instanceof ExperimenterData + && child.isExpanded()) + expandNode(child); + } + } } } } @@ -1703,7 +1805,7 @@ void setGroups(Set nodes, List expanded) TreeImageDisplay root = getTreeRoot(); root.removeAllChildren(); root.removeAllChildrenDisplay(); - root.setChildrenLoaded(Boolean.TRUE); + root.setChildrenLoaded(Boolean.valueOf(true)); root.setExpanded(true); dtm.reload(); if (nodes.size() != 0) { @@ -1880,16 +1982,23 @@ void setLeavesViews(Collection nodes, TreeImageSet parent) * Adds a new experimenter to the tree. * * @param experimenter The experimenter to add. - * @param load Pass true to load the data, - * false otherwise. + * @param groupNode The node to add the experimenter to. */ - void addExperimenter(ExperimenterData experimenter, boolean load) + void addExperimenter(ExperimenterData experimenter, + TreeImageDisplay groupNode) { + TreeImageSet node = createExperimenterNode(experimenter, groupNode); + DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); + dtm.reload(); + if (model.isSelected()) + treeDisplay.expandPath(new TreePath(node.getPath())); + /* TreeImageSet node = createExperimenterNode(experimenter); DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); dtm.reload(); if (load) - treeDisplay.expandPath(new TreePath(node.getPath())); + treeDisplay.expandPath(new TreePath(node.getPath())); + */ } /** @@ -1899,7 +2008,41 @@ void addExperimenter(ExperimenterData experimenter, boolean load) */ void removeExperimenter(ExperimenterData exp) { + if (model.getBrowserType() == Browser.ADMIN_EXPLORER) return; TreeImageDisplay root = getTreeRoot(); + List nodesToKeep; + List l = root.getChildrenDisplay(); + if (l == null || l.size() == 0) return; + Iterator j = l.iterator(); + TreeImageDisplay element, n, node; + Object ho; + ExperimenterData expElement; + DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); + Iterator k; + while (j.hasNext()) { + node = null; + element = (TreeImageDisplay) j.next(); + nodesToKeep = new ArrayList(); + for (int i = 0; i < element.getChildCount(); i++) { + n = (TreeImageDisplay) element.getChildAt(i); + ho = n.getUserObject(); + if (ho instanceof ExperimenterData) { + expElement = (ExperimenterData) ho; + if (expElement.getId() == exp.getId()) + node = n; + else nodesToKeep.add(n); + } + } + if (node != null) element.removeChildDisplay(node); + k = nodesToKeep.iterator(); + element.removeAllChildren(); + while (k.hasNext()) { + tm.insertNodeInto((TreeImageSet) k.next(), element, + element.getChildCount()); + } + } + tm.reload(); + /* List nodesToKeep = new ArrayList(); TreeImageDisplay element, node = null; Object ho; @@ -1923,41 +2066,62 @@ void removeExperimenter(ExperimenterData exp) root.getChildCount()); } tm.reload(); + */ } - /** Reactivates the tree. */ - void reActivate() - { - TreeImageDisplay root = getTreeRoot(); - root.removeAllChildren(); - root.removeAllChildrenDisplay(); - createExperimenterNode(TreeViewerAgent.getUserDetails()); - DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); - tm.reload(); - } - /** - * Returns the node hosting the logged in user. + * Removes the specified group from the tree. * - * @return See above. + * @param group The data to remove. */ - TreeImageDisplay getLoggedExperimenterNode() + void removeGroup(GroupData group) { + if (model.getBrowserType() == Browser.ADMIN_EXPLORER) return; TreeImageDisplay root = getTreeRoot(); - return (TreeImageDisplay) root.getChildAt(0); + List nodesToKeep; + List l = root.getChildrenDisplay(); + if (l == null || l.size() == 0) return; + Iterator j = l.iterator(); + TreeImageDisplay element, n, node; + Object ho; + ExperimenterData expElement; + DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); + Iterator k; + GroupData g; + nodesToKeep = new ArrayList(); + node = null; + while (j.hasNext()) { + element = (TreeImageDisplay) j.next(); + if (element.getUserObject() instanceof GroupData) { + g = (GroupData) element.getUserObject(); + if (g.getId() == group.getId()) node = element; + else nodesToKeep.add(element); + } + } + + if (node != null) root.removeChildDisplay(node); + k = nodesToKeep.iterator(); + root.removeAllChildren(); + while (k.hasNext()) { + tm.insertNodeInto((TreeImageSet) k.next(), root, + root.getChildCount()); + } + tm.reload(); } - - /** Refreshes the experimenter data. */ - void refreshExperimenter() + + /** Reactivates the tree. */ + void reActivate() { TreeImageDisplay root = getTreeRoot(); - TreeImageDisplay element = (TreeImageDisplay) root.getChildAt(0); - Object ho = element.getUserObject(); - if (ho instanceof ExperimenterData) { - element.setUserObject(model.getUserDetails()); - DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); - tm.reload(element); - } + root.removeAllChildren(); + root.removeAllChildrenDisplay(); + if (model.getBrowserType() != Browser.ADMIN_EXPLORER) { + ExperimenterData exp = TreeViewerAgent.getUserDetails(); + TreeImageDisplay node = buildTreeNodes(exp); + if (model.isSelected() && node != null) expandNode(node, true); + } + DefaultTreeModel tm = (DefaultTreeModel) treeDisplay.getModel(); + tm.reload(); } /** @@ -1978,7 +2142,6 @@ void setFoundNode(TreeImageDisplay[] newSelection) } treeDisplay.repaint(); - } /** @@ -2046,27 +2209,6 @@ void reloadNode(TreeImageDisplay node) tm.reload(node); } - /** Expands the node corresponding to the user currently logged in. */ - void expandUser() - { - TreeImageDisplay root = getTreeRoot(); - TreeImageDisplay element; - Object ho; - ExperimenterData exp; - long id = model.getUserID(); - for (int i = 0; i < root.getChildCount(); i++) { - element = (TreeImageDisplay) root.getChildAt(i); - ho = element.getUserObject(); - if (ho instanceof ExperimenterData) { - exp = (ExperimenterData) ho; - if (exp.getId() == id && !element.isExpanded()) { - expandNode(element); - break; - } - } - } - } - /** * Expands the specified node. To avoid loop, we first need to * remove the TreeExpansionListener. @@ -2076,6 +2218,7 @@ void expandUser() void expandNode(TreeImageDisplay node, boolean withListener) { //First remove listener otherwise an event is fired. + if (node == null) return; node.setExpanded(true); if (withListener) { treeDisplay.expandPath(new TreePath(node.getPath())); @@ -2110,34 +2253,41 @@ void addComponent(JComponent component) revalidate(); repaint(); } - + /** - * Returns the nodes corresponding to the passed user. - * - * @param userID The id of the user. - * @return See above. - */ - List getNodesForUser(long userID) - { - TreeImageDisplay root = getTreeRoot(); - TreeImageDisplay element; - Object ho; - ExperimenterData exp; - long id = model.getUserID(); - for (int i = 0; i < root.getChildCount(); i++) { - element = (TreeImageDisplay) root.getChildAt(i); - ho = element.getUserObject(); - if (ho instanceof ExperimenterData) { - exp = (ExperimenterData) ho; - if (exp.getId() == id) { - return element.getChildrenDisplay(); - } + * Adds the specified group to the tree. + * + * @param group The group to add. + * @param add Pass true to add, false otherwise. + */ + void setUserGroup(GroupData group, boolean add) + { + if (group == null) return; + ExperimenterData exp = model.getUserDetails(); + TreeImageSet node; + TreeImageDisplay root = getTreeRoot(); + if (add) { + //Collapses previous group. + List children = root.getChildrenDisplay(); + Iterator i = children.iterator(); + TreeImageDisplay n; + while (i.hasNext()) { + n = (TreeImageDisplay) i.next(); + n.setExpanded(false); + collapsePath(n); } + node = createGroup(model.getSelectedGroup()); + node = createExperimenterNode(exp, node); + if (model.isSelected()) expandNode(node, true); + } else { + root.removeAllChildren(); + root.removeAllChildrenDisplay(); + node = createGroup(model.getSelectedGroup()); + node = createExperimenterNode(exp, node); + if (model.isSelected()) expandNode(node, true); } - return null; - } - - + } + /** * Reacts to the D&D properties. * @see PropertyChangeListener#propertyChange(PropertyChangeEvent) diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/CreateCmd.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/CreateCmd.java index 8f4d0a7896b..bcf9601d949 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/CreateCmd.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/CreateCmd.java @@ -175,8 +175,10 @@ public void execute() type = BrowserSelectionEvent.SCREEN_TYPE; } event = new LoadImporter(display, type); - long id = TreeViewerAgent.getUserDetails().getId(); - event.setObjects(browser.getNodesForUser(id)); + event.setGroup(browser.getSecurityContext( + browser.getLastSelectedDisplay()).getGroupID()); + //long id = TreeViewerAgent.getUserDetails().getId(); + //event.setObjects(browser.getNodesForUser(id, display)); EventBus bus = TreeViewerAgent.getRegistry().getEventBus(); bus.post(event); } else { diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/ExperimenterVisitor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/ExperimenterVisitor.java new file mode 100644 index 00000000000..9b42425c51f --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/ExperimenterVisitor.java @@ -0,0 +1,163 @@ +/* + * org.openmicroscopy.shoola.agents.treeviewer.cmd.ExperimenterVisitor + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.agents.treeviewer.cmd; + + +//Java imports +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; +import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; +import org.openmicroscopy.shoola.agents.util.browser.TreeImageNode; +import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; +import pojos.ExperimenterData; +import pojos.GroupData; + +/** + * Finds the experimenters. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class ExperimenterVisitor + extends BrowserVisitor +{ + + /** The nodes found.*/ + private List nodes; + + /** The id of the user to find or -1.*/ + private long userID; + + /** The ids of the group to find or -1.*/ + private Collection groupIDs; + + /** Flag indicating to check only the group.*/ + private boolean groupOnly; + + /** + * Creates a new instance. + * + * @param model Reference to the {@link Browser}. + * Mustn't be null. + * @param groupID The id of the group. + */ + public ExperimenterVisitor(Browser model, long groupID) + { + super(model); + groupOnly = true; + groupIDs = new ArrayList(); + if (groupID >= 0) groupIDs.add(groupID); + nodes = new ArrayList(); + } + + /** + * Creates a new instance. + * + * @param model Reference to the {@link Browser}. + * Mustn't be null. + * @param userID The id of the user. + * @param groupID The id of the group. + */ + public ExperimenterVisitor(Browser model, long userID, long groupID) + { + super(model); + this.userID = userID; + groupIDs = new ArrayList(); + if (groupID >= 0) groupIDs.add(groupID); + nodes = new ArrayList(); + } + + /** + * Creates a new instance. + * + * @param model Reference to the {@link Browser}. + * Mustn't be null. + * @param userID The id of the user. + * @param groupID The id of the group. + */ + public ExperimenterVisitor(Browser model, long userID, + Collection groupIDs) + { + super(model); + this.userID = userID; + if (groupIDs == null) groupIDs = new ArrayList(); + this.groupIDs = groupIDs; + nodes = new ArrayList(); + } + + /** + * Returns the nodes. + * + * @return See above. + */ + public List getNodes() { return nodes; } + + /** + * Retrieves the nodes hosting a DataObject with the same ID + * than {@link #originalNodeID}. + * @see BrowserVisitor#visit(TreeImageNode) + */ + public void visit(TreeImageNode node) {} + + /** + * Retrieves the nodes hosting a DataObject with the same ID + * than {@link #originalNodeID}. + * @see BrowserVisitor#visit(TreeImageSet) + */ + public void visit(TreeImageSet node) + { + Object ho = node.getUserObject(); + if (ho instanceof ExperimenterData && !groupOnly) { + if (userID < 0) nodes.add(node); + else { + if (userID == ((ExperimenterData) ho).getId()) { + if (groupIDs.size() == 0) nodes.add(node); + else { + TreeImageDisplay parent = node.getParentDisplay(); + Object pho = parent.getUserObject(); + if (pho instanceof GroupData && + groupIDs.contains(((GroupData) pho).getId())) + nodes.add(node); + } + } + } + } else if (ho instanceof GroupData) { + if (groupOnly) { + if (groupIDs.contains(((GroupData) ho).getId())) { + nodes.add(node); + } else { + if (groupIDs.size() == 0) + nodes.add(node); + } + } + } + } +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/ParentVisitor.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/ParentVisitor.java index a4a648cdefe..e49d247216c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/ParentVisitor.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/cmd/ParentVisitor.java @@ -37,10 +37,9 @@ import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplayVisitor; import org.openmicroscopy.shoola.agents.util.browser.TreeImageNode; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; - -import pojos.DataObject; import pojos.DatasetData; import pojos.ExperimenterData; +import pojos.GroupData; import pojos.ImageData; import pojos.PlateData; import pojos.ProjectData; @@ -57,12 +56,12 @@ public class ParentVisitor { /** Map hosting the data objects owned by users displayed.*/ - private Map> data; + private Map>> data; /** Creates a new instance.*/ public ParentVisitor() { - data = new HashMap>(); + data = new HashMap>>(); } /** @@ -84,12 +83,33 @@ public void visit(TreeImageSet node) Object ho = parent.getUserObject(); if (ho instanceof ExperimenterData) { ExperimenterData exp = (ExperimenterData) ho; + TreeImageDisplay gp = parent.getParentDisplay(); + long gid; + if (gp.getUserObject() instanceof GroupData) { + GroupData hgp = (GroupData) gp.getUserObject(); + gid = hgp.getId(); + } else { + gid = exp.getDefaultGroup().getId(); + } + Map> m = data.get(gid); + if (m == null) { + m = new HashMap>(); + data.put(gid, m); + } + List l = m.get(exp.getId()); + if (l == null) { + l = new ArrayList(); + m.put(exp.getId(), l); + } + l.add(node); + /* List l = data.get(exp.getId()); if (l == null) { l = new ArrayList(); data.put(exp.getId(), l); } l.add(node); + */ } } } @@ -99,6 +119,9 @@ public void visit(TreeImageSet node) * * @return See above. */ - public Map> getData() { return data; } + public Map>> getData() + { + return data; + } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/AdminDialog.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/AdminDialog.java index 892a3a835d7..4faf6555f43 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/AdminDialog.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/AdminDialog.java @@ -149,12 +149,14 @@ private void cancel() private boolean isExistingObject(String name, boolean group) { AdminService svc = TreeViewerAgent.getRegistry().getAdminService(); + /* TODO: review try { if (group) return svc.lookupGroup(name) != null; return svc.lookupExperimenter(name) != null; } catch (Exception e) { // TODO: handle exception } + */ return true; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/MoveGroupSelectionDialog.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/MoveGroupSelectionDialog.java new file mode 100644 index 00000000000..9892c9d537d --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/MoveGroupSelectionDialog.java @@ -0,0 +1,398 @@ +/* + * org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.agents.treeviewer.util; + + +//Java imports +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.ToolTipManager; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; + +//Third-party libraries +import info.clearthought.layout.TableLayout; +import org.jdesktop.swingx.JXBusyLabel; + +//Application-internal dependencies +import org.openmicroscopy.shoola.agents.treeviewer.IconManager; +import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; +import org.openmicroscopy.shoola.agents.util.ViewerSorter; +import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; +import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; +import org.openmicroscopy.shoola.agents.util.browser.TreeViewerTranslator; +import org.openmicroscopy.shoola.env.data.model.TransferableActivityParam; +import org.openmicroscopy.shoola.env.data.model.TransferableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; +import org.openmicroscopy.shoola.env.ui.UserNotifier; +import org.openmicroscopy.shoola.util.ui.TitlePanel; +import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.DataObject; +import pojos.DatasetData; +import pojos.GroupData; +import pojos.PlateAcquisitionData; +import pojos.PlateData; +import pojos.ProjectData; +import pojos.ScreenData; + +/** + * Selects the targets of the move group action. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class MoveGroupSelectionDialog + extends JDialog + implements ActionListener +{ + + /** Action id to close and dispose.*/ + public static final int CANCEL = 1; + + /** Action id to move the data.*/ + private static final int MOVE = 2; + + /** Text displayed in the header.*/ + private static final String TEXT = "Select where to move the data into "; + + /** The default size of the busy image.*/ + private static final Dimension SIZE = new Dimension(32, 32); + + /** The group to move the data to.*/ + private GroupData group; + + /** The data to move.*/ + private Map> toMove; + + /** The list of possible targets.*/ + private List targets; + + /** The button to close and dispose.*/ + private JButton cancelButton; + + /** The button to move the data.*/ + private JButton moveButton; + + /** The component displayed in center of dialog.*/ + private JComponent body; + + /** The id of the user.*/ + private long userID; + + /** Sort the data.*/ + private ViewerSorter sorter; + + /** Indicate the status of the dialog.*/ + private int status; + + /** Only displayed the top node.*/ + private boolean topOnly; + + /** Handle the nodes to display.*/ + private JTree treeDisplay; + + /** + * Adds the nodes to the specified parent. + * + * @param parent The parent node. + * @param nodes The list of nodes to add. + * @param tm The tree model. + */ + private void buildTreeNode(TreeImageDisplay parent, + Collection nodes, DefaultTreeModel tm) + { + Iterator i = nodes.iterator(); + TreeImageDisplay display; + List children; + DataObject data; + while (i.hasNext()) { + display = (TreeImageDisplay) i.next(); + display.setDisplayItems(false); + data = (DataObject) display.getUserObject(); + if (!(topOnly && (data instanceof DatasetData || + data instanceof PlateData))) { + tm.insertNodeInto(display, parent, parent.getChildCount()); + if (display instanceof TreeImageSet) { + children = display.getChildrenDisplay(); + if (children.size() > 0) { + buildTreeNode(display, + prepareSortedList(sorter.sort(children)), tm); + } + } + } + } + } + /** Closes and disposes.*/ + private void cancel() + { + status = CANCEL; + setVisible(false); + dispose(); + } + + /** Moves the data.*/ + private void move() + { + SecurityContext ctx = new SecurityContext(group.getId()); + TreePath path = treeDisplay.getSelectionPath(); + DataObject target = null; + if (path != null) { + Object object = path.getLastPathComponent(); + if (object != null && object instanceof TreeImageDisplay) { + target = (DataObject) + ((TreeImageDisplay) object).getUserObject(); + } + } + TransferableObject t = new TransferableObject(ctx, target, toMove); + IconManager icons = IconManager.getInstance(); + TransferableActivityParam param = new TransferableActivityParam( + icons.getIcon(IconManager.MOVE_22), t); + param.setFailureIcon(icons.getIcon(IconManager.MOVE_FAILED_22)); + UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); + un.notifyActivity(null, param); + cancel(); + } + + /** Initializes the components.*/ + private void initComponents() + { + sorter = new ViewerSorter(); + cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(this); + cancelButton.setActionCommand(""+CANCEL); + moveButton = new JButton("Move"); + moveButton.setEnabled(false); + moveButton.addActionListener(this); + moveButton.setActionCommand(""+MOVE); + Entry entry; + Iterator i = toMove.entrySet().iterator(); + List list; + DataObject data; + while (i.hasNext()) { + entry = (Entry) i.next(); + list = (List) entry.getValue(); + if (list != null && list.size() > 0) { + data = list.get(0); + if (data instanceof PlateData || data instanceof DatasetData) { + topOnly = true; + break; + } + } + } + } + + /** + * Builds and lays out the buttons. + * + * @return See above. + */ + private JPanel buildToolBar() + { + JPanel bar = new JPanel(); + bar.add(moveButton); + bar.add(Box.createRigidArea(UIUtilities.H_SPACER_SIZE)); + bar.add(cancelButton); + bar.add(Box.createRigidArea(UIUtilities.H_SPACER_SIZE)); + return UIUtilities.buildComponentPanelRight(bar); + } + + /** Builds and lays out the UI.*/ + private void buildGUI() + { + IconManager icons = IconManager.getInstance(); + TitlePanel tp = new TitlePanel(getTitle(), TEXT+group.getName(), + icons.getIcon(IconManager.MOVE_48)); + Container c = getContentPane(); + //c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); + c.add(tp, BorderLayout.NORTH); + JXBusyLabel label = new JXBusyLabel(SIZE); + label.setBusy(true); + body = buildContent(label); + c.add(body, BorderLayout.CENTER); + c.add(buildToolBar(), BorderLayout.SOUTH); + setSize(400, 500); + } + + /** + * Builds the main component of this dialog. + * + * @param group The selected group if any. + * @param comp The component to add. + * @return See above. + */ + private JComponent buildContent(JComponent comp) + { + double[][] tl = {{TableLayout.FILL}, //columns + {TableLayout.FILL}}; //rows + JPanel content = new JPanel(); + content.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); + content.setLayout(new TableLayout(tl)); + content.setBackground(UIUtilities.BACKGROUND); + content.add(comp, "0, 0, CENTER, CENTER"); + return content; + } + + /** + * Organizes the sorted list so that the Project/Screen/Tag Set + * are displayed first. + * + * @param sorted The collection to organize. + * @return See above. + */ + private List prepareSortedList(List sorted) + { + List top = new ArrayList(); + List bottom = new ArrayList(); + + List top2 = new ArrayList(); + List bottom2 = new ArrayList(); + + Iterator j = sorted.iterator(); + TreeImageDisplay object; + Object uo; + while (j.hasNext()) { + object = (TreeImageDisplay) j.next(); + uo = object.getUserObject(); + if (uo instanceof ProjectData) top.add(object); + else if (uo instanceof ScreenData) top2.add(object); + else if (uo instanceof DatasetData) bottom.add(object); + else if (uo instanceof PlateData) bottom2.add(object); + else if (uo instanceof PlateAcquisitionData) bottom2.add(object); + } + List all = new ArrayList(); + if (top.size() > 0) all.addAll(top); + if (bottom.size() > 0) all.addAll(bottom); + if (top2.size() > 0) all.addAll(top2); + if (bottom2.size() > 0) all.addAll(bottom2); + return all; + } + + /** + * Creates a new instance. + * + * @param owner The owner of the dialog. + * @param userID The identifier of the user. + * @param group The group where to move the data to. + * @param toMove The objects to move. + */ + public MoveGroupSelectionDialog(JFrame owner, long userID, GroupData group, + Map> toMove) + { + super(owner); + if (group == null) + throw new IllegalArgumentException("No group."); + if (toMove == null || toMove.size() == 0) + throw new IllegalArgumentException("No data to move."); + setTitle("Move to "+group.getName()); + this.group = group; + this.toMove = toMove; + this.userID = userID; + initComponents(); + buildGUI(); + } + + /** + * Returns the status of the dialog. + * + * @return See above. + */ + public int getStatus() { return status; } + + /** + * Sets the values where to import the data. + * + * @param targets The values to display. + */ + public void setTargets(Collection targets) + { + moveButton.setEnabled(true); + Container c = getContentPane(); + c.remove(body); + c.remove(1); + if (targets == null || targets.size() == 0) { + c.add(buildContent(new JLabel("No target to select.")), + BorderLayout.CENTER); + c.add(buildToolBar(), BorderLayout.SOUTH); + validate(); + repaint(); + return; + } + treeDisplay = new JTree(); + treeDisplay.setVisible(true); + treeDisplay.setRootVisible(false); + ToolTipManager.sharedInstance().registerComponent(treeDisplay); + treeDisplay.setCellRenderer(new TreeCellRenderer()); + treeDisplay.setShowsRootHandles(true); + TreeImageSet root = new TreeImageSet(""); + treeDisplay.setModel(new DefaultTreeModel(root)); + Set nodes = TreeViewerTranslator.transformHierarchy(targets, userID, + -1); + DefaultTreeModel dtm = (DefaultTreeModel) treeDisplay.getModel(); + buildTreeNode(root, prepareSortedList(sorter.sort(nodes)), dtm); + dtm.reload(); + c.add(new JScrollPane(treeDisplay), BorderLayout.CENTER); + c.add(buildToolBar(), BorderLayout.SOUTH); + validate(); + repaint(); + } + + /** + * Closes or moves the data. + * @see ActionListener#actionPerformed(ActionEvent) + */ + public void actionPerformed(ActionEvent e) + { + int index = Integer.parseInt(e.getActionCommand()); + switch (index) { + case CANCEL: + cancel(); + break; + case MOVE: + move(); + } + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/TreeCellRenderer.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/TreeCellRenderer.java index 48099b2ce85..f59164fa693 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/TreeCellRenderer.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/util/TreeCellRenderer.java @@ -38,6 +38,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.treeviewer.IconManager; +import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; import org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.util.browser.SmartFolder; import org.openmicroscopy.shoola.agents.util.browser.TreeFileSet; @@ -45,6 +46,7 @@ import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; import org.openmicroscopy.shoola.agents.util.dnd.DnDTree; import org.openmicroscopy.shoola.agents.util.EditorUtil; +import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.util.filter.file.EditorFileFilter; import org.openmicroscopy.shoola.util.ui.UIUtilities; import pojos.DatasetData; @@ -219,11 +221,32 @@ public class TreeCellRenderer /** Reference to the Date icon. */ private static final Icon DATE_ICON; - /** Reference to the Date icon. */ + /** Reference to the Group icon. */ private static final Icon OWNER_GROUP_ICON; + /** Reference to the Group Private icon. */ + private static final Icon GROUP_PRIVATE_ICON; + + /** Reference to the Group RWR--- icon. */ + private static final Icon GROUP_READ_ONLY_ICON; + + /** Reference to the Group RWRW-- icon. */ + private static final Icon GROUP_READ_WRITE_ICON; + + /** Reference to the Group icon. */ + private static final Icon GROUP_PUBLIC_READ_ICON; + + /** Reference to the Group icon. */ + private static final Icon GROUP_PUBLIC_READ_WRITE_ICON; + static { IconManager icons = IconManager.getInstance(); + GROUP_PRIVATE_ICON = icons.getIcon(IconManager.PRIVATE_GROUP); + GROUP_READ_ONLY_ICON = icons.getIcon(IconManager.READ_GROUP); + GROUP_READ_WRITE_ICON = icons.getIcon(IconManager.READ_LINK_GROUP); + GROUP_PUBLIC_READ_ICON = icons.getIcon(IconManager.PUBLIC_GROUP); + GROUP_PUBLIC_READ_WRITE_ICON = icons.getIcon( + IconManager.PUBLIC_GROUP); OWNER_GROUP_ICON = icons.getIcon(IconManager.OWNER_GROUP); IMAGE_ICON = icons.getIcon(IconManager.IMAGE); IMAGE_ANNOTATED_ICON = icons.getIcon(IconManager.IMAGE_ANNOTATED); @@ -378,7 +401,28 @@ private void setIcon(TreeImageDisplay node) icon = PLATE_ACQUISITION_ANNOTATED_ICON; else icon = PLATE_ACQUISITION_ICON; } else if (usrObject instanceof GroupData) { - icon = OWNER_GROUP_ICON; + GroupData g = (GroupData) usrObject; + int level = + TreeViewerAgent.getRegistry().getAdminService().getPermissionLevel( + g); + switch (level) { + case AdminObject.PERMISSIONS_PRIVATE: + icon = GROUP_PRIVATE_ICON; + break; + case AdminObject.PERMISSIONS_GROUP_READ: + icon = GROUP_READ_ONLY_ICON; + break; + case AdminObject.PERMISSIONS_GROUP_READ_LINK: + icon = GROUP_READ_WRITE_ICON; + break; + case AdminObject.PERMISSIONS_PUBLIC_READ: + icon = GROUP_PUBLIC_READ_ICON; + break; + case AdminObject.PERMISSIONS_PUBLIC_READ_WRITE: + icon = GROUP_PUBLIC_READ_WRITE_ICON; + default: + icon = OWNER_GROUP_ICON; + } } else if (usrObject instanceof FileAnnotationData) { FileAnnotationData data = (FileAnnotationData) usrObject; String format = data.getFileFormat(); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/PopupMenu.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/PopupMenu.java index 4c3a9646ad3..569e5dd7082 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/PopupMenu.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/PopupMenu.java @@ -45,6 +45,8 @@ import org.openmicroscopy.shoola.agents.treeviewer.IconManager; import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; import org.openmicroscopy.shoola.agents.treeviewer.actions.CreateTopContainerAction; +import org.openmicroscopy.shoola.agents.treeviewer.actions.MoveToAction; +import org.openmicroscopy.shoola.agents.treeviewer.actions.SwitchUserAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.TreeViewerAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.ViewOtherAction; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; @@ -102,6 +104,9 @@ class PopupMenu /** Button to refresh the experimenter data. */ private JMenuItem refreshExperimenterElement; + /** Button to add experimenter node from the display. */ + private JMenuItem addExperimenterElement; + /** Button to refresh the tree data. */ private JMenuItem refreshTreeElement; @@ -172,7 +177,7 @@ class PopupMenu private JMenuItem newExperimentElement; /** Button to send feedback. */ - private JMenuItem sendFeedbackElement; + private JMenuItem sendFeedbackElement; /** Reference to the Control. */ private TreeViewerControl controller; @@ -189,6 +194,9 @@ class PopupMenu /** Button to activate or not user. */ private JCheckBoxMenuItem activatedUser; + /** Button to remove group from the display. */ + private JMenuItem removeGroupElement; + /** * Sets the defaults of the specified menu item. * @@ -260,6 +268,15 @@ private void createMenuItems() a = controller.getAction(TreeViewerControl.REMOVE_FROM_DISPLAY); removeExperimenterElement = new JMenuItem(a); initMenuItem(removeExperimenterElement, a.getActionName()); + a = controller.getAction(TreeViewerControl.REMOVE_GROUP); + removeGroupElement = new JMenuItem(a); + initMenuItem(removeGroupElement, a.getActionName()); + + a = controller.getAction(TreeViewerControl.SWITCH_USER); + addExperimenterElement = new JMenuItem(a); + addExperimenterElement.addMouseListener((SwitchUserAction) a); + initMenuItem(addExperimenterElement, a.getActionName()); + a = controller.getAction( TreeViewerControl.REFRESH_EXPERIMENTER); refreshExperimenterElement = new JMenuItem(a); @@ -403,6 +420,23 @@ public void itemStateChanged(ItemEvent e) { } } + /** + * Creates a menu if the various groups the data can be moved to. + * + * @return See above. + */ + private JMenu createMoveToMenu() + { + List actions = controller.getMoveAction(); + if (actions.size() <= 1) return null; + JMenu menu = new JMenu(MoveToAction.NAME); + Iterator i = actions.iterator(); + while (i.hasNext()) { + menu.add(new JMenuItem(i.next())); + } + return menu; + } + /** Builds and lays out the GUI. */ private void buildGUI() { @@ -423,6 +457,8 @@ private void buildGUI() add(cutElement); add(copyElement); add(pasteElement); + JMenu m = createMoveToMenu(); + if (m != null) add(m); add(deleteElement); add(new JSeparator(JSeparator.HORIZONTAL)); add(tagElement); @@ -434,6 +470,8 @@ private void buildGUI() add(setMinMaxElement); add(setOwnerRndElement); add(new JSeparator(JSeparator.HORIZONTAL)); + add(removeGroupElement); + add(addExperimenterElement); add(refreshExperimenterElement); add(removeExperimenterElement); break; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/ToolBar.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/ToolBar.java index a27b29cb290..793e2880a2d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/ToolBar.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/ToolBar.java @@ -23,7 +23,6 @@ package org.openmicroscopy.shoola.agents.treeviewer.view; //Java imports -import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; @@ -40,6 +39,7 @@ import java.util.Map; import java.util.Set; +import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; @@ -48,6 +48,7 @@ import javax.swing.JButton; import javax.swing.JCheckBoxMenuItem; import javax.swing.JComponent; +import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPanel; @@ -56,26 +57,29 @@ import javax.swing.JToggleButton; import javax.swing.JToolBar; import javax.swing.border.BevelBorder; -import javax.swing.border.EmptyBorder; //Third-party libraries +import org.jdesktop.swingx.JXBusyLabel; //Application-internal dependencies -import org.jdesktop.swingx.JXBusyLabel; import org.openmicroscopy.shoola.agents.treeviewer.IconManager; import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; import org.openmicroscopy.shoola.agents.treeviewer.actions.GroupSelectionAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.ManagerAction; -import org.openmicroscopy.shoola.agents.treeviewer.actions.PersonalManagementAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.RunScriptAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.SwitchUserAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.TreeViewerAction; +import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; +import org.openmicroscopy.shoola.agents.treeviewer.cmd.ExperimenterVisitor; +import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; import org.openmicroscopy.shoola.agents.util.ui.ScriptMenuItem; import org.openmicroscopy.shoola.agents.util.ui.ScriptSubMenu; +import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.env.data.model.ScriptObject; import org.openmicroscopy.shoola.env.ui.TaskBar; import org.openmicroscopy.shoola.util.ui.UIUtilities; -import pojos.ExperimenterData; + +import pojos.GroupData; /** * The tool bar of {@link TreeViewer}. @@ -97,6 +101,31 @@ class ToolBar /** Size of the horizontal box. */ private static final Dimension HBOX = new Dimension(100, 16); + /** The icon for private group.*/ + private static final Icon PERMISSIONS_PRIVATE; + + /** The icon for private group.*/ + private static final Icon PERMISSIONS_GROUP_READ; + + /** The icon for private group.*/ + private static final Icon PERMISSIONS_GROUP_READ_LINK; + + /** The icon for private group.*/ + private static final Icon PERMISSIONS_PUBLIC_READ; + + /** The icon for private group.*/ + private static final Icon PERMISSIONS_PUBLIC_READ_WRITE; + + //Initializes the icons. + static { + IconManager im = IconManager.getInstance(); + PERMISSIONS_PRIVATE = im.getIcon(IconManager.PRIVATE_GROUP); + PERMISSIONS_GROUP_READ = im.getIcon(IconManager.READ_GROUP); + PERMISSIONS_GROUP_READ_LINK = im.getIcon(IconManager.READ_LINK_GROUP); + PERMISSIONS_PUBLIC_READ = im.getIcon(IconManager.PUBLIC_GROUP); + PERMISSIONS_PUBLIC_READ_WRITE = im.getIcon(IconManager.PUBLIC_GROUP); + } + /** Reference to the control. */ private TreeViewerControl controller; @@ -127,6 +156,9 @@ class ToolBar /** The management bar.*/ private JToolBar bar; + /** The label displaying the group context.*/ + private JLabel groupContext; + /** * Sets the defaults of the specified menu item. * @@ -233,21 +265,70 @@ private JComponent createManagementBar() scriptButton = b; bar.add(b); index = bar.getComponentCount()-1; + bar.add(new JSeparator(JSeparator.VERTICAL)); - a = controller.getAction(TreeViewerControl.SWITCH_USER); - b = new JButton(a); - b.addMouseListener((SwitchUserAction) a); - UIUtilities.unifiedButtonLookAndFeel(b); - bar.add(b); + Set set = TreeViewerAgent.getAvailableUserGroups(); - if (set != null && set.size() > 0) { + if (set != null && set.size() > 1) { + groupContext = new JLabel(); + setPermissions(); + IconManager icons = IconManager.getInstance(); + b = new JButton(icons.getIcon(IconManager.OWNER_GROUP)); + UIUtilities.unifiedButtonLookAndFeel(b); + b.addMouseListener(new MouseAdapter() { + + /** + * Shows the menu with the various + */ + public void mousePressed(MouseEvent me) + { + TreeViewerAction a = + controller.getAction(TreeViewerControl.SWITCH_USER); + a.putValue(Action.SMALL_ICON, null); + JPopupMenu selectionMenu = new JPopupMenu(); + JMenuItem item = new JMenuItem(a); + item.setText(SwitchUserAction.NAME); + selectionMenu.add(item); + JMenu menu = new JMenu(GroupSelectionAction.NAME_ADD); + menu.setToolTipText(GroupSelectionAction.DESCRIPTION_ADD); + List items = createMenuItem(true); + Iterator i = items.iterator(); + while (i.hasNext()) { + menu.add(i.next()); + } + selectionMenu.add(menu); + menu = new JMenu(GroupSelectionAction.NAME); + menu.setToolTipText(GroupSelectionAction.DESCRIPTION); + items = createMenuItem(false); + i = items.iterator(); + while (i.hasNext()) { + menu.add(i.next()); + } + selectionMenu.add(menu); + selectionMenu.show((JComponent) me.getSource(), + me.getX(), me.getY()); + } + }); + bar.add(b); + bar.add(Box.createHorizontalStrut(5)); + bar.add(groupContext); + //menu attached to the button. + /* a = controller.getAction(TreeViewerControl.PERSONAL); b = new JButton(a); BorderFactory.createCompoundBorder(new EmptyBorder(2, 2, 2, 2), BorderFactory.createLineBorder(Color.GRAY)); b.addMouseListener((PersonalManagementAction) a); bar.add(b); + */ + } else { + a = controller.getAction(TreeViewerControl.SWITCH_USER); + b = new JButton(a); + b.addMouseListener((SwitchUserAction) a); + UIUtilities.unifiedButtonLookAndFeel(b); + bar.add(b); } + return bar; } @@ -348,26 +429,71 @@ void showPersonalMenu(Component c, Point p) personalMenu = new JPopupMenu(); personalMenu.setBorder( BorderFactory.createBevelBorder(BevelBorder.RAISED)); - List l = controller.getUserGroupAction(); - Iterator i = l.iterator(); - GroupSelectionAction a; - JCheckBoxMenuItem item; - ButtonGroup buttonGroup = new ButtonGroup(); - ExperimenterData exp = TreeViewerAgent.getUserDetails(); - long id = exp.getDefaultGroup().getId(); + List l = createMenuItem(false); + Iterator i = l.iterator(); while (i.hasNext()) { - a = i.next(); - item = new JCheckBoxMenuItem(a); - item.setEnabled(true); - item.setSelected(a.isSameGroup(id)); - initMenuItem(item); - buttonGroup.add(item); - personalMenu.add(item); + personalMenu.add(i.next()); } //} personalMenu.show(c, p.x, p.y); } + /** + * Creates the items for the menu. + * + * @param add Pass true to build items for the Add + * menu, false otherwise. + * @return See above + */ + private List createMenuItem(boolean add) + { + List items = new ArrayList(); + List l = controller.getUserGroupAction(add); + Iterator i = l.iterator(); + GroupSelectionAction a; + JMenuItem item; + if (add) { + //Check the groups that already in the view. + Browser browser = model.getSelectedBrowser(); + List ids = new ArrayList(); + if (browser != null) { + ExperimenterVisitor v = new ExperimenterVisitor(browser, -1); + browser.accept(v, ExperimenterVisitor.TREEIMAGE_SET_ONLY); + List nodes = v.getNodes(); + Iterator j = nodes.iterator(); + TreeImageDisplay node; + while (j.hasNext()) { + node = j.next(); + ids.add(((GroupData) node.getUserObject()).getId()); + } + } + + while (i.hasNext()) { + a = i.next(); + item = new JMenuItem(a); + if (ids.size() > 0) { + item.setEnabled(!ids.contains(a.getGroupId())); + } else item.setEnabled(true); + initMenuItem(item); + items.add(item); + } + } else { + ButtonGroup buttonGroup = new ButtonGroup(); + long id = model.getSelectedGroupId(); + while (i.hasNext()) { + a = i.next(); + item = new JCheckBoxMenuItem(a); + item.setEnabled(true); + item.setSelected(a.isSameGroup(id)); + initMenuItem(item); + buttonGroup.add(item); + items.add(item); + } + } + + return items; + } + /** * Brings up the Available Scripts on top of the specified * component at the specified location. @@ -501,4 +627,40 @@ void setScriptsLoadingStatus(boolean loading) repaint(); } + /** Sets the permissions level.*/ + void setPermissions() + { + GroupData group = model.getSelectedGroup(); + if (group == null || groupContext == null) return; + String desc = ""; + int level = + TreeViewerAgent.getRegistry().getAdminService().getPermissionLevel( + group); + Icon icon = null; + switch (level) { + case AdminObject.PERMISSIONS_PRIVATE: + desc = AdminObject.PERMISSIONS_PRIVATE_TEXT; + icon = PERMISSIONS_PRIVATE; + break; + case AdminObject.PERMISSIONS_GROUP_READ: + desc = AdminObject.PERMISSIONS_GROUP_READ_TEXT; + icon = PERMISSIONS_GROUP_READ; + break; + case AdminObject.PERMISSIONS_GROUP_READ_LINK: + desc = AdminObject.PERMISSIONS_GROUP_READ_LINK_TEXT; + icon = PERMISSIONS_GROUP_READ_LINK; + break; + case AdminObject.PERMISSIONS_PUBLIC_READ: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_TEXT; + icon = PERMISSIONS_PUBLIC_READ; + break; + case AdminObject.PERMISSIONS_PUBLIC_READ_WRITE: + desc = AdminObject.PERMISSIONS_PUBLIC_READ_WRITE_TEXT; + icon = PERMISSIONS_PUBLIC_READ; + } + if (icon != null) groupContext.setIcon(icon); + groupContext.setText(group.getName()); + groupContext.setToolTipText(desc); + repaint(); + } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewer.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewer.java index 54a7ecbdb76..2182ea1c2ab 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewer.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewer.java @@ -563,13 +563,6 @@ public interface TreeViewer */ public void showPreSavingDialog(); - /** - * Returns the id to the group selected for the current user. - * - * @return See above. - */ - public long getUserGroupID(); - /** * Retrieves the user groups. * @@ -809,12 +802,11 @@ public void browse(TreeImageDisplay node, DataObject data, public void deleteObjects(List nodes); /** - * Returns the type of objects to copy or null if no objects - * selected. + * Returns the objects to copy or null. * * @return See above. */ - public Class hasDataToCopy(); + public List getDataToCopy(); /** * Refreshes the view when nodes have been deleted. A collection of nodes @@ -895,12 +887,12 @@ public void browse(TreeImageDisplay node, DataObject data, void openWith(ApplicationData data); /** - * Sets the default group for the currently selected user and updates the - * view. + * Adds the group to the display if not already displayed * * @param group The group to set. + * @param add Pass true to add, false otherwise. */ - void setUserGroup(GroupData group); + void setUserGroup(GroupData group, boolean add); /** Opens the image in a separate window or in the main viewer. */ void setFullScreen(); @@ -915,14 +907,6 @@ public void browse(TreeImageDisplay node, DataObject data, */ public Map getScriptsAsString(); - /** - * Returns true if the currently logged in user is - * a leader of the selected group, false otherwise. - * - * @return See above. - */ - public boolean isLeaderOfSelectedGroup(); - /** * Returns true if the currently logged in user is * a leader of the specified group, false otherwise. @@ -949,16 +933,10 @@ public void browse(TreeImageDisplay node, DataObject data, * Returns the permission level of the selected group. One of the constants * defined by the AdminObject class. * + * @param group The group to handle. * @return See above. */ - int getSelectedGroupPermissions(); - - /** - * Returns the currently selected group. - * - * @return See above. - */ - GroupData getSelectedGroup(); + int getGroupPermissions(GroupData group); /** * Resets the password of the selected experimenters. @@ -1075,4 +1053,21 @@ void transfer(TreeImageDisplay target, List nodes, int */ void setSelectedNodes(Object nodes); + /** + * Returns the selected group. + * + * @return See above. + */ + GroupData getSelectedGroup(); + + /** Remove group.*/ + void removeGroup(); + + /** + * Move the selected data to the specified group. + * + * @param group The data to move. + */ + void moveTo(GroupData group, List nodes); + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerComponent.java index 2ecfaf58c0e..8a7102b64bf 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerComponent.java @@ -46,7 +46,6 @@ //Application-internal dependencies import omero.model.OriginalFile; - import org.openmicroscopy.shoola.agents.dataBrowser.DataBrowserAgent; import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowserFactory; @@ -58,6 +57,7 @@ import org.openmicroscopy.shoola.agents.events.iviewer.ViewImage; import org.openmicroscopy.shoola.agents.events.iviewer.ViewImageObject; import org.openmicroscopy.shoola.agents.events.treeviewer.BrowserSelectionEvent; +import org.openmicroscopy.shoola.agents.events.treeviewer.ChangeUserGroupEvent; import org.openmicroscopy.shoola.agents.events.treeviewer.CopyItems; import org.openmicroscopy.shoola.agents.events.treeviewer.DeleteObjectEvent; import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; @@ -66,11 +66,13 @@ import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserFactory; +import org.openmicroscopy.shoola.agents.treeviewer.cmd.ExperimenterVisitor; import org.openmicroscopy.shoola.agents.treeviewer.cmd.UpdateVisitor; import org.openmicroscopy.shoola.agents.treeviewer.finder.ClearVisitor; import org.openmicroscopy.shoola.agents.treeviewer.finder.Finder; import org.openmicroscopy.shoola.agents.treeviewer.util.AdminDialog; import org.openmicroscopy.shoola.agents.treeviewer.util.GenericDialog; +import org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog; import org.openmicroscopy.shoola.agents.treeviewer.util.NotDeletedObjectDialog; import org.openmicroscopy.shoola.agents.treeviewer.util.OpenWithDialog; import org.openmicroscopy.shoola.agents.util.browser.ContainerFinder; @@ -91,7 +93,6 @@ import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.ExitApplication; -import org.openmicroscopy.shoola.env.data.events.SwitchUserGroup; import org.openmicroscopy.shoola.env.data.login.UserCredentials; import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.env.data.model.ApplicationData; @@ -101,13 +102,16 @@ import org.openmicroscopy.shoola.env.data.model.OpenActivityParam; import org.openmicroscopy.shoola.env.data.model.ScriptObject; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.model.TransferableActivityParam; +import org.openmicroscopy.shoola.env.data.model.TransferableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; -import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.env.ui.ActivityComponent; import org.openmicroscopy.shoola.env.ui.UserNotifier; import org.openmicroscopy.shoola.util.ui.MessageBox; import org.openmicroscopy.shoola.util.ui.UIUtilities; import org.openmicroscopy.shoola.util.ui.component.AbstractComponent; + import pojos.DataObject; import pojos.DatasetData; import pojos.ExperimenterData; @@ -165,6 +169,109 @@ class TreeViewerComponent /** The dialog displaying the selected script.*/ private ScriptingDialog scriptDialog; + + /** + * Returns the name of the group. + * + * @param groupId The id of the group. + * @return See above. + */ + private String getGroupName(long groupId) + { + Set groups = TreeViewerAgent.getAvailableUserGroups(); + Iterator j = groups.iterator(); + GroupData group; + while (j.hasNext()) { + group = (GroupData) j.next(); + if (group.getId() == groupId) return group.getName(); + } + return ""; + } + + /** + * Removes the nodes from the display. + * + * @param trans The node to remove. + */ + private void removeNodes(Map> trans) + { + EventBus bus = TreeViewerAgent.getRegistry().getEventBus(); + List objects = new ArrayList(); + Iterator> i = trans.values().iterator(); + List l; + while (i.hasNext()) { + l = i.next(); + if (l != null) objects.addAll(l); + } + bus.post(new DeleteObjectEvent(objects)); + + NodesFinder finder = new NodesFinder(objects); + Browser browser = model.getSelectedBrowser(); + browser.accept(finder); + browser.removeTreeNodes(finder.getNodes()); + view.removeAllFromWorkingPane(); + DataBrowserFactory.discardAll(); + model.getMetadataViewer().setRootObject(null, -1, null); + } + + /** + * Moves the objects. + * + * @param ctx The group to move the data to. + * @param target The target object. + * @param trans The objects to transfer. + */ + private void moveData(SecurityContext ctx, DataObject target, + Map> trans) + { + removeNodes(trans); + TransferableObject t = new TransferableObject(ctx, target, trans); + t.setGroupName(getGroupName(ctx.getGroupID())); + IconManager icons = IconManager.getInstance(); + TransferableActivityParam param = new TransferableActivityParam( + icons.getIcon(IconManager.MOVE_22), t); + param.setFailureIcon(icons.getIcon(IconManager.MOVE_FAILED_22)); + UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); + un.notifyActivity(model.getSecurityContext(), param); + } + + /** + * Notifies the change of group. + * + * @param oldId The previous group id. + */ + private void notifyChangeGroup(long oldId) + { + long id = model.getSelectedGroupId(); + ChangeUserGroupEvent evt = new ChangeUserGroupEvent(id, oldId); + TreeViewerAgent.getRegistry().getEventBus().post(evt); + firePropertyChange(GROUP_CHANGED_PROPERTY, oldId, id); + } + + /** + * Returns the group the specified node belongs to. + * + * @param node The node to handle. + * @return See above. + */ + private GroupData getContext(TreeImageDisplay node) + { + if (node == null) return null; + if (node.getUserObject() instanceof GroupData) { + return (GroupData) node.getUserObject(); + } + TreeImageDisplay parent = node.getParentDisplay(); + Object ho; + if (parent == null) { + ho = node.getUserObject(); + if (ho instanceof GroupData) + return (GroupData) ho; + return null; + } + ho = parent.getUserObject(); + if (ho instanceof GroupData) return (GroupData) ho; + return getContext(parent); + } /** * Returns the name corresponding the specified object. @@ -210,26 +317,28 @@ private void downloadFile(File folder, boolean override, if (override) activity.setFileName(fa.getFileName()); activity.setApplicationData(data); - un.notifyActivity(activity); - } - - /** - * Displays the user groups. - * - * @param groups The groups the current user is a member of. - * @param location The location of the mouse pressed. - */ - private void displayUserGroups(Set groups, Point location) - { - JFrame f = (JFrame) TreeViewerAgent.getRegistry().getTaskBar(); - IconManager icons = IconManager.getInstance(); - switchUserDialog = new UserManagerDialog(f, model.getUserDetails(), - groups, icons.getIcon(IconManager.OWNER), - icons.getIcon(IconManager.OWNER_48)); - switchUserDialog.addPropertyChangeListener(controller); - switchUserDialog.setDefaultSize(); - UIUtilities.showOnScreen(switchUserDialog, location); + un.notifyActivity(model.getSecurityContext(), activity); } + + /** + * Returns the SecurityContext if already added or null. + * + * @param map The map to check. + * @param id The group's identifier. + * @return See above. + */ + private SecurityContext getKey( + Map> map, long id) + { + Iterator i = map.keySet().iterator(); + SecurityContext ctx; + while (i.hasNext()) { + ctx = i.next(); + if (ctx.getGroupID() == id) + return ctx; + } + return null; + } /** * Displays the data browser corresponding to the passed node. @@ -691,7 +800,8 @@ public void setSelectedBrowser(Browser browser, boolean activate) browser.activate(); if (browser.getBrowserType() == Browser.ADMIN_EXPLORER) { ExperimenterData exp = model.getUserDetails(); - model.getMetadataViewer().setRootObject(null, exp.getId()); + model.getMetadataViewer().setRootObject(null, + exp.getId(), null); } } @@ -808,7 +918,7 @@ public void removeEditor() "invoked in the DISCARDED, SAVE state."); } view.removeAllFromWorkingPane(); - model.getMetadataViewer().setRootObject(null, -1); + model.getMetadataViewer().setRootObject(null, -1, null); firePropertyChange(REMOVE_EDITOR_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true)); } @@ -870,7 +980,13 @@ public void onSelectedDisplay() Browser browser = model.getSelectedBrowser(); if (browser == null) return; TreeImageDisplay display = browser.getLastSelectedDisplay(); - + //Update the group. + GroupData group = getContext(display); + if (group != null) { + long oldId = model.getSelectedGroupId(); + model.setSelectedGroupId(group.getId()); + notifyChangeGroup(oldId); + } MetadataViewer metadata = model.getMetadataViewer(); TreeImageDisplay[] selection = browser.getSelectedDisplays(); @@ -881,12 +997,12 @@ public void onSelectedDisplay() TreeImageTimeSet time = (TreeImageTimeSet) display; view.removeAllFromWorkingPane(); if (!time.containsImages()) { - metadata.setRootObject(null, -1); + metadata.setRootObject(null, -1, null); } showDataBrowser(display.getUserObject(), display, true); return; } - metadata.setSelectionMode(single); + if (display != null) { Object object = display.getUserObject(); if (!single) { @@ -899,17 +1015,20 @@ public void onSelectedDisplay() } if (l.size() > 0) metadata.setRelatedNodes(l); + metadata.setSelectionMode(single); } else { ExperimenterData exp = browser.getNodeOwner(display); if (exp == null) exp = model.getUserDetails(); - metadata.setRootObject(object, exp.getId()); + metadata.setRootObject(object, exp.getId(), + browser.getSecurityContext(display)); TreeImageDisplay p = display.getParentDisplay(); if (p != null) { TreeImageDisplay pp = p.getParentDisplay(); Object gpp = null; if (pp != null) gpp = pp.getUserObject(); metadata.setParentRootObject(p.getUserObject(), gpp); - } + } + metadata.setSelectionMode(single); } if (!model.isFullScreen()) { showDataBrowser(object, display, false); @@ -918,7 +1037,7 @@ public void onSelectedDisplay() } else { DataBrowser db = model.getDataViewer(); if (db != null) db.setSelectedNodes(new ArrayList(), null); - metadata.setRootObject(null, -1); + metadata.setRootObject(null, -1, null); } if (display != null && display.getUserObject() instanceof ExperimenterData && @@ -962,7 +1081,8 @@ public void setSelectedNodes(Object nodes) if (browser != null) last = browser.getLastSelectedDisplay(); if (last != null) exp = browser.getNodeOwner(last); if (exp == null) exp = model.getUserDetails(); - mv.setRootObject(selected, exp.getId()); + mv.setRootObject(selected, exp.getId(), + browser.getSecurityContext(last)); mv.setParentRootObject(parent, null); if (model.getDataViewer() != null) model.getDataViewer().setApplications( @@ -1077,7 +1197,16 @@ public void setSelectedNode(Object object) parent = ((WellData) parent).getPlate(); } mv.setParentRootObject(parent, null); - mv.setRootObject(selected, exp.getId()); + if (browser == null) { + if (selected instanceof DataObject) { + SecurityContext ctx = new SecurityContext( + ((DataObject) selected).getGroupId()); + mv.setRootObject(selected, exp.getId(), ctx); + } + } else { + mv.setRootObject(selected, exp.getId(), + browser.getSecurityContext(last)); + } if (size > 0) mv.setRelatedNodes(siblings); @@ -1132,7 +1261,8 @@ public void setSelectedField(Object object) if (last != null) exp = browser.getNodeOwner(last); if (exp == null) exp = model.getUserDetails(); mv.setSelectionMode(true); - mv.setRootObject(selected, exp.getId()); + mv.setRootObject(selected, exp.getId(), + browser.getSecurityContext(last)); mv.setParentRootObject(parent, null); } @@ -1328,11 +1458,11 @@ public void setHierarchyRoot(long userGroupID, Iterator i = browsers.entrySet().iterator(); Browser browser; Entry entry; - Browser selected = model.getSelectedBrowser(); + userGroupID = model.getSelectedGroupId(); while (i.hasNext()) { entry = (Entry) i.next(); browser = (Browser) entry.getValue(); - browser.addExperimenter(experimenter, browser == selected); + browser.addExperimenter(experimenter, userGroupID); } } @@ -1603,12 +1733,105 @@ public void paste(TreeImageDisplay[] parents) return; } TreeImageDisplay[] nodes = model.getNodesToCopy(); - if (nodes == null || nodes.length == 0) return; - boolean b = model.paste(parents); - if (!b) { - un.notifyInfo("Paste action", "The nodes to copy cannot " + - "be added to the selected nodes."); - } else fireStateChange(); + if (nodes == null || nodes.length == 0) return; + //check to transfer data. + Map> elements = + new HashMap>(); + long gid; + List l; + TreeImageDisplay n; + Object os; + for (int j = 0; j < nodes.length; j++) { + n = nodes[j]; + os = n.getUserObject(); + if (os instanceof DataObject && + !(os instanceof ExperimenterData || + os instanceof GroupData)) { + gid = ((DataObject) os).getGroupId(); + if (!elements.containsKey(gid)) { + elements.put(gid, new ArrayList()); + } + l = elements.get(gid); + l.add((DataObject) os); + } + } + if (elements.size() == 0) return; + Iterator i; + List ids = new ArrayList(); + Map> + parentMap = new HashMap>(); + List list; + if (elements.size() == 1) { //check if cut and paste + TreeImageDisplay parent; + for (int j = 0; j < parents.length; j++) { + n = parents[j]; + os = n.getUserObject(); + if (os instanceof ExperimenterData) { + parent = n.getParentDisplay(); + if (parent.getUserObject() instanceof GroupData) { + gid = parent.getUserObjectId(); + if (!parentMap.containsKey(gid)) { + parentMap.put(gid, new ArrayList()); + } + if (!ids.contains(gid)) + ids.add(gid); + } + } else if (os instanceof DataObject) { + gid = ((DataObject) os).getGroupId(); + if (!parentMap.containsKey(gid)) { + parentMap.put(gid, new ArrayList()); + } + list = parentMap.get(gid); + if (!(os instanceof GroupData)) + list.add((DataObject) os); + if (!ids.contains(gid)) + ids.add(gid); + } + } + if (ids.size() == 1) { //check if it is a Paste in the group + i = elements.keySet().iterator(); + while (i.hasNext()) { + if (i.next().longValue() == ids.get(0).longValue()) { + boolean b = model.paste(parents); + if (!b) { + un.notifyInfo("Paste", + "The nodes to copy cannot be added to the " + + "selected nodes."); + } else fireStateChange(); + return; + } + } + } + } + MessageBox box = new MessageBox(view, "Change group", "Are you " + + "you want to move the selected items to another group?"); + if (box.centerMsgBox() != MessageBox.YES_OPTION) return; + //if we are here moving data. + i = elements.keySet().iterator(); + Map> trans = + new HashMap>(); + while (i.hasNext()) { + gid = i.next(); + trans.put(new SecurityContext(gid), elements.get(gid)); + } + IconManager icons = IconManager.getInstance(); + TransferableActivityParam param; + Entry entry; + Iterator k = parentMap.entrySet().iterator(); + TransferableObject t; + Long id; + while (k.hasNext()) { + entry = (Entry) k.next(); + id = (Long) entry.getKey(); + removeNodes(trans); + t = new TransferableObject(new SecurityContext(id), + (List) entry.getValue(), trans); + t.setGroupName(getGroupName(id)); + param = new TransferableActivityParam( + icons.getIcon(IconManager.APPLY_22), t); + param.setFailureIcon(icons.getIcon(IconManager.DELETE_22)); + un.notifyActivity(model.getSecurityContext(), param); + } } /** @@ -1657,18 +1880,6 @@ public void showPreSavingDialog() } } - /** - * Implemented as specified by the {@link TreeViewer} interface. - * @see TreeViewer#getUserGroupID() - */ - public long getUserGroupID() - { - if (model.getState() == DISCARDED) - throw new IllegalStateException( - "This method cannot be invoked in the DISCARDED state."); - return model.getUserGroupID(); - } - /** * Implemented as specified by the {@link TreeViewer} interface. * @see TreeViewer#retrieveUserGroups(Point) @@ -1678,7 +1889,26 @@ public void retrieveUserGroups(Point location) if (model.getState() == DISCARDED) throw new IllegalStateException( "This method cannot be invoked in the DISCARDED state."); - displayUserGroups(TreeViewerAgent.getAvailableUserGroups(), location); + JFrame f = (JFrame) TreeViewerAgent.getRegistry().getTaskBar(); + IconManager icons = IconManager.getInstance(); + Set groups = TreeViewerAgent.getAvailableUserGroups(); + Iterator i = groups.iterator(); + GroupData group = model.getSelectedGroup(); + GroupData g; + Set experimenters = null; + while (i.hasNext()) { + g = (GroupData) i.next(); + if (g.getId() == group.getId()) { + experimenters = g.getExperimenters(); + } + } + if (experimenters == null) return; + switchUserDialog = new UserManagerDialog(f, model.getUserDetails(), + group, icons.getIcon(IconManager.OWNER), + icons.getIcon(IconManager.OWNER_48)); + switchUserDialog.addPropertyChangeListener(controller); + switchUserDialog.setDefaultSize(); + UIUtilities.showOnScreen(switchUserDialog, location); } /** @@ -1753,8 +1983,7 @@ public void setRollOver(boolean rollOver) */ public void removeExperimenterData() { - //TODO: Check state - + if (model.getState() == DISCARDED) return; Browser browser = model.getSelectedBrowser(); TreeImageDisplay expNode = browser.getLastSelectedDisplay(); Object uo = expNode.getUserObject(); @@ -1968,19 +2197,23 @@ public void setLeaves(TreeImageSet parent, Collection leaves) DataBrowser db = null; if (parentObject instanceof TagAnnotationData) { db = DataBrowserFactory.getTagsBrowser( + model.getSecurityContext(parent), (TagAnnotationData) parentObject, leaves, false); } else if (parentObject instanceof GroupData) { db = DataBrowserFactory.getGroupsBrowser( - (GroupData) parentObject, leaves); + model.getSecurityContext(parent), (GroupData) parentObject, + leaves); } else if (parentObject instanceof FileData) { FileData f = (FileData) parentObject; if (!f.isHidden()) { if (f.isDirectory() || f instanceof MultiImageData) db = DataBrowserFactory.getFSFolderBrowser( + model.getSecurityContext(parent), (FileData) parentObject, leaves); } } else { - db = DataBrowserFactory.getDataBrowser(grandParentObject, + db = DataBrowserFactory.getDataBrowser( + model.getSecurityContext(parent), grandParentObject, parentObject, leaves, parent); if (parent instanceof TreeImageTimeSet) { ExperimenterData exp = getSelectedBrowser().getNodeOwner(parent); @@ -2027,7 +2260,6 @@ public void browseHierarchyRoots(Object parent, Collection roots) Set set, dataObjects; DatasetData d; long userID = model.getExperimenter().getId(); - long groupID = model.getUserGroupID(); Iterator k; Map m = new HashMap(); @@ -2063,7 +2295,7 @@ public void browseHierarchyRoots(Object parent, Collection roots) while (k.hasNext()) { value.addChildDisplay( TreeViewerTranslator.transformDataObject( - (ImageData) k.next(), userID, groupID)); + (ImageData) k.next(), userID, -1)); } } value.setChildrenLoaded(true); @@ -2071,7 +2303,8 @@ public void browseHierarchyRoots(Object parent, Collection roots) } model.setState(READY); fireStateChange(); - db = DataBrowserFactory.getDataBrowser(project, set); + db = DataBrowserFactory.getDataBrowser( + model.getSecurityContext(), project, set); } else if (node instanceof TagAnnotationData) { tag = (TagAnnotationData) node; set = tag.getDataObjects();//tag.getTags(); @@ -2090,7 +2323,7 @@ public void browseHierarchyRoots(Object parent, Collection roots) while (k.hasNext()) { value.addChildDisplay( TreeViewerTranslator.transformDataObject( - (ImageData) k.next(), userID, groupID) + (ImageData) k.next(), userID, -1) ); } } @@ -2107,9 +2340,7 @@ public void browseHierarchyRoots(Object parent, Collection roots) while (k.hasNext()) { value.addChildDisplay( TreeViewerTranslator.transformDataObject( - (ImageData) k.next(), - userID, groupID) - ); + (ImageData) k.next(), userID, -1)); } } value.setChildrenLoaded(true); @@ -2119,7 +2350,8 @@ public void browseHierarchyRoots(Object parent, Collection roots) } model.setState(READY); fireStateChange(); - db = DataBrowserFactory.getTagsBrowser(tag, set, true); + db = DataBrowserFactory.getTagsBrowser( + model.getSecurityContext(), tag, set, true); } } if (db != null) { @@ -2259,14 +2491,16 @@ public void showSearch() DataBrowser db = DataBrowserFactory.getSearchBrowser(); int newMode = view.getDisplayMode(); view.removeAllFromWorkingPane(); - model.getAdvancedFinder().requestFocusOnField(); + model.getAdvancedFinder( + model.getSecurityContext()).requestFocusOnField(); switch (newMode) { case EXPLORER_MODE: onSelectedDisplay(); break; case SEARCH_MODE: ExperimenterData exp = model.getUserDetails(); - model.getMetadataViewer().setRootObject(null, exp.getId()); + model.getMetadataViewer().setRootObject(null, exp.getId(), + null); if (db != null) { view.displayBrowser(db); model.setDataViewer(db); @@ -2281,10 +2515,11 @@ public void showSearch() */ public void setSearchResult(Object result) { - Collection results = (Collection) result; + Map> + results = (Map>) result; MetadataViewer metadata = model.getMetadataViewer(); if (metadata != null) { - metadata.setRootObject(null, -1); + metadata.setRootObject(null, -1, null); } if (results == null || results.size() == 0) { //UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); @@ -2379,7 +2614,7 @@ public void refreshTree() view.removeAllFromWorkingPane(); if (b != null) b.refreshTree(null, null); ExperimenterData exp = model.getUserDetails(); - model.getMetadataViewer().setRootObject(null, exp.getId()); + model.getMetadataViewer().setRootObject(null, exp.getId(), null); } /** @@ -2401,7 +2636,8 @@ public void browseTimeInterval(TreeImageTimeSet parent, Set leaves) Browser browser = model.getSelectedBrowser(); if (browser != null) exp = browser.getNodeOwner(parent); - DataBrowser db = DataBrowserFactory.getDataBrowser(grandParentObject, + DataBrowser db = DataBrowserFactory.getDataBrowser( + model.getSecurityContext(parent), grandParentObject, parentObject, leaves, parent); db.setExperimenter(exp); db.addPropertyChangeListener(controller); @@ -2452,7 +2688,8 @@ public void setPlates(Map plates, boolean withThumbnails) } } - db = DataBrowserFactory.getWellsDataBrowser(m, parentObject, + db = DataBrowserFactory.getWellsDataBrowser( + model.getSecurityContext(parent), m, parentObject, (Set) entry.getValue(), withThumbnails); } } @@ -2500,7 +2737,8 @@ public void browse(TreeImageDisplay node, DataObject data, exp = (ExperimenterData) parent.getUserObject(); if (exp == null) exp = model.getUserDetails(); node.setExpanded(true); - mv.setRootObject(node.getUserObject(), exp.getId()); + mv.setRootObject(node.getUserObject(), exp.getId(), + browser.getSecurityContext(node)); browser.onSelectedNode(null, node, false); break; } @@ -2540,7 +2778,8 @@ public void browse(TreeImageDisplay node, DataObject data, leaves.add(o.getUserObject()); } - DataBrowser db = DataBrowserFactory.getDataBrowser(null, + DataBrowser db = DataBrowserFactory.getDataBrowser( + model.getSecurityContext(node), null, parent.getUserObject(), leaves, parent); if (db == null) return; db.addPropertyChangeListener(controller); @@ -2629,7 +2868,8 @@ public void browse(TreeImageDisplay node, DataObject data, } } vo.setContext(po, gpo); - ViewImage evt = new ViewImage(vo, view.getBounds()); + ViewImage evt = new ViewImage(model.getSecurityContext(), vo, + view.getBounds()); evt.setSeparateWindow(model.isFullScreen()); bus.post(evt); } else if (node instanceof TreeImageTimeSet) { @@ -2834,14 +3074,14 @@ public void deleteObjects(List nodes) browser.removeTreeNodes(finder.getNodes()); view.removeAllFromWorkingPane(); DataBrowserFactory.discardAll(); - model.getMetadataViewer().setRootObject(null, -1); + model.getMetadataViewer().setRootObject(null, -1, null); IconManager icons = IconManager.getInstance(); DeleteActivityParam p = new DeleteActivityParam( icons.getIcon(IconManager.APPLY_22), l); p.setFailureIcon(icons.getIcon(IconManager.DELETE_22)); UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); - un.notifyActivity(p); + un.notifyActivity(model.getSecurityContext(), p); } if (values != null) { NodesFinder finder = new NodesFinder(klass, ids); @@ -2850,7 +3090,7 @@ public void deleteObjects(List nodes) model.getSelectedBrowser().removeTreeNodes(finder.getNodes()); view.removeAllFromWorkingPane(); DataBrowserFactory.discardAll(); - model.getMetadataViewer().setRootObject(null, -1); + model.getMetadataViewer().setRootObject(null, -1, null); model.fireObjectsDeletion(values); fireStateChange(); } @@ -2859,12 +3099,12 @@ public void deleteObjects(List nodes) /** * Implemented as specified by the {@link TreeViewer} interface. - * @see TreeViewer#hasDataToCopy() + * @see TreeViewer#getDataToCopy() */ - public Class hasDataToCopy() + public List getDataToCopy() { if (model.getState() == DISCARDED) return null; - return model.getDataToCopyType(); + return model.getDataToCopy(); } /** @@ -2892,7 +3132,7 @@ public void onNodesMoved() } */ //onSelectedDisplay(); - model.getMetadataViewer().setRootObject(null, -1); + model.getMetadataViewer().setRootObject(null, -1, null); setStatus(false, "", true); view.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } @@ -2934,12 +3174,14 @@ public void openEditorFile(int index) if (object instanceof FileAnnotationData) { FileAnnotationData fa = (FileAnnotationData) d.getUserObject(); - EditFileEvent evt = new EditFileEvent(fa); - bus.post(evt); + bus.post( new EditFileEvent( + browser.getSecurityContext(d), fa)); } break; case NO_SELECTION: - bus.post(new ShowEditorEvent()); + ExperimenterData exp = model.getUserDetails(); + bus.post(new ShowEditorEvent( + new SecurityContext(exp.getDefaultGroup().getId()))); break; case NEW_WITH_SELECTION: if (browser == null) return; @@ -2977,6 +3219,7 @@ else if (object instanceof PlateData) { if (name != null) { name += ShowEditorEvent.EXPERIMENT_EXTENSION; ShowEditorEvent event = new ShowEditorEvent( + browser.getSecurityContext(d), (DataObject) object, name, ShowEditorEvent.EXPERIMENT); bus.post(event); @@ -3087,10 +3330,12 @@ private void download(File folder, ApplicationData data) if (notArchived.size() > 0) { image = notArchived.get(0); try { + //TODO: review + File f = new File( folder.getAbsolutePath()+File.separator+image.getName()+".ome.tiff"); TreeViewerAgent.getRegistry().getImageService().exportImageAsOMETiff( - image.getId(), f); + model.getSecurityContext(), image.getId(), f); TreeViewerAgent.getRegistry().getUserNotifier().openApplication( data, f.getAbsolutePath()); } catch (Exception e) { @@ -3116,7 +3361,7 @@ public void setDownloadedFiles(File folder, ApplicationData data, activity = new DownloadActivityParam(file, folder, icons.getIcon(IconManager.DOWNLOAD_22)); activity.setApplicationData(data); - un.notifyActivity(activity); + un.notifyActivity(model.getSecurityContext(), activity); } } @@ -3138,13 +3383,14 @@ public void openWith(ApplicationData data) Object object; OpenActivityParam activity; UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); + SecurityContext ctx = model.getSecurityContext(); while (i.hasNext()) { object = i.next(); if (object instanceof ImageData || object instanceof FileAnnotationData) { activity = new OpenActivityParam(data, (DataObject) object, dir); - un.notifyActivity(activity); + un.notifyActivity(ctx, activity); } } return; @@ -3169,17 +3415,33 @@ public void openWith(ApplicationData data) /** * Implemented as specified by the {@link TreeViewer} interface. - * @see TreeViewer#setUserGroup(GroupData) + * @see TreeViewer#setUserGroup(GroupData, boolean) */ - public void setUserGroup(GroupData group) + public void setUserGroup(GroupData group, boolean add) { if (model.getState() != READY) return; if (group == null) return; ExperimenterData exp = TreeViewerAgent.getUserDetails(); - long oldId = model.getUserGroupID(); - if (group.getId() == oldId) return; - Registry reg = TreeViewerAgent.getRegistry(); - reg.getEventBus().post(new SwitchUserGroup(exp, group.getId())); + //if (group.getId() == model.getSelectedGroupId()) return; + //Scan browser and check if group is there. + Browser browser = model.getBrowser(Browser.PROJECTS_EXPLORER); + if (browser == null) return; + if (add) { + ExperimenterVisitor v = new ExperimenterVisitor(browser, + group.getId()); + browser.accept(v, ExperimenterVisitor.TREEIMAGE_SET_ONLY); + if (v.getNodes().size() != 0) return; + } + + //Add the group to the display and set it as the default group. + long gid = model.getSelectedGroupId(); + model.setSelectedGroupId(group.getId()); + Map browsers = model.getBrowsers(); + Iterator i = browsers.values().iterator(); + while (i.hasNext()) { + i.next().setUserGroup(group, add); + } + notifyChangeGroup(gid); } /** @@ -3213,6 +3475,8 @@ public void setMetadataVisibility() public Map getScriptsAsString() { Registry reg = TreeViewerAgent.getRegistry(); + //TODO: review + /* try { //TODO: asynchronous call instead return reg.getImageService().getScriptsAsString(); @@ -3223,19 +3487,10 @@ public Map getScriptsAsString() msg.print(e); reg.getLogger().error(this, msg); } + */ return new HashMap(); } - /** - * Implemented as specified by the {@link TreeViewer} interface. - * @see TreeViewer#uploadScript(ScriptObject) - */ - public boolean isLeaderOfSelectedGroup() - { - if (model.getState() == DISCARDED) return false; - return model.isLeaderOfSelectedGroup(); - } - /** * Implemented as specified by the {@link TreeViewer} interface. * @see TreeViewer#isLeaderOfGroup(GroupData) @@ -3288,11 +3543,10 @@ public void register(DataObjectRegistration file) /** * Implemented as specified by the {@link TreeViewer} interface. - * @see TreeViewer#getSelectedGroupPermissions() + * @see TreeViewer#getGroupPermissions(GroupData) */ - public int getSelectedGroupPermissions() + public int getGroupPermissions(GroupData group) { - GroupData group = getSelectedGroup(); int level = AdminObject.PERMISSIONS_PRIVATE; if (group != null) { PermissionData data = group.getPermissions(); @@ -3308,25 +3562,6 @@ public int getSelectedGroupPermissions() } return level; } - - /** - * Implemented as specified by the {@link TreeViewer} interface. - * @see TreeViewer#getSelectedGroup() - */ - public GroupData getSelectedGroup() - { - Set m = TreeViewerAgent.getAvailableUserGroups(); - Iterator i = m.iterator(); - long id = model.getUserGroupID(); - GroupData group = null; - while (i.hasNext()) { - group = (GroupData) i.next(); - if (group.getId() == id) { - return group; - } - } - return null; - } /** * Implemented as specified by the {@link TreeViewer} interface. @@ -3367,13 +3602,13 @@ public void resetPassword(String password) */ public void onGroupSwitched(boolean success) { + /* ExperimenterData exp = TreeViewerAgent.getUserDetails(); GroupData group = exp.getDefaultGroup(); long oldGroup = model.getUserGroupID(); if (success) { model.setRndSettings(null); model.setNodesToCopy(null, -1); - model.setGroupId(group.getId()); view.removeAllFromWorkingPane(); model.setDataViewer(null); model.getMetadataViewer().onGroupSwitched(success); @@ -3391,6 +3626,31 @@ public void onGroupSwitched(boolean success) model.getUserGroupID()); view.createTitle(); } + */ + } + + /** + * Invokes when reconnected to the server. + */ + void onReconnected() + { + model.setRndSettings(null); + model.setNodesToCopy(null, -1); + view.removeAllFromWorkingPane(); + model.setDataViewer(null); + ExperimenterData exp = model.getUserDetails(); + model.setSelectedGroupId(exp.getDefaultGroup().getId()); + model.getMetadataViewer().onGroupSwitched(true); + //model.resetMetadataViewer(); + Map browsers = model.getBrowsers(); + Entry entry; + Browser browser; + Iterator i = browsers.entrySet().iterator(); + while (i.hasNext()) { + entry = (Entry) i.next(); + browser = (Browser) entry.getValue(); + browser.reActivate(); + } } /** @@ -3425,7 +3685,8 @@ public void findDataObject(Class type, long id, boolean selectTab) view.removeAllFromWorkingPane(); browser.refreshBrowser(type, id); ExperimenterData exp = model.getUserDetails(); - model.getMetadataViewer().setRootObject(null, exp.getId()); + model.getMetadataViewer().setRootObject(null, exp.getId(), + null); } } else { /* @@ -3476,6 +3737,7 @@ public void indicateToRefresh(List containers, { TreeImageDisplay node; Browser browser = null; + Set groupIds = new HashSet(); if (containers != null && containers.size() > 0) { NodesFinder finder = new NodesFinder(containers); DataObject ho = containers.get(0); @@ -3487,60 +3749,39 @@ public void indicateToRefresh(List containers, browser.accept(finder); } Set nodes = finder.getNodes(); - //mark + //mark if (browser != null && nodes != null && nodes.size() > 0) { Iterator i = nodes.iterator(); TreeImageDisplay parent; + Object object; while (i.hasNext()) { node = i.next(); node.setToRefresh(true); + object = node.getUserObject(); + if (object instanceof DataObject) { + groupIds.add(((DataObject) object).getGroupId()); + } parent = node.getParentDisplay(); if (parent != null && !parent.isExpanded()) browser.expand(parent); } - browser.getUI().repaint(); - } - /* - if (browser == null) return; - Set nodes = finder.getNodes(); - //mark - if (nodes != null && nodes.size() > 0) { - Iterator i = nodes.iterator(); - TreeImageDisplay parent; - while (i.hasNext()) { - node = i.next(); - node.setToRefresh(true); - parent = node.getParentDisplay(); - if (parent != null && !parent.isExpanded()) - browser.expand(parent); - } - browser.getUI().repaint(); - } else { - node = browser.getLoggedExperimenterNode(); - if (node != null) { - node.setToRefresh(refreshTree); - browser.getUI().repaint(); + ExperimenterData exp = TreeViewerAgent.getUserDetails(); + ExperimenterVisitor v = new ExperimenterVisitor(browser, + exp.getId(), groupIds); + browser.accept(v, TreeImageDisplayVisitor.TREEIMAGE_SET_ONLY); + List l = v.getNodes(); + if (l != null) { + Iterator j = l.iterator(); + while (j.hasNext()) { + node = j.next(); + node.setExpanded(true); + node.setToRefresh(refreshTree); + } } - } - node = browser.getLoggedExperimenterNode(); - if (node != null) { - node.setToRefresh(refreshTree); browser.getUI().repaint(); } - */ - } - /*else { - browser = model.getSelectedBrowser(); - if (browser != null) { - node = browser.getLoggedExperimenterNode(); - if (node != null) { - node.setExpanded(true); - node.setToRefresh(refreshTree); - browser.getUI().repaint(); - } - } } - */ + /* if (browser == null) browser = model.getSelectedBrowser(); if (browser != null) { node = browser.getLoggedExperimenterNode(); @@ -3549,7 +3790,7 @@ public void indicateToRefresh(List containers, node.setToRefresh(refreshTree); browser.getUI().repaint(); } - } + }*/ } /** @@ -3725,6 +3966,25 @@ public void setScript(ScriptObject script) else objects = browser.getSelectedDataObjects(); //setStatus(false); + //Check if the objects are in the same group. + Iterator i = objects.iterator(); + List ids = new ArrayList(); + DataObject object; + long id = -1; + while (i.hasNext()) { + object = i.next(); + if (!(object instanceof ExperimenterData || + object instanceof GroupData)) { + id = object.getGroupId(); + if (!ids.contains(id) && id != -1) + ids.add(id); + } + } + if (ids.size() > 1) { + UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); + un.notifyInfo("Run Script", ScriptingDialog.WARNING); + return; + } if (scriptDialog == null) { scriptDialog = new ScriptingDialog(view, model.getScript(script.getScriptID()), objects, @@ -3738,7 +3998,6 @@ public void setScript(ScriptObject script) } } - /** * Implemented as specified by the {@link TreeViewer} interface. * @see TreeViewer#transfer(TreeImageDisplay, List, int) @@ -3768,12 +4027,14 @@ public void transfer(TreeImageDisplay target, List nodes, return; } } - if (!isUserOwner(ot)) { + if (!isUserOwner(ot) && !(ot instanceof ExperimenterData || + ot instanceof GroupData)) { un.notifyInfo("DnD", "You must be the owner of the container."); browser.rejectTransfer(); return; } + TreeImageDisplay p = target.getParentDisplay(); List list = new ArrayList(); Iterator i = nodes.iterator(); TreeImageDisplay n; @@ -3783,19 +4044,47 @@ public void transfer(TreeImageDisplay target, List nodes, String parent; os = null; int childCount = 0; + long userID = TreeViewerAgent.getUserDetails().getId(); + boolean administrator = TreeViewerAgent.isAdministrator(); + ExperimenterData exp; + long gId; + List groupIds = new ArrayList(); + DataObject data; while (i.hasNext()) { n = i.next(); os = n.getUserObject(); if (target.contains(n)) { childCount++; } else { - if (EditorUtil.isTransferable(ot, os)) { + if (EditorUtil.isTransferable(ot, os, userID)) { count++; if (ot instanceof GroupData) { - if (TreeViewerAgent.isAdministrator()) + if (os instanceof ExperimenterData && + administrator) { list.add(n); + } else { + if (isUserOwner(os)) { + data = (DataObject) os; + if (!groupIds.contains(data.getGroupId())) + groupIds.add(data.getGroupId()); + list.add(n); + } + } } else { - if (isUserOwner(os)) list.add(n); + if (ot instanceof ExperimenterData) { + exp = (ExperimenterData) ot; + if (exp.getId() == userID) { + target = null; + list.add(n); + } + } else { + if (isUserOwner(os)) { + list.add(n); + data = (DataObject) os; + if (!groupIds.contains(data.getGroupId())) + groupIds.add(data.getGroupId()); + } + } } } } @@ -3804,6 +4093,8 @@ public void transfer(TreeImageDisplay target, List nodes, browser.rejectTransfer(); return; } + + if (list.size() == 0) { String s = ""; if (nodes.size() > 1) s = "s"; @@ -3813,7 +4104,162 @@ public void transfer(TreeImageDisplay target, List nodes, browser.rejectTransfer(); return; } - model.transfer(target, list); + DataObject otData = (DataObject) ot; + long groupID = -1; + if (ot instanceof ExperimenterData) { + Object po = p.getUserObject(); + if (po instanceof GroupData) { + groupID = ((GroupData) po).getId(); + } + } else groupID = otData.getGroupId(); + //to review + if (browser.getBrowserType() == Browser.ADMIN_EXPLORER) + model.transfer(target, list); + else if (groupIds.size() == 1 && groupIds.get(0) == groupID) + model.transfer(target, list); + else { + if (groupID == -1) return; + MessageBox box = new MessageBox(view, "Change group", "Are you " + + "you want to move the selected items to another group?"); + if (box.centerMsgBox() != MessageBox.YES_OPTION) return; + SecurityContext ctx = new SecurityContext(groupID); + otData = null; + if (target != null && !(ot instanceof GroupData)) { + otData = (DataObject) ot; + } + + Map> elements = + new HashMap>(); + i = list.iterator(); + long gid; + List l; + while (i.hasNext()) { + n = i.next(); + os = n.getUserObject(); + if (os instanceof DataObject && + !(os instanceof ExperimenterData || + os instanceof GroupData)) { + gid = ((DataObject) os).getGroupId(); + if (!elements.containsKey(gid)) { + elements.put(gid, new ArrayList()); + } + l = elements.get(gid); + l.add((DataObject) os); + } + } + if (elements.size() == 0) return; + Iterator j = elements.keySet().iterator(); + Map> trans = + new HashMap>(); + while (j.hasNext()) { + gid = j.next(); + trans.put(new SecurityContext(gid), elements.get(gid)); + } + if (target == null) otData = null; + moveData(new SecurityContext(groupID), otData, trans); + } + } + + /** + * Implemented as specified by the {@link TreeViewer} interface. + * @see TreeViewer#getSelectedGroup() + */ + public GroupData getSelectedGroup() + { + if (model.getState() == DISCARDED) return null; + return model.getSelectedGroup(); + } + + /** + * Implemented as specified by the {@link TreeViewer} interface. + * @see TreeViewer#removeGroup() + */ + public void removeGroup() + { + if (model.getState() == DISCARDED) return; + Browser browser = model.getSelectedBrowser(); + if (browser == null) return; + TreeImageDisplay node = browser.getLastSelectedDisplay(); + if (node == null || !(node.getUserObject() instanceof GroupData)) + return; + ExperimenterVisitor v = new ExperimenterVisitor(browser, -1); + browser.accept(v, ExperimenterVisitor.TREEIMAGE_SET_ONLY); + //do not remove the last group. + List groups = v.getNodes(); + if (groups.size() == 1) return; + GroupData group = (GroupData) node.getUserObject(); + Map browsers = model.getBrowsers(); + Iterator i = browsers.entrySet().iterator(); + Entry entry; + while (i.hasNext()) { + entry = (Entry) i.next(); + browser = (Browser) entry.getValue(); + browser.removeGroup(group); + } + Iterator j = groups.iterator(); + GroupData g; + long gid; + while (j.hasNext()) { + g = (GroupData) j.next().getUserObject(); + if (g.getId() != group.getId()) { + gid = model.getSelectedGroupId(); + model.setSelectedGroupId(g.getId()); + notifyChangeGroup(gid); + break; + } + } + } + + /** + * Implemented as specified by the {@link TreeViewer} interface. + * @see TreeViewer#moveTo(GroupData, List) + */ + public void moveTo(GroupData group, List nodes) + { + if (group == null) + throw new IllegalArgumentException("No group to move data to."); + + if (nodes == null || nodes.size() == 0) return; + Map> + map = new HashMap>(); + Iterator i = nodes.iterator(); + Class b = null; + DataObject data; + SecurityContext ctx; + long gid; + List l; + long refgid = group.getId(); + while (i.hasNext()) { + data = i.next(); + if (data instanceof ProjectData || data instanceof ScreenData) + b = data.getClass(); + gid = data.getGroupId(); + if (gid != refgid) { + ctx = getKey(map, gid); + if (ctx == null) { + l = new ArrayList(); + ctx = new SecurityContext(gid); + map.put(ctx, l); + } + l = map.get(ctx); + l.add(data); + } + } + if (map.size() == 0) { + UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); + un.notifyInfo("Move Data ", "No data to move to "+group.getName()); + return; + } + ctx = new SecurityContext(refgid); + if (b != null) { //move The data + moveData(ctx, null, map); + } else { //load the collection for the specified group + ExperimenterData exp = TreeViewerAgent.getUserDetails(); + MoveGroupSelectionDialog dialog = new MoveGroupSelectionDialog(view, + exp.getId(), group, map); + UIUtilities.centerAndShow(dialog); + model.fireMoveDataLoading(ctx, dialog, b); + } } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerControl.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerControl.java index 536ca5b96bc..9e053830857 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerControl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerControl.java @@ -42,6 +42,8 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; + +import javax.swing.Action; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JMenu; @@ -85,12 +87,14 @@ import org.openmicroscopy.shoola.agents.treeviewer.actions.ManageRndSettingsAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.ManagerAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.MetadataVisibilityAction; +import org.openmicroscopy.shoola.agents.treeviewer.actions.MoveToAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.NewObjectAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.PasswordResetAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.PersonalManagementAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.RefreshExperimenterData; import org.openmicroscopy.shoola.agents.treeviewer.actions.RefreshTreeAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.RemoveExperimenterNode; +import org.openmicroscopy.shoola.agents.treeviewer.actions.RemoveGroupNode; import org.openmicroscopy.shoola.agents.treeviewer.actions.RollOverAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.RunScriptAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.SearchAction; @@ -129,9 +133,11 @@ import org.openmicroscopy.shoola.env.data.model.FigureParam; import org.openmicroscopy.shoola.env.data.model.ScriptActivityParam; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.ui.UserNotifier; import org.openmicroscopy.shoola.util.ui.JXTaskPaneContainerSingle; import org.openmicroscopy.shoola.util.ui.LoadingWindow; +import org.openmicroscopy.shoola.util.ui.MacOSMenuHandler; import org.openmicroscopy.shoola.util.ui.UIUtilities; import org.openmicroscopy.shoola.util.ui.filechooser.FileChooser; import pojos.DataObject; @@ -355,6 +361,9 @@ class TreeViewerControl /** Identifies the Available scripts/code>. */ static final Integer AVAILABLE_SCRIPTS = Integer.valueOf(70); + /** Identifies the Remove the group/code>. */ + static final Integer REMOVE_GROUP = Integer.valueOf(71); + /** * Reference to the {@link TreeViewer} component, which, in this context, * is regarded as the Model. @@ -373,6 +382,9 @@ class TreeViewerControl /** The loading window. */ private LoadingWindow loadingWindow; + /** One per group.*/ + private List moveActions; + /** * Downloads the possible script. * @@ -402,7 +414,9 @@ public void propertyChange(PropertyChangeEvent evt) { folder, icons.getIcon(IconManager.DOWNLOAD_22)); UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); - un.notifyActivity(activity); + SecurityContext ctx = new SecurityContext( + TreeViewerAgent.getUserDetails().getDefaultGroup().getId()); + un.notifyActivity(ctx, activity); } } }); @@ -542,6 +556,7 @@ private void createActions() new CreateObjectWithChildren(model, CreateObjectWithChildren.DATASET)); actionsMap.put(AVAILABLE_SCRIPTS, new RunScriptAction(model)); + actionsMap.put(REMOVE_GROUP, new RemoveGroupNode(model)); } /** @@ -565,6 +580,13 @@ private void createWindowsMenuItems(JMenu menu) */ private void attachListeners() { + if (UIUtilities.isMacOS()) { + try { + MacOSMenuHandler handler = new MacOSMenuHandler(view); + handler.initialize(); + view.addPropertyChangeListener(this); + } catch (Throwable e) {} + } Map browsers = model.getBrowsers(); Iterator i = browsers.values().iterator(); Browser browser; @@ -699,6 +721,25 @@ List getApplicationActions() return l; } + /** + * Returns the actions used to move data between groups. + * + * @return See abo.ve + */ + List getMoveAction() + { + if (moveActions != null) return moveActions; + Set l = TreeViewerAgent.getAvailableUserGroups(); + ViewerSorter sorter = new ViewerSorter(); + List values = sorter.sort(l); + moveActions = new ArrayList(l.size()); + Iterator i = values.iterator(); + while (i.hasNext()) { + moveActions.add(new MoveToAction(model, (GroupData) i.next())); + } + return moveActions; + } + /** * Returns the {@link ChangeListener} attached to the tab pane, * or creates one if none initialized. @@ -764,20 +805,19 @@ void attachUIListeners(JComponent component) /** * Returns the list of group the user is a member of. * + * @param add Passes true to add the group to the display, + * false to switch. * @return See above. */ - List getUserGroupAction() + List getUserGroupAction(boolean add) { List l = new ArrayList(); Set m = TreeViewerAgent.getAvailableUserGroups(); if (m == null || m.size() == 0) return l; ViewerSorter sorter = new ViewerSorter(); Iterator i = sorter.sort(m).iterator(); - GroupData group; - GroupSelectionAction action; while (i.hasNext()) { - group = (GroupData) i.next(); - l.add(new GroupSelectionAction(model, group)); + l.add(new GroupSelectionAction(model, (GroupData) i.next(), add)); } return l; } @@ -792,6 +832,8 @@ private void handleScript(ScriptObject script, int index) { if (script == null) return; + SecurityContext ctx = new SecurityContext( + TreeViewerAgent.getUserDetails().getDefaultGroup().getId()); UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); if (index == ScriptActivityParam.VIEW) { Environment env = (Environment) @@ -804,13 +846,13 @@ private void handleScript(ScriptObject script, int index) script.getScriptID(), DownloadActivityParam.ORIGINAL_FILE, f, null); activity.setApplicationData(new ApplicationData("")); - un.notifyActivity(activity); + un.notifyActivity(ctx, activity); } else if (index == ScriptActivityParam.DOWNLOAD) { downloadScript(new ScriptActivityParam(script, ScriptActivityParam.DOWNLOAD)); } else { - un.notifyActivity(new ScriptActivityParam(script, - ScriptActivityParam.RUN)); + //un.notifyActivity(new ScriptActivityParam(script, + // ScriptActivityParam.RUN)); } } @@ -1176,8 +1218,10 @@ public void propertyChange(PropertyChangeEvent pce) activity = new FigureActivityParam(object, ids, klass, FigureActivityParam.SPLIT_VIEW_FIGURE); activity.setIcon(icon); - un.notifyActivity(activity); + //TODO:review + //un.notifyActivity(activity); } else if (MetadataViewer.HANDLE_SCRIPT_PROPERTY.equals(name)) { + /* UserNotifier un = TreeViewerAgent.getRegistry().getUserNotifier(); ScriptActivityParam p = (ScriptActivityParam) pce.getNewValue(); int index = p.getIndex(); @@ -1193,12 +1237,14 @@ public void propertyChange(PropertyChangeEvent pce) p.getScript().getScriptID(), DownloadActivityParam.ORIGINAL_FILE, f, null); activity.setApplicationData(new ApplicationData("")); - un.notifyActivity(activity); + //TODO:review + //un.notifyActivity(activity); } else if (index == ScriptActivityParam.DOWNLOAD) { downloadScript(p); } else { - un.notifyActivity(pce.getNewValue()); - } + //TODO:review + //un.notifyActivity(pce.getNewValue()); + }*/ } else if (OpenWithDialog.OPEN_DOCUMENT_PROPERTY.equals(name)) { ApplicationData data = (ApplicationData) pce.getNewValue(); //Register @@ -1246,11 +1292,11 @@ public void propertyChange(PropertyChangeEvent pce) } } } else if (DataBrowser.SET__OWNER_RND_SETTINGS_PROPERTY.equals(name)) { - PasteRndSettingsCmd cmd = new PasteRndSettingsCmd(model, + PasteRndSettingsCmd cmd = new PasteRndSettingsCmd(model, PasteRndSettingsCmd.SET_OWNER); cmd.execute(); } else if (ScriptingDialog.RUN_SELECTED_SCRIPT_PROPERTY.equals(name)) { - handleScript((ScriptObject) pce.getNewValue(), + handleScript((ScriptObject) pce.getNewValue(), ScriptActivityParam.RUN); } else if (ScriptingDialog.DOWNLOAD_SELECTED_SCRIPT_PROPERTY.equals( name)) { @@ -1280,6 +1326,13 @@ else if (value instanceof String) { DataBrowser.SELECTED_DATA_BROWSER_NODES_DISPLAY_PROPERTY.equals( name)) { model.setSelectedNodes(pce.getNewValue()); + } else if (TreeViewer.GROUP_CHANGED_PROPERTY.equals(name)) { + view.setPermissions(); + } else if (MacOSMenuHandler.QUIT_APPLICATION_PROPERTY.equals(name)) { + Action a = getAction(EXIT); + ActionEvent event = + new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ""); + a.actionPerformed(event); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerFactory.java index 30b3cbac60c..bdb53a37368 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerFactory.java @@ -193,14 +193,12 @@ static void attachWindowMenuToTaskBar() /** * Returns the {@link TreeViewer}. * - * @param exp The experiment the TreeViewer is for. - * @param userGroupID The id to the group selected for the current user. + * @param exp The experiment the TreeViewer is for. * @return See above. */ - public static TreeViewer getTreeViewer(ExperimenterData exp, - long userGroupID) + public static TreeViewer getTreeViewer(ExperimenterData exp) { - TreeViewerModel model = new TreeViewerModel(exp, userGroupID); + TreeViewerModel model = new TreeViewerModel(exp); return singleton.getTreeViewer(model, null); } @@ -273,19 +271,31 @@ public static void onGroupSwitched(boolean success) } } + /** + * Notifies the model that the user is reconnected. + */ + public static void onReconnected() + { + Iterator v = singleton.viewers.iterator(); + TreeViewerComponent comp; + while (v.hasNext()) { + comp = (TreeViewerComponent) v.next(); + comp.onReconnected(); + } + } + /** * Returns the {@link TreeViewer}. * - * @param exp The experiment the TreeViewer is for. - * @param userGroupID The id to the group selected for the current user. - * @param bounds The bounds of the component invoking a new - * {@link TreeViewer}. + * @param exp The experiment the TreeViewer is for. + * @param bounds The bounds of the component invoking a new + * {@link TreeViewer}. * @return See above. */ public static TreeViewer getTreeViewer(ExperimenterData exp, - long userGroupID, Rectangle bounds) + Rectangle bounds) { - TreeViewerModel model = new TreeViewerModel(exp, userGroupID); + TreeViewerModel model = new TreeViewerModel(exp); return singleton.getTreeViewer(model, bounds); } @@ -378,10 +388,8 @@ private TreeViewer getTreeViewer(TreeViewerModel model, Rectangle bounds) TreeViewerComponent comp; while (v.hasNext()) { comp = (TreeViewerComponent) v.next(); - if (model.isSameDisplay(comp.getModel())) { - comp.setRecycled(true); - return comp; - } + comp.setRecycled(true); + return comp; } //if (viewer != null) return viewer; readExternalApplications(); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerModel.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerModel.java index bc1d728c6a0..497c7795078 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerModel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerModel.java @@ -41,7 +41,6 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; -import org.openmicroscopy.shoola.agents.metadata.MetadataViewerAgent; import org.openmicroscopy.shoola.agents.metadata.rnd.Renderer; import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewer; import org.openmicroscopy.shoola.agents.metadata.view.MetadataViewerFactory; @@ -52,6 +51,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.DataTreeViewerLoader; import org.openmicroscopy.shoola.agents.treeviewer.ExistingObjectsLoader; import org.openmicroscopy.shoola.agents.treeviewer.ExistingObjectsSaver; +import org.openmicroscopy.shoola.agents.treeviewer.MoveDataLoader; import org.openmicroscopy.shoola.agents.treeviewer.OriginalFileLoader; import org.openmicroscopy.shoola.agents.treeviewer.ParentLoader; import org.openmicroscopy.shoola.agents.treeviewer.PlateWellsLoader; @@ -65,6 +65,7 @@ import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; import org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserFactory; import org.openmicroscopy.shoola.agents.treeviewer.finder.Finder; +import org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; @@ -78,6 +79,7 @@ import org.openmicroscopy.shoola.env.data.model.ApplicationData; import org.openmicroscopy.shoola.env.data.model.ScriptObject; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.util.ui.UIUtilities; import pojos.DataObject; @@ -86,7 +88,6 @@ import pojos.FileAnnotationData; import pojos.GroupData; import pojos.ImageData; -import pojos.PermissionData; import pojos.PixelsData; import pojos.PlateData; import pojos.ProjectData; @@ -129,12 +130,6 @@ class TreeViewerModel /** The currently selected {@link Browser}. */ private Browser selectedBrowser; - /** The ID of the root. */ - private long rootID; - - /** The id of the selected group of the current user. */ - private long userGroupID; - /** The currently selected experimenter. */ private ExperimenterData experimenter; @@ -186,6 +181,12 @@ class TreeViewerModel /** Scripts with a UI. */ private List scriptsWithUI; + /** The security context for the administrator.*/ + private SecurityContext adminContext; + + /** The id of the group the currently selected node is in.*/ + private long selectedGroupId; + /** * Returns the collection of scripts with a UI, mainly the figure scripts. * @@ -197,13 +198,14 @@ private List getScriptsWithUI() try { OmeroImageService svc = TreeViewerAgent.getRegistry().getImageService(); - scriptsWithUI = svc.loadAvailableScriptsWithUI(); + scriptsWithUI = svc.loadAvailableScriptsWithUI( + getSecurityContext(null)); return scriptsWithUI; } catch (Exception e) { LogMessage msg = new LogMessage(); msg.print("Scripts with UI"); msg.print(e); - MetadataViewerAgent.getRegistry().getLogger().error(this, msg); + TreeViewerAgent.getRegistry().getLogger().error(this, msg); } return new ArrayList(); } @@ -335,26 +337,17 @@ private void initialize() importing = false; sorter = new ViewerSorter(); } - - /** - * Creates a new instance and sets the state to {@link TreeViewer#NEW}. - */ - protected TreeViewerModel() - { - initialize(); - } /** * Creates a new instance and sets the state to {@link TreeViewer#NEW}. * - * @param exp The experimenter this manager is for. - * @param userGroupID The id to the group selected for the current user. + * @param exp The experimenter this manager is for. */ - protected TreeViewerModel(ExperimenterData exp, long userGroupID) + protected TreeViewerModel(ExperimenterData exp) { initialize(); this.experimenter = exp; - setHierarchyRoot(exp.getId(), userGroupID); + selectedGroupId = exp.getDefaultGroup().getId(); } /** @@ -369,34 +362,6 @@ void initialize(TreeViewer component) createBrowsers(); } - /** - * Sets the root of the retrieved hierarchies. - * - * @param rootID The Id of the root. By default it is the - * id of the current user. - * @param userGroupID The id to the group selected for the current user. - */ - void setHierarchyRoot(long rootID, long userGroupID) - { - this.rootID = rootID; - this.userGroupID = userGroupID; - } - - /** - * Compares another model to this one to tell if they would result in - * having the same display. - * - * @param other The other model to compare. - * @return true if other would lead to a viewer - * with the same display as the one in which this model belongs; - * false otherwise. - */ - boolean isSameDisplay(TreeViewerModel other) - { - if (other == null) return false; - return ((other.rootID == rootID) && (other.userGroupID == userGroupID)); - } - /** * Returns true if the {@link TreeViewer} is recycled, * false otherwise. @@ -413,13 +378,6 @@ boolean isSameDisplay(TreeViewerModel other) */ void setRecycled(boolean b) { recycled = b; } - /** - * Returns the id to the group selected for the current user. - * - * @return See above. - */ - long getUserGroupID() { return userGroupID; } - /** * Sets the currently selected {@link Browser}. * @@ -482,7 +440,8 @@ void cancel() void fireObjectsDeletion(List values) { state = TreeViewer.SAVE; - currentLoader = new DataObjectRemover(component, values); + SecurityContext ctx = getSecurityContext(); + currentLoader = new DataObjectRemover(component, ctx, values); currentLoader.load(); } @@ -527,7 +486,11 @@ ExperimenterData getUserDetails() void fireDataExistingObjectsLoader(DataObject ho) { state = TreeViewer.LOADING_DATA; - currentLoader = new ExistingObjectsLoader(component, ho); + SecurityContext ctx = getSecurityContext(); + if (TreeViewerAgent.isAdministrator()) + ctx = adminContext; + //if (TreeViewerAgent.isAdministrator()) ctx = adminC + currentLoader = new ExistingObjectsLoader(component, ctx, ho); currentLoader.load(); } @@ -542,8 +505,9 @@ void fireAddExistingObjects(Set children) TreeImageDisplay parent = selectedBrowser.getLastSelectedDisplay(); if (parent == null) return; Object po = parent.getUserObject(); + SecurityContext ctx = getSecurityContext(); if ((po instanceof ProjectData) || ((po instanceof DatasetData))) { - currentLoader = new ExistingObjectsSaver(component, + currentLoader = new ExistingObjectsSaver(component, ctx, (DataObject) po, children); currentLoader.load(); } @@ -579,14 +543,20 @@ void setNodesToCopy(TreeImageDisplay[] nodes, int index) */ boolean paste(TreeImageDisplay[] parents) { + //Check if array contains Experimenter data + if (parents[0].getUserObject() instanceof ExperimenterData) { + copyIndex = TreeViewer.CUT_AND_PASTE; + return cut(); + } Map map = buildCopyMap(parents); + SecurityContext ctx = getSecurityContext(); if (map == null) return false; if (copyIndex == TreeViewer.COPY_AND_PASTE) - currentLoader = new DataObjectUpdater(component, map, + currentLoader = new DataObjectUpdater(component,ctx, map, DataObjectUpdater.COPY_AND_PASTE); else if (copyIndex == TreeViewer.CUT_AND_PASTE) { Map toRemove = buildCutMap(nodesToCopy); - currentLoader = new DataObjectUpdater(component, map, toRemove, + currentLoader = new DataObjectUpdater(component, ctx, map, toRemove, DataObjectUpdater.CUT_AND_PASTE); } currentLoader.load(); @@ -606,8 +576,9 @@ boolean cut() if (copyIndex != TreeViewer.CUT_AND_PASTE) return false; if (nodesToCopy == null || nodesToCopy.length == 0) return false; Map toRemove = buildCutMap(nodesToCopy); - currentLoader = new DataObjectUpdater(component, new HashMap(), toRemove, - DataObjectUpdater.CUT); + SecurityContext ctx = getSecurityContext(); + currentLoader = new DataObjectUpdater(component, ctx, + new HashMap(), toRemove, DataObjectUpdater.CUT); currentLoader.load(); state = TreeViewer.SAVE; return true; @@ -690,7 +661,8 @@ void firePasteRenderingSettings(List ids, Class klass) } if (toKeep.size() == 0) return; state = TreeViewer.SETTINGS_RND; - currentLoader = new RndSettingsSaver(component, klass, toKeep, + SecurityContext ctx = getSecurityContext(); + currentLoader = new RndSettingsSaver(component, ctx, klass, toKeep, refImage.getDefaultPixels().getId()); currentLoader.load(); } @@ -703,7 +675,8 @@ void firePasteRenderingSettings(List ids, Class klass) void firePasteRenderingSettings(TimeRefObject ref) { state = TreeViewer.SETTINGS_RND; - currentLoader = new RndSettingsSaver(component, ref, + SecurityContext ctx = getSecurityContext(); + currentLoader = new RndSettingsSaver(component, ctx, ref, refImage.getDefaultPixels().getId()); currentLoader.load(); } @@ -717,7 +690,8 @@ void firePasteRenderingSettings(TimeRefObject ref) void fireResetRenderingSettings(List ids, Class klass) { state = TreeViewer.SETTINGS_RND; - currentLoader = new RndSettingsSaver(component, klass, ids, + SecurityContext ctx = getSecurityContext(); + currentLoader = new RndSettingsSaver(component, ctx, klass, ids, RndSettingsSaver.RESET); currentLoader.load(); } @@ -730,7 +704,8 @@ void fireResetRenderingSettings(List ids, Class klass) void fireResetRenderingSettings(TimeRefObject ref) { state = TreeViewer.SETTINGS_RND; - currentLoader = new RndSettingsSaver(component, ref, + SecurityContext ctx = getSecurityContext(); + currentLoader = new RndSettingsSaver(component, ctx, ref, RndSettingsSaver.RESET); currentLoader.load(); } @@ -744,7 +719,8 @@ void fireResetRenderingSettings(TimeRefObject ref) void fireSetMinMax(List ids, Class klass) { state = TreeViewer.SETTINGS_RND; - currentLoader = new RndSettingsSaver(component, klass, ids, + SecurityContext ctx = getSecurityContext(); + currentLoader = new RndSettingsSaver(component, ctx, klass, ids, RndSettingsSaver.SET_MIN_MAX); currentLoader.load(); } @@ -758,7 +734,8 @@ void fireSetMinMax(List ids, Class klass) void fireSetOwnerRenderingSettings(List ids, Class klass) { state = TreeViewer.SETTINGS_RND; - currentLoader = new RndSettingsSaver(component, klass, ids, + SecurityContext ctx = getSecurityContext(); + currentLoader = new RndSettingsSaver(component, ctx, klass, ids, RndSettingsSaver.SET_OWNER); currentLoader.load(); } @@ -771,7 +748,8 @@ void fireSetOwnerRenderingSettings(List ids, Class klass) void fireSetOriginalRenderingSettings(TimeRefObject ref) { state = TreeViewer.SETTINGS_RND; - currentLoader = new RndSettingsSaver(component, ref, + SecurityContext ctx = getSecurityContext(); + currentLoader = new RndSettingsSaver(component, ctx, ref, RndSettingsSaver.SET_MIN_MAX); currentLoader.load(); } @@ -785,7 +763,8 @@ void fireSetOriginalRenderingSettings(TimeRefObject ref) void fireSetOwnerRenderingSettings(TimeRefObject ref) { state = TreeViewer.SETTINGS_RND; - currentLoader = new RndSettingsSaver(component, ref, + SecurityContext ctx = getSecurityContext(); + currentLoader = new RndSettingsSaver(component, ctx, ref, RndSettingsSaver.SET_MIN_MAX); currentLoader.load(); } @@ -822,7 +801,8 @@ void fireDataObjectCreation(DataObject object, boolean withParent) } } } - currentLoader = new DataObjectCreator(component, object, data); + SecurityContext ctx = getSecurityContext(); + currentLoader = new DataObjectCreator(component, ctx, object, data); currentLoader.load(); } @@ -841,13 +821,15 @@ MetadataViewer getMetadataViewer() /** * Creates the advanced finder. * + * @param ctx The security context. * @return See above. */ - AdvancedFinder getAdvancedFinder() + AdvancedFinder getAdvancedFinder(SecurityContext ctx) { if (advancedFinder == null) advancedFinder = FinderFactory.getAdvancedFinder( - TreeViewerAgent.getRegistry()); + TreeViewerAgent.getRegistry(), + TreeViewerAgent.getAvailableUserGroups()); return advancedFinder; } @@ -860,8 +842,8 @@ void browseProject(TreeImageDisplay node) { state = TreeViewer.LOADING_DATA; ExperimenterData exp = getSelectedBrowser().getNodeOwner(node); - currentLoader = new ProjectsLoader(component, node, exp.getId(), - getUserGroupID()); + SecurityContext ctx = getSecurityContext(); + currentLoader = new ProjectsLoader(component, ctx, node, exp.getId()); currentLoader.load(); } @@ -879,7 +861,9 @@ void browsePlates(Collection nodes, boolean withThumbnails) Iterator i = nodes.iterator(); while (i.hasNext()) plates.add((TreeImageSet) i.next()); - currentLoader = new PlateWellsLoader(component, plates, withThumbnails); + SecurityContext ctx = getSecurityContext(); + currentLoader = new PlateWellsLoader(component, ctx, plates, + withThumbnails); currentLoader.load(); } @@ -891,7 +875,8 @@ void browsePlates(Collection nodes, boolean withThumbnails) void browseTimeInterval(TreeImageTimeSet node) { state = TreeViewer.LOADING_DATA; - currentLoader = new TimeIntervalsLoader(component, node); + SecurityContext ctx = getSecurityContext(); + currentLoader = new TimeIntervalsLoader(component, ctx, node); currentLoader.load(); } @@ -905,7 +890,9 @@ void browseTag(TreeImageDisplay node) state = TreeViewer.LOADING_DATA; ExperimenterData exp = getSelectedBrowser().getNodeOwner(node); if (exp == null) exp = TreeViewerAgent.getUserDetails(); - currentLoader = new TagHierarchyLoader(component, node, exp.getId()); + SecurityContext ctx = getSecurityContext(); + currentLoader = new TagHierarchyLoader(component, ctx, + node, exp.getId()); currentLoader.load(); } @@ -953,6 +940,23 @@ Class getDataToCopyType() return ho.getClass(); } + /** + * Returns the objects to copy. + * + * @return See above. + */ + List getDataToCopy() + { + TreeImageDisplay[] nodes = getNodesToCopy(); + if (nodes == null || nodes.length == 0) return null; + List l = new ArrayList(); + for (int i = 0; i < nodes.length; i++) { + if (nodes[i].getUserObject() instanceof DataObject) + l.add((DataObject) nodes[i].getUserObject()); + } + return l; + } + /** * Sets the {@link DataBrowser}. * @@ -970,43 +974,6 @@ void setDataViewer(DataBrowser dataViewer) */ DataBrowser getDataViewer() { return dataViewer; } - /** - * Returns true if the multiple users flag is turned on, - * false otherwise. - * - * @return See above. - */ - boolean isMultiUser() - { - Boolean b = (Boolean) TreeViewerAgent.getRegistry().lookup( - TreeViewerAgent.MULTI_USER); - if (!b) return false; - - ExperimenterData exp = getExperimenter(); - /* - ExperimenterData exp = getExperimenter(); - Map map = exp.isLeader(); - if (map.containsKey(userGroupID)) { - b = map.get(userGroupID); - if (b) return true; - } - */ - //Now we check the status of the group. - List l = exp.getGroups(); - GroupData group; - Iterator i = l.iterator(); - PermissionData permission; - while (i.hasNext()) { - group = i.next(); - //Check status of that group - if (group.getId() == userGroupID) { - permission = group.getPermissions(); - return (permission.isGroupRead() && permission.isGroupWrite()); - } - } - return false; - } - /** * Starts an asynchronous call to download the images. * @@ -1034,7 +1001,8 @@ void downloadImages(List images, File folder, } } } - OriginalFileLoader loader = new OriginalFileLoader(component, ids, + SecurityContext ctx = getSecurityContext(); + OriginalFileLoader loader = new OriginalFileLoader(component, ctx, ids, folder, application); loader.load(); } @@ -1131,36 +1099,6 @@ boolean isAdministrator() return TreeViewerAgent.isAdministrator(); } - /** - * Sets the id of the currently selected group. - * - * @param groupID The value to set. - */ - void setGroupId(long groupID) - { - this.userGroupID = groupID; - } - - /** - * Returns true if the currently logged in user is - * a leader of the selected group, false. - * - * @return See above. - */ - boolean isLeaderOfSelectedGroup() - { - Set groups = TreeViewerAgent.getGroupsLeaderOf(); - if (groups.size() == 0) return false; - Iterator i = groups.iterator(); - GroupData group; - while (i.hasNext()) { - group = (GroupData) i.next(); - if (group.getId() == userGroupID) - return true; - } - return false; - } - /** * Fires an asynchronous call to create groups or experimenters. * @@ -1168,7 +1106,10 @@ boolean isLeaderOfSelectedGroup() */ void fireAdmin(AdminObject object) { - currentLoader = new AdminCreator(component, object); + SecurityContext ctx = getSecurityContext(); + if (TreeViewerAgent.isAdministrator()) + ctx = adminContext; + currentLoader = new AdminCreator(component, ctx, object); currentLoader.load(); } @@ -1200,7 +1141,8 @@ void fireAdmin(AdminObject object) */ void loadParentOf(FileAnnotationData data) { - ParentLoader loader = new ParentLoader(component, data); + SecurityContext ctx = new SecurityContext(data.getGroupId()); + ParentLoader loader = new ParentLoader(component, ctx, data); loader.load(); } @@ -1212,9 +1154,10 @@ void loadParentOf(FileAnnotationData data) */ void fireDataSaving(DataObject data, Collection children) { - if (data instanceof DatasetData) { - DataObjectCreator loader = new DataObjectCreator(component, data, - null, children); + if (data instanceof DatasetData) { + SecurityContext ctx = getSecurityContext(); + DataObjectCreator loader = new DataObjectCreator(component, ctx, + data, null, children); loader.load(); } } @@ -1230,13 +1173,15 @@ ScriptObject getScript(long scriptID) return scripts.get(scriptID); } - /** Loads the scripts. + /** + * Loads the scripts. * * @param location The location of the mouse. */ void loadScripts(Point location) { - ScriptsLoader loader = new ScriptsLoader(component, false, location); + ScriptsLoader loader = new ScriptsLoader(component, + getSecurityContext(null), false, location); loader.load(); } @@ -1281,7 +1226,8 @@ void setAvailableScripts(List scripts) */ void loadScript(long scriptID) { - ScriptLoader loader = new ScriptLoader(component, scriptID); + ScriptLoader loader = new ScriptLoader(component, + getSecurityContext(null), scriptID); loader.load(); } @@ -1326,13 +1272,95 @@ void transfer(TreeImageDisplay target, List nodes) new TreeImageDisplay[0]); copyIndex = TreeViewer.CUT_AND_PASTE; Map toRemove = buildCutMap(nodesToCopy); - TreeImageDisplay[] parents = new TreeImageDisplay[1]; - parents[0] = target; - Map map = buildCopyMap(parents); - currentLoader = new DataObjectUpdater(component, map, toRemove, + Map map = new HashMap(); + if (target != null) { + TreeImageDisplay[] parents = new TreeImageDisplay[1]; + parents[0] = target; + map = buildCopyMap(parents); + } + SecurityContext ctx = getSecurityContext(); + currentLoader = new DataObjectUpdater(component, ctx, map, toRemove, DataObjectUpdater.CUT_AND_PASTE); currentLoader.load(); state = TreeViewer.SAVE; } + /** + * Returns the security context. + * + * @return See above + */ + SecurityContext getSecurityContext() + { + Browser browser = getSelectedBrowser(); + if (browser == null) + return new SecurityContext( + TreeViewerAgent.getUserDetails().getDefaultGroup().getId()); + return browser.getSecurityContext(browser.getLastSelectedDisplay()); + } + + /** + * Returns the security context. + * + * @return See above + */ + SecurityContext getSecurityContext(TreeImageDisplay node) + { + Browser browser = getSelectedBrowser(); + if (browser == null) + return new SecurityContext( + TreeViewerAgent.getUserDetails().getDefaultGroup().getId()); + return browser.getSecurityContext(node); + } + + /** + * Returns the group the currently selected node belongs to or the default + * group if no node selected. + * + * @return See above. + */ + GroupData getSelectedGroup() + { + Set set = TreeViewerAgent.getAvailableUserGroups(); + Iterator i = set.iterator(); + GroupData g; + while (i.hasNext()) { + g = (GroupData) i.next(); + if (g.getId() == selectedGroupId) + return g; + } + return null; + } + + /** + * Returns the id of the group. + * + * @return See above. + */ + long getSelectedGroupId() { return selectedGroupId; } + + /** + * Sets the selected group. + * + * @param selectedGroupId The identifier of the group. + */ + void setSelectedGroupId(long selectedGroupId) + { + this.selectedGroupId = selectedGroupId; + } + + /** + * Loads the data. + * + * @param ctx The security context. + * @param dialog The dialog where to display the result. + * @param type The node type. + */ + void fireMoveDataLoading(SecurityContext ctx, + MoveGroupSelectionDialog dialog, Class type) + { + MoveDataLoader loader = new MoveDataLoader(component, ctx, type, dialog); + loader.load(); + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerWin.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerWin.java index 51d8e54690f..c4b7697a1b3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerWin.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerWin.java @@ -58,6 +58,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; +import org.openmicroscopy.shoola.agents.treeviewer.actions.MoveToAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.NewObjectAction; import org.openmicroscopy.shoola.agents.treeviewer.actions.TreeViewerAction; import org.openmicroscopy.shoola.agents.treeviewer.browser.Browser; @@ -259,7 +260,8 @@ private void layoutBrowsers() browser = browsers.get(Browser.ADMIN_EXPLORER); container.add(new TaskPaneBrowser(browser)); } - AdvancedFinder finder = model.getAdvancedFinder(); + AdvancedFinder finder = model.getAdvancedFinder( + model.getSecurityContext()); finder.addPropertyChangeListener(controller); container.add(new TaskPaneBrowser(new JScrollPane(finder))); JScrollPane s = new JScrollPane(container); @@ -473,8 +475,28 @@ private JMenu createEditMenu() controller.getAction(TreeViewerControl.PASTE_OBJECT))); menu.add(new JMenuItem( controller.getAction(TreeViewerControl.DELETE_OBJECT))); + JMenu move = createMoveToMenu(); + if (move != null) + menu.add(move); return menu; } + + /** + * Creates a menu if the various groups the data can be moved to. + * + * @return See above. + */ + private JMenu createMoveToMenu() + { + List actions = controller.getMoveAction(); + if (actions.size() <= 1) return null; + JMenu menu = new JMenu(MoveToAction.NAME); + Iterator i = actions.iterator(); + while (i.hasNext()) { + menu.add(new JMenuItem(i.next())); + } + return menu; + } /** Initializes the UI components. */ private void initComponents() @@ -877,7 +899,8 @@ else if (displayMode == TreeViewer.EXPLORER_MODE) displayMode = TreeViewer.SEARCH_MODE; splitPane.setDividerLocation(splitPane.getDividerLocation()); if (finderScrollPane == null) { - AdvancedFinder finder = model.getAdvancedFinder(); + AdvancedFinder finder = model.getAdvancedFinder( + model.getSecurityContext()); finder.addPropertyChangeListener(controller); finderScrollPane = new JScrollPane(finder); } @@ -1118,6 +1141,9 @@ void setScriptsLoadingStatus(boolean loading) toolBar.setScriptsLoadingStatus(loading); } + /** Indicates the group context.*/ + void setPermissions() { toolBar.setPermissions(); } + /** Overrides the {@link #setOnScreen() setOnScreen} method. */ public void setOnScreen() { @@ -1127,6 +1153,4 @@ public void setOnScreen() invokerBounds = null; } - - } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/EditorUtil.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/EditorUtil.java index a75855b9c83..0ad741a0c23 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/EditorUtil.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/EditorUtil.java @@ -2311,9 +2311,10 @@ public static TreeImageDisplay getDataOwner(TreeImageDisplay node) * * @param target The target of the D&D action. * @param src The node to transfer. + * @param userID The id of the user currently logged in. * @return See above. */ - public static boolean isTransferable(Object target, Object src) + public static boolean isTransferable(Object target, Object src, long userID) { if (target instanceof ProjectData && src instanceof DatasetData) return true; @@ -2321,9 +2322,17 @@ else if (target instanceof DatasetData && src instanceof ImageData) return true; else if (target instanceof ScreenData && src instanceof PlateData) return true; - else if (target instanceof GroupData && src instanceof ExperimenterData) - return true; - else if (target instanceof TagAnnotationData + else if (target instanceof GroupData) { + if (src instanceof ExperimenterData) return true; + if (src instanceof DataObject) { + GroupData g = (GroupData) target; + DataObject data = (DataObject) src; + return (g.getId() != data.getGroupId()); + } + } else if (target instanceof ExperimenterData) { + ExperimenterData exp = (ExperimenterData) target; + return exp.getId() == userID; + } else if (target instanceof TagAnnotationData && src instanceof TagAnnotationData) { TagAnnotationData tagSet = (TagAnnotationData) target; TagAnnotationData tag = (TagAnnotationData) src; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/browser/TreeImageDisplay.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/browser/TreeImageDisplay.java index 62ffbaf538e..15a20a602bd 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/browser/TreeImageDisplay.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/browser/TreeImageDisplay.java @@ -159,6 +159,9 @@ public abstract class TreeImageDisplay /** Flag indicating that the node has to be refreshed. */ protected boolean toRefresh; + /** Indicates to display or not the number of items.*/ + private boolean displayItems; + /** * Checks if the algorithm to visit the tree is one of the constants * defined by {@link TreeImageDisplayVisitor}. @@ -197,6 +200,7 @@ protected TreeImageDisplay(Object hierarchyObject) numberItems = -1; partialName = true; fontStyle = FONT_PLAIN; + displayItems = true; } /** @@ -487,6 +491,7 @@ else if (uo instanceof String && numberItems < 0) return name; else if ((uo instanceof PlateData) && !hasChildrenDisplay()) return name; + if (!displayItems) return name; if (numberItems < 0) return (name+SPACE+"[...]"); return (name+SPACE+"["+numberItems+"]"); } @@ -596,6 +601,17 @@ public long getUserObjectId() */ public boolean isToRefresh() { return toRefresh; } + /** + * Sets to true to display the number of items, + * false otherwise. + * + * @param displayItems The value to set. + */ + public void setDisplayItems(boolean displayItems) + { + this.displayItems = displayItems; + } + /** * Overridden to return the name of the hierarchy object. * @see Object#toString() diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/browser/TreeViewerTranslator.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/browser/TreeViewerTranslator.java index 2290596c532..f609c81bd82 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/browser/TreeViewerTranslator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/browser/TreeViewerTranslator.java @@ -41,18 +41,17 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.agents.treeviewer.TreeViewerAgent; import org.openmicroscopy.shoola.agents.util.browser.TreeFileSet; import org.openmicroscopy.shoola.agents.util.browser.TreeImageDisplay; import org.openmicroscopy.shoola.agents.util.browser.TreeImageNode; import org.openmicroscopy.shoola.agents.util.browser.TreeImageSet; import org.openmicroscopy.shoola.agents.util.browser.TreeImageTimeSet; import org.openmicroscopy.shoola.agents.util.EditorUtil; -import org.openmicroscopy.shoola.env.data.model.TimeRefObject; -import org.openmicroscopy.shoola.env.data.views.MetadataHandlerView; +import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.util.ui.IconManager; import org.openmicroscopy.shoola.util.ui.UIUtilities; import org.openmicroscopy.shoola.util.ui.clsf.TreeCheckNode; - import pojos.AnnotationData; import pojos.DataObject; import pojos.DatasetData; @@ -829,20 +828,34 @@ public static Set transformGroups(Collection groups) TreeImageSet n; while (i.hasNext()) { g = (GroupData) i.next(); - n = new TreeImageSet(g); - l = g.getExperimenters(); - if (l != null && l.size() > 0) { - n.setChildrenLoaded(Boolean.valueOf(true)); - j = l.iterator(); - while (j.hasNext()) - n.addChildDisplay(new TreeImageNode(j.next())); - n.setNumberItems(l.size()); - } else n.setNumberItems(0); - nodes.add(n); + n = transformGroup(g); + if (n != null) nodes.add(n); } return nodes; } + /** + * Transforms the specified group into its corresponding UI entity. + * + * @param group The group to transform + * @return See above. + */ + public static TreeImageSet transformGroup(GroupData group) + { + if (group == null) return null; + TreeImageSet n = new TreeImageSet(group); + Collection l = group.getExperimenters(); + if (l != null && l.size() > 0) { + n.setChildrenLoaded(Boolean.valueOf(true)); + Iterator j = l.iterator(); + while (j.hasNext()) + n.addChildDisplay(new TreeImageNode(j.next())); + n.setNumberItems(l.size()); + } else n.setNumberItems(0); + formatToolTipFor(n); + return n; + } + /** * Transforms the passed collection. * @@ -908,6 +921,27 @@ public static void formatToolTipFor(TreeImageDisplay node) if (uo instanceof ImageData) { l = EditorUtil.formatObjectTooltip((ImageData) uo); s = UIUtilities.formatString(((ImageData) uo).getName(), -1); + } else if (uo instanceof GroupData) { + int level = + TreeViewerAgent.getRegistry().getAdminService().getPermissionLevel( + (GroupData) uo); + switch (level) { + case AdminObject.PERMISSIONS_PRIVATE: + node.setToolTip(AdminObject.PERMISSIONS_PRIVATE_TEXT); + break; + case AdminObject.PERMISSIONS_GROUP_READ: + node.setToolTip(AdminObject.PERMISSIONS_GROUP_READ_TEXT); + break; + case AdminObject.PERMISSIONS_GROUP_READ_LINK: + node.setToolTip(AdminObject.PERMISSIONS_GROUP_READ_LINK_TEXT); + break; + case AdminObject.PERMISSIONS_PUBLIC_READ: + node.setToolTip(AdminObject.PERMISSIONS_PUBLIC_READ_TEXT); + break; + case AdminObject.PERMISSIONS_PUBLIC_READ_WRITE: + node.setToolTip(AdminObject.PERMISSIONS_PUBLIC_READ_WRITE_TEXT); + } + return; } if (l == null || l.size() == 0) node.setToolTip(s); else { diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/dnd/DnDTree.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/dnd/DnDTree.java index 73de08fb452..99c8b4a599f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/dnd/DnDTree.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/dnd/DnDTree.java @@ -195,12 +195,15 @@ private void handleMouseOver(TreeImageDisplay node, parent = (TreeImageDisplay) node.getParent(); } Object ot = parent.getUserObject(); + /* if (ot instanceof GroupData && !administrator) { setCursor(createCursor()); dropAllowed = false; return; } - if (!isUserOwner(ot)) { + */ + if (!isUserOwner(ot) && + !(ot instanceof ExperimenterData || ot instanceof GroupData)) { dropAllowed = false; setCursor(createCursor()); return; @@ -222,6 +225,15 @@ private void handleMouseOver(TreeImageDisplay node, nodes.add((TreeImageDisplay) droppedObject); } if (nodes.size() == 0) return; + //Check the first node + TreeImageDisplay first = nodes.get(0); + Object child = first.getUserObject(); + if (ot instanceof GroupData && child instanceof ExperimenterData && + !administrator) { + setCursor(createCursor()); + dropAllowed = false; + return; + } List list = new ArrayList(); Iterator i = nodes.iterator(); TreeImageDisplay n; @@ -234,9 +246,13 @@ private void handleMouseOver(TreeImageDisplay node, if (parent.contains(n)) { childCount++; } else { - if (EditorUtil.isTransferable(ot, os)) { + if (EditorUtil.isTransferable(ot, os, userID)) { if (ot instanceof GroupData) { - if (administrator) list.add(n); + if (os instanceof ExperimenterData && + administrator) list.add(n); + else { + if (isUserOwner(os)) list.add(n); + } } else { if (isUserOwner(os)) list.add(n); } @@ -493,7 +509,7 @@ public void drop(DropTargetDropEvent dtde) //if (dropNode instanceof TreeImageDisplay) { if (dropNode instanceof TreeImageDisplay) parent = (TreeImageDisplay) dropNode; - if (dropNode.isLeaf()) { + if (dropNode.isLeaf() && dropNode instanceof TreeImageNode) { parent = (TreeImageDisplay) dropNode.getParent(); } int action = DnDConstants.ACTION_MOVE; @@ -502,7 +518,10 @@ public void drop(DropTargetDropEvent dtde) firePropertyChange(DRAGGED_PROPERTY, null, transfer); //} dropped = true; - } catch (Exception e) {} + } catch (Exception e) { + dtde.rejectDrop(); + repaint(); + } dtde.dropComplete(dropped); repaint(); } @@ -554,7 +573,6 @@ public void dragGestureRecognized(DragGestureEvent e) */ public void dropActionChanged(DropTargetDragEvent dtde) {} - /** * Implemented as specified by {@link DragSourceListener} I/F but * no-operation in our case. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/dnd/ObjectToTransfer.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/dnd/ObjectToTransfer.java index e83d2695dca..9b1c11da6f0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/dnd/ObjectToTransfer.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/dnd/ObjectToTransfer.java @@ -66,6 +66,7 @@ public ObjectToTransfer(TreeImageDisplay target, { this.target = target; this.nodes = nodes; + this.dropAction = dropAction; } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/AdvancedFinder.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/AdvancedFinder.java index 33231474a25..323b367f641 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/AdvancedFinder.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/AdvancedFinder.java @@ -51,9 +51,11 @@ import org.openmicroscopy.shoola.agents.dataBrowser.DataBrowserAgent; import org.openmicroscopy.shoola.agents.util.EditorUtil; import org.openmicroscopy.shoola.agents.util.SelectionWizard; +import org.openmicroscopy.shoola.agents.util.ViewerSorter; import org.openmicroscopy.shoola.agents.util.ui.UserManagerDialog; import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.ui.UserNotifier; import org.openmicroscopy.shoola.util.ui.IconManager; import org.openmicroscopy.shoola.util.ui.UIUtilities; @@ -65,9 +67,13 @@ import pojos.DataObject; import pojos.DatasetData; import pojos.ExperimenterData; +import pojos.GroupData; import pojos.ImageData; +import pojos.PlateData; import pojos.ProjectData; +import pojos.ScreenData; import pojos.TagAnnotationData; +import pojos.WellData; /** * The class actually managing the search. @@ -88,19 +94,46 @@ public class AdvancedFinder { /** The default title of the notification message. */ - private static final String TITLE = "Search"; + private static final String TITLE = "Search"; /** Reference to the component handling data. */ - private List finderHandlers; + private FinderLoader loader; /** One of the constants defined by this class. */ - private int state; + private int state; /** Collection of selected users. */ - private Map users; + private Map users; /** The collection of tags. */ - private Collection tags; + private Collection tags; + + /** The available groups.*/ + private Collection groups; + + /** Host the result per group.*/ + private Map results; + + /** The total number of groups to search.*/ + private int total; + + /** + * Returns the name of the group corresponding to the security context. + * + * @param ctx The context to handle. + * @return See above + */ + private String getGroupName(SecurityContext ctx) + { + Iterator i = groups.iterator(); + GroupData g; + while (i.hasNext()) { + g = i.next(); + if (g.getId() == ctx.getGroupID()) + return g.getName(); + } + return null; + } /** * Determines the scope of the search. @@ -139,13 +172,12 @@ private Integer convertScope(int value) private Class convertType(int value) { switch (value) { - case SearchContext.DATASETS: - return DatasetData.class; - case SearchContext.PROJECTS: - return ProjectData.class; - case SearchContext.IMAGES: - return ImageData.class; - + case SearchContext.DATASETS: return DatasetData.class; + case SearchContext.PROJECTS: return ProjectData.class; + case SearchContext.IMAGES: return ImageData.class; + case SearchContext.SCREENS: return ScreenData.class; + case SearchContext.PLATES: return PlateData.class; + case SearchContext.WELLS: return WellData.class; default: return null; } @@ -307,10 +339,17 @@ private void handleSearchContext(SearchContext ctx) searchContext.setExcludedAnnotators(excludedAnnotators); searchContext.setCaseSensitive(ctx.isCaseSensitive()); searchContext.setNumberOfResults(ctx.getNumberOfResults()); - AdvancedFinderLoader loader = new AdvancedFinderLoader(this, - searchContext); + + List groups = ctx.getSelectedGroups(); + List l = new ArrayList(); + Iterator j = groups.iterator(); + while (j.hasNext()) { + l.add(new SecurityContext(j.next())); + } + total = l.size(); + results.clear(); + loader = new AdvancedFinderLoader(this, l, searchContext); loader.load(); - finderHandlers.add(loader); state = Finder.SEARCH; setSearchEnabled(true); } @@ -343,7 +382,8 @@ private void showUserSelection() IconManager icons = IconManager.getInstance(); UserManagerDialog dialog = new UserManagerDialog( FinderFactory.getRefFrame(), getUserDetails(), - getAvailableGroups(), icons.getIcon(IconManager.OWNER), + getUserDetails().getDefaultGroup(), + icons.getIcon(IconManager.OWNER), icons.getIcon(IconManager.OWNER_48)); dialog.addPropertyChangeListener(this); dialog.setDefaultSize(); @@ -376,7 +416,12 @@ public void actionPerformed(ActionEvent e) { private void loadTags() { if (tags == null) { - TagsLoader loader = new TagsLoader(this); + List l = new ArrayList(); + Iterator i = groups.iterator(); + while (i.hasNext()) { + l.add(new SecurityContext(i.next().getId())); + } + TagsLoader loader = new TagsLoader(this, l); loader.load(); } else setExistingTags(tags); } @@ -407,15 +452,23 @@ private void handleTagsSelection(Collection selected) setSomeValues(toAdd); } - /** Creates a new instance. */ - AdvancedFinder() + /** + * Creates a new instance. + * + * @param groups The available groups. + */ + AdvancedFinder(Collection groups) { - initialize(createControls()); - finderHandlers = new ArrayList(); + //sort + this.groups = groups; + ViewerSorter sorter = new ViewerSorter(); + List l = sorter.sort(groups); + initialize(createControls(), l); addPropertyChangeListener(SEARCH_PROPERTY, this); addPropertyChangeListener(CANCEL_SEARCH_PROPERTY, this); addPropertyChangeListener(OWNER_PROPERTY, this); users = new HashMap(); + results = new HashMap(); } /** @@ -434,9 +487,8 @@ protected void help() */ public void cancel() { - Iterator i = finderHandlers.iterator(); - while (i.hasNext()) - ((FinderLoader) i.next()).cancel(); + if (loader != null) loader.cancel(); + results.clear(); state = DISCARDED; } @@ -469,15 +521,17 @@ public void setStatus(String text, boolean status) /** * Implemented as specified by {@link Finder} I/F - * @see Finder#setResult(Object) + * @see Finder#setResult(SecurityContext, Object) */ - public void setResult(Object result) + public void setResult(SecurityContext ctx, Object result) { setSearchEnabled(false); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.setBackground(UIUtilities.BACKGROUND_COLOR); - + String group = getGroupName(ctx); + if (group != null && groups.size() > 1) + p.add(UIUtilities.setTextFont("Group: "+group)); Map map = (Map) result; //Format UI component @@ -526,10 +580,11 @@ public void setResult(Object result) } } - displayResult(UIUtilities.buildComponentPanel(p)); + addResult(UIUtilities.buildComponentPanel(p), results.size() == 0); } - - firePropertyChange(RESULTS_FOUND_PROPERTY, null, nodes); + results.put(ctx, nodes); + if (results.size() == total) + firePropertyChange(RESULTS_FOUND_PROPERTY, null, results); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/AdvancedFinderLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/AdvancedFinderLoader.java index d94a5d4cc39..d6cb10acef1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/AdvancedFinderLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/AdvancedFinderLoader.java @@ -27,7 +27,16 @@ //Third-party libraries //Application-internal dependencies +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.openmicroscopy.shoola.agents.dataBrowser.DataBrowserLoader; +import org.openmicroscopy.shoola.agents.dataBrowser.view.DataBrowser; +import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -50,22 +59,24 @@ public class AdvancedFinderLoader { /** Collection of terms to search for. */ - private SearchDataContext searchContext; + private SearchDataContext searchContext; /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** * Creates a new instance. * * @param viewer The viewer this data loader is for. * Mustn't be null. + * @param ctx The security context. * @param context The context of the search. * Mustn't be null. */ - public AdvancedFinderLoader(Finder viewer, SearchDataContext context) + public AdvancedFinderLoader(Finder viewer, List ctx, + SearchDataContext context) { - super(viewer); + super(viewer, ctx); if (context == null) throw new IllegalArgumentException("No scope defined."); searchContext = context; @@ -77,9 +88,39 @@ public AdvancedFinderLoader(Finder viewer, SearchDataContext context) */ public void load() { - handle = dhView.advancedSearchFor(searchContext, this); + handle = dhView.advancedSearchFor(ctx, searchContext, this); } + /** + * Feeds the results of the search as they arrive. + * @see FinderLoader#update(DSCallFeedbackEvent) + */ + public void update(DSCallFeedbackEvent fe) + { + if (viewer.getState() == DataBrowser.DISCARDED) return; //Async cancel. + int percDone = fe.getPercentDone(); + if (percDone == 0) return; + Object r = fe.getPartialResult(); + if (r != null) { + Map m = (Map) r; + Entry entry; + Iterator i= m.entrySet().iterator(); + while (i.hasNext()) { + entry = (Entry) i.next(); + viewer.setResult((SecurityContext) entry.getKey(), + entry.getValue()); + } + } + } + + /** + * Does nothing as the asynchronous call returns null. + * The actual pay-load (result) is delivered progressively + * during the updates. + * @see DataBrowserLoader#handleNullResult() + */ + public void handleNullResult() {} + /** * Cancels the ongoing data retrieval. * @see FinderLoader#cancel() @@ -90,10 +131,12 @@ public void load() * Feeds the result back to the viewer. * @see FinderLoader#handleResult(Object) */ + /* public void handleResult(Object result) { if (viewer.getState() == Finder.DISCARDED) return; //Async cancel. - viewer.setResult(result); + //viewer.setResult(result); } + */ } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/Finder.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/Finder.java index 923e770c013..08d921a6886 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/Finder.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/Finder.java @@ -29,6 +29,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; /** * Interface that every finder should implement @@ -50,14 +51,13 @@ public interface Finder * Bound property indicating that some results matching * the passed criteria have been found. */ - public static final String RESULTS_FOUND_PROPERTY = "resultsFound"; + public static final String RESULTS_FOUND_PROPERTY = "resultsFound"; /** Identified the DISCARD state. */ - public static final int DISCARDED = 100; + public static final int DISCARDED = 100; /** Identified the SEARCH state. */ - public static final int SEARCH = 101; - + public static final int SEARCH = 101; /** Cancels any ongoing search. */ public void cancel(); @@ -84,9 +84,10 @@ public interface Finder /** * Sets the results of the search. * + * @param ctx The security context. * @param result The value to set. */ - public void setResult(Object result); + public void setResult(SecurityContext ctx, Object result); /** * Sets the collection of tags. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/FinderFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/FinderFactory.java index 6cee452a051..085675a9d6a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/FinderFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/FinderFactory.java @@ -24,6 +24,9 @@ //Java imports +import java.util.Collection; +import java.util.List; + import javax.swing.JFrame; //Third-party libraries @@ -31,9 +34,11 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.config.Registry; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import pojos.DataObject; import pojos.ExperimenterData; +import pojos.GroupData; /** * Factory to create {@link Finder}. @@ -57,27 +62,30 @@ public class FinderFactory /** * Creates or recycles an advanced search. * - * @param ctx Reference to the registry. Mustn't be null. + * @param reg Reference to the registry. Mustn't be null. + * @param groups The available groups. * @return See above. */ - public static AdvancedFinder getAdvancedFinder(Registry ctx) + public static AdvancedFinder getAdvancedFinder(Registry reg, + Collection groups) { - return FinderFactory.getAdvancedFinder(ctx, null); + return FinderFactory.getAdvancedFinder(reg, groups, null); } /** * Creates or recycles an advanced search. * - * @param ctx Reference to the registry. Mustn't be null. + * @param reg Reference to the registry. Mustn't be null. + * @param groups The available groups. * @param refObject Object of reference. The search is limited to that * object. * @return See above. */ - public static AdvancedFinder getAdvancedFinder(Registry ctx, - DataObject refObject) + public static AdvancedFinder getAdvancedFinder(Registry reg, + Collection groups, DataObject refObject) { - if (singleton.registry == null) singleton.registry = ctx; - return (AdvancedFinder) singleton.createFinder(refObject); + if (singleton.registry == null) singleton.registry = reg; + return (AdvancedFinder) singleton.createFinder(groups, refObject); } /** @@ -149,15 +157,17 @@ private FinderFactory() /** * Creates the finder. * + * @param groups The available groups. * @param refObject Object of reference. The search is limited to that * object. * @return See above. */ - private Finder createFinder(DataObject refObject) + private Finder createFinder(Collection groups, + DataObject refObject) { if (finder != null) return finder; - finder = new AdvancedFinder(); + finder = new AdvancedFinder(groups); return finder; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/FinderLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/FinderLoader.java index 193ac559ea0..cd28ca72704 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/FinderLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/FinderLoader.java @@ -28,9 +28,12 @@ //Third-party libraries //Application-internal dependencies +import java.util.List; + import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.DataHandlerView; import org.openmicroscopy.shoola.env.data.views.MetadataHandlerView; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -77,16 +80,19 @@ public abstract class FinderLoader public static final int DATASETS = 4; /** The viewer this data loader is for. */ - protected Finder viewer; + protected Finder viewer; /** Convenience reference for subclasses. */ - protected final Registry registry; + protected final Registry registry; /** Convenience reference for subclasses. */ - protected final DataHandlerView dhView; + protected final DataHandlerView dhView; /** Convenience reference for subclasses. */ - protected final MetadataHandlerView mhView; + protected final MetadataHandlerView mhView; + + /** The security context.*/ + protected final List ctx; /** * Checks if the passed type is supported and returns the @@ -128,14 +134,16 @@ protected String convertType(Class type) * * @param viewer The viewer this data loader is for. * Mustn't be null. - * @param registry Convenience reference for subclasses. - * Mustn't be null. + * @param ctx The security context. */ - protected FinderLoader(Finder viewer) + protected FinderLoader(Finder viewer, List ctx) { if (viewer == null) throw new NullPointerException("No viewer."); + if (ctx == null || ctx.size() ==0) + throw new NullPointerException("No security context."); this.registry = FinderFactory.getRegistry(); this.viewer = viewer; + this.ctx = ctx; dhView = (DataHandlerView) registry.getDataServicesView(DataHandlerView.class); mhView = (MetadataHandlerView) diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/QuickFinder.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/QuickFinder.java index 5902865914d..cf81c856a93 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/QuickFinder.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/QuickFinder.java @@ -34,9 +34,11 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.ui.UserNotifier; import org.openmicroscopy.shoola.util.ui.search.QuickSearch; + /** * Class used to perform quick search. * @@ -57,54 +59,12 @@ public class QuickFinder { /** Reference to the component handling data. */ - private List finderHandlers; + private List finderHandlers; /** One of the constants defined by this class. */ - private int state; - - /** - * Searches for the passed values. - * - * @param values The value to search for. - * @param sep - */ - private void fireTagsRetrieval(List values, String sep) - { - state = SEARCH; - QuickFinderLoader handler = new QuickFinderLoader(this, null); - handler.load(); - finderHandlers.add(handler); - } - - /** - * Searches for the passed values. - * - * @param values The value to search for. - * @param sep - */ - private void fireImagesRetrieval(List values, String sep) - { - state = SEARCH; - QuickFinderLoader handler = new QuickFinderLoader(this, null); - handler.load(); - finderHandlers.add(handler); - } - - /** - * Searches for the passed values. - * - * @param values The value to search for. - * @param sep - */ - private void fireAnnotationsRetrieval(List values, String sep) - { - state = SEARCH; - QuickFinderLoader handler = new QuickFinderLoader(this, null); - handler.load(); - finderHandlers.add(handler); - } + private int state; - /** Creates a new instance. */ + /** Creates a new instance.*/ public QuickFinder() { finderHandlers = new ArrayList(); @@ -201,9 +161,9 @@ public void setStatus(String text, boolean status) /** * Implemented as specified by {@link Finder} I/F - * @see Finder#setResult(Object) + * @see Finder#setResult(SecurityContext, Object) */ - public void setResult(Object result) {} + public void setResult(SecurityContext ctx, Object result) {} /** * Implemented as specified by {@link Finder} I/F diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/QuickFinderLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/QuickFinderLoader.java index 6b84529d622..fc701706879 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/QuickFinderLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/QuickFinderLoader.java @@ -25,6 +25,7 @@ //Java imports +import java.util.List; import java.util.Set; //Third-party libraries @@ -33,6 +34,7 @@ import org.openmicroscopy.shoola.agents.events.hiviewer.Browse; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; import org.openmicroscopy.shoola.env.data.util.SearchResult; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.ui.UserNotifier; @@ -65,13 +67,15 @@ public class QuickFinderLoader /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param context The context of the search. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. + * @param context The context of the search. */ - public QuickFinderLoader(QuickFinder viewer, SearchDataContext context) + public QuickFinderLoader(QuickFinder viewer, List ctx, + SearchDataContext context) { - super(viewer); + super(viewer, ctx); if (context == null) throw new IllegalArgumentException("No terms to search for."); this.context = context; @@ -83,7 +87,7 @@ public QuickFinderLoader(QuickFinder viewer, SearchDataContext context) */ public void load() { - handle = dhView.advancedSearchFor(context, this); + handle = dhView.advancedSearchFor(ctx, context, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/TagsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/TagsLoader.java index 247def6e079..bc945596c94 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/TagsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/finder/TagsLoader.java @@ -25,11 +25,13 @@ //Java imports import java.util.Collection; +import java.util.List; //Third-party libraries //Application-internal dependencies import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; @@ -48,22 +50,23 @@ * * @since 3.0-Beta4 */ -public class TagsLoader +public class TagsLoader extends FinderLoader { /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param ctx The security context. */ - public TagsLoader(Finder viewer) + public TagsLoader(Finder viewer, List ctx) { - super(viewer); + super(viewer, ctx); } /** @@ -86,8 +89,8 @@ public void load() userID = -1; } - handle = mhView.loadExistingAnnotations(TagAnnotationData.class, - userID, groupID, this); + //handle = mhView.loadExistingAnnotations(ctx, TagAnnotationData.class, + // userID, groupID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/PermissionsPane.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/PermissionsPane.java index 2eb4225af37..00af3377276 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/PermissionsPane.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/PermissionsPane.java @@ -355,6 +355,19 @@ public void disablePermissions() } } + /** + * Overridden to set the flag for all components composing the display. + * @see JPanel#setEnabled(boolean) + */ + public void setEnabled(boolean enabled) + { + if (groupBox != null) groupBox.setEnabled(enabled); + if (privateBox != null) privateBox.setEnabled(enabled); + if (publicBox != null) publicBox.setEnabled(enabled); + if (readOnlyGroupBox != null) readOnlyGroupBox.setEnabled(enabled); + if (readOnlyPublicBox != null) readOnlyPublicBox.setEnabled(enabled); + } + /** * Sets the enabled flag of the {@link #readOnlyGroupBox} and * {@link #readOnlyPublicBox}. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/ScriptingDialog.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/ScriptingDialog.java index 69de53bb431..4111bdfdace 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/ScriptingDialog.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/ScriptingDialog.java @@ -96,6 +96,10 @@ public class ScriptingDialog implements ActionListener, DocumentListener, PropertyChangeListener { + /** Message indicating that script can only run on objects.*/ + public static final String WARNING = + "You can only run script on objects from the same group."; + /** Bound property indicating to run the script. */ public static final String RUN_SELECTED_SCRIPT_PROPERTY = "runSelectedScript"; @@ -701,6 +705,13 @@ private JPanel buildBody() layout.setColumn(columns); p.setLayout(layout); int row = 0; + JLabel warning = new JLabel(WARNING); + Font font = warning.getFont(); + warning.setFont(font.deriveFont(font.getStyle(), font.getSize()+2)); + warning.setForeground(UIUtilities.REQUIRED_FIELDS_COLOR); + layout.insertRow(row, TableLayout.PREFERRED); + p.add(warning, "0,"+row+", 2, "+row); + row++; JComponent area = buildDescriptionPane(); JComponent authorsPane = buildScriptDetails(); if (area != null) { @@ -735,7 +746,7 @@ private JPanel buildBody() } if (required > 0) { JLabel label = new JLabel(TEXT_END); - Font font = label.getFont(); + font = label.getFont(); label.setFont(font.deriveFont(font.getStyle(), font.getSize()-2)); label.setForeground(UIUtilities.REQUIRED_FIELDS_COLOR); layout.insertRow(row, TableLayout.PREFERRED); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/UserManagerDialog.java b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/UserManagerDialog.java index 1d4aa02f641..ffdcc5544f6 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/UserManagerDialog.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/agents/util/ui/UserManagerDialog.java @@ -34,7 +34,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -43,7 +42,6 @@ import javax.swing.DefaultListModel; import javax.swing.Icon; import javax.swing.JButton; -import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JList; @@ -128,9 +126,6 @@ public class UserManagerDialog /** Button to apply the selection. */ private JButton apply; - /** The box hosting the groups. */ - private JComboBox groupsBox; - /** The component hosting the users for a given group. */ private JList users; @@ -139,7 +134,10 @@ public class UserManagerDialog /** Helper class uses to sort elements. */ private ViewerSorter sorter; - + + /** The group currently selected.*/ + private GroupData group; + /** Closes and disposes. */ private void cancel() { @@ -152,14 +150,13 @@ private void apply() { Map r = new HashMap(1); - GroupData g = (GroupData) groupsBox.getSelectedItem(); Object user = users.getSelectedValue(); if (user == null) { firePropertyChange(NO_USER_SWITCH_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true)); return; } - r.put(g.getId(), (ExperimenterData) user); + r.put(group.getId(), (ExperimenterData) user); firePropertyChange(USER_SWITCH_PROPERTY, null, r); cancel(); } @@ -180,7 +177,6 @@ private void fillList(GroupData group) { if (group == null) return; DefaultListModel model = (DefaultListModel) users.getModel(); - ExperimenterData d; int index = 0; List l = sorter.sort(group.getLeaders()); Iterator i = l.iterator(); @@ -228,34 +224,29 @@ public void windowClosing(WindowEvent e) { cancel(); } }); - + users.addListSelectionListener(new ListSelectionListener() { + + /** + * Sets the enabled flag of the apply button. + */ + public void valueChanged(ListSelectionEvent e) { + Object value = users.getSelectedValue(); + apply.setEnabled(value instanceof ExperimenterData); + } + }); cancel.setActionCommand(""+CANCEL); cancel.addActionListener(this); apply.setActionCommand(""+APPLY); apply.addActionListener(this); - groupsBox.setActionCommand(""+GROUPS); - groupsBox.addActionListener(this); - users.getSelectionModel().addListSelectionListener( - new ListSelectionListener() { - - public void valueChanged(ListSelectionEvent e) { - ListSelectionModel lsm = (ListSelectionModel) e.getSource(); - Object object = users.getSelectedValue(); - if (object instanceof ExperimenterData) { - apply.setEnabled(!lsm.isSelectionEmpty()); - } else apply.setEnabled(false); - } - - }); } /** * Initializes the UI components. * - * @param groups The groups the user is a member of. + * @param selectedGroup The group to display * @param userIcon The icon used to represent an user. */ - private void initComponents(Set groups, Icon userIcon) + private void initComponents(Icon userIcon) { sorter = new ViewerSorter(); cancel = new JButton("Cancel"); @@ -266,61 +257,34 @@ private void initComponents(Set groups, Icon userIcon) apply.setToolTipText( UIUtilities.formatToolTipText(APPLY_DESCRIPTION)); getRootPane().setDefaultButton(apply); - GroupData defaultGroup = loggedUser.getDefaultGroup(); - long groupID = defaultGroup.getId(); - //Build the array for box. - //Iterator i = map.keySet().iterator(); - //Remove not visible group - GroupData g; - GroupData[] objects = new GroupData[groups.size()]; - int selectedIndex = 0; - int index = 0; - GroupData selectedGroup = defaultGroup; - //sort - - Iterator i = sorter.sort(groups).iterator(); - while (i.hasNext()) { - g = (GroupData) i.next(); - objects[index] = g; - if (g.getId() == groupID) { - selectedIndex = index; - selectedGroup = g; - } - index++; - } - - //sort by name - groupsBox = new JComboBox(objects); - groupsBox.setRenderer(new GroupsRenderer()); - - users = new JList(new DefaultListModel()); - fillList(selectedGroup); - users.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + fillList(group); + users.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); users.setLayoutOrientation(JList.VERTICAL); - users.setCellRenderer(new UserListRenderer(userIcon)); + users.setCellRenderer(new UserListRenderer(userIcon)); attachListeners(); - if (objects.length != 0) - groupsBox.setSelectedIndex(selectedIndex); - } /** * Builds the main component of this dialog. * + * @param group The selected group if any. * @return See above. */ - private JPanel buildContent() + private JPanel buildContent(GroupData group) { double[][] tl = {{TableLayout.PREFERRED, TableLayout.FILL}, //columns {TableLayout.PREFERRED, 5, TableLayout.FILL}}; //rows JPanel content = new JPanel(); content.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); content.setLayout(new TableLayout(tl)); - //content.add( UIUtilities.setTextFont("Groups"), "0, 0, LEFT, TOP"); - //content.add(groups, "1, 0"); - content.add(UIUtilities.setTextFont("Experimenters "), "0, 2, LEFT, TOP"); - content.add(new JScrollPane(users), "1, 2"); + if (group != null) { + content.add(UIUtilities.setTextFont( + "Select from: "+group.getName()), "0, 0, 1, 0"); + } + //content.add(UIUtilities.setTextFont("Experimenters "), + // "0, 2, LEFT, TOP"); + content.add(new JScrollPane(users), "0, 2, 1, 2"); return content; } @@ -346,35 +310,37 @@ private JPanel buildToolBar() /** * Builds and lays out the UI. * - * @param icon The icon displayed in the title panel. + * @param group The selected group. + * @param icon The icon displayed in the title panel. */ - private void buildGUI(Icon icon) + private void buildGUI(GroupData group, Icon icon) { TitlePanel titlePanel = new TitlePanel(TITLE, TEXT, icon); Container c = getContentPane(); c.setLayout(new BorderLayout(0, 0)); c.add(titlePanel, BorderLayout.NORTH); - c.add(buildContent(), BorderLayout.CENTER); + c.add(buildContent(group), BorderLayout.CENTER); c.add(buildToolBar(), BorderLayout.SOUTH); } /** * Creates a new instance. * - * @param parent The parent of this dialog. - * @param loggedUser The user currently logged in. - * @param groups The groups the user is a member of. - * @param userIcon The icon representing an user. - * @param icon The icon displayed in the title panel. + * @param parent The parent of this dialog. + * @param loggedUser The user currently logged in. + * @param selected The selected group. + * @param userIcon The icon representing an user. + * @param icon The icon displayed in the title panel. */ public UserManagerDialog(JFrame parent, ExperimenterData loggedUser, - Set groups, Icon userIcon, Icon icon) + GroupData selected, Icon userIcon, Icon icon) { super(parent); setProperties(); this.loggedUser = loggedUser; - initComponents(groups, userIcon); - buildGUI(icon); + group = selected; + initComponents(userIcon); + buildGUI(selected, icon); } @@ -397,12 +363,7 @@ public void actionPerformed(ActionEvent e) break; case APPLY: apply(); - break; - case GROUPS: - DefaultListModel model = (DefaultListModel) users.getModel(); - model.clear(); - fillList((GroupData) groupsBox.getSelectedItem()); } } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/AdminService.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/AdminService.java index 892e3373a65..59db6821b31 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/AdminService.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/AdminService.java @@ -35,6 +35,7 @@ import org.openmicroscopy.shoola.env.data.login.UserCredentials; import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.env.data.model.DiskQuota; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import pojos.ExperimenterData; import pojos.GroupData; @@ -56,49 +57,54 @@ public interface AdminService { /** Identifies the User group. */ - public static final String USER_GROUP = GroupData.USER; + public static final String USER_GROUP = GroupData.USER; /** Identifies the Default group. */ - public static final String DEFAULT_GROUP = GroupData.DEFAULT; + public static final String DEFAULT_GROUP = GroupData.DEFAULT; /** Identifies the used space on the file system. */ - public static final int USED = 100; + public static final int USED = 100; /** Identifies the free space on the file system. */ - public static final int FREE = 101; + public static final int FREE = 101; /** * Changes the password of the user currently logged in. + * Returns true if successfully modified, + * false otherwise. * - * @param oldPassword The password used to log in. - * @param newPassword The new password. - * @return true if successfully modified, - * false otherwise. + * @param ctx The security context. + * @param oldPassword The password used to log in. + * @param newPassword The new password. + * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Boolean changePassword(String oldPassword, String newPassword) + public Boolean changePassword(SecurityContext ctx, String oldPassword, + String newPassword) throws DSOutOfServiceException, DSAccessException; /** * Updates the specified experimenter. * - * @param exp The experimenter to update. + * @param ctx The security context. + * @param exp The experimenter to update. * @param group The group the user is member of. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public ExperimenterData updateExperimenter(ExperimenterData exp, GroupData - group) + public ExperimenterData updateExperimenter(SecurityContext ctx, + ExperimenterData exp, GroupData group) throws DSOutOfServiceException, DSAccessException; /** * Updates the specified group. * + * @param ctx The security context. * @param group The group to update. * @param permissions The desired permissions level or -1. * @return See above. @@ -106,24 +112,28 @@ public ExperimenterData updateExperimenter(ExperimenterData exp, GroupData * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public GroupData updateGroup(GroupData group, int permissions) + public GroupData updateGroup(SecurityContext ctx, GroupData group, + int permissions) throws DSOutOfServiceException, DSAccessException; /** * Changes the current group of the specified user. * - * @param exp The experimenter to handle. - * @param groupID The identifier group the user is member of. + * @param ctx The security context. + * @param exp The experimenter to handle. + * @param groupID The identifier group the user is member of. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public void changeExperimenterGroup(ExperimenterData exp, long groupID) + public void changeExperimenterGroup(SecurityContext ctx, + ExperimenterData exp, long groupID) throws DSOutOfServiceException, DSAccessException; /** * Creates and returns the experimenters. * + * @param ctx The security context. * @param object The object hosting information about the experimenters * to create. * @return See above. @@ -131,24 +141,27 @@ public void changeExperimenterGroup(ExperimenterData exp, long groupID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public List createExperimenters(AdminObject object) + public List createExperimenters(SecurityContext ctx, + AdminObject object) throws DSOutOfServiceException, DSAccessException; /** - * Creates and returns the new group + * Creates and returns the new group. * + * @param ctx The security context. * @param object The object hosting information about the group to create. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public GroupData createGroup(AdminObject object) + public GroupData createGroup(SecurityContext ctx, AdminObject object) throws DSOutOfServiceException, DSAccessException; /** * Returns the address of the server the user is currently connected to. * + * @param ctx The security context. * @return See above. */ public String getServerName(); @@ -156,6 +169,7 @@ public GroupData createGroup(AdminObject object) /** * Returns the version of the server if available. * + * @param ctx The security context. * @return See above. */ public String getServerVersion(); @@ -171,6 +185,7 @@ public GroupData createGroup(AdminObject object) * Loads the group specified by the passed identifier or all available * groups if -1. * + * @param ctx The security context. * @param groupID The group identifier. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -178,12 +193,13 @@ public GroupData createGroup(AdminObject object) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List loadGroups(long groupID) + public List loadGroups(SecurityContext ctx, long groupID) throws DSOutOfServiceException, DSAccessException; /** * Loads the experimenters contained in the specified group. * + * @param ctx The security context. * @param groupID The group identifier. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -191,13 +207,15 @@ public List loadGroups(long groupID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List loadExperimenters(long groupID) + public List loadExperimenters(SecurityContext ctx, + long groupID) throws DSOutOfServiceException, DSAccessException; /** * Deletes the specified experimenters. Returns the experimenters * that could not be deleted. * + * @param ctx The security context. * @param experimenters The experimenters to delete. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -205,7 +223,7 @@ public List loadExperimenters(long groupID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List deleteExperimenters( + public List deleteExperimenters(SecurityContext ctx, List experimenters) throws DSOutOfServiceException, DSAccessException; @@ -213,6 +231,7 @@ public List deleteExperimenters( * Deletes the specified groups. Returns the groups * that could not be deleted. * + * @param ctx The security context. * @param groups The groups to delete. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -220,7 +239,8 @@ public List deleteExperimenters( * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List deleteGroups(List groups) + public List deleteGroups(SecurityContext ctx, + List groups) throws DSOutOfServiceException, DSAccessException; /** @@ -242,6 +262,7 @@ public List deleteGroups(List groups) /** * Copies the passed experimenters to the specified group. * + * @param ctx The security context. * @param group The group to add the experimenters to. * @param experimenters The experimenters to add. * @return See above @@ -249,22 +270,23 @@ public List deleteGroups(List groups) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public List copyExperimenters(GroupData group, - Collection experimenters) + public List copyExperimenters(SecurityContext ctx, + GroupData group, Collection experimenters) throws DSOutOfServiceException, DSAccessException; /** * Cuts and paste the specified experimenters. * - * @param toPaste The nodes to paste. - * @param toCut The nodes to cut. + * @param ctx The security context. + * @param toPaste The nodes to paste. + * @param toCut The nodes to cut. * @return See above * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public List cutAndPasteExperimenters(Map toPaste, - Map toRemove) + public List cutAndPasteExperimenters( + SecurityContext ctx, Map toPaste, Map toRemove) throws DSOutOfServiceException, DSAccessException; /** @@ -272,20 +294,22 @@ public List cutAndPasteExperimenters(Map toPaste, * Returns a map whose keys are the group identifiers and the values the * number of experimenters in the group. * + * @param ctx The security context. * @param ids The group identifiers. * @return See above * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Map countExperimenters(List ids) + public Map countExperimenters(SecurityContext ctx, + List ids) throws DSOutOfServiceException, DSAccessException; /** * Updates the specified experimenters. Returns a map whose key are the * experimenter that cannot be updated and whose values are the exception. * - * + * @param ctx The security context. * @param group The default group. * @param experimenters The experimenters to update. * @return See above @@ -293,77 +317,86 @@ public Map countExperimenters(List ids) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Map updateExperimenters(GroupData group, + public Map updateExperimenters( + SecurityContext ctx, GroupData group, Map experimenters) throws DSOutOfServiceException, DSAccessException; /** * Resets the password of the specified experimenters. * + * @param ctx The security context. * @param object The object to handle. * @return See above * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public List resetExperimentersPassword(AdminObject object) + public List resetExperimentersPassword( + SecurityContext ctx, AdminObject object) throws DSOutOfServiceException, DSAccessException; /** * Activates or not the specified experimenters. * + * @param ctx The security context. * @param object The object to handle. * @return See above * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public List activateExperimenters(AdminObject object) + public List activateExperimenters(SecurityContext ctx, + AdminObject object) throws DSOutOfServiceException, DSAccessException; - /** * Reloads the groups and experimenters for a group owners. * + * @param ctx The security context. * @param exp The owner of a group. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public List reloadPIGroups(ExperimenterData exp) + public List reloadPIGroups(SecurityContext ctx, + ExperimenterData exp) throws DSOutOfServiceException, DSAccessException; /** * Returns the Group if the name of the group already exists, * null otherwise. * + * @param ctx The security context. * @param name The name of the group. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public GroupData lookupGroup(String name) + public GroupData lookupGroup(SecurityContext ctx, String name) throws DSOutOfServiceException, DSAccessException; /** * Returns the Experimenter if the name of the experimenter * already exists, null otherwise. * + * @param ctx The security context. * @param name The name of the experimenter. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public ExperimenterData lookupExperimenter(String name) + public ExperimenterData lookupExperimenter(SecurityContext ctx, String name) throws DSOutOfServiceException, DSAccessException; /** * Uploads the specified photo for the passed user. Returns the uploaded * photo. * + * @param ctx The security context. * @param f The file to upload. * @param format The format of the file. * @param experimenter The experimenter to handle. @@ -372,13 +405,14 @@ public ExperimenterData lookupExperimenter(String name) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Object uploadUserPhoto(File f, String format, + public Object uploadUserPhoto(SecurityContext ctx, File f, String format, ExperimenterData experimenter) throws DSOutOfServiceException, DSAccessException; /** * Returns the disk space. * + * @param ctx The security context. * @param f The file to upload. * @param format The format of the file. * @param experimenter The experimenter to handle. @@ -387,12 +421,13 @@ public Object uploadUserPhoto(File f, String format, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public DiskQuota getQuota(Class type, long id) + public DiskQuota getQuota(SecurityContext ctx, Class type, long id) throws DSOutOfServiceException, DSAccessException; /** * Adds the experimenters to the specified group. * + * @param ctx The security context. * @param group The group to add the experimenters to. * @param experimenters The experimenters to add. * @return See above. @@ -400,8 +435,8 @@ public DiskQuota getQuota(Class type, long id) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public void addExperimenters(GroupData group, List - experimenters) + public void addExperimenters(SecurityContext ctx, GroupData group, + List experimenters) throws DSOutOfServiceException, DSAccessException; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/AdminServiceImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/AdminServiceImpl.java index 13232db2631..9874c19410c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/AdminServiceImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/AdminServiceImpl.java @@ -49,6 +49,7 @@ import org.openmicroscopy.shoola.env.data.model.AdminObject; import org.openmicroscopy.shoola.env.data.model.DiskQuota; import org.openmicroscopy.shoola.env.data.util.PojoMapper; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import pojos.DataObject; import pojos.ExperimenterData; @@ -73,10 +74,10 @@ class AdminServiceImpl { /** Uses it to gain access to the container's services. */ - private Registry context; + private Registry context; /** Reference to the entry point to access the OMERO services. */ - private OMEROGateway gateway; + private OMEROGateway gateway; /** * Updates the experimenter. @@ -90,8 +91,8 @@ class AdminServiceImpl * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private ExperimenterData updateExperimenter(ExperimenterData exp, GroupData - group, boolean asAdmin) + private ExperimenterData updateExperimenter(SecurityContext ctx, + ExperimenterData exp, GroupData group, boolean asAdmin) throws DSOutOfServiceException, DSAccessException { ExperimenterData currentUser = (ExperimenterData) @@ -99,14 +100,15 @@ private ExperimenterData updateExperimenter(ExperimenterData exp, GroupData if (!asAdmin && exp.getId() != currentUser.getId()) return exp; UserCredentials uc = (UserCredentials) context.lookup(LookupNames.USER_CREDENTIALS); - gateway.updateExperimenter(exp.asExperimenter(), currentUser.getId()); + gateway.updateExperimenter(ctx, exp.asExperimenter(), + currentUser.getId()); ExperimenterData data; if (group != null && exp.getDefaultGroup().getId() != group.getId()) { - gateway.changeCurrentGroup(exp, group.getId()); + gateway.changeCurrentGroup(ctx, exp, group.getId()); } String userName = uc.getUserName(); if (asAdmin) userName = exp.getUserName(); - data = gateway.getUserDetails(userName); + data = gateway.getUserDetails(ctx, userName); if (currentUser.getId() != exp.getId()) return data; @@ -180,14 +182,14 @@ public String getLoggingName() /** * Implemented as specified by {@link AdminService}. - * @see AdminService#getQuota(Class, long) + * @see AdminService#getQuota(SecurityContext, Class, long) */ - public DiskQuota getQuota(Class type, long id) + public DiskQuota getQuota(SecurityContext ctx, Class type, long id) throws DSOutOfServiceException, DSAccessException { long v = 1000; long used = 0;//gateway.getUsedSpace(type, id); - long available = gateway.getFreeSpace(type, id); + long available = gateway.getFreeSpace(ctx, type, id); int t = DiskQuota.USER; if (GroupData.class.equals(type)) t = DiskQuota.GROUP; @@ -196,9 +198,10 @@ public DiskQuota getQuota(Class type, long id) /** * Implemented as specified by {@link AdminService}. - * @see AdminService#changePassword(String, String) + * @see AdminService#changePassword(SecurityContext, String, String) */ - public Boolean changePassword(String oldPassword, String newPassword) + public Boolean changePassword(SecurityContext ctx, String oldPassword, + String newPassword) throws DSOutOfServiceException, DSAccessException { if (newPassword == null || newPassword.trim().length() == 0) @@ -208,31 +211,30 @@ public Boolean changePassword(String oldPassword, String newPassword) if (!uc.getPassword().equals(oldPassword)) return Boolean.valueOf(false); - gateway.changePassword(newPassword, oldPassword); + gateway.changePassword(ctx, newPassword, oldPassword); uc.resetPassword(newPassword); return Boolean.valueOf(true); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#changeExperimenterGroup(ExperimenterData, long) + * @see AdminService#changeExperimenterGroup(SecurityContext, ExperimenterData, long) */ - public void changeExperimenterGroup(ExperimenterData exp, long groupID) + public void changeExperimenterGroup(SecurityContext ctx, + ExperimenterData exp, long groupID) throws DSOutOfServiceException, DSAccessException { - if (exp == null) - throw new DSAccessException("No object to update."); + UserCredentials uc = (UserCredentials) + context.lookup(LookupNames.USER_CREDENTIALS); + if (exp == null) { + exp = gateway.getUserDetails(ctx, uc.getUserName()); + } if (groupID < 0) throw new DSAccessException("No group specified."); if (exp.getDefaultGroup().getId() != groupID) { - UserCredentials uc = (UserCredentials) - context.lookup(LookupNames.USER_CREDENTIALS); - gateway.changeCurrentGroup(exp, groupID);//, uc.getUserName(), - //uc.getPassword()); + gateway.changeCurrentGroup(ctx, exp, groupID); } - UserCredentials uc = (UserCredentials) - context.lookup(LookupNames.USER_CREDENTIALS); - ExperimenterData data = gateway.getUserDetails(uc.getUserName()); + ExperimenterData data = gateway.getUserDetails(ctx, uc.getUserName()); context.bind(LookupNames.CURRENT_USER_DETAILS, data); // Bind user details to all agents' registry. @@ -250,20 +252,21 @@ public void changeExperimenterGroup(ExperimenterData exp, long groupID) /** * Implemented as specified by {@link AdminService}. - * @see AdminService#updateExperimenter(ExperimenterData, GroupData) + * @see AdminService#updateExperimenter(SecurityContext, ExperimenterData, GroupData) */ - public ExperimenterData updateExperimenter(ExperimenterData exp, GroupData - group) + public ExperimenterData updateExperimenter(SecurityContext ctx, + ExperimenterData exp, GroupData group) throws DSOutOfServiceException, DSAccessException { - return updateExperimenter(exp, group, false); + return updateExperimenter(ctx, exp, group, false); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#createExperimenters(AdminObject) + * @see AdminService#createExperimenters(SecurityContext, AdminObject) */ - public List createExperimenters(AdminObject object) + public List createExperimenters(SecurityContext ctx, + AdminObject object) throws DSOutOfServiceException, DSAccessException { if (object == null) @@ -271,15 +274,15 @@ public List createExperimenters(AdminObject object) Map m = object.getExperimenters(); if (m == null || m.size() == 0) throw new IllegalArgumentException("No experimenters to create."); - return gateway.createExperimenters(object); + return gateway.createExperimenters(ctx, object); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#addExperimenters(GroupData, List) + * @see AdminService#addExperimenters(SecurityContext, GroupData, List) */ - public void addExperimenters(GroupData group, List - experimenters) + public void addExperimenters(SecurityContext ctx, GroupData group, + List experimenters) throws DSOutOfServiceException, DSAccessException { if (group == null) @@ -287,66 +290,68 @@ public void addExperimenters(GroupData group, List "the experimenters to."); if (experimenters == null || experimenters.size() == 0) throw new IllegalArgumentException("No experimenters to add."); - gateway.addExperimenters(group, experimenters); + gateway.addExperimenters(ctx, group, experimenters); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#createGroup(AdminObject) + * @see AdminService#createGroup(SecurityContext, AdminObject) */ - public GroupData createGroup(AdminObject object) + public GroupData createGroup(SecurityContext ctx, AdminObject object) throws DSOutOfServiceException, DSAccessException { if (object == null) throw new IllegalArgumentException("No object."); if (object.getGroup() == null) throw new IllegalArgumentException("No group."); - return gateway.createGroup(object); + return gateway.createGroup(ctx, object); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#loadExperimenters(long) + * @see AdminService#loadExperimenters(SecurityContext, long) */ - public List loadExperimenters(long groupID) + public List loadExperimenters(SecurityContext ctx, + long groupID) throws DSOutOfServiceException, DSAccessException { - return gateway.loadExperimenters(groupID); + return gateway.loadExperimenters(ctx, groupID); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#loadGroups(long) + * @see AdminService#loadGroups(SecurityContext, long) */ - public List loadGroups(long id) + public List loadGroups(SecurityContext ctx, long id) throws DSOutOfServiceException, DSAccessException { - return gateway.loadGroups(id); + return gateway.loadGroups(ctx, id); } /** * Implemented as specified by {@link AdminService}. * @see AdminService#deleteExperimenters(List) */ - public List deleteExperimenters( + public List deleteExperimenters(SecurityContext ctx, List experimenters) throws DSOutOfServiceException, DSAccessException { if (experimenters == null || experimenters.size() == 0) throw new IllegalArgumentException("No experimenters to delete."); - return gateway.deleteExperimenters(experimenters); + return gateway.deleteExperimenters(ctx, experimenters); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#deleteGroups(List) + * @see AdminService#deleteGroups(SecurityContext, List) */ - public List deleteGroups(List groups) + public List deleteGroups(SecurityContext ctx, + List groups) throws DSOutOfServiceException, DSAccessException { if (groups == null || groups.size() == 0) throw new IllegalArgumentException("No groups to delete."); - return gateway.deleteGroups(groups); + return gateway.deleteGroups(ctx, groups); } /** @@ -371,19 +376,6 @@ public int getPermissionLevel(GroupData group) return AdminObject.PERMISSIONS_PUBLIC_READ_WRITE; return AdminObject.PERMISSIONS_PUBLIC_READ; } - //Check if the user is owner of the group. - /* - Set leaders = group.getLeaders(); - if (leaders == null || leaders.size() == 0) - return AdminObject.PERMISSIONS_PRIVATE; - Iterator j = leaders.iterator(); - long id = exp.getId(); - while (j.hasNext()) { - exp = (ExperimenterData) j.next(); - if (exp.getId() == id) - return AdminObject.PERMISSIONS_GROUP_READ; - } - */ return AdminObject.PERMISSIONS_PRIVATE; } @@ -401,9 +393,10 @@ public int getPermissionLevel() /** * Implemented as specified by {@link AdminService}. - * @see AdminService#updateGroup(GroupData, int) + * @see AdminService#updateGroup(SecurityContext, GroupData, int) */ - public GroupData updateGroup(GroupData group, int permissions) + public GroupData updateGroup(SecurityContext ctx, GroupData group, + int permissions) throws DSOutOfServiceException, DSAccessException { if (group == null) @@ -414,30 +407,30 @@ public GroupData updateGroup(GroupData group, int permissions) p = g.getDetails().getPermissions(); gateway.setPermissionsLevel(p, permissions); } - return gateway.updateGroup(g, p); + return gateway.updateGroup(ctx, g, p); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#copyExperimenters(GroupData, Set) + * @see AdminService#copyExperimenters(SecurityContext, GroupData, Set) */ - public List copyExperimenters(GroupData group, - Collection experimenters) + public List copyExperimenters(SecurityContext ctx, + GroupData group, Collection experimenters) throws DSOutOfServiceException, DSAccessException { if (group == null) throw new IllegalArgumentException("No group specified."); if (experimenters == null || experimenters.size() == 0) return new ArrayList(); - return gateway.copyExperimenters(group, experimenters); + return gateway.copyExperimenters(ctx, group, experimenters); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#cutAndPasteExperimenters(Map, Map) + * @see AdminService#cutAndPasteExperimenters(SecurityContext, Map, Map) */ - public List cutAndPasteExperimenters(Map toPaste, - Map toCut) + public List cutAndPasteExperimenters( + SecurityContext ctx, Map toPaste, Map toCut) throws DSOutOfServiceException, DSAccessException { if (toPaste == null) toPaste = new HashMap(); @@ -451,7 +444,7 @@ public List cutAndPasteExperimenters(Map toPaste, entry = (Entry) i.next(); parent = entry.getKey(); if (parent instanceof GroupData) - r.addAll(gateway.removeExperimenters((GroupData) parent, + r.addAll(gateway.removeExperimenters(ctx, (GroupData) parent, (Set) entry.getValue())); } @@ -461,60 +454,32 @@ public List cutAndPasteExperimenters(Map toPaste, entry = (Entry) i.next(); parent = entry.getKey(); if (parent instanceof GroupData) //b/c of orphaned container - r.addAll(copyExperimenters((GroupData) parent, + r.addAll(copyExperimenters(ctx, (GroupData) parent, (Set) entry.getValue())); } - //Need to check if the experimenters belong to at least one group - //which is not the system group. - /* - Set experimenters; - i = toCut.entrySet().iterator(); - Iterator j; - List groups; - ExperimenterData exp; - List list = new ArrayList(); - while (i.hasNext()) { - entry = (Entry) i.next(); - parent = entry.getKey(); - if (parent instanceof GroupData) { - experimenters = (Set) entry.getValue(); - if (experimenters != null) { - j = experimenters.iterator(); - while (j.hasNext()) { - exp = (ExperimenterData) j.next(); - groups = gateway.getGroups(exp.getId()); - if (groups.size() == 0) list.add(exp); - - } - } - } - } - //Update the list of experimenters. - if (list.size() > 0) { - - } - */ return r; } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#countExperimenters(List) + * @see AdminService#countExperimenters(SecurityContext, List) */ - public Map countExperimenters(List ids) + public Map countExperimenters(SecurityContext ctx, + List ids) throws DSOutOfServiceException, DSAccessException { if (ids == null || ids.size() == 0) return new HashMap(); - return gateway.countExperimenters(ids); + return gateway.countExperimenters(ctx, ids); } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#updateExperimenters(GroupData, Map) + * @see AdminService#updateExperimenters(SecurityContext, GroupData, Map) */ - public Map updateExperimenters(GroupData group, + public Map updateExperimenters( + SecurityContext ctx, GroupData group, Map experimenters) throws DSOutOfServiceException, DSAccessException { @@ -544,7 +509,7 @@ public Map updateExperimenters(GroupData group, //exp.asExperimenter().setOmeName( // omero.rtypes.rstring(uc.getUserName())); try { - updateExperimenter(exp, group, true); + updateExperimenter(ctx, exp, group, true); //b = uc.isOwner(); group = uc.getGroupToHandle(); b = uc.isGroupOwner(group); @@ -567,7 +532,7 @@ public Map updateExperimenters(GroupData group, //Check owner //reset login name if (!exp.getUserName().equals(uc.getUserName())) { - reset = gateway.resetUserName(uc.getUserName(), exp); + reset = gateway.resetUserName(ctx, uc.getUserName(), exp); if (!reset) { l.put(exp, new Exception( "The selected User Name is already taken.")); @@ -579,21 +544,23 @@ public Map updateExperimenters(GroupData group, } if (group != null) { if (ownersToAdd.size() > 0) - gateway.handleGroupOwners(true, group.asGroup(), ownersToAdd); + gateway.handleGroupOwners(ctx, true, group.asGroup(), + ownersToAdd); if (ownersToRemove.size() > 0) - gateway.handleGroupOwners(false, group.asGroup(), + gateway.handleGroupOwners(ctx, false, group.asGroup(), ownersToRemove); } if (toActivate.size() > 0) - gateway.modifyExperimentersRoles(true, toActivate, GroupData.USER); + gateway.modifyExperimentersRoles(ctx, true, toActivate, + GroupData.USER); if (toDeactivate.size() > 0) - gateway.modifyExperimentersRoles(false, toDeactivate, + gateway.modifyExperimentersRoles(ctx, false, toDeactivate, GroupData.USER); if (administratorsToAdd.size() > 0) - gateway.modifyExperimentersRoles(true, administratorsToAdd, + gateway.modifyExperimentersRoles(ctx, true, administratorsToAdd, GroupData.SYSTEM); if (administratorsToRemove.size() > 0) - gateway.modifyExperimentersRoles(false, administratorsToRemove, + gateway.modifyExperimentersRoles(ctx, false, administratorsToRemove, GroupData.SYSTEM); return l; @@ -601,9 +568,10 @@ public Map updateExperimenters(GroupData group, /** * Implemented as specified by {@link AdminService}. - * @see AdminService#resetExperimentersPassword(AdminObject) + * @see AdminService#resetExperimentersPassword(SecurityContext, AdminObject) */ - public List resetExperimentersPassword(AdminObject object) + public List resetExperimentersPassword( + SecurityContext ctx, AdminObject object) throws DSOutOfServiceException, DSAccessException { if (object == null) @@ -626,10 +594,11 @@ public List resetExperimentersPassword(AdminObject object) uc = (UserCredentials) entry.getValue(); try { //check that the user is not ldap - String ldap = gateway.lookupLdapAuthExperimenter(exp.getId()); + String ldap = gateway.lookupLdapAuthExperimenter(ctx, + exp.getId()); if (ldap != null && ldap.length() > 0) l.add(exp); else - gateway.resetPassword(exp.getUserName(), exp.getId(), + gateway.resetPassword(ctx, exp.getUserName(), exp.getId(), uc.getPassword()); } catch (Exception e) { l.add(exp); @@ -640,9 +609,10 @@ public List resetExperimentersPassword(AdminObject object) /** * Implemented as specified by {@link AdminService}. - * @see AdminService#activateExperimenters(AdminObject) + * @see AdminService#activateExperimenters(SecurityContext, AdminObject) */ - public List activateExperimenters(AdminObject object) + public List activateExperimenters(SecurityContext ctx, + AdminObject object) throws DSOutOfServiceException, DSAccessException { if (object == null) @@ -670,18 +640,20 @@ public List activateExperimenters(AdminObject object) else toDeactivate.add(exp); } if (toActivate.size() > 0) - gateway.modifyExperimentersRoles(true, toActivate, GroupData.USER); + gateway.modifyExperimentersRoles(ctx, true, toActivate, + GroupData.USER); if (toDeactivate.size() > 0) - gateway.modifyExperimentersRoles(false, toDeactivate, + gateway.modifyExperimentersRoles(ctx, false, toDeactivate, GroupData.USER); return l; } /** * Implemented as specified by {@link AdminService}. - * @see AdminService#reloadPIGroups(ExperimenterData) + * @see AdminService#reloadPIGroups(SecurityContext, ExperimenterData) */ - public List reloadPIGroups(ExperimenterData exp) + public List reloadPIGroups(SecurityContext ctx, + ExperimenterData exp) throws DSOutOfServiceException, DSAccessException { Set groups; @@ -689,7 +661,7 @@ public List reloadPIGroups(ExperimenterData exp) UserCredentials uc = (UserCredentials) context.lookup(LookupNames.USER_CREDENTIALS); List exps = new ArrayList(); - groups = gateway.getAvailableGroups(exp); + groups = gateway.getAvailableGroups(ctx, exp); //Check if the current experimenter is an administrator Iterator i = groups.iterator(); GroupData g; @@ -746,12 +718,13 @@ public List reloadPIGroups(ExperimenterData exp) /** * Implemented as specified by {@link AdminService}. - * @see AdminService#isExistingExperimenter(String) + * @see AdminService#isExistingExperimenter(SecurityContext, String) */ - public ExperimenterData lookupExperimenter(String name) + public ExperimenterData lookupExperimenter(SecurityContext ctx, + String name) throws DSOutOfServiceException, DSAccessException { - Experimenter value = gateway.lookupExperimenter(name); + Experimenter value = gateway.lookupExperimenter(ctx, name); if (value != null) return (ExperimenterData) PojoMapper.asDataObject(value); return null; @@ -759,12 +732,12 @@ public ExperimenterData lookupExperimenter(String name) /** * Implemented as specified by {@link AdminService}. - * @see AdminService#isExistingGroup(String) + * @see AdminService#isExistingGroup(SecurityContext, String) */ - public GroupData lookupGroup(String name) + public GroupData lookupGroup(SecurityContext ctx, String name) throws DSOutOfServiceException, DSAccessException { - ExperimenterGroup value = gateway.lookupGroup(name); + ExperimenterGroup value = gateway.lookupGroup(ctx, name); if (value != null) return (GroupData) PojoMapper.asDataObject(value); return null; @@ -772,10 +745,10 @@ public GroupData lookupGroup(String name) /** * Implemented as specified by {@link AdminService}. - * @see AdminService#uploadUserPhoto(File, String, experimenter) + * @see AdminService#uploadUserPhoto(SecurityContext, File, String, experimenter) */ - public BufferedImage uploadUserPhoto(File f, String format, - ExperimenterData experimenter) + public BufferedImage uploadUserPhoto(SecurityContext ctx, File f, + String format, ExperimenterData experimenter) throws DSOutOfServiceException, DSAccessException { if (experimenter == null) @@ -783,13 +756,13 @@ public BufferedImage uploadUserPhoto(File f, String format, if (f == null) throw new IllegalArgumentException("No photo specified."); - long id = gateway.uploadExperimenterPhoto(f, format, + long id = gateway.uploadExperimenterPhoto(ctx, f, format, experimenter.getId()); if (id < 0) return null; List exp = new ArrayList(); exp.add(experimenter); Map map = - context.getImageService().getExperimenterThumbnailSet(exp, 0); + context.getImageService().getExperimenterThumbnailSet(ctx, exp, 0); return map.get(experimenter); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/Connector.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/Connector.java new file mode 100644 index 00000000000..1fe37c2fdc5 --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/Connector.java @@ -0,0 +1,771 @@ +/* + * org.openmicroscopy.shoola.env.data.Connector + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.env.data; + + +//Java imports +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +//Third-party libraries + +//Application-internal dependencies +import ome.formats.OMEROMetadataStoreClient; +import omero.client; +import omero.api.ExporterPrx; +import omero.api.IAdminPrx; +import omero.api.IConfigPrx; +import omero.api.IContainerPrx; +import omero.api.IDeletePrx; +import omero.api.IMetadataPrx; +import omero.api.IPixelsPrx; +import omero.api.IProjectionPrx; +import omero.api.IQueryPrx; +import omero.api.IRenderingSettingsPrx; +import omero.api.IRepositoryInfoPrx; +import omero.api.IRoiPrx; +import omero.api.IScriptPrx; +import omero.api.IUpdatePrx; +import omero.api.RawFileStorePrx; +import omero.api.RawPixelsStorePrx; +import omero.api.RenderingEnginePrx; +import omero.api.SearchPrx; +import omero.api.ServiceFactoryPrx; +import omero.api.ServiceInterfacePrx; +import omero.api.StatefulServiceInterfacePrx; +import omero.api.ThumbnailStorePrx; +import omero.cmd.DoAll; +import omero.cmd.Request; +import omero.grid.SharedResourcesPrx; + +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + +/** + * Manages the various services and entry points. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +class Connector +{ + + /** The thumbnail service. */ + private ThumbnailStorePrx thumbnailService; + + /** The raw file store. */ + private RawFileStorePrx fileStore; + + /** The raw pixels store. */ + private RawPixelsStorePrx pixelsStore; + + /** The projection service. */ + private IProjectionPrx projService; + + /** The query service. */ + private IQueryPrx queryService; + + /** The rendering settings service. */ + private IRenderingSettingsPrx rndSettingsService; + + /** The repository service. */ + private IRepositoryInfoPrx repInfoService; + + /** The delete service. */ + private IDeletePrx deleteService; + + /** The pixels service. */ + private IPixelsPrx pixelsService; + + /** The container service. */ + private IContainerPrx pojosService; + + /** The update service. */ + private IUpdatePrx updateService; + + /** The metadata service. */ + private IMetadataPrx metadataService; + + /** The scripting service. */ + private IScriptPrx scriptService; + + /** The ROI (Region of Interest) service. */ + private IRoiPrx roiService; + + /** The Admin service. */ + private IAdminPrx adminService; + + /** The shared resources. */ + private SharedResourcesPrx sharedResources; + + /** The service to import files. */ + private OMEROMetadataStoreClient importStore; + + /** + * The Blitz client object, this is the entry point to the + * OMERO Server using a secure connection. + */ + private client secureClient; + + /** + * The client object, this is the entry point to the + * OMERO Server using non secure data transfer + */ + private client unsecureClient; + + /** + * The entry point provided by the connection library to access the various + * OMERO services. + */ + private ServiceFactoryPrx entryEncrypted; + + /** + * The entry point provided by the connection library to access the various + * OMERO services. + */ + private ServiceFactoryPrx entryUnencrypted; + + /** Collection of services to keep alive. */ + private Set services; + + /** Collection of services to keep alive. */ + private Map reServices; + + /** + * The number of thumbnails already retrieved. Resets to 0 + * when the value equals {@link OMEROGateway#MAX_RETRIEVAL}. + */ + private int thumbRetrieval; + + /** The security context for that connector.*/ + private SecurityContext context; + + /** + * Closes the specified service. + * + * @param svc The service to handle. + */ + private void closeService(StatefulServiceInterfacePrx svc) + { + try { + svc.close(); + } catch (Exception e) {} //ignore + } + + /** + * Creates a new instance. + * + * @param context The context hosting information about the user. + * @param secureClient The entry point to server. + * @param entryEncrypted The entry point to access the various services. + * @param encrypted The entry point to access the various services. + * @throws Throwable Thrown if entry points cannot be initialized. + */ + Connector(SecurityContext context, client secureClient, + ServiceFactoryPrx entryEncrypted, boolean encrypted) + throws Throwable + { + if (context == null) + throw new IllegalArgumentException("No Security context."); + if (secureClient == null) + throw new IllegalArgumentException("No Server entry point."); + if (entryEncrypted == null) + throw new IllegalArgumentException("No Services entry point."); + if (!encrypted) { + unsecureClient = secureClient.createClient(false); + entryUnencrypted = unsecureClient.getSession(); + } + this.secureClient = secureClient; + this.entryEncrypted = entryEncrypted; + this.context = context; + thumbRetrieval = 0; + services = new HashSet(); + reServices = new HashMap(); + } + + /** + * Returns the {@link SharedResourcesPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + SharedResourcesPrx getSharedResources() + throws Throwable + { + if (sharedResources == null) + sharedResources = entryEncrypted.sharedResources(); + return sharedResources; + } + + /** + * Returns the {@link IRenderingSettingsPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IRenderingSettingsPrx getRenderingSettingsService() + throws Throwable + { + if (rndSettingsService == null) { + if (entryUnencrypted != null) + rndSettingsService = + entryUnencrypted.getRenderingSettingsService(); + else + rndSettingsService = + entryEncrypted.getRenderingSettingsService(); + + if (rndSettingsService != null) + services.add(rndSettingsService); + } + return rndSettingsService; + } + + /** + * Creates or recycles the import store. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + OMEROMetadataStoreClient getImportStore() + throws Throwable + { + if (importStore == null) { + importStore = new OMEROMetadataStoreClient(); + importStore.initialize(entryEncrypted); + } + return importStore; + } + + /** + * Returns the {@link IRepositoryInfoPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IRepositoryInfoPrx getRepositoryService() + throws Throwable + { + if (repInfoService == null) { + if (entryUnencrypted != null) + repInfoService = + entryUnencrypted.getRepositoryInfoService(); + else repInfoService = + entryEncrypted.getRepositoryInfoService(); + if (repInfoService != null) + services.add(repInfoService); + } + return repInfoService; + } + + /** + * Returns the {@link IScriptPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IScriptPrx getScriptService() + throws Throwable + { + if (scriptService == null) { + if (entryUnencrypted != null) + scriptService = entryUnencrypted.getScriptService(); + else scriptService = entryEncrypted.getScriptService(); + if (scriptService != null) + services.add(scriptService); + } + return scriptService; + } + + /** + * Returns the {@link IContainerPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IContainerPrx getPojosService() + throws Throwable + { + if (pojosService == null) { + if (entryUnencrypted != null) + pojosService = entryUnencrypted.getContainerService(); + else pojosService = entryEncrypted.getContainerService(); + if (pojosService != null) + services.add(pojosService); + } + return pojosService; + } + + /** + * Returns the {@link IQueryPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IQueryPrx getQueryService() + throws Throwable + { + if (queryService == null) { + if (entryUnencrypted != null) + queryService = entryUnencrypted.getQueryService(); + else queryService = entryEncrypted.getQueryService(); + if (queryService != null) + services.add(queryService); + } + return queryService; + } + + /** + * Returns the {@link IUpdatePrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IUpdatePrx getUpdateService() + throws Throwable + { + if (updateService == null) { + if (entryUnencrypted != null) + updateService = entryUnencrypted.getUpdateService(); + else updateService = entryEncrypted.getUpdateService(); + if (updateService != null) + services.add(updateService); + } + return updateService; + } + + /** + * Returns the {@link IMetadataPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IMetadataPrx getMetadataService() + throws Throwable + { + if (metadataService == null) { + if (entryUnencrypted != null) + metadataService = entryUnencrypted.getMetadataService(); + else metadataService = entryEncrypted.getMetadataService(); + if (metadataService != null) + services.add(metadataService); + } + return metadataService; + } + + /** + * Returns the {@link IRoiPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IRoiPrx getROIService() + throws Throwable + { + if (roiService == null) { + if (entryUnencrypted != null) + roiService = entryUnencrypted.getRoiService(); + else roiService = entryEncrypted.getRoiService(); + if (roiService != null) services.add(roiService); + } + return roiService; + } + + /** + * Returns the {@link IConfigPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IConfigPrx getConfigService() + throws Throwable + { + if (entryUnencrypted != null) + return entryUnencrypted.getConfigService(); + return entryEncrypted.getConfigService(); + } + + /** + * Returns the {@link IDeletePrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IDeletePrx getDeleteService() + throws Throwable + { + if (deleteService == null) { + if (entryUnencrypted != null) + deleteService = entryUnencrypted.getDeleteService(); + else + deleteService = entryEncrypted.getDeleteService(); + if (deleteService != null) + services.add(deleteService); + } + return deleteService; + } + + /** + * Returns the {@link ThumbnailStorePrx} service. + * + * @param value The number of elements to retrieve. + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + ThumbnailStorePrx getThumbnailService(int value) + throws Throwable + { + thumbRetrieval += value; + if (thumbRetrieval >= OMEROGateway.MAX_RETRIEVAL) { + thumbRetrieval = 0; + //to be on the save side + if (thumbnailService != null) thumbnailService.close(); + services.remove(thumbnailService); + thumbnailService = null; + } + if (thumbnailService == null) { + if (entryUnencrypted != null) + thumbnailService = entryUnencrypted.createThumbnailStore(); + else + thumbnailService = entryEncrypted.createThumbnailStore(); + if (thumbnailService != null) + services.add(thumbnailService); + } + return thumbnailService; + } + + /** + * Returns the {@link ExporterPrx} service. + * + * @return See above. + * @throws @throws Throwable Thrown if the service cannot be initialized. + */ + ExporterPrx getExporterService() + throws Throwable + { + if (entryUnencrypted != null) + return entryUnencrypted.createExporter(); + return entryEncrypted.createExporter(); + } + + /** + * Returns the {@link RawFileStorePrx} service. + * + * @return See above. + * @throws @throws Throwable Thrown if the service cannot be initialized. + */ + RawFileStorePrx getRawFileService() + throws Throwable + { + if (entryUnencrypted != null) + return entryUnencrypted.createRawFileStore(); + return entryEncrypted.createRawFileStore(); + } + + /** + * Returns the {@link RenderingEnginePrx Rendering service}. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + RenderingEnginePrx getRenderingService() + throws Throwable + { + RenderingEnginePrx prx; + if (entryUnencrypted != null) + prx = entryUnencrypted.createRenderingEngine(); + else prx = entryEncrypted.createRenderingEngine(); + prx.setCompressionLevel(context.getCompression()); + return prx; + } + + /** + * Returns the {@link RawPixelsStorePrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + RawPixelsStorePrx getPixelsStore() + throws Throwable + { + if (entryUnencrypted != null) + return entryUnencrypted.createRawPixelsStore(); + return entryEncrypted.createRawPixelsStore(); + } + + /** + * Returns the {@link IPixelsPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IPixelsPrx getPixelsService() + throws Throwable + { + if (pixelsService == null) { + if (entryUnencrypted != null) + pixelsService = entryUnencrypted.getPixelsService(); + else + pixelsService = entryEncrypted.getPixelsService(); + if (pixelsService == null) + throw new DSOutOfServiceException( + "Cannot access the Pixels service."); + services.add(pixelsService); + } + return pixelsService; + } + + /** + * Returns the {@link SearchPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + SearchPrx getSearchService() + throws Throwable + { + if (entryUnencrypted != null) + return entryUnencrypted.createSearchService(); + return entryEncrypted.createSearchService(); + } + + /** + * Returns the {@link IProjectionPrx} service. + * + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IProjectionPrx getProjectionService() + throws Throwable + { + if (projService == null) { + if (entryUnencrypted != null) + projService = entryUnencrypted.getProjectionService(); + else projService = entryEncrypted.getProjectionService(); + if (projService != null) + services.add(projService); + } + return null; + } + + /** + * Returns the {@link IAdminPrx} service. + * + * @param ctx The security context. + * @return See above. + * @throws Throwable Thrown if the service cannot be initialized. + */ + IAdminPrx getAdminService(SecurityContext ctx) + throws Throwable + { + if (adminService == null) { + adminService = entryEncrypted.getAdminService(); + if (adminService != null) + services.add(adminService); + } + return adminService; + } + + /** Clears the data. */ + void clear() + { + services.clear(); + reServices.clear(); + thumbnailService = null; + fileStore = null; + metadataService = null; + pojosService = null; + projService = null; + queryService = null; + rndSettingsService = null; + repInfoService = null; + deleteService = null; + pixelsService = null; + roiService = null; + pixelsStore = null; + updateService = null; + scriptService = null; + sharedResources = null; + importStore = null; + } + + /** Closes the session.*/ + void close() + throws Throwable + { + secureClient.closeSession(); + } + + /** + * Tries to reconnect to the server. Returns true + * if it was possible to reconnect, false + * otherwise. + * + * @param userName The user name to be used for login. + * @param password The password to be used for login. + * @return See above. + */ + void reconnect(String name, String password) + throws Throwable + { + entryEncrypted = secureClient.createSession(name, password); + if (entryUnencrypted != null) { + unsecureClient = secureClient.createClient(false); + entryUnencrypted = unsecureClient.getSession(); + } + } + + /** Closes the services initialized by the importer.*/ + void closeImport() + { + if (importStore != null) { + importStore.closeServices(); + importStore = null; + } + } + + /** + * Shuts downs the stateful services. + * + * @param rendering Pass true to shut down the rendering + * services, false otherwise. + */ + void shutDownServices(boolean rendering) + { + if (thumbnailService != null) + closeService(thumbnailService); + if (pixelsStore != null) + closeService(pixelsStore); + if (fileStore != null) + closeService(fileStore); + if (importStore != null) { + importStore.closeServices(); + importStore = null; + } + Collection l = reServices.values(); + if (l != null && rendering) { + Iterator i = l.iterator(); + while (i.hasNext()) { + closeService(i.next()); + } + reServices.clear(); + } + thumbnailService = null; + pixelsStore = null; + fileStore = null; + } + + /** Keeps the services alive. */ + void keepSessionAlive() + { + Collection + all = new HashSet(); + + if (services.size() > 0) all.addAll(services); + if (reServices.size() > 0) all.addAll(reServices.values()); + if (all.size() == 0) return; + ServiceInterfacePrx[] entries = (ServiceInterfacePrx[]) + all.toArray(new ServiceInterfacePrx[all.size()]); + try { + entryEncrypted.keepAllAlive(entries); + } catch (Exception e) {} + try { + if (entryUnencrypted != null) + entryUnencrypted.keepAllAlive(entries); + } catch (Exception e) {} + } + + /** + * Closes the specified proxy. + * + * @param proxy The proxy to close. + */ + void close(StatefulServiceInterfacePrx proxy) + { + try { + if (proxy instanceof ThumbnailStorePrx) { + thumbnailService.close(); + thumbnailService = null; + } else proxy.close(); + } catch (Exception e) {} //ignore. + } + + /** + * Returns true if it is the connector corresponding to the + * passed context, false otherwise. + * + * @param ctx The security context. + * @return See above. + */ + boolean isSame(SecurityContext ctx) + { + if (ctx == null) return false; + //ignore server for now. + return ctx.getGroupID() == context.getGroupID(); + } + + /** + * Returns the secured client. + * + * @return See above. + */ + client getClient() { return secureClient; } + + /** + * Executes the commands. + * + * @param commands The commands to execute. + * @return See above. + */ + RequestCallback submit(List commands) + throws Exception + { + if (commands == null || commands.size() == 0) + return null; + DoAll all = new DoAll(); + Iterator i = commands.iterator(); + all.list = new ArrayList(); + while (i.hasNext()) { + all.list.add(i.next()); + } + + if (entryUnencrypted != null) { + //to be modified. + return new RequestCallback(getClient(), + entryUnencrypted.submit(commands.get(0))); + //return new RequestCallback(getClient(), + // entryUnencrypted.submit(all)); + } + //to be modified + return new RequestCallback(getClient(), + entryEncrypted.submit(commands.get(0))); + //return new RequestCallback(getClient(), entryEncrypted.submit(all)); + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/DataServicesFactory.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/DataServicesFactory.java index f475be66752..ffab812f623 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/DataServicesFactory.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/DataServicesFactory.java @@ -26,6 +26,7 @@ //Java imports import java.io.InputStream; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; @@ -50,6 +51,7 @@ import org.openmicroscopy.shoola.env.data.events.ReloadRenderingEngine; import org.openmicroscopy.shoola.env.data.login.LoginService; import org.openmicroscopy.shoola.env.data.login.UserCredentials; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.DataViewsFactory; import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.env.rnd.RenderingControl; @@ -306,6 +308,17 @@ private void notifyIncompatibility(String clientVersion, //exitApplication(); } + /** + * Returns the credentials. + * + * @return See above. + */ + UserCredentials getCredentials() + { + return (UserCredentials) + registry.lookup(LookupNames.USER_CREDENTIALS); + } + /** * Brings up a dialog indicating that the session has expired and * quits the application. @@ -352,7 +365,7 @@ public void sessionExpiredExit(int index, Throwable exc) while (i.hasNext()) { id = i.next(); try { - svc.reloadRenderingService(id); + //svc.reloadRenderingService(id); } catch (Exception e) { failure.add(id); } @@ -472,30 +485,19 @@ public void connect(UserCredentials uc) executor = new ScheduledThreadPoolExecutor(1); executor.scheduleWithFixedDelay(kca, 60, 60, TimeUnit.SECONDS); - String ldap = omeroGateway.lookupLdapAuthExperimenter(exp.getId()); - //replace Server string in fs config - /* - Iterator k = fsConfig.keySet().iterator(); - String value, key; - String regex = LookupNames.FS_HOSTNAME; - while (k.hasNext()) { - key = (String) k.next(); - value = fsConfig.getProperty(key); - value = value.replaceAll(regex, uc.getHostName()); - fsConfig.setProperty(key, value); - } - omeroGateway.startFS(fsConfig); - */ - registry.bind(LookupNames.USER_AUTHENTICATION, ldap); + //String ldap = omeroGateway.lookupLdapAuthExperimenter(exp.getId()); + //registry.bind(LookupNames.USER_AUTHENTICATION, ldap); registry.bind(LookupNames.CURRENT_USER_DETAILS, exp); registry.bind(LookupNames.CONNECTION_SPEED, isFastConnection(uc.getSpeedLevel())); - Set groups; + Collection groups; Set available; List exps = new ArrayList(); try { - groups = omeroGateway.getAvailableGroups(exp); + SecurityContext ctx = new SecurityContext( + exp.getDefaultGroup().getId()); + groups = omeroGateway.getAvailableGroups(ctx, exp); //Check if the current experimenter is an administrator Iterator i = groups.iterator(); GroupData g; @@ -536,15 +538,15 @@ public void connect(UserCredentials uc) } //Bind user details to all agents' registry. List agents = (List) registry.lookup(LookupNames.AGENTS); - Iterator i = agents.iterator(); + Iterator kk = agents.iterator(); AgentInfo agentInfo; Registry reg; Boolean b = (Boolean) registry.lookup(LookupNames.BINARY_AVAILABLE); - while (i.hasNext()) { - agentInfo = (AgentInfo) i.next(); + while (kk.hasNext()) { + agentInfo = (AgentInfo) kk.next(); if (agentInfo.isActive()) { reg = agentInfo.getRegistry(); - reg.bind(LookupNames.USER_AUTHENTICATION, ldap); + //reg.bind(LookupNames.USER_AUTHENTICATION, ldap); reg.bind(LookupNames.CURRENT_USER_DETAILS, exp); reg.bind(LookupNames.USER_GROUP_DETAILS, available); reg.bind(LookupNames.USERS_DETAILS, exps); @@ -574,8 +576,12 @@ public void connect(UserCredentials uc) */ public boolean isCompatible() { return compatible; } - /** Shuts down the connection. */ - public void shutdown() + /** + * Shuts down the connection. + * + * @param ctx The security context. + */ + public void shutdown(SecurityContext ctx) { //Need to write the current group. Set groups = (Set) registry.lookup(LookupNames.USER_GROUP_DETAILS); @@ -599,7 +605,7 @@ public void shutdown() ScreenLogin.registerGroup(names); } else ScreenLogin.registerGroup(null); CacheServiceFactory.shutdown(container); - ((OmeroImageServiceImpl) is).shutDown(); + ((OmeroImageServiceImpl) is).shutDown(ctx); omeroGateway.logout(); if (executor != null) executor.shutdown(); executor = null; @@ -657,7 +663,7 @@ public void exitApplication(boolean forceQuit, boolean exit) return; } } - shutdown(); + shutdown(null); if (exit) container.exit(); } @@ -669,7 +675,8 @@ public void exitApplication(boolean forceQuit, boolean exit) */ public static void isSessionAlive(Registry context) { - if (context == registry) omeroGateway.isSessionAlive(); + //To review + //if (context == registry) omeroGateway.isSessionAlive(); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OMEROGateway.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OMEROGateway.java index 1885cb4f6cf..8a82753bba1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OMEROGateway.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OMEROGateway.java @@ -61,6 +61,7 @@ import org.openmicroscopy.shoola.env.data.util.ModelMapper; import org.openmicroscopy.shoola.env.data.util.PojoMapper; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StatusLabel; import org.openmicroscopy.shoola.env.rnd.PixelsServicesFactory; import org.openmicroscopy.shoola.env.rnd.RenderingServiceException; @@ -105,7 +106,6 @@ import omero.api.IRepositoryInfoPrx; import omero.api.IRoiPrx; import omero.api.IScriptPrx; -import omero.api.ITimelinePrx; import omero.api.IUpdatePrx; import omero.api.RawFileStorePrx; import omero.api.RawPixelsStorePrx; @@ -114,11 +114,12 @@ import omero.api.RoiResult; import omero.api.SearchPrx; import omero.api.ServiceFactoryPrx; -import omero.api.ServiceInterfacePrx; import omero.api.StatefulServiceInterfacePrx; import omero.api.ThumbnailStorePrx; import omero.api.delete.DeleteCommand; import omero.api.delete.DeleteHandlePrx; +import omero.cmd.Chgrp; +import omero.cmd.Request; import omero.constants.projection.ProjectionType; import omero.grid.BoolColumn; import omero.grid.Column; @@ -356,129 +357,67 @@ class OMEROGateway ScriptObject.SETUP_PATH+"FLIM_initialise.py"); } - /** - * The number of thumbnails already retrieved. Resets to 0 - * when the value equals {@link #MAX_RETRIEVAL}. - */ - private int thumbRetrieval; - + /** The collection of connectors.*/ + private List connectors; + /** * The entry point provided by the connection library to access the various * OMERO services. */ - private ServiceFactoryPrx entryEncrypted; + private ServiceFactoryPrx entryEncrypted; /** * The entry point provided by the connection library to access the various * OMERO services. */ - private ServiceFactoryPrx entryUnencrypted; - - /** The thumbnail service. */ - private ThumbnailStorePrx thumbnailService; - - /** The raw file store. */ - private RawFileStorePrx fileStore; - - /** The raw pixels store. */ - private RawPixelsStorePrx pixelsStore; - - /** The projection service. */ - private IProjectionPrx projService; - - /** The Admin service. */ - private IAdminPrx adminService; - - /** The query service. */ - private IQueryPrx queryService; - - /** The rendering settings service. */ - private IRenderingSettingsPrx rndSettingsService; - - /** The repository service. */ - private IRepositoryInfoPrx repInfoService; - - /** The delete service. */ - private IDeletePrx deleteService; - - /** The pixels service. */ - private IPixelsPrx pixelsService; - - /** The container service. */ - private IContainerPrx pojosService; - - /** The update service. */ - private IUpdatePrx updateService; - - /** The metadata service. */ - private IMetadataPrx metadataService; - - /** The scripting service. */ - private IScriptPrx scriptService; - - /** The ROI (Region of Interest) service. */ - private IRoiPrx roiService; - - /** The time service. */ - private ITimelinePrx timeService; - - /** The shared resources. */ - private SharedResourcesPrx sharedResources; - - /** Tells whether we're currently connected and logged into OMERO. */ - private boolean connected; + private ServiceFactoryPrx entryUnencrypted; + + /** Tells whether we're currently connected and logged into OMERO.*/ + private boolean connected; /** * Used whenever a broken link is detected to get the Login Service and * try re-establishing a valid link to OMERO. */ - private DataServicesFactory dsFactory; - - /** The compression level. */ - private float compression; - - /** The port to connect. */ - private int port; + private DataServicesFactory dsFactory; - /** The port to connect. */ - private String hostName; + /** The default port to use. */ + private int port; /** * The Blitz client object, this is the entry point to the * OMERO Server using a secure connection. */ - private client secureClient; + //private client secureClient; /** * The Blitz client object, this is the entry point to the * OMERO Server using non secure data transfer */ - private client unsecureClient; + //private client unsecureClient; /** Map hosting the enumeration required for metadata. */ - private Map> enumerations; - - /** Collection of services to keep alive. */ - private Set services; - - /** Collection of services to keep alive. */ - private Map reServices; + private Map> enumerations; - /** The service to import files. */ - private OMEROMetadataStoreClient importStore; - /** The collection of system groups. */ - private List systemGroups; + private List systemGroups; /** Keep track of the file system view. */ private Map fsViews; - /** Checks if the session is still alive. */ - synchronized void isSessionAlive() + /** Flag indicating if the connection is encrypted or not.*/ + private boolean encrypted; + + /** + * Checks if the session is still alive. + * + * @param ctx The security context. + */ + synchronized void isSessionAlive(SecurityContext ctx) { if (!connected) return; try { - getAdminService().getEventContext(); + getAdminService(ctx).getEventContext(); } catch (Exception e) { Throwable cause = e.getCause(); int index = DataServicesFactory.SERVER_OUT_OF_SERVICE; @@ -490,9 +429,51 @@ synchronized void isSessionAlive() } } + /** + * Returns the RType corresponding to the passed value. + * + * @param value The value to convert. + * @return See above. + */ + private RType convertValue(Object value) + { + Iterator i; + if (value instanceof String) + return omero.rtypes.rstring((String) value); + else if (value instanceof Boolean) + return omero.rtypes.rbool((Boolean) value); + else if (value instanceof Long) + return omero.rtypes.rlong((Long) value); + else if (value instanceof Integer) + return omero.rtypes.rint((Integer) value); + else if (value instanceof Float) + return omero.rtypes.rfloat((Float) value); + else if (value instanceof List) { + List l = (List) value; + i = l.iterator(); + List list = new ArrayList(l.size()); + while (i.hasNext()) { + list.add(convertValue(i.next())); + } + return omero.rtypes.rlist(list); + } else if (value instanceof Map) { + Map map = (Map) value; + Map m = new HashMap(); + Entry entry; + i = map.entrySet().iterator(); + while (i.hasNext()) { + entry = (Entry) i.next(); + m.put((String) entry.getKey(), convertValue(entry.getValue())); + } + return omero.rtypes.rmap(m); + } + return null; + } + /** * Returns the identifier of the specified script. * + * @param ctx The security context. * @param name The name of the script. * @param message The error message. * @return See above. @@ -501,12 +482,11 @@ synchronized void isSessionAlive() * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private long getScriptID(String name, String message) + private long getScriptID(SecurityContext ctx, String name, String message) throws DSOutOfServiceException, DSAccessException { try { - IScriptPrx svc = getScriptService(); - if (svc == null) svc = getScriptService(); + IScriptPrx svc = getScriptService(ctx); return svc.getScriptID(name); } catch (Exception e) { handleException(e, message); @@ -517,22 +497,23 @@ private long getScriptID(String name, String message) /** * Returns the specified script. * + * @param ctx The security context. * @param scriptID The identifier of the script to run. * @param parameters The parameters to pass to the script. * @return See above. * @throws ProcessException If an error occurred while running the script. */ - private ScriptCallback runScript(long scriptID, + private ScriptCallback runScript(SecurityContext ctx, long scriptID, Map parameters) throws ProcessException { ScriptCallback cb = null; try { - IScriptPrx svc = getScriptService(); - if (svc == null) svc = getScriptService(); + IScriptPrx svc = getScriptService(ctx); + Connector c = getConnector(ctx); //scriptID, parameters, timeout (5s if null) ScriptProcessPrx prx = svc.runScript(scriptID, parameters, null); - cb = new ScriptCallback(scriptID, secureClient, prx); + cb = new ScriptCallback(scriptID, c.getClient(), prx); } catch (Exception e) { throw new ProcessException("Cannot run script with ID:"+scriptID, e); @@ -543,17 +524,18 @@ private ScriptCallback runScript(long scriptID, /** * Retrieves the system groups. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private List getSystemGroups() + private List getSystemGroups(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException { if (systemGroups != null) return systemGroups; - isSessionAlive(); + isSessionAlive(ctx); try { List names = new ArrayList(); Iterator j = SYSTEM_GROUPS.iterator(); @@ -565,9 +547,8 @@ private List getSystemGroups() params.map.put("names", omero.rtypes.rlist(names)); String sql = "select g from ExperimenterGroup as g "; sql += "where g.name in (:names)"; - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); - List l = getQueryService().findAllByQuery(sql, params); + IQueryPrx service = getQueryService(ctx); + List l = service.findAllByQuery(sql, params); Iterator i = l.iterator(); ExperimenterGroup group; String name; @@ -599,6 +580,7 @@ private List getSystemGroups() /** * Returns the system group corresponding to the passed name. * + * @param ctx The security context. * @param name The name to handle. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -606,10 +588,10 @@ private List getSystemGroups() * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private ExperimenterGroup getSystemGroup(String name) + private ExperimenterGroup getSystemGroup(SecurityContext ctx, String name) throws DSOutOfServiceException, DSAccessException { - getSystemGroups(); + getSystemGroups(ctx); Iterator i = systemGroups.iterator(); ExperimenterGroup g = null; @@ -1197,15 +1179,17 @@ private String convertProperty(Class nodeType, String property) /** * Loads the links. * - * @param table The table's link. - * @param childID The annotation's identifier - * @param userID The user's identifier. + * @param ctx The security context. + * @param table The table's link. + * @param childID The annotation's identifier + * @param userID The user's identifier. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private List loadLinks(String table, long childID, long userID) + private List loadLinks(SecurityContext ctx, String table, long childID, + long userID) throws DSOutOfServiceException, DSAccessException { try { @@ -1229,9 +1213,8 @@ private List loadLinks(String table, long childID, long userID) param.map.put("userID", omero.rtypes.rlong(userID)); } } - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); - return getQueryService().findAllByQuery(sb.toString(), param); + IQueryPrx service = getQueryService(ctx); + return service.findAllByQuery(sb.toString(), param); } catch (Throwable t) { handleException(t, "Cannot retrieve the requested link for "+ "child ID: "+childID); @@ -1241,26 +1224,28 @@ private List loadLinks(String table, long childID, long userID) /** * Returns the {@link SharedResourcesPrx} service. - * + * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private SharedResourcesPrx getSharedResources() + private SharedResourcesPrx getSharedResources(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { - try { - if (sharedResources == null) { - sharedResources = entryEncrypted.sharedResources(); - if (sharedResources == null) - throw new DSOutOfServiceException( - "Cannot access the Shared Resources."); - } - return sharedResources; - } catch (Exception e) { + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + SharedResourcesPrx prx = c.getSharedResources(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Shared Resources."); + return prx; + } catch (Throwable e) { handleException(e, "Cannot access the Shared Resources."); } return null; @@ -1269,29 +1254,26 @@ private SharedResourcesPrx getSharedResources() /** * Returns the {@link IRenderingSettingsPrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IRenderingSettingsPrx getRenderingSettingsService() + private IRenderingSettingsPrx getRenderingSettingsService( + SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (rndSettingsService == null) { - if (entryUnencrypted != null) - rndSettingsService = - entryUnencrypted.getRenderingSettingsService(); - else - rndSettingsService = - entryEncrypted.getRenderingSettingsService(); - - if (rndSettingsService == null) - throw new DSOutOfServiceException( - "Cannot access the RenderingSettings service."); - services.add(rndSettingsService); - } - return rndSettingsService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IRenderingSettingsPrx prx = c.getRenderingSettingsService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the RenderingSettings service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the RenderingSettings service."); } @@ -1301,20 +1283,25 @@ private IRenderingSettingsPrx getRenderingSettingsService() /** * Creates or recycles the import store. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private OMEROMetadataStoreClient getImportStore() + private OMEROMetadataStoreClient getImportStore(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (importStore == null) { - importStore = new OMEROMetadataStoreClient(); - importStore.initialize(entryEncrypted); - } - return importStore; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + OMEROMetadataStoreClient prx = c.getImportStore(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Import service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access Import service."); } @@ -1324,27 +1311,25 @@ private OMEROMetadataStoreClient getImportStore() /** * Returns the {@link IRepositoryInfoPrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IRepositoryInfoPrx getRepositoryService() + private IRepositoryInfoPrx getRepositoryService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (repInfoService == null) { - if (entryUnencrypted != null) - repInfoService = - entryUnencrypted.getRepositoryInfoService(); - else repInfoService = - entryEncrypted.getRepositoryInfoService(); - if (repInfoService == null) - throw new DSOutOfServiceException( - "Cannot access the RepositoryInfo service."); - services.add(repInfoService); - } - return repInfoService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IRepositoryInfoPrx prx = c.getRepositoryService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the RepositoryInfo service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the RepositoryInfo service."); } @@ -1354,53 +1339,85 @@ private IRepositoryInfoPrx getRepositoryService() /** * Returns the {@link IScriptPrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IScriptPrx getScriptService() + private IScriptPrx getScriptService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (scriptService == null) { - if (entryUnencrypted != null) - scriptService = entryUnencrypted.getScriptService(); - else scriptService = entryEncrypted.getScriptService(); - if (scriptService == null) - throw new DSOutOfServiceException( - "Cannot access the Scripting service."); - services.add(scriptService); - } - return scriptService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IScriptPrx prx = c.getScriptService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Scripting service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the Scripting service."); } return null; } + /** + * Returns the connector corresponding to the passed context. + * + * @param ctx The security context. + * @return + */ + private Connector getConnector(SecurityContext ctx) + throws DSAccessException, DSOutOfServiceException + { + Iterator i = connectors.iterator(); + Connector c; + while (i.hasNext()) { + c = i.next(); + if (c.isSame(ctx)) return c; + } + //We are going to create a connector and activate a session. + try { + UserCredentials uc = dsFactory.getCredentials(); + client client = new client(uc.getHostName(), port); + ServiceFactoryPrx prx = client.createSession(uc.getUserName(), + uc.getPassword()); + prx.setSecurityContext( + new ExperimenterGroupI(ctx.getGroupID(), false)); + c = new Connector(ctx, client, prx, encrypted); + connectors.add(c); + return c; + } catch (Throwable e) { + handleException(e, "Cannot create a connector"); + } + return null; + } + /** * Returns the {@link IContainerPrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IContainerPrx getPojosService() + private IContainerPrx getPojosService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (pojosService == null) { - if (entryUnencrypted != null) - pojosService = entryUnencrypted.getContainerService(); - else pojosService = entryEncrypted.getContainerService(); - if (pojosService == null) - throw new DSOutOfServiceException( - "Cannot access the Container service."); - services.add(pojosService); - } - return pojosService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IContainerPrx prx = c.getPojosService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Container service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the Container service."); } @@ -1409,26 +1426,26 @@ private IContainerPrx getPojosService() /** * Returns the {@link IQueryPrx} service. - * + * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IQueryPrx getQueryService() + private IQueryPrx getQueryService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (queryService == null) { - if (entryUnencrypted != null) - queryService = entryUnencrypted.getQueryService(); - else queryService = entryEncrypted.getQueryService(); - if (queryService == null) - throw new DSOutOfServiceException( - "Cannot access the Query service."); - services.add(queryService); - } - return queryService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IQueryPrx prx = c.getQueryService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Query service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the Query service."); } @@ -1437,26 +1454,26 @@ private IQueryPrx getQueryService() /** * Returns the {@link IUpdatePrx} service. - * + * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IUpdatePrx getUpdateService() + private IUpdatePrx getUpdateService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (updateService == null) { - if (entryUnencrypted != null) - updateService = entryUnencrypted.getUpdateService(); - else updateService = entryEncrypted.getUpdateService(); - if (updateService == null) - throw new DSOutOfServiceException( - "Cannot access Update service."); - services.add(updateService); - } - return updateService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IUpdatePrx prx = c.getUpdateService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Update service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access Update service."); } @@ -1465,26 +1482,26 @@ private IUpdatePrx getUpdateService() /** * Returns the {@link IMetadataPrx} service. - * + * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IMetadataPrx getMetadataService() + private IMetadataPrx getMetadataService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (metadataService == null) { - if (entryUnencrypted != null) - metadataService = entryUnencrypted.getMetadataService(); - else metadataService = entryEncrypted.getMetadataService(); - if (metadataService == null) - throw new DSOutOfServiceException( - "Cannot access the Metadata service."); - services.add(metadataService); - } - return metadataService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IMetadataPrx prx = c.getMetadataService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Metadata service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the Metadata service."); } @@ -1493,26 +1510,26 @@ private IMetadataPrx getMetadataService() /** * Returns the {@link IRoiPrx} service. - * + * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IRoiPrx getROIService() + private IRoiPrx getROIService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (roiService == null) { - if (entryUnencrypted != null) - roiService = entryUnencrypted.getRoiService(); - else roiService = entryEncrypted.getRoiService(); - if (roiService == null) - throw new DSOutOfServiceException( - "Cannot access the ROI service."); - services.add(roiService); - } - return roiService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IRoiPrx prx = c.getROIService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the ROI service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access th ROI service."); } @@ -1522,23 +1539,25 @@ private IRoiPrx getROIService() /** * Returns the {@link IAdminPrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IAdminPrx getAdminService() + private IAdminPrx getAdminService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (adminService == null) { - adminService = entryEncrypted.getAdminService(); - if (adminService == null) - throw new DSOutOfServiceException( - "Cannot access the Admin service."); - services.add(adminService); - } - return adminService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IAdminPrx prx = c.getAdminService(ctx); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Admin service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the Admin service."); } @@ -1569,26 +1588,25 @@ private IConfigPrx getConfigService() /** * Returns the {@link IDeletePrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IDeletePrx getDeleteService() + private IDeletePrx getDeleteService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (deleteService == null) { - if (entryUnencrypted != null) - deleteService = entryUnencrypted.getDeleteService(); - else - deleteService = entryEncrypted.getDeleteService(); - if (deleteService == null) - throw new DSOutOfServiceException( - "Cannot access the Delete service."); - services.add(deleteService); - } - return deleteService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IDeletePrx prx = c.getDeleteService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Delete service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access Delete service."); } @@ -1597,34 +1615,27 @@ private IDeletePrx getDeleteService() /** * Returns the {@link ThumbnailStorePrx} service. - * + * + * @param ctx The security context. + * @param n The number of retrieval. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private ThumbnailStorePrx getThumbService() + private ThumbnailStorePrx getThumbnailService(SecurityContext ctx, int n) throws DSAccessException, DSOutOfServiceException { try { - if (thumbRetrieval == MAX_RETRIEVAL) { - thumbRetrieval = 0; - //to be on the save side - if (thumbnailService != null) thumbnailService.close(); - services.remove(thumbnailService); - thumbnailService = null; - } - if (thumbnailService == null) { - if (entryUnencrypted != null) - thumbnailService = entryUnencrypted.createThumbnailStore(); - else - thumbnailService = entryEncrypted.createThumbnailStore(); - if (thumbnailService == null) - throw new DSOutOfServiceException( - "Cannot access Thumbnail service."); - services.add(thumbnailService); - } - return thumbnailService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + ThumbnailStorePrx prx = c.getThumbnailService(n); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Delete service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access Thumbnail service."); } @@ -1633,24 +1644,26 @@ private ThumbnailStorePrx getThumbService() /** * Returns the {@link ExporterPrx} service. - * + * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private ExporterPrx getExporterService() + private ExporterPrx getExporterService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - ExporterPrx store = null; - if (entryUnencrypted != null) - store = entryUnencrypted.createExporter(); - else store = entryEncrypted.createExporter(); - if (store == null) + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + ExporterPrx prx = c.getExporterService(); + if (prx == null) throw new DSOutOfServiceException( "Cannot access the Exporter service."); - return store; + return prx; } catch (Throwable e) { handleException(e, "Cannot access the Exporter service."); } @@ -1659,34 +1672,26 @@ private ExporterPrx getExporterService() /** * Returns the {@link RawFileStorePrx} service. - * + * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private RawFileStorePrx getRawFileService() + private RawFileStorePrx getRawFileService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - /* - if (fileStore != null) { - services.remove(fileStore); - try { - fileStore.close(); - } catch (Exception e) {} - } - fileStore = entry.createRawFileStore(); - services.add(fileStore); - */ - if (entryUnencrypted != null) - fileStore = entryUnencrypted.createRawFileStore(); - else - fileStore = entryEncrypted.createRawFileStore(); - if (fileStore == null) + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + RawFileStorePrx prx = c.getRawFileService(); + if (prx == null) throw new DSOutOfServiceException( - "Cannot access the RawFileStore Engine."); - return fileStore; + "Cannot access the RawFileStore service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the RawFileStore service."); } @@ -1696,24 +1701,25 @@ private RawFileStorePrx getRawFileService() /** * Returns the {@link RenderingEnginePrx Rendering service}. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private RenderingEnginePrx getRenderingService() + private RenderingEnginePrx getRenderingService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - RenderingEnginePrx engine; - if (entryUnencrypted != null) - engine = entryUnencrypted.createRenderingEngine(); - else engine = entryEncrypted.createRenderingEngine(); - if (engine == null) + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + RenderingEnginePrx prx = c.getRenderingService(); + if (prx == null) throw new DSOutOfServiceException( "Cannot access the Rendering Engine."); - engine.setCompressionLevel(compression); - return engine; + return prx; } catch (Throwable e) { handleException(e, "Cannot access the Rendering Engine."); } @@ -1723,23 +1729,25 @@ private RenderingEnginePrx getRenderingService() /** * Returns the {@link RawPixelsStorePrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private RawPixelsStorePrx getPixelsStore() + private RawPixelsStorePrx getPixelsStore(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (entryUnencrypted != null) - pixelsStore = entryUnencrypted.createRawPixelsStore(); - else - pixelsStore = entryEncrypted.createRawPixelsStore(); - if (pixelsStore == null) + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + RawPixelsStorePrx prx = c.getPixelsStore(); + if (prx == null) throw new DSOutOfServiceException( "Cannot access the RawPixelsStore service."); - return pixelsStore; + return prx; } catch (Throwable e) { handleException(e, "Cannot access the RawPixelsStore service."); } @@ -1749,26 +1757,25 @@ private RawPixelsStorePrx getPixelsStore() /** * Returns the {@link IPixelsPrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IPixelsPrx getPixelsService() + private IPixelsPrx getPixelsService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (pixelsService == null) { - if (entryUnencrypted != null) - pixelsService = entryUnencrypted.getPixelsService(); - else - pixelsService = entryEncrypted.getPixelsService(); - if (pixelsService == null) - throw new DSOutOfServiceException( - "Cannot access the Pixels service."); - services.add(pixelsService); - } - return pixelsService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IPixelsPrx prx = c.getPixelsService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Pixels service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the Pixels service."); } @@ -1778,22 +1785,24 @@ private IPixelsPrx getPixelsService() /** * Returns the {@link SearchPrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private SearchPrx getSearchService() + private SearchPrx getSearchService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - SearchPrx prx = null; - if (entryUnencrypted != null) - prx = entryUnencrypted.createSearchService(); - else prx = entryEncrypted.createSearchService(); + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + SearchPrx prx = c.getSearchService(); if (prx == null) throw new DSOutOfServiceException( - "Cannot access the Search service."); + "Cannot access the Search service."); return prx; } catch (Throwable e) { handleException(e, "Cannot access the Search service."); @@ -1804,25 +1813,25 @@ private SearchPrx getSearchService() /** * Returns the {@link IProjectionPrx} service. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private IProjectionPrx getProjectionService() + private IProjectionPrx getProjectionService(SecurityContext ctx) throws DSAccessException, DSOutOfServiceException { try { - if (projService == null) { - if (entryUnencrypted != null) - projService = entryUnencrypted.getProjectionService(); - else projService = entryEncrypted.getProjectionService(); - if (projService == null) - throw new DSOutOfServiceException( - "Cannot access the Projection service."); - services.add(projService); - } - return projService; + Connector c = getConnector(ctx); + if (c == null) + throw new DSOutOfServiceException( + "Cannot access the connector."); + IProjectionPrx prx = c.getProjectionService(); + if (prx == null) + throw new DSOutOfServiceException( + "Cannot access the Projection service."); + return prx; } catch (Throwable e) { handleException(e, "Cannot access the Projection service."); } @@ -1834,29 +1843,30 @@ private IProjectionPrx getProjectionService() * for the specified set of pixels. * * @param pixelsID The pixels ID. - * @param re The rendering engine to load. + * @param prx The rendering engine to load or thumbnail store. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - private synchronized void needDefault(long pixelsID, RenderingEnginePrx re) + private synchronized void needDefault(long pixelsID, Object prx) throws DSAccessException, DSOutOfServiceException { try { - if (re == null) { - ThumbnailStorePrx service = getThumbService(); + if (prx instanceof ThumbnailStorePrx) { + ThumbnailStorePrx service = (ThumbnailStorePrx) prx; if (!(service.setPixelsId(pixelsID))) { service.resetDefaults(); service.setPixelsId(pixelsID); } - } else { + } else if (prx instanceof RenderingEnginePrx) { + RenderingEnginePrx re = (RenderingEnginePrx) prx; if (!(re.lookupRenderingDef(pixelsID))) { re.resetDefaults(); re.lookupRenderingDef(pixelsID); } } } catch (Throwable e) { - handleException(e, "Cannot set RE defaults."); + handleException(e, "Cannot set the rendering defaults."); } } @@ -1983,26 +1993,10 @@ else if (BooleanAnnotationData.class.equals(pojo)) /** Clears the data. */ private void clear() { - services.clear(); - reServices.clear(); - thumbnailService = null; - fileStore = null; - metadataService = null; - pojosService = null; - projService = null; - adminService = null; - queryService = null; - rndSettingsService = null; - repInfoService = null; - deleteService = null; - pixelsService = null; - roiService = null; - pixelsStore = null; - updateService = null; - scriptService = null; - timeService = null; - sharedResources = null; - importStore = null; + Iterator i = connectors.iterator(); + while (i.hasNext()) { + i.next().clear(); + } } /** @@ -2039,7 +2033,7 @@ else if (nodeType.equals(TimestampAnnotation.class) || /** * Creates a new instance. * - * @param port The port used to connect. + * @param port The default port used to connect. * @param dsFactory A reference to the factory. Used whenever a broken * link is detected to get the Login Service and try * reestablishing a valid link to OMERO. @@ -2051,10 +2045,8 @@ else if (nodeType.equals(TimestampAnnotation.class) || throw new IllegalArgumentException("No Data service factory."); this.dsFactory = dsFactory; this.port = port; - thumbRetrieval = 0; enumerations = new HashMap>(); - services = new HashSet(); - reServices = new HashMap(); + connectors = new ArrayList(); } /** @@ -2199,18 +2191,18 @@ else if (FileAnnotationData.class.getName().equals(data)) * Retrieves the details on the current user and maps the result calling * {@link PojoMapper#asDataObjects(Map)}. * + * @param ctx The security context. * @param name The user's name. * @return The {@link ExperimenterData} of the current user. * @throws DSOutOfServiceException If the connection is broken, or * logged in. * @see IPojosPrx#getUserDetails(Set, Map) */ - ExperimenterData getUserDetails(String name) + ExperimenterData getUserDetails(SecurityContext ctx, String name) throws DSOutOfServiceException { try { - IAdminPrx service = getAdminService(); - if (service == null) service = getAdminService(); + IAdminPrx service = getAdminService(ctx); return (ExperimenterData) PojoMapper.asDataObject(service.lookupExperimenter(name)); } catch (Exception e) { @@ -2239,57 +2231,71 @@ boolean isUpgradeRequired() * Tries to connect to OMERO and log in by using the supplied * credentials. * - * @param userName The user name to be used for login. - * @param password The password to be used for login. - * @param hostName The name of the server. - * @param compressionLevel The compression level used for images and - * thumbnails depending on the connection speed. - * @param groupID The id of the group or -1. - * @param encrypted Pass true to encrypt data transfer, - * false otherwise. + * @param userName The user name to be used for login. + * @param password The password to be used for login. + * @param hostName The name of the server. + * @param compression The compression level used for images and + * thumbnails depending on the connection speed. + * @param groupID The id of the group or -1. + * @param encrypted Pass true to encrypt data transfer, + * false otherwise. * @return The user's details. * @throws DSOutOfServiceException If the connection can't be established * or the credentials are invalid. * @see #getUserDetails(String) */ ExperimenterData login(String userName, String password, String hostName, - float compressionLevel, long groupID, boolean - encrypted) + float compression, long groupID, boolean encrypted) throws DSOutOfServiceException { try { - compression = compressionLevel; - this.hostName = hostName; + //login in the default group + this.encrypted = encrypted; + client secureClient; if (port > 0) secureClient = new client(hostName, port); else secureClient = new client(hostName); - entryEncrypted = secureClient.createSession(userName, password); secureClient.setAgent(AGENT); - if (!encrypted) { - unsecureClient = secureClient.createClient(false); - entryUnencrypted = unsecureClient.getSession(); - } + entryEncrypted = secureClient.createSession(userName, password); + + + //now we register the new security context connected = true; - ExperimenterData exp = getUserDetails(userName); + IAdminPrx prx = entryEncrypted.getAdminService(); + ExperimenterData exp = (ExperimenterData) PojoMapper.asDataObject( + prx.lookupExperimenter(userName)); + SecurityContext ctx; + Connector connector; if (groupID >= 0) { long defaultID = -1; try { defaultID = exp.getDefaultGroup().getId(); - } catch (Exception e) { - // no default group - } + } catch (Exception e) {} + ctx = new SecurityContext(defaultID); + ctx.setServerInformation(hostName, port); + ctx.setCompression(compression); + connector = new Connector(ctx, secureClient, entryEncrypted, + encrypted); + connectors.add(connector); if (defaultID == groupID) return exp; try { - changeCurrentGroup(exp, groupID); - exp = getUserDetails(userName); + changeCurrentGroup(ctx, exp, groupID); + connectors.remove(connector); + ctx = new SecurityContext(groupID); + ctx.setServerInformation(hostName, port); + ctx.setCompression(compression); + connector = new Connector(ctx, secureClient, entryEncrypted, + encrypted); + connectors.add(connector); + exp = getUserDetails(ctx, userName); } catch (Exception e) { - /* - connected = false; - String s = "Can't connect to OMERO. Group not valid.\n\n"; - throw new DSOutOfServiceException(s, e); - */ } } - + ctx = new SecurityContext(exp.getDefaultGroup().getId()); + ctx.setServerInformation(hostName, port); + ctx.setCompression(compression); + connector = new Connector(ctx, secureClient, entryEncrypted, + encrypted); + connectors.add(connector); return exp; } catch (Throwable e) { connected = false; @@ -2302,22 +2308,23 @@ ExperimenterData login(String userName, String password, String hostName, /** * Retrieves the system view hosting the repositories. * + * @param ctx The security context. * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - FSFileSystemView getFSRepositories(long userID) + FSFileSystemView getFSRepositories(SecurityContext ctx, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); if (fsViews == null) fsViews = new HashMap(); if (fsViews.containsKey(userID)) return fsViews.get(userID); //Review that code FSFileSystemView view = null; try { - RepositoryMap m = getSharedResources().repositories(); + RepositoryMap m = getSharedResources(ctx).repositories(); List proxys = m.proxies; List names = m.descriptions; Iterator i = names.iterator(); @@ -2345,13 +2352,15 @@ FSFileSystemView getFSRepositories(long userID) /** * Changes the default group of the currently logged in user. * + * @param ctx The security context. * @param exp The experimenter to handle * @param groupID The id of the group. * @throws DSOutOfServiceException If the connection is broken, or logged in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - void changeCurrentGroup(ExperimenterData exp, long groupID) + void changeCurrentGroup(SecurityContext ctx, ExperimenterData exp, + long groupID) throws DSOutOfServiceException, DSAccessException { List groups = exp.getGroups(); @@ -2372,10 +2381,8 @@ void changeCurrentGroup(ExperimenterData exp, long groupID) try { shutDownServices(true); clear(); - IAdminPrx service = getAdminService(); - if (service == null) service = getAdminService(); - service.setDefaultGroup(exp.asExperimenter(), - group.asGroup()); + IAdminPrx service = getAdminService(ctx); + service.setDefaultGroup(exp.asExperimenter(), group.asGroup()); entryEncrypted.setSecurityContext( new ExperimenterGroupI(groupID, false)); } catch (Exception e) { @@ -2383,51 +2390,7 @@ void changeCurrentGroup(ExperimenterData exp, long groupID) } } - /** - * Changes the default group of the currently logged in user. - * - * @param exp The experimenter to handle - * @param groupID The id of the group. - * @throws DSOutOfServiceException If the connection is broken, or logged in. - * @throws DSAccessException If an error occurred while trying to - * retrieve data from OMERO service. - */ - /* - void changeCurrentGroup(ExperimenterData exp, long groupID, - String userName, String password) - throws DSOutOfServiceException, DSAccessException - { - List groups = exp.getGroups(); - Iterator i = groups.iterator(); - GroupData group = null; - boolean in = false; - while (i.hasNext()) { - group = i.next(); - if (group.getId() == groupID) { - in = true; - break; - } - } - String s = "Can't modify the current group.\n\n"; - if (!in) return; - try { - clear(); - secureClient.closeSession(); - if (unsecureClient != null) secureClient.closeSession(); - entryEncrypted = secureClient.createSession(userName, password); - if (unsecureClient != null) { - unsecureClient = secureClient.createClient(false); - entryUnencrypted = unsecureClient.getSession(); - } - getAdminService().setDefaultGroup(exp.asExperimenter(), - group.asGroup()); - entryEncrypted.setSecurityContext( - new ExperimenterGroupI(groupID, false)); - } catch (Exception e) { - handleException(e, s); - } - } -*/ + /** * Returns the version of the server. * @throws DSOutOfServiceException If the connection is broken, or logged in. @@ -2447,18 +2410,18 @@ String getServerVersion() /** * Returns the LDAP details or an empty string. * + * @param ctx The security context. * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection can't be established * or the credentials are invalid. */ - String lookupLdapAuthExperimenter(long userID) + String lookupLdapAuthExperimenter(SecurityContext ctx, long userID) throws DSOutOfServiceException { - isSessionAlive(); + isSessionAlive(ctx); try { - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); return svc.lookupLdapAuthExperimenter(userID); } catch (Throwable e) { String s = "Can't find the LDAP information.\n\n"; @@ -2468,8 +2431,8 @@ String lookupLdapAuthExperimenter(long userID) } void startFS(Properties fsConfig) - { + //TODO: review. /* monitorIDs = new ArrayList(); ObjectPrx base = getIceCommunicator().stringToProxy( @@ -2496,6 +2459,8 @@ void startFS(Properties fsConfig) List getRenderingServices() { List l = new ArrayList(); + //TODO: review + /* if (reServices == null || reServices.size() == 0) return l; Entry entry; Iterator i = reServices.entrySet().iterator(); @@ -2503,6 +2468,7 @@ List getRenderingServices() entry = (Entry) i.next(); l.add((Long) entry.getKey()); } + */ return l; } @@ -2517,9 +2483,35 @@ List getRenderingServices() */ boolean reconnect(String userName, String password) { - boolean b = entryUnencrypted != null; //sList clear(); + Iterator i; + try { + i = connectors.iterator(); + while (i.hasNext()) { + i.next().close(); + } + } catch (Throwable t) { + Throwable cause = t.getCause(); + connected = false; + //joining the session did not work so trying to create a session + if (cause instanceof ConnectionLostException || + t instanceof ConnectionLostException || + cause instanceof ClientError || + t instanceof ClientError) { + try { + connected = true; + i = connectors.iterator(); + while (i.hasNext()) { + i.next().reconnect(userName, password); + } + } catch (Throwable e) { + connected = false; + } + } + } + + /* try { //first to rejoin the session. connected = true; @@ -2563,7 +2555,7 @@ boolean reconnect(String userName, String password) } catch (Exception e) { return false; } - +*/ return connected; } @@ -2571,27 +2563,17 @@ boolean reconnect(String userName, String password) void logout() { connected = false; + shutDownServices(true); try { - shutDownServices(true); - clear(); - secureClient.closeSession(); - secureClient = null; - entryEncrypted = null; - } catch (Exception e) { - //session already dead. - } finally { - secureClient = null; - entryEncrypted = null; - } - try { - if (unsecureClient != null) unsecureClient.closeSession(); - unsecureClient = null; - entryUnencrypted = null; - } catch (Exception e) { - // TODO: handle exception + Iterator i = connectors.iterator(); + while (i.hasNext()) { + i.next().close(); + } + connectors.clear(); + } catch (Throwable e) { + connectors.clear(); } finally { - unsecureClient = null; - entryUnencrypted = null; + connectors.clear(); } } @@ -2604,6 +2586,7 @@ void logout() * {@link IPojos#loadContainerHierarchy(Class, List, Map)} * and maps the result calling {@link PojoMapper#asDataObjects(Set)}. * + * @param ctx The security context, necessary to determine the service. * @param rootType The top-most type which will be searched for * Can be Project. * Mustn't be null. @@ -2617,16 +2600,16 @@ void logout() * retrieve data from OMERO service. * @see IPojos#loadContainerHierarchy(Class, List, Map) */ - Set loadContainerHierarchy(Class rootType, List rootIDs, Parameters options) + Set loadContainerHierarchy(SecurityContext ctx, Class rootType, + List rootIDs, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IContainerPrx service = getPojosService(); - if (service == null) service = getPojosService(); + IContainerPrx service = getPojosService(ctx); return PojoMapper.asDataObjects( service.loadContainerHierarchy( - convertPojos(rootType).getName(), rootIDs, options)); + convertPojos(rootType).getName(), rootIDs, options)); } catch (Throwable t) { handleException(t, "Cannot load hierarchy for " + rootType+"."); } @@ -2642,6 +2625,7 @@ Set loadContainerHierarchy(Class rootType, List rootIDs, Parameters options) * {@link IPojos#findContainerHierarchies(Class, List, Map)} * and maps the result calling {@link PojoMapper#asDataObjects(Set)}. * + * @param ctx The security context, necessary to determine the service. * @param rootNodeType top-most type which will be searched for * Can be Project * Mustn't be null. @@ -2654,14 +2638,13 @@ Set loadContainerHierarchy(Class rootType, List rootIDs, Parameters options) * retrieve data from OMERO service. * @see IPojos#findContainerHierarchies(Class, List, Map) */ - Set findContainerHierarchy(Class rootNodeType, List leavesIDs, - Parameters options) + Set findContainerHierarchy(SecurityContext ctx, Class rootNodeType, + List leavesIDs, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IContainerPrx service = getPojosService(); - if (service == null) service = getPojosService(); + IContainerPrx service = getPojosService(ctx); return PojoMapper.asDataObjects(service.findContainerHierarchies( convertPojos(rootNodeType).getName(), leavesIDs, options)); } catch (Throwable t) { @@ -2682,6 +2665,7 @@ Set findContainerHierarchy(Class rootNodeType, List leavesIDs, * {@link IMetadataPrx#loadAnnotations(String, List, List, List)} * and maps the result calling {@link PojoMapper#asDataObjects(Parameters)}. * + * @param ctx The security context. * @param nodeType The type of the rootNodes. * Mustn't be null. * @param nodeIDs TheIds of the objects of type @@ -2701,11 +2685,11 @@ Set findContainerHierarchy(Class rootNodeType, List leavesIDs, * retrieve data from OMERO service. * @see IPojos#findAnnotations(Class, List, List, Map) */ - Map loadAnnotations(Class nodeType, List nodeIDs, + Map loadAnnotations(SecurityContext ctx, Class nodeType, List nodeIDs, List annotationTypes, List annotatorIDs, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List types = new ArrayList(); if (annotationTypes != null && annotationTypes.size() > 0) { types = new ArrayList(annotationTypes.size()); @@ -2718,8 +2702,7 @@ Map loadAnnotations(Class nodeType, List nodeIDs, } } try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); return PojoMapper.asDataObjects( service.loadAnnotations(convertPojos(nodeType).getName(), nodeIDs, types, annotatorIDs, options)); @@ -2732,24 +2715,24 @@ Map loadAnnotations(Class nodeType, List nodeIDs, /** * Loads the specified annotations. * + * @param ctx The security context. * @param annotationIds The annotation to load. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service.s */ - Set loadAnnotation(List annotationIds) + Set loadAnnotation(SecurityContext ctx, + List annotationIds) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); if (annotationIds == null || annotationIds.size() == 0) return new HashSet(); try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); return PojoMapper.asDataObjects( service.loadAnnotation(annotationIds)); - } catch (Throwable t) { handleException(t, "Cannot find the annotations."); } @@ -2759,6 +2742,7 @@ Set loadAnnotation(List annotationIds) /** * Finds the links if any between the specified parent and child. * + * @param ctx The security context. * @param type The type of parent to handle. * @param userID The id of the user. * @return See above. @@ -2766,13 +2750,12 @@ Set loadAnnotation(List annotationIds) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - Collection findAllAnnotations(Class type, long userID) + Collection findAllAnnotations(SecurityContext ctx, Class type, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); String table = getTableForAnnotationLink(type.getName()); if (table == null) return null; String sql = "select link from "+table+" as link"; @@ -2795,6 +2778,7 @@ Collection findAllAnnotations(Class type, long userID) * Wraps the call to the {@link IPojos#getImages(Class, List, Parameters)} * and maps the result calling {@link PojoMapper#asDataObjects(Set)}. * + * @param ctx The security context. * @param nodeType The type of container. Can be either Project, Dataset. * @param nodeIDs Set of containers' IDS. * @param options Options to retrieve the data. @@ -2804,13 +2788,13 @@ Collection findAllAnnotations(Class type, long userID) * retrieve data from OMERO service. * @see IPojos#getImages(Class, List, Map) */ - Set getContainerImages(Class nodeType, List nodeIDs, Parameters options) + Set getContainerImages(SecurityContext ctx, Class nodeType, List nodeIDs, + Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IContainerPrx service = getPojosService(); - if (service == null) service = getPojosService(); + IContainerPrx service = getPojosService(ctx); return PojoMapper.asDataObjects(service.getImages( convertPojos(nodeType).getName(), nodeIDs, options)); } catch (Throwable t) { @@ -2824,6 +2808,7 @@ Set getContainerImages(Class nodeType, List nodeIDs, Parameters options) * Wraps the call to the {@link IPojos#getUserImages(Parameters)} * and maps the result calling {@link PojoMapper#asDataObjects(Set)}. * + * @param ctx The security context. * @param options Options to retrieve the data. * @return A Set of retrieved images. * @throws DSOutOfServiceException If the connection is broken, or logged in @@ -2831,13 +2816,12 @@ Set getContainerImages(Class nodeType, List nodeIDs, Parameters options) * retrieve data from OMERO service. * @see IPojos#getUserImages(Map) */ - Set getUserImages(Parameters options) + Set getUserImages(SecurityContext ctx, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IContainerPrx service = getPojosService(); - if (service == null) service = getPojosService(); + IContainerPrx service = getPojosService(ctx); return PojoMapper.asDataObjects(service.getUserImages(options)); } catch (Throwable t) { handleException(t, "Cannot find user images."); @@ -2851,9 +2835,10 @@ Set getUserImages(Parameters options) * the number of items contained in this object and * maps the result calling {@link PojoMapper#asDataObjects(Map)}. * - * @param rootNodeType The type of container. Can either be Dataset. + * @param ctx The security context. + * @param rootNodeType The type of container. * @param property One of the properties defined by this class. - * @param ids The ids of the objects. + * @param ids The identifiers of the objects. * @param options Options to retrieve the data. * @param rootNodeIDs Set of root node IDs. * @return See above. @@ -2862,19 +2847,17 @@ Set getUserImages(Parameters options) * retrieve data from OMERO service. * @see IPojos#getCollectionCount(String, String, List, Map) */ - Map getCollectionCount(Class rootNodeType, String property, List ids, - Parameters options) + Map getCollectionCount(SecurityContext ctx, Class rootNodeType, + String property, List ids, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { if (TagAnnotationData.class.equals(rootNodeType)) { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); return service.getTaggedObjectsCount(ids, options); } - IContainerPrx service = getPojosService(); - if (service == null) service = getPojosService(); + IContainerPrx service = getPojosService(ctx); String p = convertProperty(rootNodeType, property); if (p == null) return null; return PojoMapper.asDataObjects(service.getCollectionCount( @@ -2888,6 +2871,7 @@ Map getCollectionCount(Class rootNodeType, String property, List ids, /** * Creates the specified object. * + * @param ctx The security context. * @param object The object to create. * @param options Options to create the data. * @return See above. @@ -2896,12 +2880,12 @@ Map getCollectionCount(Class rootNodeType, String property, List ids, * retrieve data from OMERO service. * @see IPojos#createDataObject(IObject, Map) */ - IObject createObject(IObject object) + IObject createObject(SecurityContext ctx, IObject object) throws DSOutOfServiceException, DSAccessException { try { - isSessionAlive(); - return saveAndReturnObject(object, null); + isSessionAlive(ctx); + return saveAndReturnObject(ctx, object, null); } catch (Throwable t) { handleException(t, "Cannot update the object."); } @@ -2911,6 +2895,7 @@ IObject createObject(IObject object) /** * Creates the specified objects. * + * @param ctx The security context. * @param objects The objects to create. * @param options Options to create the data. * @return See above. @@ -2919,12 +2904,12 @@ IObject createObject(IObject object) * retrieve data from OMERO service. * @see IPojos#createDataObjects(IObject[], Map) */ - List createObjects(List objects) + List createObjects(SecurityContext ctx, List objects) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - return saveAndReturnObject(objects, null); + return saveAndReturnObject(ctx, objects, null); } catch (Throwable t) { handleException(t, "Cannot create the objects."); } @@ -2934,24 +2919,23 @@ List createObjects(List objects) /** * Deletes the specified object. * + * @param ctx The security context. * @param object The object to delete. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. * @see IUpdate#deleteObject(IObject) */ - void deleteObject(IObject object) + void deleteObject(SecurityContext ctx, IObject object) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { if (object instanceof Plate) { - IDeletePrx svc = getDeleteService(); - if (svc == null) svc = getDeleteService(); + IDeletePrx svc = getDeleteService(ctx); svc.deletePlate(object.getId().getValue()); } else { - IUpdatePrx service = getUpdateService(); - if (service == null) service = getUpdateService(); + IUpdatePrx service = getUpdateService(ctx); service.deleteObject(object); } } catch (Throwable t) { @@ -2962,19 +2946,19 @@ void deleteObject(IObject object) /** * Deletes the specified objects. * + * @param ctx The security context. * @param objects The objects to delete. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. * @see IUpdate#deleteObject(IObject) */ - void deleteObjects(List objects) + void deleteObjects(SecurityContext ctx, List objects) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IUpdatePrx service = getUpdateService(); - if (service == null) service = getUpdateService(); + IUpdatePrx service = getUpdateService(ctx); Iterator i = objects.iterator(); //TODO: need method while (i.hasNext()) @@ -2988,6 +2972,7 @@ void deleteObjects(List objects) /** * Updates the specified object. * + * @param ctx The security context. * @param object The object to update. * @param options Options to update the data. * @return The updated object. @@ -2996,13 +2981,13 @@ void deleteObjects(List objects) * retrieve data from OMERO service. * @see IPojos#updateDataObject(IObject, Map) */ - IObject saveAndReturnObject(IObject object, Map options) + IObject saveAndReturnObject(SecurityContext ctx, IObject object, + Map options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IUpdatePrx service = getUpdateService(); - if (service == null) service = getUpdateService(); + IUpdatePrx service = getUpdateService(ctx); if (options == null) return service.saveAndReturnObject(object); return service.saveAndReturnObject(object, options); } catch (Throwable t) { @@ -3014,21 +2999,22 @@ IObject saveAndReturnObject(IObject object, Map options) /** * Updates the specified object. * + * @param ctx The security context. * @param objects The objects to update. - * @param options Options to update the data. + * @param options Options to update the data. * @return The updated object. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. * @see IPojos#updateDataObject(IObject, Map) */ - List saveAndReturnObject(List objects, Map options) + List saveAndReturnObject(SecurityContext ctx, + List objects, Map options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IUpdatePrx service = getUpdateService(); - if (service == null) service = getUpdateService(); + IUpdatePrx service = getUpdateService(ctx); return service.saveAndReturnArray(objects); } catch (Throwable t) { handleException(t, "Cannot update the object."); @@ -3039,23 +3025,24 @@ List saveAndReturnObject(List objects, Map options) /** * Updates the specified object. * - * @param object The object to update. - * @param options Options to update the data. - * @return The updated object. + * @param ctx The security context. + * @param object The object to update. + * @param options Options to update the data. + * @return The updated object. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. * @see IPojos#updateDataObject(IObject, Map) */ - IObject updateObject(IObject object, Parameters options) + IObject updateObject(SecurityContext ctx, IObject object, + Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IContainerPrx service = getPojosService(); - if (service == null) service = getPojosService(); + IContainerPrx service = getPojosService(ctx); IObject r = service.updateDataObject(object, options); - return findIObject(r); + return findIObject(ctx, r); } catch (Throwable t) { handleException(t, "Cannot update the object."); } @@ -3066,28 +3053,29 @@ IObject updateObject(IObject object, Parameters options) * Updates the specified IObjects and returned the * updated IObjects. * - * @param objects The array of objects to update. - * @param options Options to update the data. - * @return See above. + * @param ctx The security context. + * @param objects The array of objects to update. + * @param options Options to update the data. + * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. * @see IPojos#updateDataObjects(IObject[], Map) */ - List updateObjects(List objects, Parameters options) + List updateObjects(SecurityContext ctx, List objects, + Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IContainerPrx service = getPojosService(); - if (service == null) service = getPojosService(); + IContainerPrx service = getPojosService(ctx); List l = service.updateDataObjects(objects, options); if (l == null) return l; Iterator i = l.iterator(); List r = new ArrayList(l.size()); IObject io; while (i.hasNext()) { - io = findIObject(i.next()); + io = findIObject(ctx, i.next()); if (io != null) r.add(io); } return r; @@ -3100,19 +3088,19 @@ List updateObjects(List objects, Parameters options) /** * Retrieves the dimensions in microns of the specified pixels set. * + * @param ctx The security context. * @param pixelsID The pixels set ID. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - Pixels getPixels(long pixelsID) + Pixels getPixels(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IPixelsPrx service = getPixelsService(); - if (service == null) service = getPixelsService(); + IPixelsPrx service = getPixelsService(ctx); return service.retrievePixDescription(pixelsID); } catch (Throwable t) { handleException(t, "Cannot retrieve the pixels set of "+ @@ -3124,41 +3112,35 @@ Pixels getPixels(long pixelsID) /** * Retrieves the thumbnail for the passed set of pixels. * - * @param pixelsID The id of the pixels set the thumbnail is for. - * @param sizeX The size of the thumbnail along the X-axis. - * @param sizeY The size of the thumbnail along the Y-axis. - * @param userID The id of the user the thumbnail is for. + * @param ctx The security context. + * @param pixelsID The id of the pixels set the thumbnail is for. + * @param sizeX The size of the thumbnail along the X-axis. + * @param sizeY The size of the thumbnail along the Y-axis. + * @param userID The id of the user the thumbnail is for. * @return See above. * @throws RenderingServiceException If an error occurred while trying to * retrieve data from the service. * @throws DSOutOfServiceException If the connection is broken. */ - synchronized byte[] getThumbnail(long pixelsID, int sizeX, int sizeY, - long userID) + synchronized byte[] getThumbnail(SecurityContext ctx, long pixelsID, + int sizeX, int sizeY, long userID) throws RenderingServiceException, DSOutOfServiceException { - isSessionAlive(); + isSessionAlive(ctx); + ThumbnailStorePrx service = null; try { - ThumbnailStorePrx service = getThumbService(); - if (service == null) service = getThumbService(); - needDefault(pixelsID, null); + service = getThumbnailService(ctx, 1); + needDefault(pixelsID, service); //getRendering Def for a given pixels set. if (userID >= 0) { - RenderingDef def = getRenderingDef(pixelsID, userID); + RenderingDef def = getRenderingDef(ctx, pixelsID, userID); if (def != null) service.setRenderingDefId( def.getId().getValue()); } return service.getThumbnail(omero.rtypes.rint(sizeX), omero.rtypes.rint(sizeY)); } catch (Throwable t) { - if (thumbnailService != null) { - try { - thumbnailService.close(); - } catch (Exception e) { - //nothing we can do - } - } - thumbnailService = null; + closeService(ctx, service); if (t instanceof ServerError) { throw new DSOutOfServiceException( "Thumbnail service null for pixelsID: "+pixelsID, t); @@ -3170,33 +3152,28 @@ synchronized byte[] getThumbnail(long pixelsID, int sizeX, int sizeY, /** * Retrieves the thumbnail for the passed set of pixels. * - * @param pixelsID The id of the pixels set the thumbnail is for. - * @param maxLength The maximum length of the thumbnail width or height + * @param ctx The security context. + * @param pixelsID The id of the pixels set the thumbnail is for. + * @param maxLength The maximum length of the thumbnail width or height * depending on the pixel size. * @return See above. * @throws RenderingServiceException If an error occurred while trying to * retrieve data from the service. * @throws DSOutOfServiceException If the connection is broken. */ - synchronized byte[] getThumbnailByLongestSide(long pixelsID, int maxLength) + synchronized byte[] getThumbnailByLongestSide(SecurityContext ctx, + long pixelsID, int maxLength) throws RenderingServiceException, DSOutOfServiceException { - isSessionAlive(); + isSessionAlive(ctx); + ThumbnailStorePrx service = null; try { - ThumbnailStorePrx service = getThumbService(); - if (service == null) service = getThumbService(); - needDefault(pixelsID, null); + service = getThumbnailService(ctx, 1); + needDefault(pixelsID, service); return service.getThumbnailByLongestSide( omero.rtypes.rint(maxLength)); } catch (Throwable t) { - if (thumbnailService != null) { - try { - thumbnailService.close(); - } catch (Exception e) { - //nothing we can do - } - } - thumbnailService = null; + closeService(ctx, service); if (t instanceof ServerError) { throw new DSOutOfServiceException( "Thumbnail service null for pixelsID: "+pixelsID, t); @@ -3208,38 +3185,31 @@ synchronized byte[] getThumbnailByLongestSide(long pixelsID, int maxLength) /** * Retrieves the thumbnail for the passed collection of pixels set. * - * @param pixelsID The collection of pixels set. - * @param maxLength The maximum length of the thumbnail width or height + * @param ctx The security context. + * @param pixelsID The collection of pixels set. + * @param maxLength The maximum length of the thumbnail width or height * depending on the pixel size. - * @param reset Pass true to reset the thumbnail store, - * false otherwise. + * @param reset Pass true to reset the thumbnail store, + * false otherwise. * @return See above. * @throws RenderingServiceException If an error occurred while trying to * retrieve data from the service. * @throws DSOutOfServiceException If the connection is broken. */ - synchronized Map getThumbnailSet(List pixelsID, int maxLength, boolean - reset) + synchronized Map getThumbnailSet(SecurityContext ctx, List pixelsID, + int maxLength, boolean reset) throws RenderingServiceException, DSOutOfServiceException { - isSessionAlive(); + isSessionAlive(ctx); + ThumbnailStorePrx service = null; try { - if (reset) thumbRetrieval = MAX_RETRIEVAL; - else thumbRetrieval += pixelsID.size(); - ThumbnailStorePrx service = getThumbService(); - if (service == null) service = getThumbService(); + int n = MAX_RETRIEVAL; + if (!reset) n = pixelsID.size(); + service = getThumbnailService(ctx, n); return service.getThumbnailByLongestSideSet( omero.rtypes.rint(maxLength), pixelsID); - } catch (Throwable t) { - if (thumbnailService != null) { - try { - thumbnailService.close(); - } catch (Exception e) { - //nothing we can do - } - } - thumbnailService = null; + closeService(ctx, service); if (t instanceof ServerError) { throw new DSOutOfServiceException( "Thumbnail service null for pixelsID: "+pixelsID, t); @@ -3251,6 +3221,7 @@ synchronized Map getThumbnailSet(List pixelsID, int maxLength, boolean /** * Creates a new rendering service for the specified pixels set. * + * @param ctx The security context. * @param pixelsID The pixels set ID. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in @@ -3259,17 +3230,18 @@ synchronized Map getThumbnailSet(List pixelsID, int maxLength, boolean * @throws FSAccessException If an error occurred when trying to build a * pyramid or access file not available. */ - synchronized RenderingEnginePrx createRenderingEngine(long pixelsID) + synchronized RenderingEnginePrx createRenderingEngine(SecurityContext ctx, + long pixelsID) throws DSOutOfServiceException, DSAccessException, FSAccessException { - isSessionAlive(); + isSessionAlive(ctx); RenderingEnginePrx service = null; try { - service = getRenderingService(); - if (service == null) service = getRenderingService(); + service = getRenderingService(ctx); service.lookupPixels(pixelsID); needDefault(pixelsID, service); - reServices.put(pixelsID, service); + //TO be reviewed. For server + //reServices.put(pixelsID, service); service.load(); return service; } catch (Throwable t) { @@ -3288,24 +3260,24 @@ synchronized RenderingEnginePrx createRenderingEngine(long pixelsID) /** * Finds the link if any between the specified parent and child. * - * @param type The type of annotation to handle. + * @param ctx The security context. + * @param type The type of annotation to handle. * @param parentID The id of the parent. - * @param childID The id of the child, or -1 if no - * child specified. - * @param userID The id of the user. + * @param childID The id of the child, or -1 if no + * child specified. + * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - IObject findAnnotationLink(Class type, long parentID, long childID, - long userID) + IObject findAnnotationLink(SecurityContext ctx, Class type, long parentID, + long childID, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); String table = getTableForAnnotationLink(type.getName()); if (table == null) return null; String sql = "select link from "+table+" as link where " + @@ -3331,22 +3303,22 @@ IObject findAnnotationLink(Class type, long parentID, long childID, /** * Finds the link if any between the specified parent and child. * - * @param parentType The type of parent to handle. - * @param parentID The id of the parent to handle. - * @param children Collection of the ids. + * @param ctx The security context. + * @param parentType The type of parent to handle. + * @param parentID The id of the parent to handle. + * @param children Collection of the identifierss. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - List findAnnotationLinks(String parentType, long parentID, - List children) + List findAnnotationLinks(SecurityContext ctx, String parentType, + long parentID, List children) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); String table = getTableForAnnotationLink(parentType); if (table == null) return null; StringBuffer sb = new StringBuffer(); @@ -3379,17 +3351,18 @@ List findAnnotationLinks(String parentType, long parentID, /** * Finds the link if any between the specified parent and child. * - * @param parent The parent. - * @param child The child. + * @param ctx The security context. + * @param parent The parent. + * @param child The child. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - IObject findLink(IObject parent, IObject child) + IObject findLink(SecurityContext ctx, IObject parent, IObject child) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { String table = getTableForLink(parent.getClass()); if (table == null) return null; @@ -3400,8 +3373,7 @@ IObject findLink(IObject parent, IObject child) param.map = new HashMap(); param.map.put("parentID", parent.getId()); param.map.put("childID", child.getId()); - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); return service.findByQuery(sql, param); } catch (Throwable t) { handleException(t, "Cannot retrieve the requested link for "+ @@ -3414,17 +3386,18 @@ IObject findLink(IObject parent, IObject child) /** * Finds the links if any between the specified parent and children. * - * @param parent The parent. - * @param children Collection of children as children ids. + * @param ctx The security context. + * @param parent The parent. + * @param children Collection of children as identifiers. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - List findLinks(IObject parent, List children) + List findLinks(SecurityContext ctx, IObject parent, List children) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { String table = getTableForLink(parent.getClass()); if (table == null) return null; @@ -3439,8 +3412,7 @@ List findLinks(IObject parent, List children) param.addLongs("childIDs", children); } - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); return service.findAllByQuery(sql, param); } catch (Throwable t) { handleException(t, "Cannot retrieve the requested link for "+ @@ -3452,18 +3424,20 @@ List findLinks(IObject parent, List children) /** * Finds the links if any between the specified parent and children. * - * @param parentClass The parent. - * @param children Collection of children as children ids. - * @param userID The id of the user. + * @param ctx The security context. + * @param parentClass The parent. + * @param children Collection of children as identifiers. + * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - List findLinks(Class parentClass, List children, long userID) + List findLinks(SecurityContext ctx, Class parentClass, List children, + long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { String table = getTableForLink(parentClass); if (table == null) return null; @@ -3476,8 +3450,7 @@ List findLinks(Class parentClass, List children, long userID) sql += " and link.details.owner.id = :userID"; param.map.put("userID", omero.rtypes.rlong(userID)); } - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); return service.findAllByQuery(sql, param); } catch (Throwable t) { handleException(t, "Cannot retrieve the requested link for "+ @@ -3489,6 +3462,7 @@ List findLinks(Class parentClass, List children, long userID) /** * Finds all the links. * + * @param ctx The security context. * @param node The type of node to handle. * @param nodeID The id of the node if any. * @param children The collection of annotations' identifiers @@ -3498,11 +3472,11 @@ List findLinks(Class parentClass, List children, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - List findAnnotationLinks(Class node, long nodeID, List children, - long userID) + List findAnnotationLinks(SecurityContext ctx, Class node, long nodeID, + List children, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { String table = getAnnotationTableLink(node); if (table == null) return null; @@ -3523,8 +3497,7 @@ List findAnnotationLinks(Class node, long nodeID, List children, sb.append(" and link.details.owner.id = :userID"); param.map.put("userID", omero.rtypes.rlong(userID)); } - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); return service.findAllByQuery(sb.toString(), param); } catch (Throwable t) { handleException(t, "Cannot retrieve the requested link for "+ @@ -3536,46 +3509,51 @@ List findAnnotationLinks(Class node, long nodeID, List children, /** * Finds the links if any between the specified parent and children. * - * @param parentClass The parent. - * @param childID The id of the child. - * @param userID The id of the user. + * @param ctx The security context. + * @param parentClass The parent. + * @param childID The id of the child. + * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - List findLinks(Class parentClass, long childID, long userID) + List findLinks(SecurityContext ctx, Class parentClass, long childID, + long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); if (FileAnnotation.class.equals(parentClass)) { List results = new ArrayList(); - results.addAll(loadLinks("ProjectAnnotationLink", childID, userID)); - results.addAll(loadLinks("DatasetAnnotationLink", childID, userID)); - results.addAll(loadLinks("ImageAnnotationLink", childID, userID)); + results.addAll(loadLinks(ctx, "ProjectAnnotationLink", childID, + userID)); + results.addAll(loadLinks(ctx, "DatasetAnnotationLink", childID, + userID)); + results.addAll(loadLinks(ctx, "ImageAnnotationLink", childID, + userID)); return results; } - return loadLinks(getTableForLink(parentClass), childID, userID); + return loadLinks(ctx, getTableForLink(parentClass), childID, userID); } /** * Retrieves an updated version of the specified object. * - * @param o The object to retrieve. + * @param ctx The security context. + * @param o The object to retrieve. * @return The last version of the object. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - IObject findIObject(IObject o) + IObject findIObject(SecurityContext ctx, IObject o) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); + if (o == null) return null; try { - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); - return service.find(o.getClass().getName(), - o.getId().getValue()); + IQueryPrx service = getQueryService(ctx); + return service.find(o.getClass().getName(), o.getId().getValue()); } catch (Throwable t) { handleException(t, "Cannot retrieve the requested object with "+ "object ID: "+o.getId()); @@ -3586,6 +3564,7 @@ IObject findIObject(IObject o) /** * Retrieves an updated version of the specified object. * + * @param ctx The security context. * @param dataObjectThe object to retrieve. * @param name The name of the object. * @param @@ -3593,16 +3572,16 @@ IObject findIObject(IObject o) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - IObject findIObjectByName(Class dataObject, String name, long ownerID) + IObject findIObjectByName(SecurityContext ctx, Class dataObject, + String name, long ownerID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { ParametersI param = new ParametersI(); param.map.put("name", rtypes.rstring(name)); param.map.put("ownerID", rtypes.rlong(ownerID)); - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); String table = getTableForClass(dataObject); String sql = "select o from "+table+" as o"; sql += " where o.name = :name"; @@ -3617,20 +3596,20 @@ IObject findIObjectByName(Class dataObject, String name, long ownerID) /** * Retrieves an updated version of the specified object. * - * @param klassName The type of object to retrieve. - * @param id The object's id. + * @param ctx The security context. + * @param klassName The type of object to retrieve. + * @param id The object's id. * @return The last version of the object. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - IObject findIObject(String klassName, long id) + IObject findIObject(SecurityContext ctx, String klassName, long id) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); return service.find(klassName, id); } catch (Throwable t) { handleException(t, "Cannot retrieve the requested object with "+ @@ -3642,23 +3621,24 @@ IObject findIObject(String klassName, long id) /** * Retrieves the groups visible by the current experimenter. * + * @param ctx The security context. * @param loggedInUser The user currently logged in. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - Set getAvailableGroups(ExperimenterData user) + Set getAvailableGroups(SecurityContext ctx, + ExperimenterData user) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); Set pojos = new HashSet(); try { //Need method server side. ParametersI p = new ParametersI(); p.addId(user.getId()); - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); List groups = service.findAllByQuery( "select distinct g from ExperimenterGroup as g " + "join fetch g.groupExperimenterMap as map " @@ -3690,19 +3670,20 @@ Set getAvailableGroups(ExperimenterData user) /** * Retrieves the archived files if any for the specified set of pixels. * - * @param path The location where to save the files. - * @param pixelsID The ID of the pixels set. + * @param ctx The security context. + * @param path The location where to save the files. + * @param pixelsID The ID of the pixels set. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - synchronized Map getArchivedFiles(String path, long pixelsID) + synchronized Map getArchivedFiles( + SecurityContext ctx, String path, long pixelsID) throws DSAccessException, DSOutOfServiceException { - isSessionAlive(); - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + isSessionAlive(ctx); + IQueryPrx service = getQueryService(ctx); List files = null; try { ParametersI param = new ParametersI(); @@ -3728,7 +3709,7 @@ synchronized Map getArchivedFiles(String path, long pixelsID) String fullPath; while (i.hasNext()) { of = (OriginalFile) i.next(); - store = getRawFileService(); + store = getRawFileService(ctx); try { store.setFileId(of.getId().getValue()); } catch (Exception e) { @@ -3754,16 +3735,16 @@ synchronized Map getArchivedFiles(String path, long pixelsID) if (stream != null) stream.close(); if (f != null) f.delete(); notDownloaded.add(of.getName().getValue()); - closeService(store); + closeService(ctx, store); } } catch (IOException e) { if (f != null) f.delete(); notDownloaded.add(of.getName().getValue()); - closeService(store); + closeService(ctx, store); throw new DSAccessException("Cannot create file with path " + fullPath, e); } - closeService(store); + closeService(ctx, store); } result.put(Boolean.valueOf(true), files); result.put(Boolean.valueOf(false), notDownloaded); @@ -3773,28 +3754,30 @@ synchronized Map getArchivedFiles(String path, long pixelsID) /** * Downloads a file previously uploaded to the server. * - * @param file The file to copy the data into. - * @param fileID The id of the file to download. - * @param size The size of the file. + * @param ctx The security context. + * @param file The file to copy the data into. + * @param fileID The id of the file to download. + * @param size The size of the file. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - synchronized File downloadFile(File file, long fileID, long size) + synchronized File downloadFile(SecurityContext ctx, File file, long fileID, + long size) throws DSAccessException, DSOutOfServiceException { if (file == null) return null; - isSessionAlive(); + isSessionAlive(ctx); if (size <= 0) { - OriginalFile of = getOriginalFile(fileID); + OriginalFile of = getOriginalFile(ctx, fileID); if (of != null) size = of.getSize().getValue(); } - RawFileStorePrx store = getRawFileService(); + RawFileStorePrx store = getRawFileService(ctx); try { store.setFileId(fileID); } catch (Throwable e) { - closeService(store); + closeService(ctx, store); handleException(e, "Cannot set the file's id."); } String path = file.getAbsolutePath(); @@ -3818,10 +3801,10 @@ synchronized File downloadFile(File file, long fileID, long size) } } catch (IOException e) { if (file != null) file.delete(); - closeService(store); + closeService(ctx, store); throw new DSAccessException("Cannot create file " +path, e); } - closeService(store); + closeService(ctx, store); return file; } @@ -3829,14 +3812,19 @@ synchronized File downloadFile(File file, long fileID, long size) /** * Closes the specified service. * + * @param ctx The security context * @param svc The service to handle. */ - private void closeService(StatefulServiceInterfacePrx svc) + private void closeService(SecurityContext ctx, + StatefulServiceInterfacePrx svc) { try { - svc.close(); - } catch (Exception e) { //ignore + Connector c = getConnector(ctx); + if (c != null) c.close(svc); + } catch (Exception e) { + // TODO: handle exception } + } /** @@ -3847,48 +3835,30 @@ private void closeService(StatefulServiceInterfacePrx svc) */ private void shutDownServices(boolean rendering) { - if (thumbnailService != null) - closeService(thumbnailService); - if (pixelsStore != null) - closeService(pixelsStore); - if (fileStore != null) - closeService(fileStore); - if (importStore != null) { - importStore.closeServices(); - importStore = null; - } - Collection l = reServices.values(); - if (l != null && rendering) { - Iterator i = l.iterator(); - while (i.hasNext()) { - closeService(i.next()); - } - reServices.clear(); - } - thumbnailService = null; - pixelsStore = null; - fileStore = null; + Iterator i = connectors.iterator(); + while (i.hasNext()) + i.next().shutDownServices(rendering); } /** * Returns the original file corresponding to the passed id. * - * @param id The id identifying the file. + * @param ctx The security context. + * @param id The id identifying the file. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - OriginalFile getOriginalFile(long id) + OriginalFile getOriginalFile(SecurityContext ctx, long id) throws DSAccessException, DSOutOfServiceException { - isSessionAlive(); + isSessionAlive(ctx); OriginalFile of = null; try { ParametersI param = new ParametersI(); param.map.put("id", omero.rtypes.rlong(id)); - IQueryPrx svc = getQueryService(); - if (svc == null) svc = getQueryService(); + IQueryPrx svc = getQueryService(ctx); of = (OriginalFile) svc.findByQuery( "select p from OriginalFile as p " + "where p.id = :id", param); @@ -3902,22 +3872,22 @@ OriginalFile getOriginalFile(long id) * Returns the collection of original files related to the specified * pixels set. * + * @param ctx The security context. * @param pixelsID The ID of the pixels set. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - List getOriginalFiles(long pixelsID) + List getOriginalFiles(SecurityContext ctx, long pixelsID) throws DSAccessException, DSOutOfServiceException { - isSessionAlive(); + isSessionAlive(ctx); List files = null; try { ParametersI param = new ParametersI(); param.map.put("id", omero.rtypes.rlong(pixelsID)); - IQueryPrx svc = getQueryService(); - if (svc == null) svc = getQueryService(); + IQueryPrx svc = getQueryService(ctx); files = svc.findAllByQuery( "select ofile from OriginalFile as ofile left join " + "ofile.pixelsFileMaps as pfm left join pfm.child as " + @@ -3932,29 +3902,29 @@ List getOriginalFiles(long pixelsID) * Uploads the passed file to the server and returns the * original file i.e. the server object. * - * @param file The file to upload. - * @param mimeType The mimeType of the file. + * @param ctx The security context. + * @param file The file to upload. + * @param mimeType The mimeType of the file. * @param originalFileID The id of the file or -1. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - synchronized OriginalFile uploadFile(File file, String mimeType, - long originalFileID) + synchronized OriginalFile uploadFile(SecurityContext ctx, File file, + String mimeType, long originalFileID) throws DSAccessException, DSOutOfServiceException { if (file == null) throw new IllegalArgumentException("No file to upload"); if (mimeType == null || mimeType.length() == 0) mimeType = DEFAULT_MIMETYPE; - isSessionAlive(); + isSessionAlive(ctx); RawFileStorePrx store = null; OriginalFile save = null; boolean fileCreated = false; try { - store = getRawFileService(); - if (store == null) store = getRawFileService(); + store = getRawFileService(ctx); OriginalFile oFile; if (originalFileID <= 0) { oFile = new OriginalFileI(); @@ -3969,13 +3939,13 @@ synchronized OriginalFile uploadFile(File file, String mimeType, oFile.setSha1(omero.rtypes.rstring("pending")); oFile.setMimetype(omero.rtypes.rstring(mimeType)); save = - (OriginalFile) getUpdateService().saveAndReturnObject( + (OriginalFile) getUpdateService(ctx).saveAndReturnObject( oFile); store.setFileId(save.getId().getValue()); fileCreated = true; } else { - oFile = (OriginalFile) findIObject(OriginalFile.class.getName(), - originalFileID); + oFile = (OriginalFile) findIObject(ctx, + OriginalFile.class.getName(), originalFileID); if (oFile == null) { oFile = new OriginalFileI(); String name = file.getName(); @@ -3988,9 +3958,8 @@ synchronized OriginalFile uploadFile(File file, String mimeType, //Need to be modified oFile.setSha1(omero.rtypes.rstring("pending")); oFile.setMimetype(omero.rtypes.rstring(mimeType)); - save = - (OriginalFile) getUpdateService().saveAndReturnObject( - oFile); + save = (OriginalFile) + getUpdateService(ctx).saveAndReturnObject(oFile); store.setFileId(save.getId().getValue()); fileCreated = true; } else { @@ -4003,12 +3972,12 @@ synchronized OriginalFile uploadFile(File file, String mimeType, newFile.setSha1(omero.rtypes.rstring("pending")); oFile.setMimetype(oFile.getMimetype()); save = (OriginalFile) - getUpdateService().saveAndReturnObject(newFile); + getUpdateService(ctx).saveAndReturnObject(newFile); store.setFileId(save.getId().getValue()); } } } catch (Exception e) { - closeService(store); + closeService(ctx, store); handleException(e, "Cannot set the file's id."); } byte[] buf = new byte[INC]; @@ -4026,14 +3995,14 @@ synchronized OriginalFile uploadFile(File file, String mimeType, } stream.close(); save = store.save(); - closeService(store); + closeService(ctx, store); } catch (Exception e) { try { - if (fileCreated) deleteObject(save); + if (fileCreated) deleteObject(ctx, save); if (stream != null) stream.close(); - closeService(store); + closeService(ctx, store); } catch (Exception ex) {} - closeService(store); + closeService(ctx, store); throw new DSAccessException("Cannot upload the file with path " + file.getAbsolutePath(), e); } @@ -4043,19 +4012,20 @@ synchronized OriginalFile uploadFile(File file, String mimeType, /** * Modifies the password of the currently logged in user. * + * @param ctx The security context. * @param password The new password. * @param oldPassword The old password. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - void changePassword(String password, String oldPassword) + void changePassword(SecurityContext ctx, String password, + String oldPassword) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IAdminPrx service = getAdminService(); - if (service == null) service = getAdminService(); + IAdminPrx service = getAdminService(ctx); service.changePasswordWithOldPassword( omero.rtypes.rstring(oldPassword), omero.rtypes.rstring(password)); @@ -4067,20 +4037,21 @@ void changePassword(String password, String oldPassword) /** * Updates the profile of the specified experimenter. * + * @param ctx The security context. * @param exp The experimenter to handle. * @param currentUserID The identifier of the user currently logged in. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - void updateExperimenter(Experimenter exp, long currentUserID) + void updateExperimenter(SecurityContext ctx, Experimenter exp, + long currentUserID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { if (exp == null) return; - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); if (exp.getId().getValue() == currentUserID) svc.updateSelf(exp); else svc.updateExperimenter(exp); @@ -4092,26 +4063,26 @@ void updateExperimenter(Experimenter exp, long currentUserID) /** * Updates the specified group. * + * @param ctx The security context. * @param group The group to update. * @param permissions The new permissions. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - GroupData updateGroup(ExperimenterGroup group, + GroupData updateGroup(SecurityContext ctx, ExperimenterGroup group, Permissions permissions) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); svc.updateGroup(group); if (permissions != null) { - svc.changePermissions(findIObject(group), permissions); + svc.changePermissions(findIObject(ctx, group), permissions); } return (GroupData) PojoMapper.asDataObject( - (ExperimenterGroup) findIObject(group)); + (ExperimenterGroup) findIObject(ctx, group)); } catch (Throwable t) { handleException(t, "Cannot update the group. "); } @@ -4121,6 +4092,7 @@ GroupData updateGroup(ExperimenterGroup group, /** * Adds or removes the passed experimenters from the specified system group. * + * @param ctx The security context. * @param toAdd Pass true to add the experimenters as owners, * false otherwise. * @param experimenters The experimenters to add or remove. @@ -4129,14 +4101,13 @@ GroupData updateGroup(ExperimenterGroup group, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - void modifyExperimentersRoles(boolean toAdd, + void modifyExperimentersRoles(SecurityContext ctx, boolean toAdd, List experimenters, String systemGroup) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); if (toAdd) { Iterator i = experimenters.iterator(); ExperimenterData exp; @@ -4155,13 +4126,12 @@ void modifyExperimentersRoles(boolean toAdd, group = j.next(); if (group.getName().equals(systemGroup)) added = true; - } if (!added) { groups = new ArrayList(); groups.add(gs); svc.addGroups(exp.asExperimenter(), groups); - } + } } } else { Iterator i = experimenters.iterator(); @@ -4195,6 +4165,7 @@ void modifyExperimentersRoles(boolean toAdd, * Adds the passed experimenters as owner of the group if the flag is * true, removes them otherwise. * + * @param ctx The security context. * @param toAdd Pass true to add the experimenters as owners, * false otherwise. * @param group The group to handle. @@ -4203,13 +4174,13 @@ void modifyExperimentersRoles(boolean toAdd, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - void handleGroupOwners(boolean toAdd, ExperimenterGroup group, - List experimenters) + void handleGroupOwners(SecurityContext ctx, boolean toAdd, + ExperimenterGroup group, List experimenters) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IAdminPrx svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); if (toAdd) svc.addGroupOwners(group, experimenters); else svc.removeGroupOwners(group, experimenters); } catch (Throwable t) { @@ -4221,23 +4192,25 @@ void handleGroupOwners(boolean toAdd, ExperimenterGroup group, * Returns the XY-plane identified by the passed z-section, time-point * and wavelength. * - * @param pixelsID The id of pixels containing the requested plane. - * @param z The selected z-section. - * @param t The selected time-point. - * @param c The selected wavelength. + * @param ctx The security context. + * @param pixelsID The id of pixels containing the requested plane. + * @param z The selected z-section. + * @param t The selected time-point. + * @param c The selected wavelength. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - synchronized byte[] getPlane(long pixelsID, int z, int t, int c) + synchronized byte[] getPlane(SecurityContext ctx, long pixelsID, int z, + int t, int c) throws DSOutOfServiceException, DSAccessException, FSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - RawPixelsStorePrx service = getPixelsStore(); - if (service == null) service = getPixelsStore(); + RawPixelsStorePrx service = getPixelsStore(ctx); + if (service == null) service = getPixelsStore(ctx); service.setPixelsId(pixelsID, false); byte[] plane = service.getPlane(z, c, t); service.close(); @@ -4255,6 +4228,7 @@ synchronized byte[] getPlane(long pixelsID, int z, int t, int c) * Returns the free or available space (in Kilobytes) on the file system * including nested sub-directories. * + * @param ctx The security context. * @param Either a group or a user. * @param id The identifier of the user or group or -1 * if not specified. @@ -4264,13 +4238,12 @@ synchronized byte[] getPlane(long pixelsID, int z, int t, int c) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - long getFreeSpace(Class type, long id) + long getFreeSpace(SecurityContext ctx, Class type, long id) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IRepositoryInfoPrx service = getRepositoryService(); - if (service == null) service = getRepositoryService(); + IRepositoryInfoPrx service = getRepositoryService(ctx); return service.getFreeSpaceInKilobytes(); } catch (Throwable e) { handleException(e, "Cannot retrieve the free space"); @@ -4282,6 +4255,7 @@ long getFreeSpace(Class type, long id) * Returns the used space (in Kilobytes) on the file system * including nested sub-directories. * + * @param ctx The security context. * @param Either a group or a user. * @param id The identifier of the user or group or -1 * if not specified. @@ -4291,13 +4265,13 @@ long getFreeSpace(Class type, long id) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - long getUsedSpace(Class type, long id) + long getUsedSpace(SecurityContext ctx, Class type, long id) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { if (id < 0) - return getRepositoryService().getUsedSpaceInKilobytes(); + return getRepositoryService(ctx).getUsedSpaceInKilobytes(); StringBuffer buffer = new StringBuffer(); buffer.append("select f from OriginalFile as f "); buffer.append("left outer join fetch f.details.owner as o "); @@ -4305,7 +4279,7 @@ long getUsedSpace(Class type, long id) ParametersI param = new ParametersI(); param.addLong("userID", id); List result = - getQueryService().findAllByQuery(buffer.toString(), param); + getQueryService(ctx).findAllByQuery(buffer.toString(), param); if (result == null) return -1; Iterator i = result.iterator(); OriginalFile f; @@ -4325,8 +4299,9 @@ long getUsedSpace(Class type, long id) * Retrieves the images specified by a set of parameters * e.g. imported during a given period of time by a given user. * - * @param map The options. - * @param asDataObject Pass true to convert the + * @param ctx The security context. + * @param map The options. + * @param asDataObject Pass true to convert the * IObjects into the corresponding * DataObject. * @return See above. @@ -4335,13 +4310,13 @@ long getUsedSpace(Class type, long id) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Collection getImages(Parameters map, boolean asDataObject) + Collection getImages(SecurityContext ctx, Parameters map, + boolean asDataObject) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IContainerPrx service = getPojosService(); - if (service == null) service = getPojosService(); + IContainerPrx service = getPojosService(ctx); List result = service.getImagesByOptions(map); if (asDataObject) return PojoMapper.asDataObjects(result); return result; @@ -4354,30 +4329,31 @@ Collection getImages(Parameters map, boolean asDataObject) /** * Resets the rendering settings for the images contained in the - * specified datasets or categories - * if the rootType is DatasetData or CategoryData. + * specified node types. * Resets the settings to the passed images if the type is * ImageData. + * Returns if the call was successful, false otherwise. * - * @param rootNodeType The type of nodes. Can either be + * @param ctx The security context. + * @param rootNodeType The type of nodes. Can either be * ImageData, DatasetData or * PlateData. - * @param nodes The nodes to apply settings to. - * @return if the call was successful, false otherwise. + * @param nodes The nodes to apply settings to. + * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Map resetRenderingSettings(Class rootNodeType, List nodes) + Map resetRenderingSettings(SecurityContext ctx, Class rootNodeType, + List nodes) throws DSOutOfServiceException, DSAccessException { List success = new ArrayList(); List failure = new ArrayList(); - isSessionAlive(); + isSessionAlive(ctx); try { - IRenderingSettingsPrx service = getRenderingSettingsService(); - if (service == null) service = getRenderingSettingsService(); + IRenderingSettingsPrx service = getRenderingSettingsService(ctx); String klass = convertPojos(rootNodeType).getName(); if (klass.equals(Image.class.getName())) failure.addAll(nodes); success = service.resetDefaultsInSet(klass, nodes); @@ -4401,26 +4377,27 @@ Map resetRenderingSettings(Class rootNodeType, List nodes) * specified datasets if the rootType is DatasetData. * Resets the settings to the passed images if the type is * ImageData. + * Returns if the call was successful, false otherwise. * - * @param rootNodeType The type of nodes. Can either be + * @param ctx The security context. + * @param rootNodeType The type of nodes. Can either be * ImageData, DatasetData. - * @param nodes The nodes to apply settings to. - * @return if the call was successful, false otherwise. + * @param nodes The nodes to apply settings to. + * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Map setMinMaxSettings(Class rootNodeType, List nodes) + Map setMinMaxSettings(SecurityContext ctx, Class rootNodeType, List nodes) throws DSOutOfServiceException, DSAccessException { List success = new ArrayList(); List failure = new ArrayList(); - isSessionAlive(); + isSessionAlive(ctx); try { - IRenderingSettingsPrx service = getRenderingSettingsService(); - if (service == null) service = getRenderingSettingsService(); + IRenderingSettingsPrx service = getRenderingSettingsService(ctx); String klass = convertPojos(rootNodeType).getName(); if (klass.equals(Image.class.getName())) failure.addAll(nodes); success = service.resetMinMaxInSet(klass, nodes); @@ -4445,25 +4422,28 @@ Map setMinMaxSettings(Class rootNodeType, List nodes) * Resets the settings to the passed images if the type is * ImageData. * - * @param rootNodeType The type of nodes. Can either be + * Returns if the call was successful, false otherwise. + * + * @param ctx The security context. + * @param rootNodeType The type of nodes. Can either be * ImageData, DatasetData. - * @param nodes The nodes to apply settings to. + * @param nodes The nodes to apply settings to. * @return if the call was successful, false otherwise. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Map setOwnerRenderingSettings(Class rootNodeType, List nodes) + Map setOwnerRenderingSettings(SecurityContext ctx, Class rootNodeType, + List nodes) throws DSOutOfServiceException, DSAccessException { List success = new ArrayList(); List failure = new ArrayList(); - isSessionAlive(); + isSessionAlive(ctx); try { - IRenderingSettingsPrx service = getRenderingSettingsService(); - if (service == null) service = getRenderingSettingsService(); + IRenderingSettingsPrx service = getRenderingSettingsService(ctx); String klass = convertPojos(rootNodeType).getName(); if (klass.equals(Image.class.getName())) failure.addAll(nodes); success = service.resetDefaultsByOwnerInSet(klass, nodes); @@ -4489,26 +4469,28 @@ Map setOwnerRenderingSettings(Class rootNodeType, List nodes) * Applies the settings to the passed images if the type is * ImageData. * - * @param pixelsID The id of the pixels set to copy the settings from. - * @param rootNodeType The type of nodes. Can either be - * ImageData, DatasetData or - * CategoryData. - * @param nodes The nodes to apply settings to. + * Returns if the call was successful, false otherwise. + * + * @param ctx The security context. + * @param pixelsID The id of the pixels set to copy the settings from. + * @param rootNodeType The type of nodes. Can either be + * ImageData, DatasetData. + * @param nodes The nodes to apply settings to. * @return if the call was successful, false otherwise. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Map pasteRenderingSettings(long pixelsID, Class rootNodeType, List nodes) + Map pasteRenderingSettings(SecurityContext ctx, long pixelsID, + Class rootNodeType, List nodes) throws DSOutOfServiceException, DSAccessException { List success = new ArrayList(); List failure = new ArrayList(); - isSessionAlive(); + isSessionAlive(ctx); try { - IRenderingSettingsPrx service = getRenderingSettingsService(); - if (service == null) service = getRenderingSettingsService(); + IRenderingSettingsPrx service = getRenderingSettingsService(ctx); Map m = service.applySettingsToSet(pixelsID, convertPojos(rootNodeType).getName(), nodes); @@ -4527,8 +4509,9 @@ Map pasteRenderingSettings(long pixelsID, Class rootNodeType, List nodes) * Retrieves all the rendering settings linked to the specified set * of pixels. * - * @param pixelsID The pixels ID. - * @param userID The id of the user. + * @param ctx The security context. + * @param pixelsID The pixels ID. + * @param userID The id of the user. * @return Map whose key is the experimenter who set the settings, * and the value is the rendering settings itself. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -4536,14 +4519,13 @@ Map pasteRenderingSettings(long pixelsID, Class rootNodeType, List nodes) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Map getRenderingSettings(long pixelsID, long userID) + Map getRenderingSettings(SecurityContext ctx, long pixelsID, long userID) throws DSOutOfServiceException, DSAccessException { Map map = new HashMap(); - isSessionAlive(); + isSessionAlive(ctx); try { - IPixelsPrx service = getPixelsService(); - if (service == null) service = getPixelsService(); + IPixelsPrx service = getPixelsService(ctx); List results = service.retrieveAllRndSettings(pixelsID, userID); if (results == null || results.size() == 0) return map; @@ -4568,6 +4550,7 @@ Map getRenderingSettings(long pixelsID, long userID) * Retrieves all the rendering settings linked to the specified set * of pixels. * + * @param ctx The security context. * @param pixelsID The pixels ID. * @param userID The id of the user. * @param convert Pass true to convert the object, @@ -4579,13 +4562,13 @@ Map getRenderingSettings(long pixelsID, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List getRenderingSettingsFor(long pixelsID, long userID) + List getRenderingSettingsFor(SecurityContext ctx, + long pixelsID, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IPixelsPrx service = getPixelsService(); - if (service == null) service = getPixelsService(); + IPixelsPrx service = getPixelsService(ctx); List results = service.retrieveAllRndSettings(pixelsID, userID); List l = new ArrayList(); if (results == null || results.size() == 0) return l; @@ -4604,6 +4587,7 @@ List getRenderingSettingsFor(long pixelsID, long userID) /** * Retrieves the rendering settings for the specified pixels set. * + * @param ctx The security context. * @param pixelsID The pixels ID. * @param userID The id of the user who set the rendering settings. * @return See above. @@ -4612,13 +4596,13 @@ List getRenderingSettingsFor(long pixelsID, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - RenderingDef getRenderingDef(long pixelsID, long userID) + RenderingDef getRenderingDef(SecurityContext ctx, long pixelsID, + long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IPixelsPrx service = getPixelsService(); - if (service == null) service = getPixelsService(); + IPixelsPrx service = getPixelsService(ctx); return service.retrieveRndSettingsFor(pixelsID, userID); } catch (Exception e) { handleException(e, "Cannot retrieve the rendering settings"); @@ -4629,6 +4613,7 @@ RenderingDef getRenderingDef(long pixelsID, long userID) /** * Retrieves the annotations of the passed type. * + * @param ctx The security context. * @param type The type of annotations to include. * @param toInclude The collection of name space to include. * @param toExclude The collection of name space to exclude. @@ -4639,17 +4624,16 @@ RenderingDef getRenderingDef(long pixelsID, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Set loadSpecificAnnotation(Class type, List toInclude, - List toExclude, Parameters options) + Set loadSpecificAnnotation(SecurityContext ctx, Class type, + List toInclude, List toExclude, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); return PojoMapper.asDataObjects( service.loadSpecifiedAnnotations( - convertPojos(type).getName(), toInclude, + convertPojos(type).getName(), toInclude, toExclude, options)); } catch (Exception e) { handleException(e, "Cannot retrieve the annotations"); @@ -4660,6 +4644,7 @@ Set loadSpecificAnnotation(Class type, List toInclude, /** * Counts the annotations of the passed type. * + * @param ctx The security context. * @param type The type of annotations to include. * @param toInclude The collection of name space to include. * @param toExclude The collection of name space to exclude. @@ -4670,14 +4655,13 @@ Set loadSpecificAnnotation(Class type, List toInclude, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - long countSpecificAnnotation(Class type, List toInclude, - List toExclude, Parameters options) + long countSpecificAnnotation(SecurityContext ctx, Class type, + List toInclude, List toExclude, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); RLong value = service.countSpecifiedAnnotations( convertPojos(type).getName(), toInclude, toExclude, options); @@ -4693,6 +4677,7 @@ long countSpecificAnnotation(Class type, List toInclude, * Returns the number of annotations used by the passed user but not * owned. * + * @param ctx The security context. * @param annotationType The type of annotation. * @param userID The identifier of the user. * @return See above. @@ -4701,14 +4686,14 @@ long countSpecificAnnotation(Class type, List toInclude, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - long countAnnotationsUsedNotOwned(Class annotationType, long userID) + long countAnnotationsUsedNotOwned(SecurityContext ctx, Class annotationType, + long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); long count = 0; try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); RLong value = service.countAnnotationsUsedNotOwned( convertAnnotation(annotationType), userID); if (value != null) @@ -4724,21 +4709,23 @@ long countAnnotationsUsedNotOwned(Class annotationType, long userID) /** * Loads the tag Sets and the orphaned tags, if requested. * - * @param userID + * @param ctx The security context. + * @param annotationType The type of annotation to retrieve. + * @param userID The identifier of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Collection loadAnnotationsUsedNotOwned(Class annotationType, long userID) + Collection loadAnnotationsUsedNotOwned(SecurityContext ctx, + Class annotationType, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); Set result = new HashSet(); try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); List set = service.loadAnnotationsUsedNotOwned( convertAnnotation(annotationType), userID); Iterator i = set.iterator(); @@ -4759,6 +4746,7 @@ Collection loadAnnotationsUsedNotOwned(Class annotationType, long userID) /** * Searches the images acquired or created during a given period of time. * + * @param ctx The security context. * @param context The context of the search. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -4766,10 +4754,10 @@ Collection loadAnnotationsUsedNotOwned(Class annotationType, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Object searchByTime(SearchDataContext context) + Set searchByTime(SecurityContext ctx, SearchDataContext context) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); ParametersI param = new ParametersI(); param.map = new HashMap(); StringBuffer buf = new StringBuffer(); @@ -4833,8 +4821,7 @@ Object searchByTime(SearchDataContext context) } else buf.append("where owner.id in (:ids)"); - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); return PojoMapper.asDataObjects( service.findAllByQuery(buf.toString(), param)); } catch (Throwable e) { @@ -4847,6 +4834,7 @@ Object searchByTime(SearchDataContext context) /** * Searches for data. * + * @param ctx The security context. * @param context The context of search. * @return The found objects. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -4854,7 +4842,7 @@ Object searchByTime(SearchDataContext context) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Object performSearch(SearchDataContext context) + Object performSearch(SecurityContext ctx, SearchDataContext context) throws DSOutOfServiceException, DSAccessException { Map results = new HashMap(); @@ -4862,9 +4850,8 @@ Object performSearch(SearchDataContext context) List scopes = context.getScope(); if (types == null || types.size() == 0) return new HashMap(); //if (scopes == null || scopes.size() == 0) return new HashMap(); - isSessionAlive(); - SearchPrx service = getSearchService(); - if (service == null) service = getSearchService(); + isSessionAlive(ctx); + SearchPrx service = getSearchService(ctx); try { service.setAllowLeadingWildcard(true); service.setCaseSentivice(context.isCaseSensitive()); @@ -5006,6 +4993,7 @@ Object performSearch(SearchDataContext context) /** * Returns the collection of annotations of a given type. * + * @param ctx The security context. * @param annotationType The type of annotation. * @param terms The terms to search for. * @param start The lower bound of the time interval @@ -5019,14 +5007,13 @@ Object performSearch(SearchDataContext context) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List filterBy(Class annotationType, List terms, + List filterBy(SecurityContext ctx, Class annotationType, List terms, Timestamp start, Timestamp end, ExperimenterData exp) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - SearchPrx service = getSearchService(); - if (service == null) service = getSearchService(); + SearchPrx service = getSearchService(ctx); if (start != null && end != null) service.onlyAnnotatedBetween( omero.rtypes.rtime(start.getTime()), @@ -5055,6 +5042,7 @@ List filterBy(Class annotationType, List terms, * Retrieves all containers of a given type. * The containers are not linked to any of their children. * + * @param ctx The security context. * @param type The type of container to retrieve. * @param userID The id of the owner of the container. * @return See above. @@ -5063,13 +5051,12 @@ List filterBy(Class annotationType, List terms, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Set fetchContainers(Class type, long userID) + Set fetchContainers(SecurityContext ctx, Class type, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); Parameters p = new ParametersI(); p.map = new HashMap(); p.map.put("id", omero.rtypes.rlong(userID)); @@ -5084,6 +5071,7 @@ Set fetchContainers(Class type, long userID) /** * + * @param ctx The security context. * @param type * @param annotationIds * @param ownerIds @@ -5093,14 +5081,13 @@ Set fetchContainers(Class type, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Set getAnnotatedObjects(Class type, Set annotationIds, - Set ownerIds) + Set getAnnotatedObjects(SecurityContext ctx, Class type, + Set annotationIds, Set ownerIds) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); ParametersI param = new ParametersI(); param.addLongs("ids", annotationIds); StringBuilder sb = new StringBuilder(); @@ -5129,19 +5116,19 @@ Set getAnnotatedObjects(Class type, Set annotationIds, /** * Returns the number of images related to a given tag. * - * @param rootNodeIDs + * @param ctx The security context. + * @param rootNodeIDs The annotated objects. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Map getDataObjectsTaggedCount(List rootNodeIDs) + Map getDataObjectsTaggedCount(SecurityContext ctx, List rootNodeIDs) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); ParametersI param; StringBuilder sb = new StringBuilder(); @@ -5211,6 +5198,7 @@ Map getDataObjectsTaggedCount(List rootNodeIDs) /** * Removes the description linked to the tags. * + * @param ctx The security context. * @param tagID The id of tag to handle. * @param userID The id of the user who annotated the tag. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -5218,14 +5206,13 @@ Map getDataObjectsTaggedCount(List rootNodeIDs) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - void removeTagDescription(long tagID, long userID) + void removeTagDescription(SecurityContext ctx, long tagID, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { String type = "ome.model.annotations.TextAnnotation"; - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); ParametersI param = new ParametersI(); param.addLong("uid", userID); param.addLong("id", tagID); @@ -5246,8 +5233,8 @@ void removeTagDescription(long tagID, long userID) child = link.getChild(); if (!((child instanceof TagAnnotation) || (child instanceof TermAnnotation))) { - deleteObject(link); - deleteObject(child); + deleteObject(ctx, link); + deleteObject(ctx, child); } } } @@ -5259,25 +5246,17 @@ void removeTagDescription(long tagID, long userID) /** Keeps the services alive. */ void keepSessionAlive() { + Iterator i = connectors.iterator(); + Connector c; + while (i.hasNext()) { + i.next().keepSessionAlive(); + } + /* Collection all = new HashSet(); + if (services.size() > 0) all.addAll(services); if (reServices.size() > 0) all.addAll(reServices.values()); - /* - int n = services.size()+reServices.size(); - ServiceInterfacePrx[] entries = new ServiceInterfacePrx[n]; - Iterator i = services.iterator(); - int index = 0; - while (i.hasNext()) { - entries[index] = i.next(); - index++; - } - Iterator j = reServices.keySet().iterator(); - while (j.hasNext()) { - entries[index] = reServices.get(j.next()); - index++; - } - */ if (all.size() == 0) return; ServiceInterfacePrx[] entries = (ServiceInterfacePrx[]) all.toArray(new ServiceInterfacePrx[all.size()]); @@ -5292,12 +5271,14 @@ void keepSessionAlive() } catch (Exception e) { // TODO: handle exception } + */ } /** * Projects the specified set of pixels according to the projection's * parameters. Adds the created image to the passed dataset. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param startT The time-point to start projecting from. * @param endT The time-point to end projecting. @@ -5316,20 +5297,19 @@ void keepSessionAlive() * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - ImageData projectImage(long pixelsID, int startT, int endT, int startZ, - int endZ, int stepping, ProjectionType algorithm, - List channels, String name, String pixType) + ImageData projectImage(SecurityContext ctx, long pixelsID, int startT, + int endT, int startZ, int endZ, int stepping, + ProjectionType algorithm, List channels, String name, + String pixType) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IProjectionPrx service = getProjectionService(); - if (service == null) service = getProjectionService(); + IProjectionPrx service = getProjectionService(ctx); PixelsType type = null; if (pixType != null) { - IQueryPrx svc = getQueryService(); - List l = svc.findAll(PixelsType.class.getName(), - null); + IQueryPrx svc = getQueryService(ctx); + List l = svc.findAll(PixelsType.class.getName(), null); Iterator i = l.iterator(); PixelsType pt; String value; @@ -5342,10 +5322,10 @@ ImageData projectImage(long pixelsID, int startT, int endT, int startZ, } } } - long imageID = service.projectPixels(pixelsID, type, algorithm, + long imageID = service.projectPixels(pixelsID, type, algorithm, startT, endT, channels, stepping, startZ, endZ, name); - return getImage(imageID, new Parameters()); + return getImage(ctx, imageID, new Parameters()); } catch (Exception e) { handleException(e, "Cannot project the image."); } @@ -5355,6 +5335,7 @@ ImageData projectImage(long pixelsID, int startT, int endT, int startZ, /** * Returns the image and loaded pixels. * + * @param ctx The security context. * @param imageID The id of the image to load. * @param options The options. * @return See above. @@ -5363,14 +5344,14 @@ ImageData projectImage(long pixelsID, int startT, int endT, int startZ, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - ImageData getImage(long imageID, Parameters options) + ImageData getImage(SecurityContext ctx, long imageID, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { List ids = new ArrayList(1); ids.add(imageID); - Set result = getContainerImages(ImageData.class, ids, options); + Set result = getContainerImages(ctx, ImageData.class, ids, options); if (result != null && result.size() == 1) { Iterator i = result.iterator(); while (i.hasNext()) @@ -5386,6 +5367,7 @@ ImageData getImage(long imageID, Parameters options) /** * Creates default rendering setting for the passed pixels set. * + * @param ctx The security context. * @param pixelsID The id of the pixels set to handle. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -5393,28 +5375,27 @@ ImageData getImage(long imageID, Parameters options) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - RenderingDef createRenderingDef(long pixelsID) + RenderingDef createRenderingDef(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException { //TODO: add method to server so that we don't have to make 2 calls. - isSessionAlive(); + isSessionAlive(ctx); try { - IPixelsPrx svc = getPixelsService(); - if (svc == null) svc = getPixelsService(); + IPixelsPrx svc = getPixelsService(ctx); Pixels pixels = svc.retrievePixDescription(pixelsID); if (pixels == null) return null; - IRenderingSettingsPrx service = getRenderingSettingsService(); + IRenderingSettingsPrx service = getRenderingSettingsService(ctx); return service.createNewRenderingDef(pixels); } catch (Exception e) { handleException(e, "Cannot create settings for: "+pixelsID); } - return null; } /** * Returns the plate where the specified image has been imported. * + * @param ctx The security context. * @param imageID The identifier of the image. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -5422,15 +5403,14 @@ RenderingDef createRenderingDef(long pixelsID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - PlateData getImportedPlate(long imageID) + PlateData getImportedPlate(SecurityContext ctx, long imageID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { List results = null; Iterator i; - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); StringBuilder sb = new StringBuilder(); ParametersI param = new ParametersI(); param.addLong("imageID", imageID); @@ -5456,17 +5436,17 @@ PlateData getImportedPlate(long imageID) } //TMP: - Set loadPlateWells(long plateID, long acquisitionID, long userID) + Set loadPlateWells(SecurityContext ctx, long plateID, long acquisitionID, + long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { List results = null; Set wells = new HashSet(); Iterator i; - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); //if no acquisition set. First try to see if we have a id. ParametersI param = new ParametersI(); param.addLong("plateID", plateID); @@ -5509,7 +5489,7 @@ Set loadPlateWells(long plateID, long acquisitionID, long userID) /** * Loads the acquisition object related to the passed image. - * + * @param ctx The security context. * @param imageID The id of image object to handle. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -5517,16 +5497,15 @@ Set loadPlateWells(long plateID, long acquisitionID, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Object loadImageAcquisitionData(long imageID) + Object loadImageAcquisitionData(SecurityContext ctx, long imageID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); ParametersI po = new ParametersI(); po.acquisitionData(); List ids = new ArrayList(1); ids.add(imageID); - IContainerPrx service = getPojosService(); - if (service == null) service = getPojosService(); + IContainerPrx service = getPojosService(ctx); try { List images = service.getImages(Image.class.getName(), ids, po); if (images != null && images.size() == 1) @@ -5540,6 +5519,7 @@ Object loadImageAcquisitionData(long imageID) /** * Loads the acquisition metadata related to the specified channel. * + * @param ctx The security context. * @param channelID The id of the channel. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -5547,14 +5527,13 @@ Object loadImageAcquisitionData(long imageID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Object loadChannelAcquisitionData(long channelID) + Object loadChannelAcquisitionData(SecurityContext ctx, long channelID) throws DSOutOfServiceException, DSAccessException { //stage Label - isSessionAlive(); + isSessionAlive(ctx); try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); List ids = new ArrayList(1); ids.add(channelID); List l = service.loadChannelAcquisitionData(ids); @@ -5576,7 +5555,7 @@ Object loadChannelAcquisitionData(long channelID) sb.append("where l.id = :id"); ParametersI param = new ParametersI(); param.addId(src.getId()); - Laser laser = (Laser) getQueryService().findByQuery( + Laser laser = (Laser) getQueryService(ctx).findByQuery( sb.toString(), param); if (laser != null) data.setLightSource(new LightSourceData(laser)); @@ -5594,6 +5573,7 @@ Object loadChannelAcquisitionData(long channelID) * Returns the enumeration corresponding to the passed string or * null if none found. * + * @param ctx The security context. * @param klass The class the enumeration is for. * @param value The value of the enumeration. * @return See above. @@ -5602,13 +5582,12 @@ Object loadChannelAcquisitionData(long channelID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - IObject getEnumeration(Class klass, String value) + IObject getEnumeration(SecurityContext ctx, Class klass, String value) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + IQueryPrx service = getQueryService(ctx); return service.findByString(klass.getName(), "value", value); } catch (Exception e) { handleException(e, "Cannot find the enumeration's value."); @@ -5619,7 +5598,8 @@ IObject getEnumeration(Class klass, String value) /** * Returns the enumerations corresponding to the passed type or * null if none found. - * + * + * @param ctx The security context. * @param klassName The name of the class the enumeration is for. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -5627,17 +5607,16 @@ IObject getEnumeration(Class klass, String value) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List getEnumerations(String klassName) + List getEnumerations(SecurityContext ctx, + String klassName) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List r; try { r = enumerations.get(klassName); if (r != null) return r; - IPixelsPrx service = getPixelsService(); - if (service == null) - service = getPixelsService(); + IPixelsPrx service = getPixelsService(ctx); List l = service.getAllEnumerations(klassName); r = new ArrayList(); if (l == null) return r; @@ -5656,6 +5635,7 @@ List getEnumerations(String klassName) /** * Loads the tags. * + * @param ctx The security context. * @param id The id of the tags. * @param options * @return See above. @@ -5664,13 +5644,12 @@ List getEnumerations(String klassName) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Collection loadTags(Long id, Parameters options) + Collection loadTags(SecurityContext ctx, Long id, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); List ids = new ArrayList(1); ids.add(id); Map m = service.loadTagContent(ids, options); @@ -5686,6 +5665,7 @@ Collection loadTags(Long id, Parameters options) /** * Loads the tag Sets and the orphaned tags, if requested. * + * @param ctx The security context. * @param options * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -5693,13 +5673,12 @@ Collection loadTags(Long id, Parameters options) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Collection loadTagSets(Parameters options) + Collection loadTagSets(SecurityContext ctx, Parameters options) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); List list = service.loadTagSets(options); return PojoMapper.asDataObjects(list); } catch (Exception e) { @@ -5712,22 +5691,23 @@ Collection loadTagSets(Parameters options) * Returns the collection of plane info object related to the specified * pixels set. * - * @param pixelsID The id of the pixels set. - * @param z The selected z-section or -1. - * @param t The selected time-point or -1. - * @param channel The selected time-point or -1. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param z The selected z-section or -1. + * @param t The selected time-point or -1. + * @param channel The selected time-point or -1. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List loadPlaneInfo(long pixelsID, int z, int t, int channel) + List loadPlaneInfo(SecurityContext ctx, long pixelsID, int z, + int t, int channel) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - IQueryPrx service = getQueryService(); - if (service == null) service = getQueryService(); + isSessionAlive(ctx); + IQueryPrx service = getQueryService(ctx); StringBuilder sb; ParametersI param; sb = new StringBuilder(); @@ -5758,123 +5738,40 @@ List loadPlaneInfo(long pixelsID, int z, int t, int channel) /** * Fills the enumerations. - * + * + * @param ctx The security context. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - void fillEnumerations() + void fillEnumerations(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - getEnumerations(OmeroMetadataService.IMMERSION); - getEnumerations(OmeroMetadataService.CORRECTION); - getEnumerations(OmeroMetadataService.MEDIUM); - getEnumerations(OmeroMetadataService.FORMAT); - getEnumerations(OmeroMetadataService.DETECTOR_TYPE); - getEnumerations(OmeroMetadataService.BINNING); - getEnumerations(OmeroMetadataService.CONTRAST_METHOD); - getEnumerations(OmeroMetadataService.ILLUMINATION_TYPE); - getEnumerations(OmeroMetadataService.PHOTOMETRIC_INTERPRETATION); - getEnumerations(OmeroMetadataService.ACQUISITION_MODE); - getEnumerations(OmeroMetadataService.LASER_MEDIUM); - getEnumerations(OmeroMetadataService.LASER_TYPE); - getEnumerations(OmeroMetadataService.LASER_PULSE); - getEnumerations(OmeroMetadataService.ARC_TYPE); - getEnumerations(OmeroMetadataService.FILAMENT_TYPE); - getEnumerations(OmeroMetadataService.FILTER_TYPE); - getEnumerations(OmeroMetadataService.MICROSCOPE_TYPE); + isSessionAlive(ctx); + getEnumerations(ctx, OmeroMetadataService.IMMERSION); + getEnumerations(ctx, OmeroMetadataService.CORRECTION); + getEnumerations(ctx, OmeroMetadataService.MEDIUM); + getEnumerations(ctx, OmeroMetadataService.FORMAT); + getEnumerations(ctx, OmeroMetadataService.DETECTOR_TYPE); + getEnumerations(ctx, OmeroMetadataService.BINNING); + getEnumerations(ctx, OmeroMetadataService.CONTRAST_METHOD); + getEnumerations(ctx, OmeroMetadataService.ILLUMINATION_TYPE); + getEnumerations(ctx, OmeroMetadataService.PHOTOMETRIC_INTERPRETATION); + getEnumerations(ctx, OmeroMetadataService.ACQUISITION_MODE); + getEnumerations(ctx, OmeroMetadataService.LASER_MEDIUM); + getEnumerations(ctx, OmeroMetadataService.LASER_TYPE); + getEnumerations(ctx, OmeroMetadataService.LASER_PULSE); + getEnumerations(ctx, OmeroMetadataService.ARC_TYPE); + getEnumerations(ctx, OmeroMetadataService.FILAMENT_TYPE); + getEnumerations(ctx, OmeroMetadataService.FILTER_TYPE); + getEnumerations(ctx, OmeroMetadataService.MICROSCOPE_TYPE); } - /** - * Deletes the passed object using the {@link IDeletePrx} service. - * Returns an empty list of nothing prevent the delete to happen, - * otherwise returns a list of objects preventing the delete to happen. - * - * @param objectType The type of object to delete. - * @param objectID The id of the object to delete. - * @return See above. - * @throws DSOutOfServiceException If the connection is broken, or logged - * in. - * @throws DSAccessException If an error occurred while trying to - * retrieve data from OMEDS service. - */ - List removeObject(Class objectType, Long objectID) - throws DSOutOfServiceException, DSAccessException - { - isSessionAlive(); - try { - IDeletePrx service = getDeleteService(); - if (service == null) service = getDeleteService(); - if (ImageData.class.equals(objectType)) { - List r = service.checkImageDelete(objectID, false); - if (r == null || r.size() == 0) { - service.deleteImage(objectID, true); - return r; - } - return r; - } - } catch (Exception e) { - handleException(e, "Cannot delete: "+objectType+" "+objectID); - } - - return new ArrayList(); - } - - /** - * Deletes the specified image. - * - * @param object The image to delete. - * @return See above. - * @throws DSOutOfServiceException If the connection is broken, or logged - * in. - * @throws DSAccessException If an error occurred while trying to - * retrieve data from OMEDS service. - */ - Object deleteImage(Image object) - throws DSOutOfServiceException, DSAccessException - { - isSessionAlive(); - try { - IDeletePrx service = getDeleteService(); - if (service == null) service = getDeleteService(); - service.deleteImage(object.getId().getValue(), true); - - } catch (Exception e) { - handleException(e, "Cannot delete the image: "+object.getId()); - } - - return new ArrayList(); - } - - /** - * Returns the list of object than can prevent the delete. - * - * @param object The object to handle. - * @return See above. - * @throws DSOutOfServiceException If the connection is broken, or logged - * in. - * @throws DSAccessException If an error occurred while trying to - * retrieve data from OMEDS service. - */ - List checkImage(Image object) - throws DSOutOfServiceException, DSAccessException - { - isSessionAlive(); - try { - IDeletePrx service = getDeleteService(); - if (service == null) service = getDeleteService(); - return service.checkImageDelete(object.getId().getValue(), true); - } catch (Exception e) { - handleException(e, "Cannot delete the image: "+object.getId()); - } - return new ArrayList(); - } - /** * Creates a movie. Returns the id of the annotation hosting the movie. * + * @param ctx The security context. * @param imageID The id of the image. * @param pixelsID The id of the pixels. * @param userID The id of the user. @@ -5887,11 +5784,11 @@ List checkImage(Image object) * retrieve data from OMEDS service. * @throws ProcessException If an error occurred while running the script. */ - ScriptCallback saveAs(long userID, SaveAsParam param) + ScriptCallback saveAs(SecurityContext ctx, long userID, SaveAsParam param) throws ProcessException, DSOutOfServiceException, DSAccessException { - isSessionAlive(); - long id = getScriptID(SaveAsParam.SAVE_AS_SCRIPT, + isSessionAlive(ctx); + long id = getScriptID(ctx, SaveAsParam.SAVE_AS_SCRIPT, "Cannot start "+SaveAsParam.SAVE_AS_SCRIPT); if (id <= 0) return null; List objects = param.getObjects(); @@ -5910,12 +5807,13 @@ ScriptCallback saveAs(long userID, SaveAsParam param) map.put("IDs", omero.rtypes.rlist(ids)); map.put("Data_Type", omero.rtypes.rstring(type)); map.put("Format", omero.rtypes.rstring(param.getIndexAsString())); - return runScript(id, map); + return runScript(ctx, id, map); } /** * Creates a movie. Returns the id of the annotation hosting the movie. * + * @param ctx The security context. * @param imageID The id of the image. * @param pixelsID The id of the pixels. * @param userID The id of the user. @@ -5928,12 +5826,13 @@ ScriptCallback saveAs(long userID, SaveAsParam param) * retrieve data from OMEDS service. * @throws ProcessException If an error occurred while running the script. */ - ScriptCallback createMovie(long imageID, long pixelsID, long userID, - List channels, MovieExportParam param) + ScriptCallback createMovie(SecurityContext ctx, long imageID, long pixelsID, + long userID, List channels, MovieExportParam param) throws ProcessException, DSOutOfServiceException, DSAccessException { - isSessionAlive(); - long id = getScriptID(param.getScriptName(), + //TODO remove that code + isSessionAlive(ctx); + long id = getScriptID(ctx, param.getScriptName(), "Cannot start "+param.getScriptName()); if (id <= 0) return null; List set = new ArrayList(channels.size()); @@ -5945,14 +5844,14 @@ ScriptCallback createMovie(long imageID, long pixelsID, long userID, int startZ = param.getStartZ(); int endZ = param.getEndZ(); if (!param.isZSectionSet()) { - def = getRenderingDef(pixelsID, userID); + def = getRenderingDef(ctx, pixelsID, userID); startZ = def.getDefaultZ().getValue(); endZ = def.getDefaultZ().getValue(); } int startT = param.getStartT(); int endT = param.getEndT(); if (!param.isTimeIntervalSet()) { - if (def == null) def = getRenderingDef(pixelsID, userID); + if (def == null) def = getRenderingDef(ctx, pixelsID, userID); startT = def.getDefaultT().getValue(); endT = def.getDefaultT().getValue(); } @@ -5976,12 +5875,13 @@ ScriptCallback createMovie(long imageID, long pixelsID, long userID, if (param.getColor() != null) map.put("Overlay_Colour", omero.rtypes.rstring( param.getColor())); - return runScript(id, map); + return runScript(ctx, id, map); } /** * Returns all the scripts that the user can run. * + * @param ctx The security context. * @param experimenter The experimenter or null. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -5989,14 +5889,13 @@ ScriptCallback createMovie(long imageID, long pixelsID, long userID, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List loadRunnableScripts() + List loadRunnableScripts(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List scripts = new ArrayList(); try { - IScriptPrx svc = getScriptService(); - if (svc == null) svc = getScriptService(); + IScriptPrx svc = getScriptService(ctx); List storedScripts = svc.getScripts(); if (storedScripts == null || storedScripts.size() == 0) @@ -6041,20 +5940,20 @@ List loadRunnableScripts() /** * Returns all the official scripts with a UI. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List loadRunnableScriptsWithUI() + List loadRunnableScriptsWithUI(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List scripts = new ArrayList(); try { - IScriptPrx svc = getScriptService(); - if (svc == null) svc = getScriptService(); + IScriptPrx svc = getScriptService(ctx); List storedScripts = svc.getScripts(); if (storedScripts == null || storedScripts.size() == 0) @@ -6087,23 +5986,22 @@ List loadRunnableScriptsWithUI() * Loads and returns the script w/ parameters corresponding to the passed * identifier. * + * @param ctx The security context. * @param scriptID The id of the script. * @return See above. * @throws ProcessException If the script could not be loaded. */ - ScriptObject loadScript(long scriptID) + ScriptObject loadScript(SecurityContext ctx, long scriptID) throws ProcessException { - isSessionAlive(); + isSessionAlive(ctx); ScriptObject script = null; try { - IScriptPrx svc = getScriptService(); - if (svc == null) svc = getScriptService(); + IScriptPrx svc = getScriptService(ctx); script = new ScriptObject(scriptID, "", ""); script.setJobParams(svc.getParams(scriptID)); } catch (Exception e) { - throw new ProcessException("Cannot load the script: "+scriptID, - e); + throw new ProcessException("Cannot load the script: "+scriptID, e); } return script; } @@ -6111,19 +6009,19 @@ ScriptObject loadScript(long scriptID) /** * Returns all the scripts currently stored into the system. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Map getScriptsAsString() + Map getScriptsAsString(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IScriptPrx svc = getScriptService(); - if (svc == null) svc = getScriptService(); + IScriptPrx svc = getScriptService(ctx); List scripts = svc.getScripts(); Map m = new HashMap(); if (scripts != null) { @@ -6134,10 +6032,8 @@ Map getScriptsAsString() while (i.hasNext()) { of = i.next(); v = of.getName(); - if (v != null) - name = v.getValue(); - if (name != null) - m.put(of.getId().getValue(), name); + if (v != null) name = v.getValue(); + if (name != null) m.put(of.getId().getValue(), name); } } return m; @@ -6146,24 +6042,23 @@ Map getScriptsAsString() } return new HashMap(); } - /** * Returns all the scripts currently stored into the system. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List getScripts() + List getScripts(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IScriptPrx svc = getScriptService(); - if (svc == null) svc = getScriptService(); + IScriptPrx svc = getScriptService(ctx); return svc.getScripts(); } catch (Exception e) { handleException(e, "Cannot load the scripts. "); @@ -6171,56 +6066,17 @@ List getScripts() return new ArrayList(); } - /** - * Returns the RType corresponding to the passed value. - * - * @param value The value to convert. - * @return See above. - */ - private RType convertValue(Object value) - { - Iterator i; - if (value instanceof String) - return omero.rtypes.rstring((String) value); - else if (value instanceof Boolean) - return omero.rtypes.rbool((Boolean) value); - else if (value instanceof Long) - return omero.rtypes.rlong((Long) value); - else if (value instanceof Integer) - return omero.rtypes.rint((Integer) value); - else if (value instanceof Float) - return omero.rtypes.rfloat((Float) value); - else if (value instanceof List) { - List l = (List) value; - i = l.iterator(); - List list = new ArrayList(l.size()); - while (i.hasNext()) { - list.add(convertValue(i.next())); - } - return omero.rtypes.rlist(list); - } else if (value instanceof Map) { - Map map = (Map) value; - Map m = new HashMap(); - Entry entry; - i = map.entrySet().iterator(); - while (i.hasNext()) { - entry = (Entry) i.next(); - m.put((String) entry.getKey(), convertValue(entry.getValue())); - } - return omero.rtypes.rmap(m); - } - return null; - } /** * Creates a split view figure. * Returns the id of the annotation hosting the figure. * - * @param objectIDs The id of the objects composing the figure. - * @param type The type of objects. - * @param param The parameters to use. - * @param userID The id of the user. + * @param ctx The security context. + * @param objectIDs The id of the objects composing the figure. + * @param type The type of objects. + * @param param The parameters to use. + * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. @@ -6228,12 +6084,12 @@ else if (value instanceof List) { * retrieve data from OMEDS service. * @throws ProcessException If an error occurred while running the script. */ - ScriptCallback createFigure(List objectIDs, Class type, - FigureParam param, long userID) + ScriptCallback createFigure(SecurityContext ctx, List objectIDs, + Class type, FigureParam param, long userID) throws ProcessException, DSOutOfServiceException, DSAccessException { - isSessionAlive(); - long id = getScriptID(param.getScriptName(), + isSessionAlive(ctx); + long id = getScriptID(ctx, param.getScriptName(), "Cannot start "+param.getScriptName()); if (id <= 0) return null; int scriptIndex = param.getIndex(); @@ -6276,7 +6132,7 @@ ScriptCallback createFigure(List objectIDs, Class type, omero.rtypes.rstring(param.getFormatAsString())); map.put("Figure_Name", omero.rtypes.rstring(param.getName())); - return runScript(id, map); + return runScript(ctx, id, map); } //merge channels Iterator j; @@ -6353,12 +6209,13 @@ ScriptCallback createFigure(List objectIDs, Class type, map.put("ROI_Zoom", omero.rtypes.rfloat((float) param.getMagnificationFactor())); } - return runScript(id, map); + return runScript(ctx, id, map); } /** * Imports the specified file. Returns the image. * + * @param ctx The security context. * @param object Information about the file to import. * @param container The folder to import the image. * @param name The name to give to the imported image. @@ -6369,14 +6226,15 @@ ScriptCallback createFigure(List objectIDs, Class type, * @return See above. * @throws ImportException If an error occurred while importing. */ - Object importImage(ImportableObject object, IObject container, - File file, StatusLabel status, boolean archived, boolean close) + Object importImage(SecurityContext ctx, ImportableObject object, + IObject container, File file, StatusLabel status, boolean archived, + boolean close) throws ImportException { - isSessionAlive(); + isSessionAlive(ctx); OMEROMetadataStoreClient omsc = null; try { - omsc = getImportStore(); + omsc = getImportStore(ctx); ImportLibrary library = new ImportLibrary(omsc, new OMEROWrapper(new ImportConfig())); library.addObserver(status); @@ -6405,19 +6263,20 @@ Object importImage(ImportableObject object, IObject container, //return new ThumbnailData(getImage(id, params), true); //} if (ImportableObject.isHCSFile(file)) { - PlateData plate = getImportedPlate(id); + PlateData plate = getImportedPlate(ctx, id); if (plate != null) return plate; - return getImage(id, params); + return getImage(ctx, id, params); } if (n == 1) { - return getImage(id, params); + return getImage(ctx, id, params); } else if (n == 2) { ids = new ArrayList(); ids.add(id); p = pixels.get(1); id = p.getImage().getId().getValue(); ids.add(id); - return getContainerImages(ImageData.class, ids, params); + return getContainerImages(ctx, ImageData.class, ids, + params); } else if (n >= 3) { j = pixels.iterator(); int index = 0; @@ -6427,18 +6286,19 @@ Object importImage(ImportableObject object, IObject container, id = p.getImage().getId().getValue(); ids.add(id); index++; - if (index == 3) break; + if (index == 3) + break; } - return getContainerImages(ImageData.class, ids, params); + return getContainerImages(ctx, ImageData.class, ids, + params); } } } catch (Throwable e) { - closeImport(); + closeImport(ctx); throw new ImportException(e); } finally { - if (omsc != null && close) { - closeImport(); - } + if (omsc != null && close) + closeImport(ctx); } return null; } @@ -6446,20 +6306,21 @@ Object importImage(ImportableObject object, IObject container, /** * Returns the import candidates. * + * @param ctx The security context. * @param object Host information about the file to import. - * @param file The file to import. - * @param archived Pass true to archived the files, - * false otherwise. - * @param depth The depth used to set the name. This will be taken into - * account if the file is a directory. + * @param file The file to import. + * @param archived Pass true to archived the files, + * false otherwise. + * @param depth The depth used to set the name. This will be taken into + * account if the file is a directory. * @return See above. * @throws ImportException If an error occurred while importing. */ - ImportCandidates getImportCandidates(ImportableObject object, File file, - StatusLabel status) + ImportCandidates getImportCandidates(SecurityContext ctx, + ImportableObject object, File file, StatusLabel status) throws ImportException { - isSessionAlive(); + isSessionAlive(ctx); try { ImportConfig config = new ImportConfig(); OMEROWrapper reader = new OMEROWrapper(config); @@ -6477,11 +6338,20 @@ ImportCandidates getImportCandidates(ImportableObject object, File file, /** * Removes the rendering service corresponding to the pixels set ID. * + * @param ctx The security context. * @param pixelsID The pixels set Id to handle. */ - void removeREService(long pixelsID) + void removeREService(SecurityContext ctx, long pixelsID) { - reServices.remove(pixelsID); + isSessionAlive(ctx); + Iterator i = connectors.iterator(); + Connector c; + while (i.hasNext()) { + c = i.next(); + if (c.isSame(ctx)) { + //c.shutDownRendering(pixelsID); + } + } } /** @@ -6509,6 +6379,7 @@ DataObject loadFolder(String absolutePath) /** * Loads the instrument and its components. * + * @param ctx The security context. * @param id The id of the instrument. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -6516,13 +6387,12 @@ DataObject loadFolder(String absolutePath) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Object loadInstrument(long id) + Object loadInstrument(SecurityContext ctx, long id) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IMetadataPrx service = getMetadataService(); - if (service == null) service = getMetadataService(); + IMetadataPrx service = getMetadataService(ctx); Instrument instrument = service.loadInstrument(id); if (instrument == null) return null; return new InstrumentData(instrument); @@ -6532,23 +6402,24 @@ Object loadInstrument(long id) } return null; } - - + /** * Loads the table associated to a given node. * + * @param ctx The security context. * @param parameters The parameters used to retrieve the table. - * @param userID The user's identifier. + * @param userID The user's identifier. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List loadTabularData(TableParameters parameters, long userID) + List loadTabularData(SecurityContext ctx, + TableParameters parameters, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); TablePrx tablePrx = null; long id = -1; List results = new ArrayList(); @@ -6560,8 +6431,8 @@ List loadTabularData(TableParameters parameters, long userID) //TMP solution List objects = new ArrayList(1); objects.add(parameters.getNodeID()); - Map map = loadAnnotations(parameters.getNodeType(), objects, - null, null, new Parameters()); + Map map = loadAnnotations(ctx, parameters.getNodeType(), + objects, null, null, new Parameters()); Collection list = (Collection) map.get(parameters.getNodeID()); Iterator j = list.iterator(); FileAnnotationData fa; @@ -6581,7 +6452,7 @@ List loadTabularData(TableParameters parameters, long userID) Iterator i = ids.iterator(); while (i.hasNext()) { id = i.next(); - tablePrx = getSharedResources().openTable( + tablePrx = getSharedResources(ctx).openTable( new OriginalFileI(id, false)); if (tablePrx != null) { rows = new long[(int) tablePrx.getNumberOfRows()]; @@ -6602,6 +6473,7 @@ List loadTabularData(TableParameters parameters, long userID) /** * Loads the ROI related to the specified image. * + * @param ctx The security context. * @param imageID The image's ID. * @param userID The user's ID. * @return See above. @@ -6610,14 +6482,14 @@ List loadTabularData(TableParameters parameters, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List loadROI(long imageID, List measurements, long userID) + List loadROI(SecurityContext ctx, long imageID, + List measurements, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List results = new ArrayList(); try { - IRoiPrx svc = getROIService(); - if (svc == null) svc = getROIService(); + IRoiPrx svc = getROIService(ctx); RoiOptions options = new RoiOptions(); options.userId = omero.rtypes.rlong(userID); RoiResult r; @@ -6655,6 +6527,7 @@ List loadROI(long imageID, List measurements, long userID) /** * Save the ROI for the image to the server. * + * @param ctx The security context. * @param imageID The image's ID. * @param userID The user's ID. * @param roiList The list of ROI to save. @@ -6664,15 +6537,14 @@ List loadROI(long imageID, List measurements, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List saveROI(long imageID, long userID, List roiList) + List saveROI(SecurityContext ctx, long imageID, long userID, + List roiList) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - try - { - IUpdatePrx updateService = getUpdateService(); - if (updateService == null) updateService = getUpdateService(); - IRoiPrx svc = getROIService(); + isSessionAlive(ctx); + try { + IUpdatePrx updateService = getUpdateService(ctx); + IRoiPrx svc = getROIService(ctx); RoiOptions options = new RoiOptions(); options.userId = omero.rtypes.rlong(userID); RoiResult serverReturn; @@ -6692,29 +6564,22 @@ List saveROI(long imageID, long userID, List roiList) * the server that should be deleted, before creating map. * To delete an roi we first must delete all the roiShapes in * the roi. */ - for (Roi roi : serverRoiList) { - if (roi != null) { - if (!clientROIMap.containsKey(roi.getId().getValue())) - { - /* rois are now deleted using the roi service. - if (roi.getDetails().getOwner().getId().getValue() - == userID) { - for (int i = 0 ; i < roi.sizeOfShapes() ; i++) - updateService.deleteObject(roi.getShape(i)); - updateService.deleteObject(roi); - } - */ - } else roiMap.put(roi.getId().getValue(), roi); + for (Roi r : serverRoiList) { + if (r != null) { + //rois are now deleted using the roi service. + if (clientROIMap.containsKey(r.getId().getValue())) + roiMap.put(r.getId().getValue(), r); } } /* For each roi in the client, see what should be done: * 1. Create a new roi if it does not exist. - * 2. build a map of the roiShapes in the clientROI with ROICoordinate - * as a key. + * 2. build a map of the roiShapes in the clientROI with + * ROICoordinate as a key. * 3. as above but for server roiShapes. - * 4. iterate through the maps to see if the shapes have been deleted - * in the roi on the client, if so then delete the shape on the server. + * 4. iterate through the maps to see if the shapes have been + * deleted in the roi on the client, if so then delete the shape on + * the server. * 5. Somehow the server roi becomes stale on the client so we have * to retrieve the roi again from the server before updating it. * 6. Check to see if the roi in the cleint has been updated @@ -6734,6 +6599,7 @@ List saveROI(long imageID, long userID, List roiList) List deleted = new ArrayList(); Image unloaded = new ImageI(imageID, false); + Roi rr; for (ROIData roi : roiList) { /* @@ -6741,9 +6607,9 @@ List saveROI(long imageID, long userID, List roiList) */ if (!roiMap.containsKey(roi.getId())) { - Roi r = (Roi) roi.asIObject(); - r.setImage(unloaded); - updateService.saveAndReturnObject(r); + rr = (Roi) roi.asIObject(); + rr.setImage(unloaded); + updateService.saveAndReturnObject(rr); continue; } @@ -6754,8 +6620,7 @@ List saveROI(long imageID, long userID, List roiList) shapeIterator = roi.getIterator(); clientCoordMap = new HashMap(); - while (shapeIterator.hasNext()) - { + while (shapeIterator.hasNext()) { shapeList = shapeIterator.next(); shape = shapeList.get(0); if (shape != null) @@ -6767,8 +6632,7 @@ List saveROI(long imageID, long userID, List roiList) */ serverCoordMap = new HashMap(); if (serverRoi != null) { - for (int i = 0 ; i < serverRoi.sizeOfShapes(); i++) - { + for (int i = 0 ; i < serverRoi.sizeOfShapes(); i++) { s = serverRoi.getShape(i); if (s != null) { serverCoordMap.put(new ROICoordinate( @@ -6785,16 +6649,12 @@ List saveROI(long imageID, long userID, List roiList) Entry entry; List removed = new ArrayList(); List toDelete = new ArrayList(); - while (si.hasNext()) - { + while (si.hasNext()) { entry = (Entry) si.next(); coord = (ROICoordinate) entry.getKey(); - if (!clientCoordMap.containsKey(coord)) - { + if (!clientCoordMap.containsKey(coord)) { s = (Shape) entry.getValue(); - if (s != null) { - updateService.deleteObject(s); - } + if (s != null) updateService.deleteObject(s); } else { s = (Shape) entry.getValue(); if (s instanceof Line || s instanceof Polyline) { @@ -6806,7 +6666,6 @@ List saveROI(long imageID, long userID, List roiList) removed.add(coord); updateService.deleteObject(s); deleted.add(shape.getId()); - System.err.println("deleted: "+shape.getId()); } } } @@ -6817,10 +6676,9 @@ List saveROI(long imageID, long userID, List roiList) if (serverRoi != null) { id = serverRoi.getId().getValue(); tempResults = svc.findByImage(imageID, new RoiOptions()); - for (Roi r : tempResults.rois) - { - if (r.getId().getValue() == id) - serverRoi = r; + for (Roi rrr : tempResults.rois) { + if (rrr.getId().getValue() == id) + serverRoi = rrr; } } @@ -6831,8 +6689,7 @@ List saveROI(long imageID, long userID, List roiList) si = clientCoordMap.entrySet().iterator(); Shape serverShape; long sid; - while (si.hasNext()) - { + while (si.hasNext()) { entry = (Entry) si.next(); coord = (ROICoordinate) entry.getKey(); shape = (ShapeData) entry.getValue(); @@ -6840,8 +6697,7 @@ List saveROI(long imageID, long userID, List roiList) if (shape != null) { if (!serverCoordMap.containsKey(coord)) serverRoi.addShape((Shape) shape.asIObject()); - else if (shape.isDirty()) - { + else if (shape.isDirty()) { shapeIndex = -1; if (deleted.contains(shape.getId())) { serverRoi.addShape((Shape) shape.asIObject()); @@ -6851,32 +6707,27 @@ else if (shape.isDirty()) { if (serverRoi != null) { serverShape = serverRoi.getShape(j); - if (serverShape != null) - { - if (serverShape.getId() != null) - { - sid = serverShape.getId().getValue(); - if (sid == shape.getId()) - { - shapeIndex = j; - break; - } + if (serverShape != null && + serverShape.getId() != null) { + sid = serverShape.getId().getValue(); + if (sid == shape.getId()) { + shapeIndex = j; + break; } } } } - if (shapeIndex == -1) - { + if (shapeIndex == -1) { serverShape = null; shapeIndex = -1; - for (int j = 0 ; j < serverRoi.sizeOfShapes() ; j++) + for (int j = 0 ; j < serverRoi.sizeOfShapes() ; + j++) { if (serverRoi != null) { serverShape = serverRoi.getShape(j); - if (serverShape != null) - { + if (serverShape != null) { if (serverShape.getTheT().getValue() == shape.getT() && serverShape.getTheZ().getValue() @@ -6888,14 +6739,11 @@ else if (shape.isDirty()) } } } - if (shapeIndex !=-1) - { + if (shapeIndex !=-1) { if (!removed.contains(coord)) updateService.deleteObject(serverShape); serverRoi.addShape((Shape) shape.asIObject()); - } - else - { + } else { throw new Exception("serverRoi.shapeList " + "is corrupted"); } @@ -6928,10 +6776,10 @@ else if (shape.isDirty()) return new ArrayList(); } - /** * Loads the FileAnnotationDatas for the passed image. * + * @param ctx The security context. * @param imageID The image's id. * @param userID The id of the user. * @return See above. @@ -6940,13 +6788,13 @@ else if (shape.isDirty()) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Collection loadROIMeasurements(long imageID, long userID) + Collection loadROIMeasurements(SecurityContext ctx, long imageID, + long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - IRoiPrx svc = getROIService(); - if (svc == null) svc = getROIService(); + IRoiPrx svc = getROIService(ctx); RoiOptions options = new RoiOptions(); options.userId = omero.rtypes.rlong(userID); Collection files = PojoMapper.asDataObjects( @@ -6983,18 +6831,19 @@ Collection loadROIMeasurements(long imageID, long userID) /** * Returns the file * - * @param file The file to write the bytes. - * @param imageID The id of the image. + * @param ctx The security context. + * @param file The file to write the bytes. + * @param imageID The id of the image. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - File exportImageAsOMETiff(File f, long imageID) + File exportImageAsOMETiff(SecurityContext ctx, File f, long imageID) throws DSAccessException, DSOutOfServiceException { - isSessionAlive(); + isSessionAlive(ctx); FileOutputStream stream = null; DSAccessException exception = null; try { @@ -7002,30 +6851,26 @@ File exportImageAsOMETiff(File f, long imageID) stream = new FileOutputStream(f); try { - //synchronized(new Object()) { - store = getExporterService(); - if (store == null) store = getExporterService(); - store.addImage(imageID); - + store = getExporterService(ctx); + store.addImage(imageID); + try { + long size = store.generateTiff(); + long offset = 0; try { - long size = store.generateTiff(); - long offset = 0; - try { - for (offset = 0; (offset+INC) < size;) { - stream.write(store.read(offset, INC)); - offset += INC; - } - } finally { - stream.write(store.read(offset, (int)(size-offset))); - stream.close(); - } - } catch (Exception e) { - if (stream != null) stream.close(); - if (f != null) f.delete(); - exception = new DSAccessException( - "Cannot export the image as an OME-TIFF ", e); + for (offset = 0; (offset+INC) < size;) { + stream.write(store.read(offset, INC)); + offset += INC; + } + } finally { + stream.write(store.read(offset, (int)(size-offset))); + stream.close(); } - //} + } catch (Exception e) { + if (stream != null) stream.close(); + if (f != null) f.delete(); + exception = new DSAccessException( + "Cannot export the image as an OME-TIFF ", e); + } } finally { try { if (store != null) store.close(); @@ -7040,55 +6885,10 @@ File exportImageAsOMETiff(File f, long imageID) } } - /** - * Performs a basic fit. Returns the file hosting the results. - * - * @param ids The objects to analyze. - * @param objectType The type of objects to analyze. - * @param param The parameters. - * @return See above. - * @throws DSOutOfServiceException If the connection is broken, or logged - * in. - * @throws DSAccessException If an error occurred while trying to - * retrieve data from OMEDS service. - */ - long analyseFRAP(List ids, Class objectType, Object param) - throws DSOutOfServiceException, DSAccessException - { - isSessionAlive(); - try { - /* - IScriptPrx svc = getScripService(); - - Map scripts = svc.getScripts(); - if (scripts == null) return -1; - long id = -1; - Entry en; - Iterator j = scripts.entrySet().iterator(); - long value; - String scriptName = "frapFigure.py"; - while (j.hasNext()) { - en = (Entry) j.next(); - if (en.getValue().equals(scriptName)) { - value = (Long) en.getKey(); - if (value > id) id = value; - } - } - if (id <= 0) return -1; - Map map = new HashMap(); - map.put("imageId", omero.rtypes.rlong(ids.get(0))); - - runScript(id, map); - */ - } catch (Exception e) { - handleException(e, "Cannot analyze the data."); - } - return -1; - } - /** * Runs the script. * + * @param ctx The security context. * @param script The script to run. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -7097,10 +6897,10 @@ long analyseFRAP(List ids, Class objectType, Object param) * retrieve data from OMEDS service. * @throws ProcessException If an error occurred while running the script. */ - ScriptCallback runScript(ScriptObject script) + ScriptCallback runScript(SecurityContext ctx, ScriptObject script) throws ProcessException, DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); long id = -1; try { id = script.getScriptID(); @@ -7108,12 +6908,13 @@ ScriptCallback runScript(ScriptObject script) } catch (Exception e) { handleException(e, "Cannot run the script."); } - return runScript(id, script.getValueToPass()); + return runScript(ctx, id, script.getValueToPass()); } /** * Runs the script. * + * @param ctx The security context. * @param script The script to run. * @param official Pass true to indicate that the script will * be uploaded as an official script, false @@ -7123,14 +6924,14 @@ ScriptCallback runScript(ScriptObject script) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Object uploadScript(ScriptObject script, boolean official) + Object uploadScript(SecurityContext ctx, ScriptObject script, + boolean official) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); FileInputStream stream = null; try { - IScriptPrx svc = getScriptService(); - if (svc == null) svc = getScriptService(); + IScriptPrx svc = getScriptService(ctx); StringBuffer buf = new StringBuffer(""); try { File file = new File(script.getPath()); @@ -7152,7 +6953,7 @@ Object uploadScript(ScriptObject script, boolean official) return -1; } String path = script.getFolder(); - List scripts = getScripts(); + List scripts = getScripts(ctx); if (scripts.size() > 0) { Iterator i = scripts.iterator(); OriginalFile of; @@ -7190,6 +6991,7 @@ Object uploadScript(ScriptObject script, boolean official) /** * Creates the experimenters. * + * @param ctx The security context. * @param object The object hosting information about the experimenters * to create. * @return See above. @@ -7198,14 +7000,14 @@ Object uploadScript(ScriptObject script, boolean official) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List createExperimenters(AdminObject object) + List createExperimenters(SecurityContext ctx, + AdminObject object) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List results = new ArrayList(); try { - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); Map m = object.getExperimenters(); Entry entry; @@ -7230,12 +7032,12 @@ List createExperimenters(AdminObject object) exp = (Experimenter) ModelMapper.createIObject( (DataObject) entry.getKey()); uc = (UserCredentials) entry.getValue(); - value = lookupExperimenter(uc.getUserName()); + value = lookupExperimenter(ctx, uc.getUserName()); if (value == null) { if (uc.isAdministrator()) { - l.add(getSystemGroup(GroupData.USER)); - l.add(getSystemGroup(GroupData.SYSTEM)); - } else l.add(getSystemGroup(GroupData.USER)); + l.add(getSystemGroup(ctx, GroupData.USER)); + l.add(getSystemGroup(ctx, GroupData.SYSTEM)); + } else l.add(getSystemGroup(ctx, GroupData.USER)); if (g == null) { g = l.get(0); systemGroup = true; @@ -7263,6 +7065,7 @@ List createExperimenters(AdminObject object) /** * Creates the experimenters. * + * @param ctx The security context. * @param object The object hosting information about the experimenters * to create. * @return See above. @@ -7271,12 +7074,12 @@ List createExperimenters(AdminObject object) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - GroupData createGroup(AdminObject object) + GroupData createGroup(SecurityContext ctx, AdminObject object) throws DSOutOfServiceException, DSAccessException { + isSessionAlive(ctx); try { - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); Map m = object.getExperimenters(); Entry entry; @@ -7285,7 +7088,7 @@ GroupData createGroup(AdminObject object) UserCredentials uc; String password; GroupData groupData = (GroupData) object.getGroup(); - ExperimenterGroup g = lookupGroup(groupData.getName()); + ExperimenterGroup g = lookupGroup(ctx, groupData.getName()); if (g != null) return null; @@ -7296,7 +7099,7 @@ GroupData createGroup(AdminObject object) if (level != AdminObject.PERMISSIONS_PRIVATE) { Permissions p = g.getDetails().getPermissions(); setPermissionsLevel(p, level); - getAdminService().changePermissions(g, p); + svc.changePermissions(g, p); } List list = new ArrayList(); @@ -7311,7 +7114,7 @@ GroupData createGroup(AdminObject object) entry = (Entry) i.next(); uc = (UserCredentials) entry.getValue(); //Check if the experimenter already exist - value = lookupExperimenter(uc.getUserName()); + value = lookupExperimenter(ctx, uc.getUserName()); if (value != null) { exp = value; expData = new ExperimenterData(exp); @@ -7322,9 +7125,9 @@ GroupData createGroup(AdminObject object) exp = (Experimenter) ModelMapper.createIObject( (ExperimenterData) entry.getKey()); if (uc.isAdministrator()) { - l.add(getSystemGroup(GroupData.SYSTEM)); - l.add(getSystemGroup(GroupData.USER)); - } else l.add(getSystemGroup(GroupData.USER)); + l.add(getSystemGroup(ctx, GroupData.SYSTEM)); + l.add(getSystemGroup(ctx, GroupData.USER)); + } else l.add(getSystemGroup(ctx, GroupData.USER)); exp.setOmeName(omero.rtypes.rstring(uc.getUserName())); password = uc.getPassword(); if (password != null && password.length() > 0) { @@ -7352,20 +7155,20 @@ GroupData createGroup(AdminObject object) * Returns a map whose keys are the group identifiers and the values the * number of experimenters in the group. * + * @param ctx The security context. * @param ids The group identifiers. * @return See above * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - Map countExperimenters(List groupIds) + Map countExperimenters(SecurityContext ctx, List groupIds) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); Map r = new HashMap(); try { - IQueryPrx svc = getQueryService(); - if (svc == null) svc = getQueryService(); + IQueryPrx svc = getQueryService(ctx); ParametersI p = new ParametersI(); p.addLongs("gids", groupIds); List list = (List) svc.findAllByQuery("select m " + @@ -7407,7 +7210,6 @@ Map countExperimenters(List groupIds) } catch (Throwable t) { handleException(t, "Cannot count the experimenters."); } - return r; } @@ -7421,15 +7223,14 @@ Map countExperimenters(List groupIds) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List getGroups(long experimenterID) + List getGroups(SecurityContext ctx, long experimenterID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List pojos = new ArrayList(); if (experimenterID < 0) return pojos; try { - IQueryPrx svc = getQueryService(); - if (svc == null) svc = getQueryService(); + IQueryPrx svc = getQueryService(ctx); //IAdminPrx svc = getAdminService(); List groups = null; ParametersI p = new ParametersI(); @@ -7457,6 +7258,7 @@ List getGroups(long experimenterID) /** * Loads the groups the experimenters. * + * @param ctx The security context. * @param id The group identifier or -1. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -7464,14 +7266,13 @@ List getGroups(long experimenterID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List loadGroups(long id) + List loadGroups(SecurityContext ctx, long id) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List pojos = new ArrayList(); try { - IQueryPrx svc = getQueryService(); - if (svc == null) svc = getQueryService(); + IQueryPrx svc = getQueryService(ctx); List groups = null; if (id < 0) { groups = (List) @@ -7513,6 +7314,7 @@ List loadGroups(long id) * Loads the experimenters contained in the specified group or all * experimenters if the value passed is -1. * + * @param ctx The security context. * @param id The group identifier or -1. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -7520,14 +7322,13 @@ List loadGroups(long id) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List loadExperimenters(long groupID) + List loadExperimenters(SecurityContext ctx, long groupID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List pojos = new ArrayList(); try { - IAdminPrx service = getAdminService(); - if (service == null) service = getAdminService(); + IAdminPrx service = getAdminService(ctx); List l = service.lookupExperimenters(); pojos.addAll(PojoMapper.asDataObjects(l)); } catch (Throwable t) { @@ -7535,13 +7336,12 @@ List loadExperimenters(long groupID) } return pojos; } - - - + /** * Deletes the specified experimenters. Returns the experimenters * that could not be deleted. * + * @param ctx The security context. * @param experimenters The experimenters to delete. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -7549,14 +7349,13 @@ List loadExperimenters(long groupID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List deleteExperimenters( + List deleteExperimenters(SecurityContext ctx, List experimenters) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List r = new ArrayList(); - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); Iterator i = experimenters.iterator(); ExperimenterData exp; while (i.hasNext()) { @@ -7574,6 +7373,7 @@ List deleteExperimenters( * Copies the experimenter to the specified group. * Returns the experimenters that could not be copied. * + * @param ctx The security context. * @param group The group to add the experimenters to. * @param experimenters The experimenters to add. * @return See above. @@ -7582,14 +7382,13 @@ List deleteExperimenters( * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List copyExperimenters(GroupData group, - Collection experimenters) + List copyExperimenters(SecurityContext ctx, + GroupData group, Collection experimenters) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List r = new ArrayList(); - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); Iterator i = experimenters.iterator(); ExperimenterData exp; List groups = new ArrayList(); @@ -7609,6 +7408,7 @@ List copyExperimenters(GroupData group, * Removes the experimenters from the specified group. * Returns the experimenters that could not be removed. * + * @param ctx The security context. * @param group The group to add the experimenters to. * @param experimenters The experimenters to add. * @return See above. @@ -7617,14 +7417,13 @@ List copyExperimenters(GroupData group, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List removeExperimenters(GroupData group, - Collection experimenters) + List removeExperimenters(SecurityContext ctx, + GroupData group, Collection experimenters) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List r = new ArrayList(); - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); Iterator i = experimenters.iterator(); ExperimenterData exp; List groups = new ArrayList(); @@ -7644,6 +7443,7 @@ List removeExperimenters(GroupData group, * Deletes the specified groups. Returns the groups that could not be * deleted. * + * @param ctx The security context. * @param groups The groups to delete. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -7651,13 +7451,12 @@ List removeExperimenters(GroupData group, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List deleteGroups(List groups) + List deleteGroups(SecurityContext ctx, List groups) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); List r = new ArrayList(); - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + IAdminPrx svc = getAdminService(ctx); Iterator i = groups.iterator(); GroupData g; while (i.hasNext()) { @@ -7674,6 +7473,7 @@ List deleteGroups(List groups) /** * Resets the password of the specified user. * + * @param ctx The security context. * @param userName The login name. * @param userID The id of the user. * @param password The password to set. @@ -7682,12 +7482,12 @@ List deleteGroups(List groups) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - void resetPassword(String userName, long userID, String password) + void resetPassword(SecurityContext ctx, String userName, long userID, + String password) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + isSessionAlive(ctx); + IAdminPrx svc = getAdminService(ctx); try { svc.changeUserPassword(userName, omero.rtypes.rstring(password)); } catch (Throwable t) { @@ -7700,26 +7500,27 @@ void resetPassword(String userName, long userID, String password) * Returns true if the user name could be reset, * false otherwise. * - * @param userName The login name. - * @param experimenter The experimenter to handle. + * @param ctx The security context. + * @param userName The login name. + * @param experimenter The experimenter to handle. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - boolean resetUserName(String userName, ExperimenterData experimenter) + boolean resetUserName(SecurityContext ctx, String userName, + ExperimenterData experimenter) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { //First check that no user with the name already exists - Experimenter value = lookupExperimenter(userName); + Experimenter value = lookupExperimenter(ctx, userName); if (value == null) { Experimenter exp = experimenter.asExperimenter(); exp.setOmeName(omero.rtypes.rstring(userName)); - IAdminPrx service = getAdminService(); - if (service == null) service = getAdminService(); + IAdminPrx service = getAdminService(ctx); service.updateExperimenter(exp); return true; } @@ -7733,6 +7534,7 @@ boolean resetUserName(String userName, ExperimenterData experimenter) /** * Invokes when the user has forgotten his/her password. * + * @param ctx The security context. * @param userName The login name. * @param email The e-mail if set. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -7740,7 +7542,8 @@ boolean resetUserName(String userName, ExperimenterData experimenter) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - void reportForgottenPassword(String userName, String email) + void reportForgottenPassword(SecurityContext ctx, String userName, + String email) throws DSOutOfServiceException, DSAccessException { //root need to login and send an e-mail. @@ -7775,6 +7578,7 @@ void setPermissionsLevel(Permissions p, int level) /** * Returns the group corresponding to the passed name or null. * + * @param ctx The security context. * @param name The name of the group. * @return See above * @throws DSOutOfServiceException If the connection is broken, or logged @@ -7782,18 +7586,17 @@ void setPermissionsLevel(Permissions p, int level) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - ExperimenterGroup lookupGroup(String name) + ExperimenterGroup lookupGroup(SecurityContext ctx, String name) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - IAdminPrx svc = getAdminService(); + isSessionAlive(ctx); + IAdminPrx svc = getAdminService(ctx); try { - if (svc == null) svc = getAdminService(); return svc.lookupGroup(name); } catch (Exception e) { if (e instanceof ApiUsageException) return null; - handleException(e, "Cannot loade the required group."); + handleException(e, "Cannot load the group."); } return null; } @@ -7802,6 +7605,7 @@ ExperimenterGroup lookupGroup(String name) * Returns the experimenter corresponding to the passed name or * null. * + * @param ctx The security context. * @param name The name of the experimenter. * @return See above * @throws DSOutOfServiceException If the connection is broken, or logged @@ -7809,13 +7613,12 @@ ExperimenterGroup lookupGroup(String name) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Experimenter lookupExperimenter(String name) + Experimenter lookupExperimenter(SecurityContext ctx, String name) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - IAdminPrx svc = getAdminService(); + isSessionAlive(ctx); + IAdminPrx svc = getAdminService(ctx); try { - if (svc == null) svc = getAdminService(); return svc.lookupExperimenter(name); } catch (Exception e) { if (e instanceof ApiUsageException) @@ -7826,54 +7629,53 @@ Experimenter lookupExperimenter(String name) } /** - * Get the list of available workflows on the server. + * Returns the list of available workflows on the server. + * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - List retrieveWorkflows(long userID) + List retrieveWorkflows(SecurityContext ctx, long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - IQueryPrx svc = getQueryService(); - if (svc == null) svc = getQueryService(); - try - { + isSessionAlive(ctx); + IQueryPrx svc = getQueryService(ctx); + try { ParametersI param = new ParametersI(); param.map.put("userID", omero.rtypes.rlong(userID)); List serverWorkflows = (List) svc.findAllByQuery("from Namespace as n", param); return PojoMapper.asDataObjectsAsList(serverWorkflows); - } catch(Throwable t) - { + } catch(Throwable t) { return new ArrayList(); } } /** - * Get the list of available workflows on the server. + * Returns the list of available workflows on the server. + * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Object storeWorkflows(List workflows, long userID) + Object storeWorkflows(SecurityContext ctx, List workflows, + long userID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - IUpdatePrx updateService = getUpdateService(); - if (updateService == null) updateService = getUpdateService(); + isSessionAlive(ctx); + IUpdatePrx updateService = getUpdateService(ctx); for (WorkflowData workflow : workflows) if (workflow.isDirty()) { - try - { + try { updateService.saveObject(workflow.asIObject()); - } catch (ServerError e) - { + } catch (Throwable e) { handleException(e, "Unable to save Object : "+ workflow); } } @@ -7883,6 +7685,7 @@ Object storeWorkflows(List workflows, long userID) /** * Reads the file hosting the user photo. * + * @param ctx The security context. * @param fileID The id of the file. * @param size The size of the file. * @return See above @@ -7891,23 +7694,22 @@ Object storeWorkflows(List workflows, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - synchronized byte[] getUserPhoto(long fileID, long size) + synchronized byte[] getUserPhoto(SecurityContext ctx, long fileID, + long size) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - - RawFileStorePrx store = getRawFileService(); - if (store == null) store = getRawFileService(); + isSessionAlive(ctx); + RawFileStorePrx store = getRawFileService(ctx); try { store.setFileId(fileID); } catch (Throwable e) { - closeService(store); + closeService(ctx, store); handleException(e, "Cannot set the file's id."); } try { return store.read(0, (int) size); } catch (Exception e) { - closeService(store); + closeService(ctx, store); throw new DSAccessException("Cannot read the file" +fileID, e); } } @@ -7915,6 +7717,7 @@ synchronized byte[] getUserPhoto(long fileID, long size) /** * Uploads the photo hosting the user photo. * + * @param ctx The security context. * @param fileID The id of the file. * @param size The size of the file. * @return See above @@ -7923,12 +7726,12 @@ synchronized byte[] getUserPhoto(long fileID, long size) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - long uploadExperimenterPhoto(File file, String format, long experimenterID) + long uploadExperimenterPhoto(SecurityContext ctx, File file, String format, + long experimenterID) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + isSessionAlive(ctx); + IAdminPrx svc = getAdminService(ctx); try { FileInputStream stream = new FileInputStream(file); long length = file.length(); @@ -7952,22 +7755,23 @@ long uploadExperimenterPhoto(File file, String format, long experimenterID) /** * Returns the specified script. * + * @param ctx The security context. * @param commands The object to delete. * @return See above. * @throws ProcessException If an error occurred while running the script. */ - DeleteCallback deleteObject(DeleteCommand[] commands) + DeleteCallback deleteObject(SecurityContext ctx, DeleteCommand[] commands) throws ProcessException { - isSessionAlive(); + isSessionAlive(ctx); DeleteCallback cb = null; shutDownServices(false); try { - IDeletePrx svc = getDeleteService(); - if (svc == null) svc = getDeleteService(); + IDeletePrx svc = getDeleteService(ctx); //scriptID, parameters, timeout (5s if null) + Connector c = getConnector(ctx); DeleteHandlePrx prx = svc.queueDelete(commands); - cb = new DeleteCallback(secureClient, prx); + cb = new DeleteCallback(c.getClient(), prx); } catch (Exception e) { throw new ProcessException("Cannot delete the speficied objects.", e); @@ -7979,6 +7783,7 @@ DeleteCallback deleteObject(DeleteCommand[] commands) * Returns the back-off time if it requires a pyramid to be built, * null otherwise. * + * @param ctx The security context. * @param pixelsId The identifier of the pixels set to handle. * @return See above * @throws DSOutOfServiceException If the connection is broken, or logged @@ -7986,13 +7791,12 @@ DeleteCallback deleteObject(DeleteCommand[] commands) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - Boolean isLargeImage(long pixelsId) + Boolean isLargeImage(SecurityContext ctx, long pixelsId) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); + isSessionAlive(ctx); try { - RawPixelsStorePrx store = getPixelsStore(); - if (store == null) store = getPixelsStore(); + RawPixelsStorePrx store = getPixelsStore(ctx); store.setPixelsId(pixelsId, true); boolean b = store.requiresPixelsPyramid(); store.close(); @@ -8003,18 +7807,25 @@ Boolean isLargeImage(long pixelsId) return null; } - /** Closes the services initialized by the importer.*/ - void closeImport() + /** + * Closes the services initialized by the importer. + * + * @param ctx The security context. + */ + void closeImport(SecurityContext ctx) { - if (importStore != null) { - importStore.closeServices(); - importStore = null; + try { + Connector c = getConnector(ctx); + if (c != null) c.closeImport(); + } catch (Exception e) { + // TODO: handle exception } } /** * Adds the experimenters to the specified group. * + * @param ctx The security context. * @param group The group to add the experimenters to. * @param experimenters The experimenters to add. * @return See above. @@ -8022,25 +7833,93 @@ void closeImport() * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - void addExperimenters(GroupData group, List - experimenters) + void addExperimenters(SecurityContext ctx, GroupData group, + List experimenters) throws DSOutOfServiceException, DSAccessException { - isSessionAlive(); - IAdminPrx svc = getAdminService(); - if (svc == null) svc = getAdminService(); + isSessionAlive(ctx); + IAdminPrx svc = getAdminService(ctx); Iterator i = experimenters.iterator(); try { - ExperimenterData exp; List groups = new ArrayList(); groups.add(group.asGroup()); while (i.hasNext()) { - exp = i.next(); - svc.addGroups(exp.asExperimenter(), groups); + svc.addGroups(i.next().asExperimenter(), groups); } } catch (Exception e) { handleException(e, "Cannot add the experimenters."); } } + /** + * Checks that the specified context and the object match, if they don't + * creates and returns a matching context. + * + * @param ctx The context to handle. + * @param ho The context to handle. + * @return See above. + */ + SecurityContext checkContext(SecurityContext ctx, DataObject ho) + { + if (ctx == null && ho.getId() >= 0) + return new SecurityContext(ho.getGroupId()); + if (ho.getId() < 0) return ctx; + if (ho.getGroupId() == ctx.getGroupID()) return ctx; + return new SecurityContext(ho.getGroupId()); + } + + /** + * Moves data between groups. + * + * @param ctx The security context of the source group. + * @param target The security context of the destination group. + * @param map The object to move and where to move them + * @param options The options. + * @return See above + * @throws DSOutOfServiceException If the connection is broken, or logged in + * @throws DSAccessException If an error occurred while trying to + * retrieve data from OMERO service. + */ + RequestCallback transfer(SecurityContext ctx, SecurityContext target, + Map> map, Map options) + throws DSOutOfServiceException, DSAccessException + { + isSessionAlive(ctx); + Connector c = getConnector(ctx); + if (c == null) return null; + IAdminPrx svc = getAdminService(ctx); + + try { + String sessionUuid = svc.getEventContext().sessionUuid; + Entry entry; + Iterator i = map.entrySet().iterator(); + DataObject data; + List l; + Iterator j; + List commands = new ArrayList(); + Chgrp cmd; + while (i.hasNext()) { + entry = (Entry) i.next(); + data = (DataObject) entry.getKey(); + l = (List) entry.getValue(); + cmd = new Chgrp(sessionUuid, createDeleteCommand( + data.getClass().getName()), data.getId(), options, + target.getGroupID()); + commands.add(cmd); + /* + j = l.iterator(); + while (i.hasNext()) { + commands.add(new SaveI(sessionUuid, i.next())); + } + */ + } + return c.submit(commands); + } catch (Exception e) { + handleException(e, "Cannot transfer the data."); + } + + + return null; + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroDataService.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroDataService.java index 0ea820d84ad..416ab736859 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroDataService.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroDataService.java @@ -37,6 +37,8 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.model.DeletableObject; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.DataObject; /** @@ -62,40 +64,44 @@ public interface OmeroDataService * Retrieves hierarchy trees rooted by a given node. * i.e. the requested node as root and all of its descendants. * - * @param rootNodeType The top-most type which will be searched for - * Can be Project, - * Dataset. - * Mustn't be null. - * @param rootNodeIDs A set of the IDs of top-most containers. - * Passed null to retrieve all top-most - * nodes e.g. all user's projects. - * @param withLeaves Passed true to retrieve the images, - * false otherwise. - * @param userID The identifier of the selected user. - * @param groupID The identifier of the selected user. + * @param ctx The security context. + * @param rootNodeType The top-most type which will be searched for + * Can be Project, + * Dataset. + * Mustn't be null. + * @param rootNodeIDs A set of the IDs of top-most containers. + * Passed null to retrieve all top-most + * nodes e.g. all user's projects. + * @param withLeaves Passed true to retrieve the images, + * false otherwise. + * @param userID The identifier of the selected user. + * @param groupID The identifier of the selected user. * @return A set of hierarchy trees. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Set loadContainerHierarchy(Class rootNodeType, List rootNodeIDs, - boolean withLeaves, long userID, long groupID) + public Set loadContainerHierarchy(SecurityContext ctx, + Class rootNodeType, List rootNodeIDs, boolean withLeaves, + long userID, long groupID) throws DSOutOfServiceException, DSAccessException; /** * Retrieves hierarchy trees rooted by a given node. * i.e. the requested node as root and all of its descendants. * - * @param rootNodeType The top-most type which will be searched for - * Can be Project. - * Mustn't be null. - * @param userID The Id of the selected user. + * @param ctx The security context. + * @param rootNodeType The top-most type which will be searched for + * Can be Project. + * Mustn't be null. + * @param userID The Id of the selected user. * @return A set of hierarchy trees. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Set loadTopContainerHierarchy(Class rootNodeType, long userID) + public Set loadTopContainerHierarchy(SecurityContext ctx, + Class rootNodeType, long userID) throws DSOutOfServiceException, DSAccessException; /** @@ -146,6 +152,7 @@ public Set loadTopContainerHierarchy(Class rootNodeType, long userID) * would not be part of the returned tree rooted by p1. *

* + * @param ctx The security context. * @param rootNodeType Top-most type which will be searched for * Can be Project. * Mustn't be null. @@ -157,36 +164,39 @@ public Set loadTopContainerHierarchy(Class rootNodeType, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Set findContainerHierarchy(Class rootNodeType, List leavesIDs, - long userID) + public Set findContainerHierarchy(SecurityContext ctx, + Class rootNodeType, List leavesIDs, long userID) throws DSOutOfServiceException, DSAccessException; /** * Retrieves the images contained in containers specified by the * node type. * - * @param nodeType The type of container. Can either be Project, - * Dataset, or Image. - * @param nodeIDs Set of node ids.. - * @param userID The Id of the root. + * @param ctx The security context. + * @param nodeType The type of container. Can either be Project, + * Dataset, or Image. + * @param nodeIDs Set of node ids.. + * @param userID The Id of the root. * @return A Set of retrieved images. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Set getImages(Class nodeType, List nodeIDs, long userID) + public Set getImages(SecurityContext ctx, Class nodeType, List nodeIDs, + long userID) throws DSOutOfServiceException, DSAccessException; /** * Retrieves the images imported by the specified user. * + * @param ctx The security context. * @param userID The id of the user. * @return A Set of retrieved images. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Set getExperimenterImages(long userID) + public Set getExperimenterImages(SecurityContext ctx, long userID) throws DSOutOfServiceException, DSAccessException; /** @@ -194,16 +204,17 @@ public Set getExperimenterImages(long userID) * Returns a map which key is the passed rootNodeID and the value is * the number of items contained in this object. * - * @param rootNodeType The type of container. Can either be Dataset. - * @param property One of the properties defined by this class. - * @param rootNodeIDs Set of root node IDs. + * @param ctx The security context. + * @param rootNodeType The type of container. Can either be Dataset. + * @param property One of the properties defined by this class. + * @param rootNodeIDs Set of root node IDs. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Map getCollectionCount(Class rootNodeType, String property, - List rootNodeIDs) + public Map getCollectionCount(SecurityContext ctx, + Class rootNodeType, String property, List rootNodeIDs) throws DSOutOfServiceException, DSAccessException; /** @@ -211,121 +222,132 @@ public Map getCollectionCount(Class rootNodeType, String property, * parent. The parent will be null if the * DataObject to create is either a Project. * + * @param ctx The security context. * @param newObject The DataObject to create. * Mustn't be null. - * @param parent The parent of the DataObject or Can be - * null if no parent specified. - * @param children The nodes to add to the newly created - * DataObject. - * @return The newly created DataObject + * @param parent The parent of the DataObject or Can be + * null if no parent specified. + * @param children The nodes to add to the newly created + * DataObject. + * @return The newly created DataObject * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public DataObject createDataObject(DataObject newObject, DataObject parent, - Collection children) + public DataObject createDataObject(SecurityContext ctx, + DataObject newObject, DataObject parent, Collection children) throws DSOutOfServiceException, DSAccessException; /** * Updates the specified DataObject. * - * @param object The DataObject to update. - * @return The updated object. + * @param ctx The security context. + * @param object The DataObject to update. + * @return The updated object. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public DataObject updateDataObject(DataObject object) + public DataObject updateDataObject(SecurityContext ctx, DataObject object) throws DSOutOfServiceException, DSAccessException; /** * Adds the given objects to the specified node. * - * @param parent The DataObject to update. Either a - * ProjectData or DatasetData. + * @param ctx The security context. + * @param parent The DataObject to update. Either a + * ProjectData or DatasetData. * @param children The collection of objects to add. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public void addExistingObjects(DataObject parent, Collection children) + public void addExistingObjects(SecurityContext ctx, DataObject parent, + Collection children) throws DSOutOfServiceException, DSAccessException; /** * Cuts and paste the specified nodes. * + * @param ctx The security context. * @param toPaste The nodes to paste. * @param toCut The nodes to cut. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public void cutAndPaste(Map toPaste, Map toCut) + public void cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut) throws DSOutOfServiceException, DSAccessException; /** * Retrieves the channel metadata for the specified pixels sets. * - * @param pixelsID The id of pixels set. + * @param ctx The security context. + * @param pixelsID The id of pixels set. * @return A list of metadata. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public List getChannelsMetadata(long pixelsID) + public List getChannelsMetadata(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException; /** * Retrieves and saves locally the archived files. * - * @param location The location where to save the files. - * @param pixelsID The ID of the pixels set. + * @param ctx The security context. + * @param location The location where to save the files. + * @param pixelsID The ID of the pixels set. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Map getArchivedImage(String location, long pixelsID) + public Map getArchivedImage(SecurityContext ctx, + String location, long pixelsID) throws DSOutOfServiceException, DSAccessException; /** * Retrieves the images after a given date. * - * @param lowerTime The timestamp identifying the start of the period. - * @param time The timestamp identifying the end of the period. - * @param userID The Id of the user. - * @param asDataObject Pass true to convert the object into - * the corresponding DataObject. + * @param ctx The security context. + * @param lowerTime The timestamp identifying the start of the period. + * @param time The timestamp identifying the end of the period. + * @param userID The Id of the user. + * @param asDataObject Pass true to convert the object into + * the corresponding DataObject. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection getImagesPeriod(Timestamp lowerTime, Timestamp time, - long userID, boolean asDataObject) + public Collection getImagesPeriod(SecurityContext ctx, Timestamp lowerTime, + Timestamp time, long userID, boolean asDataObject) throws DSOutOfServiceException, DSAccessException; /** * Retrieves the number of images imported during a given period of time. * - * @param lowerTime The timestamp identifying the start of the period. - * @param time The timestamp identifying the end of the period. - * @param userID The Id of the user. + * @param ctx The security context. + * @param lowerTime The timestamp identifying the start of the period. + * @param time The timestamp identifying the end of the period. + * @param userID The Id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List getImagesAllPeriodCount(Timestamp lowerTime, Timestamp time, - long userID) + public List getImagesAllPeriodCount(SecurityContext ctx, + Timestamp lowerTime, Timestamp time, long userID) throws DSOutOfServiceException, DSAccessException; /** * Retrieves the objects specified by the context of the search * and returns an object hosting various elements used for the display. - * + * + * @param ctx The security context. * @param context The context of the search. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -333,30 +355,34 @@ public List getImagesAllPeriodCount(Timestamp lowerTime, Timestamp time, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object advancedSearchFor(SearchDataContext context) + public Object advancedSearchFor(SecurityContext ctx, + SearchDataContext context) throws DSOutOfServiceException, DSAccessException; /** * Finds the objects containing the object identifying by the specified * type and id e.g. find the datasets containing a given image. * - * @param type The type of the object. - * @param id The id of the object. - * @param userID The id of the user who added attachments to the object - * or -1 if the user is not specified. + * @param ctx The security context. + * @param type The type of the object. + * @param id The id of the object. + * @param userID The id of the user who added attachments to the object + * or -1 if the user is not specified. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection findContainerPaths(Class type, long id, long userID) + public Collection findContainerPaths(SecurityContext ctx, Class type, + long id, long userID) throws DSOutOfServiceException, DSAccessException; /** * Returns the collection of original files corresponding to the passed * pixels set. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -364,12 +390,13 @@ public Collection findContainerPaths(Class type, long id, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection getOriginalFiles(long pixelsID) + public Collection getOriginalFiles(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException; /** * Loads the wells for the specified plate and acquisition. * + * @param ctx The security context. * @param plateID The ID of the plate. * @param acquisitionID The ID of the acquisition. * @param userID The id of the user. @@ -378,34 +405,56 @@ public Collection getOriginalFiles(long pixelsID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public Collection loadPlateWells(long plateID, long acquisitionID, - long userID) + public Collection loadPlateWells(SecurityContext ctx, long plateID, + long acquisitionID, long userID) throws DSOutOfServiceException, DSAccessException; /** * Deletes the collection of objects. The objects should all be of the * same types. Returns a handle to monitor the status of the deletion * - * @param objects The collection of objects to delete. + * @param ctx The security context. + * @param objects The collection of objects to delete. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. * @throws ProcessException If an error occurred while starting the process. */ - public DeleteCallback delete(Collection objects) + public DeleteCallback delete(SecurityContext ctx, + Collection objects) throws DSOutOfServiceException, DSAccessException, ProcessException; /** * Returns the view of the server repositories. * + * @param ctx The security context. * @param userID The ID of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMERO service. */ - public FSFileSystemView getFSRepositories(long userID) + public FSFileSystemView getFSRepositories(SecurityContext ctx, long userID) throws DSOutOfServiceException, DSAccessException; + /** + * Transfers the collection of objects. The objects should all be of the + * same types. Returns a handle to monitor the status of the transfer. + * + * @param ctx The security context. + * @param target The context of the target. + * @param targetNode The elements to transfer the data to. + * @param objects The collection of objects to transfer. + * @return See above. + * @throws DSOutOfServiceException If the connection is broken, or logged in + * @throws DSAccessException If an error occurred while trying to + * retrieve data from OMERO service. + * @throws ProcessException If an error occurred while starting the process. + */ + public RequestCallback transfer(SecurityContext ctx, + SecurityContext target, List targetNode, + List objects) + throws DSOutOfServiceException, DSAccessException, ProcessException; + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroDataServiceImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroDataServiceImpl.java index e7758242801..96a95fa65db 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroDataServiceImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroDataServiceImpl.java @@ -40,6 +40,8 @@ //Application-internal dependencies import omero.api.delete.DeleteCommand; +import omero.cmd.Chgrp; +import omero.cmd.CmdCallbackI; import omero.model.Annotation; import omero.model.AnnotationAnnotationLink; import omero.model.Channel; @@ -52,6 +54,7 @@ import omero.model.Image; import omero.model.ImageAnnotationLink; import omero.model.Pixels; +import omero.model.Plate; import omero.model.Project; import omero.model.ProjectAnnotationLink; import omero.model.ProjectDatasetLink; @@ -68,6 +71,8 @@ import org.openmicroscopy.shoola.env.data.util.ModelMapper; import org.openmicroscopy.shoola.env.data.util.PojoMapper; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.ChannelData; import pojos.DataObject; import pojos.DatasetData; @@ -81,6 +86,7 @@ import pojos.ScreenData; import pojos.TagAnnotationData; import pojos.WellData; +import pojos.WellSampleData; /** * Implementation of the {@link OmeroDataService} I/F. @@ -98,21 +104,22 @@ class OmeroDataServiceImpl { /** Uses it to gain access to the container's services. */ - private Registry context; + private Registry context; /** Reference to the entry point to access the OMERO services. */ - private OMEROGateway gateway; + private OMEROGateway gateway; /** * Unlinks the collection of children from the specified parent. * + * @param ctx The security context. * @param parent The parent of the children. * @param children The children to unlink * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private void cut(DataObject parent, Set children) + private void cut(SecurityContext ctx, DataObject parent, Set children) throws DSOutOfServiceException, DSAccessException { IObject mParent = parent.asIObject(); @@ -121,25 +128,26 @@ private void cut(DataObject parent, Set children) while (i.hasNext()) { ids.add(Long.valueOf(((DataObject) i.next()).getId())); } - List links = gateway.findLinks(mParent, ids); + List links = gateway.findLinks(ctx, mParent, ids); if (links != null) - gateway.deleteObjects(links); + gateway.deleteObjects(ctx, links); } /** * Deletes the tag set. * + * @param ctx The security context. * @param id The identifier of the set. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private List deleteTagSet(long id) + private List deleteTagSet(SecurityContext ctx, long id) throws DSOutOfServiceException, DSAccessException { - List l = gateway.findAnnotationLinks(Annotation.class.getName(), id, - null); + List l = gateway.findAnnotationLinks(ctx, Annotation.class.getName(), + id, null); List tagIds = new ArrayList(); List tags = new ArrayList(); @@ -155,7 +163,7 @@ private List deleteTagSet(long id) } } //delete the links - gateway.deleteObjects(l); + gateway.deleteObjects(ctx, l); return tags; } @@ -178,11 +186,12 @@ private List deleteTagSet(long id) /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#loadContainerHierarchy(Class, List, boolean, long, + * @see OmeroDataService#loadContainerHierarchy(SecurityContext, Class, List, boolean, long, * long) */ - public Set loadContainerHierarchy(Class rootNodeType, List rootNodeIDs, - boolean withLeaves, long userID, long groupID) + public Set loadContainerHierarchy(SecurityContext ctx, + Class rootNodeType, List rootNodeIDs, boolean withLeaves, + long userID, long groupID) throws DSOutOfServiceException, DSAccessException { ParametersI param = new ParametersI(); @@ -200,85 +209,87 @@ public Set loadContainerHierarchy(Class rootNodeType, List rootNodeIDs, ScreenData.class.equals(rootNodeType)) param.orphan(); } - return gateway.loadContainerHierarchy(rootNodeType, rootNodeIDs, + return gateway.loadContainerHierarchy(ctx, rootNodeType, rootNodeIDs, param); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#loadTopContainerHierarchy(Class, long) + * @see OmeroDataService#loadTopContainerHierarchy(SecurityContext, Class, long) */ - public Set loadTopContainerHierarchy(Class rootNodeType, long userID) + public Set loadTopContainerHierarchy(SecurityContext ctx, + Class rootNodeType, long userID) throws DSOutOfServiceException, DSAccessException { ParametersI param = new ParametersI(); param.exp(omero.rtypes.rlong(userID)); - return gateway.loadContainerHierarchy(rootNodeType, null, param); + return gateway.loadContainerHierarchy(ctx, rootNodeType, null, param); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#findContainerHierarchy(Class, List, long) + * @see OmeroDataService#findContainerHierarchy(SecurityContext, Class, List, long) */ - public Set findContainerHierarchy(Class rootNodeType, List leavesIDs, - long userID) + public Set findContainerHierarchy(SecurityContext ctx, Class rootNodeType, + List leavesIDs, long userID) throws DSOutOfServiceException, DSAccessException { ParametersI po = new ParametersI(); po.leaves(); po.exp(omero.rtypes.rlong(userID)); - return gateway.findContainerHierarchy(rootNodeType, leavesIDs, po); + return gateway.findContainerHierarchy(ctx, rootNodeType, leavesIDs, po); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#getImages(Class, List, long) + * @see OmeroDataService#getImages(SecurityContext, Class, List, long) */ - public Set getImages(Class nodeType, List nodeIDs, long userID) + public Set getImages(SecurityContext ctx, Class nodeType, List nodeIDs, + long userID) throws DSOutOfServiceException, DSAccessException { if (nodeType == null) throw new IllegalArgumentException("No type specified."); ParametersI po = new ParametersI(); po.exp(omero.rtypes.rlong(userID)); - return gateway.getContainerImages(nodeType, nodeIDs, po); + return gateway.getContainerImages(ctx, nodeType, nodeIDs, po); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#getExperimenterImages(long) + * @see OmeroDataService#getExperimenterImages(SecurityContext, long) */ - public Set getExperimenterImages(long userID) + public Set getExperimenterImages(SecurityContext ctx, long userID) throws DSOutOfServiceException, DSAccessException { ParametersI po = new ParametersI(); po.exp(omero.rtypes.rlong(userID)); - return gateway.getUserImages(po); + return gateway.getUserImages(ctx, po); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#getCollectionCount(Class, String, List) + * @see OmeroDataService#getCollectionCount(SecurityContext, Class, String, List) */ - public Map getCollectionCount(Class rootNodeType, String property, List - rootNodeIDs) + public Map getCollectionCount(SecurityContext ctx, Class rootNodeType, + String property, List rootNodeIDs) throws DSOutOfServiceException, DSAccessException { if (!(property.equals(IMAGES_PROPERTY))) throw new IllegalArgumentException("Property not supported."); //if (rootNodeType.equals(TagAnnotationData.class)) //return gateway.getDataObjectsTaggedCount(rootNodeIDs); - return gateway.getCollectionCount(rootNodeType, property, rootNodeIDs, - new Parameters()); + return gateway.getCollectionCount(ctx, rootNodeType, property, + rootNodeIDs, new Parameters()); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#createDataObject(DataObject, DataObject, - * Collection) + * @see OmeroDataService#createDataObject(SecurityContext, DataObject, + * DataObject, Collection) */ - public DataObject createDataObject(DataObject child, DataObject parent, - Collection children) + public DataObject createDataObject(SecurityContext ctx, DataObject child, + DataObject parent, Collection children) throws DSOutOfServiceException, DSAccessException { if (child == null) @@ -289,7 +300,7 @@ public DataObject createDataObject(DataObject child, DataObject parent, if (obj == null) throw new NullPointerException("Cannot convert the object."); - IObject created = gateway.createObject(obj); + IObject created = gateway.createObject(ctx, obj); IObject link; /* if (child instanceof TagAnnotationData) { @@ -306,7 +317,7 @@ public DataObject createDataObject(DataObject child, DataObject parent, if (parent != null) { link = ModelMapper.linkParentToChild(created, parent.asIObject()); if ((child instanceof TagAnnotationData) && link != null) { - gateway.createObject(link); + gateway.createObject(ctx, link); } } @@ -321,42 +332,45 @@ public DataObject createDataObject(DataObject child, DataObject parent, ((DataObject) node).asIObject(), created)); } if (links.size() > 0) - gateway.createObjects(links); + gateway.createObjects(ctx, links); } return PojoMapper.asDataObject(created); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#updateDataObject(DataObject) + * @see OmeroDataService#updateDataObject(SecurityContext, DataObject) */ - public DataObject updateDataObject(DataObject object) + public DataObject updateDataObject(SecurityContext ctx, DataObject object) throws DSOutOfServiceException, DSAccessException { if (object == null) throw new DSAccessException("No object to update."); + ctx = gateway.checkContext(ctx, object); if (object instanceof ExperimenterData) - return updateExperimenter((ExperimenterData) object, null); + return updateExperimenter(ctx, (ExperimenterData) object, null); if (!object.isLoaded()) return object; IObject ho = null; IObject oldObject = null; oldObject = object.asIObject(); - ho = gateway.findIObject(oldObject); + ho = gateway.findIObject(ctx, oldObject); if (ho == null) return null; ModelMapper.fillIObject(oldObject, ho); ModelMapper.unloadCollections(ho); - IObject updated = gateway.updateObject(ho, new Parameters()); + IObject updated = gateway.updateObject(ctx, ho, new Parameters()); return PojoMapper.asDataObject(updated); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#addExistingObjects(DataObject, Collection) + * @see OmeroDataService#addExistingObjects(SecurityContext, DataObject, Collection) */ - public void addExistingObjects(DataObject parent, Collection children) + public void addExistingObjects(SecurityContext ctx, DataObject parent, + Collection children) throws DSOutOfServiceException, DSAccessException { + ctx = gateway.checkContext(ctx, parent); if (parent instanceof ProjectData) { try { children.toArray(new DatasetData[] {}); @@ -373,7 +387,7 @@ public void addExistingObjects(DataObject parent, Collection children) for (int i = 0; i < exp.length; i++) { list.add(exp[i]); } - context.getAdminService().addExperimenters( + context.getAdminService().addExperimenters(ctx, (GroupData) parent, list); return; } catch (ArrayStoreException ase) { @@ -419,22 +433,27 @@ public void addExistingObjects(DataObject parent, Collection children) List objects = new ArrayList(); IObject ioParent = parent.asIObject(); IObject ioChild; - Iterator child = children.iterator(); - while (child.hasNext()) { - ioChild = ((DataObject) child.next()).asIObject(); - //First make sure that the child is not linked to the parent. - if (gateway.findLink(ioParent, ioChild) == null) - objects.add(ModelMapper.linkParentToChild(ioChild, ioParent)); + Iterator i = children.iterator(); + DataObject child; + while (i.hasNext()) { + child = (DataObject) i.next(); + if (child.getGroupId() == ctx.getGroupID()) { + ioChild = child.asIObject(); + //First make sure that the child is not linked to the parent. + if (gateway.findLink(ctx, ioParent, ioChild) == null) + objects.add( + ModelMapper.linkParentToChild(ioChild, ioParent)); + } } if (objects.size() != 0) - gateway.createObjects(objects); + gateway.createObjects(ctx, objects); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#cutAndPaste(Map, Map) + * @see OmeroDataService#cutAndPaste(SecurityContext, Map, Map) */ - public void cutAndPaste(Map toPaste, Map toCut) + public void cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut) throws DSOutOfServiceException, DSAccessException { if (toPaste == null) toPaste = new HashMap(); @@ -447,7 +466,7 @@ public void cutAndPaste(Map toPaste, Map toCut) entry = (Entry) i.next(); parent = entry.getKey(); if (parent instanceof DataObject) //b/c of orphaned container - cut((DataObject) parent, (Set) entry.getValue()); + cut(ctx, (DataObject) parent, (Set) entry.getValue()); } i = toPaste.entrySet().iterator(); @@ -456,19 +475,19 @@ public void cutAndPaste(Map toPaste, Map toCut) entry = (Entry) i.next(); parent = entry.getKey(); if (parent instanceof DataObject) - addExistingObjects((DataObject) parent, + addExistingObjects(ctx, (DataObject) parent, (Set) entry.getValue()); } } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#getChannelsMetadata(long) + * @see OmeroDataService#getChannelsMetadata(SecurityContext, long) */ - public List getChannelsMetadata(long pixelsID) + public List getChannelsMetadata(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException { - Pixels pixels = gateway.getPixels(pixelsID); + Pixels pixels = gateway.getPixels(ctx, pixelsID); if (pixels == null) return new ArrayList(); Collection l = pixels.copyChannels(); if (l == null) return new ArrayList(); @@ -484,36 +503,37 @@ public List getChannelsMetadata(long pixelsID) /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#getArchivedFiles(String, long) + * @see OmeroDataService#getArchivedFiles(SecurityContext, String, long) */ - public Map getArchivedImage(String path, long pixelsID) + public Map getArchivedImage(SecurityContext ctx, + String path, long pixelsID) throws DSOutOfServiceException, DSAccessException { context.getLogger().debug(this, path); - return gateway.getArchivedFiles(path, pixelsID); + return gateway.getArchivedFiles(ctx, path, pixelsID); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#updateExperimenter(ExperimenterData, GroupData) + * @see OmeroDataService#updateExperimenter(SecurityContext, ExperimenterData, GroupData) */ - public ExperimenterData updateExperimenter(ExperimenterData exp, GroupData - group) + public ExperimenterData updateExperimenter(SecurityContext ctx, + ExperimenterData exp, GroupData group) throws DSOutOfServiceException, DSAccessException { - //ADD control if (exp == null) throw new DSAccessException("No object to update."); + ctx = gateway.checkContext(ctx, exp); UserCredentials uc = (UserCredentials) context.lookup(LookupNames.USER_CREDENTIALS); ExperimenterData user = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); - gateway.updateExperimenter(exp.asExperimenter(), user.getId()); + gateway.updateExperimenter(ctx, exp.asExperimenter(), user.getId()); ExperimenterData data; if (group != null && exp.getDefaultGroup().getId() != group.getId()) - gateway.changeCurrentGroup(exp, group.getId()); - data = gateway.getUserDetails(uc.getUserName()); + gateway.changeCurrentGroup(ctx, exp, group.getId()); + data = gateway.getUserDetails(ctx, uc.getUserName()); context.bind(LookupNames.CURRENT_USER_DETAILS, data); // Bind user details to all agents' registry. @@ -530,10 +550,10 @@ public ExperimenterData updateExperimenter(ExperimenterData exp, GroupData /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#getImagesPeriod(Timestamp, Timestamp, long, boolean) + * @see OmeroDataService#getImagesPeriod(SecurityContext, Timestamp, Timestamp, long, boolean) */ - public Collection getImagesPeriod(Timestamp startTime, Timestamp endTime, - long userID, boolean asDataObject) + public Collection getImagesPeriod(SecurityContext ctx, Timestamp startTime, + Timestamp endTime, long userID, boolean asDataObject) throws DSOutOfServiceException, DSAccessException { if (startTime == null && endTime == null) @@ -546,20 +566,21 @@ public Collection getImagesPeriod(Timestamp startTime, Timestamp endTime, po.startTime(omero.rtypes.rtime(startTime.getTime())); if (endTime != null) po.endTime(omero.rtypes.rtime(endTime.getTime())); - return gateway.getImages(po, asDataObject); + return gateway.getImages(ctx, po, asDataObject); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#getImagesAllPeriodCount(Timestamp, Timestamp, long) + * @see OmeroDataService#getImagesAllPeriodCount(SecurityContext, Timestamp, Timestamp, long) */ - public List getImagesAllPeriodCount(Timestamp startTime, - Timestamp endTime, long userID) + public List getImagesAllPeriodCount(SecurityContext ctx, + Timestamp startTime, Timestamp endTime, long userID) throws DSOutOfServiceException, DSAccessException { if (startTime == null || endTime == null) throw new NullPointerException("Time not specified."); - Collection imgs = getImagesPeriod(startTime, endTime, userID, false); + Collection imgs = getImagesPeriod(ctx, startTime, endTime, userID, + false); Iterator i = imgs.iterator(); Image object; List times = new ArrayList(imgs.size()); @@ -575,11 +596,14 @@ public List getImagesAllPeriodCount(Timestamp startTime, /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#advancedSearchFor(SearchDataContext) + * @see OmeroDataService#advancedSearchFor(List, SearchDataContext) */ - public Object advancedSearchFor(SearchDataContext context) + public Object advancedSearchFor(SecurityContext ctx, + SearchDataContext context) throws DSOutOfServiceException, DSAccessException { + if (ctx == null) + throw new IllegalArgumentException("No scontext defined."); if (context == null) throw new IllegalArgumentException("No search context defined."); if (!context.isValid()) @@ -587,10 +611,11 @@ public Object advancedSearchFor(SearchDataContext context) Map results = new HashMap(); if (!context.hasTextToSearch()) { - results.put(SearchDataContext.TIME, gateway.searchByTime(context)); + results.put(SearchDataContext.TIME, + gateway.searchByTime(ctx, context)); return results; } - Object result = gateway.performSearch(context); + Object result = gateway.performSearch(ctx, context); //Should returns a search context for the moment. //collection of images only. Map m = (Map) result; @@ -631,8 +656,8 @@ public Object advancedSearchFor(SearchDataContext context) case SearchDataContext.FILE_ANNOTATION: case SearchDataContext.URL_ANNOTATION: case SearchDataContext.CUSTOMIZED: - images = gateway.getContainerImages(ImageData.class, - value, new Parameters()); + images = gateway.getContainerImages(ctx, + ImageData.class, value, new Parameters()); k = images.iterator(); while (k.hasNext()) { img = (DataObject) k.next(); @@ -650,13 +675,15 @@ public Object advancedSearchFor(SearchDataContext context) /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#findContainerPaths(Class, long, long) + * @see OmeroDataService#findContainerPaths(SecurityContext, Class, long, + * long) */ - public Collection findContainerPaths(Class type, long id, long userID) + public Collection findContainerPaths(SecurityContext ctx, + Class type, long id, long userID) throws DSOutOfServiceException, DSAccessException { try { - Class parentClass = null; + Class parentClass = gateway.convertPojos(type); if (DatasetData.class.equals(type)) parentClass = Project.class; else if (ImageData.class.equals(type)) @@ -667,8 +694,11 @@ else if (TagAnnotationData.class.equals(type)) parentClass = TagAnnotation.class; else if (FileAnnotationData.class.equals(type)) parentClass = FileAnnotation.class; + else if (WellSampleData.class.equals(type) || + WellData.class.equals(type)) + parentClass = Plate.class; if (parentClass == null) return new HashSet(); - List links = gateway.findLinks(parentClass, id, userID); + List links = gateway.findLinks(ctx, parentClass, id, userID); if (links == null) return new HashSet(); Iterator i = links.iterator(); Set nodes = new HashSet(); @@ -697,7 +727,8 @@ else if (link instanceof ImageAnnotationLink) } parentId = parent.getId().getValue(); if (!ids.contains(parentId)) { - object = gateway.findIObject(parent.getClass().getName(), + object = gateway.findIObject(ctx, + parent.getClass().getName(), parent.getId().getValue()); data = PojoMapper.asDataObject(object); if (TagAnnotation.class.equals(parentClass)) { @@ -720,37 +751,47 @@ else if (link instanceof ImageAnnotationLink) /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#getOriginalFiles(long) + * @see OmeroDataService#getOriginalFiles(SecurityContext, long) */ - public Collection getOriginalFiles(long pixelsID) + public Collection getOriginalFiles(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException { if (pixelsID < 0) throw new IllegalArgumentException("Pixels set ID not valid."); - return gateway.getOriginalFiles(pixelsID); + return gateway.getOriginalFiles(ctx, pixelsID); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#loadPlateWells(long, long, long) + * @see OmeroDataService#loadPlateWells(SecurityContext, long, long, long) */ - public Collection loadPlateWells(long plateID, long acquisitionID, - long userID) + public Collection loadPlateWells(SecurityContext ctx, + long plateID, long acquisitionID, long userID) throws DSOutOfServiceException, DSAccessException { - return gateway.loadPlateWells(plateID, acquisitionID, userID); + return gateway.loadPlateWells(ctx, plateID, acquisitionID, userID); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#delete(Collection) + * @see OmeroDataService#delete(SecurityContext, Collection) */ - public DeleteCallback delete(Collection objects) + public DeleteCallback delete(SecurityContext ctx, + Collection objects) throws DSOutOfServiceException, DSAccessException, ProcessException { - if (objects == null || objects.size() == 0) return null; + if (objects == null || objects.size() == 0 || ctx == null) return null; Iterator i = objects.iterator(); DeletableObject object; + List l = new ArrayList(); + while (i.hasNext()) { + object = i.next(); + if (object.getObjectToDelete().getGroupId() == ctx.getGroupID()) { + l.add(object); + } + } + if (l.size() == 0) return null; + i = l.iterator(); List commands = new ArrayList(); DeleteCommand cmd; Map options; @@ -806,7 +847,7 @@ public DeleteCallback delete(Collection objects) options = null; ns = ((TagAnnotationData) data).getNameSpace(); if (TagAnnotationData.INSIGHT_TAGSET_NS.equals(ns)) { - contents = deleteTagSet(data.getId()); + contents = deleteTagSet(ctx, data.getId()); } } } @@ -824,17 +865,57 @@ public DeleteCallback delete(Collection objects) } } } - return gateway.deleteObject(commands.toArray(new DeleteCommand[] {})); + return gateway.deleteObject(ctx, + commands.toArray(new DeleteCommand[] {})); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroDataService#getFSRepositories() + * @see OmeroDataService#getFSRepositories(SecurityContext, long) */ - public FSFileSystemView getFSRepositories(long userID) - throws DSOutOfServiceException, DSAccessException + public FSFileSystemView getFSRepositories(SecurityContext ctx, long userID) + throws DSOutOfServiceException, DSAccessException { - return gateway.getFSRepositories(userID); + return gateway.getFSRepositories(ctx, userID); } - + + /** + * Implemented as specified by {@link OmeroDataService}. + * @see OmeroDataService#transfer(SecurityContext, SecurityContext, List, + * List) + */ + public RequestCallback transfer(SecurityContext ctx, + SecurityContext target, List targetNodes, + List objects) + throws DSOutOfServiceException, DSAccessException, ProcessException + { + if (target == null) + throw new IllegalArgumentException("No target specified."); + if (objects == null || objects.size() == 0) + throw new IllegalArgumentException("No object to move."); + Iterator i = objects.iterator(); + Map> map = + new HashMap>(); + DataObject data; + List l; + Iterator j; + DataObject object; + while (i.hasNext()) { + data = i.next(); + l = new ArrayList(); + if (targetNodes != null && targetNodes.size() > 0) { + j = targetNodes.iterator(); + while (j.hasNext()) { + object = j.next(); + if (object != null) + l.add(ModelMapper.linkParentToChild(data.asIObject(), + object.asIObject())); + } + } + map.put(data, l); + } + Map options = new HashMap(); + return gateway.transfer(ctx, target, map, options); + } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroImageService.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroImageService.java index 83fabe1e29a..ab0bb0f45f7 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroImageService.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroImageService.java @@ -45,6 +45,7 @@ import org.openmicroscopy.shoola.env.data.model.ROIResult; import org.openmicroscopy.shoola.env.data.model.SaveAsParam; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.env.rnd.RenderingServiceException; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; @@ -77,15 +78,16 @@ public interface OmeroImageService public static final String ZIP_EXTENSION = ".zip"; /** Identifies the Maximum intensity projection. */ - public static final int MAX_INTENSITY = - ProjectionType.MAXIMUMINTENSITY.ordinal(); + public static final int MAX_INTENSITY = + ProjectionType.MAXIMUMINTENSITY.ordinal(); /** Identifies the Mean intensity projection. */ - public static final int MEAN_INTENSITY = - ProjectionType.MEANINTENSITY.ordinal(); + public static final int MEAN_INTENSITY = + ProjectionType.MEANINTENSITY.ordinal(); /** Identifies the Sum intensity projection. */ - public static final int SUM_INTENSITY = ProjectionType.SUMINTENSITY.ordinal(); + public static final int SUM_INTENSITY = + ProjectionType.SUMINTENSITY.ordinal(); /** Identifies the type used to store pixel values. */ public static final String INT_8 = "int8"; @@ -115,6 +117,7 @@ public interface OmeroImageService * Initializes a {@link RenderingControl} proxy for the specified pixels * set. * + * @param ctx The security context. * @param pixelsID The ID of the pixels set. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -124,64 +127,70 @@ public interface OmeroImageService * @throws FSAccessException If an error occurred while trying to * retrieve data using OMERO.fs. */ - public RenderingControl loadRenderingControl(long pixelsID) + public RenderingControl loadRenderingControl(SecurityContext ctx, + long pixelsID) throws DSOutOfServiceException, DSAccessException, FSAccessException; /** * Renders the specified 2D-plane. * - * @param pixelsID The ID of the pixels set. - * @param pd The plane to render. - * @param asTexture Pass true to return a texture, + * @param ctx The security context. + * @param pixelsID The ID of the pixels set. + * @param pd The plane to render. + * @param asTexture Pass true to return a texture, * false to return a buffered image. * @param largeImage Pass true to render a large image, * false otherwise. * @return The image representing the plane. * @throws RenderingServiceException If the server cannot render the image. */ - public Object renderImage(long pixelsID, PlaneDef pd, boolean asTexture, - boolean largeImage) + public Object renderImage(SecurityContext ctx, + long pixelsID, PlaneDef pd, boolean asTexture, boolean largeImage) throws RenderingServiceException; /** * Shuts downs the rendering service attached to the specified * pixels set. * + * @param ctx The security context. * @param pixelsID The ID of the pixels set. */ - public void shutDown(long pixelsID); + public void shutDown(SecurityContext ctx, long pixelsID); /** * Returns a thumbnail of the currently selected 2D-plane for the * passed pixels set. * - * @param pixelsID The id of the pixels set. - * @param sizeX The width of the thumbnail. - * @param sizeY The height of the thumnail. - * @param userID The id of the user the thumbnail is for. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param sizeX The width of the thumbnail. + * @param sizeY The height of the thumnail. + * @param userID The id of the user the thumbnail is for. * @return See above. * @throws RenderingServiceException If the server is out of service. */ - public BufferedImage getThumbnail(long pixelsID, int sizeX, int sizeY, long - userID) + public BufferedImage getThumbnail(SecurityContext ctx, long pixelsID, + int sizeX, int sizeY, long userID) throws RenderingServiceException; /** * Retrieves the thumbnails corresponding to the passed collection of * pixels set. * + * @param ctx The security context. * @param pixelsID The collection of pixels set. * @param maxLength The maximum length of a thumbnail. * @return See above. * @throws RenderingServiceException If the server is out of service. */ - public Map getThumbnailSet(List pixelsID, - int maxLength) + public Map getThumbnailSet(SecurityContext ctx, + List pixelsID, int maxLength) throws RenderingServiceException; /** * Reloads the rendering engine for the passed set of pixels. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @return See above. * @throws RenderingServiceException If the rendering engine cannot be @@ -189,12 +198,14 @@ public Map getThumbnailSet(List pixelsID, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public RenderingControl reloadRenderingService(long pixelsID) + public RenderingControl reloadRenderingService(SecurityContext ctx, + long pixelsID) throws DSAccessException, RenderingServiceException; /** * Reloads the rendering engine for the passed set of pixels. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @return See above. * @throws RenderingServiceException If the rendering engine cannot be @@ -202,12 +213,14 @@ public RenderingControl reloadRenderingService(long pixelsID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public RenderingControl resetRenderingService(long pixelsID) + public RenderingControl resetRenderingService(SecurityContext ctx, + long pixelsID) throws DSAccessException, RenderingServiceException; /** * Loads the pixels set. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -215,17 +228,18 @@ public RenderingControl resetRenderingService(long pixelsID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public PixelsData loadPixels(long pixelsID) + public PixelsData loadPixels(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException; /** * Returns the XY-plane identified by the passed z-section, time-point * and wavelength. * - * @param pixelsID The id of pixels containing the requested plane. - * @param z The selected z-section. - * @param t The selected time-point. - * @param c The selected wavelength. + * @param ctx The security context. + * @param pixelsID The id of pixels containing the requested plane. + * @param z The selected z-section. + * @param t The selected time-point. + * @param c The selected wavelength. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. @@ -234,7 +248,8 @@ public PixelsData loadPixels(long pixelsID) * @throws FSAccessException If an error occurred while trying to * retrieve data using OMERO.fs. */ - public byte[] getPlane(long pixelsID, int z, int t, int c) + public byte[] getPlane(SecurityContext ctx, long pixelsID, int z, int t, + int c) throws DSOutOfServiceException, DSAccessException, FSAccessException; /** @@ -244,12 +259,11 @@ public byte[] getPlane(long pixelsID, int z, int t, int c) * Applies the settings to the passed images if the type is * ImageData. * - * @param pixelsID The id of the pixels set of reference. - * @param rootNodeType The type of nodes. Can either be - * ImageData, DatasetData or - * CategoryData. - * @param nodeIDs The id of the nodes to apply settings to. - * Mustn't be null. + * @param ctx The security context. + * @param pixelsID The id of the pixels set of reference. + * @param rootNodeType The type of nodes. + * @param nodeIDs The id of the nodes to apply settings to. + * Mustn't be null. * @return A map with two keys. A True key whose value * is a list of image's id, the settings have been applied to. * A False key whose value is a list @@ -259,8 +273,8 @@ public byte[] getPlane(long pixelsID, int z, int t, int c) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Map pasteRenderingSettings(long pixelsID, Class rootNodeType, - List nodeIDs) + public Map pasteRenderingSettings(SecurityContext ctx, long pixelsID, + Class rootNodeType, List nodeIDs) throws DSOutOfServiceException, DSAccessException; /** @@ -269,10 +283,11 @@ public Map pasteRenderingSettings(long pixelsID, Class rootNodeType, * Resets the settings to the passed images if the type is * ImageData. * - * @param rootNodeType The type of nodes. Can either be + * @param ctx The security context. + * @param rootNodeType The type of nodes. Can either be * ImageData, DatasetData. - * @param nodeIDs The id of the nodes to apply settings to. - * Mustn't be null. + * @param nodeIDs The id of the nodes to apply settings to. + * Mustn't be null. * @return A map with two keys. A True key whose value * is a list of image's id, the settings have been applied to. * A False key whose value is a list @@ -282,7 +297,8 @@ public Map pasteRenderingSettings(long pixelsID, Class rootNodeType, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Map resetRenderingSettings(Class rootNodeType, List nodeIDs) + public Map resetRenderingSettings(SecurityContext ctx, Class rootNodeType, + List nodeIDs) throws DSOutOfServiceException, DSAccessException; /** @@ -291,11 +307,11 @@ public Map resetRenderingSettings(Class rootNodeType, List nodeIDs) * Resets the settings to the passed images if the type is * ImageData. * - * @param rootNodeType The type of nodes. Can either be - * ImageData, DatasetData or - * CategoryData. - * @param nodeIDs The id of the nodes to apply settings to. - * Mustn't be null. + * @param ctx The security context. + * @param rootNodeType The type of nodes. Can either be + * ImageData, DatasetData + * @param nodeIDs The id of the nodes to apply settings to. + * Mustn't be null. * @return A map with two keys. A True key whose value * is a list of image's id, the settings have been applied to. * A False key whose value is a list @@ -305,8 +321,8 @@ public Map resetRenderingSettings(Class rootNodeType, List nodeIDs) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Map setMinMaxSettings(Class rootNodeType, - List nodeIDs) + public Map setMinMaxSettings(SecurityContext ctx, Class rootNodeType, + List nodeIDs) throws DSOutOfServiceException, DSAccessException; /** @@ -315,11 +331,10 @@ public Map setMinMaxSettings(Class rootNodeType, * Resets the settings to the passed images if the type is * ImageData. * - * @param rootNodeType The type of nodes. Can either be - * ImageData, DatasetData or - * CategoryData. - * @param nodeIDs The id of the nodes to apply settings to. - * Mustn't be null. + * @param rootNodeType The type of nodes. Can either be + * ImageData, DatasetData. + * @param nodeIDs The id of the nodes to apply settings to. + * Mustn't be null. * @return A map with two keys. A True key whose value * is a list of image's id, the settings have been applied to. * A False key whose value is a list @@ -329,8 +344,8 @@ public Map setMinMaxSettings(Class rootNodeType, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Map setOwnerRenderingSettings(Class rootNodeType, - List nodeIDs) + public Map setOwnerRenderingSettings(SecurityContext ctx, + Class rootNodeType, List nodeIDs) throws DSOutOfServiceException, DSAccessException; /** @@ -338,80 +353,88 @@ public Map setOwnerRenderingSettings(Class rootNodeType, * Returns a Map whose keys are the experimenter who created the rendering * settings and the value the settings itself. * - * @param pixelsID The id of the pixels set. - * @param userID The id of the user currently logged in. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param userID The id of the user currently logged in. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Map getRenderingSettings(long pixelsID, long userID) + public Map getRenderingSettings(SecurityContext ctx, long pixelsID, + long userID) throws DSOutOfServiceException, DSAccessException; /** * Retrieves the rendering setting related to a given set of pixels * for the specified user. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. - * @param userID The id of the user currently logged in. + * @param userID The id of the user currently logged in. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List getRenderingSettingsFor(long pixelsID, long userID) + public List getRenderingSettingsFor(SecurityContext ctx, + long pixelsID, long userID) throws DSOutOfServiceException, DSAccessException; /** * Creates a preview projected image * - * @param pixelsID The ID of the pixels set. - * @param startZ The first optical section. - * @param endZ The last optical section. - * @param stepping The stepping used during the projection. - * @param type The type of projection. + * @param ctx The security context. + * @param pixelsID The ID of the pixels set. + * @param startZ The first optical section. + * @param endZ The last optical section. + * @param stepping The stepping used during the projection. + * @param type The type of projection. * @param channels The collection of channels to project. * @return The buffered image representing the projected image. * @throws RenderingServiceException If the server cannot render the image. * @throws DSOutOfServiceException If the connection is broken, or logged * in. */ - public BufferedImage renderProjected(long pixelsID, int startZ, int endZ, - int stepping, int type, List channels) + public BufferedImage renderProjected(SecurityContext ctx, long pixelsID, + int startZ, int endZ, int stepping, int type, List channels) throws RenderingServiceException, DSOutOfServiceException; /** * Creates a preview projected image * - * @param pixelsID The ID of the pixels set. - * @param startZ The first optical section. - * @param endZ The last optical section. - * @param stepping The stepping used during the projection. - * @param type The type of projection. + * @param ctx The security context. + * @param pixelsID The ID of the pixels set. + * @param startZ The first optical section. + * @param endZ The last optical section. + * @param stepping The stepping used during the projection. + * @param type The type of projection. * @param channels The collection of channels to project. * @return The buffered image representing the projected image. * @throws RenderingServiceException If the server cannot render the image. * @throws DSOutOfServiceException If the connection is broken, or logged * in. */ - public TextureData renderProjectedAsTexture(long pixelsID, int startZ, - int endZ, int stepping, int type, List channels) + public TextureData renderProjectedAsTexture(SecurityContext ctx, + long pixelsID, int startZ, int endZ, int stepping, int type, + List channels) throws RenderingServiceException, DSOutOfServiceException; /** * Projects the specified set of pixels according to the projection's * parameters. Adds the created image to the passed dataset. * + * @param ctx The security context. * @param ref The object hosting the projection's parameters. * @return The newly created image. * @throws DSOutOfServiceException If the connection is broken, or logged * in. - * @throws DSAccessException If an error occured while trying to + * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public ImageData projectImage(ProjectionParam ref) + public ImageData projectImage(SecurityContext ctx, ProjectionParam ref) throws DSOutOfServiceException, DSAccessException; /** @@ -421,10 +444,11 @@ public ImageData projectImage(ProjectionParam ref) * settings have been successfully created and updated, false * otherwise. * - * @param pixelsID The id of the pixels set to handle. + * @param ctx The security context. + * @param pixelsID The id of the pixels set to handle. * @param rndToCopy The rendering settings to copy to the newly created one. - * @param indexes Collection of channel's indexes. - * Mustn't be null. + * @param indexes Collection of channel's indexes. + * Mustn't be null. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. @@ -433,41 +457,42 @@ public ImageData projectImage(ProjectionParam ref) * @throws FSAccessException If an error occurred while trying to * retrieve data using OMERO.fs. */ - public Boolean createRenderingSettings(long pixelsID, RndProxyDef rndToCopy, - List indexes) + public Boolean createRenderingSettings(SecurityContext ctx, long pixelsID, + RndProxyDef rndToCopy, List indexes) throws DSOutOfServiceException, DSAccessException, FSAccessException; /** * Loads the plane info objects related to the passed pixels set. * - * @param pixelsID The id of the pixels set. - * @param z The selected z-section or -1. - * @param t The selected time-point or -1. - * @param channel The selected time-point or -1. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param z The selected z-section or -1. + * @param t The selected time-point or -1. + * @param channel The selected time-point or -1. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection loadPlaneInfo(long pixelsID, int z, int t, int channel) + public Collection loadPlaneInfo(SecurityContext ctx, + long pixelsID, int z, int t, int channel) throws DSOutOfServiceException, DSAccessException; /** * Imports the collection of images into the specified container. * - * @param object The object hosting the information about the - * file to import. + * @param object The object hosting the information about the file to import. * @param importable The file to import. Mustn't be null. - * @param userID The id of the user. - * @param groupID The id of the group. - * @param close Pass true to close the import, - * false otherwise. + * @param userID The id of the user. + * @param groupIDThe id of the group. + * @param close Pass true to close the import, + * false otherwise. * @return See above. * @throws ImportException If an error occurred while importing. */ - public Object importFile(ImportableObject object, ImportableFile importable, - long userID, long groupID, boolean close) + public Object importFile(ImportableObject object, + ImportableFile importable, long userID, long groupID, boolean close) throws ImportException; /** @@ -480,10 +505,11 @@ public Object importFile(ImportableObject object, ImportableFile importable, /** * Creates a movie. Returns script call-back. * - * @param imageID The id of the image. - * @param pixelsID The id of the pixels set. - * @param channels The channels to map. - * @param param The parameters to create the movie. + * @param ctx The security context. + * @param imageID The id of the image. + * @param pixelsID The id of the pixels set. + * @param channels The channels to map. + * @param param The parameters to create the movie. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. @@ -491,72 +517,81 @@ public Object importFile(ImportableObject object, ImportableFile importable, * retrieve data from OMEDS service. * @throws ProcessException If an error occurred while running the script. */ - public ScriptCallback createMovie(long imageID, long pixelsID, - List channels, MovieExportParam param) + public ScriptCallback createMovie(SecurityContext ctx, + long imageID, long pixelsID, List channels, + MovieExportParam param) throws ProcessException, DSOutOfServiceException, DSAccessException; /** * Loads the ROI related to the specified image and the file. * - * @param imageID The image's ID. - * @param fileIDs The id of the original file. - * @param userID The user's ID. + * @param ctx The security context. + * @param imageID The image's ID. + * @param fileIDs The id of the original file. + * @param userID The user's ID. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List loadROI(long imageID, List fileIDs, - long userID) + public List loadROI(SecurityContext ctx, long imageID, + List fileIDs, long userID) throws DSOutOfServiceException, DSAccessException; /** * Loads the ROI related to the specified image. * - * @param imageID The image's ID. - * @param userID The user's ID. + * @param ctx The security context. + * @param imageID The image's ID. + * @param userID The user's ID. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List loadROIFromServer(long imageID, long userID) + public List loadROIFromServer(SecurityContext ctx, long imageID, + long userID) throws DSOutOfServiceException, DSAccessException; /** * Exports the passed image as an XML file. * + * @param ctx The security context. * @param imageID The ID of the image. - * @param folder The folder where to export the image. + * @param folder The folder where to export the image. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object exportImageAsOMETiff(long imageID, File folder) + public Object exportImageAsOMETiff(SecurityContext ctx, long imageID, + File folder) throws DSOutOfServiceException, DSAccessException; /** * Saves the ROI related to the specified image to the server * - * @param imageID The image's ID. - * @param userID The user's ID. - * @param roiList The list of ROI to save. + * @param ctx The security context. + * @param imageID The image's ID. + * @param userID The user's ID. + * @param roiList The list of ROI to save. * @return True if save successful. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List saveROI(long imageID, long userID, List roiList) + public List saveROI(SecurityContext ctx, long imageID, + long userID, List roiList) throws DSOutOfServiceException, DSAccessException; /** * Creates a figure composed of the specified objects. * + * @param ctx The security context. * @param ids The objects to use for the figure. * @param type The type of object to handle. * @param parameters The parameters to create the figure. @@ -567,14 +602,15 @@ public List saveROI(long imageID, long userID, List roiList) * retrieve data from OMEDS service. * @throws ProcessException If an error occurred while running the script. */ - public ScriptCallback createFigure(List ids, Class type, - Object parameters) + public ScriptCallback createFigure(SecurityContext ctx, + List ids, Class type, Object parameters) throws ProcessException, DSOutOfServiceException, DSAccessException; /** * Renders the passed plane with or without overlays depending on the * parameters. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param pd The plane to render. * @param tableID The id of the table hosting the mask. @@ -584,40 +620,27 @@ public ScriptCallback createFigure(List ids, Class type, * @return See above. * @throws RenderingServiceException If the server cannot render the image. */ - public Object renderOverLays(long pixelsID, PlaneDef pd, long tableID, - Map overlays, boolean asTexture) + public Object renderOverLays(SecurityContext ctx, long pixelsID, + PlaneDef pd, long tableID, Map overlays, + boolean asTexture) throws RenderingServiceException; - - + /** * Loads the measurement associated to a given object. * - * @param type The type of the object. - * @param id The id of the object. - * @param userID The id of the user who added attachments to the object - * or -1 if the user is not specified. + * @param ctx The security context. + * @param type The type of the object. + * @param id The id of the object. + * @param userID The id of the user who added attachments to the object + * or -1 if the user is not specified. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection loadROIMeasurements(Class type, long id, long userID) - throws DSOutOfServiceException, DSAccessException; - - /** - * Performs a basic FRAP. Returns the file hosting the results. - * - * @param ids The objects to analyze. - * @param type The type of object to analyze. - * @param param The extra parameters. - * @return See above. - * @throws DSOutOfServiceException If the connection is broken, or logged - * in. - * @throws DSAccessException If an error occurred while trying to - * retrieve data from OMEDS service. - */ - public DataObject analyseFrap(List ids, Class type, Object param) + public Collection loadROIMeasurements(SecurityContext ctx, Class type, + long id, long userID) throws DSOutOfServiceException, DSAccessException; /** @@ -626,6 +649,7 @@ public DataObject analyseFrap(List ids, Class type, Object param) * If a user is specified, returns the scripts owned by the specified * user. * + * @param ctx The security context. * @param userID The id of the experimenter or -1. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -633,12 +657,14 @@ public DataObject analyseFrap(List ids, Class type, Object param) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List loadAvailableScripts(long userID) + public List loadAvailableScripts(SecurityContext ctx, + long userID) throws DSOutOfServiceException, DSAccessException; /** * Returns all the scripts with a UI. * + * @param ctx The security context. * @param userID The id of the experimenter or -1. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -646,34 +672,37 @@ public List loadAvailableScripts(long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List loadAvailableScriptsWithUI() + public List loadAvailableScriptsWithUI(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException; /** * Loads the specified script and its parameters. * + * @param ctx The security context. * @param scriptID The id of the script. * @return See above. * @throws ProcessException If the script could not be loaded. */ - public ScriptObject loadScript(long scriptID) + public ScriptObject loadScript(SecurityContext ctx, long scriptID) throws ProcessException; /** * Returns all the scripts currently stored into the system. * + * @param ctx The security context. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Map getScriptsAsString() + public Map getScriptsAsString(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException; /** * Runs the passed script. * + * @param ctx The security context. * @param script The script to run. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -682,12 +711,13 @@ public Map getScriptsAsString() * retrieve data from OMEDS service. * @throws ProcessException If an error occurred while running the script. */ - public ScriptCallback runScript(ScriptObject script) + public ScriptCallback runScript(SecurityContext ctx, ScriptObject script) throws ProcessException, DSOutOfServiceException, DSAccessException; /** * Uploads the passed script. * + * @param ctx The security context. * @param script The script to run. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -695,16 +725,17 @@ public ScriptCallback runScript(ScriptObject script) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object uploadScript(ScriptObject script) + public Object uploadScript(SecurityContext ctx, ScriptObject script) throws DSOutOfServiceException, DSAccessException; /** * Retrieves the thumbnails corresponding to the passed collection of * files. * - * @param files The files to handle. + * @param ctx The security context. + * @param files The files to handle. * @param maxLength The maximum length of a thumbnail. - * @param userID The id of the user. + * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. @@ -713,12 +744,14 @@ public Object uploadScript(ScriptObject script) * @throws FSAccessException If an error occurred while trying to * retrieve data using OMERO.fs. */ - public Map getFSThumbnailSet( - List files, int maxLength, long userID) + public Map getFSThumbnailSet(SecurityContext ctx, + List files, int maxLength, long userID) throws DSAccessException, DSOutOfServiceException, FSAccessException; /** - * Get all the available workflows from the server for the user. + * Returns all the available workflows from the server for the user. + * + * @param ctx The security context. * @param userID The users id. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -726,12 +759,14 @@ public Map getFSThumbnailSet( * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List retrieveWorkflows(long userID) + public List retrieveWorkflows(SecurityContext ctx, + long userID) throws DSAccessException, DSOutOfServiceException; /** * Adds the workflows to the server for the user. * + * @param ctx The security context. * @param workflows See above. * @param userID The id of the user. * @return See above. @@ -740,13 +775,15 @@ public List retrieveWorkflows(long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object storeWorkflows(List workflows, long userID) - throws DSAccessException, DSOutOfServiceException; + public Object storeWorkflows(SecurityContext ctx, + List workflows, long userID) + throws DSAccessException, DSOutOfServiceException; /** * Retrieves the thumbnails corresponding to the passed collection of * experimenter. * + * @param ctx The security context. * @param experimenters The experimenters to handle. * @param maxLength The maximum length of a thumbnail. * @return See above. @@ -756,12 +793,13 @@ public Object storeWorkflows(List workflows, long userID) * retrieve data from OMEDS service. */ public Map getExperimenterThumbnailSet( - List experimenters, int maxLength) + SecurityContext ctx, List experimenters, int maxLength) throws DSAccessException, DSOutOfServiceException; /** * Saves locally the images as JPEG. * + * @param ctx The security context. * @param param Hosts the information about the objects to save, * where to save etc. * @return See above. @@ -771,13 +809,14 @@ public Map getExperimenterThumbnailSet( * retrieve data from OMEDS service. * @throws ProcessException If an error occurred while running the script. */ - public ScriptCallback saveAs(SaveAsParam param) + public ScriptCallback saveAs(SecurityContext ctx, SaveAsParam param) throws ProcessException, DSAccessException, DSOutOfServiceException; /** * Indicates if the image corresponding to the specified pixels set is * a large image. * + * @param ctx The security context. * @param pixelsId The identifier of the pixels set. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -786,7 +825,7 @@ public ScriptCallback saveAs(SaveAsParam param) * retrieve data from OMEDS service. * @throws ProcessException If an error occurred while running the script. */ - public Boolean isLargeImage(long pixelsId) + public Boolean isLargeImage(SecurityContext ctx, long pixelsId) throws DSAccessException, DSOutOfServiceException; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroImageServiceImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroImageServiceImpl.java index 506b398f501..cbd8f1b0a4e 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroImageServiceImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroImageServiceImpl.java @@ -75,6 +75,7 @@ import org.openmicroscopy.shoola.env.data.model.ThumbnailData; import org.openmicroscopy.shoola.env.data.util.ModelMapper; import org.openmicroscopy.shoola.env.data.util.PojoMapper; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StatusLabel; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.env.rnd.RenderingServiceException; @@ -123,6 +124,7 @@ class OmeroImageServiceImpl /** * Imports the specified candidates. * + * @param ctx The security context. * @param candidates The file to import. * @param status The original status. * @param object The object hosting information about the import. @@ -133,13 +135,13 @@ class OmeroImageServiceImpl * @param userID The identifier of the user. * @param hcs Value returns by the import containers. */ - private Boolean importCandidates(Map files, - StatusLabel status, ImportableObject object, boolean archived, - IObject ioContainer, List list, long userID, - boolean close, boolean hcs) + private Boolean importCandidates(SecurityContext ctx, + Map files, StatusLabel status, + ImportableObject object, boolean archived, IObject ioContainer, + List list, long userID, boolean close, boolean hcs) { if (status.isMarkedAsCancel()) { - gateway.closeImport(); + gateway.closeImport(ctx); return Boolean.valueOf(false); } boolean thumbnail = object.isLoadThumbnail(); @@ -177,18 +179,18 @@ private Boolean importCandidates(Map files, if (!label.isMarkedAsCancel()) { try { if (ioContainer == null) label.setNoContainer(); - result = gateway.importImage(object, ioContainer, file, + result = gateway.importImage(ctx, object, ioContainer, file, label, archived, toClose); if (result instanceof ImageData) { image = (ImageData) result; images.add(image); if (thumbnail) label.setFile(file, - createImportedImage(userID, image)); + createImportedImage(ctx, userID, image)); else label.setFile(file, image); } else if (result instanceof Set) { ll = (Set) result; - annotatedImportedImage(list, ll); + annotatedImportedImage(ctx, list, ll); images.addAll(ll); kk = ll.iterator(); converted = new ArrayList(ll.size()); @@ -196,7 +198,7 @@ private Boolean importCandidates(Map files, image = kk.next(); if (thumbnail) converted.add( - createImportedImage(userID, image)); + createImportedImage(ctx, userID, image)); else converted.add(image); } label.setFile(file, converted); @@ -206,19 +208,20 @@ private Boolean importCandidates(Map files, } } } - annotatedImportedImage(list, images); - if (close) gateway.closeImport(); + annotatedImportedImage(ctx, list, images); + if (close) gateway.closeImport(ctx); return null; } /** * Annotates the imported images. * + * @param ctx The security context. * @param annotations The annotations to add. * @param images The imported images. */ - private void annotatedImportedImage(List annotations, - Collection images) + private void annotatedImportedImage(SecurityContext ctx, + List annotations, Collection images) { if (annotations.size() == 0 || images.size() == 0) return; Iterator i = images.iterator(); @@ -237,7 +240,7 @@ private void annotatedImportedImage(List annotations, } if (list.size() == 0) return; try { - gateway.saveAndReturnObject(list, new HashMap()); + gateway.saveAndReturnObject(ctx, list, new HashMap()); } catch (Exception e) { //ignore } @@ -246,18 +249,20 @@ private void annotatedImportedImage(List annotations, /** * Creates a thumbnail for the imported image. * + * @param ctx The security context. * @param userID The identifier of the user. * @param image The image to handle. * @return See above. */ - private Object createImportedImage(long userID, ImageData image) + private Object createImportedImage(SecurityContext ctx, long userID, + ImageData image) { if (image != null) { ThumbnailData data; try { PixelsData pix = image.getDefaultPixels(); BufferedImage img = createImage( - gateway.getThumbnailByLongestSide(pix.getId(), + gateway.getThumbnailByLongestSide(ctx, pix.getId(), Factory.THUMB_DEFAULT_WIDTH)); data = new ThumbnailData(image.getId(), img, userID, true); data.setImage(image); @@ -276,24 +281,26 @@ private Object createImportedImage(long userID, ImageData image) /** * Formats the result of an image import. * + * @param ctx The security context. * @param image The image to handle. * @param userID The user's id. * @param thumbnail Pass true if thumbnail has to be created, * false otherwise. * @return See above. */ - private Object formatResult(ImageData image, long userID, boolean thumbnail) + private Object formatResult(SecurityContext ctx, ImageData image, + long userID, boolean thumbnail) { Boolean backoff = null; try { PixelsData pixels = image.getDefaultPixels(); - backoff = gateway.isLargeImage(pixels.getId()); + backoff = gateway.isLargeImage(ctx, pixels.getId()); } catch (Exception e) {} //if (backoff != null && backoff.booleanValue()) // return new ThumbnailData(image, backoff); if (thumbnail) { - ThumbnailData thumb = (ThumbnailData) createImportedImage(userID, - image); + ThumbnailData thumb = (ThumbnailData) createImportedImage(ctx, + userID, image); thumb.setBackOffForPyramid(backoff); return thumb; } @@ -369,6 +376,135 @@ private BufferedImage createImage(String path) } } + /** + * Recycles or creates the container. + * + * @param ctx The security context. + * @param dataset The dataset to create or recycle. + * @param container The container to create and link the dataset to. + * @param object The object hosting the import option. + * @return See above. + * @throws DSOutOfServiceException If the connection is broken, or logged in + * @throws DSAccessException If an error occurred while trying to + * retrieve data from OMERO service. + */ + private IObject determineContainer(SecurityContext ctx, DatasetData dataset, + DataObject container, ImportableObject object) + throws DSOutOfServiceException, DSAccessException + { + IObject ioContainer = null; + Map parameters = new HashMap(); + DataObject createdData; + IObject project = null; + IObject link; + if (dataset != null) { //dataset + if (dataset.getId() <= 0) { + //Check if it has been already been created. + //need to create it first + if (container != null) { + if (container.getId() <= 0) { + //project needs to be created to. + createdData = object.hasObjectBeenCreated( + container); + if (createdData == null) { + project = gateway.saveAndReturnObject(ctx, + container.asIObject(), parameters); + //register + object.addNewDataObject( + PojoMapper.asDataObject( + project)); + //now create the dataset + ioContainer = gateway.saveAndReturnObject(ctx, + dataset.asIObject(), parameters); + //register + object.registerDataset( + project.getId().getValue(), + (DatasetData) + PojoMapper.asDataObject( + ioContainer)); + link = (ProjectDatasetLink) + ModelMapper.linkParentToChild( + (Dataset) ioContainer, + (Project) project); + link = (ProjectDatasetLink) + gateway.saveAndReturnObject(ctx, link, + parameters); + } else { + DatasetData d; + d = object.isDatasetCreated( + createdData.getId(), dataset); + if (d == null) { + ioContainer = gateway.saveAndReturnObject(ctx, + dataset.asIObject(), parameters); + //register + object.registerDataset( + createdData.getId(), + (DatasetData) + PojoMapper.asDataObject( + ioContainer)); + link = (ProjectDatasetLink) + ModelMapper.linkParentToChild( + (Dataset) ioContainer, + (Project) createdData.asProject()); + link = (ProjectDatasetLink) + gateway.saveAndReturnObject(ctx, link, + parameters); + } else ioContainer = d.asIObject(); + } + } else { //project already exists. + createdData = object.isDatasetCreated( + container.getId(), dataset); + if (createdData == null) { + ioContainer = gateway.saveAndReturnObject(ctx, + dataset.asIObject(), parameters); + //register + object.registerDataset( + container.getId(), + (DatasetData) + PojoMapper.asDataObject( + ioContainer)); + link = (ProjectDatasetLink) + ModelMapper.linkParentToChild( + (Dataset) ioContainer, + (Project) container.asProject()); + link = (ProjectDatasetLink) + gateway.saveAndReturnObject(ctx, link, + parameters); + } else ioContainer = createdData.asIObject(); + } + } else { //dataset w/o project. + createdData = object.hasObjectBeenCreated(dataset); + if (createdData == null) { + ioContainer = gateway.saveAndReturnObject(ctx, + dataset.asIObject(), parameters); + //register + object.addNewDataObject(PojoMapper.asDataObject( + ioContainer)); + } else ioContainer = createdData.asIObject(); + } + } else ioContainer = dataset.asIObject(); + } else { //check on the container. + if (container != null) { + if (container.getId() <= 0) { + //container needs to be created to. + createdData = object.hasObjectBeenCreated( + container); + if (createdData == null) { + ioContainer = gateway.saveAndReturnObject(ctx, + container.asIObject(), parameters); + //register + object.addNewDataObject( + PojoMapper.asDataObject( + project)); + } else { + ioContainer = createdData.asIObject(); + } + } else ioContainer = container.asIObject(); + } + } + return ioContainer; + } + /** * Creates a new instance. * @@ -387,16 +523,17 @@ private BufferedImage createImage(String path) } /** Shuts down all active rendering engines. */ - void shutDown() + void shutDown(SecurityContext ctx) { PixelsServicesFactory.shutDownRenderingControls(context); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#loadRenderingControl(long) + * @see OmeroImageService#loadRenderingControl(SecurityContext, long) */ - public RenderingControl loadRenderingControl(long pixelsID) + public RenderingControl loadRenderingControl(SecurityContext ctx, + long pixelsID) throws DSOutOfServiceException, DSAccessException, FSAccessException { RenderingControl proxy = @@ -418,10 +555,11 @@ public RenderingControl loadRenderingControl(long pixelsID) } ExperimenterData exp = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); - RenderingEnginePrx re = gateway.createRenderingEngine(pixelsID); - Pixels pixels = gateway.getPixels(pixelsID); - List defs = gateway.getRenderingSettingsFor(pixelsID, - exp.getId()); + RenderingEnginePrx re = gateway.createRenderingEngine(ctx, + pixelsID); + Pixels pixels = gateway.getPixels(ctx, pixelsID); + List defs = gateway.getRenderingSettingsFor( + ctx, pixelsID, exp.getId()); Collection l = pixels.copyChannels(); Iterator i = l.iterator(); List m = new ArrayList(l.size()); @@ -439,34 +577,15 @@ public RenderingControl loadRenderingControl(long pixelsID) /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#renderImage(long, PlaneDef, boolean, boolean) + * @see OmeroImageService#renderImage(SecurityContext, long, PlaneDef, boolean, boolean) */ - public Object renderImage(long pixelsID, PlaneDef pDef, boolean asTexture, - boolean largeImage) + public Object renderImage(SecurityContext ctx, long pixelsID, PlaneDef pDef, + boolean asTexture, boolean largeImage) throws RenderingServiceException { try { - //if (!largeImage) - return PixelsServicesFactory.render(context, + return PixelsServicesFactory.render(context, Long.valueOf(pixelsID), pDef, asTexture, largeImage); - /* - List ids = new ArrayList(); - ids.add(pixelsID); - int w = pDef.x; - int h = pDef.y; - int max = w; - if (max < h) max = h; - if (max > RenderingControl.MAX_SIZE_THREE) - max = RenderingControl.MAX_SIZE_THREE; - Map m = gateway.getThumbnailSet(ids, max, true); - byte[] values = (byte[]) m.get(pixelsID); - if (asTexture) { - values = WriterImage.bytesToBytes(values); - return PixelsServicesFactory.createTexture(values, w, h); - } else { - return createImage(values); - } - */ } catch (Exception e) { throw new RenderingServiceException("RenderImage", e); } @@ -474,26 +593,31 @@ public Object renderImage(long pixelsID, PlaneDef pDef, boolean asTexture, /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#shutDown(long) + * @see OmeroImageService#shutDown(SecurityContext,long) */ - public void shutDown(long pixelsID) + public void shutDown(SecurityContext ctx, long pixelsID) { - if (!PixelsServicesFactory.shutDownRenderingControl(context, pixelsID)) - gateway.removeREService(pixelsID); + try { + if (!PixelsServicesFactory.shutDownRenderingControl(context, + pixelsID)) + gateway.removeREService(ctx, pixelsID); + } catch (Exception e) { + context.getLogger().error(this, e.getMessage()); + } } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#getThumbnail(long, int, int, long) + * @see OmeroImageService#getThumbnail(SecurityContext, long, int, int, long) */ - public BufferedImage getThumbnail(long pixID, int sizeX, int sizeY, - long userID) + public BufferedImage getThumbnail(SecurityContext ctx,long pixID, int sizeX, + int sizeY, long userID) throws RenderingServiceException { try { if (pixID < 0) return null; if (!isBinaryAvailable()) return null; - return createImage(gateway.getThumbnail(pixID, sizeX, sizeY, + return createImage(gateway.getThumbnail(ctx, pixID, sizeX, sizeY, userID)); } catch (Exception e) { if (e instanceof DSOutOfServiceException) { @@ -506,9 +630,10 @@ public BufferedImage getThumbnail(long pixID, int sizeX, int sizeY, /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#getThumbnailSet(List, int) + * @see OmeroImageService#getThumbnailSet(SecurityContext, List, int) */ - public Map getThumbnailSet(List pixelsID, int max) + public Map getThumbnailSet(SecurityContext ctx, + List pixelsID, int max) throws RenderingServiceException { Map r = new HashMap(); @@ -547,7 +672,7 @@ public Map getThumbnailSet(List pixelsID, int max) Map m = new HashMap(); Map map; while (j.hasNext()) { - map = gateway.getThumbnailSet((List) j.next(), max, false); + map = gateway.getThumbnailSet(ctx, (List) j.next(), max, false); m.putAll(map); } //m = gateway.getThumbnailSet(pixelsID, max, false); @@ -594,9 +719,10 @@ public Map getThumbnailSet(List pixelsID, int max) /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#reloadRenderingService(long) + * @see OmeroImageService#reloadRenderingService(SecurityContext, long) */ - public RenderingControl reloadRenderingService(long pixelsID) + public RenderingControl reloadRenderingService(SecurityContext ctx, + long pixelsID) throws RenderingServiceException { RenderingControl proxy = @@ -604,7 +730,8 @@ public RenderingControl reloadRenderingService(long pixelsID) Long.valueOf(pixelsID), false); if (proxy == null) return null; try { - RenderingEnginePrx re = gateway.createRenderingEngine(pixelsID); + RenderingEnginePrx re = gateway.createRenderingEngine(ctx, + pixelsID); return PixelsServicesFactory.reloadRenderingControl(context, pixelsID, re); } catch (Exception e) { @@ -615,9 +742,10 @@ public RenderingControl reloadRenderingService(long pixelsID) /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#resetRenderingService(long) + * @see OmeroImageService#resetRenderingService(SecurityContext, long) */ - public RenderingControl resetRenderingService(long pixelsID) + public RenderingControl resetRenderingService(SecurityContext ctx, + long pixelsID) throws RenderingServiceException { RenderingControl proxy = @@ -625,10 +753,12 @@ public RenderingControl resetRenderingService(long pixelsID) Long.valueOf(pixelsID), false); if (proxy == null) return null; try { - RenderingEnginePrx re = gateway.createRenderingEngine(pixelsID); + RenderingEnginePrx re = gateway.createRenderingEngine(ctx, + pixelsID); ExperimenterData exp = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); - RenderingDef def = gateway.getRenderingDef(pixelsID, exp.getId()); + RenderingDef def = gateway.getRenderingDef(ctx, pixelsID, + exp.getId()); return PixelsServicesFactory.resetRenderingControl(context, pixelsID, re, def); } catch (Exception e) { @@ -639,117 +769,114 @@ public RenderingControl resetRenderingService(long pixelsID) /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#loadPixels(long) + * @see OmeroImageService#loadPixels(SecurityContext, long) */ - public PixelsData loadPixels(long pixelsID) + public PixelsData loadPixels(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException { if (pixelsID < 0) throw new IllegalArgumentException("Pixels' ID not valid."); return (PixelsData) PojoMapper.asDataObject( - gateway.getPixels(pixelsID)); + gateway.getPixels(ctx, pixelsID)); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#getPlane(long, int, int, int) + * @see OmeroImageService#getPlane(SecurityContext, long, int, int, int) */ - public byte[] getPlane(long pixelsID, int z, int t, int c) + public byte[] getPlane(SecurityContext ctx, long pixelsID, int z, int t, + int c) throws DSOutOfServiceException, DSAccessException, FSAccessException { if (pixelsID < 0) throw new IllegalArgumentException("Pixels' ID not valid."); - return gateway.getPlane(pixelsID, z, t, c); + return gateway.getPlane(ctx, pixelsID, z, t, c); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#pasteRenderingSettings(long, Class, List) + * @see OmeroImageService#pasteRenderingSettings(SecurityContext, long, + * Class, List) */ - public Map pasteRenderingSettings(long pixelsID, Class rootNodeType, - List nodesID) + public Map pasteRenderingSettings(SecurityContext ctx, long pixelsID, + Class rootNodeType, List nodesID) throws DSOutOfServiceException, DSAccessException { if (nodesID == null || nodesID.size() == 0) throw new IllegalArgumentException("No nodes specified."); - return gateway.pasteRenderingSettings(pixelsID, rootNodeType, nodesID); + return gateway.pasteRenderingSettings(ctx, pixelsID, rootNodeType, + nodesID); } /** * Implemented as specified by {@link OmeroImageService}. * @see OmeroImageService#resetRenderingSettings(Class, List) */ - public Map resetRenderingSettings(Class rootNodeType, List nodesID) + public Map resetRenderingSettings(SecurityContext ctx, Class rootNodeType, + List nodesID) throws DSOutOfServiceException, DSAccessException { if (nodesID == null || nodesID.size() == 0) throw new IllegalArgumentException("No nodes specified."); - return gateway.resetRenderingSettings(rootNodeType, nodesID); + return gateway.resetRenderingSettings(ctx, rootNodeType, nodesID); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#setMinMaxSettings(Class, List) + * @see OmeroImageService#setMinMaxSettings(SecurityContext, Class, List) */ - public Map setMinMaxSettings(Class rootNodeType, List nodesID) + public Map setMinMaxSettings(SecurityContext ctx, Class rootNodeType, + List nodesID) throws DSOutOfServiceException, DSAccessException { if (nodesID == null || nodesID.size() == 0) throw new IllegalArgumentException("No nodes specified."); - return gateway.setMinMaxSettings(rootNodeType, nodesID); + return gateway.setMinMaxSettings(ctx, rootNodeType, nodesID); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#setOwnerRenderingSettings(Class, List) + * @see OmeroImageService#setOwnerRenderingSettings(SecurityContext, Class, + * List) */ - public Map setOwnerRenderingSettings(Class rootNodeType, List nodesID) + public Map setOwnerRenderingSettings(SecurityContext ctx, + Class rootNodeType, List nodesID) throws DSOutOfServiceException, DSAccessException { if (nodesID == null || nodesID.size() == 0) throw new IllegalArgumentException("No nodes specified."); - return gateway.setOwnerRenderingSettings(rootNodeType, nodesID); + return gateway.setOwnerRenderingSettings(ctx, rootNodeType, nodesID); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#getRenderingSettings(long, long) + * @see OmeroImageService#getRenderingSettings(ctx, long, long) */ - public Map getRenderingSettings(long pixelsID, long userID) + public Map getRenderingSettings(SecurityContext ctx, long pixelsID, + long userID) throws DSOutOfServiceException, DSAccessException { - return gateway.getRenderingSettings(pixelsID, userID); - /* - Map m = gateway.getRenderingSettings(pixelsID, userID); - if (m == null) return null; - Iterator i = m.keySet().iterator(); - Object key; - Map results = new HashMap(m.size()); - while (i.hasNext()) { - key = i.next(); - results.put(key, - PixelsServicesFactory.convert((RenderingDef) m.get(key))); - } - return results; - */ + return gateway.getRenderingSettings(ctx, pixelsID, userID); } /** * Implemented as specified by {@link OmeroImageService}. * @see OmeroImageService#getRenderingSettingsFor(long, long) */ - public List getRenderingSettingsFor(long pixelsID, long userID) + public List getRenderingSettingsFor(SecurityContext ctx, + long pixelsID, long userID) throws DSOutOfServiceException, DSAccessException { - return gateway.getRenderingSettingsFor(pixelsID, userID); + return gateway.getRenderingSettingsFor(ctx, pixelsID, userID); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#renderProjected(long, int, int, int, int, List) + * @see OmeroImageService#renderProjected(SecurityContext, long, int, int, + * int, int, List) */ - public BufferedImage renderProjected(long pixelsID, int startZ, int endZ, - int stepping, int type, List channels) + public BufferedImage renderProjected(SecurityContext ctx, long pixelsID, + int startZ, int endZ, int stepping, int type, List channels) throws RenderingServiceException, DSOutOfServiceException { return PixelsServicesFactory.renderProjected(context, pixelsID, startZ, @@ -758,11 +885,12 @@ public BufferedImage renderProjected(long pixelsID, int startZ, int endZ, /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#renderProjectedAsTexture(long, int, int, int, int, - * List) + * @see OmeroImageService#renderProjectedAsTexture(SecurityContext, long, + * int, int, int, int, List) */ - public TextureData renderProjectedAsTexture(long pixelsID, int startZ, - int endZ, int stepping, int type, List channels) + public TextureData renderProjectedAsTexture(SecurityContext ctx, + long pixelsID, int startZ, int endZ, int stepping, int type, + List channels) throws RenderingServiceException, DSOutOfServiceException { return PixelsServicesFactory.renderProjectedAsTexture(context, @@ -771,23 +899,23 @@ public TextureData renderProjectedAsTexture(long pixelsID, int startZ, /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#projectImage(ProjectionParam) + * @see OmeroImageService#projectImage(SecurityContext, ProjectionParam) */ - public ImageData projectImage(ProjectionParam ref) + public ImageData projectImage(SecurityContext ctx, ProjectionParam ref) throws DSOutOfServiceException, DSAccessException { if (ref == null) return null; - ImageData image = gateway.projectImage(ref.getPixelsID(), + ImageData image = gateway.projectImage(ctx, ref.getPixelsID(), ref.getStartT(), ref.getEndT(), ref.getStartZ(), - ref.getEndZ(), ref.getStepping(), ref.getProjectionType(), + ref.getEndZ(), ref.getStepping(), ref.getProjectionType(), ref.getChannels(), ref.getName(), ref.getPixelsType()); if (image == null) return null; Image img = image.asImage(); img.setDescription(omero.rtypes.rstring(ref.getDescription())); image = (ImageData) - PojoMapper.asDataObject(gateway.updateObject(img, + PojoMapper.asDataObject(gateway.updateObject(ctx, img, new Parameters())); - image = gateway.getImage(image.getId(), new Parameters()); + image = gateway.getImage(ctx, image.getId(), new Parameters()); List datasets = ref.getDatasets(); if (datasets != null && datasets.size() > 0) { Iterator i = datasets.iterator(); @@ -804,8 +932,9 @@ public ImageData projectImage(ProjectionParam ref) i = toCreate.iterator(); OmeroDataService svc = context.getDataService(); while (i.hasNext()) { - existing.add((DatasetData) svc.createDataObject(i.next(), - ref.getDatasetParent(), null)); + existing.add((DatasetData) + svc.createDataObject(ctx, i.next(), + ref.getDatasetParent(), null)); } } List links = new ArrayList(datasets.size()); @@ -816,30 +945,31 @@ public ImageData projectImage(ProjectionParam ref) l = ModelMapper.linkParentToChild(img, i.next().asIObject()); links.add(l); } - gateway.createObjects(links); + gateway.createObjects(ctx, links); } return image; } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#createRenderingSettings(long, RndProxyDef, List) + * @see OmeroImageService#createRenderingSettings(SecurityContext, long, + * RndProxyDef, List) */ - public Boolean createRenderingSettings(long pixelsID, RndProxyDef rndToCopy, - List indexes) + public Boolean createRenderingSettings(SecurityContext ctx, long pixelsID, + RndProxyDef rndToCopy, List indexes) throws DSOutOfServiceException, DSAccessException, FSAccessException { if (rndToCopy == null) { - RenderingDef def = gateway.createRenderingDef(pixelsID); + RenderingDef def = gateway.createRenderingDef(ctx, pixelsID); return (def != null); } - RenderingControl rndControl = loadRenderingControl(pixelsID); + RenderingControl rndControl = loadRenderingControl(ctx, pixelsID); try { rndControl.copyRenderingSettings(rndToCopy, indexes); //save them rndControl.saveCurrentSettings(); //discard it - shutDown(pixelsID); + shutDown(ctx, pixelsID); } catch (Exception e) { throw new DSAccessException("Unable to copy the " + "rendering settings."); @@ -850,140 +980,13 @@ public Boolean createRenderingSettings(long pixelsID, RndProxyDef rndToCopy, /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#loadPlaneInfo(long, int, int, int) - */ - public Collection loadPlaneInfo(long pixelsID, int z, int t, int channel) - throws DSOutOfServiceException, DSAccessException - { - return gateway.loadPlaneInfo(pixelsID, z, t, channel); - } - - /** - * Recycles or creates the container. - * - * @param dataset The dataset to create or recycle. - * @param container The container to create and link the dataset to. - * @param object The object hosting the import option. - * @return See above. - * @throws DSOutOfServiceException If the connection is broken, or logged in - * @throws DSAccessException If an error occurred while trying to - * retrieve data from OMERO service. + * @see OmeroImageService#loadPlaneInfo(SecurityContext, long, int, int, int) */ - private IObject determineContainer(DatasetData dataset, - DataObject container, ImportableObject object) + public Collection loadPlaneInfo(SecurityContext ctx, long pixelsID, int z, + int t, int channel) throws DSOutOfServiceException, DSAccessException { - IObject ioContainer = null; - Map parameters = new HashMap(); - DataObject createdData; - IObject project = null; - IObject link; - if (dataset != null) { //dataset - if (dataset.getId() <= 0) { - //Check if it has been already been created. - //need to create it first - if (container != null) { - if (container.getId() <= 0) { - //project needs to be created to. - createdData = object.hasObjectBeenCreated( - container); - if (createdData == null) { - project = gateway.saveAndReturnObject( - container.asIObject(), parameters); - //register - object.addNewDataObject( - PojoMapper.asDataObject( - project)); - //now create the dataset - ioContainer = gateway.saveAndReturnObject( - dataset.asIObject(), parameters); - //register - object.registerDataset( - project.getId().getValue(), - (DatasetData) - PojoMapper.asDataObject( - ioContainer)); - link = (ProjectDatasetLink) - ModelMapper.linkParentToChild( - (Dataset) ioContainer, - (Project) project); - link = (ProjectDatasetLink) - gateway.saveAndReturnObject(link, - parameters); - } else { - DatasetData d; - d = object.isDatasetCreated( - createdData.getId(), dataset); - if (d == null) { - ioContainer = gateway.saveAndReturnObject( - dataset.asIObject(), parameters); - //register - object.registerDataset( - createdData.getId(), - (DatasetData) - PojoMapper.asDataObject( - ioContainer)); - link = (ProjectDatasetLink) - ModelMapper.linkParentToChild( - (Dataset) ioContainer, - (Project) createdData.asProject()); - link = (ProjectDatasetLink) - gateway.saveAndReturnObject(link, - parameters); - } else ioContainer = d.asIObject(); - } - } else { //project already exists. - createdData = object.isDatasetCreated( - container.getId(), dataset); - if (createdData == null) { - ioContainer = gateway.saveAndReturnObject( - dataset.asIObject(), parameters); - //register - object.registerDataset( - container.getId(), - (DatasetData) - PojoMapper.asDataObject( - ioContainer)); - link = (ProjectDatasetLink) - ModelMapper.linkParentToChild( - (Dataset) ioContainer, - (Project) container.asProject()); - link = (ProjectDatasetLink) - gateway.saveAndReturnObject(link, - parameters); - } else ioContainer = createdData.asIObject(); - } - } else { //dataset w/o project. - createdData = object.hasObjectBeenCreated(dataset); - if (createdData == null) { - ioContainer = gateway.saveAndReturnObject( - dataset.asIObject(), parameters); - //register - object.addNewDataObject(PojoMapper.asDataObject( - ioContainer)); - } else ioContainer = createdData.asIObject(); - } - } else ioContainer = dataset.asIObject(); - } else { //check on the container. - if (container != null) { - if (container.getId() <= 0) { - //container needs to be created to. - createdData = object.hasObjectBeenCreated( - container); - if (createdData == null) { - ioContainer = gateway.saveAndReturnObject( - container.asIObject(), parameters); - //register - object.addNewDataObject( - PojoMapper.asDataObject( - project)); - } else { - ioContainer = createdData.asIObject(); - } - } else ioContainer = container.asIObject(); - } - } - return ioContainer; + return gateway.loadPlaneInfo(ctx, pixelsID, z, t, channel); } /** @@ -1008,18 +1011,20 @@ private boolean isHCS(List containers) /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#importFile(ImportableObject, ImportableFile, - * long, long, boolean) + * @see OmeroImageService#importFile(ImportableObject, + * ImportableFile, long, long, boolean) */ - public Object importFile(ImportableObject object, ImportableFile importable, - long userID, long groupID, boolean close) + public Object importFile(ImportableObject object, + ImportableFile importable, long userID, long groupID, boolean close) throws ImportException { if (importable == null || importable.getFile() == null) throw new IllegalArgumentException("No images to import."); StatusLabel status = importable.getStatus(); + SecurityContext ctx = + new SecurityContext(importable.getGroup().getId()); if (status.isMarkedAsCancel()) { - gateway.closeImport(); + gateway.closeImport(ctx); return Boolean.valueOf(false); } Object result = null; @@ -1041,7 +1046,7 @@ public Object importFile(ImportableObject object, ImportableFile importable, } //save the tag. try { - l = gateway.saveAndReturnObject(l, new HashMap()); + l = gateway.saveAndReturnObject(ctx, l, new HashMap()); Iterator j = l.iterator(); Annotation a; while (j.hasNext()) { @@ -1080,14 +1085,14 @@ public Object importFile(ImportableObject object, ImportableFile importable, if (hcsFile) { boolean b = ImportableObject.isArbitraryFile(file); if (b) { //check if it is actually a HCS file. - ic = gateway.getImportCandidates(object, file, status); + ic = gateway.getImportCandidates(ctx, object, file, status); if (ic != null) { candidates = ic.getPaths(); if (candidates.size() == 1) { String value = candidates.get(0); if (!file.getAbsolutePath().equals(value) && object.isFileinQueue(value)) { - gateway.closeImport(); + gateway.closeImport(ctx); status.markedAsDuplicate(); return Boolean.valueOf(true); } @@ -1105,7 +1110,7 @@ public Object importFile(ImportableObject object, ImportableFile importable, } } if (!hcsFile && ImportableObject.isOMEFile(file)) { - ic = gateway.getImportCandidates(object, file, status); + ic = gateway.getImportCandidates(ctx, object, file, status); if (ic != null) { hcsFile = isHCS(ic.getContainers()); } @@ -1121,8 +1126,8 @@ public Object importFile(ImportableObject object, ImportableFile importable, folder = object.createFolderAsContainer(importable, hcsFile); if (folder instanceof DatasetData) { try { - ioContainer = determineContainer((DatasetData) folder, - container, object); + ioContainer = determineContainer(ctx, + (DatasetData) folder, container, object); status.setContainerFromFolder(PojoMapper.asDataObject( ioContainer)); } catch (Exception e) { @@ -1131,7 +1136,8 @@ public Object importFile(ImportableObject object, ImportableFile importable, } } else if (folder instanceof ScreenData) { try { - ioContainer = determineContainer(null, folder, object); + ioContainer = determineContainer(ctx, null, folder, + object); status.setContainerFromFolder(PojoMapper.asDataObject( ioContainer)); } catch (Exception e) { @@ -1142,7 +1148,7 @@ public Object importFile(ImportableObject object, ImportableFile importable, } if (folder == null && dataset != null) { //dataset try { - ioContainer = determineContainer(dataset, container, + ioContainer = determineContainer(ctx, dataset, container, object); } catch (Exception e) { context.getLogger().error(this, "Cannot create " + @@ -1156,7 +1162,7 @@ public Object importFile(ImportableObject object, ImportableFile importable, container); if (createdData == null) { try { - ioContainer = gateway.saveAndReturnObject( + ioContainer = gateway.saveAndReturnObject(ctx, container.asIObject(), parameters); //register object.addNewDataObject( @@ -1172,7 +1178,7 @@ public Object importFile(ImportableObject object, ImportableFile importable, } } if (ImportableObject.isArbitraryFile(file)) { - ic = gateway.getImportCandidates(object, file, status); + ic = gateway.getImportCandidates(ctx, object, file, status); candidates = ic.getPaths(); int size = candidates.size(); if (size == 0) return Boolean.valueOf(false); @@ -1180,7 +1186,7 @@ else if (size == 1) { String value = candidates.get(0); if (!file.getAbsolutePath().equals(value) && object.isFileinQueue(value)) { - gateway.closeImport(); + gateway.closeImport(ctx); status.markedAsDuplicate(); return Boolean.valueOf(true); } @@ -1188,20 +1194,20 @@ else if (size == 1) { status.resetFile(f); if (ioContainer == null) status.setNoContainer(); - result = gateway.importImage(object, ioContainer, f, + result = gateway.importImage(ctx, object, ioContainer, f, status, importable.isArchived(), close); if (result instanceof ImageData) { image = (ImageData) result; images.add(image); - annotatedImportedImage(list, images); - return formatResult(image, userID, thumbnail); + annotatedImportedImage(ctx, list, images); + return formatResult(ctx, image, userID, thumbnail); } else if (result instanceof Set) { ll = (Set) result; - annotatedImportedImage(list, ll); + annotatedImportedImage(ctx, list, ll); kk = ll.iterator(); converted = new ArrayList(ll.size()); while (kk.hasNext()) { - converted.add(formatResult(kk.next(), userID, + converted.add(formatResult(ctx, kk.next(), userID, thumbnail)); } return converted; @@ -1215,7 +1221,7 @@ else if (size == 1) { while (i.hasNext()) files.put(new File(i.next()), new StatusLabel()); status.setFiles(files); - Boolean v = importCandidates(files, status, object, + Boolean v = importCandidates(ctx, files, status, object, importable.isArchived(), ioContainer, list, userID, close, hcs); if (v != null) { @@ -1225,20 +1231,20 @@ else if (size == 1) { } else { //single file let's try to import it. if (ioContainer == null) status.setNoContainer(); - result = gateway.importImage(object, ioContainer, file, status, - importable.isArchived(), close); + result = gateway.importImage(ctx, object, ioContainer, file, + status, importable.isArchived(), close); if (result instanceof ImageData) { image = (ImageData) result; images.add(image); - annotatedImportedImage(list, images); - return formatResult(image, userID, thumbnail); + annotatedImportedImage(ctx, list, images); + return formatResult(ctx, image, userID, thumbnail); } else if (result instanceof Set) { ll = (Set) result; - annotatedImportedImage(list, ll); + annotatedImportedImage(ctx, list, ll); kk = ll.iterator(); converted = new ArrayList(ll.size()); while (kk.hasNext()) { - converted.add(formatResult(kk.next(), userID, + converted.add(formatResult(ctx, kk.next(), userID, thumbnail)); } return converted; @@ -1247,7 +1253,7 @@ else if (size == 1) { } } //file import ends. //Checks folder import. - ic = gateway.getImportCandidates(object, file, status); + ic = gateway.getImportCandidates(ctx, object, file, status); candidates = ic.getPaths(); if (candidates.size() == 0) return Boolean.valueOf(false); Map hcsFiles = new HashMap(); @@ -1286,7 +1292,7 @@ else if (n > 1) { container); if (createdData == null) { try { - ioContainer = gateway.saveAndReturnObject( + ioContainer = gateway.saveAndReturnObject(ctx, container.asIObject(), parameters); //register object.addNewDataObject( @@ -1300,7 +1306,7 @@ else if (n > 1) { } } else ioContainer = container.asIObject(); } - importCandidates(hcsFiles, status, object, + importCandidates(ctx, hcsFiles, status, object, importable.isArchived(), ioContainer, list, userID, close, hcs); } @@ -1309,7 +1315,7 @@ else if (n > 1) { if (folder != null) { //folder //we have to import the image in this container. try { - ioContainer = gateway.saveAndReturnObject( + ioContainer = gateway.saveAndReturnObject(ctx, folder.asIObject(), parameters); status.setContainerFromFolder(PojoMapper.asDataObject( ioContainer)); @@ -1322,7 +1328,7 @@ else if (n > 1) { container); if (createdData == null) { project = gateway.saveAndReturnObject( - container.asIObject(), + ctx, container.asIObject(), parameters); object.addNewDataObject( PojoMapper.asDataObject(project)); @@ -1331,7 +1337,7 @@ else if (n > 1) { (Dataset) ioContainer, (Project) project); link = (ProjectDatasetLink) - gateway.saveAndReturnObject(link, + gateway.saveAndReturnObject(ctx, link, parameters); } else { link = (ProjectDatasetLink) @@ -1340,7 +1346,7 @@ else if (n > 1) { (Project) createdData.asProject()); link = (ProjectDatasetLink) - gateway.saveAndReturnObject(link, + gateway.saveAndReturnObject(ctx, link, parameters); } } else { //project already exists. @@ -1349,7 +1355,7 @@ else if (n > 1) { (Dataset) ioContainer, (Project) container.asProject()); link = (ProjectDatasetLink) - gateway.saveAndReturnObject(link, + gateway.saveAndReturnObject(ctx, link, parameters); } } catch (Exception e) { @@ -1364,7 +1370,7 @@ else if (n > 1) { } else { //folder if (dataset != null) { //dataset try { - ioContainer = determineContainer(dataset, container, + ioContainer = determineContainer(ctx, dataset, container, object); } catch (Exception e) { context.getLogger().error(this, @@ -1374,7 +1380,7 @@ else if (n > 1) { } } - importCandidates(otherFiles, status, object, + importCandidates(ctx, otherFiles, status, object, importable.isArchived(), ioContainer, list, userID, close, hcs); } @@ -1402,10 +1408,11 @@ public FileFilter[] getSupportedFileFormats() /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#createMovie(long, long, List, MovieExportParam) + * @see OmeroImageService#createMovie(SecurityContext, long, long, List, + * MovieExportParam) */ - public ScriptCallback createMovie(long imageID, long pixelsID, - List channels, MovieExportParam param) + public ScriptCallback createMovie(SecurityContext ctx, long imageID, + long pixelsID, List channels, MovieExportParam param) throws ProcessException, DSOutOfServiceException, DSAccessException { if (imageID <= 0) @@ -1417,56 +1424,58 @@ public ScriptCallback createMovie(long imageID, long pixelsID, ExperimenterData exp = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); - return gateway.createMovie(imageID, pixelsID, exp.getId(), channels, - param); + return gateway.createMovie(ctx, imageID, pixelsID, exp.getId(), + channels, param); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#loadROI(long, List, long) + * @see OmeroImageService#loadROI(SecurityContext, long, List, long) */ - public List loadROI(long imageID, List fileID, long userID) + public List loadROI(SecurityContext ctx, long imageID, + List fileID, long userID) throws DSOutOfServiceException, DSAccessException { if (imageID <= 0) throw new IllegalArgumentException("No image specified."); - return gateway.loadROI(imageID, fileID, userID); + return gateway.loadROI(ctx, imageID, fileID, userID); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#saveROI(long, long, List) + * @see OmeroImageService#saveROI(SecurityContext, long, long, List) */ - public List saveROI(long imageID, long userID, List - roiList) + public List saveROI(SecurityContext ctx, long imageID, long userID, + List roiList) throws DSOutOfServiceException, DSAccessException { if (imageID <= 0) throw new IllegalArgumentException("No image specified."); - return gateway.saveROI(imageID, userID, roiList); + return gateway.saveROI(ctx, imageID, userID, roiList); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#exportImageAsOMETiff(long, File) + * @see OmeroImageService#exportImageAsOMETiff(SecurityContext, long, File) */ - public Object exportImageAsOMETiff(long imageID, File file) - throws DSOutOfServiceException, DSAccessException + public Object exportImageAsOMETiff(SecurityContext ctx, long imageID, + File file) + throws DSOutOfServiceException, DSAccessException { if (imageID <= 0) throw new IllegalArgumentException("No image specified."); if (file == null) throw new IllegalArgumentException("No File specified."); - return gateway.exportImageAsOMETiff(file, imageID); + return gateway.exportImageAsOMETiff(ctx, file, imageID); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#createFigure(List, Class, Object) + * @see OmeroImageService#createFigure(SecurityContext, List, Class, Object) */ - public ScriptCallback createFigure(List ids, Class type, - Object parameters) - throws ProcessException, DSOutOfServiceException, DSAccessException + public ScriptCallback createFigure(SecurityContext ctx, List ids, + Class type, Object parameters) + throws ProcessException, DSOutOfServiceException, DSAccessException { if (parameters == null) throw new IllegalArgumentException("No parameters"); @@ -1474,30 +1483,33 @@ public ScriptCallback createFigure(List ids, Class type, LookupNames.CURRENT_USER_DETAILS); if (parameters instanceof FigureParam) { FigureParam p = (FigureParam) parameters; - return gateway.createFigure(ids, type, p, exp.getId()); + return gateway.createFigure(ctx, ids, type, p, exp.getId()); } return null; } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#loadROIFromServer(long, long) + * @see OmeroImageService#loadROIFromServer(SecurityContext, long, long) */ - public List loadROIFromServer(long imageID, long userID) + public List loadROIFromServer(SecurityContext ctx, long imageID, + long userID) throws DSOutOfServiceException, DSAccessException { if (imageID <= 0) throw new IllegalArgumentException("No image specified."); - return gateway.loadROI(imageID, null, userID); + return gateway.loadROI(ctx, imageID, null, userID); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#renderOverLays(long, PlaneDef, long, Map, boolean) + * @see OmeroImageService#renderOverLays(SecurityContext, long, PlaneDef, + * long, Map, boolean) */ - public Object renderOverLays(long pixelsID, PlaneDef pd, long tableID, - Map overlays, boolean asTexture) - throws RenderingServiceException + public Object renderOverLays(SecurityContext ctx, long pixelsID, + PlaneDef pd, long tableID, Map overlays, + boolean asTexture) + throws RenderingServiceException { try { return PixelsServicesFactory.renderOverlays(context, @@ -1506,80 +1518,65 @@ public Object renderOverLays(long pixelsID, PlaneDef pd, long tableID, throw new RenderingServiceException("RenderImage", e); } } - - /** - * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#analyseFrap(List, Class, Object) - */ - public DataObject analyseFrap(List ids, Class type, Object param) - throws DSOutOfServiceException, DSAccessException - { - if (ids == null || ids.size() <= 0) - throw new IllegalArgumentException("No objects to analyse."); - if (type == null) - throw new IllegalArgumentException("No node to analyze."); - long id = gateway.analyseFRAP(ids, type, param); - if (id < 0) return null; - return context.getMetadataService().loadAnnotation(id); - } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroImageService#runScript(ScriptObject) + * @see OmeroImageService#runScript(SecurityContext, ScriptObject) */ - public ScriptCallback runScript(ScriptObject script) + public ScriptCallback runScript(SecurityContext ctx, ScriptObject script) throws ProcessException, DSOutOfServiceException, DSAccessException { if (script == null) throw new IllegalArgumentException("No script to run."); - return gateway.runScript(script); + return gateway.runScript(ctx, script); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#loadAvailableScriptsWithUI() + * @see OmeroImageService#loadAvailableScriptsWithUI(SecurityContext) */ - public List loadAvailableScriptsWithUI() - throws DSOutOfServiceException, DSAccessException + public List loadAvailableScriptsWithUI(SecurityContext ctx) + throws DSOutOfServiceException, DSAccessException { - return gateway.loadRunnableScriptsWithUI(); + return gateway.loadRunnableScriptsWithUI(ctx); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#loadAvailableScripts(long) + * @see OmeroImageService#loadAvailableScripts(SecurityContext, long) */ - public List loadAvailableScripts(long userID) - throws DSOutOfServiceException, DSAccessException + public List loadAvailableScripts(SecurityContext ctx, + long userID) + throws DSOutOfServiceException, DSAccessException { - return gateway.loadRunnableScripts(); + return gateway.loadRunnableScripts(ctx); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#loadScript(long) + * @see OmeroImageService#loadScript(SecurityContext, long) */ - public ScriptObject loadScript(long scriptID) + public ScriptObject loadScript(SecurityContext ctx, long scriptID) throws ProcessException { - return gateway.loadScript(scriptID); + return gateway.loadScript(ctx, scriptID); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#getScriptsAsString() + * @see OmeroImageService#getScriptsAsString(SecurityContext) */ - public Map getScriptsAsString() + public Map getScriptsAsString(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException { - return gateway.getScriptsAsString(); + return gateway.getScriptsAsString(ctx); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#uploadScript(ScriptObject) + * @see OmeroImageService#uploadScript(SecurityContext, ScriptObject) */ - public Object uploadScript(ScriptObject script) + public Object uploadScript(SecurityContext ctx, ScriptObject script) throws DSOutOfServiceException, DSAccessException { if (script == null) @@ -1588,21 +1585,20 @@ public Object uploadScript(ScriptObject script) LookupNames.USER_ADMINISTRATOR); boolean value = false; if (b != null) value = b.booleanValue(); - return gateway.uploadScript(script, value); + return gateway.uploadScript(ctx, script, value); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#loadRatings(Class, long, long) + * @see OmeroImageService#loadRatings(SecurityContext, Class, long, long) */ - public Collection loadROIMeasurements(Class type, long id, long userID) + public Collection loadROIMeasurements(SecurityContext ctx, Class type, + long id, long userID) throws DSOutOfServiceException, DSAccessException { if (ImageData.class.equals(type)) { - return gateway.loadROIMeasurements(id, userID); + return gateway.loadROIMeasurements(ctx, id, userID); } - - List ids = null; if (userID != -1) { ids = new ArrayList(1); @@ -1612,7 +1608,7 @@ public Collection loadROIMeasurements(Class type, long id, long userID) nodeIds.add(id); List types = new ArrayList(); types.add(FileAnnotationData.class); - Map map = gateway.loadAnnotations(type, nodeIds, types, ids, + Map map = gateway.loadAnnotations(ctx, type, nodeIds, types, ids, new Parameters()); if (map == null || map.size() == 0) return new ArrayList(); Collection l = (Collection) map.get(id); @@ -1633,12 +1629,11 @@ public Collection loadROIMeasurements(Class type, long id, long userID) /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#getFSThumbnailSet(List, int, long) + * @see OmeroImageService#getFSThumbnailSet(SecurityContext, List, int, long) */ - public Map getFSThumbnailSet( - List files, - int maxLength, long userID) - throws DSAccessException, DSOutOfServiceException, FSAccessException + public Map getFSThumbnailSet(SecurityContext ctx, + List files, int maxLength, long userID) + throws DSAccessException, DSOutOfServiceException, FSAccessException { Map m = new HashMap(); @@ -1652,15 +1647,14 @@ public Map getFSThumbnailSet( } return m; } - FSFileSystemView view = gateway.getFSRepositories(userID); + FSFileSystemView view = gateway.getFSRepositories(ctx, userID); String path; while (i.hasNext()) { file = i.next(); path = view.getThumbnail(file); try { if (path != null) m.put(file, - Factory.scaleBufferedImage(createImage(path), - maxLength)); + Factory.scaleBufferedImage(createImage(path), maxLength)); else m.put(file, null); } catch (Exception e) { m.put(file, null); @@ -1671,34 +1665,36 @@ public Map getFSThumbnailSet( /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#storeWorkflows(List, long) + * @see OmeroImageService#storeWorkflows(SecurityContext, List, long) */ - public Object storeWorkflows(List workflows, long userID) - throws DSAccessException, DSOutOfServiceException + public Object storeWorkflows(SecurityContext ctx, + List workflows, long userID) + throws DSAccessException, DSOutOfServiceException { - return gateway.storeWorkflows(workflows, userID); + return gateway.storeWorkflows(ctx, workflows, userID); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#retrieveWorkflows(long) + * @see OmeroImageService#retrieveWorkflows(SecurityContext, long) */ - public List retrieveWorkflows(long userID) + public List retrieveWorkflows(SecurityContext ctx, + long userID) throws DSAccessException, DSOutOfServiceException { ExperimenterData exp = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); if (userID < 0) userID = exp.getId(); - return gateway.retrieveWorkflows(userID); + return gateway.retrieveWorkflows(ctx, userID); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#getExperimenterThumbnailSet(List, int) + * @see OmeroImageService#getExperimenterThumbnailSet(SecurityContext, List, int) */ public Map getExperimenterThumbnailSet( - List experimenters, int maxLength) - throws DSAccessException, DSOutOfServiceException + SecurityContext ctx, List experimenters, int maxLength) + throws DSAccessException, DSOutOfServiceException { Map m = new HashMap(); @@ -1725,8 +1721,8 @@ public Map getExperimenterThumbnailSet( } Map annotations; try { - annotations = gateway.loadAnnotations(ExperimenterData.class, ids, - types, new ArrayList(), new Parameters()); + annotations = gateway.loadAnnotations(ctx, ExperimenterData.class, + ids, types, new ArrayList(), new Parameters()); } catch (Exception e) { return m; } @@ -1765,8 +1761,8 @@ public Map getExperimenterThumbnailSet( if (ann != null) { exp = exps.get(id); try { - img = createImage(gateway.getUserPhoto(ann.getFileID(), - ann.getFileSize())); + img = createImage(gateway.getUserPhoto(ctx, + ann.getFileID(), ann.getFileSize())); m.put(exps.get(id), Factory.scaleBufferedImage(img, maxLength)); } catch (Exception e) { @@ -1780,9 +1776,9 @@ public Map getExperimenterThumbnailSet( /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#saveAs(SaveAsParam) + * @see OmeroImageService#saveAs(SecurityContext, SaveAsParam) */ - public ScriptCallback saveAs(SaveAsParam param) + public ScriptCallback saveAs(SecurityContext ctx, SaveAsParam param) throws ProcessException, DSAccessException, DSOutOfServiceException { if (param == null) @@ -1793,17 +1789,17 @@ public ScriptCallback saveAs(SaveAsParam param) ExperimenterData exp = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); - return gateway.saveAs(exp.getId(), param); + return gateway.saveAs(ctx, exp.getId(), param); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroImageService#isLargeImage(long) + * @see OmeroImageService#isLargeImage(SecurityContext, long) */ - public Boolean isLargeImage(long pixelsId) + public Boolean isLargeImage(SecurityContext ctx, long pixelsId) throws DSAccessException, DSOutOfServiceException { - return gateway.isLargeImage(pixelsId); + return gateway.isLargeImage(ctx, pixelsId); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroMetadataService.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroMetadataService.java index 0a872320b6c..5aceb28295f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroMetadataService.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroMetadataService.java @@ -55,6 +55,7 @@ import org.openmicroscopy.shoola.env.data.model.TableResult; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; import org.openmicroscopy.shoola.env.data.util.FilterContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StructuredDataResults; import pojos.AnnotationData; import pojos.DataObject; @@ -77,19 +78,19 @@ public interface OmeroMetadataService { /** Identifies that the file is of type protocol. */ - public static final int EDITOR_PROTOCOL = 0; + public static final int EDITOR_PROTOCOL = 0; /** Identifies that the file is of type experiment. */ - public static final int EDITOR_EXPERIMENT = 1; + public static final int EDITOR_EXPERIMENT = 1; /** Identifies that the file is of type movie. */ - public static final int MOVIE = 2; + public static final int MOVIE = 2; /** Identifies that the file is of type other. */ - public static final int OTHER = 3; + public static final int OTHER = 3; /** Identifies that the tag and tag set not owned. */ - public static final int TAG_NOT_OWNED = 4; + public static final int TAG_NOT_OWNED = 4; /** Indicates to retrieve the tags. */ public static final int LEVEL_TAG = 0; @@ -157,78 +158,82 @@ public interface OmeroMetadataService * Loads the ratings linked to an object identifying by the specified * type and id. * - * @param type The type of the object. - * @param id The id of the object. - * @param userID The id of the user who added attachments to the object - * or -1 if the user is not specified. + * @param ctx The security context. + * @param type The type of the object. + * @param id The id of the object. + * @param userID The id of the user who added attachments to the object + * or -1 if the user is not specified. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection loadRatings(Class type, long id, long userID) + public Collection loadRatings(SecurityContext ctx, Class type, long id, + long userID) throws DSOutOfServiceException, DSAccessException; /** * Loads all annotations related to the object specified by the class * type and the id. * - * @param type The type of the object. - * @param id The id of the object. - * @param userID The id of the user who added attachments to the object - * or -1 if the user is not specified. + * @param ctx The security context. + * @param type The type of the object. + * @param id The id of the object. + * @param userID The id of the user who added attachments to the object + * or -1 if the user is not specified. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection loadStructuredAnnotations(Class type, long id, - long userID) + public Collection loadStructuredAnnotations(SecurityContext ctx, Class type, + long id, long userID) throws DSOutOfServiceException, DSAccessException; /** * Loads data related to the specified object. * - * @param object The object to handle. - * @param userID The id of the user who added attachments to the object - * or -1 if the user is not specified. - * @param viewed Pass true to load the rendering settings - * related to the objects, false - * otherwise. + * @param ctx The security context. + * @param object The object to handle. + * @param userID The id of the user who added attachments to the object + * or -1 if the user is not specified. + * @param viewed Pass true to load the rendering settings + * related to the objects, false otherwise. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public StructuredDataResults loadStructuredData(Object object, - long userID, boolean viewed) + public StructuredDataResults loadStructuredData(SecurityContext ctx, + Object object, long userID, boolean viewed) throws DSOutOfServiceException, DSAccessException; /** * Loads data related to the specified objects * - * @param data The objects to handle. - * @param userID The id of the user who added attachments to the object - * or -1 if the user is not specified. - * @param viewed Pass true to load the rendering settings - * related to the objects, false - * otherwise. + * @param ctx The security context. + * @param data The objects to handle. + * @param userID The id of the user who added attachments to the object + * or -1 if the user is not specified. + * @param viewed Pass true to load the rendering settings + * related to the objects, false otherwise. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Map loadStructuredData(List data, long userID, - boolean viewed) + public Map loadStructuredData(SecurityContext ctx, List data, + long userID, boolean viewed) throws DSOutOfServiceException, DSAccessException; /** * Annotates the specified data object and returns the annotated object. * + * @param ctx The security context. * @param toAnnotate The object to annotate. * Mustn't be null. * @param annotation The annotation to create. @@ -239,71 +244,75 @@ public Map loadStructuredData(List data, long userID, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public DataObject annotate(DataObject toAnnotate, AnnotationData annotation) + public DataObject annotate(SecurityContext ctx, DataObject toAnnotate, + AnnotationData annotation) throws DSOutOfServiceException, DSAccessException; /** * Annotates the object and returns the annotated object. * - * @param type The type of object to annotate. - * Mustn't be null. - * @param id The id of the object to annotate. - * Mustn't be null. - * @param annotation The annotation to create. - * Mustn't be null. + * @param ctx The security context. + * @param type The type of object to annotate. Mustn't be null. + * @param id The id of the object to annotate. Mustn't be null. + * @param annotation The annotation to create. Mustn't be null. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public DataObject annotate(Class type, long id, AnnotationData annotation) + public DataObject annotate(SecurityContext ctx, Class type, long id, + AnnotationData annotation) throws DSOutOfServiceException, DSAccessException; /** * Removes all annotations of a given type from the specified object. * - * @param object The object to handle. - * Mustn't be null. - * @param annotationType The type of annotation to clear. + * @param ctx The security context. + * @param object The object to handle. Mustn't be null. + * @param annotationType The type of annotation to clear. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public void clearAnnotation(DataObject object, Class annotationType) + public void clearAnnotation(SecurityContext ctx, DataObject object, + Class annotationType) throws DSOutOfServiceException, DSAccessException; /** * Removes all annotations from the specified object. * - * @param object The object to handle. Mustn't be null. + * @param ctx The security context. + * @param object The object to handle. Mustn't be null. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public void clearAnnotation(DataObject object) + public void clearAnnotation(SecurityContext ctx, DataObject object) throws DSOutOfServiceException, DSAccessException; /** * Clears the annotation related to a given type object. * - * @param type The type of object the annotations are - * related to. - * @param id The object's id. - * @param annotationType The type of annotation to delete. + * @param ctx The security context. + * @param type The type of object the annotations are related to. + * @param id The object's id. + * @param annotationType The type of annotation to delete. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public void clearAnnotation(Class type, long id, Class annotationType) + public void clearAnnotation(SecurityContext ctx, Class type, long id, + Class annotationType) throws DSOutOfServiceException, DSAccessException; /** * Loads the annotation. * + * @param ctx The security context. * @param annotationID The id of the annotation. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -311,120 +320,124 @@ public void clearAnnotation(Class type, long id, Class annotationType) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public DataObject loadAnnotation(long annotationID) + public DataObject loadAnnotation(SecurityContext ctx, long annotationID) throws DSOutOfServiceException, DSAccessException; /** * Loads all annotations of a given type. * - * @param annotationType The type of annotation to retrieve. - * @param nameSpace The name space of the annotation - * or null. - * @param userID The id of the user the annotations are related - * to. - * @param groupID The id of the group. + * @param ctx The security context. + * @param annotationType The type of annotation to retrieve. + * @param nameSpace The name space of the annotation or null. + * @param userID The id of the user the annotations are related to. + * @param groupID The id of the group. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection loadAnnotations(Class annotationType, String nameSpace, - long userID, long groupID) + public Collection loadAnnotations(SecurityContext ctx, Class annotationType, + String nameSpace, long userID, long groupID) throws DSOutOfServiceException, DSAccessException; /** * Saves the object, adds (resp. removes) annotations to (resp. from) * the object if any. * - * @param data The data object to handle. - * @param toAdd Collection of annotations to add. - * @param toRemove Collection of annotations to remove. - * @param userID The id of the user. + * @param ctx The security context. + * @param data The data object to handle. + * @param toAdd Collection of annotations to add. + * @param toRemove Collection of annotations to remove. + * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object saveData(Collection data, - List toAdd, - List toRemove, long userID) + public Object saveData(SecurityContext ctx, Collection data, + List toAdd, List toRemove, long userID) throws DSOutOfServiceException, DSAccessException; /** * Saves the objects contained in the specified objects, * adds (resp. removes) annotations to(resp. from) the object if any. * - * @param data The data object to handle. - * @param toAdd Collection of annotations to add. - * @param toRemove Collection of annotations to remove. - * @param userID The id of the user. + * @param ctx The security context. + * @param data The data object to handle. + * @param toAdd Collection of annotations to add. + * @param toRemove Collection of annotations to remove. + * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object saveBatchData(Collection data, - List toAdd, - List toRemove, long userID) + public Object saveBatchData(SecurityContext ctx, + Collection data, List toAdd, + List toRemove, long userID) throws DSOutOfServiceException, DSAccessException; /** * Saves the objects contained in the specified objects, * adds (resp. removes) annotations to(resp. from) the object if any. * - * @param data The data object to handle. - * @param toAdd Collection of annotations to add. - * @param toRemove Collection of annotations to remove. - * @param userID The id of the user. + * @param ctx The security context. + * @param data The data object to handle. + * @param toAdd Collection of annotations to add. + * @param toRemove Collection of annotations to remove. + * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object saveBatchData(TimeRefObject data, - List toAdd, - List toRemove, long userID) + public Object saveBatchData(SecurityContext ctx, TimeRefObject data, + List toAdd, List toRemove, long userID) throws DSOutOfServiceException, DSAccessException; /** * Downloads a file previously uploaded to the server. * - * @param file The file to write the data into. - * @param fileID The id of the file to download. - * @param size The size of the file to download + * @param ctx The security context. + * @param file The file to write the data into. + * @param fileID The id of the file to download. + * @param size The size of the file to download * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public File downloadFile(File file, long fileID, long size) + public File downloadFile(SecurityContext ctx, File file, long fileID, + long size) throws DSOutOfServiceException, DSAccessException; /** * Loads the ratings associated to the passed objects. * + * @param ctx The security context. * @param nodeType The type of object. - * @param nodeIds The ids of the object. - * @param userID The user id. + * @param nodeIds The ids of the object. + * @param userID The user id. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Map loadRatings(Class nodeType, - List nodeIds, long userID) - throws DSOutOfServiceException, DSAccessException; + public Map loadRatings(SecurityContext ctx, + Class nodeType, List nodeIds, long userID) + throws DSOutOfServiceException, DSAccessException; /** * Returns a sub-collection of the passed collection of nodes * annotated by the passed type of annotation. * + * @param ctx The security context. * @param nodeType * @param nodeIds * @param annotationType @@ -436,14 +449,16 @@ public Map loadRatings(Class nodeType, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection filterByAnnotation(Class nodeType, List nodeIds, - Class annotationType, List terms, long userID) + public Collection filterByAnnotation(SecurityContext ctx, Class nodeType, + List nodeIds, Class annotationType, List terms, + long userID) throws DSOutOfServiceException, DSAccessException; /** * Returns a sub-collection of the passed collection of nodes * annotated by the passed type of annotation. * + * @param ctx The security context. * @param nodeType * @param nodeIds * @param annotationType @@ -455,12 +470,14 @@ public Collection filterByAnnotation(Class nodeType, List nodeIds, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection filterByAnnotated(Class nodeType, List nodeIds, - Class annotationType, boolean annotated, long userID) + public Collection filterByAnnotated(SecurityContext ctx, Class nodeType, + List nodeIds, Class annotationType, boolean annotated, + long userID) throws DSOutOfServiceException, DSAccessException; /** * + * @param ctx The security context. * @param nodeType * @param ids * @param filter @@ -471,27 +488,29 @@ public Collection filterByAnnotated(Class nodeType, List nodeIds, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection filterByAnnotation(Class nodeType, List ids, - FilterContext filter, long userID) + public Collection filterByAnnotation(SecurityContext ctx, Class nodeType, + List ids, FilterContext filter, long userID) throws DSOutOfServiceException, DSAccessException; /** * Returns the enumeration corresponding to the specified type. * - * @param type The type of enumeration. - * One of the enumerations defined by this class. + * @param ctx The security context. + * @param type The type of enumeration. + * One of the enumerations defined by this class. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection getEnumeration(String type) + public Collection getEnumeration(SecurityContext ctx, String type) throws DSOutOfServiceException, DSAccessException; /** * Loads the acquisition metadata for an image or a given channel. * + * @param ctx The security context. * @param refObject Either an ImageData or * ChannelData node. * @return See above. @@ -500,13 +519,13 @@ public Collection getEnumeration(String type) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object loadAcquisitionData(Object refObject) + public Object loadAcquisitionData(SecurityContext ctx, Object refObject) throws DSOutOfServiceException, DSAccessException; - /** * Loads the acquisition metadata for an image or a given channel. * + * @param ctx The security context. * @param refObject Either an ImageAcquisitionData or * ChannelAcquisitionData node. * @return See above. @@ -515,12 +534,13 @@ public Object loadAcquisitionData(Object refObject) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object saveAcquisitionData(Object refObject) + public Object saveAcquisitionData(SecurityContext ctx, Object refObject) throws DSOutOfServiceException, DSAccessException; /** * Saves the file back to the server. * + * @param ctx The security context. * @param fileAnnotation The annotation hosting the previous info. * @param file The file to save. * @param index One of the constants defined by this class. @@ -532,8 +552,9 @@ public Object saveAcquisitionData(Object refObject) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object archivedFile(FileAnnotationData fileAnnotation, File file, int - index, DataObject linkTo) + public Object archivedFile(SecurityContext ctx, + FileAnnotationData fileAnnotation, File file, int index, + DataObject linkTo) throws DSOutOfServiceException, DSAccessException; /** @@ -541,6 +562,7 @@ public Object archivedFile(FileAnnotationData fileAnnotation, File file, int * depending on the specified parameters. Returns a collection of * TagAnnotationDatas. * + * @param ctx The security context. * @param id The id if specified. * @param dataObject Pass true to load the * DataObjects linked to the Tag, @@ -556,8 +578,8 @@ public Object archivedFile(FileAnnotationData fileAnnotation, File file, int * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection loadTags(Long id, boolean dataObject, boolean topLevel, - long userID, long groupID) + public Collection loadTags(SecurityContext ctx, Long id, boolean dataObject, + boolean topLevel, long userID, long groupID) throws DSOutOfServiceException, DSAccessException; /** @@ -565,6 +587,7 @@ public Collection loadTags(Long id, boolean dataObject, boolean topLevel, * one of the following values: {@link #EDITOR_PROTOCOL}, * {@link #EDITOR_EXPERIMENT} or {@link #OTHER}. * + * @param ctx The security context. * @param userUD The user's identifier. * @param fileType One of the constants above. * @return See above. @@ -573,7 +596,7 @@ public Collection loadTags(Long id, boolean dataObject, boolean topLevel, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public long countFileType(long userID, int fileType) + public long countFileType(SecurityContext ctx, long userID, int fileType) throws DSOutOfServiceException, DSAccessException; /** @@ -582,6 +605,7 @@ public long countFileType(long userID, int fileType) * one of the following values: {@link #EDITOR_PROTOCOL}, * {@link #EDITOR_EXPERIMENT} or {@link #OTHER}. * + * @param ctx The security context. * @param fileType One of the constants above. * @param userID The id of the user. * @return See above. @@ -590,12 +614,13 @@ public long countFileType(long userID, int fileType) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Collection loadFiles(int fileType, long userID) + public Collection loadFiles(SecurityContext ctx, int fileType, long userID) throws DSOutOfServiceException, DSAccessException; /** * Loads the instrument. * + * @param ctx The security context. * @param instrumentID The id of the instrument. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -603,13 +628,14 @@ public Collection loadFiles(int fileType, long userID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public Object loadInstrument(long instrumentID) + public Object loadInstrument(SecurityContext ctx, long instrumentID) throws DSOutOfServiceException, DSAccessException; /** * Returns a collection of tabular data corresponding to the specified * parameters. * + * @param ctx The security context. * @param parameters The parameters to handle. * @param userID The user's identifier. * @return See above. @@ -618,13 +644,14 @@ public Object loadInstrument(long instrumentID) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List loadTabularData(TableParameters parameters, - long userID) + public List loadTabularData(SecurityContext ctx, + TableParameters parameters, long userID) throws DSOutOfServiceException, DSAccessException; /** * Loads the parents of the specified annotation. * + * @param ctx The security context. * @param annotationId The annotation to handle. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged @@ -632,7 +659,8 @@ public List loadTabularData(TableParameters parameters, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - public List loadParentsOfAnnotations(long annotationId) + public List loadParentsOfAnnotations(SecurityContext ctx, + long annotationId) throws DSOutOfServiceException, DSAccessException; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroMetadataServiceImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroMetadataServiceImpl.java index a26c8c4322c..e34575d44ef 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroMetadataServiceImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/OmeroMetadataServiceImpl.java @@ -28,6 +28,7 @@ import java.io.File; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -73,6 +74,7 @@ import org.openmicroscopy.shoola.env.data.util.FilterContext; import org.openmicroscopy.shoola.env.data.util.ModelMapper; import org.openmicroscopy.shoola.env.data.util.PojoMapper; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.util.StructuredDataResults; import pojos.AnnotationData; import pojos.BooleanAnnotationData; @@ -110,10 +112,10 @@ class OmeroMetadataServiceImpl { /** Uses it to gain access to the container's services. */ - private Registry context; + private Registry context; /** Reference to the entry point to access the OMERO services. */ - private OMEROGateway gateway; + private OMEROGateway gateway; /** @@ -135,11 +137,11 @@ private boolean containTerms(List terms, String value) return false; } - /** * Returns true if the annotation is shared, * false otherwise. * + * @param ctx The security context. * @param annotation The annotation to handle. * @param object The object to handle. * @return See above. @@ -148,13 +150,13 @@ private boolean containTerms(List terms, String value) * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private boolean isAnnotationShared(AnnotationData annotation, - DataObject object) + private boolean isAnnotationShared(SecurityContext ctx, + AnnotationData annotation, DataObject object) throws DSOutOfServiceException, DSAccessException { List ids = new ArrayList(); ids.add(annotation.getId()); - List l = gateway.findAnnotationLinks(object.getClass().getName(), + List l = gateway.findAnnotationLinks(ctx, object.getClass().getName(), -1, ids); if (l == null) return false; return l.size() > 0; @@ -163,6 +165,8 @@ private boolean isAnnotationShared(AnnotationData annotation, /** * Removes the specified annotation from the object. * Returns the updated object. + * + * @param ctx The security context. * @param annotation The annotation to create. * Mustn't be null. * @param object The object to handle. Mustn't be null. @@ -172,53 +176,55 @@ private boolean isAnnotationShared(AnnotationData annotation, * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private void removeAnnotation(AnnotationData annotation, - DataObject object) + private void removeAnnotation(SecurityContext ctx, + AnnotationData annotation, DataObject object) throws DSOutOfServiceException, DSAccessException { if (annotation == null || object == null) return; ExperimenterData exp = getUserDetails(); if (exp == null) return; - IObject ho = gateway.findIObject(annotation.asIObject()); + IObject ho = gateway.findIObject(ctx, annotation.asIObject()); if (ho == null) return; - IObject link = gateway.findAnnotationLink(object.getClass(), + IObject link = gateway.findAnnotationLink(ctx, object.getClass(), object.getId(), ho.getId().getValue(), exp.getId()); if (ho != null && link != null) { try { - gateway.deleteObject(link); + gateway.deleteObject(ctx, link); } catch (Exception e) { } } } - /** * Saves the logical channel. * + * @param ctx The security context. * @param data The data to save * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. * @throws DSAccessException */ - private void saveChannelData(ChannelData data) + private void saveChannelData(SecurityContext ctx, ChannelData data) throws DSOutOfServiceException, DSAccessException { LogicalChannel lc = data.asChannel().getLogicalChannel(); ModelMapper.unloadCollections(lc); - gateway.updateObject(lc, new Parameters()); + gateway.updateObject(ctx, lc, new Parameters()); } /** * Saves the metadata linked to a logical channel. * + * @param ctx The security context. * @param data The data to save * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. * @throws DSAccessException */ - private void saveChannelAcquisitionData(ChannelAcquisitionData data) + private void saveChannelAcquisitionData(SecurityContext ctx, + ChannelAcquisitionData data) { //LogicalChannel lc = (LogicalChannel) data.asIObject(); } @@ -226,13 +232,15 @@ private void saveChannelAcquisitionData(ChannelAcquisitionData data) /** * Saves the metadata linked to an image. * + * @param ctx The security context. * @param data The data to save * @throws DSOutOfServiceException If the connection is broken, or logged in - * @throws DSAccessException If an error occured while trying to + * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. * @throws DSAccessException */ - private void saveImageAcquisitionData(ImageAcquisitionData data) + private void saveImageAcquisitionData(SecurityContext ctx, + ImageAcquisitionData data) throws DSOutOfServiceException, DSAccessException { Image image = data.asImage(); @@ -248,7 +256,7 @@ private void saveImageAcquisitionData(ImageAcquisitionData data) label = new StageLabelI(); toCreate.add(label); } else { - label = (StageLabel) gateway.findIObject( + label = (StageLabel) gateway.findIObject(ctx, StageLabel.class.getName(), id); toUpdate.add(label); } @@ -271,7 +279,7 @@ private void saveImageAcquisitionData(ImageAcquisitionData data) condition = new ImagingEnvironmentI(); toCreate.add(condition); } else { - condition = (ImagingEnvironment) gateway.findIObject( + condition = (ImagingEnvironment) gateway.findIObject(ctx, ImagingEnvironment.class.getName(), id); toUpdate.add(condition); } @@ -293,7 +301,7 @@ private void saveImageAcquisitionData(ImageAcquisitionData data) settings = new ObjectiveSettingsI(); toCreate.add(settings); } else { - settings = (ObjectiveSettings) gateway.findIObject( + settings = (ObjectiveSettings) gateway.findIObject(ctx, ObjectiveSettings.class.getName(), id); toUpdate.add(settings); } @@ -309,13 +317,13 @@ private void saveImageAcquisitionData(ImageAcquisitionData data) long objectiveSettingsID = data.getObjectiveSettingsId(); if (toUpdate.size() > 0) { - gateway.updateObjects(toUpdate, new Parameters()); + gateway.updateObjects(ctx, toUpdate, new Parameters()); } Iterator i; if (toCreate.size() > 0) { - List l = gateway.createObjects(toCreate); + List l = gateway.createObjects(ctx, toCreate); i = l.iterator(); - image = (Image) gateway.findIObject(data.asIObject()); + image = (Image) gateway.findIObject(ctx, data.asIObject()); while (i.hasNext()) { object = i.next(); if (object instanceof StageLabel) @@ -328,7 +336,7 @@ else if (object instanceof ObjectiveSettings) { } } ModelMapper.unloadCollections(image); - gateway.updateObject(image, new Parameters()); + gateway.updateObject(ctx, image, new Parameters()); } toUpdate.clear(); toCreate.clear(); @@ -336,14 +344,14 @@ else if (object instanceof ObjectiveSettings) { //objective settings exist if (toUpdate.size() > 0) { - gateway.updateObjects(toUpdate, new Parameters()); + gateway.updateObjects(ctx, toUpdate, new Parameters()); } else { //create the object and link it to the objective settings. //and link it to an instrument. - List l = gateway.createObjects(toCreate); + List l = gateway.createObjects(ctx, toCreate); i = l.iterator(); ObjectiveSettings settings = (ObjectiveSettings) - gateway.findIObject(ObjectiveSettings.class.getName(), + gateway.findIObject(ctx, ObjectiveSettings.class.getName(), objectiveSettingsID); while (i.hasNext()) { object = i.next(); @@ -351,7 +359,7 @@ else if (object instanceof ObjectiveSettings) { settings.setObjective((Objective) object); } ModelMapper.unloadCollections(settings); - gateway.updateObject(settings, new Parameters()); + gateway.updateObject(ctx, settings, new Parameters()); } } @@ -369,13 +377,14 @@ private ExperimenterData getUserDetails() /** * Prepares the annotation to add. * + * @param ctx The security context. * @param toAdd The collection of annotation to prepare. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private List prepareAnnotationToAdd( + private List prepareAnnotationToAdd(SecurityContext ctx, List toAdd) throws DSOutOfServiceException, DSAccessException { @@ -399,7 +408,7 @@ private List prepareAnnotationToAdd( if (ann.getId() < 0) { if (ann instanceof FileAnnotationData) { fileAnn = (FileAnnotationData) ann; - of = gateway.uploadFile(fileAnn.getAttachedFile(), + of = gateway.uploadFile(ctx, fileAnn.getAttachedFile(), fileAnn.getServerFileMimetype(), -1); fa = new FileAnnotationI(); fa.setFile(of); @@ -413,7 +422,7 @@ private List prepareAnnotationToAdd( if (ann instanceof TagAnnotationData) { //update description tag = (TagAnnotationData) ann; - ann = (TagAnnotationData) updateAnnotationData(tag); + ann = (TagAnnotationData) updateAnnotationData(ctx, tag); } annotations.add(ann); } @@ -425,7 +434,7 @@ private List prepareAnnotationToAdd( while (i.hasNext()) l.add((IObject) i.next()); - List r = gateway.createObjects(l); + List r = gateway.createObjects(ctx, l); annotations.addAll(PojoMapper.asDataObjects(r)); } return annotations; @@ -434,17 +443,19 @@ private List prepareAnnotationToAdd( /** * Links the annotation and the data object. * - * @param data The data object to annotate. + * @param ctx The security context. + * @param data The data object to annotate. * @param annotation The annotation to link. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private void linkAnnotation(DataObject data, AnnotationData annotation) + private void linkAnnotation(SecurityContext ctx, DataObject data, + AnnotationData annotation) throws DSOutOfServiceException, DSAccessException { String ioType = gateway.convertPojos(data).getName(); - IObject ho = gateway.findIObject(ioType, data.getId()); + IObject ho = gateway.findIObject(ctx, ioType, data.getId()); ModelMapper.unloadCollections(ho); IObject link = null; boolean exist = false; @@ -458,42 +469,43 @@ private void linkAnnotation(DataObject data, AnnotationData annotation) TagAnnotationData tag = (TagAnnotationData) annotation; //tag a tag. if (TagAnnotationData.class.equals(data.getClass())) { - link = gateway.findAnnotationLink( - AnnotationData.class, tag.getId(), + link = gateway.findAnnotationLink(ctx, + AnnotationData.class, tag.getId(), ho.getId().getValue(), exp.getId()); if (link == null) link = ModelMapper.linkAnnotation(an, (Annotation) ho); else exist = true; } else { - link = gateway.findAnnotationLink(ho.getClass(), + link = gateway.findAnnotationLink(ctx, ho.getClass(), ho.getId().getValue(), tag.getId(), exp.getId()); if (link == null) link = ModelMapper.linkAnnotation(ho, an); else { - updateAnnotationData(tag); + updateAnnotationData(ctx, tag); exist = true; } } } else if (annotation instanceof RatingAnnotationData) { - clearAnnotation(data.getClass(), data.getId(), + clearAnnotation(ctx, data.getClass(), data.getId(), RatingAnnotationData.class); link = ModelMapper.linkAnnotation(ho, an); } else { link = ModelMapper.linkAnnotation(ho, an); } if (link != null && !exist) - gateway.createObject(link); + gateway.createObject(ctx, link); } /** * Updates the passed annotation. * + * @param ctx The security context. * @param ann The annotation to update. * @throws DSOutOfServiceException If the connection is broken, or logged in * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private DataObject updateAnnotationData(DataObject ann) + private DataObject updateAnnotationData(SecurityContext ctx, DataObject ann) throws DSOutOfServiceException, DSAccessException { long id; @@ -504,10 +516,10 @@ private DataObject updateAnnotationData(DataObject ann) TagAnnotationData tag = (TagAnnotationData) ann; id = tag.getId(); ioType = gateway.convertPojos(TagAnnotationData.class).getName(); - ho = (TagAnnotation) gateway.findIObject(ioType, id); + ho = (TagAnnotation) gateway.findIObject(ctx, ioType, id); ho.setTextValue(omero.rtypes.rstring(tag.getTagValue())); ho.setDescription(omero.rtypes.rstring(tag.getTagDescription())); - IObject object = gateway.updateObject(ho, new Parameters()); + IObject object = gateway.updateObject(ctx, ho, new Parameters()); return PojoMapper.asDataObject(object); } return ann; @@ -544,42 +556,46 @@ private void convert(List all, Collection l) /** * Loads the attachments. * - * @param type The type of object the attachment is related to. - * @param userID The id of the user. + * @param ctx The security context. + * @param type The type of object the attachment is related to. + * @param userID The id of the user. * @return See above. * @throws DSOutOfServiceException If the connection is broken, or logged * in. * @throws DSAccessException If an error occurred while trying to * retrieve data from OMEDS service. */ - private Collection loadAllAttachments(Class type, long userID) + private Collection loadAllAttachments(SecurityContext ctx, Class type, + long userID) throws DSOutOfServiceException, DSAccessException { List all = new ArrayList(); if (type == null) { //retrieve attachment to P/D and I Collection l; - l = gateway.findAllAnnotations(ProjectData.class, userID); + l = gateway.findAllAnnotations(ctx, ProjectData.class, userID); if (l != null && l.size() > 0) convert(all, l); - l = gateway.findAllAnnotations(DatasetData.class, userID); + l = gateway.findAllAnnotations(ctx, DatasetData.class, userID); if (l != null && l.size() > 0) convert(all, l); - l = gateway.findAllAnnotations(ImageData.class, userID); + l = gateway.findAllAnnotations(ctx, ImageData.class, userID); if (l != null && l.size() > 0) convert(all, l); - return getFileAnnotations(all); + return getFileAnnotations(ctx, all); } - convert(all, gateway.findAllAnnotations(type, userID)); - return getFileAnnotations(all); + convert(all, gateway.findAllAnnotations(ctx, type, userID)); + return getFileAnnotations(ctx, all); } /** * Returns the file annotations. * + * @param ctx The security context. * @param annotations The collection to handle. * @return See above. * @throws DSOutOfServiceException * @throws DSAccessException */ - private List getFileAnnotations(Collection annotations) + private List getFileAnnotations(SecurityContext ctx, + Collection annotations) throws DSOutOfServiceException, DSAccessException { List result = new ArrayList(); @@ -595,7 +611,7 @@ private List getFileAnnotations(Collection annotations) if (data instanceof FileAnnotationData) { fa = (FileAnnotation) data.asAnnotation(); fileID = fa.getFile().getId().getValue(); - of = gateway.getOriginalFile(fileID); + of = gateway.getOriginalFile(ctx, fileID); if (of != null) ((FileAnnotationData) data).setContent(of); result.add(data); @@ -607,9 +623,9 @@ private List getFileAnnotations(Collection annotations) /** * Creates a new instance. * - * @param gateway Reference to the OMERO entry point. - * Mustn't be null. - * @param registry Reference to the registry. Mustn't be null. + * @param gateway Reference to the OMERO entry point. + * Mustn't be null. + * @param registry Reference to the registry. Mustn't be null. */ OmeroMetadataServiceImpl(OMEROGateway gateway, Registry registry) { @@ -623,9 +639,10 @@ private List getFileAnnotations(Collection annotations) /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#loadRatings(Class, long, long) + * @see OmeroMetadataService#loadRatings(SecurityContext, Class, long, long) */ - public Collection loadRatings(Class type, long id, long userID) + public Collection loadRatings(SecurityContext ctx, Class type, long id, + long userID) throws DSOutOfServiceException, DSAccessException { List ids = null; @@ -637,7 +654,7 @@ public Collection loadRatings(Class type, long id, long userID) nodeIds.add(id); List types = new ArrayList(); types.add(RatingAnnotationData.class); - Map map = gateway.loadAnnotations(type, nodeIds, types, ids, + Map map = gateway.loadAnnotations(ctx, type, nodeIds, types, ids, new Parameters()); if (map == null || map.size() == 0) return new ArrayList(); return (Collection) map.get(id); @@ -645,10 +662,10 @@ public Collection loadRatings(Class type, long id, long userID) /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#loadStructuredData(DataObject, long, boolean) + * @see OmeroMetadataService#loadStructuredData(SecurityContext, DataObject, long, boolean) */ - public StructuredDataResults loadStructuredData(Object object, - long userID, boolean viewed) + public StructuredDataResults loadStructuredData(SecurityContext ctx, + Object object, long userID, boolean viewed) throws DSOutOfServiceException, DSAccessException { if (object == null) @@ -668,8 +685,8 @@ public StructuredDataResults loadStructuredData(Object object, if (r == null) throw new IllegalArgumentException("Data Object not initialized."); - Collection annotations = loadStructuredAnnotations(object.getClass(), - r.getId(), userID); + Collection annotations = loadStructuredAnnotations(ctx, + object.getClass(), r.getId(), userID); if (annotations != null && annotations.size() > 0) { List texts = new ArrayList(); @@ -716,7 +733,7 @@ else if (data instanceof FileAnnotationData) { if (annotationIds.size() > 0 && !(object instanceof TagAnnotationData || object instanceof FileAnnotationData)) { - List links = gateway.findAnnotationLinks(object.getClass(), + List links = gateway.findAnnotationLinks(ctx, object.getClass(), r.getId(), annotationIds, -1); if (links != null) { Map @@ -748,10 +765,10 @@ else if (data instanceof FileAnnotationData) { /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#loadStructuredData(List, long, boolean) + * @see OmeroMetadataService#loadStructuredData(SecurityContext, List, long, boolean) */ - public Map loadStructuredData(List data, long userID, - boolean viewed) + public Map loadStructuredData(SecurityContext ctx, List data, + long userID, boolean viewed) throws DSOutOfServiceException, DSAccessException { if (data == null) @@ -765,35 +782,39 @@ public Map loadStructuredData(List data, long userID, node = i.next(); if (node != null) { results.put(node.getId(), - loadStructuredData(node, userID, viewed)); + loadStructuredData(ctx, node, userID, viewed)); } } return results; } - + /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#annotate(DataObject, AnnotationData) + * @see OmeroMetadataService#annotate(SecurityContext, DataObject, AnnotationData) */ - public DataObject annotate(DataObject toAnnotate, AnnotationData annotation) + public DataObject annotate(SecurityContext ctx, DataObject toAnnotate, + AnnotationData annotation) throws DSOutOfServiceException, DSAccessException { if (toAnnotate == null) throw new IllegalArgumentException("DataObject cannot be null"); - return annotate(toAnnotate.getClass(), toAnnotate.getId(), annotation); + ctx = gateway.checkContext(ctx, toAnnotate); + return annotate(ctx, toAnnotate.getClass(), toAnnotate.getId(), + annotation); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#annotate(Class, long, AnnotationData) + * @see OmeroMetadataService#annotate(SecurityContext, Class, long, AnnotationData) */ - public DataObject annotate(Class type, long id, AnnotationData annotation) + public DataObject annotate(SecurityContext ctx, Class type, long id, + AnnotationData annotation) throws DSOutOfServiceException, DSAccessException { if (annotation == null) throw new IllegalArgumentException("DataObject cannot be null"); String ioType = gateway.convertPojos(type).getName(); - IObject ho = gateway.findIObject(ioType, id); + IObject ho = gateway.findIObject(ctx, ioType, id); ModelMapper.unloadCollections(ho); IObject link = null; boolean exist = false; @@ -813,8 +834,8 @@ public DataObject annotate(Class type, long id, AnnotationData annotation) } else { annObject = tag.asIObject(); ModelMapper.unloadCollections(annObject); - link = gateway.findAnnotationLink( - AnnotationData.class, tag.getId(), + link = gateway.findAnnotationLink(ctx, + AnnotationData.class, tag.getId(), ho.getId().getValue(), exp.getId()); if (link == null) link = ModelMapper.linkAnnotation(annObject, @@ -826,8 +847,8 @@ public DataObject annotate(Class type, long id, AnnotationData annotation) else { annObject = tag.asIObject(); ModelMapper.unloadCollections(annObject); - link = gateway.findAnnotationLink(ho.getClass(), - ho.getId().getValue(), + link = gateway.findAnnotationLink(ctx, ho.getClass(), + ho.getId().getValue(), tag.getId(), exp.getId()); if (link == null) link = ModelMapper.linkAnnotation(ho, @@ -838,12 +859,12 @@ public DataObject annotate(Class type, long id, AnnotationData annotation) } else if (annotation instanceof RatingAnnotationData) { //only one annotation of type rating. //Remove the previous ones. - clearAnnotation(type, id, RatingAnnotationData.class); + clearAnnotation(ctx, type, id, RatingAnnotationData.class); link = ModelMapper.createAnnotationAndLink(ho, annotation); } else if (annotation instanceof FileAnnotationData) { FileAnnotationData ann = (FileAnnotationData) annotation; if (ann.getId() < 0) { - OriginalFile of = gateway.uploadFile(ann.getAttachedFile(), + OriginalFile of = gateway.uploadFile(ctx, ann.getAttachedFile(), ann.getServerFileMimetype(), -1); FileAnnotation fa = new FileAnnotationI(); fa.setFile(of); @@ -859,7 +880,7 @@ public DataObject annotate(Class type, long id, AnnotationData annotation) if (link != null) { IObject object; if (exist) object = link; - else object = gateway.createObject(link); + else object = gateway.createObject(ctx, link); return PojoMapper.asDataObject( ModelMapper.getAnnotatedObject(object)); } @@ -869,15 +890,17 @@ public DataObject annotate(Class type, long id, AnnotationData annotation) /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#clearAnnotation(Class, long, Class) + * @see OmeroMetadataService#clearAnnotation(SecurityContext, Class, long, Class) */ - public void clearAnnotation(Class type, long id, Class annotationType) + public void clearAnnotation(SecurityContext ctx, Class type, long id, + Class annotationType) throws DSOutOfServiceException, DSAccessException { if (type == null) throw new IllegalArgumentException("No object specified."); long userID = getUserDetails().getId(); - Collection annotations = loadStructuredAnnotations(type, id, userID); + Collection annotations = loadStructuredAnnotations(ctx, type, id, + userID); if (annotations == null || annotations.size() == 0) return; List toRemove = new ArrayList(); @@ -895,11 +918,11 @@ public void clearAnnotation(Class type, long id, Class annotationType) List l = null; String klass = gateway.convertPojos(type).getName(); if (ids.size() != 0) - l = gateway.findAnnotationLinks(klass, id, ids); + l = gateway.findAnnotationLinks(ctx, klass, id, ids); if (l != null) { i = l.iterator(); while (i.hasNext()) - gateway.deleteObject((IObject) i.next()); + gateway.deleteObject(ctx, (IObject) i.next()); //Need to check if the object is not linked to other object. @@ -909,42 +932,47 @@ public void clearAnnotation(Class type, long id, Class annotationType) obj = (IObject) i.next(); ids = new ArrayList(); ids.add(obj.getId().getValue()); - l = gateway.findAnnotationLinks(klass, -1, ids); - if (l == null || l.size() == 0) gateway.deleteObject(obj); + l = gateway.findAnnotationLinks(ctx, klass, -1, ids); + if (l == null || l.size() == 0) + gateway.deleteObject(ctx, obj); } } } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#clearAnnotation(DataObject, Class) + * @see OmeroMetadataService#clearAnnotation(SecurityContext, DataObject, Class) */ - public void clearAnnotation(DataObject object, Class annotationType) + public void clearAnnotation(SecurityContext ctx, DataObject object, + Class annotationType) throws DSOutOfServiceException, DSAccessException { if (object == null) throw new IllegalArgumentException("No object specified."); - clearAnnotation(object.getClass(), object.getId(), annotationType); + ctx = gateway.checkContext(ctx, object); + clearAnnotation(ctx, object.getClass(), object.getId(), + annotationType); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#clearAnnotation(DataObject) + * @see OmeroMetadataService#clearAnnotation(SecurityContext, DataObject) */ - public void clearAnnotation(DataObject object) + public void clearAnnotation(SecurityContext ctx, DataObject object) throws DSOutOfServiceException, DSAccessException { if (object == null) throw new IllegalArgumentException("No object specified."); - clearAnnotation(object.getClass(), object.getId(), null); + ctx = gateway.checkContext(ctx, object); + clearAnnotation(ctx, object.getClass(), object.getId(), null); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#loadStructuredAnnotations(Class, long, long) + * @see OmeroMetadataService#loadStructuredAnnotations(SecurityContext, Class, long, long) */ - public Collection loadStructuredAnnotations(Class type, long id, - long userID) + public Collection loadStructuredAnnotations(SecurityContext ctx, Class type, + long id, long userID) throws DSOutOfServiceException, DSAccessException { if (id < 0) new ArrayList(); @@ -957,17 +985,17 @@ public Collection loadStructuredAnnotations(Class type, long id, } List objects = new ArrayList(1); objects.add(id); - Map map = gateway.loadAnnotations(type, objects, null, ids, + Map map = gateway.loadAnnotations(ctx, type, objects, null, ids, new Parameters()); return (Collection) map.get(id); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#loadAnnotations(Class, String, long, long) + * @see OmeroMetadataService#loadAnnotations(SecurityContext, Class, String, long, long) */ - public Collection loadAnnotations(Class annotationType, String nameSpace, - long userID, long groupID) + public Collection loadAnnotations(SecurityContext ctx, Class annotationType, + String nameSpace, long userID, long groupID) throws DSOutOfServiceException, DSAccessException { ParametersI po = new ParametersI(); @@ -988,17 +1016,16 @@ public Collection loadAnnotations(Class annotationType, String nameSpace, if (!FileAnnotationData.EXPERIMENTER_PHOTO_NS.equals(nameSpace)) toExclude.add(FileAnnotationData.EXPERIMENTER_PHOTO_NS); } - return gateway.loadSpecificAnnotation(annotationType, toInclude, + return gateway.loadSpecificAnnotation(ctx, annotationType, toInclude, toExclude, po); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#saveData(Collection, List, List, long) + * @see OmeroMetadataService#saveData(SecurityContext, Collection, List, List, long) */ - public Object saveData(Collection data, - List toAdd, List toRemove, - long userID) + public Object saveData(SecurityContext ctx, Collection data, + List toAdd, List toRemove, long userID) throws DSOutOfServiceException, DSAccessException { if (data == null) @@ -1006,7 +1033,7 @@ public Object saveData(Collection data, OmeroDataService service = context.getDataService(); DataObject object; - List annotations = prepareAnnotationToAdd(toAdd); + List annotations = prepareAnnotationToAdd(ctx, toAdd); Iterator i; Iterator j = data.iterator(); //First create the new annotations @@ -1014,16 +1041,17 @@ public Object saveData(Collection data, while (j.hasNext()) { object = j.next(); if (object instanceof AnnotationData) { - updateAnnotationData(object); + updateAnnotationData(ctx, object); } else { if (object.isLoaded()) - service.updateDataObject(object); + service.updateDataObject(ctx, object); } if (annotations.size() > 0) { i = annotations.iterator(); while (i.hasNext()) { ann = (AnnotationData) i.next(); - if (ann != null) linkAnnotation(object, ann); + if (ann != null) + linkAnnotation(ctx, object, ann); } } if (toRemove != null) { @@ -1041,16 +1069,16 @@ public Object saveData(Collection data, commands.add(cmd); */ - removeAnnotation(ann, object); + removeAnnotation(ctx, ann, object); if (ann instanceof TextualAnnotationData) { - if (!isAnnotationShared(ann, object)) { + if (!isAnnotationShared(ctx, ann, object)) { toDelete.add(ann.asIObject()); } } } } if (toDelete.size() > 0) { - gateway.deleteObjects(toDelete); + gateway.deleteObjects(ctx, toDelete); } } } @@ -1059,11 +1087,11 @@ public Object saveData(Collection data, /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#saveBatchData(Collection, List, List, long) + * @see OmeroMetadataService#saveBatchData(SecurityContext, Collection, List, List, long) */ - public Object saveBatchData(Collection data, - List toAdd, List toRemove, - long userID) + public Object saveBatchData(SecurityContext ctx, + Collection data, List toAdd, + List toRemove, long userID) throws DSOutOfServiceException, DSAccessException { if (data == null) @@ -1078,7 +1106,7 @@ public Object saveBatchData(Collection data, Iterator k; List result = null; //First create the new annotations - List annotations = prepareAnnotationToAdd(toAdd); + List annotations = prepareAnnotationToAdd(ctx, toAdd); List childrenIds = new ArrayList(); while (j.hasNext()) { object = j.next(); @@ -1089,7 +1117,8 @@ public Object saveBatchData(Collection data, //Tmp solution, this code should be pushed server side. ids = new ArrayList(1); ids.add(object.getId()); - images = gateway.getContainerImages(DatasetData.class, ids, po); + images = gateway.getContainerImages(ctx, DatasetData.class, + ids, po); if (images != null) { k = images.iterator(); while (k.hasNext()) { @@ -1100,21 +1129,22 @@ public Object saveBatchData(Collection data, if (annotations != null) { i = annotations.iterator(); while (i.hasNext()) - linkAnnotation(child, + linkAnnotation(ctx, child, (AnnotationData) i.next()); } if (toRemove != null) { i = toRemove.iterator(); while (i.hasNext()) - removeAnnotation((AnnotationData) i.next(), - child); + removeAnnotation(ctx, + (AnnotationData) i.next(), child); } } } } } else if (object instanceof PlateData) { //Load all the wells - images = gateway.loadPlateWells(object.getId(), -1, userID); + images = gateway.loadPlateWells(ctx, object.getId(), -1, + userID); if (images != null) { k = images.iterator(); while (k.hasNext()) { @@ -1125,30 +1155,31 @@ public Object saveBatchData(Collection data, if (annotations != null) { i = annotations.iterator(); while (i.hasNext()) - linkAnnotation(child, + linkAnnotation(ctx, child, (AnnotationData) i.next()); } if (toRemove != null) { i = toRemove.iterator(); while (i.hasNext()) - removeAnnotation((AnnotationData) i.next(), - child); + removeAnnotation(ctx, + (AnnotationData) i.next(), child); } } } } } else if (object instanceof ImageData) { - service.updateDataObject(object); + service.updateDataObject(ctx, object); if (annotations != null) { i = annotations.iterator(); while (i.hasNext()) - linkAnnotation(object, (AnnotationData) i.next()); + linkAnnotation(ctx, object, (AnnotationData) i.next()); //annotate(object, (AnnotationData) i.next()); } if (toRemove != null) { i = toRemove.iterator(); while (i.hasNext()) - removeAnnotation((AnnotationData) i.next(), object); + removeAnnotation(ctx, (AnnotationData) i.next(), + object); } } } @@ -1158,36 +1189,36 @@ public Object saveBatchData(Collection data, /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#saveBatchData(TimeRefObject, List, List, long) + * @see OmeroMetadataService#saveBatchData(SecurityContext, TimeRefObject, List, List, long) */ - public Object saveBatchData(TimeRefObject data, List toAdd, - List toRemove, long userID) - throws DSOutOfServiceException, DSAccessException + public Object saveBatchData(SecurityContext ctx, TimeRefObject data, + List toAdd, List toRemove, long userID) + throws DSOutOfServiceException, DSAccessException { if (data == null) throw new IllegalArgumentException("No data to save"); OmeroDataService service = context.getDataService(); - Collection images = service.getImagesPeriod(data.getStartTime(), - data.getEndTime(), userID, true); + Collection images = service.getImagesPeriod(ctx, data.getStartTime(), + data.getEndTime(), userID, true); List r = new ArrayList(); if (images == null) return r; Iterator i = images.iterator(); DataObject child; Iterator j; //First create the new annotations - List annotations = prepareAnnotationToAdd(toAdd); + List annotations = prepareAnnotationToAdd(ctx, toAdd); while (i.hasNext()) { child = (DataObject) i.next(); r.add(child); if (annotations != null) { j = annotations.iterator(); while (j.hasNext()) - linkAnnotation(child, (AnnotationData) i.next()); + linkAnnotation(ctx, child, (AnnotationData) i.next()); } if (toRemove != null) { j = toRemove.iterator(); while (j.hasNext()) - removeAnnotation((AnnotationData) j.next(), child); + removeAnnotation(ctx, (AnnotationData) j.next(), child); } } return r; @@ -1195,25 +1226,26 @@ public Object saveBatchData(TimeRefObject data, List toAdd, /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#downloadFile(String, long, int) + * @see OmeroMetadataService#downloadFile(SecurityContext, String, long, int) */ - public File downloadFile(File file, long fileID, long size) + public File downloadFile(SecurityContext ctx, File file, long fileID, + long size) throws DSOutOfServiceException, DSAccessException { if (fileID < 0) throw new IllegalArgumentException("File ID not valid"); if (file == null) throw new IllegalArgumentException("File path not valid"); - return gateway.downloadFile(file, fileID, size); + return gateway.downloadFile(ctx, file, fileID, size); } /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#loadRatings(Class, List, long) + * @see OmeroMetadataService#loadRatings(SecurityContext, Class, List, long) */ - public Map loadRatings(Class nodeType, - List nodeIds, long userID) - throws DSOutOfServiceException, DSAccessException + public Map loadRatings(SecurityContext ctx, + Class nodeType, List nodeIds, long userID) + throws DSOutOfServiceException, DSAccessException { List ids = null; if (userID != -1) { @@ -1222,7 +1254,7 @@ public Map loadRatings(Class nodeType, } List types = new ArrayList(); types.add(RatingAnnotationData.class); - Map map = gateway.loadAnnotations(nodeType, nodeIds, types, ids, + Map map = gateway.loadAnnotations(ctx, nodeType, nodeIds, types, ids, new Parameters()); Map results = new HashMap(); if (map == null) return results; @@ -1253,11 +1285,12 @@ public Map loadRatings(Class nodeType, /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#filterByAnnotation(Class, List, Class, List, - * long) + * @see OmeroMetadataService#filterByAnnotation(SecurityContext, + * Class, List, Class, List, long) */ - public Collection filterByAnnotation(Class nodeType, List nodeIds, - Class annotationType, List terms, long userID) + public Collection filterByAnnotation(SecurityContext ctx, Class nodeType, + List nodeIds, Class annotationType, List terms, + long userID) throws DSOutOfServiceException, DSAccessException { Set results = new HashSet(); @@ -1269,7 +1302,7 @@ public Collection filterByAnnotation(Class nodeType, List nodeIds, } List types = new ArrayList(); types.add(annotationType); - Map map = gateway.loadAnnotations(nodeType, nodeIds, types, ids, + Map map = gateway.loadAnnotations(ctx, nodeType, nodeIds, types, ids, new Parameters()); if (map == null || map.size() == 0) return results; long id; @@ -1325,8 +1358,8 @@ public Collection filterByAnnotation(Class nodeType, List nodeIds, } } } else - return filterByAnnotated(nodeType, nodeIds, annotationType, true, - userID); + return filterByAnnotated(ctx, nodeType, nodeIds, annotationType, + true, userID); i = m.entrySet().iterator(); while (i.hasNext()) { @@ -1342,11 +1375,12 @@ public Collection filterByAnnotation(Class nodeType, List nodeIds, /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#filterByAnnotated(Class, List, Class, boolean, - * long) + * @see OmeroMetadataService#filterByAnnotated(SecurityContext, + * Class, List, Class, boolean, long) */ - public Collection filterByAnnotated(Class nodeType, List nodeIds, - Class annotationType, boolean annotated, long userID) + public Collection filterByAnnotated(SecurityContext ctx, Class nodeType, + List nodeIds, Class annotationType, boolean annotated, + long userID) throws DSOutOfServiceException, DSAccessException { List results = new ArrayList(); @@ -1359,7 +1393,7 @@ public Collection filterByAnnotated(Class nodeType, List nodeIds, List types = new ArrayList(); types.add(annotationType); - Map map = gateway.loadAnnotations(nodeType, nodeIds, types, ids, + Map map = gateway.loadAnnotations(ctx, nodeType, nodeIds, types, ids, new Parameters()); if (map == null || map.size() == 0) return results; long id; @@ -1426,11 +1460,11 @@ public Collection filterByAnnotated(Class nodeType, List nodeIds, /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#filterByAnnotation(Class, List, FilterContext, - * long) + * @see OmeroMetadataService#filterByAnnotation(SecurityContext, Class, + * List, FilterContext, long) */ - public Collection filterByAnnotation(Class nodeType, List ids, - FilterContext filter, long userID) + public Collection filterByAnnotation(SecurityContext ctx, Class nodeType, + List ids, FilterContext filter, long userID) throws DSOutOfServiceException, DSAccessException { if (filter == null) @@ -1445,7 +1479,7 @@ public Collection filterByAnnotation(Class nodeType, List ids, } List annotationTypes = new ArrayList(); //types.add(annotationType); - Map map = gateway.loadAnnotations(nodeType, ids, annotationTypes, + Map map = gateway.loadAnnotations(ctx, nodeType, ids, annotationTypes, userIDs, new Parameters()); if (map == null || map.size() == 0) { @@ -1480,7 +1514,7 @@ public Collection filterByAnnotation(Class nodeType, List ids, entry = (Entry) i.next(); type = (Class) entry.getKey(); found = new ArrayList(); - annotations = gateway.filterBy(type, (List) + annotations = gateway.filterBy(ctx, type, (List) entry.getValue(), start, end, exp); j = annotations.iterator(); while (j.hasNext()) @@ -1521,8 +1555,8 @@ public Collection filterByAnnotation(Class nodeType, List ids, } else if (resultType == FilterContext.UNION) { while (i.hasNext()) { type = (Class) i.next(); - annotations = gateway.filterBy(type, types.get(type), - start, end, exp); + annotations = gateway.filterBy(ctx, type, types.get(type), + start, end, exp); i = annotations.iterator(); while (i.hasNext()) annotationsIds.add((Long) i.next()); @@ -1650,74 +1684,78 @@ else if (resultType == FilterContext.INTERSECTION) /** * Implemented as specified by {@link OmeroDataService}. - * @see OmeroMetadataService#getEnumeration(String) + * @see OmeroMetadataService#getEnumeration(SecurityContext, String) */ - public Collection getEnumeration(String type) + public Collection getEnumeration(SecurityContext ctx, String type) throws DSOutOfServiceException, DSAccessException { - return gateway.getEnumerations(type); + return gateway.getEnumerations(ctx, type); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroMetadataService#loadAcquisitionData(Object) + * @see OmeroMetadataService#loadAcquisitionData(SecurityContext, Object) */ - public Object loadAcquisitionData(Object refObject) + public Object loadAcquisitionData(SecurityContext ctx, Object refObject) throws DSOutOfServiceException, DSAccessException { if (refObject instanceof ImageData) { - return gateway.loadImageAcquisitionData( + ctx = gateway.checkContext(ctx, (ImageData) refObject); + return gateway.loadImageAcquisitionData(ctx, ((ImageData) refObject).getId()); - } else if (refObject instanceof ChannelData) { + ctx = gateway.checkContext(ctx, (ChannelData) refObject); Channel c = ((ChannelData) refObject).asChannel(); if (c.getLogicalChannel() == null) return null; long id = c.getLogicalChannel().getId().getValue(); - return gateway.loadChannelAcquisitionData(id); + return gateway.loadChannelAcquisitionData(ctx, id); } return null; } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroMetadataService#loadInstrument(long) + * @see OmeroMetadataService#loadInstrument(SecurityContext, long) */ - public Object loadInstrument(long instrumentID) + public Object loadInstrument(SecurityContext ctx, long instrumentID) throws DSOutOfServiceException, DSAccessException { if (instrumentID <= 0) return null; - return gateway.loadInstrument(instrumentID); + return gateway.loadInstrument(ctx, instrumentID); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroMetadataService#saveAcquisitionData(Object) + * @see OmeroMetadataService#saveAcquisitionData(SecurityContext, Object) */ - public Object saveAcquisitionData(Object refObject) + public Object saveAcquisitionData(SecurityContext ctx, Object refObject) throws DSOutOfServiceException, DSAccessException { if (refObject instanceof ImageAcquisitionData) { ImageAcquisitionData data = (ImageAcquisitionData) refObject; - saveImageAcquisitionData(data); - + ctx = gateway.checkContext(ctx, data); + saveImageAcquisitionData(ctx, data); return null;//loadAcquisitionData(data.asImage()); } else if (refObject instanceof ChannelData) { ChannelData data = (ChannelData) refObject; - saveChannelData(data); + ctx = gateway.checkContext(ctx, data); + saveChannelData(ctx, data); } else if (refObject instanceof ChannelAcquisitionData) { ChannelAcquisitionData data = (ChannelAcquisitionData) refObject; - saveChannelAcquisitionData(data); + ctx = gateway.checkContext(ctx, data); + saveChannelAcquisitionData(ctx, data); } return null; } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroMetadataService#archivedFile(FileAnnotationData, File, int, - * DataObject) + * @see OmeroMetadataService#archivedFile(SecurityContext ctx, + * FileAnnotationData, File, int, DataObject) */ - public Object archivedFile(FileAnnotationData fileAnnotation, File file, - int index, DataObject linkTo) + public Object archivedFile(SecurityContext ctx, + FileAnnotationData fileAnnotation, File file, int index, + DataObject linkTo) throws DSOutOfServiceException, DSAccessException { if (file == null) @@ -1731,10 +1769,12 @@ public Object archivedFile(FileAnnotationData fileAnnotation, File file, ns = FileAnnotationData.EDITOR_EXPERIMENT_NS; break; } + if (fileAnnotation == null) return null; + ctx = gateway.checkContext(ctx, fileAnnotation); //Upload the file back to the server long id = fileAnnotation.getId(); long originalID = fileAnnotation.getFileID(); - OriginalFile of = gateway.uploadFile(file, + OriginalFile of = gateway.uploadFile(ctx, file, fileAnnotation.getServerFileMimetype(), originalID); //Need to relink and delete the previous one. FileAnnotation fa; @@ -1745,19 +1785,19 @@ public Object archivedFile(FileAnnotationData fileAnnotation, File file, if (desc != null) fa.setDescription(omero.rtypes.rstring(desc)); if (ns != null) fa.setNs(omero.rtypes.rstring(ns)); - IObject object = gateway.createObject(fa); + IObject object = gateway.createObject(ctx, fa); id = object.getId().getValue(); } else { fa = (FileAnnotation) - gateway.findIObject(FileAnnotation.class.getName(), id); + gateway.findIObject(ctx, FileAnnotation.class.getName(), id); fa.setFile(of); if (desc != null) fa.setDescription(omero.rtypes.rstring(desc)); if (ns != null) fa.setNs(omero.rtypes.rstring(ns)); - gateway.updateObject(fa, new Parameters()); + gateway.updateObject(ctx, fa, new Parameters()); } fa = (FileAnnotation) - gateway.findIObject(FileAnnotation.class.getName(), id); + gateway.findIObject(ctx, FileAnnotation.class.getName(), id); FileAnnotationData data = (FileAnnotationData) PojoMapper.asDataObject(fa); if (of != null) { @@ -1765,7 +1805,7 @@ public Object archivedFile(FileAnnotationData fileAnnotation, File file, } if (linkTo != null) { if (linkTo.getId() > 0) { - annotate(linkTo, data); + annotate(ctx, linkTo, data); } } return data; @@ -1773,10 +1813,11 @@ public Object archivedFile(FileAnnotationData fileAnnotation, File file, /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroMetadataService#loadTags(Long, boolean, boolean, long, long) + * @see OmeroMetadataService#loadTags(SecurityContext, Long, boolean, + * boolean, long, long) */ - public Collection loadTags(Long id, boolean dataObject, boolean topLevel, - long userID, long groupID) + public Collection loadTags(SecurityContext ctx, Long id, boolean dataObject, + boolean topLevel, long userID, long groupID) throws DSOutOfServiceException, DSAccessException { ParametersI po = new ParametersI(); @@ -1784,17 +1825,16 @@ public Collection loadTags(Long id, boolean dataObject, boolean topLevel, if (groupID >= 0) po.grp(omero.rtypes.rlong(groupID)); if (topLevel) { po.orphan(); - return gateway.loadTagSets(po); + return gateway.loadTagSets(ctx, po); } - Collection l = gateway.loadTags(id, po); - return l; + return gateway.loadTags(ctx, id, po); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroMetadataService#countFileType(long, int) + * @see OmeroMetadataService#countFileType(SecurityContext, long, int) */ - public long countFileType(long userID, int fileType) + public long countFileType(SecurityContext ctx, long userID, int fileType) throws DSOutOfServiceException, DSAccessException { List include = new ArrayList(); @@ -1810,7 +1850,7 @@ public long countFileType(long userID, int fileType) include.add(FileAnnotationData.MOVIE_NS); break; case TAG_NOT_OWNED: - return gateway.countAnnotationsUsedNotOwned( + return gateway.countAnnotationsUsedNotOwned(ctx, TagAnnotationData.class, userID); case OTHER: default: @@ -1824,15 +1864,15 @@ public long countFileType(long userID, int fileType) } ParametersI po = new ParametersI(); if (userID >= 0) po.exp(omero.rtypes.rlong(userID)); - return gateway.countSpecificAnnotation(FileAnnotationData.class, + return gateway.countSpecificAnnotation(ctx, FileAnnotationData.class, include, exclude, po); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroMetadataService#loadFiles(int, long) + * @see OmeroMetadataService#loadFiles(SecurityContext, int, long) */ - public Collection loadFiles(int fileType, long userID) + public Collection loadFiles(SecurityContext ctx, int fileType, long userID) throws DSOutOfServiceException, DSAccessException { List include = new ArrayList(); @@ -1850,7 +1890,7 @@ public Collection loadFiles(int fileType, long userID) include.add(FileAnnotationData.MOVIE_NS); break; case TAG_NOT_OWNED: - return gateway.loadAnnotationsUsedNotOwned( + return gateway.loadAnnotationsUsedNotOwned(ctx, TagAnnotationData.class, userID); case OTHER: default: @@ -1863,21 +1903,20 @@ public Collection loadFiles(int fileType, long userID) exclude.add(FileAnnotationData.EXPERIMENTER_PHOTO_NS); } - return gateway.loadSpecificAnnotation(FileAnnotationData.class, + return gateway.loadSpecificAnnotation(ctx, FileAnnotationData.class, include, exclude, po); } /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroMetadataService#loadAnnotation(long) + * @see OmeroMetadataService#loadAnnotation(SecurityContext, long) */ - public DataObject loadAnnotation(long annotationID) + public DataObject loadAnnotation(SecurityContext ctx, long annotationID) throws DSOutOfServiceException, DSAccessException { //Tmp code - List ids = new ArrayList(1); - ids.add(annotationID); - Set set = gateway.loadAnnotation(ids); + Set set = gateway.loadAnnotation(ctx, + Arrays.asList(annotationID)); if (set.size() != 1) return null; Iterator i = set.iterator(); while (i.hasNext()) { @@ -1888,23 +1927,25 @@ public DataObject loadAnnotation(long annotationID) /** * Implemented as specified by {@link OmeroImageService}. - * @see OmeroMetadataService#loadTabularData(TableParameters, long) + * @see OmeroMetadataService#loadTabularData(SecurityContext ctx, + * TableParameters, long) */ - public List loadTabularData(TableParameters parameters, - long userID) + public List loadTabularData(SecurityContext ctx, + TableParameters parameters, long userID) throws DSOutOfServiceException, DSAccessException { if (parameters == null) throw new IllegalArgumentException("No parameters specified."); - return gateway.loadTabularData(parameters, userID); + return gateway.loadTabularData(ctx, parameters, userID); } /** * Implemented as specified by {@link OmeroImageService}. * @see OmeroMetadataService#loadParentsOfAnnotations(long) */ - public List loadParentsOfAnnotations(long annotationId) - throws DSOutOfServiceException, DSAccessException + public List loadParentsOfAnnotations(SecurityContext ctx, + long annotationId) + throws DSOutOfServiceException, DSAccessException { if (annotationId < 0) throw new IllegalArgumentException("Annotation id not valid."); @@ -1912,7 +1953,7 @@ public List loadParentsOfAnnotations(long annotationId) ExperimenterData exp = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); - List links = gateway.findLinks(FileAnnotation.class, annotationId, + List links = gateway.findLinks(ctx, FileAnnotation.class, annotationId, exp.getId()); List nodes = new ArrayList(); if (links != null) { diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/RequestCallback.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/RequestCallback.java new file mode 100644 index 00000000000..7db5ffd3537 --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/RequestCallback.java @@ -0,0 +1,129 @@ +/* + * org.openmicroscopy.shoola.env.data.RequestCallback + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.env.data; + + +//Java imports + +//Third-party libraries + +//Application-internal dependencies +import omero.ServerError; +import omero.client; +import omero.cmd.CmdCallbackI; +import omero.cmd.HandlePrx; +import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; + +/** + * A handle to a perform operation e.g. delete, move data between groups. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class RequestCallback + extends CmdCallbackI +{ + + /** Helper reference to the adapter to notify. */ + private DSCallAdapter adapter; + + /** List handling the reports. */ + //private List reports; + + /** Flag indicating that the operation has finished. */ + private boolean finished; + + /** Flag indicating that the results have been submitted. */ + private boolean submitted; + + /** + * Creates a new instance. + * + * @param client Reference to the client. + * @param process The process to handle. + * @throws ServerError Thrown if an error occurred while initializing the + * call-back. + */ + RequestCallback(client client, final HandlePrx process) + throws ServerError + { + super(client, process); + //reports = null; + } + + /** + * Sets the adapter. + * + * @param adapter The value to set. + */ + public void setAdapter(DSCallAdapter adapter) + { + this.adapter = adapter; + if (finished && adapter != null) { + if (!submitted) { + //adapter.handleResult(reports); + try { + close(); + } catch (Exception e) {} + } + } + } + + /** + * Overridden to handle the end of the process. + * @see CmdCallbackI#finished(int) + */ + public void finished(int value) + { + /* + super.finished(value); + finished = true; + try { + DeleteReport[] reports = handle.report(); + this.reports = new ArrayList(); + if (handle.errors() != 0) { + for (int i = 0; i < reports.length; i++) + this.reports.add(reports[i]); + } + if (adapter != null) { + submitted = true; + adapter.handleResult(this.reports); + } + } catch (Exception e) { + finished = false; + //if (adapter != null) adapter.handleResult(null); + } + + if (finished && submitted) { + try { + close(); + } catch (Exception e) { + //ignore the exception. + } + } + */ + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/events/ExitApplication.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/events/ExitApplication.java index 071f699a058..5401a4a2227 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/events/ExitApplication.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/events/ExitApplication.java @@ -30,6 +30,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.RequestEvent; /** @@ -53,6 +54,9 @@ public class ExitApplication */ private boolean askQuestion; + /** The last selected security context.*/ + private SecurityContext ctx; + /** Creates a new instance. */ public ExitApplication() { @@ -69,8 +73,26 @@ public ExitApplication() public ExitApplication(boolean askQuestion) { this.askQuestion = askQuestion; + ctx = null; + } + + /** + * Sets the security context. + * + * @param ctx The context to set. + */ + public void setSecurityContext(SecurityContext ctx) + { + this.ctx = ctx; } + /** + * Returns the security context. + * + * @return See above. + */ + public SecurityContext getContext() { return ctx; } + /** * Returns true to ask a question before closing the * application, false otherwise. @@ -78,5 +100,5 @@ public ExitApplication(boolean askQuestion) * @return See above. */ public boolean isAskQuestion() { return askQuestion; } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/DeleteActivityParam.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/DeleteActivityParam.java index 59a9dabe062..81f4a68fee8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/DeleteActivityParam.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/DeleteActivityParam.java @@ -25,6 +25,7 @@ //Java imports import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import javax.swing.Icon; @@ -74,7 +75,7 @@ public class DeleteActivityParam */ public DeleteActivityParam(Icon icon, List objects) { - if (objects == null) + if (objects == null || objects.size() == 0) throw new IllegalArgumentException("No Objects to delete."); this.icon = icon; this.objects = objects; @@ -93,8 +94,7 @@ public DeleteActivityParam(Icon icon, DeletableObject object) if (object == null) throw new IllegalArgumentException("No Object to delete."); this.icon = icon; - objects = new ArrayList(1); - objects.add(object); + objects = Arrays.asList(object); imageID = -1; uiRegister = true; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/ImportableFile.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/ImportableFile.java index f71b65b75cf..5751ab54ab5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/ImportableFile.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/ImportableFile.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.util.StatusLabel; import pojos.DatasetData; +import pojos.GroupData; /** * Store information about the file or folder to import. @@ -48,6 +49,9 @@ public class ImportableFile { + /** The group where to import the data. */ + private GroupData group; + /** The file or folder to import. */ private File file; @@ -195,6 +199,20 @@ public void setLocation(pojos.DataObject parent, DatasetData dataset) */ public void setFile(File file) { this.file = file; } + /** + * Sets the group. + * + * @param group The group where to import the data. + */ + public void setGroup(GroupData group) { this.group = group; } + + /** + * Returns the group. + * + * @return See above. + */ + public GroupData getGroup() { return group; } + /** * Returns a copy of the object. * @@ -208,6 +226,7 @@ public ImportableFile copy() newObject.parent = this.parent; newObject.file = this.file; newObject.refNode = this.refNode; + newObject.group = this.group; newObject.status = new StatusLabel(); return newObject; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/TransferableActivityParam.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/TransferableActivityParam.java new file mode 100644 index 00000000000..be58b6648b1 --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/TransferableActivityParam.java @@ -0,0 +1,127 @@ +/* + * org.openmicroscopy.shoola.env.data.model.TransferableActivityParam + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.env.data.model; + + +//Java imports +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.swing.Icon; + + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + +/** + * Parameters required to move a collection of objects between groups. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class TransferableActivityParam +{ + + /** The icon associated to the parameters. */ + private Icon icon; + + /** The icon associated to the parameters in case of failure. */ + private Icon failureIcon; + + /** The object to transfer.*/ + private TransferableObject object; + + /** + * Creates a new instance. + * + * @param icon The icon associated to the parameters. + * @param object The collection of objects to transfer. + */ + public TransferableActivityParam(Icon icon, TransferableObject object) + { + if (object == null) + throw new IllegalArgumentException("No Objects to transfer."); + this.icon = icon; + this.object = object; + } + + /** + * Sets the failure icon. + * + * @param failureIcon The icon to set. + */ + public void setFailureIcon(Icon failureIcon) + { + this.failureIcon = failureIcon; + } + + /** + * Returns the failure icon. + * + * @return See above. + */ + public Icon getFailureIcon() { return failureIcon; } + + /** + * Returns the icon if set or null. + * + * @return See above. + */ + public Icon getIcon() { return icon; } + + /** + * Returns the collection of objects to transfer. + * + * @return See above. + */ + public TransferableObject getObject() { return object; } + + /** + * Returns the number of objects to transfer. + * + * @return See above. + */ + public int getNumber() + { + int number = 0; + Map> map = object.getSource(); + Iterator> i = map.values().iterator(); + while (i.hasNext()) { + number += i.next().size(); + } + return number; + } + + /** + * Returns the name of the group. + * + * @return See above. + */ + public String getGroupName() { return object.getGroupName(); } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/TransferableObject.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/TransferableObject.java new file mode 100644 index 00000000000..0cb5456f116 --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/model/TransferableObject.java @@ -0,0 +1,140 @@ +/* + * org.openmicroscopy.shoola.env.data.model.TransferableObject + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.env.data.model; + + +//Java imports +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +//Third-party libraries + +//Application-internal dependencies + +import org.openmicroscopy.shoola.env.data.util.SecurityContext; +/** + * Hosts information necessary to transfer objects between groups. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class TransferableObject +{ + + /** The security context of the target object.*/ + private SecurityContext targetContext; + + /** The destination of the change group action.*/ + private List target; + + /** The elements to move.*/ + private Map> source; + + /** The name of the target group.*/ + private String groupName; + + /** + * Creates a new instance. + * + * @param targetContext Information about the destination group. + * Mustn't be null. + * @param target The object where to move data into or null. + * @param source The elements to move. Mustn't be null. + */ + public TransferableObject(SecurityContext targetContext, + pojos.DataObject target, + Map> source) + { + if (targetContext == null) + throw new IllegalArgumentException("No context specified."); + if (source == null || source.size() == 0) + throw new IllegalArgumentException("No elements to move."); + this.targetContext = targetContext; + if (target != null) this.target = Arrays.asList(target); + this.source = source; + } + + /** + * Creates a new instance. + * + * @param targetContext Information about the destination group. + * Mustn't be null. + * @param target The object where to move data into or null. + * @param source The elements to move. Mustn't be null. + */ + public TransferableObject(SecurityContext targetContext, + List target, + Map> source) + { + if (targetContext == null) + throw new IllegalArgumentException("No context specified."); + if (source == null || source.size() == 0) + throw new IllegalArgumentException("No elements to move."); + this.targetContext = targetContext; + this.target = target; + this.source = source; + } + + /** + * Returns the name of the group. + * + * @return See above. + */ + public String getGroupName() { return groupName; } + + /** + * Sets the name of the group. + * + * @param groupName The value to set. + */ + public void setGroupName(String groupName) { this.groupName = groupName; } + + /** + * Returns the security context of the target object. + * + * @return See above. + */ + public SecurityContext getTargetContext() { return targetContext; } + + /** + * Returns the destination of the change group action. + * + * @return See above. + */ + public List getTarget() { return target; } + + + /** + * Returns the elements to move. + * + * @return See above. + */ + public Map> getSource() + { + return source; + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/util/SearchDataContext.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/util/SearchDataContext.java index 1c359182dc6..9d50961bbed 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/util/SearchDataContext.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/util/SearchDataContext.java @@ -153,6 +153,9 @@ public class SearchDataContext /** The number of results returned. */ private int numberOfResults; + /** The collection of groups to perform the search on.*/ + private List groups; + /** * Creates a new instance. * @@ -179,6 +182,21 @@ public SearchDataContext(List scope, List types, unionOfContexts = true; } + /** + * Sets the groups to search into. + * + * @param groups The groups. + */ + public void setGroups(List groups) { this.groups = groups; } + + /** + * Returns the groups to search into. + * + * @return See above. + */ + public List getGroups() { return groups; } + + /** * Sets to true if it is an union of contexts, or * false if it is an intersection of contexts. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/util/SecurityContext.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/util/SecurityContext.java new file mode 100644 index 00000000000..068fd2a08a0 --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/util/SecurityContext.java @@ -0,0 +1,138 @@ +/* + * org.openmicroscopy.shoola.env.data.util.SecurityContext + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.env.data.util; + +//Java imports + +//Third-party libraries + +//Application-internal dependencies + +/** + * Hosts information required to access correct connector. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class SecurityContext +{ + + /** The identifier of the group.*/ + private long groupID; + + /** The experimenterID if required.*/ + private long experimenterID; + + /** The name of the server.*/ + private String host; + + /** The port to use.*/ + private int port; + + /** The compression level. */ + private float compression; + + /** + * Creates a new instance. + * + * @param groupID The identifier of the group. + */ + public SecurityContext(long groupID) + { + this.groupID = groupID; + experimenterID = -1; + } + + /** + * Sets the experimenter ID. + * + * @param experimenterID The id of the experimenter. + */ + public void setExperimenter(long experimenterID) + { + this.experimenterID = experimenterID; + } + + /** + * Returns the id of the experimenter. + * + * @return See above. + */ + public long getExperimenter() { return experimenterID; } + + /** + * Sets the information used to connect to the correct server. + * + * @param host The name of the server. + * @param port The port to use. + */ + public void setServerInformation(String host, int port) + { + this.host = host; + this.port = port; + } + + /** + * Sets the information used to connect to the correct server. + * + * @param host The name of the server. + */ + public void setServerInformation(String host) + { + this.host = host; + } + + /** + * Returns the hostname. + * + * @return See above. + */ + public String getHostName() { return host; } + + /** + * Sets the compression level. + * + * @param compression The value to set. + */ + public void setCompression(float compression) + { + this.compression = compression; + } + + /** + * Returns the compression. + * + * @return See above. + */ + public float getCompression() { return compression; } + + /** + * Returns the identifier of the group. + * + * @return See above. + */ + public long getGroupID() { return groupID; } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/AdminView.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/AdminView.java index a6dd5ad48fa..e7e3b6a76bd 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/AdminView.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/AdminView.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.login.UserCredentials; import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.AgentEventListener; import pojos.DataObject; import pojos.ExperimenterData; @@ -59,16 +60,18 @@ public interface AdminView * Loads the used and free disk space for the specified user if any, * pass -1 to retrieve the whole disk space. * + * @param ctx The security context. * @param id The id of the user or the group -1. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle getDiskSpace(Class type, long id, + public CallHandle getDiskSpace(SecurityContext ctx, Class type, long id, AgentEventListener observer); /** * Loads the disk space used by groups * + * @param ctx The security context. * @param type Either ExperimenterData or * GroupData. * @param ids The identifier of the groups/users or null to @@ -76,156 +79,173 @@ public CallHandle getDiskSpace(Class type, long id, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle getDiskSpace(Class type, List ids, - AgentEventListener observer); + public CallHandle getDiskSpace(SecurityContext ctx, Class type, + List ids, AgentEventListener observer); /** * Loads the users who are administrators. * + * @param ctx The security context. * @param id The identifier of the groups. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadAdministrators(AgentEventListener observer); + public CallHandle loadAdministrators(SecurityContext ctx, + AgentEventListener observer); /** * Updates the specified experimenter. * + * @param ctx The security context. * @param exp The experimenter to update. Mustn't be null. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle updateExperimenter(ExperimenterData exp, - AgentEventListener observer); + public CallHandle updateExperimenter(SecurityContext ctx, + ExperimenterData exp, AgentEventListener observer); /** * Updates the specified group. * + * @param ctx The security context. * @param group The group to update. Mustn't be null. * @param permissions The desired permissions level or -1. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle updateGroup(GroupData group, int permissions, - AgentEventListener observer); + public CallHandle updateGroup(SecurityContext ctx, GroupData group, + int permissions, AgentEventListener observer); /** * Creates and returns the experimenters. * + * @param ctx The security context. * @param object The object hosting information about the experimenters * to create. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle createExperimenters(AdminObject object, - AgentEventListener observer); + public CallHandle createExperimenters(SecurityContext ctx, + AdminObject object, AgentEventListener observer); /** * Creates and returns the new group. * + * @param ctx The security context. * @param object The object hosting information about the group to create. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle createGroup(AdminObject object, + public CallHandle createGroup(SecurityContext ctx, AdminObject object, AgentEventListener observer); /** * Modifies the password of the currently logged in user. * + * @param ctx The security context. * @param oldPassword The old password. * @param newPassword The new password. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle changePassword(String oldPassword, String newPassword, - AgentEventListener observer); + public CallHandle changePassword(SecurityContext ctx, + String oldPassword, String newPassword, AgentEventListener observer); /** * Loads all the available groups. * + * @param ctx The security context. * @param groupID The group identifier or -1. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadExperimenterGroups(long groupID, + public CallHandle loadExperimenterGroups(SecurityContext ctx, long groupID, AgentEventListener observer); /** * Loads the experimenters contained within the specified groups. * + * @param ctx The security context. * @param groupID The group identifier or -1. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadExperimenters(long groupID, + public CallHandle loadExperimenters(SecurityContext ctx, long groupID, AgentEventListener observer); /** * Deletes the specified experimenters or groups. Returns the experimenters * or groups that could not be deleted. * + * @param ctx The security context. * @param experimenters The experimenters to delete. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle deleteObjects(List objects, - AgentEventListener observer); + public CallHandle deleteObjects(SecurityContext ctx, + List objects, AgentEventListener observer); /** * Updates the specified experimenters. Returns the experimenters * that could not be updated. * + * @param ctx The security context. * @param experimenters The experimenters to update. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle updateExperimenters(GroupData group, + public CallHandle updateExperimenters(SecurityContext ctx, + GroupData group, Map experimenters, AgentEventListener observer); /** * Resets the password of the experimenters. * + * @param ctx The security context. * @param object The object hosting information about the experimenters * to handle. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle resetExperimentersPassword(AdminObject object, - AgentEventListener observer); + public CallHandle resetExperimentersPassword(SecurityContext ctx, + AdminObject object, AgentEventListener observer); /** * Activates or no the passed experimenters. * + * @param ctx The security context. * @param object The object hosting information about the experimenters * to handle. - * @param observer Call-back handler. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle activateExperimenters(AdminObject object, - AgentEventListener observer); + public CallHandle activateExperimenters(SecurityContext ctx, + AdminObject object, AgentEventListener observer); /** * Resets the password of the experimenters. * + * @param ctx The security context. * @param experimenter The experimenter to handle. - * @param observer Call-back handler. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadExperimenterPhoto(ExperimenterData experimenter, - AgentEventListener observer); + public CallHandle loadExperimenterPhoto(SecurityContext ctx, + ExperimenterData experimenter, AgentEventListener observer); /** * Resets the password of the experimenters. * - * @param experimenter The experimenter to handle. - * @param photo The photo to upload. + * @param ctx The security context. + * @param experimenter The experimenter to handle. + * @param photo The photo to upload. * @param format The format of the file. - * @param observer Call-back handler. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle uploadExperimenterPhoto(ExperimenterData experimenter, - File photo, String format, AgentEventListener observer); + public CallHandle uploadExperimenterPhoto(SecurityContext ctx, + ExperimenterData experimenter, File photo, String format, + AgentEventListener observer); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/AdminViewImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/AdminViewImpl.java index 5e9d76296ac..221a805ec22 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/AdminViewImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/AdminViewImpl.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.login.UserCredentials; import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.calls.AdminLoader; import org.openmicroscopy.shoola.env.data.views.calls.AdminSaver; import org.openmicroscopy.shoola.env.event.AgentEventListener; @@ -59,182 +60,184 @@ class AdminViewImpl /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#updateExperimenter(ExperimenterData, + * @see AdminView#updateExperimenter(SecurityContext, ExperimenterData, * AgentEventListener) */ - public CallHandle updateExperimenter(ExperimenterData exp, - AgentEventListener observer) + public CallHandle updateExperimenter(SecurityContext ctx, + ExperimenterData exp, AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(exp, + BatchCallTree cmd = new AdminLoader(ctx, exp, AdminLoader.EXPERIMENTER_UPDATE); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#updateGroup(GroupData, int AgentEventListener) + * @see AdminView#updateGroup(SecurityContext, GroupData, int, AgentEventListener) */ - public CallHandle updateGroup(GroupData group, int permissions, - AgentEventListener observer) + public CallHandle updateGroup(SecurityContext ctx, GroupData group, + int permissions, AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(group, permissions); + BatchCallTree cmd = new AdminLoader(ctx, group, permissions); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#changePassword(String, String, AgentEventListener) + * @see AdminView#changePassword(SecurityContext, String, String, AgentEventListener) */ - public CallHandle changePassword(String oldPassword, String newPassword, - AgentEventListener observer) + public CallHandle changePassword(SecurityContext ctx, String oldPassword, + String newPassword, AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(oldPassword, newPassword); + BatchCallTree cmd = new AdminLoader(ctx, oldPassword, newPassword); return cmd.exec(observer); } - - + /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#getDiskSpace(Class, long, AgentEventListener) + * @see AdminView#getDiskSpace(SecurityContext, Class, long, AgentEventListener) */ - public CallHandle getDiskSpace(Class type, long id, + public CallHandle getDiskSpace(SecurityContext ctx, Class type, long id, AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(type, id); + BatchCallTree cmd = new AdminLoader(ctx, type, id); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#createExperimenters(AdminObject, AgentEventListener) + * @see AdminView#createExperimenters(SecurityContext, AdminObject, AgentEventListener) */ - public CallHandle createExperimenters(AdminObject object, - AgentEventListener observer) + public CallHandle createExperimenters(SecurityContext ctx, + AdminObject object, AgentEventListener observer) { - BatchCallTree cmd = new AdminSaver(object); + BatchCallTree cmd = new AdminSaver(ctx, object); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#createGroup(AdminObject, AgentEventListener) + * @see AdminView#createGroup(SecurityContext, AdminObject, AgentEventListener) */ - public CallHandle createGroup(AdminObject object, + public CallHandle createGroup(SecurityContext ctx, AdminObject object, AgentEventListener observer) { - BatchCallTree cmd = new AdminSaver(object); + BatchCallTree cmd = new AdminSaver(ctx, object); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#loadExperimenterGroups(long, AgentEventListener) + * @see AdminView#loadExperimenterGroups(SecurityContext, long, AgentEventListener) */ - public CallHandle loadExperimenterGroups(long groupID, + public CallHandle loadExperimenterGroups(SecurityContext ctx, long groupID, AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(groupID, AdminLoader.GROUPS); + BatchCallTree cmd = new AdminLoader(ctx, groupID, AdminLoader.GROUPS); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#loadExperimenters(long, AgentEventListener) + * @see AdminView#loadExperimenters(SecurityContext, long, AgentEventListener) */ - public CallHandle loadExperimenters(long groupID, + public CallHandle loadExperimenters(SecurityContext ctx, long groupID, AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(groupID, AdminLoader.EXPERIMENTERS); + BatchCallTree cmd = new AdminLoader(ctx, groupID, + AdminLoader.EXPERIMENTERS); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#deleteObjects(List, AgentEventListener) + * @see AdminView#deleteObjects(SecurityContext, List, AgentEventListener) */ - public CallHandle deleteObjects(List objects, - AgentEventListener observer) + public CallHandle deleteObjects(SecurityContext ctx, + List objects, AgentEventListener observer) { - BatchCallTree cmd = new AdminSaver(objects, AdminSaver.DELETE); + BatchCallTree cmd = new AdminSaver(ctx, objects, AdminSaver.DELETE); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#updateExperimenters(Map, AgentEventListener) + * @see AdminView#updateExperimenters(SecurityContext, Map, AgentEventListener) */ - public CallHandle updateExperimenters(GroupData group, + public CallHandle updateExperimenters(SecurityContext ctx, GroupData group, Map experimenters, AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(group, experimenters); + BatchCallTree cmd = new AdminLoader(ctx, group, experimenters); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#resetExperimentersPassword(AdminObject, + * @see AdminView#resetExperimentersPassword(SecurityContext, AdminObject, * AgentEventListener) */ - public CallHandle resetExperimentersPassword(AdminObject object, - AgentEventListener observer) + public CallHandle resetExperimentersPassword(SecurityContext ctx, + AdminObject object, AgentEventListener observer) { - BatchCallTree cmd = new AdminSaver(object); + BatchCallTree cmd = new AdminSaver(ctx, object); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#activateExperimenters(AdminObject, AgentEventListener) + * @see AdminView#activateExperimenters(SecurityContext, AdminObject, AgentEventListener) */ - public CallHandle activateExperimenters(AdminObject object, - AgentEventListener observer) + public CallHandle activateExperimenters(SecurityContext ctx, + AdminObject object, AgentEventListener observer) { - BatchCallTree cmd = new AdminSaver(object); + BatchCallTree cmd = new AdminSaver(ctx, object); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#loadExperimenterPhoto(ExperimenterData, + * @see AdminView#loadExperimenterPhoto(SecurityContext, ExperimenterData, * AgentEventListener) */ - public CallHandle loadExperimenterPhoto(ExperimenterData experimenter, - AgentEventListener observer) + public CallHandle loadExperimenterPhoto(SecurityContext ctx, + ExperimenterData experimenter, AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(experimenter, + BatchCallTree cmd = new AdminLoader(ctx, experimenter, AdminLoader.EXPERIMENTER_PHOTO); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#uploadExperimenterPhoto(ExperimenterData, File, String + * @see AdminView#uploadExperimenterPhoto(SecurityContext, ExperimenterData, File, String * AgentEventListener) */ - public CallHandle uploadExperimenterPhoto(ExperimenterData experimenter, - File photo, String format, AgentEventListener observer) + public CallHandle uploadExperimenterPhoto(SecurityContext ctx, + ExperimenterData experimenter, File photo, String format, + AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(experimenter, photo, format); + BatchCallTree cmd = new AdminLoader(ctx, experimenter, photo, format); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#getDiskSpace(Class, List, AgentEventListener) + * @see AdminView#getDiskSpace(SecurityContext, Class, List, AgentEventListener) */ - public CallHandle getDiskSpace(Class type, List ids, - AgentEventListener observer) + public CallHandle getDiskSpace(SecurityContext ctx, Class type, + List ids, AgentEventListener observer) { - BatchCallTree cmd = new AdminLoader(type, ids); + BatchCallTree cmd = new AdminLoader(ctx, type, ids); return cmd.exec(observer); } /** * Implemented as specified by the {@link AdminView} interface. - * @see AdminView#loadAdministrators(AgentEventListener) + * @see AdminView#loadAdministrators(SecurityContext, AgentEventListener) */ - public CallHandle loadAdministrators(AgentEventListener observer) + public CallHandle loadAdministrators(SecurityContext ctx, + AgentEventListener observer) { return null; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataHandlerView.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataHandlerView.java index 40a539bfe73..1e837676018 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataHandlerView.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataHandlerView.java @@ -34,6 +34,7 @@ import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.AgentEventListener; import pojos.ExperimenterData; @@ -57,14 +58,15 @@ public interface DataHandlerView /** * Loads the images imported during the passed period. * - * @param startTime The lower bound of the period interval. - * @param endTime The upper bound of the interval. - * @param userID The id of the user the images belonged to. - * @param observer Call-back handler. + * @param ctx The security context. + * @param startTime The lower bound of the period interval. + * @param endTime The upper bound of the interval. + * @param userID The id of the user the images belonged to. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadImages(Timestamp startTime, Timestamp endTime, - long userID, AgentEventListener observer); + public CallHandle loadImages(SecurityContext ctx, Timestamp startTime, + Timestamp endTime, long userID, AgentEventListener observer); /** * Applies the rendering settings associated to the passed pixels set @@ -73,16 +75,17 @@ public CallHandle loadImages(Timestamp startTime, Timestamp endTime, * Applies the settings to the passed images if the type is * ImageData. * - * @param pixelsID The id of the pixels set of reference. - * @param rootNodeType The type of nodes. Can either be + * @param ctx The security context. + * @param pixelsID The id of the pixels set of reference. + * @param rootNodeType The type of nodes. Can either be * ImageData, DatasetData. - * @param ids The identifiers of the nodes to apply settings to. - * Mustn't be null. - * @param observer Call-back handler. + * @param ids The identifiers of the nodes to apply settings to. + * Mustn't be null. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle pasteRndSettings(long pixelsID, Class rootNodeType, - List ids, AgentEventListener observer); + public CallHandle pasteRndSettings(SecurityContext ctx, long pixelsID, + Class rootNodeType, List ids, AgentEventListener observer); /** * Applies the rendering settings associated to the passed pixels set @@ -91,13 +94,14 @@ public CallHandle pasteRndSettings(long pixelsID, Class rootNodeType, * Applies the settings to the passed images if the type is * ImageData. * - * @param pixelsID The identifier of the pixels set of reference. - * @param ref The time reference object. - * @param observer Call-back handler. + * @param ctx The security context. + * @param pixelsID The identifier of the pixels set of reference. + * @param ref The time reference object. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle pasteRndSettings(long pixelsID, TimeRefObject ref, - AgentEventListener observer); + public CallHandle pasteRndSettings(SecurityContext ctx, long pixelsID, + TimeRefObject ref, AgentEventListener observer); /** * Resets the rendering settings for the images contained in the @@ -105,25 +109,27 @@ public CallHandle pasteRndSettings(long pixelsID, TimeRefObject ref, * Resets the settings to the passed images if the type is * ImageData. * - * @param rootNodeType The type of nodes. Can either be - * ImageData, DatasetData. - * @param ids The identifiers of the nodes to apply settings to. - * Mustn't be null. - * @param observer Call-back handler. + * @param ctx The security context. + * @param rootNodeType The type of nodes. Can either be + * ImageData, DatasetData. + * @param ids The identifiers of the nodes to apply settings to. + * Mustn't be null. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle resetRndSettings(Class rootNodeType, List ids, - AgentEventListener observer); + public CallHandle resetRndSettings(SecurityContext ctx, Class rootNodeType, + List ids, AgentEventListener observer); /** * Resets the rendering settings associated for the images imported during * a period of time * - * @param ref The time reference object. - * @param observer Call-back handler. + * @param ctx The security context. + * @param ref The time reference object. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle resetRndSettings(TimeRefObject ref, + public CallHandle resetRndSettings(SecurityContext ctx, TimeRefObject ref, AgentEventListener observer); /** @@ -132,25 +138,27 @@ public CallHandle resetRndSettings(TimeRefObject ref, * Resets the settings to the passed images if the type is * ImageData. * - * @param rootNodeType The type of nodes. Can either be - * ImageData, DatasetData. - * @param ids The identifiers of the nodes to apply settings to. - * Mustn't be null. - * @param observer Call-back handler. + * @param ctx The security context. + * @param rootNodeType The type of nodes. Can either be + * ImageData, DatasetData. + * @param ids The identifiers of the nodes to apply settings to. + * Mustn't be null. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle setMinMaxSettings(Class rootNodeType, List ids, - AgentEventListener observer); + public CallHandle setMinMaxSettings(SecurityContext ctx, Class rootNodeType, + List ids, AgentEventListener observer); /** * Resets the rendering settings associated for the images imported during * a period of time * - * @param ref The time reference object. - * @param observer Call-back handler. + * @param ctx The security context. + * @param ref The time reference object. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle setMinMaxSettings(TimeRefObject ref, + public CallHandle setMinMaxSettings(SecurityContext ctx, TimeRefObject ref, AgentEventListener observer); /** @@ -159,6 +167,7 @@ public CallHandle setMinMaxSettings(TimeRefObject ref, * If the rootType is ImageDataImageData, DatasetData. * @param ids The identifiers of the nodes to apply settings to. @@ -166,51 +175,56 @@ public CallHandle setMinMaxSettings(TimeRefObject ref, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle setOwnerRndSettings(Class rootNodeType, List ids, - AgentEventListener observer); + public CallHandle setOwnerRndSettings(SecurityContext ctx, + Class rootNodeType, List ids, AgentEventListener observer); /** * Resets the rendering settings used by the owner of the images * imported during a period of time * - * @param ref The time reference object. - * @param observer Call-back handler. + * @param ctx The security context. + * @param ref The time reference object. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle setOwnerRndSettings(TimeRefObject ref, - AgentEventListener observer); + public CallHandle setOwnerRndSettings(SecurityContext ctx, + TimeRefObject ref, AgentEventListener observer); /** * Retrieves the objects specified by the context of the search. * - * @param context The context of the search. - * @param observer Call-back handler. + * @param ctx The security context. + * @param context The context of the search. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle advancedSearchFor(SearchDataContext context, - AgentEventListener observer); + public CallHandle advancedSearchFor(List ctx, + SearchDataContext context, AgentEventListener observer); /** * Loads the files of a given type. The type is one the constants * defined by the {@link OmeroMetadataService}. * - * @param type The type to handle. + * @param ctx The security context. + * @param type The type to handle. * @param userID The id of the user. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadFiles(int type, long userID, + public CallHandle loadFiles(SecurityContext ctx, int type, long userID, AgentEventListener observer); /** * Switches the user's group. * - * @param experimenter The experimenter to handle. - * @param groupID The identifier of the group. - * @param observer Call-back handler. + * @param ctx The security context. + * @param experimenter The experimenter to handle. + * @param groupID The identifier of the group. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle switchUserGroup( ExperimenterData experimenter, - long groupID, AgentEventListener observer); + public CallHandle switchUserGroup(SecurityContext ctx, + ExperimenterData experimenter, long groupID, + AgentEventListener observer); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataHandlerViewImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataHandlerViewImpl.java index bdc68773a02..c68ac00ed8d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataHandlerViewImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataHandlerViewImpl.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.model.TimeRefObject; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.calls.FilesLoader; import org.openmicroscopy.shoola.env.data.views.calls.ImagesLoader; import org.openmicroscopy.shoola.env.data.views.calls.ObjectFinder; @@ -59,143 +60,144 @@ public class DataHandlerViewImpl /** * Implemented as specified by the view interface. - * @see DataHandlerView#loadImages(Timestamp, Timestamp, long, + * @see DataHandlerView#loadImages(SecurityContext, Timestamp, Timestamp, long, * AgentEventListener) */ - public CallHandle loadImages(Timestamp startTime, Timestamp endTime, - long userID, AgentEventListener observer) + public CallHandle loadImages(SecurityContext ctx, Timestamp startTime, + Timestamp endTime, long userID, AgentEventListener observer) { - BatchCallTree cmd = new ImagesLoader(startTime, endTime, userID); + BatchCallTree cmd = new ImagesLoader(ctx, startTime, endTime, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#pasteRndSettings(long, Class, List, + * @see DataHandlerView#pasteRndSettings(SecurityContext, long, Class, List, * AgentEventListener) */ - public CallHandle pasteRndSettings(long pixelsID, Class rootNodeType, - List ids, AgentEventListener observer) + public CallHandle pasteRndSettings(SecurityContext ctx, long pixelsID, + Class rootNodeType, List ids, AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsSaver(pixelsID, rootNodeType, - ids); + BatchCallTree cmd = new RenderingSettingsSaver(ctx, pixelsID, + rootNodeType, ids); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#pasteRndSettings(long, TimeRefObject, + * @see DataHandlerView#pasteRndSettings(SecurityContext, long, TimeRefObject, * AgentEventListener) */ - public CallHandle pasteRndSettings(long pixelsID, TimeRefObject ref, - AgentEventListener observer) + public CallHandle pasteRndSettings(SecurityContext ctx, long pixelsID, + TimeRefObject ref, AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsSaver(pixelsID, ref); + BatchCallTree cmd = new RenderingSettingsSaver(ctx, pixelsID, ref); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#resetRndSettings(Class, List, AgentEventListener) + * @see DataHandlerView#resetRndSettings(SecurityContext, Class, List, AgentEventListener) */ - public CallHandle resetRndSettings(Class rootNodeType, List ids, - AgentEventListener observer) + public CallHandle resetRndSettings(SecurityContext ctx, Class rootNodeType, + List ids, AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsSaver(rootNodeType, ids, + BatchCallTree cmd = new RenderingSettingsSaver(ctx, rootNodeType, ids, RenderingSettingsSaver.RESET); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#resetRndSettings(TimeRefObject, AgentEventListener) + * @see DataHandlerView#resetRndSettings(SecurityContext, TimeRefObject, AgentEventListener) */ - public CallHandle resetRndSettings(TimeRefObject ref, + public CallHandle resetRndSettings(SecurityContext ctx, TimeRefObject ref, AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsSaver(ref, + BatchCallTree cmd = new RenderingSettingsSaver(ctx, ref, RenderingSettingsSaver.RESET); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#setMinMaxSettings(Class, List, AgentEventListener) + * @see DataHandlerView#setMinMaxSettings(SecurityContext, Class, List, AgentEventListener) */ - public CallHandle setMinMaxSettings(Class rootNodeType, List ids, - AgentEventListener observer) + public CallHandle setMinMaxSettings(SecurityContext ctx, Class rootNodeType, + List ids, AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsSaver(rootNodeType, ids, + BatchCallTree cmd = new RenderingSettingsSaver(ctx, rootNodeType, ids, RenderingSettingsSaver.SET_MIN_MAX); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#setMinMaxSettings(TimeRefObject, AgentEventListener) + * @see DataHandlerView#setMinMaxSettings(SecurityContext, TimeRefObject, AgentEventListener) */ - public CallHandle setMinMaxSettings(TimeRefObject ref, + public CallHandle setMinMaxSettings(SecurityContext ctx, TimeRefObject ref, AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsSaver(ref, + BatchCallTree cmd = new RenderingSettingsSaver(ctx, ref, RenderingSettingsSaver.SET_MIN_MAX); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#setOwnerRndSettings(Class, List, AgentEventListener) + * @see DataHandlerView#setOwnerRndSettings(SecurityContext, Class, List, AgentEventListener) */ - public CallHandle setOwnerRndSettings(Class rootNodeType, List ids, - AgentEventListener observer) + public CallHandle setOwnerRndSettings(SecurityContext ctx, + Class rootNodeType, List ids, AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsSaver(rootNodeType, ids, + BatchCallTree cmd = new RenderingSettingsSaver(ctx, rootNodeType, ids, RenderingSettingsSaver.SET_OWNER); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#setOwnerRndSettings(TimeRefObject, AgentEventListener) + * @see DataHandlerView#setOwnerRndSettings(SecurityContext, TimeRefObject, AgentEventListener) */ - public CallHandle setOwnerRndSettings(TimeRefObject ref, - AgentEventListener observer) + public CallHandle setOwnerRndSettings(SecurityContext ctx, + TimeRefObject ref, AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsSaver(ref, + BatchCallTree cmd = new RenderingSettingsSaver(ctx, ref, RenderingSettingsSaver.SET_OWNER); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#advancedSearchFor(SearchDataContext, + * @see DataHandlerView#advancedSearchFor(List, SearchDataContext, * AgentEventListener) */ - public CallHandle advancedSearchFor(SearchDataContext context, - AgentEventListener observer) + public CallHandle advancedSearchFor(List ctx, + SearchDataContext context, AgentEventListener observer) { - BatchCallTree cmd = new ObjectFinder(context); + BatchCallTree cmd = new ObjectFinder(ctx, context); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#loadFiles(int, long, AgentEventListener) + * @see DataHandlerView#loadFiles(SecurityContext, int, long, AgentEventListener) */ - public CallHandle loadFiles(int type, long userID, + public CallHandle loadFiles(SecurityContext ctx, int type, long userID, AgentEventListener observer) { - BatchCallTree cmd = new FilesLoader(type, userID); + BatchCallTree cmd = new FilesLoader(ctx, type, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataHandlerView#switchUserGroup(ExperimenterData, long, + * @see DataHandlerView#switchUserGroup(SecurityContext, ExperimenterData, long, * AgentEventListener) */ - public CallHandle switchUserGroup(ExperimenterData experimenter, - long groupID, AgentEventListener observer) + public CallHandle switchUserGroup(SecurityContext ctx, + ExperimenterData experimenter, long groupID, + AgentEventListener observer) { BatchCallTree cmd = new SwitchUserGroupLoader(experimenter, groupID); return cmd.exec(observer); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataManagerView.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataManagerView.java index 98ce72d9a14..f53686e5d9a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataManagerView.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataManagerView.java @@ -36,7 +36,11 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.model.DeletableObject; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.model.TransferableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.AgentEventListener; +import org.openmicroscopy.shoola.env.ui.DataObjectTransfer; + import pojos.DataObject; import pojos.ImageData; @@ -61,6 +65,7 @@ public interface DataManagerView /** * Retrieves the hierarchies specified by the parameters. * + * @param ctx The security context. * @param rootNodeType The type of the root node. Can only be one out of: * ProjectData, DatasetData. * @param rootNodeIDs A set of the IDs of top-most containers. Passed @@ -73,22 +78,25 @@ public interface DataManagerView * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadContainerHierarchy(Class rootNodeType, - List rootNodeIDs, boolean withLeaves, long userID, - long groupID, AgentEventListener observer); + public CallHandle loadContainerHierarchy(SecurityContext ctx, + Class rootNodeType, List rootNodeIDs, boolean withLeaves, + long userID, long groupID, AgentEventListener observer); /** * Retrieves the images for the specified user. * - * @param userID The ID of the user. - * @param observer Call-back handler. + * @param ctx The security context. + * @param userID The ID of the user. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadImages(long userID, AgentEventListener observer); + public CallHandle loadImages(SecurityContext ctx, long userID, + AgentEventListener observer); /** * Retrieves the images container in the specified root nodes. * + * @param ctx The security context. * @param nodeType The type of the node. Can only be one out of: * DatasetData. * @param nodeIDs The id of the node. @@ -96,29 +104,31 @@ public CallHandle loadContainerHierarchy(Class rootNodeType, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle getImages(Class nodeType, List nodeIDs, long userID, - AgentEventListener observer); + public CallHandle getImages(SecurityContext ctx, Class nodeType, + List nodeIDs, long userID, AgentEventListener observer); /** * Creates a new DataObject whose parent is specified by the * ID. * - * @param userObject The type of DataObject to create. - * @param parent The parent of the DataObject. - * @param observer Call-back handler. + * @param ctx The security context. + * @param userObject The type of DataObject to create. + * @param parent The parent of the DataObject. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle createDataObject(DataObject userObject, DataObject parent, - AgentEventListener observer); + public CallHandle createDataObject(SecurityContext ctx, + DataObject userObject, DataObject parent, AgentEventListener observer); /** * Counts the number of items contained in the specified containers. * + * @param ctx The security context. * @param rootNodeIDs Collection of top-most containers. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle countContainerItems(Set rootNodeIDs, + public CallHandle countContainerItems(SecurityContext ctx, Set rootNodeIDs, AgentEventListener observer); /** @@ -133,42 +143,46 @@ public CallHandle countContainerItems(Set rootNodeIDs, * original image and so that their area doesn't exceed maxWidth* * maxHeight. * - * @param image The ImageData object the thumbnail is for. - * @param maxWidth The maximum acceptable width of the thumbnails. + * @param ctx The security context. + * @param image The ImageData object the thumbnail is for. + * @param maxWidth The maximum acceptable width of the thumbnails. * @param maxHeight The maximum acceptable height of the thumbnails. - * @param userID The id of the user the thumbnails are for. - * @param observer Call-back handler. + * @param userID The id of the user the thumbnails are for. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadThumbnail(ImageData image, int maxWidth, - int maxHeight, long userID, AgentEventListener observer); - + public CallHandle loadThumbnail(SecurityContext ctx, ImageData image, + int maxWidth, int maxHeight, long userID, + AgentEventListener observer); /** * Adds the specified items to the parent. * - * @param parents The DataObjects to update. Either a + * @param ctx The security context. + * @param parents The DataObjects to update. Either a * ProjectData or DatasetData. * @param children The items to add. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle addExistingObjects(Collection parent, Collection children, - AgentEventListener observer); + public CallHandle addExistingObjects(SecurityContext ctx, + Collection parent, Collection children, AgentEventListener observer); /** * Adds the specified items to the parent. * + * @param ctx The security context. * @param objects The objects to update. * @param observer Callback handler. * @return A handle that can be used to cancel the call. */ - public CallHandle addExistingObjects(Map objects, Map toRemove, - AgentEventListener observer); + public CallHandle addExistingObjects(SecurityContext ctx, Map objects, + Map toRemove, AgentEventListener observer); /** * Cuts and Pastes. * + * @param ctx The security context. * @param toPaste Map of objects to paste into * where the key is the DataObject to paste * into and the value is a set of DataObject @@ -182,12 +196,13 @@ public CallHandle addExistingObjects(Map objects, Map toRemove, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle cutAndPaste(Map toPaste, Map toCut, boolean admin, - AgentEventListener observer); + public CallHandle cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut, + boolean admin, AgentEventListener observer); /** * Loads the emission wavelengths for the given set of pixels. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param userID If the id is specified i.e. not -1, * load the color associated to the channel, @@ -195,38 +210,39 @@ public CallHandle cutAndPaste(Map toPaste, Map toCut, boolean admin, * @param observer Callback handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadChannelsData(long pixelsID, long userID, - AgentEventListener observer); + public CallHandle loadChannelsData(SecurityContext ctx, long pixelsID, + long userID, AgentEventListener observer); /** * Reloads the hierarchy currently displayed. * * @param rootNodeType The type of the root node. Can either be - * ProjectData or - * CategoryGroupData - * @param m - * @param observer Call-back handler. + * ProjectData + * @param m The user and the nodes to refresh. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ public CallHandle refreshHierarchy(Class rootNodeType, - Map m, AgentEventListener observer); + Map m, AgentEventListener observer); /** * Retrieves the images imported by the specified user during various * periods of time. The passed map is a map whose keys are indexes * identifying a period of time and the values are time objects. * - * @param userID The user id. + * @param ctx The security context. + * @param userID The user's id. * @param m The data to handle. Mustn't be null. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle countExperimenterImages(long userID, + public CallHandle countExperimenterImages(SecurityContext ctx, long userID, Map m, AgentEventListener observer); /** * Loads the tags containing tags and creates a pseudo hierarchy. * + * @param ctx The security context. * @param id The id of the tag or -1. * @param dataObject Pass true to load the * DataObject related @@ -240,20 +256,22 @@ public CallHandle countExperimenterImages(long userID, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadTags(Long id, boolean dataObject, boolean topLevel, - long userID, long groupID, AgentEventListener observer); + public CallHandle loadTags(SecurityContext ctx, Long id, boolean dataObject, + boolean topLevel, long userID, long groupID, + AgentEventListener observer); /** * Loads to the wells contained within the specified plate. * + * @param ctx The security context. * @param ids Map whose keys are the plate ID and values are the * screen acquisition ID or -1. * @param userID The Id of the user. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadPlateWells(Map ids, long userID, - AgentEventListener observer); + public CallHandle loadPlateWells(SecurityContext ctx, + Map ids, long userID, AgentEventListener observer); /** * Deletes the passed collection. @@ -262,18 +280,8 @@ public CallHandle loadPlateWells(Map ids, long userID, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle delete(Collection values, - AgentEventListener observer); - - /** - * Deletes the passed object. - * - * @param value The object to delete. - * @param observer Call-back handler. - * @return A handle that can be used to cancel the call. - */ - public CallHandle delete(DeletableObject value, - AgentEventListener observer); + public CallHandle delete(Map> + values, AgentEventListener observer); /** * Controls if the passed files can be imported. @@ -282,27 +290,39 @@ public CallHandle delete(DeletableObject value, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle checkFileFormat(List list, + public CallHandle checkFileFormat(List list, AgentEventListener observer); /** * Loads the repositories. * + * @param ctx The security context. * @param userID The id of the user. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadRepositories(long userID, + public CallHandle loadRepositories(SecurityContext ctx, long userID, AgentEventListener observer); /** * Loads the parents of the specified annotation. * + * @param ctx The security context. * @param annotationId The id of the user. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadParentsOfAnnotation(long annotationId, + public CallHandle loadParentsOfAnnotation(SecurityContext ctx, + long annotationId, AgentEventListener observer); + + /** + * Moves the passed collection to another group. + * + * @param object The objects to transfer. + * @param observer Call-back handler. + * @return A handle that can be used to cancel the call. + */ + public CallHandle changeGroup(TransferableObject object, AgentEventListener observer); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataManagerViewImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataManagerViewImpl.java index 413b331f881..192449616de 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataManagerViewImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/DataManagerViewImpl.java @@ -35,6 +35,8 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.model.DeletableObject; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.model.TransferableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.calls.AnnotationParentLoader; import org.openmicroscopy.shoola.env.data.views.calls.ChannelMetadataLoader; import org.openmicroscopy.shoola.env.data.views.calls.ContainerCounterLoader; @@ -42,6 +44,7 @@ import org.openmicroscopy.shoola.env.data.views.calls.DMRefreshLoader; import org.openmicroscopy.shoola.env.data.views.calls.DataObjectRemover; import org.openmicroscopy.shoola.env.data.views.calls.DataObjectSaver; +import org.openmicroscopy.shoola.env.data.views.calls.DataObjectTransfer; import org.openmicroscopy.shoola.env.data.views.calls.ExistingObjectsSaver; import org.openmicroscopy.shoola.env.data.views.calls.ExperimenterImagesCounter; import org.openmicroscopy.shoola.env.data.views.calls.FilesChecker; @@ -74,48 +77,52 @@ class DataManagerViewImpl /** * Implemented as specified by the view interface. - * @see DataManagerView#loadContainerHierarchy(Class, List, boolean, long, - * long, AgentEventListener) + * @see DataManagerView#loadContainerHierarchy(SecurityContext, Class, List, + * boolean, long, long, AgentEventListener) */ - public CallHandle loadContainerHierarchy(Class rootNodeType, - List rootNodeIDs, boolean withLeaves, long userID, - long groupID, AgentEventListener observer) + public CallHandle loadContainerHierarchy(SecurityContext ctx, + Class rootNodeType, List rootNodeIDs, boolean withLeaves, + long userID, long groupID, AgentEventListener observer) { - BatchCallTree cmd = new DMLoader(rootNodeType, rootNodeIDs, withLeaves, - userID, groupID); + BatchCallTree cmd = new DMLoader(ctx, rootNodeType, rootNodeIDs, + withLeaves, userID, groupID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#loadImages(long, AgentEventListener) + * @see DataManagerView#loadImages(SecurityContext, long, + * AgentEventListener) */ - public CallHandle loadImages(long userID, AgentEventListener observer) + public CallHandle loadImages(SecurityContext ctx, long userID, + AgentEventListener observer) { - BatchCallTree cmd = new ImagesLoader(userID); + BatchCallTree cmd = new ImagesLoader(ctx, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#getImages(Class, List, long, AgentEventListener) + * @see DataManagerView#getImages(SecurityContext, Class, List, long, + * AgentEventListener) */ - public CallHandle getImages(Class nodeType, List nodeIDs, long userID, - AgentEventListener observer) + public CallHandle getImages(SecurityContext ctx, Class nodeType, + List nodeIDs, long userID, AgentEventListener observer) { - BatchCallTree cmd = new ImagesLoader(nodeType, nodeIDs, userID); + BatchCallTree cmd = new ImagesLoader(ctx, nodeType, nodeIDs, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#createDataObject(DataObject, DataObject, - * AgentEventListener) + * @see DataManagerView#createDataObject(SecurityContext, DataObject, + * DataObject, AgentEventListener) */ - public CallHandle createDataObject(DataObject userObject, DataObject parent, + public CallHandle createDataObject(SecurityContext ctx, + DataObject userObject, DataObject parent, AgentEventListener observer) { - BatchCallTree cmd = new DataObjectSaver(userObject, parent, + BatchCallTree cmd = new DataObjectSaver(ctx, userObject, parent, DataObjectSaver.CREATE); return cmd.exec(observer); } @@ -124,69 +131,74 @@ public CallHandle createDataObject(DataObject userObject, DataObject parent, * Implemented as specified by the view interface. * @see DataManagerView#countContainerItems(Set, AgentEventListener) */ - public CallHandle countContainerItems(Set rootIDs, + public CallHandle countContainerItems(SecurityContext ctx, Set rootIDs, AgentEventListener observer) { - BatchCallTree cmd = new ContainerCounterLoader(rootIDs); + BatchCallTree cmd = new ContainerCounterLoader(ctx, rootIDs); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#loadThumbnail(ImageData, int, int, long, - * AgentEventListener) + * @see DataManagerView#loadThumbnail(SecurityContext, ImageData, int, int, + * long, AgentEventListener) */ - public CallHandle loadThumbnail(ImageData image, int maxWidth, - int maxHeight, long userID, AgentEventListener observer) + public CallHandle loadThumbnail(SecurityContext ctx, ImageData image, + int maxWidth, int maxHeight, long userID, AgentEventListener observer) { - BatchCallTree cmd = new ThumbnailLoader(image, maxWidth, maxHeight, + BatchCallTree cmd = new ThumbnailLoader(ctx, image, maxWidth, maxHeight, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#addExistingObjects(Collection, Collection, - * AgentEventListener) + * @see DataManagerView#addExistingObjects(SecurityContext, Collection, + * Collection, AgentEventListener) */ - public CallHandle addExistingObjects(Collection parents, Collection children, - AgentEventListener observer) + public CallHandle addExistingObjects(SecurityContext ctx, + Collection parents, Collection children, AgentEventListener observer) { - BatchCallTree cmd = new ExistingObjectsSaver(parents, children, false); + BatchCallTree cmd = new ExistingObjectsSaver(ctx, parents, children, + false); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#addExistingObjects(Map, Map + * @see DataManagerView#addExistingObjects(SecurityContext, Map, Map * AgentEventListener) */ - public CallHandle addExistingObjects(Map toPaste, Map toRemove, - AgentEventListener observer) + public CallHandle addExistingObjects(SecurityContext ctx, Map toPaste, + Map toRemove, AgentEventListener observer) { - BatchCallTree cmd = new ExistingObjectsSaver(toPaste, toRemove, false); + BatchCallTree cmd = new ExistingObjectsSaver(ctx, toPaste, toRemove, + false); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#cutAndPaste(Map, Map, boolean, AgentEventListener) + * @see DataManagerView#cutAndPaste(SecurityContext, Map, Map, boolean, + * AgentEventListener) */ - public CallHandle cutAndPaste(Map toPaste, Map toCut, boolean admin, - AgentEventListener observer) + public CallHandle cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut, + boolean admin, AgentEventListener observer) { - BatchCallTree cmd = new ExistingObjectsSaver(toPaste, toCut, admin); + BatchCallTree cmd = new ExistingObjectsSaver(ctx, toPaste, toCut, + admin); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#loadChannelsData(long, long, AgentEventListener) + * @see DataManagerView#loadChannelsData(SecurityContext, long, long, + * AgentEventListener) */ - public CallHandle loadChannelsData(long pixelsID, long userID, - AgentEventListener observer) + public CallHandle loadChannelsData(SecurityContext ctx, long pixelsID, + long userID, AgentEventListener observer) { - BatchCallTree cmd = new ChannelMetadataLoader(pixelsID, userID); + BatchCallTree cmd = new ChannelMetadataLoader(ctx, pixelsID, userID); return cmd.exec(observer); } @@ -195,7 +207,7 @@ public CallHandle loadChannelsData(long pixelsID, long userID, * @see DataManagerView#refreshHierarchy(Class, Map, AgentEventListener) */ public CallHandle refreshHierarchy(Class rootNodeType, - Map m, AgentEventListener observer) + Map m, AgentEventListener observer) { BatchCallTree cmd = new DMRefreshLoader(rootNodeType, m); return cmd.exec(observer); @@ -203,27 +215,28 @@ public CallHandle refreshHierarchy(Class rootNodeType, /** * Implemented as specified by the view interface. - * @see DataManagerView#countExperimenterImages(long, Map, + * @see DataManagerView#countExperimenterImages(SecurityContext, long, Map, * AgentEventListener) */ - public CallHandle countExperimenterImages(long userID, + public CallHandle countExperimenterImages(SecurityContext ctx, long userID, Map m, AgentEventListener observer) { - BatchCallTree cmd = new ExperimenterImagesCounter(userID, m); + BatchCallTree cmd = new ExperimenterImagesCounter(ctx, userID, m); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#loadTags(Long, boolean, boolean, long, long, - * AgentEventListener) + * @see DataManagerView#loadTags(SecurityContext, Long, boolean, boolean, + * long, long, AgentEventListener) */ - public CallHandle loadTags(Long id, boolean dataObject, boolean topLevel, - long userID, long groupID, AgentEventListener observer) + public CallHandle loadTags(SecurityContext ctx, Long id, boolean dataObject, + boolean topLevel, long userID, long groupID, + AgentEventListener observer) { - BatchCallTree cmd = new TagsLoader(id, dataObject, topLevel, userID, - groupID); + BatchCallTree cmd = new TagsLoader(ctx, id, dataObject, topLevel, + userID, groupID); return cmd.exec(observer); } @@ -231,19 +244,19 @@ public CallHandle loadTags(Long id, boolean dataObject, boolean topLevel, * Implemented as specified by the view interface. * @see DataManagerView#loadPlateWells(Map, long, AgentEventListener) */ - public CallHandle loadPlateWells(Map ids, long userID, - AgentEventListener observer) + public CallHandle loadPlateWells(SecurityContext ctx, Map ids, + long userID, AgentEventListener observer) { - BatchCallTree cmd = new PlateWellsLoader(ids, userID); + BatchCallTree cmd = new PlateWellsLoader(ctx, ids, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#delete(Collection, AgentEventListener) + * @see DataManagerView#delete(Map, AgentEventListener) */ - public CallHandle delete(Collection values, - AgentEventListener observer) + public CallHandle delete(Map> + values, AgentEventListener observer) { BatchCallTree cmd = new DataObjectRemover(values); return cmd.exec(observer); @@ -251,44 +264,48 @@ public CallHandle delete(Collection values, /** * Implemented as specified by the view interface. - * @see DataManagerView#delete(DeletableObject, AgentEventListener) + * @see DataManagerView#checkFileFormat(List, AgentEventListener) */ - public CallHandle delete(DeletableObject value, AgentEventListener observer) + public CallHandle checkFileFormat(List list, + AgentEventListener observer) { - BatchCallTree cmd = new DataObjectRemover(value); + BatchCallTree cmd = new FilesChecker(list); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#checkFileFormat(List, AgentEventListener) + * @see DataManagerView#loadRepositories(SecurityContext, long, + * AgentEventListener) */ - public CallHandle checkFileFormat(List list, + public CallHandle loadRepositories(SecurityContext ctx, long userID, AgentEventListener observer) { - BatchCallTree cmd = new FilesChecker(list); + BatchCallTree cmd = new RepositoriesLoader(ctx, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#loadRepositories(long, AgentEventListener) + * @see DataManagerView#loadParentsOfAnnotation(SecurityContext, long, + * AgentEventListener) */ - public CallHandle loadRepositories(long userID, AgentEventListener observer) + public CallHandle loadParentsOfAnnotation(SecurityContext ctx, + long annotationId, AgentEventListener observer) { - BatchCallTree cmd = new RepositoriesLoader(userID); + BatchCallTree cmd = new AnnotationParentLoader(ctx, annotationId); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see DataManagerView#loadParentsOfAnnotation(long, AgentEventListener) + * @see DataManagerView#changeGroup(TransferableObject, AgentEventListener) */ - public CallHandle loadParentsOfAnnotation(long annotationId, + public CallHandle changeGroup(TransferableObject object, AgentEventListener observer) { - BatchCallTree cmd = new AnnotationParentLoader(annotationId); + BatchCallTree cmd = new DataObjectTransfer(object); return cmd.exec(observer); } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/HierarchyBrowsingView.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/HierarchyBrowsingView.java index 3e449bee436..1cc5bf14527 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/HierarchyBrowsingView.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/HierarchyBrowsingView.java @@ -31,6 +31,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.calls.ThumbnailSetLoader; import org.openmicroscopy.shoola.env.event.AgentEventListener; import pojos.DataObject; @@ -57,19 +58,18 @@ public interface HierarchyBrowsingView * Indicates that the thumbnails are associated to an * ExperimenterData. */ - public static final int EXPERIMENTER = - ThumbnailSetLoader.EXPERIMENTER; + public static final int EXPERIMENTER = ThumbnailSetLoader.EXPERIMENTER; /** * Indicates that the thumbnails are associated to an FileData. */ - public static final int FS_FILE = ThumbnailSetLoader.FS_FILE; + public static final int FS_FILE = ThumbnailSetLoader.FS_FILE; /** * Indicates that the thumbnails are associated to an * ImageData. */ - public static final int IMAGE = ThumbnailSetLoader.IMAGE; + public static final int IMAGE = ThumbnailSetLoader.IMAGE; /** * Loads a data hierarchy rooted by a given node. @@ -84,17 +84,18 @@ public interface HierarchyBrowsingView * a ProjectData, DatasetData depending on whether you asked for a * Project, Dataset tree.

* - * @param rootNodeType The type of the root node. Can only be one out of: + * @param ctx The security context. + * @param rootNodeType The type of the root node. Can only be one out of: * ProjectData, DatasetData. - * @param nodesID The id of the root nodes. - * @param userID The identifier of the user. - * @param groupID The identifier of the user's group. - * @param observer Call-back handler. + * @param nodesID The id of the root nodes. + * @param userID The identifier of the user. + * @param groupID The identifier of the user's group. + * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadHierarchy(Class rootNodeType, List nodesID, - long userID, long groupID, - AgentEventListener observer); + public CallHandle loadHierarchy(SecurityContext ctx, Class rootNodeType, + List nodesID, long userID, long groupID, + AgentEventListener observer); /** * Loads a thumbnail for each specified DataObject object, @@ -110,16 +111,17 @@ public CallHandle loadHierarchy(Class rootNodeType, List nodesID, * original image and so that their area doesn't exceed maxWidth* * maxHeight. * - * @param imgs Contains the objects, one for each thumbnail to retrieve. - * @param maxWidth The maximum acceptable width of the thumbnails. + * @param ctx The security context. + * @param imgs Contains the objects, one for each thumbnail to retrieve. + * @param maxWidth The maximum acceptable width of the thumbnails. * @param maxHeight The maximum acceptable height of the thumbnails. - * @param userID The id of the user the thumbnails are for. - * @param observer Callback handler. + * @param userID The id of the user the thumbnails are for. + * @param observer Callback handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadThumbnails(Collection imgs, int maxWidth, - int maxHeight, long userID, int type, - AgentEventListener observer); + public CallHandle loadThumbnails(SecurityContext ctx, + Collection imgs, int maxWidth, int maxHeight, + long userID, int type, AgentEventListener observer); /** * Loads a full size image for each specified DataObject @@ -132,13 +134,14 @@ public CallHandle loadThumbnails(Collection imgs, int maxWidth, * retrieve a ThumbnailData object for that thumbnail. The * final DSCallOutcomeEvent will have no result. * - * @param imgs Contains the objects, one for each thumbnail to retrieve. - * @param userID The id of the user the thumbnails are for. - * @param observer Callback handler. + * @param ctx The security context. + * @param imgs Contains the objects, one for each thumbnail to retrieve. + * @param userID The id of the user the thumbnails are for. + * @param observer Callback handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadImagesAsThumbnails(Collection imgs, - long userID, - AgentEventListener observer); - + public CallHandle loadImagesAsThumbnails(SecurityContext ctx, + Collection imgs, long userID, + AgentEventListener observer); + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/HierarchyBrowsingViewImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/HierarchyBrowsingViewImpl.java index efc6122da94..08864a903d0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/HierarchyBrowsingViewImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/HierarchyBrowsingViewImpl.java @@ -31,6 +31,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.calls.HierarchyLoader; import org.openmicroscopy.shoola.env.data.views.calls.ThumbnailLoader; import org.openmicroscopy.shoola.env.data.views.calls.ThumbnailSetLoader; @@ -60,15 +61,15 @@ class HierarchyBrowsingViewImpl /** * Implemented as specified by the view interface. - * @see HierarchyBrowsingView#loadHierarchy(Class, List, long, long, + * @see HierarchyBrowsingView#loadHierarchy(SecurityContext, Class, List, long, long, * AgentEventListener) */ - public CallHandle loadHierarchy(Class rootNodeType, List nodesID, - long userID, long groupID, - AgentEventListener observer) + public CallHandle loadHierarchy(SecurityContext ctx, Class rootNodeType, + List nodesID, long userID, long groupID, + AgentEventListener observer) { - BatchCallTree cmd = new HierarchyLoader(rootNodeType, nodesID, userID, - groupID); + BatchCallTree cmd = new HierarchyLoader(ctx, rootNodeType, nodesID, + userID, groupID); return cmd.exec(observer); } @@ -77,23 +78,24 @@ public CallHandle loadHierarchy(Class rootNodeType, List nodesID, * @see HierarchyBrowsingView#loadThumbnails(Collection, int, int, long, * AgentEventListener) */ - public CallHandle loadThumbnails(Collection images, - int maxWidth, int maxHeight, long userID, - int type, AgentEventListener observer) + public CallHandle loadThumbnails(SecurityContext ctx, + Collection images, int maxWidth, int maxHeight, long userID, + int type, AgentEventListener observer) { - BatchCallTree cmd = new ThumbnailSetLoader(images, maxHeight, type); + BatchCallTree cmd = new ThumbnailSetLoader(ctx, images, maxHeight, type); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see HierarchyBrowsingView#loadImagesAsThumbnails(Collection, long, + * @see HierarchyBrowsingView#loadImagesAsThumbnails(SecurityContext, Collection, long, * AgentEventListener) */ - public CallHandle loadImagesAsThumbnails(Collection images, - long userID, AgentEventListener observer) + public CallHandle loadImagesAsThumbnails(SecurityContext ctx, + Collection images, long userID, + AgentEventListener observer) { - BatchCallTree cmd = new ThumbnailLoader(images, userID); + BatchCallTree cmd = new ThumbnailLoader(ctx, images, userID); return cmd.exec(observer); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ImageDataView.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ImageDataView.java index 1e322f036a7..1e62932b6d1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ImageDataView.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ImageDataView.java @@ -41,6 +41,7 @@ import org.openmicroscopy.shoola.env.data.model.ProjectionParam; import org.openmicroscopy.shoola.env.data.model.SaveAsParam; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.AgentEventListener; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; import org.openmicroscopy.shoola.env.rnd.data.Tile; @@ -80,13 +81,14 @@ public interface ImageDataView /** * Loads the rendering proxy associated to the pixels set. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param index One of the constants defined by this class. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadRenderingControl(long pixelsID, int index, - AgentEventListener observer); + public CallHandle loadRenderingControl(SecurityContext ctx, long pixelsID, + int index, AgentEventListener observer); /** * Shuts down the rendering proxy associated to the pixels set. @@ -95,12 +97,13 @@ public CallHandle loadRenderingControl(long pixelsID, int index, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle shutDownRenderingControl(long pixelsID, - AgentEventListener observer); + public CallHandle shutDownRenderingControl(SecurityContext ctx, + long pixelsID, AgentEventListener observer); /** * Renders the specified plane. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param pd The plane to render. * @param asTexture Pass true to return a texture, @@ -110,22 +113,24 @@ public CallHandle shutDownRenderingControl(long pixelsID, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle render(long pixelsID, PlaneDef pd, boolean asTexture, - boolean largeImage, AgentEventListener observer); + public CallHandle render(SecurityContext ctx, long pixelsID, PlaneDef pd, + boolean asTexture, boolean largeImage, AgentEventListener observer); /** * Retrieves the pixels set. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param observer Call-back handler. * @return See above. */ - public CallHandle loadPixels(long pixelsID, + public CallHandle loadPixels(SecurityContext ctx, long pixelsID, AgentEventListener observer); /** * Retrieves the dimensions in microns of the pixels set. * + * @param ctx The security context. * @param pixels The pixels set to analyze. * @param channels Collection of active channels. * Mustn't be null. @@ -134,34 +139,37 @@ public CallHandle loadPixels(long pixelsID, * @param observer Call-back handler. * @return See above. */ - public CallHandle analyseShapes(PixelsData pixels, List channels, - List shapes, AgentEventListener observer); + public CallHandle analyseShapes(SecurityContext ctx, PixelsData pixels, + List channels, List shapes, AgentEventListener observer); /** * Retrieves all the rendering settings associated to a given set of pixels. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param observer Call-back handler. * @return See above. */ - public CallHandle getRenderingSettings(long pixelsID, + public CallHandle getRenderingSettings(SecurityContext ctx, long pixelsID, AgentEventListener observer); /** * Retrieves all the rendering settings associated to a given set of pixels. * for the specified user. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param userID The if of the users. * @param observer Call-back handler. * @return See above. */ - public CallHandle getRenderingSettings(long pixelsID, long userID, - AgentEventListener observer); + public CallHandle getRenderingSettings(SecurityContext ctx, long pixelsID, + long userID, AgentEventListener observer); /** * Projects a section of the stack and returns the projected image. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param startZ The first optical section. * @param endZ The last optical section. @@ -174,18 +182,20 @@ public CallHandle getRenderingSettings(long pixelsID, long userID, * @param observer Call-back handler. * @return See above. */ - public CallHandle renderProjected(long pixelsID, int startZ, int endZ, - int stepping, int algorithm, List channels, - boolean openGLSupport, AgentEventListener observer); + public CallHandle renderProjected(SecurityContext ctx, long pixelsID, + int startZ, int endZ, int stepping, int algorithm, + List channels, boolean openGLSupport, + AgentEventListener observer); /** * Projects a section of the stack and returns the projected image. * + * @param ctx The security context. * @param ref The object hosting the projection's parameters. * @param observer Call-back handler. * @return See above. */ - public CallHandle projectImage(ProjectionParam ref, + public CallHandle projectImage(SecurityContext ctx, ProjectionParam ref, AgentEventListener observer); /** @@ -193,6 +203,7 @@ public CallHandle projectImage(ProjectionParam ref, * copies the settings from the passed rendering setting object if * not null. * + * @param ctx The security context. * @param pixelsID The id of the pixels set to handle. * @param rndToCopy The rendering settings to copy to the newly created one. * @param indexes Collection of channel's indexes. @@ -200,33 +211,37 @@ public CallHandle projectImage(ProjectionParam ref, * @param observer Call-back handler. * @return See above. */ - public CallHandle createRndSetting(long pixelsID, RndProxyDef rndToCopy, - List indexes, AgentEventListener observer); + public CallHandle createRndSetting(SecurityContext ctx, long pixelsID, + RndProxyDef rndToCopy, List indexes, + AgentEventListener observer); /** * Loads the acquisition metadata for an image or a given channel. * + * @param ctx The security context. * @param refObject Either an image or a channel. * @param observer Call-back handler. * @return See above. */ - public CallHandle loadAcquisitionData(Object refObject, + public CallHandle loadAcquisitionData(SecurityContext ctx, Object refObject, AgentEventListener observer); /** * Saves the acquisition metadata related to an image or a given channel. * + * @param ctx The security context. * @param refObject Object hosting the metadata for either an image or * a channel. * @param observer Call-back handler. * @return See above. */ - public CallHandle saveAcquisitionData(Object refObject, + public CallHandle saveAcquisitionData(SecurityContext ctx, Object refObject, AgentEventListener observer); /** * Loads the plane info objects related to the passed pixels set. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param z The selected z-section or -1. * @param t The selected timepoint or -1. @@ -234,24 +249,27 @@ public CallHandle saveAcquisitionData(Object refObject, * @param observer Call-back handler. * @return See above. */ - public CallHandle loadPlaneInfo(long pixelsID, int z, int t, int channel, - AgentEventListener observer); + public CallHandle loadPlaneInfo(SecurityContext ctx, long pixelsID, int z, + int t, int channel, AgentEventListener observer); /** * Loads the enumerations used for the image metadata. * + * @param ctx The security context. * @param observer Call-back handler. * @return See above. */ - public CallHandle loadImageMetadataEnumerations(AgentEventListener observer); + public CallHandle loadImageMetadataEnumerations(SecurityContext ctx, + AgentEventListener observer); /** * Loads the enumerations used for the channel metadata. * + * @param ctx The security context. * @param observer Call-back handler. * @return See above. */ - public CallHandle loadChannelMetadataEnumerations( + public CallHandle loadChannelMetadataEnumerations(SecurityContext ctx, AgentEventListener observer); /** @@ -264,12 +282,13 @@ public CallHandle loadChannelMetadataEnumerations( * @param observer Call-back handler. * @return See above. */ - public CallHandle importFiles(ImportableObject context, long userID, - long groupID, AgentEventListener observer); + public CallHandle importFiles(ImportableObject context, + long userID, long groupID, AgentEventListener observer); /** * Monitors the passed directory. * + * @param ctx The security context. * @param directory The directory to monitor. * @param container The container where to import the images into or * null. @@ -278,23 +297,26 @@ public CallHandle importFiles(ImportableObject context, long userID, * @param observer Call-back handler. * @return See above. */ - public CallHandle monitorDirectory(File directory, DataObject container, - long userID, long groupID, AgentEventListener observer); + public CallHandle monitorDirectory(SecurityContext ctx, File directory, + DataObject container, long userID, long groupID, + AgentEventListener observer); /** * Loads the specified image. * + * @param ctx The security context. * @param imageID The id of the image to load. * @param userID The id of the user. * @param observer Call-back handler. * @return See above. */ - public CallHandle loadImage(long imageID, long userID, + public CallHandle loadImage(SecurityContext ctx, long imageID, long userID, AgentEventListener observer); /** * Creates a movie. * + * @param ctx The security context. * @param imageID The id of the image. * @param pixelsID The id of the pixels set. * @param channels The channels to map. @@ -302,80 +324,88 @@ public CallHandle loadImage(long imageID, long userID, * @param observer Call-back handler. * @return See above. */ - public CallHandle createMovie(long imageID, long pixelsID, - List channels, MovieExportParam param, + public CallHandle createMovie(SecurityContext ctx, long imageID, + long pixelsID, List channels, MovieExportParam param, AgentEventListener observer); /** * Creates a figure. * + * @param ctx The security context. * @param ids The id of the objects. * @param type The type of objects to handle. * @param param The parameters to create the movie. * @param observer Call-back handler. * @return See above. */ - public CallHandle createFigure(List ids, Class type, Object param, - AgentEventListener observer); + public CallHandle createFigure(SecurityContext ctx, List ids, + Class type, Object param, AgentEventListener observer); /** * Loads the instrument and its components. * + * @param ctx The security context. * @param instrumentID The id of instrument * @param observer Call-back handler. * @return See above. */ - public CallHandle loadInstrumentData(long instrumentID, + public CallHandle loadInstrumentData(SecurityContext ctx, long instrumentID, AgentEventListener observer); /** * Loads the ROI. * + * @param ctx The security context. * @param imageID The image's id. * @param fileID The id of the file. * @param userID The user's id. * @param observer Call-back handler. * @return See above. */ - public CallHandle loadROI(long imageID, List fileID, long userID, - AgentEventListener observer); + public CallHandle loadROI(SecurityContext ctx, long imageID, + List fileID, long userID, AgentEventListener observer); + /** - * Save the ROI for the image to the server.. + * Save the ROI for the image to the server. * + * @param ctx The security context. * @param imageID The image's ID. * @param userID The user's ID. * @param roiList The list of ROI to save. */ - public CallHandle saveROI(long imageID, long userID, List roiList, - AgentEventListener observer); + public CallHandle saveROI(SecurityContext ctx, long imageID, long userID, + List roiList, AgentEventListener observer); /** * Exports the image as an XML file. * + * @param ctx The security context. * @param imageID The image's id. * @param file The file where to export the image. * @param observer Call-back handler. * @return See above. */ - public CallHandle exportImageAsOMETiff(long imageID, File file, - AgentEventListener observer); + public CallHandle exportImageAsOMETiff(SecurityContext ctx, long imageID, + File file, AgentEventListener observer); /** * Loads the ROI if possible from the server. * + * @param ctx The security context. * @param imageID The image's id. * @param userID The user's id. * @param observer Call-back handler. * @return See above. */ - public CallHandle loadROIFromServer(long imageID, long userID, - AgentEventListener serverSideROILoader); + public CallHandle loadROIFromServer(SecurityContext ctx, long imageID, + long userID, AgentEventListener serverSideROILoader); /** * Renders the image with the overlays if the passed map is not * null, renders the image without the overlays if * null. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param pd The plane to render. * @param tableID The id of the table hosting the mask. @@ -385,76 +415,70 @@ public CallHandle loadROIFromServer(long imageID, long userID, * @param observer Call-back handler. * @return See above. */ - public CallHandle renderOverLays(long pixelsID, PlaneDef pd, long tableID, - Map overlays, boolean asTexture, - AgentEventListener observer); - - /** - * Performs a basic FRAP. - * - * @param ids The objects to analyze. - * @param type The type of object to analyze. - * @param param The extra parameters. - * @param observer Call-back handler. - * @return See above. - */ - public CallHandle analyseFRAP(List ids, Class objectType, - Object param, AgentEventListener observer); + public CallHandle renderOverLays(SecurityContext ctx, long pixelsID, + PlaneDef pd, long tableID, Map overlays, + boolean asTexture, AgentEventListener observer); /** * Runs the passed script. * + * @param ctx The security context. * @param script The script to run. * @param observer Call-back handler. * @return See above. */ - public CallHandle runScript(ScriptObject script, + public CallHandle runScript(SecurityContext ctx, ScriptObject script, AgentEventListener observer); /** * Uploads the passed script. * + * @param ctx The security context. * @param script The script to upload. * @param observer Call-back handler. * @return See above. */ - public CallHandle uploadScript(ScriptObject script, + public CallHandle uploadScript(SecurityContext ctx, ScriptObject script, AgentEventListener observer); /** * Retrieve the users workflows. * + * @param ctx The security context. * @param userID id of the user whose workflows are to be retrieved. * @param observer Call-back handler. * @return See above. */ - public CallHandle retrieveWorkflows(long userID, AgentEventListener observer); + public CallHandle retrieveWorkflows(SecurityContext ctx, long userID, + AgentEventListener observer); /** * Stores the newly created workflows. * + * @param ctx The security context. * @param workflows The new workflows. * @param userID id of the user whose workflows are to be retrieved. * @param observer Call-back handler. * @return See above. */ - public CallHandle storeWorkflows(List workflows, long userID, - AgentEventListener observer); + public CallHandle storeWorkflows(SecurityContext ctx, + List workflows, long userID, AgentEventListener observer); /** * Saves the images in the specified folder as JPEG by default. * + * @param ctx The security context. * @param parameters The parameters used to save locally the images. - *. * @param observer Call-back handler. * @return See above. */ - public CallHandle saveAs(SaveAsParam parameters, + public CallHandle saveAs(SecurityContext ctx, SaveAsParam parameters, AgentEventListener observer); /** * Loads the tiles. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param pDef The plane to render. * @param tiles The tiles. @@ -463,8 +487,8 @@ public CallHandle saveAs(SaveAsParam parameters, * @param observer Call-back handler. * @return See above. */ - public CallHandle loadTiles(long pixelsID, PlaneDef pDef, - Collection tiles, boolean asTexture, + public CallHandle loadTiles(SecurityContext ctx, long pixelsID, + PlaneDef pDef, Collection tiles, boolean asTexture, AgentEventListener observer); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ImageDataViewImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ImageDataViewImpl.java index 47e0d290439..6e76806af89 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ImageDataViewImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ImageDataViewImpl.java @@ -41,12 +41,12 @@ import org.openmicroscopy.shoola.env.data.model.ProjectionParam; import org.openmicroscopy.shoola.env.data.model.SaveAsParam; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.calls.AcquisitionDataLoader; import org.openmicroscopy.shoola.env.data.views.calls.AcquisitionDataSaver; import org.openmicroscopy.shoola.env.data.views.calls.Analyser; import org.openmicroscopy.shoola.env.data.views.calls.EnumerationLoader; import org.openmicroscopy.shoola.env.data.views.calls.ExportLoader; -import org.openmicroscopy.shoola.env.data.views.calls.FRAPAnalyser; import org.openmicroscopy.shoola.env.data.views.calls.FigureCreator; import org.openmicroscopy.shoola.env.data.views.calls.ImageRenderer; import org.openmicroscopy.shoola.env.data.views.calls.ImagesImporter; @@ -100,8 +100,8 @@ class ImageDataViewImpl * @see ImageDataView#loadRenderingControl(long, int, * AgentEventListener) */ - public CallHandle loadRenderingControl(long pixelsID, int index, - AgentEventListener observer) + public CallHandle loadRenderingControl(SecurityContext ctx, long pixelsID, + int index, AgentEventListener observer) { int i = -1; switch (index) { @@ -115,7 +115,7 @@ public CallHandle loadRenderingControl(long pixelsID, int index, case RESET: i = RenderingControlLoader.RESET; } - BatchCallTree cmd = new RenderingControlLoader(pixelsID, i); + BatchCallTree cmd = new RenderingControlLoader(ctx, pixelsID, i); return cmd.exec(observer); } @@ -124,10 +124,10 @@ public CallHandle loadRenderingControl(long pixelsID, int index, * @see ImageDataView#render(long, PlaneDef, boolean, boolean, * AgentEventListener) */ - public CallHandle render(long pixelsID, PlaneDef pd, boolean asTexture, - boolean largeImage, AgentEventListener observer) + public CallHandle render(SecurityContext ctx, long pixelsID, PlaneDef pd, + boolean asTexture, boolean largeImage, AgentEventListener observer) { - BatchCallTree cmd = new ImageRenderer(pixelsID, pd, asTexture, + BatchCallTree cmd = new ImageRenderer(ctx, pixelsID, pd, asTexture, largeImage); return cmd.exec(observer); } @@ -136,9 +136,10 @@ public CallHandle render(long pixelsID, PlaneDef pd, boolean asTexture, * Implemented as specified by the view interface. * @see ImageDataView#loadPixels(long, AgentEventListener) */ - public CallHandle loadPixels(long pixelsID, AgentEventListener observer) + public CallHandle loadPixels(SecurityContext ctx, long pixelsID, + AgentEventListener observer) { - BatchCallTree cmd = new PixelsDataLoader(pixelsID, + BatchCallTree cmd = new PixelsDataLoader(ctx, pixelsID, PixelsDataLoader.SET); return cmd.exec(observer); } @@ -148,10 +149,10 @@ public CallHandle loadPixels(long pixelsID, AgentEventListener observer) * @see ImageDataView#analyseShapes(PixelsData, List, List, * AgentEventListener) */ - public CallHandle analyseShapes(PixelsData pixels, List channels, - List shapes, AgentEventListener observer) + public CallHandle analyseShapes(SecurityContext ctx, PixelsData pixels, + List channels, List shapes, AgentEventListener observer) { - BatchCallTree cmd = new Analyser(pixels, channels, shapes); + BatchCallTree cmd = new Analyser(ctx, pixels, channels, shapes); return cmd.exec(observer); } @@ -159,20 +160,20 @@ public CallHandle analyseShapes(PixelsData pixels, List channels, * Implemented as specified by the view interface. * @see ImageDataView#getRenderingSettings(long, AgentEventListener) */ - public CallHandle getRenderingSettings(long pixelsID, + public CallHandle getRenderingSettings(SecurityContext ctx, long pixelsID, AgentEventListener observer) { - return getRenderingSettings(pixelsID, -1, observer); + return getRenderingSettings(ctx, pixelsID, -1, observer); } /** * Implemented as specified by the view interface. * @see ImageDataView#getRenderingSettings(long, long, AgentEventListener) */ - public CallHandle getRenderingSettings(long pixelsID, long userID, - AgentEventListener observer) + public CallHandle getRenderingSettings(SecurityContext ctx, + long pixelsID, long userID, AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsLoader(pixelsID, userID); + BatchCallTree cmd = new RenderingSettingsLoader(ctx, pixelsID, userID); return cmd.exec(observer); } @@ -181,11 +182,12 @@ public CallHandle getRenderingSettings(long pixelsID, long userID, * @see ImageDataView#renderProjected(long, int, int, int, int, List, * AgentEventListener) */ - public CallHandle renderProjected(long pixelsID, int startZ, int endZ, - int stepping, int algorithm, List channels, - boolean openGLSupport, AgentEventListener observer) + public CallHandle renderProjected(SecurityContext ctx, + long pixelsID, int startZ, int endZ, int stepping, int algorithm, + List channels, boolean openGLSupport, + AgentEventListener observer) { - BatchCallTree cmd = new ProjectionSaver(pixelsID, startZ, endZ, + BatchCallTree cmd = new ProjectionSaver(ctx, pixelsID, startZ, endZ, stepping, algorithm, channels, openGLSupport); return cmd.exec(observer); } @@ -194,10 +196,10 @@ public CallHandle renderProjected(long pixelsID, int startZ, int endZ, * Implemented as specified by the view interface. * @see ImageDataView#projectImage(ProjectionParam, AgentEventListener) */ - public CallHandle projectImage(ProjectionParam ref, + public CallHandle projectImage(SecurityContext ctx, ProjectionParam ref, AgentEventListener observer) { - BatchCallTree cmd = new ProjectionSaver(ref); + BatchCallTree cmd = new ProjectionSaver(ctx, ref); return cmd.exec(observer); } @@ -206,10 +208,11 @@ public CallHandle projectImage(ProjectionParam ref, * @see ImageDataView#createRndSetting(long, RndProxyDef, List, * AgentEventListener) */ - public CallHandle createRndSetting(long pixelsID, RndProxyDef rndToCopy, - List indexes, AgentEventListener observer) + public CallHandle createRndSetting(SecurityContext ctx, long pixelsID, + RndProxyDef rndToCopy, List indexes, + AgentEventListener observer) { - BatchCallTree cmd = new RenderingSettingsSaver(pixelsID, rndToCopy, + BatchCallTree cmd = new RenderingSettingsSaver(ctx, pixelsID, rndToCopy, indexes); return cmd.exec(observer); } @@ -218,10 +221,10 @@ public CallHandle createRndSetting(long pixelsID, RndProxyDef rndToCopy, * Implemented as specified by the view interface. * @see ImageDataView#loadAcquisitionData(Object, AgentEventListener) */ - public CallHandle loadAcquisitionData(Object refObject, + public CallHandle loadAcquisitionData(SecurityContext ctx, Object refObject, AgentEventListener observer) { - BatchCallTree cmd = new AcquisitionDataLoader(refObject); + BatchCallTree cmd = new AcquisitionDataLoader(ctx, refObject); return cmd.exec(observer); } @@ -229,10 +232,10 @@ public CallHandle loadAcquisitionData(Object refObject, * Implemented as specified by the view interface. * @see ImageDataView#loadInstrumentData(long, AgentEventListener) */ - public CallHandle loadInstrumentData(long instrumentID, + public CallHandle loadInstrumentData(SecurityContext ctx, long instrumentID, AgentEventListener observer) { - BatchCallTree cmd = new AcquisitionDataLoader( + BatchCallTree cmd = new AcquisitionDataLoader(ctx, AcquisitionDataLoader.INSTRUMENT, instrumentID); return cmd.exec(observer); } @@ -241,10 +244,10 @@ public CallHandle loadInstrumentData(long instrumentID, * Implemented as specified by the view interface. * @see ImageDataView#saveAcquisitionData(Object, AgentEventListener) */ - public CallHandle saveAcquisitionData(Object refObject, + public CallHandle saveAcquisitionData(SecurityContext ctx, Object refObject, AgentEventListener observer) { - BatchCallTree cmd = new AcquisitionDataSaver(refObject); + BatchCallTree cmd = new AcquisitionDataSaver(ctx, refObject); return cmd.exec(observer); } @@ -252,10 +255,10 @@ public CallHandle saveAcquisitionData(Object refObject, * Implemented as specified by the view interface. * @see ImageDataView#loadPlaneInfo(long, int, int, int, AgentEventListener) */ - public CallHandle loadPlaneInfo(long pixelsID, int z, int t, int channel, - AgentEventListener observer) + public CallHandle loadPlaneInfo(SecurityContext ctx, long pixelsID, int z, + int t, int channel, AgentEventListener observer) { - BatchCallTree cmd = new PlaneInfoLoader(pixelsID, z, t, channel); + BatchCallTree cmd = new PlaneInfoLoader(ctx, pixelsID, z, t, channel); return cmd.exec(observer); } @@ -263,10 +266,11 @@ public CallHandle loadPlaneInfo(long pixelsID, int z, int t, int channel, * Implemented as specified by the view interface. * @see ImageDataView#loadChannelMetadataEnumerations(AgentEventListener) */ - public CallHandle loadChannelMetadataEnumerations(AgentEventListener - observer) + public CallHandle loadChannelMetadataEnumerations(SecurityContext ctx, + AgentEventListener observer) { - BatchCallTree cmd = new EnumerationLoader(EnumerationLoader.CHANNEL); + BatchCallTree cmd = new EnumerationLoader(ctx, + EnumerationLoader.CHANNEL); return cmd.exec(observer); } @@ -274,19 +278,19 @@ public CallHandle loadChannelMetadataEnumerations(AgentEventListener * Implemented as specified by the view interface. * @see ImageDataView#loadImageMetadataEnumerations(AgentEventListener) */ - public CallHandle loadImageMetadataEnumerations(AgentEventListener observer) + public CallHandle loadImageMetadataEnumerations(SecurityContext ctx, + AgentEventListener observer) { - BatchCallTree cmd = new EnumerationLoader(EnumerationLoader.IMAGE); + BatchCallTree cmd = new EnumerationLoader(ctx, EnumerationLoader.IMAGE); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see ImageDataView#importImages(ImportContext, long, long, - * AgentEventListener) + * @see ImageDataView#importImages(long, long, AgentEventListener) */ - public CallHandle importFiles(ImportableObject context, long userID, - long groupID, AgentEventListener observer) + public CallHandle importFiles(ImportableObject context, + long userID, long groupID, AgentEventListener observer) { BatchCallTree cmd = new ImagesImporter(context, userID, groupID); return cmd.exec(observer); @@ -297,8 +301,9 @@ public CallHandle importFiles(ImportableObject context, long userID, * @see ImageDataView#monitorDirectory(File, DataObject, long, long, * AgentEventListener) */ - public CallHandle monitorDirectory(File directory, DataObject container, - long userID, long groupID, AgentEventListener observer) + public CallHandle monitorDirectory(SecurityContext ctx, File directory, + DataObject container, long userID, long groupID, + AgentEventListener observer) { return null; } @@ -307,10 +312,10 @@ public CallHandle monitorDirectory(File directory, DataObject container, * Implemented as specified by the view interface. * @see ImageDataView#loadImage(long, long, AgentEventListener) */ - public CallHandle loadImage(long imageID, long userID, + public CallHandle loadImage(SecurityContext ctx, long imageID, long userID, AgentEventListener observer) { - BatchCallTree cmd = new ImagesLoader(imageID, userID); + BatchCallTree cmd = new ImagesLoader(ctx, imageID, userID); return cmd.exec(observer); } @@ -319,11 +324,11 @@ public CallHandle loadImage(long imageID, long userID, * @see ImageDataView#createMovie(long, long, List, MovieExportParam, * AgentEventListener) */ - public CallHandle createMovie(long imageID, long pixelsID, - List channels, MovieExportParam param, + public CallHandle createMovie(SecurityContext ctx, long imageID, + long pixelsID, List channels, MovieExportParam param, AgentEventListener observer) { - BatchCallTree cmd = new MovieCreator(imageID, pixelsID, channels, + BatchCallTree cmd = new MovieCreator(ctx, imageID, pixelsID, channels, param); return cmd.exec(observer); } @@ -332,10 +337,10 @@ public CallHandle createMovie(long imageID, long pixelsID, * Implemented as specified by the view interface. * @see ImageDataView#createFigure(List, Class, Object, AgentEventListener) */ - public CallHandle createFigure(List ids, Class type, Object param, - AgentEventListener observer) + public CallHandle createFigure(SecurityContext ctx, List ids, + Class type, Object param, AgentEventListener observer) { - BatchCallTree cmd = new FigureCreator(ids, type, param); + BatchCallTree cmd = new FigureCreator(ctx, ids, type, param); return cmd.exec(observer); } @@ -343,10 +348,10 @@ public CallHandle createFigure(List ids, Class type, Object param, * Implemented as specified by the view interface. * @see ImageDataView#loadROI(long, Long, long, AgentEventListener) */ - public CallHandle loadROI(long imageID, List fileID, long userID, - AgentEventListener observer) + public CallHandle loadROI(SecurityContext ctx, long imageID, + List fileID, long userID, AgentEventListener observer) { - BatchCallTree cmd = new ROILoader(imageID, fileID, userID); + BatchCallTree cmd = new ROILoader(ctx, imageID, fileID, userID); return cmd.exec(observer); } @@ -354,20 +359,20 @@ public CallHandle loadROI(long imageID, List fileID, long userID, * Implemented as specified by the view interface. * @see ImageDataView#saveROI(long, Long, long, AgentEventListener) */ - public CallHandle saveROI(long imageID, long userID, List roiList, - AgentEventListener observer) + public CallHandle saveROI(SecurityContext ctx, long imageID, long userID, + List roiList, AgentEventListener observer) { - BatchCallTree cmd = new ROISaver(imageID, userID, roiList); + BatchCallTree cmd = new ROISaver(ctx, imageID, userID, roiList); return cmd.exec(observer); } /** * Implemented as specified by the view interface. * @see ImageDataView#exportImageAsOMETiff(long, File, AgentEventListener) */ - public CallHandle exportImageAsOMETiff(long imageID, File file, - AgentEventListener observer) + public CallHandle exportImageAsOMETiff(SecurityContext ctx, long imageID, + File file, AgentEventListener observer) { - BatchCallTree cmd = new ExportLoader(imageID, file, + BatchCallTree cmd = new ExportLoader(ctx, imageID, file, ExportLoader.EXPORT_AS_OMETIFF); return cmd.exec(observer); } @@ -376,10 +381,10 @@ public CallHandle exportImageAsOMETiff(long imageID, File file, * Implemented as specified by the view interface. * @see ImageDataView#loadROIFromServer(long, Long, AgentEventListener) */ - public CallHandle loadROIFromServer(long imageID, long userID, - AgentEventListener observer) + public CallHandle loadROIFromServer(SecurityContext ctx, long imageID, + long userID, AgentEventListener observer) { - BatchCallTree cmd = new ServerSideROILoader(imageID, userID); + BatchCallTree cmd = new ServerSideROILoader(ctx, imageID, userID); return cmd.exec(observer); } @@ -388,35 +393,23 @@ public CallHandle loadROIFromServer(long imageID, long userID, * @see ImageDataView#renderOverLays(long, PlaneDef, long, Map, boolean, * AgentEventListener) */ - public CallHandle renderOverLays(long pixelsID, PlaneDef pd, long tableID, - Map overlays, boolean asTexture, - AgentEventListener observer) + public CallHandle renderOverLays(SecurityContext ctx, long pixelsID, + PlaneDef pd, long tableID, Map overlays, + boolean asTexture, AgentEventListener observer) { - BatchCallTree cmd = new OverlaysRenderer(pixelsID, pd, tableID, + BatchCallTree cmd = new OverlaysRenderer(ctx, pixelsID, pd, tableID, overlays, asTexture); return cmd.exec(observer); } - /** - * Implemented as specified by the view interface. - * @see ImageDataView#analyseFRAP(List, Class, Object, AgentEventListener) - */ - public CallHandle analyseFRAP(List ids, Class objectType, - Object param, AgentEventListener observer) - { - BatchCallTree cmd = new FRAPAnalyser(ids, objectType, param); - return cmd.exec(observer); - } - - /** * Implemented as specified by the view interface. * @see ImageDataView#runScript(ScriptObject, AgentEventListener) */ - public CallHandle runScript(ScriptObject script, + public CallHandle runScript(SecurityContext ctx, ScriptObject script, AgentEventListener observer) { - BatchCallTree cmd = new ScriptRunner(script); + BatchCallTree cmd = new ScriptRunner(ctx, script); return cmd.exec(observer); } @@ -424,10 +417,10 @@ public CallHandle runScript(ScriptObject script, * Implemented as specified by the view interface. * @see ImageDataView#uploadScript(ScriptObject, AgentEventListener) */ - public CallHandle uploadScript(ScriptObject script, + public CallHandle uploadScript(SecurityContext ctx,ScriptObject script, AgentEventListener observer) { - BatchCallTree cmd = new ScriptUploader(script); + BatchCallTree cmd = new ScriptUploader(ctx, script); return cmd.exec(observer); } @@ -435,9 +428,10 @@ public CallHandle uploadScript(ScriptObject script, * Implemented as specified by the view interface. * @see ImageDataView#retrieveWorkflows(long, AgentEventListener) */ - public CallHandle retrieveWorkflows(long userID, AgentEventListener observer) + public CallHandle retrieveWorkflows(SecurityContext ctx, + long userID, AgentEventListener observer) { - BatchCallTree cmd = new WorkflowHandler(userID); + BatchCallTree cmd = new WorkflowHandler(ctx, userID); return cmd.exec(observer); } @@ -445,10 +439,11 @@ public CallHandle retrieveWorkflows(long userID, AgentEventListener observer) * Implemented as specified by the view interface. * @see ImageDataView#storeWorkflows(List, long, AgentEventListener) */ - public CallHandle storeWorkflows(List workflows, long userID, + public CallHandle storeWorkflows(SecurityContext ctx, + List workflows, long userID, AgentEventListener observer) { - BatchCallTree cmd = new WorkflowHandler(workflows, userID); + BatchCallTree cmd = new WorkflowHandler(ctx, workflows, userID); return cmd.exec(observer); } @@ -456,10 +451,10 @@ public CallHandle storeWorkflows(List workflows, long userID, * Implemented as specified by the view interface. * @see ImageDataView#saveAs(SaveAsParam, AgentEventListener) */ - public CallHandle saveAs(SaveAsParam parameters, + public CallHandle saveAs(SecurityContext ctx,SaveAsParam parameters, AgentEventListener observer) { - BatchCallTree cmd = new SaveAsLoader(parameters); + BatchCallTree cmd = new SaveAsLoader(ctx, parameters); return cmd.exec(observer); } @@ -468,11 +463,12 @@ public CallHandle saveAs(SaveAsParam parameters, * @see ImageDataView#loadTiles(long, PlaneDef, List, boolean, * AgentEventListener) */ - public CallHandle loadTiles(long pixelsID, PlaneDef pDef, - Collection tiles, boolean asTexture, + public CallHandle loadTiles(SecurityContext ctx, long pixelsID, + PlaneDef pDef, Collection tiles, boolean asTexture, AgentEventListener observer) { - BatchCallTree cmd = new TileLoader(pixelsID, pDef, tiles, asTexture); + BatchCallTree cmd = new TileLoader(ctx, pixelsID, pDef, tiles, + asTexture); return cmd.exec(observer); } @@ -480,10 +476,10 @@ public CallHandle loadTiles(long pixelsID, PlaneDef pDef, * Implemented as specified by the view interface. * @see ImageDataView#shutDownRenderingControl(long, AgentEventListener) */ - public CallHandle shutDownRenderingControl(long pixelsID, - AgentEventListener observer) + public CallHandle shutDownRenderingControl(SecurityContext ctx, + long pixelsID, AgentEventListener observer) { - BatchCallTree cmd = new RenderingControlLoader(pixelsID, + BatchCallTree cmd = new RenderingControlLoader(ctx, pixelsID, RenderingControlLoader.SHUTDOWN); return cmd.exec(observer); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/MetadataHandlerView.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/MetadataHandlerView.java index 44aa390422e..672caeffe5a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/MetadataHandlerView.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/MetadataHandlerView.java @@ -33,11 +33,11 @@ //Third-party libraries //Application-internal dependencies -import org.openmicroscopy.shoola.agents.metadata.TabularDataLoader; import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.model.TableParameters; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; import org.openmicroscopy.shoola.env.data.util.FilterContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.calls.FilesLoader; import org.openmicroscopy.shoola.env.event.AgentEventListener; import org.openmicroscopy.shoola.util.ui.MessengerDetails; @@ -92,6 +92,7 @@ public interface MetadataHandlerView * Loads all the containers containing the specified object. * Retrieves the files if the userID is not -1. * + * @param ctx The security context. * @param nodeType The class identifying the object. * Mustn't be null. * @param nodeID The id of the node. @@ -99,13 +100,14 @@ public interface MetadataHandlerView * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadContainers(Class nodeType, long nodeID, long userID, - AgentEventListener observer); + public CallHandle loadContainers(SecurityContext ctx, Class nodeType, + long nodeID, long userID, AgentEventListener observer); /** * Loads all the ratings attached by a given user to the specified objects. * Retrieves the files if the userID is not -1. * + * @param ctx The security context. * @param nodeType The class identifying the object. * Mustn't be null. * @param nodeIDs The collection of ids of the passed node type. @@ -113,13 +115,14 @@ public CallHandle loadContainers(Class nodeType, long nodeID, long userID, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadRatings(Class nodeType, List nodeIDs, - long userID, AgentEventListener observer); + public CallHandle loadRatings(SecurityContext ctx, Class nodeType, + List nodeIDs, long userID, AgentEventListener observer); /** * Loads the thumbnails associated to the passed image i.e. * one thumbnail per specified user. * + * @param ctx The security context. * @param image The image to handle. * @param userIDs The collection of users. * @param thumbWidth The width of the thumbnail. @@ -127,26 +130,28 @@ public CallHandle loadRatings(Class nodeType, List nodeIDs, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadThumbnails(ImageData image, Set userIDs, - int thumbWidth, int thumbHeight, - AgentEventListener observer); + public CallHandle loadThumbnails(SecurityContext ctx, ImageData image, + Set userIDs, int thumbWidth, int thumbHeight, + AgentEventListener observer); /** * Loads all annotations related the specified object. * Retrieves the files if the userID is not -1. * + * @param ctx The security context. * @param dataObject The object to handle. Mustn't be null. * @param userID Pass -1 if no user specified. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadStructuredData(Object dataObject, long userID, - AgentEventListener observer); + public CallHandle loadStructuredData(SecurityContext ctx, Object dataObject, + long userID, AgentEventListener observer); /** * Loads all annotations related the specified objects. * Retrieves the files if the userID is not -1. * + * @param ctx The security context. * @param data The objects to handle. Mustn't be null. * @param userID Pass -1 if no user specified. * @param viewed Pass true to load the rendering settings @@ -155,14 +160,16 @@ public CallHandle loadStructuredData(Object dataObject, long userID, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadStructuredData(List data, long userID, - boolean viewed, AgentEventListener observer); + public CallHandle loadStructuredData(SecurityContext ctx, + List data, long userID, boolean viewed, + AgentEventListener observer); /** * Loads the existing annotations defined by the annotation type * linked to a given type of object. * Loads all the annotations if the object's type is null. * + * @param ctx The security context. * @param annotation The annotation type. Mustn't be null. * @param userID The id of the user the annotations are owned by, * or -1 if no user specified. @@ -170,13 +177,15 @@ public CallHandle loadStructuredData(List data, long userID, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadExistingAnnotations(Class annotation, long userID, - long groupID, AgentEventListener observer); + public CallHandle loadExistingAnnotations(SecurityContext ctx, + Class annotation, long userID, long groupID, + AgentEventListener observer); /** * Saves the object, adds (resp. removes) annotations to (resp. from) * the object if any. * + * @param ctx The security context. * @param data The data objects to handle. * @param toAdd Collection of annotations to add. * @param toRemove Collection of annotations to remove. @@ -185,16 +194,16 @@ public CallHandle loadExistingAnnotations(Class annotation, long userID, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle saveData(Collection data, - List toAdd, List toRemove, - List metadata, long userID, - AgentEventListener observer); + public CallHandle saveData(SecurityContext ctx, Collection data, + List toAdd, List toRemove, + List metadata, long userID, AgentEventListener observer); /** * Saves the objects contained in the passed DataObjects, * adds (respectively removes) annotations to (respectively from) * the object if any. * + * @param ctx The security context. * @param data The data objects to handle. * @param toAdd Collection of annotations to add. * @param toRemove Collection of annotations to remove. @@ -202,15 +211,17 @@ public CallHandle saveData(Collection data, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle saveBatchData(Collection data, - List toAdd, List toRemove, - long userID, AgentEventListener observer); + public CallHandle saveBatchData(SecurityContext ctx, + Collection data, List toAdd, + List toRemove, long userID, + AgentEventListener observer); /** * Saves the objects contained in the passed DataObjects, * adds (respectively removes) annotations to (respectively from) * the object if any. * + * @param ctx The security context. * @param timeRefObject The object hosting the time period. * @param toAdd Collection of annotations to add. * @param toRemove Collection of annotations to remove. @@ -218,68 +229,75 @@ public CallHandle saveBatchData(Collection data, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle saveBatchData(TimeRefObject timeRefObject, - List toAdd, List toRemove, - long userID, AgentEventListener observer); + public CallHandle saveBatchData(SecurityContext ctx, + TimeRefObject timeRefObject, List toAdd, + List toRemove, long userID, + AgentEventListener observer); /** * Downloads a file previously uploaded to the server. * + * @param ctx The security context. * @param file The file to copy the date into. * @param fileID The id of the original file. * @param size The size of the file. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadFile(File file, long fileID, long size, - AgentEventListener observer); + public CallHandle loadFile(SecurityContext ctx, File file, long fileID, + long size, AgentEventListener observer); /** * Downloads a file previously uploaded to the server. * + * @param ctx The security context. * @param file The file to copy the date into. * @param fileID The id of the original file. * @param index The index of the files * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadFile(File file, long fileID, int index, - AgentEventListener observer); + public CallHandle loadFile(SecurityContext ctx, File file, long fileID, + int index, AgentEventListener observer); /** * Loads the annotation corresponding to the passed id. * + * @param ctx The security context. * @param annotationID The id of the annotation file. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadAnnotation(long annotationID, + public CallHandle loadAnnotation(SecurityContext ctx, long annotationID, AgentEventListener observer); /** * Loads the original files related to a given pixels set. * + * @param ctx The security context. * @param pixelsID The collection of the pixels sets. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadOriginalFiles(Collection pixelsID, - AgentEventListener observer); + public CallHandle loadOriginalFiles(SecurityContext ctx, + Collection pixelsID, AgentEventListener observer); /** * Loads the archived files related to the specified image. * + * @param ctx The security context. * @param pixelsID The id of the pixels set related to the image. * @param location The location where to store the archived files * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadArchivedImage(long pixelsID, String location, - AgentEventListener observer); + public CallHandle loadArchivedImage(SecurityContext ctx, long pixelsID, + String location, AgentEventListener observer); /** * Filters by annotation. * + * @param ctx The security context. * @param nodeType The type of node. * @param nodeIds The collection of nodes to filter. * @param annotationType The type of annotation to filter by. @@ -288,13 +306,14 @@ public CallHandle loadArchivedImage(long pixelsID, String location, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle filterByAnnotation(Class nodeType, List nodeIds, - Class annotationType, List terms, long userID, - AgentEventListener observer); + public CallHandle filterByAnnotation(SecurityContext ctx, Class nodeType, + List nodeIds, Class annotationType, List terms, + long userID, AgentEventListener observer); /** * Filters by annotated nodes. * + * @param ctx The security context. * @param nodeType The type of node. * @param nodeIds The collection of nodes to filter. * @param annotationType The type of annotation to filter by. @@ -304,13 +323,14 @@ public CallHandle filterByAnnotation(Class nodeType, List nodeIds, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle filterByAnnotated(Class nodeType, List nodeIds, - Class annotationType, boolean annotated, long userID, - AgentEventListener observer); + public CallHandle filterByAnnotated(SecurityContext ctx, Class nodeType, + List nodeIds, Class annotationType, boolean annotated, + long userID, AgentEventListener observer); /** * Filters the data. * + * @param ctx The security context. * @param nodeType The type of node. * @param nodeIds The collection of nodes to filter. * @param context The filtering context. @@ -318,13 +338,15 @@ public CallHandle filterByAnnotated(Class nodeType, List nodeIds, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle filterData(Class nodeType, List nodeIds, - FilterContext context, long userID, AgentEventListener observer); + public CallHandle filterData(SecurityContext ctx, Class nodeType, + List nodeIds, FilterContext context, long userID, + AgentEventListener observer); /** * Creates a new DataObject and adds the children to the * newly created node. * + * @param ctx The security context. * @param parent The parent of the DataObject to create * or null if no parent specified. * @param data The DataObject to create. @@ -333,12 +355,13 @@ public CallHandle filterData(Class nodeType, List nodeIds, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle createDataObject(DataObject parent, DataObject data, - Collection children, AgentEventListener observer); + public CallHandle createDataObject(SecurityContext ctx, DataObject parent, + DataObject data, Collection children, AgentEventListener observer); /** * Saves the file back to the server. * + * @param ctx The security context. * @param fileAnnotation The file to save back to the server. * @param file The id of the file if previously saved. * @param index One of the constants defined by this class. @@ -346,79 +369,88 @@ public CallHandle createDataObject(DataObject parent, DataObject data, * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle saveFile(FileAnnotationData fileAnnotation, File file, - int index, DataObject linkTo, AgentEventListener observer); + public CallHandle saveFile(SecurityContext ctx, + FileAnnotationData fileAnnotation, File file, int index, + DataObject linkTo, AgentEventListener observer); /** * Updates the data objects. This method will for now only be implemented * for the plate or wells. * + * @param ctx The security context. * @param objects The objects to update. Mustn't be null. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle updateDataObjects(List objects, - AgentEventListener observer); + public CallHandle updateDataObjects(SecurityContext ctx, + List objects, AgentEventListener observer); /** * Submits the files to the QA system. * + * @param ctx The security context. * @param details Object containing the information to send. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle submitFiles(MessengerDetails details, + public CallHandle submitFiles(SecurityContext ctx, MessengerDetails details, AgentEventListener observer); /** * Loads the measurements related the specified object. * Retrieves the files if the userID is not -1. * + * @param ctx The security context. * @param dataObject The object to handle. Mustn't be null. * @param userID Pass -1 if no user specified. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadROIMeasurement(Object dataObject, long userID, - AgentEventListener observer); + public CallHandle loadROIMeasurement(SecurityContext ctx, Object dataObject, + long userID, AgentEventListener observer); /** * Loads the original files hosted by the file annotation. * + * @param ctx The security context. * @param files The files to handle. Mustn't be null. * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ - public CallHandle loadFiles(Map files, - AgentEventListener observer); + public CallHandle loadFiles(SecurityContext ctx, + Map files, AgentEventListener observer); /** * Loads the scripts. * + * @param ctx The security context. * @param userID The id of the experimenter or -1. * @param all Pass true to retrieve all the scripts uploaded * ones and the default ones, false. * @return A handle that can be used to cancel the call. */ - public CallHandle loadScripts(long userID, boolean all, + public CallHandle loadScripts(SecurityContext ctx, long userID, boolean all, AgentEventListener observer); /** * Loads the specified script. * + * @param ctx The security context. * @param scriptID The id of the script. * @return A handle that can be used to cancel the call. */ - public CallHandle loadScript(long scriptID, AgentEventListener observer); + public CallHandle loadScript(SecurityContext ctx, long scriptID, + AgentEventListener observer); /** * Loads the specified tabular data. * + * @param ctx The security context. * @param parameters The parameters indicating the data to load. * @param userID The id of the experimenter or -1. * @return A handle that can be used to cancel the call. */ - public CallHandle loadTabularData(TableParameters parameters, long userID, - AgentEventListener observer); + public CallHandle loadTabularData(SecurityContext ctx, + TableParameters parameters, long userID, AgentEventListener observer); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/MetadataHandlerViewImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/MetadataHandlerViewImpl.java index 0fa44f4903f..197bff9ee7a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/MetadataHandlerViewImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/MetadataHandlerViewImpl.java @@ -35,6 +35,7 @@ import org.openmicroscopy.shoola.env.data.model.TableParameters; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; import org.openmicroscopy.shoola.env.data.util.FilterContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.calls.ArchivedFilesLoader; import org.openmicroscopy.shoola.env.data.views.calls.ArchivedFilesSaver; import org.openmicroscopy.shoola.env.data.views.calls.ArchivedImageLoader; @@ -75,131 +76,136 @@ class MetadataHandlerViewImpl /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadContainers(Class, long, long, + * @see MetadataHandlerView#loadContainers(SecurityContext, Class, long, long, * AgentEventListener) */ - public CallHandle loadContainers(Class type, long id, long userID, - AgentEventListener observer) + public CallHandle loadContainers(SecurityContext ctx, Class type, long id, + long userID, AgentEventListener observer) { - BatchCallTree cmd = new RelatedContainersLoader(type, id, userID); + BatchCallTree cmd = new RelatedContainersLoader(ctx, type, id, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadThumbnails(ImageData, Set, int, int, + * @see MetadataHandlerView#loadThumbnails(SecurityContext, ImageData, Set, int, int, * AgentEventListener) */ - public CallHandle loadThumbnails(ImageData image, Set userIDs, - int thumbWidth, int thumbHeight, AgentEventListener observer) + public CallHandle loadThumbnails(SecurityContext ctx, ImageData image, + Set userIDs, int thumbWidth, int thumbHeight, + AgentEventListener observer) { - BatchCallTree cmd = new ThumbnailLoader(image, thumbWidth, thumbHeight, - userIDs); + BatchCallTree cmd = new ThumbnailLoader(ctx, image, thumbWidth, + thumbHeight, userIDs); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadStructuredData(DataObject, long, + * @see MetadataHandlerView#loadStructuredData(SecurityContext, DataObject, long, * AgentEventListener) */ - public CallHandle loadStructuredData(Object dataObject, + public CallHandle loadStructuredData(SecurityContext ctx, Object dataObject, long userID, AgentEventListener observer) { - BatchCallTree cmd = new StructuredAnnotationLoader( + BatchCallTree cmd = new StructuredAnnotationLoader(ctx, StructuredAnnotationLoader.ALL, dataObject, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadStructuredData(List, long, boolean, + * @see MetadataHandlerView#loadStructuredData(SecurityContext, List, long, boolean, * AgentEventListener) */ - public CallHandle loadStructuredData(List data, long userID, - boolean viewed, AgentEventListener observer) + public CallHandle loadStructuredData(SecurityContext ctx, + List data, long userID, boolean viewed, + AgentEventListener observer) { - BatchCallTree cmd = new StructuredAnnotationLoader( + BatchCallTree cmd = new StructuredAnnotationLoader(ctx, StructuredAnnotationLoader.ALL, data, userID, viewed); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadExistingAnnotations(Class, long, long, + * @see MetadataHandlerView#loadExistingAnnotations(SecurityContext, Class, long, long, * AgentEventListener) */ - public CallHandle loadExistingAnnotations(Class annotation, long userID, - long groupID, AgentEventListener observer) + public CallHandle loadExistingAnnotations(SecurityContext ctx, + Class annotation, long userID, long groupID, + AgentEventListener observer) { - BatchCallTree cmd = new StructuredAnnotationLoader(annotation, + BatchCallTree cmd = new StructuredAnnotationLoader(ctx, annotation, userID, groupID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#saveData(Collection, List, List, long, + * @see MetadataHandlerView#saveData(SecurityContext, Collection, List, List, long, * AgentEventListener) */ - public CallHandle saveData(Collection data, - List toAdd, List toRemove, - List metadata, long userID, AgentEventListener observer) + public CallHandle saveData(SecurityContext ctx, + Collection data, List toAdd, + List toRemove, List metadata, long userID, + AgentEventListener observer) { - BatchCallTree cmd = new StructuredAnnotationSaver(data, + BatchCallTree cmd = new StructuredAnnotationSaver(ctx, data, toAdd, toRemove, metadata, userID, false); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#saveBatchData(Collection, List, List, + * @see MetadataHandlerView#saveBatchData(SecurityContext, Collection, List, List, * long, AgentEventListener) */ - public CallHandle saveBatchData(Collection data, - List toAdd, List toRemove, - long userID, AgentEventListener observer) + public CallHandle saveBatchData(SecurityContext ctx, + Collection data, List toAdd, + List toRemove, long userID, + AgentEventListener observer) { - BatchCallTree cmd = new StructuredAnnotationSaver(data, + BatchCallTree cmd = new StructuredAnnotationSaver(ctx, data, toAdd, toRemove, null, userID, true); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#saveBatchData(TimeRefObject, List, List, + * @see MetadataHandlerView#saveBatchData(SecurityContext, TimeRefObject, List, List, * long, AgentEventListener) */ - public CallHandle saveBatchData(TimeRefObject refObject, - List toAdd, List toRemove, - long userID, AgentEventListener observer) + public CallHandle saveBatchData(SecurityContext ctx, + TimeRefObject refObject, List toAdd, + List toRemove, long userID, AgentEventListener observer) { - BatchCallTree cmd = new StructuredAnnotationSaver(refObject, + BatchCallTree cmd = new StructuredAnnotationSaver(ctx, refObject, toAdd, toRemove, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadFile(File, long, long, + * @see MetadataHandlerView#loadFile(SecurityContext, File, long, long, * AgentEventListener) */ - public CallHandle loadFile(File file, long fileID, long size, - AgentEventListener observer) + public CallHandle loadFile(SecurityContext ctx, File file, long fileID, + long size, AgentEventListener observer) { - BatchCallTree cmd = new FilesLoader(file, fileID, size); + BatchCallTree cmd = new FilesLoader(ctx, file, fileID, size); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadFile(File, long, int, + * @see MetadataHandlerView#loadFile(SecurityContext, File, long, int, * AgentEventListener) */ - public CallHandle loadFile(File file, long fileID, int index, - AgentEventListener observer) + public CallHandle loadFile(SecurityContext ctx, File file, long fileID, + int index, AgentEventListener observer) { - BatchCallTree cmd = new FilesLoader(file, fileID, index); + BatchCallTree cmd = new FilesLoader(ctx, file, fileID, index); return cmd.exec(observer); } @@ -207,133 +213,136 @@ public CallHandle loadFile(File file, long fileID, int index, * Implemented as specified by the view interface. * @see MetadataHandlerView#loadOriginalFiles(Collection, AgentEventListener) */ - public CallHandle loadOriginalFiles(Collection pixelsID, - AgentEventListener observer) + public CallHandle loadOriginalFiles(SecurityContext ctx, + Collection pixelsID, AgentEventListener observer) { - BatchCallTree cmd = new ArchivedFilesLoader(pixelsID); + BatchCallTree cmd = new ArchivedFilesLoader(ctx, pixelsID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadOriginalImage(long, String, + * @see MetadataHandlerView#loadOriginalImage(SecurityContext, long, String, * AgentEventListener) */ - public CallHandle loadArchivedImage(long pixelsID, String path, - AgentEventListener observer) + public CallHandle loadArchivedImage(SecurityContext ctx, long pixelsID, + String path, AgentEventListener observer) { - BatchCallTree cmd = new ArchivedImageLoader(pixelsID, path); + BatchCallTree cmd = new ArchivedImageLoader(ctx, pixelsID, path); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadRatings(Class, List, long, + * @see MetadataHandlerView#loadRatings(SecurityContext, Class, List, long, * AgentEventListener) */ - public CallHandle loadRatings(Class nodeType, List nodeIDs, - long userID, AgentEventListener observer) + public CallHandle loadRatings(SecurityContext ctx, Class nodeType, + List nodeIDs, long userID, AgentEventListener observer) { - BatchCallTree cmd = new StructuredAnnotationLoader( - StructuredAnnotationLoader.RATING, nodeType, nodeIDs, - userID); + BatchCallTree cmd = new StructuredAnnotationLoader(ctx, + StructuredAnnotationLoader.RATING, nodeType, nodeIDs, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#filterByAnnotation(Class, List, Class, List, + * @see MetadataHandlerView#filterByAnnotation(SecurityContext, Class, List, Class, List, * long, AgentEventListener) */ - public CallHandle filterByAnnotation(Class nodeType, List nodeIds, - Class annotationType, List terms, long userID, - AgentEventListener observer) + public CallHandle filterByAnnotation(SecurityContext ctx, Class nodeType, + List nodeIds, Class annotationType, List terms, + long userID, AgentEventListener observer) { - BatchCallTree cmd = new DataFilter(annotationType, nodeType, nodeIds, - terms, userID); + BatchCallTree cmd = new DataFilter(ctx, annotationType, nodeType, + nodeIds, terms, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#filterByAnnotated(Class, List, Class, boolean, + * @see MetadataHandlerView#filterByAnnotated(SecurityContext, Class, List, Class, boolean, * long, AgentEventListener) */ - public CallHandle filterByAnnotated(Class nodeType, List nodeIds, - Class annotationType, boolean annotated, long userID, - AgentEventListener observer) + public CallHandle filterByAnnotated(SecurityContext ctx, Class nodeType, + List nodeIds, Class annotationType, boolean annotated, + long userID, AgentEventListener observer) { - BatchCallTree cmd = new DataFilter(annotationType, nodeType, nodeIds, - annotated, userID); + BatchCallTree cmd = new DataFilter(ctx, annotationType, nodeType, + nodeIds, annotated, userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#filterData(Class, List, FilterContext, long, + * @see MetadataHandlerView#filterData(SecurityContext, Class, List, FilterContext, long, * AgentEventListener) */ - public CallHandle filterData(Class nodeType, List nodeIds, - FilterContext context, long userID, AgentEventListener observer) + public CallHandle filterData(SecurityContext ctx, Class nodeType, + List nodeIds, FilterContext context, long userID, + AgentEventListener observer) { - BatchCallTree cmd = new DataFilter(nodeType, nodeIds, context, userID); + BatchCallTree cmd = new DataFilter(ctx, nodeType, nodeIds, context, + userID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#createDataObject(DataObject, DataObject, + * @see MetadataHandlerView#createDataObject(SecurityContext, DataObject, DataObject, * Collection, AgentEventListener) */ - public CallHandle createDataObject(DataObject parent, DataObject data, - Collection children, - AgentEventListener observer) + public CallHandle createDataObject(SecurityContext ctx, DataObject parent, + DataObject data, Collection children, AgentEventListener observer) { - BatchCallTree cmd = new DataObjectSaver(parent, data, children); + BatchCallTree cmd = new DataObjectSaver(ctx, parent, data, children); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#saveFile(FileAnnotationData, File, int, + * @see MetadataHandlerView#saveFile(SecurityContext, FileAnnotationData, File, int, * DataObject, AgentEventListener) */ - public CallHandle saveFile(FileAnnotationData fileAnnotation, File file, - int index, DataObject linkTo, AgentEventListener observer) + public CallHandle saveFile(SecurityContext ctx, + FileAnnotationData fileAnnotation, + File file, int index, DataObject linkTo, + AgentEventListener observer) { - BatchCallTree cmd = new ArchivedFilesSaver(fileAnnotation, file, index, - linkTo); + BatchCallTree cmd = new ArchivedFilesSaver(ctx, fileAnnotation, file, + index, linkTo); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadAnnotation(long, AgentEventListener) + * @see MetadataHandlerView#loadAnnotation(SecurityContext, long, AgentEventListener) */ - public CallHandle loadAnnotation(long annotationID, + public CallHandle loadAnnotation(SecurityContext ctx, long annotationID, AgentEventListener observer) { - BatchCallTree cmd = new StructuredAnnotationLoader(annotationID); + BatchCallTree cmd = new StructuredAnnotationLoader(ctx, annotationID); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#updateDataObjects(List, AgentEventListener) + * @see MetadataHandlerView#updateDataObjects(SecurityContext, List, AgentEventListener) */ - public CallHandle updateDataObjects(List objects, - AgentEventListener observer) + public CallHandle updateDataObjects(SecurityContext ctx, + List objects, AgentEventListener observer) { - BatchCallTree cmd = new DataObjectSaver(objects, null, + BatchCallTree cmd = new DataObjectSaver(ctx, objects, null, DataObjectSaver.UPDATE); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#submitFiles(MessengerDetails, AgentEventListener) + * @see MetadataHandlerView#submitFiles(SecurityContext, + * MessengerDetails, AgentEventListener) */ - public CallHandle submitFiles(MessengerDetails details, + public CallHandle submitFiles(SecurityContext ctx, MessengerDetails details, AgentEventListener observer) { BatchCallTree cmd = new FileUploader(details); @@ -342,13 +351,13 @@ public CallHandle submitFiles(MessengerDetails details, /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadRatings(Object, long, + * @see MetadataHandlerView#loadRatings(SecurityContext, Object, long, * AgentEventListener) */ - public CallHandle loadROIMeasurement(Object dataObject, long userID, - AgentEventListener observer) + public CallHandle loadROIMeasurement(SecurityContext ctx, + Object dataObject, long userID, AgentEventListener observer) { - BatchCallTree cmd = new StructuredAnnotationLoader( + BatchCallTree cmd = new StructuredAnnotationLoader(ctx, StructuredAnnotationLoader.ROI_MEASUREMENT, dataObject, userID); return cmd.exec(observer); @@ -356,48 +365,50 @@ public CallHandle loadROIMeasurement(Object dataObject, long userID, /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadFiles(Map, AgentEventListener) + * @see MetadataHandlerView#loadFiles(SecurityContext, Map, AgentEventListener) */ - public CallHandle loadFiles(Map files, - AgentEventListener observer) + public CallHandle loadFiles(SecurityContext ctx, + Map files, AgentEventListener observer) { - BatchCallTree cmd = new FilesLoader(files); + BatchCallTree cmd = new FilesLoader(ctx, files); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadScripts(long, boolean, AgentEventListener) + * @see MetadataHandlerView#loadScripts(SecurityContext, long, boolean, AgentEventListener) */ - public CallHandle loadScripts(long userID, boolean all, + public CallHandle loadScripts(SecurityContext ctx, long userID, boolean all, AgentEventListener observer) { int index = ScriptsLoader.DEFAULT_SCRIPTS; if (all) index = ScriptsLoader.ALL_SCRIPTS; - BatchCallTree cmd = new ScriptsLoader(userID, index); + BatchCallTree cmd = new ScriptsLoader(ctx, userID, index); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadScript(long, AgentEventListener) + * @see MetadataHandlerView#loadScript(SecurityContext, long, AgentEventListener) */ - public CallHandle loadScript(long scriptID, AgentEventListener observer) + public CallHandle loadScript(SecurityContext ctx, long scriptID, + AgentEventListener observer) { - BatchCallTree cmd = new ScriptsLoader(scriptID, + BatchCallTree cmd = new ScriptsLoader(ctx, scriptID, ScriptsLoader.SINGLE_SCRIPT); return cmd.exec(observer); } /** * Implemented as specified by the view interface. - * @see MetadataHandlerView#loadTabularData(TableParameters, long, + * @see MetadataHandlerView#loadTabularData(SecurityContext, TableParameters, long, * AgentEventListener) */ - public CallHandle loadTabularData(TableParameters parameters, long userID, + public CallHandle loadTabularData(SecurityContext ctx, + TableParameters parameters, long userID, AgentEventListener observer) { - BatchCallTree cmd = new TabularDataLoader(parameters, userID); + BatchCallTree cmd = new TabularDataLoader(ctx, parameters, userID); return cmd.exec(observer); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ProcessCallback.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ProcessCallback.java index e1a2d4bae48..1764d7d6a67 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ProcessCallback.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/ProcessCallback.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.DeleteCallback; +import org.openmicroscopy.shoola.env.data.RequestCallback; import org.openmicroscopy.shoola.env.data.ScriptCallback; import org.openmicroscopy.shoola.env.data.ProcessException; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; @@ -64,6 +65,7 @@ private void checkHandle(Object callback) { if (callback instanceof ScriptCallback) return; if (callback instanceof DeleteCallback) return; + if (callback instanceof RequestCallback) return; throw new omero.IllegalArgumentException("Call back not supported."); } @@ -91,6 +93,8 @@ public void setAdapter(DSCallAdapter adapter) ((ScriptCallback) callback).setAdapter(adapter); else if (callback instanceof DeleteCallback) ((DeleteCallback) callback).setAdapter(adapter); + else if (callback instanceof RequestCallback) + ((RequestCallback) callback).setAdapter(adapter); } /** Cancels the on-going process. */ @@ -115,6 +119,8 @@ Object block(long value) return ((ScriptCallback) callback).block(value); if (callback instanceof DeleteCallback) return ((DeleteCallback) callback).block(value); + if (callback instanceof RequestCallback) + return ((RequestCallback) callback).block(value); return null; } @@ -129,6 +135,8 @@ void close() ((ScriptCallback) callback).close(); } else if (callback instanceof DeleteCallback) { ((DeleteCallback) callback).close(); + } else if (callback instanceof RequestCallback) { + ((RequestCallback) callback).close(); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AcquisitionDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AcquisitionDataLoader.java index 541e5405b7a..c31d1e96cfc 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AcquisitionDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AcquisitionDataLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroMetadataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.RenderingControl; @@ -68,17 +69,19 @@ public class AcquisitionDataLoader * Creates a {@link BatchCall} to retrieve the acquisition data linked * to the passed object. * + * @param ctx The security context. * @param refObject Either an ImageData or * ChannelData node. * @return The {@link BatchCall}. */ - private BatchCall makeBatchCall(final Object refObject) + private BatchCall makeBatchCall(final SecurityContext ctx, + final Object refObject) { return new BatchCall("Loading Acquisition data: ") { public void doCall() throws Exception { OmeroMetadataService svc = context.getMetadataService(); - result = svc.loadAcquisitionData(refObject); + result = svc.loadAcquisitionData(ctx, refObject); } }; } @@ -87,16 +90,18 @@ public void doCall() throws Exception * Creates a {@link BatchCall} to retrieve the components of the passed * instrument. * + * @param ctx The security context. * @param id The id of the instrument. * @return The {@link BatchCall}. */ - private BatchCall makeInstrumentBatchCall(final long id) + private BatchCall makeInstrumentBatchCall(final SecurityContext ctx, + final long id) { return new BatchCall("Loading Instrument data: ") { public void doCall() throws Exception { OmeroMetadataService svc = context.getMetadataService(); - result = svc.loadInstrument(id); + result = svc.loadInstrument(ctx, id); } }; } @@ -120,14 +125,15 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * + * @param ctx The security context. * @param refObject Either an ImageData or * ChannelData node. */ - public AcquisitionDataLoader(Object refObject) + public AcquisitionDataLoader(SecurityContext ctx, Object refObject) { if (refObject == null) throw new IllegalArgumentException("Ref Object cannot be null."); - loadCall = makeBatchCall(refObject); + loadCall = makeBatchCall(ctx, refObject); } /** @@ -135,21 +141,22 @@ public AcquisitionDataLoader(Object refObject) * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * + * @param ctx The security context. * @param type One of the constants defined by this class. * @param id The id of the object corresponding to the passed type. */ - public AcquisitionDataLoader(int type, long id) + public AcquisitionDataLoader(SecurityContext ctx, int type, long id) { if (id <= 0) throw new IllegalArgumentException("Id not valid."); switch (type) { case INSTRUMENT: - loadCall = makeInstrumentBatchCall(id); + loadCall = makeInstrumentBatchCall(ctx, id); break; case IMAGE: ImageData img = new ImageData(); img.setId(id); - loadCall = makeBatchCall(img); + loadCall = makeBatchCall(ctx, img); break; default: throw new IllegalArgumentException("Type not supported"); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AcquisitionDataSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AcquisitionDataSaver.java index 82e378ca2a8..c0e2c21d9fe 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AcquisitionDataSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AcquisitionDataSaver.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroMetadataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.RenderingControl; @@ -60,17 +61,19 @@ public class AcquisitionDataSaver /** * Creates a {@link BatchCall} to retrieve rendering control. * + * @param ctx The security context. * @param refObject Either an ImageData or * ChannelData node. * @return The {@link BatchCall}. */ - private BatchCall makeBatchCall(final Object refObject) + private BatchCall makeBatchCall(final SecurityContext ctx, + final Object refObject) { return new BatchCall("Loading Acquisition data: ") { public void doCall() throws Exception { OmeroMetadataService rds = context.getMetadataService(); - result = rds.saveAcquisitionData(refObject); + result = rds.saveAcquisitionData(ctx, refObject); } }; } @@ -94,13 +97,14 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * + * @param ctx The security context. * @param refObject Either an ImageData or * ChannelData node. */ - public AcquisitionDataSaver(Object refObject) + public AcquisitionDataSaver(SecurityContext ctx, Object refObject) { if (refObject == null) throw new IllegalArgumentException("Ref Object cannot be null."); - loadCall = makeBatchCall(refObject); + loadCall = makeBatchCall(ctx, refObject); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AdminLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AdminLoader.java index bfd847c8c19..d0f466978fd 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AdminLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AdminLoader.java @@ -38,6 +38,7 @@ import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.login.UserCredentials; import org.openmicroscopy.shoola.env.data.model.DiskQuota; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -87,18 +88,20 @@ public class AdminLoader * Creates a {@link BatchCall} to retrieve the available and used * disk space. * + * @param ctx The security context. * @param type Either ExperimenterData or GroupData class. * @param id The id of the user, group or -1. * @param type Either experimenter or group. * @return The {@link BatchCall}. */ - private BatchCall availableSpaceCall(final Class type, final long id) + private BatchCall availableSpaceCall(final SecurityContext ctx, + final Class type, final long id) { return new BatchCall("Loading disk space information") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.getQuota(type, id); + result = os.getQuota(ctx, type, id); } }; } @@ -107,12 +110,14 @@ public void doCall() throws Exception * Creates a {@link BatchCall} to retrieve the available and used * disk space. * + * @param ctx The security context. * @param type Either ExperimenterData or GroupData class. * @param ids The id of the users or groups. * @param type Either experimenter or group. * @return The {@link BatchCall}. */ - private BatchCall availableSpaceCall(final Class type, final List ids) + private BatchCall availableSpaceCall(final SecurityContext ctx, + final Class type, final List ids) { return new BatchCall("Loading disk space information") { public void doCall() throws Exception @@ -121,7 +126,7 @@ public void doCall() throws Exception List list = new ArrayList(); Iterator i = ids.iterator(); while (i.hasNext()) { - list.add(os.getQuota(type, i.next())); + list.add(os.getQuota(ctx, type, i.next())); } result = list; } @@ -133,18 +138,19 @@ public void doCall() throws Exception * Creates a {@link BatchCall} to change the password * of the user currently logged in. * - * @param oldPassword The password used to log in. + * @param ctx The security context. + * @param oldPassword The password used to log in. * @param newPassword The new password value. * @return The {@link BatchCall}. */ - private BatchCall changePassword(final String oldPassword, - final String newPassword) + private BatchCall changePassword(final SecurityContext ctx, + final String oldPassword, final String newPassword) { return new BatchCall("Change password") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.changePassword(oldPassword, newPassword); + result = os.changePassword(ctx, oldPassword, newPassword); } }; } @@ -152,16 +158,18 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to update the specified experimenter. * + * @param ctx The security context. * @param exp The experimenter to update. * @return The {@link BatchCall}. */ - private BatchCall updateExperimenter(final ExperimenterData exp) + private BatchCall updateExperimenter(final SecurityContext ctx, + final ExperimenterData exp) { return new BatchCall("Update experimenter") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.updateExperimenter(exp, null); + result = os.updateExperimenter(ctx, exp, null); } }; } @@ -169,17 +177,19 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to update the specified group. * + * @param ctx The security context. * @param group The group to update. * @param permissions The desired permissions level or -1. * @return The {@link BatchCall}. */ - private BatchCall updateGroup(final GroupData group, final int permissions) + private BatchCall updateGroup(final SecurityContext ctx, + final GroupData group, final int permissions) { return new BatchCall("Update group") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.updateGroup(group, permissions); + result = os.updateGroup(ctx, group, permissions); } }; } @@ -188,16 +198,17 @@ public void doCall() throws Exception * Creates a {@link BatchCall} to load all the available group if the * passed parameter is -1, load the group otherwise. * + * @param ctx The security context. * @param id The id of the group. * @return The {@link BatchCall}. */ - private BatchCall loadGroup(final long id) + private BatchCall loadGroup(final SecurityContext ctx, final long id) { return new BatchCall("Load groups") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.loadGroups(id); + result = os.loadGroups(ctx, id); } }; } @@ -206,16 +217,18 @@ public void doCall() throws Exception * Creates a {@link BatchCall} to load the experimenters contained * within the specified group. * + * @param ctx The security context. * @param id The id of the group. * @return The {@link BatchCall}. */ - private BatchCall loadExperimenters(final long id) + private BatchCall loadExperimenters(final SecurityContext ctx, + final long id) { return new BatchCall("Load experimenters") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.loadExperimenters(id); + result = os.loadExperimenters(ctx, id); } }; } @@ -223,17 +236,19 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to update the specified experimenters. * + * @param ctx The security context. * @param experimenters The experimenters to update. * @return The {@link BatchCall}. */ - private BatchCall updateExperimenters(final GroupData group, - final Map experimenters) + private BatchCall updateExperimenters(final SecurityContext ctx, + final GroupData group, + final Map experimenters) { return new BatchCall("Update experimenters") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.updateExperimenters(group, experimenters); + result = os.updateExperimenters(ctx, group, experimenters); } }; } @@ -241,10 +256,12 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to load the photo. * + * @param ctx The security context. * @param experimenter The experimenter to handle. * @return The {@link BatchCall}. */ - private BatchCall loadExperimenterPhoto(final ExperimenterData experimenter) + private BatchCall loadExperimenterPhoto(final SecurityContext ctx, + final ExperimenterData experimenter) { return new BatchCall("Load photo") { public void doCall() throws Exception @@ -253,7 +270,7 @@ public void doCall() throws Exception List exps = new ArrayList(); exps.add(experimenter); Map map = - os.getExperimenterThumbnailSet(exps, 96); + os.getExperimenterThumbnailSet(ctx, exps, 96); result = map.get(experimenter); } }; @@ -262,12 +279,13 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to load the photo. * + * @param ctx The security context. * @param experimenter The experimenter to handle. * @param photo The photo to upload. * @param format The format of the file. * @return The {@link BatchCall}. */ - private BatchCall uploadExperimenterPhoto( + private BatchCall uploadExperimenterPhoto(final SecurityContext ctx, final ExperimenterData experimenter, final File photo, final String format) { @@ -275,7 +293,7 @@ private BatchCall uploadExperimenterPhoto( public void doCall() throws Exception { AdminService svc = context.getAdminService(); - result = svc.uploadUserPhoto(photo, format, experimenter); + result = svc.uploadUserPhoto(ctx, photo, format, experimenter); } }; } @@ -298,119 +316,128 @@ public void doCall() throws Exception * @param id The id of the user or -1. * @param index One of the constants defined by this class. */ - public AdminLoader(long id, int index) + public AdminLoader(SecurityContext ctx, long id, int index) { switch (index) { case SPACE: - loadCall = availableSpaceCall(ExperimenterData.class, id); + loadCall = availableSpaceCall(ctx, ExperimenterData.class, id); break; case GROUPS: - loadCall = loadGroup(id); + loadCall = loadGroup(ctx, id); break; case EXPERIMENTERS: - loadCall = loadExperimenters(id); + loadCall = loadExperimenters(ctx, id); } } /** * Creates a new instance. * + * @param ctx The security context. * @param type Either ExperimenterData or * GroupData * @param id The id of the user or -1. */ - public AdminLoader(Class type, long id) + public AdminLoader(SecurityContext ctx, Class type, long id) { - loadCall = availableSpaceCall(type, id); + loadCall = availableSpaceCall(ctx, type, id); } /** * Creates a new instance. * + * @param ctx The security context. * @param type Either ExperimenterData or * GroupData * @param ids The id of the user or groups. */ - public AdminLoader(Class type, List ids) + public AdminLoader(SecurityContext ctx, Class type, List ids) { - loadCall = availableSpaceCall(type, ids); + loadCall = availableSpaceCall(ctx, type, ids); } /** * Creates a new instance. * + * @param ctx The security context. * @param oldPassword The password used to log in. * @param newPassword The new password value. */ - public AdminLoader(String oldPassword, String newPassword) + public AdminLoader(SecurityContext ctx, String oldPassword, + String newPassword) { if (newPassword == null || newPassword.trim().length() == 0) throw new IllegalArgumentException("Password not valid."); if (oldPassword == null || oldPassword.trim().length() == 0) throw new IllegalArgumentException("Password not valid."); - loadCall = changePassword(oldPassword, newPassword); + loadCall = changePassword(ctx, oldPassword, newPassword); } /** * Creates a new instance. * + * @param ctx The security context. * @param exp The experimenter to update. Mustn't be null. */ - public AdminLoader(ExperimenterData exp, int index) + public AdminLoader(SecurityContext ctx, ExperimenterData exp, int index) { if (exp == null) throw new IllegalArgumentException("Experimenter not valid."); switch (index) { case EXPERIMENTER_UPDATE: - loadCall = updateExperimenter(exp); + loadCall = updateExperimenter(ctx, exp); break; case EXPERIMENTER_PHOTO: - loadCall = loadExperimenterPhoto(exp); + loadCall = loadExperimenterPhoto(ctx, exp); } } /** * Creates a new instance. * + * @param ctx The security context. * @param exp The experimenter to update. Mustn't be null. * @param photo The photo to upload. Mustn't be null. * @param format The format of the photo to upload. */ - public AdminLoader(ExperimenterData exp, File photo, String format) + public AdminLoader(SecurityContext ctx, ExperimenterData exp, File photo, + String format) { if (exp == null) throw new IllegalArgumentException("Experimenter not valid."); if (photo == null) throw new IllegalArgumentException("Photo not valid."); - loadCall = uploadExperimenterPhoto(exp, photo, format); + loadCall = uploadExperimenterPhoto(ctx, exp, photo, format); } /** * Creates a new instance. * + * @param ctx The security context. * @param group The group to update. Mustn't be null. * @param permissions The desired permissions level or -1. */ - public AdminLoader(GroupData group, int permissions) + public AdminLoader(SecurityContext ctx, GroupData group, int permissions) { if (group == null) throw new IllegalArgumentException("Group not valid."); - loadCall = updateGroup(group, permissions); + loadCall = updateGroup(ctx, group, permissions); } /** * Creates a new instance. * + * @param ctx The security context. * @param group The default group to set. * @param experimenters The experimenters to update. * Mustn't be null. */ - public AdminLoader(GroupData group, + public AdminLoader(SecurityContext ctx, GroupData group, Map experimenters) { if (experimenters == null) throw new IllegalArgumentException("No experimenters to update."); - loadCall = updateExperimenters(group, experimenters); + loadCall = updateExperimenters(ctx, group, experimenters); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AdminSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AdminSaver.java index 1fdb3136d05..623762a243c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AdminSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AdminSaver.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.AdminService; import org.openmicroscopy.shoola.env.data.model.AdminObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DataObject; @@ -68,10 +69,12 @@ public class AdminSaver /** * Creates a {@link BatchCall} to delete the objects. * + * @param ctx The security context. * @param objects The objects to handle. * @return The {@link BatchCall}. */ - private BatchCall deleteObjects(final List objects) + private BatchCall deleteObjects(final SecurityContext ctx, + final List objects) { return new BatchCall("Delete objects") { public void doCall() throws Exception @@ -92,9 +95,9 @@ public void doCall() throws Exception } } if (groups.size() > 0) - l.addAll(os.deleteGroups(groups)); + l.addAll(os.deleteGroups(ctx, groups)); if (experimenters.size() > 0) - l.addAll(os.deleteExperimenters(experimenters)); + l.addAll(os.deleteExperimenters(ctx, experimenters)); result = l; } }; @@ -103,16 +106,18 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to create experimenters. * + * @param ctx The security context. * @param object The experimenters to create. * @return The {@link BatchCall}. */ - private BatchCall createExperimenters(final AdminObject object) + private BatchCall createExperimenters(final SecurityContext ctx, + final AdminObject object) { return new BatchCall("Create experimenters") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.createExperimenters(object); + result = os.createExperimenters(ctx, object); } }; } @@ -120,16 +125,18 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to reset the password of the experimenters. * + * @param ctx The security context. * @param object The experimenters to handle. * @return The {@link BatchCall}. */ - private BatchCall resetExperimentersPassword(final AdminObject object) + private BatchCall resetExperimentersPassword(final SecurityContext ctx, + final AdminObject object) { return new BatchCall("Reset password") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.resetExperimentersPassword(object); + result = os.resetExperimentersPassword(ctx, object); } }; } @@ -137,16 +144,18 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to activate or not the experimenters. * - * @param object The experimenters to handle. + * @param ctx The security context. + * @param object The experimenters to handle. * @return The {@link BatchCall}. */ - private BatchCall activateExperimenters(final AdminObject object) + private BatchCall activateExperimenters(final SecurityContext ctx, + final AdminObject object) { return new BatchCall("Reset password") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.activateExperimenters(object); + result = os.activateExperimenters(ctx, object); } }; } @@ -154,16 +163,18 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to create group. * - * @param object The experimenters to create. + * @param ctx The security context. + * @param object The experimenters to create. * @return The {@link BatchCall}. */ - private BatchCall createGroup(final AdminObject object) + private BatchCall createGroup(final SecurityContext ctx, + final AdminObject object) { return new BatchCall("Create group") { public void doCall() throws Exception { AdminService os = context.getAdminService(); - result = os.createGroup(object); + result = os.createGroup(ctx, object); } }; } @@ -183,39 +194,41 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param exp The experimenter to update. Mustn't be null. */ - public AdminSaver(AdminObject object) + public AdminSaver(SecurityContext ctx, AdminObject object) { if (object == null) throw new IllegalArgumentException("Object not valid."); switch (object.getIndex()) { case AdminObject.CREATE_EXPERIMENTER: - loadCall = createExperimenters(object); + loadCall = createExperimenters(ctx, object); break; case AdminObject.CREATE_GROUP: - loadCall = createGroup(object); + loadCall = createGroup(ctx, object); break; case AdminObject.RESET_PASSWORD: - loadCall = resetExperimentersPassword(object); + loadCall = resetExperimentersPassword(ctx, object); break; case AdminObject.ACTIVATE_USER: - loadCall = activateExperimenters(object); + loadCall = activateExperimenters(ctx, object); } } /** * Creates a new instance. * + * @param ctx The security context. * @param objects The objects to handle. Mustn't be null. */ - public AdminSaver(List objects, int index) + public AdminSaver(SecurityContext ctx, List objects, int index) { if (objects == null || objects.size() == 0) throw new IllegalArgumentException("No objects to handle"); switch (index) { case DELETE: - loadCall = deleteObjects(objects); + loadCall = deleteObjects(ctx, objects); break; } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/Analyser.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/Analyser.java index 10571b881c4..d687200cd23 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/Analyser.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/Analyser.java @@ -31,6 +31,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.PixelsServicesFactory; @@ -71,10 +72,12 @@ public class Analyser /** * Creates a {@link BatchCall} to analyze the specified shapes. * - * @param shapes Collection of shapes to analyze. + * @param ctx The security context. + * @param shapes Collection of shapes to analyze. * @return The {@link BatchCall}. */ - private BatchCall analyseShapes(final ROIShape[] shapes) + private BatchCall analyseShapes(final SecurityContext ctx, + final ROIShape[] shapes) { return new BatchCall("Analysing shapes") { public void doCall() throws Exception @@ -86,11 +89,8 @@ public void doCall() throws Exception pixels.getSizeC(), pixels.getSizeX(), pixels.getSizeY()); try { - result = analyser.analyze(shapes, channels); + result = analyser.analyze(ctx, shapes, channels); } catch (Exception e) { - - //TODO handle exception - e.printStackTrace(); } } }; @@ -112,13 +112,15 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param pixels The pixels set to analyze. * @param channels Collection of active channels. * Mustn't be null. * @param shapes Collection of shapes to analyze. * Mustn't be null. */ - public Analyser(PixelsData pixels, List channels, List shapes) + public Analyser(SecurityContext ctx, PixelsData pixels, List channels, + List shapes) { if (pixels == null) throw new IllegalArgumentException("No Pixels specified."); @@ -135,7 +137,7 @@ public Analyser(PixelsData pixels, List channels, List shapes) data[index] = (ROIShape) i.next(); index++; } - loadCall = analyseShapes(data); + loadCall = analyseShapes(ctx, data); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AnnotationParentLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AnnotationParentLoader.java index 24407fecc83..c131e2d0e8c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AnnotationParentLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/AnnotationParentLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroMetadataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -53,16 +54,18 @@ public class AnnotationParentLoader /** * Creates a {@link BatchCall} to load the parents of the annotation. * + * @param ctx The security context. * @param annotationId The id of the annotation to handle. * @return The {@link BatchCall}. */ - private BatchCall makeCall(final long annotationId) + private BatchCall makeCall(final SecurityContext ctx, + final long annotationId) { return new BatchCall("Load Parents of annotations") { public void doCall() throws Exception { OmeroMetadataService svc = context.getMetadataService(); - result = svc.loadParentsOfAnnotations(annotationId); + result = svc.loadParentsOfAnnotations(ctx, annotationId); } }; } @@ -83,11 +86,12 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param annotationId The id of the annotation to handle. */ - public AnnotationParentLoader(long annotationId) + public AnnotationParentLoader(SecurityContext ctx, long annotationId) { - loadCall = makeCall(annotationId); + loadCall = makeCall(ctx, annotationId); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedFilesLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedFilesLoader.java index 6041920d0eb..eb891fe7233 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedFilesLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedFilesLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -53,10 +54,13 @@ public class ArchivedFilesLoader { /** The result of the call. */ - private Object result; + private Object result; /** The collection of files to download. */ - private Collection pixelsID; + private Collection pixelsID; + + /** The security context.*/ + private SecurityContext ctx; /** * Downloads the original file. @@ -67,7 +71,7 @@ private void downloadFile(long id) { try { OmeroDataService os = context.getDataService(); - result = os.getOriginalFiles(id); + result = os.getOriginalFiles(ctx, id); } catch (Exception e) { context.getLogger().error(this, "Cannot retrieve download the file: "+e.getMessage()); @@ -113,11 +117,14 @@ protected void buildTree() /** * Creates a new instance. * + * @param ctx The security context. * @param pixelsID The collection of the pixels set. */ - public ArchivedFilesLoader(Collection pixelsID) + public ArchivedFilesLoader(SecurityContext ctx, + Collection pixelsID) { this.pixelsID = pixelsID; + this.ctx = ctx; } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedFilesSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedFilesSaver.java index 47732b7c813..47dcb205e3c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedFilesSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedFilesSaver.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroMetadataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DataObject; @@ -61,22 +62,23 @@ public class ArchivedFilesSaver /** * Creates a {@link BatchCall} to retrieve the archived files. * - * @param fileAnnotation The annotation hosting the previous info. - * @param file The file to save. - * @param index Index used to determine the name space. - * @param linkTo The DataObject to link the - * annotation to. + * @param ctx The security context. + * @param fileAnnotation The annotation hosting the previous info. + * @param file The file to save. + * @param index Index used to determine the name space. + * @param linkTo The DataObject to link the annotation to. * @return The {@link BatchCall}. */ - private BatchCall makeBatchCall(final FileAnnotationData fileAnnotation, - final File file, final int index, - final DataObject linkTo) + private BatchCall makeBatchCall(final SecurityContext ctx, + final FileAnnotationData fileAnnotation, final File file, + final int index, final DataObject linkTo) { return new BatchCall("Loading annotation") { public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.archivedFile(fileAnnotation, file, index, linkTo); + result = os.archivedFile(ctx, fileAnnotation, file, index, + linkTo); } }; } @@ -96,16 +98,17 @@ public void doCall() throws Exception /** * Creates a new instance. * - * @param fileAnnotation The annotation hosting the previous info. - * @param file The file to save. - * @param index Index used to determine the name space. - * @param linkTo The DataObject to link the - * annotation to. + * @param ctx The security context. + * @param fileAnnotation The annotation hosting the previous info. + * @param file The file to save. + * @param index Index used to determine the name space. + * @param linkTo The DataObject to link the annotation to. */ - public ArchivedFilesSaver(FileAnnotationData fileAnnotation, File file, - int index, DataObject linkTo) + public ArchivedFilesSaver(SecurityContext ctx, + FileAnnotationData fileAnnotation, File file, int index, + DataObject linkTo) { - loadCall = makeBatchCall(fileAnnotation, file, index, linkTo); + loadCall = makeBatchCall(ctx, fileAnnotation, file, index, linkTo); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java index e333dfd2736..1b19c8eb700 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -59,19 +60,21 @@ public class ArchivedImageLoader /** * Creates a {@link BatchCall} to retrieve the channels metadata. * + * @param ctx The security context. * @param pixelsID The ID of the pixels set. * @param userID If the id is specified i.e. not -1, * load the color associated to the channel, * false otherwise. * @return The {@link BatchCall}. */ - private BatchCall makeBatchCall(final long pixelsID, final String folder) + private BatchCall makeBatchCall(final SecurityContext ctx, + final long pixelsID, final String folder) { return new BatchCall("Download the archived files. ") { public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - result = os.getArchivedImage(folder, pixelsID); + result = os.getArchivedImage(ctx, folder, pixelsID); } }; } @@ -93,13 +96,15 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * - * @param pixelsID The Id of the pixels set. + * @param ctx The security context. + * @param pixelsID The Id of the pixels set. * @param folderPath The location where to download the archived image. */ - public ArchivedImageLoader(long pixelsID, String folderPath) + public ArchivedImageLoader(SecurityContext ctx, long pixelsID, + String folderPath) { if (pixelsID < 0) throw new IllegalArgumentException("Pixels ID not valid."); - loadCall = makeBatchCall(pixelsID, folderPath); + loadCall = makeBatchCall(ctx, pixelsID, folderPath); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ChannelMetadataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ChannelMetadataLoader.java index 08f44a282fb..37ff7991666 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ChannelMetadataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ChannelMetadataLoader.java @@ -34,6 +34,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; @@ -67,22 +68,25 @@ public class ChannelMetadataLoader /** * Creates a {@link BatchCall} to retrieve the channels metadata. * + * @param ctx The security context. * @param pixelsID The ID of the pixels set. * @param userID If the id is specified i.e. not -1, * load the color associated to the channel, * false otherwise. * @return The {@link BatchCall}. */ - private BatchCall makeBatchCall(final long pixelsID, final long userID) + private BatchCall makeBatchCall(final SecurityContext ctx, + final long pixelsID, final long userID) { return new BatchCall("Loading channel Metadata: ") { public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - List l = os.getChannelsMetadata(pixelsID); + List l = os.getChannelsMetadata(ctx, pixelsID); if (userID >= 0) { //load the rendering settings. OmeroImageService svc = context.getImageService(); - List rnd = svc.getRenderingSettingsFor(pixelsID, userID); + List rnd = svc.getRenderingSettingsFor(ctx, + pixelsID, userID); Map channels = new HashMap(); Iterator i = l.iterator(); if (rnd != null && rnd.size() > 0) { @@ -121,16 +125,18 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * + * @param ctx The security context. * @param pixelsID The Id of the pixels set. - * @param userID If the id is specified i.e. not -1, - * load the color associated to the channel, - * false otherwise. + * @param userID If the id is specified i.e. not -1, + * load the color associated to the channel, + * false otherwise. */ - public ChannelMetadataLoader(long pixelsID, long userID) + public ChannelMetadataLoader(SecurityContext ctx, long pixelsID, + long userID) { if (pixelsID < 0) throw new IllegalArgumentException("Pixels ID not valid."); - loadCall = makeBatchCall(pixelsID, userID); + loadCall = makeBatchCall(ctx, pixelsID, userID); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ContainerCounterLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ContainerCounterLoader.java index 90dada937b8..ea15b1f9546 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ContainerCounterLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ContainerCounterLoader.java @@ -39,6 +39,7 @@ import org.openmicroscopy.shoola.env.data.AdminService; import org.openmicroscopy.shoola.env.data.OmeroDataService; import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DataObject; @@ -75,11 +76,13 @@ public class ContainerCounterLoader * Creates a {@link BatchCall} to retrieve the number of items per * container. * + * @param ctx The security context. * @param types A Map whose keys are the type of object and the values are * the identifiers of the objects. * @return See above */ - private BatchCall makeBatchCall(final Map> types) + private BatchCall makeBatchCall(final SecurityContext ctx, + final Map> types) { return new BatchCall("Counting items.") { @@ -97,7 +100,8 @@ public void doCall() throws Exception LookupNames.CURRENT_USER_DETAILS); long userID = exp.getId(); Map m = new HashMap(); - Map> count = new HashMap>(); + Map> count = new HashMap>(); while (i.hasNext()) { entry = (Entry) i.next(); type = (Class) entry.getKey(); @@ -107,15 +111,16 @@ public void doCall() throws Exception while (j.hasNext()) { id = j.next(); m.put(id, Long.valueOf( - ms.loadROIMeasurements( + ms.loadROIMeasurements(ctx, type, id, userID).size())); } result = m; } else if (GroupData.class.equals(type)) { AdminService svc = context.getAdminService(); - result = count.put(type, svc.countExperimenters(ids)); + result = count.put(type, svc.countExperimenters(ctx, + ids)); } else { - count.put(type, os.getCollectionCount(type, + count.put(type, os.getCollectionCount(ctx, type, OmeroDataService.IMAGES_PROPERTY, ids)); } } @@ -143,9 +148,10 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * + * @param ctx The security context. * @param rootIDs Collection of root ids. Mustn't be null. */ - public ContainerCounterLoader(Set rootIDs) + public ContainerCounterLoader(SecurityContext ctx, Set rootIDs) { if (rootIDs == null) throw new NullPointerException("No root nodes."); Iterator i = rootIDs.iterator(); @@ -174,7 +180,7 @@ public ContainerCounterLoader(Set rootIDs) ids = types.get(rootType); if (id != null) ids.add(id); } - loadCall = makeBatchCall(types); + loadCall = makeBatchCall(ctx, types); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DMLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DMLoader.java index e46acaac093..d7d0aebac71 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DMLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DMLoader.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DatasetData; @@ -58,10 +59,13 @@ public class DMLoader { /** The results of the call. */ - private Set results; + private Set results; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to retrieve a Container tree, either @@ -84,7 +88,7 @@ private BatchCall makeBatchCall(final Class rootNodeType, public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - results = os.loadContainerHierarchy(rootNodeType, + results = os.loadContainerHierarchy(ctx, rootNodeType, rootNodeIDs, withLeaves, userID, groupID); } }; @@ -103,7 +107,7 @@ private BatchCall makeBatchCall(final long userID, final long groupID) public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - results = os.loadContainerHierarchy(ProjectData.class, + results = os.loadContainerHierarchy(ctx, ProjectData.class, null, false, userID, groupID); } }; @@ -126,6 +130,7 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * + * @param ctx The security context. * @param rootNodeType The type of the root node. Can only be one out of: * {@link ProjectData}, {@link DatasetData}. * @param rootNodeIDs A set of the IDs of top-most containers. Passed @@ -136,11 +141,12 @@ public void doCall() throws Exception * @param userID The identifier of the user. * @param groupID The identifier of the user's group. */ - public DMLoader(Class rootNodeType, List rootNodeIDs, - boolean withLeaves, long userID, long groupID) + public DMLoader(SecurityContext ctx, Class rootNodeType, + List rootNodeIDs, boolean withLeaves, long userID, long groupID) { if (userID < 0) throw new IllegalArgumentException("No root ID not valid."); + this.ctx = ctx; if (rootNodeType == null) { loadCall = makeBatchCall(userID, groupID); } else if (ProjectData.class.equals(rootNodeType) || diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DMRefreshLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DMRefreshLoader.java index b1e0f7df4a8..6155dee5bc8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DMRefreshLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DMRefreshLoader.java @@ -45,6 +45,7 @@ import org.openmicroscopy.shoola.env.data.OmeroDataService; import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DataObject; @@ -75,10 +76,10 @@ public class DMRefreshLoader { /** The results of the call. */ - private Object results; + private Object results; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; /** * Retrieve the data. @@ -88,8 +89,8 @@ public class DMRefreshLoader * @param mapResult Map hosting the results. * @throws Exception Thrown if an error occurred. */ - private void retrieveData(Class rootNodeType, Map nodes, - Map mapResult) + private void retrieveData(Class rootNodeType, + Map nodes, Map mapResult) throws Exception { OmeroDataService os = context.getDataService(); @@ -109,21 +110,23 @@ private void retrieveData(Class rootNodeType, Map nodes, DataObject child, parent; Set s; Entry entry; + SecurityContext ctx; while (users.hasNext()) { entry = (Entry) users.next(); - userID = (Long) entry.getKey(); + ctx = (SecurityContext) entry.getKey(); + userID = ctx.getExperimenter(); containers = (List) entry.getValue(); if (containers == null || containers.size() == 0) { - result = os.loadContainerHierarchy(rootNodeType, null, - false, userID, groupID); - if (mapResult.containsKey(userID)) { + result = os.loadContainerHierarchy(ctx, rootNodeType, null, + false, ctx.getExperimenter(), groupID); + if (mapResult.containsKey(ctx)) { s = (Set) mapResult.get(userID); s.addAll((Set) result); } else { - mapResult.put(userID, result); + mapResult.put(ctx, result); } } else { - set = os.loadContainerHierarchy(rootNodeType, null, + set = os.loadContainerHierarchy(ctx, rootNodeType, null, false, userID, groupID); i = containers.iterator(); ids = new ArrayList(containers.size()); @@ -157,7 +160,7 @@ private void retrieveData(Class rootNodeType, Map nodes, child = (DataObject) c.next(); id = Long.valueOf(child.getId()); if (ids.contains(id)) { - r = os.loadContainerHierarchy(klass, + r = os.loadContainerHierarchy(ctx, klass, Arrays.asList(id), true, userID, groupID); k = r.iterator(); @@ -169,10 +172,10 @@ private void retrieveData(Class rootNodeType, Map nodes, } } result = topNodes; - if (mapResult.containsKey(userID)) { + if (mapResult.containsKey(ctx)) { Map map = (Map) mapResult.get(userID); map.putAll((Map) result); - } else mapResult.put(userID, result); + } else mapResult.put(ctx, result); } } } @@ -187,12 +190,13 @@ private void retrieveData(Class rootNodeType, Map nodes, * @return The {@link BatchCall}. */ private BatchCall makeBatchCall(final Class rootNodeType, - final Map nodes) + final Map nodes) { return new BatchCall("Loading container tree: ") { public void doCall() throws Exception { - Map r = new HashMap(nodes.size()); + Map r = + new HashMap(nodes.size()); results = r; //retrieveData(ProjectData.class, nodes); retrieveData(rootNodeType, nodes, r); @@ -203,11 +207,11 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to retrieve the images. * - * @param nodes The map whose keys are the id of user and the values + * @param nodes The map whose keys are the security context and the values * are the corresponding collections of data objects to reload. * @return The {@link BatchCall}. */ - private BatchCall makeImagesBatchCall(final Map nodes) + private BatchCall makeImagesBatchCall(final Map nodes) { return new BatchCall("Loading images: ") { public void doCall() throws Exception @@ -219,15 +223,18 @@ public void doCall() throws Exception Iterator j ; TimeRefObject ref; Entry entry; + SecurityContext ctx; while (i.hasNext()) { entry = (Entry) i.next(); - userID = (Long) entry.getKey(); + ctx = (SecurityContext) entry.getKey(); + userID = ctx.getExperimenter(); containers = (List) entry.getValue(); j = containers.iterator(); while (j.hasNext()) { ref = (TimeRefObject) j.next(); - ref.setResults(os.getImagesPeriod(ref.getStartTime(), - ref.getEndTime(), userID, true)); + ref.setResults(os.getImagesPeriod(ctx, + ref.getStartTime(), ref.getEndTime(), userID, + true)); } } results = nodes; @@ -238,15 +245,16 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to retrieve the groups. * - * @param nodes The map whose keys are the id of user and the values - * are the corresponding collections of data objects to reload. + * @param nodes The map whose keys are the security context and the values + * are the corresponding collections of data objects to reload. * @return The {@link BatchCall}. */ - private BatchCall makeGroupsBatchCall(final Map nodes) + private BatchCall makeGroupsBatchCall(final Map nodes) { return new BatchCall("Loading groups: ") { public void doCall() throws Exception { + /* TODO, move that outside. AdminService svc = context.getAdminService(); Entry entry; Iterator i = nodes.entrySet().iterator(); @@ -256,18 +264,20 @@ public void doCall() throws Exception Boolean admin = (Boolean) context.lookup(LookupNames.USER_ADMINISTRATOR); if (admin != null && admin.booleanValue()) { - List groups = svc.loadGroups(-1); + List groups = svc.loadGroups(ctx, -1); List r = new ArrayList(); List toRemove = new ArrayList(); List l; List list; + SecurityContext ctx; while (i.hasNext()) { entry = (Entry) i.next(); + ctx = (SecurityContext) entry.getKey(); list = (List) entry.getValue(); j = list.iterator(); while (j.hasNext()) { groupID = (Long) j.next(); - l = svc.loadGroups(groupID); + l = svc.loadGroups(ctx, groupID); toRemove.add(groupID); if (l.size() == 1) r.add(l.get(0)); } @@ -284,7 +294,7 @@ public void doCall() throws Exception ExperimenterData exp = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); - List groups = svc.reloadPIGroups(exp); + List groups = svc.reloadPIGroups(ctx, exp); Iterator g = groups.iterator(); GroupData gd; List toKeep = new ArrayList(); @@ -306,6 +316,7 @@ public void doCall() throws Exception } results = toKeep; } + */ } }; } @@ -313,30 +324,36 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to retrieve the files. * - * @param nodes The map whose keys are the id of user and the values - * are the corresponding collections of data objects to reload. + * @param nodes The map whose keys are the security context and the values + * are the corresponding collections of data objects to reload. * @return The {@link BatchCall}. */ - private BatchCall makeFilesBatchCall(final Map nodes) + private BatchCall makeFilesBatchCall(final Map nodes) { return new BatchCall("Loading files: ") { public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - Iterator users = nodes.keySet().iterator(); + //Iterator users = nodes.keySet().iterator(); long userID; List containers; Iterator j ; TimeRefObject ref; - while (users.hasNext()) { - userID = (Long) users.next(); - containers = nodes.get(userID); - j = containers.iterator(); + Entry entry; + SecurityContext ctx; + Iterator i = nodes.entrySet().iterator(); + while (i.hasNext()) { + entry = (Entry) i.next(); + ctx = (SecurityContext) entry.getKey(); + userID = ctx.getExperimenter(); + containers = (List) entry.getValue(); + j = containers.iterator(); while (j.hasNext()) { ref = (TimeRefObject) j.next(); - ref.setResults(os.loadFiles(ref.getFileType(), userID)); + ref.setResults(os.loadFiles(ctx, ref.getFileType(), + userID)); } - } + } results = nodes; } }; @@ -345,17 +362,18 @@ public void doCall() throws Exception /** * Creates a {@link BatchCall} to retrieve the files. * - * @param nodes The map whose keys are the id of user and the values - * are the corresponding collections of data objects to reload. + * @param nodes The map whose keys are the security context and the values + * are the corresponding collections of data objects to reload. * @return The {@link BatchCall}. */ - private BatchCall makeTagsBatchCall(final Map nodes) + private BatchCall makeTagsBatchCall(final Map nodes) { return new BatchCall("Loading files: ") { public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - Map r = new HashMap(nodes.size()); + Map r = + new HashMap(nodes.size()); long userID; Object result; Entry entry; @@ -368,15 +386,17 @@ public void doCall() throws Exception Map values; String ns; Set set; + SecurityContext ctx; while (j.hasNext()) { entry = (Entry) j.next(); - userID = (Long) entry.getKey(); + ctx = (SecurityContext) entry.getKey(); + userID = ctx.getExperimenter(); l = (List) entry.getValue(); - tags = os.loadTags(-1L, false, true, userID, -1); + tags = os.loadTags(ctx, -1L, false, true, userID, -1); List tagResults = new ArrayList(); if (l == null || l.size() == 0) { - r.put(userID, tags); + r.put(ctx, tags); } else { values = new HashMap(); k = l.iterator(); @@ -386,12 +406,12 @@ public void doCall() throws Exception ob = k.next(); if (ob instanceof TagAnnotationData) { tag = (TagAnnotationData) ob; - values.put(tag.getId(), os.loadTags(tag.getId(), - true, false, userID, -1)); + values.put(tag.getId(), os.loadTags(ctx, + tag.getId(), true, false, userID, -1)); } else { ref = (TimeRefObject) ob; - ref.setResults(os.loadFiles(ref.getFileType(), - userID)); + ref.setResults(os.loadFiles(ctx, + ref.getFileType(), userID)); tagResults.add(ref); } } @@ -419,7 +439,7 @@ public void doCall() throws Exception tag.getId())); } } - r.put(userID, tagResults); + r.put(ctx, tagResults); } } results = r; @@ -444,12 +464,13 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * - * @param rootNodeType The type of the root node. - * @param nodes The map whose keys are the id of user + * @param rootNodeType The type of the root node. + * @param nodes The map whose keys are the security context * and the values are the corresponding collections of * data objects to reload. */ - public DMRefreshLoader(Class rootNodeType, Map nodes) + public DMRefreshLoader(Class rootNodeType, + Map nodes) { if (rootNodeType == null) throw new IllegalArgumentException("No root node type."); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataFilter.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataFilter.java index 54475572807..ccdb21f450a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataFilter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataFilter.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.util.FilterContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -59,7 +60,9 @@ public class DataFilter /** Loads the specified experimenter groups. */ private BatchCall loadCall; - + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to load the ratings related to the object * identified by the class and the id. @@ -73,15 +76,15 @@ public class DataFilter * @return The {@link BatchCall}. */ private BatchCall filterBy(final Class annotationType, final Class nodeType, - final List ids, final boolean annotated, + final List ids, final boolean annotated, final long userID) { return new BatchCall("Filtering annotated data") { public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.filterByAnnotated(nodeType, ids, annotationType, - annotated, userID); + result = os.filterByAnnotated(ctx, nodeType, ids, + annotationType, annotated, userID); } }; } @@ -98,7 +101,7 @@ public void doCall() throws Exception * -1 if the user is not specified. * @return The {@link BatchCall}. */ - private BatchCall filterBy(final Class annotationType, final Class nodeType, + private BatchCall filterBy(final Class annotationType, final Class nodeType, final List ids, final List terms, final long userID) { @@ -106,8 +109,8 @@ private BatchCall filterBy(final Class annotationType, final Class nodeType, public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.filterByAnnotation(nodeType, ids, annotationType, - terms, userID); + result = os.filterByAnnotation(ctx, nodeType, ids, + annotationType, terms, userID); } }; } @@ -130,7 +133,8 @@ private BatchCall filterBy(final Class nodeType, final List ids, public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.filterByAnnotation(nodeType, ids, filter, userID); + result = os.filterByAnnotation(ctx, + nodeType, ids, filter, userID); } }; } @@ -152,21 +156,23 @@ public void doCall() throws Exception * index, throws an {@link IllegalArgumentException} if the index is not * supported. * - * @param annotationType The type of annotations to fetch. - * @param nodeType The type of objects to filter. - * @param nodeIds The collection of object ids. - * @param annotated Pass true to retrieve the - * annotated nodes, false otherwise. - * @param userID The id of the user or -1 if the id - * is not specified. + * @param ctx The security context. + * @param annotationType The type of annotations to fetch. + * @param nodeType The type of objects to filter. + * @param nodeIds The collection of object ids. + * @param annotated Pass true to retrieve the + * annotated nodes, false otherwise. + * @param userID The id of the user or -1 if the id + * is not specified. */ - public DataFilter(Class annotationType, Class nodeType, List nodeIds, - boolean annotated, long userID) + public DataFilter(SecurityContext ctx, Class annotationType, + Class nodeType, List nodeIds, boolean annotated, long userID) { if (annotationType == null) throw new IllegalArgumentException("Annotation type not valid."); if (nodeType == null) throw new IllegalArgumentException("Node type not valid."); + this.ctx = ctx; loadCall = filterBy(annotationType, nodeType, nodeIds, annotated, userID); } @@ -176,20 +182,22 @@ public DataFilter(Class annotationType, Class nodeType, List nodeIds, * index, throws an {@link IllegalArgumentException} if the index is not * supported. * - * @param annotationType The type of annotations to fetch. - * @param nodeType The type of objects to filter. - * @param nodeIds The collection of object ids. - * @param terms The collection of terms. - * @param userID The id of the user or -1 if the id - * is not specified. + * @param ctx The security context. + * @param annotationType The type of annotations to fetch. + * @param nodeType The type of objects to filter. + * @param nodeIds The collection of object ids. + * @param terms The collection of terms. + * @param userID The id of the user or -1 if the id + * is not specified. */ - public DataFilter(Class annotationType, Class nodeType, List nodeIds, - List terms, long userID) + public DataFilter(SecurityContext ctx, Class annotationType, Class nodeType, + List nodeIds, List terms, long userID) { if (annotationType == null) throw new IllegalArgumentException("Annotation type not valid."); if (nodeType == null) throw new IllegalArgumentException("Node type not valid."); + this.ctx = ctx; loadCall = filterBy(annotationType, nodeType, nodeIds, terms, userID); } @@ -198,17 +206,19 @@ public DataFilter(Class annotationType, Class nodeType, List nodeIds, * index, throws an {@link IllegalArgumentException} if the index is not * supported. * + * @param ctx The security context. * @param nodeType The type of objects to filter. * @param nodeIds The collection of object ids. * @param context The filtering context. * @param userID The id of the user or -1 if the id * is not specified. */ - public DataFilter(Class nodeType, List nodeIds, FilterContext context, - long userID) + public DataFilter(SecurityContext ctx, Class nodeType, List nodeIds, + FilterContext context, long userID) { if (nodeType == null) throw new IllegalArgumentException("Node type not valid."); + this.ctx = ctx; loadCall = filterBy(nodeType, nodeIds, context, userID); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectRemover.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectRemover.java index cc1addca039..aeed7754aeb 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectRemover.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectRemover.java @@ -24,9 +24,10 @@ //Java imports -import java.util.ArrayList; import java.util.Collection; -import java.util.List; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; //Third-party libraries @@ -34,6 +35,7 @@ import org.openmicroscopy.shoola.env.data.DeleteCallback; import org.openmicroscopy.shoola.env.data.OmeroDataService; import org.openmicroscopy.shoola.env.data.model.DeletableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.data.views.ProcessBatchCall; @@ -56,25 +58,27 @@ public class DataObjectRemover extends BatchCallTree { - /** The call. */ - private BatchCall call; - /** The server call-handle to the computation. */ private Object callBack; + + /** The objects to delete.*/ + private Map> map; /** * Creates a {@link BatchCall} to delete the specified objects. * + * @param ctx The security context. * @param values The objects to delete. * @return The {@link BatchCall}. */ - private BatchCall makeDeleteCall(final Collection values) + private BatchCall makeDeleteCall(final SecurityContext ctx, + final Collection values) { return new ProcessBatchCall("Delete the Objects") { public ProcessCallback initialize() throws Exception { OmeroDataService os = context.getDataService(); - DeleteCallback cb = os.delete(values); + DeleteCallback cb = os.delete(ctx, values); if (cb == null) { callBack = Boolean.valueOf(false); return null; @@ -90,7 +94,18 @@ public ProcessCallback initialize() throws Exception * Adds the {@link #call} to the computation tree. * @see BatchCallTree#buildTree() */ - protected void buildTree() { add(call); } + protected void buildTree() + { + Entry entry; + Iterator i = map.entrySet().iterator(); + while (i.hasNext()) { + entry = (Entry) i.next(); + final Collection l = + (Collection) entry.getValue(); + final SecurityContext ctx = (SecurityContext) entry.getKey(); + add(makeDeleteCall(ctx, l)); + } + } /** * Returns the server call-handle to the computation. @@ -112,27 +127,13 @@ public ProcessCallback initialize() throws Exception * * @param values The collection of object to delete. */ - public DataObjectRemover(Collection values) - { - if (values == null) - throw new IllegalArgumentException("No objects to remove."); - call = makeDeleteCall(values); - } - - /** - * Creates a new instance. - * If bad arguments are passed, we throw a runtime - * exception so to fail early and in the caller's thread. - * - * @param value The object to delete. - */ - public DataObjectRemover(DeletableObject value) + public DataObjectRemover(Map> + values) { - if (value == null) - throw new IllegalArgumentException("No object to remove."); - List l = new ArrayList(1); - l.add(value); - call = makeDeleteCall(l); + if (values == null) + throw new IllegalArgumentException("No objects to remove."); + this.map = values; + //call = makeDeleteCall(ctx, values); } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectSaver.java index db474ca02b6..88fd06cc1c1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectSaver.java @@ -34,6 +34,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DataObject; @@ -60,10 +61,13 @@ public class DataObjectSaver public static final int UPDATE = 1; /** The save call. */ - private BatchCall saveCall; + private BatchCall saveCall; /** The result of the call. */ - private Object result; + private Object result; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to create the specified {@link DataObject}s. @@ -73,9 +77,8 @@ public class DataObjectSaver * @param children The children to add to the newly created node. * @return The {@link BatchCall}. */ - private BatchCall create(final List objects, - final DataObject parent, - final Collection children) + private BatchCall create(final List objects, + final DataObject parent, final Collection children) { return new BatchCall("Create Data object.") { public void doCall() throws Exception @@ -84,7 +87,7 @@ public void doCall() throws Exception List l = new ArrayList(); Iterator i = objects.iterator(); while (i.hasNext()) { - l.add(os.createDataObject(i.next(), parent, children)); + l.add(os.createDataObject(ctx, i.next(), parent, children)); } result = l; } @@ -106,7 +109,7 @@ public void doCall() throws Exception List l = new ArrayList(); Iterator i = objects.iterator(); while (i.hasNext()) { - l.add(os.updateDataObject(i.next())); + l.add(os.updateDataObject(ctx, i.next())); } result = l; } @@ -130,6 +133,7 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * + * @param ctx The security context. * @param userObject The {@link DataObject} to create or update. * Mustn't be null. * @param parent The parent of the DataObject. @@ -137,12 +141,14 @@ public void doCall() throws Exception * is no parent. * @param index One of the constants defined by this class. */ - public DataObjectSaver(DataObject userObject, DataObject parent, int index) + public DataObjectSaver(SecurityContext ctx, DataObject userObject, + DataObject parent, int index) { if (userObject == null) throw new IllegalArgumentException("No DataObject."); List objects = new ArrayList(); objects.add(userObject); + this.ctx = ctx; switch (index) { case CREATE: saveCall = create(objects, parent, null); @@ -160,6 +166,7 @@ public DataObjectSaver(DataObject userObject, DataObject parent, int index) * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * + * @param ctx The security context. * @param objects The {@link DataObject}s to create or update. * Mustn't be null. * @param parent The parent of the DataObject. @@ -167,11 +174,12 @@ public DataObjectSaver(DataObject userObject, DataObject parent, int index) * is no parent. * @param index One of the constants defined by this class. */ - public DataObjectSaver(List objects, DataObject parent, - int index) + public DataObjectSaver(SecurityContext ctx, + List objects, DataObject parent, int index) { if (objects == null) throw new IllegalArgumentException("No DataObject."); + this.ctx = ctx; switch (index) { case CREATE: saveCall = create(objects, parent, null); @@ -189,19 +197,21 @@ public DataObjectSaver(List objects, DataObject parent, * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * + * @param ctx The security context. * @param parent The parent of the DataObject to create * or null if no parent specified. * @param data The DataObject to create. * @param children The nodes to add to the newly created * DataObject. */ - public DataObjectSaver(DataObject parent, DataObject data, - Collection children) + public DataObjectSaver(SecurityContext ctx, + DataObject parent, DataObject data, Collection children) { if (data == null) throw new IllegalArgumentException("No object to create."); - List objects = new ArrayList(); - objects.add(data); + this.ctx = ctx; + List objects = new ArrayList(); + objects.add(data); saveCall = create(objects, parent, children); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectTransfer.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectTransfer.java new file mode 100644 index 00000000000..2d75f5a254c --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/DataObjectTransfer.java @@ -0,0 +1,141 @@ +/* + * org.openmicroscopy.shoola.env.data.views.calls.DataObjectTransfer + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.env.data.views.calls; + + +//Java imports +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.RequestCallback; +import org.openmicroscopy.shoola.env.data.model.TransferableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; +import org.openmicroscopy.shoola.env.data.views.BatchCall; +import org.openmicroscopy.shoola.env.data.views.BatchCallTree; +import org.openmicroscopy.shoola.env.data.views.ProcessBatchCall; +import org.openmicroscopy.shoola.env.data.views.ProcessCallback; +import pojos.DataObject; + +/** + * Command to move between groups the passed objects. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class DataObjectTransfer extends BatchCallTree +{ + + /** The server call-handle to the computation. */ + private Object callBack; + + /** The object to transfer.*/ + private TransferableObject value; + + /** + * Creates a {@link BatchCall} to transfer the specified objects. + * + * @param ctx The security context. + * @param value The objects to transfer. + * @return The {@link BatchCall}. + */ + private BatchCall makeTransferCall(final SecurityContext ctx, + final List values) + { + return new ProcessBatchCall("Transfer objects") { + public ProcessCallback initialize() throws Exception + { + OmeroDataService os = context.getDataService(); + RequestCallback cb = os.transfer(ctx, value.getTargetContext(), + value.getTarget(), values); + if (cb == null) { + callBack = Boolean.valueOf(false); + return null; + } else { + callBack = new ProcessCallback(cb); + return (ProcessCallback) callBack; + } + } + }; + } + + /** + * Adds the {@link #call} to the computation tree. + * @see BatchCallTree#buildTree() + */ + protected void buildTree() + { + Entry entry; + Map> map = value.getSource(); + Iterator i = map.entrySet().iterator(); + while (i.hasNext()) { + entry = (Entry) i.next(); + final List l = (List) entry.getValue(); + final SecurityContext ctx = (SecurityContext) entry.getKey(); + + //add(makeTransferCall(ctx, l)); + //TODO: remove when 'doAll' is implemented. + Iterator j = l.iterator(); + while (j.hasNext()) { + final List ll = Arrays.asList(j.next()); + add(makeTransferCall(ctx, ll)); + } + } + } + + /** + * Returns the server call-handle to the computation. + * + * @return See above. + */ + protected Object getPartialResult() { return callBack; } + + /** + * Returns the result. + * @see BatchCallTree#getResult() + */ + protected Object getResult() { return Boolean.valueOf(true); } + + /** + * Creates a new instance. + * If bad arguments are passed, we throw a runtime + * exception so to fail early and in the caller's thread. + * + * @param valus The collection of object to transfer. + */ + public DataObjectTransfer(TransferableObject value) + { + if (value == null) + throw new IllegalArgumentException("No objects to move."); + this.value = value; + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/EnumerationLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/EnumerationLoader.java index f37f6314f74..70e694e86d7 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/EnumerationLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/EnumerationLoader.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroMetadataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -66,6 +67,9 @@ public class EnumerationLoader /** Loads the specified tree. */ private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to enumerations related to the image * metadata. @@ -79,13 +83,17 @@ public void doCall() throws Exception { OmeroMetadataService service = context.getMetadataService(); results.put(OmeroMetadataService.IMMERSION, - service.getEnumeration(OmeroMetadataService.IMMERSION)); + service.getEnumeration(ctx, + OmeroMetadataService.IMMERSION)); results.put(OmeroMetadataService.CORRECTION, - service.getEnumeration(OmeroMetadataService.CORRECTION)); + service.getEnumeration(ctx, + OmeroMetadataService.CORRECTION)); results.put(OmeroMetadataService.MEDIUM, - service.getEnumeration(OmeroMetadataService.MEDIUM)); + service.getEnumeration(ctx, + OmeroMetadataService.MEDIUM)); results.put(OmeroMetadataService.FORMAT, - service.getEnumeration(OmeroMetadataService.FORMAT)); + service.getEnumeration(ctx, + OmeroMetadataService.FORMAT)); } }; } @@ -103,39 +111,40 @@ public void doCall() throws Exception { OmeroMetadataService service = context.getMetadataService(); results.put(OmeroMetadataService.ILLUMINATION_TYPE, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.ILLUMINATION_TYPE)); results.put(OmeroMetadataService.CONTRAST_METHOD, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.CONTRAST_METHOD)); results.put(OmeroMetadataService.ACQUISITION_MODE, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.ACQUISITION_MODE)); results.put(OmeroMetadataService.BINNING, - service.getEnumeration(OmeroMetadataService.BINNING)); + service.getEnumeration(ctx, + OmeroMetadataService.BINNING)); results.put(OmeroMetadataService.DETECTOR_TYPE, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.DETECTOR_TYPE)); results.put(OmeroMetadataService.LASER_MEDIUM, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.LASER_MEDIUM)); results.put(OmeroMetadataService.LASER_TYPE, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.LASER_TYPE)); results.put(OmeroMetadataService.LASER_PULSE, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.LASER_PULSE)); results.put(OmeroMetadataService.ARC_TYPE, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.ARC_TYPE)); results.put(OmeroMetadataService.FILAMENT_TYPE, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.FILAMENT_TYPE)); results.put(OmeroMetadataService.FILTER_TYPE, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.FILTER_TYPE)); results.put(OmeroMetadataService.MICROSCOPE_TYPE, - service.getEnumeration( + service.getEnumeration(ctx, OmeroMetadataService.MICROSCOPE_TYPE)); } }; @@ -160,13 +169,15 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * + * @param ctx The security context * @param index One of the constants defined by this class. */ - public EnumerationLoader(int index) + public EnumerationLoader(SecurityContext ctx, int index) { results = new HashMap(); + this.ctx = ctx; if (index == IMAGE) loadCall = makeBatchCallForImage(); else loadCall = makeBatchCallForChannel(); - } + } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExistingObjectsSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExistingObjectsSaver.java index 23e272170a1..6499039d0ee 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExistingObjectsSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExistingObjectsSaver.java @@ -36,6 +36,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.AdminService; import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DataObject; @@ -59,11 +60,14 @@ public class ExistingObjectsSaver { /** Loads the specified tree. */ - private BatchCall call; + private BatchCall call; + + /** The result of the save action. */ + private Object result; + /** The security context.*/ + private SecurityContext ctx; - /** The result of the save action. */ - private Object result; /** * Creates a {@link BatchCall} to add the given children to the @@ -88,7 +92,7 @@ public void doCall() throws Exception while (i.hasNext()) { obj = i.next(); if (obj instanceof DataObject) { - os.addExistingObjects((DataObject) obj, children); + os.addExistingObjects(ctx, (DataObject) obj, children); } } @@ -118,12 +122,12 @@ public void doCall() throws Exception entry = (Entry) i.next(); p = entry.getKey(); if (p instanceof GroupData) { - as.copyExperimenters((GroupData) p, (Collection) + as.copyExperimenters(ctx, (GroupData) p, (Collection) entry.getValue()); } else { if (p instanceof DataObject) { - os.addExistingObjects((DataObject) p, (Collection) - entry.getValue()); + os.addExistingObjects(ctx, + (DataObject) p, (Collection) entry.getValue()); } } @@ -151,11 +155,11 @@ public void doCall() throws Exception { if (admin) { AdminService as = context.getAdminService(); - as.cutAndPasteExperimenters(toPaste, toRemove); + as.cutAndPasteExperimenters(ctx, toPaste, toRemove); result = toPaste; } else { OmeroDataService os = context.getDataService(); - os.cutAndPaste(toPaste, toRemove); + os.cutAndPaste(ctx, toPaste, toRemove); result = toPaste; } @@ -182,35 +186,19 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * + * @param ctx The security context. * @param parent The DataObject to update. Either a * ProjectData or DatasetData. * @param children The items to add. */ - public ExistingObjectsSaver(Collection parent, Collection children, - boolean admin) + public ExistingObjectsSaver(SecurityContext ctx, Collection parent, + Collection children, boolean admin) { if (children == null || children.size() == 0) throw new IllegalArgumentException("No item to add."); if (parent == null) throw new IllegalArgumentException("No parent to update."); - /* - if (parent instanceof ProjectData) { - try { - children.toArray(new DatasetData[] {}); - } catch (ArrayStoreException ase) { - throw new IllegalArgumentException( - "items can only be datasets."); - } - } else if (parent instanceof DatasetData) { - try { - children.toArray(new ImageData[] {}); - } catch (ArrayStoreException ase) { - throw new IllegalArgumentException( - "items can only be images."); - } - } else - throw new IllegalArgumentException("parent object not supported"); - */ + this.ctx = ctx; call = makeBatchCall(parent, children, admin); } @@ -219,13 +207,16 @@ public ExistingObjectsSaver(Collection parent, Collection children, * If bad arguments are passed, we throw a runtime * exception so to fail early and in the caller's thread. * + * @param ctx The security context. * @param toPaste The DataObjects to update. * @param toRemove The DataObjects to cut. * @param admin Pass true to indicate to handle * experimenters, false otherwise. */ - public ExistingObjectsSaver(Map toPaste, Map toRemove, boolean admin) + public ExistingObjectsSaver(SecurityContext ctx, Map toPaste, Map toRemove, + boolean admin) { + this.ctx = ctx; if (toPaste == null) toPaste = new HashMap(); if (toRemove == null) call = makeBatchCall(toPaste); else call = makeBatchCall(toPaste, toRemove, admin); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExperimenterImagesCounter.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExperimenterImagesCounter.java index f2cf7c18ed9..e04a849b888 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExperimenterImagesCounter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExperimenterImagesCounter.java @@ -37,6 +37,7 @@ import org.openmicroscopy.shoola.env.data.OmeroDataService; import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.log.LogMessage; @@ -60,20 +61,23 @@ public class ExperimenterImagesCounter { /** The id of the user the count is for. */ - private long userID; + private long userID; /** The lastly retrieved count along side the index. */ - private Map result; + private Map result; /** The nodes to handle. */ private Map nodes; /** Helper reference to the data service. */ - private OmeroDataService os; + private OmeroDataService os; /** Helper reference to the metadata service. */ - private OmeroMetadataService ms; + private OmeroMetadataService ms; + /** The security context.*/ + private SecurityContext ctx; + /** * Counts the number of images imported during a given period of time. * @@ -88,11 +92,11 @@ private void countTimeItems(Integer index, Timestamp start, Timestamp end) Collection l; result = new HashMap(1); if (start == null || end == null) { - l = os.getImagesPeriod(start, end, userID, false); + l = os.getImagesPeriod(ctx, start, end, userID, false); if (l != null) number = l.size(); result.put(index, number); } else { - l = os.getImagesAllPeriodCount(start, end, userID); + l = os.getImagesAllPeriodCount(ctx, start, end, userID); result.put(index, l); } } catch (Exception e) { @@ -114,7 +118,7 @@ private void countFileItems(Integer index, int type) { try { result = new HashMap(); - result.put(index, ms.countFileType(userID, type)); + result.put(index, ms.countFileType(ctx, userID, type)); } catch (Exception e) { LogMessage msg = new LogMessage(); msg.print("Cannot count the number of items imported during the " + @@ -180,14 +184,17 @@ protected void buildTree() /** * Creates a new instance. * - * @param userID The id of the user the count is for. - * @param m The elements to handle. + * @param ctx The security context. + * @param userID The id of the user the count is for. + * @param m The elements to handle. */ - public ExperimenterImagesCounter(long userID, Map m) + public ExperimenterImagesCounter(SecurityContext ctx, long userID, + Map m) { if (m == null || m.size() == 0) throw new IllegalArgumentException("No nodes specified."); this.userID = userID; + this.ctx = ctx; nodes = m; os = context.getDataService(); ms = context.getMetadataService(); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExportLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExportLoader.java index 0ffe137b214..ee5d129a706 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExportLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ExportLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -54,10 +55,13 @@ public class ExportLoader public static final int EXPORT_AS_OMETIFF = 0; /** Loads the specified annotations. */ - private BatchCall loadCall; + private BatchCall loadCall; /** The result of the call. */ - private Object result; + private Object result; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to export the image as XML. @@ -73,7 +77,7 @@ private BatchCall makeAsOMETiffBatchCall(final File file, public void doCall() throws Exception { OmeroImageService service = context.getImageService(); - result = service.exportImageAsOMETiff(imageID, file); + result = service.exportImageAsOMETiff(ctx, imageID, file); } }; } @@ -93,12 +97,14 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param imageID The id of the image to export. * @param file The file where to store the exported file. * @param index One of the constants defined by this class. */ - public ExportLoader(long imageID, File file, int index) + public ExportLoader(SecurityContext ctx, long imageID, File file, int index) { + this.ctx = ctx; switch (index) { case EXPORT_AS_OMETIFF: loadCall = makeAsOMETiffBatchCall(file, imageID); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FRAPAnalyser.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FRAPAnalyser.java deleted file mode 100644 index ce444679a7b..00000000000 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FRAPAnalyser.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * org.openmicroscopy.shoola.env.data.views.calls.FRAPAnalyser - * - *------------------------------------------------------------------------------ - * Copyright (C) 2006-2009 University of Dundee. All rights reserved. - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - *------------------------------------------------------------------------------ - */ -package org.openmicroscopy.shoola.env.data.views.calls; - - -//Java imports -import java.util.List; - -//Third-party libraries - -//Application-internal dependencies -import org.openmicroscopy.shoola.env.data.OmeroImageService; -import org.openmicroscopy.shoola.env.data.views.BatchCall; -import org.openmicroscopy.shoola.env.data.views.BatchCallTree; - -/** - * FRAP analysis. - * - * @author Jean-Marie Burel      - * j.burel@dundee.ac.uk - * @author Donald MacDonald      - * donald@lifesci.dundee.ac.uk - * @version 3.0 - * - * (Internal version: $Revision: $Date: $) - * - * @since 3.0-Beta4 - */ -public class FRAPAnalyser - extends BatchCallTree -{ - - /** The results of the call. */ - private Object results; - - /** Loads the specified tree. */ - private BatchCall loadCall; - - /** - * Creates a {@link BatchCall} to analyze the images. - * - * @param ids The objects to analyse. - * @param type The type of node to analyse. - * @param param The parameters. - * @return The {@link BatchCall}. - */ - private BatchCall makeBatchCall(final List ids, - final Class type, final Object param) - { - return new BatchCall("Loading user's images: ") { - public void doCall() throws Exception - { - OmeroImageService os = context.getImageService(); - results = os.analyseFrap(ids, type, param); - } - }; - } - - /** - * Adds the {@link #loadCall} to the computation tree. - * - * @see BatchCallTree#buildTree() - */ - protected void buildTree() { add(loadCall); } - - /** - * Returns the root node of the requested tree. - * - * @see BatchCallTree#getResult() - */ - protected Object getResult() { return results; } - - /** - * Creates a new instance. - * - * @param ids The objects to analyze. - * @param type The type of node to analyze. - * @param param The parameters. - */ - public FRAPAnalyser(List ids, Class type, Object param) - { - loadCall = makeBatchCall(ids, type, param); - } -} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FigureCreator.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FigureCreator.java index 7f18adb6d79..0f39a4a6a20 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FigureCreator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FigureCreator.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.ScriptCallback; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.data.views.ProcessCallback; @@ -60,6 +61,9 @@ public class FigureCreator /** The server call-handle to the computation. */ private Object callBack; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to create a movie. * @@ -75,7 +79,7 @@ private BatchCall makeBatchCall(final List ids, final Class type, public ProcessCallback initialize() throws Exception { OmeroImageService os = context.getImageService(); - ScriptCallback cb = os.createFigure(ids, type, param); + ScriptCallback cb = os.createFigure(ctx, ids, type, param); if (cb == null) { callBack = Boolean.valueOf(false); return null; @@ -111,12 +115,15 @@ public ProcessCallback initialize() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param ids The id of the objects. * @param type The type of objects to handle. * @param param The parameters used to generate the figure. */ - public FigureCreator(List imageIds, final Class type, Object param) + public FigureCreator(SecurityContext ctx, List imageIds, + Class type, Object param) { + this.ctx = ctx; loadCall = makeBatchCall(imageIds, type, param); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FilesLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FilesLoader.java index 1d3d73b2d0f..29c16b88160 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FilesLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/FilesLoader.java @@ -36,6 +36,7 @@ import omero.model.FileAnnotation; import omero.model.OriginalFile; import org.openmicroscopy.shoola.env.data.OmeroMetadataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -76,6 +77,9 @@ public class FilesLoader /** The files to load. */ private Map files; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to download a file previously loaded. * @@ -91,7 +95,7 @@ private BatchCall makeBatchCall(final File file, public void doCall() throws Exception { OmeroMetadataService service = context.getMetadataService(); - File f = service.downloadFile(file, fileID, size); + File f = service.downloadFile(ctx, file, fileID, size); result = f; } }; @@ -110,8 +114,8 @@ public void doCall() throws Exception { OmeroMetadataService service = context.getMetadataService(); FileAnnotationData fa = (FileAnnotationData) - service.loadAnnotation(id); - File f = service.downloadFile(new File(fa.getFileName()), + service.loadAnnotation(ctx, id); + File f = service.downloadFile(ctx, new File(fa.getFileName()), fa.getFileID(), fa.getFileSize()); result = f; @@ -132,10 +136,10 @@ public void doCall() throws Exception { OmeroMetadataService service = context.getMetadataService(); FileAnnotationData fa = (FileAnnotationData) - service.loadAnnotation(fileAnnotationID); + service.loadAnnotation(ctx, fileAnnotationID); Map m = new HashMap(); - File f = service.downloadFile(new File(fa.getFileName()), + File f = service.downloadFile(ctx, new File(fa.getFileName()), fa.getFileID(), fa.getFileSize()); m.put(fa, f); result = m; @@ -157,7 +161,7 @@ private void loadFile(final FileAnnotationData fa, final File f) OriginalFile of; of = ((FileAnnotation) fa.asAnnotation()).getFile(); try { - service.downloadFile(f, of.getId().getValue(), + service.downloadFile(ctx, f, of.getId().getValue(), of.getSize().getValue()); m.put(fa, f); currentFile = m; @@ -183,7 +187,7 @@ private BatchCall makeLoadFilesBatchCall(final int type, final long userID) public void doCall() throws Exception { OmeroMetadataService service = context.getMetadataService(); - result = service.loadFiles(type, userID); + result = service.loadFiles(ctx, type, userID); } }; } @@ -230,12 +234,14 @@ else if (files != null) { /** * Creates a new instance. * + * @param ctx The security context. * @param file The file where to write the data. * @param fileID The id of the file to download. * @param size The size of the file. */ - public FilesLoader(File file, long fileID, long size) + public FilesLoader(SecurityContext ctx, File file, long fileID, long size) { + this.ctx = ctx; if (file == null) loadCall = makeBatchCall(fileID); else loadCall = makeBatchCall(file, fileID, size); } @@ -243,12 +249,14 @@ public FilesLoader(File file, long fileID, long size) /** * Creates a new instance. * + * @param ctx The security context. * @param file The file where to write the data. * @param fileID The id of the file to download. * @param size The size of the file. */ - public FilesLoader(File file, long fileID, int index) + public FilesLoader(SecurityContext ctx, File file, long fileID, int index) { + this.ctx = ctx; if (file == null || index == FILE_ANNOTATION) loadCall = makeFileBatchCall(fileID); else loadCall = makeBatchCall(file, fileID, -1); @@ -257,10 +265,12 @@ public FilesLoader(File file, long fileID, int index) /** * Creates a new instance. * + * @param ctx The security context. * @param files The files to load. */ - public FilesLoader(Map files) + public FilesLoader(SecurityContext ctx, Map files) { + this.ctx = ctx; if (files == null) throw new IllegalArgumentException("No files to load."); this.files = files; @@ -269,11 +279,13 @@ public FilesLoader(Map files) /** * Creates a new instance. * + * @param ctx The security context. * @param type The type of files to load. * @param userID The id of the user. */ - public FilesLoader(int type, long userID) + public FilesLoader(SecurityContext ctx, int type, long userID) { + this.ctx = ctx; loadCall = makeLoadFilesBatchCall(type, userID); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/HierarchyLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/HierarchyLoader.java index ca41c54d0af..330869f53fe 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/HierarchyLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/HierarchyLoader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DatasetData; @@ -77,6 +78,9 @@ public class HierarchyLoader /** Loads the specified tree. */ private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates {@link BatchCall} if the type is supported. * @@ -116,8 +120,8 @@ private BatchCall makeBatchCall(final Class rootNodeType, public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - rootNodes = os.loadContainerHierarchy(rootNodeType, - rootNodeIDs, true, userID, groupID); + rootNodes = os.loadContainerHierarchy(ctx, rootNodeType, + rootNodeIDs, true, userID, groupID); } }; } @@ -142,15 +146,17 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * + * @param ctx The security context. * @param rootNodeType The type of the root node. Can only be one out of: * {@link ProjectData}, {@link DatasetData}. * @param rootNodeIDs The identifiers of the root nodes. * @param userID The identifier of the user. * @param groupID The identifier of the group. */ - public HierarchyLoader(Class rootNodeType, List rootNodeIDs, - long userID, long groupID) + public HierarchyLoader(SecurityContext ctx, + Class rootNodeType, List rootNodeIDs, long userID, long groupID) { + this.ctx = ctx; this.userID = userID; this.groupID = groupID; validate(rootNodeType, rootNodeIDs); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImageRenderer.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImageRenderer.java index e9f352c93b8..9bfecb0a213 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImageRenderer.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImageRenderer.java @@ -34,6 +34,7 @@ import omero.romio.PlaneDef; import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -57,10 +58,13 @@ public class ImageRenderer { /** The rendered image. */ - private Object result; + private Object result; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to retrieve the user images. @@ -80,7 +84,8 @@ private BatchCall makeBatchCall(final long pixelsID, final PlaneDef pd, public void doCall() throws Exception { OmeroImageService rds = context.getImageService(); - result = rds.renderImage(pixelsID, pd, asTexture, largeImage); + result = rds.renderImage(ctx, pixelsID, pd, asTexture, + largeImage); } }; } @@ -102,6 +107,7 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param pixelsID The id of the pixels set the plane belongs to. * @param pd The plane to render. * @param asTexture Pass true to return a texture, @@ -109,9 +115,10 @@ public void doCall() throws Exception * @param largeImae Pass true to render a large image, * false otherwise. */ - public ImageRenderer(long pixelsID, PlaneDef pd, boolean asTexture, - boolean largeImage) + public ImageRenderer(SecurityContext ctx, long pixelsID, PlaneDef pd, + boolean asTexture, boolean largeImage) { + this.ctx = ctx; if (pixelsID < 0) throw new IllegalArgumentException("ID not valid."); loadCall = makeBatchCall(pixelsID, pd, asTexture, largeImage); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImagesImporter.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImagesImporter.java index 57496e81fa1..5fb0705b6ec 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImagesImporter.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImagesImporter.java @@ -35,6 +35,7 @@ import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.model.ImportableFile; import org.openmicroscopy.shoola.env.data.model.ImportableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -56,16 +57,16 @@ public class ImagesImporter { /** The id of the user currently logged in. */ - private long userID; + private long userID; /** The id of the group is logged as. */ - private long groupID; + private long groupID; /** * Map of result, key is the file to import, value is an object or a * string. */ - private Map partialResult; + private Map partialResult; /** The object hosting the information for the import. */ private ImportableObject object; @@ -83,7 +84,8 @@ private void importFile(ImportableFile importable, boolean close) OmeroImageService os = context.getImageService(); try { partialResult.put(importable.getFile(), - os.importFile(object, importable, userID, groupID, close)); + os.importFile(object, importable, userID, groupID, + close)); } catch (Exception e) { e.printStackTrace(); partialResult.put(importable.getFile(), e); @@ -137,6 +139,7 @@ protected Object getResult() * Creates a new instance. If bad arguments are passed, we throw a runtime * exception so to fail early and in the call. * + * @param ctx The security context. * @param context The object hosting the information for the import. * Mustn't be null. * @param userID The id of the user. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImagesLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImagesLoader.java index 575b0a542ea..e59c19119b2 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImagesLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ImagesLoader.java @@ -36,6 +36,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DatasetData; @@ -59,11 +60,14 @@ public class ImagesLoader { /** The results of the call. */ - private Object results; + private Object results; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to retrieve the user images. * @@ -76,7 +80,7 @@ private BatchCall makeBatchCall(final long userID) public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - results = os.getExperimenterImages(userID); + results = os.getExperimenterImages(ctx, userID); } }; } @@ -96,7 +100,7 @@ public void doCall() throws Exception OmeroDataService os = context.getDataService(); List ids = new ArrayList(1); ids.add(imageID); - Set set = os.getImages(ImageData.class, ids, userID); + Set set = os.getImages(ctx, ImageData.class, ids, userID); if (set != null && set.size() == 1) { Iterator i = set.iterator(); while (i.hasNext()) { @@ -125,7 +129,7 @@ private BatchCall makeImagesInContainerBatchCall(final Class nodeType, public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - results = os.getImages(nodeType, nodeIDs, userID); + results = os.getImages(ctx, nodeType, nodeIDs, userID); } }; } @@ -146,7 +150,8 @@ private BatchCall makeBatchCall(final Timestamp startTime, public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - results = os.getImagesPeriod(startTime, endTime, userID, true); + results = os.getImagesPeriod(ctx, startTime, endTime, userID, + true); } }; } @@ -168,10 +173,12 @@ public void doCall() throws Exception /** * Creates a new instance. * - * @param rootLevelID The ID of the user. + * @param ctx The security context. + * @param rootLevelID The ID of the user. */ - public ImagesLoader(long rootLevelID) + public ImagesLoader(SecurityContext ctx, long rootLevelID) { + this.ctx = ctx; loadCall = makeBatchCall(rootLevelID); } @@ -179,19 +186,21 @@ public ImagesLoader(long rootLevelID) * Creates a new instance. If bad arguments are passed, we throw a runtime * exception so to fail early and in the call. * + * @param ctx The security context. * @param nodeType The type of the root node. Can only be one out of: * {@link DatasetData}. * @param nodeIDs A set of the IDs of top-most containers. * @param userID The Id of the user. */ - public ImagesLoader(Class nodeType, List nodeIDs, long userID) + public ImagesLoader(SecurityContext ctx, Class nodeType, List nodeIDs, + long userID) { if (nodeType == null) throw new IllegalArgumentException("No node type."); if (nodeIDs == null || nodeIDs.size() == 0) throw new IllegalArgumentException("Collection of node ID" + " not valid."); - + this.ctx = ctx; if (nodeType.equals(DatasetData.class) || nodeType.equals(ImageData.class)) loadCall = makeImagesInContainerBatchCall(nodeType, nodeIDs, @@ -204,25 +213,29 @@ else throw new IllegalArgumentException("Unsupported type: "+ * Creates a new instance. If bad arguments are passed, we throw a runtime * exception so to fail early and in the call. * + * @param ctx The security context. * @param startTime The timestamp identifying the start of a period. - * @param endTime The timestamp identifying the date. - * @param userID The Id of the user. + * @param endTime The timestamp identifying the date. + * @param userID The Id of the user. */ - public ImagesLoader(Timestamp startTime, Timestamp endTime, long userID) + public ImagesLoader(SecurityContext ctx, Timestamp startTime, + Timestamp endTime, long userID) { + this.ctx = ctx; loadCall = makeBatchCall(startTime, endTime, userID); } /** * Creates a new instance. * - * @param imageID The id of the image. - * @param rootLevelID The ID of the user. + * @param ctx The security context. + * @param imageID The id of the image. + * @param rootLevelID The ID of the root. */ - public ImagesLoader(long imageID, long rootLevelID) + public ImagesLoader(SecurityContext ctx,long imageID, long rootLevelID) { + this.ctx = ctx; loadCall = makeBatchCall(imageID, rootLevelID); } - } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/MovieCreator.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/MovieCreator.java index d261fe531a1..b34649a165f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/MovieCreator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/MovieCreator.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.ScriptCallback; import org.openmicroscopy.shoola.env.data.model.MovieExportParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.data.views.ProcessCallback; @@ -55,10 +56,13 @@ public class MovieCreator { /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; /** The server call-handle to the computation. */ - private Object callBack; + private Object callBack; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to create a movie. @@ -76,8 +80,8 @@ private BatchCall makeBatchCall(final long imageID, final long pixelsID, public ProcessCallback initialize() throws Exception { OmeroImageService os = context.getImageService(); - ScriptCallback cb = os.createMovie(imageID, pixelsID, channels, - param); + ScriptCallback cb = os.createMovie(ctx, imageID, pixelsID, + channels, param); if (cb == null) { callBack = Boolean.valueOf(false); return null; @@ -113,14 +117,16 @@ public ProcessCallback initialize() throws Exception /** * Creates a new instance. * - * @param imageID The id of the image. - * @param pixelsID The id of the pixels set. - * @param channels The channels to map. - * @param param The parameters to create the movie. + * @param ctx The security context. + * @param imageID The id of the image. + * @param pixelsID The id of the pixels set. + * @param channels The channels to map. + * @param param The parameters to create the movie. */ - public MovieCreator(long imageID, long pixelsID, List channels, - MovieExportParam param) + public MovieCreator(SecurityContext ctx, long imageID, long pixelsID, + List channels, MovieExportParam param) { + this.ctx = ctx; loadCall = makeBatchCall(imageID, pixelsID, channels, param); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ObjectFinder.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ObjectFinder.java index 0f9e680f7e9..6e561f1763f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ObjectFinder.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ObjectFinder.java @@ -30,8 +30,17 @@ //Third-party libraries //Application-internal dependencies +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.model.DeletableObject; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -53,24 +62,33 @@ public class ObjectFinder { /** The root nodes of the found trees. */ - private Object result; + private Object result; /** The search call. */ - private BatchCall loadCall; + private BatchCall loadCall; + + /** The security context.*/ + private List ctx; + + /** The context of the search.*/ + private SearchDataContext searchContext; /** * Creates a {@link BatchCall} to retrieve the data * - * @param searchContext The context of the search. + * @param ctx The security context. * @return The {@link BatchCall}. */ - private BatchCall searchFor(final SearchDataContext searchContext) + private BatchCall searchFor(final SecurityContext ctx) { - return new BatchCall("Retrieving objects") { + return new BatchCall("Searching") { public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - result = os.advancedSearchFor(searchContext); + Map r = new HashMap(); + r.put(ctx, os.advancedSearchFor(ctx, searchContext)); + result = r; } }; } @@ -79,22 +97,40 @@ public void doCall() throws Exception * Adds the {@link #loadCall} to the computation tree. * @see BatchCallTree#buildTree() */ - protected void buildTree() { add(loadCall); } + protected void buildTree() + { + Iterator i = ctx.iterator(); + while (i.hasNext()) { + final SecurityContext sc = i.next(); + add(searchFor(sc)); + } + } + + /** + * Returns the server call-handle to the computation. + * + * @return See above. + */ + protected Object getPartialResult() { return result; } + /** * Returns the result of the search. * @see BatchCallTree#getResult() */ - protected Object getResult() { return result; } + protected Object getResult() { return null; } /** * Creates a new instance. * + * @param ctx The security context. * @param searchContext The context of the search. */ - public ObjectFinder(SearchDataContext searchContext) + public ObjectFinder(List ctx, + SearchDataContext searchContext) { - loadCall = searchFor(searchContext); + this.ctx = ctx; + this.searchContext = searchContext; } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/OverlaysRenderer.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/OverlaysRenderer.java index e68b0b8a372..e43fae67a31 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/OverlaysRenderer.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/OverlaysRenderer.java @@ -33,6 +33,7 @@ import omero.romio.PlaneDef; import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -59,6 +60,9 @@ public class OverlaysRenderer /** Loads the specified tree. */ private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to retrieve the user images. * @@ -78,7 +82,7 @@ private BatchCall makeBatchCall(final long pixelsID, final PlaneDef pd, public void doCall() throws Exception { OmeroImageService rds = context.getImageService(); - result = rds.renderOverLays(pixelsID, pd, tableID, overlays, + result = rds.renderOverLays(ctx, pixelsID, pd, tableID, overlays, asTexture); } }; @@ -101,19 +105,21 @@ public void doCall() throws Exception /** * Creates a new instance. * - * @param pixelsID The id of the pixels set. - * @param pd The plane to render. - * @param tableID The id of the table. - * @param overlays The overlays to render. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param pd The plane to render. + * @param tableID The id of the table. + * @param overlays The overlays to render. * @param asTexture Pass true to return a texture, * false to return a buffered image. */ - public OverlaysRenderer(long pixelsID, PlaneDef pd, long tableID, - Map overlays, boolean asTexture) + public OverlaysRenderer(SecurityContext ctx, long pixelsID, PlaneDef pd, + long tableID, Map overlays, boolean asTexture) { - if (pixelsID < 0) - throw new IllegalArgumentException("ID not valid."); - loadCall = makeBatchCall(pixelsID, pd, tableID, overlays, asTexture); + if (pixelsID < 0) + throw new IllegalArgumentException("ID not valid."); + this.ctx = ctx; + loadCall = makeBatchCall(pixelsID, pd, tableID, overlays, asTexture); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PixelsDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PixelsDataLoader.java index a4ccd734416..6888eb2bfd2 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PixelsDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PixelsDataLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -54,14 +55,17 @@ public class PixelsDataLoader public static final int SET = 1; /** The id of the pixels set this loader is for. */ - private long pixelsID; + private long pixelsID; /** Result of the call. */ - private Object result; + private Object result; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to retrieve dimension of the pixels set. * @@ -73,7 +77,7 @@ private BatchCall makePixelsBatchCall() public void doCall() throws Exception { OmeroImageService rds = context.getImageService(); - result = rds.loadPixels(pixelsID); + result = rds.loadPixels(ctx, pixelsID); } }; } @@ -94,12 +98,14 @@ public void doCall() throws Exception /** * Creates the call corresponding to the passed index. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param index One of the constants defined by this class. */ - public PixelsDataLoader(long pixelsID, int index) + public PixelsDataLoader(SecurityContext ctx, long pixelsID, int index) { this.pixelsID = pixelsID; + this.ctx = ctx; switch (index) { case SET: loadCall = makePixelsBatchCall(); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PlaneInfoLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PlaneInfoLoader.java index 3e24b8e04d7..28ede28cfe1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PlaneInfoLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PlaneInfoLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -55,6 +56,9 @@ public class PlaneInfoLoader /** Loads the specified experimenter groups. */ private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to load the plane information. * @@ -71,7 +75,7 @@ private BatchCall loadPlaneInfo(final long pixelsID, final int z, public void doCall() throws Exception { OmeroImageService os = context.getImageService(); - result = os.loadPlaneInfo(pixelsID, z, t, channel); + result = os.loadPlaneInfo(ctx, pixelsID, z, t, channel); } }; } @@ -91,13 +95,16 @@ public void doCall() throws Exception /** * Creates a new instance. * - * @param pixelsID The id of the pixels set. - * @param z The selected z-section or -1. - * @param t The selected timepoint or -1. - * @param channel The selected timepoint or -1. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. + * @param z The selected z-section or -1. + * @param t The selected timepoint or -1. + * @param channel The selected channel or -1. */ - public PlaneInfoLoader(long pixelsID, int z, int t, int channel) + public PlaneInfoLoader(SecurityContext ctx, long pixelsID, int z, int t, + int channel) { + this.ctx = ctx; loadCall = loadPlaneInfo(pixelsID, z, t, channel); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PlateWellsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PlateWellsLoader.java index 46dbaf3ba8b..f87dad1d555 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PlateWellsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/PlateWellsLoader.java @@ -35,6 +35,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -56,10 +57,13 @@ public class PlateWellsLoader { /** The result of the call. */ - private Object result; + private Object result; /** Loads the specified experimenter groups. */ - private BatchCall loadCall; + private BatchCall loadCall; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to retrieve the wells-wellsample-image. @@ -85,17 +89,8 @@ public void doCall() throws Exception entry = (Entry) i.next(); key = (Long) entry.getKey(); value = (Long) entry.getValue(); - r.put(key, os.loadPlateWells(key, value, userID)); - } - /* - Iterator i = plateIDs.iterator(); - long id; - Map r = new HashMap(); - while (i.hasNext()) { - id = i.next(); - r.put(id, os.loadPlateWells(id, userID)); + r.put(key, os.loadPlateWells(ctx, key, value, userID)); } - */ result = r; } }; @@ -116,12 +111,15 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param ids Map whose keys are the plate ID and values are the * screen acquisition ID or -1. * @param userID The id of the user. */ - public PlateWellsLoader(Map ids, long userID) + public PlateWellsLoader(SecurityContext ctx, Map ids, + long userID) { + this.ctx = ctx; loadCall = loadPlateWells(ids, userID); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ProjectionSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ProjectionSaver.java index 73312f96b5d..48975c8438d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ProjectionSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ProjectionSaver.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.model.ProjectionParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -56,10 +57,13 @@ public class ProjectionSaver private long pixelsID; /** Result of the call. */ - private Object result; + private Object result; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to render the projected image @@ -83,9 +87,9 @@ public void doCall() throws Exception { OmeroImageService rds = context.getImageService(); if (openGLSupport) - result = rds.renderProjectedAsTexture(pixelsID, startZ, + result = rds.renderProjectedAsTexture(ctx, pixelsID, startZ, endZ, stepping, algorithm, channels); - else result = rds.renderProjected(pixelsID, startZ, + else result = rds.renderProjected(ctx, pixelsID, startZ, endZ, stepping, algorithm, channels); } }; @@ -103,7 +107,7 @@ private BatchCall makeProjectionCall(final ProjectionParam ref) public void doCall() throws Exception { OmeroImageService rds = context.getImageService(); - result = rds.projectImage(ref); + result = rds.projectImage(ctx, ref); } }; } @@ -123,6 +127,7 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param startZ The first optical section. * @param endZ The last optical section. @@ -133,12 +138,13 @@ public void doCall() throws Exception * @param openGLSupport Pass true if openGL is supported, * false otherwise. */ - public ProjectionSaver(long pixelsID, int startZ, int endZ, int stepping, - int type, List channels, boolean - openGLSupport) + public ProjectionSaver(SecurityContext ctx, long pixelsID, int startZ, + int endZ, int stepping, int type, List channels, boolean + openGLSupport) { if (pixelsID < 0) throw new IllegalArgumentException("Pixels Id not valid."); + this.ctx = ctx; this.pixelsID = pixelsID; loadCall = makeRenderProjectedCall(startZ, endZ, stepping, type, channels, openGLSupport); @@ -147,10 +153,12 @@ public ProjectionSaver(long pixelsID, int startZ, int endZ, int stepping, /** * Creates a new instance. * + * @param ctx The security context. * @param ref The object hosting the projection's parameters. */ - public ProjectionSaver(ProjectionParam ref) + public ProjectionSaver(SecurityContext ctx, ProjectionParam ref) { + this.ctx = ctx; loadCall = makeProjectionCall(ref); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ROILoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ROILoader.java index 43b061d7ff1..34176bc5957 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ROILoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ROILoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -59,19 +60,20 @@ public class ROILoader /** * Creates a {@link BatchCall} to load the ROIs. * + * @param ctx The security context. * @param imageID The id of the image. * @param fileID The id of the file. * @param userID The id of the user. * @return The {@link BatchCall}. */ - private BatchCall makeLoadCalls(final long imageID, final List fileID, - final long userID) + private BatchCall makeLoadCalls(final SecurityContext ctx, + final long imageID, final List fileID, final long userID) { return new BatchCall("load ROI") { public void doCall() throws Exception { OmeroImageService svc = context.getImageService(); - results = svc.loadROI(imageID, fileID, userID); + results = svc.loadROI(ctx, imageID, fileID, userID); } }; } @@ -91,13 +93,15 @@ public void doCall() throws Exception /** * Creates a new instance. * - * @param imageID The image's ID. - * @param fileID The ID of the files. - * @param userID The user's ID. + * @param ctx The security context. + * @param imageID The image's ID. + * @param fileID The ID of the files. + * @param userID The user's ID. */ - public ROILoader(long imageID, List fileID, long userID) + public ROILoader(SecurityContext ctx, long imageID, List fileID, + long userID) { - loadCall = makeLoadCalls(imageID, fileID, userID); + loadCall = makeLoadCalls(ctx, imageID, fileID, userID); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ROISaver.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ROISaver.java index e9caa9303cf..23932b3032c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ROISaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ROISaver.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.ROIData; @@ -59,19 +60,20 @@ public class ROISaver /** * Creates a {@link BatchCall} to load the ROIs. * + * @param ctx The security context. * @param imageID The id of the image. * @param fileID The id of the file. * @param userID The id of the user. * @return The {@link BatchCall}. */ - private BatchCall makeSaveCall(final long imageID, final long userID, - final List roiList ) + private BatchCall makeSaveCall(final SecurityContext ctx, + final long imageID, final long userID, final List roiList) { return new BatchCall("save ROI") { public void doCall() throws Exception { OmeroImageService svc = context.getImageService(); - result = svc.saveROI(imageID, userID, roiList); + result = svc.saveROI(ctx, imageID, userID, roiList); } }; } @@ -91,13 +93,15 @@ public void doCall() throws Exception /** * Creates a new instance. * - * @param imageID The image's ID. - * @param fileID The ID of the files. - * @param userID The user's ID. + * @param ctx The security context. + * @param imageID The image's ID. + * @param fileID The ID of the files. + * @param userID The user's ID. */ - public ROISaver(long imageID,long userID, List roiList) + public ROISaver(SecurityContext ctx, long imageID,long userID, + List roiList) { - saveCall = makeSaveCall(imageID, userID, roiList); + saveCall = makeSaveCall(ctx, imageID, userID, roiList); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RelatedContainersLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RelatedContainersLoader.java index eaec175d8f3..f47f170108e 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RelatedContainersLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RelatedContainersLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -50,10 +51,13 @@ public class RelatedContainersLoader { /** The result of the call. */ - private Object result; + private Object result; /** Loads the specified experimenter groups. */ - private BatchCall loadCall; + private BatchCall loadCall; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to load the files attached to the object @@ -72,7 +76,7 @@ private BatchCall loadContainers(final Class type, final long id, public void doCall() throws Exception { OmeroDataService os = context.getDataService(); - result = os.findContainerPaths(type, id, userID); + result = os.findContainerPaths(ctx, type, id, userID); } }; } @@ -94,13 +98,16 @@ public void doCall() throws Exception * index, throws an {@link IllegalArgumentException} if the index is not * supported. * - * @param type The type of node the annotations are related to. - * @param id The id of the object. - * @param userID The id of the user or -1 if the id + * @param ctx The security context. + * @param type The type of node the annotations are related to. + * @param id The id of the object. + * @param userID The id of the user or -1 if the id * is not specified. */ - public RelatedContainersLoader(Class type, long id, long userID) + public RelatedContainersLoader(SecurityContext ctx, Class type, long id, + long userID) { + this.ctx = ctx; loadCall = loadContainers(type, id, userID); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingControlLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingControlLoader.java index 6306bfe8896..3745406c475 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingControlLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingControlLoader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.DSOutOfServiceException; import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.RenderingControl; @@ -68,11 +69,14 @@ public class RenderingControlLoader public static final int SHUTDOWN = 3; /** Result of the call. */ - private Object result; + private Object result; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to retrieve rendering control. * @@ -90,16 +94,16 @@ public void doCall() throws Exception switch (index) { default: case LOAD: - result = rds.loadRenderingControl(pixelsID); + result = rds.loadRenderingControl(ctx, pixelsID); break; case RELOAD: - result = rds.reloadRenderingService(pixelsID); + result = rds.reloadRenderingService(ctx, pixelsID); break; case RESET: - result = rds.resetRenderingService(pixelsID); + result = rds.resetRenderingService(ctx, pixelsID); break; case SHUTDOWN: - rds.shutDown(pixelsID); + rds.shutDown(ctx, pixelsID); } if (result == null && index != SHUTDOWN) { throw new DSOutOfServiceException("Cannot start the " + @@ -128,13 +132,15 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * + * @param ctx The security context. * @param pixelsID The id of the pixels set the rendering control is for. * @param index One of the constants defined by this class. */ - public RenderingControlLoader(long pixelsID, int index) + public RenderingControlLoader(SecurityContext ctx, long pixelsID, int index) { if (pixelsID < 0) throw new IllegalArgumentException("ID not valid."); + this.ctx = ctx; loadCall = makeBatchCall(pixelsID, index); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingSettingsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingSettingsLoader.java index 87439624c0f..92f15d23abd 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingSettingsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingSettingsLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.RenderingControl; @@ -51,11 +52,14 @@ public class RenderingSettingsLoader { /** Result of the call. */ - private Object result; + private Object result; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to retrieve rendering settings. * @@ -70,7 +74,7 @@ private BatchCall makeBatchCall(final long pixelsID, final long userID) public void doCall() throws Exception { OmeroImageService rds = context.getImageService(); - result = rds.getRenderingSettings(pixelsID, userID); + result = rds.getRenderingSettings(ctx, pixelsID, userID); } }; } @@ -94,13 +98,16 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * + * @param ctx The security context. * @param pixelsID The id of the pixels set the rendering control is for. * @param userID The id of the user. */ - public RenderingSettingsLoader(long pixelsID, long userID) + public RenderingSettingsLoader(SecurityContext ctx, long pixelsID, + long userID) { if (pixelsID < 0) throw new IllegalArgumentException("ID not valid."); + this.ctx = ctx; loadCall = makeBatchCall(pixelsID, userID); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingSettingsSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingSettingsSaver.java index 0827d62beae..33b6d49eafb 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingSettingsSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RenderingSettingsSaver.java @@ -36,6 +36,7 @@ import org.openmicroscopy.shoola.env.data.OmeroDataService; import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.RenderingControl; @@ -83,11 +84,14 @@ public class RenderingSettingsSaver public static final int SET_OWNER = 4; /** Result of the call. */ - private Object result; + private Object result; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Controls if the passed type is supported. * @@ -124,17 +128,18 @@ public void doCall() throws Exception OmeroImageService rds = context.getImageService(); switch (index) { case PASTE: - result = rds.pasteRenderingSettings(pixelsID, rootType, - ids); + result = rds.pasteRenderingSettings(ctx, pixelsID, + rootType, ids); break; case RESET: - result = rds.resetRenderingSettings(rootType, ids); + result = rds.resetRenderingSettings(ctx, rootType, ids); break; case SET_MIN_MAX: - result = rds.setMinMaxSettings(rootType, ids); + result = rds.setMinMaxSettings(ctx, rootType, ids); break; case SET_OWNER: - result = rds.setOwnerRenderingSettings(rootType, ids); + result = rds.setOwnerRenderingSettings(ctx, rootType, + ids); } } }; @@ -157,8 +162,8 @@ public void doCall() throws Exception long userID = ((ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS)).getId(); OmeroDataService os = context.getDataService(); - Collection l = os.getImagesPeriod(ref.getStartTime(), - ref.getEndTime(), userID, true); + Collection l = os.getImagesPeriod(ctx, ref.getStartTime(), + ref.getEndTime(), userID, true); if (l != null) { Iterator i = l.iterator(); DataObject element; @@ -170,24 +175,23 @@ public void doCall() throws Exception OmeroImageService rds = context.getImageService(); switch (index) { case PASTE: - result = rds.pasteRenderingSettings(pixelsID, + result = rds.pasteRenderingSettings(ctx, pixelsID, ImageData.class, ids); break; case RESET: - result = rds.resetRenderingSettings(ImageData.class, - ids); + result = rds.resetRenderingSettings(ctx, + ImageData.class, ids); break; case SET_MIN_MAX: - result = rds.setMinMaxSettings(ImageData.class, + result = rds.setMinMaxSettings(ctx, ImageData.class, ids); break; case SET_OWNER: - result = rds.setOwnerRenderingSettings( + result = rds.setOwnerRenderingSettings(ctx, ImageData.class, ids); break; } } - } }; } @@ -209,9 +213,8 @@ private BatchCall makeCreateBatchCall(final long pixelsID, public void doCall() throws Exception { OmeroImageService os = context.getImageService(); - result = os.createRenderingSettings(pixelsID, rndToCopy, + result = os.createRenderingSettings(ctx, pixelsID, rndToCopy, indexes); - } }; } @@ -233,6 +236,7 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param rootNodeType The type of nodes. Can either be * ImageData, DatasetData, * ProjectData, ScreenData, @@ -241,78 +245,89 @@ public void doCall() throws Exception * Mustn't be null. * @param index One of the constants defined by this class. */ - public RenderingSettingsSaver(Class rootNodeType, List ids, int index) + public RenderingSettingsSaver(SecurityContext ctx, Class rootNodeType, + List ids, int index) { checkRootType(rootNodeType); if (ids == null || ids.size() == 0) throw new IllegalArgumentException("No nodes specified."); + this.ctx = ctx; loadCall = makeBatchCall(-1, rootNodeType, ids, index); } /** * Creates a new instance. * + * @param ctx The security context. * @param pixelsID The id of the pixels set of reference. * @param rootNodeType The type of nodes. Can either be - * ImageData, DatasetData or - * CategoryData. + * ImageData, DatasetData. * @param ids The nodes to apply settings to. * Mustn't be null. */ - public RenderingSettingsSaver(long pixelsID, Class rootNodeType, - List ids) + public RenderingSettingsSaver(SecurityContext ctx, long pixelsID, + Class rootNodeType, List ids) { checkRootType(rootNodeType); if (ids == null || ids.size() == 0) throw new IllegalArgumentException("No nodes specified."); if (pixelsID < 0) throw new IllegalArgumentException("Pixels ID not valid."); + this.ctx = ctx; loadCall = makeBatchCall(pixelsID, rootNodeType, ids, PASTE); } /** * Creates a new instance. * + * @param ctx The security context. * @param pixelsID The id of the pixels set of reference. * @param ref The time reference object. * @param index One of the constants defined by this class. */ - public RenderingSettingsSaver(long pixelsID, TimeRefObject ref) + public RenderingSettingsSaver(SecurityContext ctx, long pixelsID, + TimeRefObject ref) { if (pixelsID < 0) throw new IllegalArgumentException("Pixels ID not valid."); if (ref == null) throw new IllegalArgumentException("Period not valid."); + this.ctx = ctx; loadCall = makeBatchCall(pixelsID, ref, PASTE); } /** * Creates a new instance. * - * @param ref The time reference object. - * @param index One of the constants defined by this class. + * @param ctx The security context. + * @param ref The time reference object. + * @param index One of the constants defined by this class. */ - public RenderingSettingsSaver(TimeRefObject ref, int index) + public RenderingSettingsSaver(SecurityContext ctx, TimeRefObject ref, + int index) { if (ref == null) throw new IllegalArgumentException("Period not valid."); + this.ctx = ctx; loadCall = makeBatchCall(-1, ref, index); } /** * Creates a new instance. * - * @param pixelsID The id of the pixels set. + * @param ctx The security context. + * @param pixelsID The id of the pixels set. * @param rndToCopy The rendering setting to copy. - * @param indexes Collection of channel's indexes. - * Mustn't be null. + * @param indexes Collection of channel's indexes. + * Mustn't be null. */ - public RenderingSettingsSaver(long pixelsID, RndProxyDef rndToCopy, - List indexes) + public RenderingSettingsSaver(SecurityContext ctx, long pixelsID, + RndProxyDef rndToCopy,List indexes) { if (pixelsID < 0) throw new IllegalArgumentException("Pixels ID not valid."); + this.ctx = ctx; loadCall = makeCreateBatchCall(pixelsID, rndToCopy, indexes); } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RepositoriesLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RepositoriesLoader.java index ca71528a1cd..71657d97431 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RepositoriesLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/RepositoriesLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroDataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -50,24 +51,26 @@ public class RepositoriesLoader { /** Call to control if the files can be imported. */ - private BatchCall loadCall; + private BatchCall loadCall; /** The result of the call. */ - private Object result; + private Object result; /** * Creates a {@link BatchCall} to load the repositories. * + * @param ctx The security context. * @param userID The id of the user. * @return The {@link BatchCall}. */ - private BatchCall makeBatchCall(final long userID) + private BatchCall makeBatchCall(final SecurityContext ctx, + final long userID) { return new BatchCall("Loading repositories.") { public void doCall() throws Exception { OmeroDataService service = context.getDataService(); - result = service.getFSRepositories(userID); + result = service.getFSRepositories(ctx, userID); } }; } @@ -87,11 +90,12 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param userID The id of the user. */ - public RepositoriesLoader(long userID) + public RepositoriesLoader(SecurityContext ctx, long userID) { - loadCall = makeBatchCall(userID); + loadCall = makeBatchCall(ctx, userID); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/SaveAsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/SaveAsLoader.java index b60c05d1cae..c97b2164b52 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/SaveAsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/SaveAsLoader.java @@ -31,6 +31,7 @@ import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.ScriptCallback; import org.openmicroscopy.shoola.env.data.model.SaveAsParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.data.views.ProcessBatchCall; @@ -54,24 +55,26 @@ public class SaveAsLoader { /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; /** The server call-handle to the computation. */ - private Object callBack; + private Object callBack; /** * Creates a {@link BatchCall} to save the images locally. * + * @param ctx The security context. * @param param The parameters to create the movie. * @return The {@link BatchCall}. */ - private BatchCall makeBatchCall(final SaveAsParam param) + private BatchCall makeBatchCall(final SecurityContext ctx, + final SaveAsParam param) { return new ProcessBatchCall("Saving images locally: ") { public ProcessCallback initialize() throws Exception { OmeroImageService os = context.getImageService(); - ScriptCallback cb = os.saveAs(param); + ScriptCallback cb = os.saveAs(ctx, param); if (cb == null) { callBack = Boolean.valueOf(false); return null; @@ -107,13 +110,14 @@ public ProcessCallback initialize() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param parameters The parameters to handle. */ - public SaveAsLoader(SaveAsParam parameters) + public SaveAsLoader(SecurityContext ctx, SaveAsParam parameters) { if (parameters == null) throw new IllegalArgumentException("No parameters specified."); - loadCall = makeBatchCall(parameters); + loadCall = makeBatchCall(ctx, parameters); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptRunner.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptRunner.java index c5b54b44f69..0ee57920c64 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptRunner.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptRunner.java @@ -31,6 +31,7 @@ import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.ScriptCallback; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.data.views.ProcessBatchCall; @@ -54,24 +55,26 @@ public class ScriptRunner { /** The server call-handle to the computation. */ - private Object callBack; + private Object callBack; /** Calls to run the script. */ - private BatchCall loadCall; + private BatchCall loadCall; /** * Creates a {@link BatchCall} to run the script. * + * @param ctx The security context. * @param script The script to run. * @return The {@link BatchCall}. */ - private BatchCall makeCall(final ScriptObject script) + private BatchCall makeCall(final SecurityContext ctx, + final ScriptObject script) { return new ProcessBatchCall("Run the script") { public ProcessCallback initialize() throws Exception { OmeroImageService os = context.getImageService(); - ScriptCallback cb = os.runScript(script); + ScriptCallback cb = os.runScript(ctx, script); if (cb == null) { callBack = Boolean.valueOf(false); return null; @@ -106,11 +109,12 @@ public ProcessCallback initialize() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param script The script to run. */ - public ScriptRunner(ScriptObject script) + public ScriptRunner(SecurityContext ctx, ScriptObject script) { - loadCall = makeCall(script); + loadCall = makeCall(ctx, script); } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptUploader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptUploader.java index 27c2b0a2632..d85728718d3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptUploader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptUploader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -59,16 +60,18 @@ public class ScriptUploader /** * Creates a {@link BatchCall} to upload the script. * - * @param script The script to upload. + * @param ctx The security context. + * @param script The script to upload. * @return The {@link BatchCall}. */ - private BatchCall makeCall(final ScriptObject script) + private BatchCall makeCall(final SecurityContext ctx, + final ScriptObject script) { return new BatchCall("Upload the script") { public void doCall() throws Exception { OmeroImageService os = context.getImageService(); - result = os.uploadScript(script); + result = os.uploadScript(ctx, script); } }; } @@ -89,13 +92,14 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param script The script to upload. */ - public ScriptUploader(ScriptObject script) + public ScriptUploader(SecurityContext ctx, ScriptObject script) { if (script == null) throw new IllegalArgumentException("No script specified."); - loadCall = makeCall(script); + loadCall = makeCall(ctx, script); } - + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptsLoader.java index b83dfdf71a4..a090db78af8 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ScriptsLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.RenderingControl; @@ -60,11 +61,14 @@ public class ScriptsLoader public static final int DEFAULT_SCRIPTS = 2; /** Result of the call. */ - private Object result; + private Object result; /** Loads the specified tree. */ - private BatchCall loadCall; + private BatchCall loadCall; + /** The security context.*/ + private SecurityContext ctx; + /** * Creates a {@link BatchCall} to load the scripts. * @@ -77,7 +81,7 @@ private BatchCall makeBatchCall(final long userID) public void doCall() throws Exception { OmeroImageService svc = context.getImageService(); - result = svc.loadAvailableScripts(userID); + result = svc.loadAvailableScripts(ctx, userID); } }; } @@ -94,7 +98,7 @@ private BatchCall makeLoadScriptBatchCall(final long scriptID) public void doCall() throws Exception { OmeroImageService svc = context.getImageService(); - result = svc.loadScript(scriptID); + result = svc.loadScript(ctx, scriptID); } }; } @@ -118,12 +122,14 @@ public void doCall() throws Exception * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * - * @param id The id of the experimenter, the id of the script - * or -1. - * @param index One of the constants defined by this class. + * @param ctx The security context. + * @param id The id of the experimenter, the id of the script + * or -1. + * @param index One of the constants defined by this class. */ - public ScriptsLoader(long id, int index) + public ScriptsLoader(SecurityContext ctx, long id, int index) { + this.ctx = ctx; switch (index) { case ALL_SCRIPTS: case DEFAULT_SCRIPTS: @@ -132,7 +138,6 @@ public ScriptsLoader(long id, int index) case SINGLE_SCRIPT: loadCall = makeLoadScriptBatchCall(id); } - } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ServerSideROILoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ServerSideROILoader.java index 167b0d8a61b..9951b3f9447 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ServerSideROILoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ServerSideROILoader.java @@ -28,6 +28,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -62,16 +63,18 @@ public class ServerSideROILoader * load those ROIs. If there are no ROI, the measurement tool will check * to see if there is an XML ROI file to load roi's from. * + * @param ctx The security context. * @param imageID The id of the image the ROIs are related to. * @param userID The id of the user. */ - private BatchCall makeLoadCalls(final long imageID, final long userID) + private BatchCall makeLoadCalls(final SecurityContext ctx, + final long imageID, final long userID) { return new BatchCall("load ROI From Server") { public void doCall() throws Exception { OmeroImageService svc = context.getImageService(); - results = svc.loadROIFromServer(imageID, userID); + results = svc.loadROIFromServer(ctx, imageID, userID); } }; } @@ -91,14 +94,13 @@ public void doCall() throws Exception /** * Creates a new instance. * - * @param imageID The image's ID. - * @param userID The user's ID. + * @param ctx The security context. + * @param imageID The image's ID. + * @param userID The user's ID. */ - public ServerSideROILoader(long imageID, long userID) + public ServerSideROILoader(SecurityContext ctx, long imageID, long userID) { - loadCall = makeLoadCalls(imageID, userID); + loadCall = makeLoadCalls(ctx, imageID, userID); } - -} - +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/StructuredAnnotationLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/StructuredAnnotationLoader.java index 83ffd5a8da2..ca364d7dc57 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/StructuredAnnotationLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/StructuredAnnotationLoader.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.OmeroMetadataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.DataObject; @@ -65,10 +66,13 @@ public class StructuredAnnotationLoader public static final int SINGLE = 2; /** The result of the call. */ - private Object result; + private Object result; /** Loads the specified experimenter groups. */ - private BatchCall loadCall; + private BatchCall loadCall; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to load the existing annotations of the @@ -89,7 +93,7 @@ private BatchCall loadAnnotations(final Class annotationType, public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.loadAnnotations(annotationType, null, userID, + result = os.loadAnnotations(ctx, annotationType, null, userID, groupID); } }; @@ -112,7 +116,7 @@ private BatchCall loadRatings(final Class type, final long id, public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.loadRatings(type, id, userID); + result = os.loadRatings(ctx, type, id, userID); } }; } @@ -134,7 +138,7 @@ private BatchCall loadROIMeasurements(final Class type, final long id, public void doCall() throws Exception { OmeroImageService os = context.getImageService(); - result = os.loadROIMeasurements(type, id, userID); + result = os.loadROIMeasurements(ctx, type, id, userID); } }; } @@ -155,7 +159,7 @@ private BatchCall loadStructuredData(final Object object, public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.loadStructuredData(object, userID, true); + result = os.loadStructuredData(ctx, object, userID, true); } }; } @@ -164,22 +168,21 @@ public void doCall() throws Exception * Creates a {@link BatchCall} to load the ratings related to the object * identified by the class and the id. * - * @param data The objects. - * @param userID The id of the user who tagged the object or - * -1 if the user is not specified. - * @param viewed Pass true to load the rendering settings - * related to the objects, false - * otherwise. + * @param data The objects. + * @param userID The id of the user who tagged the object or + * -1 if the user is not specified. + * @param viewed Pass true to load the rendering settings + * related to the objects, false otherwise. * @return The {@link BatchCall}. */ - private BatchCall loadStructuredData(final List data, - final long userID, final boolean viewed) + private BatchCall loadStructuredData(final List data, + final long userID, final boolean viewed) { return new BatchCall("Loading Ratings") { public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.loadStructuredData(data, userID, viewed); + result = os.loadStructuredData(ctx, data, userID, viewed); } }; } @@ -196,7 +199,7 @@ private BatchCall loadAnnotation(final long annotationID) public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.loadAnnotation(annotationID); + result = os.loadAnnotation(ctx, annotationID); } }; } @@ -205,20 +208,20 @@ public void doCall() throws Exception * Creates a {@link BatchCall} to load the ratings related to the object * identified by the class and the id. * - * @param type The type of the object. - * @param ids The collection of id of the object. - * @param userID The id of the user who tagged the object or - * -1 if the user is not specified. + * @param type The type of the object. + * @param ids The collection of id of the object. + * @param userID The id of the user who tagged the object or + * -1 if the user is not specified. * @return The {@link BatchCall}. */ - private BatchCall loadRatings(final Class type, final List ids, - final long userID) + private BatchCall loadRatings(final Class type, final List ids, + final long userID) { return new BatchCall("Loading Ratings") { public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.loadRatings(type, ids, userID); + result = os.loadRatings(ctx, type, ids, userID); } }; } @@ -240,16 +243,18 @@ public void doCall() throws Exception * index, throws an {@link IllegalArgumentException} if the index is not * supported. * - * @param index The index identifying the call. One of the constants - * defined by this class. - * @param type The type of node the annotations are related to. - * @param ids Collection of the id of the object. - * @param userID The id of the user or -1 if the id - * is not specified. + * @param ctx The security context. + * @param index The index identifying the call. One of the constants + * defined by this class. + * @param type The type of node the annotations are related to. + * @param ids Collection of the id of the object. + * @param userID The id of the user or -1 if the id + * is not specified. */ - public StructuredAnnotationLoader(int index, Class type, List ids, - long userID) + public StructuredAnnotationLoader(SecurityContext ctx, int index, + Class type, List ids, long userID) { + this.ctx = ctx; switch (index) { case RATING: loadCall = loadRatings(type, ids, userID); @@ -262,6 +267,7 @@ public StructuredAnnotationLoader(int index, Class type, List ids, /** * Creates a new instance. * + * @param ctx The security context. * @param index The index identifying the call. One of the constants * defined by this class. * @param userID The id of the user or -1 if the id @@ -270,9 +276,10 @@ public StructuredAnnotationLoader(int index, Class type, List ids, * @param viewed */ - public StructuredAnnotationLoader(int index, List data, long - userID, boolean viewed) + public StructuredAnnotationLoader(SecurityContext ctx, int index, + List data, long userID, boolean viewed) { + this.ctx = ctx; switch (index) { case ALL: loadCall = loadStructuredData(data, userID, viewed); @@ -284,17 +291,19 @@ public StructuredAnnotationLoader(int index, List data, long * index, throws an {@link IllegalArgumentException} if the index is not * supported. * - * @param index The index identifying the call. One of the constants - * defined by this class. - * @param object The object to handle. - * @param userID The id of the user or -1 if the id - * is not specified. + * @param ctx The security context. + * @param index The index identifying the call. One of the constants + * defined by this class. + * @param object The object to handle. + * @param userID The id of the user or -1 if the id is not + * specified. */ - public StructuredAnnotationLoader(int index, Object object, - long userID) + public StructuredAnnotationLoader(SecurityContext ctx, int index, + Object object, long userID) { if (object == null) throw new IllegalArgumentException("Object not defined."); + this.ctx = ctx; switch (index) { case ALL: loadCall = loadStructuredData(object, userID); @@ -321,16 +330,18 @@ public StructuredAnnotationLoader(int index, Object object, * index, throws an {@link IllegalArgumentException} if the index is not * supported. * - * @param annotationType The type of annotations to fetch. - * @param objectType The type of object the annotations is related - * to, or null. - * @param userID The id of the user or -1 if the id - * is not specified. - * @param groupID The id of the group or -1. + * @param ctx The security context. + * @param annotationType The type of annotations to fetch. + * @param objectType The type of object the annotations is related + * to, or null. + * @param userID The id of the user or -1 if the id + * is not specified. + * @param groupID The id of the group or -1. */ - public StructuredAnnotationLoader(Class annotationType, long userID, - long groupID) + public StructuredAnnotationLoader(SecurityContext ctx, Class annotationType, + long userID, long groupID) { + this.ctx = ctx; loadCall = loadAnnotations(annotationType, userID, groupID); } @@ -339,10 +350,12 @@ public StructuredAnnotationLoader(Class annotationType, long userID, * index, throws an {@link IllegalArgumentException} if the index is not * supported. * + * @param ctx The security context. * @param annotationID The Id of the annotation to load. */ - public StructuredAnnotationLoader(long annotationID) + public StructuredAnnotationLoader(SecurityContext ctx, long annotationID) { + this.ctx = ctx; loadCall = loadAnnotation(annotationID); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/StructuredAnnotationSaver.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/StructuredAnnotationSaver.java index e023bdfdb23..7f30691c749 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/StructuredAnnotationSaver.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/StructuredAnnotationSaver.java @@ -33,6 +33,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.model.TimeRefObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import pojos.AnnotationData; @@ -56,12 +57,16 @@ public class StructuredAnnotationSaver { /** The result of the call. */ - private Object result; + private Object result; /** Loads the specified experimenter groups. */ - private BatchCall loadCall; + private BatchCall loadCall; + + /** The security context.*/ + private SecurityContext ctx; /** + * * Creates a {@link BatchCall} to retrieve the users who viewed * the specified set of pixels and also retrieve the rating associated * to that set. @@ -84,10 +89,10 @@ public void doCall() throws Exception if (metadata != null) { Iterator i = metadata.iterator(); while (i.hasNext()) { - os.saveAcquisitionData(i.next()) ; + os.saveAcquisitionData(ctx, i.next()) ; } } - result = os.saveData(data, toAdd, toRemove, userID); + result = os.saveData(ctx, data, toAdd, toRemove, userID); } }; } @@ -115,10 +120,10 @@ public void doCall() throws Exception if (metadata != null) { Iterator i = metadata.iterator(); while (i.hasNext()) { - os.saveAcquisitionData(i.next()) ; + os.saveAcquisitionData(ctx, i.next()) ; } } - result = os.saveBatchData(data, toAdd, toRemove, userID); + result = os.saveBatchData(ctx, data, toAdd, toRemove, userID); } }; } @@ -146,10 +151,10 @@ public void doCall() throws Exception if (metadata != null) { Iterator i = metadata.iterator(); while (i.hasNext()) { - os.saveAcquisitionData(i.next()) ; + os.saveAcquisitionData(ctx, i.next()) ; } } - result = os.saveBatchData(data, toAdd, toRemove, userID); + result = os.saveBatchData(ctx, data, toAdd, toRemove, userID); } }; } @@ -169,20 +174,23 @@ public void doCall() throws Exception /** * Creates a new instance. * - * @param data The data objects to handle. - * @param toAdd The annotations to add. - * @param toRemove The annotations to remove. - * @param metadata The acquisition metadata. - * @param userID The id of the user. - * @param batch Pass true to indicate that it is a batch - * annotation, false otherwise. + * @param ctx The security context. + * @param data The data objects to handle. + * @param toAdd The annotations to add. + * @param toRemove The annotations to remove. + * @param metadata The acquisition metadata. + * @param userID The id of the user. + * @param batch Pass true to indicate that it is a batch + * annotation, false otherwise. */ - public StructuredAnnotationSaver(Collection data, - List toAdd, List toRemove, + public StructuredAnnotationSaver(SecurityContext ctx, + Collection data, List toAdd, + List toRemove, List metadata, long userID, boolean batch) { if (data == null) throw new IllegalArgumentException("No object to save."); + this.ctx = ctx; if (batch) loadCall = loadBatchCall(data, toAdd, toRemove, metadata, userID); else @@ -192,17 +200,19 @@ public StructuredAnnotationSaver(Collection data, /** * Creates a new instance. * + * @param ctx The security context. * @param timeRefObject The object hosting the time interval. * @param toAdd The annotations to add. * @param toRemove The annotations to remove. * @param userID The id of the user. */ - public StructuredAnnotationSaver(TimeRefObject timeRefObject, - List toAdd, List toRemove, - long userID) + public StructuredAnnotationSaver(SecurityContext ctx, + TimeRefObject timeRefObject, List toAdd, + List toRemove, long userID) { if (timeRefObject == null) throw new IllegalArgumentException("No time period sepecified."); + this.ctx = ctx; loadCall = loadBatchCall(timeRefObject, toAdd, toRemove, null, userID); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/SwitchUserGroupLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/SwitchUserGroupLoader.java index c7b3aa49dd6..541eb614f4f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/SwitchUserGroupLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/SwitchUserGroupLoader.java @@ -52,20 +52,20 @@ public class SwitchUserGroupLoader { /** The experimenter to handle. */ - private ExperimenterData experimenter; + private ExperimenterData experimenter; /** The identifier of the group. */ - private long groupID; + private long groupID; /** The partial result. */ - private Object result; + private Object result; /** Switches the user group. */ private void switchUserGroup() { try { - context.getAdminService().changeExperimenterGroup(experimenter, - groupID); + //context.getAdminService().changeExperimenterGroup(experimenter, + // groupID); } catch (Exception e) { e.printStackTrace(); context.getLogger().error(this, diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TabularDataLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TabularDataLoader.java index f8264e6d003..1932bc65594 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TabularDataLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TabularDataLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroMetadataService; import org.openmicroscopy.shoola.env.data.model.TableParameters; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -51,10 +52,10 @@ public class TabularDataLoader { /** The result of the call. */ - private Object result; + private Object result; /** Loads the specified experimenter groups. */ - private BatchCall loadCall; + private BatchCall loadCall; /** * Creates a {@link BatchCall} to load the tabular data. @@ -63,14 +64,14 @@ public class TabularDataLoader * @param userID The identifier of the user. * @return The {@link BatchCall}. */ - private BatchCall makeCall(final TableParameters parameters, - final long userID) + private BatchCall makeCall(final SecurityContext ctx, + final TableParameters parameters, final long userID) { return new BatchCall("Load tabular data") { public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.loadTabularData(parameters, userID); + result = os.loadTabularData(ctx, parameters, userID); } }; } @@ -91,14 +92,16 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param parameters The parameters to handle. * @param userID The identifier of the user. */ - public TabularDataLoader(TableParameters parameters, long userID) + public TabularDataLoader(SecurityContext ctx, + TableParameters parameters, long userID) { if (parameters == null) throw new IllegalArgumentException("No data to load."); - loadCall = makeCall(parameters, userID); + loadCall = makeCall(ctx, parameters, userID); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TagsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TagsLoader.java index 99cb4862ea4..2bdd9d2e1f2 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TagsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TagsLoader.java @@ -28,6 +28,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroMetadataService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -59,27 +60,28 @@ public class TagsLoader * Creates a {@link BatchCall} to retrieve the tagSets owned by the passed * user. * - * @param id The id of the tag or -1. - * @param dataObject Pass true to load the - * DataObject related - * to the tags, false otherwise. - * @param topLevel Pass true to load Tag Set, - * false to load Tag. - * This will be taken into account if the Id is - * negative. - * @param userID The identifier of the user. - * @param groupID The identifier of the user's group. + * @param ctx The security context. + * @param id The id of the tag or -1. + * @param dataObject Pass true to load the + * DataObject related to the tags, + * false otherwise. + * @param topLevel Pass true to load Tag Set, + * false to load Tag. + * This will be taken into account if the Id is negative. + * @param userID The identifier of the user. + * @param groupID The identifier of the user's group. * @return The {@link BatchCall}. */ - private BatchCall loadTagsCall(final Long id, final boolean dataObject, - final boolean topLevel, final long userID, - final long groupID) + private BatchCall loadTagsCall(final SecurityContext ctx, + final Long id, final boolean dataObject, final boolean topLevel, + final long userID, final long groupID) { return new BatchCall("Loading tags.") { public void doCall() throws Exception { OmeroMetadataService os = context.getMetadataService(); - result = os.loadTags(id, dataObject, topLevel, userID, groupID); + result = os.loadTags(ctx, id, dataObject, topLevel, userID, + groupID); } }; } @@ -99,21 +101,20 @@ public void doCall() throws Exception /** * Creates a new instance. * - * @param id The id of the parent the tags are related to, or - * -1. - * @param withObjects Pass true to load the objects related - * to the tags, false otherwise. - * @param topLevel Pass true to load Tag Set, - * false to load Tag. - * This will be taken into account if the Id is - * negative. - * @param userID The id of the user who owns the tags or tag sets. - * @param groupID The id of the group the user is currently logged in. + * @param ctx The security context. + * @param id The id of the parent the tags are related to, or -1. + * @param withObjects Pass true to load the objects related + * to the tags, false otherwise. + * @param topLevel Pass true to load Tag Set, + * false to load Tag. + * This will be taken into account if the Id is negative. + * @param userID The id of the user who owns the tags or tag sets. + * @param groupID The id of the group the user is currently logged in. */ - public TagsLoader(Long id, boolean withObjects, boolean topLevel, - long userID, long groupID) + public TagsLoader(SecurityContext ctx, Long id, boolean withObjects, + boolean topLevel, long userID, long groupID) { - loadCall = loadTagsCall(id, withObjects, topLevel, userID, groupID); + loadCall = loadTagsCall(ctx, id, withObjects, topLevel, userID, groupID); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ThumbnailLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ThumbnailLoader.java index 52ec574ba39..cbce5770c98 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ThumbnailLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ThumbnailLoader.java @@ -37,6 +37,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.model.ThumbnailData; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.RenderingServiceException; @@ -74,31 +75,34 @@ public class ThumbnailLoader { /** The images for which we need thumbnails. */ - private Collection images; + private Collection images; /** The maximum acceptable width of the thumbnails. */ - private int maxWidth; + private int maxWidth; /** The maximum acceptable height of the thumbnails. */ - private int maxHeight; + private int maxHeight; /** The lastly retrieved thumbnail. */ - private Object currentThumbnail; + private Object currentThumbnail; /** Flag to indicate if the class was invoked for a pixels ID. */ - private boolean pixelsCall; + private boolean pixelsCall; /** The id of the pixels set this loader is for. */ - private long pixelsID; + private long pixelsID; /** Collection of user IDs. */ - private Set userIDs; + private Set userIDs; /** Helper reference to the image service. */ - private OmeroImageService service; + private OmeroImageService service; /** Load the thumbnail as an full size image. */ - private boolean asImage; + private boolean asImage; + + /** The security context.*/ + private SecurityContext ctx; /** * Loads the thumbnail for {@link #images}[index]. @@ -123,13 +127,13 @@ private void loadThumbail(ImageData image, long userID) sizeX = pxd.getSizeX(); sizeY = pxd.getSizeY(); } else { - Dimension d = Factory.computeThumbnailSize(sizeX, sizeY, + Dimension d = Factory.computeThumbnailSize(sizeX, sizeY, pxd.getSizeX(), pxd.getSizeY()); sizeX = d.width; sizeY = d.height; } try { - thumbPix = service.getThumbnail(pxd.getId(), sizeX, sizeY, + thumbPix = service.getThumbnail(ctx, pxd.getId(), sizeX, sizeY, userID); } catch (RenderingServiceException e) { context.getLogger().error(this, @@ -156,18 +160,16 @@ public void doCall() throws Exception { BufferedImage thumbPix = null; try { - thumbPix = service.getThumbnail(pixelsID, maxWidth, - maxHeight, -1); + thumbPix = service.getThumbnail(ctx, pixelsID, maxWidth, + maxHeight, -1); } catch (RenderingServiceException e) { context.getLogger().error(this, "Cannot retrieve thumbnail from ID: "+ - e.getExtendedMessage()); + e.getExtendedMessage()); } if (thumbPix == null) thumbPix = Factory.createDefaultImageThumbnail(-1); - //thumbPix = Factory.createDefaultThumbnail(maxWidth, - // maxHeight); currentThumbnail = thumbPix; } }; @@ -226,14 +228,15 @@ protected void buildTree() * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * - * @param imgs Contains {@link DataObject}s, one - * for each thumbnail to retrieve. - * @param maxWidth The maximum acceptable width of the thumbnails. + * @param ctx The security context. + * @param imgs Contains {@link DataObject}s, one + * for each thumbnail to retrieve. + * @param maxWidth The maximum acceptable width of the thumbnails. * @param maxHeight The maximum acceptable height of the thumbnails. - * @param userIDs The users the thumbnail are for. + * @param userIDs The users the thumbnail are for. */ - public ThumbnailLoader(Set imgs, int maxWidth, int maxHeight, - Set userIDs) + public ThumbnailLoader(SecurityContext ctx, Set imgs, + int maxWidth, int maxHeight, Set userIDs) { if (imgs == null) throw new NullPointerException("No images."); if (maxWidth <= 0) @@ -242,6 +245,7 @@ public ThumbnailLoader(Set imgs, int maxWidth, int maxHeight, if (maxHeight <= 0) throw new IllegalArgumentException( "Non-positive height: "+maxHeight+"."); + this.ctx = ctx; this.maxWidth = maxWidth; this.maxHeight = maxHeight; images = imgs; @@ -255,13 +259,16 @@ public ThumbnailLoader(Set imgs, int maxWidth, int maxHeight, * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * - * @param imgs Contains {@link DataObject}s, one - * for each thumbnail to retrieve. - * @param userID The user the thumbnail are for. + * @param ctx The security context. + * @param imgs Contains {@link DataObject}s, one for each thumbnail to + * retrieve. + * @param userID The user the thumbnail are for. */ - public ThumbnailLoader(Collection imgs, long userID) + public ThumbnailLoader(SecurityContext ctx, Collection imgs, + long userID) { if (imgs == null) throw new NullPointerException("No images."); + this.ctx = ctx; asImage = true; images = imgs; userIDs = new HashSet(1); @@ -274,14 +281,15 @@ public ThumbnailLoader(Collection imgs, long userID) * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * - * @param imgs Contains {@link DataObject}s, one - * for each thumbnail to retrieve. - * @param maxWidth The maximum acceptable width of the thumbnails. + * @param ctx The security context. + * @param imgs Contains {@link DataObject}s, one for each thumbnail to + * retrieve. + * @param maxWidth The maximum acceptable width of the thumbnails. * @param maxHeight The maximum acceptable height of the thumbnails. - * @param userID The user the thumbnail are for. + * @param userID The user the thumbnail are for. */ - public ThumbnailLoader(Collection imgs, int maxWidth, - int maxHeight, long userID) + public ThumbnailLoader(SecurityContext ctx, Collection imgs, + int maxWidth, int maxHeight, long userID) { if (imgs == null) throw new NullPointerException("No images."); if (maxWidth <= 0) @@ -290,6 +298,7 @@ public ThumbnailLoader(Collection imgs, int maxWidth, if (maxHeight <= 0) throw new IllegalArgumentException( "Non-positive height: "+maxHeight+"."); + this.ctx = ctx; this.maxWidth = maxWidth; this.maxHeight = maxHeight; images = imgs; @@ -304,13 +313,14 @@ public ThumbnailLoader(Collection imgs, int maxWidth, * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * - * @param image The {@link ImageData}, the thumbnail - * @param maxWidth The maximum acceptable width of the thumbnails. + * @param ctx The security context. + * @param image The {@link ImageData}, the thumbnail + * @param maxWidth The maximum acceptable width of the thumbnails. * @param maxHeight The maximum acceptable height of the thumbnails. - * @param userID The user the thumbnails are for. + * @param userID The user the thumbnails are for. */ - public ThumbnailLoader(ImageData image, int maxWidth, int maxHeight, - long userID) + public ThumbnailLoader(SecurityContext ctx, ImageData image, int maxWidth, + int maxHeight, long userID) { if (image == null) throw new IllegalArgumentException("No image."); if (maxWidth <= 0) @@ -319,6 +329,7 @@ public ThumbnailLoader(ImageData image, int maxWidth, int maxHeight, if (maxHeight <= 0) throw new IllegalArgumentException( "Non-positive height: "+maxHeight+"."); + this.ctx = ctx; userIDs = new HashSet(1); userIDs.add(userID); images = new HashSet(1); @@ -334,13 +345,14 @@ public ThumbnailLoader(ImageData image, int maxWidth, int maxHeight, * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * - * @param pixelsID The id of the pixel set. - * @param maxWidth The maximum acceptable width of the thumbnails. + * @param ctx The security context. + * @param pixelsID The id of the pixel set. + * @param maxWidth The maximum acceptable width of the thumbnails. * @param maxHeight The maximum acceptable height of the thumbnails. - * @param userID The user the thumbnail are for. + * @param userID The user the thumbnail are for. */ - public ThumbnailLoader(long pixelsID, int maxWidth, int maxHeight, - long userID) + public ThumbnailLoader(SecurityContext ctx, long pixelsID, int maxWidth, + int maxHeight, long userID) { if (maxWidth <= 0) throw new IllegalArgumentException( @@ -351,6 +363,7 @@ public ThumbnailLoader(long pixelsID, int maxWidth, int maxHeight, if (maxHeight <= 0) throw new IllegalArgumentException( "Non-positive height: "+maxHeight+"."); + this.ctx = ctx; pixelsCall = true; this.maxWidth = maxWidth; this.maxHeight = maxHeight; @@ -365,13 +378,14 @@ public ThumbnailLoader(long pixelsID, int maxWidth, int maxHeight, * If bad arguments are passed, we throw a runtime exception so to fail * early and in the caller's thread. * - * @param image The {@link ImageData}, the thumbnail - * @param maxWidth The maximum acceptable width of the thumbnails. + * @param ctx The security context. + * @param image The {@link ImageData}, the thumbnail + * @param maxWidth The maximum acceptable width of the thumbnails. * @param maxHeight The maximum acceptable height of the thumbnails. - * @param userIDs The users the thumbnail are for. + * @param userIDs The users the thumbnail are for. */ - public ThumbnailLoader(ImageData image, int maxWidth, int maxHeight, - Set userIDs) + public ThumbnailLoader(SecurityContext ctx, ImageData image, int maxWidth, + int maxHeight, Set userIDs) { if (image == null) throw new IllegalArgumentException("No image."); if (maxWidth <= 0) @@ -380,6 +394,7 @@ public ThumbnailLoader(ImageData image, int maxWidth, int maxHeight, if (maxHeight <= 0) throw new IllegalArgumentException( "Non-positive height: "+maxHeight+"."); + this.ctx = ctx; images = new HashSet(1); images.add(image); this.maxWidth = maxWidth; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ThumbnailSetLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ThumbnailSetLoader.java index 262535864a3..68f521cebcb 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ThumbnailSetLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/ThumbnailSetLoader.java @@ -41,6 +41,7 @@ import org.openmicroscopy.shoola.env.data.OmeroImageService; import org.openmicroscopy.shoola.env.data.login.UserCredentials; import org.openmicroscopy.shoola.env.data.model.ThumbnailData; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.RenderingServiceException; @@ -74,57 +75,60 @@ public class ThumbnailSetLoader * Indicates that the thumbnails are associated to an * ImageData. */ - public static final int IMAGE = 0; + public static final int IMAGE = 0; /** * Indicates that the thumbnails are associated to an * ExperimenterData. */ - public static final int EXPERIMENTER = 1; + public static final int EXPERIMENTER = 1; /** * Indicates that the thumbnails are associated to an FileData. */ - public static final int FS_FILE = 2; + public static final int FS_FILE = 2; /** Maximum number of thumbnails retrieved asynchronously. */ - private static final int FETCH_SIZE = 10; + private static final int FETCH_SIZE = 10; /** * Factor by which the maximum number of thumbnails to fetch * is multiplied with when the connection's speed is Low. */ - private static final double FETCH_LOW_SPEED = 0.25; + private static final double FETCH_LOW_SPEED = 0.25; /** * Factor by which the maximum number of thumbnails to fetch * is multiplied with when the connection's speed is Medium. */ - private static final double FETCH_MEDIUM_SPEED = 0.5; + private static final double FETCH_MEDIUM_SPEED = 0.5; /** Helper reference to the image service. */ - private OmeroImageService service; + private OmeroImageService service; /** The maximum acceptable length of the thumbnails. */ - private int maxLength; + private int maxLength; /** Collection of list of pixels set to handle. */ - private List toHandle; + private List toHandle; /** Key, value pairs, Key is the pixels set id. */ - private Map input; + private Map input; /** Collection of {@link ThumbnailData}s for not valid pixels set. */ - private List notValid; + private List notValid; /** Collection of current {@link ThumbnailData}s. */ - private Object currentThumbs; + private Object currentThumbs; /** The maximum number of the tumbnails fetched. */ - private int fetchSize; + private int fetchSize; /** The type of nodes to handle. */ - private Class type; + private Class type; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a default thumbnail for the passed image. @@ -202,8 +206,8 @@ private void loadFSThumbnails(List files) ExperimenterData exp = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); long id = exp.getId(); - Map m = service.getFSThumbnailSet(files, - maxLength, id); + Map m = service.getFSThumbnailSet(ctx, + files, maxLength, id); Entry entry; Iterator i = m.entrySet().iterator(); BufferedImage thumb; @@ -242,7 +246,7 @@ private void loadExperimenterThumbnails(List experimenters) ExperimenterData exp = (ExperimenterData) context.lookup( LookupNames.CURRENT_USER_DETAILS); Map m = - service.getExperimenterThumbnailSet(experimenters, + service.getExperimenterThumbnailSet(ctx, experimenters, maxLength); Entry entry; List result = new ArrayList(); @@ -278,7 +282,7 @@ private void loadExperimenterThumbnails(List experimenters) private void loadThumbails(List ids) { try { - Map m = service.getThumbnailSet(ids, maxLength); + Map m = service.getThumbnailSet(ctx, ids, maxLength); List result = new ArrayList(); Iterator i = m.keySet().iterator(); long pixelsID; @@ -357,18 +361,20 @@ public void doCall() { /** * Creates a new instance. * + * @param ctx The security context. * @param images The collection of images to load thumbnails for. * @param maxLength The maximum length of a thumbnail. * @param nodeType One of the constants defined by this class. */ - public ThumbnailSetLoader(Collection images, int maxLength, - int nodeType) + public ThumbnailSetLoader(SecurityContext ctx, + Collection images, int maxLength, int nodeType) { if (images == null) throw new NullPointerException("No images."); if (maxLength <= 0) throw new IllegalArgumentException( "Non-positive height: "+maxLength+"."); computeFetchSize(); + this.ctx = ctx; this.maxLength = maxLength; service = context.getImageService(); toHandle = new ArrayList(); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TileLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TileLoader.java index 4759ebecea8..4f793a0b0c4 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TileLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/TileLoader.java @@ -33,6 +33,7 @@ import omero.romio.PlaneDef; import omero.romio.RegionDef; import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; import org.openmicroscopy.shoola.env.rnd.data.Region; @@ -74,6 +75,9 @@ public class TileLoader /** The plane to render.*/ private PlaneDef pDef; + /** The security context.*/ + private SecurityContext ctx; + /** * Loads the tile. * @@ -85,7 +89,8 @@ private void loadTile(Tile tile) try { pDef.region = new RegionDef(rt.getX(), rt.getY(), rt.getWidth(), rt.getHeight()); - tile.setImage(service.renderImage(pixelsID, pDef, asTexture, false)); + tile.setImage(service.renderImage(ctx, pixelsID, pDef, asTexture, + false)); } catch (Exception e) { tile.setImage(Factory.createDefaultImageThumbnail(rt.getWidth(), rt.getHeight())); @@ -133,13 +138,14 @@ public void doCall() { /** * Creates a new instance. * + * @param ctx The security context. * @param pixelsID The id of the pixels set. * @param pDef The plane to render. * @param tiles The tiles. * @param asTexture Pass true to return a texture, * false to return a buffered image. */ - public TileLoader(long pixelsID, PlaneDef pDef, + public TileLoader(SecurityContext ctx, long pixelsID, PlaneDef pDef, Collection tiles, boolean asTexture) { if (pixelsID < 0) @@ -148,6 +154,7 @@ public TileLoader(long pixelsID, PlaneDef pDef, throw new IllegalArgumentException("No tiles to load."); if (pDef == null) throw new IllegalArgumentException("No plane to render."); + this.ctx = ctx; this.pixelsID = pixelsID; this.tiles = tiles; this.asTexture = asTexture; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/WorkflowHandler.java b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/WorkflowHandler.java index 7e3915256e0..a64e95d021a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/WorkflowHandler.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/data/views/calls/WorkflowHandler.java @@ -31,6 +31,7 @@ //Application-internal dependencies import pojos.WorkflowData; import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.BatchCall; import org.openmicroscopy.shoola.env.data.views.BatchCallTree; @@ -52,10 +53,13 @@ public class WorkflowHandler { /** The result of the call. */ - private Object result; + private Object result; /** Loads the specified experimenter groups. */ - private BatchCall loadCall; + private BatchCall loadCall; + + /** The security context.*/ + private SecurityContext ctx; /** * Creates a {@link BatchCall} to retrieve or store the workflows.. @@ -70,26 +74,26 @@ private BatchCall makeCall(final long userID) public void doCall() throws Exception { OmeroImageService os = context.getImageService(); - result = os.retrieveWorkflows(userID); + result = os.retrieveWorkflows(ctx, userID); } }; } /** - * Creates a {@link BatchCall} to retrieve or store the workflows.. + * Creates a {@link BatchCall} to retrieve or store the workflows. * - * @param userID The id of the user to retrieve workflows for.. + * @param userID The id of the user to retrieve workflows for * @param index One of the constants defined by the script. * @return The {@link BatchCall}. */ - private BatchCall makeCall(final List workflows, + private BatchCall makeCall(final List workflows, final long userID) { return new BatchCall("Run the script") { public void doCall() throws Exception { OmeroImageService os = context.getImageService(); - result = os.storeWorkflows(workflows, userID); + result = os.storeWorkflows(ctx, workflows, userID); } }; } @@ -110,27 +114,32 @@ public void doCall() throws Exception /** * Creates a new instance. * + * @param ctx The security context. * @param userID The userID of the workflows to retrieve. */ - public WorkflowHandler(long userID) + public WorkflowHandler(SecurityContext ctx, long userID) { if (userID < 0) - throw new IllegalArgumentException("invalid userID specified."); + throw new IllegalArgumentException("invalid userID specified."); + this.ctx = ctx; loadCall = makeCall(userID); } /** * Creates a new instance. * + * @param ctx The security context. * @param workflows The workflows to store. * @param userID The userID to store under. */ - public WorkflowHandler(List workflows, long userID) + public WorkflowHandler(SecurityContext ctx, List workflows, + long userID) { if (userID < 0) - throw new IllegalArgumentException("invalid userID specified."); + throw new IllegalArgumentException("invalid userID specified."); if (workflows == null || workflows.size() == 0) - throw new IllegalArgumentException("Invalid workflows specified."); + throw new IllegalArgumentException("Invalid workflows specified."); + this.ctx = ctx; loadCall = makeCall(workflows, userID); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/init/DataServicesInit.java b/components/insight/SRC/org/openmicroscopy/shoola/env/init/DataServicesInit.java index db1668b7bcc..765e64f67b9 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/init/DataServicesInit.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/init/DataServicesInit.java @@ -110,7 +110,7 @@ void rollback() try { DataServicesFactory factory = DataServicesFactory.getInstance(container); - factory.shutdown(); + factory.shutdown(null); } catch (DSOutOfServiceException e) {} } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/data/DataSink.java b/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/data/DataSink.java index b727cf6d921..cce6e149317 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/data/DataSink.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/data/DataSink.java @@ -32,6 +32,7 @@ import org.openmicroscopy.shoola.env.cache.CacheService; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.OmeroImageService; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.mem.ReadOnlyByteArray; import pojos.PixelsData; @@ -178,15 +179,17 @@ private Integer linearize(int z, int w, int t) /** * Factory method to fetch plane data and create an object to access it. * - * @param z The z-section at which data is to be fetched. - * @param t The timepoint at which data is to be fetched. - * @param w The wavelength at which data is to be fetched. - * @param strategy To transform bytes into pixels values. + * @param ctx The security context. + * @param z The z-section at which data is to be fetched. + * @param t The timepoint at which data is to be fetched. + * @param w The wavelength at which data is to be fetched. + * @param strategy To transform bytes into pixels values. * @return A plane 2D object that encapsulates the actual plane pixels. * @throws DataSourceException If an error occurs while retrieving the * plane data from the pixels source. */ - private Plane2D createPlane(int z, int t, int w, BytesConverter strategy) + private Plane2D createPlane(SecurityContext ctx, int z, int t, int w, + BytesConverter strategy) throws DataSourceException { //Retrieve data @@ -197,7 +200,7 @@ private Plane2D createPlane(int z, int t, int w, BytesConverter strategy) byte[] data = null; try { OmeroImageService service = context.getImageService(); - data = service.getPlane(source.getId(), z, t, w); + data = service.getPlane(ctx, source.getId(), z, t, w); } catch (Exception e) { String p = "("+z+", "+t+", "+w+")"; throw new DataSourceException("Cannot retrieve the plane "+p, e); @@ -213,17 +216,18 @@ private Plane2D createPlane(int z, int t, int w, BytesConverter strategy) /** * Extracts a 2D plane from the pixels set this object is working for. * - * @param z The z-section at which data is to be fetched. - * @param t The timepoint at which data is to be fetched. - * @param w The wavelength at which data is to be fetched. + * @param ctx The security context. + * @param z The z-section at which data is to be fetched. + * @param t The timepoint at which data is to be fetched. + * @param w The wavelength at which data is to be fetched. * @return A plane 2D object that encapsulates the actual plane pixels. * @throws DataSourceException If an error occurs while retrieving the * plane data from the pixels source. */ - public Plane2D getPlane(int z, int t, int w) + public Plane2D getPlane(SecurityContext ctx, int z, int t, int w) throws DataSourceException { - return createPlane(z, t, w, strategy); + return createPlane(ctx, z, t, w, strategy); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/roi/PointIterator.java b/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/roi/PointIterator.java index 8d44ccb3bf9..1eb9c4feaa9 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/roi/PointIterator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/roi/PointIterator.java @@ -35,6 +35,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.data.DataSink; import org.openmicroscopy.shoola.env.rnd.data.DataSourceException; import org.openmicroscopy.shoola.env.rnd.data.Plane2D; @@ -70,10 +71,10 @@ class PointIterator private DataSink source; /** The number of z-sections. */ - private int sizeZ; + private int sizeZ; /** The number of timepoints. */ - private int sizeT; + private int sizeT; /** The number of pixels along the x-axis. */ private int sizeX; @@ -272,13 +273,15 @@ void clearNotificationList() * All registered {@link PointIteratorObserver}s get notified of every * iterated pixels value. * - * @param shape The shape to analyse. Mustn't be null. - * @param points The collection of points contained in the shape. - * @param w The selected channel. + * @param ctx The security context. + * @param shape The shape to analyze. Mustn't be null. + * @param points The collection of points contained in the shape. + * @param w The selected channel. * @throws DataSourceException If an error occurs while retrieving plane * data from the pixels source. */ - public void iterate(ROIShape shape, List points, int w) + public void iterate(SecurityContext ctx, ROIShape shape, List points, + int w) throws DataSourceException { if (shape == null) throw new NullPointerException("No shapes."); @@ -290,7 +293,7 @@ public void iterate(ROIShape shape, List points, int w) int t = shape.getT(); if (z >= 0 && z < sizeZ && t >= 0 && t < sizeT) { notifyPlaneStart(z, w, t, points.size()); - Plane2D data = source.getPlane(z, t, w); + Plane2D data = source.getPlane(ctx, z, t, w); double value; int length = 0; int x1, x2; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/roi/ROIAnalyser.java b/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/roi/ROIAnalyser.java index f1a0864de33..8d05da0447f 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/roi/ROIAnalyser.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/rnd/roi/ROIAnalyser.java @@ -33,6 +33,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.data.DataSink; import org.openmicroscopy.shoola.env.rnd.data.DataSourceException; import org.openmicroscopy.shoola.util.roi.model.ROIShape; @@ -131,16 +132,18 @@ public ROIAnalyser(DataSink source, int sizeZ, int sizeT, int sizeC, int * Computes an {@link ROIShapeStats} object for each {@link ROIShape} * specified * - * @param shapes The shapes to analyse. - * @param channels Collection of selected channels. - * @return A map whose keys are the {@link ROIShape} objects specified - * and whose values are a map (keys: channel index, value - * the corresponding {@link ROIShapeStats} objects computed by - * this method). + * @param ctx The security context. + * @param shapes The shapes to analyze. + * @param channels Collection of selected channels. + * @return A map whose keys are the {@link ROIShape} objects specified + * and whose values are a map (keys: channel index, value + * the corresponding {@link ROIShapeStats} objects computed by + * this method). * @throws DataSourceException If an error occurs while retrieving plane * data from the pixels source. */ - public Map analyze(ROIShape[] shapes, List channels) + public Map analyze(SecurityContext ctx, ROIShape[] shapes, + List channels) throws DataSourceException { if (shapes == null) throw new NullPointerException("No shapes."); @@ -166,7 +169,7 @@ public Map analyze(ROIShape[] shapes, List channels) if (checkChannel(w.intValue())) { computer = new ROIShapeStats(); runner.register(computer); - runner.iterate(shape, points, w.intValue()); + runner.iterate(ctx, shape, points, w.intValue()); runner.remove(computer); stats.put(w, computer); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ActivityComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ActivityComponent.java index fcc7ac127f3..ad8e28948d5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ActivityComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ActivityComponent.java @@ -63,6 +63,7 @@ import org.openmicroscopy.shoola.env.data.ProcessException; import org.openmicroscopy.shoola.env.data.model.ApplicationData; import org.openmicroscopy.shoola.env.data.model.DownloadActivityParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.util.filter.file.CSVFilter; import org.openmicroscopy.shoola.util.ui.UIUtilities; @@ -166,6 +167,9 @@ public abstract class ActivityComponent /** Convenience reference for subclasses. */ protected final Registry registry; + /** Convenience reference for subclasses. */ + protected final SecurityContext ctx; + /** Convenience reference for subclasses. */ protected final UserNotifier viewer; @@ -257,7 +261,7 @@ private void open(Object object, Object parameters, JComponent source) activity.setApplicationData((ApplicationData) parameters); } activity.setSource(source); - viewer.notifyActivity(activity); + viewer.notifyActivity(ctx, activity); } /** @@ -410,18 +414,19 @@ private void showException() /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param registry Convenience reference for subclasses. - * @param text The text of the activity. - * @param icon The icon to display then done. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param ctx The security context. */ - ActivityComponent(UserNotifier viewer, Registry registry) + ActivityComponent(UserNotifier viewer, Registry registry, + SecurityContext ctx) { if (viewer == null) throw new NullPointerException("No viewer."); if (registry == null) throw new NullPointerException("No registry."); this.viewer = viewer; this.registry = registry; + this.ctx = ctx; } /** @@ -598,7 +603,7 @@ void download(String text, Object object, File folder) } activity.setLegend(desc); activity.setUIRegister(false); - viewer.notifyActivity(activity); + viewer.notifyActivity(ctx, activity); return; } JFrame f = registry.getTaskBar().getFrame(); @@ -628,7 +633,7 @@ public void propertyChange(PropertyChangeEvent evt) { folder, icons.getIcon(IconManager.DOWNLOAD_22)); } activity.setLegend(desc); - viewer.notifyActivity(activity); + viewer.notifyActivity(ctx, activity); } } }); @@ -662,7 +667,7 @@ void view(Object object, JComponent source) if (source != null) source.setEnabled(true); } else { EventBus bus = registry.getEventBus(); - bus.post(new ViewObjectEvent(object, source)); + bus.post(new ViewObjectEvent(ctx, object, source)); } } @@ -675,7 +680,7 @@ void view(Object object, JComponent source) void browse(Object object, JComponent source) { EventBus bus = registry.getEventBus(); - ViewObjectEvent evt = new ViewObjectEvent(object, source); + ViewObjectEvent evt = new ViewObjectEvent(ctx, object, source); evt.setBrowseObject(true); bus.post(evt); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/Analyser.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/Analyser.java deleted file mode 100644 index 22e1dca301d..00000000000 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/Analyser.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * org.openmicroscopy.shoola.env.ui.Analyser - * - *------------------------------------------------------------------------------ - * Copyright (C) 2006-2009 University of Dundee. All rights reserved. - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - *------------------------------------------------------------------------------ - */ -package org.openmicroscopy.shoola.env.ui; - -//Java imports -import java.util.List; - -//Third-party libraries - -//Application-internal dependencies -import org.openmicroscopy.shoola.env.config.Registry; -import org.openmicroscopy.shoola.env.data.ScriptCallback; -import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; -import org.openmicroscopy.shoola.env.data.model.AnalysisParam; -import org.openmicroscopy.shoola.env.data.views.CallHandle; - -/** - * Analyzes the passed objects. - * - * @author Jean-Marie Burel      - * j.burel@dundee.ac.uk - * @author Donald MacDonald      - * donald@lifesci.dundee.ac.uk - * @version 3.0 - * - * (Internal version: $Revision: $Date: $) - * - * @since 3.0-Beta4 - */ -public class Analyser - extends UserNotifierLoader -{ - - /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; - - /** The parameters to use.*/ - private Object param; - - /** The select objects. */ - private List ids; - - /** The type of object to handle. */ - private Class type; - - /** The type of analysis to perform. */ - private int index; - - /** The call-back returned by the server. */ - private ScriptCallback callBack; - - /** - * Notifies that an error occurred. - * @see UserNotifierLoader#onException(String, Exception) - */ - protected void onException(String message, Throwable ex) - { - activity.notifyError("Unable to analyse data", message, ex); - } - - /** Notifies the user that an error occurred. */ - protected void onException() { handleNullResult(); } - - /** - * Creates a new instance. - * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param registry Convenience reference for subclasses. - * @param param The parameters used to create the movie. - * @param ids The selected objects. - * @param type The type of objects. - * @param index The type of analysis to perform. - * @param activity The activity associated to this loader. - */ - public Analyser(UserNotifier viewer, Registry registry, - Object param, List ids, Class type, int index, - ActivityComponent activity) - { - super(viewer, registry, activity); - if (ids == null || ids.size() == 0) - throw new IllegalArgumentException("Objects not valid."); - if (param == null) - throw new IllegalArgumentException("Parameters cannot be null."); - this.param = param; - this.ids = ids; - this.type = type; - this.index = index; - } - - /** - * Creates a figure of the selected images. - * @see UserNotifierLoader#load() - */ - public void load() - { - switch (index) { - case AnalysisParam.FLIM: - break; - case AnalysisParam.FRAP: - handle = ivView.analyseFRAP(ids, type, param, this); - break; - } - } - - /** - * Cancels the ongoing data retrieval. - * @see UserNotifierLoader#cancel() - */ - public void cancel() - { - try { - if (callBack != null) { - callBack.cancel(); - activity.onActivityCancelled(); - } - } catch (Exception e) { - handleException(e); - } - handle.cancel(); - } - - /** - * Sets the call-back. - * @see UserNotifierLoader#update(DSCallFeedbackEvent) - */ - public void update(DSCallFeedbackEvent fe) - { - //if (viewer.getState() == DataBrowser.DISCARDED) return; //Async cancel. - Object o = fe.getPartialResult(); - if (o != null) { - if (o instanceof Boolean) { - Boolean b = (Boolean) o; - if (!b.booleanValue()) - onException(MESSAGE_RUN, null); - } else { - callBack = (ScriptCallback) o; - callBack.setAdapter(this); - activity.onCallBackSet(); - } - } - } - - /** - * Feeds the result back to the viewer. - * @see UserNotifierLoader#handleResult(Object) - */ - public void handleResult(Object result) - { - if (result == null) onException(MESSAGE_RESULT, null); - else if (!(result instanceof Boolean)) { - activity.endActivity(result); - } - } - -} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/AnalysisActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/AnalysisActivity.java index df7f17a1ad5..00a93bd39ec 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/AnalysisActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/AnalysisActivity.java @@ -36,6 +36,7 @@ import org.openmicroscopy.shoola.env.data.model.AnalysisActivityParam; import org.openmicroscopy.shoola.env.data.model.AnalysisParam; import org.openmicroscopy.shoola.env.data.model.DownloadActivityParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.ui.filechooser.FileChooser; import pojos.FileAnnotationData; @@ -71,15 +72,16 @@ public class AnalysisActivity /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param registry Convenience reference for subclasses. - * @param parameters The parameters used to analyze. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param ctx The security context. + * @param parameters The parameters used to analyze. */ public AnalysisActivity(UserNotifier viewer, Registry registry, - AnalysisActivityParam parameters) + SecurityContext ctx, AnalysisActivityParam parameters) { - super(viewer, registry); + super(viewer, registry, ctx); if (parameters == null) throw new IllegalArgumentException("Parameters not valid."); this.parameters = parameters; @@ -92,11 +94,7 @@ public AnalysisActivity(UserNotifier viewer, Registry registry, */ protected UserNotifierLoader createLoader() { - AnalysisParam param = (AnalysisParam) parameters.getParameters(); - loader = new Analyser(viewer, registry, param, - param.getIds(), param.getNodeType(), param.getIndex(), - this); - return loader; + return null; } /** @@ -143,7 +141,7 @@ public void propertyChange(PropertyChangeEvent evt) { activity.setLegend(data.getDescription()); activity.setLegendExtension( DownloadActivity.LEGEND_TEXT_CSV); - viewer.notifyActivity(activity); + viewer.notifyActivity(ctx, activity); } } }); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ArchivedLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ArchivedLoader.java index 47a2240cad7..a986f82b12d 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ArchivedLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ArchivedLoader.java @@ -32,6 +32,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ImageData; @@ -74,17 +75,19 @@ protected void onException(String message, Throwable ex) /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param registry Convenience reference for subclasses. - * @param image The image to export. - * @param folderPath The location where to export the image. - * @param activity The activity associated to this loader. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param ctx The security context. + * @param image The image to export. + * @param folderPat The location where to export the image. + * @param activity The activity associated to this loader. */ public ArchivedLoader(UserNotifier viewer, Registry registry, - ImageData image, String folderPath, ActivityComponent activity) + SecurityContext ctx, ImageData image, String folderPath, + ActivityComponent activity) { - super(viewer, registry, activity); + super(viewer, registry, ctx, activity); if (image == null) throw new IllegalArgumentException("Image not valid."); this.image = image; @@ -98,7 +101,7 @@ public ArchivedLoader(UserNotifier viewer, Registry registry, public void load() { long id = image.getDefaultPixels().getId(); - handle = mhView.loadArchivedImage(id, folderPath, this); + handle = mhView.loadArchivedImage(ctx, id, folderPath, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ChangesDialog.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ChangesDialog.java index 594cbfad43e..9b1b34daea7 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ChangesDialog.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ChangesDialog.java @@ -39,6 +39,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.util.AgentSaveInfo; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.ui.UIUtilities; /** @@ -76,6 +77,9 @@ class ChangesDialog /** The nodes to handle. */ private List nodes; + /** The security context.*/ + private SecurityContext ctx; + /** Sets the properties of the dialog. */ private void setProperties() { @@ -107,13 +111,15 @@ private void buildGUI() /** * Creates a new instance. * - * @param owner The owner of the dialog. + * @param owner The owner of the dialog. * @param totalTask The number of tasks to perform. + * @param ctx The security context. */ - ChangesDialog(JFrame owner, List nodes) + ChangesDialog(JFrame owner, List nodes, SecurityContext ctx) { super(owner); count = 0; + this.ctx = ctx; this.nodes = nodes; setProperties(); initComponents(); @@ -137,8 +143,7 @@ void setStatus(Object node) } if (nodes.size() == 0) { - firePropertyChange(DONE_PROPERTY, Boolean.valueOf(false), - Boolean.valueOf(true)); + firePropertyChange(DONE_PROPERTY, null, ctx); } else { status.setText(text); progressBar.setValue(count); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataObjectRemover.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataObjectRemover.java index c6ab0e12f6b..f6f755074fc 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataObjectRemover.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataObjectRemover.java @@ -23,7 +23,12 @@ package org.openmicroscopy.shoola.env.ui; //Java imports +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; //Third-party libraries @@ -31,9 +36,12 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.model.DeletableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.ProcessCallback; +import pojos.DataObject; + /** * Deletes a collection of objects. * @@ -52,13 +60,36 @@ public class DataObjectRemover { /** Handle to the asynchronous call so that we can cancel it. */ - private CallHandle handle; + private CallHandle handle; /** The call-back returned by the server. */ - private ProcessCallback callBack; + private List callBacks; /** The collection of objects to delete. */ - private List objects; + private Map> objects; + + /** The number of callbacks.*/ + private int number; + + /** + * Returns the SecurityContext if already added or null. + * + * @param map The map to check. + * @param id The group's identifier. + * @return See above. + */ + private SecurityContext getKey( + Map> map, long id) + { + Iterator i = map.keySet().iterator(); + SecurityContext ctx; + while (i.hasNext()) { + ctx = i.next(); + if (ctx.getGroupID() == id) + return ctx; + } + return null; + } /** * Notifies that an error occurred. @@ -78,13 +109,36 @@ protected void onException(String message, Throwable ex) * @param objects The collection of objects to delete. * @param activity The activity associated to this loader. */ - public DataObjectRemover(UserNotifier viewer, Registry registry, - List objects, ActivityComponent activity) + public DataObjectRemover(UserNotifier viewer, Registry registry, + List objects, + ActivityComponent activity) { - super(viewer, registry, activity); + super(viewer, registry, null, activity); if (objects == null || objects.size() == 0) throw new IllegalArgumentException("No Objects to delete."); - this.objects = objects; + callBacks = new ArrayList(); + Map> + map = new HashMap>(); + Iterator i = objects.iterator(); + DeletableObject o; + DataObject ho; + long groupId; + SecurityContext ctx; + Collection l; + while (i.hasNext()) { + o = i.next(); + ho = o.getObjectToDelete(); + groupId = ho.getGroupId(); + ctx = getKey(map, groupId); + if (ctx == null) { + l = new ArrayList(); + ctx = new SecurityContext(groupId); + map.put(ctx, l); + } + l = map.get(ctx); + l.add(o); + } + this.objects = map; } /** @@ -103,10 +157,14 @@ public void load() public void cancel() { try { - if (callBack != null) { - callBack.cancel(); - activity.onActivityCancelled(); - } + Iterator i = callBacks.iterator(); + ProcessCallback callback; + while (i.hasNext()) { + callback = i.next(); + if (callback != null) + callback.cancel(); + } + activity.onActivityCancelled(); } catch (Exception e) { handleException(e); } @@ -124,11 +182,14 @@ public void update(DSCallFeedbackEvent fe) if (o instanceof Boolean) { Boolean b = (Boolean) o; if (!b.booleanValue()) - onException(MESSAGE_RUN, null); + onException("", null); } else { - callBack = (ProcessCallback) o; + ProcessCallback callBack = (ProcessCallback) o; callBack.setAdapter(this); - activity.onCallBackSet(); + callBacks.add(callBack); + number++; + if (number == objects.size()) + activity.onCallBackSet(); } } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataObjectTransfer.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataObjectTransfer.java new file mode 100644 index 00000000000..57dc35ee2ea --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataObjectTransfer.java @@ -0,0 +1,161 @@ +/* + * org.openmicroscopy.shoola.env.ui.DataObjectTransfer + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.env.ui; + + +//Java imports +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.env.config.Registry; +import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; +import org.openmicroscopy.shoola.env.data.model.TransferableObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; +import org.openmicroscopy.shoola.env.data.views.CallHandle; +import org.openmicroscopy.shoola.env.data.views.ProcessCallback; + + +/** + * Moves data between groups. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class DataObjectTransfer + extends UserNotifierLoader +{ + + /** Handle to the asynchronous call so that we can cancel it. */ + private CallHandle handle; + + /** The call-back returned by the server. */ + private List callBacks; + + /** The object to transfer. */ + private TransferableObject object; + + /** The number of callbacks.*/ + private int number; + + /** + * Notifies that an error occurred. + * @see UserNotifierLoader#onException(String) + */ + protected void onException(String message, Throwable ex) + { + activity.notifyError("Unable to transfer the objects", message, ex); + } + + /** + * Creates a new instance. + * + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param object The objects to transfer. + * @param activity The activity associated to this loader. + */ + public DataObjectTransfer(UserNotifier viewer, Registry registry, + TransferableObject object, ActivityComponent activity) + { + super(viewer, registry, null, activity); + if (object == null) + throw new IllegalArgumentException("No Objects to transfer."); + callBacks = new ArrayList(); + this.object = object; + } + + /** + * Transfers the objects. + * @see UserNotifierLoader#load() + */ + public void load() + { + handle = dmView.changeGroup(object, this); + } + + /** + * Cancels the on-going data retrieval. + * @see UserNotifierLoader#cancel() + */ + public void cancel() + { + try { + Iterator i = callBacks.iterator(); + ProcessCallback callback; + while (i.hasNext()) { + callback = i.next(); + if (callback != null) + callback.cancel(); + } + activity.onActivityCancelled(); + } catch (Exception e) { + handleException(e); + } + handle.cancel(); + } + + /** + * Stores the call-back. + * @see UserNotifierLoader#update(DSCallFeedbackEvent) + */ + public void update(DSCallFeedbackEvent fe) + { + Object o = fe.getPartialResult(); + if (o != null) { + if (o instanceof Boolean) { + Boolean b = (Boolean) o; + if (!b.booleanValue()) + onException("", null); + } else { + ProcessCallback callBack = (ProcessCallback) o; + callBack.setAdapter(this); + callBacks.add(callBack); + number++; + if (number == object.getSource().size()) + activity.onCallBackSet(); + } + } + } + + /** + * Feeds the result back to the viewer. + * @see UserNotifierLoader#handleResult(Object) + */ + public void handleResult(Object result) + { + if (result == null) onException(MESSAGE_RESULT, null); + else if (!(result instanceof Boolean)) { + activity.endActivity(result); + } + } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataTransferActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataTransferActivity.java new file mode 100644 index 00000000000..f928f8bd86b --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DataTransferActivity.java @@ -0,0 +1,131 @@ +/* + * org.openmicroscopy.shoola.env.ui.DataTransferActivity + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.env.ui; + +//Java imports +import java.util.Collection; +import javax.swing.Icon; + +//Third-party libraries + +//Application-internal dependencies +import org.openmicroscopy.shoola.env.config.Registry; +import org.openmicroscopy.shoola.env.data.model.TransferableActivityParam; + +/** + * Activity to move data between groups. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +public class DataTransferActivity + extends ActivityComponent +{ + + /** The description of the activity. */ + private static final String DESCRIPTION_START = "Moving data to "; + + /** The description of the activity when finished. */ + private static final String DESCRIPTION_END = "Moved completed"; + + /** The description of the activity when error occurred. */ + private static final String DESCRIPTION_ERROR = + "Unable to transfer data"; + + /** The description of the activity when cancelled. */ + private static final String DESCRIPTION_CANCEL = "Move cancelled"; + + /** The parameters hosting information about the transfer. */ + private TransferableActivityParam parameters; + + /** + * Creates a new instance. + * + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param parameters The parameters used to delete. + */ + public DataTransferActivity(UserNotifier viewer, Registry registry, + TransferableActivityParam parameters) + { + super(viewer, registry, null); + if (parameters == null) + throw new IllegalArgumentException("Parameters not valid."); + this.parameters = parameters; + initialize(DESCRIPTION_START+parameters.getGroupName(), + parameters.getIcon()); + int n = parameters.getNumber(); + String end = ""; + if (n > 1) end = "s"; + messageLabel.setText("move "+n+" object"+end); + } + + /** + * Creates a concrete loader. + * @see ActivityComponent#createLoader() + */ + protected UserNotifierLoader createLoader() + { + loader = new DataObjectTransfer(viewer, registry, + parameters.getObject(), this); + return loader; + } + + /** + * Modifies the text of the component. + * @see ActivityComponent#notifyActivityEnd() + */ + protected void notifyActivityEnd() + { + Collection l = (Collection) result; + if (l.size() > 0) { + type.setText(DESCRIPTION_ERROR); + notifyActivityError(); + } else { + type.setText(DESCRIPTION_END); + } + //post an event to remove nodes + } + + /** + * Modifies the text of the component. + * @see ActivityComponent#notifyActivityCancelled() + */ + protected void notifyActivityCancelled() + { + type.setText(DESCRIPTION_CANCEL); + } + + /** + * Modifies the text of the component. + * @see ActivityComponent#notifyActivityError() + */ + protected void notifyActivityError() + { + Icon icon = parameters.getFailureIcon(); + if (icon != null) iconLabel.setIcon(icon); + } +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DeleteActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DeleteActivity.java index 43a2bfbcfb7..836279ea822 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DeleteActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DeleteActivity.java @@ -126,7 +126,7 @@ private String createMessage() public DeleteActivity(UserNotifier viewer, Registry registry, DeleteActivityParam parameters) { - super(viewer, registry); + super(viewer, registry, null); if (parameters == null) throw new IllegalArgumentException("Parameters not valid."); this.parameters = parameters; @@ -155,7 +155,7 @@ public DeleteActivity(UserNotifier viewer, Registry registry, protected UserNotifierLoader createLoader() { List objects = parameters.getObjects(); - loader = new DataObjectRemover(viewer, registry, objects, this); + loader = new DataObjectRemover(viewer, registry, objects, this); return loader; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadActivity.java index 588e211d2d5..ba5114729d3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadActivity.java @@ -40,6 +40,7 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.ApplicationData; import org.openmicroscopy.shoola.env.data.model.DownloadActivityParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.filter.file.CustomizedFileFilter; import org.openmicroscopy.shoola.util.filter.file.HTMLFilter; import org.openmicroscopy.shoola.util.filter.file.JPEGFilter; @@ -171,15 +172,16 @@ private boolean canOpenFile(String path) /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param registry Convenience reference for subclasses. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param parameters The parameters used to export the image. */ public DownloadActivity(UserNotifier viewer, Registry registry, - DownloadActivityParam parameters) + SecurityContext ctx, DownloadActivityParam parameters) { - super(viewer, registry); + super(viewer, registry, ctx); if (parameters == null) throw new IllegalArgumentException("Parameters not valid."); this.parameters = parameters; @@ -211,12 +213,12 @@ protected UserNotifierLoader createLoader() switch (parameters.getIndex()) { case DownloadActivityParam.FILE_ANNOTATION: case DownloadActivityParam.ORIGINAL_FILE: - loader = new FileLoader(viewer, registry, file, + loader = new FileLoader(viewer, registry, ctx, file, parameters.getId(), parameters.getIndex(), load, this); break; default: - loader = new FileLoader(viewer, registry, file, + loader = new FileLoader(viewer, registry, ctx, file, f.getId().getValue(), f.getSize().getValue(), load, this); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadAndZipActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadAndZipActivity.java index fff9e1e4e98..1c3948638d4 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadAndZipActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadAndZipActivity.java @@ -38,6 +38,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.DownloadAndZipParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.file.IOUtil; import pojos.FileAnnotationData; @@ -73,14 +74,16 @@ public class DownloadAndZipActivity /** * Creates a new instance. * - * @param viewer - * @param registry - * @param parameters + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param ctx The security context. + * @param parameters The parameters used to delete. */ public DownloadAndZipActivity(UserNotifier viewer, Registry registry, - DownloadAndZipParam parameters) + SecurityContext ctx, DownloadAndZipParam parameters) { - super(viewer, registry); + super(viewer, registry, ctx); if (parameters == null) throw new IllegalArgumentException("No parameters"); this.parameters = parameters; @@ -113,7 +116,7 @@ protected UserNotifierLoader createLoader() fa = i.next(); toLoad.put(fa, new File(zipFolder, fa.getFileName())); } - loader = new FilesLoader(viewer, registry, toLoad, this); + loader = new FilesLoader(viewer, registry, ctx, toLoad, this); return loader; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadArchivedActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadArchivedActivity.java index ebae7931cb4..600936d1c5a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadArchivedActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/DownloadArchivedActivity.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.DownloadArchivedActivityParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; /** * Downloads the archived image. @@ -67,13 +68,14 @@ public class DownloadArchivedActivity * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param parameters The object hosting information about the * archived image. */ DownloadArchivedActivity(UserNotifier viewer, Registry registry, - DownloadArchivedActivityParam parameters) + SecurityContext ctx, DownloadArchivedActivityParam parameters) { - super(viewer, registry); + super(viewer, registry, ctx); if (parameters == null) throw new IllegalArgumentException("No parameters"); this.parameters = parameters; @@ -88,8 +90,8 @@ public class DownloadArchivedActivity */ protected UserNotifierLoader createLoader() { - loader = new ArchivedLoader(viewer, registry, parameters.getImage(), - parameters.getLocation(), this); + loader = new ArchivedLoader(viewer, registry, ctx, + parameters.getImage(), parameters.getLocation(), this); return loader; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ExportActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ExportActivity.java index 6981811990b..cad41f1d981 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ExportActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ExportActivity.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.ExportActivityParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.filter.file.OMETIFFFilter; @@ -100,15 +101,16 @@ private String getFileName() /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param registry Convenience reference for subclasses. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param parameters The parameters used to export the image. */ public ExportActivity(UserNotifier viewer, Registry registry, - ExportActivityParam parameters) + SecurityContext ctx, ExportActivityParam parameters) { - super(viewer, registry); + super(viewer, registry, ctx); if (parameters == null) throw new IllegalArgumentException("Parameters not valid."); this.parameters = parameters; @@ -127,7 +129,8 @@ public ExportActivity(UserNotifier viewer, Registry registry, */ protected UserNotifierLoader createLoader() { - loader = new ExportLoader(viewer, registry, parameters.getImage(), + loader = new ExportLoader(viewer, registry, ctx, + parameters.getImage(), new File(getFileName()), ExportLoader.EXPORT_AS_OME_TIFF, this); return loader; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ExportLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ExportLoader.java index c789c2a2574..090fe201d09 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ExportLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ExportLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ImageData; @@ -91,16 +92,17 @@ protected void onException(String message, Throwable ex) * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param image The image to export. * @param file The file where to export the image. * @param index One of the constants defined by this class. * @param activity The activity associated to this loader. */ public ExportLoader(UserNotifier viewer, Registry registry, - ImageData image, File file, int index, + SecurityContext ctx, ImageData image, File file, int index, ActivityComponent activity) { - super(viewer, registry, activity); + super(viewer, registry, ctx, activity); if (image == null) throw new IllegalArgumentException("Image not valid."); this.image = image; @@ -114,7 +116,7 @@ public ExportLoader(UserNotifier viewer, Registry registry, */ public void load() { - handle = ivView.exportImageAsOMETiff(image.getId(), file, this); + handle = ivView.exportImageAsOMETiff(ctx, image.getId(), file, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FigureActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FigureActivity.java index e6aaac007a3..ee9f3e66ce0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FigureActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FigureActivity.java @@ -30,6 +30,8 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.FigureActivityParam; import org.openmicroscopy.shoola.env.data.model.FigureParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.DataObject; import pojos.DatasetData; import pojos.ImageData; @@ -68,15 +70,16 @@ public class FigureActivity /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param registry Convenience reference for subclasses. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param parameters The parameters used to create a figure. */ public FigureActivity(UserNotifier viewer, Registry registry, - FigureActivityParam parameters) + SecurityContext ctx, FigureActivityParam parameters) { - super(viewer, registry); + super(viewer, registry, ctx); if (parameters == null) throw new IllegalArgumentException("Parameters not valid."); this.parameters = parameters; @@ -89,7 +92,8 @@ public FigureActivity(UserNotifier viewer, Registry registry, */ protected UserNotifierLoader createLoader() { - loader = new FigureCreator(viewer, registry, parameters.getParameters(), + loader = new FigureCreator(viewer, registry, ctx, + parameters.getParameters(), parameters.getIds(), parameters.getObjectType(), this); return loader; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FigureCreator.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FigureCreator.java index 413e8b5724c..c480983b683 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FigureCreator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FigureCreator.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.ProcessCallback; @@ -80,16 +81,17 @@ protected void onException(String message, Throwable ex) * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param param The parameters used to create the movie. * @param ids The selected objects. * @param type The type of objects. * @param activity The activity associated to this loader. */ public FigureCreator(UserNotifier viewer, Registry registry, - Object param, List ids, Class type, + SecurityContext ctx, Object param, List ids, Class type, ActivityComponent activity) { - super(viewer, registry, activity); + super(viewer, registry, ctx, activity); if (ids == null || ids.size() == 0) throw new IllegalArgumentException("Objects not valid."); if (param == null) @@ -105,7 +107,7 @@ public FigureCreator(UserNotifier viewer, Registry registry, */ public void load() { - handle = ivView.createFigure(ids, type, param, this); + handle = ivView.createFigure(ctx, ids, type, param, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FileLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FileLoader.java index 077c561a933..e681fc836a3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FileLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FileLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.MetadataHandlerView; @@ -90,16 +91,18 @@ protected void onException(String message, Throwable ex) * * @param viewer Reference to the parent. * @param reg Reference to the registry. + * @param ctx The security context. * @param file The absolute path to the file. * @param fileID The file ID. * @param size The size of the file. * @param toLoad Indicates to download the file. * @param activity The activity associated to this loader. */ - FileLoader(UserNotifier viewer, Registry reg, File file, long fileID, - long size, boolean toLoad, ActivityComponent activity) + FileLoader(UserNotifier viewer, Registry reg, SecurityContext ctx, + File file, long fileID, long size, boolean toLoad, + ActivityComponent activity) { - super(viewer, reg, activity); + super(viewer, reg, ctx, activity); this.file = file; this.fileID = fileID; this.size = size; @@ -118,10 +121,11 @@ protected void onException(String message, Throwable ex) * @param toLoad Indicates to download the file. * @param activity The activity associated to this loader. */ - FileLoader(UserNotifier viewer, Registry reg, File file, long fileID, - int index, boolean toLoad, ActivityComponent activity) + FileLoader(UserNotifier viewer, Registry reg, SecurityContext ctx, + File file, long fileID, int index, boolean toLoad, + ActivityComponent activity) { - super(viewer, reg, activity); + super(viewer, reg, ctx, activity); this.file = file; this.fileID = fileID; this.toLoad = toLoad; @@ -138,10 +142,10 @@ public void load() switch (index) { case ORIGINAL_FILE: case FILE_ANNOTATION: - handle = mhView.loadFile(file, fileID, index, this); + handle = mhView.loadFile(ctx, file, fileID, index, this); break; default: - handle = mhView.loadFile(file, fileID, size, this); + handle = mhView.loadFile(ctx, file, fileID, size, this); } } else handleResult(file); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FileUploader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FileUploader.java index d5fb2c2ee9c..63616b18438 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FileUploader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FileUploader.java @@ -37,6 +37,7 @@ import org.openmicroscopy.shoola.agents.dataBrowser.DataBrowserLoader; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.util.file.ImportErrorObject; import org.openmicroscopy.shoola.util.ui.FileTableNode; @@ -83,10 +84,10 @@ class FileUploader * @param src The source object. * @param details Object hosting the data to upload. */ - FileUploader(UserNotifier viewer, Registry reg, MessengerDialog src, - MessengerDetails details) + FileUploader(UserNotifier viewer, Registry reg, SecurityContext ctx, + MessengerDialog src, MessengerDetails details) { - super(viewer, reg, null); + super(viewer, reg,ctx, null); if (details == null) throw new IllegalArgumentException("No files to upload."); this.details = details; @@ -135,7 +136,7 @@ public void load() if (!details.isExceptionOnly()) { src.setSubmitStatus("0 out of "+total, false); } - handle = mhView.submitFiles(details, this); + handle = mhView.submitFiles(ctx, details, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FilesLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FilesLoader.java index 05565831798..a949f15eef1 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FilesLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/FilesLoader.java @@ -37,6 +37,7 @@ import org.openmicroscopy.shoola.agents.metadata.EditorLoader; import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.FileAnnotationData; @@ -80,16 +81,17 @@ protected void onException(String message, Throwable ex) * * @param viewer Reference to the parent. * @param reg Reference to the registry. + * @param ctx The security context. * @param file The absolute path to the file. * @param fileID The file ID. * @param size The size of the file. * @param toLoad Indicates to download the file. * @param activity The activity associated to this loader. */ - FilesLoader(UserNotifier viewer, Registry reg, + FilesLoader(UserNotifier viewer, Registry reg, SecurityContext ctx, Map files, ActivityComponent activity) { - super(viewer, reg, activity); + super(viewer, reg, ctx, activity); if (files == null || files.size() == 0) throw new IllegalArgumentException("No files to download"); this.files = files; @@ -102,7 +104,7 @@ protected void onException(String message, Throwable ex) */ public void load() { - handle = mhView.loadFiles(files, this); + handle = mhView.loadFiles(ctx, files, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/MovieActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/MovieActivity.java index bd20cb24ff1..476b8d68740 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/MovieActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/MovieActivity.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.MovieActivityParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.ui.UIUtilities; /** @@ -69,12 +70,13 @@ public class MovieActivity * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param parameters The parameters used to create a movie. */ public MovieActivity(UserNotifier viewer, Registry registry, - MovieActivityParam parameters) + SecurityContext ctx, MovieActivityParam parameters) { - super(viewer, registry); + super(viewer, registry, ctx); if (parameters == null) throw new IllegalArgumentException("Parameters not valid."); this.parameters = parameters; @@ -90,7 +92,8 @@ public MovieActivity(UserNotifier viewer, Registry registry, */ protected UserNotifierLoader createLoader() { - loader = new MovieCreator(viewer, registry, parameters.getParameters(), + loader = new MovieCreator(viewer, registry, ctx, + parameters.getParameters(), parameters.getChannels(), parameters.getImage(), this); return loader; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/MovieCreator.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/MovieCreator.java index d5dd50526e9..49fd41da5c3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/MovieCreator.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/MovieCreator.java @@ -34,6 +34,7 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.model.MovieExportParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.ProcessCallback; import pojos.ImageData; @@ -91,10 +92,10 @@ protected void onException(String message, Throwable ex) * @param activity The activity associated to this loader. */ public MovieCreator(UserNotifier viewer, Registry registry, - MovieExportParam param, List channels, + SecurityContext ctx, MovieExportParam param, List channels, ImageData image, ActivityComponent activity) { - super(viewer, registry, activity); + super(viewer, registry, ctx, activity); if (image == null) throw new IllegalArgumentException("Image not valid."); if (param == null) @@ -113,8 +114,8 @@ public MovieCreator(UserNotifier viewer, Registry registry, public void load() { long pixelsID = image.getDefaultPixels().getId(); - handle = ivView.createMovie(image.getId(), pixelsID, channels, param, - this); + handle = ivView.createMovie(ctx, image.getId(), pixelsID, channels, + param, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/OpenObjectActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/OpenObjectActivity.java index 1ae4b60be21..fdb3f51a565 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/OpenObjectActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/OpenObjectActivity.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.OpenActivityParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; /** * Activity to open an image or a file. @@ -68,12 +69,13 @@ public class OpenObjectActivity * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param parameters The parameters used to export the image. */ public OpenObjectActivity(UserNotifier viewer, Registry registry, - OpenActivityParam parameters) + SecurityContext ctx, OpenActivityParam parameters) { - super(viewer, registry); + super(viewer, registry, ctx); if (parameters == null) throw new IllegalArgumentException("No parameters"); this.parameters = parameters; @@ -87,7 +89,8 @@ public OpenObjectActivity(UserNotifier viewer, Registry registry, */ protected UserNotifierLoader createLoader() { - loader = new OpenObjectLoader(viewer, registry, parameters.getObject(), + loader = new OpenObjectLoader(viewer, registry, ctx, + parameters.getObject(), parameters.getFolderPath(), this); return loader; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/OpenObjectLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/OpenObjectLoader.java index 9bf812634e6..4c65d75ae81 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/OpenObjectLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/OpenObjectLoader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.util.filter.file.OMETIFFFilter; import pojos.DataObject; @@ -68,15 +69,16 @@ public class OpenObjectLoader * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param object The object to handle. * @param folderPath The folder where to copy locally the object. * @param activity The activity associated to this loader. */ public OpenObjectLoader(UserNotifier viewer, Registry registry, - DataObject object, String folderPath, + SecurityContext ctx, DataObject object, String folderPath, ActivityComponent activity) { - super(viewer, registry, activity); + super(viewer, registry, ctx, activity); if (object == null) throw new IllegalArgumentException("Object not valid."); if (!(object instanceof ImageData || @@ -101,13 +103,13 @@ public void load() path += "."+OMETIFFFilter.OME_TIFF; f = new File(path); f.deleteOnExit(); - handle = ivView.exportImageAsOMETiff(image.getId(), f, this); + handle = ivView.exportImageAsOMETiff(ctx, image.getId(), f, this); } else { FileAnnotationData fa = (FileAnnotationData) object; path += fa.getFileName(); f = new File(path); f.deleteOnExit(); - handle = mhView.loadFile(f, fa.getFileID(), + handle = mhView.loadFile(ctx, f, fa.getFileID(), FileLoader.FILE_ANNOTATION, this); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SaveAsActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SaveAsActivity.java index 8600d0276e3..99294d124cb 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SaveAsActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SaveAsActivity.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.SaveAsParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; /** * The activity associated to the Save as action i.e. save a collection of @@ -69,12 +70,13 @@ public class SaveAsActivity * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param parameters The parameters used to save the collection of images. */ public SaveAsActivity(UserNotifier viewer, Registry registry, - SaveAsParam parameters) + SecurityContext ctx, SaveAsParam parameters) { - super(viewer, registry); + super(viewer, registry, ctx); if (parameters == null) throw new IllegalArgumentException("Parameters not valid."); this.parameters = parameters; @@ -91,7 +93,7 @@ public SaveAsActivity(UserNotifier viewer, Registry registry, */ protected UserNotifierLoader createLoader() { - loader = new SaveAsLoader(viewer, registry, parameters, this); + loader = new SaveAsLoader(viewer, registry, ctx, parameters, this); return loader; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SaveAsLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SaveAsLoader.java index 4b8015e222f..d47464f0acd 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SaveAsLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SaveAsLoader.java @@ -31,6 +31,7 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.model.SaveAsParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.ProcessCallback; @@ -75,13 +76,14 @@ protected void onException(String message, Throwable ex) * * @param viewer Reference to the model. Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param param The parameters used to save the images. * @param activity The activity associated to this loader. */ public SaveAsLoader(UserNotifier viewer, Registry registry, - SaveAsParam param, ActivityComponent activity) + SecurityContext ctx, SaveAsParam param, ActivityComponent activity) { - super(viewer, registry, activity); + super(viewer, registry, ctx, activity); if (param == null) throw new IllegalArgumentException("Parameters cannot be null."); this.param = param; @@ -93,7 +95,7 @@ public SaveAsLoader(UserNotifier viewer, Registry registry, */ public void load() { - handle = ivView.saveAs(param, this); + handle = ivView.saveAs(ctx, param, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptActivity.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptActivity.java index 36303c190d9..1eb348dbac6 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptActivity.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptActivity.java @@ -33,6 +33,7 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.ScriptActivityParam; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; /** * Activity to run the specified scripts. @@ -96,13 +97,14 @@ public class ScriptActivity * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param script The script to run. * @param activity The activity associated to this loader. */ public ScriptActivity(UserNotifier viewer, Registry registry, - ScriptObject script, int index) + SecurityContext ctx, ScriptObject script, int index) { - super(viewer, registry); + super(viewer, registry, ctx); if (script == null) throw new IllegalArgumentException("Parameters not valid."); initialize(DESCRIPTION_RUN_CREATION+script.getDisplayedName(), @@ -127,10 +129,11 @@ protected UserNotifierLoader createLoader() { switch (index) { case UPLOAD: - loader = new ScriptUploader(viewer, registry, script, this); + loader = new ScriptUploader(viewer, registry, ctx, script, + this); break; case RUN: - loader = new ScriptRunner(viewer, registry, script, this); + loader = new ScriptRunner(viewer, registry, ctx, script, this); } return loader; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptRunner.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptRunner.java index 4b704141313..dcd4a52ef88 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptRunner.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptRunner.java @@ -31,6 +31,7 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import org.openmicroscopy.shoola.env.data.views.ProcessCallback; @@ -75,13 +76,14 @@ protected void onException(String message, Throwable ex) * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param script The script to run. * @param activity The activity associated to this loader. */ public ScriptRunner(UserNotifier viewer, Registry registry, - ScriptObject script, ActivityComponent activity) + SecurityContext ctx, ScriptObject script, ActivityComponent activity) { - super(viewer, registry, activity); + super(viewer, registry, ctx, activity); if (script == null) throw new IllegalArgumentException("No script to run."); this.script = script; @@ -93,7 +95,7 @@ public ScriptRunner(UserNotifier viewer, Registry registry, */ public void load() { - handle = ivView.runScript(script, this); + handle = ivView.runScript(ctx, script, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptUploader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptUploader.java index ce7d2e70576..de0a773bae0 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptUploader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ScriptUploader.java @@ -29,6 +29,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; /** @@ -69,13 +70,14 @@ protected void onException(String message, Throwable ex) * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param script The script to run. * @param activity The activity associated to this loader. */ public ScriptUploader(UserNotifier viewer, Registry registry, - ScriptObject script, ActivityComponent activity) + SecurityContext ctx, ScriptObject script, ActivityComponent activity) { - super(viewer, registry, activity); + super(viewer, registry, ctx, activity); if (script == null) throw new IllegalArgumentException("No script to run."); this.script = script; @@ -87,7 +89,7 @@ public ScriptUploader(UserNotifier viewer, Registry registry, */ public void load() { - handle = ivView.uploadScript(script, this); + handle = ivView.uploadScript(ctx, script, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SwitchUserLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SwitchUserLoader.java index b49b7a0cb84..735caec3ed6 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SwitchUserLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/SwitchUserLoader.java @@ -33,6 +33,7 @@ import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallFeedbackEvent; import org.openmicroscopy.shoola.env.data.events.UserGroupSwitched; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.CallHandle; import pojos.ExperimenterData; @@ -68,14 +69,15 @@ public class SwitchUserLoader * @param viewer The viewer this data loader is for. * Mustn't be null. * @param registry Convenience reference for subclasses. + * @param ctx The security context. * @param toSave The data to save before switching group. * @param experimenter The experimenter to handle. * @param groupID The identifier of the group. */ public SwitchUserLoader(UserNotifier viewer, Registry registry, - ExperimenterData experimenter, long groupID) + SecurityContext ctx, ExperimenterData experimenter, long groupID) { - super(viewer, registry, null); + super(viewer, registry, ctx, null); this.experimenter = experimenter; this.groupID = groupID; } @@ -86,7 +88,7 @@ public SwitchUserLoader(UserNotifier viewer, Registry registry, */ public void load() { - handle = dhView.switchUserGroup(experimenter, groupID, this); + handle = dhView.switchUserGroup(ctx, experimenter, groupID, this); } /** diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/TaskBarManager.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/TaskBarManager.java index dfcdc136279..395d1068946 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/TaskBarManager.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/TaskBarManager.java @@ -60,6 +60,7 @@ import org.openmicroscopy.shoola.env.config.AgentInfo; import org.openmicroscopy.shoola.env.config.OMEROInfo; import org.openmicroscopy.shoola.env.config.Registry; +import org.openmicroscopy.shoola.env.data.AdminService; import org.openmicroscopy.shoola.env.data.DSOutOfServiceException; import org.openmicroscopy.shoola.env.data.DataServicesFactory; import org.openmicroscopy.shoola.env.data.events.ExitApplication; @@ -72,6 +73,7 @@ import org.openmicroscopy.shoola.env.data.login.LoginService; import org.openmicroscopy.shoola.env.data.login.UserCredentials; import org.openmicroscopy.shoola.env.data.util.AgentSaveInfo; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.AgentEvent; import org.openmicroscopy.shoola.env.event.AgentEventListener; import org.openmicroscopy.shoola.env.event.EventBus; @@ -244,7 +246,7 @@ private void doManageConnection() try { DataServicesFactory f = DataServicesFactory.getInstance(container); if (f.isConnected()) { - f.shutdown(); + f.shutdown(null); synchConnectionButtons(); } else { EventBus bus = container.getRegistry().getEventBus(); @@ -335,7 +337,7 @@ private void handleSwitchUserGroup(SwitchUserGroup evt) { if (evt == null) return; //Do we have data to save. - + /* CheckoutBox box = new CheckoutBox(view, SWITCH_GROUP_TITLE, SWITCH_GROUP_TEXT, getInstancesToSave()); if (box.centerMsgBox() == MessageBox.YES_OPTION) { @@ -364,6 +366,7 @@ private void handleSwitchUserGroup(SwitchUserGroup evt) evt.getGroupID()); loader.load(); } + */ } /** @@ -405,6 +408,7 @@ private void handleLogOff(LogOff evt) } } + /** Reconnects to the server.*/ private void reconnect() { Image img = IconManager.getOMEImageIcon(); @@ -438,7 +442,7 @@ private void reconnect() public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (ScreenLogin.QUIT_PROPERTY.equals(name)) - doExit(false); + doExit(false, null); else if (ScreenLogin.LOGIN_PROPERTY.equals(name)) { LoginCredentials lc = (LoginCredentials) evt.getNewValue(); if (lc != null) @@ -479,10 +483,12 @@ private void logOut() * The exit action. * Just forwards to the container. * - * @param askQuestion Pass true to pop up a message before + * @param askQuestion Pass true to pop up a message before * quitting, false otherwise. + * @param ctx The security context so the default group can be set or + * null. */ - private void doExit(boolean askQuestion) + private void doExit(boolean askQuestion, SecurityContext ctx) { IconManager icons = IconManager.getInstance(container.getRegistry()); int option = MessageBox.YES_OPTION; @@ -495,11 +501,11 @@ private void doExit(boolean askQuestion) } if (option == MessageBox.YES_OPTION) { if (msg == null) { - exitApplication(); + exitApplication(ctx); } else { Map map = msg.getInstancesToSave(); if (map == null || map.size() == 0) { - exitApplication(); + exitApplication(ctx); } else { List nodes = new ArrayList(); Iterator i = map.entrySet().iterator(); @@ -513,7 +519,7 @@ private void doExit(boolean askQuestion) agent.save(info.getInstances()); nodes.add(info); } - exitApplication(); + exitApplication(ctx); //UserNotifierImpl un = (UserNotifierImpl) //container.getRegistry().getUserNotifier(); //un.notifySaving(nodes, this); @@ -528,14 +534,37 @@ private void doExit(boolean askQuestion) } } - /** Exits the application. */ - private void exitApplication() + /** + * Exits the application. + * + * @param ctx The security context or null. + */ + private void exitApplication(SecurityContext ctx) { + //Change group if context not null + if (ctx != null) { + try { + AdminService svc = container.getRegistry().getAdminService(); + svc.changeExperimenterGroup(ctx, null, ctx.getGroupID()); + } catch (Exception e) { + Logger log = container.getRegistry().getLogger(); + LogMessage msg = new LogMessage(); + msg.print(e); + log.error(this, msg); + } + } try { + DataServicesFactory f = DataServicesFactory.getInstance(container); f.exitApplication(false, true); - } catch (Exception e) {} //ignore + } catch (Exception e) { + Logger log = container.getRegistry().getLogger(); + LogMessage msg = new LogMessage(); + msg.print("Error while exiting"); + msg.print(e); + log.error(this, msg); + } } /** Displays information about software. */ @@ -667,7 +696,7 @@ public void actionPerformed(ActionEvent ae) { private void attachOpenExitListeners() { view.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent we) { doExit(true); } + public void windowClosing(WindowEvent we) { doExit(true, null); } public void windowOpened(WindowEvent we) { synchConnectionButtons(); } @@ -872,11 +901,12 @@ boolean login() */ public void eventFired(AgentEvent e) { - if (e instanceof ServiceActivationResponse) + if (e instanceof ServiceActivationResponse) synchConnectionButtons(); - else if (e instanceof ExitApplication) - doExit(((ExitApplication) e).isAskQuestion()); - else if (e instanceof SwitchUserGroup) + else if (e instanceof ExitApplication) { + ExitApplication a = (ExitApplication) e; + doExit(a.isAskQuestion(), a.getContext()); + } else if (e instanceof SwitchUserGroup) handleSwitchUserGroup((SwitchUserGroup) e); else if (e instanceof SaveEventResponse) handleSaveEventResponse((SaveEventResponse) e); @@ -900,7 +930,7 @@ public void propertyChange(PropertyChangeEvent evt) Registry reg = container.getRegistry();; Object exp = reg.lookup(LookupNames.CURRENT_USER_DETAILS); if (exp == null) container.exit(); //not connected - else doExit(true); + //else doExit(true, null); } else if (ScreenLogin.LOGIN_PROPERTY.equals(name)) { LoginCredentials lc = (LoginCredentials) evt.getNewValue(); if (lc != null) collectCredentials(lc, login); @@ -908,9 +938,8 @@ public void propertyChange(PropertyChangeEvent evt) login.close(); success = false; } else if (ChangesDialog.DONE_PROPERTY.equals(name)) { - Boolean value = (Boolean) evt.getNewValue(); - if (value.booleanValue()) - exitApplication(); + SecurityContext value = (SecurityContext) evt.getNewValue(); + exitApplication(value); } } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifier.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifier.java index bb40adb89ed..cb065ed024c 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifier.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifier.java @@ -31,6 +31,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.model.ApplicationData; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.file.ImportErrorObject; /** @@ -157,9 +158,10 @@ public void notifyError(String title, String summary, /** * Notifies the user of an activity such as movie creation. * + * @param ctx The security context. * @param activity The activity to register. */ - public void notifyActivity(Object activity); + public void notifyActivity(SecurityContext ctx, Object activity); /** * Opens the specified application. diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierImpl.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierImpl.java index 411a5b249ac..cd201be7dfe 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierImpl.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierImpl.java @@ -50,6 +50,8 @@ import org.openmicroscopy.shoola.env.data.model.OpenActivityParam; import org.openmicroscopy.shoola.env.data.model.SaveAsParam; import org.openmicroscopy.shoola.env.data.model.ScriptActivityParam; +import org.openmicroscopy.shoola.env.data.model.TransferableActivityParam; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.file.ImportErrorObject; import org.openmicroscopy.shoola.util.ui.MessengerDialog; import org.openmicroscopy.shoola.util.ui.NotificationDialog; @@ -80,7 +82,7 @@ public class UserNotifierImpl /** Default title for the warning dialog. */ private static final String DEFAULT_WARNING_TITLE = "Warning"; - /** Default title for the info dialog. */ + /** Default title for the info dialog. */ private static final String DEFAULT_INFO_TITLE = "Information"; /** @@ -211,11 +213,13 @@ private void showErrorDialog(String title, String summary, String detail, * * @param nodes The nodes to handle. * @param listener The listener to register. + * @param ctx The security context. * @return See above */ - void notifySaving(List nodes, PropertyChangeListener listener) + void notifySaving(List nodes, PropertyChangeListener listener, + SecurityContext ctx) { - dialog = new ChangesDialog(SHARED_FRAME, nodes); + dialog = new ChangesDialog(SHARED_FRAME, nodes, ctx); dialog.addPropertyChangeListener(this); if (listener != null) dialog.addPropertyChangeListener(listener); UIUtilities.centerAndShow(dialog); @@ -342,9 +346,9 @@ public void submitMessage(String email, String comment) /** * Implemented as specified by {@link UserNotifier}. - * @see UserNotifier#notifyActivity(Object) + * @see UserNotifier#notifyActivity(SecurityContext, Object) */ - public void notifyActivity(Object activity) + public void notifyActivity(SecurityContext ctx, Object activity) { if (activity == null) return; ActivityComponent comp = null; @@ -353,13 +357,13 @@ public void notifyActivity(Object activity) boolean startActivity = true; if (activity instanceof MovieActivityParam) { MovieActivityParam p = (MovieActivityParam) activity; - comp = new MovieActivity(this, manager.getRegistry(), p); + comp = new MovieActivity(this, manager.getRegistry(), ctx, p); } else if (activity instanceof ExportActivityParam) { if (manager.hasRunningActivityOfType(ExportActivity.class)) { startActivity = false; } ExportActivityParam p = (ExportActivityParam) activity; - comp = new ExportActivity(this, manager.getRegistry(), p); + comp = new ExportActivity(this, manager.getRegistry(), ctx, p); } else if (activity instanceof DownloadActivityParam) { DownloadActivityParam p = (DownloadActivityParam) activity; register = (p.getApplicationData() == null); @@ -368,35 +372,35 @@ public void notifyActivity(Object activity) return; uiRegister = p.isUIRegister(); } - comp = new DownloadActivity(this, manager.getRegistry(), p); + comp = new DownloadActivity(this, manager.getRegistry(), ctx, p); } else if (activity instanceof FigureActivityParam) { FigureActivityParam p = (FigureActivityParam) activity; - comp = new FigureActivity(this, manager.getRegistry(), p); + comp = new FigureActivity(this, manager.getRegistry(), ctx, p); } else if (activity instanceof AnalysisActivityParam) { AnalysisActivityParam p = (AnalysisActivityParam) activity; - comp = new AnalysisActivity(this, manager.getRegistry(), p); + comp = new AnalysisActivity(this, manager.getRegistry(), ctx, p); } else if (activity instanceof ScriptActivityParam) { ScriptActivityParam p = (ScriptActivityParam) activity; - comp = new ScriptActivity(this, manager.getRegistry(), + comp = new ScriptActivity(this, manager.getRegistry(), ctx, p.getScript(), p.getIndex()); } else if (activity instanceof DownloadArchivedActivityParam) { DownloadArchivedActivityParam p = (DownloadArchivedActivityParam) activity; comp = new DownloadArchivedActivity(this, manager.getRegistry(), - p); + ctx, p); } else if (activity instanceof DeleteActivityParam) { DeleteActivityParam p = (DeleteActivityParam) activity; - comp = new DeleteActivity(this, manager.getRegistry(), - p); + comp = new DeleteActivity(this, manager.getRegistry(), p); uiRegister = p.isUIRegister(); } else if (activity instanceof OpenActivityParam) { OpenActivityParam p = (OpenActivityParam) activity; - comp = new OpenObjectActivity(this, manager.getRegistry(), p); + comp = new OpenObjectActivity(this, manager.getRegistry(), ctx, p); } else if (activity instanceof DownloadAndZipParam) { DownloadAndZipParam p = (DownloadAndZipParam) activity; if (!canWriteInFolder(p.getFolder())) return; - comp = new DownloadAndZipActivity(this, manager.getRegistry(), p); + comp = new DownloadAndZipActivity(this, manager.getRegistry(), ctx, + p); } else if (activity instanceof SaveAsParam) { SaveAsParam p = (SaveAsParam) activity; File folder = p.getFolder(); @@ -406,7 +410,10 @@ public void notifyActivity(Object activity) } if (!canWriteInFolder(folder)) return; - comp = new SaveAsActivity(this, manager.getRegistry(), p); + comp = new SaveAsActivity(this, manager.getRegistry(), ctx, p); + } else if (activity instanceof TransferableActivityParam) { + TransferableActivityParam p = (TransferableActivityParam) activity; + comp = new DataTransferActivity(this, manager.getRegistry(), p); } if (comp != null) { UserNotifierLoader loader = comp.createLoader(); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierLoader.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierLoader.java index 37ed7a6a449..17d953b12f5 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierLoader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierLoader.java @@ -30,6 +30,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.config.Registry; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.DataHandlerView; import org.openmicroscopy.shoola.env.data.views.DataManagerView; import org.openmicroscopy.shoola.env.data.views.ImageDataView; @@ -80,21 +81,26 @@ abstract class UserNotifierLoader /** Convenience reference to the activity. */ protected final ActivityComponent activity; + /** The security context.*/ + protected final SecurityContext ctx; + /** * Creates a new instance. * - * @param viewer The viewer this data loader is for. - * Mustn't be null. - * @param registry Convenience reference for subclasses. - * @param activity Convenience reference to the activity. + * @param viewer The viewer this data loader is for. + * Mustn't be null. + * @param registry Convenience reference for subclasses. + * @param ctx The security context. + * @param activity Convenience reference to the activity. */ UserNotifierLoader(UserNotifier viewer, Registry registry, - ActivityComponent activity) + SecurityContext ctx, ActivityComponent activity) { if (viewer == null) throw new NullPointerException("No viewer."); if (registry == null) throw new NullPointerException("No registry."); this.activity = activity; this.viewer = viewer; + this.ctx = ctx; this.registry = registry; mhView = (MetadataHandlerView) registry.getDataServicesView(MetadataHandlerView.class); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierManager.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierManager.java index 33b5159ad4d..2dbe015ac50 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierManager.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/UserNotifierManager.java @@ -40,6 +40,7 @@ import org.openmicroscopy.shoola.env.Container; import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.config.Registry; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.EventBus; import org.openmicroscopy.shoola.env.log.LogMessage; import org.openmicroscopy.shoola.env.log.Logger; @@ -71,11 +72,11 @@ class UserNotifierManager { /** The default message if an error occurred while transferring data. */ - private static final String MESSAGE_START = "Sorry, but due to an error " + + private static final String MESSAGE_START = "Sorry, but due to an error " + "we were not able to automatically \n"; /** The default message if an error occurred while transferring data. */ - private static final String MESSAGE_END = "\n\n"+ + private static final String MESSAGE_END = "\n\n"+ "You can still send us the error message by " + "clicking on the \n" + "error message tab, copying the error " + @@ -83,17 +84,17 @@ class UserNotifierManager "and sending it to "; /** Message if the dialog's type is {@link MessengerDialog#ERROR_TYPE}. */ - private static final String ERROR_MSG = "send your debug information."; + private static final String ERROR_MSG = "send your debug information."; /** Message if the dialog's type is {@link MessengerDialog#COMMENT_TYPE}. */ - private static final String COMMENT_MSG = "send your comment."; + private static final String COMMENT_MSG = "send your comment."; /** Reply when sending the comments. */ - private static final String COMMENT_REPLY = "Thanks, your comments have " + + private static final String COMMENT_REPLY = "Thanks, your comments have " + "been successfully posted."; /** Reply when sending the error message. */ - private static final String ERROR_REPLY = "Thanks, the error message " + + private static final String ERROR_REPLY = "Thanks, the error message " + "has been successfully posted."; /** The tool invoking the service. */ @@ -103,55 +104,48 @@ class UserNotifierManager private static final String INVOKER_COMMENT = "insight_comments"; /** Default title for the comment dialog. */ - private static final String DEFAULT_COMMENT_TITLE = "Comment"; + private static final String DEFAULT_COMMENT_TITLE = "Comment"; /** Reference to the container. */ - private Container container; + private Container container; /** Back pointer to the component. */ - private UserNotifier component; + private UserNotifier component; /** Map keeping track of the ongoing data loading. */ private Map loaders; /** The Dialog used to send comments. */ - private MessengerDialog commentDialog; + private MessengerDialog commentDialog; /** The dialog keeping track of the activity files. */ - private DownloadsDialog activityDialog; + private DownloadsDialog activityDialog; /** The collection of running activities. */ - private List activities; - - /** - * Submits files that failed to import. - * - * @param source The source of the message. - * @param details The values to send. - */ - private void submitFiles(MessengerDialog source, - MessengerDetails details) - { - FileUploader loader = new FileUploader(component, - container.getRegistry(), source, details); - loader.load(); - } - + private List activities; + /** * Sends a message. * - * @param source The source of the message. - * @param details The values to send. + * @param source The source of the message. + * @param details The values to send. */ private void handleSendMessage(MessengerDialog source, MessengerDetails details) { + Registry reg = container.getRegistry(); if (details.getObjectToSubmit() != null || details.getLogFile() != null) { - submitFiles(source, details); + ExperimenterData exp = (ExperimenterData) reg.lookup( + LookupNames.CURRENT_USER_DETAILS); + SecurityContext ctx = new SecurityContext( + exp.getDefaultGroup().getId()); + FileUploader loader = new FileUploader(component, + container.getRegistry(), ctx, source, details); + loader.load(); return; } - Registry reg = container.getRegistry(); + boolean bug = true; String error = details.getError(); if (error == null || error.length() == 0) bug = false; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ViewObjectEvent.java b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ViewObjectEvent.java index 3f777d22d87..e3b9bb86d2a 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ViewObjectEvent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/env/ui/ViewObjectEvent.java @@ -29,6 +29,7 @@ //Third-party libraries //Application-internal dependencies +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.event.RequestEvent; /** @@ -57,14 +58,21 @@ public class ViewObjectEvent /** Flag indicating to browse the object.*/ private boolean browse; + /** The security context.*/ + private SecurityContext ctx; + + /** * Creates a new instance. * + * @param ctx The security context. * @param object The object to view. * @param source The component triggering the event. */ - public ViewObjectEvent(Object object, JComponent source) + public ViewObjectEvent(SecurityContext ctx, Object object, + JComponent source) { + this.ctx = ctx; this.object = object; this.source = source; browse = false; @@ -101,4 +109,11 @@ public ViewObjectEvent(Object object, JComponent source) */ public Object getObject() { return object; } + /** + * Returns the security context. + * + * @return See above. + */ + public SecurityContext getSecurityContext() { return ctx; } + } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/MacOSMenuHandler.java b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/MacOSMenuHandler.java index 3cff6b7f6a0..e1ff7b75eb3 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/MacOSMenuHandler.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/MacOSMenuHandler.java @@ -57,7 +57,7 @@ public class MacOSMenuHandler * Bound property indicating that the Quit * menu item is selected. */ - public static final String QUIT_APPLICATION_PROPERTY = "quitpplication"; + public static final String QUIT_APPLICATION_PROPERTY = "quitApplication"; /** Helper reference to the parent. */ private Frame parent; diff --git a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/TooltipTableHeader.java b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/TooltipTableHeader.java index 98947174178..0cbbd534a57 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/TooltipTableHeader.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/TooltipTableHeader.java @@ -83,7 +83,8 @@ public String getToolTipText(MouseEvent e) } catch (Exception ex) { retStr = ""; } - if (retStr.length() < 1) retStr = super.getToolTipText(e); + if (retStr == null || retStr.length() < 1) + retStr = super.getToolTipText(e); return retStr; } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/UIUtilities.java b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/UIUtilities.java index 2793456a77c..bf602ca75d4 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/UIUtilities.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/UIUtilities.java @@ -546,7 +546,7 @@ public static void centerOnScreen(Component window) public static void showOnScreen(Component window, Point location) { if (window == null) return; - if (location == null) centerOnScreen(window); + if (location == null) centerAndShow(window); else { window.setLocation(location); window.setVisible(true); diff --git a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/GroupContext.java b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/GroupContext.java new file mode 100644 index 00000000000..7dc454cb86e --- /dev/null +++ b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/GroupContext.java @@ -0,0 +1,75 @@ +/* + * org.openmicroscopy.shoola.util.ui.search.GroupContext + * + *------------------------------------------------------------------------------ + * Copyright (C) 2006-2012 University of Dundee & Open Microscopy Environment. + * All rights reserved. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + *------------------------------------------------------------------------------ + */ +package org.openmicroscopy.shoola.util.ui.search; + + +//Java imports + +//Third-party libraries + +//Application-internal dependencies +import pojos.GroupData; + +/** + * Host information about the group to search into. + * + * @author Jean-Marie Burel      + * j.burel@dundee.ac.uk + * @since Beta4.4 + */ +class GroupContext +{ + + /** The group to handle.*/ + private String group; + + /** The identifier of the group.*/ + private long id; + + /** + * Creates a new instance. + * + * @param group The name of the group to handle. + * @param id The identifier of the group. + */ + GroupContext(String group, long id) + { + this.group = group; + this.id = id; + } + + /** + * Returns the id of the group hosted by the component. + * + * @return See above. + */ + long getId() { return id; } + + /** + * Overridden to return the name of the group. + * @see Object#toString() + */ + public String toString() { return group; } + +} diff --git a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchComponent.java b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchComponent.java index 138cb965516..87b21d5a7b2 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchComponent.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchComponent.java @@ -29,6 +29,8 @@ import java.awt.event.ActionListener; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; import java.util.List; import javax.swing.Box; import javax.swing.BoxLayout; @@ -36,6 +38,7 @@ import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.JSeparator; //Third-party libraries import info.clearthought.layout.TableLayout; @@ -44,6 +47,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.util.ui.SeparatorPane; import org.openmicroscopy.shoola.util.ui.UIUtilities; +import pojos.GroupData; /** * Component with advanced search options. @@ -183,6 +187,12 @@ public class SearchComponent /** The UI component hosting the result if any. */ private JComponent resultPane; + /** The list of groups.*/ + private Collection groups; + + /** The groups to handle.*/ + private List groupsContext; + /** * Initializes the components composing the display. * @@ -255,8 +265,9 @@ private void buildGUI(boolean showControl) { setBackground(UIUtilities.BACKGROUND_COLOR); double[][] size = {{TableLayout.PREFERRED}, - {TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, - TableLayout.PREFERRED, TableLayout.PREFERRED}}; + {TableLayout.PREFERRED, TableLayout.PREFERRED, + TableLayout.PREFERRED, TableLayout.PREFERRED, + TableLayout.PREFERRED}}; setLayout(new TableLayout(size)); int i = 0; String key = "0, "; @@ -269,6 +280,7 @@ private void buildGUI(boolean showControl) add(buildStatusBar(), key+i); resultPane = new JPanel(); resultPane.setBackground(UIUtilities.BACKGROUND_COLOR); + resultPane.setLayout(new BoxLayout(resultPane, BoxLayout.Y_AXIS)); JPanel sep = new SeparatorPane(); sep.setBackground(UIUtilities.BACKGROUND_COLOR); i++; @@ -280,7 +292,8 @@ private void buildGUI(boolean showControl) /** Closes and disposes of the window. */ private void cancel() { - firePropertyChange(CANCEL_SEARCH_PROPERTY, Boolean.FALSE, Boolean.TRUE); + firePropertyChange(CANCEL_SEARCH_PROPERTY, + Boolean.valueOf(false), Boolean.valueOf(true)); } /** Sets the default contexts. */ @@ -333,22 +346,29 @@ public SearchComponent() * Initializes the component. Displays the controls buttons. * * @param controls The collection of controls to add. + * @param groups The collection of groups. */ - public void initialize(List controls) + public void initialize(List controls, + Collection groups) { - initialize(true, controls); + initialize(true, controls, groups); } /** * Initializes the component. * - * @param showControl Pass true to display the buttons, - * false otherwise. + * @param showControl Pass true to display the buttons, + * false otherwise. * @param controls The collection of controls to add. + * @param groups The collection of groups. */ - public void initialize(boolean showControl, List controls) + public void initialize(boolean showControl, List controls, + Collection groups) { setDefaultContext(); + if (groups == null) + throw new IllegalArgumentException("No groups specified."); + this.groups = groups; initComponents(controls); buildGUI(showControl); } @@ -433,6 +453,7 @@ void search() ctx.setOwnerSearchContext(uiDelegate.getOwnerSearchContext()); ctx.setAnnotatorSearchContext(uiDelegate.getAnnotatorSearchContext()); ctx.setOwners(uiDelegate.getOwners()); + ctx.setGroups(uiDelegate.getSelectedGroups()); ctx.setAnnotators(uiDelegate.getAnnotators()); ctx.setCaseSensitive(uiDelegate.isCaseSensitive()); ctx.setType(uiDelegate.getType()); @@ -440,9 +461,30 @@ void search() ctx.setTimeType(uiDelegate.getTimeIndex()); ctx.setExcludedOwners(uiDelegate.getExcludedOwners()); ctx.setExcludedAnnotators(uiDelegate.getExcludedAnnotators()); + ctx.setGroups(uiDelegate.getSelectedGroups()); firePropertyChange(SEARCH_PROPERTY, null, ctx); } + /** + * Returns the list of possible groups. + * + * @return See above. + */ + List getGroups() + { + if (groupsContext != null) return groupsContext; + Iterator i = groups.iterator(); + GroupData g; + GroupContext gc; + groupsContext = new ArrayList(); + while (i.hasNext()) { + g = i.next(); + gc = new GroupContext(g.getName(), g.getId()); + groupsContext.add(gc); + } + return groupsContext; + } + /** * Sets the buttons enabled when performing search. * @@ -500,9 +542,29 @@ public void setUserString(long userID, String name) public void displayResult(JComponent result) { remove(resultPane); - resultPane = result; - resultPane.setBackground(UIUtilities.BACKGROUND_COLOR); - add(resultPane, "0, 4"); + if (result != null) { + resultPane = result; + resultPane.setBackground(UIUtilities.BACKGROUND_COLOR); + add(resultPane, "0, 4"); + } + repaint(); + } + + /** + * Adds the specified component to the result display. + * + * @param result The component to add. + * @param clear Pass true to remove the previous components, + * false otherwise. + */ + public void addResult(JComponent result, boolean clear) + { + if (clear) resultPane.removeAll(); + if (result == null) return; + resultPane.add(result); + resultPane.add(new JSeparator()); + result.setBackground(UIUtilities.BACKGROUND_COLOR); + revalidate(); repaint(); } diff --git a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchContext.java b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchContext.java index f9be4e5345d..3c80a9c7916 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchContext.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchContext.java @@ -68,29 +68,38 @@ public class SearchContext /** Identifying the Project context. */ public static final int PROJECTS = 2; + /** Identifying the Screen context. */ + public static final int SCREENS = 3; + + /** Identifying the Plate context. */ + public static final int PLATES = 4; + + /** Identifying the Well context. */ + public static final int WELLS = 5; + /** Identifying the Annotation context. */ - public static final int TEXT_ANNOTATION = 3; + public static final int TEXT_ANNOTATION = 6; /** Identifying the Tag context. */ - public static final int TAGS = 4; + public static final int TAGS = 7; /** Identifying the Tag set context. */ - public static final int TAG_SETS = 5; + public static final int TAG_SETS = 8; /** Identifying the Name context. */ - public static final int NAME = 6; + public static final int NAME = 9; /** Identifying the File annotation context. */ - public static final int FILE_ANNOTATION = 7; + public static final int FILE_ANNOTATION = 10; /** Identifying the URL annotation context. */ - public static final int URL_ANNOTATION = 8; + public static final int URL_ANNOTATION = 11; /** Identifying the Description context. */ - public static final int DESCRIPTION = 9; + public static final int DESCRIPTION = 12; /** Identifying the Description context. */ - public static final int CUSTOMIZED = 10; + public static final int CUSTOMIZED = 13; /** Indicates not to take into account the time criteria. */ static final int ANY_DATE = 0; @@ -241,6 +250,9 @@ public class SearchContext /** The type of attachments to retrieve. */ private int attachmentType; + /** Collection of selected groups. */ + private List selectedGroups; + /** * Creates a new instance. * @@ -303,6 +315,13 @@ void setTime(Timestamp startTime, Timestamp endTime) if (startTime != null && endTime != null) dateIndex = RANGE; } + /** + * Sets the collection of selected groups if any. + * + * @param groups The value to set. + */ + void setGroups(List groups) { this.selectedGroups = groups; } + /** * Sets the collection of selected users if any. * @@ -472,6 +491,13 @@ void setAttachmentType(int type) */ public List getContext() { return context; } + /** + * Returns the collection of selected groups. + * + * @return See above. + */ + public List getSelectedGroups() { return selectedGroups; } + /** * Returns the collection of selected users. * diff --git a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchPanel.java b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchPanel.java index 158b841f2ee..8fab2d07184 100644 --- a/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchPanel.java +++ b/components/insight/SRC/org/openmicroscopy/shoola/util/ui/search/SearchPanel.java @@ -24,6 +24,7 @@ //Java imports +import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -34,6 +35,7 @@ import java.awt.event.KeyEvent; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -287,9 +289,59 @@ class SearchPanel /** The collection of buttons to add. */ private List controls; + /** The box displaying the groups.*/ + private JComboBox groupsBox; + + /** The box displaying the groups.*/ + private List groupsBoxes; + + /** + * Returns the selected groups. + * + * @return See above. + */ + private Collection getGroups() + { + if (groupsBox == null) return model.getGroups(); + GroupContext ctx = (GroupContext) groupsBox.getSelectedItem(); + if (ctx.getId() < 0) return model.getGroups(); + List groups = new ArrayList(); + groups.add(ctx); + Iterator i = groupsBoxes.iterator(); + JComboBox box; + while (i.hasNext()) { + box = i.next(); + ctx = (GroupContext) box.getSelectedItem(); + if (ctx.getId() < 0) return model.getGroups(); + if (!groups.contains(ctx)) groups.add(ctx); + } + return groups; + } + + /** + * Creates a JComboBox with the available groups. + * + * @return See above. + */ + private JComboBox createBox() + { + List groups = model.getGroups(); + Object[] values = new Object[groups.size()+1]; + values[0] = new GroupContext("All your groups", -1); + int j = 1; + Iterator i = groups.iterator(); + while (i.hasNext()) { + values[j] = i.next(); + j++; + } + return new JComboBox(values); + } + /** Initializes the components composing the display. */ private void initComponents() { + groupsBoxes = new ArrayList(); + groupsBox = createBox(); otherOwners = new LinkedHashMap(); otherOwnersPanel = new JPanel(); otherOwnersPanel.setBackground(UIUtilities.BACKGROUND_COLOR); @@ -646,11 +698,22 @@ private JPanel buildScope() c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; //c.insets = new Insets(3, 3, 3, 3); + //c.gridx = 0; + c.gridy = 0; + if (model.getGroups().size() > 1) { + JPanel row = new JPanel(); + row.setLayout(new FlowLayout(FlowLayout.LEFT)); + row.setBackground(UIUtilities.BACKGROUND_COLOR); + row.add(new JLabel("Search in Group:")); + row.add(groupsBox); + p.add(row, c); + } List nodes = model.getNodes(); SearchObject n; int m = nodes.size(); JCheckBox box; c.weightx = 1.0; + c.gridy = 1; List ctxNodes = null; SearchContext ctx = model.getSearchContext(); if (ctx != null) ctxNodes = ctx.getContext(); @@ -677,7 +740,7 @@ private JPanel buildScope() scopes.put(n.getIndex(), box); } } - + c.gridy++; //UIUtilities.setBoldTitledBorder(SCOPE_TITLE, p); return p; } @@ -1347,7 +1410,23 @@ void advancedSearch(boolean advancedSearch) revalidate(); repaint(); } - + + /** + * Returns the selected groups. + * + * @return See above. + */ + List getSelectedGroups() + { + Collection l = getGroups(); + Iterator i = l.iterator(); + List ids = new ArrayList(l.size()); + while (i.hasNext()) { + ids.add(i.next().getId()); + } + return ids; + } + /** * Removes the user from the display. * @see ActionListener#actionPerformed(ActionEvent) diff --git a/components/insight/TEST/org/openmicroscopy/shoola/env/data/NullOmeroPojoService.java b/components/insight/TEST/org/openmicroscopy/shoola/env/data/NullOmeroPojoService.java index ecbd9e5c3bb..75cea3d373e 100644 --- a/components/insight/TEST/org/openmicroscopy/shoola/env/data/NullOmeroPojoService.java +++ b/components/insight/TEST/org/openmicroscopy/shoola/env/data/NullOmeroPojoService.java @@ -37,6 +37,8 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.model.DeletableObject; import org.openmicroscopy.shoola.env.data.util.SearchDataContext; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; + import pojos.AnnotationData; import pojos.DataObject; import pojos.ExperimenterData; @@ -65,7 +67,7 @@ public class NullOmeroPojoService * No-operation implementation * @see OmeroDataService#addExistingObjects(DataObject, Collection) */ - public void addExistingObjects(DataObject parent, Collection children) + public void addExistingObjects(SecurityContext ctx, DataObject parent, Collection children) throws DSOutOfServiceException, DSAccessException { } @@ -74,7 +76,7 @@ public void addExistingObjects(DataObject parent, Collection children) * No-operation implementation * @see OmeroDataService#advancedSearchFor(SearchDataContext) */ - public Object advancedSearchFor(SearchDataContext context) + public Object advancedSearchFor(SecurityContext ctx, SearchDataContext context) throws DSOutOfServiceException, DSAccessException { return null; @@ -84,7 +86,7 @@ public Object advancedSearchFor(SearchDataContext context) * No-operation implementation * @see OmeroDataService#annotateChildren(Set, AnnotationData) */ - public List annotateChildren(Set folders, AnnotationData data) + public List annotateChildren(SecurityContext ctx, Set folders, AnnotationData data) throws DSOutOfServiceException, DSAccessException { return null; @@ -94,7 +96,7 @@ public List annotateChildren(Set folders, AnnotationData data) * No-operation implementation * @see OmeroDataService#changePassword(String, String) */ - public Boolean changePassword(String oldPassword, String newPassword) + public Boolean changePassword(SecurityContext ctx, String oldPassword, String newPassword) throws DSOutOfServiceException, DSAccessException { return Boolean.valueOf(false); @@ -104,7 +106,7 @@ public Boolean changePassword(String oldPassword, String newPassword) * No-operation implementation * @see OmeroDataService#createAnnotationFor(DataObject, AnnotationData) */ - public DataObject createAnnotationFor(DataObject annotatedObject, + public DataObject createAnnotationFor(SecurityContext ctx, DataObject annotatedObject, AnnotationData data) throws DSOutOfServiceException, DSAccessException { @@ -115,7 +117,7 @@ public DataObject createAnnotationFor(DataObject annotatedObject, * No-operation implementation * @see OmeroDataService#createAnnotationFor(Set, AnnotationData) */ - public List createAnnotationFor(Set toAnnotate, AnnotationData data) + public List createAnnotationFor(SecurityContext ctx, Set toAnnotate, AnnotationData data) throws DSOutOfServiceException, DSAccessException { return null; @@ -125,8 +127,8 @@ public List createAnnotationFor(Set toAnnotate, AnnotationData data) * No-operation implementation * @see OmeroDataService#createDataObject(DataObject, DataObject, Collection) */ - public DataObject createDataObject(DataObject newObject, DataObject parent, - Collection children) + public DataObject createDataObject(SecurityContext ctx, DataObject newObject, + DataObject parent, Collection children) throws DSOutOfServiceException, DSAccessException { return null; @@ -136,7 +138,7 @@ public DataObject createDataObject(DataObject newObject, DataObject parent, * No-operation implementation * @see OmeroDataService#cutAndPaste(Map, Map) */ - public void cutAndPaste(Map toPaste, Map toCut) + public void cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut) throws DSOutOfServiceException, DSAccessException { } @@ -145,7 +147,8 @@ public void cutAndPaste(Map toPaste, Map toCut) * No-operation implementation * @see OmeroDataService#deleteContainer(DataObject, boolean) */ - public void deleteContainer(DataObject object, boolean content) + public void deleteContainer(SecurityContext ctx, DataObject object, + boolean content) throws DSOutOfServiceException, DSAccessException { } @@ -154,8 +157,8 @@ public void deleteContainer(DataObject object, boolean content) * No-operation implementation * @see OmeroDataService#findAnnotations(Class, List, List, boolean) */ - public Map findAnnotations(Class nodeType, List nodeIDs, List annotatorIDs, - boolean forUser) + public Map findAnnotations(SecurityContext ctx, Class nodeType, + List nodeIDs, List annotatorIDs, boolean forUser) throws DSOutOfServiceException, DSAccessException { return null; @@ -165,8 +168,8 @@ public Map findAnnotations(Class nodeType, List nodeIDs, List annotatorIDs, * No-operation implementation * @see OmeroDataService#findContainerHierarchy(Class, List, long) */ - public Set findContainerHierarchy(Class rootNodeType, List leavesIDs, - long userID) + public Set findContainerHierarchy(SecurityContext ctx, Class rootNodeType, + List leavesIDs, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -176,7 +179,8 @@ public Set findContainerHierarchy(Class rootNodeType, List leavesIDs, * No-operation implementation * @see OmeroDataService#findContainerPaths(Class, long, long) */ - public Collection findContainerPaths(Class type, long id, long userID) + public Collection findContainerPaths(SecurityContext ctx, Class type, + long id, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -186,7 +190,8 @@ public Collection findContainerPaths(Class type, long id, long userID) * No-op implementation * @see OmeroDataService#getArchivedFiles(String, long) */ - public Map getArchivedImage(String location, long pixelsID) + public Map getArchivedImage(SecurityContext ctx, String location, + long pixelsID) throws DSOutOfServiceException, DSAccessException { return null; @@ -196,7 +201,7 @@ public Map getArchivedImage(String location, long pixelsID) * No-op implementation * @see OmeroDataService#getChannelsMetadata(long) */ - public List getChannelsMetadata(long pixelsID) + public List getChannelsMetadata(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException { return null; @@ -206,8 +211,8 @@ public List getChannelsMetadata(long pixelsID) * No-op implementation * @see OmeroDataService#getCollectionCount(Class, String, List) */ - public Map getCollectionCount(Class rootNodeType, String property, - List rootNodeIDs) + public Map getCollectionCount(SecurityContext ctx, Class rootNodeType, + String property, List rootNodeIDs) throws DSOutOfServiceException, DSAccessException { return null; @@ -217,7 +222,7 @@ public Map getCollectionCount(Class rootNodeType, String property, * No-operation implementation * @see OmeroDataService#getExperimenterImages(long) */ - public Set getExperimenterImages(long userID) + public Set getExperimenterImages(SecurityContext ctx, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -227,7 +232,8 @@ public Set getExperimenterImages(long userID) * No-operation implementation * @see OmeroDataService#getImages(Class, List, long) */ - public Set getImages(Class nodeType, List nodeIDs, long userID) + public Set getImages(SecurityContext ctx, Class nodeType, List nodeIDs, + long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -237,8 +243,8 @@ public Set getImages(Class nodeType, List nodeIDs, long userID) * No-operation implementation * @see OmeroDataService#getImagesAllPeriodCount(Timestamp, Timestamp, long) */ - public List getImagesAllPeriodCount(Timestamp lowerTime, Timestamp time, - long userID) + public List getImagesAllPeriodCount(SecurityContext ctx, + Timestamp lowerTime, Timestamp time, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -248,8 +254,8 @@ public List getImagesAllPeriodCount(Timestamp lowerTime, Timestamp time, * No-operation implementation * @see OmeroDataService#getImagesPeriod(Timestamp, Timestamp, long, boolean) */ - public Collection getImagesPeriod(Timestamp lowerTime, Timestamp time, long userID, - boolean asDataObject) + public Collection getImagesPeriod(SecurityContext ctx, Timestamp lowerTime, + Timestamp time, long userID, boolean asDataObject) throws DSOutOfServiceException, DSAccessException { return null; @@ -265,7 +271,7 @@ public Collection getImagesPeriod(Timestamp lowerTime, Timestamp time, long user * No-operation implementation * @see OmeroDataService#getOriginalFiles(long) */ - public Collection getOriginalFiles(long pixelsID) + public Collection getOriginalFiles(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException { return null; @@ -281,7 +287,7 @@ public Collection getOriginalFiles(long pixelsID) * No-operation implementation * @see OmeroDataService#getSpace(int, long) */ - public long getSpace(int index, long userID) + public long getSpace(SecurityContext ctx, int index, long userID) throws DSOutOfServiceException, DSAccessException { return 0; @@ -292,8 +298,8 @@ public long getSpace(int index, long userID) * @see OmeroDataService#loadContainerHierarchy(Class, List, boolean, long, * long) */ - public Set loadContainerHierarchy(Class rootNodeType, List rootNodeIDs, - boolean withLeaves, long userID, long groupID) + public Set loadContainerHierarchy(SecurityContext ctx, Class rootNodeType, + List rootNodeIDs, boolean withLeaves, long userID, long groupID) throws DSOutOfServiceException, DSAccessException { return null; @@ -303,7 +309,8 @@ public Set loadContainerHierarchy(Class rootNodeType, List rootNodeIDs, * No-operation implementation * @see OmeroDataService#loadExistingObjects(Class, List, long) */ - public Set loadExistingObjects(Class nodeType, List nodeIDs, long userID) + public Set loadExistingObjects(SecurityContext ctx, Class nodeType, + List nodeIDs, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -313,8 +320,8 @@ public Set loadExistingObjects(Class nodeType, List nodeIDs, long userID) * No-operation implementation * @see OmeroDataService#loadPlateWells(long, long, long) */ - public Collection loadPlateWells(long plateID, long acquisitionID, - long userID) + public Collection loadPlateWells(SecurityContext ctx, long plateID, + long acquisitionID, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -324,8 +331,8 @@ public Collection loadPlateWells(long plateID, long acquisitionID, * No-operation implementation * @see OmeroDataService#loadScreenPlates(Class, List, long) */ - public Set loadScreenPlates(Class rootNodeType, List rootNodeIDs, - long userID) + public Set loadScreenPlates(SecurityContext ctx, Class rootNodeType, + List rootNodeIDs, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -335,7 +342,8 @@ public Set loadScreenPlates(Class rootNodeType, List rootNodeIDs, * No-operation implementation * @see OmeroDataService#loadTopContainerHierarchy(Class, long) */ - public Set loadTopContainerHierarchy(Class rootNodeType, long userID) + public Set loadTopContainerHierarchy(SecurityContext ctx, + Class rootNodeType, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -345,7 +353,8 @@ public Set loadTopContainerHierarchy(Class rootNodeType, long userID) * No-operation implementation * @see OmeroDataService#removeDataObjects(Set, DataObject) */ - public Set removeDataObjects(Set children, DataObject parent) + public Set removeDataObjects(SecurityContext ctx, Set children, + DataObject parent) throws DSOutOfServiceException, DSAccessException { return null; @@ -355,7 +364,7 @@ public Set removeDataObjects(Set children, DataObject parent) * No-operation implementation * @see OmeroDataService#updateAnnotationFor(Map) */ - public List updateAnnotationFor(Map toUpdate) + public List updateAnnotationFor(SecurityContext ctx, Map toUpdate) throws DSOutOfServiceException, DSAccessException { return null; @@ -365,7 +374,7 @@ public List updateAnnotationFor(Map toUpdate) * No-operation implementation * @see OmeroDataService#updateDataObject(DataObject) */ - public DataObject updateDataObject(DataObject object) + public DataObject updateDataObject(SecurityContext ctx, DataObject object) throws DSOutOfServiceException, DSAccessException { return null; @@ -375,8 +384,8 @@ public DataObject updateDataObject(DataObject object) * No-operation implementation * @see OmeroDataService#updateExperimenter(ExperimenterData, GroupData) */ - public ExperimenterData updateExperimenter(ExperimenterData exp, GroupData - group) + public ExperimenterData updateExperimenter(SecurityContext ctx, + ExperimenterData exp, GroupData group) throws DSOutOfServiceException, DSAccessException { return null; @@ -386,7 +395,8 @@ public ExperimenterData updateExperimenter(ExperimenterData exp, GroupData * No-operation implementation * @see OmeroDataService#delete(Collection) */ - public DeleteCallback delete(Collection objects) + public DeleteCallback delete(SecurityContext ctx, + Collection objects) throws DSOutOfServiceException, DSAccessException { return null; @@ -396,7 +406,7 @@ public DeleteCallback delete(Collection objects) * No-operation implementation * @see OmeroDataService#getImage(long, long) */ - public ImageData getImage(long imageID, long userID) + public ImageData getImage(SecurityContext ctx, long imageID, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -414,10 +424,22 @@ public String getServerVersion() { * No-operation implementation * @see OmeroDataService#getServerVersion() */ - public FSFileSystemView getFSRepositories(long userID) + public FSFileSystemView getFSRepositories(SecurityContext ctx, long userID) throws DSOutOfServiceException, DSAccessException { return null; } + /** + * No-operation implementation + * @see OmeroDataService#transfer(SecurityContext, List, SecurityContext, List) + */ + public RequestCallback transfer(SecurityContext ctx, + SecurityContext target, List targetNode, + List objects) throws DSOutOfServiceException, + DSAccessException, ProcessException + { + return null; + } + } diff --git a/components/insight/TEST/org/openmicroscopy/shoola/env/data/NullRenderingService.java b/components/insight/TEST/org/openmicroscopy/shoola/env/data/NullRenderingService.java index bb537c9928e..44ba0cf3c25 100644 --- a/components/insight/TEST/org/openmicroscopy/shoola/env/data/NullRenderingService.java +++ b/components/insight/TEST/org/openmicroscopy/shoola/env/data/NullRenderingService.java @@ -50,6 +50,7 @@ import org.openmicroscopy.shoola.env.data.model.ROIResult; import org.openmicroscopy.shoola.env.data.model.SaveAsParam; import org.openmicroscopy.shoola.env.data.model.ScriptObject; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.rnd.RenderingControl; import org.openmicroscopy.shoola.env.rnd.RenderingServiceException; import org.openmicroscopy.shoola.env.rnd.RndProxyDef; @@ -83,7 +84,8 @@ public class NullRenderingService * No-op implementation * @see OmeroImageService#loadRenderingControl(long) */ - public RenderingControl loadRenderingControl(long pixelsID) + public RenderingControl loadRenderingControl(SecurityContext ctx, + long pixelsID) throws DSOutOfServiceException, DSAccessException { return null; @@ -93,8 +95,8 @@ public RenderingControl loadRenderingControl(long pixelsID) * No-op implementation * @see OmeroImageService#renderImage(long, PlaneDef, boolean, boolean) */ - public Object renderImage(long pixelsID, PlaneDef pd, boolean asTexture, - boolean largeImage) + public Object renderImage(SecurityContext ctx, long pixelsID, PlaneDef pd, + boolean asTexture, boolean largeImage) throws RenderingServiceException { return null; @@ -104,13 +106,13 @@ public Object renderImage(long pixelsID, PlaneDef pd, boolean asTexture, * No-op implementation * @see OmeroImageService#shutDown(long) */ - public void shutDown(long pixelsID) {} + public void shutDown(SecurityContext ctx, long pixelsID) {} /** * No-op implementation * @see OmeroImageService#loadPixels(long) */ - public PixelsData loadPixels(long pixelsID) + public PixelsData loadPixels(SecurityContext ctx, long pixelsID) throws DSOutOfServiceException, DSAccessException { return null; @@ -120,7 +122,8 @@ public PixelsData loadPixels(long pixelsID) * No-op implementation * @see OmeroImageService#getPlane(long, int, int, int) */ - public byte[] getPlane(long pixelsID, int z, int t, int c) + public byte[] getPlane(SecurityContext ctx, long pixelsID, int z, int t, + int c) throws DSOutOfServiceException, DSAccessException { return null; @@ -130,8 +133,8 @@ public byte[] getPlane(long pixelsID, int z, int t, int c) * No-op implementation * @see OmeroImageService#pasteRenderingSettings(long, Class, List) */ - public Map pasteRenderingSettings(long pixelsID, Class rootNodeType, - List nodeIDs) + public Map pasteRenderingSettings(SecurityContext ctx, + long pixelsID, Class rootNodeType, List nodeIDs) throws DSOutOfServiceException, DSAccessException { return null; @@ -141,7 +144,8 @@ public Map pasteRenderingSettings(long pixelsID, Class rootNodeType, * No-op implementation * @see OmeroImageService#reloadRenderingService(long) */ - public RenderingControl reloadRenderingService(long pixelsID) + public RenderingControl reloadRenderingService(SecurityContext ctx, + long pixelsID) throws DSAccessException, RenderingServiceException { return null; @@ -151,7 +155,8 @@ public RenderingControl reloadRenderingService(long pixelsID) * No-op implementation * @see OmeroImageService#resetRenderingSettings(Class, Set) */ - public Map resetRenderingSettings(Class rootNodeType, List nodeIDs) + public Map resetRenderingSettings(SecurityContext ctx, Class rootNodeType, + List nodeIDs) throws DSOutOfServiceException, DSAccessException { return null; @@ -161,7 +166,8 @@ public Map resetRenderingSettings(Class rootNodeType, List nodeIDs) * No-op implementation * @see OmeroImageService#getRenderingSettings(long, long) */ - public Map getRenderingSettings(long pixelsID, long userID) + public Map getRenderingSettings(SecurityContext ctx, long pixelsID, + long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -171,7 +177,8 @@ public Map getRenderingSettings(long pixelsID, long userID) * No-op implementation * @see OmeroImageService#resetRenderingService(long) */ - public RenderingControl resetRenderingService(long pixelsID) + public RenderingControl resetRenderingService(SecurityContext ctx, + long pixelsID) throws DSAccessException, RenderingServiceException { return null; @@ -181,8 +188,8 @@ public RenderingControl resetRenderingService(long pixelsID) * No-op implementation * @see OmeroImageService#getThumbnail(long, int, int, long) */ - public BufferedImage getThumbnail(long pixelsID, int sizeX, int sizeY, - long userID) + public BufferedImage getThumbnail(SecurityContext ctx, long pixelsID, + int sizeX, int sizeY, long userID) throws RenderingServiceException { return null; @@ -192,7 +199,7 @@ public BufferedImage getThumbnail(long pixelsID, int sizeX, int sizeY, * No-op implementation * @see OmeroImageService#setMinMaxSettings(Class, List) */ - public Map setMinMaxSettings(Class rootNodeType, + public Map setMinMaxSettings(SecurityContext ctx, Class rootNodeType, List nodeIDs) throws DSOutOfServiceException, DSAccessException { @@ -203,8 +210,8 @@ public Map setMinMaxSettings(Class rootNodeType, * No-op implementation * @see OmeroImageService#getThumbnailSet(List, int) */ - public Map getThumbnailSet(List pixelsID, - int maxLength) + public Map getThumbnailSet(SecurityContext ctx, + List pixelsID, int maxLength) throws RenderingServiceException { return null; @@ -214,8 +221,9 @@ public Map getThumbnailSet(List pixelsID, * No-op implementation * @see OmeroImageService#renderProjected(long, int, int, int, int, List) */ - public BufferedImage renderProjected(long pixelsID, int startZ, int endZ, - int stepping, int type, List channels) + public BufferedImage renderProjected(SecurityContext ctx, long pixelsID, + int startZ, int endZ, int stepping, int type, + List channels) throws RenderingServiceException, DSOutOfServiceException { return null; @@ -225,7 +233,7 @@ public BufferedImage renderProjected(long pixelsID, int startZ, int endZ, * No-op implementation * @see OmeroImageService#projectImage(ProjectionParam) */ - public ImageData projectImage(ProjectionParam ref) + public ImageData projectImage(SecurityContext ctx, ProjectionParam ref) throws DSOutOfServiceException, DSAccessException { return null; @@ -235,24 +243,25 @@ public ImageData projectImage(ProjectionParam ref) * No-op implementation * @see OmeroImageService#shutDownDataSink(long) */ - public void shutDownDataSink(long pixelsID) {} + public void shutDownDataSink(SecurityContext ctx, long pixelsID) {} /** * No-op implementation * @see OmeroImageService#createRenderingSettings(long, RndProxyDef, List) */ - public Boolean createRenderingSettings(long pixelsID, RndProxyDef rndToCopy, - List indexes) + public Boolean createRenderingSettings(SecurityContext ctx, long pixelsID, + RndProxyDef rndToCopy, List indexes) throws DSOutOfServiceException, DSAccessException { - return Boolean.TRUE; + return Boolean.valueOf(true); } /** * No-op implementation * @see OmeroImageService#loadPlaneInfo(long, int, int, int) */ - public Collection loadPlaneInfo(long pixelsID, int z, int t, int channel) + public Collection loadPlaneInfo(SecurityContext ctx, long pixelsID, int z, + int t, int channel) throws DSOutOfServiceException, DSAccessException { return null; @@ -272,8 +281,8 @@ public FileFilter[] getSupportedFileFormats() * @see OmeroImageService#importImage(ImportableObject, ImportableFile, * long, long, boolean) */ - public Object importFile(ImportableObject object, ImportableFile file, - long userID, long groupID, boolean close) + public Object importFile(ImportableObject object, + ImportableFile file, long userID, long groupID, boolean close) throws ImportException { return null; @@ -283,40 +292,34 @@ public Object importFile(ImportableObject object, ImportableFile file, * No-op implementation * @see OmeroImageService#getFSFileSystemView() */ - public FileSystemView getFSFileSystemView() { return null; } - - public Object monitor(String path, DataObject container, - long userID, long groupID) + public FileSystemView getFSFileSystemView(SecurityContext ctx) { return null; } - /** - * No-op implementation - * @see OmeroImageService#createMovie(long, List, MovieExportParam) - */ - public ScriptCallback createMovie(long imageID, long pixelsID, - List channels, MovieExportParam param) - throws DSOutOfServiceException, DSAccessException + public Object monitor(SecurityContext ctx, String path, DataObject container, + long userID, long groupID) { return null; } /** * No-op implementation - * @see OmeroImageService#analyseFretFit(long, long, long) + * @see OmeroImageService#createMovie(long, List, MovieExportParam) */ - public DataObject analyseFretFit(long controlID, long toAnalyzeID, - long irfID) throws DSOutOfServiceException, DSAccessException + public ScriptCallback createMovie(SecurityContext ctx, long imageID, + long pixelsID, List channels, MovieExportParam param) + throws DSOutOfServiceException, DSAccessException { return null; } - + /** * No-op implementation * @see OmeroImageService#loadROI(long, List, long) */ - public List loadROI(long imageID, ListfileID, long userID) + public List loadROI(SecurityContext ctx, long imageID, + ListfileID, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -326,8 +329,9 @@ public List loadROI(long imageID, ListfileID, long userID) * No-op implementation * @see OmeroImageService#exportImageAsOMETiff(long, File) */ - public Object exportImageAsOMETiff(long imageID, File folder) - throws DSOutOfServiceException, DSAccessException + public Object exportImageAsOMETiff(SecurityContext ctx, long imageID, + File folder) + throws DSOutOfServiceException, DSAccessException { return null; } @@ -337,9 +341,11 @@ public Object exportImageAsOMETiff(long imageID, File folder) * @see OmeroImageService#renderProjectedAsTexture(long, int, int, int, int, * List) */ - public TextureData renderProjectedAsTexture(long pixelsID, int startZ, - int endZ, int stepping, int type, List channels) - throws RenderingServiceException, DSOutOfServiceException { + public TextureData renderProjectedAsTexture(SecurityContext ctx, + long pixelsID, int startZ, int endZ, int stepping, int type, + List channels) + throws RenderingServiceException, DSOutOfServiceException + { return null; } @@ -347,8 +353,9 @@ public TextureData renderProjectedAsTexture(long pixelsID, int startZ, * No-op implementation * @see OmeroImageService#getRenderingSettingsFor(long, long) */ - public List getRenderingSettingsFor(long pixelsID, long userID) - throws DSOutOfServiceException, DSAccessException + public List getRenderingSettingsFor(SecurityContext ctx, long pixelsID, + long userID) + throws DSOutOfServiceException, DSAccessException { return null; } @@ -357,8 +364,9 @@ public List getRenderingSettingsFor(long pixelsID, long userID) * No-op implementation * @see OmeroImageService#createFigure(List, Class, Object) */ - public ScriptCallback createFigure(List ids, Class type, Object parameters) - throws DSOutOfServiceException, DSAccessException + public ScriptCallback createFigure(SecurityContext ctx, + List ids, Class type, Object parameters) + throws DSOutOfServiceException, DSAccessException { return null; } @@ -367,8 +375,9 @@ public ScriptCallback createFigure(List ids, Class type, Object parameters * No-op implementation * @see OmeroImageService#saveROI(long, long, List) */ - public List saveROI(long imageID, long userID, List list) - throws DSOutOfServiceException, DSAccessException + public List saveROI(SecurityContext ctx, long imageID, long userID, + List list) + throws DSOutOfServiceException, DSAccessException { return null; } @@ -377,7 +386,8 @@ public List saveROI(long imageID, long userID, List list) * No-op implementation * @see OmeroImageService#loadROIFromServer(long, long) */ - public List loadROIFromServer(long imageID, long userID) + public List loadROIFromServer(SecurityContext ctx, long imageID, + long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -387,7 +397,8 @@ public List loadROIFromServer(long imageID, long userID) * No-op implementation * @see OmeroImageService#renderOverLays(long, PlaneDef, long, Map, boolean) */ - public Object renderOverLays(long pixelsID, PlaneDef pd, long tableID, + public Object renderOverLays(SecurityContext ctx, long pixelsID, + PlaneDef pd, long tableID, Map overlays, boolean asTexture) throws RenderingServiceException { @@ -396,19 +407,9 @@ public Object renderOverLays(long pixelsID, PlaneDef pd, long tableID, /** * No-op implementation - * @see OmeroImageService#analyseFrap(List, Class, Object) - */ - public DataObject analyseFrap(List ids, Class type, Object param) - throws DSOutOfServiceException, DSAccessException - { - return null; - } - - /** - * No-op implementation * @see OmeroImageService#runScript(ScriptObject) */ - public ScriptCallback runScript(ScriptObject script) + public ScriptCallback runScript(SecurityContext ctx, ScriptObject script) throws DSOutOfServiceException, DSAccessException { return null; @@ -418,7 +419,7 @@ public ScriptCallback runScript(ScriptObject script) * No-op implementation * @see OmeroImageService#getScriptsAsString() */ - public Map getScriptsAsString() + public Map getScriptsAsString(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException { return null; @@ -428,7 +429,8 @@ public Map getScriptsAsString() * No-op implementation * @see OmeroImageService#loadROIMeasurements(Class, long, long) */ - public Collection loadROIMeasurements(Class type, long id, long userID) + public Collection loadROIMeasurements(SecurityContext ctx, Class type, + long id, long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -438,7 +440,8 @@ public Collection loadROIMeasurements(Class type, long id, long userID) * No-op implementation * @see OmeroImageService#loadAvailableScripts(long) */ - public List loadAvailableScripts(long userID) + public List loadAvailableScripts(SecurityContext ctx, + long userID) throws DSOutOfServiceException, DSAccessException { return null; @@ -448,7 +451,7 @@ public List loadAvailableScripts(long userID) * No-op implementation * @see OmeroImageService#loadAvailableScriptsWithUI() */ - public List loadAvailableScriptsWithUI() + public List loadAvailableScriptsWithUI(SecurityContext ctx) throws DSOutOfServiceException, DSAccessException { return null; @@ -458,7 +461,7 @@ public List loadAvailableScriptsWithUI() * No-op implementation * @see OmeroImageService#uploadScript(ScriptObject) */ - public Object uploadScript(ScriptObject script) + public Object uploadScript(SecurityContext ctx, ScriptObject script) throws DSOutOfServiceException, DSAccessException { return null; @@ -468,7 +471,7 @@ public Object uploadScript(ScriptObject script) * No-op implementation * @see OmeroImageService#getFSThumbnailSet(List, int, long) */ - public Map getFSThumbnailSet( + public Map getFSThumbnailSet(SecurityContext ctx, List files, int maxLength, long userID) throws DSAccessException, DSOutOfServiceException, FSAccessException @@ -481,7 +484,7 @@ public Map getFSThumbnailSet( * @see OmeroImageService#getExperimenterThumbnailSet(List, int) */ public Map getExperimenterThumbnailSet( - List experimenters, int maxLength) + SecurityContext ctx, List experimenters, int maxLength) throws DSAccessException, DSOutOfServiceException { return null; @@ -491,7 +494,7 @@ public Map getExperimenterThumbnailSet( * No-op implementation * @see OmeroImageService#loadScript(long) */ - public ScriptObject loadScript(long scriptID) + public ScriptObject loadScript(SecurityContext ctx, long scriptID) throws ProcessException { return null; @@ -501,7 +504,8 @@ public ScriptObject loadScript(long scriptID) * No-op implementation * @see OmeroImageService#setOwnerRenderingSettings(Class, List) */ - public Map setOwnerRenderingSettings(Class rootNodeType, List nodeIDs) + public Map setOwnerRenderingSettings(SecurityContext ctx, + Class rootNodeType, List nodeIDs) throws DSOutOfServiceException, DSAccessException { return null; @@ -511,7 +515,8 @@ public Map setOwnerRenderingSettings(Class rootNodeType, List nodeIDs) * No-op implementation * @see OmeroImageService#retrieveWorkflows(long) */ - public List retrieveWorkflows(long userID) + public List retrieveWorkflows(SecurityContext ctx, + long userID) throws DSAccessException, DSOutOfServiceException { // TODO Auto-generated method stub @@ -522,21 +527,23 @@ public List retrieveWorkflows(long userID) * No-op implementation * @see OmeroImageService#storeWorkflows(List, long) */ - public Object storeWorkflows(List workflows, long userID) + public Object storeWorkflows(SecurityContext ctx, + List workflows, long userID) throws DSAccessException, DSOutOfServiceException { return null; } - public ScriptCallback saveAs(SaveAsParam param) throws DSAccessException, - DSOutOfServiceException { - // TODO Auto-generated method stub + public ScriptCallback saveAs(SecurityContext ctx, + SaveAsParam param) throws DSAccessException, + DSOutOfServiceException + { return null; } - public Boolean isLargeImage(long pixelsId) throws DSAccessException, + public Boolean isLargeImage(SecurityContext ctx, long pixelsId) + throws DSAccessException, DSOutOfServiceException { - // TODO Auto-generated method stub return null; } diff --git a/components/insight/TEST/org/openmicroscopy/shoola/env/data/t/TestExample.java b/components/insight/TEST/org/openmicroscopy/shoola/env/data/t/TestExample.java index 51391d11441..bae4bd90100 100644 --- a/components/insight/TEST/org/openmicroscopy/shoola/env/data/t/TestExample.java +++ b/components/insight/TEST/org/openmicroscopy/shoola/env/data/t/TestExample.java @@ -34,6 +34,7 @@ import org.openmicroscopy.shoola.env.data.DataServicesTestCase; import org.openmicroscopy.shoola.env.data.OmeroDataService; import org.openmicroscopy.shoola.env.data.events.DSCallAdapter; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.env.data.views.HierarchyBrowsingView; /** @@ -102,7 +103,7 @@ public void testOmeroService() //Note that calls to the DMS are synchronous even when the Container //is not in test mode. long start = System.currentTimeMillis(), end; - os.getExperimenterImages(1); + os.getExperimenterImages(new SecurityContext(0), 1); //TODO: check result. end = System.currentTimeMillis(); assertTrue("The call took too long: "+(end-start)+"ms.", diff --git a/components/insight/TEST/org/openmicroscopy/shoola/env/init/DataServicesTestsInit.java b/components/insight/TEST/org/openmicroscopy/shoola/env/init/DataServicesTestsInit.java index ef2e057c9f2..d56bf998d4c 100644 --- a/components/insight/TEST/org/openmicroscopy/shoola/env/init/DataServicesTestsInit.java +++ b/components/insight/TEST/org/openmicroscopy/shoola/env/init/DataServicesTestsInit.java @@ -130,7 +130,7 @@ void rollback() try { DataServicesFactory factory = DataServicesFactory.getInstance(container); - factory.shutdown(); + factory.shutdown(null); } catch (DSOutOfServiceException e) {} } diff --git a/components/insight/TEST/org/openmicroscopy/shoola/env/ui/NullUserNotifier.java b/components/insight/TEST/org/openmicroscopy/shoola/env/ui/NullUserNotifier.java index 61c48f0f925..d0274958144 100644 --- a/components/insight/TEST/org/openmicroscopy/shoola/env/ui/NullUserNotifier.java +++ b/components/insight/TEST/org/openmicroscopy/shoola/env/ui/NullUserNotifier.java @@ -36,6 +36,7 @@ //Application-internal dependencies import org.openmicroscopy.shoola.env.data.model.ApplicationData; +import org.openmicroscopy.shoola.env.data.util.SecurityContext; import org.openmicroscopy.shoola.util.file.ImportErrorObject; import org.openmicroscopy.shoola.util.ui.MessengerDialog; import pojos.FileAnnotationData; @@ -131,9 +132,9 @@ public void notifyDownload(Collection data, File directory) {} public void setLoadingStatus(int percent, long id, String name) {} /** - * @see UserNotifier#notifyActivity(Object) + * @see UserNotifier#notifyActivity(SecurityContext, Object) */ - public void notifyActivity(Object activity) {} + public void notifyActivity(SecurityContext ctx, Object activity) {} /** * @see UserNotifier#openApplication(ApplicationData, String) diff --git a/components/insight/config/treeviewer.xml b/components/insight/config/treeviewer.xml index 857ab56477c..7e50f06a4e0 100644 --- a/components/insight/config/treeviewer.xml +++ b/components/insight/config/treeviewer.xml @@ -26,7 +26,7 @@ * General set up for the data manager ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> true - + false