first commit
This commit is contained in:
680
hrmsEjb/wenrgise/hrms/webtier/action/BaseAction.java
Normal file
680
hrmsEjb/wenrgise/hrms/webtier/action/BaseAction.java
Normal file
@@ -0,0 +1,680 @@
|
||||
package wenrgise.hrms.webtier.action;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Logger;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.struts.action.Action;
|
||||
import org.apache.struts.action.ActionError;
|
||||
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.apache.struts.action.ActionMessages;
|
||||
import org.apache.struts.util.MessageResources;
|
||||
import wenrgise.common.bean.AccessBean;
|
||||
import wenrgise.common.bean.BaseDetailBean;
|
||||
import wenrgise.common.bean.BaseHeaderBean;
|
||||
import wenrgise.common.businessdelegate.BaseBD;
|
||||
import wenrgise.common.exception.EnrgiseApplicationException;
|
||||
import wenrgise.common.exception.EnrgiseMessageKeyException;
|
||||
import wenrgise.common.exception.EnrgiseSystemException;
|
||||
import wenrgise.common.utility.EnrgiseUtil;
|
||||
import wenrgise.common.utility.MessageKey;
|
||||
import wenrgise.common.vo.BaseDetailVO;
|
||||
import wenrgise.common.vo.BaseHeaderVO;
|
||||
import wenrgise.common.vo.BaseQueryVO;
|
||||
import wenrgise.common.vo.DetailSizeValues;
|
||||
import wenrgise.common.vo.ThisPageVO;
|
||||
import wenrgise.common.webtier.form.BaseForm;
|
||||
import wenrgise.common.xml.vo.DetailScreen;
|
||||
import wenrgise.ejb.common.session.UserSession;
|
||||
import wenrgise.ejb.common.utility.ParamUtil;
|
||||
|
||||
public abstract class BaseAction extends Action {
|
||||
static final Logger log = Logger.getLogger("wenrgise.common.webtier.action.BaseAction");
|
||||
|
||||
MessageResources oMsgRes = null;
|
||||
|
||||
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
ActionErrors oErrorTable = null;
|
||||
ActionMessages oMessageTable = null;
|
||||
BaseForm oBaseForm = (BaseForm)form;
|
||||
this.oMsgRes = getResources(request);
|
||||
try {
|
||||
return executeImpl(mapping, form, request, response);
|
||||
} catch (ClassNotFoundException oClassEx) {
|
||||
processSystemException(oClassEx, oErrorTable);
|
||||
} catch (InstantiationException oInSt) {
|
||||
processSystemException(oInSt, oErrorTable);
|
||||
} catch (InvocationTargetException oInvTar) {
|
||||
processSystemException(oInvTar, oErrorTable);
|
||||
} catch (IllegalAccessException oIlAcc) {
|
||||
processSystemException(oIlAcc, oErrorTable);
|
||||
} catch (EnrgiseSystemException oSys) {
|
||||
if (oErrorTable == null)
|
||||
oErrorTable = new ActionErrors();
|
||||
String sKey = (null != oSys.getKey()) ? oSys.getKey() : "wenrgise.common.system";
|
||||
ActionError oSysError = new ActionError(sKey);
|
||||
oErrorTable.add("org.apache.struts.action.GLOBAL_ERROR", oSysError);
|
||||
} catch (EnrgiseApplicationException oApp) {
|
||||
if (oErrorTable == null)
|
||||
oErrorTable = new ActionErrors();
|
||||
if (oMessageTable == null)
|
||||
oMessageTable = new ActionMessages();
|
||||
processException(oErrorTable, oMessageTable, oApp);
|
||||
if (oApp.getList() != null) {
|
||||
Iterator oIt = oApp.getList().iterator();
|
||||
while (oIt.hasNext()) {
|
||||
EnrgiseApplicationException oAppErr = oIt.next();
|
||||
processException(oErrorTable, oMessageTable, oAppErr);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (oErrorTable != null) {
|
||||
System.out.println("Save errors");
|
||||
if (oErrorTable.size() > 0) {
|
||||
saveErrors(request, oErrorTable);
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
}
|
||||
if (oMessageTable != null)
|
||||
if (oMessageTable.size() > 0) {
|
||||
System.out.println("Save messages");
|
||||
saveMessages(request, oMessageTable);
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void processSystemException(Exception oEc, ActionErrors oErrorTable) {
|
||||
if (oErrorTable == null)
|
||||
oErrorTable = new ActionErrors();
|
||||
EnrgiseSystemException oSys = new EnrgiseSystemException("wenrgise.common.system", oEc);
|
||||
ActionError oSysError = new ActionError(oSys.getKey());
|
||||
oErrorTable.add("org.apache.struts.action.GLOBAL_ERROR", oSysError);
|
||||
}
|
||||
|
||||
private void processException(ActionErrors oErrorTable, ActionMessages oMessageTable, EnrgiseApplicationException oApp) {
|
||||
if (oApp.getArguments() == null) {
|
||||
if (oApp.getErrorType().equals("E")) {
|
||||
oErrorTable.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError(oApp.getKey()));
|
||||
} else {
|
||||
oMessageTable.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage(oApp.getKey()));
|
||||
}
|
||||
} else if (oApp instanceof EnrgiseMessageKeyException) {
|
||||
processMessageKeyException((EnrgiseMessageKeyException)oApp, oErrorTable, oMessageTable);
|
||||
} else if (oApp.getErrorType().equals("E")) {
|
||||
oErrorTable.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError(oApp.getKey(), oApp.getArguments().toArray()));
|
||||
} else {
|
||||
oMessageTable.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage(oApp.getKey(), oApp.getArguments().toArray()));
|
||||
}
|
||||
}
|
||||
|
||||
private void processMessageKeyException(EnrgiseMessageKeyException oApp, ActionErrors oErrorTable, ActionMessages oMessageTable) {
|
||||
ArrayList oList = oApp.getArguments();
|
||||
if (null == oList) {
|
||||
if (oApp.getErrorType().equals("E")) {
|
||||
oErrorTable.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError(oApp.getKey()));
|
||||
} else {
|
||||
oMessageTable.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage(oApp.getKey()));
|
||||
}
|
||||
} else {
|
||||
ArrayList oNewList = new ArrayList();
|
||||
Iterator oIt = oList.iterator();
|
||||
while (oIt.hasNext()) {
|
||||
Object obj = oIt.next();
|
||||
if (obj instanceof MessageKey) {
|
||||
MessageKey oMsgKey = (MessageKey)obj;
|
||||
oNewList.add(this.oMsgRes.getMessage(oMsgKey.getKey()));
|
||||
continue;
|
||||
}
|
||||
oNewList.add(obj);
|
||||
}
|
||||
if (oApp.getErrorType().equals("E")) {
|
||||
oErrorTable.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError(oApp.getKey(), oNewList.toArray()));
|
||||
} else {
|
||||
oMessageTable.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage(oApp.getKey(), oNewList.toArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected BaseQueryVO getQueryVO(ActionForm form) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
|
||||
BaseForm oBaseForm = (BaseForm)form;
|
||||
String sFormName = form.getClass().getName();
|
||||
String sScreenName = oBaseForm.getScreenName();
|
||||
String sQueryVO = ParamUtil.getQueryVO(sFormName);
|
||||
BaseQueryVO oBaseQueryVO = (BaseQueryVO)Class.forName(sQueryVO).newInstance();
|
||||
oBaseQueryVO.setMaxHeaderSize(ParamUtil.getHeaderSize(sFormName));
|
||||
return oBaseQueryVO;
|
||||
}
|
||||
|
||||
protected BaseDetailBean getDetailBean(ActionForm form) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
|
||||
BaseForm oBaseForm = (BaseForm)form;
|
||||
String sFormName = form.getClass().getName();
|
||||
String sScreenName = oBaseForm.getScreenName();
|
||||
String sDetailBean = ParamUtil.getDetailBeanName(sFormName, sScreenName);
|
||||
BaseDetailBean oBaseDetailBean = (BaseDetailBean)Class.forName(sDetailBean).newInstance();
|
||||
return oBaseDetailBean;
|
||||
}
|
||||
|
||||
protected BaseBD getHeaderBusinessDelegate(ActionForm form, HttpServletRequest request) throws RemoteException, IllegalAccessException, InstantiationException, ClassNotFoundException {
|
||||
BaseForm oBaseForm = (BaseForm)form;
|
||||
String sFormName = form.getClass().getName();
|
||||
String sScreenName = oBaseForm.getScreenName();
|
||||
String sBusinessDelegate = ParamUtil.getHeaderBD(sFormName);
|
||||
BaseBD oBaseBD = (BaseBD)Class.forName(sBusinessDelegate).newInstance();
|
||||
UserSession oUser = getUserSessionBean(request);
|
||||
oBaseBD.setModuleName(ParamUtil.getModuleName());
|
||||
oBaseBD.setModuleFacade(oUser.getModuleFacade());
|
||||
oBaseBD.setOUserInfo(oUser.getUserInfo());
|
||||
return oBaseBD;
|
||||
}
|
||||
|
||||
protected BaseBD getDetailBusinessDelegate(ActionForm form, HttpServletRequest request) throws RemoteException, IllegalAccessException, InstantiationException, ClassNotFoundException {
|
||||
BaseForm oBaseForm = (BaseForm)form;
|
||||
String sFormName = form.getClass().getName();
|
||||
String sScreenName = oBaseForm.getScreenName();
|
||||
String sBusinessDelegate = ParamUtil.getDetailBD(sFormName, sScreenName);
|
||||
BaseBD oBaseBD = (BaseBD)Class.forName(sBusinessDelegate).newInstance();
|
||||
UserSession oUser = getUserSessionBean(request);
|
||||
oBaseBD.setModuleName(ParamUtil.getModuleName());
|
||||
oBaseBD.setModuleFacade(oUser.getModuleFacade());
|
||||
oBaseBD.setOUserInfo(oUser.getUserInfo());
|
||||
return oBaseBD;
|
||||
}
|
||||
|
||||
protected BaseHeaderBean getBaseHeaderBean(String sFormName) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
|
||||
String sBaseHeaderBean = ParamUtil.getHeaderBean(sFormName);
|
||||
BaseHeaderBean oBaseHeaderBean = (BaseHeaderBean)Class.forName(sBaseHeaderBean).newInstance();
|
||||
String pseudoHeader = ParamUtil.getPseudoHeaderFlag(sFormName);
|
||||
oBaseHeaderBean.setPseudoHeader(pseudoHeader);
|
||||
return oBaseHeaderBean;
|
||||
}
|
||||
|
||||
protected ArrayList getDetailArrayList(BaseForm oBaseForm, String sFormName, String sScreenName) throws EnrgiseSystemException, IllegalAccessException, InstantiationException, ClassNotFoundException {
|
||||
String sDetailArrayList = ParamUtil.getDetailArrayName(sFormName, sScreenName);
|
||||
ArrayList oList = (ArrayList)EnrgiseUtil.getFieldValue(oBaseForm, sDetailArrayList);
|
||||
return oList;
|
||||
}
|
||||
|
||||
protected UserSession getUserSessionBean(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
return (UserSession)session.getAttribute(ParamUtil.getSessionBeanName());
|
||||
}
|
||||
|
||||
protected void clearDetailLists(BaseForm form, ArrayList oDetailList) throws IllegalAccessException, InvocationTargetException {
|
||||
Iterator oIt = oDetailList.iterator();
|
||||
while (oIt.hasNext()) {
|
||||
DetailScreen oDetailScreen = oIt.next();
|
||||
BeanUtils.copyProperty(form, oDetailScreen.get_DetailArrayName(), new ArrayList());
|
||||
}
|
||||
}
|
||||
|
||||
protected ArrayList getDetailArray(BaseForm oBaseForm) throws EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException {
|
||||
String sFormName = oBaseForm.getClass().getName();
|
||||
String sScreenName = oBaseForm.getScreenName();
|
||||
ArrayList oDetailArray = new ArrayList();
|
||||
String sDetailBean = ParamUtil.getDetailBeanName(sFormName, sScreenName);
|
||||
BaseDetailBean oBaseDetailBean = (BaseDetailBean)Class.forName(sDetailBean).newInstance();
|
||||
ArrayList oFieldList = new ArrayList();
|
||||
oFieldList = getFieldList(oFieldList, oBaseDetailBean.getClass());
|
||||
ArrayList oList = (ArrayList)EnrgiseUtil.getFieldValue(oBaseForm, ParamUtil.getDetailArrayName(sFormName, sScreenName));
|
||||
for (int iRecord = 0; iRecord < oBaseForm.getThisPageDetailCount(); iRecord++) {
|
||||
if (null == oList)
|
||||
break;
|
||||
oBaseDetailBean = oList.get(iRecord);
|
||||
if (null == oBaseDetailBean)
|
||||
break;
|
||||
Iterator oIt = oFieldList.iterator();
|
||||
while (oIt.hasNext()) {
|
||||
try {
|
||||
Field ob = oIt.next();
|
||||
System.out.println(String.valueOf("Record name ").concat(String.valueOf(iRecord)));
|
||||
String sFieldName = ob.getName();
|
||||
System.out.println(String.valueOf("Field name ").concat(String.valueOf(sFieldName)));
|
||||
if (sFieldName.startsWith("disab"))
|
||||
continue;
|
||||
if (ob.getType().getName().equals("java.lang.String")) {
|
||||
String sValue = BeanUtils.getIndexedProperty(oBaseForm, sFieldName, iRecord);
|
||||
BeanUtils.setProperty(oBaseDetailBean, sFieldName, sValue);
|
||||
}
|
||||
} catch (NoSuchMethodException noSuchMethodException) {}
|
||||
}
|
||||
oDetailArray.add(oBaseDetailBean);
|
||||
}
|
||||
return oDetailArray;
|
||||
}
|
||||
|
||||
private ArrayList getFieldList(ArrayList oFieldList, Class oClass) {
|
||||
if (oClass == null)
|
||||
return oFieldList;
|
||||
Field[] oFields = oClass.getDeclaredFields();
|
||||
EnrgiseUtil.addToList(oFieldList, (Object[])oFields);
|
||||
return getFieldList(oFieldList, oClass.getSuperclass());
|
||||
}
|
||||
|
||||
protected void changeMode(BaseForm oBaseForm, HttpServletRequest request) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException {
|
||||
String sFormName = oBaseForm.getClass().getName();
|
||||
String sScreenName = oBaseForm.getScreenName();
|
||||
BaseHeaderBean oBaseHeaderBean = getBaseHeaderBean(sFormName);
|
||||
BeanUtils.copyProperties(oBaseForm, oBaseHeaderBean);
|
||||
clearDetailLists(oBaseForm, ParamUtil.getDetailList(sFormName));
|
||||
UserSession oUser = getUserSessionBean(request);
|
||||
oUser.putBaseHeaderVO(sFormName, null);
|
||||
oUser.removeAllDetailVO(sFormName);
|
||||
resetForm(oBaseForm);
|
||||
}
|
||||
|
||||
protected void checkHeaderNavigation(BaseForm oBaseForm, BaseHeaderVO oBaseHeaderVO) throws EnrgiseApplicationException {
|
||||
long lPositionRequested = Long.parseLong(oBaseForm.getUserPositionRequested());
|
||||
if (null != oBaseHeaderVO) {
|
||||
if (lPositionRequested <= 0L || lPositionRequested > oBaseHeaderVO.getTotalCount())
|
||||
throw new EnrgiseApplicationException("wenrgise.common.headerNavigation", "E");
|
||||
oBaseForm.setPositionRequested(lPositionRequested);
|
||||
} else {
|
||||
throw new EnrgiseApplicationException("wenrgise.common.headerNavigation", "E");
|
||||
}
|
||||
}
|
||||
|
||||
private void resetForm(BaseForm oBaseForm) {
|
||||
oBaseForm.setPageRequested(0L);
|
||||
oBaseForm.setPositionRequested(0L);
|
||||
oBaseForm.setTotalCount(0L);
|
||||
oBaseForm.setTotalDetailRecord(0L);
|
||||
oBaseForm.setTotalHeaderRecord(0L);
|
||||
oBaseForm.setHeaderPrimaryKey(null);
|
||||
oBaseForm.setUserPageRequested(null);
|
||||
oBaseForm.setDetailId(null);
|
||||
oBaseForm.setStatus(null);
|
||||
oBaseForm.setDetailDataChanged(false);
|
||||
oBaseForm.setHeaderDataChanged(false);
|
||||
oBaseForm.setChecked(null);
|
||||
oBaseForm.setUserPositionRequested(null);
|
||||
oBaseForm.setTotalCount(0L);
|
||||
oBaseForm.setNewPageRequested(null);
|
||||
oBaseForm.setItemChecked(null);
|
||||
oBaseForm.setLovKey(null);
|
||||
oBaseForm.setTxtSearchFields(null);
|
||||
oBaseForm.setTxtDisplayFields(null);
|
||||
oBaseForm.setTxtIndex(null);
|
||||
oBaseForm.setThisPageDetailCount(0);
|
||||
oBaseForm.setTotalPageCount(0L);
|
||||
oBaseForm.setHeaderStatus(null);
|
||||
oBaseForm.setButtonClicked(null);
|
||||
oBaseForm.setButtonName(null);
|
||||
oBaseForm.setDetailStartPage(0);
|
||||
}
|
||||
|
||||
protected void checkDetailNavigation(BaseForm oBaseForm, BaseDetailVO oBaseDetailVO) throws EnrgiseApplicationException {
|
||||
boolean flag = false;
|
||||
long lPageRequested = 0L;
|
||||
if (EnrgiseUtil.checkString(oBaseForm.getUserPageRequested())) {
|
||||
lPageRequested = Long.parseLong(oBaseForm.getUserPageRequested());
|
||||
} else {
|
||||
flag = true;
|
||||
}
|
||||
if (null != oBaseDetailVO) {
|
||||
if (flag == false) {
|
||||
if (lPageRequested <= 0L || oBaseDetailVO.getTotalDetailRecord() <= oBaseDetailVO.getRecordsPerPage() * (lPageRequested - 1L))
|
||||
throw new EnrgiseApplicationException("wenrgise.common.detailNavigation", "E");
|
||||
oBaseForm.setPageRequested(lPageRequested);
|
||||
} else if (oBaseForm.getDetailList() != null) {
|
||||
oBaseForm.setPageRequested(1L);
|
||||
} else {
|
||||
oBaseForm.setPageRequested(0L);
|
||||
}
|
||||
} else {
|
||||
throw new EnrgiseApplicationException("wenrgise.common.detailNavigation", "E");
|
||||
}
|
||||
}
|
||||
|
||||
protected void enableDisable(BaseForm oBaseForm, ArrayList arylstFields, String enableFlag) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException {
|
||||
if (null != arylstFields) {
|
||||
Iterator iterFields = arylstFields.iterator();
|
||||
while (iterFields.hasNext()) {
|
||||
StringBuffer sField = new StringBuffer(iterFields.next());
|
||||
String sProperty = String.valueOf("setDisab").concat(String.valueOf(sField.toString()));
|
||||
try {
|
||||
Class[] oCls = { Class.forName("java.lang.String") };
|
||||
Method oMethod = oBaseForm.getClass().getMethod(sProperty, oCls);
|
||||
String sFlag = enableFlag.equals("D") ? "true" : "false";
|
||||
Object[] obj = { sFlag };
|
||||
oMethod.invoke(oBaseForm, obj);
|
||||
} catch (NoSuchMethodException nse) {
|
||||
System.out.println(String.valueOf(String.valueOf(String.valueOf("The problem is ").concat(String.valueOf(nse.getMessage()))).concat(String.valueOf(" "))).concat(String.valueOf(sProperty)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void enableAll(BaseForm oBaseForm) {
|
||||
try {
|
||||
ArrayList arylstDisFields = new ArrayList();
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields = getFieldList(arylstFields, oBaseForm.getClass());
|
||||
Iterator iterFields = arylstFields.iterator();
|
||||
while (iterFields.hasNext()) {
|
||||
Field oField = iterFields.next();
|
||||
if (oField.getName().startsWith("disab"))
|
||||
arylstDisFields.add(oField.getName().replaceFirst("disab", ""));
|
||||
}
|
||||
enableDisable(oBaseForm, arylstDisFields, "E");
|
||||
} catch (Exception exception) {}
|
||||
}
|
||||
|
||||
protected void disableAll(BaseForm oBaseForm) {
|
||||
try {
|
||||
ArrayList arylstDisFields = new ArrayList();
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields = getFieldList(arylstFields, oBaseForm.getClass());
|
||||
Iterator iterFields = arylstFields.iterator();
|
||||
while (iterFields.hasNext()) {
|
||||
Field oField = iterFields.next();
|
||||
if (oField.getName().startsWith("disab"))
|
||||
arylstDisFields.add(oField.getName().replaceFirst("disab", ""));
|
||||
}
|
||||
enableDisable(oBaseForm, arylstDisFields, "D");
|
||||
} catch (Exception exception) {}
|
||||
}
|
||||
|
||||
protected ArrayList queryClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butQuery");
|
||||
arylstFields.add("butSave");
|
||||
arylstFields.add("butDelete");
|
||||
arylstFields.add("butPrint");
|
||||
arylstFields.add("butGetDetail");
|
||||
arylstFields.add("butAddRow");
|
||||
arylstFields.add("butDelRow");
|
||||
arylstFields.add("butNextHeader");
|
||||
arylstFields.add("butPrevHeader");
|
||||
arylstFields.add("newPositionRequested");
|
||||
arylstFields.add("butJumpHeader");
|
||||
arylstFields.add("butNextDetail");
|
||||
arylstFields.add("butPrevDetail");
|
||||
arylstFields.add("newPageRequested");
|
||||
arylstFields.add("butJumpDetail");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList insertClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butInsert");
|
||||
arylstFields.add("butExecute");
|
||||
arylstFields.add("butDelete");
|
||||
arylstFields.add("butPrint");
|
||||
arylstFields.add("butGetDetail");
|
||||
arylstFields.add("butAddRow");
|
||||
arylstFields.add("butDelRow");
|
||||
arylstFields.add("butNextHeader");
|
||||
arylstFields.add("butPrevHeader");
|
||||
arylstFields.add("newPositionRequested");
|
||||
arylstFields.add("butJumpHeader");
|
||||
arylstFields.add("butNextDetail");
|
||||
arylstFields.add("butPrevDetail");
|
||||
arylstFields.add("newPageRequested");
|
||||
arylstFields.add("butJumpDetail");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList executeClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butExecute");
|
||||
arylstFields.add("butAddRow");
|
||||
arylstFields.add("butDelRow");
|
||||
arylstFields.add("butExecute");
|
||||
arylstFields.add("butNextDetail");
|
||||
arylstFields.add("butPrevDetail");
|
||||
arylstFields.add("butJumpDetail");
|
||||
arylstFields.add("newPageRequested");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList deleteClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butQuery");
|
||||
arylstFields.add("butExecute");
|
||||
arylstFields.add("butDelete");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList saveClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butExecute");
|
||||
arylstFields.add("butGetDetail");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList refreshClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList nextHeaderClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butExecute");
|
||||
arylstFields.add("butAddRow");
|
||||
arylstFields.add("butDelRow");
|
||||
arylstFields.add("butNextDetail");
|
||||
arylstFields.add("butPrevDetail");
|
||||
arylstFields.add("butJumpDetail");
|
||||
arylstFields.add("newPageRequested");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList prevHeaderClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butExecute");
|
||||
arylstFields.add("butAddRow");
|
||||
arylstFields.add("butDelRow");
|
||||
arylstFields.add("butNextDetail");
|
||||
arylstFields.add("butPrevDetail");
|
||||
arylstFields.add("butJumpDetail");
|
||||
arylstFields.add("newPageRequested");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList getDetailClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butGetDetail");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList addRowClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butGetDetail");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected ArrayList delRowClicked() {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
arylstFields.add("butDelRow");
|
||||
arylstFields.add("butGetDetail");
|
||||
return arylstFields;
|
||||
}
|
||||
|
||||
protected void controlHeaderNavigation(BaseForm oBaseForm) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException {
|
||||
ArrayList arylstFields = new ArrayList();
|
||||
long lTotalRecord = oBaseForm.getTotalCount();
|
||||
long lRecordNum = oBaseForm.getPositionRequested();
|
||||
if (lTotalRecord == 0L || lTotalRecord == 1L) {
|
||||
arylstFields.add("butNextHeader");
|
||||
arylstFields.add("butPrevHeader");
|
||||
arylstFields.add("newPositionRequested");
|
||||
arylstFields.add("butJumpHeader");
|
||||
} else {
|
||||
if (lRecordNum == lTotalRecord)
|
||||
arylstFields.add("butNextHeader");
|
||||
if (lRecordNum == 1L)
|
||||
arylstFields.add("butPrevHeader");
|
||||
}
|
||||
enableDisable(oBaseForm, arylstFields, "D");
|
||||
}
|
||||
|
||||
protected void controlDetailNavigation(BaseForm oBaseForm) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException {
|
||||
ArrayList oEnableList = new ArrayList();
|
||||
ArrayList oDisableList = new ArrayList();
|
||||
long lTotalRecord = oBaseForm.getTotalPageCount();
|
||||
long lRecordNum = oBaseForm.getPageRequested();
|
||||
if (lTotalRecord == 0L || lTotalRecord == 1L) {
|
||||
oDisableList.add("butNextDetail");
|
||||
oDisableList.add("butPrevDetail");
|
||||
oDisableList.add("newPageRequested");
|
||||
oDisableList.add("butJumpDetail");
|
||||
} else if (lRecordNum == lTotalRecord) {
|
||||
oEnableList.add("butPrevDetail");
|
||||
oEnableList.add("newPageRequested");
|
||||
oEnableList.add("butJumpDetail");
|
||||
oDisableList.add("butNextDetail");
|
||||
} else if (lRecordNum == 1L) {
|
||||
oEnableList.add("newPageRequested");
|
||||
oEnableList.add("butJumpDetail");
|
||||
oEnableList.add("butNextDetail");
|
||||
oDisableList.add("butPrevDetail");
|
||||
} else {
|
||||
oEnableList.add("newPageRequested");
|
||||
oEnableList.add("butJumpDetail");
|
||||
oEnableList.add("butNextDetail");
|
||||
oEnableList.add("butPrevDetail");
|
||||
}
|
||||
enableDisable(oBaseForm, oEnableList, "E");
|
||||
enableDisable(oBaseForm, oDisableList, "D");
|
||||
}
|
||||
|
||||
protected void resetDetailPageData(BaseForm oBaseForm) {
|
||||
oBaseForm.setPageRequested(0L);
|
||||
oBaseForm.setTotalPageCount(0L);
|
||||
}
|
||||
|
||||
protected long calculateTotalDetailPage(String sFormName, String sScreenName, long lTotDetRecord) {
|
||||
long totRecPerPage = ParamUtil.getDetailRecordPerPage(sFormName, sScreenName);
|
||||
if (lTotDetRecord % totRecPerPage != 0L)
|
||||
return lTotDetRecord / totRecPerPage + 1L;
|
||||
return lTotDetRecord / totRecPerPage;
|
||||
}
|
||||
|
||||
protected BaseDetailVO getDetailData(BaseForm oBaseForm, String sFormName, String sScreenName, long lPageRequested, HttpServletRequest request, BaseBD oBaseBD, boolean bForce, UserSession oUser) throws RemoteException, ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException, EnrgiseApplicationException, EnrgiseSystemException {
|
||||
String sHeaderPrimaryKey = oBaseForm.getHeaderPrimaryKey();
|
||||
String pseudoHeader = ParamUtil.getPseudoHeaderFlag(sFormName);
|
||||
DetailSizeValues oDetailSizeValues = new DetailSizeValues();
|
||||
oDetailSizeValues.setDetailRecordPerPage(ParamUtil.getDetailRecordPerPage(sFormName, sScreenName));
|
||||
oDetailSizeValues.setMaxPages(ParamUtil.getMaxDetailPages(sFormName, sScreenName));
|
||||
BaseDetailVO oBaseDetailVO = null;
|
||||
oBaseDetailVO = oUser.getBaseDetailVO(sFormName, sScreenName);
|
||||
if (!EnrgiseUtil.checkString(pseudoHeader)) {
|
||||
oBaseDetailVO = oBaseBD.getDetailRecord(sFormName, sScreenName, sHeaderPrimaryKey, lPageRequested, oDetailSizeValues, oBaseDetailVO, bForce, oUser);
|
||||
} else {
|
||||
BaseQueryVO oBaseQueryVO = getQueryVO((ActionForm)oBaseForm);
|
||||
BeanUtils.copyProperties(oBaseQueryVO, oBaseForm);
|
||||
oBaseDetailVO = oBaseBD.getDetailRecord(sFormName, sScreenName, oBaseQueryVO, lPageRequested, oDetailSizeValues, oBaseDetailVO, bForce, oUser);
|
||||
}
|
||||
if (oBaseDetailVO.getOThisPageData() != null)
|
||||
BeanUtils.setProperty(oBaseForm, ParamUtil.getDetailArrayName(sFormName, sScreenName), oBaseDetailVO.getOThisPageData());
|
||||
oBaseForm.setPageRequested(lPageRequested);
|
||||
oBaseForm.setThisPageDetailCount((null != oBaseDetailVO.getOThisPageData()) ? oBaseDetailVO.getOThisPageData().size() : 0);
|
||||
BeanUtils.copyProperties(oBaseForm, oBaseDetailVO);
|
||||
oBaseForm.setNewPageRequested(null);
|
||||
oBaseForm.setPageRequested(lPageRequested);
|
||||
oUser.putBaseDetailVO(sFormName, sScreenName, oBaseDetailVO);
|
||||
return oBaseDetailVO;
|
||||
}
|
||||
|
||||
protected void onLoad(ActionForm form, HttpServletRequest request, int actionName) throws RemoteException, ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException, EnrgiseApplicationException, EnrgiseSystemException {
|
||||
BaseForm oBaseForm = (BaseForm)form;
|
||||
String sFormName = form.getClass().getName();
|
||||
String sScreenName = oBaseForm.getScreenName();
|
||||
BaseDetailVO oBaseDetailVO = new BaseDetailVO();
|
||||
UserSession oUser = getUserSessionBean(request);
|
||||
BaseBD oBaseBD = getHeaderBusinessDelegate(form, request);
|
||||
BaseHeaderBean oBaseHeaderBean = getBaseHeaderBean(sFormName);
|
||||
BeanUtils.copyProperties(oBaseHeaderBean, form);
|
||||
ThisPageVO oThisPageVO = new ThisPageVO();
|
||||
oThisPageVO.setActionName(actionName);
|
||||
oThisPageVO.setOHeaderBean(oBaseHeaderBean);
|
||||
oThisPageVO.setScreenMode(oBaseForm.getScreenMode());
|
||||
oThisPageVO.setScreenName(oBaseForm.getScreenName());
|
||||
oBaseDetailVO = oUser.getBaseDetailVO(sFormName, sScreenName);
|
||||
if (null != oBaseDetailVO) {
|
||||
ArrayList oDetailList = getDetailArrayList(oBaseForm, sFormName, sScreenName);
|
||||
oThisPageVO.setODetailList(oDetailList);
|
||||
}
|
||||
oBaseBD.onLoadAction(oThisPageVO);
|
||||
if (oThisPageVO != null)
|
||||
if (oThisPageVO.getOHeaderBean() != null)
|
||||
BeanUtils.copyProperties(form, oThisPageVO.getOHeaderBean());
|
||||
if (oThisPageVO.getODetailList() != null) {
|
||||
oBaseForm.setThisPageDetailCount(oThisPageVO.getODetailList().size());
|
||||
BeanUtils.setProperty(oBaseForm, ParamUtil.getDetailArrayName(sFormName, sScreenName), oThisPageVO.getODetailList());
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkAccessInfo(UserSession oUserSession, String sComponentName, String sScreenMode, String sButtonName, int iActionName, String sWorkListId) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
|
||||
HashMap oSecMap = oUserSession.getAccessInfo();
|
||||
AccessBean objBean = (AccessBean)oSecMap.get(sComponentName);
|
||||
if (!EnrgiseUtil.checkString(sWorkListId)) {
|
||||
if (iActionName == 10 || iActionName == 14 || iActionName == 23)
|
||||
if (!objBean.getInsertFlag().equalsIgnoreCase("Y")) {
|
||||
ArrayList oParam = new ArrayList();
|
||||
MessageKey oMessageKey = new MessageKey("right.for.insert");
|
||||
oParam.add(oMessageKey);
|
||||
throw new EnrgiseMessageKeyException("wenrgise.authorisation.error", oParam, "M");
|
||||
}
|
||||
if (iActionName == 8)
|
||||
if (sScreenMode.equalsIgnoreCase("N")) {
|
||||
if (!objBean.getInsertFlag().equalsIgnoreCase("Y")) {
|
||||
ArrayList oParam = new ArrayList();
|
||||
MessageKey oMessageKey = new MessageKey("right.for.insert");
|
||||
oParam.add(oMessageKey);
|
||||
throw new EnrgiseMessageKeyException("wenrgise.authorisation.error", oParam, "M");
|
||||
}
|
||||
} else if (sScreenMode.equalsIgnoreCase("U")) {
|
||||
if (!objBean.getUpdateFlag().equalsIgnoreCase("Y")) {
|
||||
ArrayList oParam = new ArrayList();
|
||||
MessageKey oMessageKey = new MessageKey("right.for.update");
|
||||
oParam.add(oMessageKey);
|
||||
throw new EnrgiseMessageKeyException("wenrgise.authorisation.error", oParam, "M");
|
||||
}
|
||||
}
|
||||
if (iActionName == 17 || iActionName == 15)
|
||||
if (!objBean.getDeleteFlag().equalsIgnoreCase("Y")) {
|
||||
ArrayList oParam = new ArrayList();
|
||||
MessageKey oMessageKey = new MessageKey("right.for.delete");
|
||||
oParam.add(oMessageKey);
|
||||
throw new EnrgiseMessageKeyException("wenrgise.authorisation.error", oParam, "M");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getComponentName(String sFormName) {
|
||||
String sModFormName = sFormName.replace('.', ',');
|
||||
int index = 0;
|
||||
char g = ',';
|
||||
char[] arrayModeFormName = sModFormName.toCharArray();
|
||||
System.out.println(sModFormName.substring(index));
|
||||
int k;
|
||||
for (k = arrayModeFormName.length - 1; k > 0; k--) {
|
||||
System.out.println(arrayModeFormName[k]);
|
||||
if (arrayModeFormName[k] == g) {
|
||||
index = k + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String sComponentName = sModFormName.substring(index, sModFormName.length());
|
||||
return sComponentName;
|
||||
}
|
||||
|
||||
public abstract ActionForward executeImpl(ActionMapping paramActionMapping, ActionForm paramActionForm, HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException;
|
||||
}
|
64
hrmsEjb/wenrgise/hrms/webtier/action/DecrAction.java
Normal file
64
hrmsEjb/wenrgise/hrms/webtier/action/DecrAction.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package wenrgise.hrms.webtier.action;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.struts.action.ActionForm;
|
||||
import org.apache.struts.action.ActionForward;
|
||||
import org.apache.struts.action.ActionMapping;
|
||||
import wenrgise.common.bean.BaseDetailBean;
|
||||
import wenrgise.common.exception.EnrgiseApplicationException;
|
||||
import wenrgise.common.exception.EnrgiseSystemException;
|
||||
import wenrgise.common.vo.BaseDetailVO;
|
||||
import wenrgise.common.webtier.action.BaseAction;
|
||||
import wenrgise.common.webtier.form.BaseForm;
|
||||
import wenrgise.ejb.common.session.UserSession;
|
||||
import wenrgise.ejb.common.utility.ParamUtil;
|
||||
|
||||
public class DecrAction extends BaseAction {
|
||||
public ActionForward executeImpl(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException {
|
||||
BaseForm oBaseForm = (BaseForm)form;
|
||||
String sFormName = form.getClass().getName();
|
||||
String sScreenName = oBaseForm.getScreenName();
|
||||
UserSession oUser = getUserSessionBean(request);
|
||||
BaseDetailVO oBaseDetailVO = oUser.getBaseDetailVO(sFormName, sScreenName);
|
||||
int count = 0;
|
||||
ArrayList oDetailArray = getDetailArray(oBaseForm);
|
||||
try {
|
||||
String[] itemChecked = oBaseForm.getItemChecked();
|
||||
String[] sStatuss = oBaseForm.getStatus();
|
||||
String[] sStartFields = BeanUtils.getArrayProperty(oBaseForm, "txtFromAmount");
|
||||
System.out.println(itemChecked.length);
|
||||
for (int i = 0; i < itemChecked.length; i++) {
|
||||
if (itemChecked[i].equals("Y")) {
|
||||
count++;
|
||||
String sStartField = sStartFields[i];
|
||||
for (int j = i + 1; j < itemChecked.length; j++) {
|
||||
String sStatus = sStatuss[j];
|
||||
if (!sStatus.equals("D")) {
|
||||
sStartFields[j] = sStartField;
|
||||
BaseDetailBean oBaseDetailBean = oDetailArray.get(j);
|
||||
oBaseDetailBean.setStatus("U");
|
||||
BeanUtils.setProperty(oBaseDetailBean, "txtFromAmount", sStartField);
|
||||
oDetailArray.set(j, oBaseDetailBean);
|
||||
break;
|
||||
}
|
||||
}
|
||||
((BaseDetailBean)oDetailArray.get(i)).setStatus("D");
|
||||
((BaseDetailBean)oDetailArray.get(i)).setItemChecked("N");
|
||||
oBaseDetailVO.setRowDeleted(oBaseDetailVO.getRowDeleted() + 1);
|
||||
}
|
||||
}
|
||||
} catch (NoSuchMethodException noSuchMethodException) {}
|
||||
if (count == 0)
|
||||
throw new EnrgiseApplicationException("wenrgise.common.norowselected");
|
||||
if (count > 0)
|
||||
oBaseForm.setDetailDataChanged(true);
|
||||
BeanUtils.setProperty(oBaseForm, ParamUtil.getDetailArrayName(sFormName, sScreenName), oDetailArray);
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package wenrgise.hrms.webtier.action;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Locale;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jxl.Workbook;
|
||||
import jxl.WorkbookSettings;
|
||||
import jxl.write.WritableSheet;
|
||||
import jxl.write.WritableWorkbook;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.struts.action.ActionForm;
|
||||
import org.apache.struts.action.ActionForward;
|
||||
import org.apache.struts.action.ActionMapping;
|
||||
import wenrgise.common.bean.BaseHeaderBean;
|
||||
import wenrgise.common.exception.EnrgiseApplicationException;
|
||||
import wenrgise.common.exception.EnrgiseSystemException;
|
||||
import wenrgise.hrms.bean.HrmAdhocReportHdrBean;
|
||||
import wenrgise.hrms.ejb.business.HrmAdhocReportBO;
|
||||
import wenrgise.hrms.webtier.form.HrmAdhocReportForm;
|
||||
|
||||
public class HrmAdhocReportAction extends BaseAction {
|
||||
public ActionForward executeImpl(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException {
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
WorkbookSettings ws = new WorkbookSettings();
|
||||
ws.setLocale(new Locale("en", "EN"));
|
||||
ServletOutputStream servletOutputStream = response.getOutputStream();
|
||||
HrmAdhocReportForm oForm = (HrmAdhocReportForm)form;
|
||||
String sFormName = oForm.getClass().getName();
|
||||
BaseHeaderBean oBaseHeaderBean = getBaseHeaderBean(sFormName);
|
||||
BeanUtils.copyProperties(oBaseHeaderBean, oForm);
|
||||
HrmAdhocReportBO oHrmAdhocReportBO = new HrmAdhocReportBO();
|
||||
String reportName = oForm.getCode();
|
||||
StringBuffer fileName = new StringBuffer("\\");
|
||||
fileName.append(reportName);
|
||||
fileName.append(".xls");
|
||||
response.setHeader("Content-disposition", String.valueOf(String.valueOf("attachment; filename=\"").concat(String.valueOf(fileName.toString()))).concat(String.valueOf("\"")));
|
||||
try {
|
||||
WritableWorkbook workbook = Workbook.createWorkbook((OutputStream)servletOutputStream, ws);
|
||||
WritableSheet s = workbook.createSheet(reportName, 0);
|
||||
oHrmAdhocReportBO.downloadAdhocReport((HrmAdhocReportHdrBean)oBaseHeaderBean, s);
|
||||
workbook.write();
|
||||
workbook.close();
|
||||
servletOutputStream.flush();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
}
|
101
hrmsEjb/wenrgise/hrms/webtier/action/HrmGenLoginAction.java
Normal file
101
hrmsEjb/wenrgise/hrms/webtier/action/HrmGenLoginAction.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package wenrgise.hrms.webtier.action;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import javax.ejb.CreateException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.apache.struts.action.Action;
|
||||
import org.apache.struts.action.ActionForm;
|
||||
import org.apache.struts.action.ActionForward;
|
||||
import org.apache.struts.action.ActionMapping;
|
||||
import wenrgise.common.bean.EmpInfoBean;
|
||||
import wenrgise.common.businessdelegate.SecurityBD;
|
||||
import wenrgise.common.exception.EnrgiseSystemException;
|
||||
import wenrgise.common.utility.ServiceLocator;
|
||||
import wenrgise.common.utility.UserInfo;
|
||||
import wenrgise.ejb.common.session.UserSession;
|
||||
import wenrgise.ejb.common.session.UserSessionHome;
|
||||
import wenrgise.ejb.common.utility.ParamUtil;
|
||||
import wenrgise.hrms.ejb.facade.HrmFacade;
|
||||
import wenrgise.hrms.ejb.facade.HrmFacadeHome;
|
||||
import wenrgise.hrms.ejb.facade.HrmSecondFacade;
|
||||
import wenrgise.hrms.ejb.facade.HrmSecondFacadeHome;
|
||||
import wenrgise.hrms.ejb.facade.HrmThirdFacade;
|
||||
import wenrgise.hrms.ejb.facade.HrmThirdFacadeHome;
|
||||
import wenrgise.hrms.webtier.form.HrmBaseForm;
|
||||
|
||||
public class HrmGenLoginAction extends Action {
|
||||
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
String sEmpId = null;
|
||||
String sSiteId = null;
|
||||
if (null != cookies)
|
||||
for (int i = 0; i < cookies.length; i++) {
|
||||
if ("EmpId".equals(cookies[i].getName()))
|
||||
sEmpId = cookies[i].getValue();
|
||||
if ("SiteId".equals(cookies[i].getName()))
|
||||
sSiteId = cookies[i].getValue();
|
||||
}
|
||||
HttpSession oSes = request.getSession();
|
||||
HrmBaseForm oBaseForm = new HrmBaseForm();
|
||||
oBaseForm.setEmpId(sEmpId);
|
||||
try {
|
||||
populateUserInfo(sEmpId, sSiteId, oSes);
|
||||
} catch (EnrgiseSystemException enrgiseSystemException) {}
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
|
||||
private UserInfo populateUserInfo(String sEmpId, String sSiteId, HttpSession session) throws EnrgiseSystemException {
|
||||
UserInfo oUserInfo = new UserInfo();
|
||||
try {
|
||||
UserSession oUser = (UserSession)session.getAttribute(ParamUtil.getSessionBeanName());
|
||||
if (oUser == null) {
|
||||
UserSessionHome oUserHome = (UserSessionHome)ServiceLocator.getLocator().getService("HrmUserSession");
|
||||
oUser = oUserHome.create();
|
||||
HrmFacadeHome oHome = (HrmFacadeHome)ServiceLocator.getLocator().getService("HrmFacade");
|
||||
HrmFacade oHrmFacade = oHome.create();
|
||||
oUserInfo = oHrmFacade.getLoginUserInfo(sEmpId, sSiteId);
|
||||
oUser.setUserInfo(oUserInfo);
|
||||
HrmSecondFacadeHome oSecHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
|
||||
HrmSecondFacade oSecHrmFacade = oSecHome.create();
|
||||
HrmThirdFacadeHome oThirdHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
|
||||
HrmThirdFacade oThirdFacade = oThirdHome.create();
|
||||
HashMap oMap = new HashMap();
|
||||
oMap.put(ParamUtil.getModuleName(), oHrmFacade);
|
||||
oMap.put("SecHRMS", oSecHrmFacade);
|
||||
oMap.put("ThirdHRMS", oThirdFacade);
|
||||
oUser.setModuleFacade(oMap);
|
||||
session.setAttribute(ParamUtil.getSessionBeanName(), oUser);
|
||||
EmpInfoBean oEmpInfoBean = new EmpInfoBean();
|
||||
oEmpInfoBean.setModuleId("8");
|
||||
oEmpInfoBean.setEmpId(oUserInfo.getUserTypeId());
|
||||
SecurityBD oSecurityBD = new SecurityBD();
|
||||
ArrayList menu = oSecurityBD.getTreeSet(oEmpInfoBean);
|
||||
HashMap secMap = oSecurityBD.getAccessInfo(oEmpInfoBean);
|
||||
oUser.setAccessInfo(secMap);
|
||||
session.setAttribute("menuList", menu);
|
||||
session.setAttribute("userId", sEmpId);
|
||||
}
|
||||
} catch (RemoteException oRmt) {
|
||||
oRmt.printStackTrace();
|
||||
throw new EnrgiseSystemException();
|
||||
} catch (CreateException oCrt) {
|
||||
oCrt.printStackTrace();
|
||||
throw new EnrgiseSystemException();
|
||||
} catch (Exception oExCc) {
|
||||
oExCc.printStackTrace();
|
||||
throw new EnrgiseSystemException();
|
||||
}
|
||||
return oUserInfo;
|
||||
}
|
||||
|
||||
private String getUserId(String sEmpId) {
|
||||
return null;
|
||||
}
|
||||
}
|
110
hrmsEjb/wenrgise/hrms/webtier/action/ReportViewerAction.java
Normal file
110
hrmsEjb/wenrgise/hrms/webtier/action/ReportViewerAction.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package wenrgise.hrms.webtier.action;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.sql.DataSource;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JRRuntimeException;
|
||||
import net.sf.jasperreports.engine.JasperFillManager;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
import net.sf.jasperreports.engine.JasperReport;
|
||||
import net.sf.jasperreports.engine.util.JRLoader;
|
||||
import org.apache.struts.action.ActionForm;
|
||||
import org.apache.struts.action.ActionForward;
|
||||
import org.apache.struts.action.ActionMapping;
|
||||
import wenrgise.common.exception.EnrgiseApplicationException;
|
||||
import wenrgise.common.exception.EnrgiseSystemException;
|
||||
import wenrgise.common.utility.ServiceLocator;
|
||||
import wenrgise.common.webtier.action.BaseAction;
|
||||
import wenrgise.hrms.webtier.form.JasperReportForm;
|
||||
|
||||
public class ReportViewerAction extends BaseAction {
|
||||
private String sDbName = "jdbc/conDS";
|
||||
|
||||
public ActionForward executeImpl(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse response) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException {
|
||||
JasperReportForm oForm = (JasperReportForm)form;
|
||||
req.setAttribute("reportBody", createJasperPrint(req, oForm));
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
|
||||
protected JasperPrint createJasperPrint(HttpServletRequest req, JasperReportForm form) {
|
||||
Map reportParams = null;
|
||||
if (null != form)
|
||||
reportParams = prepareReportInput(req, form);
|
||||
createReportFileName(req, reportParams);
|
||||
String repPath = req.getParameter("reportPath");
|
||||
System.out.println(String.valueOf("Report Path is ..").concat(String.valueOf(repPath)));
|
||||
File reportFile = new File(req.getSession(false).getServletContext().getRealPath(repPath));
|
||||
if (!reportFile.exists())
|
||||
throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first.");
|
||||
JasperReport jasperReport = null;
|
||||
try {
|
||||
jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());
|
||||
} catch (JRException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Exception while loading the report", e);
|
||||
}
|
||||
if (null == jasperReport)
|
||||
throw new RuntimeException(String.valueOf("Report not found in Path ").concat(String.valueOf(repPath)));
|
||||
if (null == reportParams)
|
||||
reportParams = new HashMap(2, 1.0F);
|
||||
reportParams.put("ReportTitle", req.getParameter("title"));
|
||||
reportParams.put("BaseDir", reportFile.getParentFile());
|
||||
reportParams.put("SUBREPORT_DIR", reportFile.getParentFile().getAbsolutePath());
|
||||
Connection conn = null;
|
||||
JasperPrint jasperPrint = null;
|
||||
try {
|
||||
Object dataSourceObj = ServiceLocator.getLocator().getLocalService(this.sDbName);
|
||||
DataSource oDataSource = (DataSource)dataSourceObj;
|
||||
conn = oDataSource.getConnection();
|
||||
jasperPrint = JasperFillManager.fillReport(jasperReport, reportParams, conn);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Exception while filling the report with data", e);
|
||||
} finally {
|
||||
if (null != conn)
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Exception while closing Connection ", e);
|
||||
}
|
||||
}
|
||||
return jasperPrint;
|
||||
}
|
||||
|
||||
private void createReportFileName(HttpServletRequest req, Map reportParams) {
|
||||
StringBuffer fileName = new StringBuffer("attachment; filename=\"");
|
||||
String repPath = req.getParameter("reportPath");
|
||||
String reportName = req.getParameter("reportName");
|
||||
if ("C".equalsIgnoreCase(req.getParameter("DOWNLOAD"))) {
|
||||
fileName.append(reportName);
|
||||
fileName.append(".csv\"");
|
||||
} else if ("T".equalsIgnoreCase(req.getParameter("DOWNLOAD"))) {
|
||||
fileName.append(reportName);
|
||||
fileName.append(".txt\"");
|
||||
} else if ("P".equalsIgnoreCase(req.getParameter("DOWNLOAD"))) {
|
||||
fileName.append(reportName);
|
||||
fileName.append(".pdf\"");
|
||||
} else if ("E".equalsIgnoreCase(req.getParameter("DOWNLOAD"))) {
|
||||
fileName.append(reportName);
|
||||
fileName.append(".xls\"");
|
||||
} else {
|
||||
fileName.append(reportName);
|
||||
fileName.append(".html\"");
|
||||
}
|
||||
req.setAttribute("fileName", fileName.toString());
|
||||
}
|
||||
|
||||
protected Map prepareReportInput(HttpServletRequest req, JasperReportForm form) {
|
||||
Map reportInput = (Map)form.getData(req);
|
||||
return reportInput;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user