|
@@ -123,7 +123,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
|
|
MagicScriptContext.set(newContext);
|
|
MagicScriptContext.set(newContext);
|
|
try {
|
|
try {
|
|
Object value = ScriptManager.executeScript(info.getScript(), newContext);
|
|
Object value = ScriptManager.executeScript(info.getScript(), newContext);
|
|
- if(value instanceof ExitValue){
|
|
+ if (value instanceof ExitValue) {
|
|
throw new MagicExitException((ExitValue) value);
|
|
throw new MagicExitException((ExitValue) value);
|
|
}
|
|
}
|
|
return value;
|
|
return value;
|
|
@@ -228,6 +228,33 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
|
|
return info.getId();
|
|
return info.getId();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public boolean lockApi(String id) {
|
|
|
|
+ return lockWithNotify(apiServiceProvider.lock(id), id, NOTIFY_ACTION_API);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean unlockApi(String id) {
|
|
|
|
+ return lockWithNotify(apiServiceProvider.unlock(id), id, NOTIFY_ACTION_API);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean lockFunction(String id) {
|
|
|
|
+ return lockWithNotify(functionServiceProvider.lock(id), id, NOTIFY_ACTION_FUNCTION);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean unlockFunction(String id) {
|
|
|
|
+ return lockWithNotify(functionServiceProvider.unlock(id), id, NOTIFY_ACTION_FUNCTION);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean lockWithNotify(boolean success, String id, int type) {
|
|
|
|
+ if (success) {
|
|
|
|
+ magicNotifyService.sendNotify(new MagicNotify(instanceId, id, NOTIFY_ACTION_UPDATE, type));
|
|
|
|
+ }
|
|
|
|
+ return success;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public ApiInfo getApiInfo(String id) {
|
|
public ApiInfo getApiInfo(String id) {
|
|
return apiServiceProvider.get(id);
|
|
return apiServiceProvider.get(id);
|
|
@@ -288,7 +315,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
|
|
isTrue(!functionServiceProvider.existsWithoutId(functionInfo), FUNCTION_ALREADY_EXISTS.format(functionInfo.getPath()));
|
|
isTrue(!functionServiceProvider.existsWithoutId(functionInfo), FUNCTION_ALREADY_EXISTS.format(functionInfo.getPath()));
|
|
FunctionInfo oldInfo = functionServiceProvider.get(functionInfo.getId());
|
|
FunctionInfo oldInfo = functionServiceProvider.get(functionInfo.getId());
|
|
isTrue(functionServiceProvider.update(functionInfo), FUNCTION_SAVE_FAILURE);
|
|
isTrue(functionServiceProvider.update(functionInfo), FUNCTION_SAVE_FAILURE);
|
|
- if(!oldInfo.getScript().equals(functionInfo.getScript())){
|
|
+ if (!oldInfo.getScript().equals(functionInfo.getScript())) {
|
|
backupService.backup(functionInfo);
|
|
backupService.backup(functionInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -555,7 +582,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
|
|
|
|
|
|
isTrue("0".equals(group.getParentId()) || groupServiceProvider.getGroupResource(group.getParentId()).exists(), GROUP_NOT_FOUND);
|
|
isTrue("0".equals(group.getParentId()) || groupServiceProvider.getGroupResource(group.getParentId()).exists(), GROUP_NOT_FOUND);
|
|
}
|
|
}
|
|
- if(checked) {
|
|
+ if (checked) {
|
|
|
|
|
|
groups.forEach(group -> {
|
|
groups.forEach(group -> {
|
|
Resource resource;
|
|
Resource resource;
|
|
@@ -569,7 +596,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
|
|
isTrue(src == null || src.getId().equals(group.getId()), GROUP_CONFLICT);
|
|
isTrue(src == null || src.getId().equals(group.getId()), GROUP_CONFLICT);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- }else{
|
|
+ } else {
|
|
Resource resource = workspace.getDirectory(PATH_API);
|
|
Resource resource = workspace.getDirectory(PATH_API);
|
|
resource.delete();
|
|
resource.delete();
|
|
resource.mkdir();
|
|
resource.mkdir();
|
|
@@ -710,7 +737,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
|
|
case NOTIFY_ACTION_ALL:
|
|
case NOTIFY_ACTION_ALL:
|
|
return processAllNotify();
|
|
return processAllNotify();
|
|
}
|
|
}
|
|
- switch (action){
|
|
+ switch (action) {
|
|
case NOTIFY_WS_C_S:
|
|
case NOTIFY_WS_C_S:
|
|
return processWebSocketMessageReceived(magicNotify.getSessionId(), magicNotify.getContent());
|
|
return processWebSocketMessageReceived(magicNotify.getSessionId(), magicNotify.getContent());
|
|
case NOTIFY_WS_S_C:
|
|
case NOTIFY_WS_S_C:
|
|
@@ -719,6 +746,32 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public String copyGroup(String srcId, String target) {
|
|
|
|
+ Group src = getGroup(srcId);
|
|
|
|
+ src.setId(null);
|
|
|
|
+ src.setParentId(target);
|
|
|
|
+ src.setName(src.getName() + "(复制)");
|
|
|
|
+ src.setPath(src.getPath() + "_copy");
|
|
|
|
+ String newId = createGroup(src);
|
|
|
|
+ if (GROUP_TYPE_API.equals(src.getType())) {
|
|
|
|
+ apiServiceProvider.listWithScript()
|
|
|
|
+ .stream().filter(it -> srcId.equals(it.getGroupId()))
|
|
|
|
+ .map(ApiInfo::copy)
|
|
|
|
+ .peek(it -> it.setGroupId(newId))
|
|
|
|
+ .peek(it -> it.setId(null))
|
|
|
|
+ .forEach(this::saveApi);
|
|
|
|
+ } else {
|
|
|
|
+ functionServiceProvider.listWithScript()
|
|
|
|
+ .stream().filter(it -> srcId.equals(it.getGroupId()))
|
|
|
|
+ .map(FunctionInfo::copy)
|
|
|
|
+ .peek(it -> it.setGroupId(newId))
|
|
|
|
+ .peek(it -> it.setId(null))
|
|
|
|
+ .forEach(this::saveFunction);
|
|
|
|
+ }
|
|
|
|
+ return newId;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public String getModuleName() {
|
|
public String getModuleName() {
|
|
return "magic";
|
|
return "magic";
|
|
@@ -867,7 +920,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
|
|
for (Resource file : root.files(".ms")) {
|
|
for (Resource file : root.files(".ms")) {
|
|
if (isApi) {
|
|
if (isApi) {
|
|
ApiInfo info = apiServiceProvider.deserialize(file.read());
|
|
ApiInfo info = apiServiceProvider.deserialize(file.read());
|
|
- if (checked){
|
|
+ if (checked) {
|
|
checkApiConflict(info);
|
|
checkApiConflict(info);
|
|
}
|
|
}
|
|
apiInfos.add(info);
|
|
apiInfos.add(info);
|
|
@@ -875,7 +928,7 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
|
|
isTrue(apiPaths.add(apiPath), UPLOAD_PATH_CONFLICT.format(apiPath));
|
|
isTrue(apiPaths.add(apiPath), UPLOAD_PATH_CONFLICT.format(apiPath));
|
|
} else {
|
|
} else {
|
|
FunctionInfo info = functionServiceProvider.deserialize(file.read());
|
|
FunctionInfo info = functionServiceProvider.deserialize(file.read());
|
|
- if (checked){
|
|
+ if (checked) {
|
|
checkFunctionConflict(info);
|
|
checkFunctionConflict(info);
|
|
}
|
|
}
|
|
functionInfos.add(info);
|
|
functionInfos.add(info);
|