Skip to content

Commit

Permalink
fli-iam#2388-automatic executions - back
Browse files Browse the repository at this point in the history
  • Loading branch information
jcomedouteau committed Oct 16, 2024
1 parent 6b4f1b2 commit d8bbcb3
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import org.shanoir.ng.shared.exception.SecurityException;
import org.shanoir.ng.vip.dto.ExecutionCandidateDTO;
import org.shanoir.ng.vip.dto.VipExecutionDTO;
import org.shanoir.ng.vip.model.AutomaticExecution;
import org.shanoir.ng.vip.monitoring.model.ExecutionStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.IOException;
import java.util.List;

/**
* @author Alae Es-saki
Expand Down Expand Up @@ -65,17 +66,6 @@ ResponseEntity<IdName> createExecution(
method = RequestMethod.GET)
ResponseEntity<VipExecutionDTO> getExecution(@Parameter(description = "The execution identifier", required=true) @PathVariable("identifier") String identifier) throws IOException, RestServiceException, EntityNotFoundException, SecurityException;

@Operation(summary = "Get list of existing automatic executions for the given study_id", description = "Returns the list of existing automatic executions for the given study id", tags={ })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "successful response, returns the list of automatic executions"),
@ApiResponse(responseCode = "403", description = "forbidden"),
@ApiResponse(responseCode = "500", description = "unexpected error"),
@ApiResponse(responseCode = "503", description = "Internal error")})
@GetMapping(value = "/automatic/{studyId}",
produces = { "application/json", "application/octet-stream" })
ResponseEntity<List<AutomaticExecution>> getAutomaticExecutions(@Parameter(description = "The study Id", required=true) @PathVariable("studyId") Long studyId) throws IOException, RestServiceException, EntityNotFoundException, SecurityException;


@Operation(summary = "Get stderr logs for the given VIP execution identifier", description = "Returns the stderr logs of the VIP execution that has the given identifier in parameter.", tags={ })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "successful response, returns the status"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.shanoir.ng.vip.dto.DatasetParameterDTO;
import org.shanoir.ng.vip.dto.ExecutionCandidateDTO;
import org.shanoir.ng.vip.dto.VipExecutionDTO;
import org.shanoir.ng.vip.model.AutomaticExecution;
import org.shanoir.ng.vip.monitoring.model.ExecutionMonitoring;
import org.shanoir.ng.vip.monitoring.model.ExecutionStatus;
import org.shanoir.ng.vip.monitoring.schedule.ExecutionStatusMonitorService;
Expand All @@ -46,7 +45,10 @@

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ExecutionApiController implements ExecutionApi {
Expand Down Expand Up @@ -96,7 +98,7 @@ public ResponseEntity<IdName> createExecution(
return new ResponseEntity<>(createdMonitoring, HttpStatus.OK);
}

private List<Dataset> getDatasetsFromParams(List<DatasetParameterDTO> parameters){
private List<Dataset> getDatasetsFromParams(List<DatasetParameterDTO> parameters) {
List<Long> datasetsIds = new ArrayList<>();
for (DatasetParameterDTO param : parameters) {
datasetsIds.addAll(param.getDatasetIds());
Expand Down Expand Up @@ -189,13 +191,13 @@ private String getResultsLocationUri(String resultLocation, ExecutionCandidateDT
+ "&md5=none&type=File";
}

private String getInputValueUri(ExecutionCandidateDTO candidate, String groupBy, String exportFormat, String resourceId, String authenticationToken){
private String getInputValueUri(ExecutionCandidateDTO candidate, String groupBy, String exportFormat, String resourceId, String authenticationToken) {
String entityName = "resource_id+" + resourceId + "+" + groupBy + ("dcm".equals(exportFormat) ? ".zip" : ".nii.gz");
return SHANOIR_URI_SCHEME + entityName
+ "?format=" + exportFormat
+ "&resourceId=" + resourceId
+ "&token=" + authenticationToken
+ (candidate.getConverterId() != null ? ("&converterId=" + candidate.getConverterId()) : "")
+ (candidate.getConverterId() != null ? ("&converterId=" + candidate.getConverterId()) : "")
+ "&refreshToken=" + candidate.getRefreshToken()
+ "&clientId=" + candidate.getClient()
+ "&md5=none&type=File";
Expand Down Expand Up @@ -226,13 +228,13 @@ private ExecutionMonitoring createExecutionMonitoring(ExecutionCandidateDTO exec
}

@Override
public ResponseEntity<VipExecutionDTO> getExecution(@Parameter(description = "The execution identifier", required=true) @PathVariable("identifier") String identifier) {
public ResponseEntity<VipExecutionDTO> getExecution(@Parameter(description = "The execution identifier", required = true) @PathVariable("identifier") String identifier) {
return ResponseEntity.ok(vipClient.getExecution(identifier).block());
}


@Override
public ResponseEntity<ExecutionStatus> getExecutionStatus(@Parameter(description = "The execution identifier", required=true) @PathVariable("identifier") String identifier) {
public ResponseEntity<ExecutionStatus> getExecutionStatus(@Parameter(description = "The execution identifier", required = true) @PathVariable("identifier") String identifier) {
return ResponseEntity.ok(vipClient.getExecution(identifier).map(VipExecutionDTO::getStatus).block());
}

Expand All @@ -246,12 +248,5 @@ public ResponseEntity<String> getExecutionStderr(String identifier) {
public ResponseEntity<String> getExecutionStdout(String identifier) {
return ResponseEntity.ok(vipClient.getExecutionStdout(identifier).block());
}

@Override
public ResponseEntity<List<AutomaticExecution>> getAutomaticExecutions(@Parameter(description = "The study Id", required=true) @PathVariable("studyId") Long studyId) {
AutomaticExecution autoExec = new AutomaticExecution();
autoExec.setName("superbname");
return new ResponseEntity<>(Collections.singletonList(autoExec), HttpStatus.OK);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.shanoir.ng.vip.planning.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.shanoir.ng.shared.exception.EntityNotFoundException;
import org.shanoir.ng.shared.exception.RestServiceException;
import org.shanoir.ng.shared.exception.SecurityException;
import org.shanoir.ng.vip.planning.model.PlannedExecution;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/*
Planned execution are VIP execution atuomatically applied after an import.
*/
@Tag(name = "plannedexecution", description = "the planned execution API")
@RequestMapping("/vip/execution/planned")
public interface PlannedExecutionApi {

@Operation(summary = "Get list of existing planned executions for the given study_id", description = "Returns the list of existing planned executions for the given study id", tags={ })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "successful response, returns the list of planned executions"),
@ApiResponse(responseCode = "403", description = "forbidden"),
@ApiResponse(responseCode = "500", description = "unexpected error"),
@ApiResponse(responseCode = "503", description = "Internal error")})
@GetMapping(value = "/byStudy/{studyId}",
produces = { "application/json", "application/octet-stream" })
ResponseEntity<List<PlannedExecution>> getPlannedExecutionsByStudyId(@Parameter(description = "The study Id", required=true) @PathVariable("studyId") Long studyId) throws IOException, RestServiceException, EntityNotFoundException, SecurityException;

@Operation(summary = "Create a new PlannedExecution entity", description = "Creates a new planned execution", tags={ })
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "successful creation"),
@ApiResponse(responseCode = "403", description = "forbidden"),
@ApiResponse(responseCode = "500", description = "unexpected error"),
@ApiResponse(responseCode = "503", description = "Internal error")})
@PostMapping(value = "/create", consumes = "application/json", produces = "application/json")
ResponseEntity<PlannedExecution> createPlannedExecution(@RequestBody PlannedExecution plannedExecution) throws IOException, RestServiceException, SecurityException;

@Operation(summary = "Delete a PlannedExecution entity", description = "Deletes the planned execution by its ID", tags={ })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "successful deletion"),
@ApiResponse(responseCode = "403", description = "forbidden"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error"),
@ApiResponse(responseCode = "503", description = "Internal error")})
@DeleteMapping(value = "/delete/{executionId}")
ResponseEntity<Void> deletePlannedExecution(@Parameter(description = "The PlannedExecution Id", required=true) @PathVariable("executionId") Long executionId) throws IOException, RestServiceException, EntityNotFoundException, SecurityException;

@Operation(summary = "Get a PlannedExecution entity by ID", description = "Returns a planned execution by its ID", tags={ })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "successful response, returns the planned execution"),
@ApiResponse(responseCode = "403", description = "forbidden"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error"),
@ApiResponse(responseCode = "503", description = "Internal error")})
@GetMapping(value = "/{executionId}", produces = "application/json")
ResponseEntity<PlannedExecution> getPlannedExecutionById(@Parameter(description = "The PlannedExecution Id", required=true) @PathVariable("executionId") Long executionId) throws IOException, RestServiceException, EntityNotFoundException, SecurityException;

@Operation(summary = "Update a PlannedExecution entity", description = "Updates the existing planned execution by its ID", tags={ })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "successful update, returns the updated planned execution"),
@ApiResponse(responseCode = "403", description = "forbidden"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error"),
@ApiResponse(responseCode = "503", description = "Internal error")})
@PostMapping(value = "/update/{executionId}", consumes = "application/json", produces = "application/json")
ResponseEntity<PlannedExecution> updatePlannedExecution(@RequestBody PlannedExecution plannedExecution) throws IOException, RestServiceException, EntityNotFoundException, SecurityException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.shanoir.ng.vip.planning.controller;

import io.swagger.v3.oas.annotations.Parameter;
import org.shanoir.ng.shared.exception.EntityNotFoundException;
import org.shanoir.ng.shared.exception.RestServiceException;
import org.shanoir.ng.shared.exception.SecurityException;
import org.shanoir.ng.vip.planning.model.PlannedExecution;
import org.shanoir.ng.vip.planning.service.PlannedExecutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.IOException;
import java.util.List;

/*
Planned execution are VIP execution atuomatically applied after an import.
*/
@Service
public class PlannedExecutionApiController implements PlannedExecutionApi {

@Autowired
PlannedExecutionService plannedExecutionService;

@Override
public ResponseEntity<List<PlannedExecution>> getPlannedExecutionsByStudyId (@Parameter(description = "The study Id", required=true) @PathVariable("studyId") Long studyId) {
List<PlannedExecution> executions = this.plannedExecutionService.findByStudyId(studyId);
return new ResponseEntity<>(executions, HttpStatus.OK);
}

@Override
public ResponseEntity<PlannedExecution> createPlannedExecution(@RequestBody PlannedExecution plannedExecution) throws IOException, RestServiceException, SecurityException {
return new ResponseEntity<PlannedExecution>(this.plannedExecutionService.save(plannedExecution), HttpStatus.OK);
}
@Override
public ResponseEntity<Void> deletePlannedExecution(@Parameter(description = "The PlannedExecution Id", required=true) @PathVariable("executionId") Long executionId) throws IOException, RestServiceException, EntityNotFoundException, SecurityException{
this.plannedExecutionService.delete(executionId);
return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
}
@Override
public ResponseEntity<PlannedExecution> getPlannedExecutionById(@Parameter(description = "The PlannedExecution Id", required=true) @PathVariable("executionId") Long executionId) throws IOException, RestServiceException, EntityNotFoundException, SecurityException{
return new ResponseEntity<PlannedExecution>(this.plannedExecutionService.findById(executionId), HttpStatus.OK);
}
@Override
public ResponseEntity<PlannedExecution> updatePlannedExecution(@RequestBody PlannedExecution plannedExecution) throws IOException, RestServiceException, EntityNotFoundException, SecurityException {
return new ResponseEntity<PlannedExecution>(this.plannedExecutionService.update(plannedExecution), HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.shanoir.ng.vip.model;
package org.shanoir.ng.vip.planning.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;
import org.shanoir.ng.shared.model.Study;
import org.shanoir.ng.vip.monitoring.model.PipelineParameter;

import java.util.List;

/**
* This class represents the associated criterias for an automatic execution realized after an import in shanoir.
*/
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class AutomaticExecution {
public class PlannedExecution {

@Id
private Long id;
Expand All @@ -23,11 +23,11 @@ public class AutomaticExecution {
@JoinColumn(name = "study_id")
private Study study;

/*
private String execution;

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "pipeline_parameter")
@JoinTable(name = "execution_pipeline_parameters")
private List<PipelineParameter> parameters;
*/

public String getName() {
return name;
Expand All @@ -52,4 +52,20 @@ public Study getStudy() {
public void setStudy(Study study) {
this.study = study;
}

public String getExecution() {
return execution;
}

public void setExecution(String execution) {
this.execution = execution;
}

public List<PipelineParameter> getParameters() {
return parameters;
}

public void setParameters(List<PipelineParameter> parameters) {
this.parameters = parameters;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.shanoir.ng.vip.planning.repository;

import org.shanoir.ng.vip.planning.model.PlannedExecution;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface PlannedExecutionRepository extends CrudRepository<PlannedExecution, Long> {

List<PlannedExecution> findByStudyId(Long studyId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.shanoir.ng.vip.planning.service;

import org.shanoir.ng.datasetacquisition.model.DatasetAcquisition;
import org.shanoir.ng.vip.planning.model.PlannedExecution;
import org.springframework.scheduling.annotation.Async;

import java.util.List;

public interface PlannedExecutionService {

@Async
void checkForPlannedExecutions(List<DatasetAcquisition> createdAcquisitions);

List<PlannedExecution> findByStudyId(Long studyId);

PlannedExecution update(PlannedExecution plannedExecution);

PlannedExecution findById(Long executionId);

void delete(Long executionId);

PlannedExecution save(PlannedExecution plannedExecution);
}
Loading

0 comments on commit d8bbcb3

Please sign in to comment.