diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/HtmlGeneratorController.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/HtmlGeneratorController.java index 572a19c..877ba27 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/HtmlGeneratorController.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/OpenAi/Controller/HtmlGeneratorController.java @@ -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("
")) { + bodyHtml = "
Empty Data
"; + + } + + // Build full HTML page +// StringBuilder finalHtml = new StringBuilder(); +// finalHtml.append("\n"); +// finalHtml.append("\n"); +// finalHtml.append("\n"); +// finalHtml.append(" \n"); +// finalHtml.append(" \n"); +// finalHtml.append(" Generated Page\n"); +// finalHtml.append(" \n"); +// finalHtml.append("\n"); +// finalHtml.append("\n"); +// finalHtml.append(bodyHtml).append("\n"); +// finalHtml.append("\n"); +// finalHtml.append(""); + + 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."); + } + } + } diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Builders/HtmlBuilder.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Builders/HtmlBuilder.java index 3c44ce9..5fcbde1 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Builders/HtmlBuilder.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Builders/HtmlBuilder.java @@ -17,7 +17,10 @@ public class HtmlBuilder { // TYPE_RENDERERS.put("cta-block", HtmlBuilder::renderCtaBlock); // - 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 { } // - public static String renderHeader(Map data) { + + private static String renderHeader(Map data) { StringBuilder html = new StringBuilder(); + String clazz = getString(data, "class", "mega-navbar"); - html.append("
"); - // Safely cast children list - List> children = (List>) data.get("children"); + html.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("
").append(logoContent).append("
"); - }); - - // Navigation - children.stream().filter(child -> "nav".equals(child.get("type"))).findFirst().ifPresent(nav -> { - html.append(""); - }); - } - - // Button - List> childrens = (List>) data.get("children"); - Map 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) button).get("content"); - html.append(""); + List> children = getChildren(data); + for (Map 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("
"); - 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(""); + return html.toString(); + } + + private static String getText(Map 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 data) { + StringBuilder html = new StringBuilder(); + String clazz = getString(data, "class", "nav-1"); + + html.append(""); + return html.toString(); + } + +// public static String renderHeader(Map data) { +// StringBuilder html = new StringBuilder(); +// +// html.append("
"); +// // Safely cast children list +// List> children = (List>) 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("
").append(logoContent).append("
"); +// }); +// +// // Navigation +// children.stream().filter(child -> "nav".equals(child.get("type"))).findFirst().ifPresent(nav -> { +// html.append(""); +// }); +// } +// +// // Button +// List> childrens = (List>) data.get("children"); +// Map 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) button).get("content"); +// html.append(""); +// } +// +// html.append("
"); +// +// return html.toString(); +// } + public static String renderTestimonialSection() { StringBuilder html = new StringBuilder(); diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Controllers/Design_lbraryController.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Controllers/Design_lbraryController.java index aff9fb8..6988e5b 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Controllers/Design_lbraryController.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Controllers/Design_lbraryController.java @@ -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(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(flf_line, HttpStatus.OK); + } + + @GetMapping("/Design_lbrary/list/template") + public ResponseEntity listOfTemplate(@RequestParam String operationType, @RequestParam String fieldType) { + List 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); + } + } \ No newline at end of file diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Entity/Design_lbrary.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Entity/Design_lbrary.java index c15bd23..82dbbd3 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Entity/Design_lbrary.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Entity/Design_lbrary.java @@ -43,4 +43,8 @@ public class Design_lbrary extends Extension { private String uitype; + private String typerender; + + private String techstack; + } diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Repository/Design_lbraryRepository.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Repository/Design_lbraryRepository.java index 2d9cd06..89c604e 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Repository/Design_lbraryRepository.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Repository/Design_lbraryRepository.java @@ -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 { - -@Query(value = "select * from design_lbrary where created_by=?1", nativeQuery = true) - List findAll(Long creayedBy); - -@Query(value = "select * from design_lbrary where created_by=?1", nativeQuery = true) +public interface Design_lbraryRepository extends JpaRepository { + + @Query(value = "select * from design_lbrary where created_by=?1", nativeQuery = true) + List findAll(Long creayedBy); + + @Query(value = "select * from design_lbrary where created_by=?1", nativeQuery = true) Page 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 getallFlfLine(@Param("operation_type") String operationType, + @Param("fieldtype") String fieldtype); } \ No newline at end of file diff --git a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Services/Design_lbraryService.java b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Services/Design_lbraryService.java index 23e01f1..4d808b2 100644 --- a/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Services/Design_lbraryService.java +++ b/visaproject-back-b/authsec_springboot/backend/src/main/java/com/realnet/dlf/Services/Design_lbraryService.java @@ -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 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 listOfTemplate(String operationType, String fieldType) { + List 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 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 .... ");