Skip to content

Commit

Permalink
adjusts
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 23, 2024
1 parent 40c0d21 commit db2ad77
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
9 changes: 9 additions & 0 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"liquibaseAddH2Properties": false,
"liquibaseDefaultSchemaName": "",
"listOrFlux": "List",
"listOrFluxClassPath": "java.util.List",
"lowercaseBaseName": "jhipster",
"mainClass": "JhipsterApp",
"mainJavaDir": "src/main/java/",
Expand Down Expand Up @@ -684,6 +685,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"nodePackageManager": "npm",
"nodeVersion": "NODE_VERSION",
"optionalOrMono": "Optional",
"optionalOrMonoClassPath": "java.util.Optional",
"optionalOrMonoOfNullable": "Optional.ofNullable",
"packageFolder": "com/mycompany/myapp/",
"packageInfoJavadocs": [
Expand Down Expand Up @@ -806,6 +808,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"webappLoginRegExp": "^[a-zA-Z0-9!$&*+=?^_\`{|}~.-]+@[a-zA-Z0-9-]+(?:\\\\.[a-zA-Z0-9-]+)*$|^[_.@A-Za-z0-9-]+$",
"websocket": "no",
"withAdminUi": true,
"wrapMono": [Function],
}
`;
Expand Down Expand Up @@ -1201,6 +1204,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"liquibaseAddH2Properties": false,
"liquibaseDefaultSchemaName": "",
"listOrFlux": "Flux",
"listOrFluxClassPath": "reactor.core.publisher.Flux",
"lowercaseBaseName": "jhipster",
"mainClass": "JhipsterApp",
"mainJavaDir": "src/main/java/",
Expand Down Expand Up @@ -1299,6 +1303,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"nodePackageManager": "npm",
"nodeVersion": "NODE_VERSION",
"optionalOrMono": "Mono",
"optionalOrMonoClassPath": "reactor.core.publisher.Mono",
"optionalOrMonoOfNullable": "Mono.justOrEmpty",
"packageFolder": "com/mycompany/myapp/",
"packageInfoJavadocs": [
Expand Down Expand Up @@ -1423,6 +1428,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"webappLoginRegExp": "^[a-zA-Z0-9!$&*+=?^_\`{|}~.-]+@[a-zA-Z0-9-]+(?:\\\\.[a-zA-Z0-9-]+)*$|^[_.@A-Za-z0-9-]+$",
"websocket": "no",
"withAdminUi": true,
"wrapMono": [Function],
}
`;
Expand Down Expand Up @@ -1822,6 +1828,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"liquibaseAddH2Properties": false,
"liquibaseDefaultSchemaName": "",
"listOrFlux": "List",
"listOrFluxClassPath": "java.util.List",
"lowercaseBaseName": "jhipster",
"mainClass": "JhipsterApp",
"mainJavaDir": "src/main/java/",
Expand Down Expand Up @@ -1861,6 +1868,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"nodePackageManager": "npm",
"nodeVersion": "NODE_VERSION",
"optionalOrMono": "Optional",
"optionalOrMonoClassPath": "java.util.Optional",
"optionalOrMonoOfNullable": "Optional.ofNullable",
"packageFolder": "com/mycompany/myapp/",
"packageInfoJavadocs": [
Expand Down Expand Up @@ -1978,5 +1986,6 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"useNpmWrapper": false,
"websocket": "no",
"withAdminUi": false,
"wrapMono": [Function],
}
`;
3 changes: 3 additions & 0 deletions generators/java/generators/bootstrap/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export default class BootstrapGenerator extends BaseApplicationGenerator {
applicationDefaults({
optionalOrMono: ({ reactive }) => (reactive ? 'Mono' : 'Optional'),
optionalOrMonoOfNullable: ({ reactive }) => (reactive ? 'Mono.justOrEmpty' : 'Optional.ofNullable'),
optionalOrMonoClassPath: ({ reactive }) => (reactive ? 'reactor.core.publisher.Mono' : 'java.util.Optional'),
wrapMono: ({ reactive }) => className => (reactive ? `Mono<${className}>` : className),
listOrFlux: ({ reactive }) => (reactive ? 'Flux' : 'List'),
listOrFluxClassPath: ({ reactive }) => (reactive ? 'reactor.core.publisher.Flux' : 'java.util.List'),
});
},
});
Expand Down
4 changes: 4 additions & 0 deletions generators/server/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ export type SpringBootApplication = JavaApplication &
optionalOrMono: string;
optionalOrMonoOfNullable: string;
listOrFlux: string;
optionalOrMonoClassPath: string;
wrapMono: (className: string) => string,
listOrFluxClassPath: string;

generateAuthenticationApi?: boolean;
generateInMemoryUserCredentials?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class AccountResource {
* @throws RuntimeException {@code 500 (Internal Server Error)} if the user couldn't be returned.
*/
@GetMapping("/account")
public <% if (reactive) { %>Mono<<%= user.adminUserDto %>><% } else { %><%= user.adminUserDto %><% } %> getAccount() {
public <%- wrapMono(user.adminUserDto) %> getAccount() {
return userService.getUserWithAuthorities()
.map(<%= user.adminUserDto %>::new)
<%_ if (reactive) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
-%>
package <%= packageName %>.web.rest;

<%_ if (reactive) { _%>
import <%= packageName %>.security.SecurityUtils;
<%_ } _%>
import <%= packageName %>.service.UserService;
import <%= packageName %>.service.dto.<%= user.adminUserDto %>;

Expand All @@ -33,8 +30,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
<%_ if (reactive) { _%>
import reactor.core.publisher.Mono;
<%_ } else { _%>
import java.util.Optional;
<%_ } _%>

/**
Expand Down Expand Up @@ -69,7 +64,7 @@ public class AccountResource {
* @throws AccountResourceException {@code 500 (Internal Server Error)} if the user couldn't be returned.
*/
@GetMapping("/account")
public <% if (reactive) { %>Mono<<%= user.adminUserDto %>><% } else { %><%= user.adminUserDto %><% } %> getAccount(Principal principal) {
public <%- wrapMono(user.adminUserDto) %> getAccount(Principal principal) {
if (principal instanceof AbstractAuthenticationToken) {
return userService.getUserFromAuthentication((AbstractAuthenticationToken) principal);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import <%= packageName %>.domain.Authority;
import java.security.Principal;
<%_ if (reactive) { _%>
import reactor.core.publisher.Mono;
<%_ } else { _%>
import java.util.Optional;
<%_ } _%>
<%_ if (authenticationTypeOauth2) { _%>
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import java.security.Principal;
import reactor.core.publisher.Mono;
import org.springframework.security.authentication.ReactiveAuthenticationManager;
<%_ } else { _%>
import java.util.Optional;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.context.SecurityContextHolder;
<%_ } _%>
Expand Down

0 comments on commit db2ad77

Please sign in to comment.