diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/ScriptRunnerController.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/ScriptRunnerController.java new file mode 100644 index 0000000..bd3da95 --- /dev/null +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/ScriptRunnerController.java @@ -0,0 +1,146 @@ +package com.realnet.OpenAi.Controller; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.realnet.OpenAi.Services.ScriptRunnerService; + +@RestController +@CrossOrigin(origins = "*") +@RequestMapping("/openAi") +public class ScriptRunnerController { + + @Value("${projectPath}") + private String projectpath; + + @Autowired + private ScriptRunnerService scriptRunnerService; + + /** + * runScript method by reading file + * + * @throws IOException + * + */ + + // RUN SCRIPT + @GetMapping(value = "/runScript") + public ResponseEntity runScript(@RequestParam String filepath, @RequestParam String filename) + throws IOException { + + System.out.println("runScript method called in ScriptRunnerController"); + + ResponseEntity runScript = scriptRunnerService.runScript(filepath, filename); + return runScript; + + } + + // NOT IN USE + @GetMapping(value = "/runScript1") + public ResponseEntity runScript1(@RequestParam String s1, @RequestParam String s2) throws IOException { + + System.out.println("runScript method called in ScriptRunnerController"); + + String str = null; + + String path = projectpath + "/ScriptFiles/copy.sh"; + System.out.println(path); + File pathfile = new File(path); + String filename = pathfile.getName(); + + String line = ""; + StringBuilder intialize = new StringBuilder(); + StringBuilder class_name = new StringBuilder(); + StringBuilder middle = new StringBuilder(); + StringBuilder end = new StringBuilder(); + BufferedReader br = new BufferedReader(new FileReader(path)); + intialize.append("\""); + intialize.append("*****************************************\n" + "Below is the script to copy reporsitry\n" + + "*****************************************\n" + "#!/bin/bash\n"); + + while ((line = br.readLine()) != null) { + String[] data = line.split(","); + for (String d : data) { + if (d.contains("PRJ_NAME=")) { + intialize.append("PRJ_NAME=gitclone"); + intialize.append("\n"); + } else if (d.contains("GIT_USER=")) { + intialize.append("GIT_USER=admin123"); + intialize.append("\n"); + } else if (d.contains("GIT_PASS=")) { + intialize.append("GIT_PASS=admin123"); + intialize.append("\n"); + } else if (d.contains("GIT_URL_FROM=")) { + intialize.append("GIT_URL_FROM=http://13.126.217.36:31633/admin123/" + s1 + ".git"); + intialize.append("\n"); + } else if (d.contains("GIT_URL_TO=")) { + intialize.append("GIT_URL_TO=http://13.126.217.36:31633/admin123/" + s2 + ".git"); + intialize.append("\n"); + } +// + } + } + intialize.append("docker build .\n" + "echo IMAGE_NAME=$GIT_URL_TO"); + + System.out.println(intialize); + + String path1 = projectpath + "/testingfor script/" + filename; + System.out.println(path1); + + FileWriter fw = null; + BufferedWriter bw = null; + + // FILE NAME SHOULD CHANGE DEPENDS ON TECH_STACK/OBJECT_tYPE/SUB_OBJECT_TYPE + File masterBuilderFile = new File(path1); + if (!masterBuilderFile.exists()) { + masterBuilderFile.createNewFile(); + } + fw = new FileWriter(masterBuilderFile.getAbsoluteFile()); + bw = new BufferedWriter(fw); + bw.write(intialize.toString()); + bw.close(); + + ProcessBuilder pb = new + + ProcessBuilder(path1); + + System.out.println("path taken =" + path1); + System.out.println(new File(path1).getAbsoluteFile()); + + pb.directory(new File(System.getProperty("user.home"))); + + Process process = pb.start(); + if (process.isAlive()) { + +// Process process = Runtime.getRuntime().exec("where java"); + + BufferedReader br2 = new BufferedReader(new InputStreamReader(process.getInputStream())); + + System.out.println("file is running"); + + while ((str = br2.readLine()) != null) { + System.out.println(str); + } + br2.close(); + return new ResponseEntity<>("file is running", HttpStatus.OK); + } else { + return new ResponseEntity<>("bad request", HttpStatus.BAD_REQUEST); + } + + } +} diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/SureOpsController.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/SureOpsController.java index 216c775..f01a296 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/SureOpsController.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/SureOpsController.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.realnet.OpenAi.Services.ScriptRunnerService; import com.realnet.OpenAi.Services.Script_Making; import com.realnet.fnd.response.EntityResponse; @@ -24,16 +26,21 @@ import com.realnet.fnd.response.EntityResponse; @RequestMapping("/sureops") public class SureOpsController { + @Value("${projectPath}") + private String projectpath; @Autowired private Script_Making script_serviceMaking; + @Autowired + private ScriptRunnerService scriptRunnerService; + @Value("${projectPath}") private String projectPath; - public ResponseEntity PullScript(@PathVariable Integer projId, @PathVariable String workflow_id) - throws IOException, InterruptedException { + @GetMapping("/deploy") + public ResponseEntity makeScript(@RequestParam Integer projId) throws IOException, InterruptedException { -// String workflow_id = "56"; // pull script + String workflow_id = "56"; // pull script int status_code = 500; String responsebody = null; @@ -43,13 +50,48 @@ public class SureOpsController { ResponseEntity get = script_serviceMaking.CreateFiles(projId, workflow_id, Deployment_profile); status_code = get.getStatusCodeValue(); + String filepath = projectPath + File.separator + projId + File.separator + "index"; if (status_code <= 209) { + System.out.println(" pull scriopt make"); if (get.getBody() != null) { responsebody = get.getBody().toString().replace("{", "").replace("}", ""); + } + String filename = "git_pull_exec.sh"; + + ResponseEntity script = scriptRunnerService.runScript(filepath, filename); + + if (script.getStatusCodeValue() <= 209) { + System.out.println(" Run Pull script successfullt now make all file"); + + workflow_id = "58"; + ResponseEntity pushScript = script_serviceMaking.CreateFiles(projId, workflow_id, + Deployment_profile); + if (pushScript.getStatusCodeValue() <= 209) { + + String pushScriptfilename = "git_push_exec.sh"; + + ResponseEntity scr = scriptRunnerService.runScript(filepath, pushScriptfilename); + + if (scr.getStatusCodeValue() <= 209) { + System.out.println(" Push Script run successfully"); + + System.out.println(" All code successfully push"); + + workflow_id = "245"; + + ResponseEntity deployScript = script_serviceMaking.CreateFiles(projId, workflow_id, + Deployment_profile); + + System.out.println("now deploy script make and run"); + + } + + } + } return new ResponseEntity<>(new EntityResponse(responsebody), HttpStatus.OK); @@ -69,33 +111,32 @@ public class SureOpsController { @PostMapping("/createFile") public void createHtmlFiles(@RequestParam Integer projId, @RequestBody Map pageHtmlMap) - throws IOException { + throws IOException { - for (Map.Entry entry : pageHtmlMap.entrySet()) { - String pageName = entry.getKey().trim().replaceAll("\\s+", "_"); // remove spaces from name - String htmlContent = entry.getValue(); + for (Map.Entry entry : pageHtmlMap.entrySet()) { + String pageName = entry.getKey().trim().replaceAll("\\s+", "_"); // remove spaces from name + String htmlContent = entry.getValue(); - String folderPath = projectPath + "/cns-portal/code-extractor/builders/" + projId; - File file = new File(folderPath + "/" + pageName + ".html"); + String folderPath = projectPath + "/cns-portal/code-extractor/builders/" + projId; + File file = new File(folderPath + "/" + pageName + ".html"); - // Ensure directory exists - File parentDir = file.getParentFile(); - if (!parentDir.exists()) { - parentDir.mkdirs(); - } + // Ensure directory exists + File parentDir = file.getParentFile(); + if (!parentDir.exists()) { + parentDir.mkdirs(); + } - // Create new file - if (!file.exists()) { - file.createNewFile(); - } + // Create new file + if (!file.exists()) { + file.createNewFile(); + } - try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { - writer.write(htmlContent); - } + try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { + writer.write(htmlContent); + } - System.out.println("✅ File created: " + file.getAbsolutePath()); - } + System.out.println("✅ File created: " + file.getAbsolutePath()); + } } - } diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Services/ScriptRunnerService.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Services/ScriptRunnerService.java new file mode 100644 index 0000000..6cdac0b --- /dev/null +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Services/ScriptRunnerService.java @@ -0,0 +1,49 @@ +package com.realnet.OpenAi.Services; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +@Service +public class ScriptRunnerService { + + public ResponseEntity runScript(String filepath, String filename) throws IOException { + + System.out.println("runScript method called in ScriptRunnerController"); + + String str = null; + + String path = filepath + "/" + filename; + + ProcessBuilder pb = new + + ProcessBuilder(path); + + System.out.println("file taken =" + new File(path).getAbsoluteFile()); + + pb.directory(new File(System.getProperty("user.home"))); + + Process process = pb.start(); + if (process.isAlive()) { + + BufferedReader br2 = new BufferedReader(new InputStreamReader(process.getInputStream())); + + System.out.println("file is running"); + + while ((str = br2.readLine()) != null) { + System.out.println(str); + } + br2.close(); + return new ResponseEntity<>(HttpStatus.OK); + } else { + return new ResponseEntity<>("bad request", HttpStatus.BAD_REQUEST); + } + + } + +} diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Services/ScriptSrvice.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Services/ScriptSrvice.java index 5e99b11..8c3c5a6 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Services/ScriptSrvice.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Services/ScriptSrvice.java @@ -254,7 +254,7 @@ public class ScriptSrvice { // Creating Folder - String Path1 = null; + String Path1 = projectPath + File.separator + prj_id; String ref_path = null; // when destination is not empty @@ -263,30 +263,12 @@ public class ScriptSrvice { ref_path = File.separator + sureopspath_name; - Path1 = projectPath + File.separator + "cns-portal/code-extractor/builders"; - - File builderMainDir1 = new File(Path1); - if (!builderMainDir1.exists()) { - boolean mkdir = builderMainDir1.mkdir(); - System.out.println("builder folder " + mkdir); - } - - Path1 = Path1 + File.separator + prj_id; - - System.out.println(Path1); - - File staticMainDir1 = new File(Path1); - if (!staticMainDir1.exists()) { - boolean mkdir = staticMainDir1.mkdir(); - System.out.println(mkdir); - } - Path1 = Path1 + ref_path; System.out.println(Path1); File Dir1 = new File(Path1); if (!Dir1.exists()) { - boolean mkdir = Dir1.mkdir(); + boolean mkdir = Dir1.mkdirs(); if (!mkdir) { System.out.println("folder not created"); @@ -296,22 +278,6 @@ public class ScriptSrvice { // when destination is empty } else { - Path1 = projectPath + File.separator + "cns-portal/code-extractor/builders"; - - File builderMainDir1 = new File(Path1); - if (!builderMainDir1.exists()) { - boolean mkdir = builderMainDir1.mkdir(); - System.out.println("builder folder " + mkdir); - } - - Path1 = Path1 + File.separator + prj_id; - - File staticMainDir1 = new File(Path1); - if (!staticMainDir1.exists()) { - boolean mkdir = staticMainDir1.mkdir(); - System.out.println(mkdir); - } - ref_path = File.separator + "index"; Path1 = Path1 + ref_path; @@ -319,7 +285,7 @@ public class ScriptSrvice { File Dir2 = new File(Path1); if (!Dir2.exists()) { - boolean mkdir = Dir2.mkdir(); + boolean mkdir = Dir2.mkdirs(); if (!mkdir) { System.out.println("folder not created"); @@ -354,10 +320,12 @@ public class ScriptSrvice { String filepath = Path1; String filename = file_text; - // INSERT DATA IN JOB PRO FOR RUN SCRIPT -// insertin_jobpro(prj_id, filename, filepath); + if (filename.contains(".sh")) { -// } + // INSERT DATA IN JOB PRO FOR RUN SCRIPT + insertin_jobpro(prj_id, filename, filepath); + + } } // CALL PROJECT PORTAL @@ -537,7 +505,7 @@ public class ScriptSrvice { Map jobdata = new HashMap(); // jobdata.put("parameters", builder.toString()); jobdata.put("url", - PortConstant.SUREOPS_DOMAIN + "/sureops/runScript?filepath=" + filepath + "&filename=" + filename); + PortConstant.SITE_BUILDER + "/openAi/runScript?filepath=" + filepath + "&filename=" + filename); jobdata.put("method", "GET"); jobdata.put("connection_name", "jobprtal"); jobdata.put("createdBy", "2022"); diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/utils/PortConstant.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/utils/PortConstant.java index 70e8af0..cb779ee 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/utils/PortConstant.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/utils/PortConstant.java @@ -3,11 +3,13 @@ package com.realnet.utils; import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; +@Component public class PortConstant { - public final static String LOCAL_HOST = "43.205.154.152"; + public static String LOCAL_HOST; public final static String FRONTEND_PORT_9191 = "30165"; public final static String GITEA_IP_ADDRESS = "try.gitea"; @@ -33,6 +35,8 @@ public class PortConstant { public static String SURE_VAULT_DOMAIN; public static String GITEA_DOMAIN; public static String GITEA_USERNAME; + public static String SITE_BUILDER; + public static String PROTOCOL; // SETTER @@ -49,8 +53,6 @@ public class PortConstant { @PostConstruct public void initializeConstantsFromApi() { - - if (backendPortalDomain != null) { BACKEND_PORTAL_DOMAIN = backendPortalDomain; System.out.println("Fetched BACKEND_PORTAL_DOMAIN from properties file: " + backendPortalDomain); @@ -75,6 +77,8 @@ public class PortConstant { GITEA_DOMAIN = getUrlFromApi(backendPortalDomain, "GITEA_DOMAIN"); GITEA_USERNAME = getUrlFromApi(backendPortalDomain, "GITEA_USERNAME"); PROTOCOL = getUrlFromApi(backendPortalDomain, "PROTOCOL"); + LOCAL_HOST = getUrlFromApi(backendPortalDomain, "LOCAL_HOST"); + SITE_BUILDER = getUrlFromApi(backendPortalDomain, "SITE_BUILDER"); } else { System.out.println("Error: BACKEND_PORTAL_DOMAIN could not be fetched."); diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/vpspack/Controllers/Visa_applicationController.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/vpspack/Controllers/Visa_applicationController.java index 97f6312..99c13af 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/vpspack/Controllers/Visa_applicationController.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/vpspack/Controllers/Visa_applicationController.java @@ -1,175 +1,55 @@ package com.realnet.vpspack.Controllers; -import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; - import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import com.fasterxml.jackson.core.JsonProcessingException; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.CrossOrigin; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.realnet.config.EmailService; -import com.realnet.users.entity1.AppUser; -import com.realnet.users.service1.AppUserServiceImpl; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.data.domain.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + import com.realnet.fnd.response.EntityResponse; -import org.springframework.http.*; -import org.springframework.beans.factory.annotation.*; import com.realnet.vpspack.Entity.Visa_application; -import com.realnet.vpspack.Services.Visa_applicationService ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +import com.realnet.vpspack.Services.Visa_applicationService; + @RequestMapping(value = "/Visa_application") - @CrossOrigin("*") +@CrossOrigin("*") @RestController public class Visa_applicationController { @Autowired private Visa_applicationService Service; -@Value("${projectPath}") + @Value("${projectPath}") private String projectPath; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @PostMapping("/Visa_application") - public Visa_application Savedata(@RequestBody Visa_application data) { - Visa_application save = Service.Savedata(data) ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + public Visa_application Savedata(@RequestBody Visa_application data) { + Visa_application save = Service.Savedata(data); + System.out.println("data saved..." + save); - return save; - } -@PutMapping("/Visa_application/{id}") - public Visa_application update(@RequestBody Visa_application data,@PathVariable Integer id ) { - Visa_application update = Service.update(data,id); + return save; + } + + @PutMapping("/Visa_application/{id}") + public Visa_application update(@RequestBody Visa_application data, @PathVariable Integer id) { + Visa_application update = Service.update(data, id); System.out.println("data update..." + update); return update; - } + } + // get all with pagination @GetMapping("/Visa_application/getall/page") public Page getall(@RequestParam(value = "page", required = false) Integer page, @@ -179,73 +59,32 @@ public class Visa_applicationController { return get; - } - @GetMapping("/Visa_application") - public List getdetails() { - List get = Service.getdetails(); - return get; -} -// get all without authentication - - @GetMapping("/token/Visa_application") - public List getallwioutsec() { - List get = Service.getdetails(); - return get; -} -@GetMapping("/Visa_application/{id}") - public Visa_application getdetailsbyId(@PathVariable Integer id ) { - Visa_application get = Service.getdetailsbyId(id); - return get; - } -@DeleteMapping("/Visa_application/{id}") - public ResponseEntity delete_by_id(@PathVariable Integer id ) { - Service.delete_by_id(id); - return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @GetMapping("/Visa_application") + public List getdetails() { + List get = Service.getdetails(); + return get; + } +// get all without authentication + + @GetMapping("/token/Visa_application") + public List getallwioutsec() { + List get = Service.getdetails(); + return get; + } + + @GetMapping("/Visa_application/{id}") + public Visa_application getdetailsbyId(@PathVariable Integer id) { + Visa_application get = Service.getdetailsbyId(id); + return get; + } + + @DeleteMapping("/Visa_application/{id}") + public ResponseEntity delete_by_id(@PathVariable Integer id) { + Service.delete_by_id(id); + return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK); + + } + } \ No newline at end of file diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/resources/application.properties b/visaproject-back-b/authsec_springboot/backend/src/main/resources/application.properties index 18ed6d0..526b44d 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/resources/application.properties +++ b/visaproject-back-b/authsec_springboot/backend/src/main/resources/application.properties @@ -94,8 +94,11 @@ app.auth.tokenExpirationMsec=864000000 app.oauth2.authorizedRedirectUris=http://localhost:8081/oauth2/redirect,myandroidapp://oauth2/redirect,myiosapp://oauth2/redirect -projectPath=@project.basedir@ -angularProjectPath=@project.basedir@/webui +#projectPath=@project.basedir@ +#angularProjectPath=@project.basedir@/webui + +projectPath=/data +angularProjectPath=/data/webui BACKEND_PORTAL_DOMAIN=http://157.66.191.31:30166