Compare commits

..

2 Commits

  1. 8
      src/main/java/com/apside/assist/db/backend/controller/ScriptController.java
  2. 25
      src/main/java/com/apside/assist/db/backend/service/implementation/GitServiceImpl.java
  3. 20
      src/main/java/com/apside/assist/db/backend/service/implementation/ResetDataServiceImpl.java
  4. 1
      src/main/java/com/apside/assist/db/backend/service/implementation/ScriptsServiceImpl.java
  5. 3
      src/main/java/com/apside/assist/db/backend/service/implementation/TagsServiceImpl.java
  6. 2
      src/main/resources/application.properties

@ -58,8 +58,8 @@ public class ScriptController {
} }
@GetMapping("/script/add") @PostMapping("/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) { public ResponseEntity<Void> addScript(@RequestBody 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); log.debug("Start AddScript - Get Request - with name: {}, description: {}, tagsList: {} and linkId: {}", name, description, tagsList, linkId);
try { try {
scriptsService.addOneScript(content, name); scriptsService.addOneScript(content, name);
@ -71,8 +71,8 @@ public class ScriptController {
} }
} }
@GetMapping("/script/edit") @PostMapping("/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) { public ResponseEntity<Void> editScript(@RequestBody 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); log.debug("Start EditScript - Get Request - with defaultName: {}, newName: {}, description: {}, tagsList: {}, linkId: {}", defaultName, newName, description, tagsList, linkId);
try { try {
scriptsService.simpleDeleteScript(defaultName); scriptsService.simpleDeleteScript(defaultName);

@ -21,8 +21,6 @@ public class GitServiceImpl implements GitService {
private final String tempDirectoryPath; private final String tempDirectoryPath;
private UsernamePasswordCredentialsProvider userPass;
public GitServiceImpl(){ public GitServiceImpl(){
tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "\\AssistDB_AdditionalFiles"; tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "\\AssistDB_AdditionalFiles";
} }
@ -32,23 +30,28 @@ public class GitServiceImpl implements GitService {
@Value("${ACCESS_TOKEN_GIT}") @Value("${ACCESS_TOKEN_GIT}")
private String accesToken; private String accesToken;
@Value("${URI_GIT}")
private String uriGit;
private static final String NAME_URI = "origin";
private static final String COMMIT_MESSAGE = "commited";
@Override @Override
public void pushToGit() throws IOException, GitAPIException, URISyntaxException { public void pushToGit() throws IOException, GitAPIException, URISyntaxException {
log.debug("Starting pushToGit method."); log.debug("Starting pushToGit method.");
pullFromGit();
try (Git git = Git.open(new File(tempDirectoryPath))){ try (Git git = Git.open(new File(tempDirectoryPath))){
RemoteAddCommand remoteAddCommand = git.remoteAdd(); RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin"); remoteAddCommand.setName(NAME_URI);
remoteAddCommand.setUri(new URIish("https://gitea.ci.apside-top.fr/Prudence_Creole/AssistDB_AdditionalFiles.git")); remoteAddCommand.setUri(new URIish(uriGit));
// you can add more settings here if needed // you can add more settings here if needed
remoteAddCommand.call(); remoteAddCommand.call();
git.add().setUpdate(true).addFilepattern(".").call(); git.add().setUpdate(true).addFilepattern(".").call();
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("commited").call(); git.commit().setMessage(COMMIT_MESSAGE).call();
userPass = new UsernamePasswordCredentialsProvider(userGit, accesToken); git.push().setCredentialsProvider(createCredential()).call();
git.push().setCredentialsProvider(userPass).call();
log.info("Push to Git successful."); log.info("Push to Git successful.");
} catch (IOException|GitAPIException exception){ } catch (IOException|GitAPIException exception){
log.error("Error push from git", exception); log.error("Error push from git", exception);
@ -60,7 +63,7 @@ public class GitServiceImpl implements GitService {
public void pullFromGit() throws IOException, GitAPIException { public void pullFromGit() throws IOException, GitAPIException {
log.debug("Starting pullFromGit method."); log.debug("Starting pullFromGit method.");
try (Git git = Git.open(new File(tempDirectoryPath))){ try (Git git = Git.open(new File(tempDirectoryPath))){
git.pull().setCredentialsProvider(new UsernamePasswordCredentialsProvider(userGit, accesToken)).setRemote("origin").setRemoteBranchName("main").call(); git.pull().setCredentialsProvider(createCredential()).setRemote("origin").setRemoteBranchName("main").call();
log.info("Pull from Git successful."); log.info("Pull from Git successful.");
} catch (IOException|GitAPIException exception){ } catch (IOException|GitAPIException exception){
log.error("Error push from git", exception); log.error("Error push from git", exception);
@ -68,4 +71,8 @@ public class GitServiceImpl implements GitService {
} }
} }
public UsernamePasswordCredentialsProvider createCredential() {
return new UsernamePasswordCredentialsProvider(userGit, accesToken);
}
} }

@ -38,6 +38,10 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
private Path path; private Path path;
private static final String TABLE_STRING = "table"; private static final String TABLE_STRING = "table";
private static final String SCHEMA_STRING = "schema";
private static final String DATA_STRING = "data";
private static final String COLUMN_STRING = "columns";
private static final String TABLE_TEXT_STRING = "table_text";
private static final String NAME_STRING = "name"; private static final String NAME_STRING = "name";
private static final String DATA_TYPE_STRING = "data_type"; private static final String DATA_TYPE_STRING = "data_type";
private static final String LENGTH_STRING = "length"; private static final String LENGTH_STRING = "length";
@ -63,15 +67,15 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
JSONArray jo = new JSONArray(result); JSONArray jo = new JSONArray(result);
for (int i=0; i<jo.length(); i++){ for (int i=0; i<jo.length(); i++){
JSONObject schema = jo.getJSONObject(i); JSONObject schema = jo.getJSONObject(i);
String schemaName = schema.getString("schema"); String schemaName = schema.getString(SCHEMA_STRING);
JSONArray data = schema.getJSONArray("data"); JSONArray data = schema.getJSONArray(DATA_STRING);
for (int ia = 0; ia<data.length(); ia++){ for (int ia = 0; ia<data.length(); ia++){
JSONObject apra = data.getJSONObject(ia); JSONObject apra = data.getJSONObject(ia);
String tableText; String tableText;
String tableName; String tableName;
if(apra.has("table_text")){ if(apra.has(TABLE_TEXT_STRING)){
tableText = apra.getString("table_text"); tableText = apra.getString(TABLE_TEXT_STRING);
} else { } else {
tableText = ""; tableText = "";
} }
@ -81,7 +85,7 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
tableName = ""; tableName = "";
} }
JSONArray col = apra.getJSONArray("columns"); JSONArray col = apra.getJSONArray(COLUMN_STRING);
InfoTable infoTable = new InfoTable(); InfoTable infoTable = new InfoTable();
infoTable.setNameTable(tableName); infoTable.setNameTable(tableName);
infoTable.setNameSchema(schemaName); infoTable.setNameSchema(schemaName);
@ -138,8 +142,8 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
JSONArray jo = new JSONArray(result); JSONArray jo = new JSONArray(result);
for (int i=0; i<jo.length(); i++){ for (int i=0; i<jo.length(); i++){
JSONObject schema = jo.getJSONObject(i); JSONObject schema = jo.getJSONObject(i);
String schemaName = schema.getString("schema"); String schemaName = schema.getString(SCHEMA_STRING);
JSONArray data = schema.getJSONArray("data"); JSONArray data = schema.getJSONArray(DATA_STRING);
for (int ia = 0; ia<data.length(); ia++){ for (int ia = 0; ia<data.length(); ia++){
JSONObject apra = data.getJSONObject(ia); JSONObject apra = data.getJSONObject(ia);
@ -149,7 +153,7 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
} else { } else {
tableName = ""; tableName = "";
} }
JSONArray col = apra.getJSONArray("columns"); JSONArray col = apra.getJSONArray(COLUMN_STRING);
for (int ib =0; ib<col.length(); ib++){ for (int ib =0; ib<col.length(); ib++){
JSONObject colData = col.getJSONObject(ib); JSONObject colData = col.getJSONObject(ib);

@ -115,7 +115,6 @@ public class ScriptsServiceImpl implements ScriptsService, InitializingBean {
File scriptDirectoryToDelete = new File(tempDirectoryPath + "/" + name); File scriptDirectoryToDelete = new File(tempDirectoryPath + "/" + name);
scriptDirectoryToDelete.delete(); scriptDirectoryToDelete.delete();
gitService.pushToGit(); gitService.pushToGit();
gitService.pullFromGit();
log.info("Delete one Script successful"); log.info("Delete one Script successful");
} catch (Exception e){ } catch (Exception e){
log.error("Error : ", e); log.error("Error : ", e);

@ -85,7 +85,6 @@ public class TagsServiceImpl implements TagsService, InitializingBean {
JSONObject newObj = dataGlobal.put(DATA_STRING, newArr); JSONObject newObj = dataGlobal.put(DATA_STRING, newArr);
Files.write(path, newObj.toString().getBytes()); Files.write(path, newObj.toString().getBytes());
gitService.pushToGit(); gitService.pushToGit();
gitService.pullFromGit();
log.info("Delete one tag in json file successful"); log.info("Delete one tag in json file successful");
} }
@ -102,7 +101,6 @@ public class TagsServiceImpl implements TagsService, InitializingBean {
JSONObject newObj = dataGlobal.put(DATA_STRING, newArr); JSONObject newObj = dataGlobal.put(DATA_STRING, newArr);
Files.write(path, newObj.toString().getBytes()); Files.write(path, newObj.toString().getBytes());
gitService.pushToGit(); gitService.pushToGit();
gitService.pullFromGit();
log.info("Delete one tag in json successful"); log.info("Delete one tag in json successful");
} }
@ -128,7 +126,6 @@ public class TagsServiceImpl implements TagsService, InitializingBean {
JSONObject newObj = dataGlobal.put(DATA_STRING, newArr); JSONObject newObj = dataGlobal.put(DATA_STRING, newArr);
Files.write(path, newObj.toString().getBytes()); Files.write(path, newObj.toString().getBytes());
gitService.pushToGit(); gitService.pushToGit();
gitService.pullFromGit();
log.info("Update one tag in json successful"); log.info("Update one tag in json successful");
} }

@ -8,6 +8,8 @@ server.port=9001
USERNAME_GIT = fhibert@apside.fr USERNAME_GIT = fhibert@apside.fr
ACCESS_TOKEN_GIT = accesstokenexemple ACCESS_TOKEN_GIT = accesstokenexemple
URI_GIT = https://gitea.ci.apside-top.fr/Prudence_Creole/AssistDB_AdditionalFiles.git
PATH_FOR_DATA = src/main/resources/assistDbData.json PATH_FOR_DATA = src/main/resources/assistDbData.json
PATH_FOR_SCRIPT_JSON = /AssistDB_AdditionalFiles/scripts.json PATH_FOR_SCRIPT_JSON = /AssistDB_AdditionalFiles/scripts.json
PATH_TO_SCRIPT_DIR = /AssistDB_AdditionalFiles/Scripts PATH_TO_SCRIPT_DIR = /AssistDB_AdditionalFiles/Scripts

Loading…
Cancel
Save