use of io.s4.dispatcher.partitioner.KeyInfo.KeyPathElementIndex in project core by s4.
the class AbstractPE method setKeyValue.
private void setKeyValue(Object event, CompoundKeyInfo compoundKeyInfo) {
if (compoundKeyInfo == null) {
return;
}
keyValue = new ArrayList<Object>();
Schema schema = schemaContainer.getSchema(event.getClass());
// get the value for each keyInfo
for (KeyInfo keyInfo : compoundKeyInfo.getKeyInfoList()) {
Object value = null;
Object record = event;
List<?> list = null;
Property property = null;
for (KeyPathElement keyPathElement : keyInfo.getKeyPath()) {
if (keyPathElement instanceof KeyPathElementIndex) {
record = list.get(((KeyPathElementIndex) keyPathElement).getIndex());
schema = property.getComponentProperty().getSchema();
} else {
String keyPathElementName = ((KeyPathElementName) keyPathElement).getKeyName();
property = schema.getProperties().get(keyPathElementName);
value = null;
try {
value = property.getGetterMethod().invoke(record);
} catch (Exception e) {
Logger.getLogger("s4").error(e);
return;
}
if (value == null) {
Logger.getLogger("s4").error("Value for " + keyPathElementName + " is null!");
return;
}
if (property.getType().isPrimitive() || property.isNumber() || property.getType().equals(String.class)) {
keyValue.add(value);
if (saveKeyRecord) {
if (keyRecord == null) {
keyRecord = new ArrayList<Object>();
}
keyRecord.add(record);
}
continue;
} else if (property.isList()) {
try {
list = (List) property.getGetterMethod().invoke(record);
} catch (Exception e) {
Logger.getLogger("s4").error(e);
return;
}
} else {
try {
record = property.getGetterMethod().invoke(record);
} catch (Exception e) {
Logger.getLogger("s4").error(e);
return;
}
schema = property.getSchema();
}
}
}
}
}
Aggregations