-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/development' into feature/provide-pattern-ma…
…tching # Conflicts: # src/main/java/life/qbic/qpostman/list/ListCommand.java
- Loading branch information
Showing
7 changed files
with
150 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/life/qbic/qpostman/common/DefaultExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package life.qbic.qpostman.common; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
import life.qbic.qpostman.common.options.AuthenticationOptions.NoPasswordException; | ||
import life.qbic.qpostman.common.options.SampleIdentifierOptions.IdentityFileEmptyException; | ||
import life.qbic.qpostman.common.options.SampleIdentifierOptions.IdentityFileNotFoundException; | ||
import life.qbic.qpostman.common.options.SampleIdentifierOptions.IdentityFileNotReadableException; | ||
import life.qbic.qpostman.common.options.SampleIdentifierOptions.SampleInput.ToShortSampleIdsException; | ||
import life.qbic.qpostman.openbis.ConnectionException; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.remoting.RemoteAccessException; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.IExecutionExceptionHandler; | ||
import picocli.CommandLine.ParseResult; | ||
|
||
/** | ||
* The exception handler to use for exceptions within commands. | ||
*/ | ||
public class DefaultExceptionHandler implements IExecutionExceptionHandler { | ||
private static final Logger log = LogManager.getLogger(DefaultExceptionHandler.class); | ||
private static final String LOG_PATH = Optional.ofNullable(System.getProperty("log.path")) | ||
.orElse("logs"); | ||
|
||
private void logError(RuntimeException e) { | ||
if (e instanceof RemoteAccessException remoteAccessException) { | ||
log.error( | ||
"Failed to connect to OpenBis: " + remoteAccessException.getCause().getMessage()); | ||
log.debug(remoteAccessException.getMessage(), remoteAccessException); | ||
} else if (e instanceof AuthenticationException authenticationException) { | ||
log.error( | ||
"Could not authenticate user %s. Please make sure to provide the correct password.".formatted( | ||
authenticationException.username())); | ||
log.debug(authenticationException.getMessage(), authenticationException); | ||
} else if (e instanceof ConnectionException) { | ||
log.error("Could not connect to QBiC's data source. Have you requested access to the " | ||
+ "server? If not please write to [email protected]"); | ||
log.debug(e.getMessage(), e); | ||
} else if (e instanceof NoPasswordException) { | ||
log.error("No password provided. Please provide your password."); | ||
} else if (e instanceof IdentityFileEmptyException identityFileException) { | ||
log.error(identityFileException.getFile().getAbsolutePath() + " does not contain any identifiers."); | ||
} else if (e instanceof IdentityFileNotFoundException identityFileNotFoundException) { | ||
log.error("File not found: " + identityFileNotFoundException.getFile()); | ||
} else if (e instanceof IdentityFileNotReadableException identityFileNotReadableException) { | ||
log.error("Not allowed to read file " + identityFileNotReadableException.getFile()); | ||
} else if (e instanceof ToShortSampleIdsException toShortSampleIdsException) { | ||
log.error( | ||
"Please provide at least 5 letters for your sample identifiers. The following sample identifiers are to short: " | ||
+ toShortSampleIdsException.getIdentifiers()); | ||
} else { | ||
log.error("Something went wrong. For more detailed output see " + Path.of(LOG_PATH, "postman.log").toAbsolutePath()); | ||
log.debug(e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public int handleExecutionException(Exception e, CommandLine commandLine, ParseResult parseResult) | ||
throws Exception { | ||
logError((RuntimeException) e); | ||
commandLine.usage(commandLine. getErr()); | ||
return commandLine.getCommandSpec().exitCodeOnExecutionException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,6 @@ | |
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import life.qbic.qpostman.common.AuthenticationException; | ||
import life.qbic.qpostman.common.FileSizeFormatter; | ||
import life.qbic.qpostman.common.functions.FileFilter; | ||
import life.qbic.qpostman.common.functions.FindSourceSample; | ||
|
@@ -25,19 +23,15 @@ | |
import life.qbic.qpostman.common.structures.DataSetWrapper; | ||
import life.qbic.qpostman.common.structures.FileSize; | ||
import life.qbic.qpostman.download.WriteFileToDisk.DownloadReport; | ||
import life.qbic.qpostman.openbis.ConnectionException; | ||
import life.qbic.qpostman.openbis.OpenBisSessionProvider; | ||
import life.qbic.qpostman.openbis.ServerFactory; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.remoting.RemoteAccessException; | ||
|
||
@Command(name = "download", | ||
description = "Download data from QBiC.") | ||
public class DownloadCommand implements Runnable { | ||
private static final Logger log = LogManager.getLogger(DownloadCommand.class); | ||
private static final String LOG_PATH = Optional.ofNullable(System.getProperty("log.path")) | ||
.orElse("logs"); | ||
@Mixin | ||
AuthenticationOptions authenticationOptions; | ||
@Mixin | ||
|
@@ -51,7 +45,7 @@ public class DownloadCommand implements Runnable { | |
|
||
@Override | ||
public void run() { | ||
try { | ||
|
||
Functions functions = functions(); | ||
|
||
Collection<DataFile> dataSetFiles = functions.searchDataSets() | ||
|
@@ -85,28 +79,6 @@ public void run() { | |
if (!failedDownloads.isEmpty()) { | ||
log.warn("Failed to download %s / %s files.".formatted(failedDownloads.size(), downloadReports.size())); | ||
} | ||
|
||
|
||
} catch (RemoteAccessException remoteAccessException) { | ||
log.error( | ||
"Failed to connect to OpenBis: " + remoteAccessException.getCause().getMessage()); | ||
log.debug(remoteAccessException.getMessage(), remoteAccessException); | ||
System.exit(1); | ||
} catch (AuthenticationException authenticationException) { | ||
log.error( | ||
"Could not authenticate user %s. Please make sure to provide the correct password.".formatted( | ||
authenticationException.username())); | ||
log.debug(authenticationException.getMessage(), authenticationException); | ||
System.exit(1); | ||
} catch (ConnectionException e) { | ||
log.error("Could not connect to QBiC's data source. Have you requested access to the " | ||
+ "server? If not please write to [email protected]"); | ||
log.debug(e.getMessage(), e); | ||
System.exit(1); | ||
} catch (RuntimeException e) { | ||
log.error("Something went wrong. For more detailed output see " + Path.of(LOG_PATH, "postman.log").toAbsolutePath()); | ||
log.debug(e.getMessage(), e); | ||
} | ||
} | ||
|
||
private SearchFiles searchFiles(Collection<DataSetWrapper> it) { | ||
|
Oops, something went wrong.