Skip to content

Commit 4990bc1

Browse files
authored
Merge pull request #409 from dominikl/use_gateway_download
Use Gateway method for downloading image
2 parents aad46c8 + 879ffc4 commit 4990bc1

File tree

13 files changed

+41
-241
lines changed

13 files changed

+41
-241
lines changed

src/main/java/org/openmicroscopy/shoola/agents/metadata/editor/EditorModel.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3166,7 +3166,6 @@ else if (!filesetIds.contains(id)) {
31663166
p = new DownloadArchivedActivityParam(new File(path), images, icon);
31673167
p.setOverride(override);
31683168
p.setZip(false);
3169-
p.setKeepOriginalPaths(true);
31703169
un.notifyActivity(ctx, p);
31713170
}
31723171
}

src/main/java/org/openmicroscopy/shoola/agents/treeviewer/view/TreeViewerComponent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3709,7 +3709,6 @@ else if (!filesetIds.contains(id)) {
37093709
folder, archived, icon);
37103710
p.setOverride(override);
37113711
p.setZip(false);
3712-
p.setKeepOriginalPaths(true);
37133712
un.notifyActivity(ctx, p);
37143713
}
37153714
}

src/main/java/org/openmicroscopy/shoola/env/data/OMEROGateway.java

Lines changed: 11 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.concurrent.ExecutionException;
4444

4545
import omero.gateway.facility.RawDataFacility;
46+
import omero.gateway.facility.TransferFacility;
4647
import omero.gateway.model.FolderData;
4748
import omero.gateway.model.PixelsData;
4849
import org.apache.commons.collections4.CollectionUtils;
@@ -172,7 +173,6 @@
172173
import omero.model.ExperimenterGroupI;
173174
import omero.model.FileAnnotation;
174175
import omero.model.Fileset;
175-
import omero.model.FilesetEntry;
176176
import omero.model.GroupExperimenterMap;
177177
import omero.model.IObject;
178178
import omero.model.Image;
@@ -3042,177 +3042,25 @@ Set<GroupData> getAvailableGroups(SecurityContext ctx,
30423042
/**
30433043
* Retrieves the archived files if any for the specified set of pixels.
30443044
*
3045-
* @param ctx The security context.
3046-
* @param file The location where to save the files.
3047-
* @param image The image to retrieve.
3048-
* @param keepOriginalPaths Pass <code>true</code> to preserve the original folder structure
3049-
* @return See above.
3050-
* @throws DSOutOfServiceException If the connection is broken, or not logged in
3051-
* @throws DSAccessException If an error occurred while trying to
3052-
* retrieve data from OMERO service.
3053-
*/
3054-
Map<Boolean, Object> getArchivedFiles(
3055-
SecurityContext ctx, File file, ImageData image, boolean keepOriginalPaths)
3056-
throws DSAccessException, DSOutOfServiceException
3057-
{
3058-
return retrieveArchivedFiles(ctx, file, image);
3059-
}
3060-
3061-
/**
3062-
* Retrieves the archived files if any for the specified set of pixels.
3063-
*
3064-
* @param ctx The security context.
3065-
* @param dir The location where to save the files.
3045+
* @param ctx The security context.
3046+
* @param dir The location where to save the files.
30663047
* @param image The image to retrieve.
30673048
* @return See above.
30683049
* @throws DSAccessException If an error occurred while trying to
3069-
* retrieve data from OMERO service.
3050+
* retrieve data from OMERO service.
30703051
*/
3071-
private Map<Boolean, Object> retrieveArchivedFiles(
3052+
public List<File> getArchivedFiles(
30723053
SecurityContext ctx, File dir, ImageData image)
3073-
throws DSAccessException
3074-
{
3075-
List<?> files = null;
3076-
String query;
3054+
throws DSAccessException, DSOutOfServiceException {
3055+
TransferFacility fc = null;
30773056
try {
3078-
IQueryPrx service = gw.getQueryService(ctx);
3079-
ParametersI param = new ParametersI();
3080-
long id;
3081-
if (image.isFSImage()) {
3082-
id = image.getId();
3083-
List<RType> l = new ArrayList<RType>();
3084-
l.add(omero.rtypes.rlong(id));
3085-
param.add("imageIds", omero.rtypes.rlist(l));
3086-
query = createFileSetQuery();
3087-
} else { //Prior to FS
3088-
if (image.isArchived()) {
3089-
StringBuffer buffer = new StringBuffer();
3090-
id = image.getDefaultPixels().getId();
3091-
buffer.append("select ofile from OriginalFile as ofile ");
3092-
buffer.append("join fetch ofile.hasher ");
3093-
buffer.append("left join ofile.pixelsFileMaps as pfm ");
3094-
buffer.append("left join pfm.child as child ");
3095-
buffer.append("where child.id = :id");
3096-
param.map.put("id", omero.rtypes.rlong(id));
3097-
query = buffer.toString();
3098-
} else return null;
3099-
}
3100-
files = service.findAllByQuery(query, param);
3101-
} catch (Exception e) {
3102-
handleConnectionException(e);
3103-
throw new DSAccessException("Cannot retrieve original file", e);
3104-
}
3105-
3106-
Map<Boolean, Object> result = new HashMap<Boolean, Object>();
3107-
if (CollectionUtils.isEmpty(files)) return result;
3108-
List<File> downloaded = new ArrayList<File>();
3109-
List<String> notDownloaded = new ArrayList<String>();
3110-
result.put(Boolean.valueOf(true), downloaded);
3111-
result.put(Boolean.valueOf(false), notDownloaded);
3112-
3113-
if (image.isFSImage()) {
3114-
for (Object tmp : files) {
3115-
Fileset fs = (Fileset) tmp;
3116-
File filesetDir = new File(dir.getAbsolutePath()+File.separator+"Fileset_"+fs.getId().getValue());
3117-
filesetDir.mkdir();
3118-
String repoPath = fs.getTemplatePrefix().getValue();
3119-
for (FilesetEntry fse: fs.copyUsedFiles()) {
3120-
OriginalFile of = fse.getOriginalFile();
3121-
String ofDir = of.getPath().getValue().replace(repoPath, "");
3122-
File outDir = new File(filesetDir.getAbsolutePath()+File.separator+ofDir);
3123-
outDir.mkdirs();
3124-
File saved = saveOriginalFile(ctx, of, outDir);
3125-
if (saved != null)
3126-
downloaded.add(saved);
3127-
else
3128-
notDownloaded.add(of.getName().getValue());
3129-
}
3130-
}
3131-
}
3132-
else { //Prior to FS
3133-
for (Object tmp : files) {
3134-
OriginalFile of = (OriginalFile) tmp;
3135-
File outDir = new File(dir.getAbsolutePath());
3136-
File saved = saveOriginalFile(ctx, of, outDir);
3137-
if (saved != null)
3138-
downloaded.add(saved);
3139-
else
3140-
notDownloaded.add(of.getName().getValue());
3141-
}
3057+
fc = gw.getFacility(TransferFacility.class);
3058+
} catch (ExecutionException e) {
3059+
throw new DSOutOfServiceException(e.getMessage());
31423060
}
3143-
3144-
return result;
3061+
return fc.downloadImage(ctx, dir.getAbsolutePath(), image.getId());
31453062
}
31463063

3147-
/**
3148-
* Save an OriginalFile of into directory dir
3149-
* @param ctx The SecurityContext
3150-
* @param of The OriginalFile
3151-
* @param dir The output directory
3152-
* @return The File if the operation was successfull, null if it wasn't.
3153-
*/
3154-
private File saveOriginalFile(SecurityContext ctx, OriginalFile of, File dir) {
3155-
File out = new File(dir, of.getName().getValue());
3156-
if (out.exists()) {
3157-
log(out.getAbsolutePath()+" already exists.");
3158-
return null;
3159-
}
3160-
3161-
try {
3162-
RawFileStorePrx store = gw.getRawFileService(ctx);
3163-
store.setFileId(of.getId().getValue());
3164-
3165-
long size = of.getSize().getValue();
3166-
long offset = 0;
3167-
try (FileOutputStream stream = new FileOutputStream(out))
3168-
{
3169-
for (offset = 0; (offset+INC) < size;) {
3170-
stream.write(store.read(offset, INC));
3171-
offset += INC;
3172-
}
3173-
stream.write(store.read(offset, (int) (size-offset)));
3174-
}
3175-
} catch (Exception e) {
3176-
handleConnectionException(e);
3177-
return null;
3178-
}
3179-
return out;
3180-
}
3181-
3182-
/**
3183-
* Checks if the given path already exists and if so, generates a new path
3184-
* name path(N), where N is a consecutive number
3185-
*
3186-
* @param path
3187-
* The path name to check
3188-
* @param isFile
3189-
* Pass <code>true</code> if the path name represents a file
3190-
* @return A unique path name based on the given path or the path itself if
3191-
* it doesn't exist yet
3192-
*/
3193-
private String generateUniquePathname(String path, boolean isFile) {
3194-
File tmp = new File(path);
3195-
if (tmp.exists()) {
3196-
String fileExt = null;
3197-
if (isFile && path.matches(".+\\..+")) {
3198-
fileExt = path.substring(path.lastIndexOf('.'), path.length());
3199-
path = path.substring(0, path.lastIndexOf('.'));
3200-
}
3201-
if (path.matches(".+\\(\\d+\\)")) {
3202-
int n = Integer.parseInt(path.substring(
3203-
path.lastIndexOf('(') + 1, path.lastIndexOf(')')));
3204-
n++;
3205-
path = path.substring(0, path.lastIndexOf('(')) + "(" + n + ")";
3206-
} else {
3207-
path += "(1)";
3208-
}
3209-
if (fileExt != null)
3210-
path += fileExt;
3211-
return generateUniquePathname(path, isFile);
3212-
}
3213-
return path;
3214-
}
3215-
32163064
/**
32173065
* Downloads a file previously uploaded to the server.
32183066
*

src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataService.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
import java.util.Collection;
2626
import java.util.List;
2727
import java.util.Map;
28-
import java.util.Set;
2928
import java.util.concurrent.ExecutionException;
3029

3130
import omero.api.StatefulServiceInterfacePrx;
3231

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

36-
import omero.gateway.Gateway;
3735
import omero.gateway.SecurityContext;
3836
import omero.gateway.exception.DSAccessException;
3937
import omero.gateway.exception.DSOutOfServiceException;
@@ -282,20 +280,18 @@ public void cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut)
282280
throws DSOutOfServiceException, DSAccessException;
283281

284282
/**
285-
* Retrieves and saves locally the archived files.
286-
*
287-
* @param ctx The security context.
288-
* @param location The location where to save the files.
289-
* @param imageID The ID of the image.
290-
* @param keepOriginalPath Pass <code>true</code> to preserve the original
291-
* path structure
292-
* @return See above.
293-
* @throws DSOutOfServiceException If the connection is broken, or not logged in
294-
* @throws DSAccessException If an error occurred while trying to
295-
* retrieve data from OMERO service.
296-
*/
297-
public Map<Boolean, Object> getArchivedImage(SecurityContext ctx,
298-
File location, long imageID, boolean keepOriginalPath)
283+
* Retrieves and saves locally the archived files.
284+
*
285+
* @param ctx The security context.
286+
* @param location The location where to save the files.
287+
* @param imageID The ID of the image.
288+
* @return See above.
289+
* @throws DSOutOfServiceException If the connection is broken, or not logged in
290+
* @throws DSAccessException If an error occurred while trying to
291+
* retrieve data from OMERO service.
292+
*/
293+
public List<File> getArchivedImage(SecurityContext ctx,
294+
File location, long imageID)
299295
throws DSOutOfServiceException, DSAccessException;
300296

301297
/**

src/main/java/org/openmicroscopy/shoola/env/data/OmeroDataServiceImpl.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@
3131
import java.util.Map;
3232
import java.util.Map.Entry;
3333
import java.util.Set;
34-
import java.util.concurrent.ExecutionException;
3534

3635
import omero.cmd.Request;
3736
import omero.cmd.graphs.ChildOption;
38-
import omero.gateway.facility.DataManagerFacility;
3937
import omero.gateway.model.FolderData;
4038
import omero.model.Annotation;
4139
import omero.model.AnnotationAnnotationLink;
@@ -72,9 +70,6 @@
7270

7371
import omero.gateway.util.PojoMapper;
7472

75-
import org.openmicroscopy.shoola.env.data.util.SearchDataContext;
76-
77-
import omero.gateway.Gateway;
7873
import omero.gateway.SecurityContext;
7974
import omero.gateway.exception.DSAccessException;
8075
import omero.gateway.exception.DSOutOfServiceException;
@@ -495,14 +490,14 @@ public void cutAndPaste(SecurityContext ctx, Map toPaste, Map toCut)
495490
/**
496491
* Implemented as specified by {@link OmeroDataService}.
497492
*/
498-
public Map<Boolean, Object> getArchivedImage(SecurityContext ctx,
499-
File file, long imageID, boolean keepOriginalPath)
493+
public List<File> getArchivedImage(SecurityContext ctx,
494+
File file, long imageID)
500495
throws DSOutOfServiceException, DSAccessException
501496
{
502497
context.getLogger().debug(this, file.getAbsolutePath());
503498
//Check the image is archived.
504499
ImageData image = gateway.getImage(ctx, imageID, null);
505-
return gateway.getArchivedFiles(ctx, file, image, keepOriginalPath);
500+
return gateway.getArchivedFiles(ctx, file, image);
506501
}
507502

508503
/**

src/main/java/org/openmicroscopy/shoola/env/data/model/DownloadArchivedActivityParam.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ public class DownloadArchivedActivityParam
5454
/** Flag for zipping the downloaded images */
5555
private boolean zip = false;
5656

57-
/** Flag for preserving the original folder structure */
58-
private boolean keepOriginalPaths = true;
59-
6057
/**
6158
* Creates a new instance.
6259
*
@@ -130,24 +127,4 @@ public void setZip(boolean zip) {
130127
this.zip = zip;
131128
}
132129

133-
/**
134-
* Returns if the original folder structure should be preserved
135-
*
136-
* @return See above
137-
*/
138-
public boolean isKeepOriginalPaths() {
139-
return keepOriginalPaths;
140-
}
141-
142-
/**
143-
* Sets the keepOriginalPaths flag
144-
*
145-
* @param keepOriginalPaths
146-
* Pass <code>true</code> to preserve the original folder
147-
* structure
148-
*/
149-
public void setKeepOriginalPaths(boolean keepOriginalPaths) {
150-
this.keepOriginalPaths = keepOriginalPaths;
151-
}
152-
153130
}

src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,11 @@ public CallHandle loadOriginalFiles(SecurityContext ctx,
302302
* @param override Flag indicating to override the existing file if it
303303
* exists, <code>false</code> otherwise.
304304
* @param zip Pass <code>true</code> to create a zip file
305-
* @param keepOriginalPaths Pass <code>true</code> to preserve the original folder structure
306305
* @param observer Call-back handler.
307306
* @return A handle that can be used to cancel the call.
308307
*/
309308
public CallHandle loadArchivedImage(SecurityContext ctx, List<DataObject> objects,
310-
File location, boolean override, boolean zip, boolean keepOriginalPaths,
309+
File location, boolean override, boolean zip,
311310
AgentEventListener observer);
312311

313312
/**

src/main/java/org/openmicroscopy/shoola/env/data/views/MetadataHandlerViewImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ public CallHandle loadOriginalFiles(SecurityContext ctx,
251251
*/
252252
public CallHandle loadArchivedImage(SecurityContext ctx,
253253
List<DataObject> objects, File location,
254-
boolean override, boolean zip, boolean keepOriginalPaths,
254+
boolean override, boolean zip,
255255
AgentEventListener observer) {
256256
BatchCallTree cmd = new ArchivedImageLoader(ctx, objects, location,
257-
override, zip, keepOriginalPaths);
257+
override, zip);
258258
return cmd.exec(observer);
259259
}
260260

0 commit comments

Comments
 (0)