Search in sources :

Example 11 with Validator

use of com.axway.ats.core.validation.Validator in project ats-framework by Axway.

the class FileSystemOperations method copyDirectoryTo.

/**
     * 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 copyDirectoryTo(@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).copyDirectory(fromDirName, toDirName, isRecursive, this.failOnError);
        log.info("Successfully copied directory " + fromDirName + " from local host to " + toDirName + " on " + this.atsAgent);
    }
}
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 12 with Validator

use of com.axway.ats.core.validation.Validator in project ats-framework by Axway.

the class FileSystemOperations method createFile.

/**
     * Creates a file. The content of the file is the letters of the English alphabet.
     * The letters themselves are either alphabetically sorted, or randomly generated,
     * depending on the value of the randomContent parameter.
     * The end of line character will be the default one for the system where this action is run.
     *
     * @param filePath the file to work with
     * @param size the size of the generated file
     * @param randomContent if true the method would generate a file with a random content
     */
@PublicAtsApi
public void createFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "size", type = ValidationType.NUMBER_POSITIVE) long size, boolean randomContent) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, size, randomContent });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.createFile(filePath, size, randomContent);
    // log the result of the operation
    log.info("Successfully created file by the name of " + filePath + " with size " + size);
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 13 with Validator

use of com.axway.ats.core.validation.Validator in project ats-framework by Axway.

the class FileSystemOperations method getFileUID.

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

Example 14 with Validator

use of com.axway.ats.core.validation.Validator in project ats-framework by Axway.

the class FileSystemOperations method readFile.

/**
     * Read file from specific byte position. Used for file tail.<br/>
     * <b>NOTE:</b> If the file is replaced with the same byte content, then no change is assumed and 'null' is returned
     *
     * @param fileName file name
     * @param fromBytePosition byte offset. Example: for already read 100 bytes next method call is expected to have 100 as value for this parameter
     * @return {@link FileTailInfo} object
     */
@PublicAtsApi
public FileTailInfo readFile(@Validate(name = "fileName", type = ValidationType.STRING_NOT_EMPTY) String fileName, @Validate(name = "fromBytePosition", type = ValidationType.NONE) long fromBytePosition) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { fileName, fromBytePosition });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    return operations.readFile(fileName, fromBytePosition);
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 15 with Validator

use of com.axway.ats.core.validation.Validator in project ats-framework by Axway.

the class FileSystemOperations method getLastLinesFromFile.

/**
     * Get the last lines from a file
     *
     * @param filePath the file to work with
     * @param numberOfLinesToRead the number of lines to read
     * @return the last lines
     */
@PublicAtsApi
public String[] getLastLinesFromFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "numLinesToRead", type = ValidationType.NUMBER_GREATER_THAN_ZERO) int numberOfLinesToRead) {
    String[] lastLines = null;
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { filePath, numberOfLinesToRead });
    // execute action
    IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
    lastLines = operations.getLastLinesFromFile(filePath, numberOfLinesToRead);
    // log the result of the operation
    log.debug("Successfully got the last " + numberOfLinesToRead + " lines of '" + filePath + "'" + getHostDescriptionSuffix());
    return lastLines;
}
Also used : IFileSystemOperations(com.axway.ats.core.filesystem.model.IFileSystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

Validator (com.axway.ats.core.validation.Validator)67 PublicAtsApi (com.axway.ats.common.PublicAtsApi)66 IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)45 LocalFileSystemOperations (com.axway.ats.core.filesystem.LocalFileSystemOperations)6 ISystemOperations (com.axway.ats.core.system.model.ISystemOperations)4 FullReadingBean (com.axway.ats.common.performance.monitor.beans.FullReadingBean)3 MachineDescriptionOperations (com.axway.ats.agent.components.monitoring.operations.clients.MachineDescriptionOperations)1 InternalProcessOperations (com.axway.ats.agent.components.system.operations.clients.InternalProcessOperations)1 AgentException (com.axway.ats.agent.core.exceptions.AgentException)1 FileMatchInfo (com.axway.ats.common.filesystem.FileMatchInfo)1 ProcessExecutorException (com.axway.ats.common.process.ProcessExecutorException)1 DbAccessFactory (com.axway.ats.log.autodb.DbAccessFactory)1 DbWriteAccess (com.axway.ats.log.autodb.DbWriteAccess)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1