Add interface + resposnseEntity + check sonar

version_2
floxx2112 2 years ago
parent c37c5f15c8
commit e9347aaa9a
  1. 1
      .gitignore
  2. 12
      src/main/java/com/apside/assist/db/backend/AssistDBBackendApplication.java
  3. 111
      src/main/java/com/apside/assist/db/backend/controller/InfoColumnController.java
  4. 108
      src/main/java/com/apside/assist/db/backend/controller/InfoTableController.java
  5. 65
      src/main/java/com/apside/assist/db/backend/controller/LinkInfoController.java
  6. 32
      src/main/java/com/apside/assist/db/backend/controller/ResetDataController.java
  7. 88
      src/main/java/com/apside/assist/db/backend/controller/ScriptController.java
  8. 71
      src/main/java/com/apside/assist/db/backend/controller/TagsController.java
  9. 8
      src/main/java/com/apside/assist/db/backend/implementation/GitServiceImpl.java
  10. 19
      src/main/java/com/apside/assist/db/backend/implementation/InfoColumnServiceImpl.java
  11. 19
      src/main/java/com/apside/assist/db/backend/implementation/InfoTableServiceImpl.java
  12. 16
      src/main/java/com/apside/assist/db/backend/implementation/LinkInfoServiceImpl.java
  13. 22
      src/main/java/com/apside/assist/db/backend/implementation/ResetDataServiceImpl.java
  14. 35
      src/main/java/com/apside/assist/db/backend/implementation/ScriptsServiceImpl.java
  15. 18
      src/main/java/com/apside/assist/db/backend/implementation/TagsServiceImpl.java
  16. 2
      src/main/java/com/apside/assist/db/backend/model/InfoColumn.java
  17. 2
      src/main/java/com/apside/assist/db/backend/model/InfoTable.java
  18. 2
      src/main/java/com/apside/assist/db/backend/model/LinkInfo.java
  19. 4
      src/main/java/com/apside/assist/db/backend/model/LinkScriptTag.java
  20. 2
      src/main/java/com/apside/assist/db/backend/model/Script.java
  21. 2
      src/main/java/com/apside/assist/db/backend/model/Tag.java
  22. 4
      src/main/java/com/apside/assist/db/backend/repository/InfoColumnRepository.java
  23. 4
      src/main/java/com/apside/assist/db/backend/repository/InfoTableRepository.java
  24. 4
      src/main/java/com/apside/assist/db/backend/repository/LinkInfoRepository.java
  25. 25
      src/main/java/com/apside/assist/db/backend/service/GitService.java
  26. 88
      src/main/java/com/apside/assist/db/backend/service/InfoColumnService.java
  27. 71
      src/main/java/com/apside/assist/db/backend/service/InfoTableService.java
  28. 50
      src/main/java/com/apside/assist/db/backend/service/LinkInfoService.java
  29. 25
      src/main/java/com/apside/assist/db/backend/service/ResetDataService.java
  30. 86
      src/main/java/com/apside/assist/db/backend/service/ScriptsService.java
  31. 59
      src/main/java/com/apside/assist/db/backend/service/TagsService.java
  32. 80
      src/main/java/com/apside/assistDbBackend/controller/InfoColumnController.java
  33. 77
      src/main/java/com/apside/assistDbBackend/controller/InfoTableController.java
  34. 51
      src/main/java/com/apside/assistDbBackend/controller/LinkInfoController.java
  35. 25
      src/main/java/com/apside/assistDbBackend/controller/ResetDataController.java
  36. 59
      src/main/java/com/apside/assistDbBackend/controller/ScriptController.java
  37. 45
      src/main/java/com/apside/assistDbBackend/controller/TagsController.java
  38. 2
      src/test/java/com/apside/assist/db/backend/AssistDBBackendTest.java
  39. 6
      src/test/java/com/apside/assist/db/backend/repository/InfoColumnRepositoryTest.java
  40. 4
      src/test/java/com/apside/assist/db/backend/repository/InfoTableRepositoryTest.java
  41. 6
      src/test/java/com/apside/assist/db/backend/repository/LinkInfoRepositoryTest.java
  42. 0
      src/test/java/com/apside/assist/db/backend/service/GitServiceTest.java
  43. 12
      src/test/java/com/apside/assist/db/backend/service/InfoColumnServiceImplTest.java
  44. 30
      src/test/java/com/apside/assist/db/backend/service/InfoTableServiceImplTest.java
  45. 26
      src/test/java/com/apside/assist/db/backend/service/LinkInfoServiceImplTest.java
  46. 86
      src/test/java/com/apside/assist/db/backend/service/ResetDataServiceImplTest.java
  47. 79
      src/test/java/com/apside/assist/db/backend/service/ScriptsServiceImplTest.java
  48. 61
      src/test/java/com/apside/assist/db/backend/service/TagsServiceImplTest.java
  49. 82
      src/test/java/com/apside/assistDbBackend/service/ResetDataServiceTest.java

1
.gitignore vendored

@ -32,3 +32,4 @@ build/
### VS Code ###
.vscode/
src/main/resources/application.properties
src/main/resources/application.properties

@ -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);

@ -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,5 +1,6 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.implementation;
import com.apside.assist.db.backend.service.GitService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jgit.api.Git;
@ -17,13 +18,13 @@ import java.net.URISyntaxException;
@Data
@Service
@Slf4j
public class GitService {
public class GitServiceImpl implements GitService {
private final String tempDirectoryPath;
private UsernamePasswordCredentialsProvider userPass;
public GitService(){
public GitServiceImpl(){
tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "\\AssistDB_AdditionalFiles";
}
@Value("${USERNAME_GIT}")
@ -32,6 +33,7 @@ public class GitService {
@Value("${ACCESS_TOKEN_GIT}")
private String accesToken;
@Override
public void pushToGit() throws IOException, GitAPIException, URISyntaxException {
log.debug("Starting pushToGit method.");
try (Git git = Git.open(new File(tempDirectoryPath))){

@ -1,7 +1,8 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.implementation;
import com.apside.assistDbBackend.repository.InfoColumnRepository;
import com.apside.assistDbBackend.model.InfoColumn;
import com.apside.assist.db.backend.repository.InfoColumnRepository;
import com.apside.assist.db.backend.model.InfoColumn;
import com.apside.assist.db.backend.service.InfoColumnService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -13,55 +14,65 @@ import java.util.Optional;
@Data
@Service
@Slf4j
public class InfoColumnService {
public class InfoColumnServiceImpl implements InfoColumnService {
@Autowired
private InfoColumnRepository infoColumnRepository;
@Override
public Optional<InfoColumn> getColumn(final Long id) {
log.debug("Start GetColumn method - CRUD");
return infoColumnRepository.findById(id);
}
@Override
public Iterable<InfoColumn> getAllColumns() {
log.debug("Start GetAllColumns method - CRUD");
return infoColumnRepository.findAll();
}
@Override
public Iterable<InfoColumn> getSelectedColumns(String table, String schema) {
log.debug("Start GetSelectedColumn method - Custom");
return infoColumnRepository.getSelectedColumns(table, schema);
}
@Override
public Iterable<InfoColumn> getColumnsForJoin(String firstTable, String secondTable, String firstSchema, String secondSchema) {
log.debug("Start GetColumnForJoin method - Custom");
return infoColumnRepository.getColumnsForJoin(firstTable, secondTable, firstSchema, secondSchema);
}
@Override
public Iterable<InfoColumn> getColumnsForJoinTwo(List<String> tables, List<String> schemas) {
log.debug("Start GetColumnForJoinTwo method - Custom");
return infoColumnRepository.getColumnsForJoinTwo(tables, schemas);
}
@Override
public void deleteColumn(final Long id) {
log.debug("Start deleteColumn method - CRUD");
infoColumnRepository.deleteById(id);
}
@Override
public void deleteAllColumn() {
log.debug("Start deleteAllColumns method - CRUD");
infoColumnRepository.deleteAll();
}
@Override
public InfoColumn addOrUpdateColumn(InfoColumn infoColumn) {
log.debug("Start addOrUpdateColumn method - CRUD");
return infoColumnRepository.save(infoColumn);
}
@Override
public InfoColumn getSpecCol(String nameCol, String dataType, int lengthCol, String columnText){
log.debug("Start getSpecCol method - Custom");
return infoColumnRepository.getSpecColumn(nameCol, dataType, lengthCol, columnText);
}
@Override
public void truncateMyColumn(){
log.debug("Start truncateMyColumn method - Custom");
infoColumnRepository.truncateMyColumn();

@ -1,7 +1,8 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.implementation;
import com.apside.assistDbBackend.repository.InfoTableRepository;
import com.apside.assistDbBackend.model.InfoTable;
import com.apside.assist.db.backend.repository.InfoTableRepository;
import com.apside.assist.db.backend.model.InfoTable;
import com.apside.assist.db.backend.service.InfoTableService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -12,49 +13,59 @@ import java.util.Optional;
@Data
@Service
@Slf4j
public class InfoTableService {
public class InfoTableServiceImpl implements InfoTableService {
@Autowired
private InfoTableRepository infoTableRepository;
@Override
public Optional<InfoTable> getTable(final Long id) {
log.debug("Start getTable method - CRUD");
return infoTableRepository.findById(id);
}
@Override
public Iterable<InfoTable> getAllTables() {
log.debug("Start getAllTables method - CRUD");
return infoTableRepository.findAll();
}
@Override
public Iterable<InfoTable> getTablesBySchemaName(String schema) {
log.debug("Start getTableBySchemaName method - Custom");
return infoTableRepository.getTablesBySchemaName(schema);
}
@Override
public Iterable<InfoTable> getSchemaByTableName(String table) {
log.debug("Start getSchemaByTableName method - Custom");
return infoTableRepository.getSchemaByTableName(table);
}
@Override
public Iterable<String> getAllSchemas(){
log.debug("Start getAllSchemas method - CRUD");
return infoTableRepository.getAllSchemas();
}
@Override
public void deleteTable(final Long id) {
log.debug("Start deleteTable method - CRUD");
infoTableRepository.deleteById(id);
}
@Override
public void deleteAllTable() {
log.debug("Start deleteAllTable method - CRUD");
infoTableRepository.deleteAll();
}
@Override
public InfoTable addOrUpdateTable(InfoTable infoTable) {
log.debug("Start deleteAllTable method - CRUD");
return infoTableRepository.save(infoTable);
}
@Override
public void truncateMyTable(){
log.debug("Start truncateMyTable method - Custom");
infoTableRepository.truncateMyTable();

@ -1,7 +1,8 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.implementation;
import com.apside.assistDbBackend.model.LinkInfo;
import com.apside.assistDbBackend.repository.LinkInfoRepository;
import com.apside.assist.db.backend.model.LinkInfo;
import com.apside.assist.db.backend.repository.LinkInfoRepository;
import com.apside.assist.db.backend.service.LinkInfoService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -12,36 +13,41 @@ import java.util.Optional;
@Data
@Service
@Slf4j
public class LinkInfoService {
public class LinkInfoServiceImpl implements LinkInfoService {
@Autowired
private LinkInfoRepository linkInfoRepository;
@Override
public Optional<LinkInfo> getLinkInfo(final Long id) {
log.debug("Start getLinkInfo method - CRUD");
return linkInfoRepository.findById(id);
}
@Override
public Iterable<LinkInfo> getAllLinksInfos() {
log.debug("Start getAllLinksInfos method - CRUD");
return linkInfoRepository.findAll();
}
@Override
public void deleteLinkInfo(final Long id) {
log.debug("Start deleteLinkInfo method - CRUD");
linkInfoRepository.deleteById(id);
}
@Override
public void deleteAllLinks() {
log.debug("Start deleteAllLinks method - CRUD");
linkInfoRepository.deleteAll();
}
@Override
public LinkInfo addOrUpdateLink(LinkInfo linkInfo) {
log.debug("Start addOrUpdateLink method - CRUD");
return linkInfoRepository.save(linkInfo);
}
@Override
public void truncateMyLink(){
log.debug("Start truncateMyLink method - Custom");
linkInfoRepository.truncateMyLink();

@ -1,8 +1,12 @@
package com.apside.assistDbBackend.service;
import com.apside.assistDbBackend.model.LinkInfo;
import com.apside.assistDbBackend.model.InfoColumn;
import com.apside.assistDbBackend.model.InfoTable;
package com.apside.assist.db.backend.implementation;
import com.apside.assist.db.backend.model.LinkInfo;
import com.apside.assist.db.backend.model.InfoColumn;
import com.apside.assist.db.backend.model.InfoTable;
import com.apside.assist.db.backend.service.InfoColumnService;
import com.apside.assist.db.backend.service.InfoTableService;
import com.apside.assist.db.backend.service.LinkInfoService;
import com.apside.assist.db.backend.service.ResetDataService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONArray;
@ -18,7 +22,7 @@ import java.nio.file.Paths;
@Data
@Service
@Slf4j
public class ResetDataService {
public class ResetDataServiceImpl implements ResetDataService {
@Autowired
private InfoTableService infoTableService;
@ -36,7 +40,7 @@ public class ResetDataService {
private static final String LENGTH_STRING = "length";
private static final String COLUMN_TEXT_STRING = "column_text";
public ResetDataService() throws IOException {
public ResetDataServiceImpl() throws IOException {
path = Paths.get("src/main/resources/assistDbData.json");
result = new String(Files.readAllBytes(path));
}
@ -47,7 +51,7 @@ public class ResetDataService {
linkInfoService.truncateMyLink();
}
public void insertEverything() throws IOException {
public void insertEverything() {
log.debug("Start insert every data into DB");
JSONArray jo = new JSONArray(result);
for (int i=0; i<jo.length(); i++){
@ -121,7 +125,7 @@ public class ResetDataService {
log.info("Insert all data into DB - success");
}
public void checkAndInsertLinks() throws IOException {
public void checkAndInsertLinks() {
log.debug("Start check data into DB and insert links between table and columns");
JSONArray jo = new JSONArray(result);
for (int i=0; i<jo.length(); i++){

@ -1,11 +1,11 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.implementation;
import com.apside.assistDbBackend.model.LinkScriptTag;
import com.apside.assistDbBackend.model.Script;
import com.apside.assist.db.backend.model.LinkScriptTag;
import com.apside.assist.db.backend.model.Script;
import com.apside.assist.db.backend.service.GitService;
import com.apside.assist.db.backend.service.ScriptsService;
import lombok.Data;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.apache.log4j.Logger;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.json.JSONArray;
import org.json.JSONObject;
@ -14,7 +14,6 @@ import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileWriter;
import java.io.IOError;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
@ -22,10 +21,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
@Data
@Service
@Data
@Slf4j
public class ScriptsService {
public class ScriptsServiceImpl implements ScriptsService {
@Autowired
private GitService gitService;
private String linkScriptTagPath;
@ -45,19 +44,21 @@ public class ScriptsService {
private static final String TAGS_STRING = "tags";
private static final String DATA_STRING = "data";
public ScriptsService() {
public ScriptsServiceImpl() {
linkScriptTagPath = new File(System.getProperty(USER_DIR_STRING)).getParent() + "/AssistDB_AdditionalFiles/scripts.json";
pathOfLink = Paths.get(linkScriptTagPath);
tempDirectoryPath = new File(System.getProperty(USER_DIR_STRING)).getParent() + PATH_TO_SCRIPT_DIR;
scriptDirectory = new File(tempDirectoryPath);
}
private void initialize() throws IOException {
@Override
public void initialize() throws IOException {
allScriptsContent = new String((Files.readAllBytes(pathOfLink)));
dataGlobalScripts = new JSONObject(allScriptsContent);
dataLinkScriptsTags = dataGlobalScripts.getJSONArray(DATA_STRING);
}
@Override
public List<Script> retrieveScripts() throws IOException, GitAPIException {
log.debug("Start retrieve all scripts");
gitService.pullFromGit();
@ -75,6 +76,7 @@ public class ScriptsService {
return listOfScripts;
}
@Override
public List<LinkScriptTag> getAllScriptTag() throws IOException {
log.debug("Start retrieve all links scripts/tags");
initialize();
@ -100,11 +102,12 @@ public class ScriptsService {
return listLinkScriptTag;
}
@Override
public void deleteOneScript(final String name){
log.debug("Start delete one script with Git");
try {
File scriptDirectory = new File(tempDirectoryPath + "/" + name);
scriptDirectory.delete();
File scriptDirectoryToDelete = new File(tempDirectoryPath + "/" + name);
scriptDirectoryToDelete.delete();
gitService.pushToGit();
gitService.pullFromGit();
log.info("Delete one Script successful");
@ -114,11 +117,12 @@ public class ScriptsService {
}
}
@Override
public void simpleDeleteScript(final String name){
log.debug("Start delete one script without Git");
try {
File scriptDirectory = new File(tempDirectoryPath + "/" + name);
scriptDirectory.delete();
File scriptDirectoryToSimpleDelete = new File(tempDirectoryPath + "/" + name);
scriptDirectoryToSimpleDelete.delete();
log.info("Delete one Script successful");
} catch (Exception e){
e.printStackTrace();
@ -126,6 +130,7 @@ public class ScriptsService {
}
}
@Override
public void addOneScript(final String content, final String name) throws IOException {
log.debug("Start add one scripts");
File newFile = new File(tempDirectoryPath + "/" + name);
@ -139,6 +144,7 @@ public class ScriptsService {
}
}
@Override
public void addOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException {
log.debug("Start add one link between script and tags");
initialize();
@ -161,6 +167,7 @@ public class ScriptsService {
log.info("Add one link successful");
}
@Override
public void updateOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException {
log.debug("Start update one link between script and tags");
initialize();

@ -1,6 +1,8 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.implementation;
import com.apside.assistDbBackend.model.Tag;
import com.apside.assist.db.backend.model.Tag;
import com.apside.assist.db.backend.service.GitService;
import com.apside.assist.db.backend.service.TagsService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jgit.api.errors.GitAPIException;
@ -21,7 +23,7 @@ import java.util.Objects;
@Data
@Service
@Slf4j
public class TagsService {
public class TagsServiceImpl implements TagsService {
@Autowired
private GitService gitService;
private String tempDirectoryPath;
@ -33,17 +35,19 @@ public class TagsService {
private static final String DATA_STRING = "data";
private static final String TAG_STRING = "tag";
private static final String DESCRIPTION_STRING = "description";
public TagsService() {
public TagsServiceImpl() {
tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "/AssistDB_AdditionalFiles/tags.json";
path = Paths.get(tempDirectoryPath);
}
private void initialize() throws IOException {
@Override
public void initialize() throws IOException {
jsonContent = new String(Files.readAllBytes(path));
dataGlobal = new JSONObject(jsonContent);
data = dataGlobal.getJSONArray(DATA_STRING);
}
@Override
public List<Tag> getAllTags() throws IOException, GitAPIException {
log.debug("Start get all tags from json");
gitService.pullFromGit();
@ -61,6 +65,7 @@ public class TagsService {
return listOfTag;
}
@Override
public void deleteTag(final String deleteNameTag) throws IOException, GitAPIException, URISyntaxException {
log.debug("Start delete one tag in json");
initialize();
@ -79,6 +84,7 @@ public class TagsService {
log.info("Delete one tag in json file successful");
}
@Override
public void addTag(Tag tag) throws IOException, GitAPIException, URISyntaxException {
log.debug("Start add one tag in json");
initialize();
@ -94,6 +100,8 @@ public class TagsService {
gitService.pullFromGit();
log.info("Delete one tag in json successful");
}
@Override
public void updateTag(final String prevTag, Tag modTag) throws IOException, GitAPIException, URISyntaxException {
log.debug("Start update one tag in json");
initialize();

@ -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;
@ -14,7 +14,7 @@ public class LinkScriptTag {
private List<String> tags;
public void LinkScriptTag(){}
public LinkScriptTag(){}
public LinkScriptTag(int id, String scriptName, String description, List<String> tags){
this.id = id;

@ -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 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 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;

@ -1,8 +1,8 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.service;
import com.apside.assistDbBackend.model.InfoColumn;
import com.apside.assistDbBackend.repository.InfoColumnRepository;
import org.junit.Assert;
import com.apside.assist.db.backend.implementation.InfoColumnServiceImpl;
import com.apside.assist.db.backend.repository.InfoColumnRepository;
import com.apside.assist.db.backend.model.InfoColumn;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@ -19,11 +19,11 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class InfoColumnServiceTest {
class InfoColumnServiceImplTest {
@Mock
private InfoColumnRepository infoColumnRepository;
@InjectMocks
private InfoColumnService underTest;
private InfoColumnServiceImpl underTest;
@Test

@ -1,8 +1,8 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.service;
import com.apside.assistDbBackend.model.InfoColumn;
import com.apside.assistDbBackend.model.InfoTable;
import com.apside.assistDbBackend.repository.InfoTableRepository;
import com.apside.assist.db.backend.implementation.InfoTableServiceImpl;
import com.apside.assist.db.backend.model.InfoTable;
import com.apside.assist.db.backend.repository.InfoTableRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@ -19,13 +19,13 @@ import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class InfoTableServiceTest {
class InfoTableServiceImplTest {
@Mock
private InfoTableRepository infoTableRepository;
@InjectMocks
private InfoTableService infoTableService;
private InfoTableServiceImpl infoTableServiceImpl;
@Test
void testGetTable() {
@ -37,7 +37,7 @@ class InfoTableServiceTest {
);
Long id = 1L;
when(infoTableRepository.findById(id)).thenReturn(Optional.of(infoTable));
Optional<InfoTable> result = infoTableService.getTable(id);
Optional<InfoTable> result = infoTableServiceImpl.getTable(id);
assertTrue(result.isPresent());
assertEquals(infoTable, result.get());
}
@ -47,7 +47,7 @@ class InfoTableServiceTest {
List<InfoTable> res = new ArrayList<>();
res.add(new InfoTable());
when(infoTableRepository.findAll()).thenReturn(res);
Iterable<InfoTable> expected = infoTableService.getAllTables();
Iterable<InfoTable> expected = infoTableServiceImpl.getAllTables();
assertEquals(expected, res);
}
@ -70,7 +70,7 @@ class InfoTableServiceTest {
when(infoTableRepository.getTablesBySchemaName(schemaName)).thenReturn(infoTables);
// When
Iterable<InfoTable> result = infoTableService.getTablesBySchemaName(schemaName);
Iterable<InfoTable> result = infoTableServiceImpl.getTablesBySchemaName(schemaName);
// Then
assertNotNull(result);
@ -97,7 +97,7 @@ class InfoTableServiceTest {
when(infoTableRepository.getSchemaByTableName(tableName)).thenReturn(infoTables);
// When
Iterable<InfoTable> result = infoTableService.getSchemaByTableName(tableName);
Iterable<InfoTable> result = infoTableServiceImpl.getSchemaByTableName(tableName);
// Then
assertNotNull(result);
@ -110,7 +110,7 @@ class InfoTableServiceTest {
void testGetAllSchemas() {
List<String> schemasList = Arrays.asList(new String("shcemaOne"), new String("schemaTwo"));
when(infoTableRepository.getAllSchemas()).thenReturn(schemasList);
Iterable<String> expectedAllSchemas = infoTableService.getAllSchemas();
Iterable<String> expectedAllSchemas = infoTableServiceImpl.getAllSchemas();
assertEquals(expectedAllSchemas, schemasList);
}
@ -118,14 +118,14 @@ class InfoTableServiceTest {
void testDeleteTable() {
Long id = 1L;
infoTableService.deleteTable(id);
infoTableServiceImpl.deleteTable(id);
verify(infoTableRepository, times(1)).deleteById(id);
}
@Test
void testDeleteAllTable() {
infoTableService.deleteAllTable();
infoTableServiceImpl.deleteAllTable();
verify(infoTableRepository, times(1)).deleteAll();
}
@ -140,7 +140,7 @@ class InfoTableServiceTest {
// When
when(infoTableRepository.save(infoTable)).thenReturn(infoTable);
InfoTable savedInfoTable = infoTableService.addOrUpdateTable(infoTable);
InfoTable savedInfoTable = infoTableServiceImpl.addOrUpdateTable(infoTable);
// Then
verify(infoTableRepository, times(1)).save(infoTable);
@ -150,7 +150,7 @@ class InfoTableServiceTest {
@Test
void testTruncateMyTable() {
infoTableService.truncateMyTable();
infoTableServiceImpl.truncateMyTable();
verify(infoTableRepository, times(1)).truncateMyTable();
}

@ -1,10 +1,8 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.service;
import com.apside.assistDbBackend.model.InfoColumn;
import com.apside.assistDbBackend.model.InfoTable;
import com.apside.assistDbBackend.model.LinkInfo;
import com.apside.assistDbBackend.repository.LinkInfoRepository;
import org.junit.jupiter.api.Assertions;
import com.apside.assist.db.backend.implementation.LinkInfoServiceImpl;
import com.apside.assist.db.backend.repository.LinkInfoRepository;
import com.apside.assist.db.backend.model.LinkInfo;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@ -20,12 +18,12 @@ import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class LinkInfoServiceTest {
class LinkInfoServiceImplTest {
@Mock
private LinkInfoRepository linkInfoRepository;
@InjectMocks
private LinkInfoService linkInfoService;
private LinkInfoServiceImpl linkInfoServiceImpl;
@Test
void testGetLinkInfo() {
@ -37,7 +35,7 @@ class LinkInfoServiceTest {
);
Long id = 1L;
when(linkInfoRepository.findById(id)).thenReturn(Optional.of(linkInfo));
Optional<LinkInfo> result = linkInfoService.getLinkInfo(id);
Optional<LinkInfo> result = linkInfoServiceImpl.getLinkInfo(id);
assertTrue(result.isPresent());
assertEquals(linkInfo, result.get());
}
@ -47,7 +45,7 @@ class LinkInfoServiceTest {
List<LinkInfo> res = new ArrayList<>();
res.add(new LinkInfo());
when(linkInfoRepository.findAll()).thenReturn(res);
Iterable<LinkInfo> expected = linkInfoService.getAllLinksInfos();
Iterable<LinkInfo> expected = linkInfoServiceImpl.getAllLinksInfos();
assertEquals(expected, res);
}
@ -56,14 +54,14 @@ class LinkInfoServiceTest {
void testDeleteLinkInfo() {
Long id = 1L;
linkInfoService.deleteLinkInfo(id);
linkInfoServiceImpl.deleteLinkInfo(id);
verify(linkInfoRepository, times(1)).deleteById(id);
}
@Test
void testDeleteAllLinks() {
linkInfoService.deleteAllLinks();
linkInfoServiceImpl.deleteAllLinks();
verify(linkInfoRepository, times(1)).deleteAll();
}
@ -79,7 +77,7 @@ class LinkInfoServiceTest {
// When
when(linkInfoRepository.save(linkInfo)).thenReturn(linkInfo);
LinkInfo savedLinkInfo = linkInfoService.addOrUpdateLink(linkInfo);
LinkInfo savedLinkInfo = linkInfoServiceImpl.addOrUpdateLink(linkInfo);
// Then
verify(linkInfoRepository, times(1)).save(linkInfo);
@ -89,7 +87,7 @@ class LinkInfoServiceTest {
@Test
void testTruncateMyLink() {
linkInfoService.truncateMyLink();
linkInfoServiceImpl.truncateMyLink();
verify(linkInfoRepository, times(1)).truncateMyLink();
}

@ -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,7 +1,9 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.service;
import com.apside.assistDbBackend.model.LinkScriptTag;
import com.apside.assistDbBackend.model.Script;
import com.apside.assist.db.backend.implementation.GitServiceImpl;
import com.apside.assist.db.backend.implementation.ScriptsServiceImpl;
import com.apside.assist.db.backend.model.LinkScriptTag;
import com.apside.assist.db.backend.model.Script;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.json.JSONArray;
import org.json.JSONObject;
@ -10,7 +12,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
@ -28,12 +29,12 @@ import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class ScriptsServiceTest {
class ScriptsServiceImplTest {
@Mock
private GitService gitService;
private GitServiceImpl gitServiceImpl;
@InjectMocks
private ScriptsService scriptsService;
private ScriptsServiceImpl scriptsServiceImpl;
private Path tempDirectoryPathJson;
private String jsonContent;
@ -48,27 +49,27 @@ class ScriptsServiceTest {
@BeforeEach
void setUp() throws IOException {
MockitoAnnotations.openMocks(this);
scriptsService = new ScriptsService();
scriptsServiceImpl = new ScriptsServiceImpl();
tempDirectoryPathJson = Paths.get("src/test/resources/scripts.json");
scriptsService.setPathOfLink(tempDirectoryPathJson);
scriptsServiceImpl.setPathOfLink(tempDirectoryPathJson);
jsonContent = "{\"data\":[{\"filename\":\"test.txt\", \"description\":\"Description test\", \"id\":1, \"tags\":[{\"tagname\":\"TXT\"}]}, {\"filename\":\"test2.txt\", \"description\":\"Description test2\", \"id\":2, \"tags\":[{\"tagname\":\"JOIN\"}]}]}";
Files.write(tempDirectoryPathJson, jsonContent.getBytes());
dataGlobal = new JSONObject(jsonContent);
data = dataGlobal.getJSONArray("data");
scriptsService.setDataLinkScriptsTags(data);
scriptsServiceImpl.setDataLinkScriptsTags(data);
tempDirectoryPath = new File("src/test/resources/scriptsTest").toString();
scriptDirectory = new File(tempDirectoryPath);
scriptsService.setTempDirectoryPath(tempDirectoryPath);
scriptsService.setScriptDirectory(scriptDirectory);
scriptsServiceImpl.setTempDirectoryPath(tempDirectoryPath);
scriptsServiceImpl.setScriptDirectory(scriptDirectory);
}
@Test
void retrieveScripts() throws GitAPIException, IOException {
// mock git service
doNothing().when(gitService).pullFromGit();
scriptsService.setGitService(gitService);
doNothing().when(gitServiceImpl).pullFromGit();
scriptsServiceImpl.setGitService(gitServiceImpl);
// create temp directory for test
String scriptContent1 = "Script 1 content";
@ -81,9 +82,9 @@ class ScriptsServiceTest {
Files.writeString(filePath2, scriptContent2);
// Act
List<Script> result = scriptsService.retrieveScripts();
List<Script> result = scriptsServiceImpl.retrieveScripts();
verify(gitService, times(1)).pullFromGit();
verify(gitServiceImpl, times(1)).pullFromGit();
assertEquals(2, result.size());
assertEquals("sql", result.get(0).getExtension());
assertEquals("script1.sql", result.get(0).getName());
@ -109,7 +110,7 @@ class ScriptsServiceTest {
expectedTags.add(tag2);
// Act
List<LinkScriptTag> result = scriptsService.getAllScriptTag();
List<LinkScriptTag> result = scriptsServiceImpl.getAllScriptTag();
// Assert
assertEquals(expectedTags, result);
@ -127,17 +128,17 @@ class ScriptsServiceTest {
if (!scriptFile.exists()) {
scriptFile.createNewFile();
}
doNothing().when(gitService).pushToGit();
doNothing().when(gitService).pullFromGit();
scriptsService.setGitService(gitService);
doNothing().when(gitServiceImpl).pushToGit();
doNothing().when(gitServiceImpl).pullFromGit();
scriptsServiceImpl.setGitService(gitServiceImpl);
// Act
scriptsService.deleteOneScript(scriptName);
scriptsServiceImpl.deleteOneScript(scriptName);
// Assert
assertFalse(scriptFile.exists());
verify(gitService, times(1)).pushToGit();
verify(gitService, times(1)).pullFromGit();
verify(gitServiceImpl, times(1)).pushToGit();
verify(gitServiceImpl, times(1)).pullFromGit();
}
@Test
@ -153,7 +154,7 @@ class ScriptsServiceTest {
}
// Act
scriptsService.simpleDeleteScript(scriptName);
scriptsServiceImpl.simpleDeleteScript(scriptName);
// Assert
assertFalse(scriptFile.exists());
@ -173,7 +174,7 @@ class ScriptsServiceTest {
}
// Act
scriptsService.addOneScript(content, name);
scriptsServiceImpl.addOneScript(content, name);
// Assert
assertTrue(scriptFile.exists());
@ -190,14 +191,14 @@ class ScriptsServiceTest {
String description = "New script";
List<String> tagList = Arrays.asList("TAG1", "TAG2");
int linkId = 3;
doNothing().when(gitService).pullFromGit();
doNothing().when(gitService).pushToGit();
scriptsService.setGitService(gitService);
doNothing().when(gitServiceImpl).pullFromGit();
doNothing().when(gitServiceImpl).pushToGit();
scriptsServiceImpl.setGitService(gitServiceImpl);
scriptsService.addOneLink(name, description, tagList, linkId);
scriptsServiceImpl.addOneLink(name, description, tagList, linkId);
// Assert
JSONArray updatedDataLinkScriptsTags = scriptsService.getDataLinkScriptsTags();
JSONArray updatedDataLinkScriptsTags = scriptsServiceImpl.getDataLinkScriptsTags();
assertEquals(3, updatedDataLinkScriptsTags.length());
JSONObject newLink = updatedDataLinkScriptsTags.getJSONObject(2);
@ -210,8 +211,8 @@ class ScriptsServiceTest {
assertEquals("TAG1", tagObj1.getString("tagname"));
JSONObject tagObj2 = newTags.getJSONObject(1);
assertEquals("TAG2", tagObj2.getString("tagname"));
verify(gitService, times(1)).pullFromGit();
verify(gitService, times(1)).pushToGit();
verify(gitServiceImpl, times(1)).pullFromGit();
verify(gitServiceImpl, times(1)).pushToGit();
}
@Test
@ -223,14 +224,14 @@ class ScriptsServiceTest {
int linkId = 2;
//scriptsService.setDataLinkScriptsTags(dataLinkScriptsTags);
doNothing().when(gitService).pullFromGit();
doNothing().when(gitService).pushToGit();
scriptsService.setGitService(gitService);
doNothing().when(gitServiceImpl).pullFromGit();
doNothing().when(gitServiceImpl).pushToGit();
scriptsServiceImpl.setGitService(gitServiceImpl);
// Act
scriptsService.updateOneLink(name, description, tagList, linkId);
scriptsServiceImpl.updateOneLink(name, description, tagList, linkId);
// Assert
JSONObject dataGlob = scriptsService.getDataGlobalScripts();
JSONObject dataGlob = scriptsServiceImpl.getDataGlobalScripts();
JSONArray updatedDataLinkScriptsTags = dataGlob.getJSONArray("data");
assertEquals(2, updatedDataLinkScriptsTags.length());
JSONObject updatedLink = updatedDataLinkScriptsTags.getJSONObject(1);
@ -245,7 +246,7 @@ class ScriptsServiceTest {
assertEquals("TAG1", tagObj1.getString("tagname"));
JSONObject tagObj2 = updatedTags.getJSONObject(1);
assertEquals("TAG3", tagObj2.getString("tagname"));
verify(gitService, times(1)).pullFromGit();
verify(gitService, times(1)).pushToGit();
verify(gitServiceImpl, times(1)).pullFromGit();
verify(gitServiceImpl, times(1)).pushToGit();
}
}

@ -1,6 +1,8 @@
package com.apside.assistDbBackend.service;
package com.apside.assist.db.backend.service;
import com.apside.assistDbBackend.model.Tag;
import com.apside.assist.db.backend.implementation.GitServiceImpl;
import com.apside.assist.db.backend.implementation.TagsServiceImpl;
import com.apside.assist.db.backend.model.Tag;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.json.JSONArray;
import org.json.JSONObject;
@ -18,19 +20,18 @@ import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class TagsServiceTest {
class TagsServiceImplTest {
@Mock
private GitService gitService;
private GitServiceImpl gitServiceImpl;
@InjectMocks
private TagsService tagsService;
private TagsServiceImpl tagsServiceImpl;
private Path tempDirectoryPath;
private String jsonContent;
@ -43,9 +44,9 @@ class TagsServiceTest {
@BeforeEach
void setUp() throws IOException {
MockitoAnnotations.openMocks(this);
tagsService = new TagsService();
tagsServiceImpl = new TagsServiceImpl();
tempDirectoryPath = Paths.get("src/test/resources/tagtest.json");
tagsService.setPath(tempDirectoryPath);
tagsServiceImpl.setPath(tempDirectoryPath);
jsonContent = "{\"data\":[{\"tagId\":1, \"description\":\"Description 1\", \"tag\":\"Tag1\"},{\"tagId\":2, \"description\":\"Description 2\", \"tag\":\"Tag2\",}]}";
Files.write(tempDirectoryPath, jsonContent.getBytes());
dataGlobal = new JSONObject(jsonContent);
@ -57,14 +58,14 @@ class TagsServiceTest {
@Order(1)
void getAllTags_shouldReturnListOfTags() throws IOException, GitAPIException {
// Arrange
doNothing().when(gitService).pullFromGit();
tagsService.setGitService(gitService);
doNothing().when(gitServiceImpl).pullFromGit();
tagsServiceImpl.setGitService(gitServiceImpl);
// Act
List<Tag> result = tagsService.getAllTags();
List<Tag> result = tagsServiceImpl.getAllTags();
// Assert
verify(gitService, times(1)).pullFromGit();
verify(gitServiceImpl, times(1)).pullFromGit();
assertEquals(2, result.size());
assertEquals(1, result.get(0).getTagId());
assertEquals("Tag1", result.get(0).getNameTag());
@ -78,16 +79,16 @@ class TagsServiceTest {
@Order(2)
void deleteTag_shouldDeleteTag() throws IOException, GitAPIException, URISyntaxException {
// Arrange
doNothing().when(gitService).pullFromGit();
doNothing().when(gitService).pushToGit();
tagsService.setGitService(gitService);
doNothing().when(gitServiceImpl).pullFromGit();
doNothing().when(gitServiceImpl).pushToGit();
tagsServiceImpl.setGitService(gitServiceImpl);
// Act
tagsService.deleteTag("Tag1");
tagsServiceImpl.deleteTag("Tag1");
// Assert
verify(gitService, times(1)).pullFromGit();
verify(gitService, times(1)).pushToGit();
verify(gitServiceImpl, times(1)).pullFromGit();
verify(gitServiceImpl, times(1)).pushToGit();
String updatedJsonContent = new String(Files.readAllBytes(tempDirectoryPath));
JSONObject updatedDataGlobal = new JSONObject(updatedJsonContent);
@ -103,18 +104,18 @@ class TagsServiceTest {
@Test
void addTag_shouldAddTag() throws IOException, GitAPIException, URISyntaxException {
// Arrange
doNothing().when(gitService).pullFromGit();
doNothing().when(gitService).pushToGit();
tagsService.setGitService(gitService);
doNothing().when(gitServiceImpl).pullFromGit();
doNothing().when(gitServiceImpl).pushToGit();
tagsServiceImpl.setGitService(gitServiceImpl);
Tag newTag = new Tag(3, "Tag3", "Description 3");
// Act
tagsService.addTag(newTag);
tagsServiceImpl.addTag(newTag);
// Assert
verify(gitService, times(2)).pullFromGit();
verify(gitService, times(1)).pushToGit();
verify(gitServiceImpl, times(2)).pullFromGit();
verify(gitServiceImpl, times(1)).pushToGit();
String updatedJsonContent = new String(Files.readAllBytes(tempDirectoryPath));
JSONObject updatedDataGlobal = new JSONObject(updatedJsonContent);
@ -130,18 +131,18 @@ class TagsServiceTest {
@Test
void updateTag_shouldUpdateTag() throws IOException, GitAPIException, URISyntaxException {
// Arrange
doNothing().when(gitService).pullFromGit();
doNothing().when(gitService).pushToGit();
tagsService.setGitService(gitService);
doNothing().when(gitServiceImpl).pullFromGit();
doNothing().when(gitServiceImpl).pushToGit();
tagsServiceImpl.setGitService(gitServiceImpl);
Tag modifiedTag = new Tag(2, "ModifiedTag", "ModifiedDescription");
// Act
tagsService.updateTag("Tag2", modifiedTag);
tagsServiceImpl.updateTag("Tag2", modifiedTag);
// Assert
verify(gitService, times(2)).pullFromGit();
verify(gitService, times(1)).pushToGit();
verify(gitServiceImpl, times(2)).pullFromGit();
verify(gitServiceImpl, times(1)).pushToGit();
String updatedJsonContent = new String(Files.readAllBytes(tempDirectoryPath));
JSONObject updatedDataGlobal = new JSONObject(updatedJsonContent);

@ -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…
Cancel
Save