Skip to content

Commit 7f50092

Browse files
authored
Merge branch 'paulparkinson:main' into main
2 parents 7d0f522 + 8f14cd6 commit 7f50092

11 files changed

+509
-128
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
asdf
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package oracleai;
2+
3+
public class DigitalDoubleDownloadInfo {
4+
5+
String email;
6+
String modelUrl;
7+
String modelGlbUrl;
8+
String modelFbxUrl ;
9+
String modelUsdzUrl ;
10+
String thumbnailUrl;
11+
String animatedVideoLocation;
12+
String similarImageUrl;
13+
14+
15+
16+
public DigitalDoubleDownloadInfo() {
17+
18+
}
19+
public DigitalDoubleDownloadInfo(String modelUrl, String modelGlbUrl, String modelFbxUrl,
20+
String modelUsdzUrl, String thumbnailUrl) {
21+
this.modelUrl = modelUrl;
22+
this.modelGlbUrl = modelGlbUrl;
23+
this.modelFbxUrl = modelFbxUrl;
24+
this.modelUsdzUrl = modelUsdzUrl;
25+
this.thumbnailUrl = thumbnailUrl;
26+
}
27+
28+
public DigitalDoubleDownloadInfo(String modelGlbUrl, String modelFbxUrl, String modelUsdzUrl,
29+
String thumbnailUrl, String animatedVideoLocation,
30+
String email, String similarImageUrl) {
31+
this.modelGlbUrl = modelGlbUrl;
32+
this.modelFbxUrl = modelFbxUrl;
33+
this.modelUsdzUrl = modelUsdzUrl;
34+
this.thumbnailUrl = thumbnailUrl;
35+
this.animatedVideoLocation = animatedVideoLocation;
36+
this.email = email;
37+
this.similarImageUrl = similarImageUrl;
38+
}
39+
40+
public void setEmail(String email) {
41+
this.email = email;
42+
}
43+
44+
public void setModelUrl(String modelUrl) {
45+
this.modelUrl = modelUrl;
46+
}
47+
48+
public void setModelGlbUrl(String modelGlbUrl) {
49+
this.modelGlbUrl = modelGlbUrl;
50+
}
51+
52+
public void setModelFbxUrl(String modelFbxUrl) {
53+
this.modelFbxUrl = modelFbxUrl;
54+
}
55+
56+
public void setModelUsdzUrl(String modelUsdzUrl) {
57+
this.modelUsdzUrl = modelUsdzUrl;
58+
}
59+
60+
public void setThumbnailUrl(String thumbnailUrl) {
61+
this.thumbnailUrl = thumbnailUrl;
62+
}
63+
64+
public void setAnimatedVideoLocation(String animatedVideoLocation) {
65+
this.animatedVideoLocation = animatedVideoLocation;
66+
}
67+
68+
public void setSimilarImageUrl(String similarImageUrl) {
69+
this.similarImageUrl = similarImageUrl;
70+
}
71+
72+
public String getEmail() {
73+
return email;
74+
}
75+
76+
public String getModelUrl() {
77+
return modelUrl;
78+
}
79+
80+
public String getModelGlbUrl() {
81+
return modelGlbUrl;
82+
}
83+
84+
public String getModelFbxUrl() {
85+
return modelFbxUrl;
86+
}
87+
88+
public String getModelUsdzUrl() {
89+
return modelUsdzUrl;
90+
}
91+
92+
public String getThumbnailUrl() {
93+
return thumbnailUrl;
94+
}
95+
96+
public String getAnimatedVideoLocation() {
97+
return animatedVideoLocation;
98+
}
99+
100+
public String getSimilarImageUrl() {
101+
return similarImageUrl;
102+
}
103+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package oracleai;
2+
3+
import org.springframework.http.*;
4+
import org.springframework.stereotype.Service;
5+
import org.springframework.web.client.RestTemplate;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
@Service
11+
public class DigitalDoubleService {
12+
13+
public void updateDigitalDoubleData(DigitalDoubleDownloadInfo info) {
14+
String url = AIApplication.ORDS_OMLOPSENDPOINT_URL + "update_digital_double_data/";
15+
16+
HttpHeaders headers = new HttpHeaders();
17+
headers.setContentType(MediaType.APPLICATION_JSON);
18+
19+
Map<String, String> requestBody = new HashMap<>();
20+
requestBody.put("p_participant_email", info.getEmail());
21+
requestBody.put("p_modelglburl_out", info.getModelGlbUrl());
22+
requestBody.put("p_modelfbxurl_out", info.modelFbxUrl);
23+
requestBody.put("p_modelusdzurl_out", info.modelUsdzUrl);
24+
requestBody.put("p_thumbnailurl_out", info.thumbnailUrl);
25+
26+
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers);
27+
28+
ResponseEntity<String> response =
29+
new RestTemplate().exchange(url, HttpMethod.POST, entity, String.class);
30+
31+
if (response.getStatusCode().is2xxSuccessful()) {
32+
System.out.println("Request successful: " + response.getBody());
33+
} else {
34+
System.err.println("Request failed with status code: " + response.getStatusCode());
35+
}
36+
37+
}
38+
}

java-ai/src/main/java/oracleai/DigitalDoubles.java

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import oracleai.services.ORDSCalls;
55
import oracleai.services.OracleObjectStore;
66
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;
711
import org.springframework.http.ResponseEntity;
812
import org.springframework.stereotype.Controller;
913
import org.springframework.ui.Model;
@@ -14,19 +18,30 @@
1418
import java.io.IOException;
1519
import java.nio.file.Path;
1620
import java.nio.file.Paths;
21+
import java.util.HashMap;
22+
import java.util.Map;
1723

1824
import org.springframework.http.MediaType;
1925

2026
@Controller
2127
@RequestMapping("/digitaldoubles")
2228
public 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
"\ncomments 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
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package oracleai;
2+
3+
import oracleai.services.ORDSCalls;
4+
import org.apache.commons.io.FileUtils;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Service;
7+
import org.springframework.web.multipart.MultipartFile;
8+
9+
import java.io.File;
10+
import java.io.IOException;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
13+
import java.util.concurrent.BlockingQueue;
14+
import java.util.concurrent.LinkedBlockingQueue;
15+
16+
@Service
17+
public class ImageProcessor {
18+
19+
private static final String DIRECTORY = "/tmp/images/";
20+
private static final BlockingQueue<ImageTask> queue = new LinkedBlockingQueue<>();
21+
22+
// Inject DigitalDoubleService to make REST call
23+
private final DigitalDoubleService digitalDoubleService;
24+
25+
@Autowired
26+
public ImageProcessor(DigitalDoubleService digitalDoubleService) {
27+
this.digitalDoubleService = digitalDoubleService;
28+
new Thread(this::processQueue).start();
29+
}
30+
31+
public String handleImageUpload(String email, MultipartFile image, String fullVideoName) throws IOException {
32+
String imageFileNameWithEmailPrefix = "";
33+
if (image != null && !image.isEmpty()) {
34+
FileUtils.forceMkdir(new File(DIRECTORY));
35+
imageFileNameWithEmailPrefix = email + "_" + image.getOriginalFilename();
36+
Path path = Paths.get(DIRECTORY + imageFileNameWithEmailPrefix);
37+
image.transferTo(path);
38+
}
39+
queue.offer(new ImageTask(email, imageFileNameWithEmailPrefix, fullVideoName));
40+
return "Image is being processed";
41+
}
42+
43+
public static String objectStoreLocation =
44+
"https://" + AIApplication.OBJECTSTORAGE_NAMESPACE + ".compat.objectstorage.us-ashburn-1.oraclecloud.com/" +
45+
AIApplication.OBJECTSTORAGE_BUCKETNAME + "/anim/";
46+
47+
private void processQueue() {
48+
while (true) {
49+
try {
50+
ImageTask task = queue.take();
51+
DigitalDoubleDownloadInfo digitalDoubleDownloadInfo;
52+
if (!task.getImageFileNameWithEmailPrefix().equals("")) {
53+
digitalDoubleDownloadInfo = ORDSCalls.convertImageAndQueueResults(
54+
"http://129.80.168.144/digitaldoubles/images/",
55+
task.getImageFileNameWithEmailPrefix());
56+
} else {
57+
digitalDoubleDownloadInfo = new DigitalDoubleDownloadInfo();
58+
}
59+
60+
digitalDoubleDownloadInfo.animatedVideoLocation = objectStoreLocation + task.getFullVideoName();
61+
62+
// Call the method to update Digital Double data
63+
digitalDoubleService.updateDigitalDoubleData(
64+
new DigitalDoubleDownloadInfo(
65+
digitalDoubleDownloadInfo.modelGlbUrl,
66+
digitalDoubleDownloadInfo.modelFbxUrl,
67+
digitalDoubleDownloadInfo.modelUsdzUrl,
68+
digitalDoubleDownloadInfo.thumbnailUrl,
69+
digitalDoubleDownloadInfo.animatedVideoLocation,
70+
task.getEmail(),
71+
"" // Similar image can be passed here if available
72+
)
73+
);
74+
75+
} catch (InterruptedException e) {
76+
Thread.currentThread().interrupt();
77+
break;
78+
} catch (Exception e) {
79+
System.err.println("Failed to process image for: " + e.getMessage());
80+
}
81+
}
82+
}
83+
84+
private static class ImageTask {
85+
private final String email;
86+
private final String imageFileNameWithEmailPrefix;
87+
private final String fullVideoName;
88+
89+
public ImageTask(String email, String imageFileNameWithEmailPrefix, String fullVideoName) {
90+
this.email = email;
91+
this.imageFileNameWithEmailPrefix = imageFileNameWithEmailPrefix;
92+
this.fullVideoName = fullVideoName;
93+
}
94+
95+
public String getEmail() {
96+
return email;
97+
}
98+
99+
public String getImageFileNameWithEmailPrefix() {
100+
return imageFileNameWithEmailPrefix;
101+
}
102+
103+
public String getFullVideoName() {
104+
return fullVideoName;
105+
}
106+
}
107+
}

java-ai/src/main/java/oracleai/services/DigitalDoubleORDS.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package oracleai.services;
22

3+
import oracleai.AIApplication;
34
import org.springframework.http.HttpEntity;
45
import org.springframework.http.HttpHeaders;
56
import org.springframework.http.HttpMethod;
@@ -10,7 +11,7 @@
1011
public class DigitalDoubleORDS {
1112

1213
public void insertDigitalDoubleData(DigitalDoubleDataRequest request) {
13-
String url = "https://rddainsuh6u1okc-ragdb.adb.us-ashburn-1.oraclecloudapps.com/ords/omlopsuser/insert_digital_double_data/";
14+
String url = AIApplication.ORDS_OMLOPSENDPOINT_URL + "insert_digital_double_data/";
1415

1516
RestTemplate restTemplate = new RestTemplate();
1617

0 commit comments

Comments
 (0)