DisplayLeadsService.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  * 
00024  */
00025 package org.openmobileis.examples.mycrm.terminal.services;
00026 
00027 import java.io.IOException;
00028 
00029 import javax.servlet.ServletException;
00030 import javax.servlet.http.HttpServletRequest;
00031 import javax.servlet.http.HttpServletResponse;
00032 
00033 import org.openmobileis.common.intl.IntlResourceManager;
00034 import org.openmobileis.common.util.exception.DatabaseException;
00035 import org.openmobileis.examples.mycrm.data.Account;
00036 import org.openmobileis.examples.mycrm.data.Leads;
00037 import org.openmobileis.examples.mycrm.data.fodb.AccountFactory;
00038 import org.openmobileis.examples.mycrm.data.fodb.LeadsFactory;
00039 import org.openmobileis.modules.common.data.LabelManager;
00040 import org.openmobileis.services.TemplateService;
00041 import org.openmobileis.services.common.ServiceManager;
00042 import org.openmobileis.services.navigation.NavigationBarService;
00043 
00044 import freemarker.template.SimpleScalar;
00045 import freemarker.template.TemplateModelRoot;
00046 
00055 public final class DisplayLeadsService extends TemplateService  implements NavigationBarService {
00056 
00060   public DisplayLeadsService() {
00061     super();
00062   }
00063 
00064   /*
00065    * (non-Javadoc)
00066    * 
00067    * @see org.openmobileis.services.TemplateService#runTemplate(javax.servlet.http.HttpServletRequest,
00068    *      javax.servlet.http.HttpServletResponse,
00069    *      freemarker.template.TemplateModelRoot)
00070    */
00071   public String runTemplate(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot templateData) throws ServletException, IOException {
00072     String leadid = req.getParameter("leadid");
00073     if (leadid != null) {
00074       try   {
00075         Leads lead = LeadsFactory.getManager().getLeads(leadid);
00076         if (lead != null)   {
00077           Account account = AccountFactory.getManager().getAccount(lead.getIdaccount());
00078           templateData.put("accountid", new SimpleScalar(account.getId()));
00079           templateData.put("accountname", new SimpleScalar(account.getName()));
00080           templateData.put("description", new SimpleScalar(lead.getDescription()));
00081           templateData.put("amount", new SimpleScalar(Integer.toString(lead.getAmount())));
00082           templateData.put("state", new SimpleScalar(LabelManager.getManager().getLabelWithIds(Integer.toString(lead.getState()), Leads.LEADS_STATE_LABEL_CATEGORY).getLabel()));
00083           java.text.SimpleDateFormat formater = new java.text.SimpleDateFormat("EEEEE dd MMMMM yyyy", java.util.Locale.FRANCE);
00084           templateData.put("date", new SimpleScalar(formater.format(lead.getCloseDate()).toString()));
00085         }
00086        
00087         templateData.put("leadid", new SimpleScalar(leadid));
00088       } catch (DatabaseException ex) {
00089         throw new ServletException(ex);
00090       }
00091     }
00092     return "crm/displaylead.htm";
00093   }
00094 
00095   /*
00096    * (non-Javadoc)
00097    * 
00098    * @see org.openmobileis.services.Service#getServiceUri()
00099    */
00100   public String getServiceUri() {
00101     return ServiceManager.getManager().getServiceBaseURI() + "/crm/displaylead";
00102   }
00103 
00104   /* 
00105    * Navigation bar methods
00106    */
00107 
00108   public String getNavigationBarLabel(HttpServletRequest req) {
00109     return IntlResourceManager.getManager().getLocalizedProperty("mycrm.displayleadservicenavbar", "Lead"); 
00110   }
00111 
00112   public boolean displayFormExitMessage() {
00113     return false;
00114   }
00115 
00116   public boolean displayRecursive() {
00117     return false;
00118   }
00119 
00120 }

Generated on Mon Jan 11 21:19:14 2010 for OpenMobileIS by  doxygen 1.5.4