diff --git a/pom.xml b/pom.xml index 8664950..c74fb6a 100644 --- a/pom.xml +++ b/pom.xml @@ -12,24 +12,11 @@ Tigon Tigon - - me.chyxion - maven-parent - 0.0.2-RELEASE - - 1.8 1.8 - 4.3.8.RELEASE - 1.5.10.RELEASE - 1.7.23 - 2.7 - 1.3.2 - 1.8.10 - Main - 8080 - / + 5.0.7.RELEASE + 2.0.3.RELEASE @@ -48,36 +35,24 @@ - tigon-model tigon-mybatis tigon-sequence - tigon-redis tigon-mybatis-cache-redis tigon-shiro-cache tigon-shiro-cache-redis - tigon-webmvc-core - tigon-webmvc-spring-boot - tigon-webmvc-war tigon-shiro-core - tigon-shiro-spring-boot - tigon-shiro-war + tigon-shiro-cas + tigon-shiro + tigon-web tigon-service-api tigon-service-support - tigon-props-config tigon-extjs - tigon-freemarker-support - tigon-jsp-support tigon-codegen - - me.chyxion.tigon - tigon-lombok - ${project.version} - me.chyxion.tigon tigon-model @@ -95,22 +70,7 @@ me.chyxion.tigon - tigon-webmvc-core - ${project.version} - - - me.chyxion.tigon - tigon-webmvc-spring-boot - ${project.version} - - - me.chyxion.tigon - tigon-webmvc-war - ${project.version} - - - me.chyxion.tigon - tigon-redis + tigon-web ${project.version} @@ -120,12 +80,12 @@ me.chyxion.tigon - tigon-shiro-cache-redis + tigon-shiro-cache ${project.version} me.chyxion.tigon - tigon-shiro-cache + tigon-shiro-cache-redis ${project.version} @@ -135,12 +95,12 @@ me.chyxion.tigon - tigon-shiro-spring-boot + tigon-shiro ${project.version} me.chyxion.tigon - tigon-shiro-war + tigon-shiro-cas ${project.version} @@ -158,112 +118,31 @@ tigon-extjs ${project.version} - - me.chyxion.tigon - tigon-freemarker-support - ${project.version} - - - me.chyxion.tigon - tigon-jsp-support - ${project.version} - me.chyxion.tigon tigon-codegen ${project.version} - - me.chyxion.tigon - tigon-props-config - ${project.version} - org.projectlombok lombok - 1.16.14 - - - org.hibernate - hibernate-validator - 5.4.0.Final - - - - commons-beanutils - commons-beanutils - 1.9.3 - - - - org.mybatis - mybatis - 3.4.2 - - - org.mybatis - mybatis-spring - 1.3.1 - - - - mysql - mysql-connector-java - 5.1.6 - - - com.alibaba - druid - 1.0.28 - - - org.mongodb - bson - 3.4.2 - - - redis.clients - jedis - 2.9.0 - - - - org.apache.shiro - shiro-core - ${shiro.version} - - - org.apache.shiro - shiro-web - ${shiro.version} - - - org.apache.shiro - shiro-spring - ${shiro.version} - - - commons-fileupload - commons-fileupload - 1.3.2 - - - - cglib - cglib - 3.2.4 - - - org.aspectj - aspectjrt - ${aspectj.version} - - - org.aspectj - aspectjweaver - ${aspectj.version} + 1.18.0 + + org.springframework + spring-framework-bom + ${spring.version} + pom + import + + + org.springframework.data + spring-data-releasetrain + Kay-SR2 + pom + import + org.springframework.boot spring-boot-dependencies @@ -272,366 +151,33 @@ import - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-logging - - + cglib + cglib + 3.2.4 - - org.jdom - jdom - 1.1.3 - - - com.alibaba - fastjson - 1.2.31 - - - org.apache.commons - commons-lang3 - 3.1 - - - commons-io - commons-io - 2.4 - - - org.freemarker - freemarker - 2.3.23 - - - commons-codec - commons-codec - 1.10 - - - commons-logging - commons-logging - 1.2 - - - - junit - junit - 4.12 - - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - jcl-over-slf4j - ${slf4j.version} - - - - org.apache.logging.log4j - log4j-api - ${log4j.version} - - - org.apache.logging.log4j - log4j-core - ${log4j.version} - - - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} - - - - - javax.servlet - javax.servlet-api - 3.1.0 - - - javax.el - javax.el-api - 3.0.0 - - - javax.servlet.jsp.jstl - jstl-api - 1.2 - - org.apache.maven.plugins - maven-clean-plugin - - - com.coderplus.maven.plugins - copy-rename-maven-plugin - - - org.apache.maven.plugins - maven-resources-plugin - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.maven.plugins - maven-dependency-plugin + org.springframework.boot + spring-boot-maven-plugin + + true + - - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - - org.apache.maven.plugins - maven-resources-plugin - 2.7 - - ${project.build.sourceEncoding} - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - ${maven.compiler.source} - ${maven.compiler.target} - ${project.build.sourceEncoding} - - - - org.apache.maven.plugins - maven-source-plugin - 2.4 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-dependency-plugin - 2.10 - - - copy-dependencies - package - - copy-dependencies - - - - target/lib - - provided - runtime - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - - true - true - true - - - Shaun Chyxion - - - - - - org.apache.maven.plugins - maven-shade-plugin - 2.3 - - - package - - shade - - - ${project.artifactId} - true - jar-with-dependencies - - - ${main.class} - - - META-INF/spring.handlers - - - META-INF/spring.schemas - - - META-INF/spring.tooling - - - - - - - - org.apache.maven.plugins - maven-clean-plugin - 2.6.1 - - - remove-config-file - clean - compile - - true - - - src/main/resources/spring - - config.properties - - - - src/main/resources - - application.properties - application.yaml - log4j2.xml - - - - - - - - - com.coderplus.maven.plugins - copy-rename-maven-plugin - 1.0 - - - copy-config-props-file - generate-resources - - copy - - - src/main/resources/config_${project.activeProfiles[0].id}.properties - src/main/resources/spring/config.properties - - - - copy-application-props-file - generate-resources - - copy - - - src/main/resources/application_${project.activeProfiles[0].id}.properties - src/main/resources/application.properties - - - - copy-application-yaml-file - generate-resources - - copy - - - src/main/resources/application_${project.activeProfiles[0].id}.yaml - src/main/resources/application.yaml - - - - copy-log4j2-xml-file - generate-resources - - copy - - - src/main/resources/log4j2_${project.activeProfiles[0].id}.xml - src/main/resources/log4j2.xml - - - - - - org.apache.maven.plugins - maven-war-plugin - 2.6 - - 3.0 - - - src/main/webapp - - - - - - org.apache.tomcat.maven - tomcat7-maven-plugin - 2.2 - - ${maven.tomcat.port} - ${maven.tomcat.path} - utf-8 - utf-8 - false - - ${maven.tomcat.port} - ${project.basedir} - - - org.springframework.boot spring-boot-maven-plugin ${spring-boot.version} true - ${start-class} ZIP - - -Xdebug - -Dproject.basedir=${project.basedir} - @@ -641,37 +187,6 @@ - - org.apache.maven.plugins - maven-help-plugin - 2.2 - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-clean-plugin - - [2.6.1,) - - - clean - - - - - - - - - - diff --git a/tigon-codegen-spring-boot-test b/tigon-codegen-spring-boot-test deleted file mode 160000 index a7c6906..0000000 --- a/tigon-codegen-spring-boot-test +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a7c690619e09fae1d48584794d68d1b8ee78c197 diff --git a/tigon-codegen-war-test b/tigon-codegen-war-test deleted file mode 160000 index a7c6906..0000000 --- a/tigon-codegen-war-test +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a7c690619e09fae1d48584794d68d1b8ee78c197 diff --git a/tigon-codegen/pom.xml b/tigon-codegen/pom.xml index a7db588..7584e96 100644 --- a/tigon-codegen/pom.xml +++ b/tigon-codegen/pom.xml @@ -17,10 +17,19 @@ ../ + + me.chyxion.tigon.codegen.TigonCodeGen + me.chyxion.tigon.codegen.TigonCodeGen + + - me.chyxion.tigon - tigon-freemarker-support + org.freemarker + freemarker + + + org.springframework + spring-context-support me.chyxion.tigon @@ -28,29 +37,32 @@ me.chyxion.tigon - tigon-webmvc-core + tigon-web me.chyxion.tigon tigon-service-support - - org.springframework - spring-jdbc - - - org.springframework - spring-context-support - commons-io commons-io + 2.6 me.chyxion.tigon tigon-mybatis + + mysql + mysql-connector-java + 5.1.6 + + + com.alibaba + druid + 1.1.10 + org.projectlombok lombok @@ -58,14 +70,23 @@ - org.springframework - spring-test - provided - - - junit - junit + org.springframework.boot + spring-boot-starter-test provided + + + codegen + + + org.springframework.boot + spring-boot-maven-plugin + + false + true + + + + diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java new file mode 100644 index 0000000..bb23368 --- /dev/null +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/TigonCodeGen.java @@ -0,0 +1,23 @@ +package me.chyxion.tigon.codegen; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Jun 24, 2018 20:43:36 + */ +@Slf4j +@SpringBootApplication +public class TigonCodeGen { + + /** + * @param args start args + */ + public static void main(final String[] args) { + log.info("Startup args [{}].", args); + SpringApplication.run(TigonCodeGen.class, args); + } +} diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/WebConfig.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/WebConfig.java new file mode 100644 index 0000000..7539b1a --- /dev/null +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/WebConfig.java @@ -0,0 +1,23 @@ +package me.chyxion.tigon.codegen; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Jun 24, 2018 20:58:08 + */ +@Configuration +public class WebConfig implements WebMvcConfigurer { + + /** + * {@inheritDoc} + */ + @Override + public void addResourceHandlers(final ResourceHandlerRegistry registry) { + registry.addResourceHandler("/assets/**") + .addResourceLocations("/assets/", "classpath:webapp/assets/"); + } +} diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java index 28a6181..6073db5 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/controller/CodeGenController.java @@ -9,9 +9,11 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import javax.validation.constraints.NotNull; import org.apache.commons.lang3.StringUtils; +import javax.validation.constraints.NotBlank; + +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.servlet.ModelAndView; -import org.hibernate.validator.constraints.NotBlank; import me.chyxion.tigon.codegen.service.CodeGenService; import me.chyxion.tigon.codegen.service.CodeGenBaseTool; import org.springframework.web.bind.annotation.RequestParam; @@ -35,11 +37,16 @@ public class CodeGenController { private CodeGenService service; @Autowired private CodeGenBaseTool tool; + @Value("${codegen.components:}") + private String genComponents; @RequestMapping(method = GET) public ModelAndView index() { return new ModelAndView("webapp/views/codegen") - .addObject("pkg", tool.getPkg()); + .addObject("pkg", tool.getPkg()) + .addObject("components", + StringUtils.isNotBlank(genComponents) ? + JSON.toJSONString(genComponents.split("\\s*[,;]\\s*")) : "[]"); } @RequestMapping(value = "/tables") diff --git a/tigon-freemarker-support/src/main/java/me/chyxion/tigon/freemarker/FreeMarkerViewResolverExt.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/freemarker/FreeMarkerViewResolverExt.java similarity index 62% rename from tigon-freemarker-support/src/main/java/me/chyxion/tigon/freemarker/FreeMarkerViewResolverExt.java rename to tigon-codegen/src/main/java/me/chyxion/tigon/codegen/freemarker/FreeMarkerViewResolverExt.java index f06fc92..8e76d27 100644 --- a/tigon-freemarker-support/src/main/java/me/chyxion/tigon/freemarker/FreeMarkerViewResolverExt.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/freemarker/FreeMarkerViewResolverExt.java @@ -1,8 +1,7 @@ -package me.chyxion.tigon.freemarker; +package me.chyxion.tigon.codegen.freemarker; import java.util.Locale; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; @@ -13,9 +12,8 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; * chyxion@163.com
* Dec 5, 2014 2:31:39 PM */ +@Slf4j public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver { - private static final Logger log = - LoggerFactory.getLogger(FreeMarkerViewResolverExt.class); /** * {@inheritDoc} @@ -23,7 +21,7 @@ public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver { @Override public View resolveViewName(String viewName, Locale locale) throws Exception { - log.debug("Try To Resolve View Name [{}], Locale [{}] As FreeMarker View.", viewName, locale); - return super.resolveViewName(viewName.replaceAll("(?i)(^\\s*ftl\\:)|(\\.ftl\\s*$)", ""), locale); + log.debug("Try to resolve view name [{}], locale [{}] as freemarker view.", viewName, locale); + return super.resolveViewName(viewName.replaceAll("(?i)(^\\s*ftl:)|(\\.ftl\\s*$)", ""), locale); } } diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java index fc56d91..80576b0 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenBaseTool.java @@ -1,41 +1,25 @@ package me.chyxion.tigon.codegen.service; import java.io.File; -import java.util.Map; -import java.util.Set; -import java.util.Date; -import java.util.List; -import java.util.Arrays; -import org.slf4j.Logger; -import java.util.TreeSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; +import java.util.*; import java.io.FileWriter; import java.sql.ResultSet; -import org.w3c.dom.Element; import java.io.IOException; -import java.io.InputStream; import java.sql.Connection; -import java.util.Properties; -import java.util.LinkedList; -import javax.sql.DataSource; import java.sql.SQLException; import java.io.FileInputStream; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import java.sql.DatabaseMetaData; import com.alibaba.fastjson.JSON; import java.io.InputStreamReader; import me.chyxion.tigon.model.M1; import freemarker.template.Template; import org.apache.commons.io.IOUtils; -import javax.annotation.PostConstruct; import org.apache.commons.io.FileUtils; import me.chyxion.tigon.util.WordUtils; +import java.nio.charset.StandardCharsets; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.CharEncoding; -import me.chyxion.tigon.codegen.utils.DbTool; -import javax.xml.parsers.DocumentBuilderFactory; +import me.chyxion.tigon.codegen.util.DbTool; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.dao.DataAccessException; @@ -46,7 +30,6 @@ import com.alibaba.fastjson.serializer.SerializerFeature; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; -import static org.springframework.context.ConfigurableApplicationContext.*; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; /** @@ -56,92 +39,21 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; * chyxion@163.com
* Dec 3, 2014 11:25:17 AM */ +@Slf4j public class CodeGenBaseTool { - private static final Logger log = - LoggerFactory.getLogger(CodeGenBaseTool.class); @Autowired private FreeMarkerConfigurer fmCfg; - @Autowired(required = false) - private DataSource dataSource; + @Autowired private JdbcTemplate jdbcTpl; - @Value("#{systemProperties['project.basedir']}") + @Value("${project.base-dir}") private String projDir; - private String groupId; + @Value("${project.base-package}") private String pkg; - private Properties config = new Properties(); - private Set baseCols = new HashSet(); + @Value("${codegen.table-prefix:}") + private String tablePrefix; - /** - * @param col - * @return true if col is base col - */ - public boolean isBaseCol(String col) { - return baseCols.contains(col); - } - - /** - * @param key - * @return - */ - public String getConfig(String key) { - return config.getProperty(key); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public String getConfig(String key, String defaultValue) { - return config.getProperty(key, defaultValue); - } - - /** - * get config - * @param key - * @param defaultValue - * @return - */ - public boolean getConfig(String key, boolean defaultValue) { - return Boolean.valueOf(getConfig(key, String.valueOf(defaultValue))); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public int getConfig(String key, int defaultValue) { - return Integer.valueOf(getConfig(key, String.valueOf(defaultValue))); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public long getConfig(String key, long defaultValue) { - return Long.valueOf(getConfig(key, String.valueOf(defaultValue))); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public double getConfig(String key, double defaultValue) { - return Double.valueOf(getConfig(key, String.valueOf(defaultValue))); - } - - /** - * @param key - * @param defaultValue - * @return - */ - public float getConfig(String key, float defaultValue) { - return Float.valueOf(getConfig(key, String.valueOf(defaultValue))); - } + private Set baseCols = new HashSet<>(); /** * @return the projDir @@ -150,13 +62,6 @@ public class CodeGenBaseTool { return projDir; } - /** - * @return the groupId - */ - public String getGroupId() { - return groupId; - } - /** * @return the groupId */ @@ -193,63 +98,6 @@ public class CodeGenBaseTool { } } - /** - * init config - */ - @PostConstruct - void init() { - // disable cache - log.info("Disable FreeMarker Cache In Dev Mode."); - fmCfg.getConfiguration().setTemplateUpdateDelayMilliseconds(0); - if (dataSource != null) { - jdbcTpl = new JdbcTemplate(dataSource, true); - } - - try { - log.info("Parse Group ID From [{}/pom.xml].", projDir); - Element root = DocumentBuilderFactory.newInstance() - .newDocumentBuilder() - .parse(new File(projDir, "pom.xml")) - .getDocumentElement(); - root.normalize(); - groupId = root.getElementsByTagName("groupId").item(0).getTextContent().trim(); - log.info("Group ID [{}] Found.", groupId); - } - catch (Exception e) { - throw new IllegalStateException( - "Parse [groupId] From Maven POM File [" + projDir + "/pom.xml] Error Caused", e); - } - - InputStream cfgIns = CodeGenBaseTool.class - .getResourceAsStream("/codegen/config.properties"); - if (cfgIns != null) { - try { - config.load(cfgIns); - log.info("Code Gen Config [{}] Found.", config); - } - catch (IOException e) { - throw new IllegalStateException( - "Load Code Gen Config Error Caused", e); - } - finally { - IOUtils.closeQuietly(cfgIns); - } - } - - baseCols.add("id"); - String baseColsProp = config.getProperty("base.cols"); - if (StringUtils.isNotBlank(baseColsProp)) { - log.info("Code Gen Base Cols [{}] Found.", baseColsProp); - baseCols.addAll(Arrays.asList( - org.springframework.util.StringUtils - .tokenizeToStringArray( - baseColsProp, CONFIG_LOCATION_DELIMITERS, true, true))); - } - log.info("Code Gen Base Cols [{}] Result.", baseCols); - pkg = config.getProperty("base.package", groupId); - log.info("Code Gen Package [{}].", pkg); - } - /** * list all model generated * @return @@ -270,7 +118,7 @@ public class CodeGenBaseTool { FileInputStream fin = null; try { fin = new FileInputStream(file); - mapData = JSON.parseObject(IOUtils.toString(fin, CharEncoding.UTF_8)); + mapData = JSON.parseObject(IOUtils.toString(fin, StandardCharsets.UTF_8)); } catch (IOException e) { log.info("Parse JSON File [{}] ERROR Caused.", file.getName()); @@ -284,7 +132,7 @@ public class CodeGenBaseTool { // backup data file IOUtils.copy(fin, new FileWriter(new File(projDir, backupFileName)), - CharEncoding.UTF_8); + StandardCharsets.UTF_8); } } catch (IOException e1) { @@ -296,8 +144,8 @@ public class CodeGenBaseTool { } } if (mapData == null) { - mapData = new HashMap(); - mapData.put("items", new LinkedList()); + mapData = new HashMap<>(); + mapData.put("items", new LinkedList<>()); } return mapData; } @@ -309,7 +157,7 @@ public class CodeGenBaseTool { FileUtils.write(file, JSON.toJSONStringWithDateFormat(storeData, "yyyy-MM-dd HH:mm:ss", SerializerFeature.PrettyFormat), - CharEncoding.UTF_8); + StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Write Data To File [" + file.getAbsolutePath() + "] ERROR Caused.", e); @@ -371,7 +219,7 @@ public class CodeGenBaseTool { execSQL("drop table " + item.get("table")); } catch (Exception e) { - log.info("Drop Table Error Caused.", e); + log.info("Drop table error caused.", e); } } it.remove(); @@ -392,7 +240,7 @@ public class CodeGenBaseTool { return FreeMarkerTemplateUtils.processTemplateIntoString( new Template(ftl, new InputStreamReader( CodeGenBaseTool.class.getResourceAsStream(ftl), - CharEncoding.UTF_8), fmCfg.getConfiguration()), model); + StandardCharsets.UTF_8), fmCfg.getConfiguration()), model); } catch (Exception e) { throw new RuntimeException("Code Generate Render ERROR, [" + e.getMessage() + "].", e); @@ -410,9 +258,6 @@ public class CodeGenBaseTool { try { DatabaseMetaData md = conn.getMetaData(); rs = md.getTables(null, null, "%", new String[] {"TABLE"}); - String tablePrefix = - config.getProperty("table.prefix", "") - .toLowerCase(); while (rs.next()) { Map mapTable = new HashMap(); String table = rs.getString(3).toLowerCase(); @@ -422,7 +267,7 @@ public class CodeGenBaseTool { String[] tableNameParts = null; if (StringUtils.isNotBlank(tablePrefix) && table.startsWith(tablePrefix + "_")) { - log.info("Table Prefix [{}] Found, Trim.", tablePrefix); + log.info("Table prefix [{}] found, trim.", tablePrefix); tableNameParts = table.substring(tablePrefix.length() + 1) .split("_"); @@ -451,7 +296,7 @@ public class CodeGenBaseTool { } }); } - return new LinkedList>(); + return Collections.emptyList(); } // -- @@ -468,9 +313,7 @@ public class CodeGenBaseTool { col.put("isKey", keys.contains(colName)); col.put("isIndex", indexes.contains(colName)); col.put("col", colName); - col.put("name", - StringUtils.uncapitalize( - WordUtils.convertToCamelCase(colName, "_"))); + col.put("name", WordUtils.toCamel(colName)); int size = rs.getInt("COLUMN_SIZE"); col.put("size", size); String type = rs.getString("TYPE_NAME").toLowerCase(); diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenerator.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenerator.java index ac685f3..ed516d6 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenerator.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/CodeGenerator.java @@ -1,10 +1,10 @@ package me.chyxion.tigon.codegen.service; import java.io.File; -import java.util.List; import java.util.Map; +import java.util.List; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.CharEncoding; +import java.nio.charset.StandardCharsets; import me.chyxion.tigon.codegen.CodeGenCustomizer; import me.chyxion.tigon.codegen.model.CodeGenArgs; import org.springframework.beans.factory.annotation.Autowired; @@ -57,7 +57,7 @@ public abstract class CodeGenerator { // write result FileUtils.write(new File(baseTool.getProjDir(), args.getFile()), baseTool.renderFtl(args.getFtl(), args.getModel()), - CharEncoding.UTF_8); + StandardCharsets.UTF_8); return args.getFile(); } catch (Exception e) { diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/CodeGenServiceSupport.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/CodeGenServiceSupport.java index eb96572..3be4273 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/CodeGenServiceSupport.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/CodeGenServiceSupport.java @@ -1,38 +1,42 @@ package me.chyxion.tigon.codegen.service.support; -import me.chyxion.tigon.mybatis.Table; -import me.chyxion.tigon.service.BaseCrudService; -import me.chyxion.tigon.service.BaseService; -import me.chyxion.tigon.service.support.BaseCrudServiceSupport; -import me.chyxion.tigon.util.WordUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; +import java.util.Map; +import java.util.Set; import java.util.Date; +import java.util.List; +import java.util.Arrays; +import java.util.Locale; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.ArrayList; +import java.util.Collection; import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import me.chyxion.tigon.codegen.controller.CodeGenController.GenForm; -import me.chyxion.tigon.codegen.service.CodeGenBaseTool; -import me.chyxion.tigon.codegen.service.CodeGenService; -import me.chyxion.tigon.codegen.service.CodeGenerator; -import me.chyxion.tigon.mybatis.BaseMapper; +import java.text.DateFormat; import me.chyxion.tigon.model.M0; import me.chyxion.tigon.model.M1; import me.chyxion.tigon.model.M2; import me.chyxion.tigon.model.M3; -import me.chyxion.tigon.webmvc.test.ControllerTestTool; +import lombok.extern.slf4j.Slf4j; +import java.lang.reflect.Modifier; +import me.chyxion.tigon.mybatis.Table; +import me.chyxion.tigon.util.WordUtils; +import org.springframework.util.Assert; +import me.chyxion.tigon.mybatis.BaseMapper; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.ClassUtils; +import me.chyxion.tigon.service.BaseService; import org.apache.commons.lang3.StringUtils; +import me.chyxion.tigon.service.BaseCrudService; +import org.springframework.util.ReflectionUtils; +import me.chyxion.tigon.codegen.service.CodeGenerator; +import me.chyxion.tigon.webmvc.test.ControllerTestTool; +import me.chyxion.tigon.codegen.service.CodeGenService; +import me.chyxion.tigon.codegen.service.CodeGenBaseTool; +import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired; +import me.chyxion.tigon.service.support.BaseCrudServiceSupport; +import me.chyxion.tigon.codegen.controller.CodeGenController.GenForm; /** * @version 0.0.1 @@ -41,8 +45,8 @@ import org.springframework.beans.factory.annotation.Autowired; * chyxion@163.com
* Oct 6, 2014 1:10:02 PM */ +@Slf4j public class CodeGenServiceSupport implements CodeGenService { - private static final Logger log = LoggerFactory.getLogger(CodeGenServiceSupport.class); private static final Map TYPE_PACKAGES = new HashMap() { private static final long serialVersionUID = 1L; { @@ -54,6 +58,15 @@ public class CodeGenServiceSupport implements CodeGenService { private CodeGenBaseTool baseTool; @Autowired private List codeGen; + @Value("${codegen.mapper.cache-enabled:false}") + private boolean cacheEnabled; + + @Value("${codegen.model.super-class.name:}") + private String modelSuperClassName; + @Value("${codegen.model.super-class.import-name:}") + private String modelSuperClassImportName; + @Value("${codegen.model.super-class.import-required:true}") + private boolean modelSuperClassImportRequired; /** * {@inheritDoc} @@ -88,79 +101,101 @@ public class CodeGenServiceSupport implements CodeGenService { fmDataModel.put("table", table.toLowerCase()); fmDataModel.put("notNull", false); fmDataModel.put("notBlank", false); - fmDataModel.put("cacheEnabled", baseTool.getConfig("cache.enabled", false)); + fmDataModel.put("cacheEnabled", cacheEnabled); fmDataModel.put("useGeneratedKeys", false); // collect col names String idType = null; - List colNames = new ArrayList(columns.size()); - for (Map col : (List>) columns) { + final List colNames = new ArrayList(columns.size()); + for (final Map col : (List>) columns) { String colName = ((String) col.get("col")).toLowerCase(); colNames.add(colName); if (M0.ID.equals(colName)) { - String javaType = (String) col.get("javaType"); - if (ArrayUtils.contains( - new String[] {"int", "long", "boolean", "double", "byte"}, - javaType)) { - javaType = StringUtils.capitalize(javaType); - } - idType = javaType; + String javaType = (String) col.get("javaType"); + if (ArrayUtils.contains( + new String[] {"int", "long", "boolean", "double", "byte"}, + javaType)) { + javaType = "int".equals(javaType) ? + Integer.class.getSimpleName() : + StringUtils.capitalize(javaType); } + idType = javaType; + } } - String baseModelName = null; - String baseModelFullName = null; - Collection baseCols = null; - if (colNames.containsAll(new M3().cols())) { + + final String baseModelName; + final String baseModelFullName; + final Collection baseCols; + + // custom super class + if (StringUtils.isNotBlank(modelSuperClassName)) { + Assert.state(StringUtils.isNotBlank(modelSuperClassImportName), + "config 'codegen.model.super-class.import-name' required"); + baseModelName = modelSuperClassName; + baseModelFullName = modelSuperClassImportRequired ? + modelSuperClassImportName : null; + + try { + baseCols = new HashSet<>(); + ReflectionUtils.doWithFields(ClassUtils.getClass(modelSuperClassImportName), field -> { + log.info("Super model field [{}] found.", field); + final int modifiers = field.getModifiers(); + if (!Modifier.isTransient(modifiers) && !Modifier.isStatic(modifiers)) { + final String fieldName = field.getName(); + log.info("Add super model filed [{}] to base cols.", fieldName); + baseCols.add(WordUtils.convertCamelCase(fieldName, "_").toLowerCase()); + } + }); + } + catch (final ClassNotFoundException e) { + throw new IllegalStateException( + "No model super class [" + modelSuperClassImportName + "] found", e); + } + log.info("Base cols [{}] extracted.", baseCols); + } + else if (colNames.containsAll(new M3().cols())) { baseModelName = M3.class.getSimpleName() + "<" + idType + ", " + idType + ">"; baseModelFullName = M3.class.getName(); baseCols = new M3().cols(); + log.info("Base cols [{}] read from M3.", baseCols); } else if (colNames.containsAll(new M2().cols())) { baseModelName = M2.class.getSimpleName() + "<" + idType + ">"; baseModelFullName = M2.class.getName(); baseCols = new M2().cols(); + log.info("Base cols [{}] read from M2.", baseCols); } else if (colNames.containsAll(new M1().cols())) { baseModelName = M1.class.getSimpleName() + "<" + idType + ">"; baseModelFullName = M1.class.getName(); baseCols = new M1().cols(); + log.info("Base cols [{}] read from M1.", baseCols); } else { baseModelName = M0.class.getSimpleName(); baseModelFullName = M0.class.getName(); baseCols = new M0().cols(); - } - // custom config - String cfgBaseModelName = baseTool.getConfig("super.base.model.name"); - if (StringUtils.isNotBlank(cfgBaseModelName)) { - baseCols = baseTool.getBaseCols(); + log.info("Base cols [{}] read from M0.", baseCols); } - String cfgBaseModelFullName = - baseTool.getConfig("super.base.model.full.name"); - - fmDataModel.put("baseModelName", - baseTool.getConfig("super.base.model.name", baseModelName)); - - fmDataModel.put("baseModelFullName", - "NONE".equalsIgnoreCase(cfgBaseModelFullName) ? null : - StringUtils.isNotBlank(cfgBaseModelFullName) ? - cfgBaseModelFullName : baseModelFullName); + fmDataModel.put("baseModelFullName", baseModelFullName); + fmDataModel.put("baseModelName", baseModelName); fmDataModel.put("tableAnnotationClassName", Table.class.getName()); fmDataModel.put("tableAnnotationName", Table.class.getSimpleName()); - Set imports = new HashSet(); - List> colsWithoutBase = + final Set imports = new HashSet<>(); + final List> colsWithoutBase = (List>) columns; - Iterator> colIt = + final Iterator> colIt = colsWithoutBase.iterator(); while (colIt.hasNext()) { Map col = colIt.next(); // col name - String colName = ((String) col.get("col")).toLowerCase(); + final String colName = ((String) col.get("col")).toLowerCase(); + log.info("Process model col [{}].", colName); if (!baseCols.contains(colName)) { // prop name String propName = (String) col.get("name"); @@ -175,13 +210,14 @@ public class CodeGenServiceSupport implements CodeGenService { } } // imports - String p = TYPE_PACKAGES.get(col.get("javaType")); - if (StringUtils.isNotBlank(p)) { - imports.add(p); + final String imp = TYPE_PACKAGES.get(col.get("javaType")); + if (StringUtils.isNotBlank(imp)) { + imports.add(imp); } } // remove base col else { + log.info("Remove base col [{}].", colName); colIt.remove(); } } @@ -210,17 +246,10 @@ public class CodeGenServiceSupport implements CodeGenService { fmDataModel.put("baseServiceSupportName", BaseCrudServiceSupport.class.getSimpleName()); fmDataModel.put("baseServiceSupportFullName", BaseCrudServiceSupport.class.getName()); - // model - // // mapper fmDataModel.put("baseMapperName", BaseMapper.class.getSimpleName()); fmDataModel.put("baseMapperFullName", BaseMapper.class.getName()); -// fmDataModel.put("mockMapperName", MockMapper.class.getSimpleName()); -// fmDataModel.put("mockMapperFullName", MockMapper.class.getName()); - // fmDataModel.put("mockName", Mock.class.getSimpleName()); - // fmDataModel.put("mockFullName", Mock.class.getName()); - fmDataModel.put("ctrlrTestToolName", ControllerTestTool.class.getSimpleName()); fmDataModel.put("ctrlrTestToolFullName", ControllerTestTool.class.getName()); // Object Doc diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/MapperXmlCodeGen.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/MapperXmlCodeGen.java index 3f80037..6240931 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/MapperXmlCodeGen.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/MapperXmlCodeGen.java @@ -1,7 +1,6 @@ package me.chyxion.tigon.codegen.service.support; import java.util.Map; -import org.apache.commons.lang3.StringUtils; import me.chyxion.tigon.codegen.model.CodeGenArgs; /** @@ -19,17 +18,11 @@ public class MapperXmlCodeGen extends MapperCodeGen { @Override public String process(Map dataModel, String module, String model) { - StringBuilder sbFilePath = new StringBuilder(resourcesDir) - .append("mybatis/mappers/"); - if (StringUtils.isNotBlank(module)) { - sbFilePath.append(module).append("/"); - } - sbFilePath.append(dataModel.get("minusJoinedModelName")).append("-mapper.xml"); - return render(new CodeGenArgs( - CodeGenArgs.TARGET_MAPPER_XML, - "/codegen/mapper-xml.ftl", - dataModel, - sbFilePath.toString())); + CodeGenArgs.TARGET_MAPPER_XML, + "/codegen/mapper-xml.ftl", + dataModel, + codeDir + dataModel.get("pkgDir") + + "/mapper/" + model + "Mapper.xml")); } } diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/TableCodeGen.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/TableCodeGen.java index e07fa78..0822d33 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/TableCodeGen.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/service/support/TableCodeGen.java @@ -4,7 +4,6 @@ import java.io.File; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.core.Ordered; import org.apache.commons.lang3.StringUtils; import org.springframework.core.annotation.Order; import me.chyxion.tigon.codegen.model.CodeGenArgs; @@ -17,7 +16,7 @@ import me.chyxion.tigon.codegen.service.CodeGenerator; * chyxion@163.com
* Oct 7, 2014 12:23:13 PM */ -@Order(Ordered.LOWEST_PRECEDENCE) +@Order public class TableCodeGen extends CodeGenerator { private static final Logger log = LoggerFactory.getLogger(TableCodeGen.class); @@ -35,7 +34,7 @@ public class TableCodeGen extends CodeGenerator { @Override public String process(Map dataModel, String module, String model) { String table = (String) dataModel.get("table"); - log.info("Process Generate Table [{}] SQL File.", table); + log.info("Process generate table [{}] SQL file.", table); StringBuilder filePath = new StringBuilder(resourcesDir) .append("db/"); if (StringUtils.isNotBlank(module)) { @@ -51,21 +50,21 @@ public class TableCodeGen extends CodeGenerator { if (!Boolean.FALSE.equals(dataModel.get("createTable"))) { // ignore drop table error try { - log.info("Execute Drop Table [{}].", table); + log.info("Execute drop table [{}].", table); baseTool.execSQL("drop table " + table); } catch (Exception e) { - log.info("Drop Table Failed, Error Message [{}], Ingore.", + log.info("Drop table failed, error message [{}], ignore.", e.getMessage()); } // ignore execute sql error try { - log.info("Execut Create Table SQL File [{}].", filePath); + log.info("Execute create table SQL file [{}].", filePath); baseTool.execSQL(new File(baseTool.getProjDir(), filePath .toString())); } catch (Exception e) { - log.warn("Database Create Table Error, Ingore.", e); + log.warn("Database create table error, ignore.", e); } } return filePath.toString(); diff --git a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/utils/DbTool.java b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/util/DbTool.java similarity index 99% rename from tigon-codegen/src/main/java/me/chyxion/tigon/codegen/utils/DbTool.java rename to tigon-codegen/src/main/java/me/chyxion/tigon/codegen/util/DbTool.java index 2e0b75d..daef2f4 100644 --- a/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/utils/DbTool.java +++ b/tigon-codegen/src/main/java/me/chyxion/tigon/codegen/util/DbTool.java @@ -1,4 +1,4 @@ -package me.chyxion.tigon.codegen.utils; +package me.chyxion.tigon.codegen.util; import java.io.IOException; import java.io.LineNumberReader; diff --git a/tigon-codegen/src/main/resources/codegen/model.ftl b/tigon-codegen/src/main/resources/codegen/model.ftl index eac791f..6f23be2 100644 --- a/tigon-codegen/src/main/resources/codegen/model.ftl +++ b/tigon-codegen/src/main/resources/codegen/model.ftl @@ -3,6 +3,7 @@ package ${pkg}.model; import lombok.Getter; import lombok.Setter; +import lombok.experimental.FieldNameConstants; import ${tableAnnotationClassName}; <#if baseModelFullName?has_content> import ${baseModelFullName}; @@ -15,15 +16,16 @@ ${objDoc} @Getter @Setter @${tableAnnotationName}("${table}") +@FieldNameConstants(prefix = "") public class ${ModelName} extends ${baseModelName} { private static final long serialVersionUID = 1L; - +<#-- // Column Names <#list cols as prop> public static final String ${prop.col?upper_case} = "${prop.col}"; +--> - // Properties <#list cols as prop> private ${prop.javaType} ${prop.name}; diff --git a/tigon-codegen/src/main/resources/spring/servlet-spring-tigon-codegen.xml b/tigon-codegen/src/main/resources/spring/servlet-spring-tigon-codegen.xml deleted file mode 100644 index b63d05b..0000000 --- a/tigon-codegen/src/main/resources/spring/servlet-spring-tigon-codegen.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/tigon-codegen/src/main/resources/spring/spring-tigon-codegen.xml b/tigon-codegen/src/main/resources/spring/spring-tigon-codegen.xml index 0d2a029..219291b 100644 --- a/tigon-codegen/src/main/resources/spring/spring-tigon-codegen.xml +++ b/tigon-codegen/src/main/resources/spring/spring-tigon-codegen.xml @@ -1,13 +1,10 @@ + http://www.springframework.org/schema/beans/spring-beans.xsd"> - @@ -23,4 +20,40 @@ + + + + + ${tigon.codegen.freemarker.cache.expire:36000} + utf-8 + en_US + yyyy-MM-dd + HH:mm:ss + yyyy-MM-dd HH:mm:ss + + # + + + + + + + + + + diff --git a/tigon-codegen/src/main/resources/webapp/assets/js/views/CodeGen.js b/tigon-codegen/src/main/resources/webapp/assets/js/views/CodeGen.js index e1e6d09..41f339e 100644 --- a/tigon-codegen/src/main/resources/webapp/assets/js/views/CodeGen.js +++ b/tigon-codegen/src/main/resources/webapp/assets/js/views/CodeGen.js @@ -86,13 +86,6 @@ Ext.define ('Tigon.views.CodeGen', { form = rc.down('form'); form.getForm().setValues(rec.getData()); form.down('grid').getStore().loadData(rec.get('cols')); - // show demo grid - // var dg = rc.down('container[name=demo_grid]'); - // dg.removeAll(); - // load view - // dg.add(Ext.create('App.views.' + - // (rec.get('module') ? rec.get('module') + '.' : '') + - // rec.get('model') + '.List')); } } } @@ -121,13 +114,6 @@ Ext.define ('Tigon.views.CodeGen', { createTable: false })); form.down('grid').getStore().loadData(rec.get('cols')); - // show demo grid - // var dg = rc.down('container[name=demo_grid]'); - // dg.removeAll(); - // load view - // dg.add(Ext.create('App.views.' + - // (rec.get('module') ? rec.get('module') + '.' : '') + - // rec.get('model') + '.List')); } } } @@ -215,34 +201,30 @@ Ext.define ('Tigon.views.CodeGen', { fieldLabel: 'Options', xtype: 'checkboxgroup', defaults: { - checked: true, + checked: false, xtype: 'checkbox', inputValue: true }, columns: 3, items: [{ boxLabel: 'Gen controller', + checked: components.indexOf('controller') > -1, name: 'genController' }, { boxLabel: 'Gen service', name: 'genService' }, { boxLabel: 'Gen mapper', + checked: components.indexOf('mapper') > -1, name: 'genMapper' }, { boxLabel: 'Gen model', + checked: components.indexOf('model') > -1, name: 'genModel' - }, { - boxLabel: 'Gen table', - name: 'genTable' }, { boxLabel: 'Gen form', - checked: false, + checked: components.indexOf('form') > -1, name: 'genView' - }, { - boxLabel: 'Create table', - checked: false, - name: 'createTable' }] }, { xtype: 'fieldcontainer', diff --git a/tigon-codegen/src/main/resources/webapp/views/codegen.ftl b/tigon-codegen/src/main/resources/webapp/views/codegen.ftl index b51863e..5325343 100644 --- a/tigon-codegen/src/main/resources/webapp/views/codegen.ftl +++ b/tigon-codegen/src/main/resources/webapp/views/codegen.ftl @@ -16,7 +16,7 @@ items: [{ xtype: 'box', region: 'north', - html: '

Super Super Code!

' + html: '

Tigon Code Gen!

' }, Ext.create('Tigon.views.CodeGen', { region: 'center' @@ -26,6 +26,7 @@ Ext.create('Tigon.views.ThemesBar').show(); }); var pkg = '${pkg}'; + var components = ${components}; Auto Code diff --git a/tigon-freemarker-support/README.md b/tigon-freemarker-support/README.md deleted file mode 100644 index 891a0aa..0000000 --- a/tigon-freemarker-support/README.md +++ /dev/null @@ -1 +0,0 @@ -# tigon-freemarker-support diff --git a/tigon-freemarker-support/pom.xml b/tigon-freemarker-support/pom.xml deleted file mode 100644 index 253ce73..0000000 --- a/tigon-freemarker-support/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - tigon-freemarker-support - jar - Tigon FreeMarker Support - Tigon FreeMarker Support - - - me.chyxion.tigon - tigon - 0.0.1-SNAPSHOT - ../ - - - - - org.freemarker - freemarker - - - org.slf4j - slf4j-api - - - org.springframework - spring-webmvc - - - org.springframework - spring-context-support - - - javax.servlet - javax.servlet-api - provided - - - - org.springframework - spring-test - test - - - junit - junit - test - - - diff --git a/tigon-freemarker-support/src/main/resources/spring/spring-freemarker-support.xml b/tigon-freemarker-support/src/main/resources/spring/spring-freemarker-support.xml deleted file mode 100644 index 07e090e..0000000 --- a/tigon-freemarker-support/src/main/resources/spring/spring-freemarker-support.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - ${freemarker.cache.expire:36000} - utf-8 - en_US - yyyy-MM-dd - HH:mm:ss - yyyy-MM-dd HH:mm:ss - - # - - - - - diff --git a/tigon-freemarker-support/src/test/java/me/chyxion/tigon/freemarker/test/SiteControllerTest.java b/tigon-freemarker-support/src/test/java/me/chyxion/tigon/freemarker/test/SiteControllerTest.java deleted file mode 100644 index 6b834da..0000000 --- a/tigon-freemarker-support/src/test/java/me/chyxion/tigon/freemarker/test/SiteControllerTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package me.chyxion.tigon.freemarker.test; - -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Jan 27, 2015 3:27:08 PM - */ -@WebAppConfiguration -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:spring/controller-test.xml") -public class SiteControllerTest { - -} diff --git a/tigon-freemarker-support/src/test/resources/spring/config.properties b/tigon-freemarker-support/src/test/resources/spring/config.properties deleted file mode 100644 index 76dbbbc..0000000 --- a/tigon-freemarker-support/src/test/resources/spring/config.properties +++ /dev/null @@ -1 +0,0 @@ -# Config Dev diff --git a/tigon-freemarker-support/src/test/resources/spring/controller-test.xml b/tigon-freemarker-support/src/test/resources/spring/controller-test.xml deleted file mode 100644 index 6e31ca4..0000000 --- a/tigon-freemarker-support/src/test/resources/spring/controller-test.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - diff --git a/tigon-jsp-support/README.md b/tigon-jsp-support/README.md deleted file mode 100644 index 1abc1f1..0000000 --- a/tigon-jsp-support/README.md +++ /dev/null @@ -1 +0,0 @@ -# tigon-jsp-support diff --git a/tigon-jsp-support/pom.xml b/tigon-jsp-support/pom.xml deleted file mode 100644 index 05e97b1..0000000 --- a/tigon-jsp-support/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - 4.0.0 - tigon-jsp-support - jar - Tigon JSP Support - Tigon JSP Support - - - me.chyxion.tigon - tigon - 0.0.1-SNAPSHOT - ../ - - - - - org.apache.commons - commons-lang3 - - - javax.servlet - javax.servlet-api - provided - - - org.slf4j - slf4j-api - - - org.springframework - spring-webmvc - - - org.springframework - spring-test - provided - - - junit - junit - provided - - - diff --git a/tigon-jsp-support/src/main/java/me/chyxion/tigon/jsp/InternalResourceViewResolverExt.java b/tigon-jsp-support/src/main/java/me/chyxion/tigon/jsp/InternalResourceViewResolverExt.java deleted file mode 100644 index 6cb2cab..0000000 --- a/tigon-jsp-support/src/main/java/me/chyxion/tigon/jsp/InternalResourceViewResolverExt.java +++ /dev/null @@ -1,59 +0,0 @@ -package me.chyxion.tigon.jsp; - -import java.util.Locale; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.servlet.ServletContext; -import java.net.MalformedURLException; -import org.springframework.web.servlet.View; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.servlet.view.InternalResourceViewResolver; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Dec 5, 2014 2:33:18 PM - */ -public class InternalResourceViewResolverExt - extends InternalResourceViewResolver { - private static final Logger log = - LoggerFactory.getLogger(InternalResourceViewResolverExt.class); - - @Autowired - private ServletContext sc; - - /** - * {@inheritDoc} - */ - @Override - public View resolveViewName(String viewName, Locale locale) - throws Exception { - return super.resolveViewName(viewName(viewName), locale); - } - - /** - * {@inheritDoc} - */ - @Override - protected boolean canHandle(String viewName, Locale locale) { - try { - // avoid 404 - return sc.getResource(getPrefix() + viewName(viewName) + getSuffix()) != null; - } - catch (MalformedURLException e) { - log.warn("InternalResourceViewResolverExt#canHandle Eorror Caused.", e); - return false; - } - } - - /** - * Process View Name - * @param name raw name - * @return jsp file name - */ - private String viewName(String name) { - return name.replaceAll("(?i)(^\\s*jsp\\:)|(\\.jsp\\s*$)", ""); - } -} diff --git a/tigon-jsp-support/src/main/resources/spring/spring-jsp-support.xml b/tigon-jsp-support/src/main/resources/spring/spring-jsp-support.xml deleted file mode 100644 index af5da71..0000000 --- a/tigon-jsp-support/src/main/resources/spring/spring-jsp-support.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - diff --git a/tigon-jsp-support/src/test/java/me/chyxion/tigon/webmvc/test/SiteControllerTest.java b/tigon-jsp-support/src/test/java/me/chyxion/tigon/webmvc/test/SiteControllerTest.java deleted file mode 100644 index 3c6c751..0000000 --- a/tigon-jsp-support/src/test/java/me/chyxion/tigon/webmvc/test/SiteControllerTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package me.chyxion.tigon.webmvc.test; - -import org.junit.runner.RunWith; -// import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Jan 27, 2015 3:27:08 PM - */ -@WebAppConfiguration -@RunWith(SpringJUnit4ClassRunner.class) -// @ContextConfiguration("classpath:spring/controller-test.xml") -public class SiteControllerTest { - -} diff --git a/tigon-model/pom.xml b/tigon-model/pom.xml index bb5ed05..ba7815e 100644 --- a/tigon-model/pom.xml +++ b/tigon-model/pom.xml @@ -21,10 +21,12 @@ org.apache.commons commons-lang3 + 3.7 com.alibaba fastjson + 1.2.47 org.springframework @@ -39,6 +41,13 @@ commons-beanutils commons-beanutils + 1.9.3 + + + commons-logging + commons-logging + + org.slf4j @@ -46,7 +55,7 @@ - org.hibernate + org.hibernate.validator hibernate-validator diff --git a/tigon-model/src/main/java/me/chyxion/tigon/form/BaseForm.java b/tigon-model/src/main/java/me/chyxion/tigon/form/BaseForm.java index c395292..8b3a896 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/form/BaseForm.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/form/BaseForm.java @@ -33,14 +33,14 @@ public class BaseForm implements BaseFormApi { */ @Override public T copy(Class clazz, boolean convert) { - log.debug("Copy Form [{}] To Class [{}].", this, clazz); + log.debug("Copy form [{}] to class [{}].", this, clazz); T obj = null; try { obj = clazz.newInstance(); } catch (Exception e) { throw new IllegalStateException( - "Create [" + clazz + "] Object Error Caused", e); + "Create [" + clazz + "] object error caused", e); } return copy(obj, convert); } @@ -65,18 +65,18 @@ public class BaseForm implements BaseFormApi { public T copy(T obj, boolean convert) { try { if (convert) { - log.debug("Copy Form [{}] To [{}] With Type Converting.", this, obj); + log.debug("Copy form [{}] to [{}] with type converting.", this, obj); org.apache.commons.beanutils.BeanUtils.copyProperties(obj, this); } else { - log.debug("Copy Form [{}] To [{}].", this, obj); + log.debug("Copy form [{}] to [{}].", this, obj); BeanUtils.copyProperties(this, obj); } return obj; } catch (Exception e) { throw new IllegalStateException( - "Copy [" + this + "] Error Caused", e); + "Copy [" + this + "] error caused", e); } } diff --git a/tigon-model/src/main/java/me/chyxion/tigon/form/FC2.java b/tigon-model/src/main/java/me/chyxion/tigon/form/FC2.java index 9586148..1e6ab09 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/form/FC2.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/form/FC2.java @@ -10,11 +10,11 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank; * chyxion@163.com
* Oct 8, 2016 6:26:19 PM */ -@Getter public class FC2 extends FC1 { private static final long serialVersionUID = 1L; private transient boolean __lock = true; + @Getter @NotNullOrBlank protected CreatorId createdBy; diff --git a/tigon-model/src/main/java/me/chyxion/tigon/form/FU1.java b/tigon-model/src/main/java/me/chyxion/tigon/form/FU1.java index 94d2783..486ded5 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/form/FU1.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/form/FU1.java @@ -2,7 +2,6 @@ package me.chyxion.tigon.form; import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotNull; import me.chyxion.tigon.format.annotation.EmptyToNull; /** @@ -18,8 +17,7 @@ public class FU1 extends FU0 { private static final long serialVersionUID = 1L; - @NotNull - protected Boolean enabled; + protected boolean enabled = true; @EmptyToNull protected String note; } diff --git a/tigon-model/src/main/java/me/chyxion/tigon/form/FU2.java b/tigon-model/src/main/java/me/chyxion/tigon/form/FU2.java index f63beab..3ff5f50 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/form/FU2.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/form/FU2.java @@ -1,7 +1,6 @@ package me.chyxion.tigon.form; import lombok.Getter; -import lombok.Setter; import me.chyxion.tigon.validation.annotation.NotNullOrBlank; /** @@ -11,12 +10,12 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank; * chyxion@163.com
* Oct 8, 2016 6:26:36 PM */ -@Getter public class FU2 extends FU1 { private static final long serialVersionUID = 1L; private transient boolean __lock = true; + @Getter @NotNullOrBlank private EditorId updatedBy; diff --git a/tigon-model/src/main/java/me/chyxion/tigon/form/ListForm.java b/tigon-model/src/main/java/me/chyxion/tigon/form/ListForm.java new file mode 100644 index 0000000..4766139 --- /dev/null +++ b/tigon-model/src/main/java/me/chyxion/tigon/form/ListForm.java @@ -0,0 +1,33 @@ +package me.chyxion.tigon.form; + +import lombok.Getter; +import lombok.Setter; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import me.chyxion.tigon.format.annotation.Trim; +import me.chyxion.tigon.format.annotation.EmptyToNull; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Jun 25, 2018 22:56:52 + */ +@Getter +@Setter +public class ListForm extends BaseForm { + @Min(0) + private int start; + @Min(1) + @Max(2048) + private int limit = 16; + private String search; + @Trim + @EmptyToNull + private String criteria; + @Trim + @EmptyToNull + private String filters; + @Trim + @EmptyToNull + private String orders; +} diff --git a/tigon-model/src/main/java/me/chyxion/tigon/mybatis/Search.java b/tigon-model/src/main/java/me/chyxion/tigon/mybatis/Search.java index 6f838da..fadd7c0 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/mybatis/Search.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/mybatis/Search.java @@ -198,7 +198,37 @@ public class Search implements Serializable { * @return this */ public Search like(String col, String value, boolean wrapValue) { - return like(col, wrapValue ? "%" + value + "%" : value); + return wrapValue ? contains(col, value) : like(col, value); + } + + /** + * col contains value + * @param col col name + * @param value value + * @return this + */ + public Search contains(final String col, final String value) { + return like(col, "%" + value + "%"); + } + + /** + * col starts with value + * @param col col name + * @param value value + * @return this + */ + public Search startsWith(final String col, final String value) { + return like(col, value + "%"); + } + + /** + * col ends with value + * @param col col name + * @param value value + * @return this + */ + public Search endsWith(final String col, final String value) { + return like(col, "%" + value); } /** diff --git a/tigon-model/src/main/java/me/chyxion/tigon/mybatis/SearchProcessArgs.java b/tigon-model/src/main/java/me/chyxion/tigon/mybatis/SearchProcessArgs.java index 6bfca55..354fb51 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/mybatis/SearchProcessArgs.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/mybatis/SearchProcessArgs.java @@ -5,6 +5,7 @@ import lombok.Setter; import lombok.NonNull; import java.util.List; import lombok.RequiredArgsConstructor; +import me.chyxion.tigon.util.WordUtils; import org.apache.commons.lang3.StringUtils; /** @@ -25,18 +26,23 @@ public class SearchProcessArgs { @Setter private boolean hasPrevOrCol; - public SearchProcessArgs append(String sqlFragment) { + public SearchProcessArgs append(final String sqlFragment) { result.add(new SqlFragment(sqlFragment)); return this; } - public SearchProcessArgs addValue(Object value) { + public SearchProcessArgs addValue(final Object value) { result.add(value); return this; } public String getCol() { String col = criterion.getCol(); + if (col.matches("^\\w+$")) { + col = WordUtils.convertCamelCase( + col, "_").toLowerCase(); + } + return StringUtils.isNotBlank(table) && !col.contains(".") ? table + "." + col : col; diff --git a/tigon-model/src/main/java/me/chyxion/tigon/util/WordUtils.java b/tigon-model/src/main/java/me/chyxion/tigon/util/WordUtils.java index c7a398d..8b8c2d4 100644 --- a/tigon-model/src/main/java/me/chyxion/tigon/util/WordUtils.java +++ b/tigon-model/src/main/java/me/chyxion/tigon/util/WordUtils.java @@ -32,18 +32,12 @@ public class WordUtils { public static String[] splitToWords(String str) { return StringUtils.isNotBlank(str) ? // JSONObject - JSON Object - str.split(new StringBuilder("(?<=[A-Z])(?=[A-Z][a-z])") + // 99Rose - 99 Rose + str.split(new StringBuilder("(?<=[0-9A-Z])(?=[A-Z][a-z])") // MySQL - My SQL .append("|(?<=[a-z])(?=[A-Z])") - // 99Roses -> 99 Roses - .append("|(?<=[^a-zA-Z])(?=[A-Z])") - // .append("|(?<=[^A-Z])(?=[A-Z])") - // 5s - 5 s - // .append("|(?<=[^a-zA-Z])(?=[a-z])") - // A3 - A 3 | a3 - a 3 - // .append("|(?<=[A-Za-z])(?=[^A-Za-z])") - .toString()) : - new String[]{}; + .toString()) : + new String[0]; } /** @@ -96,4 +90,13 @@ public class WordUtils { } return strRtn; } + + /** + * convert underline word to + * @param word + * @return + */ + public static String toCamel(final String word) { + return StringUtils.uncapitalize(convertToCamelCase(word.toLowerCase(), "_")); + } } diff --git a/tigon-model/src/test/java/me/chyxion/tigon/test/WordUtilsTest.java b/tigon-model/src/test/java/me/chyxion/tigon/test/WordUtilsTest.java index 8edc85a..d880980 100644 --- a/tigon-model/src/test/java/me/chyxion/tigon/test/WordUtilsTest.java +++ b/tigon-model/src/test/java/me/chyxion/tigon/test/WordUtilsTest.java @@ -17,8 +17,11 @@ public class WordUtilsTest { System.err.println(WordUtils.convertCamelCase("log4j", "_")); System.err.println(WordUtils.convertCamelCase("log4J", "_")); System.err.println(WordUtils.convertCamelCase("JSONObject", "_")); - System.err.println(WordUtils.convertCamelCase("JSONObject", "_")); System.err.println(WordUtils.convertCamelCase("99Rose", "_")); + System.err.println(WordUtils.convertCamelCase("AAA99Rose", "_")); System.err.println(WordUtils.convertCamelCase("99rose", "_")); + System.err.println(WordUtils.convertCamelCase("Foo.JSONObject", "_")); + + System.err.println("JSONObject".matches("^\\w+$")); } } diff --git a/tigon-mybatis-cache-redis/pom.xml b/tigon-mybatis-cache-redis/pom.xml index 2351f51..de4ae4c 100644 --- a/tigon-mybatis-cache-redis/pom.xml +++ b/tigon-mybatis-cache-redis/pom.xml @@ -24,6 +24,17 @@ org.mybatis mybatis + 3.4.2 + + + commons-codec + commons-codec + 1.10 + + + org.projectlombok + lombok + provided diff --git a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCache.java b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCache.java index f61ada2..80a6290 100644 --- a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCache.java +++ b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCache.java @@ -1,11 +1,12 @@ package me.chyxion.tigon.mybatis.cache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.cache.Cache; +import org.springframework.util.Assert; import java.util.concurrent.locks.ReadWriteLock; +import org.apache.commons.codec.digest.DigestUtils; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; +import org.springframework.data.redis.core.HashOperations; /** * @version 0.0.1 @@ -14,34 +15,30 @@ import org.springframework.data.redis.core.ValueOperations; * chyxion@163.com
* Feb 23, 2016 6:03:39 PM */ +@Slf4j public final class RedisCache implements Cache { - private static final Logger log = - LoggerFactory.getLogger(RedisCache.class); - - private String id; - private RedisTemplate redisTpl; - private ValueOperations valueOp; - private RedisCacheConfig config; + private final String id; + private final RedisTemplate redisTpl; + private final HashOperations hashOp; + private final RedisCacheConfig config; /** * construct cache * @param id cache id */ - public RedisCache(String id) { - if (id == null) { - throw new IllegalArgumentException( - "Cache Instance ID Could Not Be Null"); - } - log.info("Create Redis Cache [{}].", id); + public RedisCache(final String id) { + Assert.hasText(id, "Redis cache instance id could not be null"); + log.info("Create redis cache [{}].", id); this.id = id; config = RedisCacheConfig.getInstance(); redisTpl = config.getRedisTpl(); - valueOp = redisTpl.opsForValue(); + hashOp = redisTpl.opsForHash(); } /** * {@inheritDoc} */ + @Override public String getId() { return id; } @@ -49,43 +46,48 @@ public final class RedisCache implements Cache { /** * {@inheritDoc} */ + @Override public int getSize() { - log.debug("Get Cache [{}] Size.", id); - return redisTpl.keys(prefixedKey("*")).size(); + final Long size = hashOp.size(id); + log.info("Get redis cache [{}] size [{}].", id, size); + return size.intValue(); } /** * {@inheritDoc} */ + @Override public void putObject(final Object key, final Object value) { - log.debug("Put Object Key [{}], Value [{}].", key, value); - valueOp.set(prefixedKey(key), value); + log.debug("Put redis cache [{}] object key [{}], value [{}].", id, key, value); + hashOp.put(id, keyMd5(key), value); } /** * {@inheritDoc} */ + @Override public Object getObject(final Object key) { - Object value = valueOp.get(prefixedKey(key)); - log.debug("Get Object Key [{}], Value [{}].", key, value); + final Object value = hashOp.get(id, keyMd5(key)); + log.debug("Get redis cache object key [{}], value [{}].", key, value); return value; } /** * {@inheritDoc} */ + @Override public Object removeObject(final Object key) { - log.debug("Remove Object Key [{}].", key); - redisTpl.delete(prefixedKey(key)); - return 1; + log.info("Remove redis cache [{}] object key [{}].", id, key); + return hashOp.delete(id, keyMd5(key)); } /** * {@inheritDoc} */ + @Override public void clear() { - log.debug("Clear Cache Key [{}].", id); - redisTpl.delete(redisTpl.keys(prefixedKey("*"))); + log.info("Clear redis cache [{}].", id); + redisTpl.delete(id); } /** @@ -101,7 +103,7 @@ public final class RedisCache implements Cache { */ @Override public String toString() { - return "Redis Cache [" + id + "]"; + return "Redis cache [" + id + "]"; } // -- @@ -112,14 +114,9 @@ public final class RedisCache implements Cache { * @param key cache key * @return prefixed key */ - String prefixedKey(Object key) { - return prefix() + String.valueOf(key); - } - - /** - * @return cache prefix - */ - String prefix() { - return id + ":"; + private String keyMd5(final Object key) { + final String md5Hex = DigestUtils.md5Hex(key instanceof String ? (String) key : String.valueOf(key)); + log.debug("Get redis cache [{}] key [{}] md5 hex [{}].", id, key, md5Hex); + return md5Hex; } } diff --git a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCacheConfig.java b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCacheConfig.java index 0305400..535ee86 100644 --- a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCacheConfig.java +++ b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/RedisCacheConfig.java @@ -2,6 +2,7 @@ package me.chyxion.tigon.mybatis.cache; import javax.annotation.PostConstruct; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Autowired; /** @@ -13,7 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; */ public class RedisCacheConfig { @Autowired - private RedisTemplate redisTpl; + @Qualifier("redisTemplate") + private RedisTemplate redisTpl; private static RedisCacheConfig instance; @PostConstruct @@ -31,14 +33,7 @@ public class RedisCacheConfig { /** * @return the redisTpl */ - public RedisTemplate getRedisTpl() { + public RedisTemplate getRedisTpl() { return redisTpl; } - - /** - * @param redisTpl the redisTpl to set - */ - public void setRedisTpl(RedisTemplate redisTpl) { - this.redisTpl = redisTpl; - } } diff --git a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/support/CacheToolSupport.java b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/support/CacheToolSupport.java index 0b5cc39..78abe40 100644 --- a/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/support/CacheToolSupport.java +++ b/tigon-mybatis-cache-redis/src/main/java/me/chyxion/tigon/mybatis/cache/support/CacheToolSupport.java @@ -1,7 +1,6 @@ package me.chyxion.tigon.mybatis.cache.support; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.cache.Cache; import javax.annotation.PostConstruct; import org.apache.ibatis.session.Configuration; @@ -16,9 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; * chyxion@163.com
* Aug 26, 2015 10:58:58 AM */ +@Slf4j public class CacheToolSupport implements CacheTool { - private static final Logger log = - LoggerFactory.getLogger(CacheToolSupport.class); @Autowired private SqlSessionFactory ssf; @@ -29,13 +27,13 @@ public class CacheToolSupport implements CacheTool { */ @Override public void clearCache(Class mapper) { - log.info("Clear Cache [{}].", mapper); - Cache cache = getCache(mapper); + log.info("Clear mybatis cache [{}].", mapper); + final Cache cache = getCache(mapper); if (cache != null) { cache.clear(); } else { - log.warn("No Cache [{}] Found.", mapper); + log.warn("No mybatis cache [{}] found.", mapper); } } diff --git a/tigon-mybatis/pom.xml b/tigon-mybatis/pom.xml index 3a94f57..5ecfb14 100644 --- a/tigon-mybatis/pom.xml +++ b/tigon-mybatis/pom.xml @@ -26,10 +26,12 @@ org.mybatis mybatis + 3.4.2 org.mybatis mybatis-spring + 1.3.1 org.springframework @@ -60,11 +62,13 @@ com.alibaba druid + 1.0.28 test mysql mysql-connector-java + 5.1.6 test @@ -85,6 +89,7 @@ javax.el javax.el-api + 3.0.0 test diff --git a/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/BaseMapper.java b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/BaseMapper.java index 37c4623..e6afc69 100644 --- a/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/BaseMapper.java +++ b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/BaseMapper.java @@ -6,8 +6,8 @@ import java.util.Collection; import me.chyxion.tigon.model.BaseModel; import org.apache.ibatis.annotations.Param; import javax.validation.constraints.NotNull; -import org.hibernate.validator.constraints.NotBlank; -import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; import org.springframework.validation.annotation.Validated; /** @@ -140,6 +140,13 @@ public interface BaseMapper> { */ int delete(@NotNull @Param(PARAM_SEARCH_KEY) PrimaryKey primaryKey); + /** + * find one by search + * @param search search + * @return true if exists rows + */ + boolean exists(@Param(PARAM_SEARCH_KEY) Search search); + /** * find one by search * @param search search diff --git a/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/ExistsXmlProcessor.java b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/ExistsXmlProcessor.java new file mode 100644 index 0000000..4d00fbe --- /dev/null +++ b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/ExistsXmlProcessor.java @@ -0,0 +1,29 @@ +package me.chyxion.tigon.mybatis; + +import org.w3c.dom.Element; +import org.w3c.dom.Document; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * 14/10/2017 10:43 PM + */ +public class ExistsXmlProcessor extends AbstractOnMissingCreateProcessor { + + /** + * {@inheritDoc} + */ + @Override + protected String missingXPathExpression() { + return "/mapper/select[@id='exists']"; + } + + /** + * {@inheritDoc} + */ + @Override + protected Element elementToAppend(Class> mapperClass, Document doc) { + return appendIncludeEl(doc, + createSelectEl(doc, "exists", "boolean"), "Tigon.exists"); + } +} diff --git a/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/KeyGenInterceptor.java b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/KeyGenInterceptor.java index 237d6f9..b89dedf 100644 --- a/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/KeyGenInterceptor.java +++ b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/KeyGenInterceptor.java @@ -85,13 +85,13 @@ class KeyGenInterceptor implements Interceptor { Object paramObj = boundSql.getParameterObject(); if (paramObj instanceof MapperMethod.ParamMap) { @SuppressWarnings("unchecked") - MapperMethod.ParamMap paramMap = - (MapperMethod.ParamMap) paramObj; + MapperMethod.ParamMap paramMap = + (MapperMethod.ParamMap) paramObj; if (paramMap.containsKey(BaseMapper.PARAM_MODEL_KEY) || paramMap.containsKey(BaseMapper.PARAM_MODELS_KEY)) { KeyGenerator keygen = mappedStatement.getKeyGenerator(); if (keygen.getClass().equals(Jdbc3KeyGenerator.class)) { - log.debug("Replace JDBC3 Key Generator."); + log.info("Replace JDBC3 key generator."); SystemMetaObject.forObject(mappedStatement) .setValue("keyGenerator", new Jdbc3KeyGen(keygen)); diff --git a/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/TigonSqlSessionFactoryBean.java b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/TigonSqlSessionFactoryBean.java index 7975df8..c9503e3 100644 --- a/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/TigonSqlSessionFactoryBean.java +++ b/tigon-mybatis/src/main/java/me/chyxion/tigon/mybatis/TigonSqlSessionFactoryBean.java @@ -46,6 +46,7 @@ public class TigonSqlSessionFactoryBean extends SqlSessionFactoryBean { MAPPER_XML_PROCESSORS.add(new PrimaryKeyXmlProcessor()); MAPPER_XML_PROCESSORS.add(new ColsXmlProcessor()); MAPPER_XML_PROCESSORS.add(new InsertXmlProcessor()); + MAPPER_XML_PROCESSORS.add(new ExistsXmlProcessor()); MAPPER_XML_PROCESSORS.add(new FindXmlProcessor()); MAPPER_XML_PROCESSORS.add(new ListXmlProcessor()); MAPPER_XML_PROCESSORS.add(new CountXmlProcessor()); @@ -126,7 +127,7 @@ public class TigonSqlSessionFactoryBean extends SqlSessionFactoryBean { } @SuppressWarnings("unchecked") - private Class> getMapperClass(String name) { + private Class> getMapperClass(String name) { Class> mapperClassRtn = null; try { Class classFound = ClassUtils.forName(name, diff --git a/tigon-mybatis/src/main/resources/__tigon_mybatis__.xml b/tigon-mybatis/src/main/resources/__tigon_mybatis__.xml index d14ddf4..ee6ab92 100644 --- a/tigon-mybatis/src/main/resources/__tigon_mybatis__.xml +++ b/tigon-mybatis/src/main/resources/__tigon_mybatis__.xml @@ -183,6 +183,18 @@ + + + select + 0, 1, 0) + ]]> + from + + + + + select diff --git a/tigon-props-config/README.md b/tigon-props-config/README.md deleted file mode 100644 index c389510..0000000 --- a/tigon-props-config/README.md +++ /dev/null @@ -1 +0,0 @@ -# tigon-props-config diff --git a/tigon-props-config/pom.xml b/tigon-props-config/pom.xml deleted file mode 100644 index 6ae3051..0000000 --- a/tigon-props-config/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - 4.0.0 - tigon-props-config - jar - Tigon Props Config - - - me.chyxion.tigon - tigon - 0.0.1-SNAPSHOT - ../ - - - - - org.slf4j - slf4j-api - - - org.springframework - spring-context - - - javax.servlet - javax.servlet-api - provided - - - - javax.el - javax.el-api - test - - - org.springframework - spring-test - test - - - junit - junit - test - - - diff --git a/tigon-props-config/src/main/java/me/chyxion/tigon/propsconfig/PropsConfig.java b/tigon-props-config/src/main/java/me/chyxion/tigon/propsconfig/PropsConfig.java deleted file mode 100644 index 8ed0e63..0000000 --- a/tigon-props-config/src/main/java/me/chyxion/tigon/propsconfig/PropsConfig.java +++ /dev/null @@ -1,120 +0,0 @@ -package me.chyxion.tigon.propsconfig; - -import java.io.File; -import org.slf4j.Logger; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.io.FileInputStream; -import org.slf4j.LoggerFactory; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Oct 13, 2015 11:25:55 AM - */ -public class PropsConfig { - private static final Logger log = - LoggerFactory.getLogger(PropsConfig.class); - public static final Properties CONFIG_PROPS = - new Properties(); - static { load(); } - - /** - * get app (container/tomcat) dir - * @return app dir - */ - public static File getAppDir() { - File file = new File( - // classes - PropsConfig.class.getResource("/").getFile()) - // WEB-INF - .getParentFile() - // WebApp - .getParentFile() - // WebApps - .getParentFile() - // App - .getParentFile(); - log.info("Get App Dir [{}].", file.getAbsolutePath()); - return file; - } - - // -- - // private methods - - /** - * load system config - */ - static void load() { - InputStream configIn = null; - String configPath = "/spring/config.properties"; - try { - log.info("Load Classpath Config [{}].", configPath); - configIn = PropsConfig.class - .getResourceAsStream(configPath); - if (configIn != null) { - log.info("Classpath Config [{}] Found.", configPath); - CONFIG_PROPS.load(configIn); - } - else { - log.warn("No Classpath Config [{}] Found.", configPath); - } - } - catch (Exception e) { - log.error("Load Classpath Config [{}] Error Caused.", configPath, e); - } - finally { - if (configIn != null) { - try { - configIn.close(); - } - catch (IOException e) { - log.warn("Config Input Stream Close Eroror Caused."); - } - } - } - File appDir = getAppDir(); - // load global config - load(appDir.getParentFile()); - // load app config - load(appDir); - log.debug("Config Props [{}] Loaded.", CONFIG_PROPS); - } - - static void load(File dir) { - // load from custom file - File configFile = new File(dir, "config/config.properties"); - String configPath = configFile.getAbsolutePath(); - log.info("Load Config From Path [{}].", configPath); - if (configFile.exists()) { - log.info("Config File [{}] Exists.", configPath); - InputStream configIn = null; - try { - configIn = new FileInputStream(configFile); - Properties props = new Properties(); - props.load(configIn); - log.debug("Config Props [{}] Found.", props); - CONFIG_PROPS.putAll(props); - } - catch (Exception e) { - log.error("Load Config [{}] Error Caused.", configPath, e); - } - finally { - if (configIn != null) { - try { - configIn.close(); - } - catch (IOException e) { - log.warn("Config Input Stream Close Error Caused."); - } - } - } - } - else { - log.info("Config File [{}] Does Not Exist, Ignore.", configPath); - } - } -} diff --git a/tigon-props-config/src/main/resources/spring/servlet-spring-summer-props-config.xml b/tigon-props-config/src/main/resources/spring/servlet-spring-summer-props-config.xml deleted file mode 100644 index 8fd7424..0000000 --- a/tigon-props-config/src/main/resources/spring/servlet-spring-summer-props-config.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - diff --git a/tigon-props-config/src/main/resources/spring/spring-summer-props-config.xml b/tigon-props-config/src/main/resources/spring/spring-summer-props-config.xml deleted file mode 100644 index ada0c89..0000000 --- a/tigon-props-config/src/main/resources/spring/spring-summer-props-config.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/tigon-props-config/src/test/java/me/chyxion/tigon/propsconfig/TestDriver.java b/tigon-props-config/src/test/java/me/chyxion/tigon/propsconfig/TestDriver.java deleted file mode 100644 index ae452d0..0000000 --- a/tigon-props-config/src/test/java/me/chyxion/tigon/propsconfig/TestDriver.java +++ /dev/null @@ -1,12 +0,0 @@ -package me.chyxion.tigon.propsconfig; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Dec 1, 2016 2:42:36 PM - */ -public class TestDriver { - -} diff --git a/tigon-props-config/src/test/resources/log4j.xml b/tigon-props-config/src/test/resources/log4j.xml deleted file mode 100644 index ce75e3e..0000000 --- a/tigon-props-config/src/test/resources/log4j.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tigon-props-config/src/test/resources/spring/dao.xml b/tigon-props-config/src/test/resources/spring/dao.xml deleted file mode 100644 index 9ffa409..0000000 --- a/tigon-props-config/src/test/resources/spring/dao.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/tigon-redis/README.md b/tigon-redis/README.md deleted file mode 100644 index 17f626b..0000000 --- a/tigon-redis/README.md +++ /dev/null @@ -1 +0,0 @@ -# tigon-redis diff --git a/tigon-redis/pom.xml b/tigon-redis/pom.xml deleted file mode 100644 index e8a00fa..0000000 --- a/tigon-redis/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - 4.0.0 - tigon-redis - jar - Tigon Redis - Tigon Redis - - - me.chyxion.tigon - tigon - 0.0.1-SNAPSHOT - ../ - - - - - org.apache.commons - commons-lang3 - - - org.springframework.data - spring-data-redis - - - redis.clients - jedis - - - - org.slf4j - jcl-over-slf4j - test - - - org.apache.logging.log4j - log4j-slf4j-impl - test - - - org.apache.logging.log4j - log4j-core - test - - - org.springframework - spring-context - ${spring.version} - test - - - org.springframework - spring-test - ${spring.version} - test - - - junit - junit - test - - - diff --git a/tigon-redis/src/main/java/me/chyxion/tigon/redis/pub/PubProducer.java b/tigon-redis/src/main/java/me/chyxion/tigon/redis/pub/PubProducer.java deleted file mode 100644 index 72b19a6..0000000 --- a/tigon-redis/src/main/java/me/chyxion/tigon/redis/pub/PubProducer.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.chyxion.tigon.redis.pub; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Nov 7, 2015 5:32:36 PM - */ -public interface PubProducer { - String PUB_QUEUE_SUFFIX = "_QUEUE"; - String MESSAGE_CHANEL = "__PUBLICATION__"; - - /** - * @param topic topic - * @param message message - */ - void publish(String topic, Object message); - - /** - * @param topic topic - * @param message message - */ - void publish(String topic, String message); -} diff --git a/tigon-redis/src/main/java/me/chyxion/tigon/redis/pub/support/PubProducerSupport.java b/tigon-redis/src/main/java/me/chyxion/tigon/redis/pub/support/PubProducerSupport.java deleted file mode 100644 index b5b4e85..0000000 --- a/tigon-redis/src/main/java/me/chyxion/tigon/redis/pub/support/PubProducerSupport.java +++ /dev/null @@ -1,47 +0,0 @@ -package me.chyxion.tigon.redis.pub.support; - -import me.chyxion.tigon.redis.pub.PubProducer; - -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Nov 7, 2015 5:07:50 PM - */ -public class PubProducerSupport - implements PubProducer { - @Autowired - private RedisTemplate redisTpl; - @Autowired - private StringRedisTemplate strRedisTpl; - - /** - * {@inheritDoc} - */ - @Override - public void publish(String topic, Object message) { - publish(redisTpl, topic, message); - } - - /** - * {@inheritDoc} - */ - @Override - public void publish(String topic, String message) { - publish(strRedisTpl, topic, message); - } - - // -- - // private methods - - private void publish( - RedisTemplate redisTpl, String topic, T message) { - redisTpl.opsForList().rightPush(topic + PUB_QUEUE_SUFFIX, message); - strRedisTpl.convertAndSend(MESSAGE_CHANEL, topic); - } -} diff --git a/tigon-redis/src/main/resources/spring/spring-summer-redis.xml b/tigon-redis/src/main/resources/spring/spring-summer-redis.xml deleted file mode 100644 index b846181..0000000 --- a/tigon-redis/src/main/resources/spring/spring-summer-redis.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - Tigon Redis - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tigon-redis/src/test/java/cn/com/flaginfo/echat/redis/TestDriver.java b/tigon-redis/src/test/java/cn/com/flaginfo/echat/redis/TestDriver.java deleted file mode 100644 index c1bec82..0000000 --- a/tigon-redis/src/test/java/cn/com/flaginfo/echat/redis/TestDriver.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.com.flaginfo.echat.redis; - -import org.junit.Test; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author chyxion
- * chyxion@163.com
- * Mar 14, 2015 3:03:57 PM - */ -public class TestDriver { - - @Test - public void testHash() { - // System.err.println(new AuthConfig().hashPassword("123", "456")); - } -} diff --git a/tigon-redis/src/test/java/cn/com/flaginfo/echat/redis/test/TestPub.java b/tigon-redis/src/test/java/cn/com/flaginfo/echat/redis/test/TestPub.java deleted file mode 100644 index b01c89a..0000000 --- a/tigon-redis/src/test/java/cn/com/flaginfo/echat/redis/test/TestPub.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.com.flaginfo.echat.redis.test; - -import java.util.Date; - -import me.chyxion.tigon.redis.pub.PubProducer; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Nov 9, 2015 9:08:17 AM - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration({ - "classpath:spring/spring-echat-redis.xml", - "classpath:spring/spring-redis-test.xml", -}) -public class TestPub { - @Autowired - private PubProducer pp; - - @Test - public void testRun() { - pp.publish("MESSAGE", "Hello, Redis Pub!" + new Date()); - } -} diff --git a/tigon-redis/src/test/java/cn/com/flaginfo/echat/redis/test/TestSub.java b/tigon-redis/src/test/java/cn/com/flaginfo/echat/redis/test/TestSub.java deleted file mode 100644 index e62036b..0000000 --- a/tigon-redis/src/test/java/cn/com/flaginfo/echat/redis/test/TestSub.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.com.flaginfo.echat.redis.test; - -import org.junit.Test; -import java.util.Scanner; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Nov 9, 2015 9:27:19 AM - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration({ - "classpath:spring/spring-echat-redis.xml", - "classpath:spring/spring-redis-test.xml", - "classpath:spring/spring-redis-sub-test.xml", -}) -public class TestSub { - - @Test - public void testRun() { - new Scanner(System.in).next(); - } -} diff --git a/tigon-redis/src/test/resources/log4j.properties b/tigon-redis/src/test/resources/log4j.properties deleted file mode 100644 index 9b2b66b..0000000 --- a/tigon-redis/src/test/resources/log4j.properties +++ /dev/null @@ -1,6 +0,0 @@ -log4j.rootLogger=debug, console - -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.Encoding=utf-8 -log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n diff --git a/tigon-redis/src/test/resources/spring/config.properties b/tigon-redis/src/test/resources/spring/config.properties deleted file mode 100644 index b34fa1e..0000000 --- a/tigon-redis/src/test/resources/spring/config.properties +++ /dev/null @@ -1,11 +0,0 @@ -# Config Dev - -# Redis -redis.host=127.0.0.1 -#redis.port=6379 -#redis.password=0211 -redis.port=6380 -redis.password=6ca2b1bf0fe311e5:Y24kfEiNJxQFc17D - -#redis.port=6382 -#redis.password=e1605352ed8511e4:F92dd46acd0fe11e4 \ No newline at end of file diff --git a/tigon-redis/src/test/resources/spring/spring-redis-sub-test.xml b/tigon-redis/src/test/resources/spring/spring-redis-sub-test.xml deleted file mode 100644 index aa91e91..0000000 --- a/tigon-redis/src/test/resources/spring/spring-redis-sub-test.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - diff --git a/tigon-redis/src/test/resources/spring/spring-redis-test.xml b/tigon-redis/src/test/resources/spring/spring-redis-test.xml deleted file mode 100644 index 502f0b0..0000000 --- a/tigon-redis/src/test/resources/spring/spring-redis-test.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/tigon-sequence/pom.xml b/tigon-sequence/pom.xml index a405861..5d21158 100644 --- a/tigon-sequence/pom.xml +++ b/tigon-sequence/pom.xml @@ -21,6 +21,7 @@ org.mongodb bson + 3.4.2 diff --git a/tigon-sequence/src/main/resources/spring/spring-summer-sequence.xml b/tigon-sequence/src/main/resources/spring/spring-tigon-sequence.xml similarity index 100% rename from tigon-sequence/src/main/resources/spring/spring-summer-sequence.xml rename to tigon-sequence/src/main/resources/spring/spring-tigon-sequence.xml diff --git a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseCrudByFormService.java b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseCrudByFormService.java index 8165761..bad2418 100644 --- a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseCrudByFormService.java +++ b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseCrudByFormService.java @@ -21,7 +21,7 @@ public interface BaseCrudByFormService FormForUpdate extends BaseFormForUpdateApi> extends BaseCrudService, BaseQueryService, - BaseDeleteService { + BaseDeleteService { /** * @param form form diff --git a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseCrudService.java b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseCrudService.java index f933d0d..22e9af7 100644 --- a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseCrudService.java +++ b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseCrudService.java @@ -6,9 +6,8 @@ import me.chyxion.tigon.mybatis.Search; import me.chyxion.tigon.model.BaseModel; import me.chyxion.tigon.model.ViewModel; import javax.validation.constraints.NotNull; - +import javax.validation.constraints.NotEmpty; import me.chyxion.tigon.validation.annotation.NotNullOrBlank; -import org.hibernate.validator.constraints.NotEmpty; /** * @version 0.0.1 @@ -20,7 +19,7 @@ import org.hibernate.validator.constraints.NotEmpty; public interface BaseCrudService > extends BaseQueryService, - BaseDeleteService { + BaseDeleteService { /** * @param model form diff --git a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseDeleteService.java b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseDeleteService.java index 3037e2d..345c0cb 100644 --- a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseDeleteService.java +++ b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseDeleteService.java @@ -1,5 +1,6 @@ package me.chyxion.tigon.service; +import java.util.List; import me.chyxion.tigon.mybatis.Search; import javax.validation.constraints.NotNull; import org.springframework.validation.annotation.Validated; @@ -13,17 +14,19 @@ import me.chyxion.tigon.validation.annotation.NotNullOrBlank; * Nov 7, 2016 4:20:42 PM */ @Validated -public interface BaseDeleteService { +public interface BaseDeleteService { /** * delete by search * @param search search + * @return models deleted */ - int delete(@NotNull Search search); + List delete(@NotNull Search search); /** * delete by primaryKey * @param primaryKey primaryKey + * @return model deleted */ - int delete(@NotNullOrBlank PrimaryKey primaryKey); + Model delete(@NotNullOrBlank PrimaryKey primaryKey); } diff --git a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseService.java b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseService.java index 3281e8f..908fe40 100644 --- a/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseService.java +++ b/tigon-service-api/src/main/java/me/chyxion/tigon/service/BaseService.java @@ -4,7 +4,7 @@ import java.util.List; import me.chyxion.tigon.model.BaseModel; import me.chyxion.tigon.model.ViewModel; import javax.validation.constraints.NotNull; -import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.constraints.NotEmpty; /** * @version 0.0.1 diff --git a/tigon-service-support/pom.xml b/tigon-service-support/pom.xml index 29a9d5c..79e1f97 100644 --- a/tigon-service-support/pom.xml +++ b/tigon-service-support/pom.xml @@ -52,11 +52,13 @@ com.alibaba druid + 1.0.28 test mysql mysql-connector-java + 5.1.6 test @@ -77,6 +79,7 @@ javax.el javax.el-api + 3.0.0 test diff --git a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseCrudByFormServiceSupport.java b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseCrudByFormServiceSupport.java index 9731b99..b092800 100644 --- a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseCrudByFormServiceSupport.java +++ b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseCrudByFormServiceSupport.java @@ -30,9 +30,11 @@ public class BaseCrudByFormServiceSupport */ @Override public ViewModel create(FormForCreate form) { - log.debug("Create Form [{}].", form); + log.debug("Create form [{}].", form); validate(form); - return create(form.copy(modelType)); + final Model model = form.copy(modelType); + beforeCreate(form, model); + return create(model); } /** @@ -40,13 +42,15 @@ public class BaseCrudByFormServiceSupport */ @Override public ViewModel update(FormForUpdate form) { + log.debug("Update form [{}].", form); validate(form); PrimaryKey primaryKey = form.getId(); Model model = find(primaryKey); - Assert.state(model != null, "No Model [" + primaryKey + "] Found"); - return update(form.copy(model)); + Assert.state(model != null, "No model [" + primaryKey + "] found"); + form.copy(model); + beforeUpdate(form, model); + return update(model); } - // -- // private methods @@ -66,4 +70,12 @@ public class BaseCrudByFormServiceSupport protected void validate(FormForUpdate form) { // For Override } + + protected void beforeCreate(FormForCreate form, Model model) { + + } + + protected void beforeUpdate(FormForUpdate form, Model model) { + + } } diff --git a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseCrudServiceSupport.java b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseCrudServiceSupport.java index 0214e8a..a0e7ba2 100644 --- a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseCrudServiceSupport.java +++ b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseCrudServiceSupport.java @@ -1,19 +1,13 @@ package me.chyxion.tigon.service.support; -import java.util.Map; -import java.util.List; -import java.util.ArrayList; -import java.util.Collection; +import java.util.*; import lombok.extern.slf4j.Slf4j; -import me.chyxion.tigon.model.BaseModel; import me.chyxion.tigon.mybatis.Search; +import me.chyxion.tigon.model.BaseModel; import me.chyxion.tigon.model.ViewModel; import me.chyxion.tigon.mybatis.BaseMapper; -import javax.validation.constraints.NotNull; import org.apache.commons.lang3.StringUtils; import me.chyxion.tigon.service.BaseCrudService; -import org.hibernate.validator.constraints.NotEmpty; -import me.chyxion.tigon.validation.annotation.NotNullOrBlank; import org.springframework.transaction.annotation.Transactional; /** @@ -35,27 +29,21 @@ public class BaseCrudServiceSupport */ @Override @Transactional - public int delete(Search search) { - return mapper.delete(search); - } - - /** - * {@inheritDoc} - */ - @Override - public int delete(PrimaryKey primaryKey) { - return mapper.delete(primaryKey); - } - - /** - * {@inheritDoc} - */ - @Override - public ViewModel create(Model model) { - beforeInsert(model); - mapper.insert(model); - afterInsert(model); - return toViewModel(model); + public List delete(final Search search) { + log.info("Delete model by search [{}].", search); + final List models = mapper.list(search); + if (models != null && !models.isEmpty()) { + for (Model model : models) { + log.info("Delete model [{}].", model); + beforeDelete(model); + mapper.delete(model.primaryKeyValue()); + afterDelete(model); + } + } + else { + log.warn("No model found by search [{}] to delete.", search); + } + return models; } /** @@ -63,10 +51,45 @@ public class BaseCrudServiceSupport */ @Override @Transactional - public Collection> create(@NotEmpty Collection models) { - List> viewModels = new ArrayList>(models.size()); + public Model delete(final PrimaryKey primaryKey) { + log.info("Delete model by PK [{}].", primaryKey); + final Model model = mapper.find(primaryKey); + if (model != null) { + log.info("Delete model [{}].", model); + beforeDelete(model); + mapper.delete(primaryKey); + afterDelete(model); + } + else { + log.warn("No model found by PK [{}] to delete.", primaryKey); + } + return model; + } + + /** + * {@inheritDoc} + */ + @Override + public ViewModel create(Model model) { + return create(Arrays.asList(model)).iterator().next(); + } + + /** + * {@inheritDoc} + */ + @Override + @Transactional + public Collection> create(Collection models) { + for (final Model model : models) { + model.beforeInsert(); + beforeInsert(model); + } + mapper.insert(models); + final List> viewModels = + new ArrayList<>(models.size()); for (Model model : models) { - viewModels.add(create(model)); + afterInsert(model); + viewModels.add(toViewModel(model)); } return viewModels; } @@ -87,7 +110,7 @@ public class BaseCrudServiceSupport */ @Override @Transactional - public int update(@NotNull Model model, @NotNull Search search) { + public int update(Model model, Search search) { return mapper.update(model, search); } @@ -95,7 +118,7 @@ public class BaseCrudServiceSupport * {@inheritDoc} */ @Override - public int update(@NotEmpty Map model, @NotNullOrBlank PrimaryKey primaryKey) { + public int update(Map model, PrimaryKey primaryKey) { return mapper.update(model, primaryKey); } @@ -104,7 +127,7 @@ public class BaseCrudServiceSupport */ @Override @Transactional - public int update(@NotEmpty Map model, @NotNull Search search) { + public int update(Map model, Search search) { return mapper.update(model, search); } @@ -133,4 +156,12 @@ public class BaseCrudServiceSupport protected void afterUpdate(Model model) { // Hook } + + protected void beforeDelete(Model model) { + // Hook + } + + protected void afterDelete(Model model) { + // Hook + } } diff --git a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseQueryServiceSupport.java b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseQueryServiceSupport.java index d184142..c521328 100644 --- a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseQueryServiceSupport.java +++ b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseQueryServiceSupport.java @@ -25,7 +25,7 @@ public class BaseQueryServiceSupport extends BaseServiceSupport implements BaseQueryService { - @Value("${default.query.batch.size:32}") + @Value("${tigon.query.batch.size:32}") private int scanBatchSize; /** @@ -33,7 +33,7 @@ public class BaseQueryServiceSupport */ @Override public Model find(PrimaryKey primaryKey) { - log.debug("Find Model By PrimaryKey [{}].", primaryKey); + log.debug("Find model by primary key [{}].", primaryKey); return mapper.find(primaryKey); } @@ -42,7 +42,7 @@ public class BaseQueryServiceSupport */ @Override public Model find(Search search) { - log.debug("Find Model By Search [{}].", search); + log.debug("Find model by search [{}].", search); return mapper.find(search); } @@ -51,7 +51,7 @@ public class BaseQueryServiceSupport */ @Override public List list(Search search) { - log.debug("List Models By Search [{}].", search); + log.debug("List models by search [{}].", search); return mapper.list(search); } @@ -60,8 +60,8 @@ public class BaseQueryServiceSupport */ @Override public ListResult listPage(Search search) { - log.debug("List Models Page By Search [{}].", search); - return new ListResult(list(search), count(search)); + log.debug("List models page by search [{}].", search); + return new ListResult<>(list(search), count(search)); } /** @@ -88,7 +88,7 @@ public class BaseQueryServiceSupport */ @Override public int count(Search search) { - log.debug("Count Model By Search [{}].", search); + log.debug("Count model by search [{}].", search); return mapper.count(search); } @@ -97,7 +97,7 @@ public class BaseQueryServiceSupport */ @Override public List> listViewModels(Search search) { - log.debug("List View Models By Search [{}].", search); + log.debug("List view models by search [{}].", search); return toViewModel(list(search)); } @@ -107,8 +107,8 @@ public class BaseQueryServiceSupport @Override public ListResult> listViewModelsPage( Search search) { - log.debug("List View Models Page By Search [{}].", search); - return new ListResult>( + log.debug("List view models page by search [{}].", search); + return new ListResult<>( listViewModels(search), count(search)); } @@ -174,6 +174,7 @@ public class BaseQueryServiceSupport /** * @return the mapper */ + @Override public Mapper getMapper() { return mapper; } @@ -181,6 +182,7 @@ public class BaseQueryServiceSupport /** * @param mapper the mapper to set */ + @Override public void setMapper(Mapper mapper) { this.mapper = mapper; } diff --git a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseServiceSupport.java b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseServiceSupport.java index 1f3404a..34984f5 100644 --- a/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseServiceSupport.java +++ b/tigon-service-support/src/main/java/me/chyxion/tigon/service/support/BaseServiceSupport.java @@ -56,9 +56,8 @@ public class BaseServiceSupport */ @Override public ViewModel toViewModel(Model model) { - ViewModel viewModel = - new ViewModel(model); - log.debug("Model [{}] To View Model.", model); + final ViewModel viewModel = new ViewModel<>(model); + log.debug("Model [{}] to view model.", model); processViewModel(viewModel, model); return viewModel; } @@ -68,9 +67,9 @@ public class BaseServiceSupport */ @Override public List> toViewModel(List models) { - List> viewModels = null; + final List> viewModels; if (models != null && !models.isEmpty()) { - viewModels = new ArrayList>(models.size()); + viewModels = new ArrayList<>(models.size()); for (Model model : models) { viewModels.add(toViewModel(model)); } @@ -82,14 +81,23 @@ public class BaseServiceSupport } /** + * url cache clear * @param model model * @param url url * @return url */ protected String urlCacheClear(M1 model, String url) { - Date dateUpdated = model.getDateUpdated(); - return dateUpdated != null ? - url + "?_d=" + dateUpdated.getTime() : url; + return urlCacheClear(url, model.getDateUpdated()); + } + + /** + * url cache clear + * @param url url + * @param date date + * @return url + */ + protected String urlCacheClear(final String url, final Date date) { + return date != null ? url + "?_d=" + date.getTime() : url; } /** diff --git a/tigon-shiro-cache-redis/pom.xml b/tigon-shiro-cache-redis/pom.xml index a845e87..6a46836 100644 --- a/tigon-shiro-cache-redis/pom.xml +++ b/tigon-shiro-cache-redis/pom.xml @@ -20,27 +20,15 @@ me.chyxion.tigon tigon-shiro-cache - - org.springframework - spring-context - org.apache.commons commons-lang3 + 3.1 - com.alibaba - fastjson - - - org.hibernate + org.hibernate.validator hibernate-validator - - - org.apache.shiro - shiro-core - org.springframework.data spring-data-redis diff --git a/tigon-shiro-cache-redis/src/main/java/me/chyxion/tigon/shiro/cache/shiro/UserIdKeyRedisSessionCache.java b/tigon-shiro-cache-redis/src/main/java/me/chyxion/tigon/shiro/cache/shiro/UserIdKeyRedisSessionCache.java index 171c51b..c0804ff 100644 --- a/tigon-shiro-cache-redis/src/main/java/me/chyxion/tigon/shiro/cache/shiro/UserIdKeyRedisSessionCache.java +++ b/tigon-shiro-cache-redis/src/main/java/me/chyxion/tigon/shiro/cache/shiro/UserIdKeyRedisSessionCache.java @@ -14,6 +14,7 @@ import org.apache.shiro.cache.CacheException; import me.chyxion.tigon.shiro.model.AuthUser; import me.chyxion.tigon.shiro.cache.SessionCache; import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Autowired; /** @@ -28,8 +29,9 @@ import org.springframework.beans.factory.annotation.Autowired; public class UserIdKeyRedisSessionCache implements SessionCache { @Autowired - protected RedisTemplate redisTpl; - @Value("${shiro.session.redis.prefix:AUTH_SESSION}") + @Qualifier("redisTemplate") + protected RedisTemplate redisTpl; + @Value("${tigon.shiro.session.redis.prefix:AUTH_SESSION}") protected String prefix; protected String userIdSessionPrefix; @@ -65,9 +67,9 @@ public class UserIdKeyRedisSessionCache implements SessionCache { */ @Override public Session put(Serializable sessionId, Session session) { - log.info("Redis Session Cache Put [{}:{}:{}].", prefix, sessionId, session); + log.info("Redis session cache put [{}:{}:{}].", prefix, sessionId, session); valueOp().set(prefix + ":" + sessionId, - (Serializable) session, + session, session.getTimeout(), TimeUnit.MILLISECONDS); return session; @@ -78,10 +80,10 @@ public class UserIdKeyRedisSessionCache implements SessionCache { */ @Override public Session remove(Serializable sessionId) { - log.info("Redis Session Cache Remove [{}].", sessionId); + log.info("Redis session cache remove [{}].", sessionId); Session session = get(sessionId); if (session != null) { - log.info("Redis Session Cache Remove [{}].", session); + log.info("Redis session cache remove [{}].", session); redisTpl.delete(prefix + ":" + sessionId); } return session; @@ -92,7 +94,7 @@ public class UserIdKeyRedisSessionCache implements SessionCache { */ @Override public void clear() throws CacheException { - log.warn("Redis Session Cache #clear Not Supported"); + log.warn("Redis session cache #clear not supported"); } /** @@ -109,7 +111,7 @@ public class UserIdKeyRedisSessionCache implements SessionCache { */ @Override public Set keys() { - log.warn("Redis Session Cache #keys Not Supported"); + log.warn("Redis session cache #keys not supported"); return Collections.emptySet(); } @@ -118,7 +120,7 @@ public class UserIdKeyRedisSessionCache implements SessionCache { */ @Override public Collection values() { - log.warn("Redis Session Cache #values Not Supported"); + log.warn("Redis session cache #values not supported"); return Collections.emptyList(); } @@ -127,15 +129,15 @@ public class UserIdKeyRedisSessionCache implements SessionCache { */ @Override public Session findByUserId(final Serializable userId) { - log.debug("Find Session By User Id [{}].", userId); + log.debug("Find session by user id [{}].", userId); Serializable sessionId = hashOp().get(userIdSessionPrefix, userId); Session session = null; if (sessionId != null) { - log.debug("User [{}] Session Id [{}] Found.", userId, sessionId); + log.debug("User [{}] session id [{}] found.", userId, sessionId); session = get(sessionId); - log.info("User [{}] Session [{}] Found.", userId, session); + log.info("User [{}] session [{}] found.", userId, session); if (session == null) { - log.info("No User [{}] Session Found, Remove."); + log.info("No user [{}] session found, remove."); hashOp().delete(userIdSessionPrefix, userId); } } @@ -147,23 +149,23 @@ public class UserIdKeyRedisSessionCache implements SessionCache { */ @Override public Session putUserSession(Session session) { - log.info("Put User Session [{}].", session); + log.info("Put user session [{}].", session); AuthUser authUser = AuthUser.get(session); - Assert.state(authUser != null, "Auth User Not Found In Session"); + Assert.state(authUser != null, "Auth user not found in session"); final Serializable userId = authUser.getUserId(); - Assert.state(userId != null, "Session Auth User Id Could Not Be Null"); - log.info("Put User [{}] Session [{}].", userId, session); + Assert.state(userId != null, "Session auth user id could not be null"); + log.info("Put user [{}] session [{}].", userId, session); hashOp().put(userIdSessionPrefix, userId, session.getId()); return session; } // -- // private methods - protected HashOperations hashOp() { + protected HashOperations hashOp() { return redisTpl.opsForHash(); } - protected ValueOperations valueOp() { + protected ValueOperations valueOp() { return redisTpl.opsForValue(); } } diff --git a/tigon-shiro-cache/pom.xml b/tigon-shiro-cache/pom.xml index a05a386..ecec895 100644 --- a/tigon-shiro-cache/pom.xml +++ b/tigon-shiro-cache/pom.xml @@ -23,23 +23,17 @@ org.apache.commons commons-lang3 + 3.1 - com.alibaba - fastjson - - - org.hibernate + org.hibernate.validator hibernate-validator org.apache.shiro shiro-core - - - org.springframework.data - spring-data-redis + 1.3.2 diff --git a/tigon-shiro-cache/src/main/java/me/chyxion/tigon/shiro/cache/SessionCache.java b/tigon-shiro-cache/src/main/java/me/chyxion/tigon/shiro/cache/SessionCache.java index 6da3e8e..220273f 100644 --- a/tigon-shiro-cache/src/main/java/me/chyxion/tigon/shiro/cache/SessionCache.java +++ b/tigon-shiro-cache/src/main/java/me/chyxion/tigon/shiro/cache/SessionCache.java @@ -4,7 +4,7 @@ import java.io.Serializable; import org.apache.shiro.cache.Cache; import org.apache.shiro.session.Session; import javax.validation.constraints.NotNull; -import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotBlank; import org.springframework.validation.annotation.Validated; /** diff --git a/tigon-shiro-cache/src/main/java/me/chyxion/tigon/shiro/model/AuthUser.java b/tigon-shiro-cache/src/main/java/me/chyxion/tigon/shiro/model/AuthUser.java index f63d3c2..582a7d2 100644 --- a/tigon-shiro-cache/src/main/java/me/chyxion/tigon/shiro/model/AuthUser.java +++ b/tigon-shiro-cache/src/main/java/me/chyxion/tigon/shiro/model/AuthUser.java @@ -3,9 +3,9 @@ package me.chyxion.tigon.shiro.model; import lombok.Getter; import lombok.Setter; import java.util.Map; +import lombok.ToString; import java.util.HashMap; import java.io.Serializable; -import com.alibaba.fastjson.JSON; import org.apache.shiro.SecurityUtils; import org.springframework.util.Assert; import org.apache.shiro.session.Session; @@ -19,6 +19,7 @@ import org.apache.shiro.session.Session; */ @Getter @Setter +@ToString public class AuthUser implements Serializable { private static final long serialVersionUID = 1L; @@ -71,21 +72,13 @@ public class AuthUser implements Serializable { * @param authUser auth user */ public static void save(Session session, AuthUser authUser) { - Assert.notNull(session); - Assert.notNull(authUser); - Assert.state(authUser.getUserId() != null, "User Id Is Null"); + Assert.notNull(session, "Session could not be null"); + Assert.notNull(authUser, "Auth user could not be null"); + Assert.state(authUser.getUserId() != null, "Auth user id could not be null"); session.setAttribute(SESSION_AUTH_USER_KEY, authUser); session.touch(); } - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return JSON.toJSONString(this); - } - /** * @param name attr name * @param value attr value @@ -93,7 +86,7 @@ public class AuthUser implements Serializable { */ public AuthUser setAttr(String name, Serializable value) { if (attrs == null) { - attrs = new HashMap(); + attrs = new HashMap<>(); } attrs.put(name, value); return this; diff --git a/tigon-shiro-cas/.gitignore b/tigon-shiro-cas/.gitignore new file mode 100644 index 0000000..bcb9203 --- /dev/null +++ b/tigon-shiro-cas/.gitignore @@ -0,0 +1,9 @@ +.* +!.gitignore +!.gitkeep +*.iml +**/src/main/resources/application.properties +**/src/main/resources/log4j2.xml +**/src/main/resources/logback.xml +target/ +bin/ diff --git a/tigon-shiro-cas/README.md b/tigon-shiro-cas/README.md new file mode 100644 index 0000000..77cd973 --- /dev/null +++ b/tigon-shiro-cas/README.md @@ -0,0 +1 @@ +# CAS Client Shiro diff --git a/tigon-shiro-war/pom.xml b/tigon-shiro-cas/pom.xml similarity index 53% rename from tigon-shiro-war/pom.xml rename to tigon-shiro-cas/pom.xml index e47cc24..eb6446c 100644 --- a/tigon-shiro-war/pom.xml +++ b/tigon-shiro-cas/pom.xml @@ -4,9 +4,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - tigon-shiro-war - Tigon Shiro WAR + tigon-shiro-cas jar + CAS Client Shiro + CAS Client Shiro me.chyxion.tigon @@ -21,19 +22,28 @@ tigon-shiro-core - javax.servlet - javax.servlet-api + org.apache.shiro + shiro-spring + 1.4.0 + + + org.pac4j + pac4j-cas + 2.3.1 + + + io.buji + buji-pac4j + 3.2.0 + + + org.projectlombok + lombok provided - - org.springframework - spring-test - test - - - junit - junit + org.springframework.boot + spring-boot-starter-test test diff --git a/tigon-shiro-cas/src/main/java/me/chyxion/tigon/shiro/cas/DefaultProfileCreator.java b/tigon-shiro-cas/src/main/java/me/chyxion/tigon/shiro/cas/DefaultProfileCreator.java new file mode 100644 index 0000000..ff55085 --- /dev/null +++ b/tigon-shiro-cas/src/main/java/me/chyxion/tigon/shiro/cas/DefaultProfileCreator.java @@ -0,0 +1,57 @@ +package me.chyxion.tigon.shiro.cas; + +import java.util.Map; +import java.util.Collection; +import lombok.extern.slf4j.Slf4j; +import java.util.function.Consumer; +import org.pac4j.core.context.WebContext; +import org.pac4j.core.profile.CommonProfile; +import org.pac4j.core.credentials.TokenCredentials; +import org.pac4j.core.profile.creator.ProfileCreator; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Jun 23, 2018 16:17:53 + */ +@Slf4j +public class DefaultProfileCreator implements ProfileCreator { + + @Autowired(required = false) + private UserProfileProvider userProfileProvider; + + /** + * {@inheritDoc} + */ + @Override + public CommonProfile create(final TokenCredentials credentials, final WebContext context) { + log.debug("Create user profile from credentials [{}].", credentials); + + final CommonProfile userProfile = credentials.getUserProfile(); + if (userProfileProvider != null) { + log.debug("User profile provider [{}] found.", userProfileProvider); + final UserProfileProvider.UserProfile userProfileResult = + userProfileProvider.getUserProfile(userProfile.getId()); + if (userProfileResult != null) { + applyIfNotEmpty(userProfileResult.getRoles(), userProfile::addRoles); + applyIfNotEmpty(userProfileResult.getPermissions(), userProfile::addPermissions); + applyIfNotEmpty(userProfileResult.getAttrs(), userProfile::addAttributes); + applyIfNotEmpty(userProfileResult.getAuthAttrs(), userProfile::addAuthenticationAttributes); + } + } + return userProfile; + } + + private void applyIfNotEmpty(final Collection data, final Consumer> consumer) { + if (data != null && !data.isEmpty()) { + consumer.accept(data); + } + } + + private void applyIfNotEmpty(final Map data, final Consumer> consumer) { + if (data != null && !data.isEmpty()) { + consumer.accept(data); + } + } +} diff --git a/tigon-shiro-cas/src/main/java/me/chyxion/tigon/shiro/cas/UserProfileProvider.java b/tigon-shiro-cas/src/main/java/me/chyxion/tigon/shiro/cas/UserProfileProvider.java new file mode 100644 index 0000000..4299142 --- /dev/null +++ b/tigon-shiro-cas/src/main/java/me/chyxion/tigon/shiro/cas/UserProfileProvider.java @@ -0,0 +1,28 @@ +package me.chyxion.tigon.shiro.cas; + +import lombok.Getter; +import lombok.Setter; +import java.util.Map; +import java.util.Set; +import javax.validation.constraints.NotBlank; +import org.springframework.validation.annotation.Validated; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Jun 26, 2018 21:57:43 + */ +@Validated +public interface UserProfileProvider { + + @Getter + @Setter + class UserProfile { + private Set roles; + private Set permissions; + private Map attrs; + private Map authAttrs; + } + + UserProfile getUserProfile(@NotBlank String account); +} diff --git a/tigon-shiro-cas/src/main/resources/spring/spring-shiro-cas.xml b/tigon-shiro-cas/src/main/resources/spring/spring-shiro-cas.xml new file mode 100644 index 0000000..f8bb542 --- /dev/null +++ b/tigon-shiro-cas/src/main/resources/spring/spring-shiro-cas.xml @@ -0,0 +1,79 @@ + + + Shiro CAS Configuration + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tigon-shiro-cas/src/test/java/me/chyxion/tigon/shiro/cas/TestDriver.java b/tigon-shiro-cas/src/test/java/me/chyxion/tigon/shiro/cas/TestDriver.java new file mode 100644 index 0000000..188eb0c --- /dev/null +++ b/tigon-shiro-cas/src/test/java/me/chyxion/tigon/shiro/cas/TestDriver.java @@ -0,0 +1,20 @@ +package me.chyxion.tigon.shiro.cas; + +import org.junit.Test; +import lombok.extern.slf4j.Slf4j; + +/** + * @version 0.0.1 + * @since 0.0.1 + * @author Donghuang
+ * donghuang@wacai.com
+ * Sep 1, 2015 2:34:08 PM + */ +@Slf4j +public class TestDriver { + + @Test + public void test() { + + } +} diff --git a/tigon-shiro-spring-boot/src/test/resources/spring/spring-test.xml b/tigon-shiro-cas/src/test/resources/spring/spring-test.xml similarity index 82% rename from tigon-shiro-spring-boot/src/test/resources/spring/spring-test.xml rename to tigon-shiro-cas/src/test/resources/spring/spring-test.xml index 7aa0615..704a597 100644 --- a/tigon-shiro-spring-boot/src/test/resources/spring/spring-test.xml +++ b/tigon-shiro-cas/src/test/resources/spring/spring-test.xml @@ -4,5 +4,4 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - diff --git a/tigon-shiro-core/pom.xml b/tigon-shiro-core/pom.xml index fbc8f99..95f9031 100644 --- a/tigon-shiro-core/pom.xml +++ b/tigon-shiro-core/pom.xml @@ -17,6 +17,14 @@ + + org.springframework.boot + spring-boot + + + org.springframework + spring-web + me.chyxion.tigon tigon-sequence @@ -24,15 +32,12 @@ org.apache.shiro shiro-spring + 1.4.0 me.chyxion.tigon tigon-shiro-cache - - me.chyxion.tigon - tigon-webmvc-core - org.projectlombok lombok diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthConfigFactory.java b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthConfigFactory.java deleted file mode 100644 index bc3cdab..0000000 --- a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthConfigFactory.java +++ /dev/null @@ -1,115 +0,0 @@ -package me.chyxion.tigon.shiro; - -import java.util.Map; -import java.util.Set; -import org.slf4j.Logger; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import javax.servlet.Filter; -import org.slf4j.LoggerFactory; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import javax.annotation.PostConstruct; -import me.chyxion.tigon.webmvc.JSONViewConfig; -import me.chyxion.tigon.webmvc.util.ResponseTool; -import me.chyxion.tigon.webmvc.exception.ExceptionMessage; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Apr 7, 2015 4:44:04 PM - */ -public class AuthConfigFactory { - private static final Logger log = - LoggerFactory.getLogger(AuthConfigFactory.class); - @Autowired(required = false) - private AuthConfig authConfig; - @Autowired - private ResponseTool responseTool; - @Autowired - private JSONViewConfig viewConfig; - @Autowired(required = false) - private ExceptionMessage exceptionMessage; - - private UserFilterExt userFilter; - - /** - * @return filters - */ - public Map filters() { - Map filters = new LinkedHashMap(); - filters.put(AuthConfig.FILTER_USER, userFilter); - if (authConfig != null) { - authConfig.customizeFilters(filters); - } - log.info("Auth Filters [{}].", filters); - return filters; - } - - /** - * @return filter routings - */ - public Map filterRoutings() { - Map routings = new LinkedHashMap(); - routings.put("/assets/**", AuthConfig.FILTER_ANON); - InputStream authIn = AuthConfigFactory.class - .getResourceAsStream("/shiro/auth.properties"); - if (authIn != null) { - Properties props = new OrderedProperties(); - try { - props.load(authIn); - } - catch (IOException e) { - throw new IllegalStateException( - "Load Auth Config Error Caused", e); - } - finally { - if (authIn != null) { - try { - authIn.close(); - } - catch (IOException e) { - // ignore - } - } - } - for (String name : props.stringPropertyNames()) { - routings.put(name, props.getProperty(name)); - } - } - log.info("Auth Filter Routings [{}].", routings); - return routings; - } - - /** - * init - */ - @PostConstruct - void init() { - userFilter = new UserFilterExt( - responseTool, viewConfig, exceptionMessage); - } - - static class OrderedProperties extends Properties { - private static final long serialVersionUID = 1L; - private final Set keys = new LinkedHashSet(); - - public Object put(Object key, Object value) { - keys.add((String) key); - return super.put(key, value); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Set keySet() { - return keys; - } - - public Set stringPropertyNames() { - return keys; - } - } -} diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/FilterChainDefinitionMap.java b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/FilterChainDefinitionMap.java new file mode 100644 index 0000000..279d2ae --- /dev/null +++ b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/FilterChainDefinitionMap.java @@ -0,0 +1,103 @@ +package me.chyxion.tigon.shiro; + +import java.util.*; +import lombok.Getter; +import java.io.IOException; +import java.io.InputStream; +import lombok.extern.slf4j.Slf4j; +import javax.annotation.PostConstruct; +import org.springframework.core.io.Resource; + +/** + * @author Donghuang
+ * donghuang@wacai.com
+ * Jun 27, 2018 10:42 + */ +@Slf4j +@Getter +public class FilterChainDefinitionMap extends LinkedHashMap { + private final Resource configLocation; + + public FilterChainDefinitionMap(final Resource configLocation) { + this.configLocation = configLocation; + } + + public FilterChainDefinitionMap(final Resource configLocation, final Map map) { + super(map); + this.configLocation = configLocation; + } + + @PostConstruct + void init() throws IOException { + log.info("Load shiro filter chain definition from config location [{}].", configLocation); + + if (configLocation != null && configLocation.exists()) { + final InputStream authIn = configLocation.getInputStream(); + if (authIn != null) { + final Properties props = new OrderedProperties(); + try { + props.load(authIn); + } + catch (final IOException e) { + throw new IllegalStateException( + "Load shiro filter chain definition config error caused", e); + } + finally { + if (authIn != null) { + try { + authIn.close(); + } + catch (IOException e) { + // ignore + } + } + } + + for (final String path : props.stringPropertyNames()) { + final String auth = props.getProperty(path); + log.info("Shiro filter chain definition [{}] -> [{}] added.", path, auth); + put(path, auth); + } + } + else { + log.info("No input stream load from shiro filter chain definition config location [{}], ignore.", configLocation); + } + } + else { + log.info("Shiro filter chain definition config location [{}] does not exist, ignore.", configLocation); + } + } + + @Slf4j + static class OrderedProperties extends Properties { + private static final long serialVersionUID = 1L; + private final Set keys = new LinkedHashSet<>(); + + /** + * {@inheritDoc} + */ + @Override + public Object put(Object key, Object value) { + log.debug("Load shiro filter chain [{}] -> [{}].", key, value); + keys.add((String) key); + return super.put(key, value); + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Set keySet() { + return keys; + } + + /** + * {@inheritDoc} + */ + @Override + public Set stringPropertyNames() { + return keys; + } + } +} diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/SessionListenerExt.java b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/SessionListenerExt.java deleted file mode 100644 index c11c478..0000000 --- a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/SessionListenerExt.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.chyxion.tigon.shiro; - -import org.apache.shiro.session.Session; -import org.apache.shiro.session.SessionListener; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * May 14, 2016 2:09:26 PM - */ -public interface SessionListenerExt extends SessionListener { - - /** - * on session validation - * @param session session - * @return returns true if session has been changed - */ - boolean onValidation(Session session); -} diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/SessionDAOSupport.java b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/TigonSessionDAO.java similarity index 91% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/SessionDAOSupport.java rename to tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/TigonSessionDAO.java index 4e13439..80db7f2 100644 --- a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/SessionDAOSupport.java +++ b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/TigonSessionDAO.java @@ -23,7 +23,7 @@ import org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO; * Sep 8, 2014 7:43:05 PM */ @Slf4j -public class SessionDAOSupport extends EnterpriseCacheSessionDAO { +public class TigonSessionDAO extends EnterpriseCacheSessionDAO { @Autowired(required = false) private Cache sessionCache; @Autowired @@ -36,9 +36,9 @@ public class SessionDAOSupport extends EnterpriseCacheSessionDAO { void init() { if (sessionCache == null) { log.info("No Custom Session Store Found, Use Map Cache."); - sessionCache = new MapCache( + sessionCache = new MapCache<>( CachingSessionDAO.ACTIVE_SESSION_CACHE_NAME, - new ConcurrentHashMap()); + new ConcurrentHashMap<>(512)); } else { log.info("Use Custom Session Cache [{}].", sessionCache); diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/DefaultWebSecurityManagerExt.java b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/TigonWebSecurityManager.java similarity index 94% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/DefaultWebSecurityManagerExt.java rename to tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/TigonWebSecurityManager.java index 8284366..0f6aa2f 100644 --- a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/DefaultWebSecurityManagerExt.java +++ b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/TigonWebSecurityManager.java @@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; * chyxion@163.com
* Mar 12, 2015 1:18:00 PM */ -public class DefaultWebSecurityManagerExt extends DefaultWebSecurityManager { +public class TigonWebSecurityManager extends DefaultWebSecurityManager { @Autowired(required = false) private AuthCallback authCallback; diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/DefaultWebSessionManagerExt.java b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/TigonWebSessionManager.java similarity index 76% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/DefaultWebSessionManagerExt.java rename to tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/TigonWebSessionManager.java index 576205d..a0e19c2 100644 --- a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/DefaultWebSessionManagerExt.java +++ b/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/TigonWebSessionManager.java @@ -1,6 +1,8 @@ package me.chyxion.tigon.shiro; import java.util.List; + +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import java.io.Serializable; import java.util.LinkedList; @@ -28,8 +30,8 @@ import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; * chyxion@163.com
* Apr 7, 2015 2:54:25 PM */ -public class DefaultWebSessionManagerExt extends DefaultWebSessionManager { - private static final Logger log = LoggerFactory.getLogger(DefaultWebSessionManagerExt.class); +@Slf4j +public class TigonWebSessionManager extends DefaultWebSessionManager { @Autowired(required = false) private SessionIdManager sessionIdManager; @Autowired(required = false) @@ -41,10 +43,10 @@ public class DefaultWebSessionManagerExt extends DefaultWebSessionManager { @PostConstruct void init() { if (sessionListeners == null) { - sessionListeners = new LinkedList(); + sessionListeners = new LinkedList<>(); } else { - log.info("SessionListeners [{}] Found.", sessionListeners); + log.info("Session listeners [{}] found.", sessionListeners); } setSessionListeners(sessionListeners); } @@ -66,7 +68,7 @@ public class DefaultWebSessionManagerExt extends DefaultWebSessionManager { writeSessionIdCookie(sessionId, request, response); } else { - log.debug("Session ID cookie is disabled. No cookie has been set for new session with id [{}]", sessionId); + log.debug("Session id cookie is disabled. no cookie has been set for new session with id [{}]", sessionId); } request.removeAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE); request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_IS_NEW, Boolean.TRUE); @@ -79,14 +81,14 @@ public class DefaultWebSessionManagerExt extends DefaultWebSessionManager { protected Serializable getSessionId(ServletRequest request, ServletResponse response) { Serializable sessionId = null; if (sessionIdManager != null) { - log.debug("Get Custom Session ID From Custom Session Manager."); + log.debug("Get custom session id from custom session manager."); sessionId = sessionIdManager.read( (HttpServletRequest) request, (HttpServletResponse) response, new SimpleCookie(getSessionIdCookie())); } if (sessionId == null) { - log.debug("No Custom Session ID Found From Custom Session Manager, Get Session Id From Cookie."); + log.debug("No custom session id found from custom session manager, get session id from cookie."); sessionId = super.getSessionId(request, response); } return sessionId; @@ -96,21 +98,21 @@ public class DefaultWebSessionManagerExt extends DefaultWebSessionManager { // private methods void writeSessionIdCookie(Serializable currentId, HttpServletRequest request, HttpServletResponse response) { - Assert.notNull(currentId, "sessionId Cannot Be Null When Persisting For Subsequent Requests"); + Assert.notNull(currentId, "Session id cannot be null when persisting for subsequent requests"); String sessionId = currentId.toString(); // copy cookie template Cookie cookie = new SimpleCookie(getSessionIdCookie()); cookie.setValue(sessionId); if (sessionIdManager != null) { if (sessionIdManager.write(request, response, cookie)) { - log.info("Custom Session ID Mananger Write Session ID Cookie [{}] For Session [{}].", cookie, sessionId); + log.info("Custom session id manager write session id cookie [{}] for session [{}].", cookie, sessionId); return; } else { - log.info("Custom Session ID Mananger Dose Not Write Session ID Cookie [{}] For Session [{}].", cookie, sessionId); + log.info("Custom session id manager dose not write session id cookie [{}] for session [{}].", cookie, sessionId); } } - log.info("Default Write Session ID Cookie [{}] For Session [{}].", cookie, sessionId); + log.info("Default write session id cookie [{}] for session [{}].", cookie, sessionId); cookie.saveTo(request, response); } } diff --git a/tigon-shiro-core/src/main/resources/spring/spring-tigon-shiro-core.xml b/tigon-shiro-core/src/main/resources/spring/spring-tigon-shiro-core.xml new file mode 100644 index 0000000..36aaa0b --- /dev/null +++ b/tigon-shiro-core/src/main/resources/spring/spring-tigon-shiro-core.xml @@ -0,0 +1,74 @@ + + + Tigon Shiro Core Configuration + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tigon-shiro-core/src/main/resources/spring/spring-tigon-shiro.xml b/tigon-shiro-core/src/main/resources/spring/spring-tigon-shiro.xml deleted file mode 100644 index 8b855aa..0000000 --- a/tigon-shiro-core/src/main/resources/spring/spring-tigon-shiro.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - Tigon Shiro Configuration - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tigon-shiro-spring-boot/src/main/java/me/chyxion/tigon/shiro/TigonShiroConfig.java b/tigon-shiro-spring-boot/src/main/java/me/chyxion/tigon/shiro/TigonShiroConfig.java deleted file mode 100644 index 221fb35..0000000 --- a/tigon-shiro-spring-boot/src/main/java/me/chyxion/tigon/shiro/TigonShiroConfig.java +++ /dev/null @@ -1,42 +0,0 @@ -package me.chyxion.tigon.shiro; - -import javax.servlet.Filter; -import static javax.servlet.DispatcherType.*; -import org.springframework.context.annotation.Bean; -import org.apache.shiro.spring.web.ShiroFilterFactoryBean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.filter.DelegatingFilterProxy; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.web.servlet.FilterRegistrationBean; - -/** - * @author Shaun Chyxion
- * chyxion@163.com
- * Mar 06, 2017 22:40:11 - */ -@Configuration -public class TigonShiroConfig { - - @Bean - public FilterRegistrationBean someFilterRegistration( - @Qualifier("shiroFilter") ShiroFilterFactoryBean filterFactoryBean) throws Exception { - - FilterRegistrationBean registration = new FilterRegistrationBean(); - registration.setAsyncSupported(true); - registration.addUrlPatterns("/*"); - registration.addInitParameter("targetFilterLifecycle", "true"); - registration.setEnabled(true); - registration.setName("shiroFilter"); - registration.setOrder(Integer.MAX_VALUE); - // registration.setOrder(0); - registration.setDispatcherTypes(REQUEST, FORWARD, INCLUDE, ERROR); - - DelegatingFilterProxy filterProxy = - new DelegatingFilterProxy((Filter) filterFactoryBean.getObject()); - filterProxy.setTargetFilterLifecycle(true); - filterProxy.setTargetBeanName("shiroFilter"); - - registration.setFilter(filterProxy); - return registration; - } -} diff --git a/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/SiteControllerTest.java b/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/SiteControllerTest.java deleted file mode 100644 index 2684ee1..0000000 --- a/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/SiteControllerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package me.chyxion.tigon.shiro; - -import me.chyxion.tigon.shiro.test.Main; -import me.chyxion.tigon.webmvc.test.ControllerTestTool; -import org.apache.shiro.web.filter.authc.UserFilter; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -import java.util.HashMap; -import java.util.Map; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Jan 27, 2015 3:27:08 PM - */ -@WebAppConfiguration -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = Main.class) -@SpringBootTest -public class SiteControllerTest { - - @Autowired - private ControllerTestTool t; - @Autowired - private UserFilter userFilter; - - @Test - public void testIndex() { - t.print(t.get("/")); - } - - @Test - public void testRaw() { - t.print(t.get("/raw")); - } - - @Test - public void testInt() { - t.print(t.get("/int")); - } - - @Test - public void testPost() { - Map params = new HashMap(); - params.put("id", "id"); - params.put("name", "Shaun Chyxion"); - params.put("gender", ""); - t.print(t.post("/post", params)); - } -} diff --git a/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/test/Main.java b/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/test/Main.java deleted file mode 100644 index 9322f15..0000000 --- a/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/test/Main.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.chyxion.tigon.shiro.test; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; - -/** - * @author Shaun Chyxion
- * chyxion@163.com
- * Mar 08, 2017 22:12:05 - */ -@ComponentScan("me.chyxion.tigon.shiro.test") -@EnableAutoConfiguration -public class Main { - - public static void main(String[] args) { - SpringApplication.run(Main.class, args); - } -} diff --git a/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/test/controller/SiteController.java b/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/test/controller/SiteController.java deleted file mode 100644 index ed72269..0000000 --- a/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/test/controller/SiteController.java +++ /dev/null @@ -1,34 +0,0 @@ -package me.chyxion.tigon.shiro.test.controller; - -import java.util.Map; -import java.util.HashMap; -import org.springframework.stereotype.Controller; -import org.apache.shiro.authz.annotation.RequiresUser; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * @author Shaun Chyxion
- * chyxion@163.com
- * Mar 08, 2017 22:10:53 - */ -@Controller -public class SiteController { - - @RequestMapping("/") - public void index() { - - } - - @RequiresUser - @RequestMapping("/raw") - public Map raw() { - Map mapRaw = new HashMap(); - mapRaw.put("data", "Hello!"); - return mapRaw; - } - - @RequestMapping("/int") - public int integer() { - return 99; - } -} diff --git a/tigon-shiro-spring-boot/src/test/resources/shiro/auth.properties b/tigon-shiro-spring-boot/src/test/resources/shiro/auth.properties deleted file mode 100644 index ecdbe6c..0000000 --- a/tigon-shiro-spring-boot/src/test/resources/shiro/auth.properties +++ /dev/null @@ -1,3 +0,0 @@ -/int=anon -/raw=user -/**=user diff --git a/tigon-shiro-war/README.md b/tigon-shiro-war/README.md deleted file mode 100644 index 247502c..0000000 --- a/tigon-shiro-war/README.md +++ /dev/null @@ -1 +0,0 @@ -# tigon-shiro diff --git a/tigon-shiro-war/src/main/java/me/chyxion/tigon/shiro/package-info.java b/tigon-shiro-war/src/main/java/me/chyxion/tigon/shiro/package-info.java deleted file mode 100644 index 57af8d9..0000000 --- a/tigon-shiro-war/src/main/java/me/chyxion/tigon/shiro/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @author Donghuang
- * donghuang@wacai.com
- * Mar 07, 2017 13:35 - */ -package me.chyxion.tigon.shiro; diff --git a/tigon-shiro-war/src/main/resources/META-INF/web-fragment.xml b/tigon-shiro-war/src/main/resources/META-INF/web-fragment.xml deleted file mode 100644 index 5d89e1b..0000000 --- a/tigon-shiro-war/src/main/resources/META-INF/web-fragment.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - tigon-webmvc-shiro - - - - - - shiroFilter - org.springframework.web.filter.DelegatingFilterProxy - true - - targetFilterLifecycle - true - - - - shiroFilter - /* - REQUEST - FORWARD - INCLUDE - ERROR - - diff --git a/tigon-shiro-war/src/test/java/me/chyxion/tigon/shiro/TestDriver.java b/tigon-shiro-war/src/test/java/me/chyxion/tigon/shiro/TestDriver.java deleted file mode 100644 index 4acf7d8..0000000 --- a/tigon-shiro-war/src/test/java/me/chyxion/tigon/shiro/TestDriver.java +++ /dev/null @@ -1,17 +0,0 @@ -package me.chyxion.tigon.shiro; - -import org.junit.Test; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author chyxion
- * chyxion@163.com
- * Mar 14, 2015 3:03:57 PM - */ -public class TestDriver { - - @Test - public void test() { - } -} diff --git a/tigon-shiro-war/src/test/java/me/chyxion/tigon/shiro/controller/SiteController.java b/tigon-shiro-war/src/test/java/me/chyxion/tigon/shiro/controller/SiteController.java deleted file mode 100644 index b142b7d..0000000 --- a/tigon-shiro-war/src/test/java/me/chyxion/tigon/shiro/controller/SiteController.java +++ /dev/null @@ -1,103 +0,0 @@ -package me.chyxion.tigon.shiro.controller; - -import me.chyxion.tigon.format.annotation.EmptyToNull; -import org.hibernate.validator.constraints.NotBlank; -import org.springframework.stereotype.Controller; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import java.util.HashMap; -import java.util.Map; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author chyxion
- * chyxion@163.com
- * May 31, 2015 3:53:04 PM - */ -@Validated -@Controller -public class SiteController { - - @RequestMapping("/") - public void index() { - - } - - @RequestMapping("/v") - public String index(@RequestParam("v") - // @EmptyToNull - String validate) { - return validate; - } - - @RequestMapping("/raw") - public Map raw() { - Map mapRaw = new HashMap(); - mapRaw.put("data", "Hello!"); - return mapRaw; - } - - @RequestMapping("/int") - public int integer() { - return 99; - } - - @RequestMapping("/post") - public String post(@Validated Form form) { - return form.getId(); - } - - public static class Form { - @NotBlank - private String id; - @NotBlank - private String name; - @EmptyToNull - private String gender; - - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the gender - */ - public String getGender() { - return gender; - } - - /** - * @param gender the gender to set - */ - public void setGender(String gender) { - this.gender = gender; - } - } -} diff --git a/tigon-shiro-war/src/test/resources/log4j2.xml b/tigon-shiro-war/src/test/resources/log4j2.xml deleted file mode 100644 index c7486b5..0000000 --- a/tigon-shiro-war/src/test/resources/log4j2.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - %-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n - .logs - DEBUG - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tigon-shiro-war/src/test/resources/spring/servlet-spring-test.xml b/tigon-shiro-war/src/test/resources/spring/servlet-spring-test.xml deleted file mode 100644 index 4ca575e..0000000 --- a/tigon-shiro-war/src/test/resources/spring/servlet-spring-test.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - diff --git a/tigon-shiro-war/src/test/webapp/META-INF/MANIFEST.MF b/tigon-shiro-war/src/test/webapp/META-INF/MANIFEST.MF deleted file mode 100644 index 254272e..0000000 --- a/tigon-shiro-war/src/test/webapp/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Class-Path: - diff --git a/tigon-shiro-war/src/test/webapp/WEB-INF/web.xml b/tigon-shiro-war/src/test/webapp/WEB-INF/web.xml deleted file mode 100644 index 91b9f06..0000000 --- a/tigon-shiro-war/src/test/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - ${project.name} - ${project.description} - - diff --git a/tigon-shiro-spring-boot/README.md b/tigon-shiro/README.md similarity index 100% rename from tigon-shiro-spring-boot/README.md rename to tigon-shiro/README.md diff --git a/tigon-shiro-spring-boot/pom.xml b/tigon-shiro/pom.xml similarity index 69% rename from tigon-shiro-spring-boot/pom.xml rename to tigon-shiro/pom.xml index 142f961..647c15f 100644 --- a/tigon-shiro-spring-boot/pom.xml +++ b/tigon-shiro/pom.xml @@ -4,8 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - tigon-shiro-spring-boot - Tigon Shiro Spring Boot + tigon-shiro + Tigon Shiro + Tigon Shiro jar @@ -20,10 +21,19 @@ me.chyxion.tigon tigon-shiro-core
+ + me.chyxion.tigon + tigon-web + org.springframework.boot spring-boot + + org.projectlombok + lombok + provided + javax.servlet javax.servlet-api @@ -35,30 +45,10 @@ spring-test test - - me.chyxion.tigon - tigon-webmvc-spring-boot - test - - - org.springframework.boot - spring-boot-test - test - junit junit test - - org.apache.logging.log4j - log4j-slf4j-impl - test - - - org.apache.logging.log4j - log4j-core - test -
diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthConfig.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthConfig.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthConfig.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthConfig.java diff --git a/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthConfigFactory.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthConfigFactory.java new file mode 100644 index 0000000..042d70e --- /dev/null +++ b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthConfigFactory.java @@ -0,0 +1,56 @@ +package me.chyxion.tigon.shiro; + +import java.util.Map; +import org.slf4j.Logger; +import javax.servlet.Filter; +import org.slf4j.LoggerFactory; +import java.util.LinkedHashMap; +import javax.annotation.PostConstruct; +import me.chyxion.tigon.webmvc.JSONViewConfig; +import me.chyxion.tigon.webmvc.util.ResponseTool; +import me.chyxion.tigon.webmvc.exception.ExceptionMessage; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @version 0.0.1 + * @since 0.0.1 + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Apr 7, 2015 4:44:04 PM + */ +public class AuthConfigFactory { + private static final Logger log = + LoggerFactory.getLogger(AuthConfigFactory.class); + @Autowired(required = false) + private AuthConfig authConfig; + @Autowired + private ResponseTool responseTool; + @Autowired + private JSONViewConfig viewConfig; + @Autowired(required = false) + private ExceptionMessage exceptionMessage; + + private UserFilterExt userFilter; + + /** + * @return filters + */ + public Map filters() { + Map filters = new LinkedHashMap(); + filters.put(AuthConfig.FILTER_USER, userFilter); + if (authConfig != null) { + authConfig.customizeFilters(filters); + } + log.info("Auth Filters [{}].", filters); + return filters; + } + + /** + * init + */ + @PostConstruct + void init() { + userFilter = new UserFilterExt( + responseTool, viewConfig, exceptionMessage); + } +} diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthExceptionResolver.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthExceptionResolver.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthExceptionResolver.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthExceptionResolver.java diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthRealm.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthRealm.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthRealm.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthRealm.java diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthorizingRealmSupport.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthorizingRealmSupport.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/AuthorizingRealmSupport.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/AuthorizingRealmSupport.java diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/UserFilterExt.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/UserFilterExt.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/UserFilterExt.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/UserFilterExt.java diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/model/AuthInfo.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/model/AuthInfo.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/model/AuthInfo.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/model/AuthInfo.java diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/model/Credential.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/model/Credential.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/model/Credential.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/model/Credential.java diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/model/SerializableByteSource.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/model/SerializableByteSource.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/model/SerializableByteSource.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/model/SerializableByteSource.java diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/service/AuthService.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/service/AuthService.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/service/AuthService.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/service/AuthService.java diff --git a/tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/service/support/AuthServiceSupport.java b/tigon-shiro/src/main/java/me/chyxion/tigon/shiro/service/support/AuthServiceSupport.java similarity index 100% rename from tigon-shiro-core/src/main/java/me/chyxion/tigon/shiro/service/support/AuthServiceSupport.java rename to tigon-shiro/src/main/java/me/chyxion/tigon/shiro/service/support/AuthServiceSupport.java diff --git a/tigon-shiro/src/main/resources/spring/spring-tigon-shiro.xml b/tigon-shiro/src/main/resources/spring/spring-tigon-shiro.xml new file mode 100644 index 0000000..323ce58 --- /dev/null +++ b/tigon-shiro/src/main/resources/spring/spring-tigon-shiro.xml @@ -0,0 +1,24 @@ + + + Tigon Shiro Configuration + + + + + + + + + + + + + + + + + + diff --git a/tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/TestDriver.java b/tigon-shiro/src/test/java/me/chyxion/tigon/shiro/TestDriver.java similarity index 100% rename from tigon-shiro-spring-boot/src/test/java/me/chyxion/tigon/shiro/TestDriver.java rename to tigon-shiro/src/test/java/me/chyxion/tigon/shiro/TestDriver.java diff --git a/tigon-freemarker-support/src/test/resources/log4j.properties b/tigon-shiro/src/test/resources/log4j.properties similarity index 94% rename from tigon-freemarker-support/src/test/resources/log4j.properties rename to tigon-shiro/src/test/resources/log4j.properties index 270ed90..7c9201a 100644 --- a/tigon-freemarker-support/src/test/resources/log4j.properties +++ b/tigon-shiro/src/test/resources/log4j.properties @@ -1,4 +1,4 @@ -log4j.rootLogger=debug, console +log4j.rootLogger=${log.root} log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout diff --git a/tigon-webmvc-core/README.md b/tigon-web/README.md similarity index 100% rename from tigon-webmvc-core/README.md rename to tigon-web/README.md diff --git a/tigon-webmvc-core/pom.xml b/tigon-web/pom.xml similarity index 84% rename from tigon-webmvc-core/pom.xml rename to tigon-web/pom.xml index 0214f9e..75519d3 100644 --- a/tigon-webmvc-core/pom.xml +++ b/tigon-web/pom.xml @@ -5,10 +5,10 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - tigon-webmvc-core + tigon-web jar - Tigon Web MVC Core - Tigon Web MVC Core + Tigon Web + Tigon Web me.chyxion.tigon @@ -22,6 +22,10 @@ me.chyxion.tigon tigon-model
+ + org.springframework.boot + spring-boot-starter-web + org.aspectj aspectjrt @@ -36,7 +40,8 @@ org.springframework - spring-webmvc + spring-test + provided org.projectlombok @@ -48,20 +53,16 @@ javax.servlet-api provided + - org.springframework - spring-test + org.springframework.boot + spring-boot-starter-test provided - javax.el javax.el-api - test - - - junit - junit + 3.0.0 test diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/DefaultViewResolver.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/DefaultViewResolver.java similarity index 88% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/DefaultViewResolver.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/DefaultViewResolver.java index d01c27d..3c17909 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/DefaultViewResolver.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/DefaultViewResolver.java @@ -35,17 +35,17 @@ public class DefaultViewResolver implements ViewResolver, Ordered { */ @Override public View resolveViewName(String rawViewName, Locale locale) throws Exception { - log.debug("Base View Resolver Resolve View Name [{}].", rawViewName); + log.debug("Base view resolver resolve view name [{}].", rawViewName); // parse view name View view = null; if (rawViewName.startsWith(ResponseTool.PREFIX_DATA)) { String viewName = rawViewName.substring(ResponseTool.PREFIX_DATA.length()); - log.debug("Resolve View Name [{}] As JSON Data.", viewName); + log.debug("Resolve view name [{}] As JSON data.", viewName); view = new JSONView(new JSONViewDataModel(viewName), jsonViewConfig); } if (view == null) { - log.debug("No View Type Found, Render As JSON View [{}].", rawViewName); + log.debug("No view type found, render as JSON view [{}].", rawViewName); view = new JSONView(rawViewName, jsonViewConfig); } return view; diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONView.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONView.java similarity index 80% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONView.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONView.java index c132d31..7f3fb53 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONView.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONView.java @@ -1,12 +1,11 @@ package me.chyxion.tigon.webmvc; +import java.util.Map; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.support.spring.FastJsonJsonView; import lombok.extern.slf4j.Slf4j; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.Map; +import com.alibaba.fastjson.support.spring.FastJsonJsonView; /** * JSON View @@ -78,27 +77,44 @@ public class JSONView extends FastJsonJsonView { config.getDataKey(), config.getCodeKey(), config.getMessageKey()); } if (log.isDebugEnabled()) { - log.debug("Render JSON Response [{}].", JSON.toJSONString(dataResp, true)); + log.debug("Render JSON response [{}].", JSON.toJSONString(dataResp, true)); } return dataResp; } + /** + * Response json for any client accepts media + * @return content type + */ + @Override + public String getContentType() { + return "*/*"; + } + + /** + * {@inheritDoc} + */ + @Override + protected void setResponseContentType(HttpServletRequest request, HttpServletResponse response) { + response.setContentType(DEFAULT_CONTENT_TYPE); + } + private JSONViewDataModel buildDataModel(Map model) { - log.debug("Build Data Model From Map Model."); + log.debug("Build data model from map model."); Object objData = null; if (Boolean.TRUE.equals(model.get(MAP_DATA))) { objData = model.get(DATA_KEY); - log.debug("Render Map Data [{}].", objData); + log.debug("Render map data [{}].", objData); } else { // default bean name String beanName = getBeanName(); if (!requestURI.equals("/" + beanName)) { objData = beanName; - log.debug("Could Not Find Any Resource, Render As String Data [{}].", objData); + log.debug("Could not find any resource, render as string data [{}].", objData); } else { - log.debug("View Name Is Request URI, No Data To Response.."); + log.debug("View name is request URI, no data to response."); } } return new JSONViewDataModel(objData); diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONViewConfig.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONViewConfig.java similarity index 79% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONViewConfig.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONViewConfig.java index 87fff22..3351bc6 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONViewConfig.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONViewConfig.java @@ -18,13 +18,13 @@ import org.springframework.beans.factory.annotation.Autowired; @Slf4j @Getter public class JSONViewConfig { - @Value("${tigon.webmvc.jsonview.success_key:success}") + @Value("${tigon.webmvc.jsonview.success-key:success}") private String successKey; - @Value("${tigon.webmvc.jsonview.data_key:data}") + @Value("${tigon.webmvc.jsonview.data-key:data}") private String dataKey; - @Value("${tigon.webmvc.jsonview.code_key:errcode}") + @Value("${tigon.webmvc.jsonview.code-key:errcode}") private String codeKey; - @Value("${tigon.webmvc.jsonview.message_key:errmsg}") + @Value("${tigon.webmvc.jsonview.message-key:errmsg}") private String messageKey; @Autowired(required = false) private JSONViewDataModelAssembler dataModelAssembler; @@ -32,7 +32,7 @@ public class JSONViewConfig { // init json serialize config @PostConstruct void init() { - log.info("Init FastJSON Global Serialize Config To Serialize ViewModelable."); + log.info("Init FastJSON global serialize config to serialize view modelable."); final SerializeConfig serializeConfig = SerializeConfig.getGlobalInstance(); final ViewModelableSerializer viewModelableSerializer = new ViewModelableSerializer(); serializeConfig.put(ViewModel.class, viewModelableSerializer); diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModel.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModel.java similarity index 75% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModel.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModel.java index eae7e7b..92e9a1b 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModel.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModel.java @@ -3,13 +3,10 @@ package me.chyxion.tigon.webmvc; import lombok.Getter; import java.util.Map; import java.util.HashMap; -import me.chyxion.tigon.model.Mappable; /** - * @version 0.0.4 - * @since 0.0.1 - * @author Donghuang
- * donghuang@wacai.com
+ * @author Shaun Chyxion
+ * chyxion@163.com
* Sep 21, 2014 8:32:06 PM */ public class JSONViewDataModel { @@ -91,38 +88,22 @@ public class JSONViewDataModel { */ @SuppressWarnings("unchecked") public Map toMap( - final String successKey, - final String dataKey, - final String codeKey, - final String messageKey) { + final String successKey, + final String dataKey, + final String codeKey, + final String messageKey) { - Map mapData = null; - if (data instanceof Map) { - mapData = (Map) data; - } - else if (data instanceof Mappable) { - mapData = ((Mappable) data).toMap(); - } - else { - mapData = new HashMap(); - if (data != null) { - mapData.put(dataKey, data); - } - } - // attrs + final Map mapData = new HashMap<>(); if (attrs != null) { mapData.putAll(attrs); } - // success - if (!mapData.containsKey(successKey)) { - mapData.put(successKey, success); - if (!success) { - mapData.put(messageKey, getMessageOrExceptionMessage()); - } + if (data != null) { + mapData.put(dataKey, data); } - // code - if (!mapData.containsKey(codeKey)) { - mapData.put(codeKey, code); + mapData.put(successKey, success); + mapData.put(codeKey, code); + if (!success) { + mapData.put(messageKey, getMessageOrExceptionMessage()); } return mapData; } diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModelAssembler.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModelAssembler.java similarity index 100% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModelAssembler.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/JSONViewDataModelAssembler.java diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/ResourceModel.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/ResourceModel.java similarity index 64% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/ResourceModel.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/ResourceModel.java index ebda0b5..0403e06 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/ResourceModel.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/ResourceModel.java @@ -1,11 +1,11 @@ package me.chyxion.tigon.webmvc; import java.io.File; -import org.slf4j.Logger; +import lombok.Getter; import java.io.IOException; import java.io.InputStream; import java.net.URLConnection; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.util.Assert; import org.springframework.http.MediaType; import org.springframework.core.io.Resource; @@ -21,21 +21,21 @@ import org.springframework.core.io.InputStreamResource; * chyxion@163.com
* Jan 16, 2015 5:33:30 PM */ +@Slf4j +@Getter public class ResourceModel { - private static final Logger log = - LoggerFactory.getLogger(ResourceModel.class); private String contentType; private long contentLength; private String name; private Resource resource; - public ResourceModel(Resource resource, + public ResourceModel(final Resource resource, String contentType, long contentLength, String name) throws IOException { - Assert.notNull(resource); + Assert.notNull(resource, "Resource model resource could not be null"); Assert.state(!(InputStreamResource.class == resource.getClass() && contentLength <= 0), - "Input Stream Resource Content Length Must Provide."); + "Input stream resource content length must provide."); this.resource = resource; this.contentType = contentType; this.contentLength = contentLength > 0 ? @@ -43,63 +43,32 @@ public class ResourceModel { this.name = name; } - public ResourceModel(File file, String contentType, String name) { + public ResourceModel(final File file, final String contentType, final String name) { this.resource = new FileSystemResource(file); this.contentType = contentType; this.contentLength = file.length(); this.name = StringUtils.defaultIfBlank(name, file.getName()); } - public ResourceModel(InputStream inputStream, + public ResourceModel(final InputStream inputStream, String contentType, long contentLength, String name) { - Assert.notNull(inputStream); + Assert.notNull(inputStream, "Resource model input stream could not be null"); Assert.state(contentLength > 0, - "Input Stream Resource Content Length Must Provide."); + "Input stream resource content length must provide."); this.contentType = contentType; this.contentLength = contentLength; this.resource = new InputStreamResource(inputStream); + this.name = name; } public ResourceModel(byte[] data, String contentType, String name) { - Assert.notNull(data); + Assert.notNull(data, "Resource model data could not be null"); this.resource = new ByteArrayResource(data); this.contentType = contentType; this.contentLength = data.length; this.name = name; } - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - * @return - */ - public ResourceModel setName(String name) { - this.name = name; - return this; - } - - /** - * @return the resource - */ - public Resource getResource() { - return resource; - } - - /** - * @param resource the resource to set - * @return - */ - public ResourceModel setResource(Resource resource) { - this.resource = resource; - return this; - } - /** * @return the contentType */ @@ -119,21 +88,4 @@ public class ResourceModel { } return contentType; } - - /** - * @param contentType the contentType to set - * @return - */ - public ResourceModel setContentType(String contentType) { - this.contentType = contentType; - return this; - } - - /** - * @return the contentLength - * @throws IOException - */ - public long getContentLength() throws IOException { - return contentLength; - } } diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAdvice.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAdvice.java similarity index 95% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAdvice.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAdvice.java index e94c044..ebd2506 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAdvice.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAdvice.java @@ -1,17 +1,15 @@ package me.chyxion.tigon.webmvc; +import java.util.List; import lombok.extern.slf4j.Slf4j; -import me.chyxion.tigon.webmvc.exception.ExceptionResolver; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Controller; +import org.springframework.web.servlet.ModelAndView; +import me.chyxion.tigon.webmvc.exception.ExceptionResolver; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.ModelAndView; - -import java.util.List; /** * @since 0.0.1 @@ -20,7 +18,7 @@ import java.util.List; * Jul 18, 2014 8:50:17 AM */ @Slf4j -@Order(Ordered.LOWEST_PRECEDENCE) +@Order @ControllerAdvice(annotations = {Controller.class, RestController.class}) public class TigonControllerAdvice { diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAspect.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAspect.java similarity index 94% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAspect.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAspect.java index db93966..5e94d03 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAspect.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonControllerAspect.java @@ -1,14 +1,13 @@ package me.chyxion.tigon.webmvc; +import java.util.Map; +import java.util.HashMap; import com.alibaba.fastjson.JSON; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; - -import java.util.HashMap; -import java.util.Map; +import org.aspectj.lang.annotation.AfterReturning; /** * process return map @@ -45,7 +44,7 @@ public class TigonControllerAspect { public void afterReturning(JoinPoint jp, Object result) { if (result instanceof Map) { if (log.isDebugEnabled()) { - log.debug("Controller Aspect After Returning, Return Map [{}].", JSON.toJSON(result)); + log.debug("Controller aspect after returning, return map [{}].", JSON.toJSON(result)); } @SuppressWarnings("unchecked") Map mapRtn = (Map) result; diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonReturnValueHandler.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonReturnValueHandler.java similarity index 60% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonReturnValueHandler.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonReturnValueHandler.java index 20dc884..27aa75e 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonReturnValueHandler.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonReturnValueHandler.java @@ -1,17 +1,23 @@ package me.chyxion.tigon.webmvc; import java.io.File; -import org.slf4j.Logger; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.net.URLEncoder; -import org.slf4j.LoggerFactory; -import org.springframework.http.*; +import java.util.Collection; +import lombok.extern.slf4j.Slf4j; +import me.chyxion.tigon.model.Mappable; +import org.springframework.util.ClassUtils; +import org.springframework.http.MediaType; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpHeaders; import org.apache.commons.lang3.StringUtils; import org.springframework.core.io.Resource; -import org.apache.commons.lang3.CharEncoding; +import org.springframework.http.ResponseEntity; import org.springframework.core.MethodParameter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.http.converter.ResourceHttpMessageConverter; @@ -19,19 +25,23 @@ import org.springframework.web.method.support.HandlerMethodReturnValueHandler; import org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor; /** - * @author Shaun Chyxion
- * chyxion@163.com
- * Mar 19, 2017 11:32:22 + * @version 0.0.4 + * @since 0.0.1 + * @author Donghuang
+ * donghuang@wacai.com
+ * Jul 16, 2014 10:03:15 PM */ +@Slf4j public class TigonReturnValueHandler implements HandlerMethodReturnValueHandler { - private static final Logger log = - LoggerFactory.getLogger(TigonReturnValueHandler.class); + + @Value("${tigon.webmvc.jsonview.null-jsonarray-as-empty:true}") + private boolean writeNullJsonArrayAsEmpty; @Autowired private JSONViewConfig jsonViewConfig; private HttpEntityMethodProcessor httpEntityProcessor = - new HttpEntityMethodProcessor(Arrays.>asList( + new HttpEntityMethodProcessor(Arrays.asList( new ResourceHttpMessageConverter())); /** @@ -50,18 +60,31 @@ public class TigonReturnValueHandler MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { - log.debug("Return Value Handler, Handle Return Value [{}], Return Type [{}].", - returnValue, returnType); + log.debug("Return value handler, handle return value [{}], return type [{}].", + returnValue, returnType); if (!handleResource(returnValue, returnType, mavContainer, webRequest)) { - JSONViewDataModel model = null; + final JSONViewDataModel model; if (returnValue instanceof JSONViewDataModel) { - log.debug("Controller Return Value Is JSONViewDataModel, Return."); + log.debug("Controller return value is JSONViewDataModel, return."); model = (JSONViewDataModel) returnValue; } + else if (returnValue instanceof Mappable) { + log.debug("Controller return value is mappable, call #toMap."); + model = new JSONViewDataModel(((Mappable) returnValue).toMap()); + } else { - log.debug("Wrap Controller Return Value To Data Model."); - model = new JSONViewDataModel(returnValue); + final Class returnTypeClass = returnType.getMethod().getReturnType(); + if (writeNullJsonArrayAsEmpty && returnValue == null && + (returnTypeClass.isArray() || + ClassUtils.isAssignable(Collection.class, returnTypeClass))) { + log.info("Wrap controller return null collection to data model."); + model = new JSONViewDataModel(new Object[0]); + } + else { + log.debug("Wrap controller return value to data model."); + model = new JSONViewDataModel(returnValue); + } } mavContainer.setView(new JSONView(model, jsonViewConfig)); } @@ -84,33 +107,33 @@ public class TigonReturnValueHandler ResourceModel resourceModel = null; HttpEntity entity = null; if (returnValue instanceof ResourceModel) { - log.debug("Found Download Model Return."); + log.debug("Found download model return."); resourceModel = (ResourceModel) returnValue; } else if (returnValue instanceof HttpEntity) { - log.debug("Found HttpEntity Return."); + log.debug("Found http entity return."); entity = (HttpEntity) returnValue; } else if (returnValue instanceof File) { - log.debug("Found File [{}] Return.", returnValue); + log.debug("Found file [{}] return.", returnValue); resourceModel = new ResourceModel((File) returnValue, null, null); } else if (returnValue instanceof Resource) { - log.debug("Found Resouce [{}] Return.", returnValue); + log.debug("Found resource [{}] return.", returnValue); resourceModel = new ResourceModel((Resource) returnValue, null, 0, null); } else if (returnValue instanceof byte[]) { - log.debug("Found Byte Array Return."); + log.debug("Found byte array return."); resourceModel = new ResourceModel((byte[]) returnValue, null, null); } // assemble http entity if (resourceModel != null) { - HttpHeaders headers = new HttpHeaders(); + final HttpHeaders headers = new HttpHeaders(); String name = resourceModel.getName(); if (StringUtils.isNotBlank(name)) { - log.info("Found Resource Name [{}], Set Content-Disposition Header.", name); - name = URLEncoder.encode(name, CharEncoding.UTF_8); - StringBuilder sbDispo = + log.info("Found resource name [{}], set Content-Disposition header.", name); + name = URLEncoder.encode(name, StandardCharsets.UTF_8.name()); + final StringBuilder sbDispo = new StringBuilder("attachment; filename=\"") .append(name) .append("\"; filename*=utf-8''") @@ -121,7 +144,7 @@ public class TigonReturnValueHandler headers.setContentType( MediaType.valueOf(resourceModel.getContentType())); headers.setContentLength(resourceModel.getContentLength()); - entity = new ResponseEntity( + entity = new ResponseEntity<>( resourceModel.getResource(), headers, HttpStatus.OK); } boolean handled = false; diff --git a/tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonWebConfiguration.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonWebConfiguration.java new file mode 100644 index 0000000..73361ee --- /dev/null +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/TigonWebConfiguration.java @@ -0,0 +1,95 @@ +package me.chyxion.tigon.webmvc; + +import java.util.List; +import java.util.Collections; +import java.nio.charset.StandardCharsets; +import org.springframework.http.MediaType; +import org.springframework.context.annotation.Bean; +import org.springframework.format.FormatterRegistry; +import com.alibaba.fastjson.serializer.SerializerFeature; +import org.springframework.web.servlet.config.annotation.*; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.http.converter.StringHttpMessageConverter; +import me.chyxion.tigon.webmvc.formatter.TrimAnnotationFormatterFactory; +import me.chyxion.tigon.webmvc.converter.StringToJSONArrayTypeConverter; +import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4; +import me.chyxion.tigon.webmvc.converter.StringToJSONObjectTypeConverter; +import org.springframework.web.method.support.HandlerMethodReturnValueHandler; +import me.chyxion.tigon.webmvc.formatter.EmptyToNullAnnotationFormatterFactory; +import org.springframework.format.number.NumberFormatAnnotationFormatterFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Mar 01, 2017 10:35:14 + */ +@EnableWebMvc +@Configuration +@EnableAspectJAutoProxy +@ConditionalOnWebApplication +@ImportResource("classpath*:spring/spring-*.xml") +public class TigonWebConfiguration implements WebMvcConfigurer { + + /** + * {@inheritDoc} + */ + @Override + public void addFormatters(final FormatterRegistry registry) { + // converters + registry.addConverter(new StringToJSONObjectTypeConverter()); + registry.addConverter(new StringToJSONArrayTypeConverter()); + + // formatters + registry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory()); + registry.addFormatterForFieldAnnotation(new EmptyToNullAnnotationFormatterFactory()); + registry.addFormatterForFieldAnnotation(new TrimAnnotationFormatterFactory()); + } + + /** + * {@inheritDoc} + */ + @Override + public void addReturnValueHandlers( + final List returnValueHandlers) { + returnValueHandlers.add(returnValueHandler()); + } + + @Bean + public HandlerMethodReturnValueHandler returnValueHandler() { + return new TigonReturnValueHandler(); + } + + /** + * {@inheritDoc} + */ + @Override + public void configurePathMatch(final PathMatchConfigurer configurer) { + configurer.setUseSuffixPatternMatch(false); + configurer.setUseRegisteredSuffixPatternMatch(false); + } + + /** + * {@inheritDoc} + */ + @Override + public void configureMessageConverters( + List> converters) { + converters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); + final FastJsonHttpMessageConverter4 fastJsonMessageConverter = + new FastJsonHttpMessageConverter4(); + fastJsonMessageConverter.setSupportedMediaTypes( + Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); + + fastJsonMessageConverter.getFastJsonConfig() + .setSerializerFeatures( + SerializerFeature.WriteMapNullValue, + SerializerFeature.WriteNullListAsEmpty, + SerializerFeature.WriteNullBooleanAsFalse); + + converters.add(fastJsonMessageConverter); + } +} diff --git a/tigon-web/src/main/java/me/chyxion/tigon/webmvc/annotation/CriterionCol.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/annotation/CriterionCol.java new file mode 100644 index 0000000..8a0b7cb --- /dev/null +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/annotation/CriterionCol.java @@ -0,0 +1,33 @@ +package me.chyxion.tigon.webmvc.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Documented; +import java.lang.annotation.RetentionPolicy; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Jun 26, 2018 17:58:20 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +public @interface CriterionCol { + + /** + * http request param name + * @return http request param + */ + String param(); + + /** + * database table col + * @return database table col + */ + String col(); + + /** + * database table col java type + * @return database table col java type + */ + Class type(); +} diff --git a/tigon-web/src/main/java/me/chyxion/tigon/webmvc/annotation/ListApi.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/annotation/ListApi.java new file mode 100644 index 0000000..5e29c88 --- /dev/null +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/annotation/ListApi.java @@ -0,0 +1,32 @@ +package me.chyxion.tigon.webmvc.annotation; + +import java.lang.annotation.*; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Jun 26, 2018 17:57:46 + */ +@Documented +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface ListApi { + + /** + * search cols + * @return search cols + */ + String[] searchCols() default {}; + + /** + * order cols + * @return order cols + */ + OrderCol[] orderCols() default {}; + + /** + * criterion cols + * @return criterion cols + */ + CriterionCol[] criterionCols() default {}; +} diff --git a/tigon-web/src/main/java/me/chyxion/tigon/webmvc/annotation/OrderCol.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/annotation/OrderCol.java new file mode 100644 index 0000000..a664022 --- /dev/null +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/annotation/OrderCol.java @@ -0,0 +1,27 @@ +package me.chyxion.tigon.webmvc.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.Documented; +import java.lang.annotation.RetentionPolicy; + +/** + * @author Shaun Chyxion
+ * chyxion@163.com
+ * Jun 26, 2018 17:58:09 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +public @interface OrderCol { + + /** + * http request param + * @return http request param + */ + String param(); + + /** + * database table col + * @return database table col + */ + String col(); +} diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONArrayTypeConverter.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONArrayTypeConverter.java similarity index 87% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONArrayTypeConverter.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONArrayTypeConverter.java index 34c2271..eeac1da 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONArrayTypeConverter.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONArrayTypeConverter.java @@ -20,14 +20,14 @@ public class StringToJSONArrayTypeConverter * {@inheritDoc} */ @Override - public JSONArray convert(String text) { + public JSONArray convert(final String text) { try { return StringUtils.isNotBlank(text) ? JSON.parseArray(text) : null; } catch (JSONException e) { throw new IllegalArgumentException( - "Invalid JSONArray [" + text + "] Param", e); + "Invalid JSONArray [" + text + "] param", e); } } } diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONObjectTypeConverter.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONObjectTypeConverter.java similarity index 86% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONObjectTypeConverter.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONObjectTypeConverter.java index df8b00b..2ea813d 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONObjectTypeConverter.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/converter/StringToJSONObjectTypeConverter.java @@ -20,14 +20,14 @@ public class StringToJSONObjectTypeConverter * {@inheritDoc} */ @Override - public JSONObject convert(String text) { + public JSONObject convert(final String text) { try { return StringUtils.isNotBlank(text) ? JSON.parseObject(text) : null; } catch (JSONException e) { throw new IllegalArgumentException( - "Invalid JSONObject [" + text + "] Param", e); + "Invalid JSONObject [" + text + "] param", e); } } } diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/BaseExceptionResolver.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/BaseExceptionResolver.java similarity index 100% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/BaseExceptionResolver.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/BaseExceptionResolver.java diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/BindingResultResolver.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/BindingResultResolver.java similarity index 100% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/BindingResultResolver.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/BindingResultResolver.java diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/ConstraintViolationExceptionResolver.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/ConstraintViolationExceptionResolver.java similarity index 82% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/ConstraintViolationExceptionResolver.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/ConstraintViolationExceptionResolver.java index a7879fa..a4c3bf9 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/ConstraintViolationExceptionResolver.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/ConstraintViolationExceptionResolver.java @@ -2,9 +2,8 @@ package me.chyxion.tigon.webmvc.exception; import java.util.Set; import java.util.List; -import org.slf4j.Logger; import java.util.ArrayList; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import javax.validation.ConstraintViolation; import org.springframework.core.annotation.Order; import me.chyxion.tigon.webmvc.JSONViewDataModel; @@ -18,16 +17,15 @@ import me.chyxion.tigon.exception.InvalidParamException; * chyxion@163.com
* Mar 28, 2016 6:39:36 PM */ +@Slf4j @Order(10) public class ConstraintViolationExceptionResolver implements ExceptionResolver { - private static final Logger log = - LoggerFactory.getLogger(ConstraintViolationExceptionResolver.class); /** * {@inheritDoc} */ @Override - public boolean accept(Throwable ex) { + public boolean accept(final Throwable ex) { return ex instanceof ConstraintViolationException; } @@ -40,7 +38,7 @@ public class ConstraintViolationExceptionResolver implements ExceptionResolver { ((ConstraintViolationException) model.getException()).getConstraintViolations(); final List messages = new ArrayList(cvs.size()); for (ConstraintViolation cv : cvs) { - log.info("Constraint Violation [{}] Caused.", cv); + log.info("Constraint violation [{}] Caused.", cv); messages.add("'" + cv.getPropertyPath() + "' " + cv.getMessage()); } model.setCode(InvalidParamException.CODE); diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/DefaultExceptionResolver.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/DefaultExceptionResolver.java similarity index 69% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/DefaultExceptionResolver.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/DefaultExceptionResolver.java index b2c7c06..95d3f72 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/DefaultExceptionResolver.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/DefaultExceptionResolver.java @@ -22,8 +22,8 @@ import org.springframework.web.bind.MissingServletRequestParameterException; * chyxion@163.com
* Feb 3, 2015 2:06:58 PM */ -@Order(64) @Slf4j +@Order(64) public class DefaultExceptionResolver implements ExceptionResolver { @Autowired(required = false) private ExceptionMessage exceptionMessage; @@ -33,32 +33,6 @@ public class DefaultExceptionResolver implements ExceptionResolver { private static final long serialVersionUID = 1L; { // Database Exceptions -// put(CannotAcquireLockException.class, 5030); -// put(CannotSerializeTransactionException.class, 5031); -// put(CleanupFailureDataAccessException.class, 5032); -// put(ConcurrencyFailureException.class, 5033); -// put(DataAccessException.class, 5034); -// put(DataAccessResourceFailureException.class, 5035); -// put(DataIntegrityViolationException.class, 5036); -// put(DataRetrievalFailureException.class, 5037); -// put(DeadlockLoserDataAccessException.class, 5038); -// put(DuplicateKeyException.class, 5039); -// put(EmptyResultDataAccessException.class, 5040); -// put(IncorrectResultSizeDataAccessException.class, 5041); -// put(IncorrectUpdateSemanticsDataAccessException.class, 5042); -// put(InvalidDataAccessApiUsageException.class, 5043); -// put(InvalidDataAccessResourceUsageException.class, 5044); -// put(NonTransientDataAccessException.class, 5045); -// put(NonTransientDataAccessResourceException.class, 5046); -// put(OptimisticLockingFailureException.class, 5047); -// put(PermissionDeniedDataAccessException.class, 5048); -// put(PessimisticLockingFailureException.class, 5049); -// put(QueryTimeoutException.class, 5050); -// put(RecoverableDataAccessException.class, 5051); -// put(TransientDataAccessException.class, 5052); -// put(TransientDataAccessResourceException.class, 5053); -// put(TypeMismatchDataAccessException.class, 5054); -// put(UncategorizedDataAccessException.class, 5055); // 4002 put(IllegalStateException.class, InvalidStateException.CODE); put(ConversionFailedException.class, InvalidStateException.CODE); diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/ExceptionMessage.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/ExceptionMessage.java similarity index 100% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/ExceptionMessage.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/ExceptionMessage.java diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/ExceptionResolver.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/ExceptionResolver.java similarity index 100% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/exception/ExceptionResolver.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/exception/ExceptionResolver.java diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullAnnotationFormatterFactory.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullAnnotationFormatterFactory.java similarity index 100% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullAnnotationFormatterFactory.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullAnnotationFormatterFactory.java diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullFormatter.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullFormatter.java similarity index 84% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullFormatter.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullFormatter.java index 363c109..a7831d3 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullFormatter.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/EmptyToNullFormatter.java @@ -1,7 +1,6 @@ package me.chyxion.tigon.webmvc.formatter; import java.util.Locale; -import java.text.ParseException; import org.apache.commons.lang3.StringUtils; import org.springframework.format.Formatter; @@ -26,7 +25,7 @@ public class EmptyToNullFormatter implements Formatter { * {@inheritDoc} */ @Override - public String parse(String text, Locale locale) throws ParseException { + public String parse(String text, Locale locale) { return StringUtils.isNotEmpty(text) ? text : null; } } diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimAnnotationFormatterFactory.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimAnnotationFormatterFactory.java similarity index 100% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimAnnotationFormatterFactory.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimAnnotationFormatterFactory.java diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimFormatter.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimFormatter.java similarity index 73% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimFormatter.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimFormatter.java index 75ef009..7caa549 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimFormatter.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/formatter/TrimFormatter.java @@ -1,7 +1,6 @@ package me.chyxion.tigon.webmvc.formatter; import java.util.Locale; -import java.text.ParseException; import org.springframework.format.Formatter; import org.apache.commons.lang3.StringUtils; @@ -24,7 +23,7 @@ public class TrimFormatter implements Formatter { * {@inheritDoc} */ @Override - public String parse(String text, Locale locale) throws ParseException { - return StringUtils.isNotEmpty(text) ? text.trim() : null; + public String parse(String text, Locale locale) { + return StringUtils.trim(text); } } diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/test/ControllerTestTool.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/test/ControllerTestTool.java similarity index 93% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/test/ControllerTestTool.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/test/ControllerTestTool.java index 7e04d25..6c17b1c 100644 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/test/ControllerTestTool.java +++ b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/test/ControllerTestTool.java @@ -6,8 +6,8 @@ import com.alibaba.fastjson.JSON; import javax.annotation.PostConstruct; import org.springframework.util.Assert; import com.alibaba.fastjson.JSONObject; +import java.nio.charset.StandardCharsets; import org.springframework.http.MediaType; -import org.apache.commons.lang3.CharEncoding; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultActions; @@ -21,7 +21,7 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; /** - * Controler Test Tool + * Controller Test Tool * @version 0.1 * @author Shaun Chyxion
* chyxion@163.com
@@ -140,13 +140,13 @@ public final class ControllerTestTool { v = ((JSONObject) v).get(p); } } - Assert.isTrue(value.equals(v)); + Assert.isTrue(value.equals(v), "Assert failed"); } }); } catch (Exception e) { throw new IllegalStateException( - "Assert Mock HTTP Request JSON Result Value Error Caused", e); + "Assert mock http request JSON result value error caused", e); } } @@ -157,7 +157,7 @@ public final class ControllerTestTool { } catch (Exception e) { throw new IllegalStateException( - "Assert Mock HTTP Request Forward Error Caused", e); + "Assert Mock HTTP Request Forward Error Caused", e); } } @@ -173,13 +173,13 @@ public final class ControllerTestTool { ResultActions request( MockHttpServletRequestBuilder requestBuilder) { - requestBuilder.characterEncoding(CharEncoding.UTF_8); + requestBuilder.characterEncoding(StandardCharsets.UTF_8.name()); try { return mvc.perform(requestBuilder); } catch (Exception e) { throw new IllegalStateException( - "Mock HTTP Request Error Caused", e); + "Mock HTTP Request Error Caused", e); } } } diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/util/ResponseTool.java b/tigon-web/src/main/java/me/chyxion/tigon/webmvc/util/ResponseTool.java similarity index 100% rename from tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/util/ResponseTool.java rename to tigon-web/src/main/java/me/chyxion/tigon/webmvc/util/ResponseTool.java diff --git a/tigon-jsp-support/src/test/resources/spring/.gitkeep b/tigon-web/src/main/resources/.gitkeep similarity index 100% rename from tigon-jsp-support/src/test/resources/spring/.gitkeep rename to tigon-web/src/main/resources/.gitkeep diff --git a/tigon-shiro-spring-boot/src/main/resources/META-INF/spring.factories b/tigon-web/src/main/resources/META-INF/spring.factories similarity index 58% rename from tigon-shiro-spring-boot/src/main/resources/META-INF/spring.factories rename to tigon-web/src/main/resources/META-INF/spring.factories index c8a9d29..f85b20a 100644 --- a/tigon-shiro-spring-boot/src/main/resources/META-INF/spring.factories +++ b/tigon-web/src/main/resources/META-INF/spring.factories @@ -1,2 +1,2 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -me.chyxion.tigon.shiro.TigonShiroConfig +me.chyxion.tigon.webmvc.TigonWebConfiguration diff --git a/tigon-webmvc-core/src/main/resources/spring/spring-summer-webmvc-core.xml b/tigon-web/src/main/resources/spring/spring-tigon-web.xml similarity index 54% rename from tigon-webmvc-core/src/main/resources/spring/spring-summer-webmvc-core.xml rename to tigon-web/src/main/resources/spring/spring-tigon-web.xml index 6aa626d..460e745 100644 --- a/tigon-webmvc-core/src/main/resources/spring/spring-summer-webmvc-core.xml +++ b/tigon-web/src/main/resources/spring/spring-tigon-web.xml @@ -15,19 +15,4 @@ - - - - - - - - - - - - - - - diff --git a/tigon-webmvc-core/src/test/java/me/chyxion/tigon/webmvc/test/TestDriver.java b/tigon-web/src/test/java/me/chyxion/tigon/webmvc/test/TestDriver.java similarity index 100% rename from tigon-webmvc-core/src/test/java/me/chyxion/tigon/webmvc/test/TestDriver.java rename to tigon-web/src/test/java/me/chyxion/tigon/webmvc/test/TestDriver.java diff --git a/tigon-webmvc-core/src/test/resources/i18n/messages.properties b/tigon-web/src/test/resources/i18n/messages.properties similarity index 100% rename from tigon-webmvc-core/src/test/resources/i18n/messages.properties rename to tigon-web/src/test/resources/i18n/messages.properties diff --git a/tigon-shiro-spring-boot/src/test/resources/log4j2.xml b/tigon-web/src/test/resources/log4j2.xml similarity index 100% rename from tigon-shiro-spring-boot/src/test/resources/log4j2.xml rename to tigon-web/src/test/resources/log4j2.xml diff --git a/tigon-webmvc-core/src/test/resources/spring/config.properties b/tigon-web/src/test/resources/spring/config.properties similarity index 100% rename from tigon-webmvc-core/src/test/resources/spring/config.properties rename to tigon-web/src/test/resources/spring/config.properties diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonHandlerInterceptor.java b/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonHandlerInterceptor.java deleted file mode 100644 index 8087bc7..0000000 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonHandlerInterceptor.java +++ /dev/null @@ -1,29 +0,0 @@ -package me.chyxion.tigon.webmvc; - -import org.springframework.util.PathMatcher; -import org.springframework.web.servlet.HandlerInterceptor; - -/** - * @version 0.0.2 - * @since 0.0.1 - * @author Donghuang
- * donghuang@wacai.com
- * Jul 16, 2014 10:07:52 PM - */ -public interface TigonHandlerInterceptor extends HandlerInterceptor { - - /** - * @return include path patterns - */ - String[] includePathPatterns(); - - /** - * @return exinclude path patterns - */ - String[] excludePathPatterns(); - - /** - * @return path matcher - */ - PathMatcher pathMatcher(); -} diff --git a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonWebMvcConfiguration.java b/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonWebMvcConfiguration.java deleted file mode 100644 index 929380b..0000000 --- a/tigon-webmvc-core/src/main/java/me/chyxion/tigon/webmvc/TigonWebMvcConfiguration.java +++ /dev/null @@ -1,175 +0,0 @@ -package me.chyxion.tigon.webmvc; - -import java.util.List; -import java.util.Locale; -import java.util.Collections; -import java.nio.charset.Charset; -import lombok.extern.slf4j.Slf4j; -import org.springframework.util.Assert; -import org.springframework.http.MediaType; -import org.springframework.util.PathMatcher; -import javax.servlet.http.HttpServletRequest; -import org.apache.commons.lang3.CharEncoding; -import org.springframework.validation.Validator; -import org.springframework.context.annotation.Bean; -import org.springframework.web.servlet.ViewResolver; -import org.springframework.format.FormatterRegistry; -import org.springframework.web.servlet.LocaleResolver; -import com.alibaba.fastjson.serializer.SerializerFeature; -import org.springframework.web.servlet.config.annotation.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; -import me.chyxion.tigon.webmvc.formatter.TrimAnnotationFormatterFactory; -import me.chyxion.tigon.webmvc.converter.StringToJSONArrayTypeConverter; -import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4; -import me.chyxion.tigon.webmvc.converter.StringToJSONObjectTypeConverter; -import org.springframework.web.method.support.HandlerMethodReturnValueHandler; -import me.chyxion.tigon.webmvc.formatter.EmptyToNullAnnotationFormatterFactory; -import org.springframework.format.number.NumberFormatAnnotationFormatterFactory; - -/** - * @author Shaun Chyxion
- * chyxion@163.com
- * Mar 01, 2017 10:35:14 - */ -@Slf4j -public class TigonWebMvcConfiguration extends WebMvcConfigurationSupport { - @Autowired - private Validator validator; - @Autowired - private List viewResolvers; - @Autowired(required = false) - private List handlerInterceptors; - - /** - * {@inheritDoc} - */ - @Override - public void addFormatters(FormatterRegistry registry) { - super.addFormatters(registry); - // converters - registry.addConverter(new StringToJSONObjectTypeConverter()); - registry.addConverter(new StringToJSONArrayTypeConverter()); - - // formatters - registry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory()); - registry.addFormatterForFieldAnnotation(new EmptyToNullAnnotationFormatterFactory()); - registry.addFormatterForFieldAnnotation(new TrimAnnotationFormatterFactory()); - } - - /** - * {@inheritDoc} - */ - @Override - public void addInterceptors(InterceptorRegistry registry) { - super.addInterceptors(registry); - // custom interceptors - if (handlerInterceptors != null && - !handlerInterceptors.isEmpty()) { - for (TigonHandlerInterceptor handlerInterceptor : handlerInterceptors) { - log.info("Re"); - final String[] includePathPatterns = handlerInterceptor.includePathPatterns(); - Assert.state(includePathPatterns != null && includePathPatterns.length > 0, - "Handler Interceptor 'includePathPatterns' Could Not Be Empty"); - final InterceptorRegistration interceptorRegistration = - registry.addInterceptor(handlerInterceptor) - .addPathPatterns(includePathPatterns); - final String[] excludePathPatterns = - handlerInterceptor.excludePathPatterns(); - if (excludePathPatterns != null && excludePathPatterns.length > 0) { - interceptorRegistration.excludePathPatterns(excludePathPatterns); - } - final PathMatcher pathMatcher = handlerInterceptor.pathMatcher(); - if (pathMatcher != null) { - interceptorRegistration - .pathMatcher(pathMatcher); - } - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public void addReturnValueHandlers( - List returnValueHandlers) { - returnValueHandlers.add(returnValueHandler()); - super.addReturnValueHandlers(returnValueHandlers); - } - - @Bean - public HandlerMethodReturnValueHandler returnValueHandler() { - return new TigonReturnValueHandler(); - } - - /** - * {@inheritDoc} - */ - @Override - public void configurePathMatch(PathMatchConfigurer configurer) { - configurer.setUseSuffixPatternMatch(false); - configurer.setUseRegisteredSuffixPatternMatch(false); - super.configurePathMatch(configurer); - } - - /** - * {@inheritDoc} - */ - @Override - public void configureMessageConverters( - List> converters) { - converters.add(new StringHttpMessageConverter(Charset.forName(CharEncoding.UTF_8))); - FastJsonHttpMessageConverter4 fastJsonMessageConverter = - new FastJsonHttpMessageConverter4(); - fastJsonMessageConverter.setSupportedMediaTypes( - Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); - - fastJsonMessageConverter.getFastJsonConfig() - .setSerializerFeatures( - SerializerFeature.WriteMapNullValue, - SerializerFeature.WriteNullListAsEmpty, - SerializerFeature.WriteNullBooleanAsFalse); - - converters.add(fastJsonMessageConverter); - super.configureMessageConverters(converters); - } - - /** - * {@inheritDoc} - */ - @Override - public void configureViewResolvers(ViewResolverRegistry registry) { - for (ViewResolver viewResolver : viewResolvers) { - log.info("Register View Resolver [{}].", viewResolver); - registry.viewResolver(viewResolver); - } - registry.enableContentNegotiation(false); - super.configureViewResolvers(registry); - } - - /** - * {@inheritDoc} - */ - @Override - public Validator getValidator() { - return validator; - } - - @Bean - public LocaleResolver localeResolver() { - return new CookieLocaleResolver() { - private LocaleResolver acceptHeaderLocaleResolver = - new AcceptHeaderLocaleResolver(); - @Override - public Locale resolveLocale(HttpServletRequest request) { - Locale locale = super.determineDefaultLocale(request); - return locale != null ? - locale : acceptHeaderLocaleResolver.resolveLocale(request); - } - }; - } -} diff --git a/tigon-webmvc-core/src/main/resources/.gitkeep b/tigon-webmvc-core/src/main/resources/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tigon-webmvc-core/src/test/resources/log4j2.xml b/tigon-webmvc-core/src/test/resources/log4j2.xml deleted file mode 100644 index 166de45..0000000 --- a/tigon-webmvc-core/src/test/resources/log4j2.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - %-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n - .logs - DEBUG - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tigon-webmvc-spring-boot/README.md b/tigon-webmvc-spring-boot/README.md deleted file mode 100644 index 12edb4c..0000000 --- a/tigon-webmvc-spring-boot/README.md +++ /dev/null @@ -1 +0,0 @@ -# tigon-webmvc diff --git a/tigon-webmvc-spring-boot/pom.xml b/tigon-webmvc-spring-boot/pom.xml deleted file mode 100644 index 944212e..0000000 --- a/tigon-webmvc-spring-boot/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - 4.0.0 - tigon-webmvc-spring-boot - jar - Tigon Web MVC Spring Boot - Tigon Web MVC Spring Boot - - - me.chyxion.tigon - tigon - 0.0.1-SNAPSHOT - ../ - - - - - org.springframework.boot - spring-boot-starter-web - - - me.chyxion.tigon - tigon-webmvc-core - - - org.projectlombok - lombok - provided - - - javax.servlet - javax.servlet-api - provided - - - - me.chyxion.tigon - tigon-freemarker-support - test - - - me.chyxion.tigon - tigon-extjs - test - - - org.springframework - spring-test - test - - - org.springframework.boot - spring-boot-test - test - - - javax.el - javax.el-api - test - - - junit - junit - test - - - org.apache.logging.log4j - log4j-slf4j-impl - test - - - org.apache.logging.log4j - log4j-core - test - - - diff --git a/tigon-webmvc-spring-boot/src/main/java/me/chyxion/tigon/webmvc/springboot/TigonWebMvcSpringBootConfiguration.java b/tigon-webmvc-spring-boot/src/main/java/me/chyxion/tigon/webmvc/springboot/TigonWebMvcSpringBootConfiguration.java deleted file mode 100644 index c11fdce..0000000 --- a/tigon-webmvc-spring-boot/src/main/java/me/chyxion/tigon/webmvc/springboot/TigonWebMvcSpringBootConfiguration.java +++ /dev/null @@ -1,163 +0,0 @@ -package me.chyxion.tigon.webmvc.springboot; - -import java.util.List; -import java.util.Locale; -import java.util.Collections; -import java.nio.charset.Charset; -import org.springframework.util.Assert; -import org.springframework.http.MediaType; -import org.springframework.util.PathMatcher; -import javax.servlet.http.HttpServletRequest; -import org.apache.commons.lang3.CharEncoding; -import org.springframework.context.annotation.Bean; -import org.springframework.format.FormatterRegistry; -import org.springframework.web.servlet.LocaleResolver; -import me.chyxion.tigon.webmvc.TigonReturnValueHandler; -import me.chyxion.tigon.webmvc.TigonHandlerInterceptor; -import com.alibaba.fastjson.serializer.SerializerFeature; -import org.springframework.web.servlet.config.annotation.*; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.web.servlet.mvc.WebContentInterceptor; -import org.springframework.web.servlet.i18n.CookieLocaleResolver; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; -import me.chyxion.tigon.webmvc.formatter.TrimAnnotationFormatterFactory; -import me.chyxion.tigon.webmvc.converter.StringToJSONArrayTypeConverter; -import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4; -import me.chyxion.tigon.webmvc.converter.StringToJSONObjectTypeConverter; -import org.springframework.web.method.support.HandlerMethodReturnValueHandler; -import me.chyxion.tigon.webmvc.formatter.EmptyToNullAnnotationFormatterFactory; -import org.springframework.format.number.NumberFormatAnnotationFormatterFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; - -/** - * @author Shaun Chyxion
- * chyxion@163.com
- * Mar 01, 2017 10:35:14 - */ -@EnableWebMvc -@Configuration -@EnableAspectJAutoProxy -@ConditionalOnWebApplication -@ImportResource("classpath*:spring/spring-*.xml") -public class TigonWebMvcSpringBootConfiguration extends WebMvcConfigurerAdapter { - @Autowired(required = false) - private List handlerInterceptors; - - /** - * {@inheritDoc} - */ - @Override - public void addFormatters(FormatterRegistry registry) { - super.addFormatters(registry); - // converters - registry.addConverter(new StringToJSONObjectTypeConverter()); - registry.addConverter(new StringToJSONArrayTypeConverter()); - - // formatters - registry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory()); - registry.addFormatterForFieldAnnotation(new EmptyToNullAnnotationFormatterFactory()); - registry.addFormatterForFieldAnnotation(new TrimAnnotationFormatterFactory()); - } - - /** - * {@inheritDoc} - */ - @Override - public void addInterceptors(InterceptorRegistry registry) { - super.addInterceptors(registry); - registry.addInterceptor(new WebContentInterceptor()) - .excludePathPatterns("/assets/**", "classpath:webapp/assets/**"); - - if (handlerInterceptors != null && - !handlerInterceptors.isEmpty()) { - for (TigonHandlerInterceptor handlerInterceptor : handlerInterceptors) { - final String[] includePathPatterns = handlerInterceptor.includePathPatterns(); - Assert.state(includePathPatterns != null && includePathPatterns.length > 0, - "Handler Interceptor 'includePathPatterns' Could Not Be Empty"); - final InterceptorRegistration interceptorRegistration = - registry.addInterceptor(handlerInterceptor) - .addPathPatterns(includePathPatterns); - final String[] excludePathPatterns = - handlerInterceptor.excludePathPatterns(); - if (excludePathPatterns != null && excludePathPatterns.length > 0) { - interceptorRegistration.excludePathPatterns(excludePathPatterns); - } - final PathMatcher pathMatcher = handlerInterceptor.pathMatcher(); - if (pathMatcher != null) { - interceptorRegistration - .pathMatcher(pathMatcher); - } - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public void addReturnValueHandlers( - List returnValueHandlers) { - returnValueHandlers.add(returnValueHandler()); - super.addReturnValueHandlers(returnValueHandlers); - } - - @Bean - public HandlerMethodReturnValueHandler returnValueHandler() { - return new TigonReturnValueHandler(); - } - - /** - * {@inheritDoc} - */ - @Override - public void configurePathMatch(PathMatchConfigurer configurer) { - configurer.setUseSuffixPatternMatch(false); - configurer.setUseRegisteredSuffixPatternMatch(false); - super.configurePathMatch(configurer); - } - - /** - * {@inheritDoc} - */ - @Override - public void configureMessageConverters( - List> converters) { - converters.add(new StringHttpMessageConverter(Charset.forName(CharEncoding.UTF_8))); - final FastJsonHttpMessageConverter4 fastJsonMessageConverter = - new FastJsonHttpMessageConverter4(); - fastJsonMessageConverter.setSupportedMediaTypes( - Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); - - fastJsonMessageConverter.getFastJsonConfig() - .setSerializerFeatures( - SerializerFeature.WriteMapNullValue, - SerializerFeature.WriteNullListAsEmpty, - SerializerFeature.WriteNullBooleanAsFalse); - - converters.add(fastJsonMessageConverter); - super.configureMessageConverters(converters); - } - - @Bean - public LocaleResolver localeResolver() { - return new CookieLocaleResolver() { - private final LocaleResolver acceptHeaderLocaleResolver = - new AcceptHeaderLocaleResolver(); - - /** - * {@inheritDoc} - */ - @Override - public Locale resolveLocale(HttpServletRequest request) { - final Locale locale = super.determineDefaultLocale(request); - return locale != null ? - locale : acceptHeaderLocaleResolver.resolveLocale(request); - } - }; - } -} diff --git a/tigon-webmvc-spring-boot/src/main/resources/META-INF/spring.factories b/tigon-webmvc-spring-boot/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 0b16020..0000000 --- a/tigon-webmvc-spring-boot/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -me.chyxion.tigon.webmvc.springboot.TigonWebMvcSpringBootConfiguration diff --git a/tigon-webmvc-spring-boot/src/main/resources/spring/.gitkeep b/tigon-webmvc-spring-boot/src/main/resources/spring/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/Main.java b/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/Main.java deleted file mode 100644 index 410fa34..0000000 --- a/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/Main.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.chyxion.tigon.webmvc.test; - -import org.springframework.boot.SpringApplication; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; - -/** - * @author Shaun Chyxion
- * chyxion@163.com
- * Mar 05, 2017 12:12:56 - */ -@ComponentScan("me.chyxion.tigon.webmvc.test") -@EnableAutoConfiguration -public class Main { - - public static void main(String[] args) { - SpringApplication.run(Main.class, args); - } -} diff --git a/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/SiteControllerTest.java b/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/SiteControllerTest.java deleted file mode 100644 index e11e919..0000000 --- a/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/SiteControllerTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package me.chyxion.tigon.webmvc.test; - -import java.util.Map; -import org.junit.Test; -import java.util.HashMap; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Jan 27, 2015 3:27:08 PM - */ -@WebAppConfiguration -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = Main.class) -@SpringBootTest -public class SiteControllerTest { - - @Autowired - private ControllerTestTool t; - - @Test - public void testIndex() { - t.print(t.get("/")); - } - - @Test - public void testRaw() { - t.print(t.get("/raw")); - } - - @Test - public void testInt() { - t.print(t.get("/int")); - } - - @Test - public void testFtl() { - t.print(t.get("/test")); - } - - @Test - public void testViewModels() { - t.print(t.get("/view-model")); - } - - @Test - public void testListResult() { - t.print(t.get("/list-result")); - } - - @Test - public void testListResult1() { - t.print(t.get("/list-result1")); - } - - @Test - public void testExtJsCommon() { - t.print(t.get("/assets/js/extjs-commons.js")); - } - - @Test - public void testPost() { - Map params = new HashMap(); - params.put("id", "id"); - params.put("name", "Shaun Chyxion"); - params.put("gender", ""); - t.print(t.post("/post", params)); - } - - @Test - public void testRequired() { - Map params = new HashMap(); - // params.put("param", ""); - t.print(t.post("/required", params)); - } -} diff --git a/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/controller/SiteController.java b/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/controller/SiteController.java deleted file mode 100644 index ee6dad9..0000000 --- a/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/controller/SiteController.java +++ /dev/null @@ -1,139 +0,0 @@ -package me.chyxion.tigon.webmvc.test.controller; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import me.chyxion.tigon.model.ListResult; -import me.chyxion.tigon.model.ViewModel; -import me.chyxion.tigon.model.ViewModelable; -import org.springframework.stereotype.Controller; -import org.hibernate.validator.constraints.NotBlank; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.ModelAndView; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author chyxion
- * chyxion@163.com
- * May 31, 2015 3:53:04 PM - */ -@Validated -@Controller -public class SiteController { - - @RequestMapping("/") - public void index() { - - } - - @RequestMapping("/required") - public String required( - @NotBlank - @RequestParam("param") String param) { - return param; - } - - @RequestMapping("/raw") - public Map raw() { - Map mapRaw = new HashMap(); - mapRaw.put("data", "Hello!"); - return mapRaw; - } - - @RequestMapping("/int") - public int integer() { - return 99; - } - - @RequestMapping("/test") - public ModelAndView test() { - return new ModelAndView("test").addObject("name", "FreeMarker"); - } - - @RequestMapping("/view-models") - public List> viewModels() { - return Arrays.asList( - new ViewModel(1) - .setAttr("name", "foo"), - new ViewModel(2) - .setAttr("name", "bar") - .setAttr("other", - new ViewModel(3) - .setAttr("name", "foobar"))); - } - - @RequestMapping("/list-result") - public ViewModelable> listResult() { - return new ListResult().setTotal(10).setData(Arrays.asList(1, 2, 3)).setAttr("attr", "foo"); - } - - @RequestMapping("/list-result1") - public List>> listResult1() { - return Arrays.asList( - new ListResult() - .setTotal(10) - .setData(Arrays.asList(1, 2, 3)) - .setAttr("attr", "foo")); - } - - @RequestMapping("/post") - public String post(@Validated Form form) { - return form.getId(); - } - - public static class Form { - @NotBlank - private String id; - @NotBlank - private String name; - @NotBlank - private String gender; - - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the gender - */ - public String getGender() { - return gender; - } - - /** - * @param gender the gender to set - */ - public void setGender(String gender) { - this.gender = gender; - } - } -} diff --git a/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/interceptor/TimeHandlerInterceptor.java b/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/interceptor/TimeHandlerInterceptor.java deleted file mode 100644 index cd22bc6..0000000 --- a/tigon-webmvc-spring-boot/src/test/java/me/chyxion/tigon/webmvc/test/interceptor/TimeHandlerInterceptor.java +++ /dev/null @@ -1,50 +0,0 @@ -package me.chyxion.tigon.webmvc.test.interceptor; - -import lombok.extern.slf4j.Slf4j; -import me.chyxion.tigon.webmvc.TigonHandlerInterceptor; -import org.springframework.stereotype.Service; -import org.springframework.util.PathMatcher; -import org.springframework.web.servlet.ModelAndView; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @author Shaun Chyxion
- * chyxion@163.com
- * Mar 19, 2017 12:48:04 - */ -@Slf4j -@Service -public class TimeHandlerInterceptor implements TigonHandlerInterceptor { - - @Override - public String[] includePathPatterns() { - return new String[] {"/**"}; - } - - @Override - public String[] excludePathPatterns() { - return new String[0]; - } - - @Override - public PathMatcher pathMatcher() { - return null; - } - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - request.setAttribute("Begin", System.currentTimeMillis()); - return true; - } - - @Override - public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { - System.err.println("Time: " + request.getAttribute("Begin")); - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { - - } -} diff --git a/tigon-webmvc-spring-boot/src/test/resources/application.properties b/tigon-webmvc-spring-boot/src/test/resources/application.properties deleted file mode 100644 index b78b895..0000000 --- a/tigon-webmvc-spring-boot/src/test/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -tigon.webmvc.jsonview.code_key=code \ No newline at end of file diff --git a/tigon-webmvc-spring-boot/src/test/resources/i18n/messages.properties b/tigon-webmvc-spring-boot/src/test/resources/i18n/messages.properties deleted file mode 100644 index 0392dd4..0000000 --- a/tigon-webmvc-spring-boot/src/test/resources/i18n/messages.properties +++ /dev/null @@ -1 +0,0 @@ -# I18n Messages \ No newline at end of file diff --git a/tigon-webmvc-spring-boot/src/test/resources/log4j2.xml b/tigon-webmvc-spring-boot/src/test/resources/log4j2.xml deleted file mode 100644 index 166de45..0000000 --- a/tigon-webmvc-spring-boot/src/test/resources/log4j2.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - %-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n - .logs - DEBUG - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tigon-webmvc-spring-boot/src/test/resources/spring/config.properties b/tigon-webmvc-spring-boot/src/test/resources/spring/config.properties deleted file mode 100644 index 0a28378..0000000 --- a/tigon-webmvc-spring-boot/src/test/resources/spring/config.properties +++ /dev/null @@ -1,11 +0,0 @@ -# Config Dev - -# Database -db.url=jdbc:mysql://10.0.0.31/yxt?useUnicode=true&characterEncoding=utf8 -db.user=yxt -db.password=yxt402 - -# Redis -redis.host=127.0.0.1 -redis.port=6379 -redis.password=0211 diff --git a/tigon-webmvc-spring-boot/src/test/resources/spring/spring-test.xml b/tigon-webmvc-spring-boot/src/test/resources/spring/spring-test.xml deleted file mode 100644 index 7aa0615..0000000 --- a/tigon-webmvc-spring-boot/src/test/resources/spring/spring-test.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - diff --git a/tigon-webmvc-spring-boot/src/test/resources/test.ftl b/tigon-webmvc-spring-boot/src/test/resources/test.ftl deleted file mode 100644 index cf3e580..0000000 --- a/tigon-webmvc-spring-boot/src/test/resources/test.ftl +++ /dev/null @@ -1 +0,0 @@ -FTL: ${name} \ No newline at end of file diff --git a/tigon-webmvc-war/README.md b/tigon-webmvc-war/README.md deleted file mode 100644 index 12edb4c..0000000 --- a/tigon-webmvc-war/README.md +++ /dev/null @@ -1 +0,0 @@ -# tigon-webmvc diff --git a/tigon-webmvc-war/pom.xml b/tigon-webmvc-war/pom.xml deleted file mode 100644 index 3bbec9f..0000000 --- a/tigon-webmvc-war/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - 4.0.0 - tigon-webmvc-war - jar - Tigon Web MVC WAR - Tigon Web MVC WAR - - - me.chyxion.tigon - tigon - 0.0.1-SNAPSHOT - ../ - - - - - me.chyxion.tigon - tigon-webmvc-core - - - commons-fileupload - commons-fileupload - - - javax.servlet - javax.servlet-api - provided - - - org.springframework - spring-test - test - - - - javax.el - javax.el-api - test - - - org.glassfish.web - el-impl - 2.2 - test - - - junit - junit - test - - - org.apache.logging.log4j - log4j-slf4j-impl - test - - - org.apache.logging.log4j - log4j-core - test - - - diff --git a/tigon-webmvc-war/src/main/java/me/chyxion/tigon/webmvc/war/AppContextInitializer.java b/tigon-webmvc-war/src/main/java/me/chyxion/tigon/webmvc/war/AppContextInitializer.java deleted file mode 100644 index 7c41905..0000000 --- a/tigon-webmvc-war/src/main/java/me/chyxion/tigon/webmvc/war/AppContextInitializer.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.chyxion.tigon.webmvc.war; - -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.AbstractRefreshableApplicationContext; - -/** - * Disable Bean Definition Override - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Jan 23, 2015 12:19:07 PM - */ -public class AppContextInitializer - implements ApplicationContextInitializer { - - /** - * {@inheritDoc} - */ - @Override - public void initialize(ConfigurableApplicationContext appContext) { - if (appContext instanceof AbstractRefreshableApplicationContext) { - ((AbstractRefreshableApplicationContext) appContext) - .setAllowBeanDefinitionOverriding(false); - } - } -} diff --git a/tigon-webmvc-war/src/main/java/me/chyxion/tigon/webmvc/war/TigonWebMvcWarConfig.java b/tigon-webmvc-war/src/main/java/me/chyxion/tigon/webmvc/war/TigonWebMvcWarConfig.java deleted file mode 100644 index 154c694..0000000 --- a/tigon-webmvc-war/src/main/java/me/chyxion/tigon/webmvc/war/TigonWebMvcWarConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -package me.chyxion.tigon.webmvc.war; - -import org.springframework.context.annotation.Configuration; -import me.chyxion.tigon.webmvc.TigonWebMvcConfiguration; -import org.springframework.web.servlet.mvc.WebContentInterceptor; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; - -/** - * @author Donghuang
- * donghuang@wacai.com
- * Apr 09, 2017 14:28:20 - */ -@Configuration -@EnableAspectJAutoProxy -public class TigonWebMvcWarConfig extends TigonWebMvcConfiguration { - - /** - * {@inheritDoc} - */ - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new WebContentInterceptor()) - .excludePathPatterns("/assets/**", "classpath:webapp/assets/**"); - } - - /** - * {@inheritDoc} - */ - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/assets/**") - .addResourceLocations("/assets/", "classpath:webapp/assets/"); - } -} diff --git a/tigon-webmvc-war/src/main/resources/META-INF/web-fragment.xml b/tigon-webmvc-war/src/main/resources/META-INF/web-fragment.xml deleted file mode 100644 index 232a30b..0000000 --- a/tigon-webmvc-war/src/main/resources/META-INF/web-fragment.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - tigon-webmvc - - - - - - - spring.profiles.active - profile_active - - - contextConfigLocation - classpath*:spring/**/spring-*.xml - - - contextInitializerClasses - me.chyxion.tigon.webmvc.war.AppContextInitializer - - - org.springframework.web.context.ContextLoaderListener - - - - encoding - org.springframework.web.filter.CharacterEncodingFilter - - encoding - UTF-8 - - - forceEncoding - true - - true - - - encoding - /* - - - HiddenHttpMethodFilter - org.springframework.web.filter.HiddenHttpMethodFilter - true - - - HiddenHttpMethodFilter - spring-mvc - - - - spring-mvc - org.springframework.web.servlet.DispatcherServlet - - contextConfigLocation - classpath*:spring/**/servlet-spring-*.xml - - true - 1 - - - spring-mvc - / - - diff --git a/tigon-webmvc-war/src/main/resources/spring/servlet-spring-summer-webmvc.xml b/tigon-webmvc-war/src/main/resources/spring/servlet-spring-summer-webmvc.xml deleted file mode 100644 index 059ffea..0000000 --- a/tigon-webmvc-war/src/main/resources/spring/servlet-spring-summer-webmvc.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/tigon-webmvc-war/src/main/resources/spring/spring-summer-webmvc.xml b/tigon-webmvc-war/src/main/resources/spring/spring-summer-webmvc.xml deleted file mode 100644 index c2ca0da..0000000 --- a/tigon-webmvc-war/src/main/resources/spring/spring-summer-webmvc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - diff --git a/tigon-webmvc-war/src/test/java/me/chyxion/tigon/webmvc/test/SiteControllerTest.java b/tigon-webmvc-war/src/test/java/me/chyxion/tigon/webmvc/test/SiteControllerTest.java deleted file mode 100644 index ff4545e..0000000 --- a/tigon-webmvc-war/src/test/java/me/chyxion/tigon/webmvc/test/SiteControllerTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package me.chyxion.tigon.webmvc.test; - -import java.util.Map; -import java.util.Set; -import java.util.HashMap; -import javax.validation.Validator; -import javax.validation.ConstraintViolation; -import me.chyxion.tigon.webmvc.test.controller.SiteController.Form; -import org.hibernate.validator.constraints.NotBlank; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.validation.annotation.Validated; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author Shaun Chyxion
- * chyxion@163.com
- * Jan 27, 2015 3:27:08 PM - */ -@WebAppConfiguration -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration({ - "classpath*:spring/spring-*.xml", - "classpath*:spring/servlet-spring-*.xml" -}) -@Validated -public class SiteControllerTest { - - @Autowired - private ControllerTestTool t; - @Autowired - private Validator v; - - @Test - public void testIndex() { - t.print(t.get("/")); - } - - @Test - public void testV() { - t.print(t.get("/v?v=")); - } - - @Test - public void testValidation() { - testValidation(""); - } - - public void testValidation(@NotBlank String foo) { - - } - - @Test - public void testRaw() { - t.print(t.get("/raw")); - } - - @Test - public void testInt() { - t.print(t.get("/int")); - } - - @Test - public void testPost() { - Map params = new HashMap(); - params.put("id", ""); - params.put("name", "Shaun Chyxion"); - params.put("gender", ""); - t.print(t.post("/post", params)); - } - - @Test - public void testValidate() { - Set> result = v.validate(new Form()); - for (ConstraintViolation
vv : result) { - System.err.println("[" + - vv.getPropertyPath() + "] " + vv.getMessage()); - } - } - - @Test - public void testValidate1() { - Form form = new Form(); - form.setId("chyxion"); - form.setName("chyxion"); - form.setGender(""); - - Set> result = v.validate(form); - for (ConstraintViolation vv : result) { - System.err.println(vv.getMessage()); - System.err.println(vv.getPropertyPath().toString()); - } - } -} diff --git a/tigon-webmvc-war/src/test/java/me/chyxion/tigon/webmvc/test/controller/SiteController.java b/tigon-webmvc-war/src/test/java/me/chyxion/tigon/webmvc/test/controller/SiteController.java deleted file mode 100644 index 48921b8..0000000 --- a/tigon-webmvc-war/src/test/java/me/chyxion/tigon/webmvc/test/controller/SiteController.java +++ /dev/null @@ -1,103 +0,0 @@ -package me.chyxion.tigon.webmvc.test.controller; - -import java.util.HashMap; -import java.util.Map; - -import me.chyxion.tigon.format.annotation.EmptyToNull; -import org.hibernate.validator.constraints.NotBlank; -import org.springframework.stereotype.Controller; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * @version 0.0.1 - * @since 0.0.1 - * @author chyxion
- * chyxion@163.com
- * May 31, 2015 3:53:04 PM - */ -@Validated -@Controller -public class SiteController { - - @RequestMapping("/") - public void index() { - - } - - @RequestMapping("/v") - public String index(@RequestParam("v") - // @EmptyToNull - String validate) { - return validate; - } - - @RequestMapping("/raw") - public Map raw() { - Map mapRaw = new HashMap(); - mapRaw.put("data", "Hello!"); - return mapRaw; - } - - @RequestMapping("/int") - public int integer() { - return 99; - } - - @RequestMapping("/post") - public String post(@Validated Form form) { - return form.getId(); - } - - public static class Form { - @NotBlank - private String id; - @NotBlank - private String name; - @EmptyToNull - private String gender; - - /** - * @return the id - */ - public String getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the gender - */ - public String getGender() { - return gender; - } - - /** - * @param gender the gender to set - */ - public void setGender(String gender) { - this.gender = gender; - } - } -} diff --git a/tigon-webmvc-war/src/test/resources/log4j2.xml b/tigon-webmvc-war/src/test/resources/log4j2.xml deleted file mode 100644 index c7486b5..0000000 --- a/tigon-webmvc-war/src/test/resources/log4j2.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - %-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%t][%c{1}] %m%n - .logs - DEBUG - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tigon-webmvc-war/src/test/resources/spring/servlet-spring-test.xml b/tigon-webmvc-war/src/test/resources/spring/servlet-spring-test.xml deleted file mode 100644 index 9522d6f..0000000 --- a/tigon-webmvc-war/src/test/resources/spring/servlet-spring-test.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - -