Skip to content

Commit

Permalink
Merge pull request #305 from dominikl/connection_issues
Browse files Browse the repository at this point in the history
Move gateway calls to OMEROGateway
  • Loading branch information
jburel authored Nov 10, 2022
2 parents bb4f399 + 236562e commit 420cf06
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1309,9 +1309,6 @@ void deleteFolders(Collection<FolderData> folders) {

/**
* Add ROIs to Folders
*
* @param selectedObjects
* The ROIs
* @param folders
* The Folders
* @param async
Expand All @@ -1337,16 +1334,7 @@ Collection<FolderData> saveROIFolders(Collection<FolderData> folders,
try {
Registry reg = MetadataViewerAgent.getRegistry();
OmeroDataService ods = reg.getDataService();
Gateway gw = ods.getGateway();
DataManagerFacility dm = gw
.getFacility(DataManagerFacility.class);
List<IObject> objs = new ArrayList<IObject>(folders.size());
for (FolderData f : folders)
objs.add(f.asIObject());
objs = dm.saveAndReturnObject(getSecurityContext(), objs, null,
null);
Collection<FolderData> result = PojoMapper
.asCastedDataObjects(objs);
Collection<FolderData> result = ods.saveROIFolders(getSecurityContext(), folders);
Collection<Long> ids = Pojos.extractIds(this.folders);
for (FolderData f : result) {
if (!ids.contains(f.getId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ public static DataServicesFactory getInstance(Container c)
/** The Administration service adapter. */
private AdminService admin;

/** Flag indicating that we try to re-establish the connection.*/
private final AtomicBoolean reconnecting = new AtomicBoolean(false);

/**
* Attempts to create a new instance.
*
Expand Down Expand Up @@ -262,15 +259,13 @@ public void propertyChange(PropertyChangeEvent evt) {
String name = evt.getPropertyName();
if (NotificationDialog.CLOSE_NOTIFICATION_PROPERTY.equals(name))
{
reconnecting.set(false);
connectionDialog = null;
exitApplication(true, true);
} else if (
NotificationDialog.CANCEL_NOTIFICATION_PROPERTY.equals(
name))
{
connectionDialog = null;
reconnecting.set(false);
int index = (Integer) evt.getNewValue();
if (index == ConnectionExceptionHandler.LOST_CONNECTION)
reconnect();
Expand Down Expand Up @@ -335,7 +330,6 @@ private void reconnect()
connectionDialog.setVisible(false);
connectionDialog.dispose();
connectionDialog = null;
reconnecting.set(false);
} else {
//connectionDialog.setVisible(false);
message = "A failure occurred while attempting to " +
Expand Down Expand Up @@ -368,8 +362,8 @@ int runAsPlugin()
*/
public void sessionExpiredExit(int index, Throwable exc)
{
if (reconnecting.get()) return;
reconnecting.set(true);
if (connectionDialog != null && connectionDialog.isVisible())
return;
String message;
if (exc != null) {
LogMessage msg = new LogMessage();
Expand Down
119 changes: 67 additions & 52 deletions src/main/java/org/openmicroscopy/shoola/env/data/OMEROGateway.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import omero.api.StatefulServiceInterfacePrx;

import omero.gateway.model.FolderData;
import org.openmicroscopy.shoola.env.data.model.DeletableObject;

import omero.gateway.Gateway;
Expand Down Expand Up @@ -58,12 +60,6 @@ public interface OmeroDataService
*/
public static final String IMAGES_PROPERTY = "images";

/**
* Get a reference to the {@link Gateway}
* @return See above
*/
public Gateway getGateway();

/**
* Retrieves hierarchy trees rooted by a given node.
* i.e. the requested node as root and all of its descendants.
Expand Down Expand Up @@ -506,5 +502,11 @@ public Map<Long, Map<Boolean, List<ImageData>>> getImagesBySplitFilesets(
* @throws DSAccessException If an error occurred while trying to
* retrieve data from OMERO service.
*/
public Map<Long, List<DatasetData>> findDatasetsByImageId(SecurityContext ctx, List<Long> imgIds) throws DSOutOfServiceException, DSAccessException;
public Map<Long, List<DatasetData>> findDatasetsByImageId(SecurityContext ctx, List<Long> imgIds)
throws DSOutOfServiceException, DSAccessException;

public Collection<FolderData> saveROIFolders(SecurityContext ctx, Collection<FolderData> folders)
throws ExecutionException, DSOutOfServiceException, DSAccessException;

public int getROICount(SecurityContext ctx, long imageId) throws DSOutOfServiceException, DSAccessException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import omero.cmd.Request;
import omero.cmd.graphs.ChildOption;
import omero.gateway.facility.DataManagerFacility;
import omero.gateway.model.FolderData;
import omero.model.Annotation;
import omero.model.AnnotationAnnotationLink;
import omero.model.Dataset;
Expand Down Expand Up @@ -115,11 +118,6 @@ class OmeroDataServiceImpl
/** Reference to the entry point to access the <i>OMERO</i> services. */
private OMEROGateway gateway;

@Override
public Gateway getGateway() {
return gateway.getGateway();
}

/**
* Unlinks the collection of children from the specified parent.
*
Expand Down Expand Up @@ -494,7 +492,6 @@ public void cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut)

/**
* Implemented as specified by {@link OmeroDataService}.
* @see OmeroDataService#getArchivedFiles(SecurityContext, File, long, boolean)
*/
public Map<Boolean, Object> getArchivedImage(SecurityContext ctx,
File file, long imageID, boolean keepOriginalPath)
Expand All @@ -508,7 +505,6 @@ public Map<Boolean, Object> getArchivedImage(SecurityContext ctx,

/**
* Implemented as specified by {@link OmeroDataService}.
* @see OmeroDataService#updateExperimenter(SecurityContext, ExperimenterData, GroupData)
*/
public ExperimenterData updateExperimenter(SecurityContext ctx,
ExperimenterData exp, GroupData group)
Expand Down Expand Up @@ -589,7 +585,6 @@ public List getImagesAllPeriodCount(SecurityContext ctx,

/**
* Implemented as specified by {@link OmeroDataService}.
* @see OmeroDataService#advancedSearchFor(List, SearchDataContext)
*/
public SearchResultCollection search(SecurityContext ctx,
SearchParameters context)
Expand Down Expand Up @@ -730,7 +725,7 @@ private void initializeImages(SearchResultCollection results) {

/**
* Tries to convert all search terms into ids;
* @param terms
* @param query terms
* @return The ids or null if one or multiple terms contain non numeric characters
*/
private long[] convertSearchTermsToIds(String query) {
Expand Down Expand Up @@ -1148,7 +1143,6 @@ public Map<Long, Map<Boolean, List<ImageData>>> getImagesBySplitFilesets(

/**
* Implemented as specified by {@link OmeroDataService}.
* @see OmeroDataService#findDatasetsByImageId(SecurityContext ctx, imgId)
*/
public Map<Long, List<DatasetData>> findDatasetsByImageId(SecurityContext ctx, List<Long> imgIds) throws DSOutOfServiceException, DSAccessException
{
Expand All @@ -1173,4 +1167,12 @@ public Map<Long, List<DatasetData>> findDatasetsByImageId(SecurityContext ctx, L
return result;
}

public Collection<FolderData> saveROIFolders(SecurityContext ctx, Collection<FolderData> folders)
throws DSOutOfServiceException, DSAccessException {
return gateway.saveROIFolders(ctx, folders);
}

public int getROICount(SecurityContext ctx, long imageId) throws DSOutOfServiceException, DSAccessException {
return gateway.getROICount(ctx, imageId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -862,4 +862,9 @@ RndProxyDef getSettings(SecurityContext ctx, long rndID)
*/
RawPixelsStorePrx createPixelsStore(SecurityContext ctx)
throws DSAccessException, DSOutOfServiceException;

public Map<Integer, int[]> getHistogram(SecurityContext ctx,
PixelsData pixels,
int[] channels, int z, int t) throws DSAccessException,
DSOutOfServiceException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,8 @@ private int getNumberOfRenderingEngines(SecurityContext ctx, long pixelsID)
* 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.
* @param ioList The containers where to import the files.
* @param list The list of annotations.
* @param userID The identifier of the user.
* @param hcs Value returns by the import containers.
Expand Down Expand Up @@ -327,9 +325,9 @@ private BufferedImage createImage(byte[] values)
}

/**
* Creates a <code>BufferedImage</code> from the passed array of bytes.
* Creates a <code>BufferedImage</code> from the passed path.
*
* @param values The array of bytes.
* @param path The path,
* @return See above.
* @throws RenderingServiceException If we cannot create an image.
*/
Expand Down Expand Up @@ -570,8 +568,7 @@ private Collection<String> getLookupTables(SecurityContext ctx) {
return OmeroImageServiceImpl.LOOKUP_TABLES;

try {
OmeroImageServiceImpl.LOOKUP_TABLES = gateway.getGateway()
.getFacility(BrowseFacility.class).getLookupTables(ctx);
OmeroImageServiceImpl.LOOKUP_TABLES = gateway.getLookupTables(ctx);
return OmeroImageServiceImpl.LOOKUP_TABLES;
} catch (Exception e) {
context.getLogger().warn(this, e.getMessage());
Expand Down Expand Up @@ -644,7 +641,6 @@ public BufferedImage getThumbnail(SecurityContext ctx,long pixID, int sizeX,

/**
* Implemented as specified by {@link OmeroImageService}.
* @see OmeroImageService#getThumbnailSet(SecurityContext, List, int)
*/
public Map<Long, BufferedImage> getThumbnailSet(SecurityContext ctx,
Collection<Long> pixelsID, int max)
Expand Down Expand Up @@ -839,7 +835,6 @@ public Map pasteRenderingSettings(SecurityContext ctx, long pixelsID,

/**
* Implemented as specified by {@link OmeroImageService}.
* @see OmeroImageService#resetRenderingSettings(Class, List)
*/
public Map resetRenderingSettings(SecurityContext ctx, Class rootNodeType,
List nodesID)
Expand Down Expand Up @@ -879,7 +874,6 @@ public Map setOwnerRenderingSettings(SecurityContext ctx,

/**
* Implemented as specified by {@link OmeroImageService}.
* @see OmeroImageService#getRenderingSettings(ctx, long, long)
*/
public Map<DataObject, Collection<RndProxyDef>> getRenderingSettings(
SecurityContext ctx, long pixelsID, long userID)
Expand All @@ -890,7 +884,6 @@ public Map<DataObject, Collection<RndProxyDef>> getRenderingSettings(

/**
* Implemented as specified by {@link OmeroImageService}.
* @see OmeroImageService#getRenderingSettingsFor(long, long)
*/
public List<RndProxyDef> getRenderingSettingsFor(SecurityContext ctx,
long pixelsID, long userID)
Expand Down Expand Up @@ -1026,8 +1019,6 @@ private boolean isHCS(List<ImportContainer> containers)

/**
* Implemented as specified by {@link OmeroImageService}.
* @see OmeroImageService#importFile(ImportableObject,
* ImportableFile, long, long, boolean)
*/
public Object importFile(ImportableObject object,
ImportableFile importable, boolean close)
Expand Down Expand Up @@ -1595,8 +1586,6 @@ private File applyTransforms(File inputXML, List<InputStream> transforms,

/**
* Implemented as specified by {@link OmeroImageService}.
* @see OmeroImageService#exportImageAsOMEObject(SecurityContext, int, long,
* File, Target)
*/
public Object exportImageAsOMEFormat(SecurityContext ctx, int index,
long imageID, File file, Target target)
Expand Down Expand Up @@ -1797,7 +1786,6 @@ public Object uploadScript(SecurityContext ctx, ScriptObject script)

/**
* Implemented as specified by {@link OmeroDataService}.
* @see OmeroImageService#loadRatings(SecurityContext, Class, long, long)
*/
public Collection loadROIMeasurements(SecurityContext ctx, Class type,
long id, long userID)
Expand Down Expand Up @@ -2022,7 +2010,6 @@ public Long getRenderingDef(SecurityContext ctx, long pixelsID,

/**
* Implemented as specified by {@link OmeroDataService}.
* @see OmeroImageService#getRenderingDef(SecurityContext, long)
*/
public RndProxyDef getSettings(SecurityContext ctx, long rndID)
throws DSOutOfServiceException, DSAccessException
Expand All @@ -2045,4 +2032,10 @@ public RawPixelsStorePrx createPixelsStore(SecurityContext ctx)
return null;
}

public Map<Integer, int[]> getHistogram(SecurityContext ctx,
PixelsData pixels,
int[] channels, int z, int t) throws DSOutOfServiceException,
DSAccessException {
return gateway.getHistogram(ctx, pixels, channels, z, t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Map;

import omero.gateway.SecurityContext;
import omero.gateway.facility.RawDataFacility;
import omero.gateway.model.ImageData;

import org.openmicroscopy.shoola.env.data.views.BatchCall;
Expand Down Expand Up @@ -61,11 +60,8 @@ public HistogramLoader(final SecurityContext ctx, final ImageData img, final int
final int z, final int t) {
loadCall = new BatchCall("Loading Histogram data") {
public void doCall() throws Exception {
try (RawDataFacility f = context.getGateway().getFacility(
RawDataFacility.class)) {
result = f.getHistogram(ctx, img.getDefaultPixels(),
channels, z, t);
}
result = context.getImageService().getHistogram(ctx, img.getDefaultPixels(),
channels, z, t);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package org.openmicroscopy.shoola.env.data.views.calls;

import omero.gateway.SecurityContext;
import omero.gateway.facility.ROIFacility;

import org.openmicroscopy.shoola.env.data.views.BatchCall;
import org.openmicroscopy.shoola.env.data.views.BatchCallTree;
Expand All @@ -46,8 +45,7 @@ private BatchCall makeLoadCalls(final SecurityContext ctx,
final long imageID) {
return new BatchCall("Load ROI count from Server") {
public void doCall() throws Exception {
results = context.getGateway().getFacility(ROIFacility.class)
.getROICount(ctx, imageID);
results = context.getDataService().getROICount(ctx, imageID);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import omero.api.StatefulServiceInterfacePrx;

import omero.gateway.model.FolderData;
import org.openmicroscopy.shoola.env.data.model.DeletableObject;
import org.openmicroscopy.shoola.env.data.util.SearchDataContext;

Expand Down Expand Up @@ -464,7 +466,17 @@ public Map<Long, List<DatasetData>> findDatasetsByImageId(SecurityContext ctx,
return null;
}

/**
@Override
public Collection<FolderData> saveROIFolders(SecurityContext ctx, Collection<FolderData> folders) throws ExecutionException, DSOutOfServiceException, DSAccessException {
return null;
}

@Override
public int getROICount(SecurityContext ctx, long imageId) throws DSOutOfServiceException, DSAccessException {
return 0;
}

/**
* No-operation implementation
* @see OmeroDataService#search(SecurityContext, SearchParameters)
*/
Expand All @@ -484,9 +496,7 @@ public SearchResultCollection search(SecurityContext ctx,
return null;
}

@Override
public Gateway getGateway() {
// TODO Auto-generated method stub
return null;
}
}
Loading

0 comments on commit 420cf06

Please sign in to comment.