dlf
This commit is contained in:
parent
0acbf9b008
commit
0137a30e7b
@ -4,13 +4,20 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.realnet.OpenAi.Services.HtmlBuilder4;
|
||||
import com.realnet.OpenAi.Services.HtmlGenerTorService;
|
||||
import com.realnet.dlf.Entity.Design_lbrary;
|
||||
import com.realnet.dlf.Services.Design_lbraryService;
|
||||
import com.realnet.dlf.Services.HtmlService;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
|
||||
@ -21,6 +28,9 @@ public class HtmlGeneratorController {
|
||||
@Autowired
|
||||
private HtmlGenerTorService htmlGenerTorService;
|
||||
|
||||
@Autowired
|
||||
private Design_lbraryService designLibraryService;
|
||||
|
||||
@PostMapping
|
||||
public String generateHtmlFromJson(@RequestBody String jsonBody) {
|
||||
String json = htmlGenerTorService.generateHtmlFromJson(jsonBody);
|
||||
@ -56,4 +66,78 @@ public class HtmlGeneratorController {
|
||||
return ResponseEntity.status(500).body("⚠️ Failed to generate HTML due to server error.");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/generate/id/{id}")
|
||||
public ResponseEntity<?> generatehtml(@PathVariable int id) throws JsonMappingException, JsonProcessingException {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
Design_lbrary lbrary = designLibraryService.getdetailsbyId(id);
|
||||
String htmljson = lbrary.getHtmljson();
|
||||
Object jsonStructure = objectMapper.readValue(htmljson, Object.class);
|
||||
|
||||
try {
|
||||
// Object jsonStructure = request.get("jsonStructure");
|
||||
|
||||
if (jsonStructure == null) {
|
||||
return ResponseEntity.badRequest().body("Missing 'jsonStructure' in request.");
|
||||
}
|
||||
|
||||
// String html = HtmlBuilder4.buildHtml(jsonStructure);
|
||||
String html = HtmlService.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.");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/generate/html/id/{id}")
|
||||
public ResponseEntity<?> generatehtmlwithcss(@PathVariable int id)
|
||||
throws JsonMappingException, JsonProcessingException {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
Design_lbrary lbrary = designLibraryService.getdetailsbyId(id);
|
||||
String htmljson = lbrary.getHtmljson();
|
||||
String css = lbrary.getCss();
|
||||
|
||||
try {
|
||||
if (htmljson == null || htmljson.trim().isEmpty()) {
|
||||
return ResponseEntity.badRequest().body("Missing 'htmljson' in request.");
|
||||
}
|
||||
|
||||
// Convert JSON string to object (Map/List)
|
||||
Object jsonStructure = objectMapper.readValue(htmljson, Object.class);
|
||||
|
||||
// Generate inner body HTML
|
||||
String bodyHtml = HtmlService.buildHtml(jsonStructure);
|
||||
|
||||
if (bodyHtml.equalsIgnoreCase("<div></div>")) {
|
||||
bodyHtml = "<div>Empty Data</div>";
|
||||
|
||||
}
|
||||
|
||||
// Build full HTML page
|
||||
// StringBuilder finalHtml = new StringBuilder();
|
||||
// finalHtml.append("<!DOCTYPE html>\n");
|
||||
// finalHtml.append("<html lang=\"en\">\n");
|
||||
// finalHtml.append("<head>\n");
|
||||
// finalHtml.append(" <meta charset=\"UTF-8\">\n");
|
||||
// finalHtml.append(" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n");
|
||||
// finalHtml.append(" <title>Generated Page</title>\n");
|
||||
// finalHtml.append(" <style>\n").append(css).append("\n </style>\n");
|
||||
// finalHtml.append("</head>\n");
|
||||
// finalHtml.append("<body>\n");
|
||||
// finalHtml.append(bodyHtml).append("\n");
|
||||
// finalHtml.append("</body>\n");
|
||||
// finalHtml.append("</html>");
|
||||
|
||||
return ResponseEntity.ok(new EntityResponse(bodyHtml.toString()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseEntity.status(500).body("⚠️ Failed to generate HTML due to server error.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,10 @@ public class HtmlBuilder {
|
||||
// TYPE_RENDERERS.put("cta-block", HtmlBuilder::renderCtaBlock);
|
||||
|
||||
// <TYPE_RENDER>
|
||||
TYPE_RENDERERS.put("Navbar 6", HtmlBuilder::renderHeader);
|
||||
|
||||
TYPE_RENDERERS.put("header", HtmlBuilder::renderHeader);
|
||||
|
||||
// TYPE_RENDERERS.put("Navbar 6", HtmlBuilder::renderHeader);
|
||||
|
||||
TYPE_RENDERERS.put(" Testimonial Section 6", HtmlBuilder::renderTestimonialSection);
|
||||
|
||||
@ -184,51 +187,118 @@ public class HtmlBuilder {
|
||||
}
|
||||
|
||||
// <METHOD_RENDER>
|
||||
public static String renderHeader(Map<String, Object> data) {
|
||||
|
||||
private static String renderHeader(Map<String, Object> data) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
String clazz = getString(data, "class", "mega-navbar");
|
||||
|
||||
html.append("<header id=\"navbar-1\">");
|
||||
// Safely cast children list
|
||||
List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
|
||||
html.append("<header class=\"").append(clazz).append("\">");
|
||||
|
||||
if (children != null) {
|
||||
// Logo
|
||||
children.stream().filter(child -> "logo".equals(child.get("type"))).findFirst().ifPresent(logo -> {
|
||||
String logoContent = (String) logo.get("content");
|
||||
html.append("<div id=\"logo-1\">").append(logoContent).append("</div>");
|
||||
});
|
||||
|
||||
// Navigation
|
||||
children.stream().filter(child -> "nav".equals(child.get("type"))).findFirst().ifPresent(nav -> {
|
||||
html.append("<nav id=\"nav-1\">");
|
||||
List<Map<String, Object>> links = (List<Map<String, Object>>) nav.get("children");
|
||||
if (links != null) {
|
||||
links.forEach(link -> {
|
||||
String linkText = (String) link.get("content");
|
||||
html.append("<a class=\"link\" href=\"#\">").append(linkText).append("</a>");
|
||||
});
|
||||
}
|
||||
html.append("</nav>");
|
||||
});
|
||||
}
|
||||
|
||||
// Button
|
||||
List<Map<String, Object>> childrens = (List<Map<String, Object>>) data.get("children");
|
||||
Map<String, Object> button = null;
|
||||
if (childrens != null) {
|
||||
button = childrens.stream().filter(child -> "button".equals(child.get("type"))).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
if (button != null) {
|
||||
String buttonText = (String) ((Map<String, Object>) button).get("content");
|
||||
html.append("<button id=\"join-btn\">").append(buttonText).append("</button>");
|
||||
List<Map<String, Object>> children = getChildren(data);
|
||||
for (Map<String, Object> child : children) {
|
||||
String type = getString(child, "type", "");
|
||||
switch (type) {
|
||||
case "div":
|
||||
html.append(wrapTag("div", getString(child, "class"), getText(child, "content", "")));
|
||||
break;
|
||||
case "nav":
|
||||
html.append(renderNavBar(child));
|
||||
break;
|
||||
case "button":
|
||||
html.append(wrapTag("button", getString(child, "class"), getText(child, "content", "")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
html.append("</header>");
|
||||
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String wrapTag(String tag, String clazz, String content) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
html.append("<").append(tag);
|
||||
if (clazz != null && !clazz.isEmpty()) {
|
||||
html.append(" class=\"").append(clazz).append("\"");
|
||||
}
|
||||
html.append(">").append(content != null ? content : "").append("</").append(tag).append(">");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private static String getText(Map<String, Object> data, String key, String defaultValue) {
|
||||
if (data == null || key == null)
|
||||
return defaultValue;
|
||||
Object value = data.get(key);
|
||||
return (value instanceof String) ? (String) value : defaultValue;
|
||||
}
|
||||
|
||||
private static String renderNavBar(Map<String, Object> data) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
String clazz = getString(data, "class", "nav-1");
|
||||
|
||||
html.append("<nav class=\"").append(clazz).append("\"><ul>");
|
||||
|
||||
List<Map<String, Object>> children = getChildren(data);
|
||||
for (Map<String, Object> item : children) {
|
||||
String content = getText(item, "content", "");
|
||||
String itemType = getString(item, "type", "");
|
||||
|
||||
if ("dropdown".equals(itemType)) {
|
||||
html.append("<li class=\"dropdown\">").append("<a href=\"#\">").append(content).append("</a>")
|
||||
.append("</li>");
|
||||
} else {
|
||||
html.append("<li><a href=\"#\">").append(content).append("</a></li>");
|
||||
}
|
||||
}
|
||||
|
||||
html.append("</ul></nav>");
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
// public static String renderHeader(Map<String, Object> data) {
|
||||
// StringBuilder html = new StringBuilder();
|
||||
//
|
||||
// html.append("<header id=\"navbar-1\">");
|
||||
// // Safely cast children list
|
||||
// List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
|
||||
//
|
||||
// if (children != null) {
|
||||
// // Logo
|
||||
// children.stream().filter(child -> "logo".equals(child.get("type"))).findFirst().ifPresent(logo -> {
|
||||
// String logoContent = (String) logo.get("content");
|
||||
// html.append("<div id=\"logo-1\">").append(logoContent).append("</div>");
|
||||
// });
|
||||
//
|
||||
// // Navigation
|
||||
// children.stream().filter(child -> "nav".equals(child.get("type"))).findFirst().ifPresent(nav -> {
|
||||
// html.append("<nav id=\"nav-1\">");
|
||||
// List<Map<String, Object>> links = (List<Map<String, Object>>) nav.get("children");
|
||||
// if (links != null) {
|
||||
// links.forEach(link -> {
|
||||
// String linkText = (String) link.get("content");
|
||||
// html.append("<a class=\"link\" href=\"#\">").append(linkText).append("</a>");
|
||||
// });
|
||||
// }
|
||||
// html.append("</nav>");
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// // Button
|
||||
// List<Map<String, Object>> childrens = (List<Map<String, Object>>) data.get("children");
|
||||
// Map<String, Object> button = null;
|
||||
// if (childrens != null) {
|
||||
// button = childrens.stream().filter(child -> "button".equals(child.get("type"))).findFirst().orElse(null);
|
||||
// }
|
||||
//
|
||||
// if (button != null) {
|
||||
// String buttonText = (String) ((Map<String, Object>) button).get("content");
|
||||
// html.append("<button id=\"join-btn\">").append(buttonText).append("</button>");
|
||||
// }
|
||||
//
|
||||
// html.append("</header>");
|
||||
//
|
||||
// return html.toString();
|
||||
// }
|
||||
|
||||
public static String renderTestimonialSection() {
|
||||
StringBuilder html = new StringBuilder();
|
||||
|
||||
|
||||
@ -104,4 +104,41 @@ public class Design_lbraryController {
|
||||
System.out.println(" all files build..");
|
||||
}
|
||||
|
||||
// GET LINE BY header id, operation type, field type
|
||||
@GetMapping("/Design_lbrary/random")
|
||||
public ResponseEntity<?> getflflinerandom(@RequestParam String operationType, @RequestParam String fieldType) {
|
||||
Design_lbrary flf_line = designLibraryService.getflflinerandom(operationType, fieldType);
|
||||
|
||||
if (flf_line == null) {
|
||||
|
||||
return new ResponseEntity<>("not found", HttpStatus.EXPECTATION_FAILED);
|
||||
}
|
||||
|
||||
return new ResponseEntity<Design_lbrary>(flf_line, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/Design_lbrary/unique")
|
||||
public ResponseEntity<?> getflfline(@RequestParam String operationType, @RequestParam String fieldType) {
|
||||
Design_lbrary flf_line = designLibraryService.getLinestraight(operationType, fieldType);
|
||||
|
||||
if (flf_line == null) {
|
||||
|
||||
return new ResponseEntity<>("not found", HttpStatus.EXPECTATION_FAILED);
|
||||
}
|
||||
|
||||
return new ResponseEntity<Design_lbrary>(flf_line, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/Design_lbrary/list/template")
|
||||
public ResponseEntity<?> listOfTemplate(@RequestParam String operationType, @RequestParam String fieldType) {
|
||||
List<Design_lbrary> flf_line = designLibraryService.listOfTemplate(operationType, fieldType);
|
||||
|
||||
if (flf_line == null) {
|
||||
|
||||
return new ResponseEntity<>("not found", HttpStatus.EXPECTATION_FAILED);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(flf_line, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
@ -43,4 +43,8 @@ public class Design_lbrary extends Extension {
|
||||
|
||||
private String uitype;
|
||||
|
||||
private String typerender;
|
||||
|
||||
private String techstack;
|
||||
|
||||
}
|
||||
|
||||
@ -1,36 +1,31 @@
|
||||
package com.realnet.dlf.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
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 java.util.*;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.realnet.dlf.Entity.Design_lbrary;
|
||||
|
||||
@Repository
|
||||
public interface Design_lbraryRepository extends JpaRepository<Design_lbrary, Integer> {
|
||||
|
||||
@Query(value = "select * from design_lbrary where created_by=?1", nativeQuery = true)
|
||||
List<Design_lbrary> findAll(Long creayedBy);
|
||||
|
||||
@Query(value = "select * from design_lbrary where created_by=?1", nativeQuery = true)
|
||||
public interface Design_lbraryRepository extends JpaRepository<Design_lbrary, Integer> {
|
||||
|
||||
@Query(value = "select * from design_lbrary where created_by=?1", nativeQuery = true)
|
||||
List<Design_lbrary> findAll(Long creayedBy);
|
||||
|
||||
@Query(value = "select * from design_lbrary where created_by=?1", nativeQuery = true)
|
||||
Page<Design_lbrary> findAll(Pageable page, Long creayedBy);
|
||||
|
||||
@Query(value = "SELECT * from design_lbrary WHERE operation_type=:operation_type && fieldtype=:fieldtype limit 1", nativeQuery = true)
|
||||
Design_lbrary getallByHeaderIdAndFieldType(@Param("operation_type") String operation_type,
|
||||
@Param("fieldtype") String fieldtype);
|
||||
|
||||
@Query(value = "SELECT * FROM design_lbrary " + "WHERE " + " operation_type = :operation_type "
|
||||
+ "AND LOWER(fieldtype) LIKE CONCAT(LOWER(:fieldtype), '%')", nativeQuery = true)
|
||||
List<Design_lbrary> getallFlfLine(@Param("operation_type") String operationType,
|
||||
@Param("fieldtype") String fieldtype);
|
||||
}
|
||||
@ -7,6 +7,7 @@ import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -81,6 +82,8 @@ public class Design_lbraryService {
|
||||
old.setTemplatetype(data.getTemplatetype());
|
||||
|
||||
old.setUitype(data.getUitype());
|
||||
old.setTyperender(data.getTyperender());
|
||||
old.setTechstack(data.getTechstack());
|
||||
|
||||
final Design_lbrary test = designLibraryRepository.save(old);
|
||||
data.setUpdatedBy(getUser().getUserId());
|
||||
@ -103,6 +106,45 @@ public class Design_lbraryService {
|
||||
return finalHtml;
|
||||
}
|
||||
|
||||
// GET LINE BY header id, operation type, field type
|
||||
public Design_lbrary getflflinerandom(String operationType, String fieldType) {
|
||||
List<Design_lbrary> flf = designLibraryRepository.getallFlfLine(operationType.toLowerCase().trim(),
|
||||
fieldType.toLowerCase().trim());
|
||||
|
||||
if (flf == null || flf.isEmpty()) {
|
||||
return null; // ya throw new RuntimeException("No data found");
|
||||
}
|
||||
|
||||
// Random index pick
|
||||
int randomIndex = ThreadLocalRandom.current().nextInt(flf.size());
|
||||
return flf.get(randomIndex);
|
||||
}
|
||||
|
||||
// GET LINE BY header id, operation type, field type
|
||||
public Design_lbrary getLinestraight(String operationType, String fieldType) {
|
||||
Design_lbrary flf = designLibraryRepository.getallByHeaderIdAndFieldType(operationType.toLowerCase().trim(),
|
||||
fieldType.toLowerCase().trim());
|
||||
|
||||
if (flf == null) {
|
||||
return null; // ya throw new RuntimeException("No data found");
|
||||
}
|
||||
|
||||
// Random index pick
|
||||
return flf;
|
||||
}
|
||||
|
||||
public List<Design_lbrary> listOfTemplate(String operationType, String fieldType) {
|
||||
List<Design_lbrary> flf = designLibraryRepository.getallFlfLine(operationType.toLowerCase().trim(),
|
||||
fieldType.toLowerCase().trim());
|
||||
|
||||
if (flf == null || flf.isEmpty()) {
|
||||
return null; // ya throw new RuntimeException("No data found");
|
||||
}
|
||||
|
||||
// Random index pick
|
||||
return flf;
|
||||
}
|
||||
|
||||
public void build() throws IOException {
|
||||
List<Design_lbrary> dls = designLibraryRepository.findAll();
|
||||
|
||||
@ -111,7 +153,7 @@ public class Design_lbraryService {
|
||||
|
||||
String name = design_lbrary.getName();
|
||||
String javacode = design_lbrary.getJavacode();
|
||||
String method = javacode.substring(javacode.indexOf("static String")+13, javacode.indexOf("("));
|
||||
String method = javacode.substring(javacode.indexOf("static String") + 13, javacode.indexOf("("));
|
||||
|
||||
System.out.println(name + " building start .... ");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user