Compare commits

..

No commits in common. 'dab3f85d6fabe0a55c8559b561daac3dcd17d0e3' and 'ef26c7b3c87cd8c8f95962872cd5f10fbc50febd' have entirely different histories.

  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 {
} }
@PostMapping("/script/add") @GetMapping("/script/add")
public ResponseEntity<Void> addScript(@RequestBody String content, @RequestParam("name") String name, @RequestParam("desc") String description, @RequestParam("tagList") List<String> tagsList, @RequestParam("linkid") int linkId) { 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); 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 {
} }
} }
@PostMapping("/script/edit") @GetMapping("/script/edit")
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) { 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); 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,6 +21,8 @@ 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";
} }
@ -30,28 +32,23 @@ 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(NAME_URI); remoteAddCommand.setName("origin");
remoteAddCommand.setUri(new URIish(uriGit)); remoteAddCommand.setUri(new URIish("https://gitea.ci.apside-top.fr/Prudence_Creole/AssistDB_AdditionalFiles.git"));
// 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(COMMIT_MESSAGE).call(); git.commit().setMessage("commited").call();
git.push().setCredentialsProvider(createCredential()).call(); userPass = new UsernamePasswordCredentialsProvider(userGit, accesToken);
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);
@ -63,7 +60,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(createCredential()).setRemote("origin").setRemoteBranchName("main").call(); git.pull().setCredentialsProvider(new UsernamePasswordCredentialsProvider(userGit, accesToken)).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);
@ -71,8 +68,4 @@ public class GitServiceImpl implements GitService {
} }
} }
public UsernamePasswordCredentialsProvider createCredential() {
return new UsernamePasswordCredentialsProvider(userGit, accesToken);
}
} }

@ -38,10 +38,6 @@ 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";
@ -67,15 +63,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); String schemaName = schema.getString("schema");
JSONArray data = schema.getJSONArray(DATA_STRING); JSONArray data = schema.getJSONArray("data");
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_STRING)){ if(apra.has("table_text")){
tableText = apra.getString(TABLE_TEXT_STRING); tableText = apra.getString("table_text");
} else { } else {
tableText = ""; tableText = "";
} }
@ -85,7 +81,7 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
tableName = ""; tableName = "";
} }
JSONArray col = apra.getJSONArray(COLUMN_STRING); JSONArray col = apra.getJSONArray("columns");
InfoTable infoTable = new InfoTable(); InfoTable infoTable = new InfoTable();
infoTable.setNameTable(tableName); infoTable.setNameTable(tableName);
infoTable.setNameSchema(schemaName); infoTable.setNameSchema(schemaName);
@ -142,8 +138,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); String schemaName = schema.getString("schema");
JSONArray data = schema.getJSONArray(DATA_STRING); JSONArray data = schema.getJSONArray("data");
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);
@ -153,7 +149,7 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
} else { } else {
tableName = ""; tableName = "";
} }
JSONArray col = apra.getJSONArray(COLUMN_STRING); JSONArray col = apra.getJSONArray("columns");
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,6 +115,7 @@ 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,6 +85,7 @@ 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");
} }
@ -101,6 +102,7 @@ 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");
} }
@ -126,6 +128,7 @@ 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,8 +8,6 @@ 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