package cn.myapps.runtime.role;

import cn.myapps.common.model.role.Role;
import cn.myapps.designtime.common.service.DesignTimeServiceManager;
import cn.myapps.designtime.role.service.RoleDesignTimeService;

public class RoleHelper {

	public RoleHelper() throws Exception {
	}


	public String queryRoleNamesByIds(String idString) throws Exception {
		RoleDesignTimeService roleService = DesignTimeServiceManager.roleDesignTimeService();
		String[] idArray = idString.split(",");
		StringBuffer roleNameString = new StringBuffer();
		if (idArray.length > 0) {
			for (int i = 0; i < idArray.length; i++) {
				String id = idArray[i];
				Role role = (Role) roleService.findById(id);
				roleNameString.append(role.getName()).append(",");
			}
			if (roleNameString.length() > 0
					&& roleNameString.toString().endsWith(",")) {
				roleNameString.setLength(roleNameString.length() - 1);
			}
		}
		return roleNameString.toString();
	}

}
