📄 departmentaction.java
字号:
package cn.myapps.core.department.action;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.jsp.tagext.TryCatchFinally;
import cn.myapps.base.action.BaseAction;
import cn.myapps.base.action.ParamsTable;
import cn.myapps.core.department.ejb.DepartmentProcess;
import cn.myapps.core.department.ejb.DepartmentVO;
import cn.myapps.core.department.ejb.DepartmentException;
import cn.myapps.core.permission.ejb.PermissionVO;
import cn.myapps.core.resource.ejb.ResourceProcess;
import cn.myapps.core.resource.ejb.ResourceVO;
import cn.myapps.core.role.ejb.RoleProcess;
import cn.myapps.core.role.ejb.RoleVO;
import cn.myapps.core.user.ejb.UserVO;
import cn.myapps.util.ProcessFactory;
import cn.myapps.util.sequence.Sequence;
/**
* @see cn.myapps.base.action.BaseAction
* DepartmentAction class.
* @author Darvense
* @since JDK1.4
*/
public class DepartmentAction extends BaseAction {
private String _superiorid;
private Collection _deptSelect;
public Collection departments=null;
private Collection _resourcelist;
/**
* Get the _resourcelist
* @return _resourcelist
*/
public Collection get_resourcelist() {
DepartmentVO content = (DepartmentVO) getContent();
_resourcelist=new HashSet();
if(content.getId()!=null&&content.getId().trim().length()>0)
{
Collection col=content.getPermission();
Iterator it=col.iterator();
while(it.hasNext())
{
PermissionVO per=(PermissionVO)it.next();
if(per.getResource()!=null)
_resourcelist.add(per.getResource().getId());
}
return _resourcelist;
}
else
return null;
}
/**
* Set the _resourcelist
* @param _resourcelist
* @throws Exception
*/
public void set_resourcelist(Collection _resourcelist)throws Exception {
DepartmentVO content = (DepartmentVO) getContent();
ResourceProcess rp = (ResourceProcess)ProcessFactory
.createProcess(ResourceProcess.class);
for (Iterator iter = _resourcelist.iterator(); iter.hasNext();) {
String rid = (String)iter.next();
ResourceVO rv=(ResourceVO)rp.doView(rid);
PermissionVO pv=new PermissionVO();
pv.setId(Sequence.getSequence());
pv.setResource(rv);
content.getPermission().add(pv);
}
}
/**
* Get the _superiorid
* @return _superiorid
*/
public String get_superiorid() {
DepartmentVO content = (DepartmentVO) this.getContent();
if (content.getSuperior() != null) {
_superiorid = content.getSuperior().getId();
} else {
_superiorid = null;
}
return _superiorid;
}
/**
* Set _superiorid.
* @param _superiorid
* @throws Exception
*/
public void set_superiorid(String _superiorid)throws Exception {
this._superiorid = _superiorid;
if(_superiorid!=null&&_superiorid.trim().length()>0){
DepartmentVO content = (DepartmentVO) this.getContent();
DepartmentVO superior = (DepartmentVO) proxy.doView(_superiorid);
if(superior!=null){
content.setSuperior(superior);
content.setLevel(superior.getLevel()+1);}
}
}
/**
*
* DepartmentAction structure function.
* @throws ClassNotFoundException
*/
public DepartmentAction() throws Exception {
super(ProcessFactory.createProcess(DepartmentProcess.class),
new DepartmentVO());
departments = proxy.doSimpleQuery(null);
}
/**
* Get the _departments.
* @return _departments
* @throws Exception
*/
public Map get_departments() throws Exception {
ParamsTable params=new ParamsTable();
params.setParameter("application", getApplication());
Collection dc = proxy.doSimpleQuery(params);
Map dm = ((DepartmentProcess) proxy).deepSearchDepartmentTree(dc, null,
getContent().getId(), 0);
if (dm.isEmpty()) {
dm.put("", "无");
}
return dm;
}
/**
* Select department.
* @return If the action execution was successful.return "SUCCESS".Show an success view .<p>
* If the action execution was a failure. return "ERROR".Show an error view, possibly asking the user to retry entering data. <p>
* The "INPUT" is also used if the given input params are invalid, meaning the user should try providing input again.
*
* @throws Exception
*/
public String doSelect() throws Exception {
_deptSelect = proxy.doSimpleQuery(this.getParams());
return SUCCESS;
}
/**
* Get the _deptSelect.
* @return _deptSelect
*/
public Collection get_deptSelect() {
return _deptSelect;
}
/**
* Set the _deptSelect
* @param select
*/
public void set_deptSelect(Collection select) {
_deptSelect = select;
}
/**
* Delete a DepartmentVO.
* @return If the action execution was successful.return "SUCCESS".Show an success view .<p>
* If the action execution was a failure. return "ERROR".Show an error view, possibly asking the user to retry entering data. <p>
* The "INPUT" is also used if the given input params are invalid, meaning the user should try providing input again.
*
* @throws Exception
*/
public String doDelete() throws Exception
{
DepartmentVO tempDepartment = null;
String ErrorField="";
if (_selects != null){
for (int i = 0; i < _selects.length; i++)
{
String id = _selects[i];
try
{
proxy.doRemove(id);
}catch(DepartmentException e) {
ErrorField = e.getMessage()+"," + ErrorField;
}
}
}
if(!ErrorField.equals(""))
{
if(ErrorField.endsWith(","))
{
ErrorField =ErrorField.substring(0,ErrorField.length()-1);
}
this.addFieldError("1",ErrorField);
}
return SUCCESS;
}
/**
* Save tempDepartment.
* @return If the action execution was successful.return "SUCCESS".Show an success view .<p>
* If the action execution was a failure. return "ERROR".Show an error view, possibly asking the user to retry entering data. <p>
* The "INPUT" is also used if the given input params are invalid, meaning the user should try providing input again.
*
* @throws Exception
*/
public String doSave() throws Exception
{
DepartmentVO tempDepartment = (DepartmentVO)(this.getContent());
boolean flag=false;
String tempname = tempDepartment.getName();
DepartmentVO Superior = tempDepartment.getSuperior();
Collection departments = ((DepartmentProcess)proxy).getDepartmentByName(tempname, getApplication());
for (Iterator iter = departments.iterator(); iter.hasNext();) {
DepartmentVO dp = (DepartmentVO) iter.next();
if(tempDepartment.getId()==null)
{
if(Superior!=null&&dp.getSuperior()!=null&&dp.getSuperior().getId().equals(Superior.getId()))
{ this.addFieldError("1","Sorry! this Deparment has existed ,please choose another!");
flag=true;
}
else if(Superior==null&&dp.getSuperior()==null)
{
this.addFieldError("1","Sorry! this Deparment has existed ,please choose another!");
flag=true;
}
}
else
{
if(!tempDepartment.getId().equals(dp.getId())&&Superior!=null&&dp.getSuperior()!=null&&dp.getSuperior().getId().equals(Superior.getId()))
{ this.addFieldError("1","Sorry! this Deparment has existed ,please choose another!");
flag=true;
}
else if(!tempDepartment.getId().equals(dp.getId())&&Superior==null&&dp.getSuperior()==null)
{
this.addFieldError("1","Sorry! this Deparment has existed ,please choose another!");
flag=true;
}
}
}
if(!flag)
{
if(tempDepartment.getId()==null||tempDepartment.getId().equals("")){
proxy.doCreate(tempDepartment);
}
else{
proxy.doUpdate(tempDepartment);
}
}
return SUCCESS;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -