For a REST API request, I parse the JSON to get a List of recipes.
Each recipe involves multiple fields that need to be resolved to a value using different types of operations. Each field value is generated by an operation like querying DB, external REST calls, sequence number generation. A post operation will be performed on the generated value.
For example, one recipe can be
Field1+Field2+Field3
Field1 => resolved by DB operation. Then do list of post operations which would be java String manipulation. Field2 => Invoke REST call. Then do list of post operations which would be java String manipulation. Field3, to be resolved after field1 and field2 => Invoke sequence number generation based on field1 value and field2 value
I would like to derive the list of operations from the JSON and execute them in a generic way irrespective of the format of incoming JSON. Other JSON with completely different JSON would also be parsed to invoke same set of operations.
abstract class Operation {
factoryCreationMethod(operationType) {
if (operationType.equals(DB)) {
return new DbOperation();
}
}
public final doOperationTemplate() {
populateOperation(Map<String, Object>);
PerformOperation();
performPostOp(Ordered<String, String>);
// postops would be trim n chars from beg or end
}
}
Class DbOperation extends Operation {
String query = null;
SimpleBindings params = null;
@Override
populateOperation(Map<String, Object> listObjs) {
// perform op specific init
}
// implement performOperation and performPostOp
}
class genericRestTemplate extends Operation {
}
What is the best way to design this list of generic operations and post operations? At this moment, I'm going to perform operations sequentially.
Aucun commentaire:
Enregistrer un commentaire