Skip to content

Commit

Permalink
Pre-weekend commit and run
Browse files Browse the repository at this point in the history
  • Loading branch information
flawmop committed Sep 7, 2024
1 parent 7721522 commit eb33d0c
Show file tree
Hide file tree
Showing 23 changed files with 726 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.insilicosoft.portal.svc.rip.controller;

import java.io.IOException ;
import java.util.concurrent.CompletableFuture;

import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
Expand All @@ -15,7 +14,9 @@

import com.insilicosoft.portal.svc.rip.RipIdentifiers;
import com.insilicosoft.portal.svc.rip.exception.FileProcessingException;
import com.insilicosoft.portal.svc.rip.exception.InputVerificationException;
import com.insilicosoft.portal.svc.rip.service.InputProcessorService;
import com.insilicosoft.portal.svc.rip.service.SubmissionService;

import io.micrometer.core.annotation.Timed;

Expand All @@ -26,19 +27,23 @@
*/
@Controller
@RequestMapping(RipIdentifiers.REQUEST_MAPPING_RUN)
public class FileAsyncUploadController {
public class FileUploadController {

private static final Logger log = LoggerFactory.getLogger(FileAsyncUploadController.class);
private static final Logger log = LoggerFactory.getLogger(FileUploadController.class);

private final InputProcessorService inputProcessorService;
private final SubmissionService submissionService;

/**
* Initialising constructor.
*
* @param inputProcessorService Input processing implementation.
* @param submissionService Submission service.
*/
public FileAsyncUploadController(final InputProcessorService inputProcessorService) {
public FileUploadController(final InputProcessorService inputProcessorService,
final SubmissionService submissionService) {
this.inputProcessorService = inputProcessorService;
this.submissionService = submissionService;
}

// TODO Remove GET mapping in /run endpoint controller
Expand All @@ -57,13 +62,14 @@ public ResponseEntity<String> get() {
*/
@PostMapping(RipIdentifiers.REQUEST_MAPPING_UPLOAD_ASYNC)
@Timed(value = "run.handle-file-upload", description = "POST Multipart request for file upload")
public CompletableFuture<ResponseEntity<String>> handleFileUpload(final @RequestPart(required=false,
value=RipIdentifiers.PARAM_NAME_SIMULATION_FILE)
MultipartFile file)
throws FileProcessingException {
public ResponseEntity<String> handleFileUpload(final @RequestPart(required=false,
value=RipIdentifiers.PARAM_NAME_SIMULATION_FILE)
MultipartFile file)
throws FileProcessingException,
InputVerificationException {

if (file == null) {
final String message = "The POST request must supply the parameter '" + RipIdentifiers.PARAM_NAME_SIMULATION_FILE + "'";
final String message = "No Multipart file! Did you supply the parameter '" + RipIdentifiers.PARAM_NAME_SIMULATION_FILE + "' in the POST request?";
log.warn("~handleFileUpload() : ".concat(message));
throw new FileProcessingException(message);
}
Expand All @@ -80,9 +86,11 @@ public CompletableFuture<ResponseEntity<String>> handleFileUpload(final @Request
throw new FileProcessingException(e.getMessage());
}

inputProcessorService.processAsync(fileByteArray);
final long submissionId = submissionService.submit();

return CompletableFuture.completedFuture(ResponseEntity.ok(fileName));
inputProcessorService.process(submissionId, fileByteArray);

return ResponseEntity.ok(String.valueOf(submissionId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.multipart.MultipartException;

import com.insilicosoft.portal.svc.rip.exception.FileProcessingException;
import com.insilicosoft.portal.svc.rip.exception.InputVerificationException;

/**
* REST controller advice.
Expand All @@ -28,6 +29,17 @@ public ResponseEntity<String> handleFileProcessingProblem(FileProcessingExceptio
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}

/**
* Something we're going to handle.
*
* @param e Input verification exception.
* @return Response entity.
*/
@ExceptionHandler(InputVerificationException.class)
public ResponseEntity<String> handleInputVerificationProblem(InputVerificationException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}

/**
* Max upload size exceeded.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.insilicosoft.portal.svc.rip.event;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

public record SimulationMessage(int modelId, Float pacingFrequency, Float pacingMaxTime,
List<Float> plasmaPoints) {
public record SimulationMessage(long simulationId, int modelId, BigDecimal pacingFrequency,
BigDecimal pacingMaxTime, List<BigDecimal> plasmaPoints) {

public SimulationMessage {
Objects.requireNonNull(pacingFrequency, "pacingFrequency is required");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

/**
* File processing exception.
* <p>
* Throw this exception if there's been a problem receiving and extracting the content of the file.
*
* @author geoff
* @see InputVerificationException
*/
public class FileProcessingException extends Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.insilicosoft.portal.svc.rip.exception;

/**
* Input verification exception.
* <p>
* Subsequent to a successful receipt of the input, verify that it is valid. If it's not, throw
* this exception.
*
* @author geoff
*/
public class InputVerificationException extends Exception {

private static final long serialVersionUID = -5793083895981506346L;

/**
* Initialising constructor.
*
* @param message
*/
public InputVerificationException(final String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.insilicosoft.portal.svc.rip.persistence;

public enum State {
APPROVED, COMPLETED, CREATED, FAILED, REJECTED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.insilicosoft.portal.svc.rip.persistence.entity;

import com.insilicosoft.portal.svc.rip.value.MessageLevel;

import jakarta.persistence.Embeddable;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;

@Embeddable
public class Message {

@Enumerated(EnumType.STRING)
private MessageLevel level;

private String message;

protected Message() {}

public Message(MessageLevel level, String message) {
this.level = level;
this.message = message;
}

/**
* @return the level
*/
public MessageLevel getLevel() {
return level;
}

/**
* @return the message
*/
public String getMessage() {
return message;
}

@Override
public String toString() {
return "Message [level=" + level + ", message=" + message + "]";
}

}
Loading

0 comments on commit eb33d0c

Please sign in to comment.