Skip to content

Commit 2ba2d9d

Browse files
committed
digital double logic
1 parent da055b4 commit 2ba2d9d

File tree

6 files changed

+313
-152
lines changed

6 files changed

+313
-152
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package oracleai;
2+
3+
4+
import oracleai.services.ORDSCalls;
5+
import org.apache.tomcat.util.http.fileupload.FileUtils;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.stereotype.Controller;
8+
import org.springframework.ui.Model;
9+
import org.springframework.web.bind.annotation.*;
10+
import org.springframework.web.multipart.MultipartFile;
11+
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;
18+
19+
@Controller
20+
@RequestMapping("/digitaldoubles")
21+
public class DigitalDoubles {
22+
23+
@PostMapping("/uploadordownload")
24+
public String digitaldouble(@RequestParam("action") String action, Model model) {
25+
return action.equals("uploading")?"digitaldoubleupload":"digitaldoubledownload";
26+
}
27+
28+
private static final String DIRECTORY = "/tmp/images/";
29+
@PostMapping("/uploadimageandvideo")
30+
public String uploadimageandvideo(
31+
@RequestParam("image") MultipartFile image,
32+
@RequestParam("video") MultipartFile video,
33+
@RequestParam("firstName") String firstName,
34+
@RequestParam("lastName") String lastName,
35+
@RequestParam("email") String email,
36+
@RequestParam("company") String company,
37+
@RequestParam("jobrole") String jobRole,
38+
@RequestParam("tshirtsize") String tshirtSize,
39+
@RequestParam("comments") String comments,
40+
Model model) throws IOException {
41+
42+
System.out.println("image = " + image + ", video = " + video +
43+
", firstName = " + firstName + ", lastName = " + lastName +
44+
", email = " + email + ", company = " + company +
45+
", jobRole = " + jobRole + ", tshirtSize = " + tshirtSize +
46+
", comments = " + comments + ", model = " + model);
47+
if (!image.isEmpty()) {
48+
ORDSCalls.uploadImage(image);
49+
// byte[] imageBytes = image.getBytes();
50+
51+
if (!video.isEmpty()) {
52+
// Do something with the video file
53+
byte[] videoBytes = video.getBytes();
54+
// Save or process the video
55+
}
56+
try {
57+
org.apache.commons.io.FileUtils.forceMkdir(new File(DIRECTORY));
58+
Path path = Paths.get(DIRECTORY + image.getOriginalFilename());
59+
image.transferTo(path);
60+
String fbxUrl = ORDSCalls.convertImage("http://129.80.168.144/digitaldoubles/images/",
61+
image.getOriginalFilename());
62+
model.addAttribute("resultlink", fbxUrl);
63+
model.addAttribute("resulttext", "Click here for your FBX 3D model");
64+
return "resultswithlinkpage";
65+
// return ResponseEntity.ok(
66+
// ORDSCalls.convertImage("http://129.80.168.144/transferimage/images/" + file.getOriginalFilename())
67+
// );
68+
// return ResponseEntity.ok("File uploaded and available at: " + "/images/" + file.getOriginalFilename());
69+
} catch (Exception e) {
70+
return e.toString();
71+
// ResponseEntity.internalServerError().body("Could not upload the file: " + e.getMessage());
72+
}
73+
// Save or process the image
74+
} else {
75+
model.addAttribute("resultlink", "http://129.80.168.144/UploadDigitalDouble.html");
76+
model.addAttribute("resulttext",
77+
"Image not provided or is empty. Click here to try again.");
78+
return "resultswithlinkpage";
79+
}
80+
}
81+
82+
@GetMapping("/images/{filename:.+}")
83+
public ResponseEntity<byte[]> getImage(@PathVariable String filename) throws IOException {
84+
try {
85+
File file = new File(DIRECTORY, filename);
86+
byte[] fileContent = org.apache.commons.io.FileUtils.readFileToByteArray(file);
87+
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(fileContent);
88+
} catch (IOException e) {
89+
return ResponseEntity.notFound().build();
90+
}
91+
}
92+
93+
94+
@PostMapping("/downloaddigitaldouble")
95+
public String downloaddigitaldouble(@RequestParam("email") String email, Model model) {
96+
System.out.println("DigitalDoubles.downloaddigitaldouble lookup email:" + email);
97+
model.addAttribute("resultlink", email);
98+
model.addAttribute("resulttext", "Click here for your FBX 3D model");
99+
return "resultswithlinkpage";
100+
// return "digitaldoubleresults";
101+
}
102+
103+
}

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: 13 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
2-
<html lang="en" xmlns:th="http://www.thymeleaf.org">
2+
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>Upload For Digital Doubles</title>
6+
<title>Player Selection</title>
77
<style>
88
body {
99
font-family: Arial, sans-serif;
@@ -24,28 +24,10 @@
2424
h1 {
2525
color: #333;
2626
}
27-
.form-group {
28-
margin: 15px 0;
27+
.btn-group {
28+
margin-top: 20px;
2929
}
30-
label {
31-
display: block;
32-
margin-bottom: 5px;
33-
color: #333;
34-
}
35-
input[type="text"],
36-
input[type="email"],
37-
input[type="company"],
38-
input[type="jobrole"],
39-
input[type="tshirtsize"],
40-
input[type="comments"] {
41-
width: 100%;
42-
padding: 10px;
43-
margin: 5px 0 20px 0;
44-
border: 1px solid #ccc;
45-
border-radius: 5px;
46-
box-sizing: border-box;
47-
}
48-
input[type="submit"] {
30+
.btn-group button {
4931
background-color: #007BFF;
5032
color: white;
5133
border: none;
@@ -59,74 +41,21 @@
5941
cursor: pointer;
6042
transition: background-color 0.3s;
6143
}
62-
input[type="submit"]:hover {
44+
.btn-group button:hover {
6345
background-color: #0056b3;
6446
}
6547
</style>
6648
</head>
6749
<body>
6850
<div class="container">
69-
<h1>Upload Your Image</h1>
70-
71-
<form method="POST" action="/transferimage/uploadimageandvideo" enctype="multipart/form-data">
72-
73-
74-
<div class="form-group">
75-
<label for="image">Select image:</label>
76-
<input type="file" id="image" name="image" accept="image/*" required>
77-
<button type="submit">Upload</button>
78-
79-
<!-- <label for="firstName">First Name:</label>-->
80-
<!-- <input type="text" id="firstName" name="firstName" autocomplete="given-name">-->
51+
<h1>Which are you doing?...</h1>
52+
<form action="/digitaldoubles/uploadordownload" method="get">
53+
<div class="btn-group">
54+
<button type="submit" name="action" value="uploading">Uploading Your Image and Video To Create Digital Doubles</button>
55+
<button type="submit" name="action" value="downloading">Downloading Your Digital Doubles</button>
8156
</div>
82-
8357
</form>
84-
<!-- -->
85-
<!-- <form method="post" action="http://143.47.96.92/podsofkon/setPlayerNamesAndIds">-->
86-
<!-- &lt;!&ndash; Conditional display for Player 1 Name &ndash;&gt;-->
87-
<!-- <div class="form-group" th:if="${player == 'player1'}">-->
88-
<!-- <label for="player1Name">Player 1 Name:</label>-->
89-
<!-- <input type="text" id="player1Name" name="player1Name" autocomplete="player1Name">-->
90-
<!-- </div>-->
91-
92-
<!-- &lt;!&ndash; Conditional display for Player 2 Name &ndash;&gt;-->
93-
<!-- <div class="form-group" th:if="${player == 'player2'}">-->
94-
<!-- <label for="player2Name">Player 2 Name:</label>-->
95-
<!-- <input type="text" id="player2Name" name="player2Name" autocomplete="player2Name">-->
96-
<!-- </div>-->
97-
98-
<!-- <div class="form-group">-->
99-
<!-- <label for="firstName">First Name:</label>-->
100-
<!-- <input type="text" id="firstName" name="firstName" autocomplete="given-name">-->
101-
<!-- </div>-->
102-
<!-- <div class="form-group">-->
103-
<!-- <label for="lastName">Last Name:</label>-->
104-
<!-- <input type="text" id="lastName" name="lastName" autocomplete="family-name">-->
105-
<!-- </div>-->
106-
<!-- <div class="form-group">-->
107-
<!-- <label for="email">Email:</label>-->
108-
<!-- <input type="email" id="email" name="email" autocomplete="email" required>-->
109-
<!-- </div>-->
110-
<!-- <div class="form-group">-->
111-
<!-- <label for="company">Company:</label>-->
112-
<!-- <input type="text" id="company" name="company" autocomplete="organization">-->
113-
<!-- </div>-->
114-
<!-- <div class="form-group">-->
115-
<!-- <label for="jobrole">Job Role:</label>-->
116-
<!-- <input type="text" id="jobrole" name="jobrole" autocomplete="organization-title">-->
117-
<!-- </div>-->
118-
<!-- <div class="form-group">-->
119-
<!-- <label for="tshirtsize">T-Shirt Size:</label>-->
120-
<!-- <input type="text" id="tshirtsize" name="tshirtsize" autocomplete="tshirt-size">-->
121-
<!-- </div>-->
122-
<!-- <div class="form-group">-->
123-
<!-- <label for="comments">Comments:</label>-->
124-
<!-- <input type="text" id="comments" name="comments" autocomplete="comments">-->
125-
<!-- </div>-->
126-
<!-- <div class="form-group">-->
127-
<!-- <input type="submit" value="Submit">-->
128-
<!-- </div>-->
129-
<!-- </form>-->
13058
</div>
13159
</body>
132-
</html>
60+
</html>
61+

0 commit comments

Comments
 (0)