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 javax.servlet.http.HttpServletRequest;
00028
00029 import org.openmobileis.common.intl.IntlResourceManager;
00030 import org.openmobileis.common.util.UniqueIdGenerator;
00031 import org.openmobileis.common.util.collection.Array;
00032 import org.openmobileis.common.util.exception.DatabaseException;
00033 import org.openmobileis.common.util.exception.ServiceException;
00034 import org.openmobileis.examples.mycrm.data.Account;
00035 import org.openmobileis.examples.mycrm.data.Contact;
00036 import org.openmobileis.examples.mycrm.data.fodb.AccountFactory;
00037 import org.openmobileis.modules.common.data.LabelManager;
00038 import org.openmobileis.services.SimpleEditService;
00039 import org.openmobileis.services.common.ServiceManager;
00040 import org.openmobileis.services.navigation.NavigationBarService;
00041 import org.openmobileis.services.util.TemplateUtils;
00042
00043 import freemarker.template.SimpleScalar;
00044 import freemarker.template.TemplateModelRoot;
00045
00056 public final class EditAccountService extends SimpleEditService implements NavigationBarService {
00060 public EditAccountService() {
00061 super();
00062 }
00063
00064
00065
00066
00067 protected void fillTemplateWithSessionData(Object sessionDatas, TemplateModelRoot templateData) throws ServiceException {
00068 Account data = (Account) sessionDatas;
00069
00070 templateData.put("accountid", new SimpleScalar(data.getId()));
00071 templateData.put("name", new SimpleScalar(data.getName()));
00072 templateData.put("address", new SimpleScalar(data.getAddress()));
00073 templateData.put("city", new SimpleScalar(data.getCity()));
00074
00075
00076 Array array = LabelManager.getManager().getLabelListForCategorie(Account.ACCOUNT_ACTIVITY_LABEL_CATEGORY);
00077 templateData.put("activities", TemplateUtils.fillFormPopUpWithLabel(array, data.getActivity()));
00078 }
00079
00080
00081
00082
00083 protected void storeSessionObjectInDB(Object sessionDatas, HttpServletRequest req, TemplateModelRoot templateData) throws ServiceException {
00084 Account data = (Account)sessionDatas;
00085
00086
00087 if (data.getName() == null || data.getName().trim().length() == 0) {
00088 this.setInputRequestParameterError(req, "Error :A account name must be entered.");
00089 return;
00090 }
00091
00092 try {
00093 AccountFactory.getManager().storeAccount(data);
00094 } catch (DatabaseException e) {
00095 throw new ServiceException(e);
00096 }
00097 }
00098
00099
00100
00101
00102 protected void fillSessionObjectWithRequestData(Object sessionDatas, HttpServletRequest req) throws ServiceException {
00103 Account data = (Account)sessionDatas;
00104
00105
00106
00107 String temp = (String)req.getParameter("name");
00108 if (temp != null) {
00109 data.setName(temp);
00110 }
00111 temp = (String)req.getParameter("address");
00112 if (temp != null) {
00113 data.setAddress(temp);
00114 }
00115 temp = (String)req.getParameter("city");
00116 if (temp != null) {
00117 data.setCity(temp);
00118 }
00119 temp = (String)req.getParameter("activity");
00120 if (temp != null) {
00121 data.setActivity(temp);
00122 }
00123 }
00124
00125
00126
00127
00128 protected String getSessionDatasName() {
00129 return "accountdata";
00130 }
00131
00132
00133
00134
00135 protected String getTemplateName() {
00136 return "crm/editaccount.htm";
00137 }
00138
00144 protected Object createSessionObject(HttpServletRequest req) throws ServiceException {
00145
00146
00147 String accountid = req.getParameter("accountid");
00148 Account account = null;
00149 if (accountid != null) {
00150 try {
00151 account = AccountFactory.getManager().getAccount(accountid);
00152 } catch (DatabaseException ex) {
00153 throw new ServiceException(ex);
00154 }
00155 }
00156 if (account == null) {
00157 account = new Account(UniqueIdGenerator.getManager().getNewStringID());
00158 }
00159 return account;
00160 }
00161
00166 protected String getDisplayServiceURI() {
00167 return "/crm/displayaccount";
00168 }
00169
00170 public String getServiceUri() {
00171 return ServiceManager.getManager().getServiceBaseURI() + "/crm/editaccount";
00172 }
00173
00174
00175
00176
00177 public String getNavigationBarLabel(HttpServletRequest req) {
00178 return IntlResourceManager.getManager().getLocalizedProperty("mycrm.editservicenavbar", "Edit");
00179 }
00180
00181 public boolean displayFormExitMessage() {
00182 return true;
00183 }
00184
00185 public boolean displayRecursive() {
00186 return false;
00187 }
00188
00189 }