/*************************************************** * Copyright 2009-11-25, -sun,All rights reserved. * Create date : 2009-11-25 * Author : sun **************************************************/ package com.sinosoft.lz.system.right.role; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.persistence.service.PersistenceFactory; import com.persistence.service.SysPersistence; import com.persistence.service.exception.PersistenceException; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.MdpConstant; import com.sysmodel.datamodel.xmlmodel.able.SysModel; // TODO: Auto-generated Javadoc /** * The Class RoleImpl. */ public class RoleImpl implements Roleable{ /* * (non-Javadoc) * * @see * com.sinosoft.lz.system.right.role.Roleable#getAllRoleByUserId(java.lang * .String, boolean) */ public ArrayList getAllRoleByUserId(String userId, boolean isAssign) throws PersistenceException { StringBuffer sbsql = new StringBuffer( "SELECT Role_ID,Role_Name,Role_Type FROM SYS_ROLE where 1=1 "); if (!userId.equals("")) { if (isAssign) { sbsql.append(" and Role_ID in (select t.Role_ID from SYS_USER_ROLE_REL t "); sbsql.append(" where t.User_ID='" + userId + "')"); } else if (!isAssign) { sbsql.append(" and Role_ID not in (select t.Role_ID from SYS_USER_ROLE_REL t "); sbsql.append(" where t.User_ID='" + userId + "')"); } } sbsql.append(" ORDER BY Role_Type"); ArrayList rs = persistence.getSearchResult(886, sbsql.toString()); // 1 没有选中的 2选中的 StringBuffer strList = new StringBuffer(); String[] element = null; for (int i = 0; i < rs.size(); i++) { element = rs.get(i); element[2] = element[2] == null ? "" : element[2].trim(); // log.info("Role_Type = " + element[2]); if (element[2].equals("0")) element[1] = "『菜单模块角色』" + element[1]; if (element[2].equals("1")) element[1] = "(事件查看角色)" + element[1]; if (element[2].equals("2")) element[1] = "《路网监控角色》" + element[1]; if (element[2].equals("3")) element[1] = "【对象操作角色】" + element[1]; if (element[2].equals("4")) element[1] = "<病害处理角色>" + element[1]; strList.append(" \n"); element = null; } return rs; } /* * (non-Javadoc) * * @see * com.sinosoft.lz.system.right.role.Roleable#getRoleByType(java.lang.String * ) */ public List getRoleByType(String type) throws PersistenceException { String strSql = "SELECT Role_ID,Role_Name FROM SYS_ROLE where Role_Type = '" + type + "' ORDER BY FD_OBJECTID"; log.info("根据角色类型获得所有角色对象集合" + strSql); return persistence.getSearchResult(886, strSql); } /* * (non-Javadoc) * * @see * com.sinosoft.lz.system.right.role.Roleable#getRoleFunctionByType(java * .lang.String) */ public List getRoleFunctionByType(String type) { log.info("角色类型" + type); List result = new ArrayList(); // "2" 监控服务 if (type.equals("2")) { MdpConstant constant = sysmodel.getMdpConstantByName("BM$_MonitorService"); result = constant.getAllNode(); } return result; } /* * (non-Javadoc) * * @see * com.sinosoft.lz.system.right.role.Roleable#isFunctionInRole(java.lang * .String, java.lang.String) */ public boolean isFunctionInRole(String roleId, String functionId) throws PersistenceException { String sql = "select count(*) from SYS_ROLE_RIGHT_REL t where t.Role_ID='" + roleId + "' and t.Right_ID='" + functionId + "'"; // log.info(sql); int i = persistence.getFunctionNumber(99, sql); if (i > 0) { return true; } return false; } /** The sysmodel. */ private static SysModel sysmodel = ModelFactory.getSysmodel(); /** The persistence. */ private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); /** The log. */ private static Log log = LogFactory.getLog(RoleImpl.class); /** * 为了构造JUNIT单元测试 * * @param persistence */ @SuppressWarnings("static-access") public void setPersistence(SysPersistence persistence) { this.persistence = persistence; } }