Search in sources :

Example 16 with CommandCall

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();
    }
}
Also used : CommandCall(com.ibm.as400.access.CommandCall) AS400Message(com.ibm.as400.access.AS400Message) IFSFile(com.ibm.as400.access.IFSFile)

Example 17 with CommandCall

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();
    }
}
Also used : CommandCall(com.ibm.as400.access.CommandCall) AS400Message(com.ibm.as400.access.AS400Message) Job(com.ibm.as400.access.Job)

Aggregations

CommandCall (com.ibm.as400.access.CommandCall)17 AS400Message (com.ibm.as400.access.AS400Message)14 IFSFile (com.ibm.as400.access.IFSFile)9 Job (com.ibm.as400.access.Job)2 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)2 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)2 AS400FileRecordDescription (com.ibm.as400.access.AS400FileRecordDescription)1 AS400Text (com.ibm.as400.access.AS400Text)1 IFSFileOutputStream (com.ibm.as400.access.IFSFileOutputStream)1 Record (com.ibm.as400.access.Record)1 RecordFormat (com.ibm.as400.access.RecordFormat)1 SequentialFile (com.ibm.as400.access.SequentialFile)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Path (java.nio.file.Path)1 BadLocationException (javax.swing.text.BadLocationException)1 CannotRedoException (javax.swing.undo.CannotRedoException)1 CannotUndoException (javax.swing.undo.CannotUndoException)1