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());
}
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());
}
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;
}
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());
}
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);
}
}
Aggregations