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);
}
}
}
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;
}
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)");
}
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)");
}
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;
}
Aggregations