1 18 package org.ofbiz.order.order; 19 20 import java.io.IOException ; 21 import java.io.OutputStream ; 22 import java.util.List ; 23 24 import javax.servlet.ServletContext ; 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 27 import javax.servlet.http.HttpSession ; 28 29 import org.ofbiz.base.util.Debug; 30 import org.ofbiz.base.util.GeneralException; 31 import org.ofbiz.base.util.UtilHttp; 32 import org.ofbiz.base.util.UtilMisc; 33 import org.ofbiz.content.data.DataResourceWorker; 34 import org.ofbiz.entity.GenericDelegator; 35 import org.ofbiz.entity.GenericEntityException; 36 import org.ofbiz.entity.GenericValue; 37 38 43 public class OrderEvents { 44 45 public static final String module = OrderEvents.class.getName(); 46 47 public static String downloadDigitalProduct(HttpServletRequest request, HttpServletResponse response) { 48 HttpSession session = request.getSession(); 49 ServletContext application = session.getServletContext(); 50 GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); 51 GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); 52 String dataResourceId = request.getParameter("dataResourceId"); 53 54 try { 55 List orderRoleAndProductContentInfoList = delegator.findByAnd("OrderRoleAndProductContentInfo", 57 UtilMisc.toMap("partyId", userLogin.get("partyId"), "dataResourceId", dataResourceId, "productContentTypeId", "DIGITAL_DOWNLOAD", "statusId", "ITEM_COMPLETED")); 58 59 if (orderRoleAndProductContentInfoList.size() == 0) { 60 request.setAttribute("_ERROR_MESSAGE_", "No record of purchase for digital download found (dataResourceId=[" + dataResourceId + "])."); 61 return "error"; 62 } 63 64 GenericValue orderRoleAndProductContentInfo = (GenericValue) orderRoleAndProductContentInfoList.get(0); 65 66 68 if (orderRoleAndProductContentInfo.getString("mimeTypeId") != null) { 69 response.setContentType(orderRoleAndProductContentInfo.getString("mimeTypeId")); 70 } 71 OutputStream os = response.getOutputStream(); 72 DataResourceWorker.streamDataResource(os, delegator, dataResourceId, "", application.getInitParameter("webSiteId"), UtilHttp.getLocale(request), application.getRealPath("/")); 73 os.flush(); 74 } catch (GenericEntityException e) { 75 String errMsg = "Error downloading digital product content: " + e.toString(); 76 Debug.logError(e, errMsg, module); 77 request.setAttribute("_ERROR_MESSAGE_", errMsg); 78 return "error"; 79 } catch (GeneralException e) { 80 String errMsg = "Error downloading digital product content: " + e.toString(); 81 Debug.logError(e, errMsg, module); 82 request.setAttribute("_ERROR_MESSAGE_", errMsg); 83 return "error"; 84 } catch (IOException e) { 85 String errMsg = "Error downloading digital product content: " + e.toString(); 86 Debug.logError(e, errMsg, module); 87 request.setAttribute("_ERROR_MESSAGE_", errMsg); 88 return "error"; 89 } 90 91 return "success"; 92 } 93 } 94 | Popular Tags |