Skip to content

Commit

Permalink
Export database from API
Browse files Browse the repository at this point in the history
  • Loading branch information
amengus87 committed May 27, 2024
1 parent 15ad5d7 commit 2c998d3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ai.dragon.controller.api.backendapi.command;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import ai.dragon.service.DatabaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/backendapi/command/database")
@Tag(name = "Database Command", description = "Database Command API Endpoints")
public class DatabaseCommandBackendApiController {
@Autowired
private DatabaseService databaseService;

@PostMapping("/database/export")
@ApiResponse(responseCode = "200", description = "Database dump has been successfully created.")
@Operation(summary = "Create a database export", description = "Creates a JSON database dump.")
public void export(HttpServletResponse response) throws Exception {
response.setContentType("application/json");
databaseService.exportDatabase(response.getOutputStream());
response.flushBuffer();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ai.dragon.controller.api.backendapi;
package ai.dragon.controller.api.backendapi.repository;

import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -27,8 +27,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("/api/backendapi/ingestor")
@Tag(name = "Ingestor", description = "Ingestor Management API Endpoints")
@RequestMapping("/api/backendapi/repository/ingestor")
@Tag(name = "Ingestor Repository", description = "Ingestor Repository Management API Endpoints")
public class IngestorBackendApiController {
@Autowired
private IngestorRepository ingestorRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ai.dragon.controller.api.backendapi;
package ai.dragon.controller.api.backendapi.repository;

import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -29,8 +29,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("/api/backendapi/provider")
@Tag(name = "Provider", description = "Provider Management API Endpoints")
@RequestMapping("/api/backendapi/repository/provider")
@Tag(name = "Provider Repository", description = "Provider Repository Management API Endpoints")
public class ProviderBackendApiController {
@Autowired
private ProviderRepository providerRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ai.dragon.controller.api.backendapi;
package ai.dragon.controller.api.backendapi.repository;

import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -27,8 +27,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("/api/backendapi/silo")
@Tag(name = "Silo", description = "Silo Management API Endpoints")
@RequestMapping("/api/backendapi/repository/silo")
@Tag(name = "Silo Repository", description = "Silo Repository Management API Endpoints")
public class SiloBackendApiController {
@Autowired
private SiloRepository siloRepository;
Expand Down
9 changes: 9 additions & 0 deletions backend/src/main/java/ai/dragon/service/DatabaseService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ai.dragon.service;

import java.io.File;
import java.io.OutputStream;
import java.util.Optional;

import org.dizitart.no2.Nitrite;
Expand Down Expand Up @@ -72,6 +73,14 @@ public void exportDatabase(String fileOutput) {
exporter.exportTo(fileOutput);
}

public void exportDatabase(OutputStream outputStream) throws Exception {
ExportOptions exportOptions = new ExportOptions();
exportOptions.setNitriteFactory(() -> getNitriteDB());

Exporter exporter = Exporter.withOptions(exportOptions);
exporter.exportTo(outputStream);
}

private String getDatabaseFilename() {
return Optional.ofNullable(dataProperties.getDb()).orElse("dragon.db");
}
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import WIPS from '../src/components/Admonitions/_wip_section.mdx';
Let's discover **dRAGon in less than 5 minutes**.

## Launching dRAGon
:::danger
dRAGon lacks of authentication and authorization mechanisms. It is not recommended to expose it to the internet or unsafe networks.
These mechanisms will be implemented in a near future.
:::

<WIPS />

### Gradle
Expand Down

0 comments on commit 2c998d3

Please sign in to comment.