use of com.axway.ats.core.validation.Validator 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);
}
use of com.axway.ats.core.validation.Validator 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");
}
}
use of com.axway.ats.core.validation.Validator 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;
}
use of com.axway.ats.core.validation.Validator 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());
}
use of com.axway.ats.core.validation.Validator 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());
}
Aggregations