Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
javamxd committed Sep 12, 2021
2 parents 4952e2a + 0f193a4 commit 274da01
Show file tree
Hide file tree
Showing 37 changed files with 611 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ magic-api 是一个基于Java的接口快速开发框架,编写接口将通过
<dependency>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-spring-boot-starter</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
</dependency>
```
## 修改application.properties
Expand Down
2 changes: 1 addition & 1 deletion magic-api-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
</parent>
<artifactId>magic-api-spring-boot-starter</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion magic-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-parent</artifactId>
<version>1.4.2</version>
<version>1.4.3</version>
</parent>
<artifactId>magic-api</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DialectAdapter() {
}

public void add(Dialect dialect) {
this.dialectList.add(dialect);
this.dialectList.add(0, dialect);
}

public Dialect getDialectFromConnection(Connection connection) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ssssssss.magicapi.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
Expand All @@ -8,6 +9,7 @@
import org.ssssssss.magicapi.interceptor.Authorization;
import org.ssssssss.magicapi.model.ApiInfo;
import org.ssssssss.magicapi.model.Backup;
import org.ssssssss.magicapi.model.Constants;
import org.ssssssss.magicapi.model.JsonBean;

import javax.servlet.http.HttpServletRequest;
Expand All @@ -33,7 +35,9 @@ public MagicAPIController(MagicConfiguration configuration) {
@ResponseBody
@Valid(readonly = false)
public JsonBean<Boolean> delete(HttpServletRequest request, String id) {
isTrue(allowVisit(request, Authorization.DELETE, getApiInfo(id)), PERMISSION_INVALID);
ApiInfo apiInfo = getApiInfo(id);
isTrue(allowVisit(request, Authorization.DELETE, apiInfo), PERMISSION_INVALID);
isTrue(!Constants.LOCK.equals(apiInfo.getLock()), RESOURCE_LOCKED);
return new JsonBean<>(magicAPIService.deleteApi(id));
}

Expand Down Expand Up @@ -102,6 +106,7 @@ public JsonBean<Boolean> apiMove(HttpServletRequest request, String id, String g
// 新的分组ID
apiInfo.setGroupId(groupId);
isTrue(allowVisit(request, Authorization.SAVE, apiInfo), PERMISSION_INVALID);
isTrue(!Constants.LOCK.equals(apiInfo.getLock()), RESOURCE_LOCKED);
return new JsonBean<>(magicAPIService.moveApi(id, groupId));
}

Expand All @@ -113,10 +118,36 @@ public JsonBean<Boolean> apiMove(HttpServletRequest request, String id, String g
@Valid(readonly = false)
public JsonBean<String> save(HttpServletRequest request, @RequestBody ApiInfo info) {
isTrue(allowVisit(request, Authorization.SAVE, info), PERMISSION_INVALID);
if (StringUtils.isNotBlank(info.getId())) {
ApiInfo oldInfo = getApiInfo(info.getId());
isTrue(!Constants.LOCK.equals(oldInfo.getLock()), RESOURCE_LOCKED);
}
return new JsonBean<>(magicAPIService.saveApi(info));
}

private ApiInfo getApiInfo(String id){
/**
* 锁定接口
*/
@RequestMapping("/lock")
@ResponseBody
@Valid(readonly = false)
public JsonBean<Boolean> lock(HttpServletRequest request, String id) {
isTrue(allowVisit(request, Authorization.LOCK, getApiInfo(id)), PERMISSION_INVALID);
return new JsonBean<>(magicAPIService.lockApi(id));
}

/**
* 解锁接口
*/
@RequestMapping("/unlock")
@ResponseBody
@Valid(readonly = false)
public JsonBean<Boolean> unlock(HttpServletRequest request, String id) {
isTrue(allowVisit(request, Authorization.UNLOCK, getApiInfo(id)), PERMISSION_INVALID);
return new JsonBean<>(magicAPIService.unlockApi(id));
}

private ApiInfo getApiInfo(String id) {
ApiInfo apiInfo = magicAPIService.getApiInfo(id);
notNull(apiInfo, API_NOT_FOUND);
return apiInfo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.ssssssss.magicapi.controller;

import org.apache.commons.lang3.StringUtils;
import org.ssssssss.magicapi.config.Message;
import org.ssssssss.magicapi.config.MessageType;
import org.ssssssss.magicapi.config.WebSocketSessionManager;
import org.ssssssss.magicapi.model.MagicConsoleSession;
import org.ssssssss.script.MagicScriptDebugContext;

Expand Down Expand Up @@ -40,10 +40,13 @@ public boolean setBreakPoint(MagicConsoleSession session, String breakpoints) {
* 当本机没有该Session时,通知其他机器处理
*/
@Message(MessageType.RESUME_BREAKPOINT)
public boolean resumeBreakpoint(MagicConsoleSession session, String stepInto) {
public boolean resumeBreakpoint(MagicConsoleSession session, String stepInto, String breakpoints) {
MagicScriptDebugContext context = session.getMagicScriptDebugContext();
if (context != null) {
context.setStepInto("1".equals(stepInto));
if(StringUtils.isNotBlank(breakpoints)){
context.setBreakpoints(Stream.of(breakpoints.split("\\|")).map(Integer::valueOf).collect(Collectors.toList()));
}
try {
context.singal();
} catch (InterruptedException ignored) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.ssssssss.magicapi.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.ssssssss.magicapi.config.MagicConfiguration;
import org.ssssssss.magicapi.config.Valid;
import org.ssssssss.magicapi.interceptor.Authorization;
import org.ssssssss.magicapi.model.Backup;
import org.ssssssss.magicapi.model.Constants;
import org.ssssssss.magicapi.model.FunctionInfo;
import org.ssssssss.magicapi.model.JsonBean;

Expand Down Expand Up @@ -63,6 +65,7 @@ public JsonBean<Boolean> move(HttpServletRequest request, String id, String grou
FunctionInfo functionInfo = getFunctionInfo(id);
functionInfo.setGroupId(groupId);
isTrue(allowVisit(request, Authorization.SAVE, functionInfo), PERMISSION_INVALID);
isTrue(!Constants.LOCK.equals(functionInfo.getLock()), RESOURCE_LOCKED);
return new JsonBean<>(magicAPIService.moveFunction(id, groupId));
}

Expand All @@ -72,17 +75,45 @@ public JsonBean<Boolean> move(HttpServletRequest request, String id, String grou
@Valid(readonly = false)
public JsonBean<String> save(HttpServletRequest request, @RequestBody FunctionInfo functionInfo) {
isTrue(allowVisit(request, Authorization.SAVE, functionInfo), PERMISSION_INVALID);
if (StringUtils.isNotBlank(functionInfo.getId())) {
FunctionInfo oldInfo = getFunctionInfo(functionInfo.getId());
isTrue(!Constants.LOCK.equals(oldInfo.getLock()), RESOURCE_LOCKED);
}
return new JsonBean<>(magicAPIService.saveFunction(functionInfo));
}

@RequestMapping("/function/delete")
@ResponseBody
@Valid(readonly = false)
public JsonBean<Boolean> delete(HttpServletRequest request, String id) {
isTrue(allowVisit(request, Authorization.DELETE, getFunctionInfo(id)), PERMISSION_INVALID);
FunctionInfo info = getFunctionInfo(id);
isTrue(allowVisit(request, Authorization.DELETE, info), PERMISSION_INVALID);
isTrue(!Constants.LOCK.equals(info.getLock()), RESOURCE_LOCKED);
return new JsonBean<>(magicAPIService.deleteFunction(id));
}

/**
* 锁定函数
*/
@RequestMapping("/function/lock")
@ResponseBody
@Valid(readonly = false)
public JsonBean<Boolean> lock(HttpServletRequest request, String id) {
isTrue(allowVisit(request, Authorization.LOCK, getFunctionInfo(id)), PERMISSION_INVALID);
return new JsonBean<>(magicAPIService.lockFunction(id));
}

/**
* 解锁函数
*/
@RequestMapping("/function/unlock")
@ResponseBody
@Valid(readonly = false)
public JsonBean<Boolean> unlock(HttpServletRequest request, String id) {
isTrue(allowVisit(request, Authorization.UNLOCK, getFunctionInfo(id)), PERMISSION_INVALID);
return new JsonBean<>(magicAPIService.unlockFunction(id));
}

public FunctionInfo getFunctionInfo(String id) {
FunctionInfo functionInfo = magicAPIService.getFunctionInfo(id);
notNull(functionInfo, FUNCTION_NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,22 @@ public JsonBean<String> createGroup(HttpServletRequest request, @RequestBody Gro
isTrue(allowVisit(request, Authorization.SAVE, group), PERMISSION_INVALID);
return new JsonBean<>(magicAPIService.createGroup(group));
}

/**
* 复制分组
*/
@RequestMapping("/group/copy")
@ResponseBody
@Valid(readonly = false)
public JsonBean<String> copyGroup(HttpServletRequest request, String src, String target) {
Group group = magicAPIService.getGroup(src);
notNull(group, GROUP_NOT_FOUND);
if(!"0".equals(target)){
Group targetGroup = magicAPIService.getGroup(target);
notNull(targetGroup, GROUP_NOT_FOUND);
isTrue(allowVisit(request, Authorization.SAVE, targetGroup), PERMISSION_INVALID);
}
isTrue(allowVisit(request, Authorization.VIEW, group), PERMISSION_INVALID);
return new JsonBean<>(magicAPIService.copyGroup(src, target));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private MagicScriptContext createMagicScriptContext(RequestEntity requestEntity,
debugContext.setCallback(variables -> {
List<Map<String, Object>> varList = (List<Map<String, Object>>) variables.get("variables");
varList.stream().filter(it -> it.containsKey("value")).forEach(variable -> {
variable.put("value", JsonUtils.toJsonString(variable.get("value")));
variable.put("value", JsonUtils.toJsonStringWithoutLog(variable.get("value")));
});
WebSocketSessionManager.sendBySessionId(sessionId, BREAKPOINT, variables);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ public enum Authorization {
/**
* 执行推送动作
*/
PUSH
PUSH,
/**
* 锁定动作
*/
LOCK,
/**
* 解锁动作
*/
UNLOCK
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public ApiInfo simple(){
target.setGroupId(this.getGroupId());
target.setPath(this.getPath());
target.setMethod(this.getMethod());
target.setLock(this.getLock());
return target;
}

Expand Down Expand Up @@ -311,6 +312,8 @@ public ApiInfo copy() {
info.setPaths(this.paths);
info.setRequestBodyDefinition(this.requestBodyDefinition);
info.setResponseBodyDefinition(this.responseBodyDefinition);
info.setLock(this.lock);
info.setProperties(this.properties);
return info;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public class Constants {

public static final String UPLOAD_MODE_FULL = "full";

public static final String LOCK = "1";

public static final String UNLOCK = "0";

/**
* 执行成功的code值
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,20 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(id, path, script, name, groupId, parameters, description, returnType);
}

public FunctionInfo copy(){
FunctionInfo info = new FunctionInfo();
info.setId(this.id);
info.setName(this.name);
info.setGroupId(this.groupId);
info.setScript(this.script);
info.setDescription(this.description);
info.setParameters(this.parameters);
info.setPath(this.path);
info.setMappingPath(this.mappingPath);
info.setReturnType(this.returnType);
info.setProperties(this.properties);
info.setLock(this.lock);
return info;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface JsonCodeConstants {

JsonCode NAME_CONFLICT = new JsonCode(0, "移动后名称会重复,请修改名称后在试。");

JsonCode RESOURCE_LOCKED = new JsonCode(0, "当前资源已被锁定,请解锁后在操作。");

JsonCode REQUEST_PATH_CONFLICT = new JsonCode(0, "该路径已被映射,请换一个请求方法或路径");

JsonCode FUNCTION_PATH_CONFLICT = new JsonCode(0, "该路径已被映射,请换一个请求方法或路径");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class MagicEntity extends Attributes<Object> implements Cloneable {

protected Long updateTime;

protected String lock;

public String getId() {
return id;
}
Expand Down Expand Up @@ -62,6 +64,14 @@ public void setName(String name) {
this.name = name;
}

public String getLock() {
return lock;
}

public void setLock(String lock) {
this.lock = lock;
}

public MagicEntity clone() {
try {
return (MagicEntity) super.clone();
Expand Down
Loading

0 comments on commit 274da01

Please sign in to comment.