Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/omero/gateway/Gateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,24 @@ public String getSessionId(ExperimenterData user)
return null;
}

/**
* Return the host
*
* @param user The user to get the host for
* @return See above
* @throws DSOutOfServiceException
* If the connection is broken, or not logged in
*/
public String getHost(ExperimenterData user)
throws DSOutOfServiceException {
Connector c = getConnector(new SecurityContext(user.getGroupId()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the Connector needed in that case, just to check if the user is logged in?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to check if we have a connection

false, false);
if (c == null) {
return null;
}
return login.getServer().getHost();
}

/**
* Get the version of the server the Gateway is connected to
*
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/omero/gateway/facility/TransferFacility.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import omero.gateway.SecurityContext;
import omero.gateway.exception.DSAccessException;
import omero.gateway.exception.DSOutOfServiceException;
import omero.gateway.model.DataObject;

import org.apache.commons.collections.CollectionUtils;

/**
* {@link Facility} which provides data transfer functionality, i.e. download
Expand Down Expand Up @@ -70,4 +73,26 @@ public List<File> downloadImage(SecurityContext context, String targetPath,
return helper.downloadImage(context, targetPath, imageId);
}

/**
* Uploads the specified images to the server.
*
* @param ctx The security context.
* @param paths The files to import.
* @param target The container if any.
* @return See above
* @throws DSOutOfServiceException
* If the connection is broken, or not logged in
* @throws DSAccessException
* If an error occurred while trying to retrieve data from OMERO
* service.
*/
public Boolean uploadImagesDirect(final SecurityContext ctx, final List<String> paths,
final DataObject target)
throws DSAccessException, DSOutOfServiceException{
if (CollectionUtils.isEmpty(paths)) {
return Boolean.FALSE;
}
return helper.uploadImagesDirect(ctx, paths, target);
}

}
66 changes: 66 additions & 0 deletions src/main/java/omero/gateway/facility/TransferFacilityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,25 @@
import omero.gateway.SecurityContext;
import omero.gateway.exception.DSAccessException;
import omero.gateway.exception.DSOutOfServiceException;
import omero.gateway.model.DataObject;
import omero.gateway.model.ExperimenterData;
import omero.gateway.model.DatasetData;
import omero.gateway.model.ImageData;
import omero.model.Fileset;
import omero.model.FilesetEntry;
import omero.model.IObject;
import omero.model.OriginalFile;
import omero.sys.ParametersI;
import ome.formats.importer.ImportConfig;
import ome.formats.importer.OMEROWrapper;
import ome.formats.importer.ImportLibrary;
import ome.formats.importer.ImportCandidates;
import ome.formats.importer.ImportContainer;
import ome.formats.importer.cli.ErrorHandler;
import ome.formats.importer.cli.LoggingImportMonitor;

import loci.formats.in.DynamicMetadataOptions;
import loci.formats.in.MetadataLevel;

import org.apache.commons.collections.CollectionUtils;

Expand Down Expand Up @@ -85,7 +99,10 @@ public class TransferFacilityHelper {
* The identifier of the image.
* @return See above
* @throws DSOutOfServiceException
* If the connection is broken, or not logged in
* @throws DSAccessException
* If an error occurred while trying to retrieve data from OMERO
* service.
*/
List<File> downloadImage(SecurityContext context, String targetPath,
long imageId) throws DSAccessException, DSOutOfServiceException {
Expand Down Expand Up @@ -205,6 +222,55 @@ List<File> downloadImage(SecurityContext context, String targetPath,
return files;
}

/**
* Import the specified files into the given container if any.
* Returns the corresponding pixels Data object.
*
* @param context The security context.
* @param paths The paths to the file to import.
* @param object The container where to import the image.
* @return
* @throws DSOutOfServiceException
* If the connection is broken, or not logged in
* @throws DSAccessException
* If an error occurred while trying to retrieve data from OMERO
* service.
*/
Boolean uploadImagesDirect(SecurityContext ctx, List<String> paths, DataObject object)
throws DSAccessException, DSOutOfServiceException
{
String[] values = paths.toArray(new String[0]);
ExperimenterData user = gateway.getLoggedInUser();
String sessionKey = gateway.getSessionId(user);

ImportConfig config = new ImportConfig();
config.hostname.set(gateway.getHost(user));
config.sessionKey.set(sessionKey);

OMEROWrapper reader = new OMEROWrapper(config);

ImportLibrary library = null;
try {
library = new ImportLibrary(config.createStore(), reader);
} catch (Exception e) {
throw new DSAccessException("Cannot create an import store", e);
}
ErrorHandler error_handler = new ErrorHandler(config);

library.addObserver(new LoggingImportMonitor());
ImportCandidates candidates = new ImportCandidates(reader, values, error_handler);
if (object instanceof DatasetData) {
IObject dataset = browse.findIObject(ctx, "omero.model.Dataset", object.getId());
for (ImportContainer c : candidates.getContainers()) {
c.setTarget(dataset);
}
}

reader.setMetadataOptions(new DynamicMetadataOptions(MetadataLevel.ALL));

return library.importCandidates(config, candidates);
}

/**
* Creates the query to load the file set corresponding to a given image.
*
Expand Down
Loading