use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class FileSystemFolder method getAllMetaData.
public List<MetaData> getAllMetaData() throws RbvException {
//first check if the folder is already open
if (!isOpen) {
throw new MatchableNotOpenException("File system folder is not open");
}
newMetaData.clear();
if (fileName == null) {
fileName = ".*";
isRegExp = true;
}
HashMap<String, MetaData> tempMetaData = new HashMap<String, MetaData>();
//fetch dir contents recursively
String[] fileList;
try {
fileList = this.fileSystemOperations.findFiles(path, fileName, isRegExp, true, includeSubDirs);
} catch (Exception e) {
final String notExistMessageSuffix = "does not exist or is not a folder";
if ((e.getMessage() != null && e.getMessage().endsWith(notExistMessageSuffix)) || (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage().endsWith(notExistMessageSuffix))) {
log.warn(getDescription() + " does not exist, skipping to next poll attempt");
return new ArrayList<MetaData>();
}
throw new RbvException("Unable to list the contents of " + path, e);
}
if (fileList != null) {
for (String fileName : fileList) {
try {
FilePackage file = new FilePackage(atsAgent, fileName.trim(), osType);
MetaData metaData = new FileSystemMetaData(file);
// The way files are compared is by combining their name+path,
// modification time, user and group ID in a hash string
String hashKey = file.getUniqueIdentifier();
if (!allMetaData.containsKey(hashKey)) {
newMetaData.add(metaData);
}
tempMetaData.put(hashKey, metaData);
} catch (PackageException e) {
// the creation of the package somehow failed - a simple explanation would be that
// the filed was removed during the execution of this method or something similar;
log.warn("Unable to build up metadata for " + fileName, e);
// either way we need not throw an exception but only continue iterating
}
}
}
allMetaData.clear();
allMetaData.putAll(tempMetaData);
return new ArrayList<MetaData>(allMetaData.values());
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class FileMd5Rule method performMatch.
@Override
public boolean performMatch(MetaData metaData) throws RbvException {
boolean actualResult = false;
if (metaData instanceof FileSystemMetaData) {
//get the file from the meta data
FilePackage file = ((FileSystemMetaData) metaData).getFilePackage();
try {
String destMD5 = file.getMd5sum(this.binaryMode);
actualResult = !StringUtils.isNullOrEmpty(destMD5) && destMD5.equals(this.srcMD5);
} catch (PackageException pe) {
throw new RbvStorageException(pe);
}
}
return actualResult;
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class FileSizeRule method performMatch.
@Override
public boolean performMatch(MetaData metaData) throws RbvException {
boolean actuaResult = false;
if (metaData instanceof FileSystemMetaData) {
//get the file from the meta data
FilePackage file = ((FileSystemMetaData) metaData).getFilePackage();
try {
//get destination file's size
long destSize = file.getSize();
actuaResult = this.srcSize == destSize;
} catch (PackageException pe) {
throw new RbvStorageException(pe);
}
}
return actuaResult;
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class AttachmentNameRule method performMatch.
@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
//get the emailMessage
//the meta data type check already passed, so it is safe to cast
MimePackage emailMessage = getNeededMimePackage(metaData);
String attachmentFileName;
try {
attachmentFileName = emailMessage.getAttachmentFileName(attachmentIndex);
} catch (PackageException pe) {
throw new RbvException(pe);
}
//if there is no such file name return false
boolean actualResult = false;
if (attachmentFileName != null) {
actualResult = Pattern.compile(expectedValue).matcher(attachmentFileName).matches();
log.info("Actual attachment file name is '" + attachmentFileName + "'");
} else {
log.info("No attachment with name that matches '" + expectedValue + "' was found");
}
return actualResult;
}
use of com.axway.ats.action.objects.model.PackageException in project ats-framework by Axway.
the class HeaderRule method performMatch.
@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
//get the emailMessage
//the meta data type check already passed, so it is safe to cast
MimePackage emailMessage = getNeededMimePackage(metaData);
String[] headerValues;
try {
if (headerIndex == -1) {
// we are going to check all header values
if (partIndex == PART_MAIN_MESSAGE) {
headerValues = emailMessage.getHeaderValues(headerName);
} else {
headerValues = emailMessage.getPartHeaderValues(headerName, partIndex);
}
} else {
// we are going to check a particular header value
String headerValue;
if (partIndex == PART_MAIN_MESSAGE) {
headerValue = emailMessage.getHeader(headerName, headerIndex);
} else {
headerValue = emailMessage.getPartHeader(headerName, partIndex, headerIndex);
}
headerValues = new String[] { headerValue };
}
} catch (NoSuchHeaderException nshe) {
log.debug("Meta data has no header '" + headerName + "'");
//no such header, so return false
return false;
} catch (PackageException pe) {
throw new RbvException(pe);
}
//if there is no such header return false
boolean actualResult = false;
if (headerValues == null || headerValues.length == 0) {
log.info("No header '" + headerName + "' was found");
} else {
for (String headerValue : headerValues) {
switch(matchMode) {
case LEFT:
actualResult = headerValue.startsWith(expectedValue);
break;
case RIGHT:
actualResult = headerValue.endsWith(expectedValue);
break;
case EQUALS:
actualResult = headerValue.equals(expectedValue);
break;
case FIND:
actualResult = headerValue.indexOf(expectedValue) >= 0;
break;
case REGEX:
actualResult = Pattern.compile(expectedValue).matcher(headerValue).find();
break;
}
log.info("Actual value for header '" + headerName + "' is '" + headerValue + "'");
if (actualResult) {
// we matched a header value, stop iterating the rest of the values
break;
}
}
}
return actualResult;
}
Aggregations