use of com.ibm.as400.access.AS400 in project nagios-for-i by IBM.
the class QWCRSSTS method init.
private final void init(AS400 system) throws Exception {
AS400Text formatText = null;
AS400Text resetStsStatText = null;
try {
final int ccsid = system.getCcsid();
formatText = new AS400Text(format.length(), ccsid, system);
resetStsStatText = new AS400Text(resetStsStat.length(), ccsid, system);
parameters_[RECEIVER].setOutputDataLength(receiverLength);
parameters_[RECEIVER_LEN].setInputData(BinaryConverter.intToByteArray(receiverLength));
parameters_[FORMAT].setInputData(formatText.toBytes(format));
parameters_[RESET_STS_STAT].setInputData(resetStsStatText.toBytes(resetStsStat));
} catch (PropertyVetoException pve) {
System.err.println("QWCRSSTS.init: Error setting parameters: " + pve.toString());
} finally {
formatText = null;
resetStsStatText = null;
}
}
use of com.ibm.as400.access.AS400 in project camel by apache.
the class MockAS400ConnectionPool method getConnection.
@Override
public AS400 getConnection(String systemName, String userID, String password, Locale locale) throws ConnectionPoolException {
AS400 connection = getConnection(systemName, userID, password);
connection.setLocale(locale);
return connection;
}
use of com.ibm.as400.access.AS400 in project camel by apache.
the class Jt400DataQueueService method start.
@Override
public void start() throws Exception {
if (queue == null) {
AS400 system = endpoint.getSystem();
if (endpoint.isKeyed()) {
queue = new KeyedDataQueue(system, endpoint.getObjectPath());
} else {
queue = new DataQueue(system, endpoint.getObjectPath());
}
}
if (!queue.getSystem().isConnected(AS400.DATAQUEUE)) {
LOG.info("Connecting to {}", endpoint);
queue.getSystem().connectService(AS400.DATAQUEUE);
}
}
use of com.ibm.as400.access.AS400 in project IBMiProgTool by vzupka.
the class Copy_IBMi_IBMi method copyFromSourceFile.
/**
* Copy Source File (all members) to IFS directory.
*
* @param remoteServer
* @param sourcePathString
* @param targetPathString
* @return
*/
protected String copyFromSourceFile(AS400 remoteServer, String sourcePathString, String targetPathString) {
// Extract individual names (library, file, member) from the path of the source physical file
extractNamesFromIfsPath(sourcePathString);
String inLibName = libraryName;
String inFileName = fileName;
// Path to the input source file
String inSourceFilePath = "/QSYS.LIB/" + libraryName + ".LIB/" + fileName + ".FILE";
// Enable calling CL commands
CommandCall cmdCall = new CommandCall(remoteServer);
IFSFile inIfsDirectory = new IFSFile(remoteServer, inSourceFilePath);
IFSFile outIfsDirectory = new IFSFile(remoteServer, targetPathString);
try {
// Check if target is a Source Physical File
if (targetPathString.endsWith(".FILE") && outIfsDirectory.isSourcePhysicalFile()) {
// Target is another source file
// -----------------------------
// Command CPYSRCF will be used.
// Get object names from target path string for command "to"
// parameters
extractNamesFromIfsPath(targetPathString);
// parameter TOFILE
String toFile = libraryName + "/" + fileName;
if (!overwriteAllowed) {
// Member is not overwtitten but printed.
// parameter TOFILE
toFile = "*PRINT";
row = "Info: Existing members of the source file " + libraryName + "/" + fileName + " will not be overwritten but printed. Overwriting files is not allowed.";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
// Build text of the command to copy all members
String command_CPYSRCF = "CPYSRCF FROMFILE(" + inLibName + "/" + inFileName + ") TOFILE(" + toFile + ") FROMMBR(*ALL) TOMBR(*FROMMBR) MBROPT(*REPLACE)";
// Perform the command
cmdCall.run(command_CPYSRCF);
// Get messages from the command if any
AS400Message[] as400MessageList = cmdCall.getMessageList();
// return.
for (AS400Message as400Message : as400MessageList) {
if (as400Message.getType() == AS400Message.ESCAPE) {
row = "Error: Command CPYSRCF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
} else {
row = "Info: Command CPYSRCF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
if (!overwriteAllowed) {
row = "Comp: Members of source file " + inLibName + "/" + inFileName + " of matching names were copied to printer file QSYSPRT.";
} else {
row = "Comp: Source file " + inLibName + "/" + inFileName + " was copied to source file " + libraryName + "/" + fileName + ".";
}
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "";
} else {
// Check if target is a Library or IFS directory
if (targetPathString.startsWith("/QSYS.LIB")) {
// Target is a Library
// -------------------
// Command CPYF will be used.
// Get input Library name from the path string of the input Source Physical File
extractNamesFromIfsPath(inSourceFilePath);
inLibName = libraryName;
inFileName = fileName;
extractNamesFromIfsPath(targetPathString);
String outLibName = libraryName;
String commandText = "CPYF FROMFILE(" + inLibName + "/" + inFileName + ") TOFILE(" + outLibName + "/" + inFileName + ") FROMMBR(*ALL) TOMBR(*FROMMBR) MBROPT(*REPLACE) CRTFILE(*YES) FMTOPT(*MAP)";
// Enable calling CL commands
CommandCall command = new CommandCall(remoteServer);
try {
// Run the command CPYF
command.run(commandText);
// Get messages from the command if any
AS400Message[] as400MessageList = command.getMessageList();
String msgType;
// return.
for (AS400Message as400Message : as400MessageList) {
if (as400Message.getType() == AS400Message.ESCAPE) {
msgType = "Error";
row = msgType + ": message from the CPYF command is " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "";
} else {
msgType = "Info";
row = msgType + ": message from the CPYF command is " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Copying source physical file " + inSourceFilePath + " - " + exc.toString() + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
}
row = "Comp: Source physical file " + inLibName + "/" + inFileName + " was copied to library " + outLibName + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "";
} else {
// Target is an IFS directory
// --------------------------
// If the IFS directory name differs from the Source Physical File name
// ---------------------------------
// Create NEW directory with the Source Physical File name.
String ifsSrcName = inIfsDirectory.getName();
ifsSrcName = ifsSrcName.substring(0, ifsSrcName.indexOf("."));
String outDirEndName = targetPathString.substring(targetPathString.lastIndexOf("/") + 1);
if (!ifsSrcName.equals(outDirEndName)) {
targetPathString = targetPathString + "/" + ifsSrcName;
outIfsDirectory = new IFSFile(remoteServer, targetPathString);
outIfsDirectory.mkdir();
}
// Continue as if IFS directory had the same name
// If the IFS directory has the same name as Source Physical File
// --------------------------------------
// Copy all members from Source file to the IFS directory
boolean atLeastOneErrorInMembers = false;
IFSFile[] ifsFiles = inIfsDirectory.listFiles();
for (IFSFile ifsFile : ifsFiles) {
// Insert new IFS file or rewrite existing IFS file
String msgTextMbr = copyFromSourceMember(remoteServer, ifsFile.toString(), targetPathString + "/" + ifsFile.getName());
// If at least one message is not empty - note error
if (!msgTextMbr.isEmpty()) {
atLeastOneErrorInMembers = true;
}
}
if (!atLeastOneErrorInMembers) {
row = "Comp: Source physical file " + libraryName + "/" + fileName + " was copied to IFS directory " + targetPathString + ".";
mainWindow.msgVector.add(row);
} else {
row = "Error: Source physical file " + libraryName + "/" + fileName + " was NOT completely copied to IFS directory " + targetPathString + ".";
mainWindow.msgVector.add(row);
}
mainWindow.showMessages();
msgText = atLeastOneErrorInMembers ? "ERROR" : "";
return msgText;
}
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Copying from source physical file " + libraryName + "/" + fileName + " - " + exc.toString();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
}
}
use of com.ibm.as400.access.AS400 in project IBMiProgTool by vzupka.
the class Copy_IBMi_IBMi method copyFromSaveFile.
/**
* Copy Save File to IFS file.
*
* @param remoteServer
* @param sourcePathString
* @param targetPathString
* @return
*/
protected String copyFromSaveFile(AS400 remoteServer, String sourcePathString, String targetPathString) {
// Enable calling CL commands
CommandCall cmdCall = new CommandCall(remoteServer);
IFSFile sourcePath = new IFSFile(remoteServer, sourcePathString);
IFSFile targetPath = new IFSFile(remoteServer, targetPathString);
// Extract individual names (library, file, member) from the AS400 IFS path
extractNamesFromIfsPath(sourcePathString);
String inLibName = libraryName;
String inFileName = saveFileName;
// Extract individual names (library, file, member) from the AS400 IFS
// path
extractNamesFromIfsPath(targetPathString);
try {
// ----------
if (targetPathString.startsWith("/QSYS.LIB")) {
// Build command string
String command_CRTDUPOBJ = "CRTDUPOBJ OBJ(" + inFileName + ") FROMLIB(" + inLibName + ") OBJTYPE(*FILE) " + "TOLIB(" + libraryName + ") NEWOBJ(*OBJ) DATA(*YES)";
IFSFile newTargetPath = targetPath;
// For copy to Library, derive new target file path (by appending source file name)
if (targetPathString.endsWith(".LIB")) {
newTargetPath = new IFSFile(remoteServer, targetPathString + "/" + sourcePath.getName());
}
// Check if the file to copy already exists and if can be overwritten.
if (newTargetPath.exists() && !overwriteAllowed) {
row = "Error: Save file " + inLibName + "/" + fileName + " was NOT copied. Overwriting is not allowed.";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
}
// Perform the command. This command does not allow overwriting files with matching name,
// even if allowed by "Overwrite data" parameter.
cmdCall.run(command_CRTDUPOBJ);
// Get messages from the command if any
AS400Message[] as400MessageList = cmdCall.getMessageList();
// Send all messages from the command. After ESCAPE message - return.
for (AS400Message as400Message : as400MessageList) {
if (as400Message.getType() == AS400Message.ESCAPE) {
row = "Error: Copy save file with command CRTDUPOBJ - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
} else {
row = "Info: Copy save file with command CRTDUPOBJ - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
row = "Comp: Save file " + libraryName + "/" + fileName + " was copied to library " + targetPathString + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "";
} else // To IFS directory
// ----------------
{
// Extract individual names (library, file, member) from the AS400 IFS path
extractNamesFromIfsPath(sourcePathString);
String toStmf = targetPathString;
if (targetPath.isDirectory()) {
toStmf = targetPathString + "/" + sourcePath.getName();
}
sourcePathString = sourcePathString.replace(".SAVF", ".FILE");
toStmf = toStmf.replace(".FILE", ".savf");
IFSFile newTargetPath = new IFSFile(remoteServer, toStmf);
// Check if the file to copy already exists and if can be overwritten.
if (newTargetPath.exists() && !overwriteAllowed) {
row = "Error: Save file " + inLibName + "/" + inFileName + " was NOT copied to existing save file " + newTargetPath.getName().replace(".SAVF", ".savf") + ". Overwriting is not allowed.";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
}
// Copy from save file to IFS file
String command_CPYTOSTMF = "CPYTOSTMF FROMMBR('" + sourcePathString + "') " + "TOSTMF('" + toStmf + "') STMFOPT(*REPLACE)";
command_CPYTOSTMF = command_CPYTOSTMF.replace(".SAVF", ".savf");
// Perform the command
cmdCall.run(command_CPYTOSTMF);
// Get messages from the command if any
AS400Message[] as400MessageList = cmdCall.getMessageList();
// return.
for (AS400Message as400Message : as400MessageList) {
if (as400Message.getType() == AS400Message.ESCAPE) {
row = "Error: Copy save file with command CPYTOSTMF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
} else {
row = "Info: Copy save file with command CPYTOSTMF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
row = "Comp: Save file " + libraryName + "/" + fileName + " was copied to IFS directory " + targetPathString + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "";
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Copying save file " + libraryName + "/" + fileName + " - " + exc.toString() + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
}
}
Aggregations