add paramType class and its child class

This commit is contained in:
fanfuxiaoran 2014-03-13 11:31:20 +08:00
parent 43cb4fb4cf
commit 78d87b912a
11 changed files with 308 additions and 207 deletions

View File

@ -0,0 +1,23 @@
package org.bench4q.master.domain.entity.plugin;
import javax.persistence.Column;
import javax.persistence.Entity;
import com.sun.org.glassfish.gmbal.Description;
@SuppressWarnings("restriction")
@Entity
@Description("CheckBox")
public class CheckBox extends ParamType {
private String rows;
@Column(name = "rows")
public String getRows() {
return rows;
}
public void setRows(String rows) {
this.rows = rows;
}
}

View File

@ -0,0 +1,22 @@
package org.bench4q.master.domain.entity.plugin;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
@Entity
@DiscriminatorValue("Field")
public class Field extends ParamType {
private int size;
@Column(name="size")
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}

View File

@ -1,6 +1,5 @@
package org.bench4q.master.domain.entity.plugin;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@ -11,7 +10,6 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@ -25,9 +23,7 @@ public class MethodParam {
private Method method;
private String lable;
private String name;
private String seperator;
private int editorType;
private List<ParamProperty> paramProperties;
private ParamType paramType;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -67,32 +63,14 @@ public class MethodParam {
public void setLable(String lable) {
this.lable = lable;
}
@Column(name = "seperator")
public String getSeperator() {
return seperator;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "paramTypeId",nullable = false)
public ParamType getParamType() {
return paramType;
}
public void setSeperator(String seperator) {
this.seperator = seperator;
}
@Column(name = "editorType")
public int getEditorType() {
return editorType;
}
public void setEditorType(int editorType) {
this.editorType = editorType;
}
@OneToMany(mappedBy = "methodParam", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
public List<ParamProperty> getParamProperties() {
return paramProperties;
}
public void setParamProperties(List<ParamProperty> properties) {
this.paramProperties = properties;
public void setParamType(ParamType paramType) {
this.paramType = paramType;
}
}

View File

@ -0,0 +1,33 @@
package org.bench4q.master.domain.entity.plugin;
import javax.persistence.Column;
import javax.persistence.Entity;
import com.sun.org.glassfish.gmbal.Description;
@SuppressWarnings("restriction")
@Entity
@Description("MultiField")
public class MultiField extends ParamType {
public static String seperator = ";";
private int size;
@Column(name = "size")
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
@Column(name = "seperator")
public static String getSeperator() {
return seperator;
}
public static void setSeperator(String seperator) {
MultiField.seperator = seperator;
}
}

View File

@ -1,71 +0,0 @@
package org.bench4q.master.domain.entity.plugin;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "paramProperty")
public class ParamProperty {
private int id;
private String propertyName;
private String propertyValue;
private MethodParam methodParam;
private String valueSeperator;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@ManyToOne
@JoinColumn(name = "methodParamId")
public MethodParam getMethodParam() {
return methodParam;
}
public void setMethodParam(MethodParam methodParam) {
this.methodParam = methodParam;
}
@Column(name = "seperator")
public String getValueSeperator() {
return valueSeperator;
}
public void setValueSeperator(String valueSeperator) {
this.valueSeperator = valueSeperator;
}
@Column(name="propertyName")
public String getPropertyName() {
return propertyName;
}
public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}
@Column(name="propertyValue")
public String getPropertyValue() {
return propertyValue;
}
public void setPropertyValue(String propertyValue) {
this.propertyValue = propertyValue;
}
}

View File

@ -0,0 +1,67 @@
package org.bench4q.master.domain.entity.plugin;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "paramType", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("paramType")
public class ParamType {
private int id;
private String valueSeperator = ";";
private String fieldSeperator = ",";
private String type;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "type", nullable = false)
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Column(name = "valueSeperator")
public String getValueSeperator() {
return valueSeperator;
}
public void setValueSeperator(String valueSeperator) {
this.valueSeperator = valueSeperator;
}
@Column(name = "fieldSeperator")
public String getFieldSeperator() {
return fieldSeperator;
}
public void setFieldSeperator(String fieldSeperator) {
this.fieldSeperator = fieldSeperator;
}
}

View File

@ -0,0 +1,23 @@
package org.bench4q.master.domain.entity.plugin;
import javax.persistence.Column;
import javax.persistence.Entity;
import com.sun.org.glassfish.gmbal.Description;
@SuppressWarnings("restriction")
@Entity
@Description("tables")
public class Table extends ParamType {
private String cols;
@Column(name = "cols")
public String getCols() {
return cols;
}
public void setCols(String cols) {
this.cols = cols;
}
}

View File

@ -1,16 +1,23 @@
package org.bench4q.master.domain.factory;
import java.util.ArrayList;
import java.util.HashSet;
import org.bench4q.master.domain.entity.plugin.CheckBox;
import org.bench4q.master.domain.entity.plugin.Field;
import org.bench4q.master.domain.entity.plugin.Method;
import org.bench4q.master.domain.entity.plugin.MethodParam;
import org.bench4q.master.domain.entity.plugin.ParamProperty;
import org.bench4q.master.domain.entity.plugin.MultiField;
import org.bench4q.master.domain.entity.plugin.ParamType;
import org.bench4q.master.domain.entity.plugin.Plugin;
import org.bench4q.master.domain.entity.plugin.Table;
import org.bench4q.share.models.master.plugin.CheckBoxModel;
import org.bench4q.share.models.master.plugin.MethodModel;
import org.bench4q.share.models.master.plugin.MethodParamModel;
import org.bench4q.share.models.master.plugin.ParamPropertyModel;
import org.bench4q.share.models.master.plugin.MultiFieldModel;
import org.bench4q.share.models.master.plugin.ParamTypeModel;
import org.bench4q.share.models.master.plugin.ParamTypeString;
import org.bench4q.share.models.master.plugin.PluginModel;
import org.bench4q.share.models.master.plugin.FieldModel;
import org.bench4q.share.models.master.plugin.TableModel;
public class PluginFactory {
@ -49,31 +56,21 @@ public class PluginFactory {
private static MethodParam createMethodParamEntity(
MethodParamModel methodParamModel, Method method) {
MethodParam methodParam = new MethodParam();
methodParam.setEditorType(methodParamModel.getEditorType());
methodParam.setLable(methodParamModel.getLable());
methodParam.setName(methodParamModel.getName());
methodParam.setSeperator(methodParamModel.getSeperator());
methodParam.setParamProperties(new ArrayList<ParamProperty>());
if (methodParamModel.getParamProperties() != null) {
for (ParamPropertyModel paramPropertyModel : methodParamModel
.getParamProperties()) {
methodParam.getParamProperties().add(
createParamPropertyEntity(paramPropertyModel,
methodParam));
}
}
methodParam.setMethod(method);
methodParam.setParamType(createParamTypeEntity(
methodParamModel.getParamTypeModel(), methodParam));
return methodParam;
}
private static ParamProperty createParamPropertyEntity(
ParamPropertyModel paramPropertyModel, MethodParam methodParam) {
ParamProperty paramProperty = new ParamProperty();
paramProperty.setPropertyName(paramPropertyModel.getKey());
paramProperty.setPropertyValue(paramPropertyModel.getValue());
paramProperty.setValueSeperator(paramPropertyModel.getValueSeperator());
paramProperty.setMethodParam(methodParam);
return paramProperty;
private static ParamType createParamTypeEntity(
ParamTypeModel paramTypeModel, MethodParam methodParam) {
ParamType paramType = new ParamType();
paramType.setFieldSeperator(paramTypeModel.getFieldSeperator());
paramType.setValueSeperator(paramTypeModel.getFieldSeperator());
paramType.setType(paramTypeModel.getType());
return paramType;
}
public static MethodModel extractMethodModel(Method method) {
@ -92,28 +89,64 @@ public class PluginFactory {
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));
}
}
methodParamModel.setParamTypeModel(extractParamTypeModel(methodParam
.getParamType()));
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;
private static ParamTypeModel extractParamTypeModel(ParamType paramType) {
switch (paramType.getType()) {
case ParamTypeString.FIELD:
return extractFieldModel(paramType);
case ParamTypeString.MULTIFIELD:
return extractMultFieldiModel(paramType);
case ParamTypeString.TABLE:
return extractTableMode(paramType);
case ParamTypeString.CHECKBOX:
return extractCheckBoxModel(paramType);
default:
return null;
}
}
private static ParamTypeModel extractFieldModel(ParamType paramType) {
FieldModel fieldModel = new FieldModel();
Field field = (Field) paramType;
fieldModel.setSize(field.getSize());
fieldModel.setType(field.getType());
return fieldModel;
}
private static ParamTypeModel extractMultFieldiModel(ParamType paramType) {
MultiFieldModel multiFieldModel = new MultiFieldModel();
MultiField multiField = (MultiField) paramType;
multiFieldModel.setFieldSeperator(multiField.getFieldSeperator());
multiFieldModel.setSize(multiField.getSize());
multiFieldModel.setType(multiField.getType());
multiFieldModel.setValueSeperator(multiField.getValueSeperator());
return multiFieldModel;
}
private static TableModel extractTableMode(ParamType paramType) {
TableModel tableModel = new TableModel();
Table table = (Table) paramType;
tableModel.setFieldSeperator(table.getFieldSeperator());
tableModel.setType(table.getType());
tableModel.setValueSeperator(table.getValueSeperator());
tableModel.setCols(table.getCols());
return tableModel;
}
private static CheckBoxModel extractCheckBoxModel(ParamType paramType) {
CheckBoxModel checkBoxModel = new CheckBoxModel();
CheckBox checkBox = (CheckBox) paramType;
checkBoxModel.setFieldSeperator(checkBox.getFieldSeperator());
checkBoxModel.setType(checkBox.getType());
checkBoxModel.setValueSeperator(checkBox.getValueSeperator());
checkBoxModel.setRows(checkBox.getRows());
return checkBoxModel;
}
}

View File

@ -32,6 +32,10 @@
<mapping class="org.bench4q.master.domain.entity.plugin.Plugin" />
<mapping class="org.bench4q.master.domain.entity.plugin.Method" />
<mapping class="org.bench4q.master.domain.entity.plugin.MethodParam" />
<mapping class="org.bench4q.master.domain.entity.plugin.ParamProperty" />
<mapping class="org.bench4q.master.domain.entity.plugin.ParamType" />
<mapping class="org.bench4q.master.domain.entity.plugin.Field" />
<mapping class="org.bench4q.master.domain.entity.plugin.MultiField" />
<mapping class="org.bench4q.master.domain.entity.plugin.CheckBox" />
<mapping class="org.bench4q.master.domain.entity.plugin.Table" />
</session-factory>
</hibernate-configuration>

View File

@ -1,9 +1,7 @@
package org.bench4q.master.test.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@ -11,15 +9,17 @@ import javax.xml.bind.JAXBException;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.plugin.FieldModel;
import org.bench4q.share.models.master.plugin.MethodModel;
import org.bench4q.share.models.master.plugin.MethodParamModel;
import org.bench4q.share.models.master.plugin.ParamPropertyModel;
import org.bench4q.share.models.master.plugin.MultiFieldModel;
import org.bench4q.share.models.master.plugin.ParamTypeModel;
import org.bench4q.share.models.master.plugin.ParamTypeString;
import org.bench4q.share.models.master.plugin.PluginModel;
import org.bench4q.share.models.master.plugin.PluginResponseModel;
import org.junit.Assert;
import org.junit.Test;
public class PluginControllerTest extends TestBase {
private final String URLSTRING = BASE_URL + "/plugin";
@ -57,24 +57,22 @@ public class PluginControllerTest extends TestBase {
PluginResponseModel.class, httpResponse.getContent());
Assert.assertTrue(pluginResponseModel.isSuccess());
}
public PluginModel createOnePlugin() {
PluginModel plugin = new PluginModel();
MethodModel method = new MethodModel();
MethodParamModel methodParamUrl = new MethodParamModel();
methodParamUrl.setEditorType(MethodParamModel.FIELD);
methodParamUrl.setName("url");
methodParamUrl.setSeperator("");
methodParamUrl.setParamProperties(generateUrlProperties());
MethodParamModel methodParamParam = new MethodParamModel();
methodParamParam.setEditorType(MethodParamModel.TABLE);
methodParamParam.setName("Param");
methodParamParam.setSeperator("&");
methodParamParam.setParamProperties(generateParamProperties());
MethodParamModel methodParamModel = new MethodParamModel();
methodParamModel.setLable("input url");
methodParamModel.setName("url");
methodParamModel.setParamTypeModel(generateUrlParamTypeModel());
MethodParamModel methodParamsParamModel = new MethodParamModel();
methodParamsParamModel.setName("queryparams");
methodParamsParamModel.setLable("key=value");
methodParamsParamModel.setParamTypeModel(generateParamsParamTypeModel());
Set<MethodParamModel> methodParams = new HashSet<MethodParamModel>();
methodParams.add(methodParamParam);
methodParams.add(methodParamParam);
methodParams.add(methodParamModel);
methodParams.add(methodParamsParamModel);
method.setName("get");
method.setMethodParams(methodParams);
@ -87,23 +85,18 @@ public class PluginControllerTest extends TestBase {
}
private List<ParamPropertyModel> generateUrlProperties() {
ParamPropertyModel paramPropertyUrl = new ParamPropertyModel();
paramPropertyUrl.setKey("size");
paramPropertyUrl.setValue("20");
List<ParamPropertyModel> paramProperties = new ArrayList<ParamPropertyModel>();
paramProperties.add(paramPropertyUrl);
return paramProperties;
private ParamTypeModel generateUrlParamTypeModel() {
FieldModel paramPropertyUrl = new FieldModel();
paramPropertyUrl.setType(ParamTypeString.FIELD);
paramPropertyUrl.setSize(20);
return paramPropertyUrl;
}
private List<ParamPropertyModel> generateParamProperties() {
ParamPropertyModel paramProperty = new ParamPropertyModel();
paramProperty.setKey("cols");
paramProperty.setValue("key,value");
paramProperty.setValueSeperator(",");
List<ParamPropertyModel> paramProperties = new ArrayList<ParamPropertyModel>();
paramProperties.add(paramProperty);
return paramProperties;
private ParamTypeModel generateParamsParamTypeModel() {
MultiFieldModel multiFieldModel = new MultiFieldModel();
multiFieldModel.setSize(20);
multiFieldModel.setType(ParamTypeString.MULTIFIELD);
return multiFieldModel;
}
}

View File

@ -3,7 +3,6 @@ package org.bench4q.master.test.service;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
@ -16,9 +15,12 @@ import org.apache.commons.io.FileUtils;
import org.bench4q.master.domain.service.PluginService;
import org.bench4q.master.exception.Bench4QException;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.plugin.FieldModel;
import org.bench4q.share.models.master.plugin.MethodModel;
import org.bench4q.share.models.master.plugin.MethodParamModel;
import org.bench4q.share.models.master.plugin.ParamPropertyModel;
import org.bench4q.share.models.master.plugin.MultiFieldModel;
import org.bench4q.share.models.master.plugin.ParamTypeModel;
import org.bench4q.share.models.master.plugin.ParamTypeString;
import org.bench4q.share.models.master.plugin.PluginModel;
import org.junit.Assert;
import org.junit.Before;
@ -100,24 +102,21 @@ public class Test_PluginService {
.deletePlugin(plugin.getName()));
}
private PluginModel createOnePlugin() {
public PluginModel createOnePlugin() {
PluginModel plugin = new PluginModel();
MethodModel method = new MethodModel();
MethodParamModel methodParamUrl = new MethodParamModel();
methodParamUrl.setEditorType(MethodParamModel.FIELD);
methodParamUrl.setName("url");
methodParamUrl.setSeperator("");
methodParamUrl.setParamProperties(generateUrlProperties());
MethodParamModel methodParamParam = new MethodParamModel();
methodParamParam.setEditorType(MethodParamModel.TABLE);
methodParamParam.setName("Param");
methodParamParam.setSeperator("&");
methodParamParam.setParamProperties(generateParamProperties());
MethodParamModel methodParamModel = new MethodParamModel();
methodParamModel.setLable("input url");
methodParamModel.setName("url");
methodParamModel.setParamTypeModel(generateUrlParamTypeModel());
MethodParamModel methodParamsParamModel = new MethodParamModel();
methodParamsParamModel.setName("queryparams");
methodParamsParamModel.setLable("key=value");
methodParamsParamModel.setParamTypeModel(generateParamsParamTypeModel());
Set<MethodParamModel> methodParams = new HashSet<MethodParamModel>();
methodParams.add(methodParamParam);
methodParams.add(methodParamParam);
methodParams.add(methodParamModel);
methodParams.add(methodParamsParamModel);
method.setName("get");
method.setMethodParams(methodParams);
@ -130,25 +129,22 @@ public class Test_PluginService {
}
private List<ParamPropertyModel> generateUrlProperties() {
ParamPropertyModel paramPropertyUrl = new ParamPropertyModel();
paramPropertyUrl.setKey("size");
paramPropertyUrl.setValue("20");
List<ParamPropertyModel> paramProperties = new ArrayList<ParamPropertyModel>();
paramProperties.add(paramPropertyUrl);
return paramProperties;
private ParamTypeModel generateUrlParamTypeModel() {
FieldModel paramPropertyUrl = new FieldModel();
paramPropertyUrl.setType(ParamTypeString.FIELD);
paramPropertyUrl.setSize(20);
return paramPropertyUrl;
}
private List<ParamPropertyModel> generateParamProperties() {
ParamPropertyModel paramProperty = new ParamPropertyModel();
paramProperty.setKey("cols");
paramProperty.setValue("key,value");
paramProperty.setValueSeperator(",");
List<ParamPropertyModel> paramProperties = new ArrayList<ParamPropertyModel>();
paramProperties.add(paramProperty);
return paramProperties;
private ParamTypeModel generateParamsParamTypeModel() {
MultiFieldModel multiFieldModel = new MultiFieldModel();
multiFieldModel.setSize(20);
multiFieldModel.setType(ParamTypeString.MULTIFIELD);
return multiFieldModel;
}
private String buildSavePath() {
String dirString = "GUI" + System.getProperty("file.separator")
+ System.getProperty("file.separator");