Skip to content

Commit

Permalink
Fixes #312 - Add ability to delete a log using REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem committed Jul 21, 2024
1 parent 4a7e03a commit a6f42ea
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions rest/src/main/java/com/manorrock/sphynx/rest/LogResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import jakarta.ws.rs.Path;
import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
Expand Down Expand Up @@ -64,6 +65,39 @@ public class LogResource {
*/
protected File baseDirectory = new File(System.getProperty("user.home") + "/.manorrock/sphynx");

/**
* Delete the specific log.
*
* @param jobName the job name.
* @param logName the log name.
*/
@DELETE
@Path("{logName}")
public void delete(
@PathParam("jobName") String jobName,
@PathParam("logName") String logName) {

File logFile = new File(baseDirectory,
"jobs"
+ File.separator
+ jobName
+ File.separator
+ "logs"
+ File.separator
+ logName
+ ".log");

if (!logFile.exists()) {
LOGGER.log(ERROR, "Log file does not exist");
throw new WebApplicationException(NOT_FOUND);
}

if (!logFile.delete()) {
LOGGER.log(ERROR, "Log file cannot be deleted");
throw new WebApplicationException(INTERNAL_SERVER_ERROR);
}
}

/**
* Get the specific log.
*
Expand Down

0 comments on commit a6f42ea

Please sign in to comment.