Skip to content

Commit

Permalink
Fix app publish event sent at wrong times
Browse files Browse the repository at this point in the history
  • Loading branch information
sharat87 committed Jun 17, 2021
1 parent 1134265 commit 11218c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ public Mono<ResponseDTO<Application>> create(@Valid @RequestBody Application res
@PostMapping("/publish/{applicationId}")
public Mono<ResponseDTO<Boolean>> publish(@PathVariable String applicationId) {
return applicationPageService.publish(applicationId)
.map(published -> new ResponseDTO<>(HttpStatus.OK.value(), published, null));
.map(application -> {
// This even should parallel a similar even sent from the client, so we want it to be sent by the
// controller and not the service method.
applicationPageService.sendApplicationPublishedEvent(application);
// This will only be called when the publishing was successful, so we can always return `true` here.
return new ResponseDTO<>(HttpStatus.OK.value(), true, null);
});
}

@PutMapping("/{applicationId}/page/{pageId}/makeDefault")
Expand Down Expand Up @@ -132,7 +138,7 @@ public Mono<ResponseDTO<Application>> forkApplication(
@GetMapping("/export/{id}")
public Mono<ResponseEntity<ApplicationJson>> getApplicationFile(@PathVariable String id) {
log.debug("Going to export application with id: {}", id);

return importExportApplicationService.exportApplicationById(id)
.map(fetchedResource -> {
String applicationName = fetchedResource.getExportedApplication().getName();
Expand All @@ -143,7 +149,7 @@ public Mono<ResponseEntity<ApplicationJson>> getApplicationFile(@PathVariable St
.build();
responseHeaders.setContentDisposition(contentDisposition);
responseHeaders.setContentType(MediaType.APPLICATION_JSON);

return new ResponseEntity(fetchedResource, responseHeaders, HttpStatus.OK);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public interface ApplicationPageService {

Mono<PageDTO> deleteUnpublishedPage(String id);

Mono<Boolean> publish(String applicationId);
Mono<Application> publish(String applicationId);

void generateAndSetPagePolicies(Application application, PageDTO page);

Mono<Void> sendApplicationPublishedEvent(Application application);
}
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public Mono<PageDTO> deleteUnpublishedPage(String id) {
* @return Publishes a Boolean true, when the application has been published.
*/
@Override
public Mono<Boolean> publish(String applicationId) {
public Mono<Application> publish(String applicationId) {
Mono<Application> applicationMono = applicationService.findById(applicationId, MANAGE_APPLICATIONS)
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.APPLICATION, applicationId)))
.cache();
Expand Down Expand Up @@ -642,13 +642,13 @@ public Mono<Boolean> publish(String applicationId) {

return Mono.when(
publishApplicationAndPages.collectList(),
publishedActionsFlux.collectList(),
applicationMono.flatMap(this::sendApplicationPublishedEvent)
publishedActionsFlux.collectList()
)
.thenReturn(true);
.then(applicationMono);
}

private Mono<Void> sendApplicationPublishedEvent(Application application) {
@Override
public Mono<Void> sendApplicationPublishedEvent(Application application) {
if (!analyticsService.isActive()) {
return Mono.empty();
}
Expand Down

0 comments on commit 11218c2

Please sign in to comment.