finish plugin api
This commit is contained in:
parent
c9d020cffa
commit
7548eb9faf
|
@ -6,7 +6,6 @@ import org.apache.log4j.Logger;
|
||||||
import org.bench4q.master.domain.entity.User;
|
import org.bench4q.master.domain.entity.User;
|
||||||
import org.bench4q.master.domain.service.auth.AuthenticationManager;
|
import org.bench4q.master.domain.service.auth.AuthenticationManager;
|
||||||
import org.bench4q.master.exception.Bench4QException;
|
import org.bench4q.master.exception.Bench4QException;
|
||||||
import org.bench4q.master.exception.ExceptionLog;
|
|
||||||
import org.bench4q.share.models.ErrorResponseModel;
|
import org.bench4q.share.models.ErrorResponseModel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -44,6 +43,7 @@ public abstract class BaseController {
|
||||||
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ErrorResponseModel handleException(Bench4QException e) {
|
public ErrorResponseModel handleException(Bench4QException e) {
|
||||||
|
logger.error(e,e.fillInStackTrace());
|
||||||
return ErrorResponseModel.buildErrorResponse(e.getCode(),
|
return ErrorResponseModel.buildErrorResponse(e.getCode(),
|
||||||
e.getMessage(), e.getResource());
|
e.getMessage(), e.getResource());
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public abstract class BaseController {
|
||||||
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ErrorResponseModel handleException(RuntimeException e) {
|
public ErrorResponseModel handleException(RuntimeException e) {
|
||||||
logger.info(ExceptionLog.getStackTrace(e));
|
logger.error(e,e.fillInStackTrace());
|
||||||
return ErrorResponseModel.buildErrorResponse("RUNTIME_EXCEPTION",
|
return ErrorResponseModel.buildErrorResponse("RUNTIME_EXCEPTION",
|
||||||
e.getMessage(), "");
|
e.getMessage(), "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import javax.persistence.Table;
|
||||||
public class Plugin {
|
public class Plugin {
|
||||||
private int id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
private Set<Method> methods;
|
private Set<Method> pluginMethods;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@ -39,13 +39,14 @@ public class Plugin {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "plugin", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
@OneToMany(mappedBy = "plugin", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||||
public Set<Method> getMethods() {
|
public Set<Method> getPluginMethods() {
|
||||||
return methods;
|
return pluginMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMethods(Set<Method> methods) {
|
public void setPluginMethods(Set<Method> pluginMethods) {
|
||||||
this.methods = methods;
|
this.pluginMethods = pluginMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package org.bench4q.master.domain.factory;
|
package org.bench4q.master.domain.factory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import org.bench4q.master.domain.entity.plugin.Method;
|
import org.bench4q.master.domain.entity.plugin.Method;
|
||||||
import org.bench4q.master.domain.entity.plugin.MethodParam;
|
import org.bench4q.master.domain.entity.plugin.MethodParam;
|
||||||
import org.bench4q.master.domain.entity.plugin.ParamProperty;
|
import org.bench4q.master.domain.entity.plugin.ParamProperty;
|
||||||
|
@ -13,10 +16,11 @@ public class PluginFactory {
|
||||||
|
|
||||||
public static Plugin createPluginEntity(PluginModel pluginModel) {
|
public static Plugin createPluginEntity(PluginModel pluginModel) {
|
||||||
Plugin plugin = new Plugin();
|
Plugin plugin = new Plugin();
|
||||||
if (plugin.getMethods() != null) {
|
plugin.setPluginMethods(new HashSet<Method>());
|
||||||
|
if (pluginModel.getMethods() != null) {
|
||||||
for (MethodModel methodModel : pluginModel.getMethods()) {
|
for (MethodModel methodModel : pluginModel.getMethods()) {
|
||||||
plugin.getMethods()
|
plugin.getPluginMethods().add(
|
||||||
.add(createMethodEntity(methodModel, plugin));
|
createMethodEntity(methodModel, plugin));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +32,7 @@ public class PluginFactory {
|
||||||
private static Method createMethodEntity(MethodModel methodModel,
|
private static Method createMethodEntity(MethodModel methodModel,
|
||||||
Plugin plugin) {
|
Plugin plugin) {
|
||||||
Method method = new Method();
|
Method method = new Method();
|
||||||
|
method.setMethodParams(new HashSet<MethodParam>());
|
||||||
method.setName(methodModel.getName());
|
method.setName(methodModel.getName());
|
||||||
if (methodModel.getMethodParams() != null) {
|
if (methodModel.getMethodParams() != null) {
|
||||||
for (MethodParamModel methodParamModel : methodModel
|
for (MethodParamModel methodParamModel : methodModel
|
||||||
|
@ -48,6 +53,7 @@ public class PluginFactory {
|
||||||
methodParam.setLable(methodParamModel.getLable());
|
methodParam.setLable(methodParamModel.getLable());
|
||||||
methodParam.setName(methodParamModel.getName());
|
methodParam.setName(methodParamModel.getName());
|
||||||
methodParam.setSeperator(methodParamModel.getSeperator());
|
methodParam.setSeperator(methodParamModel.getSeperator());
|
||||||
|
methodParam.setParamProperties(new ArrayList<ParamProperty>());
|
||||||
if (methodParamModel.getParamProperties() != null) {
|
if (methodParamModel.getParamProperties() != null) {
|
||||||
for (ParamPropertyModel paramPropertyModel : methodParamModel
|
for (ParamPropertyModel paramPropertyModel : methodParamModel
|
||||||
.getParamProperties()) {
|
.getParamProperties()) {
|
||||||
|
@ -69,4 +75,45 @@ public class PluginFactory {
|
||||||
paramProperty.setMethodParam(methodParam);
|
paramProperty.setMethodParam(methodParam);
|
||||||
return paramProperty;
|
return paramProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MethodModel extractMethodModel(Method method) {
|
||||||
|
MethodModel methodModel = new MethodModel();
|
||||||
|
methodModel.setName(method.getName());
|
||||||
|
if (method.getMethodParams() != null) {
|
||||||
|
methodModel.setMethodParams(new HashSet<MethodParamModel>());
|
||||||
|
for (MethodParam methodParam : method.getMethodParams()) {
|
||||||
|
methodModel.getMethodParams().add(
|
||||||
|
extractMethodParamModel(methodParam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return methodModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MethodParamModel extractMethodParamModel(
|
||||||
|
MethodParam methodParam) {
|
||||||
|
MethodParamModel methodParamModel = new MethodParamModel();
|
||||||
|
methodParamModel.setEditorType(methodParam.getEditorType());
|
||||||
|
methodParamModel.setLable(methodParam.getLable());
|
||||||
|
methodParamModel.setName(methodParam.getName());
|
||||||
|
methodParamModel.setSeperator(methodParam.getSeperator());
|
||||||
|
if (methodParam.getParamProperties() != null) {
|
||||||
|
methodParamModel
|
||||||
|
.setParamProperties(new ArrayList<ParamPropertyModel>());
|
||||||
|
for (ParamProperty paramProperty : methodParam.getParamProperties()) {
|
||||||
|
methodParamModel.getParamProperties().add(
|
||||||
|
extractParamPropertyModel(paramProperty));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return methodParamModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ParamPropertyModel extractParamPropertyModel(
|
||||||
|
ParamProperty paramProperty) {
|
||||||
|
ParamPropertyModel paramPropertyModel = new ParamPropertyModel();
|
||||||
|
paramPropertyModel.setKey(paramProperty.getPropertyName());
|
||||||
|
paramPropertyModel.setValue(paramProperty.getPropertyValue());
|
||||||
|
paramPropertyModel.setValueSeperator(paramProperty.getValueSeperator());
|
||||||
|
return paramPropertyModel;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
public class PluginRepository extends AbstractRepositoty {
|
public class PluginRepository extends AbstractRepositoty {
|
||||||
public boolean attatch(Plugin plugin) throws Bench4QException {
|
public boolean attatch(Plugin plugin) throws Bench4QException {
|
||||||
|
|
||||||
Session session = this.getSessionHelper().openSession();
|
Session session = this.getSessionHelper().openSession();
|
||||||
Transaction transaction = session.beginTransaction();
|
Transaction transaction = session.beginTransaction();
|
||||||
Plugin pluginExist = null;
|
Plugin pluginExist = null;
|
||||||
|
@ -23,6 +24,7 @@ public class PluginRepository extends AbstractRepositoty {
|
||||||
;
|
;
|
||||||
if (pluginExist != null) {
|
if (pluginExist != null) {
|
||||||
logger.info("the plugin exist");
|
logger.info("the plugin exist");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
session.merge(plugin);
|
session.merge(plugin);
|
||||||
|
@ -55,6 +57,7 @@ public class PluginRepository extends AbstractRepositoty {
|
||||||
.add(Restrictions.eq("name", pluginName)).uniqueResult();
|
.add(Restrictions.eq("name", pluginName)).uniqueResult();
|
||||||
if (pluginExist == null) {
|
if (pluginExist == null) {
|
||||||
logger.info("plugin not exist");
|
logger.info("plugin not exist");
|
||||||
|
System.out.println("not exist");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
session.delete(pluginExist);
|
session.delete(pluginExist);
|
||||||
|
|
|
@ -9,6 +9,9 @@ import org.bench4q.master.domain.entity.plugin.Plugin;
|
||||||
import org.bench4q.master.domain.repository.PluginRepository;
|
import org.bench4q.master.domain.repository.PluginRepository;
|
||||||
import org.bench4q.master.exception.Bench4QException;
|
import org.bench4q.master.exception.Bench4QException;
|
||||||
import org.bench4q.master.domain.entity.plugin.Method;
|
import org.bench4q.master.domain.entity.plugin.Method;
|
||||||
|
import org.bench4q.master.domain.factory.PluginFactory;
|
||||||
|
import org.bench4q.share.models.master.plugin.MethodParamModel;
|
||||||
|
import org.bench4q.share.models.master.plugin.PluginModel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -33,8 +36,9 @@ public class PluginService {
|
||||||
return this.plugins;
|
return this.plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addPlugin(Plugin plugin) throws Bench4QException {
|
public boolean addPlugin(PluginModel pluginModel) throws Bench4QException {
|
||||||
return this.getPluginRepository().attatch(plugin);
|
return this.getPluginRepository().attatch(
|
||||||
|
PluginFactory.createPluginEntity(pluginModel));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deletePlugin(String pluginName) throws Bench4QException {
|
public boolean deletePlugin(String pluginName) throws Bench4QException {
|
||||||
|
@ -58,7 +62,8 @@ public class PluginService {
|
||||||
|
|
||||||
public List<String> getMethodNameInPlugin(String pluginName) {
|
public List<String> getMethodNameInPlugin(String pluginName) {
|
||||||
List<String> methodNameList = new ArrayList<String>();
|
List<String> methodNameList = new ArrayList<String>();
|
||||||
Set<Method> methods = this.getPluginByName(pluginName).getMethods();
|
Set<Method> methods = this.getPluginByName(pluginName)
|
||||||
|
.getPluginMethods();
|
||||||
if (methods != null) {
|
if (methods != null) {
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
methodNameList.add(method.getName());
|
methodNameList.add(method.getName());
|
||||||
|
@ -82,15 +87,22 @@ public class PluginService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Method> getMethodInPlugin(String pluginName) {
|
public Set<MethodParamModel> getMethodParamModelsInPlugin(
|
||||||
|
String pluginName, String methodName) throws Bench4QException {
|
||||||
return this.getPluginByName(pluginName).getMethods();
|
return PluginFactory.extractMethodModel(
|
||||||
|
this.getMethodInPlugin(pluginName, methodName))
|
||||||
|
.getMethodParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<MethodParam> getMethodParams(String pluginName,
|
private Set<Method> getMethodInPlugin(String pluginName) {
|
||||||
String methodName) throws Bench4QException {
|
|
||||||
|
return this.getPluginByName(pluginName).getPluginMethods();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<MethodParam> getMethodParams(String pluginName, String methodName)
|
||||||
|
throws Bench4QException {
|
||||||
Method method = this.getMethodInPlugin(pluginName, methodName);
|
Method method = this.getMethodInPlugin(pluginName, methodName);
|
||||||
return method.getMethodParams();
|
return method.getMethodParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,11 @@ import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.bench4q.master.domain.entity.plugin.Plugin;
|
|
||||||
import org.bench4q.master.domain.factory.PluginFactory;
|
|
||||||
import org.bench4q.master.domain.service.PluginService;
|
import org.bench4q.master.domain.service.PluginService;
|
||||||
import org.bench4q.master.exception.Bench4QException;
|
import org.bench4q.master.exception.Bench4QException;
|
||||||
import org.bench4q.share.helper.MarshalHelper;
|
import org.bench4q.share.helper.MarshalHelper;
|
||||||
|
@ -21,7 +20,6 @@ import org.bench4q.share.models.master.plugin.MethodModel;
|
||||||
import org.bench4q.share.models.master.plugin.MethodParamModel;
|
import org.bench4q.share.models.master.plugin.MethodParamModel;
|
||||||
import org.bench4q.share.models.master.plugin.ParamPropertyModel;
|
import org.bench4q.share.models.master.plugin.ParamPropertyModel;
|
||||||
import org.bench4q.share.models.master.plugin.PluginModel;
|
import org.bench4q.share.models.master.plugin.PluginModel;
|
||||||
import org.bench4q.share.models.master.plugin.PluginGUI;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -65,9 +63,41 @@ public class Test_PluginService {
|
||||||
@Test
|
@Test
|
||||||
public void testAddPlugin() throws JAXBException, Bench4QException {
|
public void testAddPlugin() throws JAXBException, Bench4QException {
|
||||||
|
|
||||||
Plugin plugin=PluginFactory.createPluginEntity(createOnePlugin());
|
Assert.assertTrue(this.getPluginService().addPlugin(createOnePlugin()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeletePlugin() throws Bench4QException {
|
||||||
|
PluginModel plugin = createOnePlugin();
|
||||||
|
plugin.setName("ppp");
|
||||||
Assert.assertTrue(this.getPluginService().addPlugin(plugin));
|
Assert.assertTrue(this.getPluginService().addPlugin(plugin));
|
||||||
|
Assert.assertTrue(this.getPluginService()
|
||||||
|
.deletePlugin(plugin.getName()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadPluginNameList() throws Bench4QException {
|
||||||
|
PluginModel plugin = createOnePlugin();
|
||||||
|
plugin.setName("ppp");
|
||||||
|
Assert.assertTrue(this.getPluginService().addPlugin(plugin));
|
||||||
|
List<String> pluginNameList = this.getPluginService()
|
||||||
|
.getPluginNameList();
|
||||||
|
Assert.assertTrue(pluginNameList.size() >0);
|
||||||
|
Assert.assertTrue(this.getPluginService()
|
||||||
|
.deletePlugin(plugin.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetMethodNameList() throws Bench4QException {
|
||||||
|
PluginModel plugin = createOnePlugin();
|
||||||
|
plugin.setName("ppp");
|
||||||
|
Assert.assertTrue(this.getPluginService().addPlugin(plugin));
|
||||||
|
List<String> methodNameList = this.getPluginService()
|
||||||
|
.getMethodNameInPlugin(plugin.getName());
|
||||||
|
Assert.assertTrue(methodNameList.size() == 1);
|
||||||
|
Assert.assertTrue(this.getPluginService()
|
||||||
|
.deletePlugin(plugin.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private PluginModel createOnePlugin() {
|
private PluginModel createOnePlugin() {
|
||||||
|
@ -85,28 +115,21 @@ public class Test_PluginService {
|
||||||
methodParamParam.setSeperator("&");
|
methodParamParam.setSeperator("&");
|
||||||
methodParamParam.setParamProperties(generateParamProperties());
|
methodParamParam.setParamProperties(generateParamProperties());
|
||||||
|
|
||||||
List<MethodParamModel> methodParams = new ArrayList<MethodParamModel>();
|
Set<MethodParamModel> methodParams = new HashSet<MethodParamModel>();
|
||||||
methodParams.add(methodParamParam);
|
methodParams.add(methodParamParam);
|
||||||
methodParams.add(methodParamParam);
|
methodParams.add(methodParamParam);
|
||||||
|
|
||||||
method.setName("get");
|
method.setName("get");
|
||||||
method.setParams(methodParams);
|
method.setMethodParams(methodParams);
|
||||||
|
|
||||||
Set<MethodModel> methods = new HashSet<MethodModel>();
|
Set<MethodModel> methods = new HashSet<MethodModel>();
|
||||||
methods.add(method);
|
methods.add(method);
|
||||||
plugin.setMethods(methods);
|
plugin.setMethods(methods);
|
||||||
plugin.setName("http");
|
plugin.setName("http" + UUID.randomUUID());
|
||||||
return plugin;
|
return plugin;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PluginGUI generateOnePluginGUI() {
|
|
||||||
PluginGUI pluginGUI = new PluginGUI();
|
|
||||||
pluginGUI.setPlugin(createOnePlugin());
|
|
||||||
return pluginGUI;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ParamPropertyModel> generateUrlProperties() {
|
private List<ParamPropertyModel> generateUrlProperties() {
|
||||||
ParamPropertyModel paramPropertyUrl = new ParamPropertyModel();
|
ParamPropertyModel paramPropertyUrl = new ParamPropertyModel();
|
||||||
paramPropertyUrl.setKey("size");
|
paramPropertyUrl.setKey("size");
|
||||||
|
|
Loading…
Reference in New Issue