Skip to content

Commit 7d0f522

Browse files
authored
Merge branch 'paulparkinson:main' into main
2 parents a41b789 + 73c8912 commit 7d0f522

17 files changed

+807
-207
lines changed
Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1 @@
1-
package oracleai;
2-
3-
import org.springframework.boot.SpringApplication;
4-
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
6-
@SpringBootApplication
7-
public class AIApplication {
8-
9-
public static final String COMPARTMENT_ID = System.getenv("COMPARTMENT_ID");
10-
public static final String OBJECTSTORAGE_NAMESPACE = System.getenv("OBJECTSTORAGE_NAMESPACE");
11-
public static final String OBJECTSTORAGE_BUCKETNAME = System.getenv("OBJECTSTORAGE_BUCKETNAME");
12-
public static final String ORDS_ENDPOINT_URL = System.getenv("ORDS_ENDPOINT_URL");
13-
public static final String OCI_VISION_SERVICE_ENDPOINT = System.getenv("OCI_VISION_SERVICE_ENDPOINT");
14-
public static final String OCI_SPEECH_SERVICE_ENDPOINT = System.getenv("OCI_SPEECH_SERVICE_ENDPOINT");
15-
public static final String OCI_GENAI_SERVICE_ENDPOINT = System.getenv("OCI_GENAI_SERVICE_ENDPOINT");
16-
17-
static {
18-
System.out.println("AIApplication.static initializer COMPARTMENT_ID:" + COMPARTMENT_ID);
19-
System.out.println("AIApplication.static initializer OBJECTSTORAGE_NAMESPACE:" + OBJECTSTORAGE_NAMESPACE);
20-
System.out.println("AIApplication.static initializer OBJECTSTORAGE_BUCKETNAME:" + OBJECTSTORAGE_BUCKETNAME);
21-
System.out.println("AIApplication.static initializer ORDS_ENDPOINT_URL:" + ORDS_ENDPOINT_URL);
22-
System.out.println("AIApplication.static initializer OCI_VISION_SERVICE_ENDPOINT:" + OCI_VISION_SERVICE_ENDPOINT);
23-
}
24-
public static void main(String[] args) {
25-
SpringApplication.run(AIApplication.class, args);
26-
}
27-
28-
}
1+
asdf
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package oracleai;
2+
3+
4+
import oracleai.services.ORDSCalls;
5+
import oracleai.services.OracleObjectStore;
6+
import org.apache.tomcat.util.http.fileupload.FileUtils;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.stereotype.Controller;
9+
import org.springframework.ui.Model;
10+
import org.springframework.web.bind.annotation.*;
11+
import org.springframework.web.multipart.MultipartFile;
12+
13+
import java.io.File;
14+
import java.io.IOException;
15+
import java.nio.file.Path;
16+
import java.nio.file.Paths;
17+
18+
import org.springframework.http.MediaType;
19+
20+
@Controller
21+
@RequestMapping("/digitaldoubles")
22+
public class DigitalDoubles {
23+
24+
@GetMapping("/uploadordownload")
25+
public String digitaldouble(@RequestParam("action") String action, Model model) {
26+
return action.equals("uploading")?"digitaldoubleupload":"digitaldoubledownload";
27+
}
28+
29+
private static final String DIRECTORY = "/tmp/images/";
30+
@PostMapping("/uploadimageandvideo")
31+
public String uploadimageandvideo(
32+
@RequestParam("image") MultipartFile image,
33+
@RequestParam("video") MultipartFile video,
34+
@RequestParam("animstyle") String animstyle,
35+
@RequestParam("animprompt") String animprompt,
36+
@RequestParam("firstName") String firstName,
37+
@RequestParam("lastName") String lastName,
38+
@RequestParam("email") String email,
39+
@RequestParam("company") String company,
40+
@RequestParam("jobrole") String jobRole,
41+
@RequestParam("tshirtsize") String tshirtSize,
42+
@RequestParam("comments") String comments,
43+
Model model) throws IOException {
44+
45+
String commentsWithAnimStyleAndPrompt = animstyle + " " + animprompt + " " + comments;
46+
System.out.println("image = " + image + ", video = " + video +", animstyle = " + animstyle +
47+
", firstName = " + firstName + ", lastName = " + lastName +
48+
", email = " + email + ", company = " + company +
49+
", jobRole = " + jobRole + ", tshirtSize = " + tshirtSize +
50+
", comments = " + comments + ", model = " + model +
51+
"\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";
82+
}
83+
}
84+
85+
@GetMapping("/images/{filename:.+}")
86+
public ResponseEntity<byte[]> getImage(@PathVariable String filename) throws IOException {
87+
try {
88+
File file = new File(DIRECTORY, filename);
89+
byte[] fileContent = org.apache.commons.io.FileUtils.readFileToByteArray(file);
90+
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(fileContent);
91+
} catch (IOException e) {
92+
return ResponseEntity.notFound().build();
93+
}
94+
}
95+
96+
97+
@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";
104+
}
105+
106+
}

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

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
package oracleai;
22

3-
43
import oracleai.services.ORDSCalls;
5-
import org.apache.tomcat.util.http.fileupload.FileUtils;
6-
import org.springframework.http.ResponseEntity;
74
import org.springframework.stereotype.Controller;
85
import org.springframework.ui.Model;
96
import org.springframework.web.bind.annotation.*;
107
import org.springframework.web.multipart.MultipartFile;
118

12-
import java.io.File;
13-
import java.io.IOException;
14-
import java.nio.file.Path;
15-
import java.nio.file.Paths;
16-
17-
import org.springframework.http.MediaType;
189

1910
@Controller
2011
@RequestMapping("/transferimage")
@@ -29,65 +20,6 @@ public String uploadImage(@RequestParam("image") MultipartFile image, Model mode
2920
return "images";
3021
}
3122

32-
// @GetMapping("/uploadimageandvideo0")
33-
// public String uploadimageandvideo(@RequestParam("image") MultipartFile image, Model model) {
34-
//// ORDSCalls.uploadImage(image);
35-
//// System.out.println("Image upload complete for: " + image.getOriginalFilename());
36-
// System.out.println("convertImage(): " + ORDSCalls.convertImage());
37-
// ImageStore[] imageStores = ORDSCalls.getImageStoreData();
38-
// model.addAttribute("images", imageStores);
39-
// return "images";
40-
// }
41-
42-
43-
private static final String DIRECTORY = "/tmp/images/";
44-
45-
@PostMapping("/uploadimageandvideo")
46-
public String uploadimageandvideo(@RequestParam("image") MultipartFile file, Model model) throws IOException {
47-
// public ResponseEntity<String> uploadImage(@RequestParam("image") MultipartFile file, Model model) throws IOException {
48-
// if (file.isEmpty()) {
49-
// return ResponseEntity.badRequest().body("Cannot upload empty file");
50-
// }
51-
52-
try {
53-
org.apache.commons.io.FileUtils.forceMkdir(new File(DIRECTORY));
54-
Path path = Paths.get(DIRECTORY + file.getOriginalFilename());
55-
file.transferTo(path);
56-
String fbxUrl = ORDSCalls.convertImage("http://129.80.168.144/transferimage/images/" ,
57-
file.getOriginalFilename());
58-
model.addAttribute("resultlink", fbxUrl);
59-
model.addAttribute("resulttext", "Click here for your FBX 3D model");
60-
return "resultswithlinkpage";
61-
// return ResponseEntity.ok(
62-
// ORDSCalls.convertImage("http://129.80.168.144/transferimage/images/" + file.getOriginalFilename())
63-
// );
64-
// return ResponseEntity.ok("File uploaded and available at: " + "/images/" + file.getOriginalFilename());
65-
} catch (Exception e) {
66-
return e.toString();
67-
// ResponseEntity.internalServerError().body("Could not upload the file: " + e.getMessage());
68-
}
69-
}
70-
71-
@GetMapping("/images/{filename:.+}")
72-
public ResponseEntity<byte[]> getImage(@PathVariable String filename) throws IOException {
73-
try {
74-
File file = new File(DIRECTORY, filename);
75-
byte[] fileContent = org.apache.commons.io.FileUtils.readFileToByteArray(file);
76-
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(fileContent);
77-
} catch (IOException e) {
78-
return ResponseEntity.notFound().build();
79-
}
80-
}
81-
82-
83-
84-
85-
86-
87-
88-
89-
90-
9123
@GetMapping("/downloadimages")
9224
public String getImageStoreData(Model model) {
9325
ImageStore[] imageStores = ORDSCalls.getImageStoreData();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package oracleai.common;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.ControllerAdvice;
6+
import org.springframework.web.bind.annotation.ExceptionHandler;
7+
import org.springframework.web.multipart.MaxUploadSizeExceededException;
8+
9+
@ControllerAdvice
10+
public class FileUploadExceptionAdvice {
11+
12+
@ExceptionHandler(MaxUploadSizeExceededException.class)
13+
public ResponseEntity<String> handleMaxSizeException(MaxUploadSizeExceededException exc) {
14+
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body("File too large!");
15+
}
16+
}
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
package oracleai.services;
22

3-
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
43
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
5-
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
64
import com.oracle.bmc.auth.BasicAuthenticationDetailsProvider;
7-
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
8-
import com.oracle.bmc.auth.ResourcePrincipalAuthenticationDetailsProvider;
5+
import com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider;
6+
import oracleai.AIApplication;
7+
98
import java.io.IOException;
109

1110
public class AuthProvider {
1211

1312
public static BasicAuthenticationDetailsProvider getAuthenticationDetailsProvider() throws IOException {
14-
return ResourcePrincipalAuthenticationDetailsProvider.builder().build();
13+
if (isRunningInOKE()) return InstancePrincipalsAuthenticationDetailsProvider.builder().build();
14+
else return new ConfigFileAuthenticationDetailsProvider(
15+
// "~/.oci/config", "DEFAULT");
16+
AIApplication.OCICONFIG_FILE, AIApplication.OCICONFIG_PROFILE);
1517
}
1618

1719
private static boolean isRunningInOKE() {
18-
return true; //System.getenv("OCI_RESOURCE_PRINCIPAL_VERSION") != null;
20+
return false; //System.getenv("OCI_RESOURCE_PRINCIPAL_VERSION") != null;
1921
}
2022

21-
public static AuthenticationDetailsProvider getConfigFileAuthenticationDetailsProvider() throws IOException {
22-
return new ConfigFileAuthenticationDetailsProvider(
23-
System.getenv("OCICONFIG_FILE"), System.getenv("OCICONFIG_PROFILE"));
24-
// InstancePrincipalsAuthenticationDetailsProvider.builder().build();
25-
}
2623
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package oracleai.services;
2+
3+
public class DigitalDoubleDataRequest {
4+
public String p_participant_firstname;
5+
public String p_participant_lastname;
6+
public String p_participant_email;
7+
public String p_participant_company;
8+
public String p_participant_role;
9+
public String p_participant_tshirt;
10+
public String p_participant_comments;
11+
public String p_id_image_in; // You can change this to byte[] for BLOB
12+
public String p_image_in; // You can change this to byte[] for BLOB
13+
public String p_video_in; // You can change this to byte[] for BLOB
14+
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package oracleai.services;
2+
3+
import org.springframework.http.HttpEntity;
4+
import org.springframework.http.HttpHeaders;
5+
import org.springframework.http.HttpMethod;
6+
import org.springframework.http.MediaType;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.web.client.RestTemplate;
9+
10+
public class DigitalDoubleORDS {
11+
12+
public void insertDigitalDoubleData(DigitalDoubleDataRequest request) {
13+
String url = "https://rddainsuh6u1okc-ragdb.adb.us-ashburn-1.oraclecloudapps.com/ords/omlopsuser/insert_digital_double_data/";
14+
15+
RestTemplate restTemplate = new RestTemplate();
16+
17+
HttpHeaders headers = new HttpHeaders();
18+
headers.setContentType(MediaType.APPLICATION_JSON);
19+
20+
HttpEntity<DigitalDoubleDataRequest> entity = new HttpEntity<>(request, headers);
21+
22+
ResponseEntity<String> response = restTemplate.exchange(
23+
url,
24+
HttpMethod.POST,
25+
entity,
26+
String.class
27+
);
28+
29+
System.out.println(response.getBody());
30+
}
31+
}

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import oracleai.AIApplication;
6-
import oracleai.ImageStore;
7-
import oracleai.ImageStoreWrapper;
5+
import oracleai.*;
86
import org.jetbrains.annotations.Nullable;
97
import org.springframework.http.*;
108
import org.springframework.stereotype.Service;
@@ -181,5 +179,29 @@ public static String pollApiUntilSuccess(String fileName, String theResultString
181179
}
182180
}
183181

182+
public static void insertDigitalDoubleData(MultipartFile image, MultipartFile video,
183+
String firstName, String lastName, String email,
184+
String company, String jobRole, String tshirtSize,
185+
String comments) throws IOException {
186+
187+
188+
DigitalDoubleORDS client = new DigitalDoubleORDS();
189+
190+
DigitalDoubleDataRequest request = new DigitalDoubleDataRequest();
191+
request.p_participant_firstname = firstName;
192+
request.p_participant_lastname=lastName;
193+
request.p_participant_email=email;
194+
request.p_participant_company=company;
195+
request.p_participant_role=jobRole;
196+
request.p_participant_tshirt = tshirtSize;
197+
request.p_participant_comments = comments;
198+
// request.p_id_image_in = idimage;
199+
request.p_image_in = Base64.getEncoder().encodeToString(image.getBytes());;
200+
if (video!=null ) request.p_video_in = Base64.getEncoder().encodeToString(video.getBytes());;
201+
client.insertDigitalDoubleData(request);
202+
System.out.println("ORDSCalls.insertDigitalDoubleData insert complete");
203+
}
204+
205+
184206
}
185207

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
import oracleai.AIApplication;
1010

1111
import java.io.BufferedReader;
12+
import java.io.IOException;
1213
import java.io.InputStream;
1314
import java.io.InputStreamReader;
1415
import java.nio.charset.StandardCharsets;
1516

1617
public class OracleObjectStore {
1718

1819

19-
public static void sendToObjectStorage(String fileName, InputStream inputStreamForFile) throws Exception {
20-
System.out.println("GenerateAPictureStoryUsingOnlySpeech.sendToObjectStorage fileToUpload:" + fileName);
20+
public static void sendToObjectStorage(String fileName, InputStream inputStreamForFile) throws IOException {
21+
System.out.println("sendToObjectStorage fileToUpload:" + fileName);
2122
BasicAuthenticationDetailsProvider provider = AuthProvider.getAuthenticationDetailsProvider();
2223
ObjectStorageClient client = ObjectStorageClient.builder().build(provider);
2324
PutObjectRequest putObjectRequest = PutObjectRequest.builder()

java-ai/src/main/resources/application.properties

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)