Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
Bosn committed Jan 28, 2016
2 parents 1cf90a0 + 0819ebb commit f136f9a
Show file tree
Hide file tree
Showing 49 changed files with 999 additions and 308 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RAP通过GUI工具帮助WEB工程师更高效的管理接口文档,同时通
* 免费、开源,一切尽在掌握中!

### 如何使用RAP
1. 直接访问由作者维护的[rapapi.net](http://rapapi.net/)
1. 直接访问由作者维护的[rap.taobao.org](http://rap.taobao.org/)
2. 自己部署一个RAP服务器,参考最新Release部分

### 快速上手 quick guide
Expand All @@ -54,7 +54,7 @@ RAP通过GUI工具帮助WEB工程师更高效的管理接口文档,同时通

## About

@version v0.13.1
@version v0.14.0 (in development)
@author @bosn @wangjeaf
@director @limu @xinglie
@update Oct. 13th 2015
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>groupId</groupId>
<artifactId>RAP</artifactId>
<version>0.13.0-SNAPSHOT</version>
<version>0.14.0-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/taobao/rigel/rap/account/bo/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@ public void setName(String name) {
this.name = name;
}

public static final int SUPER_ADMIN = 1;

public static final int ADMIN = 2;

public static final int USER = 3;

public static boolean isAdmin(int roleId) {
return roleId == ADMIN || roleId == SUPER_ADMIN;
}

}
10 changes: 0 additions & 10 deletions src/main/java/com/taobao/rigel/rap/account/service/AccountMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,6 @@ boolean updateProfile(int userId, String name, String email,
*/
List<Notification> getUnreadNotificationList(int curUserId);


/**
* user access validation
*
* @param userId
* @param projectId
* @return
*/
boolean canUserManageProject(int userId, int projectId);

int getUserNum();

void updateUser(User user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public boolean addUser(User user) {
String ps = user.getPassword();
if (ps == null)
return false;
if (this.getUserId(user.getAccount()) > 0) {
return false;
}

// DOUBLE MD5 encryption
ps = StringUtils.getDoubleMD5(ps);
Expand Down Expand Up @@ -160,7 +157,7 @@ public List<Corporation> getCorporationList() {


public List<Corporation> getCorporationListWithPager(int userId, int pageNum, int pageSize) {
return organizationMgr.getCorporationListWithPager(userId, pageNum, pageSize);
return organizationMgr.getCorporationListWithPager(userId, pageNum, pageSize, null);
}


Expand Down Expand Up @@ -219,40 +216,6 @@ public List<Notification> getUnreadNotificationList(int curUserId) {
}


public boolean canUserManageProject(int userId, int projectId) {
String[] cacheKey = new String[]{CacheUtils.KEY_ACCESS_USER_TO_PROJECT, new Integer(userId).toString(), new Integer(projectId).toString()};

String cache = CacheUtils.get(cacheKey);
if (cache != null) {
return Boolean.parseBoolean(cache);
}

User user = this.getUser(userId);
boolean canAccess = false;
Project project = projectMgr.getProject(projectId);
if (user.isUserInRole("admin")) {
canAccess = true;
} else if (user.getCreatedProjectList() != null) {
for (Project p : user.getCreatedProjectList()) {
if (p.getId() == projectId) {
canAccess = true;
}
}
}
if (project.getUserList() != null) {
for (User member : project.getUserList()) {
if (member.getId() == user.getId()) {
canAccess = true;
}
}
}

CacheUtils.put(cacheKey, new Boolean(canAccess).toString());

return canAccess;
}


public int getUserNum() {
return accountDao.getUsertNum();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public String readAllNotification() {
return LOGIN;
}
getAccountMgr().readNotificationList(getCurUserId());
String[] cacheKey = new String[]{CacheUtils.KEY_NOTIFICATION, new Integer(getCurUserId()).toString()};
CacheUtils.del(cacheKey);
return SUCCESS;
}

Expand Down Expand Up @@ -357,7 +359,10 @@ public String doRegister() {
return ERROR;
}

if (super.getAccountMgr().addUser(user)) {
if (getAccountMgr().getUserId(user.getAccount()) > 0) {
setErrMsg("该用户名" + user.getAccount() + "已经存在咯~~~");
return ERROR;
} else if (super.getAccountMgr().addUser(user)) {
return doLogin();
} else {
return ERROR;
Expand Down Expand Up @@ -398,6 +403,7 @@ public String updateProfile() {
setRelativeReturnUrl("/account/updateProfile.do");
return LOGIN;
}
user = getAccountMgr().getUser(getCurUserId());

setIsEditMode(true);
return SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public String querySchema() {
public String queryRAPModel() throws UnsupportedEncodingException {
Map<String, Object> resultMap = new HashMap<String, Object>();
Gson g = new Gson();
Project p = projectMgr.getProjectSummary(projectId);
Project p = projectMgr.getProject(projectId);
List<Action> aList = p.getAllAction();
Map<Integer, Object> mockDataMap = new HashMap<Integer, Object>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public List<Map<String, Object>> getCorpList() {
if (cache != null) {
corpList = CommonUtils.gson.fromJson(cache, new TypeToken<ArrayList<Corporation>>(){}.getType());
} else {
List<Corporation> list = accountMgr.getCorporationListWithPager(getCurUserId(), 1, 20);
List<Corporation> list = accountMgr.getCorporationListWithPager(getCurUserId(), 1, 40);
for (Corporation c : list) {
corpList.add(c.toMap());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.taobao.rigel.rap.common.config;

import com.alibaba.platform.buc.sso.common.dto.SimpleSSOUser;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.util.Properties;


public class SystemConstant {
private static final Logger logger = LogManager.getFormatterLogger(SystemConstant.class);
public static final int DEFAULT_PAGE_SIZE = 12;
public static final int ACCOUNT_LENGTH_MIN = 6;
public static final int ACCOUNT_LENGTH_MAX = 32;
Expand All @@ -30,7 +36,27 @@ public static void setDOMAIN_URL(String domainURL) {
SystemConstant.domainURL = domainURL;
}

private static Properties config;

private static void loadConfig() {
if (config == null) {
config = new Properties();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
config.load(loader.getResourceAsStream("config.properties"));
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
}
}
}

public static String getConfig(String key) {
if (config == null) {
loadConfig();
}
return config.getProperty(key);
}


}
11 changes: 10 additions & 1 deletion src/main/java/com/taobao/rigel/rap/common/utils/CacheUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.io.IOException;

/**
* Created by Bosn on 14/11/28.
* Basic cache, need weight for string length.
Expand All @@ -22,14 +24,21 @@ public class CacheUtils {

public static final String KEY_ACCESS_USER_TO_PROJECT = "KEY_ACCESS_USER_TO_PROJECT";
public static final String KEY_NOTIFICATION = "KEY_NOTIFICATION";
public static final String KEY_STATISTICS = "KEY_STATISTICS";
public static final String KEY_STATISTICS_OF_TEAM = "KEY_STATISTICS_OF_TEAM";

private static JedisPool jedisPool;
private static Jedis jedis;

public CacheUtils() {}

private static Jedis getJedis() {
jedisPool = JedisFactory.getInstance().getJedisPool();
try {
jedisPool = JedisFactory.getInstance().getJedisPool();
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
}
jedis = jedisPool.getResource();
return jedis;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package com.taobao.rigel.rap.common.utils;


import com.taobao.rigel.rap.common.config.SystemConstant;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;

class JedisFactory {
private static JedisPool jedisPool;
private static JedisFactory instance = null;

public JedisFactory() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
jedisPool = new JedisPool(poolConfig, "localhost", 6379);
String host = SystemConstant.getConfig("redis.host");
int port = Integer.parseInt(SystemConstant.getConfig("redis.port"));
jedisPool = new JedisPool(poolConfig, host, port);
}

public JedisPool getJedisPool() {
return jedisPool;
}

public static JedisFactory getInstance() {
public static JedisFactory getInstance() throws IOException {

if (instance == null) {
instance = new JedisFactory();
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/taobao/rigel/rap/mock/web/action/MockAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.taobao.rigel.rap.common.base.ActionBase;
import com.taobao.rigel.rap.common.utils.HTTPUtils;
import com.taobao.rigel.rap.common.utils.StringUtils;
import com.taobao.rigel.rap.common.utils.SystemVisitorLog;
import com.taobao.rigel.rap.mock.service.MockMgr;
import com.taobao.rigel.rap.project.bo.Action;
Expand Down Expand Up @@ -127,15 +128,15 @@ public void setActionId(int actionId) {
}

public String get_c() {
return _c;
return StringUtils.escapeInHJ(_c);
}

public void set_c(String _c) {
this._c = _c;
}

public String getCallback() {
return callback;
return StringUtils.escapeInHJ(callback);
}

public void setCallback(String callback) {
Expand Down Expand Up @@ -180,6 +181,7 @@ public void setPattern(String pattern) {
}

public String createData() throws UnsupportedEncodingException {
String callback = getCallback();
boolean isJSON = false;
updateProjectListMockNum(SystemVisitorLog.mock(__id__, "createData", pattern, getCurAccount()));
Map<String, Object> options = new HashMap<String, Object>();
Expand All @@ -206,6 +208,7 @@ public String createData() throws UnsupportedEncodingException {
}

public String createRule() throws UnsupportedEncodingException {
String callback = getCallback();
boolean isJSON = false;
updateProjectListMockNum(SystemVisitorLog.mock(__id__, "createRule", pattern, getCurAccount()));
Map<String, Object> options = new HashMap<String, Object>();
Expand All @@ -232,6 +235,7 @@ public String createRule() throws UnsupportedEncodingException {
}

public String createRuleAuto() throws UnsupportedEncodingException {
String callback = getCallback();
boolean isJSON = false;
updateProjectListMockNum(SystemVisitorLog.mock(__id__, "createRule", pattern, getCurAccount()));
Map<String, Object> options = new HashMap<String, Object>();
Expand Down Expand Up @@ -260,6 +264,7 @@ public String createRuleAuto() throws UnsupportedEncodingException {
}

public String createRuleByActionData() throws UnsupportedEncodingException {
String callback = getCallback();
boolean isJSON = false;
updateProjectListMockNum(SystemVisitorLog.mock(id, "createRuleByActionData", pattern, getCurAccount()));
Map<String, Object> options = new HashMap<String, Object>();
Expand Down Expand Up @@ -349,6 +354,7 @@ private void loadWhiteList(Project p, List<String> list, Map<String, Boolean> ma
}

public String createMockjsData() throws UnsupportedEncodingException {
String callback = getCallback();
boolean isJSON = false;
updateProjectListMockNum(SystemVisitorLog.mock(__id__, "createMockjsData", pattern, getCurAccount()));
String _c = get_c();
Expand Down Expand Up @@ -376,6 +382,7 @@ public String createMockjsData() throws UnsupportedEncodingException {
}

public String createMockjsDataAuto() throws UnsupportedEncodingException {
String callback = getCallback();
boolean isJSON = false;
updateProjectListMockNum(SystemVisitorLog.mock(__id__, "createMockjsData", pattern, getCurAccount()));
String _c = get_c();
Expand Down Expand Up @@ -404,6 +411,7 @@ public String createMockjsDataAuto() throws UnsupportedEncodingException {
}

public String validateAPI() throws UnsupportedEncodingException {
String callback = getCallback();
boolean isJSON = false;
updateProjectListMockNum(SystemVisitorLog.mock(id, "createRule", pattern, getCurAccount()));
Map<String, Object> options = new HashMap<String, Object>();
Expand Down
Loading

0 comments on commit f136f9a

Please sign in to comment.