use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class NavajoMap method prepareOutDoc.
protected Navajo prepareOutDoc() throws UserException {
// If currentOutDoc flag was set, make sure to copy outdoc.
if (this.useCurrentOutDoc || this.useCurrentMessages != null) {
if (this.useCurrentOutDoc) {
if (this.outDoc != null) {
this.outDoc.merge(access.getOutputDoc().copy(), true);
} else {
this.outDoc = access.getOutputDoc().copy();
}
} else {
String[] copy = useCurrentMessages.split(",");
for (String msgName : copy) {
Message msg = null;
if ((msg = access.getOutputDoc().getMessage(msgName)) != null) {
if (this.outDoc.getMessage(msg.getName()) != null) {
this.outDoc.getMessage(msg.getName()).merge(msg, true);
} else {
this.outDoc.addMessage(msg);
}
} else {
throw new UserException(-1, "Could not find message specified in useCurrentMessages: " + msgName);
}
}
}
}
if (this.copyInputMessages != null) {
String[] copy = copyInputMessages.split(",");
for (String msgName : copy) {
Message msg = null;
if ((msg = access.getInDoc().getMessage(msgName)) != null) {
if (this.outDoc.getMessage(msg.getName()) != null) {
this.outDoc.getMessage(msg.getName()).merge(msg, true);
} else {
this.outDoc.addMessage(msg);
}
} else {
throw new UserException(-1, "Could not find message specified in copyInputMessages: " + msgName);
}
}
}
if (this.useCurrentOutDoc) {
// Copy param messages.
if (inMessage.getMessage("__parms__") != null) {
Message params = inMessage.getMessage("__parms__").copy(outDoc);
try {
outDoc.addMessage(params);
} catch (NavajoException e) {
e.printStackTrace(Access.getConsoleWriter(access));
}
}
// Check for deleted messages.
if (!deletedMessages.isEmpty()) {
for (String dMn : deletedMessages) {
Message dM = outDoc.getMessage(dMn);
if (dM != null) {
Navajo rN = dM.getRootDoc();
rN.removeMessage(dMn);
}
}
}
// Check for deleted properties.
if (!deletedProperties.isEmpty()) {
for (String dPn : deletedProperties) {
if (dPn != null) {
Property dP = outDoc.getProperty(dPn);
if (dP != null) {
Message dm = dP.getParentMessage();
dm.removeProperty(dP);
}
}
}
}
}
if (this.sendThrough) {
// Check for request messages with scope "local": remove those.
for (Message m : access.getInDoc().getAllMessages()) {
if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_LOCAL)) {
if (outDoc.getMessage(m.getName()) != null) {
outDoc.removeMessage(m.getName());
}
}
}
}
if (this.useCurrentOutDoc) {
// Check for request messages with scope "local": remove those.
for (Message m : access.getOutputDoc().getAllMessages()) {
if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_LOCAL)) {
if (outDoc.getMessage(m.getName()) != null) {
outDoc.removeMessage(m.getName());
}
}
}
}
if (!this.sendThrough) {
// Check for request messages with scope "global": add those.
for (Message m : access.getInDoc().getAllMessages()) {
if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_GLOBAL)) {
if (outDoc.getMessage(m.getName()) != null) {
// Set preferthis flag to true to make sure that changes
// made in script are preferred over properties/messages
// already in global message.
outDoc.getMessage(m.getName()).merge(m.copy(outDoc), true);
} else {
outDoc.addMessage(m.copy(outDoc));
}
}
}
}
if (!this.useCurrentOutDoc) {
// Check for response messages with scope "local": remove those.
for (Message m : access.getOutputDoc().getAllMessages()) {
if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_GLOBAL)) {
if (outDoc.getMessage(m.getName()) != null) {
// Set preferthis flag to true to make sure that changes
// made in script are preferred over properties/messages
// already in global message.
outDoc.getMessage(m.getName()).merge(m.copy(outDoc), true);
} else {
outDoc.addMessage(m.copy(outDoc));
}
}
if (m.getScope() != null && m.getScope().equals(Message.MSG_SCOPE_LOCAL)) {
if (outDoc.getMessage(m.getName()) != null) {
outDoc.removeMessage(m.getName());
}
}
}
}
// Always copy globals.
if (inMessage.getMessage("__globals__") != null) {
Message globals = inMessage.getMessage("__globals__").copy(outDoc);
try {
outDoc.addMessage(globals);
} catch (NavajoException e) {
e.printStackTrace(Access.getConsoleWriter(access));
}
}
// Always copy aaa message
if (inMessage.getMessage(Message.MSG_AAA_BLOCK) != null) {
Message aaa = inMessage.getMessage(Message.MSG_AAA_BLOCK).copy(outDoc);
if (outDoc.getMessage(Message.MSG_AAA_BLOCK) != null) {
outDoc.getMessage(Message.MSG_AAA_BLOCK).merge(aaa, true);
} else {
try {
outDoc.addMessage(aaa);
} catch (NavajoException e) {
e.printStackTrace(Access.getConsoleWriter(access));
}
}
}
// Always copy token message if the user hasn't specified otherwise
if (inMessage.getMessage(Message.MSG_TOKEN_BLOCK) != null && !this.dropTokenMessage) {
Message token = inMessage.getMessage(Message.MSG_TOKEN_BLOCK).copy(outDoc);
if (outDoc.getMessage(Message.MSG_TOKEN_BLOCK) != null) {
outDoc.getMessage(Message.MSG_TOKEN_BLOCK).merge(token, true);
} else {
try {
outDoc.addMessage(token);
} catch (NavajoException e) {
e.printStackTrace(Access.getConsoleWriter(access));
}
}
}
return outDoc;
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class AdminMap method setDocumentClass.
public void setDocumentClass(String s) throws UserException {
try {
Class.forName(s);
} catch (Exception e) {
throw new UserException(-1, "Could not find document implementation: " + s);
}
System.setProperty("com.dexels.navajo.DocumentImplementation", s);
NavajoFactory.resetImplementation();
NavajoFactory.getInstance().setTempDir(DispatcherFactory.getInstance().getTempDir());
NavajoFactory.getInstance().setExpressionEvaluator(new CachedExpressionEvaluator());
logger.debug("Document class is now: {}", getDocumentClass());
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class NavajoMap method continueAfterRun.
public void continueAfterRun() throws UserException, ConditionErrorException, AuthorizationException {
try {
// Get task if if trigger was specified.
if (trigger != null) {
taskId = inDoc.getHeader().getSchedule();
logger.info("************************************************* TASKID: {}", taskId);
}
// Call sorted.
if (performOrderBy) {
inDoc.performOrdering();
}
Message error = inDoc.getMessage("error");
if (error != null && breakOnException) {
String errMsg = error.getProperty("message").getValue();
String errCode = error.getProperty("code").getValue();
int errorCode = -1;
try {
errorCode = Integer.parseInt(errCode);
} catch (NumberFormatException e) {
e.printStackTrace(Access.getConsoleWriter(access));
}
throw new UserException(errorCode, errMsg);
} else if (error != null) {
logger.debug("EXCEPTIONERROR OCCURED, BUT WAS EXCEPTION HANDLING WAS SET TO FALSE, RETURNING....");
return;
}
boolean authenticationError = false;
Message aaaError = inDoc.getMessage(AuthorizationException.AUTHENTICATION_ERROR_MESSAGE);
if (aaaError == null) {
aaaError = inDoc.getMessage(AuthorizationException.AUTHORIZATION_ERROR_MESSAGE);
} else {
authenticationError = true;
}
if (aaaError != null) {
AuditLog.log("NavajoMap", "THROWING AUTHORIZATIONEXCEPTION IN NAVAJOMAP" + aaaError.getProperty("User").getValue(), Level.WARNING, access.accessID);
throw new AuthorizationException(authenticationError, !authenticationError, aaaError.getProperty("User").getValue(), aaaError.getProperty("Message").getValue());
}
if (breakOnConditionError && inDoc.getMessage("ConditionErrors") != null) {
logger.debug("BREAKONCONDITIONERROR WAS SET TO TRUE, RETURNING CONDITION ERROR");
throw new ConditionErrorException(inDoc);
} else if (inDoc.getMessage("ConditionErrors") != null) {
logger.debug("BREAKONCONDITIONERROR WAS SET TO FALSE, RETURNING....");
return;
}
// Set property directions.
processPropertyDirections(inDoc);
// Suppress properties.
processSuppressedProperties(inDoc);
// Show properties.
processShowProperties(inDoc);
// Reset property directives
this.suppressProperties = null;
this.inputProperties = null;
this.outputProperties = null;
this.showProperties = null;
if (!compare.equals("")) {
Message other = inMessage.getMessage(compare);
Message rec = inDoc.getMessage(compare);
if (other == null || rec == null) {
isEqual = false;
} else {
isEqual = other.isEqual(rec, this.skipProperties);
}
} else {
outDoc = inDoc;
}
} finally {
synchronized (waitForResult) {
waitForResult.notify();
}
if (myResponseListener != null) {
myResponseListener.onNavajoResponse(this);
}
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class NavajoMap method addProperty.
private void addProperty(Property p) throws UserException {
try {
Message msg = MappingUtils.getMessageObject(currentFullName, null, false, outDoc, true, "", -1);
if (msg == null) {
throw new UserException(-1, "Could not create property " + currentFullName + ". Perhaps a missing message name?");
}
msg.addProperty(p);
} catch (Exception e) {
throw new UserException(-1, e.getMessage(), e);
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class CopyMessage method store.
@Override
public void store() throws MappableException, UserException {
Message from = null;
if (copyMessageFrom == null) {
from = (useOutputDoc) ? myAccess.getCompiledScript().getCurrentOutMsg() : myAccess.getCompiledScript().getCurrentInMsg();
} else {
from = (useOutputDoc) ? outputDoc.getMessage(this.copyMessageFrom) : inDoc.getMessage(this.copyMessageFrom);
if (useDefinitionMessage) {
if (!from.isArrayMessage() || from.getDefinitionMessage() == null) {
throw new UserException(-1, "Could not copy definition message: not present.");
}
from = from.getDefinitionMessage();
}
}
if (from == null)
throw new UserException(-1, "Could not find message " + this.copyMessageFrom + " in " + (this.useOutputDoc ? "out" : "in") + "put document");
Message to = null;
if (copyMessageTo != null) {
try {
String type = Message.MSG_TYPE_SIMPLE;
if (!from.getType().equals(Message.MSG_TYPE_DEFINITION)) {
type = from.getType();
}
// if the message does not exist in the indoc and if the type is array_element
if (!outputDoc.getMessages().containsKey(copyMessageTo) && type.equals(Message.MSG_TYPE_ARRAY_ELEMENT)) {
type = Message.MSG_TYPE_SIMPLE;
}
to = MappingUtils.addMessage(outputDoc, myAccess.getCurrentOutMessage(), copyMessageTo, null, 1, type, "")[0];
} catch (Exception e1) {
throw new UserException(-1, e1.getMessage(), e1);
}
} else {
if (myAccess.getCompiledScript().getCurrentOutMsg() == null) {
throw new UserException(-1, "No current message available for copy message.");
}
to = myAccess.getCompiledScript().getCurrentOutMsg();
}
copy(from, to);
}
Aggregations