Search in sources :

Example 16 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method createBinaryFile.

/**
     * Creates a binary file. The content of the file is a byte sequence. The bytes
     * themselves are either fixed sequence, or randomly generated, depending on the
     * value of the randomContent parameter.
     *
     * @param filePath the file to work with
     * @param size the size of the generated file
     * @param userId the identification number of the user this file should belong to
     * @param groupId the identification number of the group this file should belong to
     * @param randomContent if true the method would generate a file with a random content
     */
@PublicAtsApi
public void createBinaryFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "size", type = ValidationType.NUMBER_POSITIVE) long size, @Validate(name = "userId", type = ValidationType.NUMBER_POSITIVE) int userId, @Validate(name = "groupId", type = ValidationType.NUMBER_POSITIVE) int groupId, boolean randomContent) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, size, userId, groupId, randomContent });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.createBinaryFile(filePath, size, userId, groupId, randomContent);
    // log the result of the operation
    String message = new StringBuilder().append("Successfully created binary file by the name of ").append(filePath).append(" with size ").append(size).append(" and UID/GID ").append(userId).append("/").append(groupId).toString();
    log.info(message);
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 17 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method copyDirectoryFrom.

/**
     * Copies the contents of a directory to a new one
     *
     * @param fromDirName the source file to copy
     * @param toDirName the destination file to copy to
     * @param isRecursive whether to copy recursively or not
     */
@PublicAtsApi
public void copyDirectoryFrom(@Validate(name = "fromDirName", type = ValidationType.STRING_NOT_EMPTY) String fromDirName, @Validate(name = "toDirName", type = ValidationType.STRING_NOT_EMPTY) String toDirName, @Validate(name = "isRecursive", type = ValidationType.NONE) boolean isRecursive) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { fromDirName, toDirName, isRecursive });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(this.atsAgent);
    if (operations instanceof LocalFileSystemOperations) {
        ((LocalFileSystemOperations) operations).copyDirectory(fromDirName, toDirName, isRecursive, this.failOnError);
        log.info("Successfully copied directory " + fromDirName + " to " + toDirName);
    } else {
        ((RemoteFileSystemOperations) operations).copyDirectoryFrom(fromDirName, toDirName, isRecursive, this.failOnError);
        log.info("Successfully copied directory " + fromDirName + " from " + this.atsAgent + " to " + toDirName + " on the local host");
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 18 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method getFileSize.

/**
     * Get the size of a file or directory
     *
     * @param filePath the file to work with
     * @return the size in bytes
     */
@PublicAtsApi
public long getFileSize(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath });
    long result = -1l;
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    result = operations.getFileSize(filePath);
    // log the result of the operation
    log.debug("Successfully got the size of " + filePath + getHostDescriptionSuffix());
    return result;
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 19 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method setFileHiddenAttribute.

/**
     * Make a file hidden or not hidden. <br/>
     * On Unix systems a file is made hidden by inserting '.' in front of its name. <br/>
     * On Windows a file is made hidden by setting the appropriate file attribute.
     *
     * @param filePath the file to work with
     * @param hidden switch hidden/not hidden
     */
@PublicAtsApi
public void setFileHiddenAttribute(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, boolean hidden) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, hidden });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.setFileHiddenAttribute(filePath, hidden);
    // log the result of the operation
    log.info("Successfully made the " + filePath + " to be " + (hidden ? "" : "not ") + "hidden" + getHostDescriptionSuffix());
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 20 with IFileSystemOperations

use of com.axway.ats.core.filesystem.model.IFileSystemOperations in project ats-framework by Axway.

the class FileSystemOperations method deleteFile.

/**
     * Deletes a file <br/>
     * <b>Note: </b>It does nothing if the file does not exist
     *
     * @param filePath the file to work with
     */
@PublicAtsApi
public void deleteFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.deleteFile(filePath);
    // log the result of the operation
    log.info("Successfully deleted " + filePath + getHostDescriptionSuffix());
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)46 Validator (com.axway.ats.core.validation.Validator)45 PublicAtsApi (com.axway.ats.common.PublicAtsApi)44 LocalFileSystemOperations (com.axway.ats.core.filesystem.LocalFileSystemOperations)6 FileMatchInfo (com.axway.ats.common.filesystem.FileMatchInfo)1 IProcessExecutor (com.axway.ats.core.process.model.IProcessExecutor)1 MobileOperationException (com.axway.ats.uiengine.exceptions.MobileOperationException)1 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1