Skip to content

Commit

Permalink
Implement the interface + code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
vedran-kasalica committed Nov 22, 2023
1 parent d105c58 commit 56adbb1
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 123 deletions.
36 changes: 18 additions & 18 deletions src/main/java/nl/esciencecenter/controller/NotYetAController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import nl.esciencecenter.models.SynthesisRun;
import nl.esciencecenter.service.SynthesisRunService;
import nl.esciencecenter.models.Domain;
import nl.esciencecenter.service.DomainService;

/**
* RestController to retch the SynthesisRun data from the database.
* RestController to handle the Domain data from the database.
* Not yet implemented.
*/
public class NotYetAController {

// autowired the SynthesisRunService class
// autowired the DomainService class
@Autowired
SynthesisRunService synthesisRunService;
DomainService domainService;

// creating a get mapping that retrieves all the synthesisRuns detail from the
// database
@GetMapping("/synthesisRun")
private List<SynthesisRun> getAllSynthesisRun() {
return synthesisRunService.getAllSynthesisRun();
@GetMapping("/domain")
private List<Domain> getAllDomain() {
return domainService.getAllDomain();
}

// creating a get mapping that retrieves the detail of a specific synthesisRun
@GetMapping("/synthesisRun/{id}")
private SynthesisRun getSynthesisRun(@PathVariable("id") int id) {
return synthesisRunService.getSynthesisRunById(id);
@GetMapping("/domain/{id}")
private Domain getSynthesisRun(@PathVariable("id") int id) {
return domainService.getDomainById(id);
}

// creating a delete mapping that deletes a specific synthesisRun
@DeleteMapping("/synthesisRun/{id}")
private void deleteSynthesisRun(@PathVariable("id") int id) {
synthesisRunService.delete(id);
@DeleteMapping("/domain/{id}")
private void deleteDomain(@PathVariable("id") int id) {
domainService.delete(id);
}

// creating post mapping that post the synthesisRun detail in the database
@PostMapping("/synthesisRun")
private int saveSynthesisRun(@RequestBody SynthesisRun synthesisRun) {
synthesisRunService.saveOrUpdate(synthesisRun);
return synthesisRun.getId();
@PostMapping("/domain")
private int saveSynthesisRun(@RequestBody Domain domain) {
domainService.saveOrUpdate(domain);
return domain.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public ResponseEntity<?> getImage(
}
try {
return ResponseEntity.ok().contentType(mediaType)
.body(IOUtils.getImageFromFileSystem(path));
.body(IOUtils.getImageFromFileSystem(path, imgFormat.toLowerCase()));
} catch (IOException e) {
return ResponseEntity.badRequest().body("The image file could not be found.");
}
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/nl/esciencecenter/models/SynthesisRun.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.esciencecenter.models;
package nl.esciencecenter.models.benchmarks;

import org.json.JSONObject;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.esciencecenter.models;
package nl.esciencecenter.models.benchmarks;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.esciencecenter.models;
package nl.esciencecenter.models.benchmarks;

import java.util.ArrayList;
import java.util.List;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.esciencecenter.models;
package nl.esciencecenter.models.benchmarks;

import java.util.Collection;

Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/java/nl/esciencecenter/restape/ApeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.util.Collection;
import java.util.List;

import nl.esciencecenter.models.BenchmarkBase;
import nl.esciencecenter.models.BioToolsBenchmark;
import nl.esciencecenter.models.benchmarks.BenchmarkBase;
import nl.esciencecenter.models.benchmarks.BioToolsBenchmark;
import nl.uu.cs.ape.APE;
import nl.uu.cs.ape.configuration.APECoreConfig;
import nl.uu.cs.ape.configuration.APERunConfig;
Expand Down Expand Up @@ -163,8 +163,8 @@ public static JSONArray runSynthesis(JSONObject configJson, boolean benchmark)

// Write solutions (as CWL files and figures) to the file system.
APE.writeCWLWorkflows(candidateSolutions);
APE.writeTavernaDesignGraphs(candidateSolutions, Format.PNG);
APE.writeTavernaDesignGraphs(candidateSolutions, Format.SVG);
APE.writeTavernaDesignGraphs(candidateSolutions, Format.PNG);

// benchmark workflows if required
if (benchmark) {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/nl/esciencecenter/restape/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ public class IOUtils {
* Get byte array that represents the image from the file system at the given
* path.
*
* @param filePath - path to the image
* @param filePath - path to the image
* @param formatName - a {@code String} containing the informal name of the
* format.
* @return byte array that represents the image
* @throws IOException - if the image cannot be read
*/
public static byte[] getImageFromFileSystem(Path filePath) throws IOException {
public static byte[] getImageFromFileSystem(Path filePath, String formatName) throws IOException {
File currFile = filePath.toFile();
BufferedImage image = ImageIO.read(currFile);

ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
ImageIO.write(image, "png", byteArray);
ImageIO.write(image, formatName, byteArray);

return byteArray.toByteArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import nl.esciencecenter.models.BenchmarkBase;
import nl.esciencecenter.models.BioToolsBenchmark;
import nl.esciencecenter.models.benchmarks.BenchmarkBase;
import nl.esciencecenter.models.benchmarks.BioToolsBenchmark;
import nl.uu.cs.ape.solver.solutionStructure.SolutionWorkflow;
import nl.uu.cs.ape.solver.solutionStructure.SolutionsList;
import nl.uu.cs.ape.utils.APEFiles;
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/nl/esciencecenter/service/DomainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -16,14 +19,21 @@ public class DomainService {

// getting all domain records
public List<Domain> getAllDomain() {
List<Domain> domains = new ArrayList<Domain>();
domainRepository.findAll().forEach(domain -> domains.add(domain));
List<Domain> domains = new ArrayList<>();
domainRepository.findAll().forEach(domains::add);
return domains;
}

// getting a specific record
/**
* Get the domain object with the given id.
*
* @param id - id of the domain
* @return - Domain object with the given id
* @throws NoSuchElementException - if no domain with the given id exists
*/
public Domain getDomainById(int id) {
return domainRepository.findById(id).get();
Optional<Domain> optionalDomain = domainRepository.findById(id);
return optionalDomain.orElseThrow(() -> new NoSuchElementException("No domain found with id: " + id));
}

public void saveOrUpdate(Domain domain) {
Expand Down
37 changes: 0 additions & 37 deletions src/main/java/nl/esciencecenter/service/SynthesisRunService.java

This file was deleted.

0 comments on commit 56adbb1

Please sign in to comment.