DisplayReportService.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.Contact;
00037 import org.openmobileis.examples.mycrm.data.Report;
00038 import org.openmobileis.examples.mycrm.data.fodb.AccountFactory;
00039 import org.openmobileis.modules.common.data.LabelManager;
00040 import org.openmobileis.modules.common.data.TerminalUser;
00041 import org.openmobileis.modules.common.data.TerminalUserManager;
00042 import org.openmobileis.services.TemplateService;
00043 import org.openmobileis.services.common.ServiceManager;
00044 import org.openmobileis.services.navigation.NavigationBarService;
00045 
00046 import freemarker.template.SimpleScalar;
00047 import freemarker.template.TemplateModelRoot;
00048 
00057 public final class DisplayReportService extends TemplateService  implements NavigationBarService {
00058 
00062   public DisplayReportService() {
00063     super();
00064   }
00065 
00066   /*
00067    * (non-Javadoc)
00068    * 
00069    * @see org.openmobileis.services.TemplateService#runTemplate(javax.servlet.http.HttpServletRequest,
00070    *      javax.servlet.http.HttpServletResponse,
00071    *      freemarker.template.TemplateModelRoot)
00072    */
00073   public String runTemplate(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot templateData) throws ServletException, IOException {
00074     String accountid = req.getParameter("accountid");
00075     String contactid = req.getParameter("contactid");
00076     String reportid = req.getParameter("reportid");
00077     if (accountid != null && contactid != null && reportid!=null) {
00078       try   {
00079         Account account = AccountFactory.getManager().getAccount(accountid);
00080         Contact contact = account.getContactById(contactid);
00081         
00082         templateData.put("accountid", new SimpleScalar(accountid));
00083         templateData.put("contactid", new SimpleScalar(contactid));
00084         templateData.put("reportid", new SimpleScalar(reportid));
00085         
00086         Report  report = contact.getReportById(reportid);
00087         if (report != null) {        
00088           templateData.put("description", new SimpleScalar(report.getDescription()));
00089           templateData.put("action", new SimpleScalar(LabelManager.getManager().getLabelWithIds(Integer.toString(report.getAction()), Report.REPORT_ACTION_LABEL_CATEGORY).getLabel()));
00090           java.text.SimpleDateFormat formater = new java.text.SimpleDateFormat("EEEEE dd MMMMM yyyy", java.util.Locale.FRANCE);
00091           templateData.put("date", new SimpleScalar(formater.format(report.getReportDate()).toString()));
00092           TerminalUser user = TerminalUserManager.getManager().getTerminalUser(report.getTerminalUserId());
00093           if (user != null) {
00094             templateData.put("user", new SimpleScalar(user.getName()));
00095           }
00096        }
00097         
00098       } catch (DatabaseException ex) {
00099         throw new ServletException(ex);
00100       }
00101     }
00102     return "crm/displayreport.htm";
00103   }
00104 
00105   /*
00106    * (non-Javadoc)
00107    * 
00108    * @see org.openmobileis.services.Service#getServiceUri()
00109    */
00110   public String getServiceUri() {
00111     return ServiceManager.getManager().getServiceBaseURI() + "/crm/displayreport";
00112   }
00113 
00114   /* 
00115    * Navigation bar methods
00116    */
00117 
00118   public String getNavigationBarLabel(HttpServletRequest req) {
00119     return IntlResourceManager.getManager().getLocalizedProperty("mycrm.displayreportservicenavbar", "Report");
00120   }
00121 
00122   public boolean displayFormExitMessage() {
00123     return false;
00124   }
00125 
00126   public boolean displayRecursive() {
00127     return false;
00128   }
00129 
00130 }

Generated on Tue May 22 23:01:08 2007 for OpenMobileIS by  doxygen 1.5.1-p1