use of com.ibm.as400.access.CommandCall in project IBMiProgTool by vzupka.
the class CreateAndDeleteInIBMi method createIfsDirectory.
/**
* Create IFS directory.
*/
protected void createIfsDirectory() {
// Enable calling CL commands
CommandCall cmdCall = new CommandCall(remoteServer);
// "false" stands for not changing result to upper case
String directoryName = new GetTextFromDialog("CREATE NEW DIRECTORY").getTextFromDialog("Parent directory", "New directory name", mainWindow.rightPathString + "/", "", false, currentX, currentY);
// User canceled creating the directory
if (directoryName == null) {
return;
}
if (directoryName.isEmpty()) {
directoryName = "New directory";
}
try {
// Get path to the newly created directory by adding its name to the parent directory path
IFSFile ifsFile = new IFSFile(remoteServer, mainWindow.rightPathString + "/" + directoryName);
// Create new directory
ifsFile.mkdir();
// String for command CHGATR to set CCSID attribute of the new directory
String command_CHGATR = "CHGATR OBJ('" + mainWindow.rightPathString + "/" + directoryName + "') ATR(*CCSID) VALUE(" + ibmCcsid + ") SUBTREE(*ALL)";
System.out.println(command_CHGATR);
// Perform the command
cmdCall.run(command_CHGATR);
// 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: Change CCSID attribute with command CHGATR - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
} else {
row = "Info: Change CCSID attribute with command CHGATR - " + as400Message.getID() + " " + as400Message.getText();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
row = "Comp: IFS directory " + ifsFile.toString() + " created in directory " + mainWindow.rightPathString + " - CCSID " + ibmCcsid + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
} catch (Exception exc) {
exc.printStackTrace();
row = "Error:" + exc.toString();
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
}
use of com.ibm.as400.access.CommandCall in project IBMiProgTool by vzupka.
the class Compile method performCommand.
/**
* @param compileCommandText
*/
protected void performCommand(String compileCommandText) {
if (compileCommandText == null) {
return;
}
// Create object for calling CL commands
CommandCall cmdCall = new CommandCall(remoteServer);
try {
// Get current server job
Job currentJob = new Job();
currentJob = cmdCall.getServerJob();
// Set job attributes
currentJob.setLoggingLevel(4);
currentJob.setLoggingCLPrograms("*YES");
currentJob.setLoggingSeverity(0);
currentJob.setLoggingText(Job.LOGGING_TEXT_SECLVL);
// Get library list from the file "UserLibraryList.lib"
String liblParameter = "";
List<String> items = Files.readAllLines(libraryListPath);
if (!items.isEmpty()) {
items.get(0);
String[] userUserLibraryList = items.get(0).split(",");
for (int idx = 1; idx < userUserLibraryList.length; idx++) {
liblParameter += userUserLibraryList[idx].trim() + " ";
}
}
if (liblParameter.isEmpty()) {
liblParameter = "*NONE";
}
// Get current library for the file "CurrentLibrary.lib"
String curlibParameter = "";
List<String> curlib = Files.readAllLines(currentLibraryPath);
if (!curlib.isEmpty()) {
// The only item is the current library name or *CRTDFT
curlibParameter += curlib.get(0);
}
// Build command CHGLIBL
String commandChgLiblText = "CHGLIBL LIBL(" + liblParameter + ") CURLIB(" + curlibParameter + ")";
// Perform the GHGLIBL command
// -------
cmdCall.run(commandChgLiblText);
// Perform the compile command
// -------------------
cmdCall.run(compileCommandText);
// Get messages from the command if any
AS400Message[] messagelist = cmdCall.getMessageList();
String[] strArr = new String[messagelist.length];
// Print all messages
String type = "";
int msgType;
for (int idx = 0; idx < messagelist.length; idx++) {
msgType = messagelist[idx].getType();
switch(msgType) {
case AS400Message.ESCAPE:
{
type = "*ESCAPE";
}
case AS400Message.DIAGNOSTIC:
{
type = "*DIAGNOSTIC";
}
case AS400Message.COMPLETION:
{
type = "*COMPLETION";
}
case AS400Message.NOTIFY:
{
type = "*NOTIFY";
}
case AS400Message.INFORMATIONAL:
{
type = "*INFORMATIONAL";
}
}
strArr[idx] = messagelist[idx].getID() + " " + type + ": " + messagelist[idx].getText();
row = strArr[idx];
msgVector.add(row);
if (!messagelist[idx].getHelp().isEmpty()) {
strArr[idx] = " " + messagelist[idx].getHelp();
row = strArr[idx];
msgVector.add(row);
}
}
reloadMessages();
} catch (Exception exc) {
exc.printStackTrace();
}
}
Aggregations