Search in sources :

Example 1 with EntityEcaReader

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);
        }
    }
}
Also used : GenericEntityConfException(org.apache.ofbiz.entity.GenericEntityConfException) Resource(org.apache.ofbiz.entity.config.model.Resource) ResourceHandler(org.apache.ofbiz.base.config.ResourceHandler) MainResourceHandler(org.apache.ofbiz.base.config.MainResourceHandler) LinkedList(java.util.LinkedList) EntityEcaReader(org.apache.ofbiz.entity.config.model.EntityEcaReader) MainResourceHandler(org.apache.ofbiz.base.config.MainResourceHandler) ComponentConfig(org.apache.ofbiz.base.component.ComponentConfig) Future(java.util.concurrent.Future) List(java.util.List) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 ComponentConfig (org.apache.ofbiz.base.component.ComponentConfig)1 MainResourceHandler (org.apache.ofbiz.base.config.MainResourceHandler)1 ResourceHandler (org.apache.ofbiz.base.config.ResourceHandler)1 GenericEntityConfException (org.apache.ofbiz.entity.GenericEntityConfException)1 EntityEcaReader (org.apache.ofbiz.entity.config.model.EntityEcaReader)1 Resource (org.apache.ofbiz.entity.config.model.Resource)1