Skip to content

Commit d35dfc6

Browse files
authored
Merge pull request #66 from lishifeng0/master
a little change
2 parents 4ae202a + 87babd6 commit d35dfc6

36 files changed

+341
-397
lines changed

pack-angular/celerio/pack-angular/src/main/java/Application.java.p.vm

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ $output.java($Root,"Application")##
1616

1717
import org.springframework.boot.SpringApplication;
1818
import org.springframework.boot.autoconfigure.SpringBootApplication;
19-
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
2019
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
2120
import org.springframework.boot.web.servlet.ErrorPage;
2221
import org.springframework.context.annotation.Bean;
@@ -29,16 +28,10 @@ public class Application {
2928
SpringApplication.run(Application.class, args);
3029
}
3130

31+
// http://stackoverflow.com/questions/36761019/how-can-i-use-angular2-pathlocationstrategy-in-a-spring-boot-application
3232
@Bean
3333
public EmbeddedServletContainerCustomizer containerCustomizer() {
34-
return new Angular2PathLocationStrategyCustomizer();
35-
}
36-
37-
// http://stackoverflow.com/questions/36761019/how-can-i-use-angular2-pathlocationstrategy-in-a-spring-boot-application
38-
private static class Angular2PathLocationStrategyCustomizer implements EmbeddedServletContainerCustomizer {
39-
@Override
40-
public void customize(ConfigurableEmbeddedServletContainer container) {
41-
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/"));
42-
}
34+
return container -> container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/"));
4335
}
36+
4437
}

pack-angular/celerio/pack-angular/src/main/java/audit/AuditContextHolder.p.vm.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
##
1515
$output.java($Audit, "AuditContextHolder")##
1616
17-
$output.requireStatic("org.apache.commons.lang.StringUtils.trimToNull")##
17+
$output.requireStatic("org.apache.commons.lang3.StringUtils.trimToNull")##
1818
$output.require("javax.persistence.PrePersist")##
1919
$output.require("javax.persistence.PreUpdate")##
2020
$output.require($Security, "UserContext")##
@@ -24,8 +24,8 @@
2424
* Please note that you are in charge of reseting the context properties if you use them directly.
2525
*/
2626
public final class $output.currentClass {
27-
private static final ThreadLocal<Boolean> audit = new ThreadLocal<Boolean>();
28-
private static final ThreadLocal<String> username = new ThreadLocal<String>();
27+
private static final ThreadLocal<Boolean> audit = new ThreadLocal<>();
28+
private static final ThreadLocal<String> username = new ThreadLocal<>();
2929

3030
private ${output.currentClass}(){
3131
}

pack-angular/celerio/pack-angular/src/main/java/config/SecurityConfiguration.java.p.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
3939
}
4040

4141
@Override
42-
public void configure(WebSecurity web) throws Exception {
42+
public void configure(WebSecurity web) {
4343
web.ignoring(). //
4444
antMatchers(HttpMethod.OPTIONS, "/**"). //
4545
antMatchers("/"). //

pack-angular/celerio/pack-angular/src/main/java/config/SwaggerConfiguration.java.p.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $output.require("springfox.documentation.builders.RequestHandlerSelectors")##
3030
@Configuration
3131
@EnableSwagger2
3232
public class SwaggerConfiguration {
33-
private final Logger log = LoggerFactory.getLogger(SwaggerConfiguration.class);
33+
private final Logger log = LoggerFactory.getLogger(getClass());
3434

3535
@Bean
3636
public Docket swaggerSpringfoxDocket() {

pack-angular/celerio/pack-angular/src/main/java/domain/Entity.java.e.vm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ $output.require($manyToMany.to)##
165165
@Override
166166
$output.dynamicAnnotation("javax.persistence.Transient")
167167
public boolean ${entity.primaryKey.has}() {
168-
return ${entity.primaryKey.getter}() != null && ${entity.primaryKey.getter}().areFieldsSet();
168+
return $entity.primaryKey.var != null && $entity.primaryKey.var.areFieldsSet();
169169
}
170170
#end
171171
#if ($entity.isAccount())
@@ -609,7 +609,7 @@ $output.require("$entity.collectionType.implementationFullType")##
609609
*/
610610
@Override
611611
public boolean equals(Object other) {
612-
return ${output.currentRootCast}this == other || (other instanceof $output.currentClass && hashCode() == other.hashCode());
612+
return ${output.currentRootCast}this == other || other instanceof $output.currentClass && hashCode() == other.hashCode();
613613
}
614614

615615
#if($entity.useBusinessKey())
@@ -667,7 +667,7 @@ $output.require("com.jaxio.jpa.querybyexample.LocaleHolder")##
667667
String language = LocaleHolder.getLocale().getLanguage().toLowerCase();
668668
#foreach($attribute in $bundle.attributes)
669669
if (language.equals("$attribute.columnNameLanguage")) {
670-
return ${attribute.getter}();
670+
return $attribute.var;
671671
}
672672
#end
673673
throw new IllegalStateException("Could not find the proper getter for current locale's language " + language);
@@ -684,7 +684,7 @@ $output.require("com.jaxio.jpa.querybyexample.LocaleHolder")##
684684
return #if ($entity.hasParent())super.toString() + #{end}MoreObjects.toStringHelper(this) //
685685
#foreach ($attribute in $entity.nonCpkAttributes.list)
686686
#if(!$attribute.isInFk() || $attribute.isSimplePk())
687-
.add("${attribute.var}", #if($attribute.isPassword())"XXXX"#else${attribute.getter}()#end) //
687+
.add("${attribute.var}", #if($attribute.isPassword())"XXXX"#else$attribute.var#end) //
688688
#end
689689
#end
690690
.toString();
@@ -709,13 +709,13 @@ $output.require("com.jaxio.jpa.querybyexample.LocaleHolder")##
709709
$output.dynamicAnnotation("javax.persistence.Transient")
710710
public void copyTo($entity.model.type $entity.model.var) {
711711
#if ($entity.isRoot() && $entity.primaryKey.isComposite())
712-
if (${entity.primaryKey.getter}() != null) {
713-
${entity.model.var}.${entity.primaryKey.setter}(${entity.primaryKey.getter}().copy());
712+
if ($entity.primaryKey.var != null) {
713+
${entity.model.var}.${entity.primaryKey.setter}($entity.primaryKey.var.copy());
714714
}
715715
#end
716716
#foreach ($attribute in $entity.nonCpkAttributes.list)
717717
#if ($attribute.isSetterAccessibilityPublic())
718-
${entity.model.var}.${attribute.setter}(${attribute.getter}());
718+
${entity.model.var}.${attribute.setter}($attribute.var);
719719
#end
720720
#end
721721
#foreach ($xToOne in $entity.xToOne.list)

pack-angular/celerio/pack-angular/src/main/java/domain/support/IdentifiableHashBuilder.java.p.vm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ $output.java($ModelSupport, "IdentifiableHashBuilder")##
1616

1717
$output.require("java.io.Serializable")##
1818
$output.require("java.util.logging.Logger")
19+
$output.require("java.rmi.dgc.VMID")
1920
$output.require("${ModelSupport.packageName}.Identifiable")##
2021

2122
/**
@@ -34,7 +35,7 @@ public class $output.currentClass implements Serializable {
3435
if (identifiable.${identifiableProperty.iser}()) {
3536
technicalId = identifiable.${identifiableProperty.getter}();
3637
} else {
37-
technicalId = new java.rmi.dgc.VMID();
38+
technicalId = new VMID();
3839
log.warning("DEVELOPER: hashCode is not safe." //
3940
+ "If you encounter this message you should take the time to carefuly " //
4041
+ "review the equals/hashCode methods for: " + identifiable.getClass().getCanonicalName() //

pack-angular/celerio/pack-angular/src/main/java/dto/EntityDTOService.java.e.vm

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ $output.require($relation.toEntity.model) ##
9393
example = Example.of($entity.model.var, matcher);
9494
}
9595

96-
Page<$entity.model.type> page;
97-
if (example != null){
98-
page = ${entity.repository.var}.findAll(example, req.toPageable());
99-
} else {
100-
page = ${entity.repository.var}.findAll(req.toPageable());
101-
}
96+
Page<$entity.model.type> page = example != null ?
97+
${entity.repository.var}.findAll(example, req.toPageable()) :
98+
${entity.repository.var}.findAll(req.toPageable());
99+
102100

103101
List<$entity.dto.type> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
104102
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
@@ -138,7 +136,7 @@ $output.require($relation.toEntity.model) ##
138136
${entity.model.var}.${relation.to.setter}(null);
139137
} else {
140138
$relation.to.type $relation.to.var = ${entity.model.var}.${relation.to.getter}();
141-
if ($relation.to.var == null || (${relation.to.var}.getId().compareTo(dto.${relation.to.var}.id) != 0)) {
139+
if ($relation.to.var == null || ${relation.to.var}.getId().compareTo(dto.${relation.to.var}.id) != 0) {
142140
${entity.model.var}.${relation.to.setter}(${relation.toEntity.repository.var}.findOne(dto.${relation.to.var}.id));
143141
}
144142
}

pack-angular/celerio/pack-angular/src/main/java/dto/support/PageRequestByExample.java.p.vm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
$output.java("${Root.packageName}.dto.support","PageRequestByExample")##
22

3-
$output.require("org.springframework.data.domain.Example")##
43
$output.require("org.springframework.data.domain.Pageable")##
54

65
public class PageRequestByExample<DTO> {

pack-angular/celerio/pack-angular/src/main/java/rest/EntityResource.java.e.vm

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ $output.require("java.math.BigInteger")##
2121
$output.require("java.util.Date")##
2222
#end
2323
$output.require($entity.dto)##
24-
$output.require($entity.model)##
2524
$output.require($entity.root.primaryKey)##
2625
#foreach($enumAttribute in $entity.uniqueEnumAttributes.list)
2726
$output.require($enumAttribute)##
@@ -43,14 +42,9 @@ $output.require("javax.inject.Inject")##
4342
$output.require("org.slf4j.LoggerFactory")##
4443
$output.require("org.slf4j.Logger")##
4544

46-
$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.GET")##
47-
$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.POST")##
48-
$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.PUT")##
49-
$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.DELETE")##
5045
$output.require("org.springframework.web.bind.annotation.*")##
51-
$output.requireStatic("org.springframework.http.MediaType.APPLICATION_JSON_VALUE")##
46+
5247
$output.require("org.springframework.http.ResponseEntity")##
53-
$output.require("org.springframework.web.bind.annotation.RequestBody")##
5448
$output.require("org.springframework.http.HttpHeaders")##
5549
$output.require("org.springframework.http.HttpStatus")##
5650

@@ -59,7 +53,7 @@ $output.require("org.springframework.http.HttpStatus")##
5953
@RequestMapping("/api/${entity.model.vars}")
6054
public class $output.currentClass{
6155

62-
private final Logger log = LoggerFactory.getLogger(${output.currentClass}.class);
56+
private final Logger log = LoggerFactory.getLogger(getClass());
6357

6458
@Inject
6559
private $entity.repository.type $entity.repository.var;
@@ -89,7 +83,7 @@ $output.require("java.beans.PropertyEditorSupport")##
8983
/**
9084
* Create a new ${entity.model.type}.
9185
*/
92-
@RequestMapping(value = "/", method = POST, produces = APPLICATION_JSON_VALUE)
86+
@PostMapping
9387
public ResponseEntity<$entity.dto.type> create(@RequestBody $entity.dto.type $entity.dto.var) throws URISyntaxException {
9488

9589
log.debug("Create $entity.dto.type : {}", $entity.dto.var);
@@ -108,8 +102,8 @@ $output.require("java.beans.PropertyEditorSupport")##
108102
/**
109103
* Find by id ${entity.model.type}.
110104
*/
111-
@RequestMapping(value = "/{id}", method = GET, produces = APPLICATION_JSON_VALUE)
112-
public ResponseEntity<$entity.dto.type> findById(@PathVariable $entity.root.primaryKey.type $entity.root.primaryKey.var) throws URISyntaxException {
105+
@GetMapping("{id}")
106+
public ResponseEntity<$entity.dto.type> findById(@PathVariable $entity.root.primaryKey.type $entity.root.primaryKey.var) {
113107

114108
log.debug("Find by id $entity.model.type : {}", $entity.root.primaryKey.var);
115109

@@ -121,7 +115,7 @@ $output.require("java.beans.PropertyEditorSupport")##
121115
/**
122116
* Update ${entity.model.type}.
123117
*/
124-
@RequestMapping(value = "/", method = PUT, produces = APPLICATION_JSON_VALUE)
118+
@PutMapping
125119
public ResponseEntity<$entity.dto.type> update(@RequestBody $entity.dto.type $entity.dto.var) throws URISyntaxException {
126120

127121
log.debug("Update $entity.dto.type : {}", $entity.dto.var);
@@ -142,7 +136,7 @@ $output.require("org.springframework.web.bind.annotation.RequestParam")##
142136
/**
143137
* Target url for ${attribute.var} file upload.
144138
*/
145-
@RequestMapping(value = "/{id}/upload/${attribute.var}", method = POST, produces = APPLICATION_JSON_VALUE)
139+
@PostMapping("/{id}/upload/${attribute.var}")
146140
public ResponseEntity<Void> ${attribute.var}FileUpload(@PathVariable $entity.root.primaryKey.type $entity.root.primaryKey.var, @RequestParam("$attribute.var") MultipartFile multipartFile) {
147141

148142
log.debug("File Upload: {}", multipartFile.getName());
@@ -175,8 +169,7 @@ $output.require("org.springframework.web.bind.annotation.RequestParam")##
175169
/**
176170
* File download facility for ${attribute.var}.
177171
*/
178-
@RequestMapping(value = "/{id}/download/${attribute.var}", method = GET)
179-
@ResponseBody
172+
@GetMapping("/{id}/download/${attribute.var}")
180173
public ResponseEntity<byte[]> ${attribute.var}FileDownload(@PathVariable $entity.root.primaryKey.type $entity.root.primaryKey.var) {
181174

182175
$entity.model.type $entity.model.var = ${entity.repository.var}.findOne($entity.root.primaryKey.var);
@@ -203,17 +196,17 @@ $output.require("org.springframework.web.bind.annotation.RequestParam")##
203196
/**
204197
* Find a Page of $entity.model.type using query by example.
205198
*/
206-
@RequestMapping(value = "/page", method = POST, produces = APPLICATION_JSON_VALUE)
207-
public ResponseEntity<PageResponse<$entity.dto.type>> findAll(@RequestBody PageRequestByExample<$entity.dto.type> prbe) throws URISyntaxException {
199+
@PostMapping("page")
200+
public ResponseEntity<PageResponse<$entity.dto.type>> findAll(@RequestBody PageRequestByExample<$entity.dto.type> prbe) {
208201
PageResponse<$entity.dto.type> pageResponse = ${entity.dtoservice.var}.findAll(prbe);
209202
return new ResponseEntity<>(pageResponse, new HttpHeaders(), HttpStatus.OK);
210203
}
211204

212205
/**
213206
* Auto complete support.
214207
*/
215-
@RequestMapping(value = "/complete", method = POST, produces = APPLICATION_JSON_VALUE)
216-
public ResponseEntity<List<$entity.dto.type>> complete(@RequestBody AutoCompleteQuery acq) throws URISyntaxException {
208+
@PostMapping("complete")
209+
public ResponseEntity<List<$entity.dto.type>> complete(@RequestBody AutoCompleteQuery acq) {
217210

218211
List<$entity.dto.type> results = ${entity.dtoservice.var}.complete(acq.query, acq.maxResults);
219212

@@ -223,8 +216,8 @@ $output.require("org.springframework.web.bind.annotation.RequestParam")##
223216
/**
224217
* Delete by id ${entity.model.type}.
225218
*/
226-
@RequestMapping(value = "/{id}", method = DELETE, produces = APPLICATION_JSON_VALUE)
227-
public ResponseEntity<Void> delete(@PathVariable $entity.root.primaryKey.type $entity.root.primaryKey.var) throws URISyntaxException {
219+
@DeleteMapping("{id}")
220+
public ResponseEntity<Void> delete(@PathVariable $entity.root.primaryKey.type $entity.root.primaryKey.var) {
228221

229222
log.debug("Delete by id $entity.model.type : {}", $entity.root.primaryKey.var);
230223

pack-angular/celerio/pack-angular/src/main/java/rest/SecurityResource.java.p.vm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
## limitations under the License.
1414
##
1515
$output.java("${Root.packageName}.rest","SecurityResource")##
16-
$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.GET")##
16+
1717
$output.require("org.springframework.web.bind.annotation.*")##
18-
$output.requireStatic("org.springframework.http.MediaType.APPLICATION_JSON_VALUE")##
19-
$output.require("javax.servlet.http.HttpServletRequest")##
18+
2019
$output.require($Security, "UserContext")##
2120

2221
@RestController
2322
@RequestMapping("/api")
2423
public class $output.currentClass{
2524

26-
@RequestMapping(value = "/authenticated", method = GET, produces = APPLICATION_JSON_VALUE)
25+
@GetMapping("authenticated")
2726
public boolean isAuthenticated() {
2827
return UserContext.getId() != null;
2928
}

pack-angular/celerio/pack-angular/src/main/java/security/AjaxAuthenticationFailureHandler.java.p.vm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.springframework.security.core.AuthenticationException;
44
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
55
import org.springframework.stereotype.Component;
66

7-
import javax.servlet.ServletException;
87
import javax.servlet.http.HttpServletRequest;
98
import javax.servlet.http.HttpServletResponse;
109
import java.io.IOException;
@@ -17,7 +16,7 @@ public class $output.currentClass extends SimpleUrlAuthenticationFailureHandler
1716

1817
@Override
1918
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
20-
AuthenticationException exception) throws IOException, ServletException {
19+
AuthenticationException exception) throws IOException {
2120
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed");
2221
}
2322
}

pack-angular/celerio/pack-angular/src/main/java/security/AjaxAuthenticationSuccessHandler.java.p.vm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import org.springframework.security.core.Authentication;
44
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
55
import org.springframework.stereotype.Component;
66

7-
import javax.servlet.ServletException;
87
import javax.servlet.http.HttpServletRequest;
98
import javax.servlet.http.HttpServletResponse;
10-
import java.io.IOException;
119

1210
/**
1311
* Spring Security success handler, specialized for Ajax requests.
@@ -17,7 +15,7 @@ public class $output.currentClass extends SimpleUrlAuthenticationSuccessHandler
1715

1816
@Override
1917
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
20-
Authentication authentication) throws IOException, ServletException {
18+
Authentication authentication) {
2119
response.setStatus(HttpServletResponse.SC_OK);
2220
}
2321
}

pack-angular/celerio/pack-angular/src/main/java/security/UserDetailsServiceImpl.java.p.vm

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,22 @@ $output.require($project.accountEntity.repository)##
8181
#else
8282
if ("user".equals(username)) {
8383
String password = "user";
84-
boolean enabled = true;
85-
boolean accountNonExpired = true;
86-
boolean credentialsNonExpired = true;
87-
boolean accountNonLocked = true;
88-
List<String> roles = new ArrayList();
84+
List<String> roles = new ArrayList<>();
8985
roles.add("ROLE_USER");
90-
return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
86+
return new UserWithId(username, password, toGrantedAuthorities(roles), null);
9187
}
9288
if ("admin".equals(username)) {
9389
String password = "admin";
94-
boolean enabled = true;
95-
boolean accountNonExpired = true;
96-
boolean credentialsNonExpired = true;
97-
boolean accountNonLocked = true;
98-
List<String> roles = new ArrayList();
90+
List<String> roles = new ArrayList<>();
9991
roles.add("ROLE_ADMIN");
100-
return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
92+
return new UserWithId(username, password, toGrantedAuthorities(roles), null);
10193
}
10294
return null;
10395
#end
10496
}
10597

10698
private Collection<GrantedAuthority> toGrantedAuthorities(List<String> roles) {
107-
List<GrantedAuthority> result = new ArrayList();
99+
List<GrantedAuthority> result = new ArrayList<>();
108100
for (String role : roles) {
109101
result.add(new SimpleGrantedAuthority(role));
110102
}

pack-angular/celerio/pack-angular/src/main/java/security/UserWithId.p.vm.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@
3131
*/
3232
public class $output.currentClass extends User {
3333
private static final long serialVersionUID = 1L;
34-
private $idType id;
34+
private final $idType id;
3535

3636
public ${output.currentClass}(String username, String password, boolean enabled, boolean accountNonExpired,
3737
boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities, $idType id) {
3838
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
3939
this.id = id;
4040
}
41+
42+
public UserWithId(String username, String password, Collection<? extends GrantedAuthority> authorities, $idType id) {
43+
super(username, password, authorities);
44+
this.id = id;
45+
}
4146

4247
public $idType getId() {
4348
return id;

0 commit comments

Comments
 (0)