📄 roleaction.java
字号:
package cn.myapps.core.role.action;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import cn.myapps.base.action.BaseAction;
import cn.myapps.core.department.ejb.DepartmentProcess;
import cn.myapps.core.department.ejb.DepartmentVO;
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.util.ProcessFactory;
import cn.myapps.util.sequence.Sequence;
public class RoleAction extends BaseAction {
private Collection _resourcelist;
public Collection get_resourcelist() {
RoleVO content = (RoleVO) 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();
_resourcelist.add(per.getResource().getId());
}
return _resourcelist;
}
else
return null;
}
public void set_resourcelist(Collection _resourcelist)throws Exception {
RoleVO content = (RoleVO) 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);
}
}
public RoleAction() throws Exception {
super(ProcessFactory.createProcess(RoleProcess.class), new RoleVO());
}
public String doGrant() throws Exception {
String id = (String)getContext().getParameters().get("id");
RoleVO contentVO = (RoleVO) proxy.doView(id);
return null;
}
public String doSave() throws Exception {
RoleVO tempRole = (RoleVO)(this.getContent());
boolean flag = false;
String tempname = tempRole.getName();
DepartmentVO department = tempRole.getDepartment();
Collection roles = ((RoleProcess)proxy).getRoleByName(tempname, getApplication());
for (Iterator iter = roles.iterator(); iter.hasNext();) {
RoleVO role = (RoleVO) iter.next();
if(tempRole.getId()==null){
if(department!= null&&role.getDepartment()!=null&&department.getId().equals(role.getDepartment().getId()))
{
flag=true;
this.addFieldError("1","Sorry! The name and Role has existed ,please choose another!");
}else if(department==null&&(role.getDepartment()==null)){
this.addFieldError("1","Sorry! this Role has existed ,please choose another!");
flag=true;
}
}
else
{
if(!tempRole.getId().equals(role.getId())&&department!= null&&role.getDepartment()!=null&&department.getId().equals(role.getDepartment().getId()))
{
flag=true;
this.addFieldError("1","Sorry! The name and Role has existed ,please choose another!");
}else if(!tempRole.getId().equals(role.getId())&&department==null&&(role.getDepartment()==null)){
this.addFieldError("1","Sorry! this Role has existed ,please choose another!");
flag=true;
}
}
}
if(!flag)
{
if (tempRole.getId() == null || tempRole.getId().equals("")) {
proxy.doCreate(tempRole);}
else{
proxy.doUpdate(tempRole);
}
}
return SUCCESS;
}
public Map get_departmentList(String application) throws Exception {
DepartmentProcess dp = (DepartmentProcess)ProcessFactory.createProcess(DepartmentProcess.class);
Collection dc = dp.doSimpleQuery(null, application);
Map dm = ((DepartmentProcess)dp).deepSearchDepartmentTree(dc,null,null,0);
return dm;
}
public String get_departmentid() {
RoleVO role = (RoleVO)getContent();
if (role.getDepartment()!=null) {
return role.getDepartment().getId();
}
else {
return null;
}
}
public void set_departmentid(String dptid) throws Exception {
RoleVO role = (RoleVO)getContent();
DepartmentProcess dp = (DepartmentProcess)ProcessFactory.createProcess(DepartmentProcess.class);
if (dptid!=null) {
DepartmentVO dptvo = (DepartmentVO)dp.doView(dptid);
role.setDepartment(dptvo);
}
}
public String doDelete() throws Exception
{
String ErrorField="";
RoleVO tempRole = null;
if (_selects != null){
for (int i = 0; i < _selects.length; i++)
{
String id = _selects[i];
try
{
tempRole = (RoleVO)(proxy.doView(id));
proxy.doRemove(id);
}catch (Exception e) {
ErrorField = tempRole.getName()+"," + ErrorField;
}
}
}
if(!ErrorField.equals(""))
{
if(ErrorField.endsWith(","))
{
ErrorField =ErrorField.substring(0,ErrorField.length()-1);
}
this.addFieldError("1",ErrorField);
}
return SUCCESS;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -