1 25 package org.ofbiz.service.mail; 26 27 import java.util.Map ; 28 29 import org.ofbiz.service.GenericServiceException; 30 import org.ofbiz.service.LocalDispatcher; 31 import org.ofbiz.service.ServiceUtil; 32 import org.ofbiz.base.util.UtilMisc; 33 import org.ofbiz.base.util.Debug; 34 import org.ofbiz.entity.GenericValue; 35 36 import org.w3c.dom.Element ; 37 38 44 public class ServiceMcaAction implements java.io.Serializable { 45 46 public static final String module = ServiceMcaAction.class.getName(); 47 48 protected String serviceName = null; 49 protected String serviceMode = null; 50 protected String runAsUser = null; 51 protected boolean persist = false; 52 53 protected ServiceMcaAction() { } 54 55 protected ServiceMcaAction(Element action) { 56 this.serviceName = action.getAttribute("service"); 57 this.serviceMode = action.getAttribute("mode"); 58 this.runAsUser = action.getAttribute("runAsUser"); 59 this.persist = "true".equals(action.getAttribute("persist")); 60 } 61 62 public boolean runAction(LocalDispatcher dispatcher, MimeMessageWrapper messageWrapper, GenericValue userLogin) throws GenericServiceException { 63 Map serviceContext = UtilMisc.toMap("messageWrapper", messageWrapper, "userLogin", userLogin); 64 serviceContext.put("userLogin", ServiceUtil.getUserLogin(dispatcher.getDispatchContext(), serviceContext, runAsUser)); 65 66 if (serviceMode.equals("sync")) { 67 Map result = dispatcher.runSync(serviceName, serviceContext); 68 if (ServiceUtil.isError(result)) { 69 Debug.logError(ServiceUtil.getErrorMessage(result), module); 70 return false; 71 } else { 72 return true; 73 } 74 } else if (serviceMode.equals("async")) { 75 dispatcher.runAsync(serviceName, serviceContext, persist); 76 return true; 77 } else { 78 Debug.logError("Invalid service mode [" + serviceMode + "] unable to invoke MCA action (" + serviceName + ").", module); 79 return false; 80 } 81 } 82 } 83 | Popular Tags |