use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class FileSystemOperations method findNewTextInFile.
/**
* Searches some texts in file and it remembers where the search stopped.
* The following search starts from the point where the last search stopped<br/>
*
* This method is appropriate for growing text files(for example some kind of a log file)
*
* @param filePath the file to work with
* @param searchTexts the texts to search for. At least one should match.
* @param isRegex if the searchText is regular expression, otherwise the text must
* simply be contained by the file line
* @return {@link FileMatchInfo} object
*/
@PublicAtsApi
public FileMatchInfo findNewTextInFile(@Validate(name = "filePath", type = ValidationType.STRING_NOT_EMPTY) String filePath, @Validate(name = "searchTexts", type = ValidationType.NOT_NULL) String[] searchTexts, boolean isRegex) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { filePath, searchTexts, isRegex });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
long searchFromPosition = 0l;
int lastReadLineNumber = 0;
FileMatchInfo fileInfo = this.savedFileMatchDetails.get(filePath);
if (fileInfo != null) {
searchFromPosition = fileInfo.lastReadByte;
lastReadLineNumber = fileInfo.lastReadLineNumber;
}
fileInfo = operations.findTextInFileAfterGivenPosition(filePath, searchTexts, isRegex, searchFromPosition, lastReadLineNumber);
this.savedFileMatchDetails.put(filePath, fileInfo);
return fileInfo;
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class FileSystemOperations method copyRemoteDirectory.
/**
* Copies the contents of a directory located on a remote host to another remote host
*
* @param fromHost the address of the ATS agent on the source host
* @param fromDirectory the source file to copy
* @param toHost the address of the ATS agent on the destination host
* @param toDirectory the destination file to copy to
* @param isRecursive whether to copy recursively or not
*/
@PublicAtsApi
public void copyRemoteDirectory(@Validate(name = "fromHost", type = ValidationType.STRING_SERVER_WITH_PORT) String fromHost, @Validate(name = "fromDirectory", type = ValidationType.STRING_NOT_EMPTY) String fromDirectory, @Validate(name = "toHost", type = ValidationType.STRING_SERVER_WITH_PORT) String toHost, @Validate(name = "toDirectory", type = ValidationType.STRING_NOT_EMPTY) String toDirectory, @Validate(name = "isRecursive", type = ValidationType.NONE) boolean isRecursive) {
// replace to pass validation
if (fromHost == null) {
fromHost = LOCAL_HOST_NAME_AND_PORT;
}
if (toHost == null) {
toHost = LOCAL_HOST_NAME_AND_PORT;
}
// validate input parameters
fromHost = HostUtils.getAtsAgentIpAndPort(fromHost);
toHost = HostUtils.getAtsAgentIpAndPort(toHost);
new Validator().validateMethodParameters(new Object[] { fromHost, fromDirectory, toHost, toDirectory, isRecursive });
// execute action
IFileSystemOperations fromHostOperations = getOperationsImplementationFor(fromHost);
if (fromHostOperations instanceof LocalFileSystemOperations) {
IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
if (toHostOperations instanceof LocalFileSystemOperations) {
((LocalFileSystemOperations) toHostOperations).copyDirectory(fromDirectory, toDirectory, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirectory + " to " + toDirectory);
} else {
((RemoteFileSystemOperations) toHostOperations).copyDirectory(fromDirectory, toDirectory, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirectory + " from local host to " + toDirectory + " on " + toHost);
}
} else {
IFileSystemOperations toHostOperations = getOperationsImplementationFor(toHost);
if (toHostOperations instanceof LocalFileSystemOperations) {
((RemoteFileSystemOperations) fromHostOperations).copyDirectoryFrom(fromDirectory, toDirectory, isRecursive, this.failOnError);
log.info("Successfully copied directory " + fromDirectory + " from " + fromHost + " to " + toDirectory + " on the local host");
} else {
if (fromHost.equalsIgnoreCase(toHost)) {
// source and target hosts are remote, but they are same host indeed
((RemoteFileSystemOperations) fromHostOperations).copyDirectoryLocally(fromDirectory, toDirectory, isRecursive, this.failOnError);
} else {
((RemoteFileSystemOperations) fromHostOperations).copyDirectoryTo(fromDirectory, toHost, toDirectory, isRecursive, this.failOnError);
}
log.info("Successfully copied directory " + fromDirectory + " from " + fromHost + " to " + toDirectory + " on " + toHost);
}
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class FileSystemOperations method findFiles.
/**
* Searches for files and/or directories on the file system and returns the
* path of the matched ones. </br>
* <b>Note: </b>When path points to a directory, it ends with host's file path separator "/" or "\"
*
* @param startLocation the folder where search starts
* @param searchName the name of the searched files or folders
* @param isRegex whether we search the names by RegEx or a static name
* @param acceptDirectories if we will include matching directories as well
* @param recursiveSearch if will search in sub-directories
* @return the array of matched files and directories
*/
@PublicAtsApi
public String[] findFiles(@Validate(name = "startLocation", type = ValidationType.STRING_NOT_EMPTY) String startLocation, @Validate(name = "searchName", type = ValidationType.STRING_NOT_EMPTY) String searchName, @Validate(name = "isRegex", type = ValidationType.NONE) boolean isRegex, @Validate(name = "acceptDirectories", type = ValidationType.NONE) boolean acceptDirectories, @Validate(name = "recursiveSearch", type = ValidationType.NONE) boolean recursiveSearch) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { startLocation, searchName, isRegex, acceptDirectories, recursiveSearch });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
return operations.findFiles(startLocation, searchName, isRegex, acceptDirectories, recursiveSearch);
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class FileSystemOperations method copyFileTo.
/**
* Copies the contents of a file from the local host to a new file on the atsAgent host
*
* @param fromFile the source file to copy
* @param toFile the destination file to copy to
*/
@PublicAtsApi
public void copyFileTo(@Validate(name = "fromFile", type = ValidationType.STRING_NOT_EMPTY) String fromFile, @Validate(name = "toFile", type = ValidationType.STRING_NOT_EMPTY) String toFile) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { fromFile, toFile });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
if (operations instanceof LocalFileSystemOperations) {
((LocalFileSystemOperations) operations).copyFile(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " to " + toFile);
} else {
((RemoteFileSystemOperations) operations).copyFile(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " from local host to file " + toFile + " on " + atsAgent);
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class FileSystemOperations method copyFileFrom.
/**
* Copies the contents of a file from atsAgent host to a new file on the local host. <br/>
* <b>Note:</b> If no atsAgent is used or it is local, then the source files is searched on the local host
*
* @param fromFile the source file
* @param toFile the local destination file
*/
@PublicAtsApi
public void copyFileFrom(@Validate(name = "fromFile", type = ValidationType.STRING_NOT_EMPTY) String fromFile, @Validate(name = "toFile", type = ValidationType.STRING_NOT_EMPTY) String toFile) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { fromFile, toFile });
// execute action
IFileSystemOperations operations = getOperationsImplementationFor(atsAgent);
if (operations instanceof LocalFileSystemOperations) {
((LocalFileSystemOperations) operations).copyFile(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " to " + toFile);
} else {
((RemoteFileSystemOperations) operations).copyFileFrom(fromFile, toFile, this.failOnError);
log.info("Successfully copied " + fromFile + " from " + atsAgent + " to file " + toFile + " on the localhost");
}
}
Aggregations