Search in sources :

Example 1 with MatchableNotOpenException

use of com.axway.ats.rbv.model.MatchableNotOpenException 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 2 with MatchableNotOpenException

use of com.axway.ats.rbv.model.MatchableNotOpenException in project ats-framework by Axway.

the class Test_MatchableNotOpenException method constructors.

@Test
public void constructors() {
    MatchableNotOpenException exception;
    exception = new MatchableNotOpenException("test");
    assertEquals("test", exception.getMessage());
    assertNull(exception.getCause());
    Exception helperException = new Exception();
    exception = new MatchableNotOpenException("test", helperException);
    assertEquals("test", exception.getMessage());
    assertEquals(helperException, exception.getCause());
    exception = new MatchableNotOpenException(helperException);
    assertEquals("java.lang.Exception", exception.getMessage());
    assertEquals(helperException, exception.getCause());
}
Also used : MatchableNotOpenException(com.axway.ats.rbv.model.MatchableNotOpenException) MatchableNotOpenException(com.axway.ats.rbv.model.MatchableNotOpenException) BaseTest(com.axway.ats.rbv.BaseTest) Test(org.junit.Test)

Example 3 with MatchableNotOpenException

use of com.axway.ats.rbv.model.MatchableNotOpenException in project ats-framework by Axway.

the class ImapFolder method getNewMetaData.

public List<MetaData> getNewMetaData() throws RbvException {
    //first check if the folder is open
    if (!isOpen) {
        throw new MatchableNotOpenException(getDescription() + " is not open");
    }
    if (isInitialPass) {
        isInitialPass = false;
        return getAllMetaData();
    }
    try {
        newMetaDataList.clear();
        Message[] imapMessages = folder.getMessages();
        for (Message imapMessage : imapMessages) {
            if (!imapMessage.getFlags().contains(Flags.Flag.FLAGGED)) {
                imapMessage.setFlag(Flags.Flag.FLAGGED, true);
                ImapMetaData currentMeta = createImapMetaData((MimeMessage) imapMessage);
                if (currentMeta != null) {
                    allMetaDataList.add(currentMeta);
                    newMetaDataList.add(currentMeta);
                }
            }
        }
    } catch (MessagingException me) {
        throw new RbvStorageException("Could not get meta data from " + getDescription(), me);
    }
    return newMetaDataList;
}
Also used : Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MatchableNotOpenException(com.axway.ats.rbv.model.MatchableNotOpenException) MessagingException(javax.mail.MessagingException) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException)

Example 4 with MatchableNotOpenException

use of com.axway.ats.rbv.model.MatchableNotOpenException in project ats-framework by Axway.

the class ImapFolder method expunge.

/**
     * Cleans up the associated IMAP folder
     * @throws RbvStorageException
     */
@PublicAtsApi
public void expunge() throws RbvStorageException {
    //first check if the folder is open
    if (!isOpen) {
        throw new MatchableNotOpenException(getDescription() + " is not open");
    }
    try {
        folder.setFlags(folder.getMessages(), new Flags(Flags.Flag.DELETED), true);
        folder.expunge();
    } catch (MessagingException me) {
        throw new RbvStorageException(me);
    }
    log.info("Expunged " + getDescription());
}
Also used : MatchableNotOpenException(com.axway.ats.rbv.model.MatchableNotOpenException) MessagingException(javax.mail.MessagingException) Flags(javax.mail.Flags) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 5 with MatchableNotOpenException

use of com.axway.ats.rbv.model.MatchableNotOpenException in project ats-framework by Axway.

the class ImapFolder method close.

/**
     * Closes the IMAP folder
     * @see com.axway.ats.rbv.storage.Matchable#close()
     */
@PublicAtsApi
public void close() throws RbvStorageException {
    //first check if the folder is open
    if (!isOpen) {
        throw new MatchableNotOpenException(getDescription() + " is not open");
    }
    try {
        if (store.isConnected()) {
            folder.close(true);
            store.close();
            log.info("Closed " + getDescription());
        }
        isOpen = false;
    } catch (MessagingException me) {
        throw new RbvStorageException("Could not close " + getDescription(), me);
    }
}
Also used : MatchableNotOpenException(com.axway.ats.rbv.model.MatchableNotOpenException) MessagingException(javax.mail.MessagingException) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

MatchableNotOpenException (com.axway.ats.rbv.model.MatchableNotOpenException)6 RbvStorageException (com.axway.ats.rbv.model.RbvStorageException)5 MessagingException (javax.mail.MessagingException)4 PublicAtsApi (com.axway.ats.common.PublicAtsApi)2 Message (javax.mail.Message)2 MimeMessage (javax.mail.internet.MimeMessage)2 FilePackage (com.axway.ats.action.objects.FilePackage)1 PackageException (com.axway.ats.action.objects.model.PackageException)1 BaseTest (com.axway.ats.rbv.BaseTest)1 MetaData (com.axway.ats.rbv.MetaData)1 MatchableAlreadyOpenException (com.axway.ats.rbv.model.MatchableAlreadyOpenException)1 RbvException (com.axway.ats.rbv.model.RbvException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Flags (javax.mail.Flags)1 Test (org.junit.Test)1