DisplayContactService.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.util.collection.Array;
00034 import org.openmobileis.common.util.exception.DatabaseException;
00035 import org.openmobileis.common.util.log.LogManager;
00036 import org.openmobileis.examples.mycrm.data.Account;
00037 import org.openmobileis.examples.mycrm.data.Contact;
00038 import org.openmobileis.examples.mycrm.data.Report;
00039 import org.openmobileis.examples.mycrm.data.fodb.AccountFactory;
00040 import org.openmobileis.modules.common.data.LabelManager;
00041 import org.openmobileis.services.TemplateService;
00042 import org.openmobileis.services.common.ServiceManager;
00043 import org.openmobileis.services.navigation.NavigationBarService;
00044 
00045 import freemarker.template.SimpleHash;
00046 import freemarker.template.SimpleList;
00047 import freemarker.template.SimpleScalar;
00048 import freemarker.template.TemplateModelRoot;
00049 
00058 public final class DisplayContactService extends TemplateService  implements NavigationBarService {
00059 
00063   public DisplayContactService() {
00064     super();
00065   }
00066 
00067   /*
00068    * (non-Javadoc)
00069    * 
00070    * @see org.openmobileis.services.TemplateService#runTemplate(javax.servlet.http.HttpServletRequest,
00071    *      javax.servlet.http.HttpServletResponse,
00072    *      freemarker.template.TemplateModelRoot)
00073    */
00074   public String runTemplate(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot templateData) throws ServletException, IOException {
00075     String accountid = req.getParameter("accountid");
00076     String contactid = req.getParameter("contactid");
00077     if (accountid != null && contactid != null) {
00078       try   {
00079         Account account = AccountFactory.getManager().getAccount(accountid);
00080         Contact contact = account.getContactById(contactid);
00081         templateData.put("name", new SimpleScalar(account.getName()));
00082         templateData.put("firstname", new SimpleScalar(contact.getFirstname()));
00083         templateData.put("lastname", new SimpleScalar(contact.getLastname()));
00084         templateData.put("function", new SimpleScalar(LabelManager.getManager().getLabelWithIds(Integer.toString(contact.getFunction()), Contact.CONTACT_FUNCTION_LABEL_CATEGORY).getLabel()));
00085        
00086         
00087         Array reportslist = contact.getAllReports();
00088         
00089         // construct the SimpleList to fill HTML array (see the template).
00090         SimpleList showList = new SimpleList();
00091         SimpleHash dataStruct;
00092         java.text.SimpleDateFormat formater = new java.text.SimpleDateFormat("EEEEE dd MMMMM yyyy", java.util.Locale.FRANCE);
00093         for (int i = 0; i < reportslist.size(); i++) {
00094           dataStruct = new SimpleHash();
00095           Report report = (Report)reportslist.get(i);
00096           dataStruct.put("id", report.getId());
00097           dataStruct.put("action",  LabelManager.getManager().getLabelWithIds(Integer.toString(report.getAction()), Report.REPORT_ACTION_LABEL_CATEGORY).getLabel());
00098           dataStruct.put("date", new SimpleScalar(formater.format(report.getReportDate()).toString()));         
00099           showList.add(dataStruct);
00100         }
00101         templateData.put("reportlist", showList);
00102         templateData.put("accountid", new SimpleScalar(accountid));
00103         templateData.put("contactid", new SimpleScalar(contactid));
00104       } catch (DatabaseException ex) {
00105         throw new ServletException(ex);
00106       }
00107     }
00108     return "crm/displaycontact.htm";
00109   }
00110 
00111   /*
00112    * (non-Javadoc)
00113    * 
00114    * @see org.openmobileis.services.Service#getServiceUri()
00115    */
00116   public String getServiceUri() {
00117     return ServiceManager.getManager().getServiceBaseURI() + "/crm/displaycontact";
00118   }
00119 
00120   /* 
00121    * Navigation bar methods
00122    */
00123 
00124   public String getNavigationBarLabel(HttpServletRequest req) {
00125     String accountid = req.getParameter("accountid");
00126     String contactid = req.getParameter("contactid");
00127     if (accountid != null && contactid != null) {
00128       try   {
00129         Account account = AccountFactory.getManager().getAccount(accountid);
00130         Contact contact = account.getContactById(contactid);
00131         return contact.getLastname();
00132       } catch (Throwable ex)    {
00133         LogManager.traceError(0, ex);
00134       }
00135     }
00136     return "Contact";
00137   }
00138 
00139   public boolean displayFormExitMessage() {
00140     return false;
00141   }
00142 
00143   public boolean displayRecursive() {
00144     return false;
00145   }
00146 
00147 }

Generated on Mon Dec 4 11:03:26 2006 for OpenMobileIS by  doxygen 1.5.1-p1