Skip to content

Commit

Permalink
Restore ElasticsearchIndexResource
Browse files Browse the repository at this point in the history
  • Loading branch information
mraible committed Apr 4, 2024
1 parent a8a0245 commit 82d0864
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.jhipster.health.web.rest;

import io.micrometer.core.annotation.Timed;
import java.net.URISyntaxException;
import java.util.List;
import org.jhipster.health.security.AuthoritiesConstants;
import org.jhipster.health.security.SecurityUtils;
import org.jhipster.health.service.ElasticsearchIndexService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.jhipster.web.util.HeaderUtil;

/**
* REST controller for managing Elasticsearch index.
*/
@RestController
@RequestMapping("/api")
public class ElasticsearchIndexResource {

private final Logger log = LoggerFactory.getLogger(ElasticsearchIndexResource.class);

private final ElasticsearchIndexService elasticsearchIndexService;

public ElasticsearchIndexResource(ElasticsearchIndexService elasticsearchIndexService) {
this.elasticsearchIndexService = elasticsearchIndexService;
}

@Value("${jhipster.clientApp.name}")
private String applicationName;

/**
* POST /elasticsearch/index -> Reindex all Elasticsearch documents
*/
@PostMapping("/elasticsearch/index")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<Void> reindexAll() throws URISyntaxException {
log.info("REST request to reindex Elasticsearch by user : {}, all entities", SecurityUtils.getCurrentUserLogin());
elasticsearchIndexService.reindexSelected(null, true);
return ResponseEntity.accepted().headers(HeaderUtil.createAlert(applicationName, "elasticsearch.reindex.accepted", "")).build();
}

/**
* POST /elasticsearch/selected -> Reindex selected Elasticsearch documents
*/
@PostMapping("/elasticsearch/selected")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<Void> reindexSelected(@RequestBody List<String> selectedEntities) throws URISyntaxException {
log.info("REST request to reindex Elasticsearch by user : {}, entities: {}", SecurityUtils.getCurrentUserLogin(), selectedEntities);
elasticsearchIndexService.reindexSelected(selectedEntities, false);
return ResponseEntity.accepted()
.headers(HeaderUtil.createAlert(applicationName, "elasticsearch.reindex.acceptedSelected", ""))
.build();
}
}

0 comments on commit 82d0864

Please sign in to comment.