use of com.ibm.as400.access.AS400Message in project IBMiProgTool by vzupka.
the class Copy_PC_IBMi method copyFromPcDirectory.
/**
* Copying a PC directory to IFS directory or to Library/Source File.
*
* @param sourcePathString
* @param targetPathString
* @param sourcePathStringPrefix
*/
protected void copyFromPcDirectory(String sourcePathString, String targetPathString, String sourcePathStringPrefix) {
// Get object and member names (libraryName, fileName, memberName
extractNamesFromIfsPath(targetPathString);
if (!sourcePathString.contains(pcFileSep + ".")) {
IFSFile targetPath = new IFSFile(remoteServer, targetPathString + "/" + sourcePathString.substring(sourcePathStringPrefix.length()));
// --------------------------------
if (!targetPathString.startsWith("/QSYS.LIB")) {
// Create the first shadow IFS directory
try {
if (!targetPath.exists()) {
// Create new directory in target IFS directory with PC file ending name
targetPath.mkdir();
// Add message text to the message table and show it
row = "Info: Directory " + sourcePathString + " was created in IFS directory " + targetPathString + ".";
mainWindow.msgVector.add(row);
}
} catch (Exception exc) {
exc.printStackTrace();
row = exc.toString();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return;
}
// Create shadow directories in the first shadow IFS directory created above
msgText = walkPcDirectory_CreateNestedIfsDirectories(remoteServer, sourcePathString, targetPath);
// Copy PC files to appropriate IFS shadow directories
msgText = copyPcFilesToIfsDirectories(sourcePathString, targetPath, sourcePathStringPrefix);
// Construct a message in the message table and show it
if (msgText.isEmpty()) {
row = "Comp: PC directory " + sourcePathString + " was copied to IFS directory " + targetPathString + ".";
} else {
row = "Comp: PC directory " + sourcePathString + " was NOT completely copied to IFS directory " + targetPathString + ".";
}
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
// ------------------
if (targetPathString.startsWith("/QSYS.LIB")) {
if (ibmCcsid.equals("*DEFAULT")) {
ibmCcsid = "500";
}
// Create new source physical file in the library and call copyToSourceFile() method
if (targetPathString.endsWith(".LIB")) {
// Extract individual names (libraryName, fileName, memberName) from the AS400 IFS path
extractNamesFromIfsPath(targetPathString);
// Extract a new file name from the last component of the PC path string.
// The file name extracted by the method before was null!
fileName = sourcePathString.substring(sourcePathString.lastIndexOf(pcFileSep) + 1);
// Create new source physical file
String sourceRecordLength = (String) properties.get("SOURCE_RECORD_LENGTH");
// The property contains all digits. It was made certain when the user entered the value.
int sourceRecordLengthInt = Integer.parseInt(sourceRecordLength);
// Source record must contain 12 byte prefix to data line: sequence number (6) and date (6)
sourceRecordLengthInt += 12;
// Build command CRTSRCPF to create a source physical file with certain CCSID in the library
String commandText = "CRTSRCPF FILE(" + libraryName + "/" + fileName + ") " + "RCDLEN(" + sourceRecordLengthInt + ") CCSID(" + ibmCcsid + ")";
// Enable calling CL commands
CommandCall cmdCall = new CommandCall(remoteServer);
try {
// Run the command
cmdCall.run(commandText);
// 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: Create source physical file " + libraryName + "/" + fileName + " using CRTSRCPF command - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return;
} else {
row = "Info: Create source physical file " + libraryName + "/" + fileName + " using CRTSRCPF command - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Copying PC directory " + sourcePathString + " to source physical File " + libraryName + "/" + fileName + " - " + exc.toString();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
// Must return! Could be fatal error (e. g. lock of the source file)!
return;
}
// Copy members to the new source physical file in a library
msgText = copyToSourceFile(sourcePathString, targetPathString + "/" + fileName + ".FILE");
if (msgText.isEmpty()) {
row = "Comp: PC directory " + sourcePathString + " was copied to source physical file " + libraryName + "/" + fileName + ".";
} else {
row = "Comp: PC directory " + sourcePathString + " was NOT completely copied to source physical file " + libraryName + "/" + fileName + ".";
}
mainWindow.msgVector.add(row);
mainWindow.showMessages();
} else // ---------------------------------------------------------
if (targetPathString.endsWith(".FILE")) {
// Copy single PC file to source file to existing member or as a new member
msgText = copyToSourceFile(sourcePathString, targetPathString);
if (msgText.isEmpty()) {
row = "Comp: PC directory " + sourcePathString + " was copied to source physical file " + libraryName + "/" + fileName + ".";
} else {
row = "Comp: PC directory " + sourcePathString + " was NOT completely copied to source physical file " + libraryName + "/" + fileName + ".";
}
mainWindow.msgVector.add(row);
mainWindow.showMessages();
} else // ----------------------------------------
if (targetPathString.endsWith(".MBR")) {
row = "Error: PC directory " + sourcePathString + " cannot be copied to a source physical file member " + libraryName + "/" + fileName + "(" + memberName + ").";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
}
}
use of com.ibm.as400.access.AS400Message in project IBMiProgTool by vzupka.
the class CreateAndDeleteInIBMi method createSourcePhysicalFile.
/**
* Create Source Physical File.
*/
protected void createSourcePhysicalFile() {
// Get library name from the IFS path string
extractNamesFromIfsPath(mainWindow.rightPathString);
// "true" stands for changing result to upper case
String sourceFileName = new GetTextFromDialog("CREATE NEW SOURCE PHYSICAL FILE").getTextFromDialog("Library", "Source physical file name", libraryName, "", true, currentX, currentY);
if (sourceFileName == null) {
return;
}
if (sourceFileName.isEmpty()) {
sourceFileName = "QRPGLESRC";
}
// Get and adjust source record length
sourceRecordLength = (String) properties.get("SOURCE_RECORD_LENGTH");
// The property contains all digits. It was made certain when the user entered the value.
int sourceRecordLengthInt = Integer.parseInt(sourceRecordLength);
// Source record must contain 12 byte prefix to data line: sequence number (6) and date (6)
sourceRecordLengthInt += 12;
// Build command CRTSRCPF to create a source physical file with certain CCSID in the library
String commandText = "CRTSRCPF FILE(" + libraryName + "/" + sourceFileName + ") " + "RCDLEN(" + sourceRecordLengthInt + ") CCSID(" + ibmCcsid + ")";
// Enable calling CL commands
CommandCall command = new CommandCall(remoteServer);
try {
// Run the command
command.run(commandText);
// Get messages from the command if any
AS400Message[] as400MessageList = command.getMessageList();
String msgType;
// Send all messages from the command. After ESCAPE message - return.
for (AS400Message as400Message : as400MessageList) {
if (as400Message.getType() == AS400Message.ESCAPE) {
msgType = "Error";
row = msgType + ": message from the CRTSRCPF command is " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return;
} else {
msgType = "Info";
row = msgType + ": message from the CRTSRCPF command is " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Creating source physical file " + ifsFile.toString() + " - " + exc.toString() + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return;
}
row = "Comp: Source physical file " + sourceFileName + " was created in " + libraryName + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
use of com.ibm.as400.access.AS400Message in project IBMiProgTool by vzupka.
the class CreateAndDeleteInIBMi method deleteLibrary.
/**
* Delete library
*/
protected void deleteLibrary() {
extractNamesFromIfsPath(mainWindow.rightPathString);
// Enable calling CL commands
CommandCall command = new CommandCall(remoteServer);
// Build command DLTLIB to delete the library
String commandText = "DLTLIB LIB(" + libraryName + ")";
try {
// Run the command
command.run(commandText);
// Get messages from the command if any
AS400Message[] as400MessageList = command.getMessageList();
String msgType;
// Send all messages from the command. After ESCAPE message - return.
for (AS400Message as400Message : as400MessageList) {
if (as400Message.getType() == AS400Message.ESCAPE) {
msgType = "Error";
row = msgType + ": message from the DLTLIB command is " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return;
} else {
msgType = "Info";
row = msgType + ": message from the DLTLIB command is " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Deleting library " + libraryName + " - " + exc.toString() + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return;
}
row = "Comp: Library " + libraryName + " was deleted.";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
use of com.ibm.as400.access.AS400Message in project IBMiProgTool by vzupka.
the class CreateAndDeleteInIBMi method clearLibrary.
/**
* Clear library
*/
protected void clearLibrary() {
extractNamesFromIfsPath(mainWindow.rightPathString);
// Enable calling CL commands
CommandCall command = new CommandCall(remoteServer);
// Build command CLRLIB to clear the library
String commandText = "CLRLIB LIB(" + libraryName + ")";
try {
// Run the command
command.run(commandText);
// Get messages from the command if any
AS400Message[] as400MessageList = command.getMessageList();
String msgType;
// Send all messages from the command. After ESCAPE message - return.
for (AS400Message as400Message : as400MessageList) {
if (as400Message.getType() == AS400Message.ESCAPE) {
msgType = "Error";
row = msgType + ": message from the CLRLIB command is " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return;
} else {
msgType = "Info";
row = msgType + ": message from the CLRLIB command is " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Clearing library " + libraryName + " - " + exc.toString() + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return;
}
row = "Comp: Library " + libraryName + " was cleared.";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
use of com.ibm.as400.access.AS400Message in project IBMiProgTool by vzupka.
the class EditFile method rewriteSourceMember.
/**
* Rewrite source member with edited text area using an intermediate temporary IFS file; This method is fast enough.
*
* @return
*/
protected String rewriteSourceMember() {
// Extract individual names (libraryName, fileName, memberName) from the AS400 IFS path
extractNamesFromIfsPath(filePathString);
// Path to the output source member
String outMemberPathString = "/QSYS.LIB/" + libraryName + ".LIB/" + fileName + ".FILE" + "/" + memberName + ".MBR";
// Enable calling CL commands
CommandCall cmdCall = new CommandCall(remoteServer);
IFSFileOutputStream outStream = null;
try {
// ------------------------------------
if (!properties.getProperty("OVERWRITE_FILE").equals("Y")) {
row = "Info: Member " + libraryName + "/" + fileName + "(" + memberName + ") cannot be overwtitten. " + " Overwriting files is not allowed.";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
}
// Overwrite is allowed
// --------------------
// First create an IFS '/home/userName directory if it does not exist
String home_userName = "/home/" + userName;
IFSFile ifsDir = new IFSFile(remoteServer, home_userName);
// Create new directory if it does not exist
ifsDir.mkdir();
// Create hidden temporary file (with leading dot) in the directory
String tmpFileString = home_userName + "/.tmp" + Timestamp.valueOf(LocalDateTime.now()).toString();
IFSFile ifsTmpFile = new IFSFile(remoteServer, tmpFileString);
IFSFile ifsTmpFilePath = new IFSFile(remoteServer, tmpFileString);
ifsTmpFile.createNewFile();
// Force the memeber CCSID to the IFS file as an attribute
ifsTmpFilePath.setCCSID(ibmCcsidInt);
// Copy edited text area to the temporary IFS file
outStream = new IFSFileOutputStream(remoteServer, tmpFileString);
String textAreaString = textArea.getText();
byte[] byteArray;
AS400Text textConverter = new AS400Text(textAreaString.length(), ibmCcsidInt);
byteArray = textConverter.toBytes(textAreaString);
// Write text from the text area to the file
outStream.write(byteArray);
// Close file
outStream.close();
// Copy data from temporary IFS file to the member. If the member does not exist it is created.
String commandCpyFrmStmfString = "CPYFRMSTMF FROMSTMF('" + tmpFileString + "') TOMBR('" + outMemberPathString + "') MBROPT(*REPLACE) CVTDTA(*AUTO)";
// Perform the command
cmdCall.run(commandCpyFrmStmfString);
// Get messages from the command if any
AS400Message[] as400MessageList = cmdCall.getMessageList();
// return.
for (AS400Message as400Message : as400MessageList) {
if (as400Message.getType() == AS400Message.ESCAPE) {
row = "Error: Copy IFS file " + tmpFileString + " to source member " + tmpFileString + " using command CPYFRMSTMF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
} else {
row = "Info: Copy IFS file " + tmpFileString + " to source member " + tmpFileString + " using command CPYFRMSTMF - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
// Delete the temporary file
ifsTmpFile.delete();
row = "Comp: Source member " + libraryName + "/" + fileName + "(" + memberName + ") was saved.";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "";
} catch (Exception exc) {
try {
outStream.close();
} catch (Exception exce) {
exce.printStackTrace();
}
exc.printStackTrace();
row = "Error: 3 Data cannot be written to the source member " + libraryName + "/" + fileName + "(" + memberName + ") - " + exc.toString();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
// Must not continue in order not to lock an object
return "ERROR";
}
}
Aggregations