Search in sources :

Example 1 with SaveFile

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

the class CreateAndDeleteInIBMi method deleteSaveFile.

/**
 * Delete Save File.
 */
@SuppressWarnings("UseSpecificCatch")
protected void deleteSaveFile() {
    extractNamesFromIfsPath(mainWindow.rightPathString);
    try {
        // Save file was recognized as type .FILE, subtype SAVF.
        SaveFile saveFile = new SaveFile(remoteServer, libraryName, saveFileName);
        saveFile.delete();
        row = "Comp: Save file  " + libraryName + "/" + saveFileName + "  was deleted.";
        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();
    } catch (Exception exc) {
        exc.printStackTrace();
        row = "Error deleting save file  " + mainWindow.rightPathString + ".";
        mainWindow.msgVector.add(row);
        mainWindow.showMessages();
    }
}
Also used : SaveFile(com.ibm.as400.access.SaveFile)

Example 2 with SaveFile

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

the class CreateAndDeleteInIBMi method createSaveFile.

/**
 * Create Save File.
 */
@SuppressWarnings("UseSpecificCatch")
protected void createSaveFile() {
    extractNamesFromIfsPath(mainWindow.rightPathString);
    // "true" stands for changing result to upper case
    saveFileName = new GetTextFromDialog("CREATE NEW SAVE FILE").getTextFromDialog("Library", "Save file name", libraryName, "", true, currentX, currentY);
    if (saveFileName == null) {
        return;
    }
    try {
        SaveFile saveFile = new SaveFile(remoteServer, libraryName, saveFileName);
        saveFile.create();
        row = "Comp: Save file  " + saveFileName + "  was created in library  " + libraryName + ".";
        mainWindow.msgVector.add(row);
        mainWindow.showMessages();
    } catch (Exception exc) {
        exc.printStackTrace();
        row = "Error at creating save file  " + libraryName + "/" + saveFileName + ".  System message is:  " + exc.toString() + ".";
        mainWindow.msgVector.add(row);
        mainWindow.showMessages();
    }
}
Also used : SaveFile(com.ibm.as400.access.SaveFile)

Example 3 with SaveFile

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

the class Copy_PC_IBMi method copyToSaveFile.

/**
 * Copy PC file to a new or existing Save File
 *
 * @param targetPathString
 * @param sourcePathString
 * @param toLibrary
 * @return
 */
@SuppressWarnings("UseSpecificCatch")
protected String copyToSaveFile(String sourcePathString, String targetPathString, boolean toLibrary) {
    // Extract individual names (libraryName, fileName, memberName) from the AS400 IFS path
    extractNamesFromIfsPath(targetPathString);
    String saveFilePathString;
    // Copy to LIBRARY
    if (toLibrary) {
        // Save file name is derived from PC file name excluding suffix .savf
        saveFileName = sourcePathString.substring(sourcePathString.lastIndexOf(pcFileSep) + 1, sourcePathString.lastIndexOf(".savf"));
        // Save file path string is derived from the path string of the library by adding the PC file name with suffix
        // .SAVF in upper case
        saveFilePathString = targetPathString + "/" + sourcePathString.substring(sourcePathString.lastIndexOf(pcFileSep) + 1).toUpperCase();
        // Create a new Save File if it does not exist
        try {
            SaveFile saveFile = new SaveFile(remoteServer, libraryName, saveFileName);
            if (!saveFile.exists()) {
                saveFile.create();
            }
        } catch (Exception exc) {
            exc.printStackTrace();
            row = "Error1: " + exc.toString();
            mainWindow.msgVector.add(row);
            mainWindow.showMessages();
            return "ERROR";
        }
        // Copy the PC file to Save file using FTP (File Transfer Protocol)
        AS400FTP ftp = new AS400FTP(remoteServer);
        try {
            // FTP Binary data transfer
            // ftp.setDataTransferType(AS400FTP.BINARY); // not necessary when suffix is .savf
            // FTP Put command
            ftp.put(sourcePathString, saveFilePathString);
            ftp.disconnect();
            row = "Comp: PC file  " + sourcePathString + "  was copied to save file  " + libraryName + "/" + saveFileName + ".";
            mainWindow.msgVector.add(row);
            mainWindow.showMessages();
            return "";
        } catch (Exception exc) {
            exc.printStackTrace();
            row = "Error: Copying PC file  " + sourcePathString + "  to save file  " + libraryName + "/" + saveFileName + "  failed:  " + exc.toString();
            mainWindow.msgVector.add(row);
            mainWindow.showMessages();
            return "ERROR";
        }
    } else // 
    // Copy to IFS FILE
    {
        // Save file name is derived from PC file name excluding suffix .savf
        saveFileName = sourcePathString.substring(sourcePathString.lastIndexOf(pcFileSep) + 1);
        if (!sourcePathString.endsWith(".savf")) {
            row = "Error: Copying PC save file  " + sourcePathString + "  ending with suffix \".savf\" cannot be copied to the existing file  " + targetPathString + "  with a different suffix.";
            mainWindow.msgVector.add(row);
            mainWindow.showMessages();
            return "ERROR";
        } else {
            // Copy the PC file to Save file using FTP (File Transfer Protocol)
            AS400FTP ftp = new AS400FTP(remoteServer);
            try {
                // FTP Binary data transfer
                // ftp.setDataTransferType(AS400FTP.BINARY); // not necessary when suffix is .savf
                // FTP Put command
                ftp.put(sourcePathString, targetPathString);
                ftp.disconnect();
                row = "Comp: PC save file  " + sourcePathString + "  was copied to IFS save file  " + targetPathString + ".";
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
                return "";
            } catch (Exception exc) {
                exc.printStackTrace();
                row = "Error: Copying PC save file  " + sourcePathString + "  to IFS save file  " + targetPathString + "  failed:  " + exc.toString();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
                return "ERROR";
            }
        }
    }
}
Also used : SaveFile(com.ibm.as400.access.SaveFile) AS400FTP(com.ibm.as400.access.AS400FTP) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException)

Example 4 with SaveFile

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

the class CreateAndDeleteInIBMi method clearSaveFile.

/**
 * Clear Save File.
 */
@SuppressWarnings("UseSpecificCatch")
protected void clearSaveFile() {
    extractNamesFromIfsPath(mainWindow.rightPathString);
    try {
        SaveFile saveFile = new SaveFile(remoteServer, libraryName, saveFileName);
        saveFile.clear();
        row = "Comp: Save file  " + libraryName + "/" + saveFileName + "  was cleared.";
        mainWindow.msgVector.add(row);
        mainWindow.showMessages(false);
    } catch (Exception exc) {
        exc.printStackTrace();
        row = "Error clearing save file  " + mainWindow.rightPathString + ".";
        mainWindow.msgVector.add(row);
        mainWindow.showMessages(false);
    }
}
Also used : SaveFile(com.ibm.as400.access.SaveFile)

Aggregations

SaveFile (com.ibm.as400.access.SaveFile)4 AS400FTP (com.ibm.as400.access.AS400FTP)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1