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

Use positive conditional instead of negation in reactive templates #17544

Merged
merged 5 commits into from
Jan 19, 2022
Merged
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 @@ -37,12 +37,7 @@ partialUpdated<%= persistClass %>.set<%= primaryKey.nameCapitalized %>(<%= persi
<%_ } _%>
<%_ } _%>

<%_ if (!reactive) { _%>
rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, partialUpdated<%= asEntity(entityClass) %>.get<%= primaryKey.nameCapitalized %>())<% if (testsNeedCsrf) { %>.with(csrf())<% }%>
.contentType("application/merge-patch+json")
.content(TestUtil.convertObjectToJsonBytes(<%= 'partialUpdated' + persistClass %>)))
.andExpect(status().isOk());
<%_ } else { _%>
<%_ if (reactive) { _%>
webTestClient
.patch()
.uri(ENTITY_API_URL_ID, partialUpdated<%= asEntity(entityClass) %>.get<%= primaryKey.nameCapitalized %>())
Expand All @@ -51,6 +46,11 @@ webTestClient
.exchange()
.expectStatus()
.isOk();
<%_ } else { _%>
rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, partialUpdated<%= asEntity(entityClass) %>.get<%= primaryKey.nameCapitalized %>())<% if (testsNeedCsrf) { %>.with(csrf())<% }%>
.contentType("application/merge-patch+json")
.content(TestUtil.convertObjectToJsonBytes(<%= 'partialUpdated' + persistClass %>)))
.andExpect(status().isOk());
<%_ } _%>

// Validate the <%= entityClass %> in the database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,42 @@ _%>
return <%= entityInstance %>Service.findAll()<% if (reactive) { %>.collectList()<% } %>;
<%_ } else if (dtoMapstruct) { _%>
<%= reactive ? 'Flux' : 'List' %><<%= persistClass %>> <%= entityInstancePlural %> = <%= entityInstance %>Repository.<% if (relationshipsContainEagerLoad) { %>findAllWithEagerRelationships<% } else { %>findAll<% } %>();
<%_ if (!reactive) { _%>
return <%= entityListToDtoListReference %>(<%= entityInstancePlural %>);
<%_ } else { _%>
<%_ if (reactive) { _%>
return <%= entityInstancePlural %>.map(<%= entityToDtoReference %>).collectList();
<%_ } else { _%>
return <%= entityListToDtoListReference %>(<%= entityInstancePlural %>);
<%_ } _%>
<%_ } else { _%>
return <%= entityInstance %>Repository.<% if (relationshipsContainEagerLoad) { %>findAllWithEagerRelationships<% } else { %>findAll<% } %>()<% if (reactive) { %>.collectList()<% } %>;
<%_ } _%>
<%_ } else { _%>
public <% if (reactive) { %>Mono<ResponseEntity<List<<%= instanceType %>>>><% } else { %>ResponseEntity<List<<%= instanceType %>>><% } %> getAll<%= entityClassPlural %>(@org.springdoc.api.annotations.ParameterObject Pageable pageable<% if (reactive) { %>, ServerHttpRequest request<% } %><% if (fieldsContainNoOwnerOneToOne) { %>, @RequestParam(required = false) String filter<% } %><% if (relationshipsContainEagerLoad) { %>, @RequestParam(required = false, defaultValue = "false") boolean eagerload<% } %>) {<%- include('get_all_stream_template', {viaService: viaService}); -%>
log.debug("REST request to get a page of <%= entityClassPlural %>");
<%_ if (!reactive) { _%>
<%_ if (reactive) { _%>
return <%= entityInstance %><%= viaService ? 'Service.countAll' : 'Repository.count' %>().zipWith(<%= entityInstance %><%= viaService ? 'Service.findAll' : 'Repository.findAllBy' %>(pageable)<%= reactiveEntityToDto %>.collectList())
.map(countWithEntities ->
ResponseEntity.ok()
.headers(
PaginationUtil.generatePaginationHttpHeaders(
UriComponentsBuilder.fromHttpRequest(request),
new PageImpl<>(countWithEntities.getT2(), pageable, countWithEntities.getT1())
)
).body(countWithEntities.getT2())
);
<%_ } else { _%>
<%_ if (relationshipsContainEagerLoad) { _%>
Page<<%= instanceType %>> page;
if (eagerload) {
page = <%= entityInstance %><%= viaService ? 'Service' : 'Repository' %>.findAllWithEagerRelationships(pageable)<%= reactiveEntityToDto %>;
} else {
page = <%= entityInstance %><%= viaService ? 'Service' : 'Repository' %>.findAll(pageable)<%= reactiveEntityToDto %>;
}
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (!reactive) { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } else { %>UriComponentsBuilder.fromHttpRequest(request)<% } %>, page);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (reactive) { %>UriComponentsBuilder.fromHttpRequest(request)<% } else { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } %>, page);
<%_ } else { _%>
Page<<%= instanceType %>> page = <%= entityInstance %><%= viaService ? 'Service' : 'Repository' %>.findAll(pageable)<%= reactiveEntityToDto %>;
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (!reactive) { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } else { %>UriComponentsBuilder.fromHttpRequest(request)<% } %>, page);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (reactive) { %>UriComponentsBuilder.fromHttpRequest(request)<% } else { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } %>, page);
<%_ } _%>
return ResponseEntity.ok().headers(headers).body(page.getContent());
<%_ } else { _%>
return <%= entityInstance %><%= viaService ? 'Service.countAll' : 'Repository.count' %>().zipWith(<%= entityInstance %><%= viaService ? 'Service.findAll' : 'Repository.findAllBy' %>(pageable)<%= reactiveEntityToDto %>.collectList())
.map(countWithEntities -> {
return ResponseEntity.ok()
.headers(
PaginationUtil.generatePaginationHttpHeaders(
UriComponentsBuilder.fromHttpRequest(request),
new PageImpl<>(countWithEntities.getT2(), pageable, countWithEntities.getT1())
)
).body(countWithEntities.getT2());
});
<%_ } _%>
<%_ } _%>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const returnPrefix = (isService) ? 'return' : returnType + '<' + instanceType +
const mapper = entityInstance + 'Mapper';
_%>
<%_ if(viaService) { _%>
<%_ if(!reactive) { _%>
Optional<<%= instanceType %>> result = <%= entityInstance %>Service.partialUpdate(<%= instanceName %>);
<%_ } else { _%>
<%_ if(reactive) { _%>
Mono<<%= instanceType %>> result = <%= entityInstance %>Service.partialUpdate(<%= instanceName %>);
<%_ } else { _%>
Optional<<%= instanceType %>> result = <%= entityInstance %>Service.partialUpdate(<%= instanceName %>);
<%_ } _%>
<%_ } else { %>
<%- returnPrefix %> <%= entityInstance %>Repository.findById(<%= instanceName %>.get<%= primaryKey.nameCapitalized %>())
Expand All @@ -53,10 +53,10 @@ _%>
<%_ if (searchEngineElasticsearch) { _%>
.<%= mapOrFlatMap %>(saved<%= entityClass %> -> {
<%= entityInstance %>SearchRepository.save(saved<%= entityClass %>);
<%_ if(!reactive) { %>
return saved<%= entityClass %>;
<%_ } else { %>
<%_ if(reactive) { %>
return Mono.just(saved<%= entityClass %>);
<%_ } else { %>
return saved<%= entityClass %>;
<%_ } %>
})
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
const mapper = entityInstance + 'Mapper';
const entityToDtoReference = mapper + '::' + 'toDto'; %>
<%_ if (!viaService) { _%>
<%_ if (!reactive) { _%>
<%_ if (reactive) { _%>
return <%= entityInstance %><% if (searchEngineElasticsearch) { %>Search<% } %>Repository.search(query)<%_ if (dtoMapstruct) { %>
.map(<%= entityToDtoReference %>)<%_ } %><%_ if (fromResource) { _%>.collectList()<%_ } _%>;
<%_ } else { _%>
<%_ if (searchEngineElasticsearch) { _%>
return StreamSupport
.stream(<%= entityInstance %>SearchRepository.search(query).spliterator(), false)
Expand All @@ -33,10 +36,7 @@ const entityToDtoReference = mapper + '::' + 'toDto'; %>
<%_ if (dtoMapstruct || searchEngineElasticsearch) { _%>
.collect(Collectors.toList());
<%_ } _%>
<%_ } else { _%>
return <%= entityInstance %><% if (searchEngineElasticsearch) { %>Search<% } %>Repository.search(query)<%_ if (dtoMapstruct) { %>
.map(<%= entityToDtoReference %>)<%_ } %><%_ if (fromResource) { _%>.collectList()<%_ } _%>;
<%_ } _%>
<%_ } _%>
<%_ } else { _%>
return <%= entityInstance %>Service.search(query)<% if (reactive && fromResource) { %>.collectList()<% } %>;
<%_ } _%>
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ if (paginationNo) { %>
<% } if (!paginationNo) { %>
public <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= listOrFlux %><<%= instanceType %>>><% if (reactive) { %>><% } %> search<%= entityClassPlural %>(@RequestParam String query, @org.springdoc.api.annotations.ParameterObject Pageable pageable<% if (reactive) { %>, ServerHttpRequest request<% } %>) {
log.debug("REST request to search for a page of <%= entityClassPlural %> for query {}", query);
<%_ if (!reactive) { _%>
<%_ if (viaService) { _%>
Page<<%= instanceType %>> page = <%= entityInstance %>Service.search(query, pageable);
<%_ } else { _%>
Page<<%= persistClass %>> page = <%= entityInstance %><% if (searchEngineElasticsearch) { %>Search<% } %>Repository.search(query, pageable);
<%_ } _%>
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (!reactive) { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } else { %>UriComponentsBuilder.fromHttpRequest(request)<% } %>, page);
return ResponseEntity.ok().headers(headers).body(<% if (!viaService && dtoMapstruct) { %><%= entityListToDtoListReference %>(<% } %>page.getContent()<% if (!viaService && dtoMapstruct) { %>)<% } %>);
<%_ } else { _%>
<%_ if (reactive) { _%>
return <%= entityInstance %><%= viaService ?
'Service.' + (searchEngineElasticsearch ? 'searchCount' : 'countAll') :
(searchEngineElasticsearch ? 'Search' : '') + 'Repository.count' %>()
.map(total -> new PageImpl<>(new ArrayList<>(), pageable, total))
.map(page -> PaginationUtil.generatePaginationHttpHeaders(UriComponentsBuilder.fromHttpRequest(request), page))
.map(headers -> ResponseEntity.ok().headers(headers).body(<%= entityInstance %><%= viaService ? 'Service' : (searchEngineElasticsearch ? 'Search' : '') + 'Repository' %>.search(query, pageable)<% if (!viaService && dtoMapstruct) { %>.map(<%= entityToDtoReference %>)<% } %>));
<%_ } else { _%>
<%_ if (viaService) { _%>
Page<<%= instanceType %>> page = <%= entityInstance %>Service.search(query, pageable);
<%_ } else { _%>
Page<<%= persistClass %>> page = <%= entityInstance %><% if (searchEngineElasticsearch) { %>Search<% } %>Repository.search(query, pageable);
<%_ } _%>
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(<% if (reactive) { %>UriComponentsBuilder.fromHttpRequest(request)<% } else { %>ServletUriComponentsBuilder.fromCurrentRequest()<% } %>, page);
return ResponseEntity.ok().headers(headers).body(<% if (!viaService && dtoMapstruct) { %><%= entityListToDtoListReference %>(<% } %>page.getContent()<% if (!viaService && dtoMapstruct) { %>)<% } %>);
<%_ } _%>
<% } -%>
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public interface <%= entityClass %>Service {
* @param <%= instanceName %> the entity to update partially.
* @return the persisted entity.
*/
<% if (!reactive) { %>Optional<<% } %><% if (reactive) { %>Mono<<% } %><%= instanceType %>> partialUpdate(<%= instanceType %> <%= instanceName %>);
<% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= instanceType %>> partialUpdate(<%= instanceType %> <%= instanceName %>);

/**
* Get all the <%= entityInstancePlural %>.
*<% if (!paginationNo) { %>
* @param pageable the pagination information.<% } %>
* @return the list of entities.
*/
<% if (!paginationNo) { %><%= pageOrFlux %><<%= instanceType %><% } else { %><%= listOrFlux %><<%= instanceType %><% } %>> findAll(<% if (!paginationNo) { %>Pageable pageable<% } %>);
<% if (paginationNo) { %><%= listOrFlux %><% } else { %><%= pageOrFlux %><% } %><<%= instanceType %>> findAll(<% if (!paginationNo) { %>Pageable pageable<% } %>);
<%_ for (const relationship of relationships) { _%>
<%_ if (relationship.relationshipOneToOne && !relationship.ownerSide) { _%>
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public class <%= serviceClassName %><% if (serviceImpl) { %> implements <%= enti
<%_ if (serviceImpl) { _%>
@Override
<%_ } _%>
public <% if (!reactive) { %>Optional<<% } %><% if (reactive) { %>Mono<<% } %><%= instanceType %>> partialUpdate(<%= instanceType %> <%= instanceName %>) {
public <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= instanceType %>> partialUpdate(<%= instanceType %> <%= instanceName %>) {
log.debug("Request to partially update <%= entityClass %> : {}", <%= instanceName %>);
<%- include('../../common/patch_template', {asEntity, asDto, isService: true, viaService: false}); -%>
}
Expand All @@ -147,7 +147,7 @@ public class <%= serviceClassName %><% if (serviceImpl) { %> implements <%= enti
<%_ if (databaseTypeSql) { _%>
@Transactional(readOnly = true)
<%_ } _%>
public <% if (!paginationNo) { %><%= pageOrFlux %><<%= instanceType %><% } else { %><%= listOrFlux %><<%= instanceType %><% } %>> findAll(<% if (!paginationNo) { %>Pageable pageable<% } %>) {
public <% if (paginationNo) { %><%= listOrFlux %><% } else { %><%= pageOrFlux %><% } %><<%= instanceType %>> findAll(<% if (!paginationNo) { %>Pageable pageable<% } %>) {
log.debug("Request to get all <%= entityClassPlural %>");
<%_ if (paginationNo) { _%>
return <%= entityInstance %>Repository.<% if (relationshipsContainEagerLoad) { %>findAllWithEagerRelationships<% } else { %>findAll<% } %>()<% if (dtoMapstruct) { %><% if (!reactive) { %>.stream()<% } %>
Expand Down
Loading