|
@@ -0,0 +1,213 @@
|
|
|
+package com.trs.web2frame;
|
|
|
+
|
|
|
+import com.trs.infra.common.BizError;
|
|
|
+import com.trs.infra.common.WCMException;
|
|
|
+import com.trs.infra.util.CMyString;
|
|
|
+import com.trs.infra.util.Loader;
|
|
|
+import com.trs.support.ApplicationProperties;
|
|
|
+import com.trs.util.DBUtil;
|
|
|
+import com.trs.util.ExcelReader;
|
|
|
+import com.trs.web2frame.dispatch.Dispatch;
|
|
|
+import junit.framework.TestCase;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Title: TRS 内容协作平台(TRS WCM) <BR>
|
|
|
+ * Description: <BR>
|
|
|
+ * TODO <BR>
|
|
|
+ * Copyright: Copyright (c) 2004-2005 TRS信息技术有限公司 <BR>
|
|
|
+ * Company: TRS信息技术有限公司(www.trs.com.cn) <BR>
|
|
|
+ *
|
|
|
+ * @author TRS信息技术有限公司 LY
|
|
|
+ * @version 1.0
|
|
|
+ */
|
|
|
+
|
|
|
+public class WCMRoleRightCallerTest extends TestCase {
|
|
|
+
|
|
|
+
|
|
|
+ private static final String connectUrl = ApplicationProperties.get("mysql_connectUrl");
|
|
|
+ private static final String userName = ApplicationProperties.get("user_name");
|
|
|
+ private static final String pswd = ApplicationProperties.get("pswd");
|
|
|
+ private static Connection connection;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setUp() throws Exception {
|
|
|
+ super.setUp();
|
|
|
+ connection = DBUtil.getConnection(connectUrl, userName, pswd);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void tearDown() throws Exception {
|
|
|
+ super.tearDown();
|
|
|
+ try {
|
|
|
+ if (connection != null) {
|
|
|
+ connection.close();
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量创建模板
|
|
|
+ */
|
|
|
+ public void testCreateRightTemplate() throws WCMException {
|
|
|
+
|
|
|
+ String filePath = Loader.getResource("template").getPath() + "/贵州-权限数据-填充模板.xlsx";
|
|
|
+
|
|
|
+
|
|
|
+ String[][] values = ExcelReader.readExcel(new File(filePath), 0, 1, 0);
|
|
|
+ //获取站点的偏移量
|
|
|
+ List<Map<String, Object>> siteOffset = querySiteOffset();
|
|
|
+ if (siteOffset == null || siteOffset.isEmpty()) {
|
|
|
+ throw new BizError("偏移量表未获取到数据");
|
|
|
+ }
|
|
|
+ testRightTemplate(values, siteOffset);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量创建角色,授权
|
|
|
+ */
|
|
|
+ public void testCreateRole() throws WCMException {
|
|
|
+
|
|
|
+ String filePath = Loader.getResource("template").getPath() + "/贵州-权限数据-填充模板.xlsx";
|
|
|
+
|
|
|
+ String[][] values = ExcelReader.readExcel(new File(filePath), 1, 1, 0);
|
|
|
+ //获取站点的偏移量
|
|
|
+ List<Map<String, Object>> siteOffset = querySiteOffset();
|
|
|
+ if (siteOffset == null || siteOffset.isEmpty()) {
|
|
|
+ throw new BizError("偏移量表未获取到数据");
|
|
|
+ }
|
|
|
+ //获取栏目的偏移量
|
|
|
+ List<Map<String, Object>> channelOffset = queryChannelOffset();
|
|
|
+ if (channelOffset == null || channelOffset.isEmpty()) {
|
|
|
+ throw new BizError("偏移量表未获取到数据");
|
|
|
+ }
|
|
|
+ testRole(values, siteOffset, channelOffset);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void testRightTemplate(String[][] values, List<Map<String, Object>> siteOffset) throws WCMException {
|
|
|
+
|
|
|
+ String sServiceId = "gov_right";
|
|
|
+
|
|
|
+ String sMethodName = "saveRightTemplate";
|
|
|
+
|
|
|
+ for (String[] strings : values) {
|
|
|
+
|
|
|
+ HashMap<String, Object> hParameters = new HashMap<>();
|
|
|
+
|
|
|
+ hParameters.put("CurrUserName", "admin"); // 当前操作的用户
|
|
|
+ if (CMyString.isEmpty(strings[0])) {
|
|
|
+ throw new BizError("权限模板名称不能为空");
|
|
|
+ }
|
|
|
+ hParameters.put("RTName", strings[0]);
|
|
|
+
|
|
|
+ if (!CMyString.isEmpty(strings[1])) {
|
|
|
+ long siteId = Double.valueOf(strings[1]).longValue();
|
|
|
+ long offsetNum = getOffset(siteOffset, siteId);
|
|
|
+ hParameters.put("SITEID", siteId + offsetNum);
|
|
|
+ }
|
|
|
+ if (CMyString.isEmpty(strings[2])) {
|
|
|
+ throw new BizError("权限值不能为空");
|
|
|
+ }
|
|
|
+ hParameters.put("RIGHTVALUE", strings[2]);
|
|
|
+
|
|
|
+ Dispatch oResult = WCMServiceCaller.Call(sServiceId, sMethodName, hParameters, true);
|
|
|
+
|
|
|
+ System.out.println("结果:" + oResult.getResponseText());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void testRole(String[][] values, List<Map<String, Object>> siteOffset, List<Map<String, Object>> channelOffset) throws BizError {
|
|
|
+
|
|
|
+ String sServiceId = "gov_role";
|
|
|
+
|
|
|
+ String sMethodName = "saveRolesAndRelations";
|
|
|
+
|
|
|
+ for (String[] strings : values) {
|
|
|
+
|
|
|
+ HashMap<String, Object> hParameters = new HashMap<>();
|
|
|
+ hParameters.put("CurrUserName", "admin"); // 当前操作的用户
|
|
|
+ if (CMyString.isEmpty(strings[0])) {
|
|
|
+ throw new BizError("角色名称不能为空");
|
|
|
+ }
|
|
|
+ hParameters.put("ROLENAME", strings[0]);
|
|
|
+ if (CMyString.isEmpty(strings[1])) {
|
|
|
+ throw new BizError("权限模板名称不能为空");
|
|
|
+ }
|
|
|
+ hParameters.put("RIGHTTEMNAME", strings[1]);
|
|
|
+ if (!CMyString.isEmpty(strings[2])) {
|
|
|
+ long siteId = Double.valueOf(strings[2]).longValue();
|
|
|
+ long siteOffsetNum = getOffset(siteOffset, siteId);
|
|
|
+ hParameters.put("SITEID", siteId + siteOffsetNum);
|
|
|
+ }
|
|
|
+ if (!CMyString.isEmpty(strings[3])) {
|
|
|
+ long channelId = Double.valueOf(strings[3]).longValue();
|
|
|
+ long channelOffsetNum = getOffset(channelOffset, channelId);
|
|
|
+ hParameters.put("CHANNELID", channelId + channelOffsetNum);
|
|
|
+ }
|
|
|
+ if (!CMyString.isEmpty(strings[4])) {
|
|
|
+ hParameters.put("USERNAMES", strings[4]);
|
|
|
+ }
|
|
|
+ if (!CMyString.isEmpty(strings[5])) {
|
|
|
+ hParameters.put("GROUPNAMES", strings[5]);
|
|
|
+ }
|
|
|
+ if (!CMyString.isEmpty(strings[6])) {
|
|
|
+ String channelIds = strings[6];
|
|
|
+ channelIds = channelIds.replaceAll(",", ",");
|
|
|
+ String[] channelIdStrs = CMyString.split(channelIds, ",");
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ for (String channelIdStr : channelIdStrs) {
|
|
|
+ long channelId = Long.parseLong(channelIdStr);
|
|
|
+ long channelOffsetNum = getOffset(channelOffset, channelId);
|
|
|
+ stringBuilder.append(channelId + channelOffsetNum).append(",");
|
|
|
+ }
|
|
|
+ stringBuilder.deleteCharAt(stringBuilder.length() - 1);
|
|
|
+ hParameters.put("CHANNELIDS", stringBuilder.toString());
|
|
|
+ }
|
|
|
+ Dispatch oResult = WCMServiceCaller.Call(sServiceId, sMethodName, hParameters, true);
|
|
|
+
|
|
|
+ System.out.println("结果:" + oResult.getResponseText());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> querySiteOffset() throws WCMException {
|
|
|
+
|
|
|
+ String sql = "SELECT * FROM data_migration_offset WHERE table_name = ?;";
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
+ list.add("wcmwebsite");
|
|
|
+ return DBUtil.getDBManager().executeStringsQuery(connection, sql, list);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> queryChannelOffset() throws WCMException {
|
|
|
+
|
|
|
+ String sql = "SELECT * FROM data_migration_offset WHERE table_name = ?;";
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
+ list.add("wcmchannel");
|
|
|
+ return DBUtil.getDBManager().executeStringsQuery(connection, sql, list);
|
|
|
+ }
|
|
|
+
|
|
|
+ private long getOffset(List<Map<String, Object>> offsetMap, long id) throws BizError {
|
|
|
+ long offsetNum = -1;
|
|
|
+ for (Map<String, Object> objectMap : offsetMap) {
|
|
|
+ long startId = (long) objectMap.get("START_ID");
|
|
|
+ long endId = (long) objectMap.get("END_ID");
|
|
|
+ if (id > startId && id <= endId) {
|
|
|
+ offsetNum = (long) objectMap.get("OFFSET_NUM");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (offsetNum == -1) {
|
|
|
+ throw new BizError("没有找到对应的偏移量");
|
|
|
+ }
|
|
|
+ return offsetNum;
|
|
|
+ }
|
|
|
+}
|