sitebuilder
This commit is contained in:
parent
152301c92b
commit
0801abe596
@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.realnet.utils.Port_Constant;
|
||||
import com.realnet.utils.PortConstant;
|
||||
|
||||
@Service
|
||||
public class SurevaultService {
|
||||
@ -71,8 +71,8 @@ public class SurevaultService {
|
||||
|
||||
public String callconnector(String name) throws JsonProcessingException {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = Port_Constant.SURE_VAULT_DOMAIN + "/token/Sure_Connectbyname/" + name;
|
||||
System.out.println(Port_Constant.SURE_VAULT_DOMAIN);
|
||||
String url = PortConstant.SURE_VAULT_DOMAIN + "/token/Sure_Connectbyname/" + name;
|
||||
System.out.println(PortConstant.SURE_VAULT_DOMAIN);
|
||||
|
||||
ResponseEntity<Object> u = restTemplate.getForEntity(url, Object.class);
|
||||
Object object = u.getBody();
|
||||
|
||||
@ -1,22 +1,14 @@
|
||||
package com.realnet.Dashboard1.Entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
package com.realnet.OpenAi.Controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.realnet.OpenAi.Services.HtmlBuilder3;
|
||||
import com.realnet.OpenAi.Services.HtmlGenerTorService;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/html")
|
||||
public class HtmlGeneratorController {
|
||||
|
||||
@Autowired
|
||||
private HtmlGenerTorService htmlGenerTorService;
|
||||
|
||||
@PostMapping
|
||||
public String generateHtmlFromJson(@RequestBody String jsonBody) {
|
||||
String json = htmlGenerTorService.generateHtmlFromJson(jsonBody);
|
||||
return json;
|
||||
}
|
||||
//
|
||||
// @PostMapping("/generate")
|
||||
// public ResponseEntity<Map<String, String>> generateHtml(@RequestBody HtmlRequest request) {
|
||||
// String sectionType = request.getSectionType();
|
||||
// Map<String, Object> structure = request.getJsonStructure();
|
||||
//
|
||||
// String html = HtmlRenderer.render(sectionType, structure);
|
||||
//
|
||||
// Map<String, String> result = new HashMap<>();
|
||||
// result.put("html", html);
|
||||
// return ResponseEntity.ok(result);
|
||||
// }
|
||||
|
||||
@PostMapping("/generate")
|
||||
public ResponseEntity<?> generateHtml(@RequestBody Map<String, Object> request) {
|
||||
try {
|
||||
Object jsonStructure = request.get("jsonStructure");
|
||||
|
||||
if (jsonStructure == null) {
|
||||
return ResponseEntity.badRequest().body("Missing 'jsonStructure' in request.");
|
||||
}
|
||||
|
||||
String html = HtmlBuilder3.buildHtml(jsonStructure);
|
||||
return ResponseEntity.ok(new EntityResponse(html));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseEntity.status(500).body("⚠️ Failed to generate HTML due to server error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
package com.realnet.OpenAi.Controller;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
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.OpenAi.Services.Script_Making;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sureops")
|
||||
public class SureOpsController {
|
||||
|
||||
@Autowired
|
||||
private Script_Making script_serviceMaking;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
public ResponseEntity<?> PullScript(@PathVariable Integer projId, @PathVariable String workflow_id)
|
||||
throws IOException, InterruptedException {
|
||||
|
||||
// String workflow_id = "56"; // pull script
|
||||
int status_code = 500;
|
||||
|
||||
String responsebody = null;
|
||||
|
||||
long Deployment_profile = 2l;
|
||||
// NOW MAKE SHELLSCRIPT THAT CLONE FROM REPOSITORY
|
||||
ResponseEntity<?> get = script_serviceMaking.CreateFiles(projId, workflow_id, Deployment_profile);
|
||||
|
||||
status_code = get.getStatusCodeValue();
|
||||
|
||||
if (status_code <= 209) {
|
||||
|
||||
if (get.getBody() != null) {
|
||||
|
||||
responsebody = get.getBody().toString().replace("{", "").replace("}", "");
|
||||
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(new EntityResponse(responsebody), HttpStatus.OK);
|
||||
|
||||
} else {
|
||||
|
||||
if (get.getBody() != null) {
|
||||
|
||||
responsebody = get.getBody().toString().replace("{", "").replace("}", "");
|
||||
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(new EntityResponse(responsebody), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/createFile")
|
||||
public void createHtmlFiles(@RequestParam Integer projId, @RequestBody Map<String, String> pageHtmlMap)
|
||||
throws IOException {
|
||||
|
||||
for (Map.Entry<String, String> 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");
|
||||
|
||||
// Ensure directory exists
|
||||
File parentDir = file.getParentFile();
|
||||
if (!parentDir.exists()) {
|
||||
parentDir.mkdirs();
|
||||
}
|
||||
|
||||
// Create new file
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
|
||||
writer.write(htmlContent);
|
||||
}
|
||||
|
||||
System.out.println("✅ File created: " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.realnet.OpenAi.Models;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HtmlRequest {
|
||||
private String sectionType;
|
||||
private Map<String, Object> jsonStructure;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.realnet.OpenAi.Renders;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
public class FeatureSectionRenderer {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String render(Map<String, Object> json) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<div class='feature-section'>");
|
||||
|
||||
sb.append("<img src='' alt='Feature Image'/>");
|
||||
|
||||
sb.append("<div class='feature-content'><ul>");
|
||||
|
||||
Object rawList = json.get("features");
|
||||
if (rawList instanceof List) {
|
||||
List<Object> features = (List<Object>) rawList;
|
||||
for (Object f : features) {
|
||||
sb.append("<li>").append(f.toString()).append("</li>");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("</ul></div></div>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.realnet.OpenAi.Renders;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FooterRenderer {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String render(Map<String, Object> json) {
|
||||
List<String> links = (List<String>) json.get("footerLinks");
|
||||
List<String> legalLinks = (List<String>) json.get("legalLinks");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<footer class='footer-1'>");
|
||||
|
||||
sb.append("<div class='footer-top'>").append("<img class='logo-1' src='' alt='Logo'>")
|
||||
.append("<nav class='footer-nav'><ul>");
|
||||
if (links != null) {
|
||||
for (String link : links) {
|
||||
sb.append("<li><a href='#'>").append(link).append("</a></li>");
|
||||
}
|
||||
}
|
||||
sb.append("</ul></nav>");
|
||||
|
||||
sb.append("<div class='footer-social'>").append("<div></div><div></div><div></div>").append("</div></div>");
|
||||
|
||||
sb.append("<div class='footer-bottom'>").append("<span>© 2025 Relume. All rights reserved.</span>")
|
||||
.append("<ul class='footer-legal'>");
|
||||
|
||||
if (legalLinks != null) {
|
||||
for (String legal : legalLinks) {
|
||||
sb.append("<li><a href='#'>").append(legal).append("</a></li>");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("</ul></div>");
|
||||
sb.append("</footer>");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.realnet.OpenAi.Renders;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class HeaderRenderer {
|
||||
public static String render(Map<String, Object> json) {
|
||||
String heading = String.valueOf(json.getOrDefault("title", ""));
|
||||
String subheading = String.valueOf(json.getOrDefault("subtitle", ""));
|
||||
|
||||
return "<header class='hero-header'>" + "<h1>" + heading + "</h1>" + "<p>" + subheading + "</p>"
|
||||
+ "<div class='cta-buttons'>" + "<button>Sign Up</button>" + "<button>Learn More</button>" + "</div>"
|
||||
+ "</header>";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package com.realnet.OpenAi.Renders;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class HtmlRenderer {
|
||||
|
||||
private static final String COMMON_CSS = "<style>\n" + "/* ✅ Your centralized CSS */\n"
|
||||
+ ".navbar-1 { display: flex; justify-content: space-between; align-items: center; padding: 20px 40px; }\n"
|
||||
+ ".logo-1 { width: 100px; height: 30px; background: #ccc; }\n"
|
||||
+ ".nav-1 { display: flex; gap: 20px; list-style: none; }\n"
|
||||
+ ".join-btn { background: black; color: white; padding: 8px 16px; border: none; border-radius: 4px; }\n"
|
||||
+ "/* ...more... */\n" + "</style>\n";
|
||||
|
||||
public static String render(String sectionType, Map<String, Object> json) {
|
||||
// 🔁 Delegate to SectionRenderFactory
|
||||
String sectionHtml = SectionRenderFactory.renderSection(sectionType, json);
|
||||
|
||||
// ✅ Inject centralized CSS
|
||||
// return COMMON_CSS + sectionHtml;
|
||||
return sectionHtml;
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package com.realnet.OpenAi.Renders;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NavbarRenderer {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String render(Map<String, Object> json) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<nav class='navbar-1'>");
|
||||
|
||||
Object rawChildren = json.get("children");
|
||||
if (rawChildren instanceof List) {
|
||||
List<Map<String, Object>> children = (List<Map<String, Object>>) rawChildren;
|
||||
|
||||
for (Map<String, Object> child : children) {
|
||||
String type = (String) child.get("type");
|
||||
switch (type != null ? type.toLowerCase() : "") {
|
||||
case "logo":
|
||||
sb.append("<div class='logo-1'>").append(child.getOrDefault("content", "")).append("</div>");
|
||||
break;
|
||||
case "nav":
|
||||
sb.append("<ul class='nav-1'>");
|
||||
List<Map<String, String>> links = (List<Map<String, String>>) child.get("children");
|
||||
if (links != null) {
|
||||
for (Map<String, String> link : links) {
|
||||
sb.append("<li><a href='#'>").append(link.getOrDefault("content", "")).append("</a></li>");
|
||||
}
|
||||
}
|
||||
sb.append("</ul>");
|
||||
break;
|
||||
case "button":
|
||||
sb.append("<button class='join-btn'>").append(child.getOrDefault("content", ""))
|
||||
.append("</button>");
|
||||
break;
|
||||
default:
|
||||
// Skip unrecognized types silently
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("</nav>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.realnet.OpenAi.Renders;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SectionRenderFactory {
|
||||
|
||||
public static String renderSection(String type, Map<String, Object> json) {
|
||||
if (type == null || json == null)
|
||||
return "<div class='empty-section'></div>";
|
||||
|
||||
switch (type.toLowerCase()) {
|
||||
case "navbar":
|
||||
return NavbarRenderer.render(json);
|
||||
case "header":
|
||||
return HeaderRenderer.render(json);
|
||||
case "featuresection":
|
||||
return FeatureSectionRenderer.render(json);
|
||||
case "testimonial":
|
||||
return TestimonialRenderer.render(json);
|
||||
case "footer":
|
||||
return FooterRenderer.render(json);
|
||||
default:
|
||||
return "<div class='unknown-section'></div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.realnet.OpenAi.Renders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
public class TestimonialRenderer {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String render(Map<String, Object> json) {
|
||||
List<Map<String, String>> testimonials = (List<Map<String, String>>) json.get("cards");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<div class='testimonial-section'>");
|
||||
sb.append("<h2 class='testimonial-heading'>Customer Testimonials</h2>");
|
||||
sb.append("<p class='testimonial-subtitle'>What our clients are saying...</p>");
|
||||
sb.append("<div class='testimonial-grid'>");
|
||||
|
||||
if (testimonials != null) {
|
||||
for (Map<String, String> t : testimonials) {
|
||||
sb.append("<div class='testimonial-card'>")
|
||||
.append("<div class='profile'></div>")
|
||||
.append("<blockquote>").append(t.getOrDefault("quote", "")).append("</blockquote>")
|
||||
.append("<p><strong>").append(t.getOrDefault("name", "")).append("</strong><br>")
|
||||
.append(t.getOrDefault("role", "")).append("</p>")
|
||||
.append("</div>");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("</div></div>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,123 @@
|
||||
package com.realnet.OpenAi.Services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HtmlBuilder {
|
||||
|
||||
// public static String buildHtml(Object node) {
|
||||
// if (node instanceof Map) {
|
||||
// return renderFromMap((Map<String, Object>) node);
|
||||
// } else if (node instanceof List) {
|
||||
// return renderFromList((List<Object>) node);
|
||||
// } else {
|
||||
// return String.valueOf(node);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static String renderFromMap(Map<String, Object> node) {
|
||||
// StringBuilder html = new StringBuilder();
|
||||
//
|
||||
// String tag = (String) node.getOrDefault("tag", "div");
|
||||
// String content = (String) node.getOrDefault("content", "");
|
||||
// String className = (String) node.getOrDefault("class", "");
|
||||
// String id = (String) node.getOrDefault("id", "");
|
||||
// Object children = node.get("children");
|
||||
//
|
||||
// html.append("<").append(tag);
|
||||
// if (!className.isEmpty())
|
||||
// html.append(" class=\"").append(className).append("\"");
|
||||
// if (!id.isEmpty())
|
||||
// html.append(" id=\"").append(id).append("\"");
|
||||
// html.append(">");
|
||||
//
|
||||
// if (!content.isEmpty())
|
||||
// html.append(content);
|
||||
//
|
||||
// if (children != null) {
|
||||
// html.append(buildHtml(children));
|
||||
// }
|
||||
//
|
||||
// html.append("</").append(tag).append(">");
|
||||
// return html.toString();
|
||||
// }
|
||||
//
|
||||
// private static String renderFromList(List<Object> list) {
|
||||
// return list.stream().map(HtmlBuilder::buildHtml).collect(Collectors.joining());
|
||||
// }
|
||||
//
|
||||
|
||||
|
||||
// part 2
|
||||
|
||||
|
||||
|
||||
|
||||
public static String buildHtml(Object node) {
|
||||
if (node instanceof Map) {
|
||||
return renderFromMap((Map<String, Object>) node);
|
||||
} else if (node instanceof List) {
|
||||
return renderFromList((List<Object>) node);
|
||||
} else if (node != null) {
|
||||
return String.valueOf(node);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String renderFromMap(Map<String, Object> node) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
|
||||
// String tag = getString(node, "tag", "div");
|
||||
String tag = getString(node, "tag", getString(node, "type", "div"));
|
||||
|
||||
String className = getString(node, "class", "");
|
||||
String id = getString(node, "id", "");
|
||||
String content = getString(node, "content", "");
|
||||
|
||||
// Start opening tag
|
||||
html.append("<").append(tag);
|
||||
|
||||
// Attributes
|
||||
if (!className.isEmpty()) html.append(" class=\"").append(className).append("\"");
|
||||
if (!id.isEmpty()) html.append(" id=\"").append(id).append("\"");
|
||||
|
||||
// Add any custom attributes
|
||||
for (Map.Entry<String, Object> entry : node.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (!key.equals("tag") && !key.equals("class") && !key.equals("id") &&
|
||||
!key.equals("content") && !key.equals("children")) {
|
||||
html.append(" ").append(key).append("=\"").append(entry.getValue()).append("\"");
|
||||
}
|
||||
}
|
||||
|
||||
html.append(">");
|
||||
|
||||
// Add content
|
||||
if (!content.isEmpty()) {
|
||||
html.append(content);
|
||||
}
|
||||
|
||||
// Children (recursive)
|
||||
if (node.containsKey("children")) {
|
||||
Object children = node.get("children");
|
||||
html.append(buildHtml(children));
|
||||
}
|
||||
|
||||
// Closing tag
|
||||
html.append("</").append(tag).append(">");
|
||||
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String renderFromList(List<Object> list) {
|
||||
return list.stream().map(HtmlBuilder::buildHtml).collect(Collectors.joining());
|
||||
}
|
||||
|
||||
private static String getString(Map<String, Object> map, String key, String defaultValue) {
|
||||
Object val = map.get(key);
|
||||
return (val instanceof String) ? (String) val : defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,345 @@
|
||||
package com.realnet.OpenAi.Services;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class HtmlBuilder2 {
|
||||
|
||||
// Plugin registry for special sections
|
||||
private static final Map<String, Function<Object, String>> SPECIAL_RENDERERS = new HashMap<>();
|
||||
|
||||
static {
|
||||
// Menu renderer
|
||||
SPECIAL_RENDERERS.put("menu", new Function<Object, String>() {
|
||||
public String apply(Object obj) {
|
||||
return renderMenu(obj);
|
||||
}
|
||||
});
|
||||
|
||||
// Actions renderer
|
||||
SPECIAL_RENDERERS.put("actions", new Function<Object, String>() {
|
||||
public String apply(Object obj) {
|
||||
return renderActions(obj);
|
||||
}
|
||||
});
|
||||
|
||||
// Logo renderer
|
||||
SPECIAL_RENDERERS.put("logo", new Function<Object, String>() {
|
||||
public String apply(Object obj) {
|
||||
return "<div class=\"logo\">" + obj + "</div>";
|
||||
}
|
||||
});
|
||||
|
||||
SPECIAL_RENDERERS.put("Header Section", new Function<Object, String>() {
|
||||
public String apply(Object obj) {
|
||||
return renderHeaderSection(obj);
|
||||
}
|
||||
});
|
||||
|
||||
SPECIAL_RENDERERS.put("Blog Template", new Function<Object, String>() {
|
||||
public String apply(Object obj) {
|
||||
return renderBlogTemplate((Map<String, Object>) obj);
|
||||
}
|
||||
});
|
||||
|
||||
// More renderers can be added here dynamically
|
||||
}
|
||||
|
||||
public static String buildHtml(Object node) {
|
||||
if (node instanceof Map) {
|
||||
return renderFromMap((Map<String, Object>) node);
|
||||
} else if (node instanceof List) {
|
||||
return renderFromList((List<Object>) node);
|
||||
} else if (node != null) {
|
||||
return String.valueOf(node);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String renderFromMap(Map<String, Object> node) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
|
||||
String type = getString(node, "type", "div");
|
||||
String tag = resolveTag(getString(node, "tag", ""), type);
|
||||
|
||||
if (tag.isEmpty()) {
|
||||
tag = TYPE_TAG_MAP.getOrDefault(type.toLowerCase(), type);
|
||||
}
|
||||
|
||||
html.append("<").append(tag);
|
||||
|
||||
String className = getString(node, "class", "");
|
||||
String id = getString(node, "id", "");
|
||||
|
||||
if (!className.isEmpty())
|
||||
html.append(" class=\"").append(className).append("\"");
|
||||
if (!id.isEmpty())
|
||||
html.append(" id=\"").append(id).append("\"");
|
||||
|
||||
// Flat string attributes
|
||||
for (Map.Entry<String, Object> entry : node.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (!Arrays.asList("tag", "type", "class", "id", "content", "children").contains(key)
|
||||
&& !(value instanceof Map || value instanceof List)) {
|
||||
html.append(" ").append(key).append("=\"").append(value).append("\"");
|
||||
}
|
||||
}
|
||||
|
||||
html.append(">");
|
||||
|
||||
// Standard content
|
||||
if (node.containsKey("content")) {
|
||||
html.append(node.get("content"));
|
||||
}
|
||||
|
||||
// Plugin-based section renderers
|
||||
for (Map.Entry<String, Function<Object, String>> plugin : SPECIAL_RENDERERS.entrySet()) {
|
||||
if (node.containsKey(plugin.getKey())) {
|
||||
html.append(plugin.getValue().apply(node.get(plugin.getKey())));
|
||||
}
|
||||
}
|
||||
|
||||
// Children
|
||||
if (node.containsKey("children")) {
|
||||
html.append(buildHtml(node.get("children")));
|
||||
}
|
||||
|
||||
html.append("</").append(tag).append(">");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String renderFromList(List<Object> list) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
for (Object obj : list) {
|
||||
html.append(buildHtml(obj));
|
||||
}
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static final Map<String, String> TYPE_TAG_MAP = new HashMap<>();
|
||||
static {
|
||||
TYPE_TAG_MAP.put("navbar", "nav");
|
||||
TYPE_TAG_MAP.put("footer", "footer");
|
||||
TYPE_TAG_MAP.put("article", "article");
|
||||
// add more if needed
|
||||
}
|
||||
|
||||
private static String getString(Map<String, Object> map, String key, String defaultValue) {
|
||||
Object val = map.get(key);
|
||||
return (val instanceof String) ? (String) val : defaultValue;
|
||||
}
|
||||
|
||||
private static String resolveTag(String tag, String type) {
|
||||
if (tag != null && !tag.isEmpty())
|
||||
return tag;
|
||||
if ("navbar".equalsIgnoreCase(type))
|
||||
return "nav";
|
||||
return type != null ? type : "div";
|
||||
}
|
||||
|
||||
// -------- Renderers for plugins --------
|
||||
|
||||
private static String renderMenu(Object obj) {
|
||||
StringBuilder html = new StringBuilder("<ul class=\"main-menu\">");
|
||||
|
||||
List<Object> menu = (List<Object>) obj;
|
||||
for (Object item : menu) {
|
||||
if (item instanceof String) {
|
||||
html.append("<li><a href=\"#\">").append(item).append("</a></li>");
|
||||
} else if (item instanceof Map) {
|
||||
Map<String, Object> dropdownItem = (Map<String, Object>) item;
|
||||
html.append("<li class=\"dropdown\">");
|
||||
html.append("<a href=\"#\">").append(dropdownItem.get("title")).append("</a>");
|
||||
|
||||
if (dropdownItem.containsKey("dropdown")) {
|
||||
html.append(renderDropdown(dropdownItem.get("dropdown")));
|
||||
}
|
||||
|
||||
html.append("</li>");
|
||||
}
|
||||
}
|
||||
|
||||
html.append("</ul>");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String renderDropdown(Object obj) {
|
||||
StringBuilder html = new StringBuilder("<div class=\"dropdown-content\"><div class=\"dropdown-columns\">");
|
||||
|
||||
Map<String, Object> dropdown = (Map<String, Object>) obj;
|
||||
List<Map<String, Object>> columns = (List<Map<String, Object>>) dropdown.get("columns");
|
||||
|
||||
for (Map<String, Object> column : columns) {
|
||||
html.append("<div class=\"column\">");
|
||||
html.append("<h4>").append(column.get("title")).append("</h4>");
|
||||
html.append("<ul>");
|
||||
|
||||
if (column.containsKey("items")) {
|
||||
List<Map<String, Object>> items = (List<Map<String, Object>>) column.get("items");
|
||||
for (Map<String, Object> item : items) {
|
||||
html.append("<li>");
|
||||
html.append("<span class=\"icon\">").append(item.get("icon")).append("</span>");
|
||||
html.append("<div class=\"info\">").append("<strong>").append(item.get("title")).append("</strong>")
|
||||
.append("<p>").append(item.get("description")).append("</p>").append("</div>");
|
||||
html.append("</li>");
|
||||
}
|
||||
} else if (column.containsKey("blogs")) {
|
||||
List<Map<String, Object>> blogs = (List<Map<String, Object>>) column.get("blogs");
|
||||
for (Map<String, Object> blog : blogs) {
|
||||
html.append("<li><strong>").append(blog.get("title")).append("</strong>");
|
||||
html.append("<p>").append(blog.get("description")).append("</p>");
|
||||
html.append("<a href=\"#\">").append(blog.get("cta")).append("</a></li>");
|
||||
}
|
||||
if (column.containsKey("footerLink")) {
|
||||
html.append("<div class=\"footer-link\"><a href=\"#\">").append(column.get("footerLink"))
|
||||
.append("</a></div>");
|
||||
}
|
||||
}
|
||||
|
||||
html.append("</ul></div>");
|
||||
}
|
||||
|
||||
html.append("</div></div>");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String renderActions(Object obj) {
|
||||
StringBuilder html = new StringBuilder("<div class=\"navbar-actions\">");
|
||||
|
||||
List<Map<String, Object>> actions = (List<Map<String, Object>>) obj;
|
||||
for (Map<String, Object> action : actions) {
|
||||
String label = getString(action, "label", "Button");
|
||||
String variant = getString(action, "variant", "");
|
||||
String btnClass = "join-btn";
|
||||
if (!variant.isEmpty())
|
||||
btnClass += " " + variant;
|
||||
|
||||
html.append("<button class=\"").append(btnClass).append("\">").append(label).append("</button>");
|
||||
}
|
||||
|
||||
html.append("</div>");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String renderHeaderSection(Object obj) {
|
||||
Map<String, Object> data = (Map<String, Object>) obj;
|
||||
|
||||
StringBuilder html = new StringBuilder();
|
||||
String sectionClass = getString(data, "class", "");
|
||||
html.append("<section");
|
||||
if (!sectionClass.isEmpty()) {
|
||||
html.append(" class=\"").append(sectionClass).append("\"");
|
||||
}
|
||||
html.append(">");
|
||||
|
||||
String heading = getString(data, "heading", "");
|
||||
if (!heading.isEmpty()) {
|
||||
html.append("<h1>").append(heading).append("</h1>");
|
||||
}
|
||||
|
||||
String subheading = getString(data, "subheading", "");
|
||||
if (!subheading.isEmpty()) {
|
||||
html.append("<p>").append(subheading).append("</p>");
|
||||
}
|
||||
|
||||
if (data.containsKey("buttons")) {
|
||||
Map<String, Object> buttons = (Map<String, Object>) data.get("buttons");
|
||||
String btnClass = getString(buttons, "class", "");
|
||||
List<String> items = (List<String>) buttons.get("items");
|
||||
|
||||
html.append("<div");
|
||||
if (!btnClass.isEmpty()) {
|
||||
html.append(" class=\"").append(btnClass).append("\"");
|
||||
}
|
||||
html.append(">");
|
||||
for (String label : items) {
|
||||
html.append("<button>").append(label).append("</button>");
|
||||
}
|
||||
html.append("</div>");
|
||||
}
|
||||
|
||||
html.append("</section>");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String renderBlogTemplate(Map<String, Object> node) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
html.append("<section class=\"blog-template\">");
|
||||
|
||||
// Header
|
||||
if (node.containsKey("header")) {
|
||||
Map<String, Object> header = (Map<String, Object>) node.get("header");
|
||||
html.append("<header class=\"blog-header\">")
|
||||
.append("<h1><span class=\"icon\">")
|
||||
.append(getString(header, "icon", "💡"))
|
||||
.append("</span> ")
|
||||
.append(getString(header, "title", "Blog Title"))
|
||||
.append("</h1></header>");
|
||||
}
|
||||
|
||||
// Navigation
|
||||
if (node.containsKey("navigation")) {
|
||||
List<String> navItems = (List<String>) node.get("navigation");
|
||||
html.append("<nav class=\"blog-nav\"><ul>");
|
||||
for (String item : navItems) {
|
||||
html.append("<li><a href=\"#\">").append(item).append("</a></li>");
|
||||
}
|
||||
html.append("</ul></nav>");
|
||||
}
|
||||
|
||||
// Layout Columns
|
||||
if (node.containsKey("layout")) {
|
||||
Map<String, Object> layout = (Map<String, Object>) node.get("layout");
|
||||
List<Map<String, Object>> columns = (List<Map<String, Object>>) layout.get("columns");
|
||||
|
||||
html.append("<div class=\"blog-layout\">");
|
||||
|
||||
for (Map<String, Object> col : columns) {
|
||||
String type = getString(col, "type", "");
|
||||
|
||||
if ("main".equalsIgnoreCase(type)) {
|
||||
html.append("<main class=\"main-column\">");
|
||||
List<Map<String, Object>> blocks = (List<Map<String, Object>>) col.get("contentBlocks");
|
||||
for (Map<String, Object> block : blocks) {
|
||||
html.append("<div class=\"content-block\">")
|
||||
.append("<h2>").append(getString(block, "heading", "")).append("</h2>")
|
||||
.append("<p>").append(getString(block, "text", "")).append("</p>")
|
||||
.append("</div>");
|
||||
}
|
||||
html.append("</main>");
|
||||
}
|
||||
|
||||
if ("sidebar".equalsIgnoreCase(type)) {
|
||||
html.append("<aside class=\"sidebar-column\">");
|
||||
List<String> widgets = (List<String>) col.get("widgets");
|
||||
for (String widget : widgets) {
|
||||
String emoji = getWidgetIcon(widget);
|
||||
html.append("<div class=\"widget\">").append(emoji).append(" ").append(widget).append("</div>");
|
||||
}
|
||||
html.append("</aside>");
|
||||
}
|
||||
}
|
||||
|
||||
html.append("</div>");
|
||||
}
|
||||
|
||||
html.append("</section>");
|
||||
return html.toString();
|
||||
}
|
||||
private static String getWidgetIcon(String widget) {
|
||||
widget = widget.toLowerCase();
|
||||
if (widget.contains("search")) return "🔍";
|
||||
if (widget.contains("recent")) return "📝";
|
||||
if (widget.contains("newsletter")) return "📬";
|
||||
return "📦";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------- END --------------------
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,126 @@
|
||||
package com.realnet.OpenAi.Services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.OpenAi.Renders.NavbarRenderer;
|
||||
|
||||
@Service
|
||||
public class HtmlGenerTorService {
|
||||
|
||||
public String generateHtmlFromJson(String jsonBody) {
|
||||
JSONObject contentJson = new JSONObject(jsonBody);
|
||||
StringBuilder htmlBuilder = new StringBuilder();
|
||||
generateHtml(contentJson, htmlBuilder);
|
||||
return htmlBuilder.toString();
|
||||
}
|
||||
|
||||
// Java 8 style static CSS map
|
||||
private static final Map<String, Map<String, String>> CSS = new HashMap<>();
|
||||
|
||||
static {
|
||||
CSS.put("header-1", createStyle(new String[][] { { "display", "flex" }, { "justifyContent", "space-between" },
|
||||
{ "alignItems", "center" }, { "padding", "20px 40px" } }));
|
||||
CSS.put("logo-1", createStyle(new String[][] { { "fontFamily", "cursive" }, { "fontSize", "20px" } }));
|
||||
CSS.put("nav-1", createStyle(new String[][] { { "display", "flex" }, { "gap", "20px" } }));
|
||||
CSS.put("button-join", createStyle(new String[][] { { "background", "black" }, { "color", "white" },
|
||||
{ "padding", "8px 16px" }, { "border", "none" }, { "borderRadius", "4px" } }));
|
||||
CSS.put("hero-1", createStyle(new String[][] { { "textAlign", "center" }, { "padding", "60px 20px" } }));
|
||||
CSS.put("hero-heading", createStyle(new String[][] { { "fontSize", "36px" }, { "fontWeight", "bold" } }));
|
||||
CSS.put("hero-paragraph", createStyle(new String[][] { { "margin", "20px auto" }, { "maxWidth", "600px" } }));
|
||||
CSS.put("hero-buttons", createStyle(new String[][] { { "marginTop", "20px" } }));
|
||||
CSS.put("button-signup", createStyle(new String[][] { { "padding", "10px 20px" }, { "background", "black" },
|
||||
{ "color", "white" }, { "marginRight", "10px" }, { "border", "none" } }));
|
||||
CSS.put("button-learn", createStyle(new String[][] { { "padding", "10px 20px" }, { "background", "white" },
|
||||
{ "border", "1px solid #ccc" } }));
|
||||
CSS.put("image-grid-1",
|
||||
createStyle(new String[][] { { "display", "grid" },
|
||||
{ "gridTemplateColumns", "repeat(auto-fill, minmax(200px, 1fr))" }, { "gap", "20px" },
|
||||
{ "padding", "40px" } }));
|
||||
CSS.put("tile", createStyle(new String[][] { { "background", "#eee" }, { "height", "150px" },
|
||||
{ "display", "flex" }, { "alignItems", "center" }, { "justifyContent", "center" } }));
|
||||
}
|
||||
|
||||
private static Map<String, String> createStyle(String[][] pairs) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (String[] pair : pairs) {
|
||||
map.put(pair[0], pair[1]);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void generateHtml(JSONObject node, StringBuilder html) {
|
||||
String type = node.optString("type");
|
||||
String ref = node.optString("ref");
|
||||
String tag = mapTypeToTag(type);
|
||||
|
||||
if (tag != null) {
|
||||
html.append("<").append(tag);
|
||||
|
||||
if (!ref.isEmpty() && CSS.containsKey(ref)) {
|
||||
html.append(" style=\\").append(convertStyle(CSS.get(ref))).append("\\\"");
|
||||
}
|
||||
|
||||
html.append(">");
|
||||
}
|
||||
|
||||
if (node.has("content")) {
|
||||
html.append(node.getString("content"));
|
||||
}
|
||||
|
||||
if (node.has("children")) {
|
||||
JSONArray children = node.getJSONArray("children");
|
||||
for (int i = 0; i < children.length(); i++) {
|
||||
generateHtml(children.getJSONObject(i), html);
|
||||
}
|
||||
}
|
||||
|
||||
if (tag != null) {
|
||||
html.append("</").append(tag).append(">");
|
||||
}
|
||||
}
|
||||
|
||||
private String mapTypeToTag(String type) {
|
||||
if ("page".equals(type))
|
||||
return null;
|
||||
if ("header".equals(type))
|
||||
return "header";
|
||||
if ("logo".equals(type) || "paragraph".equals(type))
|
||||
return "div";
|
||||
if ("nav".equals(type))
|
||||
return "nav";
|
||||
if ("link".equals(type))
|
||||
return "a";
|
||||
if ("button".equals(type))
|
||||
return "button";
|
||||
if ("button-group".equals(type))
|
||||
return "div";
|
||||
if ("hero-section".equals(type))
|
||||
return "section";
|
||||
if ("heading".equals(type))
|
||||
return "h1";
|
||||
if ("image-grid".equals(type))
|
||||
return "section";
|
||||
if ("image-tile".equals(type))
|
||||
return "div";
|
||||
return "div";
|
||||
}
|
||||
|
||||
private String convertStyle(Map<String, String> styleMap) {
|
||||
StringBuilder css = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : styleMap.entrySet()) {
|
||||
css.append(camelToKebab(entry.getKey())).append(": ").append(entry.getValue()).append("; ");
|
||||
}
|
||||
return css.toString().trim();
|
||||
}
|
||||
|
||||
private String camelToKebab(String str) {
|
||||
return str.replaceAll("([a-z])([A-Z]+)", "$1-$2").toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,560 @@
|
||||
package com.realnet.OpenAi.Services;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.realnet.utils.PortConstant;
|
||||
|
||||
@Service
|
||||
public class ScriptSrvice {
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
public void Createonefile(Integer prj_id, List<String> lineList, String workflow_model, Long Deployment_profile)
|
||||
throws IOException {
|
||||
|
||||
// Parsing Json data
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(workflow_model);
|
||||
JsonArray Array = element.getAsJsonArray();
|
||||
|
||||
for (JsonElement ar : Array) {
|
||||
|
||||
JsonObject obj = ar.getAsJsonObject();
|
||||
|
||||
JsonElement workflowvalue = obj.get("workflow");
|
||||
String value = workflowvalue.getAsString();
|
||||
|
||||
String tableid_url = PortConstant.BACKEND_PORTAL_DOMAIN
|
||||
+ "/token/fnd1/callingsureops/workflowlinebytable_id/" + value;
|
||||
Object body2 = GET(tableid_url).getBody();
|
||||
String workflow = callforline(body2);
|
||||
CreateFiles(prj_id, lineList, workflow, Deployment_profile);
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Creating files like yaml, shell SCript ,docker File
|
||||
|
||||
public ResponseEntity<?> CreateFiles(Integer prj_id, List<String> lineList, String workflow_model,
|
||||
Long Deployment_profile) throws IOException {
|
||||
|
||||
// Appending data to Sting builder object
|
||||
|
||||
HashMap<String, String> json = new HashMap<>();
|
||||
|
||||
String PRJ_NAME = lineList.get(0);
|
||||
String gitea_url = lineList.get(1);
|
||||
|
||||
// Parsing Json data
|
||||
|
||||
List<String> keys = new ArrayList<>();
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(workflow_model);
|
||||
JsonArray Array = element.getAsJsonArray();
|
||||
|
||||
int i = 1;
|
||||
for (JsonElement ar : Array) {
|
||||
JsonObject obj = ar.getAsJsonObject();
|
||||
Set<Map.Entry<String, JsonElement>> entries = obj.entrySet();
|
||||
for (Map.Entry<String, JsonElement> entry : entries) {
|
||||
// String key = entry.getKey();
|
||||
String value = entry.getValue().getAsString();
|
||||
keys.add(value);
|
||||
|
||||
if (value.equalsIgnoreCase("Shell Script")) {
|
||||
System.out.println("script data");
|
||||
script(prj_id, workflow_model, PRJ_NAME, gitea_url, Deployment_profile);
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (i == 1) {
|
||||
Createonefile(prj_id, lineList, workflow_model, Deployment_profile);
|
||||
|
||||
}
|
||||
|
||||
return new ResponseEntity<HashMap<String, String>>(json, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
// CREATE SCRIPT FILE
|
||||
|
||||
public void script(Integer prj_id, String workflow_model, String prj, String gitea_url, Long deployment_line_id)
|
||||
throws IOException {
|
||||
|
||||
// String file_text2 = "script_test" + addString + ".sh";
|
||||
|
||||
// ArrayList<Object> list = calldeploymentprofile(Deployment_profile);
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
String pROTOCOL = PortConstant.PROTOCOL;
|
||||
|
||||
ArrayList<Object> getdatafromgiturl = getdatafromgiturl(gitea_url);
|
||||
|
||||
ArrayList<Object> namelist = new ArrayList<>();
|
||||
ArrayList<Object> filepath_list = new ArrayList<>();
|
||||
String sureops_dir = projectPath + File.separator + "cns-portal/code-extractor/builders" + File.separator
|
||||
+ prj_id + File.separator + "index";
|
||||
|
||||
StringBuilder scriptdata = new StringBuilder();
|
||||
// StringBuilder scriptvalue = new StringBuilder();
|
||||
|
||||
List<String> keys = new ArrayList<>();
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(workflow_model);
|
||||
JsonArray Array = element.getAsJsonArray();
|
||||
|
||||
for (JsonElement ar : Array) {
|
||||
JsonObject obj = ar.getAsJsonObject();
|
||||
Set<Map.Entry<String, JsonElement>> entries = obj.entrySet();
|
||||
for (Map.Entry<String, JsonElement> entry : entries) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue().getAsString();
|
||||
keys.add(value);
|
||||
|
||||
if (key.equalsIgnoreCase("a_uri")) {
|
||||
String full_url = value + "/" + prj_id + "/" + deployment_line_id + "/" + prj + "/" + "build_app";
|
||||
ArrayList<Object> jsonlist = call_url_byjson(full_url);
|
||||
|
||||
String git_user = jsonlist.get(0).toString().replace("\"", "");
|
||||
list.add(git_user);
|
||||
|
||||
String git_password = jsonlist.get(1).toString().replace("\"", "");
|
||||
list.add(git_password);
|
||||
|
||||
String git_email = jsonlist.get(2).toString().replace("\"", "");
|
||||
list.add(git_email);
|
||||
|
||||
String dokr_username = jsonlist.get(3).toString().replace("\"", "");
|
||||
list.add(dokr_username);
|
||||
|
||||
String dokr_url = jsonlist.get(4).toString().replace("\"", "");
|
||||
list.add(dokr_url);
|
||||
|
||||
String dokr_pass = jsonlist.get(5).toString().replace("\"", "");
|
||||
list.add(dokr_pass);
|
||||
|
||||
String PRJ_NAME = jsonlist.get(6).toString().replace("\"", "");
|
||||
list.add(PRJ_NAME);
|
||||
|
||||
String MSG = jsonlist.get(7).toString().replace("\"", "");
|
||||
list.add(MSG);
|
||||
|
||||
String DOMAIN = jsonlist.get(8).toString().replace("\"", "");
|
||||
list.add(DOMAIN);
|
||||
|
||||
String REPO_NAME = jsonlist.get(9).toString().replace("\"", "");
|
||||
list.add(REPO_NAME);
|
||||
|
||||
String REPO_NAME_TO = jsonlist.get(10).toString().replace("\"", "");
|
||||
list.add(REPO_NAME_TO);
|
||||
|
||||
}
|
||||
|
||||
if (key.equals("destination")) {
|
||||
filepath_list.add(value);
|
||||
}
|
||||
if (key.equals("name")) {
|
||||
namelist.add(value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (JsonElement ar : Array) {
|
||||
JsonObject obj = ar.getAsJsonObject();
|
||||
|
||||
Set<Map.Entry<String, JsonElement>> entries = obj.entrySet();
|
||||
for (Map.Entry<String, JsonElement> entry : entries) {
|
||||
String key = entry.getKey();
|
||||
|
||||
String value = entry.getValue().getAsString();
|
||||
if (key.equalsIgnoreCase("script")) {
|
||||
|
||||
if (list.isEmpty()) {
|
||||
scriptdata.append(value);
|
||||
System.out.println(scriptdata);
|
||||
} else {
|
||||
|
||||
String replace = value.replace("<REPO_NAME>", list.get(9).toString().replace("\"", ""));
|
||||
String replace2 = replace.replace("<REPO_NAME_TO>", prj);
|
||||
|
||||
String replace3 = replace2.replace("<GITEA_USER>", list.get(0).toString().replace("\"", ""));
|
||||
|
||||
String replace4 = replace3.replace("<GITEA_PASS>", list.get(1).toString().replace("\"", ""));
|
||||
|
||||
String replace5 = replace4.replace("<GITEA_EMAIL>", list.get(2).toString().replace("\"", ""));
|
||||
|
||||
String replace6 = replace5.replace("<DOMAIN>", list.get(8).toString().replace("\"", ""));
|
||||
|
||||
String replace7 = replace6.replace("<DOCKER_USER>", list.get(3).toString().replace("\"", ""));
|
||||
|
||||
String replace8 = replace7.replace("<DOCKER_PASS>", list.get(5).toString().replace("\"", ""));
|
||||
|
||||
String replace9 = replace8.replace("<DOCKER_URL>", list.get(4).toString().replace("\"", ""));
|
||||
|
||||
String replace10 = replace9.replace("<SUREOPS_FOLDER>", sureops_dir);
|
||||
|
||||
String replace11 = replace10.replace("<PROTOCOL>", pROTOCOL);
|
||||
|
||||
// .replace("<GIT_PULL>", );
|
||||
|
||||
String finalreplace_value = replace11.replace("<MSG>",
|
||||
"\"" + list.get(7).toString().replace("\"", "") + "\"");
|
||||
|
||||
// for testing
|
||||
scriptdata.append(finalreplace_value);
|
||||
System.out.println("scriptdata make");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String file_text = null;
|
||||
|
||||
if (!namelist.isEmpty()) {
|
||||
file_text = namelist.get(0).toString().replace("\"", "") + ".sh";
|
||||
|
||||
} else {
|
||||
file_text = "copy_exec" + ".sh";
|
||||
}
|
||||
|
||||
// Creating Folder
|
||||
|
||||
String Path1 = null;
|
||||
String ref_path = null;
|
||||
|
||||
// when destination is not empty
|
||||
if (!filepath_list.isEmpty()) {
|
||||
String sureopspath_name = filepath_list.get(0).toString().replace("\"", "");
|
||||
|
||||
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();
|
||||
if (!mkdir) {
|
||||
System.out.println("folder not created");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
System.out.println(Path1);
|
||||
|
||||
File Dir2 = new File(Path1);
|
||||
if (!Dir2.exists()) {
|
||||
boolean mkdir = Dir2.mkdir();
|
||||
if (!mkdir) {
|
||||
System.out.println("folder not created");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// creating files
|
||||
// String dir2 = projectPath + "/yaml_files" + addString + "/" + file_text;
|
||||
String dir2 = Path1 + File.separator + file_text;
|
||||
|
||||
File file = new File(dir2);
|
||||
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
|
||||
Files.setPosixFilePermissions(file.toPath(), PosixFilePermissions.fromString("rwxrwxrwx"));
|
||||
|
||||
file.setExecutable(true);
|
||||
file.setReadable(true);
|
||||
file.setWritable(true);
|
||||
}
|
||||
System.out.println("file created successfully");
|
||||
System.out.println("file path : " + dir2);
|
||||
|
||||
FileWriter fw = new FileWriter(file.getAbsoluteFile());
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
bw.write(scriptdata.toString());
|
||||
bw.close();
|
||||
|
||||
String filepath = Path1;
|
||||
String filename = file_text;
|
||||
|
||||
// INSERT DATA IN JOB PRO FOR RUN SCRIPT
|
||||
// insertin_jobpro(prj_id, filename, filepath);
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
// CALL PROJECT PORTAL
|
||||
public List<String> callforproject(Object object) throws JsonProcessingException {
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(object);
|
||||
// System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object));// print
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
|
||||
String prj_name = obj.get("projectName").getAsString();
|
||||
list.add(prj_name);
|
||||
|
||||
String gitea_url = obj.get("gitea_url").getAsString();
|
||||
list.add(gitea_url);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public String callforline(Object object) throws JsonProcessingException {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(object);
|
||||
// System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object));// print
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
JsonElement workflowid = obj.get("model");
|
||||
System.out.println(workflowid);
|
||||
return workflowid.getAsString();
|
||||
}
|
||||
|
||||
public String callfortable(Object object) throws JsonProcessingException {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(object);
|
||||
// System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object));// print
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
JsonElement workflowid = obj.get("id");
|
||||
System.out.println(workflowid);
|
||||
return workflowid.getAsString();
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> GET(String get) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
ResponseEntity<Object> u = restTemplate.getForEntity(get, Object.class);
|
||||
|
||||
return u;
|
||||
|
||||
}
|
||||
|
||||
private HttpHeaders getHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
return headers;
|
||||
}
|
||||
|
||||
public ArrayList<Object> calldeploymentprofile(Long Deployment_profile) throws JsonProcessingException {
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
|
||||
String tableid_url = PortConstant.BACKEND_PORTAL_DOMAIN + "/token/fnd1/callingsureops/deplomentprofile_line/"
|
||||
+ Deployment_profile;
|
||||
Object body2 = GET(tableid_url).getBody();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(body2);
|
||||
// System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(body2));// print
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
|
||||
JsonElement git_user = obj.get("git_user");
|
||||
list.add(git_user);
|
||||
|
||||
JsonElement git_password = obj.get("git_password");
|
||||
list.add(git_password);
|
||||
|
||||
JsonElement git_email = obj.get("git_email");
|
||||
list.add(git_email);
|
||||
|
||||
System.out.println(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Object> call_url_byjson(String full_url) throws JsonProcessingException {
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
|
||||
Object body2 = GET(full_url).getBody();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(body2);
|
||||
// System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(body2));// print
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
|
||||
JsonElement git_user = obj.get("GITEA_USER");
|
||||
list.add(git_user);
|
||||
|
||||
JsonElement git_password = obj.get("GITEA_PASS");
|
||||
list.add(git_password);
|
||||
|
||||
JsonElement git_email = obj.get("GITEA_EMAIL");
|
||||
list.add(git_email);
|
||||
|
||||
JsonElement dokr_username = obj.get("DOCKER_USER");
|
||||
list.add(dokr_username);
|
||||
|
||||
JsonElement dokr_url = obj.get("DOCKER_URL");
|
||||
list.add(dokr_url);
|
||||
|
||||
JsonElement dokr_pass = obj.get("DOCKER_PASS");
|
||||
list.add(dokr_pass);
|
||||
|
||||
JsonElement PRJ_NAME = obj.get("PRJ_NAME");
|
||||
list.add(PRJ_NAME);
|
||||
|
||||
JsonElement MSG = obj.get("MSG");
|
||||
list.add(MSG);
|
||||
|
||||
JsonElement DOMAIN = obj.get("DOMAIN");
|
||||
list.add(DOMAIN);
|
||||
|
||||
JsonElement REPO_NAME = obj.get("REPO_NAME");
|
||||
list.add(REPO_NAME);
|
||||
|
||||
JsonElement REPO_NAME_TO = obj.get("REPO_NAME_TO");
|
||||
list.add(REPO_NAME_TO);
|
||||
|
||||
System.out.println(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Object> getdatafromgiturl(String str) throws JsonProcessingException {
|
||||
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
|
||||
int indexOf = str.indexOf("://");
|
||||
|
||||
// int indexOf2 = str.indexOf("/a");
|
||||
|
||||
int ordinalIndexOf = StringUtils.ordinalIndexOf(str, "/", 3);
|
||||
String domain = str.substring(indexOf + 3, ordinalIndexOf);
|
||||
|
||||
// String domain = str.substring(indexOf + 3, indexOf2);
|
||||
|
||||
System.out.println("\n" + domain);
|
||||
list.add(domain);
|
||||
|
||||
int namelast = str.lastIndexOf("/");
|
||||
int namelast2 = str.lastIndexOf(".");
|
||||
String name = str.substring(namelast + 1, namelast2);
|
||||
System.out.println(name);
|
||||
list.add(name);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public ResponseEntity<?> geterror() {
|
||||
return new ResponseEntity<>("file not created", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
public void insertin_jobpro(Integer prj_id, String filename, String filepath) throws JsonProcessingException {
|
||||
|
||||
Map<String, String> jobdata = new HashMap<String, String>();
|
||||
// jobdata.put("parameters", builder.toString());
|
||||
jobdata.put("url",
|
||||
PortConstant.SUREOPS_DOMAIN + "/sureops/runScript?filepath=" + filepath + "&filename=" + filename);
|
||||
jobdata.put("method", "GET");
|
||||
jobdata.put("connection_name", "jobprtal");
|
||||
jobdata.put("createdBy", "2022");
|
||||
jobdata.put("updatedBy", "2022");
|
||||
jobdata.put("job_type", "CreatesureprjPrj");
|
||||
jobdata.put("ref", prj_id.toString());
|
||||
System.out.println(jobdata);
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String jobprourl = PortConstant.JOBPRO_DOMAIN + "/jobpro/pipiline";
|
||||
HttpHeaders headers = getHeaders();
|
||||
HttpEntity<Object> request = new HttpEntity<Object>(jobdata, headers);
|
||||
ResponseEntity<Object> res1 = restTemplate.postForEntity(jobprourl, request, Object.class);
|
||||
if (res1.getStatusCodeValue() == 200) {
|
||||
System.out.println("script runner data inserted in job pro");
|
||||
}
|
||||
// System.out.println(res1.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,170 @@
|
||||
package com.realnet.OpenAi.Services;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import com.realnet.utils.PortConstant;
|
||||
|
||||
@Service
|
||||
public class Script_Making {
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
@Autowired
|
||||
private ScriptSrvice sureservice;
|
||||
|
||||
// Creating files like yaml, shell SCript ,docker File
|
||||
|
||||
public ResponseEntity<?> CreateFiles(Integer prj_id,String workflow_id,long Deployment_profile)
|
||||
throws IOException {
|
||||
|
||||
// String table_name = tble.replaceAll(" ", "_").toLowerCase();
|
||||
|
||||
|
||||
String prj_url = PortConstant.BACKEND_PORTAL_DOMAIN
|
||||
+ "/token/fnd1/callingsureops/getproject/" + prj_id;
|
||||
|
||||
// get project
|
||||
ResponseEntity<Object> prj = GET(prj_url);
|
||||
Object prj_body = prj.getBody();
|
||||
List<String> lineList = callforproject(prj_body);
|
||||
|
||||
|
||||
|
||||
// get workflowline
|
||||
String line_url = PortConstant.BACKEND_PORTAL_DOMAIN
|
||||
+ "/token/fnd1/callingsureops/workflowline/" + workflow_id;
|
||||
ResponseEntity<Object> get = GET(line_url);
|
||||
Object body = get.getBody();
|
||||
String workflow_model = callforline(body);
|
||||
|
||||
String PRJ_NAME = lineList.get(0);
|
||||
String gitea_url = lineList.get(1);
|
||||
|
||||
|
||||
// Parsing Json data
|
||||
|
||||
JsonParser parser1 = new JsonParser();
|
||||
JsonElement element1 = parser1.parse(workflow_model);
|
||||
JsonArray Array1 = element1.getAsJsonArray();
|
||||
|
||||
int i = 1;
|
||||
for (JsonElement ar1 : Array1) {
|
||||
JsonObject obj1 = ar1.getAsJsonObject();
|
||||
// System.out.println(obj1);
|
||||
Set<Map.Entry<String, JsonElement>> entries = obj1.entrySet();
|
||||
for (Map.Entry<String, JsonElement> entry : entries) {
|
||||
String key = entry.getKey();
|
||||
String value1 = entry.getValue().getAsString();
|
||||
|
||||
if (value1.equalsIgnoreCase("Shell Script")) {
|
||||
System.out.println("script data");
|
||||
sureservice.script(prj_id, workflow_model, PRJ_NAME, gitea_url,
|
||||
Deployment_profile);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i == 1) {
|
||||
|
||||
sureservice.Createonefile(prj_id, lineList, workflow_model, Deployment_profile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return new ResponseEntity<>(new EntityResponse("script file created"), HttpStatus.CREATED);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<String> callforproject(Object object) throws JsonProcessingException {
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(object);
|
||||
// System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object));// print
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
|
||||
String prj_name = obj.get("projectName").getAsString();
|
||||
list.add(prj_name);
|
||||
|
||||
String gitea_url = obj.get("gitea_url").getAsString();
|
||||
list.add(gitea_url);
|
||||
|
||||
String prj_id = obj.get("id").getAsString();
|
||||
list.add(prj_id);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public String callforline(Object object) throws JsonProcessingException {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(object);
|
||||
// System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object));// print
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
JsonElement workflowid = obj.get("model");
|
||||
// System.out.println(workflowid);
|
||||
return workflowid.getAsString();
|
||||
}
|
||||
|
||||
public String callfortable(Object object) throws JsonProcessingException {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String str = mapper.writeValueAsString(object);
|
||||
// System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object));// print
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonElement element = parser.parse(str);
|
||||
|
||||
JsonObject obj = element.getAsJsonObject();
|
||||
JsonElement workflowid = obj.get("id");
|
||||
// System.out.println(workflowid);
|
||||
return workflowid.getAsString();
|
||||
}
|
||||
|
||||
public ResponseEntity<Object> GET(String get) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
ResponseEntity<Object> u = restTemplate.getForEntity(get, Object.class);
|
||||
|
||||
return u;
|
||||
|
||||
}
|
||||
|
||||
private HttpHeaders getHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE);
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
return headers;
|
||||
}
|
||||
|
||||
}
|
||||
@ -19,7 +19,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.realnet.utils.Port_Constant;
|
||||
import com.realnet.utils.PortConstant;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -116,7 +116,7 @@ public class EmailService {
|
||||
|
||||
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(queryParams, headers);
|
||||
|
||||
String apiUrl2 = Port_Constant.SURE_SETU_DOMAIN
|
||||
String apiUrl2 = PortConstant.SURE_SETU_DOMAIN
|
||||
+ "/token/Surecommunication/communication/jobtable/Com_jobTable"; // Replace with the
|
||||
// actual API URL
|
||||
|
||||
|
||||
@ -371,9 +371,9 @@ public class SessionController {
|
||||
public ResponseEntity<?> resendotp(@RequestParam String email) {
|
||||
|
||||
AppUser user = userService.findUserByEmail(email);
|
||||
if (user == null) {
|
||||
return ResponseEntity.badRequest().body(new MessageResponse(email + " not exist"));
|
||||
} else {
|
||||
// if (user == null) {
|
||||
// return ResponseEntity.badRequest().body(new MessageResponse(email + " not exist"));
|
||||
// } else {
|
||||
// Random random = new Random();
|
||||
SecureRandom random = new SecureRandom();
|
||||
|
||||
@ -383,7 +383,7 @@ public class SessionController {
|
||||
String url = String.valueOf(otp);
|
||||
emailService.sendEmail(email, subject, url);
|
||||
return new ResponseEntity<>(new EntityResponse("resend Otp send successfully"), HttpStatus.OK);
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ import com.realnet.users.repository1.AppUserRepository;
|
||||
import com.realnet.users.repository1.passwordTokenRepository;
|
||||
import com.realnet.users.response.MessageResponse;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.utils.Port_Constant;
|
||||
import com.realnet.utils.PortConstant;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -210,7 +210,7 @@ public class UserController {
|
||||
|
||||
String em = user.getEmail();
|
||||
String subject = "Pass reset";
|
||||
String url = "http://" + Port_Constant.LOCAL_HOST + ":" + Port_Constant.FRONTEND_PORT_9191
|
||||
String url = "http://" + PortConstant.LOCAL_HOST + ":" + PortConstant.FRONTEND_PORT_9191
|
||||
+ "/#/forgotresetpassword/" + token;
|
||||
// String url = "http://surecns.ml:30165/#/forgotresetpassword/" + token;
|
||||
// String url = "http://localhost:9191/api" + "/resources/savePassword/" + token;
|
||||
|
||||
@ -44,7 +44,7 @@ import com.realnet.users.repository1.AppUserRepository;
|
||||
import com.realnet.users.repository1.AppUserRoleRepository;
|
||||
import com.realnet.users.response.MessageResponse;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.utils.Port_Constant;
|
||||
import com.realnet.utils.PortConstant;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@ -203,7 +203,7 @@ public class AppUserController {
|
||||
|
||||
String subject = "add user";
|
||||
|
||||
String url = Port_Constant.FRONTEND_PORTAL_DOMAIN + "/#/adduser/" + token;
|
||||
String url = PortConstant.FRONTEND_PORTAL_DOMAIN + "/#/adduser/" + token;
|
||||
// String url = "http://localhost:4200/#/adduser/" +token;
|
||||
// String url = "http://surecns.ml:30165/#/adduser/" +token;
|
||||
// String url = "http://" + Port_Constant.LOCAL_HOST + ":" + Port_Constant.BACKEND_PORT_9191 + "/api"
|
||||
@ -281,7 +281,7 @@ public class AppUserController {
|
||||
userService.addguestviaadmin(appUser, token, email, account_id);
|
||||
|
||||
// String subject = "add guest";
|
||||
String url = Port_Constant.FRONTEND_PORTAL_DOMAIN + "/#/addguest/" + token;
|
||||
String url = PortConstant.FRONTEND_PORTAL_DOMAIN + "/#/addguest/" + token;
|
||||
|
||||
// String url = "http://localhost:4200/#/addguest/" +token;
|
||||
// String url = "http://surecns.ml:30165/#/addguest/" +token;
|
||||
|
||||
@ -628,7 +628,8 @@ public class AppUserServiceImpl implements UserDetailsService, AppUserService {
|
||||
AppUser user = findUserByEmail(email);
|
||||
|
||||
user.setRandom_no(String.valueOf(otp));
|
||||
|
||||
user.setUsername(email);
|
||||
user.setEmail(email);
|
||||
appUserRepository.save(user);
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,100 @@
|
||||
package com.realnet.utils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
public class PortConstant {
|
||||
|
||||
public final static String LOCAL_HOST = "43.205.154.152";
|
||||
public final static String FRONTEND_PORT_9191 = "30165";
|
||||
|
||||
public final static String GITEA_IP_ADDRESS = "try.gitea";
|
||||
public final static String GITEA_PORT = "io";
|
||||
public final static String SUREVAULT_DEPLOYMENT_TYPE = "32";
|
||||
|
||||
public static String BACKEND_PORTAL_DOMAIN;
|
||||
public static String FRONTEND_PORTAL_DOMAIN;
|
||||
public static String SUREOPS_DOMAIN;
|
||||
public static String JOBPRO_DOMAIN;
|
||||
public static String APP_BUILD_DOMAIN;
|
||||
public static String SURE_SERVE_DOMAIN;
|
||||
public static String SURE_SETU_DOMAIN;
|
||||
public static String FARM_SCRIPT_RUNNER_DOMAIN;
|
||||
public static String DEPLOYMENT_TYPE;
|
||||
public static String FARM_IP_ADDRESS_online;
|
||||
public static String CONTROL_CENTRE_PORT;
|
||||
public static String CONTROL_CENTRE_MASTER_PORT;
|
||||
public static String CONTROL_CENTRE_MASTER_IP;
|
||||
public static String LOCALHOST;
|
||||
public static String SUREOPS_LOCALHOST;
|
||||
public static String APPBUILD_LOCALHOST;
|
||||
public static String SURE_VAULT_DOMAIN;
|
||||
public static String GITEA_DOMAIN;
|
||||
public static String GITEA_USERNAME;
|
||||
public static String PROTOCOL;
|
||||
|
||||
// SETTER
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
// Type ('dev', 'prod')
|
||||
private final String type = "dev";
|
||||
|
||||
@Value("${BACKEND_PORTAL_DOMAIN}")
|
||||
private String backendPortalDomain;
|
||||
|
||||
// @PostConstruct is used to make API calls and initialize the constants for the
|
||||
// entire application during startup.
|
||||
@PostConstruct
|
||||
public void initializeConstantsFromApi() {
|
||||
|
||||
|
||||
|
||||
if (backendPortalDomain != null) {
|
||||
BACKEND_PORTAL_DOMAIN = backendPortalDomain;
|
||||
System.out.println("Fetched BACKEND_PORTAL_DOMAIN from properties file: " + backendPortalDomain);
|
||||
|
||||
FRONTEND_PORTAL_DOMAIN = getUrlFromApi(backendPortalDomain, "Frontend_portal_domain");
|
||||
System.out.println("FRONTEND_PORTAL_DOMAIN: " + FRONTEND_PORTAL_DOMAIN);
|
||||
SUREOPS_DOMAIN = getUrlFromApi(backendPortalDomain, "SUREOPS_DOMAIN");
|
||||
JOBPRO_DOMAIN = getUrlFromApi(backendPortalDomain, "JOBPRO_DOMAIN");
|
||||
APP_BUILD_DOMAIN = getUrlFromApi(backendPortalDomain, "APP_BUILD_DOMAIN");
|
||||
SURE_SERVE_DOMAIN = getUrlFromApi(backendPortalDomain, "SURE_SERVE_DOMAIN");
|
||||
SURE_SETU_DOMAIN = getUrlFromApi(backendPortalDomain, "SURE_SETU_DOMAIN");
|
||||
FARM_SCRIPT_RUNNER_DOMAIN = getUrlFromApi(backendPortalDomain, "FARM_SCRIPT_RUNNER_DOMAIN");
|
||||
DEPLOYMENT_TYPE = getUrlFromApi(backendPortalDomain, "DEPLOYMENT_TYPE");
|
||||
FARM_IP_ADDRESS_online = getUrlFromApi(backendPortalDomain, "FARM_IP_ADDRESS_online");
|
||||
CONTROL_CENTRE_PORT = getUrlFromApi(backendPortalDomain, "CONTROL_CENTRE_PORT");
|
||||
CONTROL_CENTRE_MASTER_PORT = getUrlFromApi(backendPortalDomain, "CONTROL_CENTRE_MASTER_PORT");
|
||||
CONTROL_CENTRE_MASTER_IP = getUrlFromApi(backendPortalDomain, "CONTROL_CENTRE_MASTER_IP");
|
||||
LOCALHOST = getUrlFromApi(backendPortalDomain, "Localhost");
|
||||
SUREOPS_LOCALHOST = getUrlFromApi(backendPortalDomain, "SUREOPS_LOCALHOST");
|
||||
APPBUILD_LOCALHOST = getUrlFromApi(backendPortalDomain, "APPBUILD_LOCALHOST");
|
||||
SURE_VAULT_DOMAIN = getUrlFromApi(backendPortalDomain, "SURE_VAULT_DOMAIN");
|
||||
GITEA_DOMAIN = getUrlFromApi(backendPortalDomain, "GITEA_DOMAIN");
|
||||
GITEA_USERNAME = getUrlFromApi(backendPortalDomain, "GITEA_USERNAME");
|
||||
PROTOCOL = getUrlFromApi(backendPortalDomain, "PROTOCOL");
|
||||
|
||||
} else {
|
||||
System.out.println("Error: BACKEND_PORTAL_DOMAIN could not be fetched.");
|
||||
}
|
||||
}
|
||||
|
||||
private String getUrlFromApi(String backendPortalDomain, String serviceName) {
|
||||
try {
|
||||
// Use the provided backendPortalDomain to construct the full URL
|
||||
String baseUrl = backendPortalDomain + "/token/HealthCheckup/DeploymentUrl/Deployment_url/";
|
||||
String url = baseUrl + type + "/" + serviceName;
|
||||
|
||||
String Object = restTemplate.getForObject(url, String.class); // Fetch URL from API
|
||||
|
||||
System.out.println(serviceName + " : " + Object);
|
||||
return Object;
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error fetching URL for " + serviceName + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package com.realnet.utils;
|
||||
|
||||
public class Port_Constant {
|
||||
|
||||
public final static String LOCAL_HOST = "43.205.154.152";
|
||||
public final static String FRONTEND_PORT_9191 = "30165";
|
||||
public static String SURE_SETU_DOMAIN = "http://34.198.218.30:30173";
|
||||
|
||||
public final static String GITEA_IP_ADDRESS = "try.gitea";
|
||||
public final static String GITEA_PORT = "io";
|
||||
public final static String SURE_VAULT_DOMAIN = "http://54.92.243.148:30150";
|
||||
public final static String SUREVAULT_DEPLOYMENT_TYPE = "32";
|
||||
public static String FRONTEND_PORTAL_DOMAIN;
|
||||
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package com.realnet.vpspack.Controllers;
|
||||
|
||||
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 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 com.realnet.vpspack.Entity.SiteBuilder;
|
||||
import com.realnet.vpspack.Services.SiteBuilderService;
|
||||
|
||||
@RequestMapping(value = "/SiteTree")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class SiteBuilderController {
|
||||
@Autowired
|
||||
private SiteBuilderService Service;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
@PostMapping("/SiteTree")
|
||||
public SiteBuilder Savedata(@RequestBody SiteBuilder data) {
|
||||
SiteBuilder save = Service.Savedata(data);
|
||||
|
||||
System.out.println("data saved..." + save);
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
@PutMapping("/SiteTree/{id}")
|
||||
public SiteBuilder update(@RequestBody SiteBuilder data, @PathVariable Integer id) {
|
||||
SiteBuilder update = Service.update(data, id);
|
||||
System.out.println("data update..." + update);
|
||||
return update;
|
||||
}
|
||||
|
||||
// get all with pagination
|
||||
@GetMapping("/SiteTree/getall/page")
|
||||
public Page<SiteBuilder> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "size", required = false) Integer size) {
|
||||
Pageable paging = PageRequest.of(page, size);
|
||||
Page<SiteBuilder> get = Service.getAllWithPagination(paging);
|
||||
|
||||
return get;
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/SiteTree")
|
||||
public List<SiteBuilder> getdetails() {
|
||||
List<SiteBuilder> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
// get all without authentication
|
||||
|
||||
@GetMapping("/token/SiteTree")
|
||||
public List<SiteBuilder> getallwioutsec() {
|
||||
List<SiteBuilder> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
|
||||
@GetMapping("/SiteTree/{id}")
|
||||
public SiteBuilder getdetailsbyId(@PathVariable Integer id) {
|
||||
SiteBuilder get = Service.getdetailsbyId(id);
|
||||
return get;
|
||||
}
|
||||
|
||||
@DeleteMapping("/SiteTree/{id}")
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Integer id) {
|
||||
Service.delete_by_id(id);
|
||||
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package com.realnet.vpspack.Entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import com.realnet.WhoColumn.Entity.Extension;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class SiteBuilder extends Extension {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Column(length = 2000)
|
||||
private String description;
|
||||
|
||||
private boolean active;
|
||||
|
||||
@Column(length = 10000)
|
||||
private String model;
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.realnet.vpspack.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.vpspack.Entity.SiteBuilder;
|
||||
|
||||
@Repository
|
||||
public interface SiteBuilderRepository extends JpaRepository<SiteBuilder, Integer> {
|
||||
|
||||
@Query(value = "select * from site_builder where created_by=?1", nativeQuery = true)
|
||||
List<SiteBuilder> findAll(Long creayedBy);
|
||||
|
||||
@Query(value = "select * from site_builder where created_by=?1", nativeQuery = true)
|
||||
Page<SiteBuilder> findAll(Pageable page, Long creayedBy);
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
package com.realnet.vpspack.Services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.realnet.realm.Entity.Realm;
|
||||
import com.realnet.realm.Services.RealmService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.vpspack.Entity.SiteBuilder;
|
||||
import com.realnet.vpspack.Repository.SiteBuilderRepository;
|
||||
|
||||
@Service
|
||||
public class SiteBuilderService {
|
||||
@Autowired
|
||||
private SiteBuilderRepository Repository;
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
@Autowired
|
||||
private RealmService realmService;
|
||||
|
||||
public SiteBuilder Savedata(SiteBuilder data) {
|
||||
|
||||
data.setUpdatedBy(getUser().getUserId());
|
||||
data.setCreatedBy(getUser().getUserId());
|
||||
data.setAccountId(getUser().getAccount().getAccount_id());
|
||||
SiteBuilder save = Repository.save(data);
|
||||
return save;
|
||||
}
|
||||
|
||||
// get all with pagination
|
||||
public Page<SiteBuilder> getAllWithPagination(Pageable page) {
|
||||
return Repository.findAll(page, getUser().getUserId());
|
||||
}
|
||||
|
||||
public List<SiteBuilder> getdetails() {
|
||||
List<Realm> realm = realmService.findByUserId(getUser().getUserId());
|
||||
List<SiteBuilder> all = Repository.findAll(getUser().getUserId());
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
public SiteBuilder getdetailsbyId(Integer id) {
|
||||
return Repository.findById(id).get();
|
||||
}
|
||||
|
||||
public void delete_by_id(Integer id) {
|
||||
Repository.deleteById(id);
|
||||
}
|
||||
|
||||
public SiteBuilder update(SiteBuilder data, Integer id) {
|
||||
SiteBuilder old = Repository.findById(id).get();
|
||||
|
||||
if (data.getName() != null) {
|
||||
old.setName(data.getName());
|
||||
}
|
||||
|
||||
if (data.getDescription() != null) {
|
||||
old.setDescription(data.getDescription());
|
||||
}
|
||||
|
||||
if (data.getModel() != null) {
|
||||
old.setModel(data.getModel());
|
||||
}
|
||||
|
||||
// isActive is boolean, use Boolean wrapper to check null safety
|
||||
if (data.isActive() != old.isActive()) {
|
||||
old.setActive(data.isActive());
|
||||
}
|
||||
|
||||
old.setUpdatedBy(getUser().getUserId());
|
||||
|
||||
final SiteBuilder test = Repository.save(old);
|
||||
return test;
|
||||
}
|
||||
|
||||
public AppUser getUser() {
|
||||
AppUser user = userService.getLoggedInUser();
|
||||
return user;
|
||||
|
||||
}
|
||||
}
|
||||
@ -96,3 +96,6 @@ app.oauth2.authorizedRedirectUris=http://localhost:8081/oauth2/redirect,myandroi
|
||||
|
||||
projectPath=@project.basedir@
|
||||
angularProjectPath=@project.basedir@/webui
|
||||
|
||||
|
||||
BACKEND_PORTAL_DOMAIN=http://157.66.191.31:30166
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user