diff --git a/src/main/java/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java b/src/main/java/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java index ad3c94271..ea4ede411 100644 --- a/src/main/java/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java +++ b/src/main/java/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java @@ -3166,7 +3166,6 @@ else if (!filesetIds.contains(id)) { p = new DownloadArchivedActivityParam(new File(path), images, icon); p.setOverride(override); p.setZip(false); - p.setKeepOriginalPaths(true); un.notifyActivity(ctx, p); } } diff --git a/src/main/java/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerComponent.java b/src/main/java/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerComponent.java index b945c6004..2fc072de1 100644 --- a/src/main/java/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerComponent.java +++ b/src/main/java/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerComponent.java @@ -3709,7 +3709,6 @@ else if (!filesetIds.contains(id)) { folder, archived, icon); p.setOverride(override); p.setZip(false); - p.setKeepOriginalPaths(true); un.notifyActivity(ctx, p); } } diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/OMEROGateway.java b/src/main/java/org/openmicroscopy/shoola/env/data/OMEROGateway.java index b87004859..d061c61b1 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/OMEROGateway.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/OMEROGateway.java @@ -43,6 +43,7 @@ import java.util.concurrent.ExecutionException; import omero.gateway.facility.RawDataFacility; +import omero.gateway.facility.TransferFacility; import omero.gateway.model.FolderData; import omero.gateway.model.PixelsData; import org.apache.commons.collections4.CollectionUtils; @@ -172,7 +173,6 @@ import omero.model.ExperimenterGroupI; import omero.model.FileAnnotation; import omero.model.Fileset; -import omero.model.FilesetEntry; import omero.model.GroupExperimenterMap; import omero.model.IObject; import omero.model.Image; @@ -3042,177 +3042,25 @@ Set getAvailableGroups(SecurityContext ctx, /** * Retrieves the archived files if any for the specified set of pixels. * - * @param ctx The security context. - * @param file The location where to save the files. - * @param image The image to retrieve. - * @param keepOriginalPaths Pass true to preserve the original folder structure - * @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. - */ - Map getArchivedFiles( - SecurityContext ctx, File file, ImageData image, boolean keepOriginalPaths) - throws DSAccessException, DSOutOfServiceException - { - return retrieveArchivedFiles(ctx, file, image); - } - - /** - * Retrieves the archived files if any for the specified set of pixels. - * - * @param ctx The security context. - * @param dir The location where to save the files. + * @param ctx The security context. + * @param dir The location where to save the files. * @param image The image to retrieve. * @return See above. * @throws DSAccessException If an error occurred while trying to - * retrieve data from OMERO service. + * retrieve data from OMERO service. */ - private Map retrieveArchivedFiles( + public List getArchivedFiles( SecurityContext ctx, File dir, ImageData image) - throws DSAccessException - { - List files = null; - String query; + throws DSAccessException, DSOutOfServiceException { + TransferFacility fc = null; try { - IQueryPrx service = gw.getQueryService(ctx); - ParametersI param = new ParametersI(); - long id; - if (image.isFSImage()) { - id = image.getId(); - List l = new ArrayList(); - l.add(omero.rtypes.rlong(id)); - param.add("imageIds", omero.rtypes.rlist(l)); - query = createFileSetQuery(); - } else { //Prior to FS - if (image.isArchived()) { - StringBuffer buffer = new StringBuffer(); - id = image.getDefaultPixels().getId(); - buffer.append("select ofile from OriginalFile as ofile "); - buffer.append("join fetch ofile.hasher "); - buffer.append("left join ofile.pixelsFileMaps as pfm "); - buffer.append("left join pfm.child as child "); - buffer.append("where child.id = :id"); - param.map.put("id", omero.rtypes.rlong(id)); - query = buffer.toString(); - } else return null; - } - files = service.findAllByQuery(query, param); - } catch (Exception e) { - handleConnectionException(e); - throw new DSAccessException("Cannot retrieve original file", e); - } - - Map result = new HashMap(); - if (CollectionUtils.isEmpty(files)) return result; - List downloaded = new ArrayList(); - List notDownloaded = new ArrayList(); - result.put(Boolean.valueOf(true), downloaded); - result.put(Boolean.valueOf(false), notDownloaded); - - if (image.isFSImage()) { - for (Object tmp : files) { - Fileset fs = (Fileset) tmp; - File filesetDir = new File(dir.getAbsolutePath()+File.separator+"Fileset_"+fs.getId().getValue()); - filesetDir.mkdir(); - String repoPath = fs.getTemplatePrefix().getValue(); - for (FilesetEntry fse: fs.copyUsedFiles()) { - OriginalFile of = fse.getOriginalFile(); - String ofDir = of.getPath().getValue().replace(repoPath, ""); - File outDir = new File(filesetDir.getAbsolutePath()+File.separator+ofDir); - outDir.mkdirs(); - File saved = saveOriginalFile(ctx, of, outDir); - if (saved != null) - downloaded.add(saved); - else - notDownloaded.add(of.getName().getValue()); - } - } - } - else { //Prior to FS - for (Object tmp : files) { - OriginalFile of = (OriginalFile) tmp; - File outDir = new File(dir.getAbsolutePath()); - File saved = saveOriginalFile(ctx, of, outDir); - if (saved != null) - downloaded.add(saved); - else - notDownloaded.add(of.getName().getValue()); - } + fc = gw.getFacility(TransferFacility.class); + } catch (ExecutionException e) { + throw new DSOutOfServiceException(e.getMessage()); } - - return result; + return fc.downloadImage(ctx, dir.getAbsolutePath(), image.getId()); } - /** - * Save an OriginalFile of into directory dir - * @param ctx The SecurityContext - * @param of The OriginalFile - * @param dir The output directory - * @return The File if the operation was successfull, null if it wasn't. - */ - private File saveOriginalFile(SecurityContext ctx, OriginalFile of, File dir) { - File out = new File(dir, of.getName().getValue()); - if (out.exists()) { - log(out.getAbsolutePath()+" already exists."); - return null; - } - - try { - RawFileStorePrx store = gw.getRawFileService(ctx); - store.setFileId(of.getId().getValue()); - - long size = of.getSize().getValue(); - long offset = 0; - try (FileOutputStream stream = new FileOutputStream(out)) - { - for (offset = 0; (offset+INC) < size;) { - stream.write(store.read(offset, INC)); - offset += INC; - } - stream.write(store.read(offset, (int) (size-offset))); - } - } catch (Exception e) { - handleConnectionException(e); - return null; - } - return out; - } - - /** - * Checks if the given path already exists and if so, generates a new path - * name path(N), where N is a consecutive number - * - * @param path - * The path name to check - * @param isFile - * Pass true if the path name represents a file - * @return A unique path name based on the given path or the path itself if - * it doesn't exist yet - */ - private String generateUniquePathname(String path, boolean isFile) { - File tmp = new File(path); - if (tmp.exists()) { - String fileExt = null; - if (isFile && path.matches(".+\\..+")) { - fileExt = path.substring(path.lastIndexOf('.'), path.length()); - path = path.substring(0, path.lastIndexOf('.')); - } - if (path.matches(".+\\(\\d+\\)")) { - int n = Integer.parseInt(path.substring( - path.lastIndexOf('(') + 1, path.lastIndexOf(')'))); - n++; - path = path.substring(0, path.lastIndexOf('(')) + "(" + n + ")"; - } else { - path += "(1)"; - } - if (fileExt != null) - path += fileExt; - return generateUniquePathname(path, isFile); - } - return path; - } - /** * Downloads a file previously uploaded to the server. * diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataService.java b/src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataService.java index acb8d1045..2f3a794fb 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataService.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataService.java @@ -25,7 +25,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.concurrent.ExecutionException; import omero.api.StatefulServiceInterfacePrx; @@ -33,7 +32,6 @@ import omero.gateway.model.FolderData; import org.openmicroscopy.shoola.env.data.model.DeletableObject; -import omero.gateway.Gateway; import omero.gateway.SecurityContext; import omero.gateway.exception.DSAccessException; import omero.gateway.exception.DSOutOfServiceException; @@ -282,20 +280,18 @@ public void cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut) throws DSOutOfServiceException, DSAccessException; /** - * Retrieves and saves locally the archived files. - * - * @param ctx The security context. - * @param location The location where to save the files. - * @param imageID The ID of the image. - * @param keepOriginalPath Pass true to preserve the original - * path structure - * @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 Map getArchivedImage(SecurityContext ctx, - File location, long imageID, boolean keepOriginalPath) + * Retrieves and saves locally the archived files. + * + * @param ctx The security context. + * @param location The location where to save the files. + * @param imageID The ID 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. + */ + public List getArchivedImage(SecurityContext ctx, + File location, long imageID) throws DSOutOfServiceException, DSAccessException; /** diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataServiceImpl.java b/src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataServiceImpl.java index 58b6c3e93..c2d92ff3d 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataServiceImpl.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataServiceImpl.java @@ -31,11 +31,9 @@ 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; @@ -72,9 +70,6 @@ import omero.gateway.util.PojoMapper; -import org.openmicroscopy.shoola.env.data.util.SearchDataContext; - -import omero.gateway.Gateway; import omero.gateway.SecurityContext; import omero.gateway.exception.DSAccessException; import omero.gateway.exception.DSOutOfServiceException; @@ -495,14 +490,14 @@ public void cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut) /** * Implemented as specified by {@link OmeroDataService}. */ - public Map getArchivedImage(SecurityContext ctx, - File file, long imageID, boolean keepOriginalPath) + public List getArchivedImage(SecurityContext ctx, + File file, long imageID) throws DSOutOfServiceException, DSAccessException { context.getLogger().debug(this, file.getAbsolutePath()); //Check the image is archived. ImageData image = gateway.getImage(ctx, imageID, null); - return gateway.getArchivedFiles(ctx, file, image, keepOriginalPath); + return gateway.getArchivedFiles(ctx, file, image); } /** diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/model/DownloadArchivedActivityParam.java b/src/main/java/org/openmicroscopy/shoola/env/data/model/DownloadArchivedActivityParam.java index c66c30f98..a1f77b958 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/model/DownloadArchivedActivityParam.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/model/DownloadArchivedActivityParam.java @@ -54,9 +54,6 @@ public class DownloadArchivedActivityParam /** Flag for zipping the downloaded images */ private boolean zip = false; - /** Flag for preserving the original folder structure */ - private boolean keepOriginalPaths = true; - /** * Creates a new instance. * @@ -130,24 +127,4 @@ public void setZip(boolean zip) { this.zip = zip; } - /** - * Returns if the original folder structure should be preserved - * - * @return See above - */ - public boolean isKeepOriginalPaths() { - return keepOriginalPaths; - } - - /** - * Sets the keepOriginalPaths flag - * - * @param keepOriginalPaths - * Pass true to preserve the original folder - * structure - */ - public void setKeepOriginalPaths(boolean keepOriginalPaths) { - this.keepOriginalPaths = keepOriginalPaths; - } - } diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerView.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerView.java index 500f68801..8807653ea 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerView.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerView.java @@ -302,12 +302,11 @@ public CallHandle loadOriginalFiles(SecurityContext ctx, * @param override Flag indicating to override the existing file if it * exists, false otherwise. * @param zip Pass true to create a zip file - * @param keepOriginalPaths Pass true to preserve the original folder structure * @param observer Call-back handler. * @return A handle that can be used to cancel the call. */ public CallHandle loadArchivedImage(SecurityContext ctx, List objects, - File location, boolean override, boolean zip, boolean keepOriginalPaths, + File location, boolean override, boolean zip, AgentEventListener observer); /** diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerViewImpl.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerViewImpl.java index 570ff1764..b4ca4d576 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerViewImpl.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerViewImpl.java @@ -251,10 +251,10 @@ public CallHandle loadOriginalFiles(SecurityContext ctx, */ public CallHandle loadArchivedImage(SecurityContext ctx, List objects, File location, - boolean override, boolean zip, boolean keepOriginalPaths, + boolean override, boolean zip, AgentEventListener observer) { BatchCallTree cmd = new ArchivedImageLoader(ctx, objects, location, - override, zip, keepOriginalPaths); + override, zip); return cmd.exec(observer); } diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java index 942afe634..7debb655d 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java @@ -72,9 +72,6 @@ public class ArchivedImageLoader /** Flag for zipping the downloaded images */ private boolean zip = true; - /** Flag for preserving the original folder structure */ - private boolean keepOriginalPaths = false; - /** * Copies the specified file to the folder. * @@ -122,8 +119,7 @@ private File copyFile(File f, File folder) * Creates a {@link BatchCall} to load the image. * * @param ctx The security context. - * @param objects The objects to download the original image files for. - * @param name The name of the image. + * @param objects The objects to download the original image files for.. * @param folder The path to the folder where to save the image. * @return The {@link BatchCall}. */ @@ -170,9 +166,9 @@ public void doCall() throws Exception List files = new ArrayList(); for (Long imageID : imageIDs) { - Map r = os.getArchivedImage(ctx, - tmpFolder, imageID, keepOriginalPaths); - files.addAll((List) r.get(Boolean.TRUE)); + List r = os.getArchivedImage(ctx, + tmpFolder, imageID); + files.addAll(r); } result = new HashMap>(); @@ -250,16 +246,14 @@ public ArchivedImageLoader(SecurityContext ctx, List objects, * @param override Flag indicating to override the existing file if it * exists, false otherwise. * @param zip Pass true to create a zip file - * @param keepOriginalPaths Pass true to preserve the original folder structure */ public ArchivedImageLoader(SecurityContext ctx, List objects, - File folderPath, boolean override, boolean zip, boolean keepOriginalPaths) + File folderPath, boolean override, boolean zip) { if (CollectionUtils.isEmpty(objects)) throw new IllegalArgumentException("No objects provided."); this.override = override; this.zip = zip; - this.keepOriginalPaths = keepOriginalPaths; loadCall = makeBatchCall(ctx, objects, folderPath); } } diff --git a/src/main/java/org/openmicroscopy/shoola/env/ui/ArchivedLoader.java b/src/main/java/org/openmicroscopy/shoola/env/ui/ArchivedLoader.java index 0456e084d..49f3c3803 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/ui/ArchivedLoader.java +++ b/src/main/java/org/openmicroscopy/shoola/env/ui/ArchivedLoader.java @@ -66,9 +66,6 @@ public class ArchivedLoader /** Flag for zipping the downloaded images */ private boolean zip = false; - /** Flag for preserving the original folder structure */ - private boolean keepOriginalPaths = true; - /** * Notifies that an error occurred. * @see UserNotifierLoader#onException(String, Throwable) @@ -91,12 +88,11 @@ protected void onException(String message, Throwable ex) * @param override Flag indicating to override the existing file if it * exists, false otherwise. * @param zip Pass true to create a zip file - * @param keepOriginalPaths Pass true to preserve the original folder structure * @param activity The activity associated to this loader. */ public ArchivedLoader(UserNotifier viewer, Registry registry, SecurityContext ctx, List objects, File file, - boolean override, boolean zip, boolean keepOriginalPaths, ActivityComponent activity) + boolean override, boolean zip, ActivityComponent activity) { super(viewer, registry, ctx, activity); if (objects == null) @@ -105,7 +101,6 @@ public ArchivedLoader(UserNotifier viewer, Registry registry, this.file = file; this.override = override; this.zip = zip; - this.keepOriginalPaths = keepOriginalPaths; } /** @@ -117,8 +112,7 @@ public void load() { if (CollectionUtils.isEmpty(objects)) return; - handle = mhView.loadArchivedImage(ctx, objects, file, override, zip, - keepOriginalPaths, this); + handle = mhView.loadArchivedImage(ctx, objects, file, override, zip, this); } /** diff --git a/src/main/java/org/openmicroscopy/shoola/env/ui/DownloadArchivedActivity.java b/src/main/java/org/openmicroscopy/shoola/env/ui/DownloadArchivedActivity.java index 0ea62dcc6..a46f820e4 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/ui/DownloadArchivedActivity.java +++ b/src/main/java/org/openmicroscopy/shoola/env/ui/DownloadArchivedActivity.java @@ -105,8 +105,7 @@ protected UserNotifierLoader createLoader() { File f = parameters.getLocation(); loader = new ArchivedLoader(viewer, registry, ctx, - parameters.getImages(), f, parameters.isOverride(), parameters.isZip(), - parameters.isKeepOriginalPaths(), this); + parameters.getImages(), f, parameters.isOverride(), parameters.isZip(), this); return loader; } diff --git a/src/main/java/org/openmicroscopy/shoola/env/ui/OpenObjectLoader.java b/src/main/java/org/openmicroscopy/shoola/env/ui/OpenObjectLoader.java index 205788953..16de43a1b 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/ui/OpenObjectLoader.java +++ b/src/main/java/org/openmicroscopy/shoola/env/ui/OpenObjectLoader.java @@ -125,7 +125,7 @@ public void load() objects.add(image); f = new File(folderPath); handle = mhView.loadArchivedImage(ctx, objects, f, false, false, - false, this); + this); } else { String name = image.getName(); name += image.getName(); diff --git a/src/test/java/org/openmicroscopy/shoola/env/data/NullOmeroPojoService.java b/src/test/java/org/openmicroscopy/shoola/env/data/NullOmeroPojoService.java index 72b4e8b9d..9b1291cbf 100644 --- a/src/test/java/org/openmicroscopy/shoola/env/data/NullOmeroPojoService.java +++ b/src/test/java/org/openmicroscopy/shoola/env/data/NullOmeroPojoService.java @@ -189,10 +189,10 @@ public Collection findContainerPaths(SecurityContext ctx, Class type, /** * No-op implementation - * @see OmeroDataService#getArchivedFiles(String, long) + * @see OmeroDataService#getArchivedImage(SecurityContext, File, long) */ - public Map getArchivedImage(SecurityContext ctx, File location, - long pixelsID, boolean keepOriginalPath) + public List getArchivedImage(SecurityContext ctx, File location, + long pixelsID) throws DSOutOfServiceException, DSAccessException { return null;