Search in sources :

Example 11 with MappableException

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);
    }
}
Also used : Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) UserException(com.dexels.navajo.script.api.UserException) Property(com.dexels.navajo.document.Property) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 12 with MappableException

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();
    }
}
Also used : RecordMap(com.dexels.navajo.adapter.sqlmap.RecordMap) Message(com.dexels.navajo.document.Message) NavajoException(com.dexels.navajo.document.NavajoException) ResultSetMap(com.dexels.navajo.adapter.sqlmap.ResultSetMap) UserException(com.dexels.navajo.script.api.UserException) Property(com.dexels.navajo.document.Property) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) NavajoException(com.dexels.navajo.document.NavajoException)

Example 13 with MappableException

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);
}
Also used : Message(com.dexels.navajo.document.Message) UserException(com.dexels.navajo.script.api.UserException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 14 with MappableException

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);
        }
    }
}
Also used : MappableTreeNode(com.dexels.navajo.script.api.MappableTreeNode) Message(com.dexels.navajo.document.Message) MappingException(com.dexels.navajo.script.api.MappingException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 15 with MappableException

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);
    }
// }
}
Also used : MappableException(com.dexels.navajo.script.api.MappableException) Message(com.dexels.navajo.document.Message) ConnectionBrokerManager(com.dexels.navajo.adapter.sqlmap.ConnectionBrokerManager) NavajoException(com.dexels.navajo.document.NavajoException)

Aggregations

MappableException (com.dexels.navajo.script.api.MappableException)16 UserException (com.dexels.navajo.script.api.UserException)10 Message (com.dexels.navajo.document.Message)8 NavajoException (com.dexels.navajo.document.NavajoException)5 IOException (java.io.IOException)5 Property (com.dexels.navajo.document.Property)4 Navajo (com.dexels.navajo.document.Navajo)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 FileLineMap (com.dexels.navajo.adapter.filemap.FileLineMap)1 AttachmentMapInterface (com.dexels.navajo.adapter.mailmap.AttachmentMapInterface)1 ConnectionBrokerManager (com.dexels.navajo.adapter.sqlmap.ConnectionBrokerManager)1 RecordMap (com.dexels.navajo.adapter.sqlmap.RecordMap)1 ResultSetMap (com.dexels.navajo.adapter.sqlmap.ResultSetMap)1 SQLMapDatasourceMap (com.dexels.navajo.adapter.sqlmap.SQLMapDatasourceMap)1 ClientInterface (com.dexels.navajo.client.ClientInterface)1 Selection (com.dexels.navajo.document.Selection)1 Binary (com.dexels.navajo.document.types.Binary)1 ElasticSearchResult (com.dexels.navajo.elasticsearch.impl.ElasticSearchResult)1