Skip to content

Commit

Permalink
MIR-1235 log all exceptions thrown in wizard commands
Browse files Browse the repository at this point in the history
  • Loading branch information
toKrause authored and kkrebs committed Aug 29, 2023
1 parent bbc44e5 commit 9d73393
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,45 @@ private MIRWizardDownloadDBLib(String name) {

@Override
public void doExecute() {
Element library = getInputXML().getChild("database").getChild("library");
try {

if (library != null && library.getChildren().size() > 0) {
String libDir = MCRConfigurationDir.getConfigurationDirectory().getAbsolutePath() + File.separator + "lib";
Element library = getInputXML().getChild("database").getChild("library");

boolean success = true;
for (Element lib : library.getChildren()) {
String url = lib.getTextTrim();
String fname = FilenameUtils.getName(url);
File file = new File(libDir + File.separator + fname);
try {
if (library != null && library.getChildren().size() > 0) {
String libDir = MCRConfigurationDir.getConfigurationDirectory().getAbsolutePath() + File.separator
+ "lib";

FileUtils.copyURLToFile(new URL(url), file);
MCRConfigurationDirSetup.loadExternalLibs();
boolean success = true;
for (Element lib : library.getChildren()) {
String url = lib.getTextTrim();
String fname = FilenameUtils.getName(url);
File file = new File(libDir + File.separator + fname);
try {

success = true;
} catch (Exception ex) {
LOGGER.error("Exception while downloading or loading database library: " + file.getAbsolutePath(),
ex);
success = false;
}
FileUtils.copyURLToFile(new URL(url), file);
MCRConfigurationDirSetup.loadExternalLibs();

success = true;
} catch (Exception ex) {
LOGGER.error("Exception while downloading or loading database library: "
+ file.getAbsolutePath(), ex);
success = false;
}

if (success) {
this.result.setAttribute("lib", fname);
this.result.setAttribute("url", url);
this.result.setAttribute("to", libDir);
break;
if (success) {
this.result.setAttribute("lib", fname);
this.result.setAttribute("url", url);
this.result.setAttribute("to", libDir);
break;
}
}
}

this.result.setSuccess(success);
this.result.setSuccess(success);
}
} catch (Exception ex) {
LOGGER.error("Exception while downloading DB library.", ex);
this.result.setResult(ex.toString());
this.result.setSuccess(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.mycore.mir.wizard.MIRWizardCommand;

public class MIRWizardGenerateJPAConfig extends MIRWizardCommand {

private static final Logger LOGGER = LogManager.getLogger();

public MIRWizardGenerateJPAConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@
import java.util.Properties;
import java.util.Scanner;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jdom2.Element;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.common.config.MCRConfigurationDir;
import org.mycore.mir.wizard.MIRWizardCommand;

public class MIRWizardGenerateProperties extends MIRWizardCommand {

private static final Logger LOGGER = LogManager.getLogger();

public MIRWizardGenerateProperties() {
this("mycore.properties");
}
Expand Down Expand Up @@ -67,9 +72,9 @@ public void doExecute() {
scanner.close();

this.result.setSuccess(true);
} catch (Exception e) {
this.result.setResult(e.getMessage());

} catch (Exception ex) {
LOGGER.error("Exception while generating properties.", ex);
this.result.setResult(ex.toString());
this.result.setSuccess(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@

public class MIRWizardInitDatabase extends MIRWizardCommand {

private final static String ACTION = "create";

private static final Logger LOGGER = LogManager.getLogger();

private final static String ACTION = "create";

public MIRWizardInitDatabase() {
this("init.database");
}
Expand Down Expand Up @@ -79,8 +79,8 @@ public void doExecute() {
this.result.setResult(res.toString());
} catch (IOException | PersistenceException ex) {
LOGGER.error("Exception while initializing database.", ex);
this.result.setResult(ex.toString());
this.result.setSuccess(false);
this.result.setResult(ex.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.backend.jpa.MCREntityManagerProvider;
import org.mycore.mir.wizard.MIRWizardCommand;
import org.mycore.user2.MCRUserCommands;
Expand All @@ -33,6 +35,8 @@

public class MIRWizardInitSuperuser extends MIRWizardCommand {

private static final Logger LOGGER = LogManager.getLogger();

public MIRWizardInitSuperuser() {
this("init.superuser");
}
Expand Down Expand Up @@ -60,7 +64,9 @@ public void doExecute() {
}

} catch (Exception ex) {
this.result.setResult(ex.getMessage());
LOGGER.error("Exception while initializing superuser.", ex);
this.result.setResult(ex.toString());
this.result.setSuccess(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void doExecute() {
this.result.setResult(result);
this.result.setSuccess(true);
} catch (Exception ex) {
LOGGER.error("Exception while loading classifiactions.", ex);
this.result.setResult(ex.toString());
this.result.setSuccess(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
package org.mycore.mir.wizard.command;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.mir.wizard.MIRWizardCommand;
import org.mycore.solr.commands.MCRSolrCommands;

Expand All @@ -31,9 +33,12 @@
*/
public class MIRWizardSolr extends MIRWizardCommand {

private static String DEFAULT_CORE = "main";
private static final Logger LOGGER = LogManager.getLogger();

private static String DEFAULT_CLASSIFICATION = "classification";

private static final String DEFAULT_CORE = "main";

private static final String DEFAULT_CLASSIFICATION = "classification";

public MIRWizardSolr() {
this("solr");
Expand All @@ -57,7 +62,9 @@ public void doExecute() {

this.result.setSuccess(true);
} catch (final Exception ex) {
this.result.setResult(ex.getMessage());
LOGGER.error("Exception while initializing SOLR.", ex);
this.result.setResult(ex.toString());
this.result.setSuccess(false);
}
}
}

0 comments on commit 9d73393

Please sign in to comment.