Skip to content

Commit

Permalink
added tests, modified start.sh to give right to created user
Browse files Browse the repository at this point in the history
  • Loading branch information
boringAdam committed Apr 24, 2024
1 parent 400f557 commit fcb137d
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 286 deletions.
30 changes: 15 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM eclipse-temurin:17-jdk-alpine as builder

WORKDIR /workspace/app
COPY . .
RUN chmod +x gradlew
RUN sh ./gradlew clean build

FROM eclipse-temurin:17-jdk-alpine

WORKDIR /app

COPY --from=builder /workspace/app/build/libs/FileTree-0.0.1-SNAPSHOT.jar /app/app.jar
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh

FROM eclipse-temurin:17-jdk-alpine as builder

WORKDIR /workspace/app
COPY . .
RUN chmod +x gradlew
RUN sh ./gradlew clean bootJar

FROM eclipse-temurin:17-jdk-alpine

WORKDIR /app

COPY --from=builder /workspace/app/build/libs/FileTree-0.0.1-SNAPSHOT.jar /app/app.jar
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh

ENTRYPOINT ["sh", "/app/start.sh"]
202 changes: 101 additions & 101 deletions src/main/java/com/filetree/controller/FileTreeController.java
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
package com.filetree.controller;

import com.filetree.dto.LogEntryDTO;
import com.filetree.service.FileService;
import com.filetree.service.LogEntryService;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
* The FileTreeController class handles all the endpoints
*/
@Controller
public class FileTreeController {

private final FileService fileService;
private final LogEntryService logEntryService;

/**
* Constructor to initialize the FileTreeController
* @param logEntryService The LogEntryService the to log the callings of the /getunique endpoint.
*/
@Autowired
public FileTreeController(LogEntryService logEntryService, FileService fileService) {
this.fileService = fileService;
this.logEntryService = logEntryService;
}

/**
* Endpoint to retrieve a set of unique filenames matching the specified extension.
* @param rootFolder The root folder to search.
* @param extension The file extension to match.
* @return Returns with the list of the distinct filenames.
*/
@GetMapping("/getunique")
@ResponseBody
public Set<String> findFiles(@RequestParam String rootFolder, @RequestParam String extension) {

return fileService.findFiles(rootFolder, extension);
}

/**
* Endpoint to get the /getunique endpoint's calling history
* @return Returns with a list of responses
*/
@GetMapping("/history")
@ResponseBody
public List<LogEntryDTO> getHistory() {

return logEntryService.getAllLogEntries();
}

/**
* Endpoint to get the Application Documentation
* @return Redirects to the root folder, where the documentation is
*/
@GetMapping("/doc")
public String getDocumentation(){

return "redirect:/";
}

/**
* Endpoint to generate a random filesystem, to test the /getuniqe endpoint.
* @return Returns with a message if it was successful or not.
*/
@GetMapping("/gen")
@ResponseBody
public String generateFileStructure() {

File rootFolder = new File("generated_root");

if (rootFolder.exists()) {
try {
FileUtils.deleteDirectory(rootFolder);
} catch (IOException e) {
e.printStackTrace();
return "Failed to delete existing folder.";
}
}

rootFolder.mkdirs();

try {
fileService.createFileStructure(rootFolder, 0);
return "File structure generated successfully.";
} catch (IOException e) {
e.printStackTrace();
return "Failed to generate file structure.";
}
}

}
package com.filetree.controller;

import com.filetree.dto.LogEntryDTO;
import com.filetree.service.FileService;
import com.filetree.service.LogEntryService;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
* The FileTreeController class handles all the endpoints
*/
@Controller
public class FileTreeController {

private final FileService fileService;
private final LogEntryService logEntryService;

/**
* Constructor to initialize the FileTreeController
* @param logEntryService The LogEntryService the to log the callings of the /getunique endpoint.
*/
@Autowired
public FileTreeController(LogEntryService logEntryService, FileService fileService) {
this.fileService = fileService;
this.logEntryService = logEntryService;
}

/**
* Endpoint to retrieve a set of unique filenames matching the specified extension.
* @param rootFolder The root folder to search.
* @param extension The file extension to match.
* @return Returns with the list of the distinct filenames.
*/
@GetMapping("/getunique")
@ResponseBody
public Set<String> findFiles(@RequestParam String rootFolder, @RequestParam String extension) {

return fileService.findFiles(rootFolder, extension);
}

/**
* Endpoint to get the /getunique endpoint's calling history
* @return Returns with a list of the responses
*/
@GetMapping("/history")
@ResponseBody
public List<LogEntryDTO> getHistory() {

return logEntryService.getAllLogEntries();
}

/**
* Endpoint to get the Application Documentation
* @return Redirects to the root folder, where the documentation is
*/
@GetMapping("/doc")
public String getDocumentation(){

return "redirect:/";
}

/**
* Endpoint to generate a random filesystem, to test the /getuniqe endpoint.
* @return Returns with a message if it was successful or not.
*/
@GetMapping("/gen")
@ResponseBody
public String generateFileStructure() {

File rootFolder = new File("generated_root");

if (rootFolder.exists()) {
try {
FileUtils.deleteDirectory(rootFolder);
} catch (IOException e) {
e.printStackTrace();
return "Failed to delete existing folder.";
}
}

rootFolder.mkdirs();

try {
fileService.createFileStructure(rootFolder, 0);
return "File structure generated successfully.";
} catch (IOException e) {
e.printStackTrace();
return "Failed to generate file structure.";
}
}

}
Loading

0 comments on commit fcb137d

Please sign in to comment.