() {
13 | @Override
14 | protected JDataContext initialValue() {
15 | return new JDataContext();
16 | }
17 | };
18 |
19 | public static JDataContext get() {
20 | return threadLocal.get();
21 | }
22 |
23 | public static void set(JDataContext jDataContext) {
24 | threadLocal.set(jDataContext);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/admin/sys/MorphiaFactory.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.admin.sys;
2 |
3 | import com.mongodb.Mongo;
4 | import com.mongodb.MongoClient;
5 | import org.mongodb.morphia.Datastore;
6 | import org.mongodb.morphia.Morphia;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
9 | import org.springframework.boot.autoconfigure.mongo.MongoProperties;
10 | import org.springframework.context.annotation.Bean;
11 | import org.springframework.context.annotation.Configuration;
12 |
13 | /**
14 | * Created by gongxinyi on 2018/11/26.
15 | */
16 | @Configuration
17 | @ConditionalOnClass(Mongo.class)
18 | public class MorphiaFactory {
19 |
20 | @Autowired
21 | private Mongo mongo;
22 |
23 | @Autowired
24 | MongoProperties mongoProperties;
25 |
26 | @Bean
27 | public Datastore get() {
28 | Morphia morphia = new Morphia();
29 | return morphia.createDatastore((MongoClient) mongo,mongoProperties.getMongoClientDatabase());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/admin/sys/SequenceService.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.admin.sys;
2 |
3 | import com.mongodb.client.MongoCollection;
4 | import com.mongodb.client.model.FindOneAndUpdateOptions;
5 | import com.mongodb.client.model.ReturnDocument;
6 | import org.bson.Document;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Component;
9 |
10 | /**
11 | * sequence util
12 | *
13 | * getNextSequence base on mongo
14 | */
15 | @Component
16 | public class SequenceService {
17 |
18 | public final static String SEQUENCE_COLLECTION = "_sequence";
19 |
20 | @Autowired
21 | SysService sysService;
22 |
23 | private void createCountersCollection(MongoCollection countersCollection, String sequenceName) {
24 |
25 | Document document = new Document();
26 | document.append("_id", sequenceName);
27 | document.append("seq", 0);
28 | countersCollection.insertOne(document);
29 | }
30 |
31 | /**
32 | * get next sequence
33 | *
34 | * for this project backend use {entity+"_"+domain} name to keep identity
35 | *
36 | * @param sequenceName must identity for one collection
37 | * @return
38 | */
39 | public String getNextSequence(String sequenceName) {
40 | MongoCollection countersCollection = sysService.getTenantCollection(SEQUENCE_COLLECTION);
41 | if (countersCollection.count() == 0) {
42 | createCountersCollection(countersCollection, sequenceName);
43 | }
44 | Document searchQuery = new Document("_id", sequenceName);
45 | Document increase = new Document("seq", 1);
46 | Document updateQuery = new Document("$inc", increase);
47 | Document result = countersCollection.findOneAndUpdate(searchQuery, updateQuery, new FindOneAndUpdateOptions().upsert(true).returnDocument(ReturnDocument.AFTER));
48 | return result.get("seq").toString();
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/admin/sys/SysService.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.admin.sys;
2 |
3 | import com.dataserver.admin.model.Permission;
4 | import com.dataserver.admin.model.security.AuthorityName;
5 | import com.dataserver.admin.security.User;
6 | import com.dataserver.api.Filter;
7 | import com.mongodb.MongoClient;
8 | import com.mongodb.MongoClientURI;
9 | import com.mongodb.client.MongoCollection;
10 | import io.jsonwebtoken.lang.Collections;
11 | import org.mongodb.morphia.Datastore;
12 | import org.mongodb.morphia.Morphia;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
15 | import org.springframework.security.core.GrantedAuthority;
16 | import org.springframework.security.core.context.SecurityContextHolder;
17 | import org.springframework.stereotype.Component;
18 |
19 | import java.util.*;
20 | import java.util.stream.Collectors;
21 |
22 | /**
23 | *
24 | */
25 | @Component
26 | public class SysService {
27 |
28 | @Autowired
29 | MorphiaFactory morphiaFactory;
30 |
31 | /**
32 | * all the tenant cache the mongoClient
33 | */
34 | @Autowired
35 | Map uriMongoMap;
36 |
37 | public Datastore getSysDataStore() {
38 | return morphiaFactory.get();
39 | }
40 |
41 | public Datastore getTenantDataStore() {
42 |
43 | // setJDataContext();
44 | JDataContext jDataContext = JDataContext.get();
45 | return getTenantDataStore(jDataContext.getTenant().getConnectionStr());
46 | }
47 |
48 | public Datastore getTenantDataStore(Tenant tenant) {
49 | return getTenantDataStore(tenant.getConnectionStr());
50 | }
51 |
52 | public Datastore getTenantDataStore(String mongoUri) {
53 | MongoClientURI mongoClientURI = getMongoClientURI(mongoUri);
54 | initMongoClient(mongoUri);
55 | return new Morphia().createDatastore(uriMongoMap.get(mongoUri), mongoClientURI.getDatabase());
56 | }
57 |
58 | public MongoCollection getTenantCollection(String entity) {
59 | // setJDataContext();
60 | JDataContext jDataContext = JDataContext.get();
61 | MongoClientURI mongoClientURI = getMongoClientURI(jDataContext.getTenant().getConnectionStr());
62 | initMongoClient(jDataContext.getTenant().getConnectionStr());
63 | return uriMongoMap.get(jDataContext.getTenant().getConnectionStr()).getDatabase(mongoClientURI.getDatabase()).getCollection(entity);
64 | }
65 |
66 | public MongoClient initMongoClient(String uri) {
67 | if (!uriMongoMap.containsKey(uri)) {
68 | MongoClientURI mongoClientURI = getMongoClientURI(uri);
69 | MongoClient client = new MongoClient(mongoClientURI);
70 | uriMongoMap.put(uri, client);
71 | }
72 | return uriMongoMap.get(uri);
73 | }
74 |
75 | public MongoClientURI getMongoClientURI(String uri) {
76 | return new MongoClientURI(uri);
77 | }
78 |
79 | public List getRoles() {
80 | UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
81 | Collection grantedAuthorities = authentication.getAuthorities();
82 | return grantedAuthorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
83 | }
84 |
85 | public Set getPermissions() {
86 | User user = getTenantDataStore().get(User.class, SecurityContextHolder.getContext().getAuthentication().getName());
87 | return user.getPermissions();
88 | }
89 |
90 |
91 | public List getFilters(String eid) {
92 | for (Permission permission : getPermissions()) {
93 | if (eid.equals(permission.getEid()) && !Collections.isEmpty(permission.getFilters())) {
94 | return permission.getFilters();
95 | }
96 | }
97 | return new ArrayList<>();
98 | }
99 |
100 | public boolean isAdmin() {
101 | return getRoles().contains(AuthorityName.ROLE_ADMIN.toString());
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/admin/sys/Tenant.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.admin.sys;
2 |
3 | import lombok.Data;
4 | import org.mongodb.morphia.annotations.Entity;
5 | import org.mongodb.morphia.annotations.Id;
6 |
7 | /**
8 | * Created by gongxinyi on 2018/11/27.
9 | */
10 | @Data
11 | @Entity(value = "_tenant", noClassnameStored = true)
12 | public class Tenant {
13 | @Id
14 | private String id;
15 | private String connectionStr;
16 | }
17 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/admin/sys/TenantUser.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.admin.sys;
2 |
3 | import lombok.Data;
4 | import org.mongodb.morphia.annotations.Entity;
5 | import org.mongodb.morphia.annotations.Id;
6 | import org.mongodb.morphia.annotations.Reference;
7 |
8 | /**
9 | * Created by gongxinyi on 2018/12/5.
10 | */
11 | @Entity(value = "_tenantUser", noClassnameStored = true)
12 | @Data
13 | public class TenantUser {
14 | @Id
15 | private String username;
16 | @Reference
17 | private Tenant tenant;
18 | }
19 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/admin/util/JsonUtil.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.admin.util;
2 |
3 | import com.fasterxml.jackson.core.JsonGenerationException;
4 | import com.fasterxml.jackson.core.JsonParseException;
5 | import com.fasterxml.jackson.databind.DeserializationFeature;
6 | import com.fasterxml.jackson.databind.JavaType;
7 | import com.fasterxml.jackson.databind.JsonMappingException;
8 | import com.fasterxml.jackson.databind.ObjectMapper;
9 |
10 | import java.io.IOException;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * @author paul
16 | * @version V1.0
17 | * @description json工具类, 依赖jackson
18 | * @date 2017年7月10日 上午10:54:43
19 | * @update 2017年7月10日 上午10:54:43
20 | */
21 | public class JsonUtil {
22 | private static ObjectMapper INSTANCE = new ObjectMapper();
23 |
24 | static {
25 | INSTANCE.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
26 | }
27 |
28 | private JsonUtil() {
29 | }
30 |
31 | /**
32 | * @param obj 准备转换对象
33 | * @return
34 | * @throws JsonProcessingException
35 | * @description 对象转换成json字符串
36 | * @author paul
37 | * @date 2017年7月10日 上午10:54:50
38 | * @update 2017年7月10日 上午10:54:50
39 | * @version V1.0
40 | */
41 | public static String toJsonStr(Object obj) {
42 | try {
43 | return INSTANCE.writeValueAsString(obj);
44 | } catch (JsonGenerationException e) {
45 | e.printStackTrace();
46 | } catch (JsonMappingException e) {
47 | e.printStackTrace();
48 | } catch (IOException e) {
49 | e.printStackTrace();
50 | }
51 | return null;
52 | }
53 |
54 | /**
55 | * @param json 准备转换json
56 | * @param type 转换类型
57 | * @return
58 | * @throws Exception 转换异常
59 | * @description json字符串转换成对象
60 | * @author paul
61 | * @date 2017年7月10日 上午11:08:34
62 | * @update 2017年7月10日 上午11:08:34
63 | * @version V1.0
64 | */
65 | @SuppressWarnings("unchecked")
66 | public static T parseJson(String json, String type) {
67 | try {
68 | return (T) parseJson(json, Class.forName(type));
69 | } catch (ClassNotFoundException e) {
70 | e.printStackTrace();
71 | } catch (Exception e) {
72 | e.printStackTrace();
73 | }
74 | return null;
75 | }
76 |
77 | /**
78 | * @param json 准备转换json
79 | * @param clazz 转换类型
80 | * @return
81 | * @description json字符串转换成对象
82 | * @author paul
83 | * @date 2017年7月10日 上午11:12:58
84 | * @update 2017年7月10日 上午11:12:58
85 | * @version V1.0
86 | */
87 | public static T parseJson(String json, Class clazz) {
88 | try {
89 | return (T) INSTANCE.readValue(json, clazz);
90 | } catch (JsonParseException e) {
91 | e.printStackTrace();
92 | } catch (JsonMappingException e) {
93 | e.printStackTrace();
94 | } catch (IOException e) {
95 | e.printStackTrace();
96 | }
97 | return null;
98 | }
99 |
100 | /**
101 | * @param json 准备转换json
102 | * @param clazz 集合元素类型
103 | * @return
104 | * @description json字符串转换成对象集合
105 | * @author paul
106 | * @date 2017年8月12日 下午1:28:27
107 | * @update 2017年8月12日 下午1:28:27
108 | * @version V1.0
109 | */
110 | @SuppressWarnings("unchecked")
111 | public static List parseJsonList(String json, Class clazz) {
112 | try {
113 | JavaType javaType = getCollectionType(ArrayList.class, clazz);
114 | return (List) INSTANCE.readValue(json, javaType);
115 | } catch (IOException e) {
116 | e.printStackTrace();
117 | }
118 | return null;
119 | }
120 |
121 | /**
122 | * @param collectionClass 集合类
123 | * @param elementClasses 集合元素类
124 | * @return
125 | * @description 获取泛型的ColloectionType
126 | * @author paul
127 | * @date 2017年8月12日 下午2:17:38
128 | * @update 2017年8月12日 下午2:17:38
129 | * @version V1.0
130 | */
131 | private static JavaType getCollectionType(Class> collectionClass, Class>... elementClasses) {
132 | return INSTANCE.getTypeFactory().constructParametricType(collectionClass, elementClasses);
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/admin/util/ResponseUtil.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.admin.util;
2 |
3 | import org.springframework.http.HttpStatus;
4 | import org.springframework.http.ResponseEntity;
5 |
6 | import java.util.Collection;
7 | import java.util.List;
8 |
9 | /**
10 | * Created by gongxinyi on 2019-05-08.
11 | */
12 | public class ResponseUtil {
13 | public static ResponseEntity listToResponseEntity(Collection results, Long totalCount) {
14 | return ResponseEntity
15 | .status(HttpStatus.OK)
16 | .header("X-Total-Count", totalCount + "")
17 | .header("Access-Control-Expose-Headers", "X-Total-Count")
18 | .body(results);
19 | }
20 |
21 | public static ResponseEntity listToResponseEntity(Collection results) {
22 | return listToResponseEntity(results, new Long(results.size()));
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/admin/util/SnowFlake.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.admin.util;
2 |
3 | /**
4 | * Created by gongxinyi on 2018-11-12.
5 | */
6 | public class SnowFlake {
7 |
8 | /**
9 | * 起始的时间戳
10 | */
11 | private final static long START_STMP = 1480166465631L;
12 |
13 | /**
14 | * 每一部分占用的位数
15 | */
16 | private final static long SEQUENCE_BIT = 12; //序列号占用的位数
17 | private final static long MACHINE_BIT = 5; //机器标识占用的位数
18 | private final static long DATACENTER_BIT = 5;//数据中心占用的位数
19 |
20 | /**
21 | * 每一部分的最大值
22 | */
23 | private final static long MAX_DATACENTER_NUM = -1L ^ (-1L << DATACENTER_BIT);
24 | private final static long MAX_MACHINE_NUM = -1L ^ (-1L << MACHINE_BIT);
25 | private final static long MAX_SEQUENCE = -1L ^ (-1L << SEQUENCE_BIT);
26 |
27 | /**
28 | * 每一部分向左的位移
29 | */
30 | private final static long MACHINE_LEFT = SEQUENCE_BIT;
31 | private final static long DATACENTER_LEFT = SEQUENCE_BIT + MACHINE_BIT;
32 | private final static long TIMESTMP_LEFT = DATACENTER_LEFT + DATACENTER_BIT;
33 |
34 | private long datacenterId; //数据中心
35 | private long machineId; //机器标识
36 | private long sequence = 0L; //序列号
37 | private long lastStmp = -1L;//上一次时间戳
38 |
39 | public SnowFlake(long datacenterId, long machineId) {
40 | if (datacenterId > MAX_DATACENTER_NUM || datacenterId < 0) {
41 | throw new IllegalArgumentException("datacenterId can't be greater than MAX_DATACENTER_NUM or less than 0");
42 | }
43 | if (machineId > MAX_MACHINE_NUM || machineId < 0) {
44 | throw new IllegalArgumentException("machineId can't be greater than MAX_MACHINE_NUM or less than 0");
45 | }
46 | this.datacenterId = datacenterId;
47 | this.machineId = machineId;
48 | }
49 |
50 | /**
51 | * 产生下一个ID
52 | *
53 | * @return
54 | */
55 | public synchronized long nextId() {
56 | long currStmp = getNewstmp();
57 | if (currStmp < lastStmp) {
58 | throw new RuntimeException("Clock moved backwards. Refusing to generate id");
59 | }
60 |
61 | if (currStmp == lastStmp) {
62 | //相同毫秒内,序列号自增
63 | sequence = (sequence + 1) & MAX_SEQUENCE;
64 | //同一毫秒的序列数已经达到最大
65 | if (sequence == 0L) {
66 | currStmp = getNextMill();
67 | }
68 | } else {
69 | //不同毫秒内,序列号置为0
70 | sequence = 0L;
71 | }
72 |
73 | lastStmp = currStmp;
74 |
75 | return (currStmp - START_STMP) << TIMESTMP_LEFT //时间戳部分
76 | | datacenterId << DATACENTER_LEFT //数据中心部分
77 | | machineId << MACHINE_LEFT //机器标识部分
78 | | sequence; //序列号部分
79 | }
80 |
81 | private long getNextMill() {
82 | long mill = getNewstmp();
83 | while (mill <= lastStmp) {
84 | mill = getNewstmp();
85 | }
86 | return mill;
87 | }
88 |
89 | private long getNewstmp() {
90 | return System.currentTimeMillis();
91 | }
92 |
93 | public static void main(String[] args) {
94 | SnowFlake snowFlake = new SnowFlake(2, 3);
95 |
96 | for (int i = 0; i < (1 << 12); i++) {
97 | System.out.println(snowFlake.nextId());
98 | }
99 |
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/Constants.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi;
2 |
3 | /**
4 | * 关键字
5 | *
6 | * @author gongxinyi
7 | * @date 2018-09-27
8 | */
9 | public class Constants {
10 | public static final String SYS_COL_DS = "_datasource";
11 | public static final String SYS_COL_ENTITY = "_entity";
12 | public static final String ApiStandard = "apiStandard";
13 | public static final String ApiStandard_postgrest = "postgrest";
14 | public static final String ApiStandard_jsonserver = "jsonserver";
15 | public static final String delimiter = "__";
16 | public static final String id = "id";
17 | public static final String q = "q";
18 |
19 | public static final String _id = "_id";
20 |
21 | public static final String ENTITY_NAME_PREFIX = "e";
22 | public static final String FIELD_NAME_PREFIX = "f";
23 | }
24 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/SwaggerConfig.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import springfox.documentation.builders.PathSelectors;
6 | import springfox.documentation.builders.RequestHandlerSelectors;
7 | import springfox.documentation.service.ApiKey;
8 | import springfox.documentation.service.AuthorizationScope;
9 | import springfox.documentation.service.SecurityReference;
10 | import springfox.documentation.spi.DocumentationType;
11 | import springfox.documentation.spi.service.contexts.SecurityContext;
12 | import springfox.documentation.spring.web.plugins.Docket;
13 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
14 |
15 | import java.util.Arrays;
16 | import java.util.List;
17 |
18 | @Configuration
19 | @EnableSwagger2
20 | public class SwaggerConfig {
21 | @Bean
22 | public Docket api() {
23 | return new Docket(DocumentationType.SWAGGER_2)
24 | .select()
25 | .apis(RequestHandlerSelectors.any())
26 | .paths(PathSelectors.regex("^(?!auth).*$"))
27 | .build()
28 | .securitySchemes(securitySchemes())
29 | .securityContexts(securityContexts());
30 | }
31 |
32 | private List securitySchemes() {
33 | return Arrays.asList(new ApiKey("Authorization", "Authorization", "header"));
34 | }
35 | private List securityContexts() {
36 | return Arrays.asList(
37 | SecurityContext.builder()
38 | .securityReferences(defaultAuth())
39 | .forPaths(PathSelectors.regex("^(?!auth).*$"))
40 | .build()
41 | );
42 | }
43 |
44 | List defaultAuth() {
45 | AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
46 | AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
47 | authorizationScopes[0] = authorizationScope;
48 | return Arrays.asList(
49 | new SecurityReference("Authorization", authorizationScopes));
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/SysConfig.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi;
2 |
3 | import com.aliyun.oss.OSSClient;
4 | import com.dataserver.api.IDataService;
5 | import com.dataserver.api.schema.DbTypeEnum;
6 | import com.dataserver.connector.elasticsearch.EsDataService;
7 | import com.dataserver.connector.mongodb.MongoDataService;
8 | import com.dataserver.connector.mysql.MySqlDataService;
9 | import com.dataserver.dataapi.data.AbstractRequestWrapper;
10 | import com.dataserver.dataapi.data.ApiStandard;
11 | import com.dataserver.dataapi.data.FileStorageApi;
12 | import com.dataserver.dataapi.data.ResponseWrapper;
13 | import com.dataserver.dataapi.jsonserver.JsonServerRequestWrapper;
14 | import com.dataserver.dataapi.jsonserver.JsonServerResponseWrapper;
15 | import com.dataserver.dataapi.postgrest.PostgrestRequestWrapper;
16 | import com.dataserver.dataapi.postgrest.PostgrestResponseWrapper;
17 | import org.springframework.beans.factory.BeanFactory;
18 | import org.springframework.beans.factory.annotation.Autowired;
19 | import org.springframework.beans.factory.annotation.Value;
20 | import org.springframework.context.annotation.Bean;
21 | import org.springframework.stereotype.Component;
22 |
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | /**
27 | * Created by gongxinyi on 2018-11-01.
28 | */
29 | @Component
30 | public class SysConfig {
31 |
32 | @Bean
33 | public Map> apiRequestWrapperMap() {
34 | Map> apiRequestWrapperMap = new HashMap<>();
35 | apiRequestWrapperMap.put(ApiStandard.postgrest, PostgrestRequestWrapper.class);
36 | apiRequestWrapperMap.put(ApiStandard.jsonserver, JsonServerRequestWrapper.class);
37 | return apiRequestWrapperMap;
38 | }
39 |
40 | @Bean
41 | public Map> apiResponseWrapperMap() {
42 | Map> apiResponseWrapperMap = new HashMap<>();
43 | apiResponseWrapperMap.put(ApiStandard.postgrest, PostgrestResponseWrapper.class);
44 | apiResponseWrapperMap.put(ApiStandard.jsonserver, JsonServerResponseWrapper.class);
45 | return apiResponseWrapperMap;
46 | }
47 |
48 | @Bean
49 | public Map> dataServiceMap() {
50 | Map> dbTypeEnumClassMap = new HashMap<>();
51 | dbTypeEnumClassMap.put(DbTypeEnum.mysql, MySqlDataService.class);
52 | dbTypeEnumClassMap.put(DbTypeEnum.mongo, MongoDataService.class);
53 | dbTypeEnumClassMap.put(DbTypeEnum.elasticsearch, EsDataService.class);
54 | return dbTypeEnumClassMap;
55 | }
56 |
57 |
58 | @Value("${jdatastudio.storage.endpoint}")
59 | String endpoint;
60 |
61 | @Bean
62 | public OSSClient cosClient() {
63 | // Endpoint以杭州为例,其它Region请按实际情况填写。
64 | // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
65 | String accessKeyId = "***";
66 | String accessKeySecret = "***";
67 |
68 | // 创建OSSClient实例。
69 | OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
70 | return ossClient;
71 | }
72 |
73 | @Autowired
74 | private BeanFactory beanFactory;
75 |
76 | @Value("${jdatastudio.storage.strategy}")
77 | String storageStrategy;
78 |
79 | @Bean
80 | public FileStorageApi fileStorageApi() {
81 | return (FileStorageApi) beanFactory.getBean(storageStrategy);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/data/AbstractRequestWrapper.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.data;
2 |
3 | import com.dataserver.api.Filter;
4 | import com.dataserver.api.Pagination;
5 | import com.dataserver.api.QueryParams;
6 | import com.dataserver.api.Sort;
7 | import com.dataserver.dataapi.Constants;
8 |
9 | import java.util.List;
10 | import java.util.Map;
11 |
12 | /**
13 | * @author gongxinyi
14 | * @date 2018-11-02
15 | */
16 | public abstract class AbstractRequestWrapper {
17 | protected abstract Pagination wrapPagination(Map requestParams);
18 |
19 | protected abstract List wrapSort(Map requestParams);
20 |
21 | protected abstract String[] wrapSelect(Map requestParams);
22 |
23 | protected abstract List wrapFilters(Map requestParams);
24 |
25 | protected String wrapQ(Map requestParams){
26 | String q = (String)requestParams.get(Constants.q);
27 | requestParams.remove(Constants.q);
28 | return q;
29 | }
30 |
31 | public QueryParams wrapQueryParams(Map requestParams) {
32 | requestParams.remove(Constants.ApiStandard);
33 | return QueryParams.builder()
34 | .q(wrapQ(requestParams))
35 | .filters(wrapFilters(requestParams))
36 | .pagination(wrapPagination(requestParams))
37 | .sorts(wrapSort(requestParams))
38 | .select(wrapSelect(requestParams))
39 | .build();
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/data/ApiStandard.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.data;
2 |
3 | /**
4 | * Created by gongxinyi on 2018-11-02.
5 | */
6 | public enum ApiStandard {
7 | postgrest,
8 | jsonserver,
9 | }
10 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/data/DataServiceProxy.java:
--------------------------------------------------------------------------------
1 | //package com.dataserver.dataapi.data;
2 | //
3 | //import com.dataserver.api.IDataService;
4 | //import com.dataserver.api.schema.DbTypeEnum;
5 | //import com.dataserver.api.schema.JDataSource;
6 | //import org.springframework.beans.factory.annotation.Autowired;
7 | //import org.springframework.context.ApplicationContext;
8 | //import org.springframework.stereotype.Component;
9 | //
10 | //import java.util.Map;
11 | //
12 | ///**
13 | // * @author gongxinyi
14 | // * @date 2018-10-31
15 | // */
16 | //@Component
17 | //public class DataServiceProxy {
18 | //
19 | // @Autowired
20 | // ApplicationContext applicationContext;
21 | //
22 | //
23 | //
24 | // public JDataSource getJDataSource() {
25 | //// JDataSource jDataSource = JDataSource.builder()
26 | //// .id("1")
27 | //// .dbType(DbTypeEnum.mysql)
28 | //// .url("jdbc:mysql://172.24.7.29:3306/test_easyadmin")
29 | //// .username("root")
30 | //// .password("JRTESTbai!@#123")
31 | //// .build();
32 | //
33 | //// JDataSource jDataSource = JDataSource.builder()
34 | //// .id("2")
35 | //// .dbType(DbTypeEnum.mongo)
36 | //// .url("mongodb://192.168.202.238:27017/wnsyrtdipt")
37 | //// .build();
38 | //
39 | //// JDataSource jDataSource = JDataSource.builder()
40 | //// .dbType(DbTypeEnum.elasticsearch)
41 | //// .url("http://10.194.32.168:40000")
42 | //// .clusterName("")
43 | //// .indexName("")
44 | //// .build();
45 | //
46 | // return null;
47 | // }
48 | //}
49 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/data/FileStorageApi.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.data;
2 |
3 | import lombok.SneakyThrows;
4 |
5 | /**
6 | * Created by gongxinyi on 2019-05-25.
7 | */
8 | public interface FileStorageApi {
9 | @SneakyThrows
10 | String saveBase64File(String base64Str);
11 |
12 | @SneakyThrows
13 | String getBase64Str(String objectName);
14 | }
15 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/data/JdsFile.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.data;
2 |
3 | import lombok.Builder;
4 | import lombok.Data;
5 |
6 | @Data
7 | @Builder
8 | public class JdsFile {
9 | String title;
10 | String id;
11 |
12 | public String toPersistentStr() {
13 | return id + ";" + title;
14 | }
15 |
16 | public JdsFile toPojo(String persistentStr) {
17 | String[] jdsFile = persistentStr.split(";");
18 | return JdsFile.builder().id(jdsFile[0]).title(jdsFile[1]).build();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/data/ResponseWrapper.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.data;
2 |
3 | import org.springframework.http.ResponseEntity;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | *
9 | * @author gongxinyi
10 | * @date 2018-11-02
11 | */
12 | public interface ResponseWrapper {
13 | ResponseEntity listToResponseEntity(List results, Long totalCount);
14 | }
15 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/data/StorageAliyunServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.data;
2 |
3 | import com.aliyun.oss.OSSClient;
4 | import com.aliyun.oss.model.OSSObject;
5 | import com.dataserver.admin.util.SnowFlake;
6 | import lombok.SneakyThrows;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | import java.io.BufferedReader;
11 | import java.io.ByteArrayInputStream;
12 | import java.io.InputStream;
13 | import java.io.InputStreamReader;
14 |
15 | @Service(value = "aliyun")
16 | public class StorageAliyunServiceImpl implements FileStorageApi {
17 | @Autowired
18 | SnowFlake snowFlake;
19 |
20 | @Autowired
21 | OSSClient ossClient;
22 |
23 | static final String bucketName = "jdatastudio";
24 |
25 | /**
26 | * 保存base64文件
27 | *
28 | * @param base64Str
29 | * @return 唯一id
30 | */
31 | @Override
32 | @SneakyThrows
33 | public String saveBase64File(String base64Str) {
34 | String objectName = String.valueOf(snowFlake.nextId());
35 | ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(base64Str.getBytes("UTF-8")));
36 | return "aliyun:" + objectName;
37 | }
38 |
39 | /**
40 | * 根据文件id,返回base64
41 | *
42 | * @param fileId
43 | * @return
44 | */
45 | @Override
46 | @SneakyThrows
47 | public String getBase64Str(String fileId) {
48 | String objectName = fileId.replace("aliyun:", "");
49 | // 调用ossClient.getObject返回一个OSSObject实例,该实例包含文件内容及文件元信息。
50 | OSSObject ossObject = ossClient.getObject(bucketName, objectName);
51 | // 调用ossObject.getObjectContent获取文件输入流,可读取此输入流获取其内容。
52 | InputStream content = ossObject.getObjectContent();
53 | StringBuffer stringBuffer = new StringBuffer();
54 | if (content != null) {
55 | BufferedReader reader = new BufferedReader(new InputStreamReader(content));
56 | while (true) {
57 | String line = reader.readLine();
58 | if (line == null) {
59 | break;
60 | }
61 | stringBuffer.append(line);
62 | }
63 | // 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
64 | content.close();
65 | }
66 |
67 | return stringBuffer.toString();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/data/StorageJdsServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.data;
2 |
3 | import com.dataserver.admin.util.SnowFlake;
4 | import lombok.SneakyThrows;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.io.File;
10 | import java.nio.charset.StandardCharsets;
11 | import java.nio.file.Files;
12 | import java.nio.file.Path;
13 | import java.nio.file.Paths;
14 |
15 | @Service("jds")
16 | public class StorageJdsServiceImpl implements FileStorageApi {
17 |
18 | @Autowired
19 | SnowFlake snowFlake;
20 | @Value("${jdatastudio.storage.rootPath}")
21 | String rootPath;
22 |
23 | /**
24 | * 保存base64文件
25 | *
26 | * @param base64Str
27 | * @return 唯一id
28 | */
29 | @Override
30 | @SneakyThrows
31 | public String saveBase64File(String base64Str) {
32 | String fileId = String.valueOf(snowFlake.nextId());
33 | if(!Files.exists(Paths.get(rootPath))){
34 | Files.createDirectories(Paths.get(rootPath));
35 | }
36 | Files.write(Paths.get(rootPath + File.separator + fileId), base64Str.getBytes("UTF-8"));
37 | return "jds:" + fileId;
38 | }
39 |
40 | /**
41 | * 根据文件id,返回base64
42 | *
43 | * @param fileId
44 | * @return
45 | */
46 | @Override
47 | @SneakyThrows
48 | public String getBase64Str(String fileId) {
49 | String fileName = fileId.replace("jds:", "");
50 | if(!Files.exists(Paths.get(rootPath))){
51 | Files.createDirectories(Paths.get(rootPath));
52 | }
53 | Path path = Paths.get(rootPath + File.separator + fileName);
54 | return Files.exists(path) ? new String(Files.readAllBytes(path), StandardCharsets.UTF_8) : null;
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/jsonserver/JsonServerResponseWrapper.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.jsonserver;
2 |
3 | import com.dataserver.dataapi.data.ResponseWrapper;
4 | import org.springframework.http.HttpStatus;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.stereotype.Component;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * Created by gongxinyi on 2018-11-02.
12 | */
13 | @Component
14 | public class JsonServerResponseWrapper implements ResponseWrapper {
15 | @Override
16 | public ResponseEntity listToResponseEntity(List results, Long totalCount) {
17 | return ResponseEntity
18 | .status(HttpStatus.OK)
19 | .header("X-Total-Count", totalCount + "")
20 | .header("Access-Control-Expose-Headers", "X-Total-Count")
21 | .body(results);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/postgrest/PostgrestRequestWrapper.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.postgrest;
2 |
3 | import com.dataserver.api.*;
4 | import com.dataserver.dataapi.data.AbstractRequestWrapper;
5 | import org.apache.commons.lang.StringUtils;
6 | import org.springframework.stereotype.Component;
7 |
8 | import java.util.ArrayList;
9 | import java.util.Arrays;
10 | import java.util.List;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author gongxinyi
15 | * @date 2018-11-02
16 | */
17 | @Component
18 | public class PostgrestRequestWrapper extends AbstractRequestWrapper {
19 | @Override
20 | protected Pagination wrapPagination(Map requestParams) {
21 | return Pagination.builder()
22 | .offset(Integer.parseInt(requestParams.getOrDefault(offset, "0").toString()))
23 | .limit(Integer.parseInt(requestParams.getOrDefault(limit, "10").toString()))
24 | .build();
25 | }
26 |
27 | @Override
28 | protected List wrapSort(Map requestParams) {
29 | List sorts = new ArrayList<>();
30 | String orderStr = requestParams.getOrDefault(order, "").toString();
31 | if (!StringUtils.isEmpty(orderStr)) {
32 | String[] orders = orderStr.split(",");
33 | for (String order : orders) {
34 | String[] orderArray = order.split("\\.");
35 | sorts.add(new Sort(orderArray[0], OrderEnum.valueOf(orderArray[1])));
36 | }
37 | }
38 | return sorts;
39 | }
40 |
41 | @Override
42 | protected String[] wrapSelect(Map requestParams) {
43 | return String.valueOf(requestParams.getOrDefault(select, allcolumns)).split(",");
44 | }
45 |
46 | @Override
47 | protected List wrapFilters(Map requestParams) {
48 | List filters = new ArrayList<>();
49 | requestParams.forEach((k, v) -> {
50 | if (!sysKeys.contains(k)) {
51 | String[] operatorAndValue = v.toString().split("\\.");
52 | OperatorEnum operatorEnum = OperatorEnum.eq;
53 | String value;
54 | if (operatorAndValue.length == 2) {
55 | operatorEnum = OperatorEnum.valueOf(operatorAndValue[0]);
56 | value = operatorAndValue[1];
57 | } else {
58 | value = operatorAndValue[0];
59 | }
60 | filters.add(new Filter(k, operatorEnum, value));
61 | }
62 | });
63 | return filters;
64 | }
65 |
66 | public static final String select = "select";
67 | public static final String order = "order";
68 | public static final String limit = "limit";
69 | public static final String offset = "offset";
70 | public static final String and = "and";
71 | public static final String or = "or";
72 | public static final String allcolumns = "*";
73 |
74 | static List sysKeys = Arrays.asList(offset,
75 | select,
76 | and,
77 | limit,
78 | order,
79 | or);
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/java/com/dataserver/dataapi/postgrest/PostgrestResponseWrapper.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.dataapi.postgrest;
2 |
3 | import com.dataserver.dataapi.data.ResponseWrapper;
4 | import org.springframework.http.HttpStatus;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.stereotype.Component;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * @author gongxinyi
13 | * @date 2018-11-02
14 | */
15 | @Component
16 | public class PostgrestResponseWrapper implements ResponseWrapper {
17 | @Override
18 | public ResponseEntity listToResponseEntity(List results, Long totalCount) {
19 | return ResponseEntity
20 | .status(HttpStatus.OK)
21 | .header("Content-Range", totalCount + "")
22 | .header("Access-Control-Expose-Headers", "Content-Range")
23 | .body(results);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/resources/2110293_jdatastudio.com.pfx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/data-server/jdatastudio/588dbba7fef8a9819a8f6d0439faf411a72d0ba8/jdatastudio-admin/src/main/resources/2110293_jdatastudio.com.pfx
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/resources/application-aliyun.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 443
3 | ssl:
4 | enabled: true
5 | key-store: classpath:2110293_jdatastudio.com.pfx
6 | key-password: 80hKDEWT
7 | key-store-type: PFX
8 |
9 | http-port: 80
10 |
11 | jwt:
12 | header: Authorization
13 | secret: datastudio
14 | expiration: 604800
15 | route:
16 | authentication:
17 | path: /auth
18 | refresh: /refresh
19 |
20 | jdatastudio:
21 | cloud: true
22 | storage:
23 | strategy: aliyun
24 | endpoint: http://oss-cn-shanghai-internal.aliyuncs.com
25 |
26 | spring:
27 | application:
28 | name: jdatastudio-admin
29 | data:
30 | mongodb:
31 | uri: mongodb://jdatastudioadmin:jdatastudioadmin@101.132.97.131:27017/jdatastudio-admin
32 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/resources/application-lcloud.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 80
3 |
4 | jwt:
5 | header: Authorization
6 | secret: datastudio
7 | expiration: 604800
8 | route:
9 | authentication:
10 | path: /auth
11 | refresh: /refresh
12 |
13 | jdatastudio:
14 | cloud: true
15 |
16 | spring:
17 | application:
18 | name: jdatastudio-admin
19 | data:
20 | mongodb:
21 | uri: mongodb://localhost:27017/jdatastudio-admin
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 80
3 |
4 | jwt:
5 | header: Authorization
6 | secret: datastudio
7 | expiration: 604800
8 | route:
9 | authentication:
10 | path: /auth
11 | refresh: /refresh
12 |
13 | jdatastudio:
14 | cloud: false
15 | tenant:
16 | uri: mongodb://localhost:27017/testLocal2
17 | admin: gongxinong@gmail.com
18 | storage:
19 | strategy: jds
20 | rootPath: /Users/gongmark/data/jds
21 | endpoint: http://oss-cn-shanghai.aliyuncs.com
22 |
23 | spring:
24 | application:
25 | name: jdatastudio-admin
26 | data:
27 | mongodb:
28 | uri: mongodb://192.168.202.238:27017/jdatastudio
--------------------------------------------------------------------------------
/jdatastudio-admin/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | %d{yy-MM-dd.HH:mm:ss.SSS} [%-16t] %-5p %-22c{0} %X{ServiceId} - %m%n
8 | UTF-8
9 |
10 |
11 |
12 | ${LOG_HOME}/${APP}_detail.log
13 |
14 | %d{yy-MM-dd.HH:mm:ss.SSS} [%-16t] %-5p %-22c{0} %X{ServiceId} - %m%n
15 | UTF-8
16 |
17 |
18 | ${LOG_HOME}/${APP}_detail.log.%d{yyyyMMdd}
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/jdatastudio-admin/src/test/java/com/dataserver/admin/UserServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.admin;
2 |
3 | import com.dataserver.admin.security.Role;
4 | import com.dataserver.admin.security.User;
5 | import com.fasterxml.jackson.databind.ObjectWriter;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.junit.Test;
8 | import org.springframework.http.MediaType;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
14 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
16 |
17 | /**
18 | * Created by gongxinyi on 2018/12/5.
19 | */
20 | @Slf4j
21 | public class UserServiceTest extends AbstractTest {
22 | @Test
23 | public void getUsers() throws Exception {
24 | final String token = extractToken(login("admin", "admin").andReturn());
25 | log.info("token:{}", token);
26 | mockMvc.perform(get("/users")
27 | .header("Authorization", "Bearer " + token)
28 | .accept(MediaType.APPLICATION_JSON))
29 | .andExpect(status().isOk());
30 | }
31 |
32 | @Test
33 | public void addUser() throws Exception {
34 | final String token = extractToken(login("admin", "admin").andReturn());
35 | User user = new User();
36 | user.setUsername("foo");
37 | user.setPassword("foo");
38 | user.setEnabled(true);
39 | Role role = new Role();
40 | role.setId("ROLE_ADMIN");
41 | List roles = new ArrayList();
42 | roles.add(role);
43 | user.setRoles(roles);
44 | ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
45 | mockMvc.perform(post("/users")
46 | .content(ow.writeValueAsString(user))
47 | .header("Authorization", "Bearer " + token)
48 | .accept(MediaType.APPLICATION_JSON))
49 | .andExpect(status().isOk());
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/jdatastudio-api/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
--------------------------------------------------------------------------------
/jdatastudio-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | jdatastudio-api
7 |
8 |
9 | com.dataserver
10 | jdatastudio
11 | 0.0.1-SNAPSHOT
12 |
13 |
14 |
15 |
16 | org.projectlombok
17 | lombok
18 | true
19 |
20 |
21 | commons-lang
22 | commons-lang
23 | 2.6
24 |
25 |
26 | org.mongodb.morphia
27 | morphia
28 | 1.3.1
29 |
30 |
31 | com.fasterxml.jackson.core
32 | jackson-annotations
33 | 2.8.0
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/jdatastudio-api/src/main/java/com/dataserver/api/ComplexFilter.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.api;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * 复杂组合
9 | *
10 | * @author gongxinyi
11 | * @date 2018-09-27
12 | */
13 | @Data
14 | public class ComplexFilter {
15 | LogicEnum logicEnum;
16 | List filtersList;
17 | }
18 |
--------------------------------------------------------------------------------
/jdatastudio-api/src/main/java/com/dataserver/api/Constants.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.api;
2 |
3 | /**
4 | * 关键字
5 | *
6 | * @author gongxinyi
7 | * @date 2018-09-27
8 | */
9 | public class Constants {
10 | public static final String choiceitemdelimiter = "\\|";
11 | public static final String choiceitemtab = "\n";
12 | public static final String allcolumns = "*";
13 | public static final String dataService = "dataService";
14 | public static final String schemaService = "dataService";
15 | }
16 |
--------------------------------------------------------------------------------
/jdatastudio-api/src/main/java/com/dataserver/api/Filter.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.api;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | /**
9 | * 过滤器
10 | *
11 | * @author gongxinyi
12 | * @date 2018-09-27
13 | */
14 | @Builder
15 | @Data
16 | @AllArgsConstructor
17 | @NoArgsConstructor
18 | public class Filter {
19 | private String field;
20 | private OperatorEnum operator;
21 | private String value;
22 | }
23 |
--------------------------------------------------------------------------------
/jdatastudio-api/src/main/java/com/dataserver/api/Filters.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.api;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * 过滤组合
9 | *
10 | * @author gongxinyi
11 | * @date 2018-09-27
12 | */
13 | @Data
14 | public class Filters {
15 | LogicEnum logicEnum;
16 | List filterList;
17 | }
18 |
--------------------------------------------------------------------------------
/jdatastudio-api/src/main/java/com/dataserver/api/IDataService.java:
--------------------------------------------------------------------------------
1 | package com.dataserver.api;
2 |
3 | import com.dataserver.api.schema.JDataSource;
4 |
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /**
9 | * 数据服务
10 | *
11 | * @author gongxinyi
12 | * @date 2018-09-27
13 | */
14 | public interface IDataService {
15 |
16 | /**
17 | * 查询数据列表
18 | *
19 | * @param jDataSource
20 | * @param entityName
21 | * @param queryParams
22 | * @return
23 | */
24 | List