Skip to content

Commit bf47fae

Browse files
authored
Merge pull request #67 from jaxio/revert-66-master
Revert "a little change"
2 parents d35dfc6 + 4d46587 commit bf47fae

36 files changed

+397
-341
lines changed

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ $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;
1920
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
2021
import org.springframework.boot.web.servlet.ErrorPage;
2122
import org.springframework.context.annotation.Bean;
@@ -28,10 +29,16 @@ public class Application {
2829
SpringApplication.run(Application.class, args);
2930
}
3031

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 container -> container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/"));
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+
}
3543
}
36-
3744
}

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

+3-3
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.lang3.StringUtils.trimToNull")##
17+
$output.requireStatic("org.apache.commons.lang.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<>();
28-
private static final ThreadLocal<String> username = new ThreadLocal<>();
27+
private static final ThreadLocal<Boolean> audit = new ThreadLocal<Boolean>();
28+
private static final ThreadLocal<String> username = new ThreadLocal<String>();
2929

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

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

+1-1
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) {
42+
public void configure(WebSecurity web) throws Exception {
4343
web.ignoring(). //
4444
antMatchers(HttpMethod.OPTIONS, "/**"). //
4545
antMatchers("/"). //

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

+1-1
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(getClass());
33+
private final Logger log = LoggerFactory.getLogger(SwaggerConfiguration.class);
3434

3535
@Bean
3636
public Docket swaggerSpringfoxDocket() {

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

+7-7
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.var != null && $entity.primaryKey.var.areFieldsSet();
168+
return ${entity.primaryKey.getter}() != null && ${entity.primaryKey.getter}().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.var;
670+
return ${attribute.getter}();
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.var#end) //
687+
.add("${attribute.var}", #if($attribute.isPassword())"XXXX"#else${attribute.getter}()#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.var != null) {
713-
${entity.model.var}.${entity.primaryKey.setter}($entity.primaryKey.var.copy());
712+
if (${entity.primaryKey.getter}() != null) {
713+
${entity.model.var}.${entity.primaryKey.setter}(${entity.primaryKey.getter}().copy());
714714
}
715715
#end
716716
#foreach ($attribute in $entity.nonCpkAttributes.list)
717717
#if ($attribute.isSetterAccessibilityPublic())
718-
${entity.model.var}.${attribute.setter}($attribute.var);
718+
${entity.model.var}.${attribute.setter}(${attribute.getter}());
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ $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")
2019
$output.require("${ModelSupport.packageName}.Identifiable")##
2120

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

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

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

96-
Page<$entity.model.type> page = example != null ?
97-
${entity.repository.var}.findAll(example, req.toPageable()) :
98-
${entity.repository.var}.findAll(req.toPageable());
99-
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+
}
100102

101103
List<$entity.dto.type> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
102104
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
@@ -136,7 +138,7 @@ $output.require($relation.toEntity.model) ##
136138
${entity.model.var}.${relation.to.setter}(null);
137139
} else {
138140
$relation.to.type $relation.to.var = ${entity.model.var}.${relation.to.getter}();
139-
if ($relation.to.var == null || ${relation.to.var}.getId().compareTo(dto.${relation.to.var}.id) != 0) {
141+
if ($relation.to.var == null || (${relation.to.var}.getId().compareTo(dto.${relation.to.var}.id) != 0)) {
140142
${entity.model.var}.${relation.to.setter}(${relation.toEntity.repository.var}.findOne(dto.${relation.to.var}.id));
141143
}
142144
}

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

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

3+
$output.require("org.springframework.data.domain.Example")##
34
$output.require("org.springframework.data.domain.Pageable")##
45

56
public class PageRequestByExample<DTO> {

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

+21-14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $output.require("java.math.BigInteger")##
2121
$output.require("java.util.Date")##
2222
#end
2323
$output.require($entity.dto)##
24+
$output.require($entity.model)##
2425
$output.require($entity.root.primaryKey)##
2526
#foreach($enumAttribute in $entity.uniqueEnumAttributes.list)
2627
$output.require($enumAttribute)##
@@ -42,9 +43,14 @@ $output.require("javax.inject.Inject")##
4243
$output.require("org.slf4j.LoggerFactory")##
4344
$output.require("org.slf4j.Logger")##
4445

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")##
4550
$output.require("org.springframework.web.bind.annotation.*")##
46-
51+
$output.requireStatic("org.springframework.http.MediaType.APPLICATION_JSON_VALUE")##
4752
$output.require("org.springframework.http.ResponseEntity")##
53+
$output.require("org.springframework.web.bind.annotation.RequestBody")##
4854
$output.require("org.springframework.http.HttpHeaders")##
4955
$output.require("org.springframework.http.HttpStatus")##
5056

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

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

5864
@Inject
5965
private $entity.repository.type $entity.repository.var;
@@ -83,7 +89,7 @@ $output.require("java.beans.PropertyEditorSupport")##
8389
/**
8490
* Create a new ${entity.model.type}.
8591
*/
86-
@PostMapping
92+
@RequestMapping(value = "/", method = POST, produces = APPLICATION_JSON_VALUE)
8793
public ResponseEntity<$entity.dto.type> create(@RequestBody $entity.dto.type $entity.dto.var) throws URISyntaxException {
8894

8995
log.debug("Create $entity.dto.type : {}", $entity.dto.var);
@@ -102,8 +108,8 @@ $output.require("java.beans.PropertyEditorSupport")##
102108
/**
103109
* Find by id ${entity.model.type}.
104110
*/
105-
@GetMapping("{id}")
106-
public ResponseEntity<$entity.dto.type> findById(@PathVariable $entity.root.primaryKey.type $entity.root.primaryKey.var) {
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 {
107113

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

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

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

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

175182
$entity.model.type $entity.model.var = ${entity.repository.var}.findOne($entity.root.primaryKey.var);
@@ -196,17 +203,17 @@ $output.require("org.springframework.web.bind.annotation.RequestParam")##
196203
/**
197204
* Find a Page of $entity.model.type using query by example.
198205
*/
199-
@PostMapping("page")
200-
public ResponseEntity<PageResponse<$entity.dto.type>> findAll(@RequestBody PageRequestByExample<$entity.dto.type> prbe) {
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 {
201208
PageResponse<$entity.dto.type> pageResponse = ${entity.dtoservice.var}.findAll(prbe);
202209
return new ResponseEntity<>(pageResponse, new HttpHeaders(), HttpStatus.OK);
203210
}
204211

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

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

@@ -216,8 +223,8 @@ $output.require("org.springframework.web.bind.annotation.RequestParam")##
216223
/**
217224
* Delete by id ${entity.model.type}.
218225
*/
219-
@DeleteMapping("{id}")
220-
public ResponseEntity<Void> delete(@PathVariable $entity.root.primaryKey.type $entity.root.primaryKey.var) {
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 {
221228

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

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

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

2122
@RestController
2223
@RequestMapping("/api")
2324
public class $output.currentClass{
2425

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

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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;
78
import javax.servlet.http.HttpServletRequest;
89
import javax.servlet.http.HttpServletResponse;
910
import java.io.IOException;
@@ -16,7 +17,7 @@ public class $output.currentClass extends SimpleUrlAuthenticationFailureHandler
1617

1718
@Override
1819
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
19-
AuthenticationException exception) throws IOException {
20+
AuthenticationException exception) throws IOException, ServletException {
2021
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed");
2122
}
2223
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ 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;
78
import javax.servlet.http.HttpServletRequest;
89
import javax.servlet.http.HttpServletResponse;
10+
import java.io.IOException;
911

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

1618
@Override
1719
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
18-
Authentication authentication) {
20+
Authentication authentication) throws IOException, ServletException {
1921
response.setStatus(HttpServletResponse.SC_OK);
2022
}
2123
}

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

+13-5
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,30 @@ $output.require($project.accountEntity.repository)##
8181
#else
8282
if ("user".equals(username)) {
8383
String password = "user";
84-
List<String> roles = new ArrayList<>();
84+
boolean enabled = true;
85+
boolean accountNonExpired = true;
86+
boolean credentialsNonExpired = true;
87+
boolean accountNonLocked = true;
88+
List<String> roles = new ArrayList();
8589
roles.add("ROLE_USER");
86-
return new UserWithId(username, password, toGrantedAuthorities(roles), null);
90+
return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
8791
}
8892
if ("admin".equals(username)) {
8993
String password = "admin";
90-
List<String> roles = new ArrayList<>();
94+
boolean enabled = true;
95+
boolean accountNonExpired = true;
96+
boolean credentialsNonExpired = true;
97+
boolean accountNonLocked = true;
98+
List<String> roles = new ArrayList();
9199
roles.add("ROLE_ADMIN");
92-
return new UserWithId(username, password, toGrantedAuthorities(roles), null);
100+
return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
93101
}
94102
return null;
95103
#end
96104
}
97105

98106
private Collection<GrantedAuthority> toGrantedAuthorities(List<String> roles) {
99-
List<GrantedAuthority> result = new ArrayList<>();
107+
List<GrantedAuthority> result = new ArrayList();
100108
for (String role : roles) {
101109
result.add(new SimpleGrantedAuthority(role));
102110
}

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,13 @@
3131
*/
3232
public class $output.currentClass extends User {
3333
private static final long serialVersionUID = 1L;
34-
private final $idType id;
34+
private $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-
}
4641

4742
public $idType getId() {
4843
return id;

0 commit comments

Comments
 (0)