use of com.dexels.navajo.article.APIException in project navajo by Dexels.
the class ServiceCommand method execute.
@Override
public JsonNode execute(ArticleRuntime runtime, ArticleContext context, Map<String, String> parameters, XMLElement element) throws APIException {
Long startedAt = System.currentTimeMillis();
String name = parameters.get("name");
if (name == null) {
throw new APIException("Command: " + this.getName() + " can't be executed without required parameters: " + name, null, APIErrorCode.InternalError);
}
String refresh = parameters.get("refresh");
if ("false".equals(refresh)) {
Navajo res = runtime.getNavajo(name);
if (res != null) {
runtime.pushNavajo(name, res);
return null;
}
}
String input = parameters.get("input");
Navajo n = null;
if (input != null) {
n = runtime.getNavajo(input);
if (n == null) {
throw new APIException("Command: " + this.getName() + " supplies an 'input' parameter: " + input + ", but that navajo object can not be found" + name, null, APIErrorCode.InternalError);
}
}
if (runtime.getNavajo() != null) {
n = runtime.getNavajo();
} else {
n = NavajoFactory.getInstance().createNavajo();
}
appendTokenAttributes(runtime, n);
final String username = runtime.getUsername();
Header h = NavajoFactory.getInstance().createHeader(n, name, username, "", -1);
if (runtime.getAccess() != null) {
h.setHeaderAttribute("parentaccessid", runtime.getAccess().accessID);
}
n.addHeader(h);
h.setHeaderAttribute("application", "article");
final Navajo result = performCall(runtime, name, n, runtime.getInstance());
statLogger.info("Finished {} ({}) in {}ms", h.getHeaderAttribute("parentaccessid"), name, (System.currentTimeMillis() - startedAt));
runtime.pushNavajo(name, result);
return null;
}
use of com.dexels.navajo.article.APIException in project navajo by Dexels.
the class TestServiceCommand method performCall.
@Override
protected Navajo performCall(ArticleRuntime runtime, String name, Navajo n, String instance) throws APIException {
File tmlFolder = new File("testresources/tml");
File scriptFile = new File(tmlFolder, name + ".xml");
if (scriptFile.exists()) {
FileReader fr = null;
try {
fr = new FileReader(scriptFile);
return NavajoFactory.getInstance().createNavajo(fr);
} catch (FileNotFoundException e) {
throw new APIException("Error reading tml stub at: " + scriptFile.getAbsolutePath(), e, APIErrorCode.ArticleNotFound);
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
logger.error("Error closing file: ", e);
}
}
}
} else {
throw new APIException("Error reading tml stub at: " + scriptFile.getAbsolutePath(), null, APIErrorCode.ArticleNotFound);
}
}
Aggregations