use of org.apache.ofbiz.entity.config.model.EntityEcaReader in project ofbiz-framework by apache.
the class EntityEcaUtil method readConfig.
private static void readConfig(String entityEcaReaderName, Map<String, Map<String, List<EntityEcaRule>>> ecaCache) {
EntityEcaReader entityEcaReaderInfo = null;
try {
entityEcaReaderInfo = EntityConfig.getInstance().getEntityEcaReader(entityEcaReaderName);
} catch (GenericEntityConfException e) {
Debug.logError(e, "Exception thrown while getting entity-eca-reader config with name: " + entityEcaReaderName, module);
}
if (entityEcaReaderInfo == null) {
Debug.logError("BAD ERROR: Could not find entity-eca-reader config with name: " + entityEcaReaderName, module);
return;
}
List<Future<List<EntityEcaRule>>> futures = new LinkedList<Future<List<EntityEcaRule>>>();
for (Resource eecaResourceElement : entityEcaReaderInfo.getResourceList()) {
ResourceHandler handler = new MainResourceHandler(EntityConfig.ENTITY_ENGINE_XML_FILENAME, eecaResourceElement.getLoader(), eecaResourceElement.getLocation());
futures.add(ExecutionPool.GLOBAL_FORK_JOIN.submit(createEcaLoaderCallable(handler)));
}
// get all of the component resource eca stuff, ie specified in each ofbiz-component.xml file
for (ComponentConfig.EntityResourceInfo componentResourceInfo : ComponentConfig.getAllEntityResourceInfos("eca")) {
if (entityEcaReaderName.equals(componentResourceInfo.readerName)) {
futures.add(ExecutionPool.GLOBAL_FORK_JOIN.submit(createEcaLoaderCallable(componentResourceInfo.createResourceHandler())));
}
}
for (List<EntityEcaRule> oneFileRules : ExecutionPool.getAllFutures(futures)) {
for (EntityEcaRule rule : oneFileRules) {
String entityName = rule.getEntityName();
String eventName = rule.getEventName();
Map<String, List<EntityEcaRule>> eventMap = ecaCache.get(entityName);
List<EntityEcaRule> rules = null;
if (eventMap == null) {
eventMap = new HashMap<String, List<EntityEcaRule>>();
rules = new LinkedList<EntityEcaRule>();
ecaCache.put(entityName, eventMap);
eventMap.put(eventName, rules);
} else {
rules = eventMap.get(eventName);
if (rules == null) {
rules = new LinkedList<EntityEcaRule>();
eventMap.put(eventName, rules);
}
}
// This will prevent duplicate rule execution along with enabled/disabled eca workflow
if (rules.remove(rule)) {
Debug.logWarning("Duplicate Entity ECA [" + entityName + "]" + "for operation [ " + rule.getOperationName() + "] " + "on [" + eventName + "] ", module);
}
rules.add(rule);
}
}
}
Aggregations