Search in sources :

Example 96 with UserException

use of com.dexels.navajo.script.api.UserException 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 97 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class CSVMap method getEntries.

public CSVEntryMap[] getEntries() throws UserException {
    BufferedReader buffer = null;
    try {
        Reader f = null;
        if (fileContent != null) {
            f = new InputStreamReader(fileContent.getDataAsStream(), StandardCharsets.UTF_8);
        } else {
            f = new FileReader(fileName);
        }
        buffer = new BufferedReader(f);
        String line = "";
        boolean firstLine = true;
        int importCount = 0;
        List<CSVEntryMap> entryList = new ArrayList<>();
        while ((line = buffer.readLine()) != null) {
            if (maximumImportCount != 0 && (importCount >= maximumImportCount)) {
                break;
            }
            if (isSkipFirstRow() && firstLine) {
            // First line will be skipped. Probably contains headers
            } else {
                if (includeEmpty) {
                    parseLineWithEmpty(line, entryList);
                } else {
                    parseLineDefault(line, entryList);
                }
                importCount++;
            }
            firstLine = false;
        }
        entries = new CSVEntryMap[entryList.size()];
        int i = 0;
        for (CSVEntryMap ce : entryList) {
            entries[i++] = ce;
        }
    } catch (java.io.IOException ioe) {
        throw new UserException(-1, ioe.getMessage());
    } finally {
        if (buffer != null) {
            try {
                buffer.close();
            } catch (IOException e) {
            // Too late to apologize!
            }
        }
    }
    return entries;
}
Also used : InputStreamReader(java.io.InputStreamReader) CSVEntryMap(com.dexels.navajo.adapter.csvmap.CSVEntryMap) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) UserException(com.dexels.navajo.script.api.UserException)

Example 98 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class ResultSetMap method getColumnName.

public final String getColumnName(final Integer index) throws UserException {
    if (index != null) {
        int inx = index.intValue();
        if (inx >= order.size())
            throw new UserException(-1, "Column index out of range: " + inx + " > " + (order.size() + 1));
        String name = (String) order.get(inx);
        return name;
    } else
        throw new UserException(-1, "Null value given in getColumnValue(Integer)");
}
Also used : UserException(com.dexels.navajo.script.api.UserException)

Example 99 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class ResultSetMap method getColumnValue.

public final Object getColumnValue(final Integer index) throws UserException {
    if (index != null) {
        int inx = index.intValue();
        if (inx >= order.size()) {
            throw new UserException(-1, "Column index out of range: " + inx + " > " + (order.size() + 1));
        }
        String name = (String) order.get(inx);
        return values.get(name);
    } else
        throw new UserException(-1, "Null value given in getColumnValue(Integer)");
}
Also used : UserException(com.dexels.navajo.script.api.UserException)

Example 100 with UserException

use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.

the class SQLMapHelper method getColumnValue.

/**
 * Gets the columnvalue from the resultset while checking the correct datatype
 * @param rs
 * @param type
 * @param columnIndex
 * @return Object
 * @throws SQLException
 * @throws UserException
 */
public static Object getColumnValue(ResultSet rs, int type, int columnIndex) throws SQLException, UserException {
    Object value = null;
    ResultSetMetaData meta = rs.getMetaData();
    switch(type) {
        case Types.SQLXML:
        case Types.CLOB:
        case Types.NCLOB:
        case Types.BINARY:
        case Types.BLOB:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            InputStream is = rs.getBinaryStream(columnIndex);
            if (is != null) {
                value = new Binary(is);
            }
            break;
        case Types.INTEGER:
        case Types.BIGINT:
        case Types.SMALLINT:
        case Types.TINYINT:
            int tmpValue = rs.getInt(columnIndex);
            if (rs.wasNull()) {
            } else {
                value = Integer.valueOf(tmpValue);
            }
            break;
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.CHAR:
        case Types.VARCHAR:
            if (rs.getString(columnIndex) != null) {
                value = new String(rs.getString(columnIndex));
            }
            break;
        case Types.NUMERIC:
            int scale = meta.getScale(columnIndex);
            if (scale <= 0) {
                if (// java max int takes 19 digits
                meta.getPrecision(columnIndex) >= 19) {
                    // Note that if we want to support such high precision, also getSimplefiedType (see below) needs to change
                    logger.warn("getColumnValue: Retrieving value with great precision ( " + meta.getPrecision(columnIndex) + " ), possible truncation taking place");
                }
                int tmpValueNumeric = rs.getInt(columnIndex);
                if (!rs.wasNull()) {
                    value = Integer.valueOf(tmpValueNumeric);
                }
            } else {
                double tmpValueDouble = rs.getDouble(columnIndex);
                if (!rs.wasNull()) {
                    value = Double.valueOf(tmpValueDouble);
                }
            }
            break;
        case Types.DECIMAL:
        case Types.FLOAT:
        case Types.DOUBLE:
            double tmpValueDouble = rs.getDouble(columnIndex);
            if (!rs.wasNull()) {
                value = Double.valueOf(tmpValueDouble);
            }
            break;
        case Types.DATE:
            if (rs.getDate(columnIndex) != null) {
                long l = -1;
                try {
                    Date d = rs.getDate(columnIndex);
                    l = d.getTime();
                } catch (Exception e) {
                    Date d = rs.getDate(columnIndex);
                    l = d.getTime();
                }
                value = new java.util.Date(l);
            }
            break;
        case // For Oracle; timestamp with
        -101:
            // clocktime.
            if (rs.getTimestamp(columnIndex) != null) {
                long l = -1;
                try {
                    Timestamp ts = rs.getTimestamp(columnIndex);
                    l = ts.getTime();
                } catch (Exception e) {
                    Date d = rs.getDate(columnIndex);
                    l = d.getTime();
                }
                value = new ClockTime(new java.util.Date(l));
            }
            break;
        case Types.TIMESTAMP:
            if (rs.getTimestamp(columnIndex) != null) {
                long l = -1;
                try {
                    Timestamp ts = rs.getTimestamp(columnIndex);
                    l = ts.getTime();
                } catch (Exception e) {
                    Date d = rs.getDate(columnIndex);
                    l = d.getTime();
                }
                value = new java.util.Date(l);
            }
            break;
        case Types.TIME:
            value = new Time(rs.getTime(columnIndex).getTime());
            break;
        case Types.BOOLEAN:
        case Types.BIT:
            boolean tmpValueBoolean = rs.getBoolean(columnIndex);
            if (!rs.wasNull()) {
                value = Boolean.valueOf(tmpValueBoolean);
            }
            break;
        case Types.ARRAY:
            value = rs.getArray(columnIndex);
            break;
        case Types.REF:
            value = rs.getRef(columnIndex);
            break;
        case Types.ROWID:
            value = rs.getRowId(columnIndex);
            break;
        case Types.NULL:
            break;
        // TODO: No idea what to do with these types
        case Types.DATALINK:
        case Types.DISTINCT:
        case Types.JAVA_OBJECT:
        case Types.OTHER:
        case Types.REAL:
        case Types.STRUCT:
            value = rs.getObject(columnIndex);
            break;
        default:
            // If it concerns an unknown type, then throw exception
            throw new UserException(-1, "Unknown SQL type : " + type);
    }
    return value;
}
Also used : InputStream(java.io.InputStream) Time(java.sql.Time) ClockTime(com.dexels.navajo.document.types.ClockTime) ClockTime(com.dexels.navajo.document.types.ClockTime) Timestamp(java.sql.Timestamp) Date(java.sql.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) UserException(com.dexels.navajo.script.api.UserException) SQLException(java.sql.SQLException) ResultSetMetaData(java.sql.ResultSetMetaData) Binary(com.dexels.navajo.document.types.Binary) UserException(com.dexels.navajo.script.api.UserException)

Aggregations

UserException (com.dexels.navajo.script.api.UserException)113 MappableException (com.dexels.navajo.script.api.MappableException)54 IOException (java.io.IOException)33 NavajoException (com.dexels.navajo.document.NavajoException)25 Message (com.dexels.navajo.document.Message)22 SQLException (java.sql.SQLException)19 SystemException (com.dexels.navajo.script.api.SystemException)18 Binary (com.dexels.navajo.document.types.Binary)14 ConditionErrorException (com.dexels.navajo.server.ConditionErrorException)13 Property (com.dexels.navajo.document.Property)12 ArrayList (java.util.ArrayList)12 Navajo (com.dexels.navajo.document.Navajo)11 AuthorizationException (com.dexels.navajo.script.api.AuthorizationException)11 ResultSet (java.sql.ResultSet)11 MappingException (com.dexels.navajo.script.api.MappingException)10 ResultSetMetaData (java.sql.ResultSetMetaData)9 Element (org.w3c.dom.Element)8 CompilationException (com.dexels.navajo.script.api.CompilationException)7 File (java.io.File)7 NodeList (org.w3c.dom.NodeList)7