Better CLI error handling for unit tests
This commit is contained in:
parent
4f16fea580
commit
31b8a392b7
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -112,7 +112,6 @@ public abstract class BaseApp {
|
||||||
PrintWriter pw = new PrintWriter(System.out);
|
PrintWriter pw = new PrintWriter(System.out);
|
||||||
fmt.printOptions(pw, columns, theCommand.getOptions(), 2, 2);
|
fmt.printOptions(pw, columns, theCommand.getOptions(), 2, 2);
|
||||||
pw.flush();
|
pw.flush();
|
||||||
pw.close();
|
|
||||||
|
|
||||||
// That's it!
|
// That's it!
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
@ -199,7 +198,9 @@ public abstract class BaseApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
System.err.println("Unknown command: " + theArgs[1]);
|
String message = "Unknown command: " + theArgs[1];
|
||||||
|
System.err.println(message);
|
||||||
|
exitDueToProblem(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logCommandUsage(command);
|
logCommandUsage(command);
|
||||||
|
@ -215,9 +216,11 @@ public abstract class BaseApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
System.out.println("Unrecognized command: " + ansi().bold().fg(Ansi.Color.RED) + theArgs[0] + ansi().boldOff().fg(Ansi.Color.WHITE));
|
String message = "Unrecognized command: " + ansi().bold().fg(Ansi.Color.RED) + theArgs[0] + ansi().boldOff().fg(Ansi.Color.WHITE);
|
||||||
|
System.out.println(message);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
logUsage();
|
logUsage();
|
||||||
|
exitDueToProblem(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +253,9 @@ public abstract class BaseApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
loggingConfigOff();
|
if (!"true".equals(System.getProperty("test"))) {
|
||||||
|
loggingConfigOff();
|
||||||
|
}
|
||||||
System.err.println("Invalid command options for command: " + command.getCommandName());
|
System.err.println("Invalid command options for command: " + command.getCommandName());
|
||||||
System.err.println(" " + ansi().fg(Ansi.Color.RED).bold() + e.getMessage());
|
System.err.println(" " + ansi().fg(Ansi.Color.RED).bold() + e.getMessage());
|
||||||
System.err.println("" + ansi().fg(Ansi.Color.WHITE).boldOff());
|
System.err.println("" + ansi().fg(Ansi.Color.WHITE).boldOff());
|
||||||
|
@ -269,6 +274,14 @@ public abstract class BaseApp {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void exitDueToProblem(String theDescription) {
|
||||||
|
if ("true".equals(System.getProperty("test"))) {
|
||||||
|
throw new Error(theDescription);
|
||||||
|
} else {
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void exitDueToException(Throwable e) {
|
private void exitDueToException(Throwable e) {
|
||||||
if ("true".equals(System.getProperty("test"))) {
|
if ("true".equals(System.getProperty("test"))) {
|
||||||
if (e instanceof CommandFailureException) {
|
if (e instanceof CommandFailureException) {
|
||||||
|
@ -323,7 +336,7 @@ public abstract class BaseApp {
|
||||||
private class MyShutdownHook extends Thread {
|
private class MyShutdownHook extends Thread {
|
||||||
private final BaseCommand myFinalCommand;
|
private final BaseCommand myFinalCommand;
|
||||||
|
|
||||||
public MyShutdownHook(BaseCommand theFinalCommand) {
|
MyShutdownHook(BaseCommand theFinalCommand) {
|
||||||
myFinalCommand = theFinalCommand;
|
myFinalCommand = theFinalCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
|
||||||
* #%L
|
* #%L
|
||||||
* HAPI FHIR - Command Line Client - API
|
* HAPI FHIR - Command Line Client - API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2014 - 2018 University Health Network
|
* Copyright (C) 2014 - 2019 University Health Network
|
||||||
* %%
|
* %%
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -80,6 +80,7 @@ import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.thymeleaf.util.ListUtils;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -2060,7 +2061,8 @@ public class SearchBuilder implements ISearchBuilder {
|
||||||
String targetResourceType = defaultString(nextInclude.getParamTargetType(), null);
|
String targetResourceType = defaultString(nextInclude.getParamTargetType(), null);
|
||||||
for (String nextPath : paths) {
|
for (String nextPath : paths) {
|
||||||
String sql;
|
String sql;
|
||||||
boolean haveTargetTypesDefinedByParam = param != null && param.getTargets() != null && param.getTargets().isEmpty() == false;
|
|
||||||
|
boolean haveTargetTypesDefinedByParam = param.getTargets() != null && param.getTargets().isEmpty() == false;
|
||||||
if (targetResourceType != null) {
|
if (targetResourceType != null) {
|
||||||
sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids) AND r.myTargetResourceType = :target_resource_type";
|
sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids) AND r.myTargetResourceType = :target_resource_type";
|
||||||
} else if (haveTargetTypesDefinedByParam) {
|
} else if (haveTargetTypesDefinedByParam) {
|
||||||
|
@ -2068,6 +2070,7 @@ public class SearchBuilder implements ISearchBuilder {
|
||||||
} else {
|
} else {
|
||||||
sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)";
|
sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)";
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedQuery<ResourceLink> q = theEntityManager.createQuery(sql, ResourceLink.class);
|
TypedQuery<ResourceLink> q = theEntityManager.createQuery(sql, ResourceLink.class);
|
||||||
q.setParameter("src_path", nextPath);
|
q.setParameter("src_path", nextPath);
|
||||||
q.setParameter("target_pids", nextRoundMatches);
|
q.setParameter("target_pids", nextRoundMatches);
|
||||||
|
|
Loading…
Reference in New Issue