use of com.axway.ats.rbv.model.RbvException in project ats-framework by Axway.
the class DbFolder method refresh.
private void refresh() throws RbvException {
newMetaDataMap = new HashMap<String, MetaData>();
//store the current meta data map and clear the map holding all meta data
//this way we will be able to detect any changes including added and removed
//meta data
HashMap<String, MetaData> oldMetaDataMap = allMetaDataMap;
allMetaDataMap = new HashMap<String, MetaData>();
log.debug("Run DB query '" + this.searchQuery.getQuery() + "'");
DbRecordValuesList[] queryResults;
try {
queryResults = dbProvider.select(this.searchQuery);
} catch (DbException dbe) {
throw new RbvException(dbe);
}
if (queryResults != null) {
for (DbRecordValuesList queryResult : queryResults) {
DbMetaData currentData = new DbMetaData();
StringBuffer metaDataHash = new StringBuffer();
for (DbRecordValue recordValue : queryResult) {
DbMetaDataKey key = new DbMetaDataKey(recordValue.getDbColumn());
Object value = recordValue.getValue();
currentData.putProperty(key.toString(), value);
//calculate the hash
metaDataHash.append(key.toString());
metaDataHash.append(recordValue.getValueAsString());
}
try {
//compute MD5 so we don't keep the whole StringBuffer in memory
MessageDigest metaDataHashDigest = MessageDigest.getInstance("MD5");
String metaDataSum = new String(metaDataHashDigest.digest(metaDataHash.toString().getBytes()));
if (!oldMetaDataMap.containsKey(metaDataSum)) {
newMetaDataMap.put(metaDataSum, currentData);
}
//always put the record in the map holding all meta data
allMetaDataMap.put(metaDataSum, currentData);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
didPollingOccured = true;
}
}
use of com.axway.ats.rbv.model.RbvException in project ats-framework by Axway.
the class DbDateFieldRule method checkDate.
private boolean checkDate(DbMetaData dbMetaData) throws RbvException {
Timestamp actual;
try {
actual = (Timestamp) dbMetaData.getProperty(this.expectedMetaDataKey);
} catch (ClassCastException cce) {
throw new MetaDataIncorrectException("Meta data is incorrect - expected Timestamp");
}
long timestamp = ((Date) this.expectedValue).getTime();
Timestamp expected = new Timestamp(timestamp);
switch(this.relation) {
case BEFORE_DATE:
return actual.compareTo(expected) <= 0;
case AFTER_DATE:
return actual.compareTo(expected) >= 0;
case EXACT:
return actual.compareTo(expected) == 0;
default:
throw new RbvException("No implementation for MatchRelation '" + this.relation.toString() + "' in DbDateFieldMatchingTerm");
}
}
use of com.axway.ats.rbv.model.RbvException in project ats-framework by Axway.
the class DbDateFieldRule method checkString.
private boolean checkString(DbMetaData dbMetaData) throws RbvException {
String actualValue;
try {
actualValue = (String) dbMetaData.getProperty(this.expectedMetaDataKey.toString());
} catch (ClassCastException cce) {
throw new MetaDataIncorrectException("Meta data is incorrect - expected String");
}
try {
SimpleDateFormat sdf = new SimpleDateFormat(this.actualValuePattern);
sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
Date expectedDate = new Date(Long.parseLong((String) this.expectedValue) * 1000);
Date actualDate = sdf.parse(actualValue);
switch(this.relation) {
case BEFORE_DATE:
return expectedDate.before(actualDate);
case AFTER_DATE:
return expectedDate.after(actualDate);
case EXACT:
return expectedDate.compareTo(actualDate) == 0;
default:
throw new RbvException("No implementation for MatchRelation '" + this.relation.toString() + "' in DbDateFieldMatchingTerm");
}
} catch (NumberFormatException nfe) {
throw new RbvException("Expected value '" + this.expectedValue + "' cannot be converted to UNIX timestamp");
} catch (ParseException pe) {
//only if the actual value is incorrect
throw new RbvException("Actual value '" + actualValue + "' cannot be converted to Date");
}
}
use of com.axway.ats.rbv.model.RbvException in project ats-framework by Axway.
the class DbStringFieldRule method performMatch.
@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
boolean actualResult = false;
//this cast is safe, as isMatch has already checked the type of meta data
DbMetaData dbMetaData = (DbMetaData) metaData;
String actualValue;
try {
actualValue = (String) dbMetaData.getProperty(expectedMetaDataKey.toString());
if (dbEncryptor != null) {
actualValue = dbEncryptor.decrypt(actualValue);
}
log.info("Actual value is '" + actualValue + "'");
} catch (ClassCastException cce) {
throw new MetaDataIncorrectException("Meta data is incorrect - expected String");
}
if (expectedValue == null) {
return actualValue == null;
} else {
if (actualValue == null) {
return false;
}
}
if (relation == MatchRelation.EQUALS) {
actualResult = expectedValue.equals(actualValue);
} else if (relation == MatchRelation.CONTAINS) {
actualResult = actualValue.contains((String) expectedValue);
} else if (relation == MatchRelation.REGEX_MATCH) {
Pattern regexPattern = Pattern.compile((String) expectedValue);
actualResult = regexPattern.matcher(actualValue).matches();
} else {
throw new RbvException("No implementation for MatchRelation '" + relation.toString() + "' in DbStringFieldMatchingTerm");
}
return actualResult;
}
use of com.axway.ats.rbv.model.RbvException 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());
}
Aggregations