00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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.collection.Array;
00035 import org.openmobileis.common.util.exception.DatabaseException;
00036 import org.openmobileis.common.util.log.LogManager;
00037 import org.openmobileis.examples.mycrm.data.Account;
00038 import org.openmobileis.examples.mycrm.data.Contact;
00039 import org.openmobileis.examples.mycrm.data.Report;
00040 import org.openmobileis.examples.mycrm.data.fodb.AccountFactory;
00041 import org.openmobileis.modules.common.data.LabelManager;
00042 import org.openmobileis.modules.common.data.TerminalUser;
00043 import org.openmobileis.modules.common.data.TerminalUserManager;
00044 import org.openmobileis.services.TemplateService;
00045 import org.openmobileis.services.common.ServiceManager;
00046 import org.openmobileis.services.navigation.NavigationBarService;
00047 import org.openmobileis.services.util.TemplateUtils;
00048
00049 import freemarker.template.SimpleHash;
00050 import freemarker.template.SimpleList;
00051 import freemarker.template.SimpleScalar;
00052 import freemarker.template.TemplateModelRoot;
00053
00062 public final class DisplayReportService extends TemplateService implements NavigationBarService {
00063
00067 public DisplayReportService() {
00068 super();
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078 public String runTemplate(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot templateData) throws ServletException, IOException {
00079 String accountid = req.getParameter("accountid");
00080 String contactid = req.getParameter("contactid");
00081 String reportid = req.getParameter("reportid");
00082 if (accountid != null && contactid != null && reportid!=null) {
00083 try {
00084 Account account = AccountFactory.getManager().getAccount(accountid);
00085 Contact contact = account.getContactById(contactid);
00086
00087 templateData.put("accountid", new SimpleScalar(accountid));
00088 templateData.put("contactid", new SimpleScalar(contactid));
00089 templateData.put("reportid", new SimpleScalar(reportid));
00090
00091 Report report = contact.getReportById(reportid);
00092 if (report != null) {
00093 templateData.put("description", new SimpleScalar(report.getDescription()));
00094 templateData.put("action", new SimpleScalar(LabelManager.getManager().getLabelWithIds(Integer.toString(report.getAction()), Report.REPORT_ACTION_LABEL_CATEGORY).getLabel()));
00095 java.text.SimpleDateFormat formater = new java.text.SimpleDateFormat("EEEEE dd MMMMM yyyy", java.util.Locale.FRANCE);
00096 templateData.put("date", new SimpleScalar(formater.format(report.getReportDate()).toString()));
00097 TerminalUser user = TerminalUserManager.getManager().getTerminalUser(report.getTerminalUserId());
00098 if (user != null) {
00099 templateData.put("user", new SimpleScalar(user.getName()));
00100 }
00101 }
00102
00103 } catch (DatabaseException ex) {
00104 throw new ServletException(ex);
00105 }
00106 }
00107 return "crm/displayreport.htm";
00108 }
00109
00110
00111
00112
00113
00114
00115 public String getServiceUri() {
00116 return ServiceManager.getManager().getServiceBaseURI() + "/crm/displayreport";
00117 }
00118
00119
00120
00121
00122
00123 public String getNavigationBarLabel(HttpServletRequest req) {
00124 return IntlResourceManager.getManager().getLocalizedProperty("mycrm.displayreportservicenavbar", "Report");
00125 }
00126
00127 public boolean displayFormExitMessage() {
00128 return false;
00129 }
00130
00131 public boolean displayRecursive() {
00132 return false;
00133 }
00134
00135 }