use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class SFTPMap method send.
private void send() throws UserException {
// String SFTPWORKINGDIR = "file/to/transfer";
Session session = null;
Channel channel = null;
ChannelSftp channelSftp = null;
logger.debug("preparing the host information for sftp.");
InputStream data = null;
try {
JSch jsch = new JSch();
session = jsch.getSession(this.username, this.server, this.remotePort);
if (this.password != null) {
session.setPassword(this.password);
}
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
logger.debug("Host connected.");
channel = session.openChannel("sftp");
channel.connect();
logger.debug("sftp channel opened and connected.");
channelSftp = (ChannelSftp) channel;
if (this.path != null) {
channelSftp.cd(this.path);
}
File f = new File(this.filename);
data = content.getDataAsStream();
channelSftp.put(data, f.getName());
logger.info("File transfered successfully to host.");
} catch (Exception ex) {
ex.printStackTrace();
throw new UserException("SFTP problem", ex);
} finally {
if (data != null) {
try {
data.close();
} catch (IOException e) {
}
}
if (channelSftp != null) {
channelSftp.exit();
}
logger.info("sftp Channel exited.");
if (channel != null) {
channel.disconnect();
}
logger.info("Channel disconnected.");
if (session != null) {
session.disconnect();
}
logger.info("Host Session disconnected.");
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class TslPreCompiler method getAllDependencies.
public void getAllDependencies(File script, String scriptFolder, List<Dependency> deps, String scriptTenant) throws XPathExpressionException, UserException {
Document tslDoc = null;
InputStream is = null;
try {
if (script.getAbsolutePath().endsWith(".ns")) {
// Check for NS3 type script
NS3ToNSXML ns3toxml = new NS3ToNSXML();
ns3toxml.initialize();
String content = ns3toxml.read(script.getAbsolutePath());
InputStream metais = ns3toxml.parseNavascript(content);
MapMetaData mmd = MapMetaData.getInstance();
String intermed = mmd.parse(script.getAbsolutePath(), metais);
metais.close();
is = new ByteArrayInputStream(intermed.getBytes());
} else if (MapMetaData.isMetaScript(script.getAbsolutePath())) {
// Check for navascript type script
MapMetaData mmd = MapMetaData.getInstance();
InputStream metais = inputStreamReader.getResource(script.getAbsolutePath());
String intermed = mmd.parse(script.getAbsolutePath(), metais);
metais.close();
is = new ByteArrayInputStream(intermed.getBytes());
} else {
// Normal tsl type script
is = inputStreamReader.getResource(script.getAbsolutePath());
}
tslDoc = XMLDocumentUtils.createDocument(is, false);
} catch (Exception e) {
throw new UserException(-1, "Exception on pre-compiling script: " + script, e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
logger.error("Error: ", e);
}
}
}
getAllDependencies(script.getAbsolutePath(), scriptTenant, scriptFolder, deps, tslDoc);
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class TslPreCompiler method findIncludeDependencies.
private void findIncludeDependencies(String fullScriptPath, String scriptTenant, String scriptFolder, List<Dependency> deps, Document tslDoc) throws UserException {
NodeList includes = tslDoc.getElementsByTagName("include");
for (int i = 0; i < includes.getLength(); i++) {
Element n = (Element) includes.item(i);
String includedScript = n.getAttribute("script");
if (includedScript == null || includedScript.equals("")) {
throw new UserException(-1, "No script name found in include tag (missing or empty script attribute): " + n);
}
if (scriptTenant != null) {
// trying tenant-specific variant first
String includeScriptFile = fetchScriptFileName(scriptFolder + File.separator + includedScript + "_" + scriptTenant);
// Check if exists
if (includeScriptFile != null) {
deps.add(new Dependency(fullScriptPath, includeScriptFile, Dependency.INCLUDE_DEPENDENCY, getLineNr(n)));
// Thus continue with next include
continue;
}
}
String includeScriptFile = fetchScriptFileName(scriptFolder + File.separator + includedScript);
// Check if exists
boolean isBroken = false;
if (includeScriptFile == null) {
isBroken = true;
includeScriptFile = scriptFolder + File.separator + includedScript + ".broken";
}
if (includeScriptFile.equals(fullScriptPath)) {
throw new UserException(-1, "Cannot include myself!");
}
deps.add(new Dependency(fullScriptPath, includeScriptFile, Dependency.INCLUDE_DEPENDENCY, getLineNr(n), isBroken));
// Going to check for tenant-specific include-variants
if (scriptTenant == null) {
File scriptFolderFile = new File(includeScriptFile).getParentFile();
if (scriptFolderFile.exists() && scriptFolderFile.isDirectory()) {
AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(includedScript) + "_*.xml");
Collection<File> files = FileUtils.listFiles(scriptFolderFile, fileFilter, null);
for (File f : files) {
deps.add(new Dependency(fullScriptPath, f.getAbsolutePath(), Dependency.INCLUDE_DEPENDENCY, getLineNr(n)));
}
// NS3
AbstractFileFilter fileFilterNS3 = new WildcardFileFilter(FilenameUtils.getName(includedScript) + "_*.xml");
Collection<File> filesNS3 = FileUtils.listFiles(scriptFolderFile, fileFilterNS3, null);
for (File f : filesNS3) {
deps.add(new Dependency(fullScriptPath, f.getAbsolutePath(), Dependency.INCLUDE_DEPENDENCY, getLineNr(n)));
}
}
}
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class JDBCMap method setQuery.
/*
* (non-Javadoc)
*
* @see com.dexels.navajo.adapter.JDBCMappable#setQuery(java.lang.String)
*/
@Override
public void setQuery(final String newQuery) throws UserException {
if (newQuery.indexOf(';') != -1) {
throw new UserException(-1, "Use of semicolon in query fields is not allowed, maybe you meant to use an update field?");
}
query = newQuery.replace('"', (this.replaceQueryDoubleQuotes) ? '\'' : '\"');
if (debug) {
Access.writeToConsole(myAccess, "SQLMap(): query = " + query + "\n");
}
this.savedQuery = query;
this.resultSet = null;
this.update = null;
parameters = new ArrayList();
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class JDBCMap method getResultSet.
protected ResultSetMap[] getResultSet(boolean updateOnly) throws UserException {
ResultSet rs = null;
try {
if (resultSet == null) {
rs = getDBResultSet(updateOnly);
}
if (debug) {
Access.writeToConsole(myAccess, "SQLMAP, QUERY HAS BEEN EXECUTED, RETRIEVING RESULTSET\n");
}
if (rs != null) {
int columns = 0;
ResultSetMetaData meta = null;
try {
meta = rs.getMetaData();
columns = meta.getColumnCount();
} catch (Exception e) {
throw new UserException(-1, "Error retrieving metadata / columncount", e);
}
List<ResultSetMap> dummy = new ArrayList<>();
int index = 1;
rowCount = 0;
try {
while (rs.next()) {
ResultSetMap rm = new ResultSetMap();
for (int i = 1; i < (columns + 1); i++) {
String param = meta.getColumnLabel(i);
int type = meta.getColumnType(i);
Object value = null;
final Object strVal = rs.getObject(i);
if ((strVal != null && !rs.wasNull()) || type == Types.BLOB) {
value = SQLMapHelper.getColumnValue(rs, type, i);
}
rm.addValue(param.toUpperCase(), value);
}
dummy.add(rm);
}
rowCount++;
index++;
} catch (Exception e) {
if (debug) {
Access.writeToConsole(myAccess, "batch mode did not provide a fully baked result set, sorry.\n");
Access.writeToConsole(myAccess, "SQL exception is '" + e.toString() + "'\n");
logger.warn("Some sql problem: ", e);
}
rs.close();
rs = null;
resetAll();
}
if (debug) {
Access.writeToConsole(myAccess, "GOT RESULTSET. Size: " + dummy.size() + " indexcounter says: " + index + "\n");
}
resultSet = dummy.toArray(new ResultSetMap[] {});
rowCount = resultSet.length;
}
} catch (SQLException sqle) {
logger.error("SQL Problem: ");
AuditLog.log("SQLMap", sqle.getMessage(), Level.SEVERE, (myAccess != null ? (myAccess != null ? myAccess.accessID : "unknown access") : "unknown access"));
throw new UserException(-1, sqle.getMessage(), sqle);
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace(Access.getConsoleWriter(myAccess));
}
rs = null;
}
this.resetAll();
}
return resultSet;
}
Aggregations