multiple change and opti via ticket

version_2
floxx2112 1 year ago
parent 7d36756f15
commit 2ca96c3778
  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")
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) {
@PostMapping("/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) {
log.debug("Start AddScript - Get Request - with name: {}, description: {}, tagsList: {} and linkId: {}", name, description, tagsList, linkId);
try {
scriptsService.addOneScript(content, name);
@ -71,8 +71,8 @@ public class ScriptController {
}
}
@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) {
@PostMapping("/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) {
log.debug("Start EditScript - Get Request - with defaultName: {}, newName: {}, description: {}, tagsList: {}, linkId: {}", defaultName, newName, description, tagsList, linkId);
try {
scriptsService.simpleDeleteScript(defaultName);

@ -21,8 +21,6 @@ public class GitServiceImpl implements GitService {
private final String tempDirectoryPath;
private UsernamePasswordCredentialsProvider userPass;
public GitServiceImpl(){
tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "\\AssistDB_AdditionalFiles";
}
@ -32,23 +30,28 @@ public class GitServiceImpl implements GitService {
@Value("${ACCESS_TOKEN_GIT}")
private String accesToken;
@Value("${URI_GIT}")
private String uriGit;
private static final String NAME_URI = "origin";
private static final String COMMIT_MESSAGE = "commited";
@Override
public void pushToGit() throws IOException, GitAPIException, URISyntaxException {
log.debug("Starting pushToGit method.");
pullFromGit();
try (Git git = Git.open(new File(tempDirectoryPath))){
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
remoteAddCommand.setUri(new URIish("https://gitea.ci.apside-top.fr/Prudence_Creole/AssistDB_AdditionalFiles.git"));
remoteAddCommand.setName(NAME_URI);
remoteAddCommand.setUri(new URIish(uriGit));
// you can add more settings here if needed
remoteAddCommand.call();
git.add().setUpdate(true).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(userPass).call();
git.push().setCredentialsProvider(createCredential()).call();
log.info("Push to Git successful.");
} catch (IOException|GitAPIException exception){
log.error("Error push from git", exception);
@ -60,7 +63,7 @@ public class GitServiceImpl implements GitService {
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();
git.pull().setCredentialsProvider(createCredential()).setRemote("origin").setRemoteBranchName("main").call();
log.info("Pull from Git successful.");
} catch (IOException|GitAPIException 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 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 DATA_TYPE_STRING = "data_type";
private static final String LENGTH_STRING = "length";
@ -63,15 +67,15 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
JSONArray jo = new JSONArray(result);
for (int i=0; i<jo.length(); i++){
JSONObject schema = jo.getJSONObject(i);
String schemaName = schema.getString("schema");
JSONArray data = schema.getJSONArray("data");
String schemaName = schema.getString(SCHEMA_STRING);
JSONArray data = schema.getJSONArray(DATA_STRING);
for (int ia = 0; ia<data.length(); ia++){
JSONObject apra = data.getJSONObject(ia);
String tableText;
String tableName;
if(apra.has("table_text")){
tableText = apra.getString("table_text");
if(apra.has(TABLE_TEXT_STRING)){
tableText = apra.getString(TABLE_TEXT_STRING);
} else {
tableText = "";
}
@ -81,7 +85,7 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
tableName = "";
}
JSONArray col = apra.getJSONArray("columns");
JSONArray col = apra.getJSONArray(COLUMN_STRING);
InfoTable infoTable = new InfoTable();
infoTable.setNameTable(tableName);
infoTable.setNameSchema(schemaName);
@ -138,8 +142,8 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
JSONArray jo = new JSONArray(result);
for (int i=0; i<jo.length(); i++){
JSONObject schema = jo.getJSONObject(i);
String schemaName = schema.getString("schema");
JSONArray data = schema.getJSONArray("data");
String schemaName = schema.getString(SCHEMA_STRING);
JSONArray data = schema.getJSONArray(DATA_STRING);
for (int ia = 0; ia<data.length(); ia++){
JSONObject apra = data.getJSONObject(ia);
@ -149,7 +153,7 @@ public class ResetDataServiceImpl implements ResetDataService, InitializingBean
} else {
tableName = "";
}
JSONArray col = apra.getJSONArray("columns");
JSONArray col = apra.getJSONArray(COLUMN_STRING);
for (int ib =0; ib<col.length(); ib++){
JSONObject colData = col.getJSONObject(ib);

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

@ -85,7 +85,6 @@ public class TagsServiceImpl implements TagsService, InitializingBean {
JSONObject newObj = dataGlobal.put(DATA_STRING, newArr);
Files.write(path, newObj.toString().getBytes());
gitService.pushToGit();
gitService.pullFromGit();
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);
Files.write(path, newObj.toString().getBytes());
gitService.pushToGit();
gitService.pullFromGit();
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);
Files.write(path, newObj.toString().getBytes());
gitService.pushToGit();
gitService.pullFromGit();
log.info("Update one tag in json successful");
}

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

Loading…
Cancel
Save