Search in sources :

Example 11 with CommandCall

use of com.ibm.as400.access.CommandCall 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";
    }
}
Also used : CommandCall(com.ibm.as400.access.CommandCall) IFSFileOutputStream(com.ibm.as400.access.IFSFileOutputStream) AS400Text(com.ibm.as400.access.AS400Text) AS400Message(com.ibm.as400.access.AS400Message) CannotUndoException(javax.swing.undo.CannotUndoException) CannotRedoException(javax.swing.undo.CannotRedoException) BadLocationException(javax.swing.text.BadLocationException) IFSFile(com.ibm.as400.access.IFSFile)

Example 12 with CommandCall

use of com.ibm.as400.access.CommandCall in project IBMiProgTool by vzupka.

the class Compile method printJobLog.

/**
 */
protected void printJobLog() {
    try {
        // Create object for calling CL commands
        CommandCall cmdCall = new CommandCall(remoteServer);
        // Build command DSPJOBLOG so that the job log is printed after the current job ends
        String commandDspJobLog = "DSPJOBLOG JOB(*) OUTPUT(*PRINT) MSGF(*MSG) DUPJOBOPT(*MSG)";
        // Perform the DSPJOBLOG command
        cmdCall.run(commandDspJobLog);
    } catch (Exception exc) {
        exc.printStackTrace();
    }
}
Also used : CommandCall(com.ibm.as400.access.CommandCall)

Example 13 with CommandCall

use of com.ibm.as400.access.CommandCall in project IBMiProgTool by vzupka.

the class ChangeLibraryList method getUserLibraryList2.

/**
 * @return
 */
protected String[] getUserLibraryList2() {
    CommandCall cmdCall = new CommandCall(remoteServer);
    Job currentJob = new Job();
    try {
        currentJob = cmdCall.getServerJob();
        currentJob.getUser();
        currentJob.getName();
        currentJob.getNumber();
        String[] libList = currentJob.getUserLibraryList();
        return libList;
    } catch (Exception exc) {
        exc.printStackTrace();
        return null;
    }
}
Also used : CommandCall(com.ibm.as400.access.CommandCall) Job(com.ibm.as400.access.Job) IOException(java.io.IOException)

Example 14 with CommandCall

use of com.ibm.as400.access.CommandCall in project IBMiProgTool by vzupka.

the class CreateAndDeleteInIBMi method createSourceMember.

/**
 * Create Source Member.
 */
protected void createSourceMember() {
    sourceFilesAndTypes = new TreeMap<>();
    // Table of Standard Source Physical File Names (keys) and default Source Types (values)
    sourceFilesAndTypes.put("QCLSRC", "CLLE");
    sourceFilesAndTypes.put("QDDSSRC", "DSPF");
    sourceFilesAndTypes.put("QRPGLESRC", "RPGLE");
    sourceFilesAndTypes.put("QRPGSRC", "RPG");
    sourceFilesAndTypes.put("QCBLLESRC", "CBLLE");
    sourceFilesAndTypes.put("QCBLSRC", "CBL");
    sourceFilesAndTypes.put("QCMDSRC", "CMD");
    sourceFilesAndTypes.put("QCSRC", "C");
    sourceFilesAndTypes.put("QTBLSRC", "TBL");
    // Get library name from the IFS path string
    extractNamesFromIfsPath(mainWindow.rightPathString);
    // "true" stands for changing result to upper case
    String memberName = new GetTextFromDialog("CREATE NEW SOURCE MEMBER").getTextFromDialog("Library", "Source member name", libraryName, "", true, currentX, currentY);
    if (memberName == null) {
        return;
    }
    if (memberName.isEmpty()) {
        memberName = "MEMBER.MBR";
    }
    // Set source type according to the source physical file name
    String sourceType = getDefaultSourceType(fileName);
    // Build command ADDPFM to create a member in the source physical file
    String commandText = "ADDPFM FILE(" + libraryName + "/" + fileName + ") MBR(" + memberName + ")" + " TEXT('Member " + memberName + "')" + " SRCTYPE(" + sourceType + ")";
    // 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 ADDPFM command is " + as400Message.getID() + " " + as400Message.getText();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
                return;
            } else {
                msgType = "Info";
                row = msgType + ": message from the ADDPFM command is " + as400Message.getID() + " " + as400Message.getText();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        row = "Error: Creating source member  " + ifsFile.toString() + " - " + exc.toString() + ".";
        mainWindow.msgVector.add(row);
        mainWindow.showMessages();
        return;
    }
}
Also used : CommandCall(com.ibm.as400.access.CommandCall) AS400Message(com.ibm.as400.access.AS400Message)

Example 15 with CommandCall

use of com.ibm.as400.access.CommandCall in project IBMiProgTool by vzupka.

the class CreateAndDeleteInIBMi method copyLibrary.

/**
 * Copy library
 */
protected void copyLibrary() {
    extractNamesFromIfsPath(mainWindow.rightPathString);
    // "false" stands for not changing result to upper case
    String newLibraryName = new GetTextFromDialog("COPY LIBRARY").getTextFromDialog("Library name", "New library name", libraryName, "", true, currentX, currentY);
    // Enable calling CL commands
    CommandCall command = new CommandCall(remoteServer);
    // Build command CPYLIB to copy the library
    String commandText = "CPYLIB FROMLIB(" + libraryName + ") TOLIB(" + newLibraryName + ") CRTLIB(*YES) ";
    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 CPYLIB command is  " + as400Message.getID() + " " + as400Message.getText();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
                return;
            } else {
                msgType = "Info";
                row = msgType + ": message from the CPYLIB command is  " + as400Message.getID() + " " + as400Message.getText();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        row = "Error: Copying library  " + libraryName + "  -  " + exc.toString() + ".";
        mainWindow.msgVector.add(row);
        mainWindow.showMessages();
        return;
    }
    row = "Comp: Library  " + libraryName + "  was copied to  " + newLibraryName + ".";
    mainWindow.msgVector.add(row);
    // PARENT NODE of deleted node will be reloaded and the deleted node will disappear from the tree.
    // Get parent path string
    mainWindow.rightPathString = mainWindow.rightPathString.substring(0, mainWindow.rightPathString.lastIndexOf("/"));
    // Get parent node
    mainWindow.rightNode = (DefaultMutableTreeNode) mainWindow.rightNode.getParent();
    mainWindow.showMessages();
}
Also used : CommandCall(com.ibm.as400.access.CommandCall) AS400Message(com.ibm.as400.access.AS400Message)

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