use of com.ibm.as400.access.IFSFile in project IBMiProgTool by vzupka.
the class Copy_IBMi_IBMi method walkIfsDirectory_CreateNestedIfsDirectories.
/**
* Walk through IFS directory recursively to create shadow directories in IFS
* target directory; Shadow directories are named by last names of the IFS
* directory paths so that only one-level directories are inserted to the IFS
* target directory.
*
* @param sourcePathString
* Source IFS directory path
* @param targetPathString
* Target IFS directory name
* @return
*/
protected String walkIfsDirectory_CreateNestedIfsDirectories(IFSFile sourcePathString, String targetPathString) {
try {
// Get list of objects in the IFS directory that may be directories and
// single files.
// Here we process directories only.
IFSFile[] objectList = sourcePathString.listFiles();
// Process only non-empty directory
if (objectList.length > 0) {
for (IFSFile subDirectory : objectList) {
// Only IFS sub-directories are processed
if (subDirectory.isDirectory()) {
// Newly created IFS directory path is built as
// IFS directory path string from parameter plus
// the last part (leaf) of the subDirectory path
String newTargetPathString = targetPathString + "/" + subDirectory.getName();
// Create the new nested IFS directory if it does not exist
IFSFile newOutputDirFile = new IFSFile(remoteServer, newTargetPathString);
if (!newOutputDirFile.exists()) {
newOutputDirFile.mkdir();
}
row = "Info: IFS directory " + newTargetPathString + " was created.";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
// Recursive call with IFS sub-directory and new IFS path
// (parent of the new IFS directory)
walkIfsDirectory_CreateNestedIfsDirectories(subDirectory, newTargetPathString);
}
}
}
return "";
} catch (Exception exc) {
exc.printStackTrace();
return "ERROR";
}
}
use of com.ibm.as400.access.IFSFile in project IBMiProgTool by vzupka.
the class Copy_IBMi_IBMi method copyToSaveFile.
/**
* @param sourcePathString
* @return
*/
protected String copyToSaveFile(String sourcePathString, String targetPathString) {
// Get object names from IFS path string: qsyslib, library, file, member.
extractNamesFromIfsPath(targetPathString);
try {
// Create target file path
IFSFile sourcePath = new IFSFile(remoteServer, sourcePathString);
// Create target file path
IFSFile targetPath = new IFSFile(remoteServer, targetPathString);
if (targetPathString.endsWith(".LIB")) {
// Add file name to directory path
targetPathString = targetPathString + "/" + sourcePath.getName();
}
// Replace .savf suffix to .FILE for the save file
targetPathString = targetPathString.replace(".savf", ".FILE");
targetPath = new IFSFile(remoteServer, targetPathString);
if (targetPath.exists() && !overwriteAllowed) {
// IFS file exists and overwriting data is NOT allowed
row = "Error: IFS file " + sourcePathString + " cannot be copied to save file " + libraryName + "/" + fileName + "(" + memberName + ") . Overwriting files is not allowed.";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "ERROR";
}
// Copy IFS file to Save file
String command_CPYFRMSTMF = "CPYFRMSTMF FROMSTMF('" + sourcePathString + "') TOMBR('" + targetPathString + "') MBROPT(*REPLACE) CVTDTA(*AUTO) STMFCCSID(*STMF)";
// Enable calling CL commands
CommandCall cmdCall = new CommandCall(remoteServer);
cmdCall.run(command_CPYFRMSTMF);
// 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 IFS file to save file with command CPYFRMSTMF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
} else {
row = "Info: Copy IFS file to save file with command CPYFRMSTMF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
row = "Comp: IFS file " + sourcePathString + " was copied to save file " + targetPathString + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Copy IFS file to save file with command CPYFRMSTMF - " + exc.toString();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
msgText = "";
return msgText;
}
use of com.ibm.as400.access.IFSFile in project IBMiProgTool by vzupka.
the class Copy_IBMi_IBMi method copyFromIfsFile.
/**
* @param sourcePathString
* @param targetPathString
* @return
*/
protected String copyFromIfsFile(String sourcePathString, String targetPathString) {
if (targetPathString.equals(sourcePathString)) {
return "ERROR";
}
// Path to input IFS file
inputDirFile = new IFSFile(remoteServer, sourcePathString);
// Path to output IFS file
outputDirFile = new IFSFile(remoteServer, targetPathString);
try {
// ---------------
if (targetPathString.startsWith("/QSYS.LIB/")) {
extractNamesFromIfsPath(sourcePathString);
if (targetPathString.endsWith(".SAVF")) {
// IFS file to Save File:
// ----------------------
msgText = copyToSaveFile(sourcePathString, targetPathString);
if (msgText.isEmpty()) {
row = "Comp: IFS file " + sourcePathString + " was copied to Save file " + libraryName + "/" + fileName + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "";
} else {
row = "Comp: IFS file " + sourcePathString + " was NOT copied to Save file " + libraryName + "/" + fileName + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "ERROR";
}
} else if (targetPathString.endsWith(".LIB")) {
//
// IFS file to Library
// -------------------
copyToSaveFile(sourcePathString, targetPathString);
} else if (targetPathString.endsWith(".FILE")) {
//
// IFS file to Source file
// -----------------------
msgText = copyToSourceFile(remoteServer, sourcePathString, targetPathString);
if (msgText.isEmpty()) {
row = "Comp: IFS file " + targetPathString + " was copied to Source file " + libraryName + "/" + fileName + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "";
} else {
row = "Comp File: IFS fileSource file " + libraryName + "/" + fileName + " was NOT copied to Source file " + libraryName + "/" + fileName + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "ERROR";
}
} else if (targetPathString.endsWith(".MBR")) {
//
// IFS file to Member
// ------------------
msgText = copyToSourceMember(sourcePathString, targetPathString);
if (msgText.isEmpty()) {
row = "Comp: Source member " + libraryName + "/" + fileName + "(" + memberName + ") was copied to IFS file " + targetPathString + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "";
} else {
row = "Comp Source member " + libraryName + "/" + fileName + "(" + memberName + ") was NOT copied to IFS file " + targetPathString + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "ERROR";
}
}
return msgText;
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Copying from IFS file " + targetPathString + " - " + exc.toString();
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "ERROR";
}
return "";
}
use of com.ibm.as400.access.IFSFile in project IBMiProgTool by vzupka.
the class Copy_IBMi_IBMi method copyIfsFilesToIfsDirectories.
/**
* Copying IFS files to IFS directories created before (see
* walkIfsDirectory_CreateNestedIfsDirectories method).
*
* @param ifsPath
* IFS directory path
* @param targetPathString
* Target IFS directory name
* @param ifsPathStringPrefix
* @return
*/
protected String copyIfsFilesToIfsDirectories(IFSFile ifsPath, String targetPathString, String ifsPathStringPrefix) {
String msgTextDir;
boolean atLeastOneErrorInFiles = false;
try {
IFSFile[] objectList = ifsPath.listFiles();
if (objectList.length != 0) {
for (IFSFile inputDirFile : objectList) {
String newDirPathString = targetPathString + "/" + inputDirFile.getName();
// IFS directory
if (inputDirFile.isDirectory()) {
// Recursive call with different parameter values
copyIfsFilesToIfsDirectories(inputDirFile, newDirPathString, ifsPathStringPrefix);
} else //
// Simple IFS file
{
if (inputDirFile.isFile()) {
ifsPathStringPrefix = inputDirFile.toString().substring(0, inputDirFile.toString().lastIndexOf("/"));
// Append
String newFilePathString = targetPathString + inputDirFile.toString().substring(ifsPathStringPrefix.length());
// Copy the IFS file to IFS directory created before
msgTextDir = copyToIfsFile(inputDirFile.toString(), newFilePathString, fromWalk);
if (!msgTextDir.isEmpty()) {
atLeastOneErrorInFiles = true;
}
if (atLeastOneErrorInFiles) {
row = "Comp: IFS file " + inputDirFile.toString() + " was copied to IFS directory " + newFilePathString + ".";
} else {
row = "Error: IFS file " + inputDirFile.toString() + " was NOT copied to IFS directory " + newFilePathString + ".";
}
}
}
}
msgText = atLeastOneErrorInFiles ? "ERROR" : "";
}
} catch (Exception exc) {
exc.printStackTrace();
}
return msgText;
}
use of com.ibm.as400.access.IFSFile in project IBMiProgTool by vzupka.
the class Copy_IBMi_IBMi method copyToSourceMember.
/**
* @param sourcePathString
* @param targetPathString
* @return
*/
protected String copyToSourceMember(String sourcePathString, String targetPathString) {
// Get object names from IFS path string: qsyslib, library, file, member.
extractNamesFromIfsPath(targetPathString);
try {
// Create source file path
IFSFile sourcePath = new IFSFile(remoteServer, sourcePathString);
// Create target file path
IFSFile targetPath = new IFSFile(remoteServer, targetPathString);
// Check if member name is correct
try {
targetPath.exists();
} catch (Exception exc) {
row = "Error: IFS file " + sourcePathString + " cannot be copied to source member " + libraryName + "/" + fileName + "(" + memberName + ") . Member name is invalid.";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "ERROR";
}
// Check if overwriting data is allowed
if (targetPath.exists() && !overwriteAllowed) {
// IFS file exists and overwriting data is NOT allowed
row = "Error: IFS file " + sourcePathString + " cannot be copied to source member " + libraryName + "/" + fileName + "(" + memberName + ") . Overwriting files is not allowed.";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
return "ERROR";
}
// Copy IFS file to Member
String command_CPYFRMSTMF = "CPYFRMSTMF FROMSTMF('" + sourcePathString + "') TOMBR('" + targetPathString + "') MBROPT(*REPLACE) CVTDTA(*AUTO) STMFCCSID(*STMF) DBFCCSID(*FILE)";
// Enable calling CL commands
CommandCall cmdCall = new CommandCall(remoteServer);
cmdCall.run(command_CPYFRMSTMF);
int sourceCcsid = sourcePath.getCCSID();
sourceCcsidStr = String.valueOf(sourceCcsid);
int targetCcsid = targetPath.getCCSID();
targetCcsidStr = String.valueOf(targetCcsid);
// 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 IFS file " + sourcePathString + " to source member " + targetPathString + " using command CPYFRMSTMF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
} else {
row = "Info: Copy IFS file " + sourcePathString + " to source member " + targetPathString + " using command CPYFRMSTMF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
// Get source type from application paameters
String sourceType = (String) properties.get("SOURCE_TYPE");
// parameter
if (sourceType.equals("*DEFAULT")) {
// Get default source type for standard source physical file name
// (QCLSRC, QRPGLESRC, ...)
sourceType = getDefaultSourceType(fileName);
}
String command_CHGPFM = "CHGPFM FILE(" + libraryName + "/" + fileName + ") MBR(" + memberName + ") SRCTYPE(" + sourceType + ")";
// Perform command CGHPFM to correct source type of the member
cmdCall.run(command_CHGPFM);
// Get messages from the command if any
as400MessageList = cmdCall.getMessageList();
// Send all messages from the command. After ESCAPE message - return.
for (AS400Message as400Message : as400MessageList) {
if (as400Message.getType() == AS400Message.ESCAPE) {
row = "Error: Command CHGPFM - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
} else {
row = "Info: Command CHGPFM - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
row = "Comp: IFS file " + sourcePathString + " was copied to source member " + targetPathString + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Copy IFS file " + sourcePathString + " to source member " + targetPathString + " using command CPYFRMSTMF - " + exc.toString();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
msgText = "";
return msgText;
}
Aggregations