1 22 package org.ofbiz.order.quote; 23 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Locale ; 28 import java.util.Map ; 29 30 import javolution.util.FastMap; 31 32 import org.ofbiz.base.util.Debug; 33 import org.ofbiz.base.util.GeneralException; 34 import org.ofbiz.base.util.UtilMisc; 35 import org.ofbiz.base.util.UtilProperties; 36 import org.ofbiz.base.util.UtilValidate; 37 import org.ofbiz.entity.GenericDelegator; 38 import org.ofbiz.entity.GenericEntityException; 39 import org.ofbiz.entity.GenericValue; 40 import org.ofbiz.party.party.PartyWorker; 41 import org.ofbiz.service.DispatchContext; 42 import org.ofbiz.service.GenericServiceException; 43 import org.ofbiz.service.LocalDispatcher; 44 import org.ofbiz.service.ServiceUtil; 45 46 52 53 public class QuoteServices { 54 55 public static final String module = QuoteServices.class.getName(); 56 public static final String resource = "OrderUiLabels"; 57 public static final String resource_error = "OrderErrorUiLabels"; 58 59 public static Map sendQuoteReportMail(DispatchContext dctx, Map context) { 60 LocalDispatcher dispatcher = dctx.getDispatcher(); 61 GenericDelegator delegator = dctx.getDelegator(); 62 GenericValue userLogin = (GenericValue) context.get("userLogin"); 63 Locale locale = (Locale ) context.get("locale"); 64 65 String emailType = (String ) context.get("emailType"); 66 String quoteId = (String ) context.get("quoteId"); 67 String sendTo = (String ) context.get("sendTo"); 68 String sendCc = (String ) context.get("sendCc"); 69 String note = (String ) context.get("note"); 70 71 Map sendMap = FastMap.newInstance(); 73 74 GenericValue quote = null; 76 try { 77 quote = delegator.findByPrimaryKey("Quote", UtilMisc.toMap("quoteId", quoteId)); 78 } catch (GenericEntityException e) { 79 Debug.logError(e, "Problem getting Quote", module); 80 } 81 82 if (quote == null) { 83 return ServiceUtil.returnFailure("Could not find Quote with ID [" + quoteId + "]"); 84 } 85 86 GenericValue productStoreEmail = null; 87 try { 88 productStoreEmail = delegator.findByPrimaryKey("ProductStoreEmailSetting", UtilMisc.toMap("productStoreId", quote.get("productStoreId"), "emailType", emailType)); 89 } catch (GenericEntityException e) { 90 Debug.logError(e, "Problem getting the ProductStoreEmailSetting for productStoreId=" + quote.get("productStoreId") + " and emailType=" + emailType, module); 91 } 92 if (productStoreEmail == null) { 93 return ServiceUtil.returnFailure("No valid email setting for store with productStoreId=" + quote.get("productStoreId") + " and emailType=" + emailType); 94 } 95 String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation"); 96 if (UtilValidate.isEmpty(bodyScreenLocation)) { 97 return ServiceUtil.returnFailure("No valid bodyScreenLocation in email setting for store with productStoreId=" + quote.get("productStoreId") + " and emailType=" + emailType); 98 } 99 sendMap.put("bodyScreenUri", bodyScreenLocation); 100 String xslfoAttachScreenLocation = productStoreEmail.getString("xslfoAttachScreenLocation"); 101 sendMap.put("xslfoAttachScreenLocation", xslfoAttachScreenLocation); 102 103 if ((sendTo == null) || !UtilValidate.isEmail(sendTo)) { 104 return ServiceUtil.returnError("No sendTo email address found"); 105 } 106 107 Map bodyParameters = UtilMisc.toMap("quoteId", quoteId, "userLogin", userLogin, "locale", locale); 108 bodyParameters.put("note", note); 109 bodyParameters.put("partyId", quote.getString("partyId")); sendMap.put("bodyParameters", bodyParameters); 111 sendMap.put("userLogin", userLogin); 112 113 String subjectString = productStoreEmail.getString("subject"); 114 sendMap.put("subject", subjectString); 115 116 sendMap.put("contentType", productStoreEmail.get("contentType")); 117 sendMap.put("sendFrom", productStoreEmail.get("fromAddress")); 118 sendMap.put("sendCc", productStoreEmail.get("ccAddress")); 119 sendMap.put("sendBcc", productStoreEmail.get("bccAddress")); 120 sendMap.put("sendTo", sendTo); 121 if ((sendCc != null) && UtilValidate.isEmail(sendCc)) { 122 sendMap.put("sendCc", sendCc); 123 } else { 124 sendMap.put("sendCc", productStoreEmail.get("ccAddress")); 125 } 126 127 Map sendResp = null; 129 try { 130 sendResp = dispatcher.runSync("sendMailFromScreen", sendMap); 131 } catch (Exception e) { 132 Debug.logError(e, module); 133 return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderServiceExceptionSeeLogs",locale)); 134 } 135 136 if (sendResp != null && !ServiceUtil.isError(sendResp)) { 138 sendResp.put("emailType", emailType); 139 } 140 return sendResp; 141 } 142 143 } 144 | Popular Tags |