1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
| package org.mifos.application.customer.struts.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.mifos.application.customer.business.CustomerBO;
import org.mifos.application.customer.business.service.CustomerBusinessService;
import org.mifos.application.customer.center.util.helpers.CenterConstants;
import org.mifos.application.customer.exceptions.CustomerException;
import org.mifos.application.customer.struts.actionforms.CustSearchActionForm;
import org.mifos.application.customer.util.helpers.CustomerConstants;
import org.mifos.application.customer.util.helpers.CustomerSearchConstants;
import org.mifos.application.office.business.service.OfficeBusinessService;
import org.mifos.application.office.util.helpers.OfficeLevel;
import org.mifos.application.personnel.business.PersonnelBO;
import org.mifos.application.personnel.business.service.PersonnelBusinessService;
import org.mifos.application.personnel.util.helpers.PersonnelLevel;
import org.mifos.application.util.helpers.ActionForwards;
import org.mifos.framework.business.service.BusinessService;
import org.mifos.framework.business.service.ServiceFactory;
import org.mifos.framework.components.configuration.business.Configuration;
import org.mifos.framework.exceptions.ServiceException;
import org.mifos.framework.security.util.ActionSecurity;
import org.mifos.framework.security.util.UserContext;
import org.mifos.framework.security.util.resources.SecurityConstants;
import org.mifos.framework.struts.action.SearchAction;
import org.mifos.framework.util.helpers.BusinessServiceName;
import org.mifos.framework.util.helpers.Constants;
import org.mifos.framework.util.helpers.SessionUtils;
import org.mifos.framework.util.helpers.StringUtils;
import org.mifos.framework.util.helpers.TransactionDemarcate;
import org.mifos.config.ClientRules;
public class CustSearchAction extends SearchAction {
public static ActionSecurity getSecurity() {
ActionSecurity security = new ActionSecurity("custSearchAction");
security.allow("loadSearch", SecurityConstants.VIEW);
security.allow("search", SecurityConstants.VIEW);
security.allow("load", SecurityConstants.VIEW);
security.allow("loadMainSearch", SecurityConstants.VIEW);
security.allow("mainSearch", SecurityConstants.VIEW);
security.allow("getHomePage", SecurityConstants.VIEW);
security.allow("loadAllBranches", SecurityConstants.VIEW);
security.allow("get", SecurityConstants.VIEW);
security.allow("preview", SecurityConstants.VIEW);
security.allow("getOfficeHomePage", SecurityConstants.VIEW);
return security;
}
@TransactionDemarcate(joinToken = true)
public ActionForward get(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
CustSearchActionForm actionForm = (CustSearchActionForm) form;
if (actionForm.getLoanOfficerId() != null) {
loadLoanOfficer(
new PersonnelBusinessService()
.getPersonnel(getShortValue(actionForm
.getLoanOfficerId())), request);
}
String officeName = null;
if (actionForm.getOfficeId() != null
&& !actionForm.getOfficeId().equals(""))
officeName = new OfficeBusinessService().getOffice(
getShortValue(actionForm.getOfficeId())).getOfficeName();
else
officeName = new OfficeBusinessService().getOffice(
getUserContext(request).getBranchId()).getOfficeName();
SessionUtils.setAttribute(CustomerSearchConstants.OFFICE, officeName,
request);
SessionUtils.setAttribute("isCenterHeirarchyExists", ClientRules.getCenterHierarchyExists(), request);
SessionUtils.setAttribute(CustomerSearchConstants.LOADFORWARD,
CustomerSearchConstants.LOADFORWARDNONLOANOFFICER, request);
return mapping
.findForward(CustomerSearchConstants.LOADFORWARDLOANOFFICER_SUCCESS);
}
@TransactionDemarcate(conditionToken = true)
public ActionForward preview(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
CustSearchActionForm actionForm = (CustSearchActionForm) form;
if (actionForm.getOfficeId() != null) {
List<PersonnelBO> personnelList = new PersonnelBusinessService()
.getActiveLoanOfficersUnderOffice(getShortValue(actionForm
.getOfficeId()));
SessionUtils.setCollectionAttribute(CustomerSearchConstants.LOANOFFICERSLIST,
personnelList, request);
}
String officeName = null;
if (actionForm.getOfficeId() != null
&& !actionForm.getOfficeId().equals(""))
officeName = new OfficeBusinessService().getOffice(
getShortValue(actionForm.getOfficeId())).getOfficeName();
else
officeName = new OfficeBusinessService().getOffice(
getUserContext(request).getBranchId()).getOfficeName();
SessionUtils.setAttribute(CustomerSearchConstants.OFFICE, officeName,
request);
SessionUtils.setAttribute("isCenterHeirarchyExists", ClientRules.getCenterHierarchyExists(), request);
SessionUtils.setAttribute(CustomerSearchConstants.LOADFORWARD,
CustomerSearchConstants.LOADFORWARDNONLOANOFFICER, request);
return mapping
.findForward(CustomerSearchConstants.LOADFORWARDNONLOANOFFICER_SUCCESS);
}
@TransactionDemarcate(saveToken = true)
public ActionForward loadAllBranches(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
CustSearchActionForm actionForm = (CustSearchActionForm) form;
actionForm.setOfficeId("0");
UserContext userContext = (UserContext) SessionUtils.getAttribute(
Constants.USERCONTEXT, request.getSession());
SessionUtils.setAttribute("isCenterHeirarchyExists", ClientRules.getCenterHierarchyExists(), request);
loadMasterData(userContext.getId(), request, actionForm);
return mapping
.findForward(CustomerSearchConstants.LOADALLBRANCHES_SUCCESS);
}
@TransactionDemarcate(saveToken = true)
public ActionForward getHomePage(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
CustSearchActionForm actionForm = (CustSearchActionForm) form;
actionForm.setSearchString(null);
cleanUpSearch(request);
UserContext userContext = (UserContext) SessionUtils.getAttribute(
Constants.USERCONTEXT, request.getSession());
SessionUtils.setAttribute("isCenterHeirarchyExists", ClientRules.getCenterHierarchyExists(), request);
loadMasterData(userContext.getId(), request, actionForm);
return mapping.findForward(CustomerConstants.GETHOMEPAGE_SUCCESS);
}
@TransactionDemarcate(saveToken = true)
public ActionForward loadSearch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
CustSearchActionForm actionForm = (CustSearchActionForm) form;
actionForm.setSearchString(null);
if (request.getParameter("perspective") != null) {
request.setAttribute("perspective", request.getParameter("perspective"));
}
cleanUpSearch(request);
return mapping
.findForward(ActionForwards.loadSearch_success.toString());
}
@TransactionDemarcate(saveToken = true)
public ActionForward loadMainSearch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String forward = null;
CustSearchActionForm actionForm = (CustSearchActionForm) form;
actionForm.setSearchString(null);
actionForm.setOfficeId("0");
cleanUpSearch(request);
UserContext userContext = getUserContext(request);
SessionUtils.setAttribute("isCenterHeirarchyExists", ClientRules.getCenterHierarchyExists(), request);
forward = loadMasterData(userContext.getId(), request, actionForm);
return mapping.findForward(forward);
}
@TransactionDemarcate(joinToken = true)
public ActionForward mainSearch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
CustSearchActionForm actionForm = (CustSearchActionForm) form;
Short officeId = getShortValue(actionForm.getOfficeId());
String searchString = actionForm.getSearchString();
UserContext userContext = (UserContext) SessionUtils.getAttribute(
Constants.USERCONTEXT, request.getSession());
super.search(mapping, form, request, response);
if (searchString == null || searchString.equals("")) {
ActionErrors errors = new ActionErrors();
errors.add(CustomerSearchConstants.NAMEMANDATORYEXCEPTION,
new ActionMessage(
CustomerSearchConstants.NAMEMANDATORYEXCEPTION));
request.setAttribute(Globals.ERROR_KEY, errors);
return mapping.findForward(ActionForwards.mainSearch_success
.toString());
}
if (officeId != null && officeId != 0)
addSeachValues(searchString, officeId.toString(),
new OfficeBusinessService().getOffice(officeId)
.getOfficeName(), request);
else
addSeachValues(searchString, officeId.toString(),
new OfficeBusinessService().getOffice(
userContext.getBranchId()).getOfficeName(), request);
searchString = StringUtils.normalizeSearchString(searchString);
if (searchString.equals(""))
throw new CustomerException(
CustomerSearchConstants.NAMEMANDATORYEXCEPTION);
SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS,
getCustomerBusinessService().search(searchString, officeId,
userContext.getId(), userContext.getBranchId()),
request);
return mapping
.findForward(ActionForwards.mainSearch_success.toString());
}
@TransactionDemarcate(conditionToken = true)
public ActionForward getOfficeHomePage(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Short loggedUserLevel = getUserContext(request).getLevelId();
if (loggedUserLevel.equals(PersonnelLevel.LOAN_OFFICER.getValue())) {
return loadMainSearch(mapping, form, request, response);
} else {
return preview(mapping, form, request, response);
}
}
private String loadMasterData(Short userId, HttpServletRequest request,
CustSearchActionForm form) throws Exception {
PersonnelBO personnel = new PersonnelBusinessService()
.getPersonnel(userId);
SessionUtils.setAttribute(CustomerSearchConstants.OFFICE, personnel
.getOffice().getOfficeName(), request);
if (personnel.getLevelEnum() == PersonnelLevel.LOAN_OFFICER)
return loadLoanOfficer(personnel, request);
else
return loadNonLoanOfficer(personnel, request, form);
}
private String loadLoanOfficer(PersonnelBO personnel,
HttpServletRequest request) throws Exception {
List<CustomerBO> customerList = null;
boolean isCenterHierarchyExist = ClientRules.getCenterHierarchyExists();
if (isCenterHierarchyExist)
customerList = getCustomerBusinessService()
.getActiveCentersUnderUser(personnel);
else
customerList = getCustomerBusinessService().getGroupsUnderUser(
personnel);
SessionUtils.setCollectionAttribute(CustomerSearchConstants.CUSTOMERLIST,
customerList, request);
SessionUtils.setAttribute("GrpHierExists", isCenterHierarchyExist,
request);
SessionUtils.setAttribute(CustomerSearchConstants.LOADFORWARD,
CustomerSearchConstants.LOADFORWARDLOANOFFICER, request);
return CustomerSearchConstants.LOADFORWARDLOANOFFICER_SUCCESS;
}
private String loadNonLoanOfficer(PersonnelBO personnel,
HttpServletRequest request, CustSearchActionForm form)
throws Exception {
if (personnel.getOffice().getOfficeLevel().equals(
OfficeLevel.BRANCHOFFICE)) {
List<PersonnelBO> personnelList = new PersonnelBusinessService()
.getActiveLoanOfficersUnderOffice(personnel.getOffice().getOfficeId());
SessionUtils.setCollectionAttribute(CustomerSearchConstants.LOANOFFICERSLIST,
personnelList, request);
SessionUtils.setAttribute(CustomerSearchConstants.LOADFORWARD,
CustomerSearchConstants.LOADFORWARDNONLOANOFFICER, request);
form.setOfficeId(personnel.getOffice().getOfficeId().toString());
return CustomerSearchConstants.LOADFORWARDNONLOANOFFICER_SUCCESS;
} else {
SessionUtils.setCollectionAttribute(CustomerSearchConstants.OFFICESLIST,
new OfficeBusinessService()
.getActiveBranchesUnderUser(personnel), request);
SessionUtils
.setAttribute(CustomerSearchConstants.LOADFORWARD,
CustomerSearchConstants.LOADFORWARDNONBRANCHOFFICE,
request);
return CustomerSearchConstants.LOADFORWARDOFFICE_SUCCESS;
}
}
@Override
@TransactionDemarcate(joinToken = true)
public ActionForward search(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionForward actionForward = super.search(mapping, form, request,
response);
;
CustSearchActionForm actionForm = (CustSearchActionForm) form;
UserContext userContext = getUserContext(request);
String searchString = actionForm.getSearchString();
if (searchString == null)
throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
addSeachValues(searchString, userContext.getBranchId().toString(),
new OfficeBusinessService()
.getOffice(userContext.getBranchId()).getOfficeName(),
request);
searchString = StringUtils.normalizeSearchString(searchString);
if (searchString.equals(""))
throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
if (actionForm.getInput() != null
&& actionForm.getInput().equals("loan"))
SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS,
getCustomerBusinessService().searchGroupClient(
searchString, userContext.getId()), request);
else if (actionForm.getInput() != null
&& actionForm.getInput().equals("savings"))
SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS,
getCustomerBusinessService().searchCustForSavings(
searchString, userContext.getId()), request);
if (request.getParameter("perspective") != null) {
request.setAttribute("perspective", request.getParameter("perspective"));
}
return actionForward;
}
@Override
protected boolean skipActionFormToBusinessObjectConversion(String method) {
return true;
}
protected CustomerBusinessService getCustomerBusinessService() {
return (CustomerBusinessService) ServiceFactory.getInstance()
.getBusinessService(BusinessServiceName.Customer);
}
@Override
protected BusinessService getService() throws ServiceException {
return getCustomerBusinessService();
}
} |
Partager