Search in sources :

Example 21 with PackageException

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());
}
Also used : MatchableNotOpenException(com.axway.ats.rbv.model.MatchableNotOpenException) HashMap(java.util.HashMap) RbvException(com.axway.ats.rbv.model.RbvException) ArrayList(java.util.ArrayList) MatchableAlreadyOpenException(com.axway.ats.rbv.model.MatchableAlreadyOpenException) MatchableNotOpenException(com.axway.ats.rbv.model.MatchableNotOpenException) RbvException(com.axway.ats.rbv.model.RbvException) PackageException(com.axway.ats.action.objects.model.PackageException) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException) FilePackage(com.axway.ats.action.objects.FilePackage) MetaData(com.axway.ats.rbv.MetaData) PackageException(com.axway.ats.action.objects.model.PackageException)

Example 22 with PackageException

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;
}
Also used : FilePackage(com.axway.ats.action.objects.FilePackage) PackageException(com.axway.ats.action.objects.model.PackageException) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData)

Example 23 with PackageException

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;
}
Also used : FilePackage(com.axway.ats.action.objects.FilePackage) PackageException(com.axway.ats.action.objects.model.PackageException) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException) FileSystemMetaData(com.axway.ats.rbv.filesystem.FileSystemMetaData)

Example 24 with PackageException

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;
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) RbvException(com.axway.ats.rbv.model.RbvException) PackageException(com.axway.ats.action.objects.model.PackageException)

Example 25 with PackageException

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;
}
Also used : MimePackage(com.axway.ats.action.objects.MimePackage) RbvException(com.axway.ats.rbv.model.RbvException) PackageException(com.axway.ats.action.objects.model.PackageException) NoSuchHeaderException(com.axway.ats.action.objects.model.NoSuchHeaderException)

Aggregations

PackageException (com.axway.ats.action.objects.model.PackageException)52 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)34 MessagingException (javax.mail.MessagingException)32 PublicAtsApi (com.axway.ats.common.PublicAtsApi)31 MimePart (javax.mail.internet.MimePart)11 IOException (java.io.IOException)10 NoSuchMimePartException (com.axway.ats.action.objects.model.NoSuchMimePartException)9 FilePackage (com.axway.ats.action.objects.FilePackage)7 BaseTest (com.axway.ats.rbv.BaseTest)7 InternetAddress (javax.mail.internet.InternetAddress)7 Test (org.junit.Test)7 MimePackage (com.axway.ats.action.objects.MimePackage)6 RbvException (com.axway.ats.rbv.model.RbvException)6 InputStream (java.io.InputStream)6 RbvStorageException (com.axway.ats.rbv.model.RbvStorageException)5 ContentType (javax.mail.internet.ContentType)5 MimeBodyPart (javax.mail.internet.MimeBodyPart)5 MimeMultipart (javax.mail.internet.MimeMultipart)5 FileSystemMetaData (com.axway.ats.rbv.filesystem.FileSystemMetaData)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4