Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "a little change"" #69

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $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 @@ -29,16 +28,10 @@ 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 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, "/"));
}
return 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.lang.StringUtils.trimToNull")##
$output.requireStatic("org.apache.commons.lang3.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<Boolean>();
private static final ThreadLocal<String> username = new ThreadLocal<String>();
private static final ThreadLocal<Boolean> audit = new ThreadLocal<>();
private static final ThreadLocal<String> username = new ThreadLocal<>();

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) throws Exception {
public void configure(WebSecurity web) {
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(SwaggerConfiguration.class);
private final Logger log = LoggerFactory.getLogger(getClass());

@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.getter}() != null && ${entity.primaryKey.getter}().areFieldsSet();
return $entity.primaryKey.var != null && $entity.primaryKey.var.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.getter}();
return $attribute.var;
}
#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.getter}()#end) //
.add("${attribute.var}", #if($attribute.isPassword())"XXXX"#else$attribute.var#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.getter}() != null) {
${entity.model.var}.${entity.primaryKey.setter}(${entity.primaryKey.getter}().copy());
if ($entity.primaryKey.var != null) {
${entity.model.var}.${entity.primaryKey.setter}($entity.primaryKey.var.copy());
}
#end
#foreach ($attribute in $entity.nonCpkAttributes.list)
#if ($attribute.isSetterAccessibilityPublic())
${entity.model.var}.${attribute.setter}(${attribute.getter}());
${entity.model.var}.${attribute.setter}($attribute.var);
#end
#end
#foreach ($xToOne in $entity.xToOne.list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $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 @@ -34,7 +35,7 @@ public class $output.currentClass implements Serializable {
if (identifiable.${identifiableProperty.iser}()) {
technicalId = identifiable.${identifiableProperty.getter}();
} else {
technicalId = new java.rmi.dgc.VMID();
technicalId = new 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,12 +93,10 @@ $output.require($relation.toEntity.model) ##
example = Example.of($entity.model.var, matcher);
}

Page<$entity.model.type> page;
if (example != null){
page = ${entity.repository.var}.findAll(example, req.toPageable());
} else {
page = ${entity.repository.var}.findAll(req.toPageable());
}
Page<$entity.model.type> page = example != null ?
${entity.repository.var}.findAll(example, req.toPageable()) :
${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 @@ -138,7 +136,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,6 +1,5 @@
$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,7 +21,6 @@ $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 @@ -43,14 +42,9 @@ $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 @@ -59,7 +53,7 @@ $output.require("org.springframework.http.HttpStatus")##
@RequestMapping("/api/${entity.model.vars}")
public class $output.currentClass{

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

@Inject
private $entity.repository.type $entity.repository.var;
Expand Down Expand Up @@ -89,7 +83,7 @@ $output.require("java.beans.PropertyEditorSupport")##
/**
* Create a new ${entity.model.type}.
*/
@RequestMapping(value = "/", method = POST, produces = APPLICATION_JSON_VALUE)
@PostMapping
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 @@ -108,8 +102,8 @@ $output.require("java.beans.PropertyEditorSupport")##
/**
* Find by id ${entity.model.type}.
*/
@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 {
@GetMapping("{id}")
public ResponseEntity<$entity.dto.type> findById(@PathVariable $entity.root.primaryKey.type $entity.root.primaryKey.var) {

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

Expand All @@ -121,7 +115,7 @@ $output.require("java.beans.PropertyEditorSupport")##
/**
* Update ${entity.model.type}.
*/
@RequestMapping(value = "/", method = PUT, produces = APPLICATION_JSON_VALUE)
@PutMapping
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 @@ -142,7 +136,7 @@ $output.require("org.springframework.web.bind.annotation.RequestParam")##
/**
* Target url for ${attribute.var} file upload.
*/
@RequestMapping(value = "/{id}/upload/${attribute.var}", method = POST, produces = APPLICATION_JSON_VALUE)
@PostMapping("/{id}/upload/${attribute.var}")
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 @@ -175,8 +169,7 @@ $output.require("org.springframework.web.bind.annotation.RequestParam")##
/**
* File download facility for ${attribute.var}.
*/
@RequestMapping(value = "/{id}/download/${attribute.var}", method = GET)
@ResponseBody
@GetMapping("/{id}/download/${attribute.var}")
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 @@ -203,17 +196,17 @@ $output.require("org.springframework.web.bind.annotation.RequestParam")##
/**
* Find a Page of $entity.model.type using query by example.
*/
@RequestMapping(value = "/page", method = POST, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<PageResponse<$entity.dto.type>> findAll(@RequestBody PageRequestByExample<$entity.dto.type> prbe) throws URISyntaxException {
@PostMapping("page")
public ResponseEntity<PageResponse<$entity.dto.type>> findAll(@RequestBody PageRequestByExample<$entity.dto.type> prbe) {
PageResponse<$entity.dto.type> pageResponse = ${entity.dtoservice.var}.findAll(prbe);
return new ResponseEntity<>(pageResponse, new HttpHeaders(), HttpStatus.OK);
}

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

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

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

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,17 +13,16 @@
## 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{

@RequestMapping(value = "/authenticated", method = GET, produces = APPLICATION_JSON_VALUE)
@GetMapping("authenticated")
public boolean isAuthenticated() {
return UserContext.getId() != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 @@ -17,7 +16,7 @@ public class $output.currentClass extends SimpleUrlAuthenticationFailureHandler

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {
AuthenticationException exception) throws IOException {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ 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 @@ -17,7 +15,7 @@ public class $output.currentClass extends SimpleUrlAuthenticationSuccessHandler

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
Authentication authentication) {
response.setStatus(HttpServletResponse.SC_OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,22 @@ $output.require($project.accountEntity.repository)##
#else
if ("user".equals(username)) {
String password = "user";
boolean enabled = true;
boolean accountNonExpired = true;
boolean credentialsNonExpired = true;
boolean accountNonLocked = true;
List<String> roles = new ArrayList();
List<String> roles = new ArrayList<>();
roles.add("ROLE_USER");
return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
return new UserWithId(username, password, toGrantedAuthorities(roles), null);
}
if ("admin".equals(username)) {
String password = "admin";
boolean enabled = true;
boolean accountNonExpired = true;
boolean credentialsNonExpired = true;
boolean accountNonLocked = true;
List<String> roles = new ArrayList();
List<String> roles = new ArrayList<>();
roles.add("ROLE_ADMIN");
return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
return new UserWithId(username, password, 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,13 +31,18 @@
*/
public class $output.currentClass extends User {
private static final long serialVersionUID = 1L;
private $idType id;
private final $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