4
4
import oracleai .services .ORDSCalls ;
5
5
import oracleai .services .OracleObjectStore ;
6
6
import 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 ;
7
11
import org .springframework .http .ResponseEntity ;
8
12
import org .springframework .stereotype .Controller ;
9
13
import org .springframework .ui .Model ;
14
18
import java .io .IOException ;
15
19
import java .nio .file .Path ;
16
20
import java .nio .file .Paths ;
21
+ import java .util .HashMap ;
22
+ import java .util .Map ;
17
23
18
24
import org .springframework .http .MediaType ;
19
25
20
26
@ Controller
21
27
@ RequestMapping ("/digitaldoubles" )
22
28
public class DigitalDoubles {
23
29
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
+
24
39
@ GetMapping ("/uploadordownload" )
25
40
public String digitaldouble (@ RequestParam ("action" ) String action , Model model ) {
26
- return action .equals ("uploading" )? "digitaldoubleupload" : "digitaldoubledownload" ;
41
+ return action .equals ("uploading" ) ? "digitaldoubleupload" : "digitaldoubledownload" ;
27
42
}
28
43
29
- private static final String DIRECTORY = "/tmp/images/" ;
44
+
30
45
@ PostMapping ("/uploadimageandvideo" )
31
46
public String uploadimageandvideo (
32
47
@ RequestParam ("image" ) MultipartFile image ,
@@ -43,43 +58,42 @@ public String uploadimageandvideo(
43
58
Model model ) throws IOException {
44
59
45
60
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 +
47
62
", firstName = " + firstName + ", lastName = " + lastName +
48
63
", email = " + email + ", company = " + company +
49
64
", jobRole = " + jobRole + ", tshirtSize = " + tshirtSize +
50
65
", comments = " + comments + ", model = " + model +
51
66
"\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 ());
82
74
}
75
+ imageProcessor .handleImageUpload (email , image , fullVideoName );
76
+
77
+ // try {
78
+ // org.apache.commons.io.FileUtils.forceMkdir(new File(DIRECTORY));
79
+ // String imageFileNameWithEmailPrefix = email + "_" + image.getOriginalFilename();
80
+ // Path path = Paths.get(DIRECTORY + imageFileNameWithEmailPrefix);
81
+ // image.transferTo(path);
82
+ // String fbxUrl = ORDSCalls.convertImage("http://129.80.168.144/digitaldoubles/images/",
83
+ // imageFileNameWithEmailPrefix);
84
+ // model.addAttribute("resultlink", fbxUrl);
85
+ // model.addAttribute("resulttext", "Click here for your FBX 3D model");
86
+ // return "resultswithlinkpage";
87
+ // } catch (Exception e) {
88
+ // return e.toString();
89
+ //// ResponseEntity.internalServerError().body("Could not upload the file: " + e.getMessage());
90
+ // }
91
+
92
+ // model.addAttribute("resultlink", "http://129.80.168.144/UploadDigitalDouble.html");
93
+ // model.addAttribute("resulttext",
94
+ // "Image not provided or is empty. Click here to try again.");
95
+ return "digitaldoubledownload" ;
96
+
83
97
}
84
98
85
99
@ GetMapping ("/images/{filename:.+}" )
@@ -96,11 +110,10 @@ public ResponseEntity<byte[]> getImage(@PathVariable String filename) throws IOE
96
110
97
111
@ PostMapping ("/downloaddigitaldouble" )
98
112
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" );
113
+ ORDSCalls .getDigitalDoubleData (email , model );
102
114
return "resultswithlinkpage" ;
103
115
// return "digitaldoubleresults";
104
116
}
105
117
118
+
106
119
}
0 commit comments