KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > order > quote > QuoteServices


1 /*
2  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
20  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */

22 package org.ofbiz.order.quote;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Locale JavaDoc;
28 import java.util.Map JavaDoc;
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 /**
47  * Quote Services
48  *
49  * @author <a HREF="mailto:tiz@sastau.it">Jacopo Cappellato</a>
50  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
51  */

52
53 public class QuoteServices {
54
55     public static final String JavaDoc module = QuoteServices.class.getName();
56     public static final String JavaDoc resource = "OrderUiLabels";
57     public static final String JavaDoc resource_error = "OrderErrorUiLabels";
58
59     public static Map JavaDoc sendQuoteReportMail(DispatchContext dctx, Map JavaDoc context) {
60         LocalDispatcher dispatcher = dctx.getDispatcher();
61         GenericDelegator delegator = dctx.getDelegator();
62         GenericValue userLogin = (GenericValue) context.get("userLogin");
63         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
64
65         String JavaDoc emailType = (String JavaDoc) context.get("emailType");
66         String JavaDoc quoteId = (String JavaDoc) context.get("quoteId");
67         String JavaDoc sendTo = (String JavaDoc) context.get("sendTo");
68         String JavaDoc sendCc = (String JavaDoc) context.get("sendCc");
69         String JavaDoc note = (String JavaDoc) context.get("note");
70
71         // prepare the order information
72
Map JavaDoc sendMap = FastMap.newInstance();
73
74         // get the quote and store
75
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 JavaDoc 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 JavaDoc 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 JavaDoc bodyParameters = UtilMisc.toMap("quoteId", quoteId, "userLogin", userLogin, "locale", locale);
108         bodyParameters.put("note", note);
109         bodyParameters.put("partyId", quote.getString("partyId")); // This is set to trigger the "storeEmailAsCommunication" seca
110
sendMap.put("bodyParameters", bodyParameters);
111         sendMap.put("userLogin", userLogin);
112
113         String JavaDoc 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         // send the notification
128
Map JavaDoc sendResp = null;
129         try {
130             sendResp = dispatcher.runSync("sendMailFromScreen", sendMap);
131         } catch (Exception JavaDoc e) {
132             Debug.logError(e, module);
133             return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderServiceExceptionSeeLogs",locale));
134         }
135
136         // check for errors
137
if (sendResp != null && !ServiceUtil.isError(sendResp)) {
138             sendResp.put("emailType", emailType);
139         }
140         return sendResp;
141     }
142
143 }
144
Popular Tags