附录
(1)
Struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="LoginForm" type="issuecontrol.actionform.LoginForm" />
<form-bean name="NewUserForm" type="issuecontrol.actionform.NewUserForm"/>
<form-bean name="BaseForm" type="issuecontrol.actionform.BaseForm"/>
<form-bean name="loginActionForm" type="issuecontrol.actionform.LoginActionForm" />
<form-bean name="componentActionForm" type="issuecontrol.actionform.ComponentActionForm" />
<form-bean name="environmentActionForm" type="issuecontrol.actionform.EnvironmentActionForm" />
<form-bean name="flagActionForm" type="issuecontrol.actionform.FlagActionForm" />
<form-bean name="issueActionForm" type="issuecontrol.actionform.IssueActionForm" />
<form-bean name="logActionForm" type="issuecontrol.actionform.LogActionForm" />
<form-bean name="priorityActionForm" type="issuecontrol.actionform.PriorityActionForm" />
<form-bean name="typeActionForm" type="issuecontrol.actionform.TypeActionForm" />
<form-bean name="issueDataActionForm" type="issuecontrol.actionform.IssueDataActionForm"/>
</form-beans>
<global-forwards>
<forward name="loginSuccess" path="/main.jsp" />
<forward name="newUser" path="/newUser.jsp"/>
<forward name="updateUser" path="/newUser.jsp"/>
<forward name="deleteUser" path="/deleteUser.jsp"/>
<forward name="login" path="/index.jsp"/>
<forward name="success" path="/message.jsp"/>
<forward name="operationSuccess" path="/Success.jsp" />
<forward name="error" path="/error.jsp"/>
<forward name="viewUser" path="/viewUser.jsp"/>
</global-forwards>
<action-mappings>
<action name="LoginForm" type="issuecontrol.action.MainAction" validate="true" scope="session" input="/index.jsp" path="/login" />
<action path="/newUser" name="BaseForm" type="issuecontrol.action.MainAction" validate="false" scope="request" input="/main.jsp"/>
<action path="/doNewUser" name="NewUserForm" type="issuecontrol.action.MainAction" validate="true" scope="request" input="/newUser.jsp"/>
<action path="/viewUser" name="BaseForm" type="issuecontrol.action.MainAction" validate="false" scope="request" input="/main.jsp"/>
<action path="/updateUser" name="BaseForm" type="issuecontrol.action.MainAction" validate="false" scope="request" input="/viewUser.jsp"/>
<action path="/doUpdateUser" name="NewUserForm" type="issuecontrol.action.MainAction" validate="true" scope="request" input="/newUser.jsp"/>
<action path="/deleteUser" name="BaseForm" type="issuecontrol.action.MainAction" validate="false" scope="request" input="/viewUser.jsp"/>
<action path="/doDeleteUser" name="BaseForm" type="issuecontrol.action.MainAction" validate="false" scope="request" input="/deleteUser.jsp"/>
<action name="issueActionForm" type="issuecontrol.action.IssueAction" validate="false" scope="request" path="/issueAction">
<forward name="viewIssue" path="/IssueList.jsp" />
<forward name="viewIssueDetail" path="/IssueDetail.jsp" />
<forward name="issueData" path="/IssueData.jsp" />
</action>
<action name="issueDataActionForm" type="issuecontrol.action.IssueAction" validate="false" scope="request" path="/issueDataAction"/>
</action-mappings>
<message-resources parameter="/ApplicationResources"/>
</struts-config>
(2)
IssueAction.java
package issuecontrol.action;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import issuecontrol.actionform.*;
import java.util.Locale;
import org.apache.struts.util.MessageResources;
import issuecontrol.model.*;
import issuecontrol.objects.*;
import issuecontrol.view.*;
import java.util.*;
import java.text.DateFormat;
public class IssueAction extends Action {
public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
String action = "view";
if(httpServletRequest.getParameter("action")!=null) action = httpServletRequest.getParameter("action").trim();
String viewPage=httpServletRequest.getParameter("viewPage");
ArrayList runningErrors = new ArrayList();
int pageNum=1;
String address = "viewIssue";
//
查看所有的
Issue
if(("view".equals(action)) || (action == null)) {
address = "viewIssue";
if((viewPage!= null)&&(viewPage.length()!= 0)){
pageNum = Integer.parseInt(viewPage);
}
int pageSize=8;
//1.
先进行参数分析
//2.
下面调用逻辑层方法得到显示的对象
PageView selectPageView=IssueBean.getIssueByPage(new Page(pageNum,pageSize));
//3.
放到
request
中然后转发
httpServletRequest.setAttribute("items",selectPageView.getItems());
httpServletRequest.setAttribute("selectPageView",selectPageView);
httpServletRequest.setAttribute("action",action);
}
//
查看单个
Issue
及其
IssueDatas
和
ChangeLogs
else if("viewDetail".equals(action)) {
String issueId = "";
if(httpServletRequest.getParameter("issueId")!=null) issueId = httpServletRequest.getParameter("issueId").trim();
IssueActionForm issueActionForm = IssueBean.getIssueById(issueId);
if(issueActionForm == null) {
runningErrors.add(new ActionError("Issue(IssueID=" + issueId + ") not found."));
httpServletRequest.setAttribute("runningErrors",runningErrors);
address = "error";
}
else {
httpServletRequest.setAttribute("issueActionForm",issueActionForm);
issueActionForm.setActionType(action);
address = "viewIssueDetail";
}
}
//
新建一个
Issue
else if("create".equals(action)) {
address = "viewIssueDetail";
httpServletRequest.setAttribute("typeActionForms",IssueBean.getAllTypes());
httpServletRequest.setAttribute("componentActionForms",IssueBean.getAllComponents());
httpServletRequest.setAttribute("flagActionForms",IssueBean.getAllFlags());
httpServletRequest.setAttribute("environmentActionForms",IssueBean.getAllEnvironments());
httpServletRequest.setAttribute("priorityActionForms",IssueBean.getAllPriorities());
httpServletRequest.setAttribute("forward","/issueAction.do?action=save");
}
//
编辑已有的
Issue
else if("edit".equals(action)) {
address = "viewIssueDetail";
String issueId = "";
if(httpServletRequest.getParameter("issueId") != null) issueId = httpServletRequest.getParameter("issueId").trim();
IssueActionForm issueActionForm = IssueBean.getIssueById(issueId);
if(issueActionForm == null) {
runningErrors.add(new ActionError("Issue(IssueID=" + issueId + ") not found."));
httpServletRequest.setAttribute("runningErrors",runningErrors);
address = "error" ;
}
else {
address = "viewIssueDetail";
issueActionForm.setActionType(action);
httpServletRequest.setAttribute("issueActionForm",issueActionForm);
httpServletRequest.setAttribute("typeActionForms",IssueBean.getAllTypes());
httpServletRequest.setAttribute("componentActionForms",IssueBean.getAllComponents());
httpServletRequest.setAttribute("flagActionForms",IssueBean.getAllFlags());
httpServletRequest.setAttribute("environmentActionForms",IssueBean.getAllEnvironments());
httpServletRequest.setAttribute("priorityActionForms",IssueBean.getAllPriorities());
httpServletRequest.setAttribute("forward","/issueAction.do?action=update");
}
}
//
删除对应的
Issue
else if("delete".equals(action)) {
String issueId = "";
if(httpServletRequest.getParameter("issueId")!=null) issueId = httpServletRequest.getParameter("issueId").trim();
IssueBean.delIssueById(issueId);
httpServletRequest.setAttribute("message","Issue(IssueID="+issueId+") have been deleted.");
address = "operationSuccess";
}
//
保存新建的
Issue
else if("save".equals(action)) {
IssueActionForm issueActionForm = (IssueActionForm)actionForm;
String type = issueActionForm.getActionType();
if(type.equals("")) type = "create";
if("create".equals(type) || "".equals(type)) {
IssueBean.addOneIssue(issueActionForm);
httpServletRequest.setAttribute("message","New Issue(IssueID=" + issueActionForm.getIssueId()+ ") have been created.");
}
else if("edit".equals(type)) {
IssueBean.updateIssue(issueActionForm);
httpServletRequest.setAttribute("message","New Issue(IssueID=" + issueActionForm.getIssueId()+ ") have been updated.");
}
address = "operationSuccess";
}
//
新建
IssueData
else if("createIssueData".equals(action)) {
String issueId = "";
if(httpServletRequest.getParameter("issueId")!=null)
issueId = httpServletRequest.getParameter("issueId");
IssueActionForm issueActionForm = IssueBean.getIssueById(issueId);
if(issueActionForm == null) {
runningErrors.add(new ActionError("Issue(IssueID=" + issueId + ") not found."));
httpServletRequest.setAttribute("runningErrors",runningErrors);
address = "error" ;
}
else {
address = "issueData";
DateFormat dateFormat = DateFormat.getInstance();
IssueDataActionForm issueDataActionForm = new IssueDataActionForm();
issueDataActionForm.setActionType(action);
issueDataActionForm.setStartDay(ExtendCalendar.getDate("yyyy/MM/dd"));
String name = (String)httpServletRequest.getSession().getAttribute("userName");
UserBean userBean = new UserBean();
try {
NewUserForm userForm = userBean.getUserByName(name);
httpServletRequest.setAttribute("userForm",userForm);
}
catch (Exception ex) {
System.out.println("Exception:" + ex.getMessage());
}
httpServletRequest.setAttribute("issueActionForm",issueActionForm);
httpServletRequest.setAttribute("issueDataActionForm",issueDataActionForm);
httpServletRequest.setAttribute("priorityActionForms",IssueBean.getAllPriorities());
httpServletRequest.setAttribute("flagActionForms",IssueBean.getAllFlags());
}
}
//
保存新建的
IssueData
else if("saveIssueData".equals(action)) {
IssueDataActionForm issueDataActionForm = (IssueDataActionForm)actionForm;
String type = issueDataActionForm.getActionType();
if(type.equals("") || (type==null)) type = "createIssueData";
if("createIssueData".equals(type)) {
issueDataActionForm.setUser(httpServletRequest.getParameter("userName"));
issueDataActionForm.setUserId(httpServletRequest.getParameter("userId"));
issueDataActionForm.setIssueId(httpServletRequest.getParameter("issueId"));
IssueBean.addOneIssueData(issueDataActionForm);
httpServletRequest.setAttribute("message","New IssueData have been created.");
address = "operationSuccess";
}
else if("editIssueData".equals(type)) {
IssueBean.updateIssueData(issueDataActionForm);
LogActionForm logActionForm = new LogActionForm();
logActionForm.setChangeTo(issueDataActionForm.getEndDay());
logActionForm.setIssueId(issueDataActionForm.getIssueId());
logActionForm.setOriginal(httpServletRequest.getParameter("original"));
logActionForm.setReason(httpServletRequest.getParameter("reason"));
logActionForm.setUser(issueDataActionForm.getUserId());
httpServletRequest.setAttribute("message","IssueData have been updated.");
address = "operationSuccess";
}
}
//
编辑
IssueData
else if("editIssueData".equals(action)) {
String issueDataId = "";
if(httpServletRequest.getParameter("issueDataId")!=null)
issueDataId = httpServletRequest.getParameter("issueDataId");
IssueDataActionForm issueDataActionForm = IssueBean.getIssueDataById(issueDataId);
if(issueDataActionForm!=null) {
address = "issueData";
issueDataActionForm.setActionType(action);
LogActionForm logActionForm = new LogActionForm();
logActionForm.setIssueId(issueDataActionForm.getIssueId());
logActionForm.setOriginal(issueDataActionForm.getEndDay());
httpServletRequest.setAttribute("logActionForm",logActionForm);
IssueActionForm issueActionForm = IssueBean.getIssueById(issueDataActionForm.getIssueId());
if(issueActionForm!=null) httpServletRequest.setAttribute("issueActionForm",issueActionForm);
httpServletRequest.setAttribute("issueDataActionForm",issueDataActionForm);
httpServletRequest.setAttribute("priorityActionForms",IssueBean.getAllPriorities());
httpServletRequest.setAttribute("flagActionForms",IssueBean.getAllFlags());
}
else {
runningErrors.add(new ActionError("IssueData(IssueDataID=" + issueDataId + ") not found."));
httpServletRequest.setAttribute("runningErrors",runningErrors);
address = "error";
}
}
//
删除
IssueData
else if("deleteIssueData".equals(action)) {
String issueDataId = "";
if(httpServletRequest.getParameter("issueDataId")!=null) {
issueDataId = httpServletRequest.getParameter("issueDataId");
IssueBean.delOneIssueData(issueDataId);
httpServletRequest.setAttribute("message","The issueData has been deleted.");
address = "operationSuccess";
}
else {
runningErrors.add(new ActionError("IssueData(IssueDataID=" + issueDataId + ") not found."));
httpServletRequest.setAttribute("runningErrors",runningErrors);
address = "error";
}
}
return actionMapping.findForward(address);
}
}
(3)
IssueBean.java
package issuecontrol.model;
/**
* Issue
操作类
*/
import net.sf.hibernate.*;
import issuecontrol.objects.*;
import java.util.*;
import issuecontrol.view.*;
import issuecontrol.actionform.*;
import java.util.ArrayList;
public class IssueBean {
public static PageView getIssueByPage(Page thepage) {
Page selectPage = null;
try {
IssueDAO issueDAO= (IssueDAO) DAOFactory.getInstance("IssueDAO");
selectPage = issueDAO.getIssueByPage(thepage);
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("Exception:" + ex.getMessage());
}
ArrayList items=new ArrayList(selectPage.getItems());
for(int i=0;i<items.size();i++)
{
IssueView theissueview=new IssueView((Issue)items.get(i));
items.set(i,theissueview);
}
PageView selectPageView=new PageView(selectPage);
selectPageView.setItems(items);
return selectPageView;
}
public static void addOneIssue(IssueActionForm issueActionForm) {
try {
Issue addIssue = new Issue();
IssueDAO issueDAO= (IssueDAO) DAOFactory.getInstance("IssueDAO");
addIssue.setComponent(issueDAO.getComponentById(Long.valueOf(issueActionForm.getComponentId())));
addIssue.setDescription(issueActionForm.getDescription());
addIssue.setEnvironment(issueDAO.getEnvironmentById(Long.valueOf(issueActionForm.getEnvironmentId())));
addIssue.setFlag(issueDAO.getFlagById(Long.valueOf(issueActionForm.getFlagId())));
addIssue.setIssueId(issueActionForm.getIssueId());
addIssue.setPriority(issueDAO.getPriorityById(Long.valueOf(issueActionForm.getPriorityId())));
addIssue.setTitle(issueActionForm.getTitle());
addIssue.setType(issueDAO.getTypeById(Long.valueOf(issueActionForm.getTypeId())));
issueDAO.addIssue(addIssue);
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
}
public static void addOneIssueData(IssueDataActionForm issueDataActionForm) {
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
UserDAO userDAO = (UserDAO)DAOFactory.getInstance("UserDAO");
Issue selectIssue = issueDAO.getIssueById(issueDataActionForm.getIssueId());
Issuedata addIssueData = new Issuedata();
if(issueDataActionForm.getEndDay()!=null) addIssueData.setEndDay(new Date(issueDataActionForm.getEndDay()));
if(issueDataActionForm.getFlagId()!=null) addIssueData.setFlag(issueDAO.getFlagById(Long.valueOf(issueDataActionForm.getFlagId())));
if(issueDataActionForm.getIssueId()!=null) addIssueData.setIssue(issueDAO.getIssueById(issueDataActionForm.getIssueId()));
if(issueDataActionForm.getPriorityId()!=null) addIssueData.setPriority(issueDAO.getPriorityById(Long.valueOf(issueDataActionForm.getPriorityId())));
if(issueDataActionForm.getStartDay()!=null) addIssueData.setStartDay(new Date(issueDataActionForm.getStartDay()));
if(issueDataActionForm.getSubmitDay()!=null) addIssueData.setSubmitDay(new Date(issueDataActionForm.getSubmitDay()));
if(issueDataActionForm.getUserId()!=null) addIssueData.setUser(userDAO.getUserById(Long.valueOf(issueDataActionForm.getUserId())));
issueDAO.addOneIssueData(selectIssue,addIssueData);
DAOFactory.returnInstance();
}
catch(Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
}
public static void addOneLog(IssueActionForm issueActionForm,LogActionForm logActionForm) {
try {
IssueDAO issueDAO= (IssueDAO) DAOFactory.getInstance("IssueDAO");
Issue theIssue = issueDAO.getIssueById(issueActionForm.getIssueId());
Log theLog = new Log();
theLog.setIssue(issueDAO.getIssueById(issueActionForm.getIssueId()));
theLog.setReason(logActionForm.getReason());
issueDAO.addOneLog(theIssue, theLog);
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
}
public static void delIssueById(String issueId) {
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
issueDAO.delIssueById(issueId);
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
}
public static void delOneIssueData(String issueDataId) {
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
issueDAO.delOneIssueData(Long.valueOf(issueDataId));
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
}
public static void delOneLog(String logId) {
try{
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
issueDAO.delOneLog(Long.valueOf(logId));
DAOFactory.returnInstance();
}catch(Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
}
public static IssueActionForm getIssueById(String issueId) {
IssueActionForm issueActionForm = new IssueActionForm();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Issue selectIssue = issueDAO.getIssueById(issueId);
issueActionForm.setComponent(selectIssue.getComponent().getComponent());
issueActionForm.setComponentId(String.valueOf(selectIssue.getComponent().getComponentId()));
issueActionForm.setDescription(selectIssue.getDescription());
issueActionForm.setEnvironment(selectIssue.getEnvironment().getEnvironment());
issueActionForm.setEnvironmentId(String.valueOf(selectIssue.getEnvironment().getEnvironmentId()));
issueActionForm.setFlag(selectIssue.getFlag().getFlag());
issueActionForm.setFlagId(String.valueOf(selectIssue.getFlag().getFlagId()));
issueActionForm.setIssueId(selectIssue.getIssueId());
issueActionForm.setPriority(selectIssue.getPriority().getPriority());
issueActionForm.setPriorityId(String.valueOf(selectIssue.getPriority().getPriorityId()));
issueActionForm.setTitle(selectIssue.getTitle());
issueActionForm.setType(selectIssue.getType().getType());
issueActionForm.setTypeId(String.valueOf(selectIssue.getType().getTypeId()));
if(selectIssue.getIssueDatas()!=null) {
Issuedata[] issuedatas = (Issuedata[])selectIssue.getIssueDatas().toArray(new Issuedata[0]);
for(int i=0;i<issuedatas.length;i++) {
IssueDataActionForm issueDataActionForm = new IssueDataActionForm();
issueDataActionForm.setEndDay(String.valueOf(issuedatas[i].getEndDay()));
issueDataActionForm.setFlag(issuedatas[i].getFlag().getFlag());
issueDataActionForm.setId(String.valueOf(issuedatas[i].getId()));
issueDataActionForm.setIssueId(issuedatas[i].getIssueId());
issueDataActionForm.setPriority(issuedatas[i].getPriority().getPriority());
issueDataActionForm.setStartDay(String.valueOf(issuedatas[i].getStartDay()));
issueDataActionForm.setSubmitDay(String.valueOf(issuedatas[i].getSubmitDay()));
issueDataActionForm.setUser(issuedatas[i].getUser().getName());
issueActionForm.getIssueDatas().add(issueDataActionForm);
}
}
if(selectIssue.getLogs()!=null) {
Log[] logs = (Log[])selectIssue.getLogs().toArray(new Log[0]);
for(int i=0;i<logs.length;i++) {
LogActionForm logActionForm = new LogActionForm();
logActionForm.setChangeTo(logs[i].getChangeTo().toString());
logActionForm.setId(String.valueOf(logs[i].getId()));
logActionForm.setIssueId(logs[i].getIssue().getIssueId());
logActionForm.setOriginal(logs[i].getOriginal().toString());
logActionForm.setReason(logs[i].getReason());
logActionForm.setUser(logs[i].getUser().getName());
issueActionForm.getLogDatas().add(logActionForm);
}
}
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
return null;
}
return issueActionForm;
}
public static TypeActionForm getTypeById(String typeId) {
TypeActionForm typeActionForm = new TypeActionForm();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Type selectType = issueDAO.getTypeById(Long.valueOf(typeId));
typeActionForm.setType(selectType.getType());
typeActionForm.setTypeId(String.valueOf(selectType.getTypeId()));
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return typeActionForm;
}
public static ComponentActionForm getComponentById(String componentId) {
ComponentActionForm componentActionForm = new ComponentActionForm();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Component selectComponent = issueDAO.getComponentById(Long.valueOf(componentId));
componentActionForm.setComponent(selectComponent.getComponent());
componentActionForm.setComponentId(String.valueOf(selectComponent.getComponentId()));
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return componentActionForm;
}
public static FlagActionForm getFlagById(String flagId) {
FlagActionForm flagActionForm = new FlagActionForm();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Flag selectFlag = issueDAO.getFlagById(Long.valueOf(flagId));
flagActionForm.setFlag(selectFlag.getFlag());
flagActionForm.setFlagId(String.valueOf(selectFlag.getFlagId()));
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return flagActionForm;
}
public static EnvironmentActionForm getEnvironmentById(String environmentId) {
EnvironmentActionForm environmentAcrionForm = new EnvironmentActionForm();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Environment selectEnvironment = issueDAO.getEnvironmentById(Long.valueOf(environmentId));
environmentAcrionForm.setEnvironment(selectEnvironment.getEnvironment());
environmentAcrionForm.setEnvironmentId(String.valueOf(selectEnvironment.getEnvironmentId()));
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return environmentAcrionForm;
}
public static PriorityActionForm getPriorityById(String priorityId) {
PriorityActionForm priorityActionForm = new PriorityActionForm();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Priority selectPriority = issueDAO.getPriorityById(Long.valueOf(priorityId));
priorityActionForm.setPriority(selectPriority.getPriority());
priorityActionForm.setPriorityId(String.valueOf(selectPriority.getPriorityId()));
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return priorityActionForm;
}
public static LogActionForm getLogById(String logId) {
LogActionForm logActionForm = new LogActionForm();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Log selectLog = issueDAO.getLogById(Long.valueOf(logId));
logActionForm.setId(String.valueOf(selectLog.getId()));
logActionForm.setIssueId(String.valueOf(selectLog.getIssue().getIssueId()));
logActionForm.setOriginal(selectLog.getOriginal().toString());
logActionForm.setReason(selectLog.getReason());
logActionForm.setUser(String.valueOf(selectLog.getUser().getUserId()));
logActionForm.setChangeTo(selectLog.getChangeTo().toString());
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return logActionForm;
}
public static ComponentActionForm[] getAllComponents() {
Collection collection = new ArrayList();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Iterator iterator = issueDAO.getAllComponents().iterator();
DAOFactory.returnInstance();
while(iterator.hasNext()) {
Component selectComponent = (Component)iterator.next();
ComponentActionForm componentActionForm = new ComponentActionForm();
componentActionForm.setComponent(selectComponent.getComponent());
componentActionForm.setComponentId(String.valueOf(selectComponent.getComponentId()));
collection.add(componentActionForm);
}
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return (ComponentActionForm[])collection.toArray(new ComponentActionForm[0]);
}
public static EnvironmentActionForm[] getAllEnvironments() {
Collection collection = new ArrayList();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Iterator iterator = issueDAO.getAllEnvironments().iterator();
DAOFactory.returnInstance();
while(iterator.hasNext()) {
Environment selectEnvironment = (Environment)iterator.next();
EnvironmentActionForm environmentActionForm = new EnvironmentActionForm();
environmentActionForm.setEnvironment(selectEnvironment.getEnvironment());
environmentActionForm.setEnvironmentId(String.valueOf(selectEnvironment.getEnvironmentId()));
collection.add(environmentActionForm);
}
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return (EnvironmentActionForm[])collection.toArray(new EnvironmentActionForm[0]);
}
public static FlagActionForm[] getAllFlags() {
Collection collection = new ArrayList();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Iterator iterator = issueDAO.getAllFlags().iterator();
DAOFactory.returnInstance();
while(iterator.hasNext()) {
Flag selectFlag = (Flag)iterator.next();
FlagActionForm flagActionForm = new FlagActionForm();
flagActionForm.setFlag(selectFlag.getFlag());
flagActionForm.setFlagId(String.valueOf(selectFlag.getFlagId()));
collection.add(flagActionForm);
}
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return (FlagActionForm[])collection.toArray(new FlagActionForm[0]);
}
public static PriorityActionForm[] getAllPriorities() {
Collection collection = new ArrayList();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Iterator iterator = issueDAO.getAllPrioritys().iterator();
DAOFactory.returnInstance();
while(iterator.hasNext()) {
Priority selectPriority = (Priority)iterator.next();
PriorityActionForm priorityActionForm = new PriorityActionForm();
priorityActionForm.setPriority(selectPriority.getPriority());
priorityActionForm.setPriorityId(String.valueOf(selectPriority.getPriorityId()));
collection.add(priorityActionForm);
}
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return (PriorityActionForm[])collection.toArray(new PriorityActionForm[0]);
}
public static TypeActionForm[] getAllTypes() {
Collection collection = new ArrayList();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Iterator iterator = issueDAO.getAllTypes().iterator();
DAOFactory.returnInstance();
while(iterator.hasNext()) {
Type selectType = (Type)iterator.next();
TypeActionForm typeActionForm = new TypeActionForm();
typeActionForm.setType(selectType.getType());
typeActionForm.setTypeId(String.valueOf(selectType.getTypeId()));
collection.add(typeActionForm);
}
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return (TypeActionForm[])collection.toArray(new TypeActionForm[0]);
}
public static void updateIssue(IssueActionForm issueActionForm) {
try {
IssueDAO issueDAO= (IssueDAO) DAOFactory.getInstance("IssueDAO");
Issue updateIssue = issueDAO.getIssueById(issueActionForm.getIssueId());
updateIssue.setComponent(issueDAO.getComponentById(Long.valueOf(issueActionForm.getComponentId())));
updateIssue.setDescription(issueActionForm.getDescription());
updateIssue.setEnvironment(issueDAO.getEnvironmentById(Long.valueOf(issueActionForm.getEnvironmentId())));
updateIssue.setFlag(issueDAO.getFlagById(Long.valueOf(issueActionForm.getFlagId())));
updateIssue.setPriority(issueDAO.getPriorityById(Long.valueOf(issueActionForm.getPriorityId())));
updateIssue.setTitle(issueActionForm.getTitle());
updateIssue.setType(issueDAO.getTypeById(Long.valueOf(issueActionForm.getTypeId())));
issueDAO.updateIssue(updateIssue);
DAOFactory.returnInstance();
}
catch (Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
}
public static IssueDataActionForm getIssueDataById(String issueDataId) {
IssueDataActionForm issueDataActionForm = new IssueDataActionForm();
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
Issuedata selectIssuedata = issueDAO.getIssueDataById(Long.valueOf(issueDataId));
issueDataActionForm.setEndDay(String.valueOf(selectIssuedata.getEndDay()));
issueDataActionForm.setFlag(selectIssuedata.getFlag().getFlag());
issueDataActionForm.setFlagId(String.valueOf(selectIssuedata.getFlag().getFlagId()));
issueDataActionForm.setId(String.valueOf(selectIssuedata.getId()));
issueDataActionForm.setIssueId(selectIssuedata.getIssue().getIssueId());
issueDataActionForm.setPriority(selectIssuedata.getPriority().getPriority());
issueDataActionForm.setPriorityId(String.valueOf(selectIssuedata.getPriority().getPriorityId()));
issueDataActionForm.setStartDay(String.valueOf(selectIssuedata.getStartDay()));
issueDataActionForm.setSubmitDay(String.valueOf(selectIssuedata.getSubmitDay()));
issueDataActionForm.setUser(selectIssuedata.getUser().getName());
issueDataActionForm.setUserId(String.valueOf(selectIssuedata.getUser().getUserId()));
DAOFactory.returnInstance();
}catch(Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
return issueDataActionForm;
}
public static void updateIssueData(IssueDataActionForm issueDataActionForm) {
try {
IssueDAO issueDAO = (IssueDAO)DAOFactory.getInstance("IssueDAO");
UserDAO userDAO = (UserDAO)DAOFactory.getInstance("UserDAO");
Issuedata issuedata = issueDAO.getIssueDataById(Long.valueOf(issueDataActionForm.getId()));
issuedata.setEndDay(new Date(issueDataActionForm.getEndDay()));
issuedata.setFlag(issueDAO.getFlagById(Long.valueOf(issueDataActionForm.getFlagId())));
issuedata.setId(Long.valueOf(issueDataActionForm.getId()));
issuedata.setIssue(issueDAO.getIssueById(issueDataActionForm.getIssueId()));
issuedata.setIssueId(issueDataActionForm.getIssueId());
issuedata.setPriority(issueDAO.getPriorityById(Long.valueOf(issueDataActionForm.getPriorityId())));
issuedata.setStartDay(new Date(issueDataActionForm.getStartDay()));
issuedata.setSubmitDay(new Date(issueDataActionForm.getSubmitDay()));
issuedata.setUser(userDAO.getUserById(Long.valueOf(issueDataActionForm.getUserId())));
issueDAO.updateOneIssueData(issuedata);
DAOFactory.returnInstance();
}catch(Exception ex) {
System.out.println("HibernateException:" + ex.getMessage());
}
}
}
(4)
IssueDetail.jsp
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ page contentType="text/html; charset=GBK" %>
<template:insert template="header.jsp">
<template:put name="title">end-to-end</template:put>
</template:insert>
<center>
<table width="100%" border="0" cellpadding="1">
<TR>
<TD width="250" valign="top"><template:insert template="function.jsp"/>
</TD>
<TD><html:form action="/issueAction.do?action=save" method="POST">
<table width="100%" border="0" cellpadding="1" class="tableborder">
<tr width="100%" height="20" align="left">
<td colspan="2" class="forumHeaderBackgroundAlternate">
<html:hidden name="issueActionForm" property="actionType"/>
<logic:equal name="issueActionForm" property="actionType" value="create">
Create new issue:
</logic:equal>
<logic:equal name="issueActionForm" property="actionType" value="edit">
Edit selected issue:
</logic:equal>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
View selected issue's detail:
</logic:equal>
</td>
</tr>
<tr width="100%" height="20">
<td class="Forumrow">IssueID:</td>
<td class="Forumrow">
<logic:equal name="issueActionForm" property="actionType" value="create">
<html:text property="issueId"/>
</logic:equal>
<logic:equal name="issueActionForm" property="actionType" value="edit">
<logic:present name="issueActionForm">
<html:text name="issueActionForm" property="issueId"/>
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="issueActionForm">
<bean:write name="issueActionForm" property="issueId" />
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
</td>
</tr>
<tr width="100%" height="20">
<td class="Forumrow">Title:</td>
<td class="Forumrow">
<logic:equal name="issueActionForm" property="actionType" value="create">
<html:text property="title"/>
</logic:equal>
<logic:equal name="issueActionForm" property="actionType" value="edit">
<logic:present name="issueActionForm">
<html:text name="issueActionForm" property="title" />
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="issueActionForm">
<bean:write name="issueActionForm" property="title" />
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
</td>
</tr>
<tr width="100%" height="20">
<td class="Forumrow">Description:</td>
<td class="Forumrow">
<logic:equal name="issueActionForm" property="actionType" value="create">
<html:textarea property="description" rows="8" cols="40"/>
</logic:equal>
<logic:equal name="issueActionForm" property="actionType" value="edit">
<logic:present name="issueActionForm">
<html:textarea property="description" rows="8" cols="40"/>
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="issueActionForm">
<bean:write name="issueActionForm" property="description" />
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
</td>
</tr>
<tr width="100%" height="20">
<td class="Forumrow">Type:</td>
<td class="Forumrow">
<logic:notEqual name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="typeActionForms">
<html:select property="typeId" size="1">
<logic:iterate id="types" name="typeActionForms">
<option value="<bean:write name="types" property="typeId"/>"><bean:write name="types" property="type" /></option>
</logic:iterate>
</html:select>
</logic:present>
<logic:notPresent name="typeActionForms">
<b>Error:TypeActionForms are not present.</b>
</logic:notPresent>
</logic:notEqual>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="issueActionForm">
<bean:write name="issueActionForm" property="type" />
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
</td>
</tr>
<tr width="100%" height="20">
<td class="Forumrow">Component:</td>
<td class="Forumrow">
<logic:notEqual name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="componentActionForms">
<html:select property="componentId" size="1">
<logic:iterate id="components" name="componentActionForms">
<option value="<bean:write name="components" property="componentId"/>"><bean:write name="components" property="component" /></option>
</logic:iterate>
</html:select>
</logic:present>
<logic:notPresent name="componentActionForms">
<b>Error:ComponentActionForms are not present.</b>
</logic:notPresent>
</logic:notEqual>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="issueActionForm">
<bean:write name="issueActionForm" property="component" />
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
</td>
</tr>
<tr width="100%" height="20">
<td class="Forumrow">Environment:</td>
<td class="Forumrow">
<logic:notEqual name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="environmentActionForms">
<html:select property="environmentId" size="1">
<logic:iterate id="environments" name="environmentActionForms">
<option value="<bean:write name="environments" property="environmentId"/>"><bean:write name="environments" property="environment" /></option>
</logic:iterate>
</html:select>
</logic:present>
<logic:notPresent name="environmentActionForms">
<b>Error:EnvironmentActionFomrs are not present.</b>
</logic:notPresent>
</logic:notEqual>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="issueActionForm">
<bean:write name="issueActionForm" property="environment" />
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
</td>
</tr>
<tr width="100%" height="20">
<td class="Forumrow">Priority:</td>
<td class="Forumrow">
<logic:notEqual name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="priorityActionForms">
<html:select property="priorityId" size="1">
<logic:iterate id="priorities" name="priorityActionForms">
<option value="<bean:write name="priorities" property="priorityId"/>"><bean:write name="priorities" property="priority" /></option>
</logic:iterate>
</html:select>
</logic:present>
<logic:notPresent name="priorityActionForms">
<b>Error:PriorityActionForms are not present.</b>
</logic:notPresent>
</logic:notEqual>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="issueActionForm">
<bean:write name="issueActionForm" property="priority" />
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
</td>
</tr>
<tr width="100%" height="20">
<td class="Forumrow">Flag:</td>
<td class="Forumrow">
<logic:notEqual name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="flagActionForms">
<html:select property="flagId" size="1">
<logic:iterate id="flags" name="flagActionForms">
<option value="<bean:write name="flags" property="flagId"/>"><bean:write name="flags" property="flag" /></option>
</logic:iterate>
</html:select>
</logic:present>
<logic:notPresent name="flagActionForms">
<b>Error:FlagActionForms are not present.</b>
</logic:notPresent>
</logic:notEqual>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
<logic:present name="issueActionForm">
<bean:write name="issueActionForm" property="flag" />
</logic:present>
<logic:notPresent name="issueActionForm">
<b>Error:No issue.</b>
</logic:notPresent>
</logic:equal>
</td>
</tr>
<logic:notEqual name="issueActionForm" property="actionType" value="viewDetail">
<tr width="100%" height="20"><td class="Forumrow">
<html:submit property="submit" value="Submit"/>
<html:reset value ="Reset"/>
</td></tr>
</logic:notEqual>
</table>
</html:form>
<logic:equal name="issueActionForm" property="actionType" value="viewDetail">
<table width="100%" border="0" cellpadding="1" class="tableborder">
<logic:present name="issueActionForm" property="issueDatas">
<tr width="100%" align="left" height="20">
<th colspan="7" height="28">IssueData List:</th>
</tr>
<tr width="100%" align="center" height="20">
<td class="forumHeaderBackgroundAlternate" height="23">Priority</td>
<td class="forumHeaderBackgroundAlternate" height="23">User</td>
<td class="forumHeaderBackgroundAlternate" height="23">Flag</td>
<td class="forumHeaderBackgroundAlternate" height="23">StartDay</td>
<td class="forumHeaderBackgroundAlternate" height="23">EndDay</td>
<td class="forumHeaderBackgroundAlternate" height="23">SubmitDay</td>
<td class="forumHeaderBackgroundAlternate" height="23"> </td>
</tr>
<logic:iterate id="issueData" name="issueActionForm" property="issueDatas">
<tr width="100%" align="center" height="20">
<td class="Forumrow"><bean:write name="issueData" property="priority" /></td>
<td class="Forumrow"><bean:write name="issueData" property="user" /></td>
<td class="Forumrow"><bean:write name="issueData" property="flag" /></td>
<td class="Forumrow"><bean:write name="issueData" property="startDay" /></td>
<td class="Forumrow"><bean:write name="issueData" property="endDay" /></td>
<td class="Forumrow"><bean:write name="issueData" property="submitDay" /></td>
<td class="Forumrow">
<img src="images/edit.gif" border="0" alt="edit selected issuedata">
<img src="images/delete.gif" border="0" alt="delete selected issuedata">
</td>
</tr>
</logic:iterate>
</logic:present>
<logic:notPresent name="issueActionForm" property="issueDatas" >
<tr width="100%" align="center" height="20"><td colspan="7">
<p>There is no issuedatas now.</p>
</td></tr>
</logic:notPresent>
</table>
<table width="100%" border="0" cellpadding="1" class="tableborder">
<logic:present name="issueActionForm" property="issueDatas">
<tr width="100%" align="left" height="20">
<th colspan="5" height="28">IssueChangeLog List:</th>
</tr>
<tr width="100%" align="center" height="20">
<td class="forumHeaderBackgroundAlternate" height="23">Original</td>
<td class="forumHeaderBackgroundAlternate" height="23">ChangeTo</td>
<td class="forumHeaderBackgroundAlternate" height="23">Reason</td>
<td class="forumHeaderBackgroundAlternate" height="23">User</td>
<td class="forumHeaderBackgroundAlternate" height="23"> </td>
</tr>
<logic:iterate id="logData" name="issueActionForm" property="logDatas">
<tr width="100%" align="center" height="20">
<td class="Forumrow"><bean:write name="logData" property="original" /></td>
<td class="Forumrow"><bean:write name="logData" property="changeTo" /></td>
<td class="Forumrow"><bean:write name="logData" property="reason" /></td>
<td class="Forumrow"><bean:write name="logData" property="user" /></td>
<td class="Forumrow">
<img src="images/edit.gif" border="0" alt="edit selected issuedata">
<img src="images/delete.gif" border="0" alt="delete selected issuedata">
</td>
</tr>
</logic:iterate>
</logic:present>
<logic:notPresent name="issueActionForm" property="issueDatas" >
<tr width="100%" align="center" height="20"><td colspan="5">
<p>There is no issuedatas now.</p>
</td></tr>
</logic:notPresent>
</table>
</logic:equal>
</TD>
</TR>
</table>
</center></body>
</html>
posted on 2005-01-27 14:54
eamoi 阅读(2064)
评论(2) 编辑 收藏 所属分类:
Java 、
毕业设计文档