parent
c37c5f15c8
commit
e9347aaa9a
@ -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<InfoColumn> getColumn(@PathVariable("id") final Long id) { |
||||
log.debug("Start GetColumn - Get Request - with id: " + id); |
||||
Optional<InfoColumn> 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<Iterable<InfoColumn>> getColumns() { |
||||
log.debug("Start getColumns - Get Request"); |
||||
try { |
||||
Iterable<InfoColumn> 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<Iterable<InfoColumn>> getSelectedColumns(@PathVariable("schema") final String schema, @PathVariable("table") final String table) { |
||||
log.debug("Start GetSelectedColumns - Get Request - with schema: {}, table: {}", schema, table); |
||||
try { |
||||
Iterable<InfoColumn> 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<Iterable<InfoColumn>> 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<InfoColumn> 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<Iterable<InfoColumn>> getColumnsForJoinTwo(@RequestParam("tables") String tables, @RequestParam("schemas") String schemas) { |
||||
log.debug("Start GetColumnsForJoinTwo - Get Request - with tables: {}, schemas: {}", tables, schemas); |
||||
List<String> tablesList = new ArrayList<>(Arrays.asList(tables.split(","))); |
||||
List<String> schemasList = new ArrayList<>(Arrays.asList(schemas.split(","))); |
||||
try { |
||||
Iterable<InfoColumn> 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<Void> 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(); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -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<InfoTable> getTable(@PathVariable("id") final Long id) { |
||||
log.debug("Start getTable - Get Request - with id: " + id); |
||||
|
||||
Optional<InfoTable> 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<Iterable<InfoTable>> getTables() { |
||||
try { |
||||
Iterable<InfoTable> 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<Iterable<String>> getSchemas() { |
||||
log.debug("Start getSchemas - Get Request"); |
||||
try { |
||||
Iterable<String> 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<Iterable<InfoTable>> getTablesBySchemaName(@PathVariable("schema") final String schema) { |
||||
log.debug("Start getTablesBySchemaName - Get Request - with schema: {}", schema); |
||||
try { |
||||
Iterable<InfoTable> 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<Iterable<InfoTable>> getSchemaByTableName(@PathVariable("table") final String table) { |
||||
log.debug("Start getSchemaByTableName - Get Request - with table: {}", table); |
||||
try { |
||||
Iterable<InfoTable> 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<Void> 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(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -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<LinkInfo> getLinkInfo(@PathVariable("id") final Long id) { |
||||
log.debug("Start getLinkInfo - Get Request - with id: " + id); |
||||
Optional<LinkInfo> 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<Iterable<LinkInfo>> getLinksInfos() { |
||||
log.debug("Start getLinksInfos - Get Request"); |
||||
try { |
||||
Iterable<LinkInfo> 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<Void> 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(); |
||||
} |
||||
} |
||||
} |
@ -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<Void> 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(); |
||||
} |
||||
} |
||||
} |
@ -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<List<Script>> getAllScripts() { |
||||
log.debug("GetAllScripts called"); |
||||
try { |
||||
List<Script> scripts = scriptsService.retrieveScripts(); |
||||
return ResponseEntity.ok(scripts); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while retrieving scripts", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@GetMapping("/scripts/link") |
||||
public ResponseEntity<List<LinkScriptTag>> getAllLinkScriptsTags() { |
||||
log.debug("GetAllLinkScriptsTags called"); |
||||
try { |
||||
List<LinkScriptTag> linkScriptsTags = scriptsService.getAllScriptTag(); |
||||
return ResponseEntity.ok(linkScriptsTags); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while retrieving link scripts tags", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@DeleteMapping("/script/delete/{name}") |
||||
public ResponseEntity<Void> deleteScript(@PathVariable("name") final String name) { |
||||
log.debug("Start DeleteScript - Delete Request - with name: {}", name); |
||||
try { |
||||
scriptsService.deleteOneScript(name); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while deleting script", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
|
||||
@GetMapping("/script/add") |
||||
public ResponseEntity<Void> addScript(@RequestParam("content") String content, @RequestParam("name") String name, @RequestParam("desc") String description, @RequestParam("tagList") List<String> tagsList, @RequestParam("linkid") int linkId) { |
||||
log.debug("Start AddScript - Get Request - with name: {}, description: {}, tagsList: {} and linkId: {}", name, description, tagsList, linkId); |
||||
try { |
||||
scriptsService.addOneScript(content, name); |
||||
scriptsService.addOneLink(name, description, tagsList, linkId); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while adding script", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@GetMapping("/script/edit") |
||||
public ResponseEntity<Void> editScript(@RequestParam("content") String content, @RequestParam("defaultname") String defaultName, @RequestParam("newname") String newName, @RequestParam("desc") String description, @RequestParam("tagList") List<String> tagsList, @RequestParam("linkid") int linkId) { |
||||
log.debug("Start EditScript - Get Request - with defaultName: {}, newName: {}, description: {}, tagsList: {}, linkId: {}", defaultName, newName, description, tagsList, linkId); |
||||
try { |
||||
scriptsService.simpleDeleteScript(defaultName); |
||||
scriptsService.addOneScript(content, newName); |
||||
scriptsService.updateOneLink(newName, description, tagsList, linkId); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while editing script", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,71 @@ |
||||
package com.apside.assist.db.backend.controller; |
||||
|
||||
import com.apside.assist.db.backend.model.Tag; |
||||
import com.apside.assist.db.backend.service.TagsService; |
||||
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 TagsController { |
||||
|
||||
@Autowired |
||||
private TagsService tagsService; |
||||
|
||||
@GetMapping("/tags/all") |
||||
public ResponseEntity<List<Tag>> getTags() { |
||||
log.debug("GetTags called"); |
||||
try { |
||||
List<Tag> tags = tagsService.getAllTags(); |
||||
return ResponseEntity.ok(tags); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while retrieving tags", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@DeleteMapping("/tag/delete/{nameTag}") |
||||
public ResponseEntity<Void> deleteTag(@PathVariable("nameTag") final String nameTag) { |
||||
log.debug("Start DeleteTag - Delete Request - with name: {}", nameTag); |
||||
try { |
||||
tagsService.deleteTag(nameTag); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while deleting tag", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@PostMapping("/tag/add") |
||||
public ResponseEntity<Void> addTag(@RequestBody Tag tag) { |
||||
log.debug("Start AddTag - Post Request - with tag: {}", tag); |
||||
try { |
||||
tagsService.addTag(tag); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while adding tag", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
|
||||
@PutMapping("/tag/update/{prevTag}") |
||||
public ResponseEntity<Void> updateTag(@PathVariable("prevTag") final String prevTag, @RequestBody Tag tag) { |
||||
log.debug("Start UpdateTag - Put Request - with previous tag: {}, new tag info: {}", prevTag, tag); |
||||
try { |
||||
tagsService.updateTag(prevTag, tag); |
||||
return ResponseEntity.ok().build(); |
||||
} catch (Exception e) { |
||||
log.error("Error occurred while updating tag", e); |
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); |
||||
} |
||||
} |
||||
} |
@ -1,4 +1,4 @@ |
||||
package com.apside.assistDbBackend.model; |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import jakarta.persistence.*; |
||||
import lombok.Builder; |
@ -1,4 +1,4 @@ |
||||
package com.apside.assistDbBackend.model; |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import jakarta.persistence.*; |
||||
import lombok.Builder; |
@ -1,4 +1,4 @@ |
||||
package com.apside.assistDbBackend.model; |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import jakarta.persistence.*; |
||||
import lombok.Data; |
@ -1,4 +1,4 @@ |
||||
package com.apside.assistDbBackend.model; |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import lombok.Data; |
||||
|
@ -1,4 +1,4 @@ |
||||
package com.apside.assistDbBackend.model; |
||||
package com.apside.assist.db.backend.model; |
||||
|
||||
import lombok.Data; |
||||
|
@ -1,6 +1,6 @@ |
||||
package com.apside.assistDbBackend.repository; |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assistDbBackend.model.InfoColumn; |
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import org.springframework.data.jpa.repository.Modifying; |
||||
import org.springframework.data.jpa.repository.Query; |
||||
import org.springframework.data.repository.CrudRepository; |
@ -1,6 +1,6 @@ |
||||
package com.apside.assistDbBackend.repository; |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assistDbBackend.model.InfoTable; |
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import org.springframework.data.jpa.repository.Modifying; |
||||
import org.springframework.data.jpa.repository.Query; |
||||
import org.springframework.data.repository.CrudRepository; |
@ -1,6 +1,6 @@ |
||||
package com.apside.assistDbBackend.repository; |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assistDbBackend.model.LinkInfo; |
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import org.springframework.data.jpa.repository.Modifying; |
||||
import org.springframework.data.jpa.repository.Query; |
||||
import org.springframework.data.repository.CrudRepository; |
@ -0,0 +1,25 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
|
||||
public interface GitService { |
||||
|
||||
/** |
||||
* Réalise un push sur le Gitea - AdditionalFiles |
||||
* @param |
||||
* @return void |
||||
* @throws | IOException | GitAPIException | URISyntaxException |
||||
*/ |
||||
void pushToGit() throws IOException, GitAPIException, URISyntaxException; |
||||
|
||||
/** |
||||
* Réalise un pull via le Gitea - AdditionalFiles |
||||
* @param |
||||
* @return void |
||||
* @throws | IOException | GitAPIException | URISyntaxException |
||||
*/ |
||||
void pullFromGit() throws IOException, GitAPIException; |
||||
} |
@ -0,0 +1,88 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
|
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
public interface InfoColumnService { |
||||
|
||||
/** |
||||
* Récupère une colonne spécifique |
||||
* @param id |
||||
* @return InfoColum, |
||||
*/ |
||||
Optional<InfoColumn> getColumn(final Long id); |
||||
|
||||
/** |
||||
* Récupère toutes les colonnes |
||||
* @param |
||||
* @return InfoColum, |
||||
*/ |
||||
Iterable<InfoColumn> getAllColumns(); |
||||
|
||||
/** |
||||
* Récupère les colonnes présentes dans un duo Schéma/Table spécifique |
||||
* @param table |
||||
* @param schema |
||||
* @return InfoColum, |
||||
*/ |
||||
Iterable<InfoColumn> getSelectedColumns(String table, String schema); |
||||
|
||||
/** |
||||
* Récupère les colonnes présentes dans deux tables différentes |
||||
* @param firstTable |
||||
* @param secondTable |
||||
* @param firstSchema |
||||
* @param secondSchema |
||||
* @return InfoColum, |
||||
*/ |
||||
Iterable<InfoColumn> getColumnsForJoin(String firstTable, String secondTable, String firstSchema, String secondSchema); |
||||
|
||||
/** |
||||
* Récupère les colonnes présentes dans deux tables différentes |
||||
* @param tables |
||||
* @param schemas |
||||
* @return InfoColum, |
||||
*/ |
||||
Iterable<InfoColumn> getColumnsForJoinTwo(List<String> tables, List<String> schemas); |
||||
|
||||
/** |
||||
* Supprime une colonne spécifique |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
void deleteColumn(final Long id); |
||||
|
||||
/** |
||||
* Supprime toutes les colonnes |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void deleteAllColumn(); |
||||
|
||||
/** |
||||
* Ajoute ou modifie une colonne |
||||
* @param infoColumn |
||||
* @return InfoColum, |
||||
*/ |
||||
InfoColumn addOrUpdateColumn(InfoColumn infoColumn); |
||||
|
||||
/** |
||||
* Récupère les informations d'une colonne spécifique |
||||
* @param nameCol |
||||
* @param dataType |
||||
* @param lengthCol |
||||
* @param columnText |
||||
* @return InfoColum, |
||||
*/ |
||||
InfoColumn getSpecCol(String nameCol, String dataType, int lengthCol, String columnText); |
||||
|
||||
/** |
||||
* Vide la table contenant toutes les colonnes |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void truncateMyColumn(); |
||||
|
||||
} |
@ -0,0 +1,71 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
public interface InfoTableService { |
||||
|
||||
/** |
||||
* Récupère une table spécifique |
||||
* @param id |
||||
* @return InfoTable, |
||||
*/ |
||||
Optional<InfoTable> getTable(final Long id); |
||||
|
||||
/** |
||||
* Récupère toutes les tables |
||||
* @param |
||||
* @return InfoTable, |
||||
*/ |
||||
Iterable<InfoTable> getAllTables(); |
||||
|
||||
/** |
||||
* Récupère les tables ayant un schéma spécifique |
||||
* @param schema |
||||
* @return InfoTable, |
||||
*/ |
||||
Iterable<InfoTable> getTablesBySchemaName(String schema); |
||||
|
||||
/** |
||||
* Récupère les schémas ayant une table spécifique |
||||
* @param table |
||||
* @return InfoTable, |
||||
*/ |
||||
Iterable<InfoTable> getSchemaByTableName(String table); |
||||
|
||||
/** |
||||
* Récupère tous les schémas |
||||
* @param |
||||
* @return String, |
||||
*/ |
||||
Iterable<String> getAllSchemas(); |
||||
|
||||
/** |
||||
* Supprime une table spécifique |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
void deleteTable(final Long id); |
||||
|
||||
/** |
||||
* Supprime toutes les tables |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void deleteAllTable(); |
||||
|
||||
/** |
||||
* Ajoute ou modifie une table |
||||
* @param infoTable |
||||
* @return InfoTable, |
||||
*/ |
||||
InfoTable addOrUpdateTable(InfoTable infoTable); |
||||
|
||||
/** |
||||
* Vide la table contenant toutes les tables |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void truncateMyTable(); |
||||
} |
@ -0,0 +1,50 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
public interface LinkInfoService { |
||||
|
||||
/** |
||||
* Récupère un lien spécifique |
||||
* @param id |
||||
* @return LinkInfo, |
||||
*/ |
||||
Optional<LinkInfo> getLinkInfo(final Long id); |
||||
|
||||
/** |
||||
* Récupère tous les liens |
||||
* @param |
||||
* @return LinkInfo, |
||||
*/ |
||||
Iterable<LinkInfo> getAllLinksInfos(); |
||||
|
||||
/** |
||||
* Supprime un lien spécifique |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
void deleteLinkInfo(final Long id); |
||||
|
||||
/** |
||||
* Supprime tous les liens |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void deleteAllLinks(); |
||||
|
||||
/** |
||||
* Ajoute ou modifie un lien spécifique |
||||
* @param linkInfo |
||||
* @return LinkInfo, |
||||
*/ |
||||
LinkInfo addOrUpdateLink(LinkInfo linkInfo); |
||||
|
||||
/** |
||||
* Vide la table contenant tous les liens entre tables et colonnes |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void truncateMyLink(); |
||||
} |
@ -0,0 +1,25 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
public interface ResetDataService { |
||||
|
||||
/** |
||||
* Supprime toutes les données stockées en Base de données |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void deleteEverything(); |
||||
|
||||
/** |
||||
* Insert les données des tables, colonnes et schémas dans la base de données |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void insertEverything(); |
||||
|
||||
/** |
||||
* Insert les informations des liens entre les colonnes et les tables en base de données |
||||
* @param |
||||
* @return |
||||
*/ |
||||
void checkAndInsertLinks(); |
||||
} |
@ -0,0 +1,86 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.LinkScriptTag; |
||||
import com.apside.assist.db.backend.model.Script; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.util.List; |
||||
|
||||
public interface ScriptsService { |
||||
|
||||
/** |
||||
* Initialise le chemin du répertoire où les fichiers seront récupérés |
||||
* @param |
||||
* @return |
||||
* @throws IOException |
||||
*/ |
||||
void initialize() throws IOException; |
||||
|
||||
/** |
||||
* Permet de récupérer l'ensemble des scripts et requêtes dans le répertoire |
||||
* @param |
||||
* @return Script |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
*/ |
||||
List<Script> retrieveScripts() throws IOException, GitAPIException; |
||||
|
||||
/** |
||||
* Permet de récupérer l'ensemble des informations liant les scripts et leurs tags associés via le fichier json "scripts" |
||||
* @param |
||||
* @return LinkScriptTag |
||||
* @throws IOException |
||||
*/ |
||||
List<LinkScriptTag> getAllScriptTag() throws IOException; |
||||
|
||||
/** |
||||
* Supprime un script spécifique |
||||
* @param name |
||||
* @return |
||||
*/ |
||||
void deleteOneScript(final String name); |
||||
|
||||
/** |
||||
* Supprime un script spécifique |
||||
* @param name |
||||
* @return |
||||
*/ |
||||
void simpleDeleteScript(final String name); |
||||
|
||||
/** |
||||
* Ajoute un script dans le répertoire |
||||
* @param content |
||||
* @param name |
||||
* @return |
||||
* @throws IOException |
||||
*/ |
||||
void addOneScript(final String content, final String name) throws IOException; |
||||
|
||||
/** |
||||
* Ajoute un lien entre un script et ses tags dans le fichier json |
||||
* @param name |
||||
* @param description |
||||
* @param tagList |
||||
* @param linkId |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void addOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException; |
||||
|
||||
/** |
||||
* Modifie et actualise un lien spécifique entre un script et ses tags |
||||
* @param name |
||||
* @param description |
||||
* @param tagList |
||||
* @param linkId |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void updateOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException; |
||||
} |
@ -0,0 +1,59 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.model.Tag; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.util.List; |
||||
|
||||
public interface TagsService { |
||||
|
||||
/** |
||||
* Initialise le chemin du répertoire où le fichier json contenant les tags se situe |
||||
* @param |
||||
* @return |
||||
* @throws IOException |
||||
*/ |
||||
void initialize() throws IOException; |
||||
|
||||
/** |
||||
* Permet de récupérer tous les tags via le fichier json "tags" |
||||
* @param |
||||
* @return Tag |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
*/ |
||||
List<Tag> getAllTags() throws IOException, GitAPIException; |
||||
|
||||
/** |
||||
* Supprime un tag dans le fichier json |
||||
* @param deleteNameTag |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void deleteTag(final String deleteNameTag) throws IOException, GitAPIException, URISyntaxException; |
||||
|
||||
/** |
||||
* Ajoute un tag dans le fichier json |
||||
* @param tag |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void addTag(Tag tag) throws IOException, GitAPIException, URISyntaxException; |
||||
|
||||
/** |
||||
* Modifie et actualise un tag |
||||
* @param prevTag |
||||
* @param modTag |
||||
* @return |
||||
* @throws IOException |
||||
* @throws GitAPIException |
||||
* @throws URISyntaxException |
||||
*/ |
||||
void updateTag(final String prevTag, Tag modTag) throws IOException, GitAPIException, URISyntaxException; |
||||
} |
@ -1,80 +0,0 @@ |
||||
package com.apside.assistDbBackend.controller; |
||||
|
||||
import com.apside.assistDbBackend.model.InfoColumn; |
||||
import com.apside.assistDbBackend.service.InfoColumnService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
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 InfoColumn getColumn(@PathVariable("id") final Long id) { |
||||
log.debug("Start GetColumn - Get Request - with id: " + id); |
||||
Optional<InfoColumn> infoColumn = infoColumnService.getColumn(id); |
||||
if(infoColumn.isPresent()) { |
||||
return infoColumn.get(); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Read - Get all Columns |
||||
* @return - An Iterable object of InfoColumn full filled |
||||
*/ |
||||
@GetMapping("/columns/all") |
||||
public Iterable<InfoColumn> getColumns() { |
||||
log.debug("Start getColumns - Get Request"); |
||||
return infoColumnService.getAllColumns(); |
||||
} |
||||
|
||||
/** |
||||
* Read - Get Columns by Schema's and Table's name |
||||
* @return - An Iterable object of InfoColumn full filled |
||||
*/ |
||||
@GetMapping("/columns/{schema}/{table}") |
||||
public Iterable<InfoColumn> getSelectedColumns(@PathVariable("schema") final String schema, @PathVariable("table") final String table) { |
||||
log.debug("Start GetSelectedColumns - Get Request - with schema: {}, table: {}", schema, table); |
||||
return infoColumnService.getSelectedColumns(table, schema); |
||||
} |
||||
|
||||
@GetMapping("/columns/{firstSchema}/{secondSchema}/{firstTable}/{secondTable}") |
||||
public Iterable<InfoColumn> 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); |
||||
|
||||
return infoColumnService.getColumnsForJoin(firstTable, secondTable, firstSchema, secondSchema); |
||||
} |
||||
|
||||
@GetMapping("/columns/joins") |
||||
public Iterable<InfoColumn> getColumnsForJoinTwo(@RequestParam("tables") String tables, @RequestParam("schemas") String schemas) { |
||||
log.debug("Start GetColumnsForJoinTwo - Get Request - with tables: {}, schemas: {}", tables, schemas); |
||||
List<String> tablesList = new ArrayList<>(Arrays.asList(tables.split(","))); |
||||
List<String> schemasList = new ArrayList<>(Arrays.asList(schemas.split(","))); |
||||
return infoColumnService.getColumnsForJoinTwo(tablesList, schemasList); |
||||
} |
||||
|
||||
@DeleteMapping("/columns/deleteAll") |
||||
public void deleteAllColumns() { |
||||
log.debug("DeleteAllColumns called"); |
||||
infoColumnService.deleteAllColumn(); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -1,77 +0,0 @@ |
||||
package com.apside.assistDbBackend.controller; |
||||
|
||||
import com.apside.assistDbBackend.service.InfoTableService; |
||||
import com.apside.assistDbBackend.model.InfoTable; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
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 InfoTable getTable(@PathVariable("id") final Long id) { |
||||
log.debug("Start getTable - Get Request - with id: " + id); |
||||
Optional<InfoTable> infoTable = infoTableService.getTable(id); |
||||
if(infoTable.isPresent()) { |
||||
return infoTable.get(); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Read - Get all Tables |
||||
* @return - An Iterable object of InfoTable full filled |
||||
*/ |
||||
@GetMapping("/tables/all") |
||||
public Iterable<InfoTable> getTables() { |
||||
return infoTableService.getAllTables(); |
||||
} |
||||
|
||||
/** |
||||
* Read - Get all Schemas |
||||
* @return - An Iterable object of String full filled |
||||
*/ |
||||
@GetMapping("/schemas/all") |
||||
public Iterable<String> getSchemas() { |
||||
log.debug("Start getSchemas - Get Request"); |
||||
return infoTableService.getAllSchemas(); |
||||
} |
||||
|
||||
/** |
||||
* Read - Get Tables by Schema's name |
||||
* @return - An Iterable object of InfoTable full filled |
||||
*/ |
||||
@GetMapping("/tables/{schema}") |
||||
public Iterable<InfoTable> getTablesBySchemaName(@PathVariable("schema") final String schema) { |
||||
log.debug("Start getTablesBySchemaName - Get Request - with schema: {}", schema); |
||||
return infoTableService.getTablesBySchemaName(schema); |
||||
} |
||||
|
||||
@GetMapping("/schemas/{table}") |
||||
public Iterable<InfoTable> getSchemaByTableName(@PathVariable("table") final String table) { |
||||
log.debug("Start getSchemaByTableName - Get Request - with table: {}", table); |
||||
return infoTableService.getSchemaByTableName(table); |
||||
} |
||||
|
||||
@DeleteMapping("/tables/deleteAll") |
||||
public void deleteAllTables() { |
||||
log.debug("DeleteAllTables called"); |
||||
infoTableService.deleteAllTable(); |
||||
} |
||||
|
||||
} |
@ -1,51 +0,0 @@ |
||||
package com.apside.assistDbBackend.controller; |
||||
|
||||
import com.apside.assistDbBackend.model.LinkInfo; |
||||
import com.apside.assistDbBackend.service.LinkInfoService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
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 LinkInfo getLinkInfo(@PathVariable("id") final Long id) { |
||||
log.debug("Start getLinkInfo - Get Request - with id: " + id); |
||||
Optional<LinkInfo> linkInfo = linkInfoService.getLinkInfo(id); |
||||
if(linkInfo.isPresent()) { |
||||
return linkInfo.get(); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Read - Get all LinkInfos |
||||
* @return - An Iterable object of LinkInfo full filled |
||||
*/ |
||||
@GetMapping("/links/all") |
||||
public Iterable<LinkInfo> getLinksInfos() { |
||||
log.debug("Start getLinksInfos - Get Request"); |
||||
return linkInfoService.getAllLinksInfos(); |
||||
} |
||||
|
||||
@DeleteMapping("/links/deleteAll") |
||||
public void deleteAllLinks() { |
||||
log.debug("DeleteAllLinks called"); |
||||
linkInfoService.deleteAllLinks(); |
||||
} |
||||
} |
@ -1,25 +0,0 @@ |
||||
package com.apside.assistDbBackend.controller; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import com.apside.assistDbBackend.service.ResetDataService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api") |
||||
@Slf4j |
||||
public class ResetDataController { |
||||
@Autowired |
||||
private ResetDataService resetDataService; |
||||
|
||||
|
||||
@PostMapping("/reset") |
||||
public void resetData() throws IOException { |
||||
log.debug("ResetData called"); |
||||
resetDataService.deleteEverything(); |
||||
resetDataService.insertEverything(); |
||||
resetDataService.checkAndInsertLinks(); |
||||
} |
||||
} |
@ -1,59 +0,0 @@ |
||||
package com.apside.assistDbBackend.controller; |
||||
|
||||
import com.apside.assistDbBackend.model.LinkScriptTag; |
||||
import com.apside.assistDbBackend.model.Script; |
||||
import com.apside.assistDbBackend.service.ScriptsService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
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 List<Script> getAllScripts() throws IOException, GitAPIException { |
||||
log.debug("GetAllScripts called"); |
||||
return scriptsService.retrieveScripts(); |
||||
} |
||||
|
||||
@GetMapping("/scripts/link") |
||||
public List<LinkScriptTag> getAllLinkScriptsTags() throws IOException { |
||||
log.debug("GetAllLinkScriptsTags called"); |
||||
return scriptsService.getAllScriptTag(); |
||||
} |
||||
|
||||
@DeleteMapping("/script/delete/{name}") |
||||
public void deleteScript(@PathVariable("name") final String name){ |
||||
log.debug("Start DeleteScript - Delete Request - with name: {}" + name); |
||||
scriptsService.deleteOneScript(name); |
||||
} |
||||
|
||||
|
||||
@GetMapping("/script/add") |
||||
public void addScript(@RequestParam("content") String content, @RequestParam("name") String name, @RequestParam("desc") String description, @RequestParam("tagList") List<String> tagsList, @RequestParam("linkid") int linkId) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start AddScript - Get Request - with name: {}, description: {}, tagsList: {} and linkId: {}", name, description, tagsList, linkId); |
||||
scriptsService.addOneScript(content, name); |
||||
scriptsService.addOneLink(name, description, tagsList, linkId); |
||||
} |
||||
|
||||
@GetMapping("/script/edit") |
||||
public void editScript(@RequestParam("content") String content, @RequestParam("defaultname") String defaultName, @RequestParam("newname") String newName, @RequestParam("desc") String description, @RequestParam("tagList") List<String> tagsList, @RequestParam("linkid") int linkId) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start EditScript - Get Request - with defaultName: {}, newName: {}, description: {}, tagsList: {}, linkId: {}", defaultName, newName, description, tagsList, linkId); |
||||
scriptsService.simpleDeleteScript(defaultName); |
||||
scriptsService.addOneScript(content, newName); |
||||
scriptsService.updateOneLink(newName, description, tagsList, linkId); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -1,45 +0,0 @@ |
||||
package com.apside.assistDbBackend.controller; |
||||
|
||||
import com.apside.assistDbBackend.model.Tag; |
||||
import com.apside.assistDbBackend.service.TagsService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
import java.util.List; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api") |
||||
@Slf4j |
||||
public class TagsController { |
||||
|
||||
@Autowired |
||||
private TagsService tagsService; |
||||
|
||||
@GetMapping("/tags/all") |
||||
public List<Tag> getTags() throws IOException, GitAPIException { |
||||
log.debug("GetTags called"); |
||||
return tagsService.getAllTags(); |
||||
} |
||||
|
||||
@DeleteMapping("/tag/delete/{nameTag}") |
||||
public void deleteTag(@PathVariable("nameTag") final String nameTag) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start DeleteTag - Delete Request - with name: {}", nameTag); |
||||
tagsService.deleteTag(nameTag); |
||||
} |
||||
|
||||
@PostMapping("/tag/add") |
||||
public void addTag(@RequestBody Tag tag) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start AddTag - Post Request - with tag: {}", tag); |
||||
tagsService.addTag(tag); |
||||
} |
||||
|
||||
@PutMapping("/tag/update/{prevTag}") |
||||
public void updateTag(@PathVariable("prevTag") final String prevTag, @RequestBody Tag tag) throws IOException, GitAPIException, URISyntaxException { |
||||
log.debug("Start UpdateTag - Put Request - with previous tag: {}, new tag info: {}", prevTag, tag); |
||||
tagsService.updateTag(prevTag, tag); |
||||
} |
||||
} |
@ -1,4 +1,4 @@ |
||||
package com.apside.assistDbBackend; |
||||
package com.apside.assist.db.backend; |
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
@ -1,7 +1,7 @@ |
||||
package com.apside.assistDbBackend.repository; |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assistDbBackend.model.InfoColumn; |
||||
import com.apside.assistDbBackend.model.LinkInfo; |
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
@ -1,6 +1,6 @@ |
||||
package com.apside.assistDbBackend.repository; |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assistDbBackend.model.InfoTable; |
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
@ -1,7 +1,7 @@ |
||||
package com.apside.assistDbBackend.repository; |
||||
package com.apside.assist.db.backend.repository; |
||||
|
||||
import com.apside.assistDbBackend.model.InfoTable; |
||||
import com.apside.assistDbBackend.model.LinkInfo; |
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
@ -0,0 +1,86 @@ |
||||
package com.apside.assist.db.backend.service; |
||||
|
||||
import com.apside.assist.db.backend.implementation.InfoColumnServiceImpl; |
||||
import com.apside.assist.db.backend.implementation.InfoTableServiceImpl; |
||||
import com.apside.assist.db.backend.implementation.LinkInfoServiceImpl; |
||||
import com.apside.assist.db.backend.implementation.ResetDataServiceImpl; |
||||
import com.apside.assist.db.backend.model.InfoTable; |
||||
import com.apside.assist.db.backend.model.InfoColumn; |
||||
import com.apside.assist.db.backend.model.LinkInfo; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.Mock; |
||||
import org.mockito.MockitoAnnotations; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
|
||||
import static org.mockito.Mockito.*; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
class ResetDataServiceImplTest { |
||||
|
||||
@Mock |
||||
private InfoTableServiceImpl infoTableServiceImpl; |
||||
|
||||
@Mock |
||||
private InfoColumnServiceImpl infoColumnServiceImpl; |
||||
|
||||
@Mock |
||||
private LinkInfoServiceImpl linkInfoServiceImpl; |
||||
private ResetDataServiceImpl resetDataServiceImpl; |
||||
|
||||
@BeforeEach |
||||
void setUp() throws IOException { |
||||
MockitoAnnotations.openMocks(this); |
||||
resetDataServiceImpl = new ResetDataServiceImpl(); |
||||
resetDataServiceImpl.setInfoTableService(infoTableServiceImpl); |
||||
resetDataServiceImpl.setInfoColumnService(infoColumnServiceImpl); |
||||
resetDataServiceImpl.setLinkInfoService(linkInfoServiceImpl); |
||||
Path tempPath = Paths.get("src/test/resources/testDb.json"); |
||||
resetDataServiceImpl.setPath(tempPath); |
||||
resetDataServiceImpl.setResult(new String(Files.readAllBytes(tempPath))); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
void deleteEverything_shouldTruncateTables() { |
||||
// Arrange
|
||||
|
||||
// Act
|
||||
resetDataServiceImpl.deleteEverything(); |
||||
|
||||
// Assert
|
||||
verify(infoColumnServiceImpl, times(1)).truncateMyColumn(); |
||||
verify(infoTableServiceImpl, times(1)).truncateMyTable(); |
||||
verify(linkInfoServiceImpl, times(1)).truncateMyLink(); |
||||
} |
||||
|
||||
@Test |
||||
void insertEverything_shouldInsertData() throws IOException { |
||||
// Arrange
|
||||
// Act
|
||||
resetDataServiceImpl.insertEverything(); |
||||
|
||||
// Assert
|
||||
verify(infoTableServiceImpl, times(1)).addOrUpdateTable(any(InfoTable.class)); |
||||
verify(infoColumnServiceImpl, times(1)).addOrUpdateColumn(any(InfoColumn.class)); |
||||
} |
||||
|
||||
@Test |
||||
void checkAndInsertLinks_shouldInsertLinks() throws IOException { |
||||
// Arrange
|
||||
when(infoColumnServiceImpl.getSpecCol(anyString(), anyString(), anyInt(), anyString())) |
||||
.thenReturn(new InfoColumn(1L, "col1", "type1", 10, "coltext1")); // Mocking infoColumnService.getSpecCol()
|
||||
|
||||
// Act
|
||||
resetDataServiceImpl.checkAndInsertLinks(); |
||||
|
||||
// Assert
|
||||
verify(linkInfoServiceImpl, times(1)).addOrUpdateLink(any(LinkInfo.class)); |
||||
} |
||||
} |
@ -1,82 +0,0 @@ |
||||
package com.apside.assistDbBackend.service; |
||||
|
||||
import com.apside.assistDbBackend.model.InfoColumn; |
||||
import com.apside.assistDbBackend.model.InfoTable; |
||||
import com.apside.assistDbBackend.model.LinkInfo; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.Mock; |
||||
import org.mockito.MockitoAnnotations; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
|
||||
import static org.mockito.Mockito.*; |
||||
|
||||
@ExtendWith(MockitoExtension.class) |
||||
class ResetDataServiceTest { |
||||
|
||||
@Mock |
||||
private InfoTableService infoTableService; |
||||
|
||||
@Mock |
||||
private InfoColumnService infoColumnService; |
||||
|
||||
@Mock |
||||
private LinkInfoService linkInfoService; |
||||
private ResetDataService resetDataService; |
||||
|
||||
@BeforeEach |
||||
void setUp() throws IOException { |
||||
MockitoAnnotations.openMocks(this); |
||||
resetDataService = new ResetDataService(); |
||||
resetDataService.setInfoTableService(infoTableService); |
||||
resetDataService.setInfoColumnService(infoColumnService); |
||||
resetDataService.setLinkInfoService(linkInfoService); |
||||
Path tempPath = Paths.get("src/test/resources/testDb.json"); |
||||
resetDataService.setPath(tempPath); |
||||
resetDataService.setResult(new String(Files.readAllBytes(tempPath))); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
void deleteEverything_shouldTruncateTables() { |
||||
// Arrange
|
||||
|
||||
// Act
|
||||
resetDataService.deleteEverything(); |
||||
|
||||
// Assert
|
||||
verify(infoColumnService, times(1)).truncateMyColumn(); |
||||
verify(infoTableService, times(1)).truncateMyTable(); |
||||
verify(linkInfoService, times(1)).truncateMyLink(); |
||||
} |
||||
|
||||
@Test |
||||
void insertEverything_shouldInsertData() throws IOException { |
||||
// Arrange
|
||||
// Act
|
||||
resetDataService.insertEverything(); |
||||
|
||||
// Assert
|
||||
verify(infoTableService, times(1)).addOrUpdateTable(any(InfoTable.class)); |
||||
verify(infoColumnService, times(1)).addOrUpdateColumn(any(InfoColumn.class)); |
||||
} |
||||
|
||||
@Test |
||||
void checkAndInsertLinks_shouldInsertLinks() throws IOException { |
||||
// Arrange
|
||||
when(infoColumnService.getSpecCol(anyString(), anyString(), anyInt(), anyString())) |
||||
.thenReturn(new InfoColumn(1L, "col1", "type1", 10, "coltext1")); // Mocking infoColumnService.getSpecCol()
|
||||
|
||||
// Act
|
||||
resetDataService.checkAndInsertLinks(); |
||||
|
||||
// Assert
|
||||
verify(linkInfoService, times(1)).addOrUpdateLink(any(LinkInfo.class)); |
||||
} |
||||
} |
Loading…
Reference in new issue