diff --git a/.gitignore b/.gitignore index a838fac..66ba643 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ build/ ### VS Code ### .vscode/ src/main/resources/application.properties +src/main/resources/application.properties diff --git a/src/main/java/com/apside/assistDbBackend/AssistDBBackendApplication.java b/src/main/java/com/apside/assist/db/backend/AssistDBBackendApplication.java similarity index 80% rename from src/main/java/com/apside/assistDbBackend/AssistDBBackendApplication.java rename to src/main/java/com/apside/assist/db/backend/AssistDBBackendApplication.java index f18b7b1..cee1b84 100644 --- a/src/main/java/com/apside/assistDbBackend/AssistDBBackendApplication.java +++ b/src/main/java/com/apside/assist/db/backend/AssistDBBackendApplication.java @@ -1,4 +1,4 @@ -package com.apside.assistDbBackend; +package com.apside.assist.db.backend; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -8,14 +8,14 @@ import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; -import java.io.File; -import java.io.IOException; import java.util.Arrays; @SpringBootApplication(exclude = SecurityAutoConfiguration.class) public class AssistDBBackendApplication { - public static void main(String[] args) throws IOException { + private static final String ACCESS_CONTROL = "Access-Control-Allow-Origin"; + + public static void main(String[] args){ SpringApplication.run(AssistDBBackendApplication.class, args); @@ -26,11 +26,11 @@ public class AssistDBBackendApplication { CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.setAllowCredentials(true); corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:9002")); - corsConfiguration.setAllowedHeaders(Arrays.asList("Origin", "Access-Control-Allow-Origin", "Content-Type", + corsConfiguration.setAllowedHeaders(Arrays.asList("Origin", ACCESS_CONTROL, "Content-Type", "Accept", "Authorization", "Origin, Accept", "X-Requested-With", "Access-Control-Request-Method", "Access-Control-Request-Headers")); corsConfiguration.setExposedHeaders(Arrays.asList("Origin", "Content-Type", "Accept", "Authorization", - "Access-Control-Allow-Origin", "Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")); + ACCESS_CONTROL, ACCESS_CONTROL, "Access-Control-Allow-Credentials")); corsConfiguration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS")); UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource(); urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); diff --git a/src/main/java/com/apside/assist/db/backend/controller/InfoColumnController.java b/src/main/java/com/apside/assist/db/backend/controller/InfoColumnController.java new file mode 100644 index 0000000..88f47c6 --- /dev/null +++ b/src/main/java/com/apside/assist/db/backend/controller/InfoColumnController.java @@ -0,0 +1,111 @@ +package com.apside.assist.db.backend.controller; + +import com.apside.assist.db.backend.model.InfoColumn; +import com.apside.assist.db.backend.service.InfoColumnService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +@RestController +@RequestMapping("/api") +@Slf4j +public class InfoColumnController { + @Autowired + private InfoColumnService infoColumnService; + + /** + * Read - Get one column + * @param id The id of the InfoColumn + * @return An InfoColumn object full filled + */ + @GetMapping("/column/{id}") + public ResponseEntity getColumn(@PathVariable("id") final Long id) { + log.debug("Start GetColumn - Get Request - with id: " + id); + Optional infoColumn = infoColumnService.getColumn(id); + if(infoColumn.isPresent()) { + return ResponseEntity.ok(infoColumn.get()); + } else { + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); + } + } + + /** + * Read - Get all Columns + * @return - An Iterable object of InfoColumn full filled + */ + @GetMapping("/columns/all") + public ResponseEntity> getColumns() { + log.debug("Start getColumns - Get Request"); + try { + Iterable columns = infoColumnService.getAllColumns(); + return ResponseEntity.ok(columns); + } catch (Exception e){ + log.error("Error occurred while fetching columns", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + /** + * Read - Get Columns by Schema's and Table's name + * @return - An Iterable object of InfoColumn full filled + */ + @GetMapping("/columns/{schema}/{table}") + public ResponseEntity> getSelectedColumns(@PathVariable("schema") final String schema, @PathVariable("table") final String table) { + log.debug("Start GetSelectedColumns - Get Request - with schema: {}, table: {}", schema, table); + try { + Iterable columnsSelected = infoColumnService.getSelectedColumns(table, schema); + return ResponseEntity.ok(columnsSelected); + } catch (Exception e){ + log.error("Error occurred while fetching columns", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + @GetMapping("/columns/{firstSchema}/{secondSchema}/{firstTable}/{secondTable}") + public ResponseEntity> getColumnsForJoin(@PathVariable("firstTable") final String firstTable, @PathVariable("secondTable") final String secondTable, @PathVariable("firstSchema") final String firstSchema, @PathVariable("secondSchema") final String secondSchema) { + log.debug("Start GetColumnsForJoin - Get Request - with firstTable: {}, secondTable: {}, firstSchema: {}, secondSchema: {}", firstTable, secondTable, firstSchema, secondSchema); + try { + Iterable columnsForJoin = infoColumnService.getColumnsForJoin(firstTable, secondTable, firstSchema, secondSchema); + return ResponseEntity.ok(columnsForJoin); + } catch (Exception e){ + log.error("Error occurred while fetching columns", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + @GetMapping("/columns/joins") + public ResponseEntity> getColumnsForJoinTwo(@RequestParam("tables") String tables, @RequestParam("schemas") String schemas) { + log.debug("Start GetColumnsForJoinTwo - Get Request - with tables: {}, schemas: {}", tables, schemas); + List tablesList = new ArrayList<>(Arrays.asList(tables.split(","))); + List schemasList = new ArrayList<>(Arrays.asList(schemas.split(","))); + try { + Iterable columnsForJoin = infoColumnService.getColumnsForJoinTwo(tablesList, schemasList); + return ResponseEntity.ok(columnsForJoin); + } catch (Exception e){ + log.error("Error occurred while fetching columns", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + @DeleteMapping("/columns/deleteAll") + public ResponseEntity deleteAllColumns() { + log.debug("DeleteAllColumns called"); + try { + infoColumnService.deleteAllColumn(); + return ResponseEntity.ok().build(); + } catch (Exception e) { + log.error("Error occurred while deleting columns", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + + +} diff --git a/src/main/java/com/apside/assist/db/backend/controller/InfoTableController.java b/src/main/java/com/apside/assist/db/backend/controller/InfoTableController.java new file mode 100644 index 0000000..4a11f77 --- /dev/null +++ b/src/main/java/com/apside/assist/db/backend/controller/InfoTableController.java @@ -0,0 +1,108 @@ +package com.apside.assist.db.backend.controller; + +import com.apside.assist.db.backend.model.InfoTable; +import com.apside.assist.db.backend.service.InfoTableService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Optional; + +@RestController +@RequestMapping("/api") +@Slf4j +public class InfoTableController { + @Autowired + private InfoTableService infoTableService; + + + /** + * Read - Get one table + * @param id The id of the InfoTable + * @return An InfoTable object full filled + */ + @GetMapping("/table/{id}") + public ResponseEntity getTable(@PathVariable("id") final Long id) { + log.debug("Start getTable - Get Request - with id: " + id); + + Optional infoTable = infoTableService.getTable(id); + if (infoTable.isPresent()) { + return ResponseEntity.ok(infoTable.get()); + } else { + return ResponseEntity.notFound().build(); + } + } + + /** + * Read - Get all Tables + * @return - An Iterable object of InfoTable full filled + */ + @GetMapping("/tables/all") + public ResponseEntity> getTables() { + try { + Iterable tables = infoTableService.getAllTables(); + return ResponseEntity.ok(tables); + } catch (Exception e) { + log.error("Error occurred while fetching tables", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + /** + * Read - Get all Schemas + * @return - An Iterable object of String full filled + */ + @GetMapping("/schemas/all") + public ResponseEntity> getSchemas() { + log.debug("Start getSchemas - Get Request"); + try { + Iterable schemas = infoTableService.getAllSchemas(); + return ResponseEntity.ok(schemas); + } catch (Exception e) { + log.error("Error occurred while fetching schemas", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + /** + * Read - Get Tables by Schema's name + * @return - An Iterable object of InfoTable full filled + */ + @GetMapping("/tables/{schema}") + public ResponseEntity> getTablesBySchemaName(@PathVariable("schema") final String schema) { + log.debug("Start getTablesBySchemaName - Get Request - with schema: {}", schema); + try { + Iterable tables = infoTableService.getTablesBySchemaName(schema); + return ResponseEntity.ok(tables); + } catch (Exception e) { + log.error("Error occurred while fetching tables by schema", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + @GetMapping("/schemas/{table}") + public ResponseEntity> getSchemaByTableName(@PathVariable("table") final String table) { + log.debug("Start getSchemaByTableName - Get Request - with table: {}", table); + try { + Iterable schemas = infoTableService.getSchemaByTableName(table); + return ResponseEntity.ok(schemas); + } catch (Exception e) { + log.error("Error occurred while fetching schema by table name", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + @DeleteMapping("/tables/deleteAll") + public ResponseEntity deleteAllTables() { + log.debug("DeleteAllTables called"); + try { + infoTableService.deleteAllTable(); + return ResponseEntity.ok().build(); + } catch (Exception e) { + log.error("Error occurred while deleting tables", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + +} diff --git a/src/main/java/com/apside/assist/db/backend/controller/LinkInfoController.java b/src/main/java/com/apside/assist/db/backend/controller/LinkInfoController.java new file mode 100644 index 0000000..570f88f --- /dev/null +++ b/src/main/java/com/apside/assist/db/backend/controller/LinkInfoController.java @@ -0,0 +1,65 @@ +package com.apside.assist.db.backend.controller; + +import com.apside.assist.db.backend.model.LinkInfo; +import com.apside.assist.db.backend.service.LinkInfoService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Optional; + +@RestController +@RequestMapping("/api") +@Slf4j +public class LinkInfoController { + + @Autowired + private LinkInfoService linkInfoService; + + + /** + * Read - Get one Link + * @param id The id of the LinkInfo + * @return An LinkInfo object full filled + */ + @GetMapping("/link/{id}") + public ResponseEntity getLinkInfo(@PathVariable("id") final Long id) { + log.debug("Start getLinkInfo - Get Request - with id: " + id); + Optional linkInfo = linkInfoService.getLinkInfo(id); + if (linkInfo.isPresent()) { + return ResponseEntity.ok(linkInfo.get()); + } else { + return ResponseEntity.notFound().build(); + } + } + + /** + * Read - Get all LinkInfos + * @return - An Iterable object of LinkInfo full filled + */ + @GetMapping("/links/all") + public ResponseEntity> getLinksInfos() { + log.debug("Start getLinksInfos - Get Request"); + try { + Iterable linksInfos = linkInfoService.getAllLinksInfos(); + return ResponseEntity.ok(linksInfos); + } catch (Exception e) { + log.error("Error occurred while fetching link infos", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + @DeleteMapping("/links/deleteAll") + public ResponseEntity deleteAllLinks() { + log.debug("DeleteAllLinks called"); + try { + linkInfoService.deleteAllLinks(); + return ResponseEntity.ok().build(); + } catch (Exception e) { + log.error("Error occurred while deleting links", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } +} diff --git a/src/main/java/com/apside/assist/db/backend/controller/ResetDataController.java b/src/main/java/com/apside/assist/db/backend/controller/ResetDataController.java new file mode 100644 index 0000000..c5341e9 --- /dev/null +++ b/src/main/java/com/apside/assist/db/backend/controller/ResetDataController.java @@ -0,0 +1,32 @@ +package com.apside.assist.db.backend.controller; + +import java.io.IOException; +import com.apside.assist.db.backend.service.ResetDataService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api") +@Slf4j +public class ResetDataController { + @Autowired + private ResetDataService resetDataService; + + + @PostMapping("/reset") + public ResponseEntity resetData() { + log.debug("ResetData called"); + try { + resetDataService.deleteEverything(); + resetDataService.insertEverything(); + resetDataService.checkAndInsertLinks(); + return ResponseEntity.ok().build(); + } catch (Exception e) { + log.error("Error occurred while resetting data", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/apside/assist/db/backend/controller/ScriptController.java b/src/main/java/com/apside/assist/db/backend/controller/ScriptController.java new file mode 100644 index 0000000..216f5e6 --- /dev/null +++ b/src/main/java/com/apside/assist/db/backend/controller/ScriptController.java @@ -0,0 +1,88 @@ +package com.apside.assist.db.backend.controller; + +import com.apside.assist.db.backend.model.LinkScriptTag; +import com.apside.assist.db.backend.model.Script;; +import com.apside.assist.db.backend.service.ScriptsService; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.List; + +@RestController +@RequestMapping("/api") +@Slf4j +public class ScriptController { + @Autowired + ScriptsService scriptsService; + + @GetMapping("/scripts") + public ResponseEntity> getAllScripts() { + log.debug("GetAllScripts called"); + try { + List