001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.pdp.action.customerprofile;
017:
018: import java.util.ArrayList;
019: import java.util.Iterator;
020: import java.util.List;
021:
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.apache.struts.action.ActionForm;
026: import org.apache.struts.action.ActionForward;
027: import org.apache.struts.action.ActionMapping;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.module.pdp.action.BaseAction;
030: import org.kuali.module.pdp.bo.CustomerBank;
031: import org.kuali.module.pdp.bo.CustomerProfile;
032: import org.kuali.module.pdp.bo.DisbursementType;
033: import org.kuali.module.pdp.form.customerprofile.CustomerBankForm;
034: import org.kuali.module.pdp.form.customerprofile.CustomerProfileForm;
035: import org.kuali.module.pdp.service.CustomerProfileService;
036: import org.kuali.module.pdp.service.ReferenceService;
037: import org.kuali.module.pdp.service.SecurityRecord;
038:
039: public class CustomerProfileAction extends BaseAction {
040: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
041: .getLogger(CustomerProfileAction.class);
042:
043: private CustomerProfileService customerProfileService;
044: private ReferenceService referenceService;
045:
046: public CustomerProfileAction() {
047: super ();
048: setCustomerProfileService(SpringContext
049: .getBean(CustomerProfileService.class));
050: setReferenceService(SpringContext
051: .getBean(ReferenceService.class));
052: }
053:
054: public void setCustomerProfileService(CustomerProfileService c) {
055: customerProfileService = c;
056: }
057:
058: public void setReferenceService(ReferenceService r) {
059: referenceService = r;
060: }
061:
062: protected boolean isAuthorized(ActionMapping mapping,
063: ActionForm form, HttpServletRequest request,
064: HttpServletResponse response) {
065: SecurityRecord sr = getSecurityRecord(request);
066: return sr.isSysAdminRole();
067: }
068:
069: protected ActionForward executeLogic(ActionMapping mapping,
070: ActionForm form, HttpServletRequest request,
071: HttpServletResponse response) throws Exception {
072: LOG.info("executeLogic() starting");
073: String forward = "list";
074: String profileId = request.getParameter("profile");
075:
076: if (profileId != null) {
077: int cpId = -1;
078: try {
079: cpId = Integer.parseInt(profileId);
080: } catch (NumberFormatException e) {
081: // Bad number - we don't need to do anything here
082: }
083: LOG.debug("executeLogic() cpId = " + cpId);
084: if (cpId == 0) {
085: // Add a new Profile
086: CustomerProfileForm newProfileForm = new CustomerProfileForm();
087:
088: List dtl = referenceService.getAll("DisbursementType");
089: int i = 0;
090: newProfileForm.setCustomerBankFormArraySize(dtl.size());
091: for (Iterator iter = dtl.iterator(); iter.hasNext();) {
092: DisbursementType dt = (DisbursementType) iter
093: .next();
094: CustomerBankForm cbf = new CustomerBankForm();
095: cbf.setDisbursementTypeCode(dt.getCode());
096: cbf.setDisbursementDescription(dt.getDescription());
097: newProfileForm.setCustomerBankForms(i, cbf);
098: i++;
099: }
100:
101: request.setAttribute("PdpCustomerProfileForm",
102: newProfileForm);
103: forward = "edit";
104: } else if (cpId == -1) {
105: // No Id or invalid customer profile ID, go back to the list
106: List l = customerProfileService.getAll();
107: request.setAttribute("customers", l);
108: forward = "list";
109: } else {
110: // Load the customer profile to edit it
111: CustomerProfile custProfile = customerProfileService
112: .get(new Integer(profileId));
113: CustomerProfileForm cpf = new CustomerProfileForm();
114: List formList = new ArrayList();
115:
116: cpf.setForm(custProfile);
117: LOG
118: .debug("executeLogic() profile list of customerbanks is "
119: + custProfile.getCustomerBanks());
120:
121: LOG.debug("executeLogic() CustomerProfileForm is "
122: + cpf);
123:
124: List dtl = referenceService.getAll("DisbursementType");
125: int i = 0;
126: cpf.setCustomerBankFormArraySize(dtl.size());
127: for (Iterator iter = dtl.iterator(); iter.hasNext();) {
128: DisbursementType dt = (DisbursementType) iter
129: .next();
130: CustomerBankForm cbf = new CustomerBankForm();
131: cbf.setDisbursementTypeCode(dt.getCode());
132: cbf.setDisbursementDescription(dt.getDescription());
133: CustomerBank cb = custProfile
134: .getCustomerBankByDisbursementType(dt
135: .getCode());
136: if (cb != null) {
137: cbf.setBankId(cb.getBank().getId());
138: }
139: cpf.setCustomerBankForms(i, cbf);
140: i++;
141: }
142:
143: request.setAttribute("PdpCustomerProfileForm", cpf);
144: forward = "edit";
145: }
146: } else {
147: List l = customerProfileService.getAll();
148: request.setAttribute("customers", l);
149: }
150:
151: return mapping.findForward(forward);
152: }
153: }
|