Skip to content
Snippets Groups Projects
Commit 786d1cd6 authored by Smitha Manjunath's avatar Smitha Manjunath
Browse files

add delete api

parent 97ba9d60
No related branches found
No related tags found
2 merge requests!346Merge branch 'aws-integration' into 'master',!273Delete api
......@@ -48,6 +48,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;
import springfox.documentation.annotations.ApiIgnore;
import static java.util.Collections.singletonList;
@Log
@RestController
......@@ -106,19 +107,21 @@ public class CleanupIndiciesApi {
}
}
@DeleteMapping(value = "/delete-index-for-kind", produces = MediaType.APPLICATION_JSON_VALUE)
@DeleteMapping(value = "/index", produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("@authorizationFilter.hasPermission('" + SearchServiceRole.ADMIN + "')")
public ResponseEntity deleteIndex(@RequestParam("kind") @NotBlank @ValidKind String kind) {
String index = elasticIndexNameResolver.getIndexNameFromKind(kind);
try {
String index = elasticIndexNameResolver.getIndexNameFromKind(kind);
boolean responseStatus = indicesService.deleteIndex(index);
if (responseStatus) {
return new ResponseEntity(HttpStatus.OK);
this.auditLogger.indexDeleteSuccess(singletonList(index));
}
return new ResponseEntity(HttpStatus.OK);
} catch (AppException e) {
throw e;
} catch (Exception e) {
throw new AppException(HttpStatus.BAD_REQUEST.value(), "Unknown error", "An unknown error has occurred.", e);
this.auditLogger.indexDeleteFail(singletonList(index));
throw new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unknown error", "An unknown error has occurred.", e);
}
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
}
......@@ -60,6 +60,10 @@ public class AuditEvents {
private static final String CONFIGURE_PARTITION_ACTION_ID = "IN0012";
private static final String CONFIGURE_PARTITION_OPERATION = "Data partition cluster configuration update";
private static final String INDEX_DELETE_ACTION_ID = "IN0012";
private static final String INDEX_DELETE_SUCCESS = "Successfully deleted index";
private static final String INDEX_DELETE_FAILURE = "Failed deleting index";
private final String user;
public AuditEvents(String user) {
......@@ -135,6 +139,28 @@ public class AuditEvents {
.build();
}
public AuditPayload getIndexDeleteFailEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.DELETE)
.status(AuditStatus.FAILURE)
.actionId(INDEX_DELETE_ACTION_ID)
.message(INDEX_DELETE_FAILURE)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexDeleteSuccessEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.DELETE)
.status(AuditStatus.SUCCESS)
.actionId(INDEX_DELETE_ACTION_ID)
.message(INDEX_DELETE_SUCCESS)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getIndexPurgeRecordSuccessEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.DELETE)
......
......@@ -65,6 +65,14 @@ public class AuditLogger {
this.writeLog(this.getAuditEvents().getIndexDeleteRecordFailEvent(resources));
}
public void indexDeleteSuccess(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexDeleteSuccessEvent(resources));
}
public void indexDeleteFail(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexDeleteFailEvent(resources));
}
public void indexPurgeRecordSuccess(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexPurgeRecordSuccessEvent(resources));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment