add loggers

version_2
floxx2112 2 years ago
parent 951904394b
commit c37c5f15c8
  1. 5
      pom.xml
  2. 9
      src/main/java/com/apside/assistDbBackend/controller/InfoColumnController.java
  3. 10
      src/main/java/com/apside/assistDbBackend/controller/InfoTableController.java
  4. 11
      src/main/java/com/apside/assistDbBackend/controller/LinkInfoController.java
  5. 3
      src/main/java/com/apside/assistDbBackend/controller/ResetDataController.java
  6. 8
      src/main/java/com/apside/assistDbBackend/controller/ScriptController.java
  7. 6
      src/main/java/com/apside/assistDbBackend/controller/TagsController.java
  8. 13
      src/main/java/com/apside/assistDbBackend/service/GitService.java
  9. 12
      src/main/java/com/apside/assistDbBackend/service/InfoColumnService.java
  10. 15
      src/main/java/com/apside/assistDbBackend/service/InfoTableService.java
  11. 8
      src/main/java/com/apside/assistDbBackend/service/LinkInfoService.java
  12. 6
      src/main/java/com/apside/assistDbBackend/service/ResetDataService.java
  13. 28
      src/main/java/com/apside/assistDbBackend/service/ScriptsService.java
  14. 12
      src/main/java/com/apside/assistDbBackend/service/TagsService.java
  15. 2
      src/main/resources/application.properties
  16. 15
      src/main/resources/log4j.properties

@ -92,6 +92,11 @@
<version>3.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>

@ -2,6 +2,7 @@ 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.*;
@ -12,6 +13,7 @@ import java.util.Optional;
@RestController
@RequestMapping("/api")
@Slf4j
public class InfoColumnController {
@Autowired
private InfoColumnService infoColumnService;
@ -23,6 +25,7 @@ public class InfoColumnController {
*/
@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();
@ -37,6 +40,7 @@ public class InfoColumnController {
*/
@GetMapping("/columns/all")
public Iterable<InfoColumn> getColumns() {
log.debug("Start getColumns - Get Request");
return infoColumnService.getAllColumns();
}
@ -46,16 +50,20 @@ public class InfoColumnController {
*/
@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);
@ -63,6 +71,7 @@ public class InfoColumnController {
@DeleteMapping("/columns/deleteAll")
public void deleteAllColumns() {
log.debug("DeleteAllColumns called");
infoColumnService.deleteAllColumn();
}

@ -2,13 +2,16 @@ 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;
@ -21,6 +24,7 @@ public class InfoTableController {
*/
@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();
@ -44,6 +48,7 @@ public class InfoTableController {
*/
@GetMapping("/schemas/all")
public Iterable<String> getSchemas() {
log.debug("Start getSchemas - Get Request");
return infoTableService.getAllSchemas();
}
@ -52,17 +57,20 @@ public class InfoTableController {
* @return - An Iterable object of InfoTable full filled
*/
@GetMapping("/tables/{schema}")
public Iterable<InfoTable> getTables(@PathVariable("schema") final String 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();
}

@ -2,13 +2,15 @@ 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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
@RestController
@RequestMapping("/api")
@Slf4j
public class LinkInfoController {
@Autowired
@ -22,6 +24,7 @@ public class LinkInfoController {
*/
@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();
@ -36,11 +39,13 @@ public class LinkInfoController {
*/
@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();
}
}

@ -3,11 +3,13 @@ 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;
@ -15,6 +17,7 @@ public class ResetDataController {
@PostMapping("/reset")
public void resetData() throws IOException {
log.debug("ResetData called");
resetDataService.deleteEverything();
resetDataService.insertEverything();
resetDataService.checkAndInsertLinks();

@ -3,8 +3,10 @@ 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;
@ -13,34 +15,40 @@ 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);

@ -2,6 +2,7 @@ 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.*;
@ -12,6 +13,7 @@ import java.util.List;
@RestController
@RequestMapping("/api")
@Slf4j
public class TagsController {
@Autowired
@ -19,21 +21,25 @@ public class TagsController {
@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,6 +1,7 @@
package com.apside.assistDbBackend.service;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.RemoteAddCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
@ -15,6 +16,7 @@ import java.net.URISyntaxException;
@Data
@Service
@Slf4j
public class GitService {
private final String tempDirectoryPath;
@ -31,6 +33,7 @@ public class GitService {
private String accesToken;
public void pushToGit() throws IOException, GitAPIException, URISyntaxException {
log.debug("Starting pushToGit method.");
try (Git git = Git.open(new File(tempDirectoryPath))){
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
@ -45,12 +48,22 @@ public class GitService {
userPass = new UsernamePasswordCredentialsProvider(userGit, accesToken);
git.push().setCredentialsProvider(userPass).call();
log.info("Push to Git successful.");
} catch (IOException|GitAPIException exception){
log.error("Error push from git", exception);
throw exception;
}
}
public void pullFromGit() throws IOException, GitAPIException {
log.debug("Starting pullFromGit method.");
try (Git git = Git.open(new File(tempDirectoryPath))){
git.pull().setCredentialsProvider(new UsernamePasswordCredentialsProvider(userGit, accesToken)).setRemote("origin").setRemoteBranchName("main").call();
log.info("Pull from Git successful.");
} catch (IOException|GitAPIException exception){
log.error("Error push from git", exception);
throw exception;
}
}

@ -3,6 +3,7 @@ package com.apside.assistDbBackend.service;
import com.apside.assistDbBackend.repository.InfoColumnRepository;
import com.apside.assistDbBackend.model.InfoColumn;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -11,47 +12,58 @@ import java.util.Optional;
@Data
@Service
@Slf4j
public class InfoColumnService {
@Autowired
private InfoColumnRepository infoColumnRepository;
public Optional<InfoColumn> getColumn(final Long id) {
log.debug("Start GetColumn method - CRUD");
return infoColumnRepository.findById(id);
}
public Iterable<InfoColumn> getAllColumns() {
log.debug("Start GetAllColumns method - CRUD");
return infoColumnRepository.findAll();
}
public Iterable<InfoColumn> getSelectedColumns(String table, String schema) {
log.debug("Start GetSelectedColumn method - Custom");
return infoColumnRepository.getSelectedColumns(table, schema);
}
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);
}
public Iterable<InfoColumn> getColumnsForJoinTwo(List<String> tables, List<String> schemas) {
log.debug("Start GetColumnForJoinTwo method - Custom");
return infoColumnRepository.getColumnsForJoinTwo(tables, schemas);
}
public void deleteColumn(final Long id) {
log.debug("Start deleteColumn method - CRUD");
infoColumnRepository.deleteById(id);
}
public void deleteAllColumn() {
log.debug("Start deleteAllColumns method - CRUD");
infoColumnRepository.deleteAll();
}
public InfoColumn addOrUpdateColumn(InfoColumn infoColumn) {
log.debug("Start addOrUpdateColumn method - CRUD");
return infoColumnRepository.save(infoColumn);
}
public InfoColumn getSpecCol(String nameCol, String dataType, int lengthCol, String columnText){
log.debug("Start getSpecCol method - Custom");
return infoColumnRepository.getSpecColumn(nameCol, dataType, lengthCol, columnText);
}
public void truncateMyColumn(){
log.debug("Start truncateMyColumn method - Custom");
infoColumnRepository.truncateMyColumn();
}
}

@ -3,6 +3,7 @@ package com.apside.assistDbBackend.service;
import com.apside.assistDbBackend.repository.InfoTableRepository;
import com.apside.assistDbBackend.model.InfoTable;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -10,40 +11,52 @@ import java.util.Optional;
@Data
@Service
@Slf4j
public class InfoTableService {
@Autowired
private InfoTableRepository infoTableRepository;
public Optional<InfoTable> getTable(final Long id) {
log.debug("Start getTable method - CRUD");
return infoTableRepository.findById(id);
}
public Iterable<InfoTable> getAllTables() {
log.debug("Start getAllTables method - CRUD");
return infoTableRepository.findAll();
}
public Iterable<InfoTable> getTablesBySchemaName(String schema) {
log.debug("Start getTableBySchemaName method - Custom");
return infoTableRepository.getTablesBySchemaName(schema);
}
public Iterable<InfoTable> getSchemaByTableName(String table) {
log.debug("Start getSchemaByTableName method - Custom");
return infoTableRepository.getSchemaByTableName(table);
}
public Iterable<String> getAllSchemas(){return infoTableRepository.getAllSchemas();}
public Iterable<String> getAllSchemas(){
log.debug("Start getAllSchemas method - CRUD");
return infoTableRepository.getAllSchemas();
}
public void deleteTable(final Long id) {
log.debug("Start deleteTable method - CRUD");
infoTableRepository.deleteById(id);
}
public void deleteAllTable() {
log.debug("Start deleteAllTable method - CRUD");
infoTableRepository.deleteAll();
}
public InfoTable addOrUpdateTable(InfoTable infoTable) {
log.debug("Start deleteAllTable method - CRUD");
return infoTableRepository.save(infoTable);
}
public void truncateMyTable(){
log.debug("Start truncateMyTable method - Custom");
infoTableRepository.truncateMyTable();
}

@ -3,6 +3,7 @@ package com.apside.assistDbBackend.service;
import com.apside.assistDbBackend.model.LinkInfo;
import com.apside.assistDbBackend.repository.LinkInfoRepository;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -10,32 +11,39 @@ import java.util.Optional;
@Data
@Service
@Slf4j
public class LinkInfoService {
@Autowired
private LinkInfoRepository linkInfoRepository;
public Optional<LinkInfo> getLinkInfo(final Long id) {
log.debug("Start getLinkInfo method - CRUD");
return linkInfoRepository.findById(id);
}
public Iterable<LinkInfo> getAllLinksInfos() {
log.debug("Start getAllLinksInfos method - CRUD");
return linkInfoRepository.findAll();
}
public void deleteLinkInfo(final Long id) {
log.debug("Start deleteLinkInfo method - CRUD");
linkInfoRepository.deleteById(id);
}
public void deleteAllLinks() {
log.debug("Start deleteAllLinks method - CRUD");
linkInfoRepository.deleteAll();
}
public LinkInfo addOrUpdateLink(LinkInfo linkInfo) {
log.debug("Start addOrUpdateLink method - CRUD");
return linkInfoRepository.save(linkInfo);
}
public void truncateMyLink(){
log.debug("Start truncateMyLink method - Custom");
linkInfoRepository.truncateMyLink();
}
}

@ -4,6 +4,7 @@ import com.apside.assistDbBackend.model.LinkInfo;
import com.apside.assistDbBackend.model.InfoColumn;
import com.apside.assistDbBackend.model.InfoTable;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Service;
@ -16,6 +17,7 @@ import java.nio.file.Paths;
@Data
@Service
@Slf4j
public class ResetDataService {
@Autowired
@ -46,6 +48,7 @@ public class ResetDataService {
}
public void insertEverything() throws IOException {
log.debug("Start insert every data into DB");
JSONArray jo = new JSONArray(result);
for (int i=0; i<jo.length(); i++){
JSONObject schema = jo.getJSONObject(i);
@ -115,9 +118,11 @@ public class ResetDataService {
}
}
}
log.info("Insert all data into DB - success");
}
public void checkAndInsertLinks() throws IOException {
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++){
JSONObject schema = jo.getJSONObject(i);
@ -175,6 +180,7 @@ public class ResetDataService {
}
}
}
log.info("Check and insert links data into DB - success");
}

@ -3,6 +3,9 @@ package com.apside.assistDbBackend.service;
import com.apside.assistDbBackend.model.LinkScriptTag;
import com.apside.assistDbBackend.model.Script;
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;
@ -11,6 +14,7 @@ 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;
@ -20,6 +24,7 @@ import java.util.*;
@Data
@Service
@Slf4j
public class ScriptsService {
@Autowired
private GitService gitService;
@ -40,7 +45,7 @@ public class ScriptsService {
private static final String TAGS_STRING = "tags";
private static final String DATA_STRING = "data";
public ScriptsService() throws IOException {
public ScriptsService() {
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;
@ -54,6 +59,7 @@ public class ScriptsService {
}
public List<Script> retrieveScripts() throws IOException, GitAPIException {
log.debug("Start retrieve all scripts");
gitService.pullFromGit();
List<Script> listOfScripts = new ArrayList<>();
//Creating a File object for directory
@ -65,10 +71,12 @@ public class ScriptsService {
Script tempScript = new Script(extension, contents[i], allData);
listOfScripts.add(tempScript);
}
log.info("Get all Scripts successful");
return listOfScripts;
}
public List<LinkScriptTag> getAllScriptTag() throws IOException {
log.debug("Start retrieve all links scripts/tags");
initialize();
List<LinkScriptTag> listLinkScriptTag = new ArrayList<>();
if (dataLinkScriptsTags.length()>0){
@ -88,40 +96,51 @@ public class ScriptsService {
listLinkScriptTag.add(newLinkScriptTag);
}
}
log.info("Get all links between Scripts and Tags successful");
return listLinkScriptTag;
}
public void deleteOneScript(final String name){
log.debug("Start delete one script with Git");
try {
File scriptDirectory = new File(tempDirectoryPath + "/" + name);
scriptDirectory.delete();
gitService.pushToGit();
gitService.pullFromGit();
log.info("Delete one Script successful");
} catch (Exception e){
log.error("Error : ", e);
e.printStackTrace();
}
}
public void simpleDeleteScript(final String name){
log.debug("Start delete one script without Git");
try {
File scriptDirectory = new File(tempDirectoryPath + "/" + name);
scriptDirectory.delete();
log.info("Delete one Script successful");
} catch (Exception e){
e.printStackTrace();
log.error("Error : ", e);
}
}
public void addOneScript(final String content, final String name) throws IOException {
log.debug("Start add one scripts");
File newFile = new File(tempDirectoryPath + "/" + name);
newFile.createNewFile();
try (FileWriter writerDataFile = new FileWriter(tempDirectoryPath + "/" + name);) {
writerDataFile.write(content);
log.info("Add one Script successful");
} catch (IOException ioException){
log.error("Error add one Script : ", ioException);
throw ioException;
}
}
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();
gitService.pullFromGit();
JSONObject newLink = new JSONObject();
@ -139,9 +158,11 @@ public class ScriptsService {
JSONObject newObj = dataGlobalScripts.put(DATA_STRING, newArr);
Files.write(pathOfLink, newObj.toString().getBytes());
gitService.pushToGit();
log.info("Add one link successful");
}
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();
gitService.pullFromGit();
JSONArray newArr = new JSONArray();
@ -169,6 +190,7 @@ public class ScriptsService {
Files.write(pathOfLink, newObj.toString().getBytes());
gitService.pushToGit();
log.info("Update one link successful");
}
}

@ -2,6 +2,7 @@ package com.apside.assistDbBackend.service;
import com.apside.assistDbBackend.model.Tag;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.json.JSONArray;
import org.json.JSONObject;
@ -19,6 +20,7 @@ import java.util.Objects;
@Data
@Service
@Slf4j
public class TagsService {
@Autowired
private GitService gitService;
@ -31,7 +33,7 @@ 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() throws IOException {
public TagsService() {
tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "/AssistDB_AdditionalFiles/tags.json";
path = Paths.get(tempDirectoryPath);
}
@ -43,6 +45,7 @@ public class TagsService {
}
public List<Tag> getAllTags() throws IOException, GitAPIException {
log.debug("Start get all tags from json");
gitService.pullFromGit();
initialize();
List<Tag> listOfTag = new ArrayList<>();
@ -54,10 +57,12 @@ public class TagsService {
Tag tempTag = new Tag(tagId, tagName, tagDescription);
listOfTag.add(tempTag);
}
log.info("Get all tags from json successful");
return listOfTag;
}
public void deleteTag(final String deleteNameTag) throws IOException, GitAPIException, URISyntaxException {
log.debug("Start delete one tag in json");
initialize();
JSONArray newArr = new JSONArray();
for (int i=0; i<data.length(); i++) {
@ -71,9 +76,11 @@ public class TagsService {
Files.write(path, newObj.toString().getBytes());
gitService.pushToGit();
gitService.pullFromGit();
log.info("Delete one tag in json file successful");
}
public void addTag(Tag tag) throws IOException, GitAPIException, URISyntaxException {
log.debug("Start add one tag in json");
initialize();
gitService.pullFromGit();
JSONObject newTag = new JSONObject();
@ -85,8 +92,10 @@ public class TagsService {
Files.write(path, newObj.toString().getBytes());
gitService.pushToGit();
gitService.pullFromGit();
log.info("Delete one tag in json successful");
}
public void updateTag(final String prevTag, Tag modTag) throws IOException, GitAPIException, URISyntaxException {
log.debug("Start update one tag in json");
initialize();
gitService.pullFromGit();
JSONArray newArr = new JSONArray();
@ -107,6 +116,7 @@ public class TagsService {
Files.write(path, newObj.toString().getBytes());
gitService.pushToGit();
gitService.pullFromGit();
log.info("Update one tag in json successful");
}
}

@ -6,7 +6,7 @@ spring.datasource.password=Pompom.21
server.port=9001
USERNAME_GIT = fhibert@apside.fr
ACCESS_TOKEN_GIT = e54612b6d1d73eef4f0a49c88b0e35ccf02d45eb
ACCESS_TOKEN_GIT = accesstokenexemple
logging.level.org.springframework.boot.web.embedded.tomcat=INFO
logging.level.org.springframework=error

@ -0,0 +1,15 @@
# Log4J configuration
log4j.rootLogger=DEBUG,CONSOLE,FILE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%d] %t %c %L %-5p - %m%n
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=/apps/logs/appname.log
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[%d] %t %c %L %-5p - %m%n
log4j.logger.org.springframework=WARN
Loading…
Cancel
Save