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.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
00069
00070
00071
00072
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
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
00113
00114
00115
00116 public String getServiceUri() {
00117 return ServiceManager.getManager().getServiceBaseURI() + "/crm/displaycontact";
00118 }
00119
00120
00121
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 }