spring-gen 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE.txt +674 -0
  7. data/README.md +133 -0
  8. data/Rakefile +1 -0
  9. data/bin/setup +7 -0
  10. data/bin/spring-gen +8 -0
  11. data/lib/command_router.rb +15 -0
  12. data/lib/commands/resource.rb +129 -0
  13. data/lib/commands/service.rb +53 -0
  14. data/lib/spring-gen/version.rb +3 -0
  15. data/lib/spring-gen.rb +5 -0
  16. data/lib/templates/layout/.gitignore +36 -0
  17. data/lib/templates/layout/build.gradle.erb +105 -0
  18. data/lib/templates/layout/intellij/config/checkstyle/checkstyle.xml +199 -0
  19. data/lib/templates/layout/intellij/config/codestyle/Codestyle.xml +34 -0
  20. data/lib/templates/layout/intellij/config/copyright/gnu.xml +6 -0
  21. data/lib/templates/layout/intellij/config/copyright/profiles_settings.xml +10 -0
  22. data/lib/templates/layout/src/java/config/AppConfig.java.erb +54 -0
  23. data/lib/templates/layout/src/java/main/App.java.erb +41 -0
  24. data/lib/templates/layout/src/resources/application.yml.erb +108 -0
  25. data/lib/templates/layout/src/resources/bootstrap.yml.erb +3 -0
  26. data/lib/templates/resource/assembler/Assembler.java.erb +57 -0
  27. data/lib/templates/resource/assembler/BaseAssembler.java.erb +95 -0
  28. data/lib/templates/resource/controller/BaseController.java.erb +66 -0
  29. data/lib/templates/resource/controller/Controller.java.erb +106 -0
  30. data/lib/templates/resource/exception/NotCreatedException.java.erb +34 -0
  31. data/lib/templates/resource/model/JpaBaseEntity.java.erb +43 -0
  32. data/lib/templates/resource/model/Model.java.erb +51 -0
  33. data/lib/templates/resource/model/MongodbBaseEntity.java.erb +33 -0
  34. data/lib/templates/resource/model/Neo4jBaseEntity.java.erb +81 -0
  35. data/lib/templates/resource/repository/Repository.java.erb +30 -0
  36. data/lib/templates/resource/resource/Resource.java.erb +48 -0
  37. data/lib/templates/resource/test/TestUtil.java.erb +85 -0
  38. data/lib/templates/resource/test/integration/jpa/IntegrationTest.java.erb +123 -0
  39. data/lib/templates/resource/test/integration/jpa/IntegrationTestConfig.java.erb +47 -0
  40. data/lib/templates/resource/test/integration/jpa/sampleData.xml.erb +20 -0
  41. data/lib/templates/resource/test/integration/mongodb/IntegrationTest.java.erb +114 -0
  42. data/lib/templates/resource/test/integration/mongodb/IntegrationTestConfig.java.erb +60 -0
  43. data/lib/templates/resource/test/integration/mongodb/SampleData.java.erb +43 -0
  44. data/lib/templates/resource/test/integration/neo4j/IntegrationTest.java.erb +123 -0
  45. data/lib/templates/resource/test/integration/neo4j/IntegrationTestConfig.java.erb +47 -0
  46. data/lib/templates/resource/test/integration/neo4j/SampleData.java.erb +23 -0
  47. data/lib/templates/resource/test/unit/assembler/AssemblerUnitTest.java.erb +52 -0
  48. data/lib/templates/resource/test/unit/assembler/AssemblerUnitTestConfig.java.erb +43 -0
  49. data/lib/templates/resource/test/unit/controller/ControllerUnitTest.java.erb +115 -0
  50. data/lib/templates/resource/test/unit/controller/ControllerUnitTestConfig.java.erb +64 -0
  51. data/lib/templates/service.yml.erb +4 -0
  52. data/lib/util.rb +39 -0
  53. data/spring-gen.gemspec +25 -0
  54. metadata +153 -0
@@ -0,0 +1,199 @@
1
+ <?xml version="1.0"?>
2
+ <!DOCTYPE module PUBLIC
3
+ "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4
+ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5
+
6
+ <!--
7
+ Checkstyle configuration that checks the Google coding conventions from:
8
+
9
+ - Google Java Style
10
+ https://google-styleguide.googlecode.com/svn-history/r130/trunk/javaguide.html
11
+
12
+ Checkstyle is very configurable. Be sure to read the documentation at
13
+ http://checkstyle.sf.net (or in your downloaded distribution).
14
+ Most Checks are configurable, be sure to consult the documentation.
15
+ To completely disable a check, just comment it out or delete it from the file.
16
+ Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
17
+
18
+ -->
19
+
20
+ <module name = "Checker">
21
+ <property name="charset" value="UTF-8"/>
22
+
23
+ <property name="severity" value="warning"/>
24
+
25
+ <property name="fileExtensions" value="java, properties, xml"/>
26
+ <!-- Checks for whitespace -->
27
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
28
+ <module name="FileTabCharacter">
29
+ <property name="eachLine" value="true"/>
30
+ </module>
31
+
32
+ <module name="TreeWalker">
33
+ <module name="OuterTypeFilename"/>
34
+ <module name="IllegalTokenText">
35
+ <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
36
+ <property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
37
+ <property name="message" value="Avoid using corresponding octal or Unicode escape."/>
38
+ </module>
39
+ <module name="AvoidEscapedUnicodeCharacters">
40
+ <property name="allowEscapesForControlCharacters" value="true"/>
41
+ <property name="allowByTailComment" value="true"/>
42
+ <property name="allowNonPrintableEscapes" value="true"/>
43
+ </module>
44
+ <module name="LineLength">
45
+ <property name="max" value="100"/>
46
+ <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
47
+ </module>
48
+ <module name="AvoidStarImport"/>
49
+ <module name="OneTopLevelClass"/>
50
+ <module name="NoLineWrap"/>
51
+ <module name="EmptyBlock">
52
+ <property name="option" value="TEXT"/>
53
+ <property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
54
+ </module>
55
+ <module name="NeedBraces"/>
56
+ <module name="LeftCurly">
57
+ <property name="maxLineLength" value="100"/>
58
+ </module>
59
+ <module name="RightCurly"/>
60
+ <module name="RightCurly">
61
+ <property name="option" value="alone"/>
62
+ <property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
63
+ </module>
64
+ <module name="WhitespaceAround">
65
+ <property name="allowEmptyConstructors" value="true"/>
66
+ <property name="allowEmptyMethods" value="true"/>
67
+ <property name="allowEmptyTypes" value="true"/>
68
+ <property name="allowEmptyLoops" value="true"/>
69
+ <message key="ws.notFollowed"
70
+ value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
71
+ <message key="ws.notPreceded"
72
+ value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
73
+ </module>
74
+ <module name="OneStatementPerLine"/>
75
+ <module name="MultipleVariableDeclarations"/>
76
+ <module name="ArrayTypeStyle"/>
77
+ <module name="MissingSwitchDefault"/>
78
+ <module name="FallThrough"/>
79
+ <module name="UpperEll"/>
80
+ <module name="ModifierOrder"/>
81
+ <module name="EmptyLineSeparator">
82
+ <property name="allowNoEmptyLineBetweenFields" value="true"/>
83
+ </module>
84
+ <module name="SeparatorWrap">
85
+ <property name="tokens" value="DOT"/>
86
+ <property name="option" value="nl"/>
87
+ </module>
88
+ <module name="SeparatorWrap">
89
+ <property name="tokens" value="COMMA"/>
90
+ <property name="option" value="EOL"/>
91
+ </module>
92
+ <module name="PackageName">
93
+ <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
94
+ <message key="name.invalidPattern"
95
+ value="Package name ''{0}'' must match pattern ''{1}''."/>
96
+ </module>
97
+ <module name="TypeName">
98
+ <message key="name.invalidPattern"
99
+ value="Type name ''{0}'' must match pattern ''{1}''."/>
100
+ </module>
101
+ <module name="MemberName">
102
+ <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
103
+ <message key="name.invalidPattern"
104
+ value="Member name ''{0}'' must match pattern ''{1}''."/>
105
+ </module>
106
+ <module name="ParameterName">
107
+ <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
108
+ <message key="name.invalidPattern"
109
+ value="Parameter name ''{0}'' must match pattern ''{1}''."/>
110
+ </module>
111
+ <module name="LocalVariableName">
112
+ <property name="tokens" value="VARIABLE_DEF"/>
113
+ <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
114
+ <property name="allowOneCharVarInForLoop" value="true"/>
115
+ <message key="name.invalidPattern"
116
+ value="Local variable name ''{0}'' must match pattern ''{1}''."/>
117
+ </module>
118
+ <module name="ClassTypeParameterName">
119
+ <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
120
+ <message key="name.invalidPattern"
121
+ value="Class type name ''{0}'' must match pattern ''{1}''."/>
122
+ </module>
123
+ <module name="MethodTypeParameterName">
124
+ <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
125
+ <message key="name.invalidPattern"
126
+ value="Method type name ''{0}'' must match pattern ''{1}''."/>
127
+ </module>
128
+ <module name="NoFinalizer"/>
129
+ <module name="GenericWhitespace">
130
+ <message key="ws.followed"
131
+ value="GenericWhitespace ''{0}'' is followed by whitespace."/>
132
+ <message key="ws.preceded"
133
+ value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
134
+ <message key="ws.illegalFollow"
135
+ value="GenericWhitespace ''{0}'' should followed by whitespace."/>
136
+ <message key="ws.notPreceded"
137
+ value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
138
+ </module>
139
+ <module name="Indentation">
140
+ <property name="basicOffset" value="2"/>
141
+ <property name="braceAdjustment" value="0"/>
142
+ <property name="caseIndent" value="2"/>
143
+ <property name="throwsIndent" value="4"/>
144
+ <property name="lineWrappingIndentation" value="4"/>
145
+ <property name="arrayInitIndent" value="2"/>
146
+ </module>
147
+ <module name="AbbreviationAsWordInName">
148
+ <property name="ignoreFinal" value="false"/>
149
+ <property name="allowedAbbreviationLength" value="1"/>
150
+ </module>
151
+ <module name="OverloadMethodsDeclarationOrder"/>
152
+ <module name="VariableDeclarationUsageDistance"/>
153
+ <module name="CustomImportOrder">
154
+ <property name="specialImportsRegExp" value="com.google"/>
155
+ <property name="sortImportsInGroupAlphabetically" value="true"/>
156
+ <property name="customImportOrderRules" value="STATIC###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
157
+ </module>
158
+ <module name="MethodParamPad"/>
159
+ <module name="OperatorWrap">
160
+ <property name="option" value="NL"/>
161
+ <property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
162
+ </module>
163
+ <module name="AnnotationLocation">
164
+ <property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
165
+ </module>
166
+ <module name="AnnotationLocation">
167
+ <property name="tokens" value="VARIABLE_DEF"/>
168
+ <property name="allowSamelineMultipleAnnotations" value="true"/>
169
+ </module>
170
+ <module name="NonEmptyAtclauseDescription"/>
171
+ <module name="JavadocTagContinuationIndentation"/>
172
+ <module name="SummaryJavadocCheck">
173
+ <property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
174
+ </module>
175
+ <module name="JavadocParagraph"/>
176
+ <module name="AtclauseOrder">
177
+ <property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
178
+ <property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
179
+ </module>
180
+ <module name="JavadocMethod">
181
+ <property name="scope" value="public"/>
182
+ <property name="allowMissingParamTags" value="true"/>
183
+ <property name="allowMissingThrowsTags" value="true"/>
184
+ <property name="allowMissingReturnTag" value="true"/>
185
+ <property name="minLineCount" value="2"/>
186
+ <property name="allowedAnnotations" value="Override, Test"/>
187
+ <property name="allowThrowsTagsForSubclasses" value="true"/>
188
+ </module>
189
+ <module name="MethodName">
190
+ <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
191
+ <message key="name.invalidPattern"
192
+ value="Method name ''{0}'' must match pattern ''{1}''."/>
193
+ </module>
194
+ <module name="SingleLineJavadoc"/>
195
+ <module name="EmptyCatchBlock">
196
+ <property name="exceptionVariableName" value="expected"/>
197
+ </module>
198
+ </module>
199
+ </module>
@@ -0,0 +1,34 @@
1
+ <code_scheme name="Codestyle">
2
+ <option name="OTHER_INDENT_OPTIONS">
3
+ <value>
4
+ <option name="INDENT_SIZE" value="2" />
5
+ <option name="CONTINUATION_INDENT_SIZE" value="4" />
6
+ <option name="TAB_SIZE" value="2" />
7
+ <option name="USE_TAB_CHARACTER" value="false" />
8
+ <option name="SMART_TABS" value="false" />
9
+ <option name="LABEL_INDENT_SIZE" value="0" />
10
+ <option name="LABEL_INDENT_ABSOLUTE" value="false" />
11
+ <option name="USE_RELATIVE_INDENTS" value="false" />
12
+ </value>
13
+ </option>
14
+ <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1000" />
15
+ <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="1000" />
16
+ <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
17
+ <value />
18
+ </option>
19
+ <option name="IMPORT_LAYOUT_TABLE">
20
+ <value>
21
+ <package name="" withSubpackages="true" static="true" />
22
+ <emptyLine />
23
+ <package name="" withSubpackages="true" static="false" />
24
+ <emptyLine />
25
+ <package name="java" withSubpackages="true" static="false" />
26
+ <package name="javax" withSubpackages="true" static="false" />
27
+ <emptyLine />
28
+ </value>
29
+ </option>
30
+ <option name="RIGHT_MARGIN" value="80" />
31
+ <XML>
32
+ <option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
33
+ </XML>
34
+ </code_scheme>
@@ -0,0 +1,6 @@
1
+ <component name="CopyrightManager">
2
+ <copyright>
3
+ <option name="myName" value="gnu" />
4
+ <option name="notice" value="Copyright (c) &amp;#36;today.year Rene Richter. &#10;This program is free software; you can redistribute it and/or modify&#10;it under the terms of the GNU General Public License as published by&#10;the Free Software Foundation; either version 3 of the License, or&#10;(at your option) any later version.&#10;This program is distributed in the hope that it will be useful,&#10;but WITHOUT ANY WARRANTY; without even the implied warranty of&#10;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the&#10;GNU General Public License for more details.&#10;You should have received a copy of the GNU General Public License&#10;along with this program; if not, write to the Free Software Foundation,&#10;Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA" />
5
+ </copyright>
6
+ </component>
@@ -0,0 +1,10 @@
1
+ <component name="CopyrightManager">
2
+ <settings default="gnu">
3
+ <module2copyright>
4
+ <element module="All" copyright="gnu" />
5
+ </module2copyright>
6
+ <LanguageOptions name="JAVA">
7
+ <option name="fileLocation" value="2" />
8
+ </LanguageOptions>
9
+ </settings>
10
+ </component>
@@ -0,0 +1,54 @@
1
+ package <%=@group_id%>.config;
2
+
3
+
4
+ /*
5
+ * Copyright (c) 2015 <%=@user_name%>.
6
+ * This program is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software Foundation,
16
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+ <%if @repository_technique == "jpa"-%>
20
+ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
21
+ <%elsif @repository_technique == "mongodb"-%>
22
+ import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
23
+ <%elsif @repository_technique == "neo4j"-%>
24
+ <%end-%>
25
+ import org.springframework.boot.orm.jpa.EntityScan;
26
+ import org.springframework.context.annotation.Bean;
27
+ import org.springframework.context.annotation.ComponentScan;
28
+ import org.springframework.context.annotation.Configuration;
29
+ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
30
+ import org.springframework.data.web.config.EnableSpringDataWebSupport;
31
+ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
32
+ /**
33
+ * Application config-class.
34
+ *
35
+ * @author <%=@user_name%>
36
+ */
37
+
38
+ @Configuration
39
+ @EnableWebMvc
40
+ @ComponentScan(basePackages = {"<%=@group_id%>"})
41
+ <%if @repository_technique == "jpa"-%>
42
+ @EnableJpaRepositories(basePackages = "<%=@group_id%>.repository")
43
+ <%elsif @repository_technique == "mongodb"-%>
44
+ @EnableMongoRepositories(basePackages = "<%=@group_id%>.repository")
45
+ <%elsif @repository_technique == "neo4j"-%>
46
+ <%end-%>
47
+ @EntityScan(basePackages = "<%=@group_id%>.repository")
48
+ @EnableSpringDataWebSupport
49
+ public class AppConfig {
50
+ @Bean
51
+ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
52
+ return new PropertySourcesPlaceholderConfigurer();
53
+ }
54
+ }
@@ -0,0 +1,41 @@
1
+ package <%=@group_id%>.main;
2
+
3
+
4
+ /*
5
+ * Copyright (c) 2015 <%=@user_name%>.
6
+ * This program is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software Foundation,
16
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+ */
18
+
19
+ import org.springframework.boot.CommandLineRunner;
20
+ import org.springframework.boot.SpringApplication;
21
+ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
22
+ import org.springframework.boot.autoconfigure.SpringBootApplication;
23
+ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
24
+
25
+
26
+
27
+ @EnableAutoConfiguration
28
+ @EnableDiscoveryClient
29
+ @SpringBootApplication
30
+ public class App implements CommandLineRunner {
31
+
32
+ public static void main(String[] args) {
33
+ SpringApplication.run(App.class, args);
34
+
35
+ }
36
+
37
+ @Override
38
+ public void run(String... args) throws Exception {
39
+
40
+ }
41
+ }
@@ -0,0 +1,108 @@
1
+ spring:
2
+ profiles:
3
+ active: development
4
+
5
+ ---
6
+
7
+ spring:
8
+ profiles: development
9
+ data:
10
+ rest:
11
+ basePath: / #root URI for Spring Data REST
12
+ defaultPageSize: 20 #change default number of items served in a single page
13
+ maxPageSize: 100 #change maximum number of items in a single page
14
+ #pageParamName: #change name of the query parameter for selecting pages
15
+ #limitParamName: #change name of the query parameter for number of items to show in a page
16
+ #sortParamName: #change name of the query parameter for sorting
17
+ #defaultMediaType: #change default media type to use when none is specified
18
+ returnBodyOnCreate: false #change if a body should be returned on creating a new entity
19
+ returnBodyOnupdate: false #change if a body should be returned on updating an entity
20
+ <%if @repository_technique == "jpa"%>
21
+ jpa:
22
+ open-in-view: true
23
+ show-sql: true
24
+ repositories.enabled: true # if spring data repository support is enabled
25
+
26
+ <%elsif @repository_technique == "mongodb"%>
27
+
28
+ mongodb
29
+ host: localhost # the db host
30
+ port: 27017 # the connection port (defaults to 27107)
31
+ uri: mongodb://localhost/test # connection URL
32
+ database: test
33
+ #authentication-database:
34
+ #grid-fs-database:
35
+ username: test
36
+ password: test
37
+ repositories.enabled: true # if spring data repository support is enabled
38
+
39
+
40
+ <%elsif @repository_technique == "neo4j"%>
41
+
42
+
43
+
44
+
45
+ <%end%>
46
+
47
+
48
+ ---
49
+
50
+ spring:
51
+ profiles: production
52
+ data:
53
+ rest:
54
+ basePath: / #root URI for Spring Data REST
55
+ defaultPageSize: 20 #change default number of items served in a single page
56
+ maxPageSize: 100 #change maximum number of items in a single page
57
+ #pageParamName: #change name of the query parameter for selecting pages
58
+ #limitParamName: #change name of the query parameter for number of items to show in a page
59
+ #sortParamName: #change name of the query parameter for sorting
60
+ #defaultMediaType: #change default media type to use when none is specified
61
+ returnBodyOnCreate: false #change if a body should be returned on creating a new entity
62
+ returnBodyOnupdate: false #change if a body should be returned on updating an entity
63
+ <%if @repository_technique == "jpa"%>
64
+ jpa:
65
+ open-in-view: true
66
+ show-sql: true
67
+ repositories.enabled: true # if spring data repository support is enabled
68
+
69
+ datasource:
70
+ initialize: true # populate using data.sql
71
+ sql-script-encoding: UTF-8 # a charset for reading SQL scripts
72
+ separator: ; # statement separator in SQL initialization scripts
73
+ #driver-class-name: # JDBC Settings...
74
+ #url:
75
+ #username:
76
+ #password:
77
+ #jndi-name: # For JNDI lookup (class, url, username & password are ignored when set)
78
+ #max-active:100 # Advanced configuration...
79
+ #max-idle:8
80
+ #min-idle:8
81
+ #initial-size:10
82
+ #validation-query:
83
+
84
+ <%elsif @repository_technique == "mongodb"%>
85
+
86
+ mongodb
87
+ host: localhost # the db host
88
+ port: 27017 # the connection port (defaults to 27107)
89
+ uri: mongodb://localhost/production # connection URL
90
+ database: production
91
+ #authentication-database:
92
+ #grid-fs-database:
93
+ username: production
94
+ password: production
95
+ repositories.enabled: true # if spring data repository support is enabled
96
+
97
+
98
+ <%elsif @repository_technique == "neo4j"%>
99
+
100
+
101
+
102
+
103
+ <%end%>
104
+
105
+ eureka:
106
+ client:
107
+ serviceUrl:
108
+ defaultZone: http://localhost:8761/eureka/
@@ -0,0 +1,3 @@
1
+ spring:
2
+ application:
3
+ name: <%=@name%>
@@ -0,0 +1,57 @@
1
+ package <%=@group_id%>.assembler;
2
+
3
+ /*
4
+ * Copyright (c) 2015 <%=@user_name%>
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program; if not, write to the Free Software Foundation,
15
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
19
+ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
20
+
21
+ import <%=@group_id%>.model.<%=@model_name%>;
22
+ import <%=@group_id%>.controller.<%=@model_name%>Controller;
23
+ import <%=@group_id%>.resource.<%=@model_name%>Resource;
24
+ import org.springframework.beans.factory.annotation.Autowired;
25
+ import org.springframework.hateoas.EntityLinks;
26
+ import org.springframework.hateoas.mvc.ResourceAssemblerSupport;
27
+ import org.springframework.stereotype.Component;
28
+
29
+ /**
30
+ * Assembler to create <%=@model_name%> resources.
31
+ * @author <%=@user_name%>
32
+ */
33
+ @Component
34
+ public class <%=@model_name%>Assembler extends BaseAssembler<<%=@model_name%>, <%=@model_name%>Resource> {
35
+
36
+ /**
37
+ * Creates a new {@link ResourceAssemblerSupport}
38
+ * using the given controller class and resource type.
39
+ */
40
+ public <%=@model_name%>Assembler() {
41
+ super(<%=@model_name%>Controller.class, <%=@model_name%>Resource.class);
42
+ }
43
+
44
+
45
+ @Autowired
46
+ EntityLinks entityLinks;
47
+
48
+
49
+ @Override
50
+ public <%=@model_name%>Resource toResource(<%=@model_name%> entity) {
51
+ <%=@model_name%>Resource resource = createResource(entity);
52
+
53
+ //TODO add links
54
+
55
+ return resource;
56
+ }
57
+ }
@@ -0,0 +1,95 @@
1
+ package <%=@group_id%>.assembler;
2
+
3
+ /*
4
+ * Copyright (c) 2015 <%=@user_name%>
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program; if not, write to the Free Software Foundation,
15
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+ */
17
+
18
+ import <%=@group_id%>.model.BaseEntity;
19
+ import org.springframework.beans.factory.annotation.Autowired;
20
+ import org.springframework.cloud.client.ServiceInstance;
21
+ import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
22
+ import org.springframework.hateoas.Link;
23
+ import org.springframework.hateoas.ResourceSupport;
24
+ import org.springframework.hateoas.mvc.IdentifiableResourceAssemblerSupport;
25
+ import org.springframework.stereotype.Component;
26
+
27
+ import java.lang.reflect.InvocationTargetException;
28
+
29
+ /**
30
+ * A common base class for assembler.
31
+ * @author <%=@user_name%>
32
+ */
33
+ @Component
34
+ public abstract class BaseAssembler<T extends BaseEntity, D extends ResourceSupport>
35
+ extends IdentifiableResourceAssemblerSupport<T, D> {
36
+
37
+ protected Class<D> resourceTypeClass;
38
+
39
+ public BaseAssembler(Class<?> controllerClass, Class<D> resourceType) {
40
+ super(controllerClass, resourceType);
41
+ this.resourceTypeClass = resourceType;
42
+ }
43
+
44
+
45
+ @Autowired
46
+ LoadBalancerClient loadBalancerClient;
47
+
48
+ /**
49
+ * Adds a link for the given service to the given resource.
50
+ * @param resource the resource you want to add the link to.
51
+ * @param serviceName the name of the service.
52
+ * @param subUri the path the resource is located.
53
+ * @param ref the ref of the link.
54
+ */
55
+ public void linkToService(ResourceSupport resource,
56
+ String serviceName,
57
+ String subUri,
58
+ String ref) {
59
+ ServiceInstance instance = loadBalancerClient.choose(serviceName);
60
+ if (instance != null) {
61
+ resource.add(new Link(instance.getUri().toString() + "/" + subUri,ref));
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Adds a link for the given service to the given resource.
67
+ * @param resource the resource you want to add the link to.
68
+ * @param serviceName the name of the service.
69
+ * @param ref the ref of the link.
70
+ */
71
+ public void linkToService(ResourceSupport resource,
72
+ String serviceName,
73
+ String ref) {
74
+ ServiceInstance instance = loadBalancerClient.choose(serviceName);
75
+ if (instance != null) {
76
+ resource.add(new Link(instance.getUri().toString(),ref));
77
+ }
78
+ }
79
+
80
+
81
+ @Override
82
+ protected D instantiateResource(T entity) {
83
+ try {
84
+ return resourceTypeClass
85
+ .getConstructor(entity.getClass())
86
+ .newInstance(entity);
87
+ } catch (InvocationTargetException
88
+ | NoSuchMethodException
89
+ | InstantiationException
90
+ | IllegalAccessException e) {
91
+ throw new RuntimeException(
92
+ "Resource does not have an appropriate constructor!", e);
93
+ }
94
+ }
95
+ }