Search in sources :

Example 26 with IFileSystemOperations

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

the class FileSystemOperations method createFile.

/**
     * Creates a file. The content is set by the user.
     *
     * @param filePath the file to work with
     * @param fileContent the text that will be parsed in the 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
     */
@PublicAtsApi
public void createFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "fileContent", type = ValidationType.NOT_NULL) String fileContent, @Validate(name = "userId", type = ValidationType.NUMBER_POSITIVE) int userId, @Validate(name = "groupId", type = ValidationType.NUMBER_POSITIVE) int groupId) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, fileContent, userId, groupId });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.createFile(filePath, fileContent, userId, groupId);
    // log the result of the operation
    String message = new StringBuilder().append("Successfully created file by the name of ").append(filePath).append(" with content ").append(fileContent).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 27 with IFileSystemOperations

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

the class FileSystemOperations method computeMd5Sum.

/**
     * Compute a file's MD5 sum
     *
     * @param filePath the file to work with
     * @param mode mode for computing the MD5 sum
     * <blockquote>
     * ASCII mode - the line endings will be ignored when computing the sum.
     * E.g. same file with Windows and Linux style line endings will give same MD5 sum <br/>
     * BINARY mode - each byte is affecting the returned result
     * </blockquote>
     * @return the MD5 sum in hex format
     */
@PublicAtsApi
public String computeMd5Sum(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, Md5SumMode mode) {
    String md5 = null;
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, Md5SumMode.BINARY });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    md5 = operations.computeMd5Sum(filePath, mode);
    // log the result of the operation
    log.debug("Successfully extracted the MD5 sum '" + md5 + "' of " + filePath + getHostDescriptionSuffix());
    return md5;
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 28 with IFileSystemOperations

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

the class FileSystemOperations method readFile.

/**
     * Reads the file content<br/>
     * <b>NOTE:</b> This method should be used for relatively small files as it loads the whole file in the memory
     *
     * @param filePathh the file to work with
     * @param fileEncoding the file encoding. If null the default encoding will be used
     * @return the file content
     */
@PublicAtsApi
public String readFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, String fileEncoding) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, fileEncoding });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    return operations.readFile(filePath, fileEncoding);
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 29 with IFileSystemOperations

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

the class FileSystemOperations method setFileGID.

/**
     * Set the GID of a file or directory
     *
     * @param filePath the file to work with
     * @param gid the GID number
     */
@PublicAtsApi
public void setFileGID(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "gid", type = ValidationType.NUMBER_POSITIVE) long gid) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, gid });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.setFileGID(filePath, gid);
    // log the result of the operation
    log.debug("Successfully set the GID '" + gid + "' of " + 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)

Example 30 with IFileSystemOperations

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

the class FileSystemOperations method createDirectory.

/**
     * Creates a directory on with a specific user and group id
     *
     * @param directoryName the name of the new directory
     * @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
     */
@PublicAtsApi
public void createDirectory(@Validate(name = "directoryName", type = ValidationType.STRING_NOT_EMPTY) String directoryName, @Validate(name = "userId", type = ValidationType.NUMBER_POSITIVE) int userId, @Validate(name = "groupId", type = ValidationType.NUMBER_POSITIVE) int groupId) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { directoryName, userId, groupId });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.createDirectory(directoryName, userId, groupId);
    // log the result of the operation
    log.info("Successfully created directory by the name of " + directoryName + 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