44import oracleai .services .ORDSCalls ;
55import oracleai .services .OracleObjectStore ;
66import org .apache .tomcat .util .http .fileupload .FileUtils ;
7+ import org .jetbrains .annotations .Nullable ;
8+ import org .springframework .beans .factory .annotation .Autowired ;
9+ import org .springframework .http .HttpEntity ;
10+ import org .springframework .http .HttpHeaders ;
711import org .springframework .http .ResponseEntity ;
812import org .springframework .stereotype .Controller ;
913import org .springframework .ui .Model ;
1418import java .io .IOException ;
1519import java .nio .file .Path ;
1620import java .nio .file .Paths ;
21+ import java .util .HashMap ;
22+ import java .util .Map ;
1723
1824import org .springframework .http .MediaType ;
1925
2026@ Controller
2127@ RequestMapping ("/digitaldoubles" )
2228public class DigitalDoubles {
2329
30+ private final ImageProcessor imageProcessor ;
31+
32+ // Inject the ImageProcessor using constructor injection
33+ @ Autowired
34+ public DigitalDoubles (ImageProcessor imageProcessor ) {
35+ this .imageProcessor = imageProcessor ;
36+ }
37+ private static final String DIRECTORY = "/tmp/images/" ;
38+
2439 @ GetMapping ("/uploadordownload" )
2540 public String digitaldouble (@ RequestParam ("action" ) String action , Model model ) {
26- return action .equals ("uploading" )? "digitaldoubleupload" : "digitaldoubledownload" ;
41+ return action .equals ("uploading" ) ? "digitaldoubleupload" : "digitaldoubledownload" ;
2742 }
2843
29- private static final String DIRECTORY = "/tmp/images/" ;
44+
3045 @ PostMapping ("/uploadimageandvideo" )
3146 public String uploadimageandvideo (
3247 @ RequestParam ("image" ) MultipartFile image ,
@@ -43,43 +58,24 @@ public String uploadimageandvideo(
4358 Model model ) throws IOException {
4459
4560 String commentsWithAnimStyleAndPrompt = animstyle + " " + animprompt + " " + comments ;
46- System .out .println ("image = " + image + ", video = " + video +", animstyle = " + animstyle +
61+ System .out .println ("image = " + image + ", video = " + video + ", animstyle = " + animstyle +
4762 ", firstName = " + firstName + ", lastName = " + lastName +
4863 ", email = " + email + ", company = " + company +
4964 ", jobRole = " + jobRole + ", tshirtSize = " + tshirtSize +
5065 ", comments = " + comments + ", model = " + model +
5166 "\n comments with animstyle and prompt = " + commentsWithAnimStyleAndPrompt );
52- if (!image .isEmpty ()) {
53- ORDSCalls .insertDigitalDoubleData (
54- image ,null , firstName , lastName , email , company ,jobRole , tshirtSize , commentsWithAnimStyleAndPrompt );
55- if (!video .isEmpty ()) {
56- OracleObjectStore .sendToObjectStorage (
57- email + "_" + animstyle + "_" + video .getOriginalFilename (), video .getInputStream ());
58- }
59- try {
60- org .apache .commons .io .FileUtils .forceMkdir (new File (DIRECTORY ));
61- Path path = Paths .get (DIRECTORY + image .getOriginalFilename ());
62- image .transferTo (path );
63- String fbxUrl = ORDSCalls .convertImage ("http://129.80.168.144/digitaldoubles/images/" ,
64- image .getOriginalFilename ());
65- model .addAttribute ("resultlink" , fbxUrl );
66- model .addAttribute ("resulttext" , "Click here for your FBX 3D model" );
67- return "resultswithlinkpage" ;
68- // return ResponseEntity.ok(
69- // ORDSCalls.convertImage("http://129.80.168.144/transferimage/images/" + file.getOriginalFilename())
70- // );
71- // return ResponseEntity.ok("File uploaded and available at: " + "/images/" + file.getOriginalFilename());
72- } catch (Exception e ) {
73- return e .toString ();
74- // ResponseEntity.internalServerError().body("Could not upload the file: " + e.getMessage());
75- }
76- // Save or process the image
77- } else {
78- model .addAttribute ("resultlink" , "http://129.80.168.144/UploadDigitalDouble.html" );
79- model .addAttribute ("resulttext" ,
80- "Image not provided or is empty. Click here to try again." );
81- return "resultswithlinkpage" ;
67+ ORDSCalls .insertDigitalDoubleData (
68+ image , null , firstName , lastName , email , company , jobRole , tshirtSize , commentsWithAnimStyleAndPrompt );
69+
70+ String fullVideoName ="" ;
71+ if (!video .isEmpty ()) {
72+ fullVideoName = email + "_" + animstyle + "_" + video .getOriginalFilename ();
73+ OracleObjectStore .sendToObjectStorage (fullVideoName , video .getInputStream ());
8274 }
75+ imageProcessor .handleImageUpload (email , image , fullVideoName );
76+
77+ return "digitaldoubledownload" ;
78+
8379 }
8480
8581 @ GetMapping ("/images/{filename:.+}" )
@@ -95,12 +91,13 @@ public ResponseEntity<byte[]> getImage(@PathVariable String filename) throws IOE
9591
9692
9793 @ PostMapping ("/downloaddigitaldouble" )
98- public String downloaddigitaldouble (@ RequestParam ("email" ) String email , Model model ) {
99- System . out . println ( "DigitalDoubles.downloaddigitaldouble lookup email:" + email );
100- model .addAttribute ("resultlink " , email );
101- model .addAttribute ("resulttext " , "Click here for your FBX 3D model " );
102- return "resultswithlinkpage" ;
103- // return "digitaldoubleresults";
94+ public String downloaddigitaldouble (@ RequestParam ("email" ) String email , Model model ) throws Exception {
95+ model . addAttribute ( "fbxlink" , ORDSCalls . getDigitalDoubleData ( email ) );
96+ model .addAttribute ("fbxtext " , "FBX 3D Model" );
97+ model .addAttribute ("mp4link " , ImageProcessor . objectStoreLocation + email + ".mp4 " );
98+ model . addAttribute ( "mp4text" , "MP4 Animation" ) ;
99+ return "digitaldoubleresults" ;
104100 }
105101
102+
106103}
0 commit comments