/action/UserLoginAction-validation.xml
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="username">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="stringlength"> <param
name="minLength">6</param> <param name="maxLength">18</param>
<message key="errors.required.password.lengthLimit"></message>
</field-validator>
<!--<field-validator type="regex">
<param name="expression"><![CDATA[(\w{6,18})]]></param>
<message key="errors.required.password.lengthLimit"></message>
</field-validator>
-->
</field>
<field name="validationCode">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
</field>
</validators>/action/UserAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="ID_NO">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{1,10})]]></param>
<message key="errors.required.ID_NO.lengthLimit"></message>
</field-validator>
</field>
<field name="name">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{1,20})]]></param>
<message key="errors.required.name.lengthLimit"></message>
</field-validator>
</field>
<field name="Email">
<field-validator type="Email">
<message key="errors.Email" />
</field-validator>
</field>
</validators>/action/RequestTypeAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="name">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="stringlength">
<param name="minLength">1</param>
<param name="maxLength">25</param>
<message key="errors.requesttype.name.lengthLimit"></message>
</field-validator>
</field>
<field name="template">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="stringlength">
<param name="minLength">1</param>
<param name="maxLength">500</param>
<message key="errors.template.lengthLimit"></message>
</field-validator>
</field>
</validators>/action/RequestSubmitAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="title">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="stringlength">
<param name="minLength">1</param>
<param name="maxLength">50</param>
<message key="errors.request.title.lengthLimit"></message>
</field-validator>
</field>
</validators>/action/FeatureAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="feature.pid">
<field-validator type="required">
<message key="requiredstring" />
</field-validator>
</field>
<field name="feature.name">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
</field>
</validators>/action/ChangePasswordAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="oldPassword">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{6,18})]]></param>
<message key="errors.required.password.lengthLimit"></message>
</field-validator>
</field>
<field name="newPassword">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{6,18})]]></param>
<message key="errors.required.password.lengthLimit"></message>
</field-validator>
</field>
<field name="rePassword">
<field-validator type="fieldexpression">
<param name="expression"><![CDATA[(rePassword==newPassword)]]></param>
<message key="errors.passwordMatch" />
</field-validator>
</field>
</validators>
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="username">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="stringlength"> <param
name="minLength">6</param> <param name="maxLength">18</param>
<message key="errors.required.password.lengthLimit"></message>
</field-validator>
<!--<field-validator type="regex">
<param name="expression"><![CDATA[(\w{6,18})]]></param>
<message key="errors.required.password.lengthLimit"></message>
</field-validator>
-->
</field>
<field name="validationCode">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
</field>
</validators>/action/UserAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="ID_NO">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{1,10})]]></param>
<message key="errors.required.ID_NO.lengthLimit"></message>
</field-validator>
</field>
<field name="name">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{1,20})]]></param>
<message key="errors.required.name.lengthLimit"></message>
</field-validator>
</field>
<field name="Email">
<field-validator type="Email">
<message key="errors.Email" />
</field-validator>
</field>
</validators>/action/RequestTypeAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="name">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="stringlength">
<param name="minLength">1</param>
<param name="maxLength">25</param>
<message key="errors.requesttype.name.lengthLimit"></message>
</field-validator>
</field>
<field name="template">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="stringlength">
<param name="minLength">1</param>
<param name="maxLength">500</param>
<message key="errors.template.lengthLimit"></message>
</field-validator>
</field>
</validators>/action/RequestSubmitAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="title">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="stringlength">
<param name="minLength">1</param>
<param name="maxLength">50</param>
<message key="errors.request.title.lengthLimit"></message>
</field-validator>
</field>
</validators>/action/FeatureAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="feature.pid">
<field-validator type="required">
<message key="requiredstring" />
</field-validator>
</field>
<field name="feature.name">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
</field>
</validators>/action/ChangePasswordAction-validation.xml<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators>
<field name="oldPassword">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{6,18})]]></param>
<message key="errors.required.password.lengthLimit"></message>
</field-validator>
</field>
<field name="newPassword">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{6,18})]]></param>
<message key="errors.required.password.lengthLimit"></message>
</field-validator>
</field>
<field name="rePassword">
<field-validator type="fieldexpression">
<param name="expression"><![CDATA[(rePassword==newPassword)]]></param>
<message key="errors.passwordMatch" />
</field-validator>
</field>
</validators>
package com.augmentum.larry.action;import java.awt.image.BufferedImage;
import java.util.Map;import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;import com.augmentum.larry.util.ValidateCode;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions shows the validation code on the login page.
* @category
* @name ValidateCodeAction
* @author larry.chi
* @version 1.0
*/
@SuppressWarnings("serial")
public class ValidateCodeAction extends ActionSupport { @SuppressWarnings("unchecked")
public String execute() throws Exception { int width = 100, height = 18;
ValidateCode validateCode = new ValidateCode();
BufferedImage image = null;
String text = "";
try { text = validateCode.getContent();
} catch (InterruptedException e) { throw new InterruptedException();
}
HttpServletResponse response = (HttpServletResponse) ActionContext
.getContext().get(ServletActionContext.HTTP_RESPONSE);
image = validateCode.getBufferedImage(text, width, height);
ServletOutputStream sos = response.getOutputStream();
ImageIO.write(image, "JPEG", sos);
sos.flush();
sos.close();
Map session = ActionContext.getContext().getSession();
session.put("validateCode", text);
return SUCCESS;
}
}
package com.augmentum.larry.action;import java.util.Map;import com.augmentum.larry.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions handles user login
* @category
* @name UserLoginAction
* @author larry.chi
* @version 1.0
*/
public class UserLoginAction extends ActionSupport { /**
*
*/
private static final long serialVersionUID = 1L;
private String username;
private String password;
private String validationCode;
private UserService userService; public void setUserService(UserService userService) { this.userService = userService;
} public String getUsername() { return username;
} public void setUsername(String username) { this.username = username;
} public String getPassword() { return password;
} public void setPassword(String password) { this.password = password;
} public String getValidationCode() { return validationCode;
} public void setValidationCode(String validationCode) { this.validationCode = validationCode;
} /**
* @Descriptions Determines whether it is success for user login, if
* success,store some user message in session
*/
@SuppressWarnings("unchecked")
public String execute() throws Exception {
Map session = ActionContext.getContext().getSession();
session.put("username", getUsername());
if (getValidationCode().equalsIgnoreCase(
(String) session.get("validateCode"))) { if (userService.isLogin(getUsername(), getPassword())) { session.put("role", userService.getRole(getUsername()));
return SUCCESS;
} else { this.addActionError(getText("login.fail"));
return INPUT;
}
} else { this.addActionError(getText("login.fail"));
this
.addFieldError("validationCode",
getText("errors.validateCode"));
return INPUT;
}
}
}
package com.augmentum.larry.action;import com.augmentum.larry.model.User;
import com.augmentum.larry.service.UserService;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions handles add and update user
* @category class
* @name UserActions
* @author larry.chi
* @version 1.0
*/
public class UserAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private String ID_NO;
private String name;
private String role;
private int reportManager;
private String Email;
private final static String password = "abc123_";
private String success;
private UserService userService;
private User user;
private String errorMessage;
public String getErrorMessage() {
return errorMessage;
} public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
} public void setUser(User user) {
this.user = user;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getSuccess() {
return success;
} public void setSuccess(String success) {
this.success = success;
} public String getPassword() {
return password;
} public String getID_NO() {
return ID_NO;
} public void setID_NO(String iDNO) {
ID_NO = iDNO;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getRole() {
return role;
} public void setRole(String role) {
this.role = role;
} public int getReportManager() {
return reportManager;
} public void setReportManager(int reportManager) {
this.reportManager = reportManager;
} public String getEmail() {
return Email;
} public void setEmail(String email) {
Email = email;
} public void setUserService(UserService userService) {
this.userService = userService;
}
/**
* @Descriptions administrator add a user
* @return "success" if update success,otherwise "error"
*/
public String execute() throws Exception { user.setID_NO(getID_NO());
user.setName(getName());
user.setRole(getRole());
User manager = null;
if (getReportManager() > 0 && "Engineer".equals(getRole())) {
manager = userService.getUserById(getReportManager());
user.setReportManager(manager);
}
user.setEmail(getEmail());
user.setPassword(getPassword());
boolean isSuccess = userService.addUser(user);
if (isSuccess) {
setSuccess("add success!");
return SUCCESS;
} else {
setErrorMessage("errors.addUserFail");
return ERROR;
}
} /**
* @Descriptions administrator update a user
* @return "success" if update success,otherwise "error"
* @throws Exception
*/
public String updateUser() throws Exception { user = userService.getUserById(getId());
user.setID_NO(getID_NO());
user.setName(getName());
user.setRole(getRole());
if (!"Engineer".equals(getRole())) {
setReportManager(0);
}
User manager = userService.getUserById(getReportManager());
user.setReportManager(manager);
user.setEmail(getEmail());
boolean isSuccess = userService.updateUser(user);
if (isSuccess) {
setSuccess("update success!");
return SUCCESS;
} else {
setErrorMessage("errors.updateUserFail");
return ERROR;
}
}
}
package com.augmentum.larry.action;import java.util.List;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.Request;
import com.augmentum.larry.model.User;
import com.augmentum.larry.service.RequestService;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions gets data about request for front page
* @name RequestValueAction
* @author larry.chi
* @version 1.0
*/
public class RequestValueAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final String REQUESTED = "requested";
private static final String APPROVED = "new";
private static final String REJECTED = "rejected";
private static final String REVOKED = "revoked";
private static final String REOPEN = "processing";
private static final String PROCESSING = "processing";
private static final String PENDING = "pending";
private static final String DONE = "done";
private static final String TABLE_NAME="Request";
private RequestService requestService;
private int id;
private String success;
private Pager pager;
private static final String TARGET="requestList.action";
public Pager getPager() {
return pager;
} public void setPager(Pager pager) {
this.pager = pager;
}
public String getSuccess() {
return success;
} public void setSuccess(String success) {
this.success = success;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public void setRequestService(RequestService requestService) { this.requestService = requestService;
} /**
* @Descriptions gets requests whose status is 'requested'
* @return the list of request entities
* @throws Exception
* @Re no longer in use
*/
public List<Request> getRequested() throws Exception {
List<Request> requests = requestService.getRequestByStatus(REQUESTED);
return requests;
} /**
* @Descriptions get all the requests in request table
* @return pager entity
* @throws Exception
*/
public Pager getAllRequests() throws Exception{
if(!TABLE_NAME.equals(pager.getTableName())){
pager.setSearchField(null);
pager.setSortField(null);
}
pager.setTableName(TABLE_NAME);
pager.setTarget(TARGET);
return requestService.getAllRequests(pager);
}
public String execute() throws Exception {
return SUCCESS;
}
/**
* @Descriptions offers error information for error page
* @return error information
*/
public String getErrorMessage() {
return "errors.statusChangeFail";
}
/**
* @Descriptions gets request by request id
* @return request entity
* @throws Exception
*/
public Request getRequestById() throws Exception { return requestService.getRequestById(getId());
}
/**
* @Descriptions gets requests by requester
* @return the list of request entities
* @throws Exception
*/
public Pager getRequestByRequester() throws Exception{
if(!TABLE_NAME.equals(pager.getTableName())){
pager.setSearchField(null);
pager.setSortField(null);
}
User requester=requestService.getCurrentUser();
pager.setTableName(TABLE_NAME);
pager.setTarget(TARGET);
if(requester!=null){
return requestService.getRequestByRequester(requester,pager);
}
return null;
}
/**
* @Descriptions gets requests which IT Staff can view
* @return the list of request entities
* @throws Exception
*/
public Pager getRequestsForITStaff() throws Exception{
if(!TABLE_NAME.equals(pager.getTableName())){
pager.setSearchField(null);
pager.setSortField(null);
}
pager.setTableName(TABLE_NAME);
pager.setTarget(TARGET);
return requestService.getRequestsForITStaff(pager);
}
/**
* @Descriptions IT Manager approve a request
* @return "success" if success,otherwise is "error"
* @throws Exception
*/
public String approveRequest() throws Exception { boolean isSuccess = requestService.operateRequest(getId(),APPROVED);
if (isSuccess) {
setSuccess("approve success!");
return SUCCESS;
} else {
return ERROR;
}
} /**
* @Descriptions IT Manager reject a request
* @return "success" if success,otherwise is "error"
* @throws Exception
*/
public String rejectRequest() throws Exception { boolean isSuccess = requestService.operateRequest(getId(),REJECTED);
if (isSuccess) {
setSuccess("reject success!");
return SUCCESS;
} else {
return ERROR;
}
}
/**
* @Descriptions Engineer,SDM or IT Staff revoke a request
* @return "success" if success,otherwise is "error"
* @throws Exception
*/
public String revokeRequest() throws Exception { boolean isSuccess = requestService.operateRequest(getId(),REVOKED);
if (isSuccess) {
setSuccess("revoke success!");
return SUCCESS;
} else {
return ERROR;
}
}
/**
* @Descriptions Engineer or SDM reopen a request
* @return "success" if success,otherwise is "error"
* @throws Exception
*/
public String reopenRequest() throws Exception { boolean isSuccess = requestService.operateRequest(getId(),REOPEN);
if (isSuccess) {
setSuccess("reopen success!");
return SUCCESS;
} else {
return ERROR;
}
}
/**
* @Descriptions IT Staff process a request
* @return "success" if success,otherwise is "error"
* @throws Exception
*/
public String processRequest() throws Exception { boolean isSuccess = requestService.operateRequest(getId(),PROCESSING);
if (isSuccess) {
setSuccess("process success!");
return SUCCESS;
} else {
return ERROR;
}
}
/**
* @Descriptions IT Staff pending a request
* @return "success" if success,otherwise is "error"
* @throws Exception
*/
public String pendingRequest() throws Exception { boolean isSuccess = requestService.operateRequest(getId(),PENDING);
if (isSuccess) {
setSuccess("pending success!");
return SUCCESS;
} else {
return ERROR;
}
}
/**
* @Descriptions IT Staff done a request
* @return "success" if success,otherwise is "error"
* @throws Exception
*/
public String doneRequest() throws Exception { boolean isSuccess = requestService.operateRequest(getId(),DONE);
if (isSuccess) {
setSuccess("done success!");
return SUCCESS;
} else {
return ERROR;
}
}
}
package com.augmentum.larry.action;import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;import com.augmentum.larry.model.Request;
import com.augmentum.larry.model.RequestType;
import com.augmentum.larry.model.User;
import com.augmentum.larry.service.RequestService;
import com.augmentum.larry.service.RequestTypeService;
import com.augmentum.larry.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions gets data from request submit form and save it.
* @name RequestSubmitAction
* @author larry.chi
* @version 1.0
*/
public class RequestSubmitAction extends ActionSupport { /**
*
*/
private static final long serialVersionUID = 1L;
private static final String REQUESTED = "requested";
private int typeId;
private String title;
private String label0;
private String label1;
private String label2;
private String label3;
private String label4;
private String label5;
private String label6;
private String label7;
private String label8;
private String label9;
private RequestService requestService;
private RequestTypeService requestTypeService;
private UserService userService;
private String success;
private Request request;
private User requester;
private RequestType requestType; public String getErrorMessage() { return "The content of template is too long,you must keep the content less than 800 chars!";
} public void setRequester(User requester) { this.requester = requester;
} public void setRequestType(RequestType requestType) { this.requestType = requestType;
} public void setUserService(UserService userService) { this.userService = userService;
} public String getTitle() { return title;
} public void setTitle(String title) { this.title = title;
} public int getTypeId() { return typeId;
} public void setTypeId(int typeId) { this.typeId = typeId;
} public String getLabel0() { return label0;
} public void setLabel0(String label0) { this.label0 = label0;
} public String getLabel1() { return label1;
} public void setLabel1(String label1) { this.label1 = label1;
} public String getLabel2() { return label2;
} public void setLabel2(String label2) { this.label2 = label2;
} public String getLabel3() { return label3;
} public void setLabel3(String label3) { this.label3 = label3;
} public String getLabel4() { return label4;
} public void setLabel4(String label4) { this.label4 = label4;
} public String getLabel5() { return label5;
} public void setLabel5(String label5) { this.label5 = label5;
} public String getLabel6() { return label6;
} public void setLabel6(String label6) { this.label6 = label6;
} public String getLabel7() { return label7;
} public void setLabel7(String label7) { this.label7 = label7;
} public String getLabel8() { return label8;
} public void setLabel8(String label8) { this.label8 = label8;
} public String getLabel9() { return label9;
} public void setLabel9(String label9) { this.label9 = label9;
} public String getSuccess() { return success;
} public void setSuccess(String success) { this.success = success;
} public void setRequestService(RequestService requestService) { this.requestService = requestService;
} public void setRequestTypeService(RequestTypeService requestTypeService) { this.requestTypeService = requestTypeService;
} public void setRequest(Request request) { this.request = request;
} /**
* @Descriptions processes the request data and calls service method to save it
*/
@SuppressWarnings("unchecked")
public String execute() throws Exception { String requestContent = "";
ArrayList<String> values = new ArrayList<String>();
values.add(getLabel0());
values.add(getLabel1());
values.add(getLabel2());
values.add(getLabel3());
values.add(getLabel4());
values.add(getLabel5());
values.add(getLabel6());
values.add(getLabel7());
values.add(getLabel8());
values.add(getLabel9());
ArrayList<ArrayList<Object>> template = requestTypeService
.getTemplateById(getTypeId());
for (int i = 0; i < template.size(); i++) { ArrayList<Object> label = template.get(i);
String labelName = (String) label.get(0);
requestContent = requestContent + "<font size='3'><strong>"
+ labelName + ": </strong></font>" + values.get(i)
+ "<br/>";
}
if (requestContent.length() <= 800) { Map session = ActionContext.getContext().getSession();
Integer userId = (Integer) session.get("userid");
Date now = new Date();
Timestamp currentTime = new Timestamp(now.getTime());
if (userId != null) { requester = userService.getUserById(userId);
request.setRequester(requester);
request.setContent(requestContent);
request.setRequestTime(currentTime);
request.setTitle(getTitle());
requestType = requestTypeService
.getRequestTypeById(getTypeId());
request.setRequestType(requestType);
request.setStatus(REQUESTED);
requestService.addRequest(request);
setSuccess("add success!");
return SUCCESS;
} else { return ERROR;
}
} else { return ERROR;
}
}
}
package com.augmentum.larry.action;import java.util.ArrayList;
import java.util.List;
import java.util.Map;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.RequestType;
import com.augmentum.larry.service.RequestTypeService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions gets data about request type for front page
* @name RequestTypeValueAction
* @author larry.chi
* @version 1.0
*/
public class RequestTypeValueAction extends ActionSupport { /**
*
*/
private static final long serialVersionUID = 1L; private static final String TABLE_NAME="RequestType";
private static final String TARGET="requestTypeList";
private RequestTypeService requestTypeService;
private int id;
private RequestType requestType;
private String success;
private int typeId;
private Pager pager;
public Pager getPager() {
return pager;
} public void setPager(Pager pager) {
this.pager = pager;
}
public int getTypeId() { return typeId;
} public void setTypeId(int typeId) { this.typeId = typeId;
} public String getSuccess() { return success;
} public void setSuccess(String success) { this.success = success;
} public int getId() { return id;
} public void setId(int id) { this.id = id;
} public void setRequestTypeService(RequestTypeService requestTypeService) { this.requestTypeService = requestTypeService;
} public void setRequestType(RequestType requestType) { this.requestType = requestType;
} /**
* @Descriptions offers error information for error page.
* @return
*/
public String getErrorMessage() { return "errors.getValue";
} /**
* @Descriptions gets all request types
* @return the list of request type entities
* @throws Exception
*/
public List<RequestType> getRequestTypes() throws Exception { return requestTypeService.getAllRequestTypes();
} public Pager getRequestTypeList() throws Exception{
if(!TABLE_NAME.equals(pager.getTableName())){
pager.setSearchField(null);
pager.setSortField(null);
}
pager.setTableName(TABLE_NAME);
pager.setTarget(TARGET);
return requestTypeService.getAllRequestTypes(pager);
}
public String execute() throws Exception { return SUCCESS;
} /**
* @Descriptions gets request type by id
* @return the request type entity
* @throws Exception
*/
public RequestType getRequestTypeById() throws Exception {
return requestTypeService.getRequestTypeById(id);
} /**
* @Descriptions deletes request type
* @return
* @throws Exception
*/
public String deleteRequestType() throws Exception { setSuccess("delete success!");
requestType = getRequestTypeById();
requestTypeService.deleteRequestType(requestType);
return SUCCESS;
} /**
* @Descriptions saves request type to requestType table in database.
* @return
* @throws Exception
*/
@SuppressWarnings("unchecked")
public String saveRequestType() throws Exception { Map session = ActionContext.getContext().getSession();
requestType = (RequestType) session.get("requestType");
if (requestType != null) {
requestTypeService.addRequestType(requestType);
session.remove("requestType");
}
setSuccess("add success!");
return SUCCESS;
} /**
* @Descriptions gets all the request types' name
* @return the list of request type names
* @throws Exception
*/
public List<String> getRequestTypeNames() throws Exception { return requestTypeService.getRequestTypeNames();
} /**
* @Descriptions gets template by request type id
* @return template information
* @throws Exception
*/
public ArrayList<ArrayList<Object>> getTemplateById() throws Exception { ArrayList<ArrayList<Object>> template = requestTypeService
.getTemplateById(getTypeId());
/*
* System.out
* .println("*****----------IT Help Request Template---------*****"); if
* (template == null) {
* System.out.println("\n****** Template is null!!!"); } else {
* System.out.println("\n****** Template is not null!!!"); }
* System.out.println("\n******Template Length: " + template.size());
* for (int i = 0; i < template.size(); i++) { ArrayList<Object> temp =
* template.get(i);
* System.out.print("Information Length: "+temp.size()+" Label Name: "
* + temp.get(0) + " inputType: " + temp.get(1) + " values: "); if
* (temp.size()==3) { ArrayList<String> values = (ArrayList<String>)
* temp.get(2); for (int j = 0; j < values.size(); j++) {
* System.out.print(values.get(j) + " ; "); } } System.out.println(); }
*/
return template;
}
}
package com.augmentum.larry.action;import java.util.ArrayList;
import java.util.Map;import com.augmentum.larry.model.RequestType;
import com.augmentum.larry.service.RequestTypeService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions adds and update request type
* @name RequestTypeAction
* @author larry.chi
* @version 1.0
*/
public class RequestTypeAction extends ActionSupport { /**
*
*/
private static final long serialVersionUID = 1L; private RequestTypeService requestTypeService;
private String name = null;
private String template = null;
private boolean engineerVisible;
private String inputType = null;
private String labelName = null;
private String value = null;
private RequestType requestType;
private int id;
private String success; public String getSuccess() { return success;
} public void setSuccess(String success) { this.success = success;
} public int getId() { return id;
} public void setId(int id) { this.id = id;
} public void setRequestType(RequestType requestType) { this.requestType = requestType;
} public String getInputType() { return inputType;
} public void setInputType(String inputType) { this.inputType = inputType;
} public String getLabelName() { return labelName;
} public void setLabelName(String labelName) { this.labelName = labelName;
} public String getValue() { return value;
} public void setValue(String value) { this.value = value;
} public void setRequestTypeService(RequestTypeService requestTypeService) { this.requestTypeService = requestTypeService;
} public String getName() { return name;
} public void setName(String name) { this.name = name;
} public String getTemplate() { return template;
} public void setTemplate(String template) { this.template = template;
} public boolean isEngineerVisible() { return engineerVisible;
} public void setEngineerVisible(boolean engineerVisible) { this.engineerVisible = engineerVisible;
} /**
* @Descriptions adds request type to session
*/
@SuppressWarnings("unchecked")
public String execute() throws Exception { RequestType requestType = new RequestType();
requestType.setName(getName());
requestType.setTemplate(getTemplate());
requestType.setEngineerVisible(isEngineerVisible());
Map session = ActionContext.getContext().getSession();
session.put("requestType", requestType);
// requestTypeService.addRequestType(requestType);
// setSuccess("add success!");
return SUCCESS;
}
/**
* @Descriptions updates request type
* @return
* @throws Exception
*/
public String updateRequestType() throws Exception { requestType.setId(getId());
requestType.setName(getName());
requestType.setTemplate(getTemplate());
requestType.setEngineerVisible(isEngineerVisible());
requestTypeService.updateRequestType(requestType);
setSuccess("update success!");
return SUCCESS;
} /**
* @Descriptions gets the new submit template information
*/
public ArrayList<ArrayList<Object>> getTemplateInfo() { return requestTypeService.getTemplate(getTemplate());
}
}
package com.augmentum.larry.action;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions clears session
* @name LogoutAction
* @author larry.chi
* @version 1.0
*/
public class LogoutAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private String operation;
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
@SuppressWarnings("unchecked")
public String execute() throws Exception {
Map session=ActionContext.getContext().getSession();
session.clear();
return getOperation();
}
}
package com.augmentum.larry.action;import java.util.List;
import java.util.Map;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.User;
import com.augmentum.larry.model.UserRole;
import com.augmentum.larry.service.UserRoleService;
import com.augmentum.larry.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions gets data about user for front page
* @name GetUserValueAction
* @author larry.chi
* @version 1.0
*/
@SuppressWarnings("serial")
public class GetUserValueAction extends ActionSupport { private static final String TABLE_NAME="User";
private static final String TARGET="requestList.action";
private static final String USER_LIST="getAllUsers.action";
private UserService userService;
private String success;
private User user;
private int id;
private UserRoleService userRoleService;
private Pager pager;
public Pager getPager() {
return pager;
} public void setPager(Pager pager) {
this.pager = pager;
}
public void setUserRoleService(UserRoleService userRoleService){
this.userRoleService=userRoleService;
}
public void setUser(User user) { this.user = user;
} public String getSuccess() { return success;
} public void setSuccess(String success) { this.success = success;
} public int getId() { return id;
} public void setId(int id) { this.id = id;
} public void setUserService(UserService userService) { this.userService = userService;
} /**
* @Descriptions offers error information for error page
* @return error information
*/
public String getErrorMessage() { return "errors.getValue";
} public Pager getUsers() throws Exception { if(!TABLE_NAME.equals(pager.getTableName())){
pager.setSearchField(null);
pager.setSortField(null);
}
pager.setTableName(TABLE_NAME);
pager.setTarget(USER_LIST);
return userService.getUsers(pager);
} public List<User> getManagers() throws Exception { return userService.getManagers();
}
public List<UserRole> getAllUserRoles() throws Exception{
return userRoleService.getAllUserRole();
}
public User getUser() throws Exception { return userService.getUserById(getId());
} public String execute() throws Exception {
return SUCCESS;
} /**
* @Descriptions gets the SDM's engineers
* @return pager entity
* @throws Exception
*/
@SuppressWarnings("unchecked")
public Pager getMyEngineers() throws Exception {
pager.setTableName(TABLE_NAME);
pager.setTarget(TARGET);
Map session = ActionContext.getContext().getSession();
Integer userId = (Integer) session.get("userid");
if (userId != null) { Pager engineers = userService.getMyEngineers(userService
.getUserById(userId),pager);
return engineers;
}
return null;
} /**
* @Descriptions deletes a user(Mark user's status as 'left')
* @return
* @throws Exception
*/
public String deleteUser() throws Exception { setSuccess("delete success!");
user = getUser();
user.setStatus("left");
userService.updateUser(user);
return SUCCESS;
}
}
package com.augmentum.larry.action;import java.util.List;
import java.util.Map;import com.augmentum.larry.model.Feature;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.service.FeatureService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions gets data about feature for front page
* @name FeatureValueAction
* @author larry.chi
* @version 1.0
*/
public class FeatureValueAction extends ActionSupport{ /**
*
*/
private static final long serialVersionUID = 1L;
private static final String TABLE_NAME="Feature";
private static final String TARGET="featureList.action";
private FeatureService featureService;
private int id;
private String success;
private Pager pager;
public Pager getPager() {
return pager;
} public void setPager(Pager pager) {
this.pager = pager;
}
public String getSuccess() {
return success;
} public void setSuccess(String success) {
this.success = success;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
}
public String getErrorMessage() {
return "errors.getValue";
}
public void setFeatureService(FeatureService featureService){
this.featureService=featureService;
}
/**
* @Descriptions gets feature menu by user role
* @throws Exception
*/
@SuppressWarnings("unchecked")
public String getMenuByRole() throws Exception{
Map session=ActionContext.getContext().getSession();
String role = (String) session.get("role");
List<Feature> features= featureService.getMenuByRole(role);
session.put("features",features);
return SUCCESS;
}
/**
* @Descriptions gets all the features
* @return pager entity
* @throws Exception
*/
public Pager getMenuList() throws Exception{
if(!TABLE_NAME.equals(pager.getTableName())){
pager.setSearchField(null);
pager.setSortField(null);
}
pager.setTableName(TABLE_NAME);
pager.setTarget(TARGET);
return featureService.getMenuList(pager);
}
public String execute() throws Exception {
return SUCCESS;
}
/**
* @Descriptions deletes a feature
* @return
* @throws Exception
*/
public String deleteFeature() throws Exception{
Feature feature=featureService.getFeatureById(getId());
featureService.deleteFeature(feature);
setSuccess("delete success!");
return SUCCESS;
}
/**
* @Descriptions gets feature by id
* @return feature entity
* @throws Exception
*/
public Feature getFeature() throws Exception{
Feature feature=featureService.getFeatureById(getId());
return feature;
}
}
package com.augmentum.larry.action;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.service.ActionsService;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions gets data about actions for front page
* @name ActionsValueAction
* @author larry.chi
* @version 1.0
*/
public class ActionsValueAction extends ActionSupport { private static final String TABLE_NAME="Actions";
/**
*
*/
private static final long serialVersionUID = 1L;
private ActionsService actionsService;
private Pager pager;
public Pager getPager() {
return pager;
} public void setPager(Pager pager) {
this.pager = pager;
} public void setActionsService(ActionsService actionsService) { this.actionsService = actionsService;
} /**
* @Descriptions gets all the operations about request status change
* @return pager entity
* @throws Exception
*/
public Pager getOperationsPage() throws Exception {
if(!TABLE_NAME.equals(pager.getTableName())){
pager.setSearchField(null);
pager.setSortField(null);
}
pager.setTableName(TABLE_NAME);
pager.setTarget("operationList.action");
return actionsService.getOperations(pager);
}
public String execute() throws Exception { return SUCCESS;
}
}
package com.augmentum.larry.action;import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions deliver the Illegal access prompt message
* @name AccessDenyAction
* @author larry.chi
* @version 1.0
*/
public class AccessDenyAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String denyMessage; public String getDenyMessage() { return denyMessage;
} public void setDenyMessage(String denyMessage) { this.denyMessage = denyMessage;
} public String execute() throws Exception { return SUCCESS;
}
}
package com.augmentum.larry.action;import java.util.Map;import com.augmentum.larry.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions Change user's password
* @name ChangePasswordAction
* @author larry.chi
* @version 1.0
*/
public class ChangePasswordAction extends ActionSupport { /**
*
*/
private static final long serialVersionUID = 1L;
private String oldPassword;
private String newPassword;
private String rePassword;
private UserService userService; public void setUserService(UserService userService) { this.userService = userService;
} public String getErrorMessage() { return getText("errors.changePassword");
} public String getOldPassword() { return oldPassword;
} public void setOldPassword(String oldPassword) { this.oldPassword = oldPassword;
} public String getNewPassword() { return newPassword;
} public void setNewPassword(String newPassword) { this.newPassword = newPassword;
} public String getRePassword() { return rePassword;
} public void setRePassword(String rePassword) { this.rePassword = rePassword;
} @SuppressWarnings("unchecked")
public String execute() throws Exception { Map session = ActionContext.getContext().getSession();
String username = (String) session.get("username");
if (userService.isLogin(username, getOldPassword())) { userService.changePassword(username, getNewPassword());
return SUCCESS;
} else { return ERROR;
}
}
}
package com.augmentum.larry.action;import com.augmentum.larry.model.Feature;
import com.augmentum.larry.service.FeatureService;
import com.opensymphony.xwork2.ActionSupport;/**
* @Descriptions feature add and update
* @author larry.chi
*
*/
public class FeatureAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private Feature feature;
private String success;
private FeatureService featureService;
public String getSuccess() {
return success;
}
public void setSuccess(String success) {
this.success = success;
}
public Feature getFeature(){
return feature;
}
public void setFeature(Feature feature) {
this.feature = feature;
}
public void setFeatureService(FeatureService featureService) {
this.featureService = featureService;
}
/**
* @Descriptions feature add operation
*/
public String execute() throws Exception {
featureService.saveFeature(feature);
setSuccess("add success!");
return SUCCESS;
}
/**
* @Descriptions feature update operation
* @return
* @throws Exception
*/
public String updateFeature() throws Exception{
featureService.updateFeature(feature);
setSuccess("update success!");
return SUCCESS;
}
}
package com.augmentum.larry.dao;import com.augmentum.larry.model.Pager;
/**
* @Descriptions In the interface of ActionsDao,define some methods
* which the entity of Actions interact with the database.
* @category interface
* @name ActionsDao
* @author larry.chi
* @version 1.0
*/
public interface ActionsDao {
/**
* @Descriptions this method is used for getting all the operation records
* from database.
* @return pager entity
* @param pager entity
* @throws Exception
*/
public Pager getAllActions(Pager pager) throws Exception;
/**
* @Descriptions gets the total count of operations.
*
* @return total count of operations.
* @throws Exception
* @Re No use
*/
public int getTotalCount() throws Exception;
}
package com.augmentum.larry.dao;import java.util.List;
import com.augmentum.larry.model.Feature;
import com.augmentum.larry.model.Pager;/**
* @Descriptions this interface defined methods
* which the feature entity interact with database.
* @category interface
* @name FeatureDao
* @author larry.chi
* @version 1.0
*/
public interface FeatureDao {
/**
* @Descriptions gets the feature menu by user role.
* @param role
* @return the list of feature entity
* @throws Exception
*/
public List<Feature> getMenuByRole(String role) throws Exception;
/**
* @Descriptions adds a feature item which will show on the feature menu
* @param feature
* @throws Exception
*/
public void addFeature(Feature feature) throws Exception;
/**
* @Descriptions gets all the features
* which allow the administrator to review,update,and delete.
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
public Pager getMenuList(Pager pager) throws Exception;
/**
* @Descriptions gets feature by the key of feature.
* @param id:the key of feature
* @return feature entity
* @throws Exception
*/
public Feature getFeatureById(int id) throws Exception;
/**
* @Descriptions deletes a feature.
* @param feature
* @throws Exception
*/
public void deleteFeature(Feature feature) throws Exception;
/**
* @Descriptions updates a feature.
* @param feature
* @throws Exception
*/
public void updateFeature(Feature feature) throws Exception;
}
package com.augmentum.larry.dao;import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @Descriptions base DAO
* @author larry.chi
* @res no in use.
*/
public class HibernateSessionFactory {
private static String CONFIG_FILE_LOCATION="applicationContext.xml";
private static final ThreadLocal<Session> threadLocal=new ThreadLocal<Session>();
private static ClassPathXmlApplicationContext configuration;
private static SessionFactory sessionFactory;
private static String configFile=CONFIG_FILE_LOCATION;
static{
try{
configuration=new ClassPathXmlApplicationContext(configFile);
sessionFactory=(SessionFactory) configuration.getBean("sessionFactory");
}catch(Exception e){
System.err.println("%%%Error Creating SessionFactory%%%");
e.printStackTrace();
}
} public static Session getSession()throws HibernateException{
Session session=(Session)threadLocal.get();
if(session==null||!session.isOpen()){
if(sessionFactory==null){
rebuildSessionFactory();
}
session=(sessionFactory!=null)?sessionFactory.openSession():null;
threadLocal.set(session);
}
return session;
}
public static void rebuildSessionFactory(){
try{
configuration=new ClassPathXmlApplicationContext(configFile);
sessionFactory=(SessionFactory) configuration.getBean("sessionFactory");
}catch(Exception e){
System.err.println("%%%Error Creating SessionFactory%%%");
e.printStackTrace();
}
}
public static void closeSession()throws HibernateException{
Session session=(Session)threadLocal.get();
threadLocal.set(null);
if(session!=null){
session.close();
}
}
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
public static void setConfigFile(String configFile){
HibernateSessionFactory.configFile=configFile;
sessionFactory=null;
}
public static ClassPathXmlApplicationContext getConfiguration(){
return configuration;
}
}
package com.augmentum.larry.dao;import com.augmentum.larry.model.Pager;/**
* @Descriptions defines methods about pagination.
* @author larry.chi
* @category interface
* @name PagerDao
*/
public interface PagerDao {
/**
* @Descriptions gets the result after pagination.
*
* @param queryString : a string to query
* @param pager : the entity of pager
* @return pager entity.
* @throws Exception
*/
public Pager getResults(String queryString, Pager pager) throws Exception;
}
package com.augmentum.larry.dao;import java.util.List;import com.augmentum.larry.model.Actions;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.Request;
import com.augmentum.larry.model.User;/**
* @Descriptions defines methods which request interact with the database.
* @author larry.chi
* @category interface
* @name RequestDao
*/
public interface RequestDao {
/**
* @Descriptions stores the request submit by engineer or SDM
* @param the instance of request
* @throws Exception
*/
public void addRequest(Request request) throws Exception;
/**
* @Descriptions updates a request,mainly used for users to change request status.
* @param request
* @throws Exception
*/
public void updateRequest(Request request) throws Exception;
/**
* @Descriptions gets requests by status.
* @param status:requested,new,pending,processing,revoked,rejected,close
* @throws Exception
*/
public List<Request> getRequestByStatus(String status) throws Exception;
/**
* @Descriptions gets requests by requester.
* @param requester
* @param Pager entity
* @return pager entity
* @throws Exception
*/
public Pager getRequestByRequester(User requester,Pager pager) throws Exception;
/**
* @Descriptions gets request by the key of request
* @param id: key of request
* @return request entity
* @throws Exception
*/
public Request getRequestById(int id) throws Exception;
/**
* @Descriptions adds a operation to the table named actions.
* @param action:a entity of actions which describe a operation.
* @throws Exception
*/
public void addAction(Actions action) throws Exception;
/**
* @Descriptions gets requests whose status are
* new,processing,pending,done and close.
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
public Pager getRequestsForITStaff(Pager pager) throws Exception;
/**
* @Descriptions gets all the requests in request table
* @param pager entity
* @return pager entity
* @throws Exception
*/
public Pager getAllRequests(Pager pager) throws Exception;
}
package com.augmentum.larry.dao;import java.util.List;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.RequestType;/**
* @Descriptions defines the methods which RequestType interact with database.
* @category interface
* @name RequestTypeDao
* @author larry.chi
* @version 1.0
*/
public interface RequestTypeDao {
/**
* @Descriptions administrator add a request type to the table named
* requestType.
* @param requestType
* @throws Exception
*/
public void addRequestType(RequestType requestType) throws Exception; /**
* @Descriptions administrator delete a request type.
* @param requestType
* @throws Exception
*/
public void deleteRequestType(RequestType requestType) throws Exception; /**
* @Descriptions administrator update a request type.
* @param requestType
* @throws Exception
*/
public void updateRequestType(RequestType requestType) throws Exception; /**
* @Descriptions gets the request types which engineer have the permission,
* that is to say,the engineer visible is true.
* @return the list of request type.
* @throws Exception
*/
public List<RequestType> getRequestTypes() throws Exception; /**
* @Descriptions gets all the request types from requestType table.
* @param pager: pager entity
* @return pager entity.
* @throws Exception
*/
public Pager getAllRequestTypes(Pager pager) throws Exception; /**
* @Descriptions gets all the request types from requestType table.
* @return the list of request type entities.
* @throws Exception
*/
public List<RequestType> getAllRequestTypes() throws Exception;
/**
* @Descriptions gets request type by id.
* @param id
* : the key of requestType table.
* @return requestType entity.
* @throws Exception
*/
public RequestType getRequestTypeById(int id) throws Exception; /**
* @Descriptions gets all the request types' name.
* @return the list of request types' name.
* @throws Exception
*/
public List<String> getRequestTypeNames() throws Exception; /**
* @Descriptions gets request template by name.
* @param name
* : the request type's name
* @return request template
* @throws Exception
*/
public String getRequestTemplateByName(String name) throws Exception; /**
* @Descriptions gets template by the key of reuqestType table
* @param id
* : the key of requestType table
* @return the template of request
* @throws Exception
*/
public String getTemplateById(int id) throws Exception;
}
package com.augmentum.larry.dao;import java.util.List;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.User;/**
* @Descriptions defines methods which user entity interact with database.
* @category
* @name UserDao
* @author larry.chi
* @version 1.0
*/
public interface UserDao {
/**
* @Descriptions administrator add a user to user table.
* @param user
* @throws Exception
*/
public void addUser(User user) throws Exception; /**
* @Descriptions administrator delete a user
* @param user
* @throws Exception
*/
public void deleteUser(User user) throws Exception; /**
* @Descriptions administrator update a user
* @param user
* @throws Exception
*/
public void updateUser(User user) throws Exception; /**
* @Descriptions gets user by one's name
* @param name
* : the user's English name
* @return user entity
* @throws Exception
*/
public User findByName(String name) throws Exception; /**
* @Descriptions gets user by one's email
* @param email
* @return user entity
* @throws Exception
*/
public User findByEmail(String email) throws Exception; /**
* @Descriptions gets user by the key of user table
* @param id
* : the key of user table
* @return user entity
* @throws Exception
*/
public User findById(int id) throws Exception; /**
* @Descriptions gets user by ID_NO
* @param ID_NO
* @return user entity
* @throws Exception
*/
public User findByID_NO(String ID_NO) throws Exception;
/**
* @Descriptions gets all the users except the status is left.
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
public Pager getUsers(Pager pager) throws Exception; /**
* @Descriptions gets all the users whose role is "SDM"
* @return the list of user entity
* @throws Exception
*/
public List<User> getManagers() throws Exception; /**
* @Descriptions gets all the SDM's engineer
* @param sdm
* @return the list of user entity
* @throws Exception
*/
public Pager getEngineersBySDM(User sdm,Pager pager) throws Exception;
}
package com.augmentum.larry.dao;import java.util.List;import com.augmentum.larry.model.UserRole;
/**
* @Descriptions defines methods which UserRole entity interact with database.
*
* @category interface
* @name UserRoleDao
* @author larry.chi
* @version 1.0
*/
public interface UserRoleDao { /**
* @Descriptions gets all the user role
* @return the list of UserRole entities
* @throws Exception
*/
public List<UserRole> getUserRole() throws Exception;
}
package com.augmentum.larry.dao.impl;import java.util.List;import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.augmentum.larry.dao.ActionsDao;
import com.augmentum.larry.dao.PagerDao;
import com.augmentum.larry.model.Pager;/**
* @Descriptions implements the methods defined in the interface of ActionsDao
* @category name ActionsDaoImpl
* @author larry.chi
* @version 1.0
*/
public class ActionsDaoImpl extends HibernateDaoSupport implements ActionsDao { private static final Logger log = Logger.getLogger(ActionsDaoImpl.class);
private PagerDao pagerDao; public void setPagerDao(PagerDao pagerDao){
this.pagerDao=pagerDao;
}
/**
* @throws Exception
* @Descriptions gets all operation records
* @param pager entity
* @return pager entity
*/
@Override
public Pager getAllActions(Pager pager) throws Exception {
String queryString="from Actions as a";
Pager result=null;
try {
result=pagerDao.getResults(queryString, pager);
} catch (Exception e) { log.error("gets all request operations error!", e);
throw e;
}
return result;
} /**
* @Descriptions gets the total count of operations.
*
* @return total count of operations.
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public int getTotalCount() throws Exception {
// TODO Auto-generated method stub
List<Integer> amount;
amount=getHibernateTemplate().find("select count(*) from Actions as a");
if(amount!=null&&amount.size()>=1){
return (Integer) amount.get(0);
}
return 0;
}}
package com.augmentum.larry.dao.impl;import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.augmentum.larry.dao.PagerDao;
import com.augmentum.larry.model.Pager;/**
* @Descriptions implements methods in the PagerDao interface.
*
* @name PagerDaoImpl
* @author larry.chi
* @version 1.0
*/
public class PagerDaoImpl implements PagerDao { private static final Logger log = Logger.getLogger(PagerDaoImpl.class); /**
* @Descriptions gets the total count and data list after pagination.
*
* @param queryString
* : a string to query
* @param pager
* : the entity of pager
* @return pager entity.
* @exception Exception
*/
@Override
@SuppressWarnings("unchecked")
public Pager getResults(String queryString, Pager pager) throws Exception { ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext(
"applicationContext.xml");
SessionFactory sessionFactory = (SessionFactory) factory
.getBean("sessionFactory");
Session session = sessionFactory.openSession();
List<Object> list = null;
Query query = null;
if (pager.getSearchField() != null
&& !pager.getSearchField().equals("")) { queryString = searchQueryString(queryString, pager);
}
pager.setTotalRecords(getTotalCount(session, queryString));
if ((pager.getSortField() != null)
&& (!pager.getSortField().equals(""))) { queryString += " order by " + pager.getSortField() + " "
+ pager.getSortOrder();
}
try { query = session.createQuery(queryString);
query.setFirstResult((pager.getCurrentPage() - 1)
* pager.getPageSize());
query.setMaxResults(pager.getPageSize());
list = query.list();
pager.setQueryResult(list);
session.close();
sessionFactory.close();
} catch (Exception e) { log.error("gets total records fail!", e);
throw e;
}
return pager;
} /**
* @Descriptions gets the total count of result set.
*
* @param session
* @param queryString
* : a string for querying.
* @return total count number
* @throws Exception
*/
private int getTotalCount(Session session, String hql) throws Exception { Long amount = new Long(0);
int sqlFrom = hql.indexOf("from");
int sqlOrderby = hql.indexOf("order by");
String countStr = "";
if (sqlOrderby > 0) { countStr = "select count(*) " + hql.substring(sqlFrom, sqlOrderby);
} else { countStr = "select count(*) " + hql.substring(sqlFrom);
}
Query qry = null;
try { qry = session.createQuery(countStr);
amount = (Long) qry.uniqueResult();
} catch (Exception e) { log.error("gets total count error!", e);
throw e;
}
return amount.intValue();
} /**
* @Descriptions if <code>pager.getSearchField()</code> does not empty,this
* method will run. this method will add search condition code
* to the query string.
*
* @param queryString
* @param pager
* @return a string for query
* @throws Exception
*/
private String searchQueryString(String queryString, Pager pager)
throws Exception { int where = queryString.indexOf("where");
String fieldType = null;
Timestamp dateTime = null;
if ("Actions".equals(pager.getTableName())) { if ("id".equals(pager.getSearchField())
|| "request".equals(pager.getSearchField())
|| "executor".equals(pager.getSearchField())) { if (pager.getStringValue().matches("[0-9]+")) { fieldType = "int";
} else { log.error("Input invalid chars,only numbers are allowed!");
}
} else if ("operationTime".equals(pager.getSearchField())) { fieldType = "datetime";
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setLenient(false);
dateTime = new Timestamp(pager.getDateValue().getTime());
} else if ("start".equals(pager.getSearchField())
|| "end".equals(pager.getSearchField())) { fieldType = "varchar";
}
} else if ("Request".equals(pager.getTableName())) { if ("requestTime".equals(pager.getSearchField())
|| "executeTime".equals(pager.getSearchField())) { fieldType = "datetime";
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setLenient(false);
dateTime = new Timestamp(pager.getDateValue().getTime());
} else if ("id".equals(pager.getSearchField())
|| "requester".equals(pager.getSearchField())
|| "executor".equals(pager.getSearchField())
|| "requestType".equals(pager.getSearchField())) { if (pager.getStringValue().matches("[0-9]+")) { fieldType = "int";
} else { log.error("Input invalid chars,only numbers are allowed!");
}
} else if ("status".equals(pager.getSearchField())
|| "title".equals(pager.getSearchField())) { fieldType = "varchar";
}
} else if ("RequestType".equals(pager.getTableName())) { if ("id".equals(pager.getSearchField())) { if (pager.getStringValue().matches("[0-9]+")) { fieldType = "int";
} else { log.error("Input invalid chars,only numbers are allowed!");
}
} else if ("name".equals(pager.getSearchField())) { fieldType = "varchar";
} else if ("engineerVisible".equals(pager.getSearchField())) { if ("true".equals(pager.getStringValue())
|| "false".equals(pager.getStringValue())) { fieldType = "int";
} else { log
.error("engineerVisible only accept 'true' or 'false' value!");
}
}
} else if ("User".equals(pager.getTableName())) { if ("name".equals(pager.getSearchField())
|| "ID_NO".equals(pager.getSearchField())
|| "Email".equals(pager.getSearchField())
|| "role".equals(pager.getSearchField())
|| "status".equals(pager.getSearchField())) { fieldType = "varchar";
} else if ("id".equals(pager.getSearchField())
|| "reportManager".equals(pager.getSearchField())) { if (pager.getStringValue().matches("[0-9]+")) { fieldType = "int";
} else { log.error("Input invalid chars,only numbers are allowed!");
}
}
} else if ("Feature".equals(pager.getTableName())) { if ("id".equals(pager.getSearchField())
|| "pid".equals(pager.getSearchField())) { if (pager.getStringValue().matches("[0-9]+")) { fieldType = "int";
} else { log.error("Input invalid chars,only numbers are allowed!");
}
} else if ("name".equals(pager.getSearchField())
|| "url".equals(pager.getSearchField())
|| "roles".equals(pager.getSearchField())) { fieldType = "varchar";
}
}
if (where > 0) { if ("int".equals(fieldType)) { queryString += " and " + pager.getSearchField() + " = "
+ pager.getStringValue();
} else if ("varchar".equals(fieldType)) { queryString += " and " + pager.getSearchField() + " like '%"
+ pager.getStringValue() + "%'";
} else if ("datetime".equals(fieldType)) { queryString += " and " + pager.getSearchField() + " "
+ pager.getOperator() + " '" + dateTime + "'";
}
} else { if ("int".equals(fieldType)) { queryString += " where " + pager.getSearchField() + " = "
+ pager.getStringValue();
} else if ("varchar".equals(fieldType)) { queryString += " where " + pager.getSearchField() + " like '%"
+ pager.getStringValue() + "%'";
} else if ("datetime".equals(fieldType)) { /*
* DateFormat format = new
* SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
* format.setLenient(false); Timestamp dateTime=new
* Timestamp(format.parse(pager.getSearchValue()).getTime());
*/
queryString += " where " + pager.getSearchField() + " "
+ pager.getOperator() + " '" + dateTime + "'";
}
}
return queryString;
}
}
package com.augmentum.larry.dao.impl;import java.util.List;import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.augmentum.larry.dao.FeatureDao;
import com.augmentum.larry.dao.PagerDao;
import com.augmentum.larry.model.Feature;
import com.augmentum.larry.model.Pager;/**
* @Descriptions implements the method defined in the interface of FeatureDaoImpl
* @category name FeatureDaoImpl
* @author larry.chi
* @version 1.0
*/
public class FeatureDaoImpl extends HibernateDaoSupport implements FeatureDao { private static final Logger log = Logger.getLogger(FeatureDaoImpl.class); private PagerDao pagerDao; public void setPagerDao(PagerDao pagerDao){
this.pagerDao=pagerDao;
}
/**
* @Descriptions gets the feature menu by user role.
* @param role
* @return the list of feature entity
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public List<Feature> getMenuByRole(String role) throws Exception { String condition = "%" + role + "%";
List<Feature> menu = null;
try { menu = getHibernateTemplate().find(
"from Feature as f where f.roles like ?", condition);
} catch (Exception e) { log.error("gets menu by role error!", e);
throw e;
}
return menu;
} /**
* @Descriptions adds a feature item which will show on the feature menu
* @param feature
* @throws Exception
*/
@Override
public void addFeature(Feature feature) throws Exception { try { getHibernateTemplate().save(feature);
log.info("adds feature success!"+feature);
} catch (Exception e) { log.error("adds feature error!"+feature, e);
throw e;
}
} /**
* @Descriptions gets all the features which allow the administrator to
* review,update,and delete.
*
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
@Override
public Pager getMenuList(Pager pager) throws Exception { String queryString="from Feature as f";
Pager result=null;
try {
result=pagerDao.getResults(queryString, pager);
} catch (Exception e) { log.error("gets menu list error!", e);
throw e;
}
return result;
} /**
* @Descriptions gets feature by the key of feature.
* @param id
* :the key of feature
* @return feature entity
* @throws Exception
*/
@Override
public void deleteFeature(Feature feature) throws Exception { try { getHibernateTemplate().delete(feature);
log.info("deletes feature success!"+feature);
} catch (Exception e) { log.error("deletes feature error!"+feature, e);
throw e;
}
} /**
* @Descriptions deletes a feature.
* @param feature
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public Feature getFeatureById(int id) throws Exception { List<Feature> features = null;
try { features = getHibernateTemplate().find(
"from Feature as f where f.id=?", id);
} catch (Exception e) { log.error("gets feature by id error!", e);
throw e;
}
if (features != null && features.size() > 0) { log.info("gets feature by id success!"+features.get(0));
return features.get(0);
}
return null;
} /**
* @Descriptions updates a feature.
* @param feature
* @throws Exception
*/
@Override
public void updateFeature(Feature feature) throws Exception { try { getHibernateTemplate().update(feature);
log.info("updates feature success!"+feature);
} catch (Exception e) { log.error("updates feature error!"+feature, e);
throw e;
}
}}
package com.augmentum.larry.dao.impl;import java.util.List;import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.augmentum.larry.dao.PagerDao;
import com.augmentum.larry.dao.RequestDao;
import com.augmentum.larry.model.Actions;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.Request;
import com.augmentum.larry.model.User;/**
* @Descriptions implements the methods defined in the interface of ReqeustDao.
* @author larry.chi
* @name RequestDaoImpl
*/
public class RequestDaoImpl extends HibernateDaoSupport implements RequestDao { private static final Logger log = Logger.getLogger(RequestDaoImpl.class); private PagerDao pagerDao; public void setPagerDao(PagerDao pagerDao){
this.pagerDao=pagerDao;
}
/**
* @Descriptions stores the request submit by engineer or SDM
* @param the
* instance of request
* @throws Exception
*/
@Override
public void addRequest(Request request) throws Exception { try { getHibernateTemplate().save(request);
log.info("adds request success!"+request);
} catch (Exception e) {
log.error("adds request error!"+request, e);
throw e;
}
} /**
* @Descriptions updates a request,mainly used for users to change request
* status.
* @param request
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public List<Request> getRequestByStatus(String status) throws Exception { List<Request> requests = null;
try { requests = getHibernateTemplate().find(
"from Request as r where r.status=?", status);
} catch (Exception e) { log.error("gets request by status fail !", e);
throw e;
}
return requests;
} /**
* @Descriptions gets requests by status.
* @param status
* :requested,new,pending,processing,revoked,rejected,close
* @throws Exception
*/
@Override
public void updateRequest(Request request) throws Exception { try { getHibernateTemplate().update(request);
log.info("updates request success!"+request);
} catch (Exception e) { log.error("updates request error!"+request, e);
throw e;
}
} /**
* @Descriptions gets requests by requester.
* @param requester
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
@Override
public Pager getRequestByRequester(User requester,Pager pager) throws Exception { String queryString="from Request as r where r.requester='"+requester.getId()+"'";
Pager result=null;
try {
result=pagerDao.getResults(queryString, pager);
} catch (Exception e) { log.error("gets request by requester fail!", e);
throw e;
}
return result;
} /**
* @Descriptions gets request by the key of request
* @param id
* : key of request
* @return request entity
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public Request getRequestById(int id) throws Exception { List<Request> requests = null;
try { requests = getHibernateTemplate().find(
"from Request as r where r.id=?", id);
} catch (Exception e) { log.error("gets request by id fail!", e);
throw e;
}
if (requests != null && requests.size() > 0) { return requests.get(0);
}
return null;
} /**
* @Descriptions adds a operation to the table named actions.
* @param action
* :a entity of actions which describe a operation.
* @throws Exception
*/
@Override
public void addAction(Actions action) throws Exception { try { getHibernateTemplate().save(action);
log.info("adds operation to actions table success!"+action);
} catch (Exception e) { log.error("adds operation to actions table error!"+action, e);
throw e;
}
} /**
* @Descriptions gets requests whose status are new,processing,pending,done
* and close.
* @return the list of request
* @throws Exception
*/
@Override
public Pager getRequestsForITStaff(Pager pager) throws Exception { String queryString="from Request as r where r.status in ('new','processing','pending','done','close')";
Pager result=null;
try {
result=pagerDao.getResults(queryString, pager);
} catch (Exception e) { log.error("gets request for IT Staff fail!", e);
throw e;
}
return result;
} /**
* @Descriptions gets all the requests in request table
* @return the list of request entities
* @throws Exception
*/
@Override
public Pager getAllRequests(Pager pager) throws Exception { String queryString="from Request as r";
Pager result=null;
try {
result=pagerDao.getResults(queryString, pager);
} catch (Exception e) { log.error("gets all requests fail!", e);
throw e;
}
return result;
}}
package com.augmentum.larry.dao.impl;import java.util.List;import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.augmentum.larry.dao.PagerDao;
import com.augmentum.larry.dao.RequestTypeDao;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.RequestType;/**
* @Descriptions implements the method defined in the interface of RequesTypeDao.
* @name RequestTypeDaoImpl
* @author larry.chi
* @version 1.0
*/
public class RequestTypeDaoImpl extends HibernateDaoSupport implements
RequestTypeDao { private static final Logger log = Logger
.getLogger(RequestTypeDaoImpl.class); private PagerDao pagerDao; public void setPagerDao(PagerDao pagerDao){
this.pagerDao=pagerDao;
}
/**
* @Descriptions administrator add a request type to the table named
* requestType.
* @param requestType
* @throws Exception
*/
@Override
public void addRequestType(RequestType requestType) throws Exception { try { getHibernateTemplate().save(requestType);
log.info("adds request type success!" + requestType);
} catch (Exception e) { log.error("adds request type error!" + requestType, e);
throw e;
}
} /**
* @Descriptions administrator delete a request type.
* @param requestType
* @throws Exception
*/
@Override
public void deleteRequestType(RequestType requestType) throws Exception { try { getHibernateTemplate().delete(requestType);
log.info("deletes request type success!" + requestType);
} catch (Exception e) { log.error("deletes request type error!" + requestType, e);
throw e;
}
} /**
* @Descriptions gets the request types which engineer have the permission,
* that is to say,the engineer visible is true.
* @return the list of request type.
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public List<RequestType> getRequestTypes() throws Exception { List<RequestType> requestTypes = null;
try { requestTypes = getHibernateTemplate().find(
"from RequestType rt where rt.engineerVisible=?", true);
} catch (Exception e) { log.error("gets request types fail!", e);
throw e;
}
return requestTypes;
} /**
* @Descriptions administrator update a request type.
* @param requestType
* @throws Exception
*/
@Override
public void updateRequestType(RequestType requestType) throws Exception { try { getHibernateTemplate().update(requestType);
log.info("updates request type success!"+requestType);
} catch (Exception e) { log.error("updates request type fail!"+requestType, e);
throw e;
}
} /**
* @Descriptions gets request type by id.
* @param id
* : the key of requestType table.
* @return requestType entity.
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public RequestType getRequestTypeById(int id) throws Exception { List<RequestType> requestTypes = null;
try { requestTypes = getHibernateTemplate().find(
"from RequestType as rt where rt.id=?", id);
} catch (Exception e) { log.error("gets request type by id fail!", e);
throw e;
}
if (requestTypes != null && requestTypes.size() >= 1) { log.info("gets request type by id success!"+requestTypes.get(0));
return (RequestType) requestTypes.get(0);
}
return null;
} /**
* @Descriptions gets all the request types' name.
* @return the list of request types' name.
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public List<String> getRequestTypeNames() throws Exception { List<String> typeNames = null;
try { typeNames = getHibernateTemplate().find(
"select new list(rt.name) from RequestType as rt");
} catch (Exception e) { log.error("gets request type names fail!", e);
throw e;
}
return typeNames;
} /**
* @Descriptions gets request template by name.
* @param name
* : the request type's name
* @return request template
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public String getRequestTemplateByName(String name) throws Exception { List<String> template = null;
try { template = getHibernateTemplate()
.find(
"select rt.template from RequestType as rt where rt.name=?",
name);
} catch (Exception e) { log.error("gets request template by name fail!", e);
throw e;
}
if (template.size() != 0) { return template.get(template.size() - 1);
} else { return null;
}
} /**
* @Descriptions gets template by the key of reuqestType table
* @param id
* : the key of requestType table
* @return the template of request
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public String getTemplateById(int id) throws Exception { List<String> template = null;
try { template = getHibernateTemplate().find(
"select rt.template from RequestType as rt where rt.id=?",
id);
} catch (Exception e) { log.error("gets template by id fail!", e);
throw e;
}
if (template.size() != 0) { return template.get(template.size() - 1);
} else { return null;
}
} /**
* @Descriptions gets all the request types from requestType table.
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
@Override
public Pager getAllRequestTypes(Pager pager) throws Exception { String queryString="from RequestType rt";
Pager result=null;
try {
result=pagerDao.getResults(queryString, pager);
} catch (Exception e) { log.error("gets all request types fail!", e);
throw e;
}
return result;
} @SuppressWarnings("unchecked")
@Override
public List<RequestType> getAllRequestTypes() throws Exception { List<RequestType> requestTypes=null;
try {
requestTypes=getHibernateTemplate().find("from RequestType rt");
} catch (Exception e) { log.error("gets all request types fail!", e);
throw e;
}
return requestTypes;
}
}
package com.augmentum.larry.dao.impl;import java.util.List;import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.augmentum.larry.dao.PagerDao;
import com.augmentum.larry.dao.UserDao;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.User;/**
* @Descriptions implements the methods defined in the interface of UserDao
* @name UserDaoImpl
* @author larry.chi
* @version 1.0
*/
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
private static final Logger log = Logger.getLogger(UserDaoImpl.class); private PagerDao pagerDao; public void setPagerDao(PagerDao pagerDao){
this.pagerDao=pagerDao;
}
/**
* @Descriptions administrator add a user to user table.
* @param user
* @throws Exception
*/
public void addUser(User user) throws Exception { try { getHibernateTemplate().save(user);
log.debug("saves user successful!"+user);
} catch (Exception e) { log.error("saves user fail!"+user, e);
throw e;
}
} /**
* @Descriptions administrator delete a user
* @param user
* @throws Exception
*/
public void deleteUser(User user) throws Exception { try { getHibernateTemplate().delete(user);
log.debug("delete user successful!"+user);
} catch (Exception e) { log.error("deletes user failed!"+user, e);
throw e;
}
} /**
* @Descriptions gets user by one's name
* @param name
* : the user's English name
* @return user entity
* @throws Exception
*/
@SuppressWarnings("unchecked")
public User findByName(String name) throws Exception { List<User> users = null;
try {
users = getHibernateTemplate().find(
"from User as u where u.name=? and u.status is null", name);
} catch (Exception e) {
log.error("finds user by name error!", e);
throw e;
}
if (users != null && users.size() >= 1) { return (User) users.get(0);
}
return null;
} /**
* @Descriptions administrator update a user
* @param user
* @throws Exception
*/
@Override
public void updateUser(User user) throws Exception {
try {
getHibernateTemplate().update(user);
log.info("updates user successful!"+user);
} catch (Exception e) { log.error("updates user error!"+user, e);
throw e;
}
} /**
* @Descriptions gets all the users except the status is left.
* @return the list of user entity
* @throws Exception
*/
@Override
public Pager getUsers(Pager pager) throws Exception { String queryString="from User u where u.status is null";
Pager result=null;
try {
result=pagerDao.getResults(queryString, pager);
} catch (Exception e) { log.error("gets all users fail!", e);
throw e;
}
return result;
} /**
* @Descriptions gets all the users whose role is "SDM"
* @return the list of user entity
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public List<User> getManagers() throws Exception { List<User> managers = null;
try {
managers = getHibernateTemplate().find(
"from User u where u.role='SDM' and u.status is null");
} catch (Exception e) { log.error("gets managers fail!", e);
throw e;
}
return managers;
} /**
* @Descriptions gets user by the key of user table
* @param id
* : the key of user table
* @return user entity
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public User findById(int id) throws Exception { log.debug("getting user instance with id:" + id);
List<User> users = null;
try {
users = getHibernateTemplate().find(
"from User as u where u.id=? and u.status is null", id);
} catch (Exception e) { log.error("gets user by id error!", e);
throw e;
}
if (users != null && users.size() >= 1) { return (User) users.get(0);
}
return null;
} /**
* @Descriptions gets all the SDM's engineer
* @param sdm
* @return the list of user entity
* @throws Exception
*/
@Override
public Pager getEngineersBySDM(User sdm,Pager pager) throws Exception { String queryString="from User as u where u.reportManager='"+sdm.getId()+"' and u.status is null";
Pager result=null;
try {
result=pagerDao.getResults(queryString, pager);
} catch (Exception e) { log.error("gets engineers by SDM fail!", e);
throw e;
}
return result;
} /**
* @Descriptions gets user by one's email
* @param email
* @return user entity
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public User findByEmail(String email) throws Exception { List<User> users = null;
try {
users = getHibernateTemplate().find(
"from User as u where u.Email=? and u.status is null",
email);
} catch (Exception e) { log.error("gets user by email error!", e);
throw e;
}
if (users != null && users.size() >= 1) { return (User) users.get(0);
}
return null;
}
/**
* @Descriptions gets user by ID_NO
* @param ID_NO
* @return user entity
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public User findByID_NO(String ID_NO) throws Exception { List<User> users = null;
try {
users = getHibernateTemplate().find(
"from User as u where u.ID_NO=? and u.status is null",
ID_NO);
} catch (Exception e) { log.error("gets user by ID_NO error!", e);
throw e;
}
if (users != null && users.size() >= 1) { return (User) users.get(0);
}
return null;
}
}
package com.augmentum.larry.dao.impl;import java.util.List;import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.augmentum.larry.dao.UserRoleDao;
import com.augmentum.larry.model.UserRole;/**
* @Descriptions implements the methods defined in the interface of UserRoleDao
*
* @category class
* @name UserRoleDaoImpl
* @author larry.chi
* @version 1.0
*/
public class UserRoleDaoImpl extends HibernateDaoSupport implements UserRoleDao { /**
* @Descriptions gets all the user role
* @return the list of UserRole entities
*/
@SuppressWarnings("unchecked")
@Override
public List<UserRole> getUserRole() throws Exception{
List<UserRole> userRoles=null;
userRoles=getHibernateTemplate().find("from UserRole ur");
return userRoles;
}
}
package com.augmentum.larry.interceptor;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;/**
* @Descriptions only allow SDM to access the relative actions.
* @category name SDMAccess
* @author larry.chi
* @version 1.0
*/
public class SDMAccess extends AbstractInterceptor { /**
* interceptor for security.
*/
private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked")
@Override
public String intercept(ActionInvocation invocation) throws Exception { ActionContext ct = invocation.getInvocationContext();
Map session = ct.getSession();
String role = (String) session.get("role");
String result = null;
if (role == null) { result = "noLogin";
} else if (!role.equals("SDM")) { result = "noPermission";
} else { result = invocation.invoke();
}
return result;
}}package com.augmentum.larry.interceptor;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;/**
* @Descriptions only allow IT Staff to access the relative actions.
* @category name ITStaffAccess
* @author larry.chi
* @version 1.0
*/
public class ITStaffAccess extends AbstractInterceptor { /**
*
*/
private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked")
@Override
public String intercept(ActionInvocation invocation) throws Exception { ActionContext ct = invocation.getInvocationContext();
Map session = ct.getSession();
String role = (String) session.get("role");
String result = null;
if (role == null) { result = "noLogin"; } else if (!role.equals("IT Staff")) { result = "noPermission";
} else { result = invocation.invoke();
}
return result;
}}
package com.augmentum.larry.interceptor;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;/**
* @Descriptions only allow IT Manager to access the relative actions.
* @category
* @name ITManagerAccess
* @author larry.chi
* @version 1.0
*/
public class ITManagerAccess extends AbstractInterceptor { /**
*
*/
private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked")
@Override
public String intercept(ActionInvocation invocation) throws Exception { ActionContext ct = invocation.getInvocationContext();
Map session = ct.getSession();
String role = (String) session.get("role");
String result = null;
if (role == null) { result = "noLogin";
} else if (!role.equals("IT Manager")) { result = "noPermission";
} else { result = invocation.invoke();
}
return result;
}}
package com.augmentum.larry.interceptor;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;/**
* @Descriptions allows users who have login this system can access the relative
* actions.
* @category
* @name GeneralInterceptor
* @author larry.chi
* @version 1.0
*/
public class GeneralInterceptor extends AbstractInterceptor { /**
*
*/
private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked")
@Override
public String intercept(ActionInvocation invocation) throws Exception { ActionContext ct = invocation.getInvocationContext();
Map session = ct.getSession();
String role = (String) session.get("role");
String result = null;
if (role != null
&& (role.equals("IT Manager") || role.equals("Engineer")
|| role.equals("SDM") || role.equals("IT Staff") || role
.equals("Admin"))) { result = invocation.invoke();
} else { result = "noLogin";
}
return result;
}}package com.augmentum.larry.interceptor;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;/**
* @Descriptions allows Engineer and SDM to access the relative actions.
* @category
* @name DeveloperAccess
* @author larry.chi
* @version 1.0
*/
public class DeveloperAccess extends AbstractInterceptor { /**
*
*/
private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked")
@Override
public String intercept(ActionInvocation invocation) throws Exception { ActionContext ct = invocation.getInvocationContext();
Map session = ct.getSession();
String role = (String) session.get("role");
String result = null;
if (role == null) { result = "noLogin";
} else if (!role.equals("Engineer") && !role.equals("SDM")) { result = "noPermission";
} else { result = invocation.invoke();
}
return result;
}}
package com.augmentum.larry.interceptor;import java.io.IOException;
import java.sql.SQLException;import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.mail.MailException;import com.augmentum.larry.util.SystemException;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;/**
* @Descriptions handles exceptions thrown by actions.
*
* @author larry.chi
* @category class
* @name ExceptionInterceptor
* @version 1.0
*/
public class ExceptionInterceptor extends AbstractInterceptor { private static final long serialVersionUID = 1L;
private static final Logger log = Logger
.getLogger(ExceptionInterceptor.class);
@Override
public String intercept(ActionInvocation invocation) throws Exception { String result = ""; try { result = invocation.invoke();
} catch (DataAccessException ex) { log.error("Database Access Fail!", ex);
throw new SystemException("Database Access Fail",ex);
} catch (NullPointerException ex) { log.error("Called uninitialized object or the object does not exist!", ex);
throw new SystemException("Called uninitialized object or the object does not exist",ex);
} catch (IOException ex) { log.error("IO Exception!", ex);
throw new SystemException("IO Exception",ex);
} catch (ClassNotFoundException ex) { log.error("Class Not Found!", ex);
throw new SystemException("Class Not Found",ex);
} catch (ArithmeticException ex) { log.error("Arithmetic exception!", ex);
throw new SystemException("Arithmetic exception",ex);
} catch (ArrayIndexOutOfBoundsException ex) { log.error("Array Index Out Of Bounds Exception!", ex);
throw new SystemException("Array Index Out Of Bounds Exception",ex);
} catch (IllegalArgumentException ex) { log.error("Illegal Argument Exception!", ex);
throw new SystemException("Illegal Argument Exception",ex);
} catch (MailException ex) { log.error("Mail Send Exceptin!", ex);
throw new SystemException("Mail Send Exceptin",ex);
} catch (ClassCastException ex) { log.error("Class Cast Exception!", ex);
throw new SystemException("Class Cast Exception",ex);
} catch (SQLException ex) { log.error("Database Operation Exception!", ex);
throw new SystemException("Database Operation Exception",ex);
} catch (NoSuchMethodException ex) { log.error("No Such Method Exception!", ex);
throw new SystemException("No Such Method Exception",ex);
} catch (Exception ex) { log.error("Program Internal Error, Operation Failed!", ex);
throw new SystemException("Program Internal Error, Operation Failed",ex);
}
return result;
}
}
package com.augmentum.larry.interceptor;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
* @Descriptions only allow Admin to access the relative actions.
* @category class
* @name AdminAccess
* @author larry.chi
* @version 1.0
*/
@SuppressWarnings("serial")
public class AdminAccess extends AbstractInterceptor{ @SuppressWarnings("unchecked")
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
ActionContext ct=invocation.getInvocationContext();
Map session=ct.getSession();
String role=(String)session.get("role");
String result=null;
if(role==null){
result="noLogin";
}else if(!role.equals("Admin")){
result="noPermission";
}else{
result=invocation.invoke();
}
return result;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.augmentum.larry.model"> <class name="UserRole" table="UserRole" mutable="true" dynamic-update="true">
<id name="id" type="integer" column="id">
<generator class="identity" />
</id>
<property name="role" length="20" not-null="true" update="true"
insert="true" unique="true"></property>
</class>
</hibernate-mapping>/model/User.hbm.xml<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.augmentum.larry.model"> <class name="User" table="user" mutable="true" dynamic-update="true">
<id name="id" type="integer" column="id">
<generator class="identity" />
</id>
<property name="ID_NO" length="10" not-null="true" update="true"
insert="true" unique="true"></property>
<property name="name" length="20" not-null="true" update="true"
insert="true" unique="true"></property>
<property name="Email" column="Email" not-null="true" update="true"
insert="true" unique="true"></property>
<property name="role" length="20" not-null="true" update="true"
insert="true"></property>
<many-to-one name="reportManager" class="User" update="true"
insert="true" lazy="false">
<column name="reportManager" not-null="false"></column>
</many-to-one>
<property name="password" type="java.lang.String" length="100"
not-null="true" update="true" insert="true"></property>
<property name="status" length="5" update="true" insert="true"></property>
<set name="requestList" inverse="true" lazy="false">
<key column="requester" not-null="false"></key>
<one-to-many class="Request"/>
</set>
</class>
</hibernate-mapping>/model/RequestType.hbm.xml<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.augmentum.larry.model"> <class name="RequestType" table="RequestType" mutable="true"
dynamic-update="true">
<id name="id" type="integer" column="id">
<generator class="identity" />
</id>
<property name="name" length="25" not-null="true" update="true"
insert="true"></property>
<property name="template" length="500" not-null="true"
update="true" insert="true"></property>
<property name="engineerVisible" not-null="true" update="true"
insert="true">
<column name="engineerVisible" default="true"></column>
</property>
<set name="requestList" inverse="true" >
<key column="requestType" not-null="false"></key>
<one-to-many class="Request"/>
</set>
</class>
</hibernate-mapping>
/model/Request.hbm.xml<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.augmentum.larry.model"> <class name="Request" table="request" mutable="true"
dynamic-update="true">
<id name="id" type="integer" column="id">
<generator class="identity" />
</id>
<many-to-one name="requester" class="User" not-null="true"
update="true" insert="true" lazy="false"></many-to-one>
<property name="requestTime" update="true" insert="true">
<column name="requestTime" sql-type="datetime" length="19"
not-null="true"></column>
</property>
<many-to-one name="executor" class="User" update="true"
insert="true" lazy="false"></many-to-one>
<property name="executeTime" update="true" insert="true">
<column name="executeTime" sql-type="datetime" length="19"></column>
</property>
<property name="status" length="20" not-null="true" update="true"
insert="true"></property>
<many-to-one name="requestType" class="RequestType"
not-null="true" lazy="false"></many-to-one>
<property name="title" length="50" not-null="true" update="true"
insert="true"></property>
<property name="content" length="800" not-null="true" update="true"
insert="true"></property>
<set name="actions" inverse="true">
<key column="request" not-null="false"></key>
<one-to-many class="Actions" />
</set>
</class>
</hibernate-mapping>/model/Feature.hbm.xml<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.augmentum.larry.model"> <class name="Feature" table="Feature" mutable="true"
dynamic-update="true">
<id name="id" type="integer" column="id">
<generator class="identity" />
</id>
<property name="pid" not-null="true" update="true"
insert="true"></property>
<property name="name" length="50" not-null="true"
update="true" insert="true"></property>
<property name="url" length="150" update="true"
insert="true"></property>
<property name="target" length="30" update="true"
insert="true"></property>
<property name="icon" length="150" update="true"
insert="true"></property>
<property name="iconOpen" length="150" update="true"
insert="true"></property>
<property name="roles" length="150" update="true"
insert="true"></property>
</class>
</hibernate-mapping>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.augmentum.larry.model"><class name="Actions" table="Actions" mutable="true" dynamic-update="true">
<id name="id" type="integer" column="id">
<generator class="identity" />
</id>
<!-- set name="requestId">
<key column="id"></key>
<one-to-many class="Request"/>
</set -->
<many-to-one name="request" column="request" class="Request" not-null="true" update="false" insert="true" lazy="false"></many-to-one>
<property name="operationTime" update="false" insert="true">
<column name="operationTime" sql-type="datetime" length="19" not-null="true"></column>
</property>
<many-to-one name="executor" class="User" update="true" insert="true" lazy="false">
<column name="executor" not-null="true" ></column>
</many-to-one>
<property name="start" length="20" not-null="true" update="false" insert="true"></property>
<property name="end" length="20" not-null="true" update="false" insert="true"></property>
</class>
</hibernate-mapping>
package com.augmentum.larry.model;public class UserRole { private int id;
private String role; public int getId() { return id;
} public void setId(int id) { this.id = id;
} public String getRole() { return role;
} public void setRole(String role) { this.role = role;
} public String toString() { return "The detail information of User:----->id:" + id + " role:"
+ role;
}
}package com.augmentum.larry.model;import java.util.HashSet;
import java.util.Set;public class User implements java.io.Serializable { /**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private String ID_NO;
private String name;
private String Email;
private String role;
private User reportManager;
private String password;
private String status; @SuppressWarnings("unchecked")
private Set requestList = new HashSet(0); @SuppressWarnings("unchecked")
public Set getRequestList() { return requestList;
} @SuppressWarnings("unchecked")
public void setRequestList(Set requestList) { this.requestList = requestList;
} public String getID_NO() { return ID_NO;
} public void setID_NO(String iDNO) { ID_NO = iDNO;
} public String getStatus() { return status;
} public void setStatus(String status) { this.status = status;
} public int getId() { return id;
} public void setId(int id) { this.id = id;
} public String getName() { return name;
} public void setName(String name) { this.name = name;
} public String getEmail() { return Email;
} public void setEmail(String email) { Email = email;
} public String getRole() { return role;
} public void setRole(String role) { this.role = role;
} public User getReportManager() { return reportManager;
} public void setReportManager(User reportManager) { this.reportManager = reportManager;
} public String getPassword() { return password;
} public void setPassword(String password) { this.password = password;
} public String toString() { return "The detail information of User:----->id:" + id + " ID NO:"
+ ID_NO + " name:" + name + " Email:" + Email + " role:"
+ role + " reportManager:" + reportManager.getName()
+ " status:" + status;
}
}
package com.augmentum.larry.model;import java.util.HashSet;
import java.util.Set;public class RequestType implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private String name;
private String template;
private boolean engineerVisible; @SuppressWarnings("unchecked")
private Set requestList = new HashSet(0); @SuppressWarnings("unchecked")
public Set getRequestList() { return requestList;
} @SuppressWarnings("unchecked")
public void setRequestList(Set requestList) { this.requestList = requestList;
} public int getId() { return id;
} public void setId(int id) { this.id = id;
} public String getName() { return name;
} public void setName(String name) { this.name = name;
} public String getTemplate() { return template;
} public void setTemplate(String template) { this.template = template;
} public boolean isEngineerVisible() { return engineerVisible;
} public void setEngineerVisible(boolean engineerVisible) { this.engineerVisible = engineerVisible;
} public String toString() { return "The detail information of User:----->id:" + id + " Type Name:"
+ name + " Template:" + template + " Engineer Visible"
+ engineerVisible;
}
}
package com.augmentum.larry.model;import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.Set;public class Request implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private User requester;
private Timestamp requestTime;
private User executor;
private Timestamp executeTime;
private String status;
private RequestType requestType;
private String title;
private String content; @SuppressWarnings("unchecked")
private Set actions = new HashSet(0); public User getRequester() { return requester;
} public void setRequester(User requester) { this.requester = requester;
} public User getExecutor() { return executor;
} public void setExecutor(User executor) { this.executor = executor;
} public RequestType getRequestType() { return requestType;
} public void setRequestType(RequestType requestType) { this.requestType = requestType;
} @SuppressWarnings("unchecked")
public Set getActions() { return actions;
} @SuppressWarnings("unchecked")
public void setActions(Set actions) { this.actions = actions;
} public int getId() { return id;
} public void setId(int id) { this.id = id;
} public Timestamp getRequestTime() { return requestTime;
} public String getRequestTimeStr() { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String timeStr = df.format(getRequestTime());
return timeStr;
} public void setRequestTime(Timestamp requestTime) { this.requestTime = requestTime;
} public Timestamp getExecuteTime() { return executeTime;
} public String getExecuteTimeStr() { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String timeStr = df.format(getExecuteTime());
return timeStr;
} public void setExecuteTime(Timestamp executeTime) { this.executeTime = executeTime;
} public String getStatus() { return status;
} public void setStatus(String status) { this.status = status;
} public String getTitle() { return title;
} public void setTitle(String title) { this.title = title;
} public String getContent() { return content;
} public void setContent(String content) { this.content = content;
} public String toString() { return "The detail information of User:----->id:" + id
+ " Requester:" + requester.getName() + " Request Time:"
+ requestTime + " Executor:" + executor.getName()
+ "Execute Time:" + executeTime + " Request Title:" + title
+ " Content:" + content;
}
}
package com.augmentum.larry.model;import java.util.Date;
import java.util.List;public class Pager { private int currentPage;
private int totalRecords;
private int pageSize;
private int totalPage;
private Boolean isFirstPage;
private Boolean isLastPage;
private int previousPage;
private int nextPage;
private int firstPage = 1;
private int lastPage;
private String sortField;
private String sortOrder;
private List<Object> queryResult;
private String tableName;
private String searchField;
private String operator;
private String stringValue;
private Date dateValue;
private String target;
public String getTarget() {
return target;
} public void setTarget(String target) {
this.target = target;
} public String getTableName() {
return tableName;
} public void setTableName(String tableName) {
this.tableName = tableName;
} public String getSearchField() {
return searchField;
} public void setSearchField(String searchField) {
this.searchField = searchField;
} public String getOperator() {
return operator;
} public void setOperator(String operator) {
this.operator = operator;
} public String getStringValue() {
return stringValue;
} public void setStringValue(String stringValue) {
this.stringValue = stringValue;
} public Date getDateValue() {
return dateValue;
} public void setDateValue(Date dateValue) {
this.dateValue = dateValue;
} public int getCurrentPage() {
return currentPage;
} public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
} public int getPageSize() {
return pageSize;
} public void setPageSize(int pageSize) {
this.pageSize = pageSize;
} public int getTotalPage() {
return totalPage;
} public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
} public Boolean getIsFirstPage() {
return isFirstPage;
} public void setIsFirstPage(Boolean isFirstPage) {
this.isFirstPage = isFirstPage;
} public Boolean getIsLastPage() {
return isLastPage;
} public void setIsLastPage(Boolean isLastPage) {
this.isLastPage = isLastPage;
} public int getPreviousPage() {
return previousPage;
} public void setPreviousPage(int previousPage) {
this.previousPage = previousPage;
} public int getNextPage() {
return nextPage;
} public void setNextPage(int nextPage) {
this.nextPage = nextPage;
} public int getFirstPage() {
return firstPage;
} public void setFirstPage(int firstPage) {
this.firstPage = firstPage;
} public int getLastPage() {
return lastPage;
} public void setLastPage(int lastPage) {
this.lastPage = lastPage;
} public String getSortField() {
return sortField;
} public void setSortField(String sortField) {
this.sortField = sortField;
} public String getSortOrder() {
return sortOrder;
} public void setSortOrder(String sortOrder) {
this.sortOrder = sortOrder;
} public int getTotalRecords() {
return totalRecords;
}
public List<Object> getQueryResult() {
return queryResult;
} public void setQueryResult(List<Object> queryResult) {
this.queryResult = queryResult;
} public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
pageSize = pageSize == 0 ? 5 : pageSize;
totalPage = totalRecords % pageSize == 0 ? totalRecords / pageSize
: totalRecords / pageSize + 1;
lastPage = totalPage;
currentPage = currentPage < 1 ? 1 : currentPage;
currentPage = currentPage > lastPage ? lastPage : currentPage;
isFirstPage = ((currentPage == firstPage)||(currentPage==0));
isLastPage = currentPage == lastPage;
previousPage = isFirstPage ? 1 : currentPage - 1;
nextPage = isLastPage ? lastPage : currentPage + 1;
}
}package com.augmentum.larry.model;public class Feature implements java.io.Serializable { /**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private int pid;
private String name;
private String url;
private String target;
private String icon;
private String iconOpen;
private String roles; public int getId() { return id;
} public void setId(int id) { this.id = id;
} public int getPid() { return pid;
} public void setPid(int pid) { this.pid = pid;
} public String getName() { return name;
} public void setName(String name) { this.name = name;
} public String getUrl() { return url;
} public void setUrl(String url) { this.url = url;
} public String getTarget() { return target;
} public void setTarget(String target) { this.target = target;
} public String getIcon() { return icon;
} public void setIcon(String icon) { this.icon = icon;
} public String getIconOpen() { return iconOpen;
} public void setIconOpen(String iconOpen) { this.iconOpen = iconOpen;
} public String getRoles() { return roles;
} public void setRoles(String roles) { this.roles = roles;
} public String toString() { return "The detail information of User:----->id:" + id
+ " parent id:" + pid + " name:" + name + " url:" + url
+ " target:" + target + " icon address:" + icon
+ " open icon address:" + iconOpen + " User Roles:" + roles;
}
}
package com.augmentum.larry.model;import java.sql.Timestamp;
import java.text.SimpleDateFormat;public class Actions implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private Request request;
private Timestamp operationTime;
private User executor;
private String start;
private String end; public int getId() { return id;
} public void setId(int id) { this.id = id;
} public Request getRequest() { return request;
} public void setRequest(Request request) { this.request = request;
} public Timestamp getOperationTime() { return operationTime;
} public String getOperationTimeStr() { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String timeStr = df.format(getOperationTime());
return timeStr;
} public void setOperationTime(Timestamp operationTime) { this.operationTime = operationTime;
} public User getExecutor() { return executor;
} public void setExecutor(User executor) { this.executor = executor;
} public String getStart() { return start;
} public void setStart(String start) { this.start = start;
} public String getEnd() { return end;
} public void setEnd(String end) { this.end = end;
} public String toString() { return "The detail information of Actions:----->id:" + id
+ " Request Title:" + request.getTitle()
+ " Operation Time:" + operationTime + " executor:"
+ executor.getName() + " Start Status:" + start
+ " End Status:" + end;
}
}
package com.augmentum.larry.service.impl;import java.util.List;
import java.util.Map;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;import com.augmentum.larry.dao.UserDao;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.User;
import com.augmentum.larry.service.UserService;
import com.augmentum.larry.util.DES;
import com.opensymphony.xwork2.ActionContext;/**
* @Dscriptions defines methods which get data from DAO and do some business
* logic.
* @category
* @name UserServiceImpl
* @author larry.chi
* @version 1.0
*/
public class UserServiceImpl implements UserService {
private static final Log log = LogFactory.getLog(UserServiceImpl.class);
private UserDao userDao; public void setUserDao(UserDao userDao) {
this.userDao = userDao;
} /**
* @Dscriptions administrator adds a user
* @param user
* @return true if add success
* @throws Exception
*/
@Override
public boolean addUser(User user) throws Exception { if (isExistUserName(user.getName()) || isExistEmail(user.getEmail())||isExistID_NO(user.getID_NO())) { return false;
}
try {
user.setPassword(new DES().getEncString(user.getPassword()));
} catch (Exception e) { log.error("ncrypts password error!", e);
throw e;
}
userDao.addUser(user);
return true;
} /**
* @Dscriptions determines whether ID_NO is exist
* @param ID_NO
* @return true if exist
* @throws Exception
*/
@Override
public boolean isExistID_NO(String ID_NO) throws Exception { User user = userDao.findByID_NO(ID_NO);
if (user != null) { return true;
} return false;
}
/**
* @Dscriptions determines whether userName is exist
* @param username
* @return true if exist
* @throws Exception
*/
@Override
public boolean isExistUserName(String username) throws Exception { User user = userDao.findByName(username);
if (user != null) { return true;
} return false;
} /**
* @Dscriptions determines whether login is success
* @param username
* @param password
* @return true if userName and password is exist
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public boolean isLogin(String username, String password) throws Exception { User user = userDao.findByName(username);
if (user != null) { String realPassword = new DES().getDesString(user.getPassword());
if (user != null && password.equals(realPassword)) { Map session = ActionContext.getContext().getSession();
session.put("userid", user.getId());
return true;
}
}
return false;
} /**
* @Dscriptions gets the role by userName
* @param username
* @return user role
* @throws Exception
*/
@Override
public String getRole(String username) throws Exception { User user = userDao.findByName(username);
if (user != null) { return user.getRole();
}
return null;
} /**
* @Dscriptions changes user's password
* @param username
* @param password
* @return true if change success
* @throws Exception
*/
@Override
public boolean changePassword(String username, String password) throws Exception { User user = userDao.findByName(username);
user.setPassword(new DES().getEncString(password));
userDao.updateUser(user);
return true;
} /**
* @Dscriptions gets all users
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
@Override
public Pager getUsers(Pager pager) throws Exception { return userDao.getUsers(pager);
} /**
* @Dscriptions gets all managers
* @return the list of user entities
* @throws Exception
*/
@Override
public List<User> getManagers() throws Exception { return userDao.getManagers();
} /**
* @Dscriptions gets user by id
* @param id
* @return the user entity
* @throws Exception
*/
@Override
public User getUserById(int id) throws Exception { User user = userDao.findById(id);
String password = user.getPassword();
if (password != null && !password.equals("")) { user.setPassword(new DES().getDesString(password));
}
return user;
} /**
* @Dscriptions updates user
* @param user
* @return true if update success
* @throws Exception
*/
@Override
public boolean updateUser(User user) throws Exception { User byName = userDao.findByName(user.getName());
User byEmail = userDao.findByEmail(user.getEmail());
User byID_NO = userDao.findByID_NO(user.getID_NO());
if (byName.getId() != user.getId() || byEmail.getId() != user.getId()||byID_NO.getId()!=user.getId()) { return false;
}
user.setPassword(new DES().getEncString(user.getPassword()));
userDao.updateUser(user);
return true;
} /**
* @Dscriptions gets the sdm's all engineers
* @param sdm
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
@Override
public Pager getMyEngineers(User sdm,Pager pager) throws Exception { return userDao.getEngineersBySDM(sdm,pager);
} /**
* @Dscriptions determines whether email is exist
* @param email
* @return true if exist
* @throws Exception
*/
@Override
public boolean isExistEmail(String email) throws Exception { User user = userDao.findByEmail(email);
if (user != null) { return true;
}
return false;
}
}
package com.augmentum.larry.service.impl;import java.util.List;import com.augmentum.larry.dao.UserRoleDao;
import com.augmentum.larry.model.UserRole;
import com.augmentum.larry.service.UserRoleService;/**
* @Dscriptions defines methods which get data from DAO and do some business
* logic.
* @name UserRoleServiceImpl
* @author larry.chi
* @version 1.0
*/
public class UserRoleServiceImpl implements UserRoleService{ private UserRoleDao userRoleDao;
public void setUserRoleDao(UserRoleDao userRoleDao){
this.userRoleDao=userRoleDao;
}
/**
* @Descriptions gets all the user roles
*
* @return the list of UserRole entities
* @throws Exception
*/
@Override
public List<UserRole> getAllUserRole() throws Exception {
return userRoleDao.getUserRole();
}}
package com.augmentum.larry.service.impl;import java.util.ArrayList;
import java.util.List;
import java.util.Map;import com.augmentum.larry.dao.RequestTypeDao;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.RequestType;
import com.augmentum.larry.service.RequestTypeService;
import com.opensymphony.xwork2.ActionContext;/**
* @Dscriptions defines methods which get data from DAO and do some business
* logic.
* @name RequestTypeServiceImpl
* @author larry.chi
* @version 1.0
*/
public class RequestTypeServiceImpl implements RequestTypeService { private RequestTypeDao requestTypeDao; public void setRequestTypeDao(RequestTypeDao requestTypeDao) { this.requestTypeDao = requestTypeDao;
} /**
* @Dscriptions administrator adds a request type
* @param requestType
* @return true if add success
* @throws Exception
*/
@Override
public boolean addRequestType(RequestType requestType) throws Exception { requestTypeDao.addRequestType(requestType);
return true;
} /**
* @Dscriptions administrator deletes a request type
* @param requestType
* @return true if delete success
* @throws Exception
*/
@Override
public boolean deleteRequestType(RequestType requestType) throws Exception { requestTypeDao.deleteRequestType(requestType);
return true;
} /**
* @Dscriptions gets current user's role
* @return current user role
*/
@SuppressWarnings("unchecked")
@Override
public String getCurrentUserRole() { Map session = ActionContext.getContext().getSession();
String role = (String) session.get("role");
return role;
} /**
* @Dscriptions gets all the requestTypes,that is to say,get requests SDM can
* see
* @return the list of request type entities
* @throws Exception
*/
@Override
public List<RequestType> getAllRequestTypes() throws Exception { if ("Engineer".equals(getCurrentUserRole())) { return requestTypeDao.getRequestTypes();
} else if ("SDM".equals(getCurrentUserRole())) { return requestTypeDao.getAllRequestTypes();
} else { return null;
}
} /**
* @Dscriptions administrator updates a request type
* @param requestType
* @return true if update success
* @throws Exception
*/
@Override
public boolean updateRequestType(RequestType requestType) throws Exception { requestTypeDao.updateRequestType(requestType);
return true;
} /**
* @Dscriptions gets request type by id
* @param id
* : the key of request type table
* @return RequestType entity
* @throws Exception
*/
@Override
public RequestType getRequestTypeById(int id) throws Exception { return requestTypeDao.getRequestTypeById(id);
} /**
* @Dscriptions gets all the request types' name
* @return the list of request type entities
* @throws Exception
*/
@Override
public List<String> getRequestTypeNames() throws Exception { return requestTypeDao.getRequestTypeNames();
} /**
* @Dscriptions gets template by id
* @param id
* : the key of request type table
* @return the template information which have been processed
* @throws Exception
*/
@Override
public ArrayList<ArrayList<Object>> getTemplateById(int id) throws Exception { return getTemplate(requestTypeDao.getTemplateById(id));
} /**
* @Descriptions analyzes request type template
*/
@Override
public ArrayList<ArrayList<Object>> getTemplate(String template) { ArrayList<ArrayList<Object>> templateInfo = new ArrayList<ArrayList<Object>>();
String[] labels = template.split("/");
for (int i = 0; i < labels.length; i++) { String obj = labels[i];
ArrayList<Object> info = new ArrayList<Object>();
if (obj != null && !obj.trim().equals("")) { String[] seperate = obj.split("&");
if (seperate.length == 2) { info.add(seperate[0]);
String[] inputType = seperate[1].split(":");
if (inputType.length == 2) { info.add(inputType[0]);
if (inputType[1] != null
&& !inputType[1].trim().equals("")) { ArrayList<String> value = new ArrayList<String>();
String[] values = inputType[1].split(";");
for (int j = 0; j < values.length; j++) { value.add(values[j]);
}
info.add(value);
}
} else { info.add(inputType[0]);
}
}
}
templateInfo.add(info);
}
return templateInfo;
} @Override
public Pager getAllRequestTypes(Pager pager) throws Exception { return requestTypeDao.getAllRequestTypes(pager);
}
}
package com.augmentum.larry.service.impl;import com.augmentum.larry.dao.ActionsDao;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.service.ActionsService;/**
* @Descriptions defines methods which get data from DAO and do some business
* logic.
* @name ActionsServiceImpl
* @author larry.chi
* @version 1.0
*/
public class ActionsServiceImpl implements ActionsService { private ActionsDao actionsDao; public void setActionsDao(ActionsDao actionsDao) { this.actionsDao = actionsDao;
} /**
* @Descriptions gets all the operations
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
@Override
public Pager getOperations(Pager pager) throws Exception { return actionsDao.getAllActions(pager);
}
/**
* @Descriptions gets the total count of operations.
*
* @return total count of operations.
* @throws Exception
* @re No in use at present
*/
@Override
public int getTotalCount() throws Exception {
return actionsDao.getTotalCount();
}
}
package com.augmentum.larry.service.impl;import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;import org.springframework.transaction.annotation.Transactional;import com.augmentum.larry.dao.RequestDao;
import com.augmentum.larry.model.Actions;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.Request;
import com.augmentum.larry.model.User;
import com.augmentum.larry.service.RequestService;
import com.augmentum.larry.service.UserService;
import com.opensymphony.xwork2.ActionContext;/**
* @Dscriptions defines methods which get data from DAO and do some business
* logic.
* @name RequestServiceImpl
* @author larry.chi
* @version 1.0
*/
public class RequestServiceImpl implements RequestService {
private static final String CLOSE = "close";
private static final String DONE = "done";
private RequestDao requestDao;
private UserService userService;
private Request request;
private Actions action;
private final static int CLOSE_TIME = -24; public void setAction(Actions action) {
this.action = action;
} public void setRequest(Request request) {
this.request = request;
} public void setUserService(UserService userService) {
this.userService = userService;
} public void setRequestDao(RequestDao requestDao) { this.requestDao = requestDao;
} /**
* @Dscriptions saves request submitted by Engineer or SDM
* @param request
* @return true if save success
* @throws Exception
*/
@Override
public boolean addRequest(Request request) throws Exception { requestDao.addRequest(request);
return true;
} /**
* @Dscriptions gets requests by status
* @param status
* @return the list of request entities
* @throws Exception
*/
@Override
public List<Request> getRequestByStatus(String status) throws Exception { checkDoneRequest();
return requestDao.getRequestByStatus(status);
} /**
* @Dscriptions gets request by the key of request table.
* @param id
* : the key of request table
* @return request entity
* @throws Exception
*/
@Override
public Request getRequestById(int id) throws Exception { return requestDao.getRequestById(id);
} /**
* @Dscriptions updates request,mainly used to change password
* @param request
* @return true if update success
* @throws Exception
*/
@Override
public boolean updateRequest(Request request) throws Exception { requestDao.updateRequest(request);
return true;
} /**
* @Dscriptions gets current time
* @return current time
*/
@Override
public Timestamp getCurrentTime() { Date now = new Date();
Timestamp currentTime = new Timestamp(now.getTime());
return currentTime;
} /**
* @Dscriptions gets current user
* @return current user entity
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
public User getCurrentUser() throws Exception { Map session = ActionContext.getContext().getSession();
Integer userId = (Integer) session.get("userid");
if (userId != null) { return userService.getUserById(userId);
}
return null;
} /**
* @Dscriptions changes the status of request
* @param id
* : the key of request table
* @param operation
* : the status which want to change
* @return true if operation success
* @throws Exception
*/
@Override
@Transactional
public boolean operateRequest(int id, String operation) throws Exception { if (getCurrentUser() != null) { request = getRequestById(id);
request.setExecuteTime(getCurrentTime());
request.setExecutor(getCurrentUser());
request.setStatus(operation);
action.setRequest(getRequestById(id));
action.setStart(getRequestById(id).getStatus());
action.setEnd(operation);
action.setOperationTime(getCurrentTime());
action.setExecutor(getCurrentUser());
updateRequest(request);
requestDao.addAction(action);
return true;
} else {
return false;
}
} /**
* @Dscriptions gets requests by status
* @param requester
* @return the list of request entities
* @throws Exception
*/
@Override
public Pager getRequestByRequester(User requester,Pager pager) throws Exception { checkDoneRequest();
return requestDao.getRequestByRequester(requester,pager);
} /**
* @Dscriptions gets requests which IT Staff can view
* @return the list of request entities
* @throws Exception
*/
@Override
public Pager getRequestsForITStaff(Pager pager) throws Exception { checkDoneRequest();
return requestDao.getRequestsForITStaff(pager);
} /**
* @Descriptions getss all the requests in request table
* @return the list of request entities
* @throws Exception
*/
@Override
public Pager getAllRequests(Pager pager) throws Exception { checkDoneRequest();
return requestDao.getAllRequests(pager);
} /**
* @Descriptions determines whether it is one day later
* @param timeStamp
* @return true if one day later
*/
@Override
public boolean isAfterOneDay(Timestamp doneTime) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR, CLOSE_TIME);
Timestamp currentTime = new Timestamp(calendar.getTimeInMillis());
if (currentTime.after(doneTime)) { return true;
} else { return false;
}
} /**
* @throws Exception
* @Descriptions determines whether the done request can be close
*/
@Transactional
@Override
public void checkDoneRequest() throws Exception { List<Request> requests = requestDao.getRequestByStatus(DONE);
for (Request request : requests) { boolean isClose = isAfterOneDay(request.getExecuteTime());
if (isClose) { operateRequest(request.getId(), CLOSE);
}
}
}
}
package com.augmentum.larry.service;import java.util.ArrayList;
import java.util.List;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.RequestType;/**
* @Dscriptions defines methods which get data from DAO and do some business
* logic.
* @category name RequestTypeService
* @author larry.chi
* @version 1.0
*/
public interface RequestTypeService {
/**
* @Dscriptions gets all the requestTypes,that is to say,get requests SDM can
* see.
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
public Pager getAllRequestTypes(Pager pager) throws Exception; /**
* @Dscriptions gets all the requestTypes,that is to say,get requests SDM can
* see.
* @return the list of request type entities
* @throws Exception
*/
public List<RequestType> getAllRequestTypes() throws Exception;
/**
* @Dscriptions administrator adds a request type
* @param requestType
* @return true if add success
* @throws Exception
*/
public boolean addRequestType(RequestType requestType) throws Exception; /**
* @Dscriptions administrator deletes a request type
* @param requestType
* @return true if delete success
* @throws Exception
*/
public boolean deleteRequestType(RequestType requestType) throws Exception; /**
* @Dscriptions administrator updates a request type
* @param requestType
* @return true if update success
* @throws Exception
*/
public boolean updateRequestType(RequestType requestType) throws Exception; /**
* @Dscriptions gets request type by id
* @param id
* : the key of request type table
* @return RequestType entity
* @throws Exception
*/
public RequestType getRequestTypeById(int id) throws Exception; /**
* @Dscriptions gets all the request types' name
* @return the list of request type entities
* @throws Exception
*/
public List<String> getRequestTypeNames() throws Exception; /**
* @Dscriptions gets template by id
* @param id
* : the key of request type table
* @return the template which have been processed
* @throws Exception
*/
public ArrayList<ArrayList<Object>> getTemplateById(int id)
throws Exception; /**
* @Dscriptions gets current user's role
* @return current user role
*/
public String getCurrentUserRole(); /**
* @Descriptions analyzes request type template
*/
public ArrayList<ArrayList<Object>> getTemplate(String template);
}
package com.augmentum.larry.service.impl;import java.util.List;import com.augmentum.larry.dao.FeatureDao;
import com.augmentum.larry.model.Feature;
import com.augmentum.larry.model.Pager;
import com.augmentum.larry.service.FeatureService;/**
* @Descriptions defines methods which get data from DAO and do some business
* logic.
* @author larry.chi
* @category
* @name FeatureServiceImpl
* @version 1.0
*/
public class FeatureServiceImpl implements FeatureService { private FeatureDao featureDao; public void setFeatureDao(FeatureDao featureDao) { this.featureDao = featureDao;
} /**
* @Descriptions gets feature menu by user role
* @param role
* @return the list of feature entity
* @throws Exception
*/
@Override
public List<Feature> getMenuByRole(String role) throws Exception { return featureDao.getMenuByRole(role);
} /**
* @Descriptions saves the feature added by administrator
* @param feature
* @return true if save success
* @throws Exception
*/
@Override
public boolean saveFeature(Feature feature) throws Exception { featureDao.addFeature(feature);
return true;
} /**
* @Descriptions gets all the features in feature table
*
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
@Override
public Pager getMenuList(Pager pager) throws Exception { return featureDao.getMenuList(pager);
} /**
* @Descriptions administrator deletes a feature
* @param feature
* @return true if delete success
* @throws Exception
*/
@Override
public boolean deleteFeature(Feature feature) throws Exception { featureDao.deleteFeature(feature);
return true;
} /**
* @Descriptions gets feature by id
* @param id
* : the key of feature table
* @return feature entity
* @throws Exception
*/
@Override
public Feature getFeatureById(int id) throws Exception { return featureDao.getFeatureById(id);
} /**
* @Descriptions administrator updates a feature
* @param feature
* @return true if update success
* @throws Exception
*/
@Override
public boolean updateFeature(Feature feature) throws Exception { featureDao.updateFeature(feature);
return true;
}}package com.augmentum.larry.service;import java.util.List;import com.augmentum.larry.model.UserRole;
/**
* @Descriptions defines methods to handle about UserRole's business logic.
*
* @category interface
* @author larry.chi
* @version 1.0
*/
public interface UserRoleService {
/**
* @Descriptions gets all the user roles
*
* @return the list of UserRole entities
* @throws Exception
*/
public List<UserRole> getAllUserRole() throws Exception;
}package com.augmentum.larry.service;import java.sql.Timestamp;
import java.util.List;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.Request;
import com.augmentum.larry.model.User;/**
* @Dscriptions defines methods which get data from DAO and do some business
* logic.
* @category
* @name RequestService
* @author larry.chi
* @version 1.0
*/
public interface RequestService { /**
* @Dscriptions saves request submitted by Engineer or SDM
* @param request
* @return true if save success
* @throws Exception
*/
public boolean addRequest(Request request) throws Exception; /**
* @Dscriptions gets requests by status
* @param status
* @return the list of request entities
* @throws Exception
*/
public List<Request> getRequestByStatus(String status) throws Exception; /**
* @Dscriptions gets requests by status
* @param requester :user entity
* @param pager :pager entity
* @return pager entity
* @throws Exception
*/
public Pager getRequestByRequester(User requester,Pager pager) throws Exception; /**
* @Dscriptions gets request by the key of request table.
* @param id
* : the key of request table
* @return request entity
* @throws Exception
*/
public Request getRequestById(int id) throws Exception; /**
* @Dscriptions updates request,mainly used to change password
* @param request
* @return true if update success
* @throws Exception
*/
public boolean updateRequest(Request request) throws Exception; /**
* @Dscriptions gets current time
* @return current time
*/
public Timestamp getCurrentTime(); /**
* @Dscriptions gets current user
* @return current user entity
* @throws Exception
*/
public User getCurrentUser() throws Exception; /**
* @Dscriptions gets requests which IT Staff can view
*
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
public Pager getRequestsForITStaff(Pager pager) throws Exception; /**
* @Dscriptions changes status of request
* @param id
* : the key of request table
* @param operation
* : the status which want to change
* @return true if operation success
* @throws Exception
*/
public boolean operateRequest(int id, String operation) throws Exception; /**
* @Descriptions gets all the requests in request table
* @param pager :pager entity
* @return pager :pager entity
* @throws Exception
*/
public Pager getAllRequests(Pager pager) throws Exception; /**
* @Descriptions determines whether it is one day later
* @param timeStamp
* @return true if one day later
*/
public boolean isAfterOneDay(Timestamp doneTime); /**
* @Descriptions determines whether the done request can be close
*
* @throws Exception
*/
public void checkDoneRequest() throws Exception;
}
package com.augmentum.larry.service;import java.util.List;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.User;/**
* @Dscriptions defines methods which get data from DAO and do some business
* logic.
* @category
* @name UserService
* @author larry.chi
* @version 1.0
*/
public interface UserService { /**
* @Dscriptions administrator adds a user
* @param user
* @return true if add success
* @throws Exception
*/
public boolean addUser(User user) throws Exception; /**
* @Dscriptions determines whether login is success
* @param username
* @param password
* @return true if userName and password is exist
* @throws Exception
*/
public boolean isLogin(String username, String password) throws Exception; /**
* @Dscriptions determines whether userName is exist
* @param username
* @return true if exist
* @throws Exception
*/
public boolean isExistUserName(String username) throws Exception; /**
* @Dscriptions determines whether email is exist
* @param email
* @return true if exist
* @throws Exception
*/
public boolean isExistEmail(String email) throws Exception; /**
* @Dscriptions gets the role by userName
* @param username
* @return user role
* @throws Exception
*/
public String getRole(String username) throws Exception; /**
* @Dscriptions changes user's password
* @param username
* @param password
* @return true if change success
* @throws Exception
*/
public boolean changePassword(String username, String password) throws Exception; /**
* @Dscriptions gets all users
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
public Pager getUsers(Pager pager) throws Exception; /**
* @Dscriptions gets all managers
* @return the list of user entities
* @throws Exception
*/
public List<User> getManagers() throws Exception; /**
* @Dscriptions gets user by id
* @param id
* @return the user entity
* @throws Exception
*/
public User getUserById(int id) throws Exception; /**
* @Dscriptions updates user
* @param user
* @return true if update success
* @throws Exception
*/
public boolean updateUser(User user) throws Exception; /**
* @Dscriptions gets the sdm's all engineers
* @param sdm
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
public Pager getMyEngineers(User sdm,Pager pager) throws Exception; /**
* @Dscriptions determines whether ID_NO is exist
* @param ID_NO
* @return true if exist
* @throws Exception
*/
public boolean isExistID_NO(String ID_NO) throws Exception;
}package com.augmentum.larry.service;import com.augmentum.larry.model.Pager;
/**
* @Descriptions defines methods which get data from DAO and do some business logic.
* @category interface
* @name ActionsService
* @author larry.chi
* @version 1.0
*/
public interface ActionsService {
/**
* @Descriptions gets all the operations
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
public Pager getOperations(Pager pager) throws Exception;
/**
* @Descriptions gets the total count of operations.
*
* @return total count of operations.
* @throws Exception
*/
public int getTotalCount()throws Exception;
}package com.augmentum.larry.service;import java.util.List;import com.augmentum.larry.model.Feature;
import com.augmentum.larry.model.Pager;
/**
* @Descriptions defines methods which get data from DAO and do some business logic.
* @author larry.chi
* @category interface
* @name FeatureService
* @version 1.0
*/
public interface FeatureService {
/**
* @Descriptions gets feature menu by user role
* @param role
* @return the list of feature entity
* @throws Exception
*/
public List<Feature> getMenuByRole(String role) throws Exception;
/**
* @Descriptions saves the feature added by administrator
* @param feature
* @return true if save success
* @throws Exception
*/
public boolean saveFeature(Feature feature) throws Exception;
/**
* @Descriptions gets all the features in feature table
*
* @param pager: pager entity
* @return pager entity
* @throws Exception
*/
public Pager getMenuList(Pager pager) throws Exception;
/**
* @Descriptions gets feature by id
* @param id: the key of feature table
* @return feature entity
* @throws Exception
*/
public Feature getFeatureById(int id) throws Exception;
/**
* @Descriptions administrator deletes a feature
* @param feature
* @return true if delete success
* @throws Exception
*/
public boolean deleteFeature(Feature feature) throws Exception;
/**
* @Descriptions administrator updates a feature
* @param feature
* @return true if update success
* @throws Exception
*/
public boolean updateFeature(Feature feature) throws Exception;
}
package com.augmentum.larry.util;import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.LinkedList;
import java.util.Random;/**
* @Descriptions creates validation code
* @author larry.chi
*
*/
public class ValidateCode {
public String sRand="";
public ValidateCode(){
}
public Color getRandColor(int fc,int bc){
Random random=new Random();
if(fc>255){
fc=255;
}
if(bc>255){
bc=255;
}
int r=fc+random.nextInt(bc-fc);
int g=fc+random.nextInt(bc-fc);
int b=fc+random.nextInt(bc-fc);
return new Color(r,g,b);
}
public BufferedImage getBufferedImage(String content){
int width=60,height=20;
return getBufferedImage(content,width,height);
}
public BufferedImage getBufferedImage(String content,int width,int height){
BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics2D g=image.createGraphics();
Random random=new Random();
String []fonts={"Arial","Times New Roman","Bitstream Vera Sans","Gulim","Trebuchet MS","WST_Engl"};
int i=random.nextInt(5);
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);
g.setFont(new Font(fonts[i],Font.PLAIN,18));
g.setColor(Color.black);
g.drawString(content, 10, 15);
g.dispose();
return image;
}
public String getContent()throws InterruptedException{
String content="";
for(int i=0;i<4;i++){
content +=getChar();
Thread.sleep(new Random().nextInt(10)+10);
}
return content;
}
public char getChar(){
Random random=new Random();
char ch='0';
LinkedList<String> ls=new LinkedList<String>();
for(int i=0;i<10;i++){
ls.add(String.valueOf(48+i));
}
for(int i=0;i<26;i++){
ls.add(String.valueOf(65+i));
}
for(int i=0;i<26;i++){
ls.add(String.valueOf(97+i));
}
int index=random.nextInt(ls.size());
if(index>(ls.size()-1)){
index=ls.size()-1;
}
ch=(char)Integer.parseInt(String.valueOf(ls.get(index)));
return ch;
}
}package com.augmentum.larry.util;/**
* @Descriptions Exception(SystemException) defines by myself
*
* @author larry.chi
*
*/
public class SystemException extends Exception {
private static final long serialVersionUID = 0xc1a865c45ffdc5f9L; public SystemException(String frdMessage,Throwable throwable) {
super(createFriendlyErrMsg(frdMessage),throwable); } public SystemException(Throwable throwable) {
super(throwable);
} public SystemException(Throwable throwable, String frdMessage) {
super(throwable);
} private static String createFriendlyErrMsg(String msgBody) { String prefixStr = "Sorry,program exception,<***";
String suffixStr = " ***>.Please try again later or contact administrator!";
StringBuffer friendlyErrMsg = new StringBuffer("");
friendlyErrMsg.append(prefixStr);
friendlyErrMsg.append(msgBody);
friendlyErrMsg.append(suffixStr);
return friendlyErrMsg.toString();
}
}
package com.augmentum.larry.util;public class Page {// get method is ignored.
private int totalPage;
private int currentPage;
private int totalRecord;
private int currentRecord;
private int pageSize = 15; public int getTotalPage() {
return totalPage;
} public int getCurrentPage() {
return currentPage;
} public int getTotalRecord() {
return totalRecord;
} public int getCurrentRecord() {
return currentRecord;
} public int getPageSize() {
return pageSize;
} public void setTotalPage(int totalRecord, int pageSize) {
if (totalRecord % pageSize == 0) {
totalPage = totalRecord / pageSize;
} else {
totalPage = totalRecord / pageSize + 1;
}
} public void setCurrentPage(int currentRecord, int pageSize) {
if (currentRecord % pageSize == 0) {
currentPage = currentRecord / pageSize;
} else {
currentPage = currentRecord / pageSize + 1;
}
} public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
} public void setCurrentRecord(int currentRecord) {
this.currentRecord = currentRecord;
} public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
}
package com.augmentum.larry.util;import java.security.*;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import org.apache.log4j.Logger;/**
* @Descriptions DES encryption
*
* @author larry.chi
*
*/
public class DesEncryption { private static final Logger log = Logger.getLogger(DesEncryption.class);
private static final String PASSWORD_CRYPT_KEY = "3118310"; private final static String DES = "DES"; /**
*
* encryption
*
* @param src
*
* @param key
*
* @return the string after encryption
*
* @throws Exception
*/ public static byte[] encrypt(byte[] src, byte[] key) throws Exception { SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance(DES);
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
return cipher.doFinal(src); } /**
*
* decryption
*
* @param src
*
* @param key
*
* @return
*
* @throws Exception
*/ public static byte[] decrypt(byte[] src, byte[] key) throws Exception { SecureRandom sr = new SecureRandom();
DESKeySpec dks = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance(DES);
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
return cipher.doFinal(src); } /**
*
* decryption
*
* @param data
*
* @return
*
* @throws Exception
*/ public final static String decrypt(String data) { try { return new String(decrypt(hex2byte(data.getBytes()), PASSWORD_CRYPT_KEY.getBytes())); } catch (Exception e) { }
return null; } /**
*
* encryption
*
* @param password
*
* @return
* @throws Exception
*
* @throws Exception
*/ public final static String encrypt(String password) throws Exception { try { return byte2hex(encrypt(password.getBytes(), PASSWORD_CRYPT_KEY
.getBytes()));
} catch (Exception e) { log.error("Password encrypts fail!", e);
throw e;
}
} /**
*
* byte to hex
*
* @param b
*
* @return
*/ public static String byte2hex(byte[] b) { String hs = ""; String stmp = ""; for (int n = 0; n < b.length; n++) { stmp = (java.lang.Integer.toHexString(b[n] & 0XFF)); if (stmp.length() == 1) hs = hs + "0" + stmp; else hs = hs + stmp;
} return hs.toUpperCase(); } public static byte[] hex2byte(byte[] b) { if ((b.length % 2) != 0) throw new IllegalArgumentException("Length is not even!"); byte[] b2 = new byte[b.length / 2]; for (int n = 0; n < b.length; n += 2) { String item = new String(b, n, 2); b2[n / 2] = (byte) Integer.parseInt(item, 16); } return b2;
}
}
package com.augmentum.larry.util;import java.security.Key;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* @Descriptions DES encryption
*
* @author larry.chi
*
*/
public class DES {
Key key;
public DES(String str) {
setKey(str);
}
public DES() {
setKey("3118310");
}
public void setKey(String strKey) {
try {
KeyGenerator _generator = KeyGenerator.getInstance("DES");
_generator.init(new SecureRandom(strKey.getBytes()));
this.key = _generator.generateKey();
_generator = null;
} catch (Exception e) {
throw new RuntimeException(
"Error initializing SqlMap class. Cause:" + e);
}
}
/**
* encrypts string
* @return string after encryption
*/
public String getEncString(String strMing) {
byte[] byteMi = null;
byte[] byteMing = null;
String strMi ="";
BASE64Encoder base64en = new BASE64Encoder();
try {
byteMing = strMing.getBytes("UTF8");
byteMi = this.getEncCode(byteMing);
strMi = base64en.encode(byteMi);
} catch (Exception e) {
throw new RuntimeException(
"Error initializing SqlMap class. Cause:" + e);
} finally {
base64en = null;
byteMing = null;
byteMi = null;
}
return strMi;
}
/**
* descryption
* @param strMi
* @return
*/
public String getDesString(String strMi) {
BASE64Decoder base64De = new BASE64Decoder();
byte[] byteMing = null;
byte[] byteMi = null;
String strMing ="";
try {
byteMi = base64De.decodeBuffer(strMi);
byteMing = this.getDesCode(byteMi);
strMing = new String(byteMing,"UTF8");
} catch (Exception e) {
throw new RuntimeException(
"Error initializing SqlMap class. Cause:" + e);
} finally {
base64De = null;
byteMing = null;
byteMi = null;
}
return strMing;
}
/**
* encryption
* @param byteS
* @return
*/
private byte[] getEncCode(byte[] byteS) {
byte[] byteFina = null;
Cipher cipher;
try {
cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byteFina = cipher.doFinal(byteS);
} catch (Exception e) {
throw new RuntimeException(
"Error initializing SqlMap class. Cause:" + e);
} finally {
cipher = null;
}
return byteFina;
}
/**
* descryption
* @param byteD
* @return
*/
private byte[] getDesCode(byte[] byteD) {
Cipher cipher;
byte[] byteFina = null;
try {
cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
byteFina = cipher.doFinal(byteD);
} catch (Exception e) {
throw new RuntimeException(
"Error initializing SqlMap class. Cause:" + e);
} finally {
cipher = null;
}
return byteFina;
}
}
package com.augmentum.larry.unitTest;import static org.junit.Assert.*;import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.augmentum.larry.model.Pager;
import com.augmentum.larry.model.User;
import com.augmentum.larry.service.UserService;public class UserServiceTest { private static UserService userService; @BeforeClass
public static void setUpBeforeClass() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext(
"applicationContext.xml");
userService = (UserService) ac.getBean("userService");
} @AfterClass
public static void tearDownAfterClass() throws Exception { } @Test
public void testId_noExist() throws Exception { String ID_NO = "T03596";
assertTrue(userService.isExistID_NO(ID_NO));
} @Test
public void testUserExist() throws Exception { String userName = "Larry Chi";
assertTrue(userService.isExistUserName(userName));
} @Test
public void testEmailExist() throws Exception { String email = "[email protected]";
assertTrue(userService.isExistEmail(email));
} @Test
public void testGetRole() throws Exception { String userName = "Engineer";
assertEquals("Engineer", userService.getRole(userName));
} @Test
public void testGetUsers() throws Exception { Pager pager = new Pager();
assertNotNull(userService.getUsers(pager));
} @Test
public void testGetManagers() throws Exception { assertNotNull(userService.getManagers());
} @Test
public void testGetUserById() throws Exception { assertNotNull(userService.getUserById(1));
} @Test
public void testAddUser() throws Exception { User user = new User();
user.setID_NO("T03596");
user.setName("Larry Chi");
user.setEmail("[email protected]");
user.setRole("Engineer");
user.setPassword("abc123_");
assertFalse(userService.addUser(user));
}
}package com.augmentum.larry.unitTest;import static org.junit.Assert.*;import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.augmentum.larry.service.RequestTypeService;public class RequestTypeServiceTest { private static RequestTypeService requestTypeService;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
requestTypeService = (RequestTypeService) ac.getBean("requestTypeService");
} @AfterClass
public static void tearDownAfterClass() throws Exception {
} @Test
public void testGetRequestTypeById() throws Exception { assertNotNull(requestTypeService.getRequestTypeById(2));
} @Test
public void testGetRequestTypeNames() throws Exception { assertNotNull(requestTypeService.getRequestTypeNames());
} @Test
public void testGetTemplateById() throws Exception { assertNotNull(requestTypeService.getTemplateById(2));
}}/**
*
*/
package com.augmentum.larry.unitTest;import static org.junit.Assert.*;import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.augmentum.larry.service.RequestService;/**
* @author larry.chi
*
*/
public class RequestServiceTest { private static RequestService requestService; /**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception { ApplicationContext ac = new ClassPathXmlApplicationContext(
"applicationContext.xml");
requestService = (RequestService) ac.getBean("requestService");
} /**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
} /**
* Test method for
* {@link com.augmentum.larry.service.impl.RequestServiceImpl#getRequestByStatus(java.lang.String)}
* .
*
* @throws Exception
*/
@Test
public void testGetRequestByStatus() throws Exception { String status = "close";
assertNotNull(requestService.getRequestByStatus(status));
} /**
* Test method for
* {@link com.augmentum.larry.service.impl.RequestServiceImpl#getRequestById(int)}
* .
*
* @throws Exception
*/
@Test
public void testGetRequestById() throws Exception { assertNotNull(requestService.getRequestById(1));
} /**
* Test method for
* {@link com.augmentum.larry.service.impl.RequestServiceImpl#getCurrentTime()}
* .
*/
@Test
public void testGetCurrentTime() { assertNotNull(requestService.getCurrentTime());
}}
package com.augmentum.larry.unitTest;import static org.junit.Assert.*;import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.augmentum.larry.service.FeatureService;public class FeatureServiceTest { private static FeatureService featureService; @BeforeClass
public static void setUpBeforeClass() throws Exception { ApplicationContext ac = new ClassPathXmlApplicationContext(
"applicationContext.xml");
featureService = (FeatureService) ac.getBean("featureService");
} @AfterClass
public static void tearDownAfterClass() throws Exception {
} @Test
public void testGetMenuByRole() throws Exception { String role = "Engineer";
assertNotNull(featureService.getMenuByRole(role));
} @Test
public void testGetFeatureById() throws Exception { assertNotNull(featureService.getFeatureById(2));
}}