created AlgorithmController file

This commit is contained in:
Kea Horvath committed 2023-03-17 01:09:06 +01:00
1 parent 4fbc3d98dd
commit 9bb87d6497
3 files changed
+63 -44

No files matched your search

@@ -7,14 +7,14 @@ import org.springframework.web.server.ResponseStatusException;
public class Algorithm { public class Algorithm {
private final String name; private final String name;
private final String pass; private final String path;
private final ArrayList<Parameter> parameters; private final ArrayList<Parameter> parameters;
public Algorithm(String name, String pass) { public Algorithm(String name, String path) {
this.name = name; this.name = name;
this.pass = pass; this.path = path;
this.parameters = new ArrayList<>(); this.parameters = new ArrayList<>();
switch (pass) { switch (path) {
case "changeLuminosity": case "changeLuminosity":
Parameter param1 = new Parameter("delta", "", -255, 255, false); Parameter param1 = new Parameter("delta", "", -255, 255, false);
this.parameters.add(param1); this.parameters.add(param1);
@@ -45,8 +45,8 @@ public class Algorithm {
return this.name; return this.name;
} }
public String getPass() { public String getPath() {
return this.pass; return this.path;
} }
public ArrayList<Parameter> getParameters() { public ArrayList<Parameter> getParameters() {
@@ -0,0 +1,57 @@
package pdl.backend;
import java.util.ArrayList;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class AlgorithmController {
@Autowired
private ObjectMapper mapper;
@GetMapping(value = "/algorithms", produces = "application/json")
@ResponseBody
public ArrayNode getAlgorithmList() {
ArrayList<Algorithm> algorithms = new ArrayList<Algorithm>();
Algorithm algo = new Algorithm("Changement de luminosité", "changeLuminosity");
algorithms.add(algo);
algo = new Algorithm("Changement de teinte", "colorFilter");
algorithms.add(algo);
algo = new Algorithm("Filtre Moyenneur", "meanFilter");
algorithms.add(algo);
algo = new Algorithm("Filtre Gaussien", "gaussienFilter");
algorithms.add(algo);
algo = new Algorithm("Détection de contours", "contours");
algorithms.add(algo);
algo = new Algorithm("Histogramme", "histogram");
algorithms.add(algo);
ArrayNode nodes = mapper.createArrayNode();
for (Algorithm a : algorithms) {
ObjectNode objectNode = mapper.createObjectNode();
objectNode.put("name", a.getName());
objectNode.put("pass", a.getPath());
ArrayNode parameters = objectNode.putArray("parameters");
for (Parameter p : a.getParameters()) {
ObjectNode paramNode = mapper.createObjectNode();
paramNode.put("name", p.getName());
paramNode.put("displayName", p.getDisplayName());
paramNode.put("min", p.getMin());
paramNode.put("max", p.getMax());
paramNode.put("mustBeOdd", p.mustBeOdd());
parameters.add(paramNode);
}
nodes.add(objectNode);
}
return nodes;
}
}
@@ -5,7 +5,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Map; import java.util.Map;
@@ -113,43 +112,6 @@ public class ImageController {
return nodes; return nodes;
} }
@GetMapping(value = "/algorithms", produces = "application/json")
@ResponseBody
public ArrayNode getAlgorithmList() {
ArrayList<Algorithm> algorithms = new ArrayList<Algorithm>();
Algorithm algo = new Algorithm("Changement de luminosité", "changeLuminosity");
algorithms.add(algo);
algo = new Algorithm("Changement de teinte", "colorFilter");
algorithms.add(algo);
algo = new Algorithm("Filtre Moyenneur", "meanFilter");
algorithms.add(algo);
algo = new Algorithm("Filtre Gaussien", "gaussienFilter");
algorithms.add(algo);
algo = new Algorithm("Détection de contours", "contours");
algorithms.add(algo);
algo = new Algorithm("Histogramme", "histogram");
algorithms.add(algo);
ArrayNode nodes = mapper.createArrayNode();
for (Algorithm a : algorithms) {
ObjectNode objectNode = mapper.createObjectNode();
objectNode.put("name", a.getName());
objectNode.put("pass", a.getPass());
ArrayNode parameters = objectNode.putArray("parameters");
for (Parameter p : a.getParameters()) {
ObjectNode paramNode = mapper.createObjectNode();
paramNode.put("name", p.getName());
paramNode.put("displayName", p.getDisplayName());
paramNode.put("min", p.getMin());
paramNode.put("max", p.getMax());
paramNode.put("mustBeOdd", p.mustBeOdd());
parameters.add(paramNode);
}
nodes.add(objectNode);
}
return nodes;
}
@GetMapping(value = "/images/{id}", produces = { MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE, @GetMapping(value = "/images/{id}", produces = { MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE,
"application/json" }) "application/json" })
public ResponseEntity<?> getImage(@PathVariable("id") long id, public ResponseEntity<?> getImage(@PathVariable("id") long id,