|
|
|
@ -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"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|