Skip to content

Commit

Permalink
Use $ as the portal for core operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed May 31, 2017
1 parent 9f3d2e9 commit 742ffa2
Show file tree
Hide file tree
Showing 25 changed files with 281 additions and 285 deletions.
156 changes: 79 additions & 77 deletions README.adoc

Large diffs are not rendered by default.

210 changes: 90 additions & 120 deletions docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<description>Dew公共模块</description>
<url>https://github.com/gudaoxuri/dew-common</url>
<packaging>jar</packaging>
<version>1.1.1</version>
<version>1.2.0</version>

<properties>
<java.version>1.8</java.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.ecfront.dew.common;

import com.ecfront.dew.common.interceptor.DewInterceptorProcessor;

/**
* DEW Common 操作入口
*/
public class DEW {
public class $ {

/**
* Json与Java对象互转
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ecfront/dew/common/BeanHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class BeanHelper {

private static NullAwareBeanUtilsBean copyPropertiesAdapter = new NullAwareBeanUtilsBean();

BeanHelper(){}

/**
* Java Bean Copy
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ecfront/dew/common/ClassScanHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
public class ClassScanHelper {

ClassScanHelper(){}

/**
* 扫描获取指定包下符合条件的class类
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ecfront.dew.common.interceptor;
package com.ecfront.dew.common;

import com.ecfront.dew.common.Resp;
import com.ecfront.dew.common.interceptor.DewInterceptExec;
import com.ecfront.dew.common.interceptor.DewInterceptRespBody;
import com.ecfront.dew.common.interceptor.DewInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -18,6 +20,9 @@ public class DewInterceptorProcessor {

private static Map<String, List<DewInterceptor<?>>> CONTAINER = new HashMap<>();

DewInterceptorProcessor() {
}

/**
* 注册拦截器栈
*
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/ecfront/dew/common/EncryptHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
*/
public class EncryptHelper {

EncryptHelper() {
}

public Symmetric symmetric = new Symmetric();
public Asymmetric asymmetric = new Asymmetric();

/**
* Base64 转 数组
*/
Expand Down Expand Up @@ -51,13 +57,10 @@ public String encodeStringToBase64(String str, String encode) throws Unsupported
return new String(Base64.getEncoder().encode(str.getBytes(encode)), encode);
}

public Symmetric symmetric = new Symmetric();
public Asymmetric asymmetric = new Asymmetric();

/**
* 对称加密
*/
class Symmetric {
public class Symmetric {

/**
* 对称加密
Expand Down Expand Up @@ -110,7 +113,7 @@ public boolean validate(String strSrc, String strEncrypted, String algorithm) th
/**
* 非对称加密
*/
class Asymmetric {
public class Asymmetric {

/**
* 生成公钥和私钥
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ecfront/dew/common/FieldHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class FieldHelper {
Pattern.compile("^[\u4e00-\u9fa5]+$");


FieldHelper(){}

/**
* 验证邮箱格式是否合法
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ecfront/dew/common/FileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
public class FileHelper {

FileHelper(){}

/**
* 根据文件路径名读取文件所有内容
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ecfront/dew/common/JsonHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class JsonHelper {
setTimeZone(Calendar.getInstance().getTimeZone());
}

JsonHelper(){}

/**
* 设置时区
*
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/ecfront/dew/common/MimeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
*/
public class MimeHelper {

private Map<String, List<String>> types = new HashMap<String, List<String>>() {{
MimeHelper(){}

private static Map<String, List<String>> types = new HashMap<String, List<String>>() {{
put("office", new ArrayList<String>() {{
add(Mime.TXT.toString());
add(Mime.DOC.toString());
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/ecfront/dew/common/Resp.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static Resp<Void> error(Resp<?> resp) {
public static <E> Resp<E> generic(Resp resp, Class<E> bodyClazz) {
E body = null;
if (resp.ok() && resp.getBody() != null) {
body = DEW.json.toObject(resp.getBody(), bodyClazz);
body = $.json.toObject(resp.getBody(), bodyClazz);
}
return new Resp<>(resp.getCode(), resp.getMessage(), body);
}
Expand All @@ -226,7 +226,7 @@ public static <E> Resp<E> generic(Resp resp, Class<E> bodyClazz) {
public static <E> Resp<List<E>> genericList(Resp resp, Class<E> bodyClazz) {
List<E> body = null;
if (resp.ok() && resp.getBody() != null) {
body = DEW.json.toList(resp.getBody(), bodyClazz);
body = $.json.toList(resp.getBody(), bodyClazz);
}
return new Resp<>(resp.getCode(), resp.getMessage(), body);
}
Expand All @@ -241,8 +241,8 @@ public static <E> Resp<List<E>> genericList(Resp resp, Class<E> bodyClazz) {
public static <E> Resp<PageDTO<E>> genericPage(Resp resp, Class<E> bodyClazz) {
PageDTO<E> body = null;
if (resp.ok() && resp.getBody() != null) {
body = DEW.json.toObject(resp.getBody(), PageDTO.class);
body.setObjects(body.getObjects().stream().map(i -> DEW.json.toObject(i, bodyClazz)).collect(Collectors.toList()));
body = $.json.toObject(resp.getBody(), PageDTO.class);
body.setObjects(body.getObjects().stream().map(i -> $.json.toObject(i, bodyClazz)).collect(Collectors.toList()));
}
return new Resp<>(resp.getCode(), resp.getMessage(), body);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ecfront/dew/common/ShellProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class ShellProcessor {

private static final Logger logger = LoggerFactory.getLogger(ShellProcessor.class);

ShellProcessor(){}

private volatile String taskId;
private volatile String successFlag;
private volatile String progressFlag;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ecfront/dew/common/TimeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
public class TimeHelper {

TimeHelper(){}

public final SimpleDateFormat msf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
public final SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
public final SimpleDateFormat mf = new SimpleDateFormat("yyyyMMddHHmm");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ecfront/dew/common/TimerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class TimerHelper {

private static Map<String, ScheduledFuture<?>> CONTAINER = new HashMap<>();

TimerHelper(){}

/**
* 延迟执行的周期性任务
*
Expand Down
34 changes: 17 additions & 17 deletions src/test/java/com/ecfront/dew/common/BeanHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@ public void copyProperties() throws Exception {
User dest = new User();
dest.setAge(11);
dest.setWorkAge(11);
DEW.bean.copyProperties(dest, ori);
$.bean.copyProperties(dest, ori);
Assert.assertTrue(Objects.equals(dest.getName(), "张三") && dest.getAge() == 0 && dest.getWorkAge() == 11);
}

@Test
public void findClassAnnotation() throws Exception {
TestAnnotation.RPC ann = DEW.bean.getClassAnnotation(IdxController.class, TestAnnotation.RPC.class);
TestAnnotation.RPC ann = $.bean.getClassAnnotation(IdxController.class, TestAnnotation.RPC.class);
Assert.assertEquals("/idx/", ann.path());
}

@Test
public void findFieldInfo() throws Exception {
Map<String, BeanHelper.FieldInfo> fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, null, null, null, null);
Map<String, BeanHelper.FieldInfo> fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, null, null, null);
Assert.assertEquals(2, fieldsInfo.size());
fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, null, new HashSet<Class<? extends Annotation>>() {{
fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, new HashSet<Class<? extends Annotation>>() {{
add(Deprecated.class);
}}, null, null);
Assert.assertEquals(1, fieldsInfo.size());
fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, new HashSet<String>() {{
fieldsInfo = $.bean.findFieldsInfo(IdxController.class, new HashSet<String>() {{
add("parentField");
}}, new HashSet<Class<? extends Annotation>>() {{
add(Deprecated.class);
}}, null, null);
Assert.assertEquals(0, fieldsInfo.size());
fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, null, null, null, new HashSet<Class<? extends Annotation>>() {{
fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, null, null, new HashSet<Class<? extends Annotation>>() {{
add(Deprecated.class);
}});
Assert.assertEquals(1, fieldsInfo.size());
fieldsInfo = DEW.bean.findFieldsInfo(IdxController.class, null, null, new HashSet<String>() {{
fieldsInfo = $.bean.findFieldsInfo(IdxController.class, null, null, new HashSet<String>() {{
add("parentField");
}}, new HashSet<Class<? extends Annotation>>() {{
add(Resource.class);
Expand All @@ -61,23 +61,23 @@ public void findFieldInfo() throws Exception {

@Test
public void findMethodInfo() throws Exception {
List<BeanHelper.MethodInfo> methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, null, null, null, null);
List<BeanHelper.MethodInfo> methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, null, null, null);
Assert.assertEquals(methodsInfo.size(), 7);
methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, null, new HashSet<Class<? extends Annotation>>() {{
methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, new HashSet<Class<? extends Annotation>>() {{
add(TestAnnotation.GET.class);
}}, null, null);
Assert.assertEquals(methodsInfo.size(), 6);
methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, new HashSet<String>() {{
methodsInfo = $.bean.findMethodsInfo(IdxController.class, new HashSet<String>() {{
add("find");
}}, new HashSet<Class<? extends Annotation>>() {{
add(TestAnnotation.GET.class);
}}, null, null);
Assert.assertEquals(methodsInfo.size(), 4);
methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, null, null, null, new HashSet<Class<? extends Annotation>>() {{
methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, null, null, new HashSet<Class<? extends Annotation>>() {{
add(TestAnnotation.POST.class);
}});
Assert.assertEquals(methodsInfo.size(), 3);
methodsInfo = DEW.bean.findMethodsInfo(IdxController.class, null, null, new HashSet<String>() {{
methodsInfo = $.bean.findMethodsInfo(IdxController.class, null, null, new HashSet<String>() {{
add("childFind");
}}, new HashSet<Class<? extends Annotation>>() {{
add(TestAnnotation.POST.class);
Expand All @@ -87,7 +87,7 @@ public void findMethodInfo() throws Exception {

@Test
public void parseRelFieldAndMethod() throws Exception {
Map<String, Method[]> rel = DEW.bean.parseRelFieldAndMethod(User.class, null, null, null, null);
Map<String, Method[]> rel = $.bean.parseRelFieldAndMethod(User.class, null, null, null, null);
Assert.assertEquals(6, rel.size());
Assert.assertEquals(2, rel.get("enable").length);
}
Expand All @@ -96,29 +96,29 @@ public void parseRelFieldAndMethod() throws Exception {
public void findValuesByRel() throws Exception {
User user = new User();
user.setName("张三");
Map<String, Object> values = DEW.bean.findValuesByRel(user, DEW.bean.parseRelFieldAndMethod(User.class, null, null, null, null));
Map<String, Object> values = $.bean.findValuesByRel(user, $.bean.parseRelFieldAndMethod(User.class, null, null, null, null));
Assert.assertEquals("张三", values.get("name"));
}

@Test
public void findValues() throws Exception {
User user = new User();
user.setName("张三");
Map<String, Object> values = DEW.bean.findValues(user, null, null, null, null);
Map<String, Object> values = $.bean.findValues(user, null, null, null, null);
Assert.assertEquals("张三", values.get("name"));
}

@Test
public void getValue() throws Exception {
User user = new User();
user.setName("张三");
Assert.assertEquals("张三", DEW.bean.getValue(user, "name"));
Assert.assertEquals("张三", $.bean.getValue(user, "name"));
}

@Test
public void setValue() throws Exception {
User user = new User();
DEW.bean.setValue(user, "name", "张三");
$.bean.setValue(user, "name", "张三");
Assert.assertEquals("张三", user.getName());
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/ecfront/dew/common/ClassScanHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class ClassScanHelperTest {

@Test
public void scan() throws Exception {
Set<Class<?>> resultInFile = DEW.clazz.scan("com.ecfront.dew.common.test", new HashSet<Class<? extends Annotation>>() {{
Set<Class<?>> resultInFile = $.clazz.scan("com.ecfront.dew.common.test", new HashSet<Class<? extends Annotation>>() {{
add(Deprecated.class);
}}, null);
Assert.assertEquals(2, resultInFile.size());
Set<Class<?>> resultInJar = DEW.clazz.scan("org.junit", null, new HashSet<String>() {{
Set<Class<?>> resultInJar = $.clazz.scan("org.junit", null, new HashSet<String>() {{
add("Before\\w*");
}});
Assert.assertEquals(4, resultInJar.size());
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/com/ecfront/dew/common/EncryptHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class EncryptHelperTest {
@Test
public void symmetric() throws Exception {
Assert.assertEquals("70C0CC2B7BF8A8EBCD7B59C49DDDA9A1E551122BA5D7AB3B7B02141D4CE4C626".toLowerCase(),
DEW.encrypt.symmetric.encrypt("gudaoxuri", "SHA-256"));
Assert.assertTrue(DEW.encrypt.symmetric.validate("gudaoxuri", DEW.encrypt.symmetric.encrypt("gudaoxuri", "SHA-256"), "SHA-256"));
Assert.assertTrue(DEW.encrypt.symmetric.validate("password", DEW.encrypt.symmetric.encrypt("password", "bcrypt"), "bcrypt"));
$.encrypt.symmetric.encrypt("gudaoxuri", "SHA-256"));
Assert.assertTrue($.encrypt.symmetric.validate("gudaoxuri", $.encrypt.symmetric.encrypt("gudaoxuri", "SHA-256"), "SHA-256"));
Assert.assertTrue($.encrypt.symmetric.validate("password", $.encrypt.symmetric.encrypt("password", "bcrypt"), "bcrypt"));
}

@Test
Expand All @@ -25,20 +25,20 @@ public void asymmetric() throws Exception {

String d = "Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1]  ,设计初衷是实现可伸缩的语言[2]  、并集成面向对象编程和函数式编程的各种特性。";
// 生成公钥密钥
Map<String, String> keys = DEW.encrypt.asymmetric.generateKeys("RSA", 1024, "UTF-8");
PublicKey publicKey = DEW.encrypt.asymmetric.getPublicKey(publicStr, "RSA");
PrivateKey privateKey = DEW.encrypt.asymmetric.getPrivateKey(privateStr, "RSA");
Map<String, String> keys = $.encrypt.asymmetric.generateKeys("RSA", 1024, "UTF-8");
PublicKey publicKey = $.encrypt.asymmetric.getPublicKey(publicStr, "RSA");
PrivateKey privateKey = $.encrypt.asymmetric.getPrivateKey(privateStr, "RSA");

// 公钥加密/私钥解密
byte[] encryptByPub = DEW.encrypt.asymmetric.encrypt(d.getBytes("UTF-8"), publicKey, 1024, "RSA");
String result = new String(DEW.encrypt.asymmetric.decrypt(encryptByPub, privateKey, 1024, "RSA"), "UTF-8");
byte[] encryptByPub = $.encrypt.asymmetric.encrypt(d.getBytes("UTF-8"), publicKey, 1024, "RSA");
String result = new String($.encrypt.asymmetric.decrypt(encryptByPub, privateKey, 1024, "RSA"), "UTF-8");
Assert.assertTrue(Objects.equals(result, d));

// 私钥加密/公钥解密
byte[] encryptByPriv = DEW.encrypt.asymmetric.encrypt(d.getBytes("UTF-8"), privateKey, 1024, "RSA");
byte[] decryptByPub = DEW.encrypt.asymmetric.decrypt(encryptByPriv, publicKey, 1024, "RSA");
byte[] encryptByPriv = $.encrypt.asymmetric.encrypt(d.getBytes("UTF-8"), privateKey, 1024, "RSA");
byte[] decryptByPub = $.encrypt.asymmetric.decrypt(encryptByPriv, publicKey, 1024, "RSA");
Assert.assertTrue(Objects.equals(new String(decryptByPub, "UTF-8"), d));
Assert.assertTrue(DEW.encrypt.asymmetric.verify(publicKey, decryptByPub, DEW.encrypt.asymmetric.sign(privateKey, d.getBytes("UTF-8"), "SHA1withRSA"), "SHA1withRSA"));
Assert.assertTrue($.encrypt.asymmetric.verify(publicKey, decryptByPub, $.encrypt.asymmetric.sign(privateKey, d.getBytes("UTF-8"), "SHA1withRSA"), "SHA1withRSA"));
}

}
Loading

0 comments on commit 742ffa2

Please sign in to comment.