use of com.dexels.navajo.script.api.MappableException in project navajo by Dexels.
the class PropertyMap method store.
@Override
public void store() throws MappableException, UserException {
try {
Message msg = access.getCurrentOutMessage();
if (msg == null) {
throw new UserException(-1, "PropertyMap adapter can only be called from within a constructed output message");
}
Property prop = null;
prop = msg.getProperty(name);
if (prop != null && !removeExisting) {
throw new UserException(-1, "Cannot add already existing property " + name + " when removeExisting is false.");
}
// this will create if property not found and otherwise update value and other attributes, except for subtype and the options
// Do not have to pass inDoc as we're not creating a param
prop = MappingUtils.setProperty(false, msg, name, currentValue, type, null, direction, description, length == null ? -1 : length, outMessage, null, false);
if (subtype != null) {
prop.setSubType(subtype);
}
// For the selection property, parse the given optionList and the multiple setting
if (Property.SELECTION_PROPERTY.equals(type)) {
if (optionList != null) {
prop.clearSelections();
for (Option o : optionList) {
Selection sel = NavajoFactory.getInstance().createSelection(outMessage, o.getName(), o.getValue(), o.getSelected());
prop.addSelectionWithoutReplace(sel);
}
}
prop.setCardinality(multiple ? "+" : "1");
}
} catch (Exception e) {
throw new UserException(-1, e.getMessage(), e);
}
}
use of com.dexels.navajo.script.api.MappableException in project navajo by Dexels.
the class QueryMap method store.
@Override
public void store() throws MappableException, UserException {
// Construct Navajo message.
try {
Message recordSet = NavajoFactory.getInstance().createMessage(outputDoc, "RecordSet", Message.MSG_TYPE_ARRAY);
try {
outputDoc.addMessage(recordSet);
} catch (NavajoException ex) {
throw new UserException(-1, ex.getMessage(), ex);
}
ResultSetMap[] resultSet = getResultSet();
for (int i = 0; i < resultSet.length; i++) {
Message record = NavajoFactory.getInstance().createMessage(outputDoc, "RecordSet", Message.MSG_TYPE_ARRAY_ELEMENT);
recordSet.addElement(record);
RecordMap[] columns = resultSet[i].getRecords();
for (int j = 0; j < columns.length; j++) {
try {
Object value = columns[j].getRecordValue();
String type = (value != null ? MappingUtils.determineNavajoType(value) : "unknown");
Property prop = NavajoFactory.getInstance().createProperty(outputDoc, columns[j].recordName, type, null, 0, "", Property.DIR_IN);
prop.setAnyValue(value);
record.addProperty(prop);
} catch (Exception ex1) {
throw new UserException(-1, ex1.getMessage(), ex1);
}
}
}
} finally {
super.store();
}
}
use of com.dexels.navajo.script.api.MappableException 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);
}
use of com.dexels.navajo.script.api.MappableException in project navajo by Dexels.
the class AccessMap method store.
@Override
public void store() throws MappableException, UserException {
if (showDetails) {
try {
Message user = getMessage(null, "User");
addProperty(user, "Starttime", getCreated(), Property.DATE_PROPERTY, 10);
addProperty(user, "Totaltime", Integer.valueOf(getTotaltime()), Property.INTEGER_PROPERTY, 10);
addProperty(user, "ClientIP", getIpAddress(), Property.STRING_PROPERTY, 50);
addProperty(user, "ClientHostname", getHost(), Property.STRING_PROPERTY, 50);
addProperty(user, "User", myAccess.rpcUser, Property.STRING_PROPERTY, 50);
addProperty(user, "Webservice", myAccess.rpcName, Property.STRING_PROPERTY, 50);
addProperty(user, "AccessId", myAccess.accessID, Property.STRING_PROPERTY, 50);
addProperty(user, "Stacktrace", myAccess.getCompiledScript().getStackTrace(), Property.MEMO_PROPERTY, 4096);
Message currentMapMessage = getMessage(user, "CurrentMap");
MappableTreeNode currentNode = getCurrentMap();
if (currentNode != null) {
showMapDetails(currentMapMessage, currentNode);
}
Message requestNavajoMessage = getMessage(user, "RequestNavajo");
addProperty(requestNavajoMessage, "Document", getRequestNavajo(), Property.MEMO_PROPERTY, -1);
Message responseNavajoMessage = getMessage(user, "ResponseNavajo");
addProperty(responseNavajoMessage, "Document", getResponseNavajo(), Property.MEMO_PROPERTY, -1);
Message outMessagStack = getMessage(user, "OutMessageStack");
addProperty(outMessagStack, "Stack", getOutMessageStack(), Property.STRING_PROPERTY, -1);
Message mapStack = getMessage(user, "MapObjectStack");
addProperty(mapStack, "Stack", getMapStack(), Property.STRING_PROPERTY, -1);
} catch (Exception ne) {
logger.error("Error: ", ne);
}
}
}
use of com.dexels.navajo.script.api.MappableException in project navajo by Dexels.
the class SQLMap method setReload.
/**
* @param reload
*/
@Deprecated
public void setReload(String datasourceName) throws MappableException, UserException {
if (Version.osgiActive()) {
// this method makes no sense in OSGi
return;
}
// synchronized ( semaphore ) {
if (debug) {
Access.writeToConsole(myAccess, "SQLMAP setReload(" + datasourceName + ") called!\n");
}
try {
synchronized (semaphore) {
if (!initialized || !datasourceName.equals("")) {
if (configFile == null) {
configFile = navajoConfig.readConfig("sqlmap.xml");
// SQLMap!!!
if (fixedBroker == null && datasourceName.equals("")) {
// Only
// re-create
// entire
// HashMap
// at
// initialization!
fixedBroker = new ConnectionBrokerManager();
}
if (datasourceName.equals("")) {
// Get other data sources.
if (configFile != null) {
List<Message> all = configFile.getMessages("/datasources/.*");
for (int i = 0; i < all.size(); i++) {
Message body = all.get(i);
createDataSource(body, navajoConfig);
}
} else {
logger.debug("No config file set. Normal in multitenant.");
}
} else {
createDataSource(configFile.getMessage("/datasources/" + datasourceName), navajoConfig);
}
this.checkDefaultDatasource();
}
initialized = true;
}
}
rowCount = 0;
} catch (NavajoException ne) {
ne.printStackTrace(Access.getConsoleWriter(myAccess));
AuditLog.log("SQLMap", ne.getMessage(), ne, Level.SEVERE, (myAccess != null ? myAccess.accessID : "unknown access"));
throw new MappableException(ne.getMessage(), ne);
} catch (java.io.IOException fnfe) {
fnfe.printStackTrace(Access.getConsoleWriter(myAccess));
AuditLog.log("SQLMap", fnfe.getMessage(), fnfe, Level.SEVERE, (myAccess != null ? myAccess.accessID : "unknown access"));
throw new MappableException("Could not load configuration file for SQLMap object: " + fnfe.getMessage(), fnfe);
} catch (Throwable t) {
t.printStackTrace(Access.getConsoleWriter(myAccess));
AuditLog.log("SQLMap", t.getMessage(), Level.SEVERE, (myAccess != null ? myAccess.accessID : ""));
throw new MappableException(t.getMessage(), t);
}
// }
}
Aggregations