|
|
@ -30,7 +30,8 @@ import java.util.*; |
|
|
|
@Data |
|
|
|
@Data |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
public class ScriptsService { |
|
|
|
public class ScriptsService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private GitService gitService; |
|
|
|
private final String linkScriptTagPath; |
|
|
|
private final String linkScriptTagPath; |
|
|
|
private final Path pathOfLink; |
|
|
|
private final Path pathOfLink; |
|
|
|
private String allScriptsContent; |
|
|
|
private String allScriptsContent; |
|
|
@ -46,11 +47,10 @@ public class ScriptsService { |
|
|
|
allScriptsContent = new String((Files.readAllBytes(pathOfLink))); |
|
|
|
allScriptsContent = new String((Files.readAllBytes(pathOfLink))); |
|
|
|
dataGlobalScripts = new JSONObject(allScriptsContent); |
|
|
|
dataGlobalScripts = new JSONObject(allScriptsContent); |
|
|
|
dataLinkScriptsTags = dataGlobalScripts.getJSONArray("data"); |
|
|
|
dataLinkScriptsTags = dataGlobalScripts.getJSONArray("data"); |
|
|
|
System.out.println(dataLinkScriptsTags); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<Script> retrieveScripts() throws IOException, GitAPIException { |
|
|
|
public List<Script> retrieveScripts() throws IOException, GitAPIException { |
|
|
|
pullFromGit(); |
|
|
|
gitService.pullFromGit(); |
|
|
|
List<Script> listOfScripts = new ArrayList<>(); |
|
|
|
List<Script> listOfScripts = new ArrayList<>(); |
|
|
|
//Creating a File object for directory
|
|
|
|
//Creating a File object for directory
|
|
|
|
String tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "/AssistDB_AdditionalFiles/Scripts"; |
|
|
|
String tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "/AssistDB_AdditionalFiles/Scripts"; |
|
|
@ -76,6 +76,7 @@ public class ScriptsService { |
|
|
|
JSONObject link = dataLinkScriptsTags.getJSONObject(i); |
|
|
|
JSONObject link = dataLinkScriptsTags.getJSONObject(i); |
|
|
|
int linkId = link.getInt("id"); |
|
|
|
int linkId = link.getInt("id"); |
|
|
|
String scriptName = link.getString("filename"); |
|
|
|
String scriptName = link.getString("filename"); |
|
|
|
|
|
|
|
String desc = link.getString("description"); |
|
|
|
List<String> tagList = new ArrayList<>(); |
|
|
|
List<String> tagList = new ArrayList<>(); |
|
|
|
JSONArray tags = link.getJSONArray("tags"); |
|
|
|
JSONArray tags = link.getJSONArray("tags"); |
|
|
|
for (int j=0; j<tags.length(); j++){ |
|
|
|
for (int j=0; j<tags.length(); j++){ |
|
|
@ -83,7 +84,7 @@ public class ScriptsService { |
|
|
|
String tagName = unitTag.getString("tagname"); |
|
|
|
String tagName = unitTag.getString("tagname"); |
|
|
|
tagList.add(tagName); |
|
|
|
tagList.add(tagName); |
|
|
|
} |
|
|
|
} |
|
|
|
LinkScriptTag newLinkScriptTag = new LinkScriptTag(linkId, scriptName, tagList); |
|
|
|
LinkScriptTag newLinkScriptTag = new LinkScriptTag(linkId, scriptName, desc, tagList); |
|
|
|
listLinkScriptTag.add(newLinkScriptTag); |
|
|
|
listLinkScriptTag.add(newLinkScriptTag); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -96,8 +97,8 @@ public class ScriptsService { |
|
|
|
try { |
|
|
|
try { |
|
|
|
File scriptDirectory = new File(tempDirectoryPath + "/" + name); |
|
|
|
File scriptDirectory = new File(tempDirectoryPath + "/" + name); |
|
|
|
scriptDirectory.delete(); |
|
|
|
scriptDirectory.delete(); |
|
|
|
pushToGit(); |
|
|
|
gitService.pushToGit(); |
|
|
|
pullFromGit(); |
|
|
|
gitService.pullFromGit(); |
|
|
|
} catch (Exception e){ |
|
|
|
} catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
@ -124,11 +125,13 @@ public class ScriptsService { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addOneLink(final String name, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException { |
|
|
|
public void addOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException { |
|
|
|
initialize(); |
|
|
|
initialize(); |
|
|
|
|
|
|
|
gitService.pullFromGit(); |
|
|
|
JSONObject newLink = new JSONObject(); |
|
|
|
JSONObject newLink = new JSONObject(); |
|
|
|
newLink.put("id", linkId); |
|
|
|
newLink.put("id", linkId); |
|
|
|
newLink.put("filename", name); |
|
|
|
newLink.put("filename", name); |
|
|
|
|
|
|
|
newLink.put("description", description); |
|
|
|
JSONArray tagArray = new JSONArray(); |
|
|
|
JSONArray tagArray = new JSONArray(); |
|
|
|
for(int i=0; i<tagList.size(); i++){ |
|
|
|
for(int i=0; i<tagList.size(); i++){ |
|
|
|
JSONObject tempTag = new JSONObject(); |
|
|
|
JSONObject tempTag = new JSONObject(); |
|
|
@ -139,11 +142,12 @@ public class ScriptsService { |
|
|
|
JSONArray newArr = dataLinkScriptsTags.put(newLink); |
|
|
|
JSONArray newArr = dataLinkScriptsTags.put(newLink); |
|
|
|
JSONObject newObj = dataGlobalScripts.put("data", newArr); |
|
|
|
JSONObject newObj = dataGlobalScripts.put("data", newArr); |
|
|
|
Files.write(pathOfLink, newObj.toString().getBytes()); |
|
|
|
Files.write(pathOfLink, newObj.toString().getBytes()); |
|
|
|
pushToGit(); |
|
|
|
gitService.pushToGit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void updateOneLink(final String name, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException { |
|
|
|
public void updateOneLink(final String name, final String description, final List<String> tagList, final int linkId) throws IOException, GitAPIException, URISyntaxException { |
|
|
|
initialize(); |
|
|
|
initialize(); |
|
|
|
|
|
|
|
gitService.pullFromGit(); |
|
|
|
JSONArray newArr = new JSONArray(); |
|
|
|
JSONArray newArr = new JSONArray(); |
|
|
|
for (int d = 0; d<dataLinkScriptsTags.length(); d++){ |
|
|
|
for (int d = 0; d<dataLinkScriptsTags.length(); d++){ |
|
|
|
JSONObject actualLink = dataLinkScriptsTags.getJSONObject(d); |
|
|
|
JSONObject actualLink = dataLinkScriptsTags.getJSONObject(d); |
|
|
@ -154,6 +158,7 @@ public class ScriptsService { |
|
|
|
JSONObject newLink = new JSONObject(); |
|
|
|
JSONObject newLink = new JSONObject(); |
|
|
|
newLink.put("id", linkId); |
|
|
|
newLink.put("id", linkId); |
|
|
|
newLink.put("filename", name); |
|
|
|
newLink.put("filename", name); |
|
|
|
|
|
|
|
newLink.put("description", description); |
|
|
|
JSONArray tagArray = new JSONArray(); |
|
|
|
JSONArray tagArray = new JSONArray(); |
|
|
|
for(int i=0; i<tagList.size(); i++){ |
|
|
|
for(int i=0; i<tagList.size(); i++){ |
|
|
|
JSONObject tempTag = new JSONObject(); |
|
|
|
JSONObject tempTag = new JSONObject(); |
|
|
@ -167,45 +172,7 @@ public class ScriptsService { |
|
|
|
JSONObject newObj = dataGlobalScripts.put("data", newArr); |
|
|
|
JSONObject newObj = dataGlobalScripts.put("data", newArr); |
|
|
|
Files.write(pathOfLink, newObj.toString().getBytes()); |
|
|
|
Files.write(pathOfLink, newObj.toString().getBytes()); |
|
|
|
|
|
|
|
|
|
|
|
pushToGit(); |
|
|
|
gitService.pushToGit(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${USERNAME_GIT}") |
|
|
|
|
|
|
|
private String userGit; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${ACCESS_TOKEN_GIT}") |
|
|
|
|
|
|
|
private String accesToken; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void pushToGit() throws IOException, GitAPIException, URISyntaxException { |
|
|
|
|
|
|
|
String tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "\\AssistDB_AdditionalFiles"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")); |
|
|
|
|
|
|
|
// 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.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(userGit, accesToken)).call(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void pullFromGit() throws IOException, GitAPIException { |
|
|
|
|
|
|
|
String tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "\\AssistDB_AdditionalFiles"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Git git = Git.open(new File(tempDirectoryPath)); |
|
|
|
|
|
|
|
git.pull().setCredentialsProvider(new UsernamePasswordCredentialsProvider(userGit, accesToken)).setRemote("origin").setRemoteBranchName("main").call(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|