use of com.adaptris.util.KeyValuePair in project interlok by adaptris.
the class IntegerValueMatcher method getNextServiceId.
public String getNextServiceId(String serviceKey, KeyValuePairBag mappings) {
String result = null;
Integer lhs = null;
Integer rhs = null;
try {
lhs = Integer.parseInt(serviceKey);
} catch (NumberFormatException e) {
logR.trace("[{}] not parseable as an integer", serviceKey);
return result;
}
Pattern matchPattern = Pattern.compile(INTEGER_OPERATOR_PATTERN);
Set<KeyValuePair> pairs = sort(mappings);
for (KeyValuePair kvp : pairs) {
Matcher m = matchPattern.matcher(kvp.getKey());
if (m.matches()) {
String operator = m.group(1);
rhs = Integer.parseInt(m.group(2));
Operator o = OPERATORS.get(operator);
if (o == null) {
logR.trace("[{}] not handled, ignoring", kvp.getKey());
continue;
}
logR.trace("Comparing [{}] against [{}] using {}", lhs, rhs, o.toString());
if (o.matches(lhs, rhs)) {
result = kvp.getValue();
break;
}
} else {
logR.trace("Ignoring {}, no match for regular expression [{}]", kvp.getKey(), INTEGER_OPERATOR_PATTERN);
}
}
return result;
}
use of com.adaptris.util.KeyValuePair in project interlok by adaptris.
the class MapMetadataService method doService.
/**
* @see com.adaptris.core.Service#doService(AdaptrisMessage)
*/
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
if (metadataKey == null || !msg.headersContainsKey(metadataKey)) {
log.debug("Message does not contain metadatakey [" + metadataKey + "]");
return;
}
String metadataValue = msg.getMetadataValue(metadataKey);
metadataValue = ObjectUtils.defaultIfNull(metadataValue, "");
List<MetadataElement> mapped = new ArrayList<>();
for (KeyValuePair k : getMetadataKeyMap()) {
if (metadataValue.matches(k.getKey())) {
String newMetadataValue = doSubstitution(metadataValue, k, msg);
MetadataElement e = new MetadataElement(metadataKey, newMetadataValue);
msg.addMetadata(e);
mapped.add(e);
break;
}
}
logMetadata("Modified Metadata : {}", mapped);
}
use of com.adaptris.util.KeyValuePair in project interlok by adaptris.
the class DocumentBuilderFactoryBuilder method withFeatures.
public DocumentBuilderFactoryBuilder withFeatures(Map<String, Boolean> f) {
Map<String, Boolean> featureList = Args.notNull(f, "features");
KeyValuePairSet newFeatures = new KeyValuePairSet();
for (Map.Entry<String, Boolean> entry : featureList.entrySet()) {
newFeatures.add(new KeyValuePair(entry.getKey(), String.valueOf(entry.getValue())));
}
return withFeatures(newFeatures);
}
use of com.adaptris.util.KeyValuePair in project interlok by adaptris.
the class AdapterStateSummaryTest method testAddChannelStateKeyValuePair.
@Test
public void testAddChannelStateKeyValuePair() {
AdapterStateSummary s1 = new AdapterStateSummary();
s1.addChannelState(new KeyValuePair(DEFAULT_KEY, ClosedState.getInstance().getClass().getName()));
assertEquals(1, s1.getChannelStates().size());
assertTrue(s1.getChannelStates().contains(new KeyValuePair(DEFAULT_KEY, "")));
assertEquals(DEFAULT_KEY, s1.getChannelStates().getKeyValuePair(DEFAULT_KEY).getKey());
assertEquals(ClosedState.getInstance().getClass().getName(), s1.getChannelStates().getKeyValuePair(DEFAULT_KEY).getValue());
s1.addChannelState(new KeyValuePair("", "ABC"));
assertEquals(1, s1.getChannelStates().size());
try {
s1.addChannelState(new KeyValuePair("ABC", ""));
fail("Null Value in KeyValuePair");
} catch (IllegalArgumentException expected) {
}
try {
s1.addChannelState(null);
fail("Null KeyValuePair");
} catch (IllegalArgumentException expected) {
}
}
use of com.adaptris.util.KeyValuePair in project interlok by adaptris.
the class ConfiguredRequestHeadersTest method testSetHandlers.
@Test
public void testSetHandlers() throws Exception {
ConfiguredRequestHeaders headers = new ConfiguredRequestHeaders();
assertNotNull(headers.getHeaders());
assertEquals(0, headers.getHeaders().size());
String name = testName.getMethodName();
headers.getHeaders().add(new KeyValuePair(name, name));
assertEquals(1, headers.getHeaders().size());
headers.setHeaders(new KeyValuePairSet());
assertEquals(0, headers.getHeaders().size());
}
Aggregations