Skip to content

Commit

Permalink
#3627 Unzip subfolders, additional checks, wording in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ymarcon committed May 21, 2021
1 parent 4d874ce commit 94e0fb9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
22 changes: 18 additions & 4 deletions opal-core-ws/src/main/java/org/obiba/opal/web/FilesResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,30 @@ public Response unzipArchive(@PathParam("path") String archivePath, @QueryParam(
FileObject archive = resolveFileInFileSystem(archivePath);
FileObject destination = resolveFileInFileSystem(destinationPath);

if (!destination.exists() || !destination.getType().equals(FileType.FOLDER)) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("cannotCreateFolderUnexpectedError").build();
if (destination.exists() && !destination.getType().equals(FileType.FOLDER)) {
return Response.status(Status.BAD_REQUEST).entity("Destination path is a regular file.").build();
} else if (!destination.exists()) {
destination.createFolder();
if (!destination.exists())
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("cannotCreateFolderUnexpectedError").build();
}

if (archive.exists() && archive.getType().equals(FileType.FILE)) {
File archiveFile = opalRuntime.getFileSystem().getLocalFile(archive);
String archiveBasename = archiveFile.getName().replace(".zip", "");
File destinationFolder = new File(opalRuntime.getFileSystem().getLocalFile(destination), archiveBasename);
int inc = 1;
while (destinationFolder.exists()) {
destinationFolder = new File(destinationFolder.getParentFile(), archiveBasename + "-" + inc);
inc++;
}
if (Strings.isNullOrEmpty(archiveKey)) {
org.obiba.core.util.FileUtil.unzip(opalRuntime.getFileSystem().getLocalFile(archive), opalRuntime.getFileSystem().getLocalFile(destination));
org.obiba.core.util.FileUtil.unzip(archiveFile, destinationFolder);
} else {
org.obiba.core.util.FileUtil.unzip(opalRuntime.getFileSystem().getLocalFile(archive), opalRuntime.getFileSystem().getLocalFile(destination), archiveKey);
org.obiba.core.util.FileUtil.unzip(archiveFile, destinationFolder, archiveKey);
}
} else {
return Response.status(Status.NOT_FOUND).entity("No archive file found.").build();
}

return Response.ok(destinationPath).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
</b:Button>
</b:ButtonGroup>
<b:ButtonGroup>
<b:Button ui:field="unzip">
<ui:msg description="Unzip label">Unzip</ui:msg>
<b:Button icon="ARCHIVE" ui:field="unzip">
<ui:msg description="Extract label">Extract</ui:msg>
</b:Button>
</b:ButtonGroup>
<b:ButtonGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<b:Controls>
<o:OpalSimplePanel ui:field="filePanel"/>
</b:Controls>
<b:HelpBlock>
<ui:msg description="Unzip destination help">The archive will be extracted in the selected folder.</ui:msg>
</b:HelpBlock>
</b:ControlGroup>

<b:ControlGroup ui:field="passwordGroup">
Expand All @@ -24,11 +27,14 @@
<b:PasswordTextBox name="encryptPassword" ui:field="password" visibleLength="16"/>
<b:Button icon="EYE_OPEN" ui:field="viewPasswordButton"></b:Button>
</b:Controls>
<b:HelpBlock>
<ui:msg description="Archive password help">Password to decrypt the archive. Leave empty if not applicable.</ui:msg>
</b:HelpBlock>
</b:ControlGroup>

<b:ModalFooter>
<b:Button ui:field="unzip" type="PRIMARY">
<ui:msg description="Unzip label">Unzip</ui:msg>
<ui:msg description="Unzip label">Extract</ui:msg>
</b:Button>
<b:Button ui:field="cancelButton">
<ui:msg description="Cancel button label">Cancel</ui:msg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,7 @@ public interface Translations extends Constants {
String createFolderModalTitle();

@Description("Unzip Modal title")
@DefaultStringValue("Unzip")
@DefaultStringValue("Extract Archive")
String unzipModalTitle();

@Description("Upload File Modal title")
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<newrelic.version>3.20.0</newrelic.version>
<nimbus-jose-jwt.version>7.9</nimbus-jose-jwt.version>
<oauth-oidc-sdk.version>5.45</oauth-oidc-sdk.version>
<obiba-commons.version>1.15.2</obiba-commons.version>
<obiba-commons.version>1.15.3</obiba-commons.version>
<opal-oda.version>1.2.3</opal-oda.version>
<opencsv.version>2.3</opencsv.version>
<orientdb.version>2.2.37</orientdb.version>
Expand Down

0 comments on commit 94e0fb9

Please sign in to comment.