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