Skip to content

Commit

Permalink
Merge pull request #67 from jaxio/revert-66-master
Browse files Browse the repository at this point in the history
Revert "a little change"
  • Loading branch information
nromanetti authored Feb 20, 2018
2 parents d35dfc6 + 4d46587 commit bf47fae
Show file tree
Hide file tree
Showing 36 changed files with 397 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $output.java($Root,"Application")##

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.context.annotation.Bean;
Expand All @@ -28,10 +29,16 @@ public class Application {
SpringApplication.run(Application.class, args);
}

// http://stackoverflow.com/questions/36761019/how-can-i-use-angular2-pathlocationstrategy-in-a-spring-boot-application
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return container -> container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/"));
return new Angular2PathLocationStrategyCustomizer();
}

// http://stackoverflow.com/questions/36761019/how-can-i-use-angular2-pathlocationstrategy-in-a-spring-boot-application
private static class Angular2PathLocationStrategyCustomizer implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
##
$output.java($Audit, "AuditContextHolder")##
$output.requireStatic("org.apache.commons.lang3.StringUtils.trimToNull")##
$output.requireStatic("org.apache.commons.lang.StringUtils.trimToNull")##
$output.require("javax.persistence.PrePersist")##
$output.require("javax.persistence.PreUpdate")##
$output.require($Security, "UserContext")##
Expand All @@ -24,8 +24,8 @@
* Please note that you are in charge of reseting the context properties if you use them directly.
*/
public final class $output.currentClass {
private static final ThreadLocal<Boolean> audit = new ThreadLocal<>();
private static final ThreadLocal<String> username = new ThreadLocal<>();
private static final ThreadLocal<Boolean> audit = new ThreadLocal<Boolean>();
private static final ThreadLocal<String> username = new ThreadLocal<String>();

private ${output.currentClass}(){
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
}

@Override
public void configure(WebSecurity web) {
public void configure(WebSecurity web) throws Exception {
web.ignoring(). //
antMatchers(HttpMethod.OPTIONS, "/**"). //
antMatchers("/"). //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $output.require("springfox.documentation.builders.RequestHandlerSelectors")##
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
private final Logger log = LoggerFactory.getLogger(getClass());
private final Logger log = LoggerFactory.getLogger(SwaggerConfiguration.class);

@Bean
public Docket swaggerSpringfoxDocket() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ $output.require($manyToMany.to)##
@Override
$output.dynamicAnnotation("javax.persistence.Transient")
public boolean ${entity.primaryKey.has}() {
return $entity.primaryKey.var != null && $entity.primaryKey.var.areFieldsSet();
return ${entity.primaryKey.getter}() != null && ${entity.primaryKey.getter}().areFieldsSet();
}
#end
#if ($entity.isAccount())
Expand Down Expand Up @@ -609,7 +609,7 @@ $output.require("$entity.collectionType.implementationFullType")##
*/
@Override
public boolean equals(Object other) {
return ${output.currentRootCast}this == other || other instanceof $output.currentClass && hashCode() == other.hashCode();
return ${output.currentRootCast}this == other || (other instanceof $output.currentClass && hashCode() == other.hashCode());
}

#if($entity.useBusinessKey())
Expand Down Expand Up @@ -667,7 +667,7 @@ $output.require("com.jaxio.jpa.querybyexample.LocaleHolder")##
String language = LocaleHolder.getLocale().getLanguage().toLowerCase();
#foreach($attribute in $bundle.attributes)
if (language.equals("$attribute.columnNameLanguage")) {
return $attribute.var;
return ${attribute.getter}();
}
#end
throw new IllegalStateException("Could not find the proper getter for current locale's language " + language);
Expand All @@ -684,7 +684,7 @@ $output.require("com.jaxio.jpa.querybyexample.LocaleHolder")##
return #if ($entity.hasParent())super.toString() + #{end}MoreObjects.toStringHelper(this) //
#foreach ($attribute in $entity.nonCpkAttributes.list)
#if(!$attribute.isInFk() || $attribute.isSimplePk())
.add("${attribute.var}", #if($attribute.isPassword())"XXXX"#else$attribute.var#end) //
.add("${attribute.var}", #if($attribute.isPassword())"XXXX"#else${attribute.getter}()#end) //
#end
#end
.toString();
Expand All @@ -709,13 +709,13 @@ $output.require("com.jaxio.jpa.querybyexample.LocaleHolder")##
$output.dynamicAnnotation("javax.persistence.Transient")
public void copyTo($entity.model.type $entity.model.var) {
#if ($entity.isRoot() && $entity.primaryKey.isComposite())
if ($entity.primaryKey.var != null) {
${entity.model.var}.${entity.primaryKey.setter}($entity.primaryKey.var.copy());
if (${entity.primaryKey.getter}() != null) {
${entity.model.var}.${entity.primaryKey.setter}(${entity.primaryKey.getter}().copy());
}
#end
#foreach ($attribute in $entity.nonCpkAttributes.list)
#if ($attribute.isSetterAccessibilityPublic())
${entity.model.var}.${attribute.setter}($attribute.var);
${entity.model.var}.${attribute.setter}(${attribute.getter}());
#end
#end
#foreach ($xToOne in $entity.xToOne.list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $output.java($ModelSupport, "IdentifiableHashBuilder")##

$output.require("java.io.Serializable")##
$output.require("java.util.logging.Logger")
$output.require("java.rmi.dgc.VMID")
$output.require("${ModelSupport.packageName}.Identifiable")##

/**
Expand All @@ -35,7 +34,7 @@ public class $output.currentClass implements Serializable {
if (identifiable.${identifiableProperty.iser}()) {
technicalId = identifiable.${identifiableProperty.getter}();
} else {
technicalId = new VMID();
technicalId = new java.rmi.dgc.VMID();
log.warning("DEVELOPER: hashCode is not safe." //
+ "If you encounter this message you should take the time to carefuly " //
+ "review the equals/hashCode methods for: " + identifiable.getClass().getCanonicalName() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ $output.require($relation.toEntity.model) ##
example = Example.of($entity.model.var, matcher);
}

Page<$entity.model.type> page = example != null ?
${entity.repository.var}.findAll(example, req.toPageable()) :
${entity.repository.var}.findAll(req.toPageable());

Page<$entity.model.type> page;
if (example != null){
page = ${entity.repository.var}.findAll(example, req.toPageable());
} else {
page = ${entity.repository.var}.findAll(req.toPageable());
}

List<$entity.dto.type> content = page.getContent().stream().map(this::toDTO).collect(Collectors.toList());
return new PageResponse<>(page.getTotalPages(), page.getTotalElements(), content);
Expand Down Expand Up @@ -136,7 +138,7 @@ $output.require($relation.toEntity.model) ##
${entity.model.var}.${relation.to.setter}(null);
} else {
$relation.to.type $relation.to.var = ${entity.model.var}.${relation.to.getter}();
if ($relation.to.var == null || ${relation.to.var}.getId().compareTo(dto.${relation.to.var}.id) != 0) {
if ($relation.to.var == null || (${relation.to.var}.getId().compareTo(dto.${relation.to.var}.id) != 0)) {
${entity.model.var}.${relation.to.setter}(${relation.toEntity.repository.var}.findOne(dto.${relation.to.var}.id));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
$output.java("${Root.packageName}.dto.support","PageRequestByExample")##

$output.require("org.springframework.data.domain.Example")##
$output.require("org.springframework.data.domain.Pageable")##

public class PageRequestByExample<DTO> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $output.require("java.math.BigInteger")##
$output.require("java.util.Date")##
#end
$output.require($entity.dto)##
$output.require($entity.model)##
$output.require($entity.root.primaryKey)##
#foreach($enumAttribute in $entity.uniqueEnumAttributes.list)
$output.require($enumAttribute)##
Expand All @@ -42,9 +43,14 @@ $output.require("javax.inject.Inject")##
$output.require("org.slf4j.LoggerFactory")##
$output.require("org.slf4j.Logger")##

$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.GET")##
$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.POST")##
$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.PUT")##
$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.DELETE")##
$output.require("org.springframework.web.bind.annotation.*")##

$output.requireStatic("org.springframework.http.MediaType.APPLICATION_JSON_VALUE")##
$output.require("org.springframework.http.ResponseEntity")##
$output.require("org.springframework.web.bind.annotation.RequestBody")##
$output.require("org.springframework.http.HttpHeaders")##
$output.require("org.springframework.http.HttpStatus")##

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

private final Logger log = LoggerFactory.getLogger(getClass());
private final Logger log = LoggerFactory.getLogger(${output.currentClass}.class);

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

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

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

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

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

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

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

/**
* Auto complete support.
*/
@PostMapping("complete")
public ResponseEntity<List<$entity.dto.type>> complete(@RequestBody AutoCompleteQuery acq) {
@RequestMapping(value = "/complete", method = POST, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<List<$entity.dto.type>> complete(@RequestBody AutoCompleteQuery acq) throws URISyntaxException {

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
## limitations under the License.
##
$output.java("${Root.packageName}.rest","SecurityResource")##

$output.requireStatic("org.springframework.web.bind.annotation.RequestMethod.GET")##
$output.require("org.springframework.web.bind.annotation.*")##

$output.requireStatic("org.springframework.http.MediaType.APPLICATION_JSON_VALUE")##
$output.require("javax.servlet.http.HttpServletRequest")##
$output.require($Security, "UserContext")##

@RestController
@RequestMapping("/api")
public class $output.currentClass{

@GetMapping("authenticated")
@RequestMapping(value = "/authenticated", method = GET, produces = APPLICATION_JSON_VALUE)
public boolean isAuthenticated() {
return UserContext.getId() != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.stereotype.Component;

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

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException {
AuthenticationException exception) throws IOException, ServletException {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

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

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) {
Authentication authentication) throws IOException, ServletException {
response.setStatus(HttpServletResponse.SC_OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,30 @@ $output.require($project.accountEntity.repository)##
#else
if ("user".equals(username)) {
String password = "user";
List<String> roles = new ArrayList<>();
boolean enabled = true;
boolean accountNonExpired = true;
boolean credentialsNonExpired = true;
boolean accountNonLocked = true;
List<String> roles = new ArrayList();
roles.add("ROLE_USER");
return new UserWithId(username, password, toGrantedAuthorities(roles), null);
return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
}
if ("admin".equals(username)) {
String password = "admin";
List<String> roles = new ArrayList<>();
boolean enabled = true;
boolean accountNonExpired = true;
boolean credentialsNonExpired = true;
boolean accountNonLocked = true;
List<String> roles = new ArrayList();
roles.add("ROLE_ADMIN");
return new UserWithId(username, password, toGrantedAuthorities(roles), null);
return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
}
return null;
#end
}

private Collection<GrantedAuthority> toGrantedAuthorities(List<String> roles) {
List<GrantedAuthority> result = new ArrayList<>();
List<GrantedAuthority> result = new ArrayList();
for (String role : roles) {
result.add(new SimpleGrantedAuthority(role));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@
*/
public class $output.currentClass extends User {
private static final long serialVersionUID = 1L;
private final $idType id;
private $idType id;

public ${output.currentClass}(String username, String password, boolean enabled, boolean accountNonExpired,
boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities, $idType id) {
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
this.id = id;
}

public UserWithId(String username, String password, Collection<? extends GrantedAuthority> authorities, $idType id) {
super(username, password, authorities);
this.id = id;
}

public $idType getId() {
return id;
Expand Down
Loading

0 comments on commit bf47fae

Please sign in to comment.