listGenerateImports() {
29 | return Arrays.asList(
30 | new ModelGenerateHelper("java.lang.String", "String"),
31 | new ModelGenerateHelper("java.lang.Integer", "Integer"),
32 | new ModelGenerateHelper("java.lang.Double", "Double"),
33 | new ModelGenerateHelper("java.lang.Float", "Float"),
34 | new ModelGenerateHelper("java.lang.Long", "Long"),
35 | new ModelGenerateHelper("java.lang.Short", "Short"),
36 | new ModelGenerateHelper("java.lang.Byte", "Byte"),
37 | new ModelGenerateHelper("java.lang.Char", "Char"),
38 | new ModelGenerateHelper("java.lang.Boolean", "Boolean"),
39 | new ModelGenerateHelper("java.lang.Object", "Object"),
40 | new ModelGenerateHelper("java.util.Date", "Date"),
41 | new ModelGenerateHelper("java.math.BigDecimal", "BigDecimal"));
42 | }
43 |
44 | public static String generateImports(String parameters) {
45 | String[] separator = parameters.split(" ");
46 | String imports = "";
47 | for (int i = 0; i < separator.length; i++) {
48 | String [] nameAndType = separator[i].split(":");
49 |
50 | for (int j = 0; j < listGenerateImports().size(); j++) {
51 | if (nameAndType[1].equals(listGenerateImports().get(j).getNameVariable())) {
52 | imports += "import " + listGenerateImports().get(j).getImportVariable() + "; \n";
53 | }
54 | }
55 |
56 | }
57 | return imports;
58 | }
59 |
60 | public static String generateGettersAndSetters(String parameters) {
61 | String[] separator = parameters.split(" ");
62 | String gettersAndSetters = "";
63 | for (int i = 0; i < separator.length; i++) {
64 | String [] nameAndType = separator[i].split(":");
65 | String name = nameAndType[0];
66 | String type = nameAndType[1];
67 |
68 | //SETTER
69 | gettersAndSetters += TAB + "public void set" + StringUtils.capitalize(name) + "(" + type + " " + name + ") {" ;
70 | gettersAndSetters += "this." + name + " = " + name + ";";
71 | gettersAndSetters += "}";
72 |
73 | gettersAndSetters += "\n";
74 |
75 | //GETTER
76 | gettersAndSetters += TAB + "public " + type + " get" + StringUtils.capitalize(name) + "() {" ;
77 | gettersAndSetters += "return " + name + ";";
78 | gettersAndSetters += "}";
79 |
80 | gettersAndSetters += "\n";
81 | }
82 | return gettersAndSetters;
83 | }
84 |
85 | public String getNameVariable() {
86 | return nameVariable;
87 | }
88 |
89 | public void setNameVariable(String nameVariable) {
90 | this.nameVariable = nameVariable;
91 | }
92 |
93 | public String getImportVariable() {
94 | return importVariable;
95 | }
96 |
97 | public void setImportVariable(String importVariable) {
98 | this.importVariable = importVariable;
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/resources/GeneratorProperties.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.resources;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | import org.apache.commons.io.FileUtils;
7 | import org.apache.commons.io.IOUtils;
8 |
9 | import br.com.generate.helpers.ScaffoldInfoHelper;
10 |
11 | public class GeneratorProperties extends ScaffoldInfoHelper {
12 |
13 | public GeneratorProperties() throws IOException {
14 | if (validate()) {
15 | generate();
16 | }
17 | }
18 |
19 | public void generate() throws IOException {
20 | String strings = IOUtils.toString(getClass().getResourceAsStream("/templates/resources/template-application.properties.txt"), null);
21 |
22 | String nameDatabase = getNameDatabase();
23 | String userDataBase = getUserDatabase();
24 | String passwordDatabase = getPassWordDatabase();
25 |
26 | strings = strings.replace("{nameDatabase}", nameDatabase);
27 | strings = strings.replace("{userDatabase}", userDataBase);
28 | strings = strings.replace("{passwordDatabase}", passwordDatabase);
29 |
30 | File newFile = new File(getUserDir() + "/src/main/resources/application.properties");
31 | FileUtils.writeStringToFile(newFile, strings);
32 | System.out.println("create /src/main/resources/application.properties");
33 | }
34 |
35 | public boolean validate() throws IOException {
36 | String pathFile = "/src/main/resources/application.properties";
37 | File f = new File(getUserDir() + pathFile);
38 | if(f.exists()) {
39 | String strings = FileUtils.readFileToString(f);
40 | if (strings.equals("") || strings == null) {
41 | return true;
42 | }
43 | } else {
44 | return true;
45 | }
46 | return false;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/setup/SetupGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.setup;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.io.PrintWriter;
6 | import java.io.UnsupportedEncodingException;
7 |
8 | import br.com.generate.helpers.ScaffoldInfoHelper;
9 |
10 | /**
11 | * @author NetoDevel
12 | * @since 0.0.1
13 | */
14 | public class SetupGenerator extends ScaffoldInfoHelper {
15 |
16 | public SetupGenerator(String...params) {
17 | generate(params);
18 | }
19 |
20 | public void generate(String... params) {
21 | PrintWriter writer = null;
22 | try {
23 | File file = new File(getUserDir() + "/src/main/resources/scaffold.info");
24 | file.getParentFile().mkdirs();
25 | writer = new PrintWriter(file, "UTF-8");
26 | String namePackage = params[0] != null ? params[0] : "com.example";
27 | String dataBaseName = params[1] != null ? params[1] : "mydb";
28 | String userDataBase = params[2] != null ? params[2] : "root";
29 | String passWordDatabase = params[3] != null ? params[3] : "root";
30 | String springVersion = params[4] != null ? params[4] : "1.x";
31 | writer.println("package:" + namePackage);
32 | writer.println("dataBaseName:" + dataBaseName);
33 | writer.println("username:" + userDataBase);
34 | writer.println("password:" + passWordDatabase);
35 | writer.println("springVersion:" + springVersion);
36 | writer.close();
37 | System.out.println("create /src/main/resources/scaffold.info");
38 | } catch (FileNotFoundException e) {
39 | } catch (UnsupportedEncodingException e) {
40 | }
41 | }
42 |
43 | public boolean validateFile(String nameFile) {
44 | File f = new File(getUserDir() + "/src/main/resources/scaffold.info");
45 | if(f.exists()) {
46 | System.out.println("scaffold.info already exists!");
47 | return false;
48 | } else {
49 | return true;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/source/controller/ControllerCleanGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.source.controller;
2 |
3 | import java.io.IOException;
4 |
5 | import br.com.generate.Layers;
6 | import br.com.generate.helpers.FileHelper;
7 |
8 | public class ControllerCleanGenerator extends FileHelper {
9 |
10 | @Override
11 | public String getLayer() {
12 | return Layers.CONTROLLER;
13 | }
14 |
15 | @Override
16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) {
17 | return javaStrings.replace("${package}", getPackage() + ".controller")
18 | .replace("${path}", nameClass.toLowerCase())
19 | .replace("${className}", nameClass);
20 | }
21 |
22 | public static void main(String[] args) throws IOException {
23 | new ControllerCleanGenerator().generate("Credential", null, "template-clean-controller.txt");
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/source/controller/ControllerGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.source.controller;
2 |
3 | import java.io.IOException;
4 |
5 | import br.com.generate.Layers;
6 | import br.com.generate.helpers.FileHelper;
7 |
8 | public class ControllerGenerator extends FileHelper {
9 |
10 | @Override
11 | public String getLayer() {
12 | return Layers.CONTROLLER;
13 | }
14 |
15 | @Override
16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) {
17 | return javaStrings.replace("${package}", getPackage() + ".controller")
18 | .replace("${package_model}", getPackage() + ".model")
19 | .replace("${package_service}", getPackage() + ".service")
20 | .replace("${className}", nameClass)
21 | .replace("${paramClassName}", nameClass.toLowerCase())
22 | .replace("${url_path}", nameClass.toLowerCase() + "s");
23 | }
24 |
25 | public static void main(String[] args) throws IOException {
26 | new ControllerGenerator().generate("User", null, "template-controller.txt");
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/source/model/ModelGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.source.model;
2 |
3 | import br.com.generate.Layers;
4 | import br.com.generate.helpers.FileHelper;
5 | import br.com.generate.helpers.ModelGenerateHelper;
6 |
7 | /**
8 | * @author NetoDevel
9 | */
10 | public class ModelGenerator extends FileHelper {
11 |
12 | @Override
13 | public String getLayer() {
14 | return Layers.MODEL;
15 | }
16 |
17 | @Override
18 | public String operationGenerate(String javaStrings, String nameClass, String parameters) {
19 | return javaStrings.replace("${package}", getPackage() + ".model")
20 | .replace("${imports}", ModelGenerateHelper.generateImports(parameters))
21 | .replace("${className}", nameClass)
22 | .replace("${name_table}", nameClass.toLowerCase() + "s")
23 | .replace("${parameters}", generateParams(parameters))
24 | .replace("${getters}", ModelGenerateHelper.generateGettersAndSetters(parameters));
25 | }
26 |
27 | public String generateParams(String params) {
28 | String[] variablesSplits = params.split(" ");
29 | String finalParameters = "";
30 | for (int i = 0; i < variablesSplits.length; i++) {
31 |
32 | String [] typeAndNameVars = variablesSplits[i].split(":");
33 |
34 | String column = " @Column(name = \"" + typeAndNameVars[0] + "\")";
35 | String lineVariables = " private " + typeAndNameVars[1] + " " + typeAndNameVars[0] + ";";
36 | String lineClean = "\n";
37 |
38 | finalParameters += lineClean;
39 | finalParameters += column;
40 | finalParameters += lineClean;
41 | finalParameters += lineVariables;
42 | finalParameters += lineClean;
43 | }
44 | return finalParameters;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/source/repository/RepositoryCleanGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.source.repository;
2 |
3 | import java.io.IOException;
4 |
5 | import br.com.generate.Layers;
6 | import br.com.generate.helpers.FileHelper;
7 |
8 | public class RepositoryCleanGenerator extends FileHelper {
9 |
10 | @Override
11 | public String getLayer() {
12 | return Layers.REPOSITORY;
13 | }
14 |
15 | @Override
16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) {
17 | return javaStrings.replace("${package}", getPackage() + ".repository")
18 | .replace("${className}", nameClass);
19 | }
20 |
21 | public static void main(String[] args) throws IOException {
22 | new RepositoryCleanGenerator().generate("User", null, "template-clean-repository.txt");
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/source/repository/RepositoryGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.source.repository;
2 |
3 | import java.io.IOException;
4 |
5 | import br.com.generate.Layers;
6 | import br.com.generate.helpers.FileHelper;
7 |
8 | public class RepositoryGenerator extends FileHelper {
9 |
10 | @Override
11 | public String getLayer() {
12 | return Layers.REPOSITORY;
13 | }
14 |
15 | @Override
16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) {
17 | return javaStrings.replace("${package}", getPackage() + ".repository")
18 | .replace("${package_model}", getPackage() + ".model")
19 | .replace("${className}", nameClass);
20 | }
21 |
22 |
23 | public static void main(String[] args) throws IOException {
24 | new RepositoryGenerator().generate("User", null, "template-repository.txt");
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/source/service/ServiceCleanGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.source.service;
2 |
3 | import java.io.IOException;
4 |
5 | import br.com.generate.Layers;
6 | import br.com.generate.helpers.FileHelper;
7 |
8 | public class ServiceCleanGenerator extends FileHelper {
9 |
10 | @Override
11 | public String getLayer() {
12 | return Layers.SERVICE;
13 | }
14 |
15 | @Override
16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) {
17 | return javaStrings.replace("${package}", getPackage() + ".service")
18 | .replace("${className}", nameClass);
19 | }
20 |
21 | public static void main(String[] args) throws IOException {
22 | new ServiceCleanGenerator().generate("User", null, "template-clean-service.txt");
23 | }
24 |
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/source/service/ServiceGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.source.service;
2 |
3 | import java.io.IOException;
4 |
5 | import br.com.generate.Layers;
6 | import br.com.generate.helpers.FileHelper;
7 |
8 | public class ServiceGenerator extends FileHelper {
9 |
10 | @Override
11 | public String getLayer() {
12 | return Layers.SERVICE;
13 | }
14 |
15 | @Override
16 | public String operationGenerate(String javaStrings, String nameClass, String parameters) {
17 | if ( getSpringVersion().equals("2.x") ) {
18 | javaStrings = javaStrings.replace(".findOne(id)", ".findById(id).get()");
19 | }
20 | return javaStrings.replace("${package}", getPackage() + ".service")
21 | .replace("${package_model}", getPackage() + ".model")
22 | .replace("${package_repository}", getPackage() + ".repository")
23 | .replace("${className}", nameClass)
24 | .replace("${paramClassName}", nameClass.toLowerCase());
25 | }
26 |
27 | public static void main(String[] args) throws IOException {
28 | new ServiceGenerator().generate("User", null, "template-service.txt");
29 | }
30 |
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/thymeleaf/AbstractThymeleafGenerate.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.thymeleaf;
2 |
3 | import org.springframework.util.StringUtils;
4 |
5 | import br.com.generate.helpers.ScaffoldInfoHelper;
6 |
7 |
8 | /**
9 | * @author NetoDevel
10 | */
11 | public abstract class AbstractThymeleafGenerate extends ScaffoldInfoHelper {
12 |
13 | private static final String TABS_INDEX = " ";
14 | private static final String TABS_FORM = " ";
15 | private static final String TABS_SHOW = " ";
16 |
17 | public String generateThParameters(String parameters) {
18 | String [] params = parameters.split(" ");
19 | String thParameters = "";
20 |
21 | for (int i = 0; i < params.length; i++) {
22 | String [] nameAndType = params[i].split(":");
23 | thParameters += TABS_INDEX + "" + StringUtils.capitalize(nameAndType[0]) + " | \n";
24 | }
25 |
26 | thParameters += TABS_INDEX + "Action | ";
27 | return thParameters;
28 | }
29 |
30 |
31 |
32 | public String generateTdParameters(String className, String parameters) {
33 | String [] params = parameters.split(" ");
34 | String tdParameters = "";
35 | for (int i = 0; i < params.length; i++) {
36 | String [] nameAndType = params[i].split(":");
37 | tdParameters += TABS_INDEX + " | \n";
38 | }
39 |
40 | tdParameters += TABS_INDEX + "\n";
41 | tdParameters += TABS_INDEX + " Show \n";
42 | tdParameters += TABS_INDEX + " Edit \n";
43 | tdParameters += TABS_INDEX + " Destroy \n";
44 | tdParameters += TABS_INDEX + " | ";
45 | return tdParameters;
46 | }
47 |
48 | public String generateInputParameters(String parameters) {
49 | String inputParameters = "";
50 | String [] params = parameters.split(" ");
51 | for (int i = 0; i < params.length; i++) {
52 | String [] nameAndType = params[i].split(":");
53 |
54 | inputParameters += TABS_FORM + " \n";
55 | inputParameters += TABS_FORM + " \n";
56 | inputParameters += TABS_FORM + " \n";
57 | inputParameters += TABS_FORM + "
\n";
58 | }
59 |
60 | return inputParameters;
61 | }
62 |
63 | public String generateShowParameters(String paramClassName, String parameters) {
64 | String inputParameters = "";
65 | String [] params = parameters.split(" ");
66 | for (int i = 0; i < params.length; i++) {
67 | String [] nameAndType = params[i].split(":");
68 | inputParameters += TABS_SHOW + " \n";
69 | inputParameters += TABS_SHOW + " \n";
70 | inputParameters += TABS_SHOW + " \n";
71 | inputParameters += TABS_SHOW + "
\n";
72 | }
73 | return inputParameters;
74 | }
75 |
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/thymeleaf/ThymeleafCleanGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.thymeleaf;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | import org.apache.commons.io.FileUtils;
7 | import org.apache.commons.io.IOUtils;
8 |
9 | public class ThymeleafCleanGenerator extends AbstractThymeleafGenerate {
10 |
11 | public void index(String className, String parameters) throws IOException {
12 | String htmlString = IOUtils.toString(getClass().getResourceAsStream("/templates/template-clean-index.html"), null);
13 | String template = "layout";
14 | String classNameParam = className;
15 | String paramClassName = className.toLowerCase();
16 | String pathUrl = "/" + className.toLowerCase() + "s";
17 | String eachParam = "list" + className;
18 |
19 | htmlString = htmlString.replace("${template}", template);
20 | htmlString = htmlString.replace("${className}", classNameParam);
21 | htmlString = htmlString.replace("paramClassName", paramClassName);
22 | htmlString = htmlString.replace("eachParam", eachParam);
23 | htmlString = htmlString.replace("url_path", pathUrl);
24 |
25 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/" + className.toLowerCase() + "/index.html");
26 |
27 | FileUtils.writeStringToFile(newHtmlFile, htmlString);
28 | System.out.println("create /src/main/resources/templates/" + className.toLowerCase() + "/index.html");
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/thymeleaf/ThymeleafGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.thymeleaf;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | import org.apache.commons.io.FileUtils;
7 | import org.apache.commons.io.IOUtils;
8 |
9 | public class ThymeleafGenerator extends AbstractThymeleafGenerate {
10 |
11 | public ThymeleafGenerator(String className, String parameters) throws IOException {
12 | if (validateLayoutHtml()) {
13 | generateTemplateLayout();
14 | }
15 | generateIndexHtml(className, parameters);
16 | generateFormHtml(className, parameters);
17 | generateShowHtml(className, parameters);
18 | }
19 |
20 | public void generateTemplateLayout() throws IOException {
21 | String htmlString = IOUtils.toString(getClass().getResourceAsStream("/templates/template-layout.html"), null);
22 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/layout.html");
23 | FileUtils.writeStringToFile(newHtmlFile, htmlString);
24 | System.out.println("create /src/main/resources/templates/layout.html");
25 | }
26 |
27 | public void generateIndexHtml(String className, String parameters) throws IOException {
28 | String htmlString = IOUtils.toString(getClass().getResourceAsStream("/templates/template-index.html"), null);
29 | String template = "layout";
30 | String classNameParam = className;
31 | String paramClassName = className.toLowerCase();
32 | String pathUrl = "/" + className.toLowerCase() + "s";
33 | String thAttributes = generateThParameters(parameters);
34 | String tdAttributes = generateTdParameters(className, parameters);
35 | String eachParam = "list" + className;
36 |
37 | htmlString = htmlString.replace("${template}", template);
38 | htmlString = htmlString.replace("${className}", classNameParam);
39 | htmlString = htmlString.replace("paramClassName", paramClassName);
40 | htmlString = htmlString.replace("eachParam", eachParam);
41 | htmlString = htmlString.replace("url_path", pathUrl);
42 | htmlString = htmlString.replace("${th_attributes}", thAttributes);
43 | htmlString = htmlString.replace("${td_attributes}", tdAttributes);
44 |
45 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/" + className.toLowerCase() + "/index.html");
46 |
47 | FileUtils.writeStringToFile(newHtmlFile, htmlString);
48 | System.out.println("create /src/main/resources/templates/" + className.toLowerCase() + "/index.html");
49 | }
50 |
51 | public void generateFormHtml(String className, String parameters) throws IOException {
52 | String htmlString =IOUtils.toString(getClass().getResourceAsStream("/templates/template-form.html"), null);
53 |
54 | String template = "layout";
55 | String paramClassName = className.toLowerCase();
56 | String pathUrl = "/" + className.toLowerCase() + "s";
57 | String inputParameters = generateInputParameters(parameters);
58 |
59 | htmlString = htmlString.replace("${template}", template);
60 | htmlString = htmlString.replace("${className}", className);
61 | htmlString = htmlString.replace("paramClassName", paramClassName);
62 | htmlString = htmlString.replace("url_path", pathUrl);
63 | htmlString = htmlString.replace("${input_parameters}", inputParameters);
64 |
65 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/" + className.toLowerCase() + "/form.html");
66 |
67 | FileUtils.writeStringToFile(newHtmlFile, htmlString);
68 | System.out.println("create /src/main/resources/templates/" + className.toLowerCase() + "/form.html");
69 | }
70 |
71 | public void generateShowHtml(String className, String parameters) throws IOException {
72 | String htmlString =IOUtils.toString(getClass().getResourceAsStream("/templates/template-show.html"), null);
73 |
74 | String template = "layout";
75 | String paramClassName = className.toLowerCase();
76 | String pathUrl = "/" + className.toLowerCase() + "s";
77 | String showAttributes = generateShowParameters(paramClassName, parameters);
78 |
79 | htmlString = htmlString.replace("${template}", template);
80 | htmlString = htmlString.replace("${className}", className);
81 | htmlString = htmlString.replace("paramClassName", paramClassName);
82 | htmlString = htmlString.replace("/path_url", pathUrl);
83 | htmlString = htmlString.replace("${showAttributes}", showAttributes);
84 |
85 | File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/" + className.toLowerCase() + "/show.html");
86 |
87 | FileUtils.writeStringToFile(newHtmlFile, htmlString);
88 | System.out.println("create /src/main/resources/templates/" + className.toLowerCase() + "/show.html");
89 | }
90 |
91 | public boolean validateLayoutHtml() throws IOException {
92 | String pathFile = "/src/main/resources/templates/layout.html";
93 | File f = new File(getUserDir() + pathFile);
94 | if(f.exists()) {
95 | return false;
96 | }
97 | return true;
98 | }
99 |
100 | public static void main(String[] args) throws IOException {
101 | new ThymeleafGenerator("User", "name:String email:String");
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/validators/GenerateValidator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.validators;
2 |
3 | import java.io.File;
4 |
5 | import br.com.generate.Layers;
6 | import br.com.generate.helpers.ScaffoldInfoHelper;
7 | import org.springframework.util.StringUtils;
8 |
9 | /**
10 | * @author Jose
11 | */
12 | public class GenerateValidator extends ScaffoldInfoHelper {
13 |
14 | private TypeValidator typeValidator = new TypeValidator();
15 |
16 | public boolean validate(String nameClass, String parameters, String layer) {
17 | if (typeValidator.validate(parameters, layer) && getSetupDone() && !validateFileExists(nameClass, layer)) {
18 | return true;
19 | }
20 | return false;
21 | }
22 |
23 | public boolean validateFileExists(String nameClass, String layer) {
24 | String pathFile = "";
25 | if (layer.equals(Layers.MODEL) || layer.equals("consumer")) {
26 | pathFile = "/" + getPathPackage() + layer + "/" + nameClass + ".java";
27 | } else {
28 | pathFile = "/" + getPathPackage() + layer + "/" + nameClass + getCapitalize(layer) + ".java";
29 | }
30 | File f = new File(getUserDir() + pathFile);
31 | if (f.exists()) {
32 | System.out.println("Error: file " + nameClass + getCapitalize(layer) + ".java" + " already exists.");
33 | return true;
34 | } else {
35 | return false;
36 | }
37 | }
38 |
39 | private String getCapitalize(String layer) {
40 | if (!layer.equals(Layers.MODEL) && !layer.equals("consumer")) {
41 | return StringUtils.capitalize(layer);
42 | }
43 | return "";
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/java/br/com/generate/validators/TypeValidator.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.validators;
2 |
3 | import br.com.generate.Layers;
4 |
5 | import java.util.Arrays;
6 | import java.util.List;
7 |
8 |
9 | /**
10 | * @author NetoDevel
11 | */
12 | public class TypeValidator {
13 |
14 | public List typesSupported = Arrays.asList("String", "Double", "Float", "Long", "Integer", "Short", "Byte", "Char", "Boolean", "Object", "BigDecimal", "Date");
15 |
16 | public boolean validate(String parameters, String layer) {
17 | if (layer.equals(Layers.MODEL)) {
18 | String[] separator = parameters.split(" ");
19 | for (int i = 0; i < separator.length; i++) {
20 | String [] nameAndType = separator[i].split(":");
21 | if (!typesSupported.contains(nameAndType[1].trim())) {
22 | System.out.println("Error: type " + nameAndType[1] + " not supported.");
23 | return false;
24 | }
25 | }
26 | }
27 | return true;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/scaffold.info:
--------------------------------------------------------------------------------
1 | package:br.com.example
2 | user-database:root
3 | password-database:root
4 | springVersion:1.x
5 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/config/jms_aws_sqs/template-message-listener.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | public interface MessageListener {
4 | void queueListener(String String);
5 | }
6 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/java/controller/template-clean-controller.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import org.springframework.stereotype.Controller;
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | @Controller
7 | @RequestMapping("/${path}")
8 | public class ${className}Controller {
9 |
10 | @GetMapping
11 | public String index() {
12 | return "${path}/index";
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/java/controller/template-controller.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | import java.util.List;
4 |
5 | import javax.validation.Valid;
6 |
7 | import org.hibernate.service.spi.ServiceException;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Controller;
10 | import org.springframework.ui.Model;
11 | import org.springframework.validation.BindingResult;
12 | import org.springframework.web.bind.annotation.DeleteMapping;
13 | import org.springframework.web.bind.annotation.GetMapping;
14 | import org.springframework.web.bind.annotation.ModelAttribute;
15 | import org.springframework.web.bind.annotation.PathVariable;
16 | import org.springframework.web.bind.annotation.PostMapping;
17 | import org.springframework.web.bind.annotation.PutMapping;
18 | import org.springframework.web.bind.annotation.RequestMapping;
19 | import org.springframework.web.servlet.mvc.support.RedirectAttributes;
20 | import ${package_model}.${className};
21 | import ${package_service}.${className}Service;
22 |
23 | @Controller
24 | @RequestMapping("/${paramClassName}s")
25 | public class ${className}Controller {
26 |
27 | private static final String MSG_SUCESS_INSERT = "${className} inserted successfully.";
28 | private static final String MSG_SUCESS_UPDATE = "${className} successfully changed.";
29 | private static final String MSG_SUCESS_DELETE = "Deleted ${className} successfully.";
30 | private static final String MSG_ERROR = "Error.";
31 |
32 | @Autowired
33 | private ${className}Service ${paramClassName}Service;
34 |
35 | @GetMapping
36 | public String index(Model model) {
37 | List<${className}> all = ${paramClassName}Service.findAll();
38 | model.addAttribute("list${className}", all);
39 | return "${paramClassName}/index";
40 | }
41 |
42 | @GetMapping("/{id}")
43 | public String show(Model model, @PathVariable("id") Integer id) {
44 | if (id != null) {
45 | ${className} ${paramClassName} = ${paramClassName}Service.findOne(id);
46 | model.addAttribute("${paramClassName}", ${paramClassName});
47 | }
48 | return "${paramClassName}/show";
49 | }
50 |
51 | @GetMapping(value = "/new")
52 | public String create(Model model, @ModelAttribute ${className} entity) {
53 | model.addAttribute("${paramClassName}", entity);
54 | return "${paramClassName}/form";
55 | }
56 |
57 | @PostMapping
58 | public String create(@Valid @ModelAttribute ${className} entity, BindingResult result, RedirectAttributes redirectAttributes) {
59 | ${className} ${paramClassName} = null;
60 | try {
61 | ${paramClassName} = ${paramClassName}Service.save(entity);
62 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_INSERT);
63 | } catch (Exception e) {
64 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
65 | e.printStackTrace();
66 | }
67 | return "redirect:/${url_path}/" + ${paramClassName}.getId();
68 | }
69 |
70 | @GetMapping("/{id}/edit")
71 | public String update(Model model, @PathVariable("id") Integer id) {
72 | try {
73 | if (id != null) {
74 | ${className} entity = ${paramClassName}Service.findOne(id);
75 | model.addAttribute("${paramClassName}", entity);
76 | }
77 | } catch (Exception e) {
78 | throw new ServiceException(e.getMessage());
79 | }
80 | return "${paramClassName}/form";
81 | }
82 |
83 | @PutMapping
84 | public String update(@Valid @ModelAttribute ${className} entity, BindingResult result, RedirectAttributes redirectAttributes) {
85 | ${className} ${paramClassName} = null;
86 | try {
87 | ${paramClassName} = ${paramClassName}Service.save(entity);
88 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_UPDATE);
89 | } catch (Exception e) {
90 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
91 | e.printStackTrace();
92 | }
93 | return "redirect:/${url_path}/" + ${paramClassName}.getId();
94 | }
95 |
96 | @DeleteMapping("/{id}")
97 | public String delete(@PathVariable("id") Integer id, RedirectAttributes redirectAttributes) {
98 | try {
99 | if (id != null) {
100 | ${className} entity = ${paramClassName}Service.findOne(id);
101 | ${paramClassName}Service.delete(entity);
102 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_DELETE);
103 | }
104 | } catch (Exception e) {
105 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
106 | throw new ServiceException(e.getMessage());
107 | }
108 | return "redirect:/${url_path}/index";
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/java/model/template-model.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import javax.persistence.Entity;
3 | import javax.persistence.GenerationType;
4 | import javax.persistence.Table;
5 | import javax.persistence.Column;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.Id;
8 | import java.io.Serializable;
9 | ${imports}
10 |
11 | @Entity
12 | @Table(name = "${name_table}")
13 | public class ${className} implements Serializable {
14 |
15 | private static final long serialVersionUID = 1L;
16 |
17 | @Id @GeneratedValue(strategy = GenerationType.AUTO)
18 | private Integer id;
19 | ${parameters}
20 | ${getters}
21 | public Integer getId() { return id; }
22 | public void setId(Integer id) { this.id = id; }
23 |
24 | }
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/java/repository/template-clean-repository.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import org.springframework.stereotype.Repository;
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | @Repository
6 | public interface ${className}Repository { //extends JpaRepository, ?> {
7 |
8 | }
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/java/repository/template-repository.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import org.springframework.stereotype.Repository;
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 | import ${package_model}.${className};
5 |
6 | @Repository
7 | public interface ${className}Repository extends JpaRepository<${className}, Integer> {
8 |
9 | }
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/java/service/template-clean-service.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import org.springframework.stereotype.Service;
3 | import org.springframework.transaction.annotation.Transactional;
4 |
5 | @Service
6 | @Transactional(readOnly = true)
7 | public class ${className}Service {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/java/service/template-service.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Service;
6 | import ${package_model}.${className};
7 | import ${package_repository}.${className}Repository;
8 | import org.springframework.transaction.annotation.Transactional;
9 | import java.util.List;
10 |
11 | @Service
12 | @Transactional(readOnly = true)
13 | public class ${className}Service {
14 |
15 | @Autowired
16 | private ${className}Repository ${paramClassName}Repository;
17 |
18 | public List<${className}> findAll() {
19 | return ${paramClassName}Repository.findAll();
20 | }
21 |
22 | public ${className} findOne(Integer id) {
23 | return ${paramClassName}Repository.findOne(id);
24 | }
25 |
26 | @Transactional(readOnly = false)
27 | public ${className} save(${className} entity) {
28 | return ${paramClassName}Repository.save(entity);
29 | }
30 |
31 | @Transactional(readOnly = false)
32 | public void delete(${className} entity) {
33 | ${paramClassName}Repository.delete(entity);
34 | }
35 |
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/resources/template-application.properties.txt:
--------------------------------------------------------------------------------
1 | # DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
2 | spring.datasource.url = jdbc:mysql://localhost/{nameDatabase}
3 | spring.datasource.username={userDatabase}
4 | spring.datasource.password={passwordDatabase}
5 |
6 | spring.datasource.tomcat.test-on-borrow=true
7 | spring.datasource.tomcat.validation-query=SELECT 1
8 | spring.datasource.sql-script-encoding=UTF-8
9 |
10 | # JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
11 | spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
12 | spring.jpa.openInView=true
13 | spring.jpa.show-sql=false
14 | spring.jpa.hibernate.ddl-auto=create-drop
15 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/template-clean-index.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
${className}
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/template-form.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
9 |
10 |
11 | New ${className}
12 |
13 |
14 |
15 |
New ${className}
16 |
Edit ${className}
17 |
18 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/template-index.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
List ${className}
15 |
16 |
New ${className}
17 |
18 |
19 |
20 |
21 | ${th_attributes}
22 |
23 |
24 |
25 |
26 | ${td_attributes}
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/template-layout.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 | Template Layout
10 |
11 |
12 |
13 |
14 |
15 |
16 |
35 |
36 |
37 |
msg success
38 |
msg error
39 |
40 |
41 |
Page content goes here
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/main/resources/templates/template-show.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
9 |
10 |
11 | Show ${className}
12 |
13 |
14 |
22 |
23 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/java/br/com/generate/test/ControllerGenerateTest.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.test;
2 |
3 | import br.com.generate.Layers;
4 | import br.com.generate.source.controller.ControllerGenerator;
5 | import br.com.generate.utils.LoadTemplateHelper;
6 | import org.junit.Test;
7 |
8 | import java.io.IOException;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | public class ControllerGenerateTest {
13 |
14 | @Test
15 | public void shouldGenerateController() throws IOException {
16 | ControllerGenerator controllerGenerator = new ControllerGenerator();
17 | String javaStrings = controllerGenerator.readTemplateFile("template-controller.txt");
18 |
19 | String expectedValue = new LoadTemplateHelper().loadDataset(Layers.CONTROLLER, "UserController.txt");
20 | String generatedValue = controllerGenerator.operationGenerate(javaStrings, "User", "name:String");
21 |
22 | assertEquals(expectedValue, generatedValue);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/java/br/com/generate/test/RepositoryCleanGeneratorBoundaryTest.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.test;
2 |
3 | import br.com.generate.Layers;
4 | import br.com.generate.source.repository.RepositoryCleanGenerator;
5 | import br.com.generate.utils.LoadTemplateHelper;
6 | import org.junit.Test;
7 |
8 | import java.io.IOException;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | public class RepositoryCleanGeneratorBoundaryTest {
13 |
14 | @Test
15 | public void shouldGenerateRepository() throws IOException {
16 | RepositoryCleanGenerator repositoryGenerator = new RepositoryCleanGenerator();
17 | String javaStrings = repositoryGenerator.readTemplateFile("template-clean-repository.txt");
18 |
19 | String expectedValue = new LoadTemplateHelper().loadDataset(Layers.REPOSITORY,"UserCleanRepository.txt");
20 | String generatedValue = repositoryGenerator.operationGenerate(javaStrings, "User", "name:String");
21 |
22 | assertEquals(expectedValue, generatedValue);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/java/br/com/generate/test/RepositoryGenerateTest.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.test;
2 |
3 | import br.com.generate.Layers;
4 | import br.com.generate.source.repository.RepositoryGenerator;
5 | import br.com.generate.utils.LoadTemplateHelper;
6 | import org.junit.Test;
7 |
8 | import java.io.IOException;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | public class RepositoryGenerateTest {
13 |
14 | @Test
15 | public void repositoryGeneratorTest() throws IOException {
16 | RepositoryGenerator repositoryGenerator = new RepositoryGenerator();
17 | String javaStrings = repositoryGenerator.readTemplateFile("template-repository.txt");
18 |
19 | String expectedValue = new LoadTemplateHelper().loadDataset(Layers.REPOSITORY, "UserRepository.txt");
20 | String generatedValue = repositoryGenerator.operationGenerate(javaStrings, "User", "name:String");
21 |
22 | assertEquals(expectedValue, generatedValue);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/java/br/com/generate/test/ServiceGenerateTest.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.test;
2 |
3 | import br.com.generate.Layers;
4 | import br.com.generate.source.service.ServiceGenerator;
5 | import br.com.generate.utils.LoadTemplateHelper;
6 | import org.junit.Test;
7 |
8 | import java.io.IOException;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | public class ServiceGenerateTest {
13 |
14 | @Test
15 | public void shouldGeneratorService() throws IOException {
16 | ServiceGenerator serviceGenerator = new ServiceGenerator();
17 | String javaStrings = serviceGenerator.readTemplateFile("template-service.txt");
18 |
19 | String expectedValue = new LoadTemplateHelper().loadDataset(Layers.SERVICE, "UserService.txt");
20 | String generatedValue = serviceGenerator.operationGenerate(javaStrings, "User", "name:String");
21 |
22 | assertEquals(expectedValue, generatedValue);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/java/br/com/generate/utils/FileGeneratorTestUtils.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.utils;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileNotFoundException;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 |
9 | import org.apache.commons.io.FileDeleteStrategy;
10 | import org.apache.commons.io.FileUtils;
11 | import org.apache.commons.io.IOUtils;
12 |
13 | public class FileGeneratorTestUtils {
14 |
15 | public static File convertJavaToText(File file, String layer, String outPutFileName) throws FileNotFoundException, IOException {
16 | InputStream in = new FileInputStream(file);
17 | String theString = IOUtils.toString(in, "UTF-8");
18 | File newTextFile = new File("src/test/resources/templates/java/" + layer + "/" + outPutFileName);
19 | FileUtils.writeStringToFile(newTextFile, theString);
20 | return newTextFile;
21 | }
22 |
23 | public static void deleteFileAndDirectory(File... files) throws IOException {
24 | for (File file : files) {
25 | FileDeleteStrategy.FORCE.delete(file);
26 | }
27 | // FileUtils.forceDelete(new File("src/main/java/br/com/example"));
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/java/br/com/generate/utils/LoadTemplateHelper.java:
--------------------------------------------------------------------------------
1 | package br.com.generate.utils;
2 |
3 | import org.apache.commons.io.IOUtils;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | public class LoadTemplateHelper {
9 |
10 | public String loadDataset(String layer, String fileNameTemplate) throws IOException {
11 | InputStream in = getClass().getResourceAsStream("/templates/java/" + layer + "/" + fileNameTemplate);
12 | String theString = IOUtils.toString(in, "UTF-8");
13 | return theString;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/resources/templates/java/controller/UserController.txt:
--------------------------------------------------------------------------------
1 | package br.com.example.controller;
2 |
3 | import java.util.List;
4 |
5 | import javax.validation.Valid;
6 |
7 | import org.hibernate.service.spi.ServiceException;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Controller;
10 | import org.springframework.ui.Model;
11 | import org.springframework.validation.BindingResult;
12 | import org.springframework.web.bind.annotation.DeleteMapping;
13 | import org.springframework.web.bind.annotation.GetMapping;
14 | import org.springframework.web.bind.annotation.ModelAttribute;
15 | import org.springframework.web.bind.annotation.PathVariable;
16 | import org.springframework.web.bind.annotation.PostMapping;
17 | import org.springframework.web.bind.annotation.PutMapping;
18 | import org.springframework.web.bind.annotation.RequestMapping;
19 | import org.springframework.web.servlet.mvc.support.RedirectAttributes;
20 | import br.com.example.model.User;
21 | import br.com.example.service.UserService;
22 |
23 | @Controller
24 | @RequestMapping("/users")
25 | public class UserController {
26 |
27 | private static final String MSG_SUCESS_INSERT = "User inserted successfully.";
28 | private static final String MSG_SUCESS_UPDATE = "User successfully changed.";
29 | private static final String MSG_SUCESS_DELETE = "Deleted User successfully.";
30 | private static final String MSG_ERROR = "Error.";
31 |
32 | @Autowired
33 | private UserService userService;
34 |
35 | @GetMapping
36 | public String index(Model model) {
37 | List all = userService.findAll();
38 | model.addAttribute("listUser", all);
39 | return "user/index";
40 | }
41 |
42 | @GetMapping("/{id}")
43 | public String show(Model model, @PathVariable("id") Integer id) {
44 | if (id != null) {
45 | User user = userService.findOne(id);
46 | model.addAttribute("user", user);
47 | }
48 | return "user/show";
49 | }
50 |
51 | @GetMapping(value = "/new")
52 | public String create(Model model, @ModelAttribute User entity) {
53 | model.addAttribute("user", entity);
54 | return "user/form";
55 | }
56 |
57 | @PostMapping
58 | public String create(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) {
59 | User user = null;
60 | try {
61 | user = userService.save(entity);
62 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_INSERT);
63 | } catch (Exception e) {
64 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
65 | e.printStackTrace();
66 | }
67 | return "redirect:/users/" + user.getId();
68 | }
69 |
70 | @GetMapping("/{id}/edit")
71 | public String update(Model model, @PathVariable("id") Integer id) {
72 | try {
73 | if (id != null) {
74 | User entity = userService.findOne(id);
75 | model.addAttribute("user", entity);
76 | }
77 | } catch (Exception e) {
78 | throw new ServiceException(e.getMessage());
79 | }
80 | return "user/form";
81 | }
82 |
83 | @PutMapping
84 | public String update(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) {
85 | User user = null;
86 | try {
87 | user = userService.save(entity);
88 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_UPDATE);
89 | } catch (Exception e) {
90 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
91 | e.printStackTrace();
92 | }
93 | return "redirect:/users/" + user.getId();
94 | }
95 |
96 | @DeleteMapping("/{id}")
97 | public String delete(@PathVariable("id") Integer id, RedirectAttributes redirectAttributes) {
98 | try {
99 | if (id != null) {
100 | User entity = userService.findOne(id);
101 | userService.delete(entity);
102 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_DELETE);
103 | }
104 | } catch (Exception e) {
105 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
106 | throw new ServiceException(e.getMessage());
107 | }
108 | return "redirect:/users/index";
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/resources/templates/java/controller/UserControllerTest.txt:
--------------------------------------------------------------------------------
1 | package br.com.example.controller;
2 |
3 | import java.util.List;
4 |
5 | import javax.validation.Valid;
6 |
7 | import org.hibernate.service.spi.ServiceException;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Controller;
10 | import org.springframework.ui.Model;
11 | import org.springframework.validation.BindingResult;
12 | import org.springframework.web.bind.annotation.DeleteMapping;
13 | import org.springframework.web.bind.annotation.GetMapping;
14 | import org.springframework.web.bind.annotation.ModelAttribute;
15 | import org.springframework.web.bind.annotation.PathVariable;
16 | import org.springframework.web.bind.annotation.PostMapping;
17 | import org.springframework.web.bind.annotation.PutMapping;
18 | import org.springframework.web.bind.annotation.RequestMapping;
19 | import org.springframework.web.servlet.mvc.support.RedirectAttributes;
20 | import br.com.example.model.User;
21 | import br.com.example.service.UserService;
22 |
23 | @Controller
24 | @RequestMapping("/users")
25 | public class UserController {
26 |
27 | private static final String MSG_SUCESS_INSERT = "User inserted successfully.";
28 | private static final String MSG_SUCESS_UPDATE = "User successfully changed.";
29 | private static final String MSG_SUCESS_DELETE = "Deleted User successfully.";
30 | private static final String MSG_ERROR = "Error.";
31 |
32 | @Autowired
33 | private UserService userService;
34 |
35 | @GetMapping
36 | public String index(Model model) {
37 | List all = userService.findAll();
38 | model.addAttribute("listUser", all);
39 | return "user/index";
40 | }
41 |
42 | @GetMapping("/{id}")
43 | public String show(Model model, @PathVariable("id") Integer id) {
44 | if (id != null) {
45 | User user = userService.findOne(id);
46 | model.addAttribute("user", user);
47 | }
48 | return "user/show";
49 | }
50 |
51 | @GetMapping(value = "/new")
52 | public String create(Model model, @ModelAttribute User entity) {
53 | model.addAttribute("user", entity);
54 | return "user/form";
55 | }
56 |
57 | @PostMapping
58 | public String create(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) {
59 | User user = null;
60 | try {
61 | user = userService.save(entity);
62 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_INSERT);
63 | } catch (Exception e) {
64 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
65 | e.printStackTrace();
66 | }
67 | return "redirect:/users/" + user.getId();
68 | }
69 |
70 | @GetMapping("/{id}/edit")
71 | public String update(Model model, @PathVariable("id") Integer id) {
72 | try {
73 | if (id != null) {
74 | User entity = userService.findOne(id);
75 | model.addAttribute("user", entity);
76 | }
77 | } catch (Exception e) {
78 | throw new ServiceException(e.getMessage());
79 | }
80 | return "user/form";
81 | }
82 |
83 | @PutMapping
84 | public String update(@Valid @ModelAttribute User entity, BindingResult result, RedirectAttributes redirectAttributes) {
85 | User user = null;
86 | try {
87 | user = userService.save(entity);
88 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_UPDATE);
89 | } catch (Exception e) {
90 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
91 | e.printStackTrace();
92 | }
93 | return "redirect:/users/" + user.getId();
94 | }
95 |
96 | @DeleteMapping("/{id}")
97 | public String delete(@PathVariable("id") Integer id, RedirectAttributes redirectAttributes) {
98 | try {
99 | if (id != null) {
100 | User entity = userService.findOne(id);
101 | userService.delete(entity);
102 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_DELETE);
103 | }
104 | } catch (Exception e) {
105 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
106 | throw new ServiceException(e.getMessage());
107 | }
108 | return "redirect:/users/index";
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/resources/templates/java/repository/UserCleanRepository.txt:
--------------------------------------------------------------------------------
1 | package br.com.example.repository;
2 | import org.springframework.stereotype.Repository;
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | @Repository
6 | public interface UserRepository { //extends JpaRepository, ?> {
7 |
8 | }
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/resources/templates/java/repository/UserRepository.txt:
--------------------------------------------------------------------------------
1 | package br.com.example.repository;
2 | import org.springframework.stereotype.Repository;
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 | import br.com.example.model.User;
5 |
6 | @Repository
7 | public interface UserRepository extends JpaRepository {
8 |
9 | }
--------------------------------------------------------------------------------
/spring-boot-generate/src/test/resources/templates/java/service/UserService.txt:
--------------------------------------------------------------------------------
1 | package br.com.example.service;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Service;
6 | import br.com.example.model.User;
7 | import br.com.example.repository.UserRepository;
8 | import org.springframework.transaction.annotation.Transactional;
9 | import java.util.List;
10 |
11 | @Service
12 | @Transactional(readOnly = true)
13 | public class UserService {
14 |
15 | @Autowired
16 | private UserRepository userRepository;
17 |
18 | public List findAll() {
19 | return userRepository.findAll();
20 | }
21 |
22 | public User findOne(Integer id) {
23 | return userRepository.findOne(id);
24 | }
25 |
26 | @Transactional(readOnly = false)
27 | public User save(User entity) {
28 | return userRepository.save(entity);
29 | }
30 |
31 | @Transactional(readOnly = false)
32 | public void delete(User entity) {
33 | userRepository.delete(entity);
34 | }
35 |
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | br.com.netodevel
5 | spring-scaffold-cli
6 | 1.1.0.BUILD-SNAPSHOT
7 |
8 |
9 | org.springframework.boot
10 | spring-boot-starter-parent
11 | 2.1.3.RELEASE
12 |
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-cli
18 | 2.1.3.RELEASE
19 |
20 |
21 |
22 | junit
23 | junit
24 |
25 |
26 |
27 | br.com
28 | spring-boot-generate
29 | 1.1.0.BUILD-SNAPSHOT
30 |
31 |
32 |
33 | br.com.netodevel
34 | templates
35 | 1.1.0.BUILD-SNAPSHOT
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-test
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/ScaffoldFactoryCommands.java:
--------------------------------------------------------------------------------
1 | package br.com.command;
2 |
3 | import br.com.command.controller.ControllerCommand;
4 | import br.com.command.controller.ControllerHandler;
5 | import br.com.command.model.ModelCommand;
6 | import br.com.command.model.ModelHandler;
7 | import br.com.command.repository.RepositoryCommand;
8 | import br.com.command.repository.RepositoryHandler;
9 | import br.com.command.scaffold.ScaffoldCommand;
10 | import br.com.command.scaffold.ScaffoldHandler;
11 | import br.com.command.service.ServiceCommand;
12 | import br.com.command.service.ServiceHandler;
13 | import br.com.command.setup.SetupScaffoldCommand;
14 | import br.com.command.setup.SetupScaffoldHandler;
15 | import br.com.command.template.TemplateCommand;
16 | import br.com.command.template.TemplateHandler;
17 | import br.com.generate.helpers.ScaffoldInfoHelper;
18 | import org.springframework.boot.cli.command.Command;
19 | import org.springframework.boot.cli.command.CommandFactory;
20 |
21 | import java.util.Arrays;
22 | import java.util.Collection;
23 |
24 | /**
25 | * all commands scaffold
26 | *
27 | * @author NetoDevel
28 | * @since 0.0.1
29 | */
30 | public class ScaffoldFactoryCommands implements CommandFactory {
31 |
32 | public Collection getCommands() {
33 | ScaffoldInfoHelper scaffoldInfoHelper = new ScaffoldInfoHelper();
34 | return Arrays.asList(
35 | new ModelCommand("model", "generate entities", new ModelHandler(scaffoldInfoHelper)),
36 | new RepositoryCommand("repository", "generate repositories", new RepositoryHandler()),
37 | new ServiceCommand("service", "generate services", new ServiceHandler()),
38 | new ControllerCommand("controller", "generate controllers", new ControllerHandler()),
39 | new ScaffoldCommand("scaffold", "generate api scaffold", new ScaffoldHandler()),
40 | new SetupScaffoldCommand("setup:scaffold", "setup scaffold", new SetupScaffoldHandler()),
41 | new TemplateCommand("template", "generate setup project", new TemplateHandler(scaffoldInfoHelper)));
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/controller/ControllerCommand.java:
--------------------------------------------------------------------------------
1 | package br.com.command.controller;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collection;
5 | import java.util.List;
6 |
7 | import org.springframework.boot.cli.command.HelpExample;
8 | import org.springframework.boot.cli.command.OptionParsingCommand;
9 | import org.springframework.boot.cli.command.options.OptionHandler;
10 |
11 | /**
12 | * @author NetoDevel
13 | * @since 0.0.1
14 | */
15 | public class ControllerCommand extends OptionParsingCommand {
16 |
17 | public ControllerCommand(String name, String description, OptionHandler handler) {
18 | super(name, description, handler);
19 | }
20 |
21 | @Override
22 | public String getUsageHelp() {
23 | return "[name-model]";
24 | }
25 |
26 | @Override
27 | public Collection getExamples() {
28 | List list = new ArrayList();
29 | list.add(new HelpExample("create controller kotlin", "controller -n User -l kotlin"));
30 | list.add(new HelpExample("create controller java", "controller -n User -l java"));
31 | return list;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/controller/ControllerHandler.java:
--------------------------------------------------------------------------------
1 | package br.com.command.controller;
2 |
3 | import java.io.IOException;
4 | import java.util.Arrays;
5 |
6 | import org.springframework.boot.cli.command.options.OptionHandler;
7 | import org.springframework.boot.cli.command.status.ExitStatus;
8 |
9 | import br.com.generate.source.controller.ControllerCleanGenerator;
10 | import br.com.generate.thymeleaf.ThymeleafCleanGenerator;
11 | import joptsimple.OptionSet;
12 | import joptsimple.OptionSpec;
13 |
14 | /**
15 | * @author NetoDevel
16 | * @since 0.0.1
17 | */
18 | public class ControllerHandler extends OptionHandler {
19 |
20 | @SuppressWarnings("unused")
21 | private OptionSpec nameEntity;
22 |
23 | @Override
24 | protected void options() {
25 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity to generate controller").withRequiredArg();
26 | }
27 |
28 | @Override
29 | protected ExitStatus run(OptionSet options) throws Exception {
30 | String nameClass = (String) options.valueOf("n");
31 | generateControllerJava(nameClass.trim());
32 | return ExitStatus.OK;
33 | }
34 |
35 | private void generateControllerJava(String nameClass) throws IOException {
36 | new ControllerCleanGenerator().generate(nameClass, null, "template-clean-controller.txt");
37 | new ThymeleafCleanGenerator().index(nameClass, null);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/model/ModelCommand.java:
--------------------------------------------------------------------------------
1 | package br.com.command.model;
2 |
3 | import org.springframework.boot.cli.command.OptionParsingCommand;
4 | import org.springframework.boot.cli.command.options.OptionHandler;
5 |
6 | /**
7 | * command model for generate entitys
8 | * @author NetoDevel
9 | * @since 0.0.1
10 | */
11 | public class ModelCommand extends OptionParsingCommand {
12 |
13 | public ModelCommand(String name, String description, OptionHandler handler) {
14 | super(name, description, handler);
15 | }
16 |
17 | @Override
18 | public String getUsageHelp() {
19 | return " ";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/model/ModelHandler.java:
--------------------------------------------------------------------------------
1 | package br.com.command.model;
2 |
3 | import br.com.generate.helpers.ScaffoldInfoHelper;
4 | import br.com.generator.core.GeneratorOptions;
5 | import br.com.templates.entity.EntityCache;
6 | import br.com.templates.entity.EntityExecutor;
7 | import br.com.templates.entity.EntityGenerator;
8 | import br.com.templates.entity.LombokDependencyGenerator;
9 | import joptsimple.OptionSet;
10 | import joptsimple.OptionSpec;
11 | import org.springframework.boot.cli.command.options.OptionHandler;
12 | import org.springframework.boot.cli.command.status.ExitStatus;
13 |
14 | import java.io.IOException;
15 | import java.util.Arrays;
16 | import java.util.HashMap;
17 | import java.util.Map;
18 |
19 | /**
20 | * @author NetoDevel
21 | * @since 0.0.1
22 | */
23 | public class ModelHandler extends OptionHandler {
24 |
25 | @SuppressWarnings("unused")
26 | private OptionSpec nameEntity;
27 |
28 | @SuppressWarnings("unused")
29 | private OptionSpec parametersEntity;
30 |
31 | private ScaffoldInfoHelper scaffoldInfoHelper;
32 |
33 | public ModelHandler() {
34 | }
35 |
36 | public ModelHandler(ScaffoldInfoHelper scaffoldInfoHelper) {
37 | this.scaffoldInfoHelper = scaffoldInfoHelper;
38 | }
39 |
40 | @Override
41 | protected void options() {
42 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity").withRequiredArg();
43 | this.parametersEntity = option(Arrays.asList("parameterEntity", "p"), "Parameters of entity").withRequiredArg();
44 | }
45 |
46 | @Override
47 | protected ExitStatus run(OptionSet options) throws Exception {
48 | String nameClass = (String) options.valueOf("n");
49 | String parametersClass = (String) options.valueOf("p");
50 |
51 | if (nameClass == null || nameClass.replace(" ", "").isEmpty()) {
52 | System.out.println("[INFO] - name of entity is required. use: -n ${entity_name}");
53 | return ExitStatus.ERROR;
54 | }
55 | if (parametersClass == null || parametersClass.replace(" ", "").isEmpty()){
56 | System.out.println("[INFO] - parameters of entity is required. use: -p ${parameters}");
57 | return ExitStatus.ERROR;
58 | }
59 |
60 | generateModelJava(nameClass, parametersClass);
61 | return ExitStatus.OK;
62 | }
63 |
64 | private void generateModelJava(String nameClass, String parameters) throws IOException {
65 | EntityExecutor entityExecutor = new EntityExecutor();
66 | entityExecutor.run(nameClass, parameters);
67 |
68 | lombokGenerate();
69 |
70 | for (EntityCache entity : entityExecutor.getEntities()) {
71 | GeneratorOptions generatorOptions = new GeneratorOptions();
72 | generatorOptions.setName(entity.getName().concat(".java"));
73 | generatorOptions.setDestination(scaffoldInfoHelper.getPathPackage().concat("models"));
74 |
75 | Map keyValue = new HashMap<>();
76 | keyValue.put("${content}", entity.getContent());
77 | keyValue.put("${package}", scaffoldInfoHelper.getPackage().concat(".models"));
78 |
79 | generatorOptions.setKeyValue(keyValue);
80 |
81 | EntityGenerator entityGenerator = new EntityGenerator(generatorOptions);
82 | entityGenerator.runGenerate();
83 | }
84 |
85 | }
86 |
87 | private void lombokGenerate() throws IOException {
88 | GeneratorOptions lombokDepsOptions = new GeneratorOptions();
89 | lombokDepsOptions.setTemplatePath(scaffoldInfoHelper.getPomPath());
90 | lombokDepsOptions.setDestination(scaffoldInfoHelper.getPomDest());
91 |
92 | LombokDependencyGenerator lombokDependencyGenerator = new LombokDependencyGenerator(lombokDepsOptions);
93 | lombokDependencyGenerator.runGenerate();
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/repository/RepositoryCommand.java:
--------------------------------------------------------------------------------
1 | package br.com.command.repository;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collection;
5 | import java.util.List;
6 |
7 | import org.springframework.boot.cli.command.HelpExample;
8 | import org.springframework.boot.cli.command.OptionParsingCommand;
9 | import org.springframework.boot.cli.command.options.OptionHandler;
10 |
11 | /**
12 | * @author NetoDevel
13 | * @since 0.0.1
14 | */
15 | public class RepositoryCommand extends OptionParsingCommand {
16 |
17 | public RepositoryCommand(String name, String description,OptionHandler handler) {
18 | super(name, description, handler);
19 | }
20 |
21 | @Override
22 | public String getUsageHelp() {
23 | return "[name-model]";
24 | }
25 |
26 | @Override
27 | public Collection getExamples() {
28 | List list = new ArrayList();
29 | list.add(new HelpExample("create repository kotlin", "repository -n User -l kotlin"));
30 | list.add(new HelpExample("create repository java", "repository -n User -l java"));
31 | return list;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/repository/RepositoryHandler.java:
--------------------------------------------------------------------------------
1 | package br.com.command.repository;
2 |
3 | import java.io.IOException;
4 | import java.util.Arrays;
5 |
6 | import joptsimple.OptionSet;
7 | import joptsimple.OptionSpec;
8 |
9 | import org.springframework.boot.cli.command.options.OptionHandler;
10 | import org.springframework.boot.cli.command.status.ExitStatus;
11 |
12 | import br.com.generate.source.repository.RepositoryCleanGenerator;
13 |
14 | /**
15 | * @author NetoDevel
16 | * @since 0.0.1
17 | */
18 | public class RepositoryHandler extends OptionHandler {
19 |
20 | @SuppressWarnings("unused")
21 | private OptionSpec nameEntity;
22 |
23 | @Override
24 | protected void options() {
25 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity to generate repository").withRequiredArg();
26 | }
27 |
28 | @Override
29 | protected ExitStatus run(OptionSet options) throws Exception {
30 | String nameClass = (String) options.valueOf("n");
31 | generateRepositoryJava(nameClass.trim());
32 | return ExitStatus.OK;
33 | }
34 |
35 | private void generateRepositoryJava(String nameClass) throws IOException {
36 | new RepositoryCleanGenerator().generate(nameClass, null, "template-clean-repository.txt");
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/scaffold/ScaffoldCommand.java:
--------------------------------------------------------------------------------
1 | package br.com.command.scaffold;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collection;
5 | import java.util.List;
6 |
7 | import org.springframework.boot.cli.command.HelpExample;
8 | import org.springframework.boot.cli.command.OptionParsingCommand;
9 | import org.springframework.boot.cli.command.options.OptionHandler;
10 |
11 | /**
12 | * @author NetoDevel
13 | * @since 0.0.1
14 | */
15 | public class ScaffoldCommand extends OptionParsingCommand{
16 |
17 | public ScaffoldCommand(String name, String description, OptionHandler handler) {
18 | super(name, description, handler);
19 | }
20 |
21 | @Override
22 | public String getUsageHelp() {
23 | return "[name-model] [parameters-model]";
24 | }
25 |
26 | @Override
27 | public Collection getExamples() {
28 | List list = new ArrayList();
29 | list.add(new HelpExample("scaffold", "scaffold -n User -p name:String"));
30 | return list;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/scaffold/ScaffoldHandler.java:
--------------------------------------------------------------------------------
1 | package br.com.command.scaffold;
2 |
3 | import java.io.IOException;
4 | import java.util.Arrays;
5 |
6 | import org.springframework.boot.cli.command.options.OptionHandler;
7 | import org.springframework.boot.cli.command.status.ExitStatus;
8 |
9 | import br.com.generate.source.controller.ControllerGenerator;
10 | import br.com.generate.source.model.ModelGenerator;
11 | import br.com.generate.source.repository.RepositoryGenerator;
12 | import br.com.generate.source.service.ServiceGenerator;
13 | import br.com.generate.thymeleaf.ThymeleafGenerator;
14 | import joptsimple.OptionSet;
15 | import joptsimple.OptionSpec;
16 |
17 | /**
18 | * @author NetoDevel
19 | * @since 0.0.1
20 | */
21 | public class ScaffoldHandler extends OptionHandler {
22 |
23 | @SuppressWarnings("unused")
24 | private OptionSpec nameEntity;
25 |
26 | @SuppressWarnings("unused")
27 | private OptionSpec parametersEntity;
28 |
29 | @SuppressWarnings("unused")
30 | private OptionSpec language;
31 |
32 | @Override
33 | protected void options() {
34 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity to generate scaffold").withRequiredArg();
35 | this.parametersEntity = option(Arrays.asList("parameterEntity", "p"), "Parameter of entity to generate scaffold").withRequiredArg();
36 | }
37 |
38 | @Override
39 | protected ExitStatus run(OptionSet options) throws Exception {
40 | String nameClass = (String) options.valueOf("n");
41 | String parametersClass = (String) options.valueOf("p");
42 | generateJava(nameClass.trim(), parametersClass);
43 | return ExitStatus.OK;
44 | }
45 |
46 | private void generateJava(String nameClass, String parametersClass) throws IOException {
47 | generateScaffoldJava(nameClass, parametersClass);
48 | }
49 |
50 | private void generateScaffoldJava(String nameClass, String parametersClass) throws IOException {
51 | try {
52 | if (new ModelGenerator().generate(nameClass, parametersClass, "template-model.txt")) {
53 | new RepositoryGenerator().generate(nameClass, null, "template-repository.txt");
54 | new ServiceGenerator().generate(nameClass, null, "template-service.txt");
55 | new ControllerGenerator().generate(nameClass, null, "template-controller.txt");
56 | new ThymeleafGenerator(nameClass, parametersClass);
57 | //new Migrations().create(nameClass, parametersClass);
58 | }
59 | } catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/service/ServiceCommand.java:
--------------------------------------------------------------------------------
1 | package br.com.command.service;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collection;
5 | import java.util.List;
6 |
7 | import org.springframework.boot.cli.command.HelpExample;
8 | import org.springframework.boot.cli.command.OptionParsingCommand;
9 | import org.springframework.boot.cli.command.options.OptionHandler;
10 |
11 | /**
12 | * @author NetoDevel
13 | * @since 0.0.1
14 | */
15 | public class ServiceCommand extends OptionParsingCommand {
16 |
17 | public ServiceCommand(String name, String description, OptionHandler handler) {
18 | super(name, description, handler);
19 | }
20 |
21 | @Override
22 | public String getUsageHelp() {
23 | return "[name-model]";
24 | }
25 |
26 | @Override
27 | public Collection getExamples() {
28 | List list = new ArrayList();
29 | list.add(new HelpExample("create service kotlin", "service -n User -l kotlin"));
30 | list.add(new HelpExample("create service java", "service -n User -l java"));
31 | return list;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/service/ServiceHandler.java:
--------------------------------------------------------------------------------
1 | package br.com.command.service;
2 |
3 | import java.io.IOException;
4 | import java.util.Arrays;
5 |
6 | import joptsimple.OptionSet;
7 | import joptsimple.OptionSpec;
8 |
9 | import org.springframework.boot.cli.command.options.OptionHandler;
10 | import org.springframework.boot.cli.command.status.ExitStatus;
11 |
12 | import br.com.generate.source.service.ServiceCleanGenerator;
13 |
14 | /**
15 | * @author NetoDevel
16 | * @since 0.0.1
17 | */
18 | public class ServiceHandler extends OptionHandler {
19 |
20 | @SuppressWarnings("unused")
21 | private OptionSpec nameEntity;
22 |
23 | @Override
24 | protected void options() {
25 | this.nameEntity = option(Arrays.asList("nameEntity", "n"), "Name of entity to generate service").withRequiredArg();
26 | }
27 |
28 | @Override
29 | protected ExitStatus run(OptionSet options) throws Exception {
30 | String nameClass = (String) options.valueOf("n");
31 | generateServiceJava(nameClass.trim());
32 | return ExitStatus.OK;
33 | }
34 |
35 | private void generateServiceJava(String nameClass) throws IOException {
36 | new ServiceCleanGenerator().generate(nameClass, null, "template-clean-service.txt");
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/setup/SetupScaffoldCommand.java:
--------------------------------------------------------------------------------
1 | package br.com.command.setup;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collection;
5 | import java.util.List;
6 |
7 | import org.springframework.boot.cli.command.HelpExample;
8 | import org.springframework.boot.cli.command.OptionParsingCommand;
9 | import org.springframework.boot.cli.command.options.OptionHandler;
10 |
11 | public class SetupScaffoldCommand extends OptionParsingCommand {
12 |
13 | public SetupScaffoldCommand(String name, String description, OptionHandler handler) {
14 | super(name, description, handler);
15 | }
16 |
17 | @Override
18 | public String getUsageHelp() {
19 | return "[namepackage][user-database][password-database][spring-version]";
20 | }
21 |
22 | @Override
23 | public Collection getExamples() {
24 | List list = new ArrayList();
25 | list.add(new HelpExample("setup scaffold", "spring setup:scaffold"));
26 | list.add(new HelpExample("setup scaffold with parameters", "spring setup:scaffold -p com.example -u root -p root"));
27 | return list;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/setup/SetupScaffoldHandler.java:
--------------------------------------------------------------------------------
1 | package br.com.command.setup;
2 |
3 | import java.util.Arrays;
4 |
5 | import joptsimple.OptionSet;
6 | import joptsimple.OptionSpec;
7 |
8 | import org.springframework.boot.cli.command.options.OptionHandler;
9 | import org.springframework.boot.cli.command.status.ExitStatus;
10 |
11 | import br.com.generate.resources.GeneratorProperties;
12 | import br.com.generate.setup.SetupGenerator;
13 |
14 | /**
15 | * @author NetoDevel
16 | * @since 0.0.1
17 | */
18 | public class SetupScaffoldHandler extends OptionHandler {
19 |
20 | @SuppressWarnings("unused")
21 | private OptionSpec namePackage;
22 |
23 | @SuppressWarnings("unused")
24 | private OptionSpec dataBase;
25 |
26 | @SuppressWarnings("unused")
27 | private OptionSpec userDatabase;
28 |
29 | @SuppressWarnings("unused")
30 | private OptionSpec passwordDatabase;
31 |
32 | @SuppressWarnings("unused")
33 | private OptionSpec springVersion;
34 |
35 | @Override
36 | protected void options() {
37 | this.namePackage = option(Arrays.asList("namePackage", "n"), "name of package to create scaffolds").withOptionalArg();
38 | this.dataBase = option(Arrays.asList("dataBaseName", "d"), "name of database").withOptionalArg();
39 | this.userDatabase = option(Arrays.asList("userDatabase", "u"), "username database for migrates").withOptionalArg();
40 | this.passwordDatabase = option(Arrays.asList("passwordDatabase", "p"), "password database for migrates").withOptionalArg();
41 | this.springVersion = option(Arrays.asList("springVersion", "s"), "spring version: 1.x or 2.x").withOptionalArg();
42 | }
43 |
44 | @Override
45 | protected ExitStatus run(OptionSet options) throws Exception {
46 | String namePackage = (String) options.valueOf("n");
47 | String nameDataBase = (String) options.valueOf("d");
48 | String userNameDatabase = (String) options.valueOf("u");
49 | String passwordDatabase = (String) options.valueOf("p");
50 | String springVersion = (String) options.valueOf("s");
51 |
52 | namePackage = namePackage != null ? namePackage.trim() : namePackage;
53 | nameDataBase = nameDataBase != null ? nameDataBase.trim() : nameDataBase;
54 | userNameDatabase = userNameDatabase != null ? userNameDatabase.trim() : userNameDatabase;
55 | passwordDatabase = passwordDatabase != null ? passwordDatabase.trim() : passwordDatabase;
56 | springVersion = springVersion != null ? springVersion.trim() : springVersion;
57 |
58 | new SetupGenerator(namePackage, nameDataBase, userNameDatabase, passwordDatabase, springVersion);
59 | new GeneratorProperties();
60 |
61 | return ExitStatus.OK;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/template/TemplateCommand.java:
--------------------------------------------------------------------------------
1 | package br.com.command.template;
2 |
3 | import org.springframework.boot.cli.command.OptionParsingCommand;
4 | import org.springframework.boot.cli.command.options.OptionHandler;
5 |
6 | public class TemplateCommand extends OptionParsingCommand {
7 |
8 | public TemplateCommand(String name, String description, OptionHandler handler) {
9 | super(name, description, handler);
10 | }
11 |
12 | @Override
13 | public String getUsageHelp() {
14 | return "[options] ";
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/java/br/com/command/template/TemplateHandler.java:
--------------------------------------------------------------------------------
1 | package br.com.command.template;
2 |
3 | import br.com.generate.helpers.ScaffoldInfoHelper;
4 | import br.com.generator.core.GeneratorOptions;
5 | import br.com.templates.ComposeTemplate;
6 | import br.com.templates.config.jms_aws_sqs.*;
7 | import br.com.templates.config.openj9.OpenJ9DockerfileGenerator;
8 | import br.com.templates.config.openj9.OpenJ9MavenPluginGenerator;
9 | import joptsimple.OptionSet;
10 | import joptsimple.OptionSpec;
11 | import org.springframework.boot.cli.command.options.OptionHandler;
12 | import org.springframework.boot.cli.command.status.ExitStatus;
13 |
14 | import java.io.IOException;
15 | import java.net.URISyntaxException;
16 | import java.util.HashMap;
17 | import java.util.List;
18 | import java.util.Map;
19 |
20 | import static java.util.Arrays.asList;
21 |
22 | public class TemplateHandler extends OptionHandler {
23 |
24 | private List templates = asList("jms-aws-sqs", "openj9");
25 |
26 | private OptionSpec template;
27 | private OptionSpec listTemplates;
28 |
29 | private ScaffoldInfoHelper scaffoldInfo;
30 |
31 | public TemplateHandler() {
32 | }
33 |
34 | public TemplateHandler(ScaffoldInfoHelper scaffoldInfoHelper) {
35 | this.scaffoldInfo = scaffoldInfoHelper;
36 | }
37 |
38 | @Override
39 | public void options() {
40 | this.template = option(asList("template", "t"), "name of template").withRequiredArg();
41 | this.listTemplates = option(asList("list"), "list of available templates");
42 | }
43 |
44 | @Override
45 | protected ExitStatus run(OptionSet options) {
46 | String template = (String) options.valueOf("t");
47 |
48 | if (templateNotExists(template)) return ExitStatus.ERROR;
49 | if (options.has(this.listTemplates)) output();
50 |
51 | if (options.has(this.template)) return executeTemplate(template);
52 | return ExitStatus.ERROR;
53 | }
54 |
55 | private ExitStatus executeTemplate(String template) {
56 | System.out.println("Generate config to: ".concat(template));
57 | if (template.equals("jms-aws-sqs")) {
58 | return generateJmsAwsSQS();
59 | }
60 | if (template.equals("openj9")) {
61 | return generateOpenJ9();
62 | }
63 | return ExitStatus.OK;
64 | }
65 |
66 | private ExitStatus generateOpenJ9() {
67 | try {
68 | GeneratorOptions generatorOptions = new GeneratorOptions();
69 | generatorOptions.setDestination(scaffoldInfo.getUserDir().concat("/deploy"));
70 |
71 | GeneratorOptions pomOptions = new GeneratorOptions();
72 | pomOptions.setTemplatePath(scaffoldInfo.getPomPath());
73 | pomOptions.setDestination(scaffoldInfo.getPomDest());
74 |
75 | Map keyValue = new HashMap<>();
76 | keyValue.put("${main_class}", scaffoldInfo.getPathMainClass());
77 | pomOptions.setPluginValues(keyValue);
78 |
79 | ComposeTemplate.runAll(scaffoldInfo.getPathPackage(), asList(new OpenJ9DockerfileGenerator(generatorOptions), new OpenJ9MavenPluginGenerator(pomOptions)));
80 | } catch (Exception e) {
81 | System.out.println("ERROR: ".concat(e.getMessage()));
82 | return ExitStatus.ERROR;
83 | }
84 | return ExitStatus.OK;
85 | }
86 |
87 | private ExitStatus generateJmsAwsSQS() {
88 | try {
89 | GeneratorOptions generatorOptions = new GeneratorOptions();
90 | generatorOptions.setDestination(scaffoldInfo.getPathPackage().concat("consumer"));
91 | HashMap keyValues = new HashMap();
92 | keyValues.put("${package}", scaffoldInfo.getPackage().concat(".consumer"));
93 | generatorOptions.setKeyValue(keyValues);
94 |
95 | GeneratorOptions sqsDependencyOptions = new GeneratorOptions();
96 | sqsDependencyOptions.setTemplatePath(scaffoldInfo.getPomPath());
97 | sqsDependencyOptions.setDestination(scaffoldInfo.getPomDest());
98 |
99 | GeneratorOptions sqsPropertyOptions = new GeneratorOptions();
100 | sqsPropertyOptions.setTemplatePath(scaffoldInfo.getApplicationProperties());
101 | sqsPropertyOptions.setDestination(scaffoldInfo.getApplicationPropertiesDest());
102 |
103 | ComposeTemplate.runAll(scaffoldInfo.getPathPackage(),
104 | asList(new MessageListenerGenerator(generatorOptions), new EntryPointMessageGenerator(generatorOptions),
105 | new ProducerMessageGenerator(generatorOptions), new SQSDependencyGenerator(sqsDependencyOptions),
106 | new SQSPropertiesGenerator(sqsPropertyOptions)));
107 |
108 | } catch (IOException | URISyntaxException e) {
109 | System.out.println("ERROR: ".concat(e.getMessage()));
110 | return ExitStatus.ERROR;
111 | }
112 |
113 | return ExitStatus.OK;
114 | }
115 |
116 | private boolean templateNotExists(String template) {
117 | if (template != null && !template.isEmpty()) {
118 | if (!templates.contains(template)) {
119 | System.out.println("template ".concat(template).concat(" not found. Use --list to see available template"));
120 | return true;
121 | }
122 | }
123 | return false;
124 | }
125 |
126 | private void output() {
127 | System.out.println("Templates available");
128 | System.out.println("* jms-aws-sqs");
129 | System.out.println("* openj9");
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.command.CommandFactory:
--------------------------------------------------------------------------------
1 | br.com.command.ScaffoldFactoryCommands
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/scaffold.info:
--------------------------------------------------------------------------------
1 | package:br.com.example
2 | user-database:root
3 | password-database:root
4 | springVersion:1.x
5 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/config/jms_aws_sqs/template-message-listener.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | public interface MessageListener {
4 | void queueListener(String String);
5 | }
6 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/java/controller/template-clean-controller.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import org.springframework.stereotype.Controller;
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 |
6 | @Controller
7 | @RequestMapping("/${path}")
8 | public class ${className}Controller {
9 |
10 | @GetMapping
11 | public String index() {
12 | return "${path}/index";
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/java/controller/template-controller.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | import java.util.List;
4 |
5 | import javax.validation.Valid;
6 |
7 | import org.hibernate.service.spi.ServiceException;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Controller;
10 | import org.springframework.ui.Model;
11 | import org.springframework.validation.BindingResult;
12 | import org.springframework.web.bind.annotation.DeleteMapping;
13 | import org.springframework.web.bind.annotation.GetMapping;
14 | import org.springframework.web.bind.annotation.ModelAttribute;
15 | import org.springframework.web.bind.annotation.PathVariable;
16 | import org.springframework.web.bind.annotation.PostMapping;
17 | import org.springframework.web.bind.annotation.PutMapping;
18 | import org.springframework.web.bind.annotation.RequestMapping;
19 | import org.springframework.web.servlet.mvc.support.RedirectAttributes;
20 | import ${package_model}.${className};
21 | import ${package_service}.${className}Service;
22 |
23 | @Controller
24 | @RequestMapping("/${paramClassName}s")
25 | public class ${className}Controller {
26 |
27 | private static final String MSG_SUCESS_INSERT = "${className} inserted successfully.";
28 | private static final String MSG_SUCESS_UPDATE = "${className} successfully changed.";
29 | private static final String MSG_SUCESS_DELETE = "Deleted ${className} successfully.";
30 | private static final String MSG_ERROR = "Error.";
31 |
32 | @Autowired
33 | private ${className}Service ${paramClassName}Service;
34 |
35 | @GetMapping
36 | public String index(Model model) {
37 | List<${className}> all = ${paramClassName}Service.findAll();
38 | model.addAttribute("list${className}", all);
39 | return "${paramClassName}/index";
40 | }
41 |
42 | @GetMapping("/{id}")
43 | public String show(Model model, @PathVariable("id") Integer id) {
44 | if (id != null) {
45 | ${className} ${paramClassName} = ${paramClassName}Service.findOne(id);
46 | model.addAttribute("${paramClassName}", ${paramClassName});
47 | }
48 | return "${paramClassName}/show";
49 | }
50 |
51 | @GetMapping(value = "/new")
52 | public String create(Model model, @ModelAttribute ${className} entity) {
53 | model.addAttribute("${paramClassName}", entity);
54 | return "${paramClassName}/form";
55 | }
56 |
57 | @PostMapping
58 | public String create(@Valid @ModelAttribute ${className} entity, BindingResult result, RedirectAttributes redirectAttributes) {
59 | ${className} ${paramClassName} = null;
60 | try {
61 | ${paramClassName} = ${paramClassName}Service.save(entity);
62 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_INSERT);
63 | } catch (Exception e) {
64 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
65 | e.printStackTrace();
66 | }
67 | return "redirect:/${url_path}/" + ${paramClassName}.getId();
68 | }
69 |
70 | @GetMapping("/{id}/edit")
71 | public String update(Model model, @PathVariable("id") Integer id) {
72 | try {
73 | if (id != null) {
74 | ${className} entity = ${paramClassName}Service.findOne(id);
75 | model.addAttribute("${paramClassName}", entity);
76 | }
77 | } catch (Exception e) {
78 | throw new ServiceException(e.getMessage());
79 | }
80 | return "${paramClassName}/form";
81 | }
82 |
83 | @PutMapping
84 | public String update(@Valid @ModelAttribute ${className} entity, BindingResult result, RedirectAttributes redirectAttributes) {
85 | ${className} ${paramClassName} = null;
86 | try {
87 | ${paramClassName} = ${paramClassName}Service.save(entity);
88 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_UPDATE);
89 | } catch (Exception e) {
90 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
91 | e.printStackTrace();
92 | }
93 | return "redirect:/${url_path}/" + ${paramClassName}.getId();
94 | }
95 |
96 | @DeleteMapping("/{id}")
97 | public String delete(@PathVariable("id") Integer id, RedirectAttributes redirectAttributes) {
98 | try {
99 | if (id != null) {
100 | ${className} entity = ${paramClassName}Service.findOne(id);
101 | ${paramClassName}Service.delete(entity);
102 | redirectAttributes.addFlashAttribute("success", MSG_SUCESS_DELETE);
103 | }
104 | } catch (Exception e) {
105 | redirectAttributes.addFlashAttribute("error", MSG_ERROR);
106 | throw new ServiceException(e.getMessage());
107 | }
108 | return "redirect:/${url_path}/index";
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/java/model/template-model.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import javax.persistence.Entity;
3 | import javax.persistence.GenerationType;
4 | import javax.persistence.Table;
5 | import javax.persistence.Column;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.Id;
8 | import java.io.Serializable;
9 | ${imports}
10 |
11 | @Entity
12 | @Table(name = "${name_table}")
13 | public class ${className} implements Serializable {
14 |
15 | private static final long serialVersionUID = 1L;
16 |
17 | @Id @GeneratedValue(strategy = GenerationType.AUTO)
18 | private Integer id;
19 | ${parameters}
20 | ${getters}
21 | public Integer getId() { return id; }
22 | public void setId(Integer id) { this.id = id; }
23 |
24 | }
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/java/repository/template-clean-repository.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import org.springframework.stereotype.Repository;
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | @Repository
6 | public interface ${className}Repository { //extends JpaRepository, ?> {
7 |
8 | }
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/java/repository/template-repository.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import org.springframework.stereotype.Repository;
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 | import ${package_model}.${className};
5 |
6 | @Repository
7 | public interface ${className}Repository extends JpaRepository<${className}, Integer> {
8 |
9 | }
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/java/service/template-clean-service.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 | import org.springframework.stereotype.Service;
3 | import org.springframework.transaction.annotation.Transactional;
4 |
5 | @Service
6 | @Transactional(readOnly = true)
7 | public class ${className}Service {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/java/service/template-service.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Service;
6 | import ${package_model}.${className};
7 | import ${package_repository}.${className}Repository;
8 | import org.springframework.transaction.annotation.Transactional;
9 | import java.util.List;
10 |
11 | @Service
12 | @Transactional(readOnly = true)
13 | public class ${className}Service {
14 |
15 | @Autowired
16 | private ${className}Repository ${paramClassName}Repository;
17 |
18 | public List<${className}> findAll() {
19 | return ${paramClassName}Repository.findAll();
20 | }
21 |
22 | public ${className} findOne(Integer id) {
23 | return ${paramClassName}Repository.findOne(id);
24 | }
25 |
26 | @Transactional(readOnly = false)
27 | public ${className} save(${className} entity) {
28 | return ${paramClassName}Repository.save(entity);
29 | }
30 |
31 | @Transactional(readOnly = false)
32 | public void delete(${className} entity) {
33 | ${paramClassName}Repository.delete(entity);
34 | }
35 |
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/resources/template-application.properties.txt:
--------------------------------------------------------------------------------
1 | # DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
2 | spring.datasource.url = jdbc:mysql://localhost/{nameDatabase}
3 | spring.datasource.username={userDatabase}
4 | spring.datasource.password={passwordDatabase}
5 |
6 | spring.datasource.tomcat.test-on-borrow=true
7 | spring.datasource.tomcat.validation-query=SELECT 1
8 | spring.datasource.sql-script-encoding=UTF-8
9 |
10 | # JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
11 | spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
12 | spring.jpa.openInView=true
13 | spring.jpa.show-sql=false
14 | spring.jpa.hibernate.ddl-auto=create-drop
15 |
16 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/template-clean-index.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
${className}
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/template-form.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
9 |
10 |
11 | New ${className}
12 |
13 |
14 |
15 |
New ${className}
16 |
Edit ${className}
17 |
18 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/template-index.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
List ${className}
15 |
16 |
New ${className}
17 |
18 |
19 |
20 |
21 | ${th_attributes}
22 |
23 |
24 |
25 |
26 | ${td_attributes}
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/template-layout.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 | Template Layout
10 |
11 |
12 |
13 |
14 |
15 |
16 |
35 |
36 |
37 |
msg success
38 |
msg error
39 |
40 |
41 |
Page content goes here
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/main/resources/templates/template-show.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
9 |
10 |
11 | Show ${className}
12 |
13 |
14 |
22 |
23 |
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/test/java/br/com/command/model/ModelHandlerTest.java:
--------------------------------------------------------------------------------
1 | package br.com.command.model;
2 |
3 | import br.com.generate.helpers.ScaffoldInfoHelper;
4 | import org.junit.Before;
5 | import org.junit.Rule;
6 | import org.junit.Test;
7 | import org.junit.rules.TemporaryFolder;
8 | import org.mockito.Mockito;
9 | import org.springframework.boot.cli.command.status.ExitStatus;
10 |
11 | import java.io.File;
12 | import java.io.IOException;
13 |
14 | import static org.junit.Assert.assertEquals;
15 | import static org.mockito.Mockito.mock;
16 |
17 | public class ModelHandlerTest {
18 |
19 | @Rule
20 | public TemporaryFolder temporaryFolder = new TemporaryFolder();
21 |
22 | private File temporaryPath;
23 |
24 | @Before
25 | public void setUp() throws IOException {
26 | temporaryPath = temporaryFolder.newFolder("test-path");
27 | }
28 |
29 | @Test
30 | public void shouldReturnOk() throws Exception {
31 | ScaffoldInfoHelper scaffoldInfoHelper = mock(ScaffoldInfoHelper.class);
32 |
33 | Mockito.when(scaffoldInfoHelper.getPackage()).thenReturn("com.example");
34 | Mockito.when(scaffoldInfoHelper.getPathPackage()).thenReturn(temporaryPath.getAbsolutePath().concat("\\com\\example\\"));
35 | Mockito.when(scaffoldInfoHelper.getPomPath()).thenReturn(getClass().getResource("/templates/template-fake-pom.xml").toURI().getPath());
36 | Mockito.when(scaffoldInfoHelper.getPomDest()).thenReturn(temporaryPath.getAbsolutePath().concat("/pom.xml"));
37 |
38 | ModelHandler modelHandler = new ModelHandler(scaffoldInfoHelper);
39 | ExitStatus exitStatus = modelHandler.run("-n", "User", "-p", "name:String Foo:references(relation:hasMany, name:String)");
40 | assertEquals(ExitStatus.OK, exitStatus);
41 | }
42 |
43 | @Test
44 | public void givenNoParameters_shouldReturnError() throws Exception {
45 | ScaffoldInfoHelper scaffoldInfoHelper = mock(ScaffoldInfoHelper.class);
46 |
47 | ModelHandler modelHandler = new ModelHandler(scaffoldInfoHelper);
48 | ExitStatus exitStatus = modelHandler.run("-n", "USer");
49 | assertEquals(ExitStatus.ERROR, exitStatus);
50 | }
51 |
52 | @Test
53 | public void givenNoClass_shouldReturnError() throws Exception {
54 | ScaffoldInfoHelper scaffoldInfoHelper = mock(ScaffoldInfoHelper.class);
55 |
56 | ModelHandler modelHandler = new ModelHandler(scaffoldInfoHelper);
57 | ExitStatus exitStatus = modelHandler.run("-p", "foo:String");
58 | assertEquals(ExitStatus.ERROR, exitStatus);
59 | }
60 |
61 | }
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/test/java/br/com/command/template/TemplateHandlerTest.java:
--------------------------------------------------------------------------------
1 | package br.com.command.template;
2 |
3 | import br.com.generate.helpers.ScaffoldInfoHelper;
4 | import org.junit.Before;
5 | import org.junit.Rule;
6 | import org.junit.Test;
7 | import org.junit.rules.TemporaryFolder;
8 | import org.mockito.Mockito;
9 | import org.springframework.boot.cli.command.status.ExitStatus;
10 |
11 | import java.io.File;
12 | import java.io.IOException;
13 |
14 | import static org.junit.Assert.assertEquals;
15 | import static org.junit.Assert.assertTrue;
16 | import static org.mockito.Mockito.mock;
17 |
18 | public class TemplateHandlerTest {
19 |
20 | @Rule
21 | public TemporaryFolder temporaryFolder = new TemporaryFolder();
22 |
23 | private File temporaryPath;
24 |
25 | @Before
26 | public void setUp() throws IOException {
27 | temporaryPath = temporaryFolder.newFolder("test-path");
28 | }
29 |
30 | @Test
31 | public void shouldReturnOk() throws Exception {
32 | ScaffoldInfoHelper scaffoldInfoHelper = mock(ScaffoldInfoHelper.class);
33 |
34 | Mockito.when(scaffoldInfoHelper.getPackage()).thenReturn("com.example");
35 | Mockito.when(scaffoldInfoHelper.getPathPackage()).thenReturn(temporaryPath.getAbsolutePath().concat("\\com\\example\\"));
36 |
37 | Mockito.when(scaffoldInfoHelper.getPomPath()).thenReturn(getClass().getResource("/templates/template-fake-pom.xml").toURI().getPath());
38 | Mockito.when(scaffoldInfoHelper.getPomDest()).thenReturn(temporaryPath.getAbsolutePath().concat("/pom.xml"));
39 |
40 | Mockito.when(scaffoldInfoHelper.getApplicationProperties()).thenReturn(getClass().getResource("/templates/fake-application.properties").toURI().getPath());
41 | Mockito.when(scaffoldInfoHelper.getApplicationPropertiesDest()).thenReturn(temporaryPath.getAbsolutePath().concat("/application.properties"));
42 |
43 | TemplateHandler templateHandler = new TemplateHandler(scaffoldInfoHelper);
44 | ExitStatus exitStatus = templateHandler.run("-t", "jms-aws-sqs");
45 | assertEquals(ExitStatus.OK, exitStatus);
46 | }
47 |
48 | @Test
49 | public void shouldReturnError() throws Exception {
50 | ScaffoldInfoHelper scaffoldInfoHelper = mock(ScaffoldInfoHelper.class);
51 |
52 | TemplateHandler templateHandler = new TemplateHandler(scaffoldInfoHelper);
53 | ExitStatus exitStatus = templateHandler.run("-t", "api-rest");
54 | assertEquals(ExitStatus.ERROR, exitStatus);
55 | }
56 |
57 | @Test
58 | public void givenArgumentList_shoudListTemplates() throws Exception {
59 | ScaffoldInfoHelper scaffoldInfoHelper = mock(ScaffoldInfoHelper.class);
60 |
61 | TemplateHandler templateHandler = new TemplateHandler(scaffoldInfoHelper);
62 | templateHandler.run("--list");
63 | }
64 |
65 | @Test
66 | public void givenOpenJ9_shouldReturnOk() throws Exception {
67 | ScaffoldInfoHelper scaffoldInfoHelper = mock(ScaffoldInfoHelper.class);
68 | Mockito.when(scaffoldInfoHelper.getUserDir()).thenReturn(temporaryPath.getAbsolutePath());
69 | Mockito.when(scaffoldInfoHelper.getPathPackage()).thenReturn("br.com.example");
70 | Mockito.when(scaffoldInfoHelper.getPathMainClass()).thenReturn("br.com.example.DemoApplication");
71 | Mockito.when(scaffoldInfoHelper.getPomPath()).thenReturn(getClass().getResource("/templates/template-fake-pom.xml").toURI().getPath());
72 | Mockito.when(scaffoldInfoHelper.getPomDest()).thenReturn(temporaryPath.getAbsolutePath().concat("/pom.xml"));
73 |
74 | TemplateHandler templateHandler = new TemplateHandler(scaffoldInfoHelper);
75 | ExitStatus exitStatus = templateHandler.run("-t", "openj9");
76 | assertEquals(ExitStatus.OK, exitStatus);
77 | }
78 |
79 | @Test
80 | public void givenOpenJ9_shouldCreateDockerfile() throws Exception {
81 | ScaffoldInfoHelper scaffoldInfoHelper = mock(ScaffoldInfoHelper.class);
82 |
83 | Mockito.when(scaffoldInfoHelper.getPathMainClass()).thenReturn("br.com.example.DemoApplication");
84 | Mockito.when(scaffoldInfoHelper.getUserDir()).thenReturn(temporaryPath.getAbsolutePath());
85 | Mockito.when(scaffoldInfoHelper.getPomPath()).thenReturn(getClass().getResource("/templates/template-fake-pom.xml").toURI().getPath());
86 | Mockito.when(scaffoldInfoHelper.getPomDest()).thenReturn(temporaryPath.getAbsolutePath().concat("/pom.xml"));
87 |
88 | TemplateHandler templateHandler = new TemplateHandler(scaffoldInfoHelper);
89 | templateHandler.run("-t", "openj9");
90 |
91 | assertTrue(new File(temporaryPath.getAbsolutePath().concat("/deploy/Dockerfile")).exists());
92 | }
93 |
94 |
95 | }
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/test/resources/templates/fake-application.properties:
--------------------------------------------------------------------------------
1 | my-var=my-value
--------------------------------------------------------------------------------
/spring-scaffold-cli/src/test/resources/templates/template-fake-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.springframework.boot
4 | spring-boot-starter-web
5 |
6 |
--------------------------------------------------------------------------------
/templates/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-cli
7 | br.com.netodevel
8 | 1.1.0.BUILD-SNAPSHOT
9 |
10 |
11 |
12 |
13 | org.apache.maven.plugins
14 | maven-compiler-plugin
15 |
16 | 8
17 | 8
18 |
19 |
20 |
21 |
22 | 4.0.0
23 |
24 | templates
25 |
26 |
27 | br.com.netodevel
28 | generator-core
29 | 1.0.0-BUILD-SNAPSHOT
30 | compile
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/ComposeTemplate.java:
--------------------------------------------------------------------------------
1 | package br.com.templates;
2 |
3 | import br.com.generator.core.Generator;
4 |
5 | import java.io.IOException;
6 | import java.util.List;
7 |
8 | public class ComposeTemplate {
9 |
10 | public static void runAll(String pathPackage, List generators) throws IOException {
11 | for (Generator generator : generators) {
12 | generator.runGenerate();
13 | }
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/config/jms_aws_sqs/EntryPointMessageGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.jms_aws_sqs;
2 |
3 | import br.com.generator.core.Generator;
4 | import br.com.generator.core.GeneratorOptions;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 |
9 | public class EntryPointMessageGenerator extends Generator {
10 |
11 | private GeneratorOptions generatorOptions;
12 |
13 | public EntryPointMessageGenerator() {
14 | }
15 |
16 | public EntryPointMessageGenerator(GeneratorOptions generatorOptions) {
17 | this.generatorOptions = generatorOptions;
18 | }
19 |
20 | public File runGenerate() throws IOException {
21 | this.generatorOptions.setTemplatePath("/templates/config/template-entrypoint-listener.txt");
22 | this.generatorOptions.setName("EntryPointMessage.java");
23 | return generate(this.generatorOptions);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/config/jms_aws_sqs/MessageListenerGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.jms_aws_sqs;
2 |
3 | import br.com.generator.core.Generator;
4 | import br.com.generator.core.GeneratorOptions;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 |
9 | public class MessageListenerGenerator extends Generator {
10 |
11 | private GeneratorOptions generatorOptions;
12 |
13 | public MessageListenerGenerator() {
14 | }
15 |
16 | public MessageListenerGenerator(GeneratorOptions generatorOptions) {
17 | this.generatorOptions = generatorOptions;
18 | }
19 |
20 | public File runGenerate() throws IOException {
21 | this.generatorOptions.setTemplatePath("/templates/config/template-message-listener.txt");
22 | this.generatorOptions.setName("MessageListener.java");
23 | return generate(this.generatorOptions);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/config/jms_aws_sqs/ProducerMessageGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.jms_aws_sqs;
2 |
3 |
4 | import br.com.generator.core.Generator;
5 | import br.com.generator.core.GeneratorOptions;
6 |
7 | import java.io.File;
8 | import java.io.IOException;
9 |
10 | public class ProducerMessageGenerator extends Generator {
11 |
12 | private GeneratorOptions generatorOptions;
13 |
14 | public ProducerMessageGenerator(GeneratorOptions generatorOptions) {
15 | this.generatorOptions = generatorOptions;
16 | }
17 |
18 | public File runGenerate() throws IOException {
19 | this.generatorOptions.setTemplatePath("/templates/config/template-producer-message.txt");
20 | this.generatorOptions.setName("ProducerMessage.java");
21 | return generate(this.generatorOptions);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/config/jms_aws_sqs/SQSDependencyGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.jms_aws_sqs;
2 |
3 | import br.com.generator.core.Generator;
4 | import br.com.generator.core.GeneratorOptions;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | public class SQSDependencyGenerator extends Generator {
12 |
13 | private GeneratorOptions generatorOptions;
14 |
15 | public SQSDependencyGenerator(GeneratorOptions generatorOptions) {
16 | this.generatorOptions = generatorOptions;
17 | }
18 |
19 | public File runGenerate() throws IOException {
20 | String dependency = "\n" +
21 | " \n" +
22 | " org.springframework.cloud\n" +
23 | " spring-cloud-aws-messaging\n" +
24 | " 2.1.1.RELEASE\n" +
25 | " \n" +
26 | " \n" +
27 | " org.springframework.cloud\n" +
28 | " spring-cloud-starter-aws\n" +
29 | " 2.1.1.RELEASE\n" +
30 | " \n" +
31 | "";
32 |
33 | Map keyValue = new HashMap();
34 | keyValue.put("", dependency);
35 | this.generatorOptions.setKeyValue(keyValue);
36 | this.generatorOptions.setName("pom.xml");
37 |
38 | return addDependency(this.generatorOptions);
39 | }
40 |
41 | @Override
42 | public void output(String pathPackage, String filename) {
43 | System.out.println("Add dependencies in ".concat(pathPackage.concat(filename)));
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/config/jms_aws_sqs/SQSPropertiesGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.jms_aws_sqs;
2 |
3 | import br.com.generator.core.Generator;
4 | import br.com.generator.core.GeneratorOptions;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 |
9 | public class SQSPropertiesGenerator extends Generator {
10 |
11 | private GeneratorOptions generatorOptions;
12 |
13 | public SQSPropertiesGenerator(GeneratorOptions generatorOptions) {
14 | this.generatorOptions = generatorOptions;
15 | }
16 |
17 | public File runGenerate() throws IOException {
18 | this.generatorOptions.setProperties(
19 | "\ncloud.aws.credentials.accessKey=xxxxxx\n" +
20 | "cloud.aws.credentials.secretKey=xxxxxx\n" +
21 | "cloud.aws.region.static=us-east-1\n" +
22 | "cloud.aws.stack.auto=false\n" +
23 | "cloud.aws.sqs.queue-name=my-queue.fifo");
24 | this.generatorOptions.setName("application.properties");
25 | return addProperties(this.generatorOptions);
26 | }
27 |
28 | @Override
29 | public void output(String pathPackage, String filename) {
30 | System.out.println("Add properties in ".concat(pathPackage.concat(filename)));
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/config/openj9/OpenJ9DockerfileGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.openj9;
2 |
3 | import br.com.generator.core.Generator;
4 | import br.com.generator.core.GeneratorOptions;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 |
9 | public class OpenJ9DockerfileGenerator extends Generator {
10 |
11 | private GeneratorOptions generatorOptions;
12 |
13 | public OpenJ9DockerfileGenerator(GeneratorOptions generatorOptions) {
14 | this.generatorOptions = generatorOptions;
15 | }
16 |
17 | @Override
18 | public File runGenerate() throws IOException {
19 | this.generatorOptions.setTemplatePath("/templates/config/openj9/dockerfile-template.txt");
20 | this.generatorOptions.setName("Dockerfile");
21 | return generate(this.generatorOptions);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/config/openj9/OpenJ9MavenPluginGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.openj9;
2 |
3 | import br.com.generator.core.Generator;
4 | import br.com.generator.core.GeneratorOptions;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | public class OpenJ9MavenPluginGenerator extends Generator {
12 |
13 | private GeneratorOptions generatorOptions;
14 |
15 | public OpenJ9MavenPluginGenerator(GeneratorOptions generatorOptions) {
16 | this.generatorOptions = generatorOptions;
17 | }
18 |
19 | @Override
20 | public File runGenerate() throws IOException {
21 | String plugin = "\n" +
22 | "\n" +
23 | " \n" +
24 | " org.apache.maven.plugins\n" +
25 | " maven-shade-plugin\n" +
26 | " 2.4.3\n" +
27 | " \n" +
28 | " \n" +
29 | " org.springframework.boot\n" +
30 | " spring-boot-maven-plugin\n" +
31 | " 2.1.5.RELEASE\n" +
32 | " \n" +
33 | " \n" +
34 | " \n" +
35 | " \n" +
36 | " package\n" +
37 | " \n" +
38 | " shade\n" +
39 | " \n" +
40 | " \n" +
41 | " \n" +
42 | " \n" +
44 | " META-INF/spring.handlers\n" +
45 | " \n" +
46 | " \n" +
48 | " META-INF/spring.factories\n" +
49 | " \n" +
50 | " \n" +
52 | " META-INF/spring.schemas\n" +
53 | " \n" +
54 | " \n" +
56 | " \n" +
58 | " ${main_class}\n" +
59 | " \n" +
60 | " \n" +
61 | " \n" +
62 | " \n" +
63 | " \n" +
64 | " \n" +
65 | " false\n" +
66 | " \n" +
67 | " \n";
68 |
69 | Map keyValue = new HashMap();
70 | keyValue.put("", plugin);
71 | this.generatorOptions.setKeyValue(keyValue);
72 | this.generatorOptions.setName("pom.xml");
73 |
74 | return addMavenPlugin(this.generatorOptions);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/entity/EntityCache.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.entity;
2 |
3 | public class EntityCache {
4 |
5 | private String name;
6 | private String content;
7 |
8 | public EntityCache(String name, String content) {
9 | this.name = name;
10 | this.content = content;
11 | }
12 |
13 | public String getName() {
14 | return name;
15 | }
16 |
17 | public void setName(String name) {
18 | this.name = name;
19 | }
20 |
21 | public String getContent() {
22 | return content;
23 | }
24 |
25 | public void setContent(String content) {
26 | this.content = content;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/entity/EntityGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.entity;
2 |
3 | import br.com.generator.core.Generator;
4 | import br.com.generator.core.GeneratorOptions;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 |
9 | public class EntityGenerator extends Generator {
10 |
11 | private GeneratorOptions generatorOptions;
12 |
13 | public EntityGenerator(GeneratorOptions generatorOptions) {
14 | this.generatorOptions = generatorOptions;
15 | }
16 |
17 | @Override
18 | public File runGenerate() throws IOException {
19 | this.generatorOptions.setTemplatePath("/templates.entity/entity-template.txt");
20 | return generate(this.generatorOptions);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/entity/EntityValidator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.entity;
2 |
3 | public class EntityValidator extends RuntimeException {
4 |
5 | public EntityValidator(String msg) {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/templates/src/main/java/br/com/templates/entity/LombokDependencyGenerator.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.entity;
2 |
3 | import br.com.generator.core.Generator;
4 | import br.com.generator.core.GeneratorOptions;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.util.Collections;
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | public class LombokDependencyGenerator extends Generator {
13 |
14 | private GeneratorOptions generatorOptions;
15 |
16 | public LombokDependencyGenerator(GeneratorOptions generatorOptions) {
17 | this.generatorOptions = generatorOptions;
18 | }
19 |
20 | public File runGenerate() throws IOException {
21 | String dependency = "\n" +
22 | " \n" +
23 | " org.projectlombok\n" +
24 | " lombok\n" +
25 | " provided\n" +
26 | " \n" +
27 | "";
28 |
29 | Map keyValue = new HashMap();
30 | keyValue.put("", dependency);
31 | this.generatorOptions.setKeyValue(keyValue);
32 | this.generatorOptions.setName("pom.xml");
33 | this.generatorOptions.setDependencies(Collections.singletonList("org.projectlombok"));
34 |
35 | return addDependency(this.generatorOptions);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/templates/src/main/resources/templates.entity/entity-template.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | import lombok.Data;
4 | import java.util.List;
5 |
6 | ${content}
--------------------------------------------------------------------------------
/templates/src/main/resources/templates/config/openj9/dockerfile-template.txt:
--------------------------------------------------------------------------------
1 | FROM adoptopenjdk/openjdk8-openj9
2 |
3 | RUN mkdir /opt/shareclasses
4 | RUN mkdir /opt/app
5 |
6 | ADD ../target/*.jar /opt/app.jar
7 |
8 | EXPOSE 8080
9 |
10 | CMD ["java", "-Xmx512m", "-XX:+IdleTuningGcOnIdle", "-Xtune:virtualized", "-Xscmx512m", "-Xscmaxaot100m", "-Xshareclasses:cacheDir=/opt/shareclasses", "-jar", "/opt/app.jar"]
11 |
--------------------------------------------------------------------------------
/templates/src/main/resources/templates/config/template-entrypoint-listener.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy;
6 | import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener;
7 |
8 | public class EntryPointMessage implements MessageListener {
9 |
10 | private static final Logger log = LogManager.getLogger(EntryPointMessage.class);
11 |
12 | @Override
13 | @SqsListener(value = "${cloud.aws.sqs.queue-name}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
14 | public void queueListener(String String) {
15 |
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/templates/src/main/resources/templates/config/template-message-listener.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | public interface MessageListener {
4 | void queueListener(String String);
5 | }
6 |
--------------------------------------------------------------------------------
/templates/src/main/resources/templates/config/template-producer-message.txt:
--------------------------------------------------------------------------------
1 | package ${package};
2 |
3 | import com.amazonaws.services.sqs.AmazonSQSAsync;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.beans.factory.annotation.Value;
6 | import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;
7 | import org.springframework.cloud.aws.messaging.core.SqsMessageHeaders;
8 | import org.springframework.stereotype.Component;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 | import java.util.UUID;
13 |
14 | @Component
15 | public class ProducerMessage {
16 |
17 | @Value("${cloud.aws.sqs.queue-name}")
18 | private String queueName;
19 |
20 | private QueueMessagingTemplate queueMessagingTemplate;
21 |
22 | @Autowired
23 | public ProducerMessage(AmazonSQSAsync amazonSqs) {
24 | this.queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs);
25 | }
26 |
27 | public void sendMessage() {
28 | this.queueMessagingTemplate.convertAndSend(queueName, "YOUR_MESSAGE_OBJECT", getHeader());
29 | }
30 |
31 | private Map getHeader() {
32 | Map headers = new HashMap<>();
33 | headers.put(SqsMessageHeaders.SQS_GROUP_ID_HEADER, UUID.randomUUID().toString());
34 | headers.put(SqsMessageHeaders.SQS_DEDUPLICATION_ID_HEADER, UUID.randomUUID().toString());
35 | headers.put(SqsMessageHeaders.CONTENT_TYPE, "application/json");
36 | return headers;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/templates/src/test/java/br/com/templates/config/jms_aws_sqs/EntryPointMessageGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.jms_aws_sqs;
2 |
3 |
4 | import br.com.generator.core.GeneratorOptions;
5 | import br.com.templates.helper.LoadTemplateTester;
6 | import org.apache.commons.io.FileUtils;
7 | import org.junit.Before;
8 | import org.junit.Rule;
9 | import org.junit.Test;
10 | import org.junit.rules.TemporaryFolder;
11 |
12 | import java.io.File;
13 | import java.io.IOException;
14 | import java.util.HashMap;
15 |
16 | import static junit.framework.TestCase.assertEquals;
17 | import static junit.framework.TestCase.assertTrue;
18 |
19 | public class EntryPointMessageGeneratorTest {
20 |
21 | private LoadTemplateTester loadTemplateTester;
22 |
23 | @Rule
24 | public TemporaryFolder temporaryFolder = new TemporaryFolder();
25 |
26 | private File temporaryPath;
27 |
28 | @Before
29 | public void setUp() throws IOException {
30 | temporaryPath = temporaryFolder.newFolder("test-templates");
31 | loadTemplateTester = new LoadTemplateTester();
32 | }
33 |
34 | @Test
35 | public void shouldCreateFile() throws IOException {
36 | GeneratorOptions generatorOptions = new GeneratorOptions();
37 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
38 |
39 | HashMap keyValue = new HashMap();
40 | keyValue.put("${package}", "br.com.example");
41 | generatorOptions.setKeyValue(keyValue);
42 |
43 | EntryPointMessageGenerator entryPointMessageGenerator = new EntryPointMessageGenerator(generatorOptions);
44 |
45 | File file = entryPointMessageGenerator.runGenerate();
46 | assertTrue(file.exists());
47 | }
48 |
49 | @Test
50 | public void shouldReturnContent() throws IOException {
51 | GeneratorOptions generatorOptions = new GeneratorOptions();
52 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
53 |
54 | HashMap keyValue = new HashMap();
55 | keyValue.put("${package}", "br.com.example");
56 | generatorOptions.setKeyValue(keyValue);
57 |
58 | EntryPointMessageGenerator entryPointMessageGenerator = new EntryPointMessageGenerator(generatorOptions);
59 | File file = entryPointMessageGenerator.runGenerate();
60 |
61 | String contentReturned = FileUtils.readFileToString(file);
62 | String contentExpected = loadTemplateTester.loadTemplate("/templates/config/template-entrypoint-listener-test.txt");
63 |
64 | assertEquals(contentExpected, contentReturned);
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/templates/src/test/java/br/com/templates/config/jms_aws_sqs/MessageListenerGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.jms_aws_sqs;
2 |
3 | import br.com.generator.core.GeneratorOptions;
4 | import br.com.templates.helper.LoadTemplateTester;
5 | import org.apache.commons.io.FileUtils;
6 | import org.junit.Before;
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.junit.rules.TemporaryFolder;
10 |
11 | import java.io.File;
12 | import java.io.IOException;
13 | import java.util.HashMap;
14 |
15 | import static junit.framework.TestCase.assertEquals;
16 | import static junit.framework.TestCase.assertTrue;
17 |
18 | public class MessageListenerGeneratorTest {
19 |
20 | private LoadTemplateTester loadTemplateTester;
21 |
22 | @Rule
23 | public TemporaryFolder temporaryFolder = new TemporaryFolder();
24 |
25 | private File temporaryPath;
26 |
27 | @Before
28 | public void setUp() throws IOException {
29 | temporaryPath = temporaryFolder.newFolder("test-templates");
30 | loadTemplateTester = new LoadTemplateTester();
31 | }
32 |
33 | @Test
34 | public void shouldCreateFile() throws IOException {
35 | GeneratorOptions generatorOptions = new GeneratorOptions();
36 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
37 |
38 | HashMap keyValue = new HashMap();
39 | keyValue.put("${package}", "br.com.example");
40 | generatorOptions.setKeyValue(keyValue);
41 |
42 | MessageListenerGenerator messageListenerGenerator = new MessageListenerGenerator(generatorOptions);
43 | File file = messageListenerGenerator.runGenerate();
44 | assertTrue(file.exists());
45 | }
46 |
47 | @Test
48 | public void shouldReturnContent() throws IOException {
49 | GeneratorOptions generatorOptions = new GeneratorOptions();
50 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
51 |
52 | HashMap keyValue = new HashMap();
53 | keyValue.put("${package}", "br.com.example");
54 | generatorOptions.setKeyValue(keyValue);
55 |
56 | MessageListenerGenerator messageListenerGenerator = new MessageListenerGenerator(generatorOptions);
57 | File file = messageListenerGenerator.runGenerate();
58 |
59 | String contentReturned = FileUtils.readFileToString(file);
60 | String contentExpected = loadTemplateTester.loadTemplate("/templates/config/template-message-listener-test.txt");
61 |
62 | assertEquals(contentExpected, contentReturned);
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/templates/src/test/java/br/com/templates/config/jms_aws_sqs/ProducerMessageGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.jms_aws_sqs;
2 |
3 | import br.com.generator.core.GeneratorOptions;
4 | import br.com.templates.helper.LoadTemplateTester;
5 | import org.apache.commons.io.FileUtils;
6 | import org.junit.Before;
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.junit.rules.TemporaryFolder;
10 |
11 | import java.io.File;
12 | import java.io.IOException;
13 | import java.util.HashMap;
14 |
15 | import static junit.framework.TestCase.assertEquals;
16 | import static junit.framework.TestCase.assertTrue;
17 |
18 | public class ProducerMessageGeneratorTest {
19 |
20 | private LoadTemplateTester loadTemplateTester;
21 |
22 | @Rule
23 | public TemporaryFolder temporaryFolder = new TemporaryFolder();
24 |
25 | private File temporaryPath;
26 |
27 | @Before
28 | public void setUp() throws IOException {
29 | temporaryPath = temporaryFolder.newFolder("test-templates");
30 | loadTemplateTester = new LoadTemplateTester();
31 | }
32 |
33 | @Test
34 | public void shouldCreateFile() throws IOException {
35 | GeneratorOptions generatorOptions = new GeneratorOptions();
36 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
37 |
38 | HashMap keyValue = new HashMap();
39 | keyValue.put("${package}", "br.com.example");
40 | generatorOptions.setKeyValue(keyValue);
41 |
42 | ProducerMessageGenerator messageListenerGenerator = new ProducerMessageGenerator(generatorOptions);
43 | File file = messageListenerGenerator.runGenerate();
44 | assertTrue(file.exists());
45 | }
46 |
47 | @Test
48 | public void shouldReturnContent() throws IOException {
49 | GeneratorOptions generatorOptions = new GeneratorOptions();
50 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
51 |
52 | HashMap keyValue = new HashMap();
53 | keyValue.put("${package}", "br.com.example");
54 | generatorOptions.setKeyValue(keyValue);
55 |
56 | ProducerMessageGenerator messageListenerGenerator = new ProducerMessageGenerator(generatorOptions);
57 | File file = messageListenerGenerator.runGenerate();
58 |
59 | String contentReturned = FileUtils.readFileToString(file);
60 | String contentExpected = loadTemplateTester.loadTemplate("/templates/config/template-producer-message-test.txt");
61 |
62 | assertEquals(contentExpected, contentReturned);
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/templates/src/test/java/br/com/templates/config/jms_aws_sqs/SQSDependencyGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.jms_aws_sqs;
2 |
3 | import br.com.generator.core.GeneratorOptions;
4 | import br.com.templates.helper.LoadTemplateTester;
5 | import org.apache.commons.io.FileUtils;
6 | import org.junit.Before;
7 | import org.junit.Ignore;
8 | import org.junit.Rule;
9 | import org.junit.Test;
10 | import org.junit.rules.TemporaryFolder;
11 |
12 | import java.io.File;
13 | import java.io.IOException;
14 | import java.net.URISyntaxException;
15 |
16 | import static junit.framework.TestCase.assertEquals;
17 | import static junit.framework.TestCase.assertTrue;
18 |
19 | public class SQSDependencyGeneratorTest {
20 |
21 | private LoadTemplateTester loadTemplateTester;
22 |
23 | @Rule
24 | public TemporaryFolder temporaryFolder = new TemporaryFolder();
25 |
26 | private File temporaryPath;
27 |
28 | @Before
29 | public void setUp() throws IOException {
30 | temporaryPath = temporaryFolder.newFolder("test-templates");
31 | loadTemplateTester = new LoadTemplateTester();
32 | }
33 |
34 | @Test
35 | public void shouldCreateFile() throws IOException, URISyntaxException {
36 | GeneratorOptions generatorOptions = new GeneratorOptions();
37 | generatorOptions.setDestination(temporaryPath.getAbsolutePath().concat("/pom.xml"));
38 | generatorOptions.setTemplatePath(getClass().getResource("/templates/config/template-pom.xml").toURI().getPath());
39 |
40 | SQSDependencyGenerator sqsDependencyGenerator = new SQSDependencyGenerator(generatorOptions);
41 |
42 | File file = sqsDependencyGenerator.runGenerate();
43 |
44 | assertTrue(file.exists());
45 | }
46 |
47 | @Test
48 | @Ignore
49 | public void shouldReturnContent() throws IOException {
50 | GeneratorOptions generatorOptions = new GeneratorOptions();
51 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
52 | generatorOptions.setTemplatePath("/templates/config/template-pom.xml");
53 |
54 | SQSDependencyGenerator sqsDependencyGenerator = new SQSDependencyGenerator(generatorOptions);
55 | File file = sqsDependencyGenerator.runGenerate();
56 |
57 | String contentReturned = FileUtils.readFileToString(file);
58 | String contentExpected = loadTemplateTester.loadTemplate("/templates/config/template-pom-test.xml");
59 |
60 | assertEquals(contentExpected.replace(" ", "").trim(), contentReturned.replace(" ", "").trim());
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/templates/src/test/java/br/com/templates/config/openj9/OpenJ9DockerfileGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.openj9;
2 |
3 | import br.com.generator.core.GeneratorOptions;
4 | import br.com.templates.helper.LoadTemplateTester;
5 | import org.apache.commons.io.FileUtils;
6 | import org.junit.Before;
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.junit.rules.TemporaryFolder;
10 |
11 | import java.io.File;
12 | import java.io.IOException;
13 |
14 | import static junit.framework.TestCase.assertEquals;
15 | import static junit.framework.TestCase.assertTrue;
16 |
17 | public class OpenJ9DockerfileGeneratorTest {
18 |
19 | private LoadTemplateTester loadTemplateTester;
20 |
21 | @Rule
22 | public TemporaryFolder temporaryFolder = new TemporaryFolder();
23 |
24 | private File temporaryPath;
25 |
26 | @Before
27 | public void setUp() throws IOException {
28 | temporaryPath = temporaryFolder.newFolder("test-templates");
29 | loadTemplateTester = new LoadTemplateTester();
30 | }
31 |
32 | @Test
33 | public void shouldCreateFile() throws IOException {
34 | GeneratorOptions generatorOptions = new GeneratorOptions();
35 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
36 |
37 | OpenJ9DockerfileGenerator entryPointMessageGenerator = new OpenJ9DockerfileGenerator(generatorOptions);
38 | File file = entryPointMessageGenerator.runGenerate();
39 | assertTrue(file.exists());
40 | }
41 |
42 | @Test
43 | public void shouldReturnContent() throws IOException {
44 | GeneratorOptions generatorOptions = new GeneratorOptions();
45 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
46 |
47 | OpenJ9DockerfileGenerator entryPointMessageGenerator = new OpenJ9DockerfileGenerator(generatorOptions);
48 | File file = entryPointMessageGenerator.runGenerate();
49 |
50 | String contentReturned = FileUtils.readFileToString(file);
51 | String contentExpected = loadTemplateTester.loadTemplate("/templates/config/openj9/dockerfile-template-test.txt");
52 |
53 | assertEquals(contentExpected, contentReturned);
54 | }
55 | }
--------------------------------------------------------------------------------
/templates/src/test/java/br/com/templates/config/openj9/OpenJ9MavenPluginGeneratorTest.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.config.openj9;
2 |
3 | import br.com.generator.core.GeneratorOptions;
4 | import br.com.templates.config.jms_aws_sqs.SQSDependencyGenerator;
5 | import br.com.templates.helper.LoadTemplateTester;
6 | import org.apache.commons.io.FileUtils;
7 | import org.junit.Before;
8 | import org.junit.Ignore;
9 | import org.junit.Rule;
10 | import org.junit.Test;
11 | import org.junit.rules.TemporaryFolder;
12 |
13 | import java.io.File;
14 | import java.io.IOException;
15 | import java.net.URISyntaxException;
16 | import java.util.HashMap;
17 | import java.util.Map;
18 |
19 | import static junit.framework.TestCase.assertEquals;
20 | import static junit.framework.TestCase.assertTrue;
21 |
22 | public class OpenJ9MavenPluginGeneratorTest {
23 |
24 | private LoadTemplateTester loadTemplateTester;
25 |
26 | @Rule
27 | public TemporaryFolder temporaryFolder = new TemporaryFolder();
28 |
29 | private File temporaryPath;
30 |
31 | @Before
32 | public void setUp() throws IOException {
33 | temporaryPath = temporaryFolder.newFolder("test-templates");
34 | loadTemplateTester = new LoadTemplateTester();
35 | }
36 |
37 | @Test
38 | public void shouldCreateFile() throws IOException, URISyntaxException {
39 | GeneratorOptions generatorOptions = new GeneratorOptions();
40 | generatorOptions.setDestination(temporaryPath.getAbsolutePath().concat("/pom.xml"));
41 | generatorOptions.setTemplatePath(getClass().getResource("/templates/config/template-pom.xml").toURI().getPath());
42 | Map keyValue = new HashMap<>();
43 | keyValue.put("${main_class}", "br.com.example.DemoApplication");
44 | generatorOptions.setKeyValue(keyValue);
45 |
46 | OpenJ9MavenPluginGenerator sqsDependencyGenerator = new OpenJ9MavenPluginGenerator(generatorOptions);
47 |
48 | File file = sqsDependencyGenerator.runGenerate();
49 | assertTrue(file.exists());
50 | }
51 |
52 | @Test
53 | @Ignore
54 | public void shouldReturnContent() throws IOException {
55 | GeneratorOptions generatorOptions = new GeneratorOptions();
56 | generatorOptions.setDestination(temporaryPath.getAbsolutePath());
57 | generatorOptions.setTemplatePath("/templates/config/template-pom.xml");
58 | Map keyValue = new HashMap<>();
59 | keyValue.put("${main_class}", "br.com.example.DemoApplication");
60 | generatorOptions.setKeyValue(keyValue);
61 |
62 | SQSDependencyGenerator sqsDependencyGenerator = new SQSDependencyGenerator(generatorOptions);
63 | File file = sqsDependencyGenerator.runGenerate();
64 |
65 | String contentReturned = FileUtils.readFileToString(file);
66 | String contentExpected = loadTemplateTester.loadTemplate("/templates/config/openj9/template-pom-test.xml");
67 |
68 | assertEquals(contentExpected.replace(" ", "").trim(), contentReturned.replace(" ", "").trim());
69 | }
70 | }
--------------------------------------------------------------------------------
/templates/src/test/java/br/com/templates/entity/EntityCacheTest.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.entity;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.assertEquals;
7 |
8 | public class EntityCacheTest {
9 |
10 | private EntityExecutor entityExecutor;
11 |
12 | @Before
13 | public void setUp() {
14 | entityExecutor = new EntityExecutor();
15 | }
16 |
17 | @Test
18 | public void shouldReturnTwoEntities() {
19 | String valueArgument = "name:String age:Int Foo:references(relation:hasMany, foo:String)";
20 | entityExecutor.run("User", valueArgument);
21 | assertEquals(2, entityExecutor.getEntities().size());
22 | }
23 |
24 | @Test
25 | public void shouldReturnContentOfUser() {
26 | String valueArgument = "name:String age:Int Foo:references(relation:hasMany, foo:String)";
27 | entityExecutor.run("User", valueArgument);
28 |
29 | String expectedValue = "" +
30 | "@Entity\n" +
31 | "@Data\n" +
32 | "public class User {\n" +
33 | "\t\n" +
34 | "\t@Id @GeneratedValue(strategy = GenerationType.AUTO)\n" +
35 | "\tprivate Integer id;\n" +
36 | "\tprivate String name;\n" +
37 | "\tprivate Integer age;\n" +
38 | "\t\t\n" +
39 | "\t@OneToMany\n" +
40 | "\tprivate List foo;\n" +
41 | "}\n";
42 |
43 | assertEquals(expectedValue.trim(), entityExecutor.getEntities().get(1).getContent().trim());
44 | }
45 |
46 | @Test
47 | public void shouldReturnContentOfFoo() {
48 | String valueArgument = "name:String age:Int Foo:references(relation:hasMany, foo:String)";
49 | entityExecutor.run("User", valueArgument);
50 |
51 | String expectedValue = "" +
52 | "@Entity\n" +
53 | "@Data\n" +
54 | "public class Foo {\n" +
55 | "\tprivate String foo;\n" +
56 | "}\n";
57 | assertEquals(expectedValue.trim(), entityExecutor.getEntities().get(0).getContent());
58 | }
59 |
60 | @Test
61 | public void shouldReturnThreeCount() {
62 | String valueArgument = "name:String age:Int Foo:references(relation:hasMany, foo:String) Bar:references(relation:belongsTo, bar:String)";
63 | entityExecutor.run("User", valueArgument);
64 | assertEquals(3, entityExecutor.getEntities().size());
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/templates/src/test/java/br/com/templates/helper/LoadTemplateTester.java:
--------------------------------------------------------------------------------
1 | package br.com.templates.helper;
2 |
3 | import org.apache.commons.io.IOUtils;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | public class LoadTemplateTester {
9 |
10 | public String loadTemplate(String templatePath) throws IOException {
11 | InputStream in = getClass().getResourceAsStream(templatePath);
12 | String theString = IOUtils.toString(in, "UTF-8");
13 | return theString;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/templates/src/test/resources/templates/config/fake-application.properties:
--------------------------------------------------------------------------------
1 | my-var=my-value
--------------------------------------------------------------------------------
/templates/src/test/resources/templates/config/openj9/dockerfile-template-test.txt:
--------------------------------------------------------------------------------
1 | FROM adoptopenjdk/openjdk8-openj9
2 |
3 | RUN mkdir /opt/shareclasses
4 | RUN mkdir /opt/app
5 |
6 | ADD ../target/*.jar /opt/app.jar
7 |
8 | EXPOSE 8080
9 |
10 | CMD ["java", "-Xmx512m", "-XX:+IdleTuningGcOnIdle", "-Xtune:virtualized", "-Xscmx512m", "-Xscmaxaot100m", "-Xshareclasses:cacheDir=/opt/shareclasses", "-jar", "/opt/app.jar"]
11 |
--------------------------------------------------------------------------------
/templates/src/test/resources/templates/config/openj9/template-pom-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.springframework.boot
4 | spring-boot-starter-web
5 |
6 |
7 | org.springframework.cloud
8 | spring-cloud-aws-messaging
9 | 2.1.1.RELEASE
10 |
11 |
12 | org.springframework.cloud
13 | spring-cloud-starter-aws
14 | 2.1.1.RELEASE
15 |
16 |
17 |
18 |
19 |
20 |
21 | org.apache.maven.plugins
22 | maven-shade-plugin
23 | 2.4.3
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-maven-plugin
28 | 2.1.5.RELEASE
29 |
30 |
31 |
32 |
33 | package
34 |
35 | shade
36 |
37 |
38 |
39 |
41 | META-INF/spring.handlers
42 |
43 |
45 | META-INF/spring.factories
46 |
47 |
49 | META-INF/spring.schemas
50 |
51 |
53 |
55 | br.com.example.DemoApplication
56 |
57 |
58 |
59 |
60 |
61 |
62 | false
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/templates/src/test/resources/templates/config/template-entrypoint-listener-test.txt:
--------------------------------------------------------------------------------
1 | package br.com.example;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy;
6 | import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener;
7 |
8 | public class EntryPointMessage implements MessageListener {
9 |
10 | private static final Logger log = LogManager.getLogger(EntryPointMessage.class);
11 |
12 | @Override
13 | @SqsListener(value = "${cloud.aws.sqs.queue-name}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
14 | public void queueListener(String String) {
15 |
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/templates/src/test/resources/templates/config/template-message-listener-test.txt:
--------------------------------------------------------------------------------
1 | package br.com.example;
2 |
3 | public interface MessageListener {
4 | void queueListener(String String);
5 | }
6 |
--------------------------------------------------------------------------------
/templates/src/test/resources/templates/config/template-pom-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.springframework.boot
4 | spring-boot-starter-web
5 |
6 |
7 | org.springframework.cloud
8 | spring-cloud-aws-messaging
9 | 2.1.1.RELEASE
10 |
11 |
12 | org.springframework.cloud
13 | spring-cloud-starter-aws
14 | 2.1.1.RELEASE
15 |
16 |
--------------------------------------------------------------------------------
/templates/src/test/resources/templates/config/template-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.springframework.boot
4 | spring-boot-starter-web
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/templates/src/test/resources/templates/config/template-producer-message-test.txt:
--------------------------------------------------------------------------------
1 | package br.com.example;
2 |
3 | import com.amazonaws.services.sqs.AmazonSQSAsync;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.beans.factory.annotation.Value;
6 | import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;
7 | import org.springframework.cloud.aws.messaging.core.SqsMessageHeaders;
8 | import org.springframework.stereotype.Component;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 | import java.util.UUID;
13 |
14 | @Component
15 | public class ProducerMessage {
16 |
17 | @Value("${cloud.aws.sqs.queue-name}")
18 | private String queueName;
19 |
20 | private QueueMessagingTemplate queueMessagingTemplate;
21 |
22 | @Autowired
23 | public ProducerMessage(AmazonSQSAsync amazonSqs) {
24 | this.queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs);
25 | }
26 |
27 | public void sendMessage() {
28 | this.queueMessagingTemplate.convertAndSend(queueName, "YOUR_MESSAGE_OBJECT", getHeader());
29 | }
30 |
31 | private Map getHeader() {
32 | Map headers = new HashMap<>();
33 | headers.put(SqsMessageHeaders.SQS_GROUP_ID_HEADER, UUID.randomUUID().toString());
34 | headers.put(SqsMessageHeaders.SQS_DEDUPLICATION_ID_HEADER, UUID.randomUUID().toString());
35 | headers.put(SqsMessageHeaders.CONTENT_TYPE, "application/json");
36 | return headers;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------