fix:第三章开发结束
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package org.brapi.test.BrAPITestServer.controller.geno;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.controller.core.BrAPIController;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.CallSetWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.service.geno.CallSetService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.model.geno.CallSet;
|
||||
import io.swagger.model.geno.CallSetResponse;
|
||||
import io.swagger.model.geno.CallSetsListResponse;
|
||||
import io.swagger.model.geno.CallSetsListResponseResult;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
public class GenotypingCallSetWriteController extends BrAPIController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GenotypingCallSetWriteController.class);
|
||||
|
||||
private final CallSetService callSetService;
|
||||
private final HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
public GenotypingCallSetWriteController(CallSetService callSetService, HttpServletRequest request) {
|
||||
this.callSetService = callSetService;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/callsets", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.POST)
|
||||
public ResponseEntity<CallSetsListResponse> callSetsPost(@RequestBody CallSetWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
CallSet data = callSetService.saveCallSet(body);
|
||||
return responseOK(new CallSetsListResponse(), new CallSetsListResponseResult(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/callsets/{callSetDbId}", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.PUT)
|
||||
public ResponseEntity<CallSetResponse> callSetsCallSetDbIdPut(@PathVariable("callSetDbId") String callSetDbId,
|
||||
@RequestBody CallSetWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
CallSet data = callSetService.updateCallSet(callSetDbId, body);
|
||||
return responseOK(new CallSetResponse(), data);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/callsets/{callSetDbId}", produces = {
|
||||
"application/json" }, method = RequestMethod.DELETE)
|
||||
public ResponseEntity<CallSetResponse> callSetsCallSetDbIdDelete(@PathVariable("callSetDbId") String callSetDbId,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
CallSet data = callSetService.deleteCallSet(callSetDbId);
|
||||
return responseOK(new CallSetResponse(), data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package org.brapi.test.BrAPITestServer.controller.geno;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.controller.core.BrAPIController;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.CallWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.service.geno.CallService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.model.Metadata;
|
||||
import io.swagger.model.geno.Call;
|
||||
import io.swagger.model.geno.CallsListResponse;
|
||||
import io.swagger.model.geno.CallsListResponseResult;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
public class GenotypingCallWriteController extends BrAPIController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GenotypingCallWriteController.class);
|
||||
|
||||
private final CallService callService;
|
||||
private final HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
public GenotypingCallWriteController(CallService callService, HttpServletRequest request) {
|
||||
this.callService = callService;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/calls", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.POST)
|
||||
public ResponseEntity<CallsListResponse> callsPost(@RequestBody CallWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
Call data = callService.saveCall(body);
|
||||
Metadata metadata = generateEmptyMetadata();
|
||||
CallsListResponseResult result = new CallsListResponseResult();
|
||||
result.setData(List.of(data));
|
||||
return responseOK(new CallsListResponse(), result, metadata);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/calls/import", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.POST)
|
||||
public ResponseEntity<CallsListResponse> callsImportPost(@RequestBody List<CallWriteRequest> body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
List<Call> data = callService.importCalls(body);
|
||||
Metadata metadata = generateEmptyMetadata();
|
||||
CallsListResponseResult result = new CallsListResponseResult();
|
||||
result.setData(data);
|
||||
return responseOK(new CallsListResponse(), result, metadata);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/calls/{callDbId}", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.PUT)
|
||||
public ResponseEntity<CallsListResponse> callsCallDbIdPut(@PathVariable("callDbId") String callDbId,
|
||||
@RequestBody CallWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
Call data = callService.updateCall(callDbId, body);
|
||||
Metadata metadata = generateEmptyMetadata();
|
||||
CallsListResponseResult result = new CallsListResponseResult();
|
||||
result.setData(List.of(data));
|
||||
return responseOK(new CallsListResponse(), result, metadata);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/calls/{callDbId}", produces = {
|
||||
"application/json" }, method = RequestMethod.DELETE)
|
||||
public ResponseEntity<CallsListResponse> callsCallDbIdDelete(@PathVariable("callDbId") String callDbId,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
Call data = callService.deleteCall(callDbId);
|
||||
Metadata metadata = generateEmptyMetadata();
|
||||
CallsListResponseResult result = new CallsListResponseResult();
|
||||
result.setData(List.of(data));
|
||||
return responseOK(new CallsListResponse(), result, metadata);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package org.brapi.test.BrAPITestServer.controller.geno;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.controller.core.BrAPIController;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.GenomeMapWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.LinkageGroupWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.MarkerPositionWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.service.geno.GenomeMapService;
|
||||
import org.brapi.test.BrAPITestServer.service.geno.MarkerPositionService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.model.geno.GenomeMap;
|
||||
import io.swagger.model.geno.GenomeMapListResponse;
|
||||
import io.swagger.model.geno.GenomeMapListResponseResult;
|
||||
import io.swagger.model.geno.GenomeMapSingleResponse;
|
||||
import io.swagger.model.geno.LinkageGroup;
|
||||
import io.swagger.model.geno.LinkageGroupListResponse;
|
||||
import io.swagger.model.geno.LinkageGroupListResponseResult;
|
||||
import io.swagger.model.geno.MarkerPosition;
|
||||
import io.swagger.model.geno.MarkerPositionsListResponse;
|
||||
import io.swagger.model.geno.MarkerPositionsListResponseResult;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
public class GenotypingGenomeMapWriteController extends BrAPIController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GenotypingGenomeMapWriteController.class);
|
||||
|
||||
private final GenomeMapService genomeMapService;
|
||||
private final MarkerPositionService markerPositionService;
|
||||
private final HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
public GenotypingGenomeMapWriteController(GenomeMapService genomeMapService,
|
||||
MarkerPositionService markerPositionService, HttpServletRequest request) {
|
||||
this.genomeMapService = genomeMapService;
|
||||
this.markerPositionService = markerPositionService;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/maps", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.POST)
|
||||
public ResponseEntity<GenomeMapListResponse> mapsPost(@RequestBody GenomeMapWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
GenomeMap data = genomeMapService.saveMap(body);
|
||||
return responseOK(new GenomeMapListResponse(), new GenomeMapListResponseResult(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/maps/{mapDbId}", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.PUT)
|
||||
public ResponseEntity<GenomeMapSingleResponse> mapsMapDbIdPut(@PathVariable("mapDbId") String mapDbId,
|
||||
@RequestBody GenomeMapWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
GenomeMap data = genomeMapService.updateMap(mapDbId, body);
|
||||
return responseOK(new GenomeMapSingleResponse(), data);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/maps/{mapDbId}", produces = { "application/json" }, method = RequestMethod.DELETE)
|
||||
public ResponseEntity<GenomeMapSingleResponse> mapsMapDbIdDelete(@PathVariable("mapDbId") String mapDbId,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
GenomeMap data = genomeMapService.deleteMap(mapDbId);
|
||||
return responseOK(new GenomeMapSingleResponse(), data);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/maps/{mapDbId}/linkagegroups", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.POST)
|
||||
public ResponseEntity<LinkageGroupListResponse> mapsMapDbIdLinkagegroupsPost(
|
||||
@PathVariable("mapDbId") String mapDbId, @RequestBody LinkageGroupWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
LinkageGroup data = genomeMapService.saveLinkageGroup(mapDbId, body);
|
||||
return responseOK(new LinkageGroupListResponse(), new LinkageGroupListResponseResult(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/maps/{mapDbId}/linkagegroups/{linkageGroupDbId}", produces = {
|
||||
"application/json" }, consumes = { "application/json" }, method = RequestMethod.PUT)
|
||||
public ResponseEntity<LinkageGroupListResponse> mapsMapDbIdLinkagegroupsLinkageGroupDbIdPut(
|
||||
@PathVariable("mapDbId") String mapDbId, @PathVariable("linkageGroupDbId") String linkageGroupDbId,
|
||||
@RequestBody LinkageGroupWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
LinkageGroup data = genomeMapService.updateLinkageGroup(mapDbId, linkageGroupDbId, body);
|
||||
return responseOK(new LinkageGroupListResponse(), new LinkageGroupListResponseResult(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/maps/{mapDbId}/linkagegroups/{linkageGroupDbId}", produces = {
|
||||
"application/json" }, method = RequestMethod.DELETE)
|
||||
public ResponseEntity<LinkageGroupListResponse> mapsMapDbIdLinkagegroupsLinkageGroupDbIdDelete(
|
||||
@PathVariable("mapDbId") String mapDbId, @PathVariable("linkageGroupDbId") String linkageGroupDbId,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
LinkageGroup data = genomeMapService.deleteLinkageGroup(mapDbId, linkageGroupDbId);
|
||||
return responseOK(new LinkageGroupListResponse(), new LinkageGroupListResponseResult(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/markerpositions", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.POST)
|
||||
public ResponseEntity<MarkerPositionsListResponse> markerpositionsPost(@RequestBody MarkerPositionWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
MarkerPosition data = markerPositionService.saveMarkerPosition(body);
|
||||
return responseOK(new MarkerPositionsListResponse(), new MarkerPositionsListResponseResult(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/markerpositions/{markerPositionDbId}", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.PUT)
|
||||
public ResponseEntity<MarkerPositionsListResponse> markerpositionsMarkerPositionDbIdPut(
|
||||
@PathVariable("markerPositionDbId") String markerPositionDbId,
|
||||
@RequestBody MarkerPositionWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
MarkerPosition data = markerPositionService.updateMarkerPosition(markerPositionDbId, body);
|
||||
return responseOK(new MarkerPositionsListResponse(), new MarkerPositionsListResponseResult(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/markerpositions/{markerPositionDbId}", produces = {
|
||||
"application/json" }, method = RequestMethod.DELETE)
|
||||
public ResponseEntity<MarkerPositionsListResponse> markerpositionsMarkerPositionDbIdDelete(
|
||||
@PathVariable("markerPositionDbId") String markerPositionDbId,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
MarkerPosition data = markerPositionService.deleteMarkerPosition(markerPositionDbId);
|
||||
return responseOK(new MarkerPositionsListResponse(), new MarkerPositionsListResponseResult(), List.of(data));
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,16 @@ import java.util.List;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.controller.core.BrAPIController;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantSetAnalysisListResponse;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantSetAnalysisWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantSetAvailableFormatListResponse;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantSetAvailableFormatRecord;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantSetAvailableFormatWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantSetWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.service.geno.VariantService;
|
||||
import org.brapi.test.BrAPITestServer.service.geno.VariantSetAnalysisService;
|
||||
import org.brapi.test.BrAPITestServer.service.geno.VariantSetAvailableFormatService;
|
||||
import org.brapi.test.BrAPITestServer.service.geno.VariantSetService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -20,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.model.geno.Analysis;
|
||||
import io.swagger.model.geno.Variant;
|
||||
import io.swagger.model.geno.VariantSet;
|
||||
import io.swagger.model.geno.VariantSetResponse;
|
||||
@@ -36,13 +44,19 @@ public class GenotypingVariantWriteController extends BrAPIController {
|
||||
private static final Logger log = LoggerFactory.getLogger(GenotypingVariantWriteController.class);
|
||||
|
||||
private final VariantSetService variantSetService;
|
||||
private final VariantSetAnalysisService variantSetAnalysisService;
|
||||
private final VariantSetAvailableFormatService variantSetAvailableFormatService;
|
||||
private final VariantService variantService;
|
||||
private final HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
public GenotypingVariantWriteController(VariantSetService variantSetService, VariantService variantService,
|
||||
public GenotypingVariantWriteController(VariantSetService variantSetService,
|
||||
VariantSetAnalysisService variantSetAnalysisService,
|
||||
VariantSetAvailableFormatService variantSetAvailableFormatService, VariantService variantService,
|
||||
HttpServletRequest request) {
|
||||
this.variantSetService = variantSetService;
|
||||
this.variantSetAnalysisService = variantSetAnalysisService;
|
||||
this.variantSetAvailableFormatService = variantSetAvailableFormatService;
|
||||
this.variantService = variantService;
|
||||
this.request = request;
|
||||
}
|
||||
@@ -88,6 +102,131 @@ public class GenotypingVariantWriteController extends BrAPIController {
|
||||
return responseOK(new VariantSetResponse(), data);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/variantsets/{variantSetDbId}/analysis", produces = {
|
||||
"application/json" }, method = RequestMethod.GET)
|
||||
public ResponseEntity<VariantSetAnalysisListResponse> variantSetsVariantSetDbIdAnalysisGet(
|
||||
@PathVariable("variantSetDbId") String variantSetDbId,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
List<Analysis> data = variantSetAnalysisService.findAnalysisByVariantSet(variantSetDbId);
|
||||
return responseOK(new VariantSetAnalysisListResponse(), new VariantSetAnalysisListResponse.Result(), data);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/variantsets/{variantSetDbId}/analysis", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.POST)
|
||||
public ResponseEntity<VariantSetAnalysisListResponse> variantSetsVariantSetDbIdAnalysisPost(
|
||||
@PathVariable("variantSetDbId") String variantSetDbId, @RequestBody VariantSetAnalysisWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
Analysis data = variantSetAnalysisService.saveAnalysis(variantSetDbId, body);
|
||||
return responseOK(new VariantSetAnalysisListResponse(), new VariantSetAnalysisListResponse.Result(),
|
||||
List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/variantsets/{variantSetDbId}/analysis/{analysisDbId}", produces = {
|
||||
"application/json" }, consumes = { "application/json" }, method = RequestMethod.PUT)
|
||||
public ResponseEntity<VariantSetAnalysisListResponse> variantSetsVariantSetDbIdAnalysisAnalysisDbIdPut(
|
||||
@PathVariable("variantSetDbId") String variantSetDbId,
|
||||
@PathVariable("analysisDbId") String analysisDbId, @RequestBody VariantSetAnalysisWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
Analysis data = variantSetAnalysisService.updateAnalysis(variantSetDbId, analysisDbId, body);
|
||||
return responseOK(new VariantSetAnalysisListResponse(), new VariantSetAnalysisListResponse.Result(),
|
||||
List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/variantsets/{variantSetDbId}/analysis/{analysisDbId}", produces = {
|
||||
"application/json" }, method = RequestMethod.DELETE)
|
||||
public ResponseEntity<VariantSetAnalysisListResponse> variantSetsVariantSetDbIdAnalysisAnalysisDbIdDelete(
|
||||
@PathVariable("variantSetDbId") String variantSetDbId,
|
||||
@PathVariable("analysisDbId") String analysisDbId,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
Analysis data = variantSetAnalysisService.deleteAnalysis(variantSetDbId, analysisDbId);
|
||||
return responseOK(new VariantSetAnalysisListResponse(), new VariantSetAnalysisListResponse.Result(),
|
||||
List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/variantsets/{variantSetDbId}/availableformats", produces = {
|
||||
"application/json" }, method = RequestMethod.GET)
|
||||
public ResponseEntity<VariantSetAvailableFormatListResponse> variantSetsVariantSetDbIdAvailableformatsGet(
|
||||
@PathVariable("variantSetDbId") String variantSetDbId,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
List<VariantSetAvailableFormatRecord> data = variantSetAvailableFormatService
|
||||
.findFormatsByVariantSet(variantSetDbId);
|
||||
return responseOK(new VariantSetAvailableFormatListResponse(),
|
||||
new VariantSetAvailableFormatListResponse.Result(), data);
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/variantsets/{variantSetDbId}/availableformats", produces = { "application/json" },
|
||||
consumes = { "application/json" }, method = RequestMethod.POST)
|
||||
public ResponseEntity<VariantSetAvailableFormatListResponse> variantSetsVariantSetDbIdAvailableformatsPost(
|
||||
@PathVariable("variantSetDbId") String variantSetDbId,
|
||||
@RequestBody VariantSetAvailableFormatWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
VariantSetAvailableFormatRecord data = variantSetAvailableFormatService.saveFormat(variantSetDbId, body);
|
||||
return responseOK(new VariantSetAvailableFormatListResponse(),
|
||||
new VariantSetAvailableFormatListResponse.Result(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/variantsets/{variantSetDbId}/availableformats/{formatDbId}", produces = {
|
||||
"application/json" }, consumes = { "application/json" }, method = RequestMethod.PUT)
|
||||
public ResponseEntity<VariantSetAvailableFormatListResponse> variantSetsVariantSetDbIdAvailableformatsFormatDbIdPut(
|
||||
@PathVariable("variantSetDbId") String variantSetDbId, @PathVariable("formatDbId") String formatDbId,
|
||||
@RequestBody VariantSetAvailableFormatWriteRequest body,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
VariantSetAvailableFormatRecord data = variantSetAvailableFormatService.updateFormat(variantSetDbId, formatDbId,
|
||||
body);
|
||||
return responseOK(new VariantSetAvailableFormatListResponse(),
|
||||
new VariantSetAvailableFormatListResponse.Result(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/variantsets/{variantSetDbId}/availableformats/{formatDbId}", produces = {
|
||||
"application/json" }, method = RequestMethod.DELETE)
|
||||
public ResponseEntity<VariantSetAvailableFormatListResponse> variantSetsVariantSetDbIdAvailableformatsFormatDbIdDelete(
|
||||
@PathVariable("variantSetDbId") String variantSetDbId, @PathVariable("formatDbId") String formatDbId,
|
||||
@RequestHeader(value = "Authorization", required = false) String authorization)
|
||||
throws BrAPIServerException {
|
||||
log.debug("Request: " + request.getRequestURI());
|
||||
validateSecurityContext(request, "ROLE_USER");
|
||||
validateAcceptHeader(request);
|
||||
VariantSetAvailableFormatRecord data = variantSetAvailableFormatService.deleteFormat(variantSetDbId, formatDbId);
|
||||
return responseOK(new VariantSetAvailableFormatListResponse(),
|
||||
new VariantSetAvailableFormatListResponse.Result(), List.of(data));
|
||||
}
|
||||
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/variants", produces = { "application/json" }, consumes = {
|
||||
"application/json" }, method = RequestMethod.POST)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CallSetWriteRequest {
|
||||
private String callSetDbId;
|
||||
private String callSetName;
|
||||
private String sampleDbId;
|
||||
private List<String> variantSetDbIds;
|
||||
|
||||
public String getCallSetDbId() {
|
||||
return callSetDbId;
|
||||
}
|
||||
|
||||
public void setCallSetDbId(String callSetDbId) {
|
||||
this.callSetDbId = callSetDbId;
|
||||
}
|
||||
|
||||
public String getCallSetName() {
|
||||
return callSetName;
|
||||
}
|
||||
|
||||
public void setCallSetName(String callSetName) {
|
||||
this.callSetName = callSetName;
|
||||
}
|
||||
|
||||
public String getSampleDbId() {
|
||||
return sampleDbId;
|
||||
}
|
||||
|
||||
public void setSampleDbId(String sampleDbId) {
|
||||
this.sampleDbId = sampleDbId;
|
||||
}
|
||||
|
||||
public List<String> getVariantSetDbIds() {
|
||||
return variantSetDbIds;
|
||||
}
|
||||
|
||||
public void setVariantSetDbIds(List<String> variantSetDbIds) {
|
||||
this.variantSetDbIds = variantSetDbIds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
public class CallWriteRequest {
|
||||
private String callDbId;
|
||||
private String callSetDbId;
|
||||
private String variantDbId;
|
||||
private String genotype;
|
||||
private Integer readDepth;
|
||||
private Double genotypeLikelihood;
|
||||
private String phaseSet;
|
||||
|
||||
public String getCallDbId() {
|
||||
return callDbId;
|
||||
}
|
||||
|
||||
public void setCallDbId(String callDbId) {
|
||||
this.callDbId = callDbId;
|
||||
}
|
||||
|
||||
public String getCallSetDbId() {
|
||||
return callSetDbId;
|
||||
}
|
||||
|
||||
public void setCallSetDbId(String callSetDbId) {
|
||||
this.callSetDbId = callSetDbId;
|
||||
}
|
||||
|
||||
public String getVariantDbId() {
|
||||
return variantDbId;
|
||||
}
|
||||
|
||||
public void setVariantDbId(String variantDbId) {
|
||||
this.variantDbId = variantDbId;
|
||||
}
|
||||
|
||||
public String getGenotype() {
|
||||
return genotype;
|
||||
}
|
||||
|
||||
public void setGenotype(String genotype) {
|
||||
this.genotype = genotype;
|
||||
}
|
||||
|
||||
public Integer getReadDepth() {
|
||||
return readDepth;
|
||||
}
|
||||
|
||||
public void setReadDepth(Integer readDepth) {
|
||||
this.readDepth = readDepth;
|
||||
}
|
||||
|
||||
public Double getGenotypeLikelihood() {
|
||||
return genotypeLikelihood;
|
||||
}
|
||||
|
||||
public void setGenotypeLikelihood(Double genotypeLikelihood) {
|
||||
this.genotypeLikelihood = genotypeLikelihood;
|
||||
}
|
||||
|
||||
public String getPhaseSet() {
|
||||
return phaseSet;
|
||||
}
|
||||
|
||||
public void setPhaseSet(String phaseSet) {
|
||||
this.phaseSet = phaseSet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
public class GenomeMapWriteRequest {
|
||||
private String mapDbId;
|
||||
private String mapName;
|
||||
private String mapPUI;
|
||||
private String commonCropName;
|
||||
private String scientificName;
|
||||
private String type;
|
||||
private String unit;
|
||||
private String comments;
|
||||
private String documentationURL;
|
||||
private String publishedDate;
|
||||
|
||||
public String getMapDbId() {
|
||||
return mapDbId;
|
||||
}
|
||||
|
||||
public void setMapDbId(String mapDbId) {
|
||||
this.mapDbId = mapDbId;
|
||||
}
|
||||
|
||||
public String getMapName() {
|
||||
return mapName;
|
||||
}
|
||||
|
||||
public void setMapName(String mapName) {
|
||||
this.mapName = mapName;
|
||||
}
|
||||
|
||||
public String getMapPUI() {
|
||||
return mapPUI;
|
||||
}
|
||||
|
||||
public void setMapPUI(String mapPUI) {
|
||||
this.mapPUI = mapPUI;
|
||||
}
|
||||
|
||||
public String getCommonCropName() {
|
||||
return commonCropName;
|
||||
}
|
||||
|
||||
public void setCommonCropName(String commonCropName) {
|
||||
this.commonCropName = commonCropName;
|
||||
}
|
||||
|
||||
public String getScientificName() {
|
||||
return scientificName;
|
||||
}
|
||||
|
||||
public void setScientificName(String scientificName) {
|
||||
this.scientificName = scientificName;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public String getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void setComments(String comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public String getDocumentationURL() {
|
||||
return documentationURL;
|
||||
}
|
||||
|
||||
public void setDocumentationURL(String documentationURL) {
|
||||
this.documentationURL = documentationURL;
|
||||
}
|
||||
|
||||
public String getPublishedDate() {
|
||||
return publishedDate;
|
||||
}
|
||||
|
||||
public void setPublishedDate(String publishedDate) {
|
||||
this.publishedDate = publishedDate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
public class LinkageGroupWriteRequest {
|
||||
private String linkageGroupDbId;
|
||||
private String linkageGroupName;
|
||||
private Integer maxPosition;
|
||||
|
||||
public String getLinkageGroupDbId() {
|
||||
return linkageGroupDbId;
|
||||
}
|
||||
|
||||
public void setLinkageGroupDbId(String linkageGroupDbId) {
|
||||
this.linkageGroupDbId = linkageGroupDbId;
|
||||
}
|
||||
|
||||
public String getLinkageGroupName() {
|
||||
return linkageGroupName;
|
||||
}
|
||||
|
||||
public void setLinkageGroupName(String linkageGroupName) {
|
||||
this.linkageGroupName = linkageGroupName;
|
||||
}
|
||||
|
||||
public Integer getMaxPosition() {
|
||||
return maxPosition;
|
||||
}
|
||||
|
||||
public void setMaxPosition(Integer maxPosition) {
|
||||
this.maxPosition = maxPosition;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
public class MarkerPositionWriteRequest {
|
||||
private String markerPositionDbId;
|
||||
private String linkageGroupDbId;
|
||||
private String variantDbId;
|
||||
private Integer position;
|
||||
|
||||
public String getMarkerPositionDbId() {
|
||||
return markerPositionDbId;
|
||||
}
|
||||
|
||||
public void setMarkerPositionDbId(String markerPositionDbId) {
|
||||
this.markerPositionDbId = markerPositionDbId;
|
||||
}
|
||||
|
||||
public String getLinkageGroupDbId() {
|
||||
return linkageGroupDbId;
|
||||
}
|
||||
|
||||
public void setLinkageGroupDbId(String linkageGroupDbId) {
|
||||
this.linkageGroupDbId = linkageGroupDbId;
|
||||
}
|
||||
|
||||
public String getVariantDbId() {
|
||||
return variantDbId;
|
||||
}
|
||||
|
||||
public void setVariantDbId(String variantDbId) {
|
||||
this.variantDbId = variantDbId;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.model.BrAPIResponse;
|
||||
import io.swagger.model.BrAPIResponseResult;
|
||||
import io.swagger.model.Context;
|
||||
import io.swagger.model.Metadata;
|
||||
import io.swagger.model.geno.Analysis;
|
||||
|
||||
public class VariantSetAnalysisListResponse implements BrAPIResponse<VariantSetAnalysisListResponse.Result> {
|
||||
private Context _atContext;
|
||||
private Metadata metadata;
|
||||
private Result result = new Result();
|
||||
|
||||
public static class Result implements BrAPIResponseResult<Analysis> {
|
||||
private List<Analysis> data = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public List<Analysis> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(List<Analysis> data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
public void set_atContext(Context _atContext) {
|
||||
this._atContext = _atContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(Metadata metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VariantSetAnalysisWriteRequest {
|
||||
private String analysisDbId;
|
||||
private String variantSetDbId;
|
||||
private String analysisName;
|
||||
private String description;
|
||||
private String type;
|
||||
private String created;
|
||||
private String updated;
|
||||
private List<String> software;
|
||||
|
||||
public String getAnalysisDbId() {
|
||||
return analysisDbId;
|
||||
}
|
||||
|
||||
public void setAnalysisDbId(String analysisDbId) {
|
||||
this.analysisDbId = analysisDbId;
|
||||
}
|
||||
|
||||
public String getVariantSetDbId() {
|
||||
return variantSetDbId;
|
||||
}
|
||||
|
||||
public void setVariantSetDbId(String variantSetDbId) {
|
||||
this.variantSetDbId = variantSetDbId;
|
||||
}
|
||||
|
||||
public String getAnalysisName() {
|
||||
return analysisName;
|
||||
}
|
||||
|
||||
public void setAnalysisName(String analysisName) {
|
||||
this.analysisName = analysisName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(String created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(String updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public List<String> getSoftware() {
|
||||
return software;
|
||||
}
|
||||
|
||||
public void setSoftware(List<String> software) {
|
||||
this.software = software;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.model.BrAPIResponse;
|
||||
import io.swagger.model.BrAPIResponseResult;
|
||||
import io.swagger.model.Context;
|
||||
import io.swagger.model.Metadata;
|
||||
|
||||
public class VariantSetAvailableFormatListResponse
|
||||
implements BrAPIResponse<VariantSetAvailableFormatListResponse.Result> {
|
||||
private Context _atContext;
|
||||
private Metadata metadata;
|
||||
private Result result = new Result();
|
||||
|
||||
public static class Result implements BrAPIResponseResult<VariantSetAvailableFormatRecord> {
|
||||
private List<VariantSetAvailableFormatRecord> data = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public List<VariantSetAvailableFormatRecord> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(List<VariantSetAvailableFormatRecord> data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set_atContext(Context _atContext) {
|
||||
this._atContext = _atContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(Metadata metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
public class VariantSetAvailableFormatRecord {
|
||||
private String formatDbId;
|
||||
private String variantSetDbId;
|
||||
private String dataFormat;
|
||||
private String fileFormat;
|
||||
private String fileURL;
|
||||
private Boolean expandHomozygotes;
|
||||
private String sepPhased;
|
||||
private String sepUnphased;
|
||||
private String unknownString;
|
||||
|
||||
public String getFormatDbId() {
|
||||
return formatDbId;
|
||||
}
|
||||
|
||||
public void setFormatDbId(String formatDbId) {
|
||||
this.formatDbId = formatDbId;
|
||||
}
|
||||
|
||||
public String getVariantSetDbId() {
|
||||
return variantSetDbId;
|
||||
}
|
||||
|
||||
public void setVariantSetDbId(String variantSetDbId) {
|
||||
this.variantSetDbId = variantSetDbId;
|
||||
}
|
||||
|
||||
public String getDataFormat() {
|
||||
return dataFormat;
|
||||
}
|
||||
|
||||
public void setDataFormat(String dataFormat) {
|
||||
this.dataFormat = dataFormat;
|
||||
}
|
||||
|
||||
public String getFileFormat() {
|
||||
return fileFormat;
|
||||
}
|
||||
|
||||
public void setFileFormat(String fileFormat) {
|
||||
this.fileFormat = fileFormat;
|
||||
}
|
||||
|
||||
public String getFileURL() {
|
||||
return fileURL;
|
||||
}
|
||||
|
||||
public void setFileURL(String fileURL) {
|
||||
this.fileURL = fileURL;
|
||||
}
|
||||
|
||||
public Boolean getExpandHomozygotes() {
|
||||
return expandHomozygotes;
|
||||
}
|
||||
|
||||
public void setExpandHomozygotes(Boolean expandHomozygotes) {
|
||||
this.expandHomozygotes = expandHomozygotes;
|
||||
}
|
||||
|
||||
public String getSepPhased() {
|
||||
return sepPhased;
|
||||
}
|
||||
|
||||
public void setSepPhased(String sepPhased) {
|
||||
this.sepPhased = sepPhased;
|
||||
}
|
||||
|
||||
public String getSepUnphased() {
|
||||
return sepUnphased;
|
||||
}
|
||||
|
||||
public void setSepUnphased(String sepUnphased) {
|
||||
this.sepUnphased = sepUnphased;
|
||||
}
|
||||
|
||||
public String getUnknownString() {
|
||||
return unknownString;
|
||||
}
|
||||
|
||||
public void setUnknownString(String unknownString) {
|
||||
this.unknownString = unknownString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.brapi.test.BrAPITestServer.model.dto.geno;
|
||||
|
||||
public class VariantSetAvailableFormatWriteRequest {
|
||||
private String formatDbId;
|
||||
private String variantSetDbId;
|
||||
private String dataFormat;
|
||||
private String fileFormat;
|
||||
private String fileURL;
|
||||
private Boolean expandHomozygotes;
|
||||
private String sepPhased;
|
||||
private String sepUnphased;
|
||||
private String unknownString;
|
||||
|
||||
public String getFormatDbId() {
|
||||
return formatDbId;
|
||||
}
|
||||
|
||||
public void setFormatDbId(String formatDbId) {
|
||||
this.formatDbId = formatDbId;
|
||||
}
|
||||
|
||||
public String getVariantSetDbId() {
|
||||
return variantSetDbId;
|
||||
}
|
||||
|
||||
public void setVariantSetDbId(String variantSetDbId) {
|
||||
this.variantSetDbId = variantSetDbId;
|
||||
}
|
||||
|
||||
public String getDataFormat() {
|
||||
return dataFormat;
|
||||
}
|
||||
|
||||
public void setDataFormat(String dataFormat) {
|
||||
this.dataFormat = dataFormat;
|
||||
}
|
||||
|
||||
public String getFileFormat() {
|
||||
return fileFormat;
|
||||
}
|
||||
|
||||
public void setFileFormat(String fileFormat) {
|
||||
this.fileFormat = fileFormat;
|
||||
}
|
||||
|
||||
public String getFileURL() {
|
||||
return fileURL;
|
||||
}
|
||||
|
||||
public void setFileURL(String fileURL) {
|
||||
this.fileURL = fileURL;
|
||||
}
|
||||
|
||||
public Boolean getExpandHomozygotes() {
|
||||
return expandHomozygotes;
|
||||
}
|
||||
|
||||
public void setExpandHomozygotes(Boolean expandHomozygotes) {
|
||||
this.expandHomozygotes = expandHomozygotes;
|
||||
}
|
||||
|
||||
public String getSepPhased() {
|
||||
return sepPhased;
|
||||
}
|
||||
|
||||
public void setSepPhased(String sepPhased) {
|
||||
this.sepPhased = sepPhased;
|
||||
}
|
||||
|
||||
public String getSepUnphased() {
|
||||
return sepUnphased;
|
||||
}
|
||||
|
||||
public void setSepUnphased(String sepUnphased) {
|
||||
this.sepUnphased = sepUnphased;
|
||||
}
|
||||
|
||||
public String getUnknownString() {
|
||||
return unknownString;
|
||||
}
|
||||
|
||||
public void setUnknownString(String unknownString) {
|
||||
this.unknownString = unknownString;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,12 @@ package org.brapi.test.BrAPITestServer.repository.geno;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.CallEntity;
|
||||
import org.brapi.test.BrAPITestServer.repository.BrAPIRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
public interface CallRepository extends BrAPIRepository<CallEntity, String> {
|
||||
|
||||
@Query("SELECT COUNT(c) FROM CallEntity c WHERE c.callSet.id = :callSetDbId")
|
||||
long countByCallSetDbId(@Param("callSetDbId") String callSetDbId);
|
||||
|
||||
public interface CallRepository extends BrAPIRepository<CallEntity, String>{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.brapi.test.BrAPITestServer.repository.geno;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.VariantSetAnalysisEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface VariantSetAnalysisRepository extends JpaRepository<VariantSetAnalysisEntity, String> {
|
||||
List<VariantSetAnalysisEntity> findByVariantSet_Id(String variantSetId);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.brapi.test.BrAPITestServer.repository.geno;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.VariantSetAvailableFormatEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface VariantSetAvailableFormatRepository extends JpaRepository<VariantSetAvailableFormatEntity, String> {
|
||||
List<VariantSetAvailableFormatEntity> findByVariantSet_Id(String variantSetId);
|
||||
}
|
||||
@@ -3,18 +3,27 @@ package org.brapi.test.BrAPITestServer.service.geno;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerDbIdNotFoundException;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.CallWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.CallEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.CallSetEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.VariantEntity;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.CallRepository;
|
||||
import org.brapi.test.BrAPITestServer.service.PagingUtility;
|
||||
import org.brapi.test.BrAPITestServer.service.SearchQueryBuilder;
|
||||
import org.brapi.test.BrAPITestServer.service.UpdateUtility;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -37,9 +46,13 @@ public class CallService {
|
||||
public static final String UNKNOWN_STRING_DEFAULT = ".";
|
||||
|
||||
private final CallRepository callRepository;
|
||||
private final CallSetService callSetService;
|
||||
private final VariantService variantService;
|
||||
|
||||
public CallService(CallRepository callRepository) {
|
||||
public CallService(CallRepository callRepository, CallSetService callSetService, VariantService variantService) {
|
||||
this.callRepository = callRepository;
|
||||
this.callSetService = callSetService;
|
||||
this.variantService = variantService;
|
||||
}
|
||||
|
||||
public CallsListResponseResult findCalls(String callSetDbId, String variantDbId, String variantSetDbId,
|
||||
@@ -103,7 +116,14 @@ public class CallService {
|
||||
|
||||
private Call convertFromEntityWithFormatting(CallEntity entity, CallsSearchRequest request) {
|
||||
Call call = new Call();
|
||||
call.setAdditionalInfo(entity.getAdditionalInfoMap());
|
||||
Map<String, Object> additionalInfo = entity.getAdditionalInfoMap();
|
||||
if (additionalInfo == null) {
|
||||
additionalInfo = new HashMap<>();
|
||||
} else {
|
||||
additionalInfo = new HashMap<>(additionalInfo);
|
||||
}
|
||||
additionalInfo.put("callDbId", entity.getId());
|
||||
call.setAdditionalInfo(additionalInfo);
|
||||
if (entity.getCallSet() != null) {
|
||||
call.setCallSetDbId(entity.getCallSet().getId());
|
||||
call.setCallSetName(entity.getCallSet().getCallSetName());
|
||||
@@ -154,6 +174,7 @@ public class CallService {
|
||||
}
|
||||
|
||||
public CallsListResponseResult updateCalls(List<Call> body) throws BrAPIServerException {
|
||||
ensureVariantSetBindings(body);
|
||||
CallsSearchRequest searchReq = new CallsSearchRequest();
|
||||
Map<String, Call> callsMap = new HashMap<>();
|
||||
for (Call call : body) {
|
||||
@@ -214,4 +235,126 @@ public class CallService {
|
||||
|
||||
}
|
||||
|
||||
public Call getCall(String callDbId) throws BrAPIServerException {
|
||||
return convertFromEntity(getCallEntity(callDbId, HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
||||
public CallEntity getCallEntity(String callDbId) throws BrAPIServerException {
|
||||
return getCallEntity(callDbId, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
public CallEntity getCallEntity(String callDbId, HttpStatus errorStatus) throws BrAPIServerException {
|
||||
Optional<CallEntity> entityOpt = callRepository.findById(callDbId);
|
||||
if (entityOpt.isPresent()) {
|
||||
return entityOpt.get();
|
||||
}
|
||||
throw new BrAPIServerDbIdNotFoundException("call", callDbId, errorStatus);
|
||||
}
|
||||
|
||||
public Call saveCall(CallWriteRequest request) throws BrAPIServerException {
|
||||
if (request.getCallSetDbId() == null || request.getCallSetDbId().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "callSetDbId is required");
|
||||
}
|
||||
if (request.getVariantDbId() == null || request.getVariantDbId().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "variantDbId is required");
|
||||
}
|
||||
if (request.getGenotype() == null || request.getGenotype().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "genotype is required");
|
||||
}
|
||||
if (request.getCallDbId() != null && callRepository.findById(request.getCallDbId()).isPresent()) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "Call already exists: " + request.getCallDbId());
|
||||
}
|
||||
CallSetEntity callSet = callSetService.getCallSetEntity(request.getCallSetDbId());
|
||||
VariantEntity variant = variantService.getVariantEntity(request.getVariantDbId());
|
||||
assertNoDuplicateCall(callSet.getId(), variant.getId(), null);
|
||||
if (request.getReadDepth() != null && request.getReadDepth() < 0) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "readDepth cannot be negative");
|
||||
}
|
||||
|
||||
CallEntity entity = new CallEntity();
|
||||
if (request.getCallDbId() != null && !request.getCallDbId().isBlank()) {
|
||||
entity.setId(request.getCallDbId().trim());
|
||||
}
|
||||
updateEntity(entity, request, callSet, variant);
|
||||
Call saved = convertFromEntity(callRepository.save(entity));
|
||||
if (variant.getVariantSet() != null) {
|
||||
callSetService.ensureVariantSetBinding(callSet.getId(), variant.getVariantSet().getId());
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
public List<Call> importCalls(List<CallWriteRequest> requests) throws BrAPIServerException {
|
||||
List<Call> saved = new ArrayList<>();
|
||||
for (CallWriteRequest request : requests) {
|
||||
saved.add(saveCall(request));
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
public Call updateCall(String callDbId, CallWriteRequest request) throws BrAPIServerException {
|
||||
CallEntity entity = getCallEntity(callDbId, HttpStatus.NOT_FOUND);
|
||||
CallSetEntity callSet = callSetService.getCallSetEntity(request.getCallSetDbId());
|
||||
VariantEntity variant = variantService.getVariantEntity(request.getVariantDbId());
|
||||
assertNoDuplicateCall(callSet.getId(), variant.getId(), callDbId);
|
||||
if (request.getReadDepth() != null && request.getReadDepth() < 0) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "readDepth cannot be negative");
|
||||
}
|
||||
updateEntity(entity, request, callSet, variant);
|
||||
Call saved = convertFromEntity(callRepository.save(entity));
|
||||
if (variant.getVariantSet() != null) {
|
||||
callSetService.ensureVariantSetBinding(callSet.getId(), variant.getVariantSet().getId());
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
public Call deleteCall(String callDbId) throws BrAPIServerException {
|
||||
CallEntity entity = getCallEntity(callDbId, HttpStatus.NOT_FOUND);
|
||||
Call deleted = convertFromEntity(entity);
|
||||
try {
|
||||
callRepository.delete(entity);
|
||||
callRepository.flush();
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "Call cannot be deleted");
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
private void assertNoDuplicateCall(String callSetDbId, String variantDbId, String excludeCallDbId)
|
||||
throws BrAPIServerException {
|
||||
Pageable pageReq = PageRequest.of(0, 1);
|
||||
SearchQueryBuilder<CallEntity> searchQuery = new SearchQueryBuilder<CallEntity>(CallEntity.class)
|
||||
.appendSingle(callSetDbId, "callSet.id")
|
||||
.appendSingle(variantDbId, "variant.id");
|
||||
Page<CallEntity> page = callRepository.findAllBySearch(searchQuery, pageReq);
|
||||
if (page.getTotalElements() > 0) {
|
||||
CallEntity existing = page.getContent().get(0);
|
||||
if (excludeCallDbId == null || !excludeCallDbId.equals(existing.getId())) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT,
|
||||
"Call already exists for this callSet and variant");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateEntity(CallEntity entity, CallWriteRequest request, CallSetEntity callSet,
|
||||
VariantEntity variant) {
|
||||
entity.setCallSet(callSet);
|
||||
entity.setVariant(variant);
|
||||
entity.setGenotype(request.getGenotype().trim());
|
||||
entity.setReadDepth(request.getReadDepth());
|
||||
entity.setGenotypeLikelihood(request.getGenotypeLikelihood());
|
||||
entity.setPhaseSet(request.getPhaseSet());
|
||||
}
|
||||
|
||||
private void ensureVariantSetBindings(List<Call> calls) throws BrAPIServerException {
|
||||
Set<String> processed = new HashSet<>();
|
||||
for (Call call : calls) {
|
||||
if (call.getCallSetDbId() == null || call.getVariantSetDbId() == null) {
|
||||
continue;
|
||||
}
|
||||
String key = call.getCallSetDbId() + "|" + call.getVariantSetDbId();
|
||||
if (processed.add(key)) {
|
||||
callSetService.ensureVariantSetBinding(call.getCallSetDbId(), call.getVariantSetDbId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
package org.brapi.test.BrAPITestServer.service.geno;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerDbIdNotFoundException;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.CallSetWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.CallSetEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.SampleEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.VariantSetEntity;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.CallRepository;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.CallSetRepository;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.VariantSetRepository;
|
||||
import org.brapi.test.BrAPITestServer.service.DateUtility;
|
||||
import org.brapi.test.BrAPITestServer.service.PagingUtility;
|
||||
import org.brapi.test.BrAPITestServer.service.SearchQueryBuilder;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -24,9 +33,16 @@ import io.swagger.model.geno.CallSetsSearchRequest;
|
||||
public class CallSetService {
|
||||
|
||||
private final CallSetRepository callSetRepository;
|
||||
private final CallRepository callRepository;
|
||||
private final SampleService sampleService;
|
||||
private final VariantSetRepository variantSetRepository;
|
||||
|
||||
public CallSetService(CallSetRepository callSetRepository) {
|
||||
public CallSetService(CallSetRepository callSetRepository, CallRepository callRepository,
|
||||
SampleService sampleService, VariantSetRepository variantSetRepository) {
|
||||
this.callSetRepository = callSetRepository;
|
||||
this.callRepository = callRepository;
|
||||
this.sampleService = sampleService;
|
||||
this.variantSetRepository = variantSetRepository;
|
||||
}
|
||||
|
||||
public List<CallSet> findCallSets(String callSetDbId, String callSetName, String variantSetDbId, String sampleDbId,
|
||||
@@ -111,4 +127,101 @@ public class CallSetService {
|
||||
public CallSetEntity save(CallSetEntity entity) {
|
||||
return callSetRepository.save(entity);
|
||||
}
|
||||
|
||||
public void ensureVariantSetBinding(String callSetDbId, String variantSetDbId) throws BrAPIServerException {
|
||||
if (callSetDbId == null || callSetDbId.isBlank() || variantSetDbId == null || variantSetDbId.isBlank()) {
|
||||
return;
|
||||
}
|
||||
CallSetEntity callSet = getCallSetEntity(callSetDbId.trim());
|
||||
VariantSetEntity variantSet = variantSetRepository.findById(variantSetDbId.trim())
|
||||
.orElseThrow(() -> new BrAPIServerDbIdNotFoundException("variantSet", variantSetDbId,
|
||||
HttpStatus.BAD_REQUEST));
|
||||
if (callSet.getVariantSets() == null) {
|
||||
callSet.setVariantSets(new ArrayList<>());
|
||||
}
|
||||
boolean exists = callSet.getVariantSets().stream().anyMatch(item -> variantSetDbId.trim().equals(item.getId()));
|
||||
if (!exists) {
|
||||
callSet.getVariantSets().add(variantSet);
|
||||
callSet.setUpdated(new Date());
|
||||
callSetRepository.save(callSet);
|
||||
}
|
||||
}
|
||||
|
||||
public CallSet saveCallSet(CallSetWriteRequest request) throws BrAPIServerException {
|
||||
if (request.getCallSetName() == null || request.getCallSetName().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "callSetName is required");
|
||||
}
|
||||
if (request.getSampleDbId() == null || request.getSampleDbId().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "sampleDbId is required");
|
||||
}
|
||||
if (request.getCallSetDbId() != null && callSetRepository.findById(request.getCallSetDbId()).isPresent()) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "CallSet already exists: " + request.getCallSetDbId());
|
||||
}
|
||||
CallSetEntity entity = new CallSetEntity();
|
||||
if (request.getCallSetDbId() != null && !request.getCallSetDbId().isBlank()) {
|
||||
entity.setId(request.getCallSetDbId().trim());
|
||||
}
|
||||
entity.setCreated(new Date());
|
||||
entity.setUpdated(new Date());
|
||||
updateEntity(entity, request);
|
||||
return convertFromEntity(callSetRepository.save(entity));
|
||||
}
|
||||
|
||||
public CallSet updateCallSet(String callSetDbId, CallSetWriteRequest request) throws BrAPIServerException {
|
||||
CallSetEntity entity = getCallSetEntity(callSetDbId, HttpStatus.NOT_FOUND);
|
||||
entity.setUpdated(new Date());
|
||||
updateEntity(entity, request);
|
||||
return convertFromEntity(callSetRepository.save(entity));
|
||||
}
|
||||
|
||||
public CallSet deleteCallSet(String callSetDbId) throws BrAPIServerException {
|
||||
CallSetEntity entity = getCallSetEntity(callSetDbId, HttpStatus.NOT_FOUND);
|
||||
assertNoCallSetDependencies(callSetDbId);
|
||||
CallSet deleted = convertFromEntity(entity);
|
||||
try {
|
||||
callSetRepository.delete(entity);
|
||||
callSetRepository.flush();
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "CallSet is in use and cannot be deleted");
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
private void assertNoCallSetDependencies(String callSetDbId) throws BrAPIServerException {
|
||||
if (callRepository.countByCallSetDbId(callSetDbId) > 0) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "CallSet is referenced by allele_call records");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateEntity(CallSetEntity entity, CallSetWriteRequest request) throws BrAPIServerException {
|
||||
if (request.getCallSetName() != null && !request.getCallSetName().isBlank()) {
|
||||
entity.setCallSetName(request.getCallSetName().trim());
|
||||
} else if (entity.getCallSetName() == null || entity.getCallSetName().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "callSetName is required");
|
||||
}
|
||||
if (request.getSampleDbId() != null && !request.getSampleDbId().isBlank()) {
|
||||
SampleEntity sample = sampleService.getSampleEntity(request.getSampleDbId());
|
||||
entity.setSample(sample);
|
||||
} else if (entity.getSample() == null) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "sampleDbId is required");
|
||||
}
|
||||
if (request.getVariantSetDbIds() != null) {
|
||||
List<VariantSetEntity> variantSets = new ArrayList<>();
|
||||
LinkedHashSet<String> seen = new LinkedHashSet<>();
|
||||
for (String variantSetDbId : request.getVariantSetDbIds()) {
|
||||
if (variantSetDbId == null || variantSetDbId.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
String normalizedId = variantSetDbId.trim();
|
||||
if (!seen.add(normalizedId)) {
|
||||
continue;
|
||||
}
|
||||
VariantSetEntity variantSet = variantSetRepository.findById(normalizedId)
|
||||
.orElseThrow(() -> new BrAPIServerDbIdNotFoundException("variantSet", variantSetDbId,
|
||||
HttpStatus.BAD_REQUEST));
|
||||
variantSets.add(variantSet);
|
||||
}
|
||||
entity.setVariantSets(variantSets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,22 @@ import java.util.Optional;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerDbIdNotFoundException;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.GenomeMapWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.LinkageGroupWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.GenomeMapEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.LinkageGroupEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.MarkerPositionEntity;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.GenomeMapRepository;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.LinkageGroupRepository;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.MarkerPositionRepository;
|
||||
import org.brapi.test.BrAPITestServer.service.DateUtility;
|
||||
import org.brapi.test.BrAPITestServer.service.PagingUtility;
|
||||
import org.brapi.test.BrAPITestServer.service.SearchQueryBuilder;
|
||||
import org.brapi.test.BrAPITestServer.service.core.CropService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -25,13 +32,18 @@ import io.swagger.model.geno.LinkageGroup;
|
||||
@Service
|
||||
public class GenomeMapService {
|
||||
|
||||
private GenomeMapRepository genomeMapRepository;
|
||||
private LinkageGroupRepository linkageGroupRepository;
|
||||
private final GenomeMapRepository genomeMapRepository;
|
||||
private final LinkageGroupRepository linkageGroupRepository;
|
||||
private final MarkerPositionRepository markerPositionRepository;
|
||||
private final CropService cropService;
|
||||
|
||||
@Autowired
|
||||
public GenomeMapService(GenomeMapRepository genomeMapRepository, LinkageGroupRepository linkageGroupRepository) {
|
||||
public GenomeMapService(GenomeMapRepository genomeMapRepository, LinkageGroupRepository linkageGroupRepository,
|
||||
MarkerPositionRepository markerPositionRepository, CropService cropService) {
|
||||
this.genomeMapRepository = genomeMapRepository;
|
||||
this.linkageGroupRepository = linkageGroupRepository;
|
||||
this.markerPositionRepository = markerPositionRepository;
|
||||
this.cropService = cropService;
|
||||
}
|
||||
|
||||
public List<GenomeMap> findMaps(String commonCropName, String mapPUI, String scientificName, String type,
|
||||
@@ -74,11 +86,183 @@ public class GenomeMapService {
|
||||
|
||||
Pageable pageReq = PagingUtility.getPageRequest(metadata);
|
||||
Page<LinkageGroupEntity> page = linkageGroupRepository.findAllBySearch(searchQuery, pageReq);
|
||||
List<LinkageGroup> linkageGroups = page.map(this::convertFromEntity).getContent();
|
||||
List<LinkageGroup> linkageGroups = page.map(this::convertLinkageGroupFromEntity).getContent();
|
||||
PagingUtility.calculateMetaData(metadata, page);
|
||||
return linkageGroups;
|
||||
}
|
||||
|
||||
public GenomeMap saveMap(GenomeMapWriteRequest request) throws BrAPIServerException {
|
||||
if (request.getMapName() == null || request.getMapName().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "mapName is required");
|
||||
}
|
||||
if (request.getMapDbId() != null && genomeMapRepository.findById(request.getMapDbId()).isPresent()) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "GenomeMap already exists: " + request.getMapDbId());
|
||||
}
|
||||
GenomeMapEntity entity = new GenomeMapEntity();
|
||||
if (request.getMapDbId() != null && !request.getMapDbId().isBlank()) {
|
||||
entity.setId(request.getMapDbId().trim());
|
||||
}
|
||||
updateMapEntity(entity, request);
|
||||
entity = genomeMapRepository.save(entity);
|
||||
ensureMapPUI(entity);
|
||||
return convertFromEntity(genomeMapRepository.save(entity));
|
||||
}
|
||||
|
||||
public GenomeMap updateMap(String mapDbId, GenomeMapWriteRequest request) throws BrAPIServerException {
|
||||
GenomeMapEntity entity = getMapEntity(mapDbId);
|
||||
updateMapEntity(entity, request);
|
||||
return convertFromEntity(genomeMapRepository.save(entity));
|
||||
}
|
||||
|
||||
public GenomeMap deleteMap(String mapDbId) throws BrAPIServerException {
|
||||
GenomeMapEntity entity = getMapEntity(mapDbId);
|
||||
assertNoMapDependencies(mapDbId);
|
||||
GenomeMap deleted = convertFromEntity(entity);
|
||||
try {
|
||||
genomeMapRepository.delete(entity);
|
||||
genomeMapRepository.flush();
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "GenomeMap is in use and cannot be deleted");
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public LinkageGroup saveLinkageGroup(String mapDbId, LinkageGroupWriteRequest request) throws BrAPIServerException {
|
||||
if (request.getLinkageGroupName() == null || request.getLinkageGroupName().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "linkageGroupName is required");
|
||||
}
|
||||
if (request.getLinkageGroupDbId() != null
|
||||
&& linkageGroupRepository.findById(request.getLinkageGroupDbId()).isPresent()) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT,
|
||||
"LinkageGroup already exists: " + request.getLinkageGroupDbId());
|
||||
}
|
||||
GenomeMapEntity map = getMapEntity(mapDbId);
|
||||
assertLinkageGroupNameUnique(map.getId(), request.getLinkageGroupName().trim(), null);
|
||||
LinkageGroupEntity entity = new LinkageGroupEntity();
|
||||
if (request.getLinkageGroupDbId() != null && !request.getLinkageGroupDbId().isBlank()) {
|
||||
entity.setId(request.getLinkageGroupDbId().trim());
|
||||
}
|
||||
entity.setGenomeMap(map);
|
||||
updateLinkageGroupEntity(entity, request);
|
||||
return convertLinkageGroupFromEntity(linkageGroupRepository.save(entity));
|
||||
}
|
||||
|
||||
public LinkageGroup updateLinkageGroup(String mapDbId, String linkageGroupDbId, LinkageGroupWriteRequest request)
|
||||
throws BrAPIServerException {
|
||||
LinkageGroupEntity entity = getLinkageGroupEntity(linkageGroupDbId);
|
||||
if (entity.getGenomeMap() == null || !mapDbId.equals(entity.getGenomeMap().getId())) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "LinkageGroup does not belong to map: " + mapDbId);
|
||||
}
|
||||
if (request.getLinkageGroupName() != null && !request.getLinkageGroupName().isBlank()) {
|
||||
assertLinkageGroupNameUnique(mapDbId, request.getLinkageGroupName().trim(), linkageGroupDbId);
|
||||
}
|
||||
updateLinkageGroupEntity(entity, request);
|
||||
return convertLinkageGroupFromEntity(linkageGroupRepository.save(entity));
|
||||
}
|
||||
|
||||
public LinkageGroup deleteLinkageGroup(String mapDbId, String linkageGroupDbId) throws BrAPIServerException {
|
||||
LinkageGroupEntity entity = getLinkageGroupEntity(linkageGroupDbId);
|
||||
if (entity.getGenomeMap() == null || !mapDbId.equals(entity.getGenomeMap().getId())) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "LinkageGroup does not belong to map: " + mapDbId);
|
||||
}
|
||||
assertNoLinkageGroupDependencies(linkageGroupDbId);
|
||||
LinkageGroup deleted = convertLinkageGroupFromEntity(entity);
|
||||
try {
|
||||
linkageGroupRepository.delete(entity);
|
||||
linkageGroupRepository.flush();
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "LinkageGroup is in use and cannot be deleted");
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public GenomeMapEntity getMapEntity(String mapDbId) throws BrAPIServerException {
|
||||
return genomeMapRepository.findById(mapDbId)
|
||||
.orElseThrow(() -> new BrAPIServerDbIdNotFoundException("map", mapDbId, HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
||||
public LinkageGroupEntity getLinkageGroupEntity(String linkageGroupDbId) throws BrAPIServerException {
|
||||
return linkageGroupRepository.findById(linkageGroupDbId).orElseThrow(
|
||||
() -> new BrAPIServerDbIdNotFoundException("linkageGroup", linkageGroupDbId, HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
||||
private void assertNoMapDependencies(String mapDbId) throws BrAPIServerException {
|
||||
Pageable pageReq = PageRequest.of(0, 1);
|
||||
SearchQueryBuilder<LinkageGroupEntity> query = new SearchQueryBuilder<LinkageGroupEntity>(LinkageGroupEntity.class)
|
||||
.appendSingle(mapDbId, "genomeMap.id");
|
||||
if (linkageGroupRepository.findAllBySearch(query, pageReq).getTotalElements() > 0) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "GenomeMap is referenced by linkage group records");
|
||||
}
|
||||
}
|
||||
|
||||
private void assertNoLinkageGroupDependencies(String linkageGroupDbId) throws BrAPIServerException {
|
||||
Pageable pageReq = PageRequest.of(0, 1);
|
||||
SearchQueryBuilder<MarkerPositionEntity> query = new SearchQueryBuilder<MarkerPositionEntity>(
|
||||
MarkerPositionEntity.class).appendSingle(linkageGroupDbId, "linkageGroup.id");
|
||||
if (markerPositionRepository.findAllBySearch(query, pageReq).getTotalElements() > 0) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT,
|
||||
"LinkageGroup is referenced by marker_position records");
|
||||
}
|
||||
}
|
||||
|
||||
private void assertLinkageGroupNameUnique(String mapDbId, String linkageGroupName, String excludeId)
|
||||
throws BrAPIServerException {
|
||||
SearchQueryBuilder<LinkageGroupEntity> query = new SearchQueryBuilder<LinkageGroupEntity>(LinkageGroupEntity.class)
|
||||
.appendSingle(mapDbId, "genomeMap.id")
|
||||
.appendSingle(linkageGroupName, "linkageGroupName");
|
||||
Page<LinkageGroupEntity> page = linkageGroupRepository.findAllBySearch(query, PageRequest.of(0, 2));
|
||||
for (LinkageGroupEntity existing : page.getContent()) {
|
||||
if (excludeId == null || !excludeId.equals(existing.getId())) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT,
|
||||
"linkageGroupName already exists on this map: " + linkageGroupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureMapPUI(GenomeMapEntity entity) {
|
||||
if (entity.getMapPUI() == null || entity.getMapPUI().isBlank()) {
|
||||
entity.setMapPUI("urn:uuid:" + entity.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMapEntity(GenomeMapEntity entity, GenomeMapWriteRequest request) throws BrAPIServerException {
|
||||
entity.setMapName(request.getMapName().trim());
|
||||
entity.setScientificName(trimOrNull(request.getScientificName()));
|
||||
entity.setType(trimOrNull(request.getType()));
|
||||
entity.setUnit(trimOrNull(request.getUnit()));
|
||||
entity.setComments(trimOrNull(request.getComments()));
|
||||
entity.setDocumentationURL(trimOrNull(request.getDocumentationURL()));
|
||||
if (request.getPublishedDate() != null) {
|
||||
entity.setPublishedDate(DateUtility.toDate(request.getPublishedDate()));
|
||||
}
|
||||
if (request.getCommonCropName() != null && !request.getCommonCropName().isBlank()) {
|
||||
entity.setCrop(cropService.getCropEntity(request.getCommonCropName().trim()));
|
||||
} else if (request.getCommonCropName() != null) {
|
||||
entity.setCrop(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLinkageGroupEntity(LinkageGroupEntity entity, LinkageGroupWriteRequest request)
|
||||
throws BrAPIServerException {
|
||||
if (request.getLinkageGroupName() != null && !request.getLinkageGroupName().isBlank()) {
|
||||
entity.setLinkageGroupName(request.getLinkageGroupName().trim());
|
||||
}
|
||||
if (request.getMaxPosition() != null) {
|
||||
if (request.getMaxPosition() < 0) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "maxPosition cannot be negative");
|
||||
}
|
||||
entity.setMaxMarkerPosition(request.getMaxPosition());
|
||||
}
|
||||
}
|
||||
|
||||
private String trimOrNull(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
return trimmed.isEmpty() ? null : trimmed;
|
||||
}
|
||||
|
||||
private GenomeMap convertFromEntity(GenomeMapEntity entity) {
|
||||
GenomeMap map = new GenomeMap();
|
||||
map.setAdditionalInfo(entity.getAdditionalInfoMap());
|
||||
@@ -102,12 +286,18 @@ public class GenomeMapService {
|
||||
return map;
|
||||
}
|
||||
|
||||
private LinkageGroup convertFromEntity(LinkageGroupEntity entity) {
|
||||
private LinkageGroup convertLinkageGroupFromEntity(LinkageGroupEntity entity) {
|
||||
LinkageGroup group = new LinkageGroup();
|
||||
group.setAdditionalInfo(entity.getAdditionalInfoMap());
|
||||
group.setLinkageGroupName(entity.getLinkageGroupName());
|
||||
group.setMarkerCount(entity.getMarkers().size());
|
||||
int markerCount = entity.getMarkers() != null ? entity.getMarkers().size() : 0;
|
||||
group.setMarkerCount(markerCount);
|
||||
group.setMaxPosition(entity.getMaxMarkerPosition());
|
||||
group.putAdditionalInfoItem("linkageGroupDbId", entity.getId());
|
||||
if (entity.getGenomeMap() != null) {
|
||||
group.putAdditionalInfoItem("mapDbId", entity.getGenomeMap().getId());
|
||||
group.putAdditionalInfoItem("mapName", entity.getGenomeMap().getMapName());
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,20 @@ package org.brapi.test.BrAPITestServer.service.geno;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerDbIdNotFoundException;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.MarkerPositionWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.LinkageGroupEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.MarkerPositionEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.VariantEntity;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.MarkerPositionRepository;
|
||||
import org.brapi.test.BrAPITestServer.service.PagingUtility;
|
||||
import org.brapi.test.BrAPITestServer.service.SearchQueryBuilder;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import io.swagger.model.Metadata;
|
||||
@@ -18,9 +26,14 @@ import io.swagger.model.geno.MarkerPosition;
|
||||
public class MarkerPositionService {
|
||||
|
||||
private final MarkerPositionRepository markerPositionRepository;
|
||||
private final GenomeMapService genomeMapService;
|
||||
private final VariantService variantService;
|
||||
|
||||
public MarkerPositionService(MarkerPositionRepository markerPositionRepository) {
|
||||
public MarkerPositionService(MarkerPositionRepository markerPositionRepository, GenomeMapService genomeMapService,
|
||||
VariantService variantService) {
|
||||
this.markerPositionRepository = markerPositionRepository;
|
||||
this.genomeMapService = genomeMapService;
|
||||
this.variantService = variantService;
|
||||
}
|
||||
|
||||
public List<MarkerPosition> findMarkerPositions(String mapDbId, String linkageGroupName, String variantDbId,
|
||||
@@ -52,11 +65,91 @@ public class MarkerPositionService {
|
||||
return markerPositions;
|
||||
}
|
||||
|
||||
public MarkerPosition saveMarkerPosition(MarkerPositionWriteRequest request) throws BrAPIServerException {
|
||||
if (request.getLinkageGroupDbId() == null || request.getLinkageGroupDbId().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "linkageGroupDbId is required");
|
||||
}
|
||||
if (request.getVariantDbId() == null || request.getVariantDbId().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "variantDbId is required");
|
||||
}
|
||||
if (request.getPosition() == null) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "position is required");
|
||||
}
|
||||
if (request.getMarkerPositionDbId() != null
|
||||
&& markerPositionRepository.findById(request.getMarkerPositionDbId()).isPresent()) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT,
|
||||
"MarkerPosition already exists: " + request.getMarkerPositionDbId());
|
||||
}
|
||||
MarkerPositionEntity entity = new MarkerPositionEntity();
|
||||
if (request.getMarkerPositionDbId() != null && !request.getMarkerPositionDbId().isBlank()) {
|
||||
entity.setId(request.getMarkerPositionDbId().trim());
|
||||
}
|
||||
updateMarkerPositionEntity(entity, request);
|
||||
return convertFromEntity(markerPositionRepository.save(entity));
|
||||
}
|
||||
|
||||
public MarkerPosition updateMarkerPosition(String markerPositionDbId, MarkerPositionWriteRequest request)
|
||||
throws BrAPIServerException {
|
||||
MarkerPositionEntity entity = getMarkerPositionEntity(markerPositionDbId);
|
||||
updateMarkerPositionEntity(entity, request);
|
||||
return convertFromEntity(markerPositionRepository.save(entity));
|
||||
}
|
||||
|
||||
public MarkerPosition deleteMarkerPosition(String markerPositionDbId) throws BrAPIServerException {
|
||||
MarkerPositionEntity entity = getMarkerPositionEntity(markerPositionDbId);
|
||||
MarkerPosition deleted = convertFromEntity(entity);
|
||||
try {
|
||||
markerPositionRepository.delete(entity);
|
||||
markerPositionRepository.flush();
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "MarkerPosition cannot be deleted");
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public MarkerPositionEntity getMarkerPositionEntity(String markerPositionDbId) throws BrAPIServerException {
|
||||
return markerPositionRepository.findById(markerPositionDbId).orElseThrow(
|
||||
() -> new BrAPIServerDbIdNotFoundException("markerPosition", markerPositionDbId, HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
||||
private void updateMarkerPositionEntity(MarkerPositionEntity entity, MarkerPositionWriteRequest request)
|
||||
throws BrAPIServerException {
|
||||
LinkageGroupEntity linkageGroup = genomeMapService.getLinkageGroupEntity(request.getLinkageGroupDbId());
|
||||
VariantEntity variant = variantService.getVariantEntity(request.getVariantDbId());
|
||||
assertMarkerVariantUnique(linkageGroup.getId(), variant.getId(), entity.getId());
|
||||
if (request.getPosition() < 0) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "position cannot be negative");
|
||||
}
|
||||
if (linkageGroup.getMaxMarkerPosition() != null
|
||||
&& request.getPosition() > linkageGroup.getMaxMarkerPosition()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST,
|
||||
"position cannot exceed linkage group maxPosition");
|
||||
}
|
||||
entity.setLinkageGroup(linkageGroup);
|
||||
entity.setVariant(variant);
|
||||
entity.setPosition(request.getPosition());
|
||||
}
|
||||
|
||||
private void assertMarkerVariantUnique(String linkageGroupDbId, String variantDbId, String excludeId)
|
||||
throws BrAPIServerException {
|
||||
SearchQueryBuilder<MarkerPositionEntity> query = new SearchQueryBuilder<MarkerPositionEntity>(
|
||||
MarkerPositionEntity.class).appendSingle(linkageGroupDbId, "linkageGroup.id")
|
||||
.appendSingle(variantDbId, "variant.id");
|
||||
Page<MarkerPositionEntity> page = markerPositionRepository.findAllBySearch(query, PageRequest.of(0, 2));
|
||||
for (MarkerPositionEntity existing : page.getContent()) {
|
||||
if (excludeId == null || !excludeId.equals(existing.getId())) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT,
|
||||
"variant already has a marker position on this linkage group");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MarkerPosition convertFromEntity(MarkerPositionEntity entity) {
|
||||
MarkerPosition position = new MarkerPosition();
|
||||
position.setAdditionalInfo(entity.getAdditionalInfoMap());
|
||||
if (entity.getLinkageGroup() != null) {
|
||||
position.setLinkageGroupName(entity.getLinkageGroup().getLinkageGroupName());
|
||||
position.putAdditionalInfoItem("linkageGroupDbId", entity.getLinkageGroup().getId());
|
||||
if (entity.getLinkageGroup().getGenomeMap() != null) {
|
||||
position.setMapDbId(entity.getLinkageGroup().getGenomeMap().getId());
|
||||
position.setMapName(entity.getLinkageGroup().getGenomeMap().getMapName());
|
||||
@@ -67,6 +160,7 @@ public class MarkerPositionService {
|
||||
position.setVariantDbId(entity.getVariant().getId());
|
||||
position.setVariantName(entity.getVariant().getVariantName());
|
||||
}
|
||||
position.putAdditionalInfoItem("markerPositionDbId", entity.getId());
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package org.brapi.test.BrAPITestServer.service.geno;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerDbIdNotFoundException;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantSetAnalysisWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.VariantSetAnalysisEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.VariantSetEntity;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.VariantSetAnalysisRepository;
|
||||
import org.brapi.test.BrAPITestServer.service.DateUtility;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import io.swagger.model.geno.Analysis;
|
||||
|
||||
@Service
|
||||
public class VariantSetAnalysisService {
|
||||
|
||||
private final VariantSetAnalysisRepository variantSetAnalysisRepository;
|
||||
private final VariantSetService variantSetService;
|
||||
|
||||
public VariantSetAnalysisService(VariantSetAnalysisRepository variantSetAnalysisRepository,
|
||||
VariantSetService variantSetService) {
|
||||
this.variantSetAnalysisRepository = variantSetAnalysisRepository;
|
||||
this.variantSetService = variantSetService;
|
||||
}
|
||||
|
||||
public List<Analysis> findAnalysisByVariantSet(String variantSetDbId) throws BrAPIServerException {
|
||||
assertVariantSetExists(variantSetDbId);
|
||||
return variantSetAnalysisRepository.findByVariantSet_Id(variantSetDbId).stream()
|
||||
.map(this::convertFromEntity)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Analysis saveAnalysis(String variantSetDbId, VariantSetAnalysisWriteRequest request)
|
||||
throws BrAPIServerException {
|
||||
VariantSetEntity variantSet = variantSetService.getVariantSetEntity(variantSetDbId);
|
||||
if (request.getAnalysisName() == null || request.getAnalysisName().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "analysisName is required");
|
||||
}
|
||||
if (request.getAnalysisDbId() != null
|
||||
&& variantSetAnalysisRepository.findById(request.getAnalysisDbId()).isPresent()) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT,
|
||||
"Analysis already exists: " + request.getAnalysisDbId());
|
||||
}
|
||||
VariantSetAnalysisEntity entity = new VariantSetAnalysisEntity();
|
||||
if (request.getAnalysisDbId() != null && !request.getAnalysisDbId().isBlank()) {
|
||||
entity.setId(request.getAnalysisDbId().trim());
|
||||
}
|
||||
updateEntity(entity, variantSet, request);
|
||||
return convertFromEntity(variantSetAnalysisRepository.save(entity));
|
||||
}
|
||||
|
||||
public Analysis updateAnalysis(String variantSetDbId, String analysisDbId, VariantSetAnalysisWriteRequest request)
|
||||
throws BrAPIServerException {
|
||||
VariantSetAnalysisEntity entity = getAnalysisEntity(variantSetDbId, analysisDbId);
|
||||
if (request.getAnalysisName() == null || request.getAnalysisName().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "analysisName is required");
|
||||
}
|
||||
updateEntity(entity, entity.getVariantSet(), request);
|
||||
return convertFromEntity(variantSetAnalysisRepository.save(entity));
|
||||
}
|
||||
|
||||
public Analysis deleteAnalysis(String variantSetDbId, String analysisDbId) throws BrAPIServerException {
|
||||
VariantSetAnalysisEntity entity = getAnalysisEntity(variantSetDbId, analysisDbId);
|
||||
Analysis deleted = convertFromEntity(entity);
|
||||
try {
|
||||
variantSetAnalysisRepository.delete(entity);
|
||||
variantSetAnalysisRepository.flush();
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "Analysis cannot be deleted");
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
private void assertVariantSetExists(String variantSetDbId) throws BrAPIServerException {
|
||||
variantSetService.getVariantSetEntity(variantSetDbId);
|
||||
}
|
||||
|
||||
private VariantSetAnalysisEntity getAnalysisEntity(String variantSetDbId, String analysisDbId)
|
||||
throws BrAPIServerException {
|
||||
VariantSetAnalysisEntity entity = variantSetAnalysisRepository.findById(analysisDbId).orElseThrow(
|
||||
() -> new BrAPIServerDbIdNotFoundException("analysis", analysisDbId, HttpStatus.NOT_FOUND));
|
||||
if (entity.getVariantSet() == null || !variantSetDbId.equals(entity.getVariantSet().getId())) {
|
||||
throw new BrAPIServerDbIdNotFoundException("analysis", analysisDbId, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void updateEntity(VariantSetAnalysisEntity entity, VariantSetEntity variantSet,
|
||||
VariantSetAnalysisWriteRequest request) throws BrAPIServerException {
|
||||
entity.setVariantSet(variantSet);
|
||||
entity.setAnalysisName(request.getAnalysisName().trim());
|
||||
entity.setDescription(trimToNull(request.getDescription()));
|
||||
entity.setType(trimToNull(request.getType()));
|
||||
entity.setCreated(DateUtility.toDate(request.getCreated()));
|
||||
entity.setUpdated(DateUtility.toDate(request.getUpdated()));
|
||||
entity.setSoftware(normalizeSoftware(request.getSoftware()));
|
||||
}
|
||||
|
||||
private List<String> normalizeSoftware(List<String> software) {
|
||||
if (software == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return software.stream()
|
||||
.map(this::trimToNull)
|
||||
.filter(item -> item != null && !item.isBlank())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String trimToNull(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
return trimmed.isEmpty() ? null : trimmed;
|
||||
}
|
||||
|
||||
private Analysis convertFromEntity(VariantSetAnalysisEntity entity) {
|
||||
Analysis analysis = new Analysis();
|
||||
analysis.setAnalysisDbId(entity.getId());
|
||||
analysis.setAnalysisName(entity.getAnalysisName());
|
||||
analysis.setCreated(DateUtility.toOffsetDateTime(entity.getCreated()));
|
||||
analysis.setDescription(entity.getDescription());
|
||||
analysis.setSoftware(entity.getSoftware());
|
||||
analysis.setType(entity.getType());
|
||||
analysis.setUpdated(DateUtility.toOffsetDateTime(entity.getUpdated()));
|
||||
return analysis;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package org.brapi.test.BrAPITestServer.service.geno;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerDbIdNotFoundException;
|
||||
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantSetAvailableFormatRecord;
|
||||
import org.brapi.test.BrAPITestServer.model.dto.geno.VariantSetAvailableFormatWriteRequest;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.VariantSetAvailableFormatEntity;
|
||||
import org.brapi.test.BrAPITestServer.model.entity.geno.VariantSetEntity;
|
||||
import org.brapi.test.BrAPITestServer.repository.geno.VariantSetAvailableFormatRepository;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import io.swagger.model.geno.GenoFileDataFormatEnum;
|
||||
|
||||
@Service
|
||||
public class VariantSetAvailableFormatService {
|
||||
|
||||
private final VariantSetAvailableFormatRepository variantSetAvailableFormatRepository;
|
||||
private final VariantSetService variantSetService;
|
||||
|
||||
public VariantSetAvailableFormatService(
|
||||
VariantSetAvailableFormatRepository variantSetAvailableFormatRepository,
|
||||
VariantSetService variantSetService) {
|
||||
this.variantSetAvailableFormatRepository = variantSetAvailableFormatRepository;
|
||||
this.variantSetService = variantSetService;
|
||||
}
|
||||
|
||||
public List<VariantSetAvailableFormatRecord> findFormatsByVariantSet(String variantSetDbId)
|
||||
throws BrAPIServerException {
|
||||
variantSetService.getVariantSetEntity(variantSetDbId);
|
||||
return variantSetAvailableFormatRepository.findByVariantSet_Id(variantSetDbId).stream()
|
||||
.map(this::convertFromEntity)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public VariantSetAvailableFormatRecord saveFormat(String variantSetDbId,
|
||||
VariantSetAvailableFormatWriteRequest request) throws BrAPIServerException {
|
||||
VariantSetEntity variantSet = variantSetService.getVariantSetEntity(variantSetDbId);
|
||||
validateFormatRequest(request);
|
||||
if (request.getFormatDbId() != null
|
||||
&& variantSetAvailableFormatRepository.findById(request.getFormatDbId()).isPresent()) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT,
|
||||
"Available format already exists: " + request.getFormatDbId());
|
||||
}
|
||||
VariantSetAvailableFormatEntity entity = new VariantSetAvailableFormatEntity();
|
||||
if (request.getFormatDbId() != null && !request.getFormatDbId().isBlank()) {
|
||||
entity.setId(request.getFormatDbId().trim());
|
||||
}
|
||||
updateEntity(entity, variantSet, request);
|
||||
return convertFromEntity(variantSetAvailableFormatRepository.save(entity));
|
||||
}
|
||||
|
||||
public VariantSetAvailableFormatRecord updateFormat(String variantSetDbId, String formatDbId,
|
||||
VariantSetAvailableFormatWriteRequest request) throws BrAPIServerException {
|
||||
VariantSetAvailableFormatEntity entity = getFormatEntity(variantSetDbId, formatDbId);
|
||||
validateFormatRequest(request);
|
||||
updateEntity(entity, entity.getVariantSet(), request);
|
||||
return convertFromEntity(variantSetAvailableFormatRepository.save(entity));
|
||||
}
|
||||
|
||||
public VariantSetAvailableFormatRecord deleteFormat(String variantSetDbId, String formatDbId)
|
||||
throws BrAPIServerException {
|
||||
VariantSetAvailableFormatEntity entity = getFormatEntity(variantSetDbId, formatDbId);
|
||||
VariantSetAvailableFormatRecord deleted = convertFromEntity(entity);
|
||||
try {
|
||||
variantSetAvailableFormatRepository.delete(entity);
|
||||
variantSetAvailableFormatRepository.flush();
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
throw new BrAPIServerException(HttpStatus.CONFLICT, "Available format cannot be deleted");
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
private VariantSetAvailableFormatEntity getFormatEntity(String variantSetDbId, String formatDbId)
|
||||
throws BrAPIServerException {
|
||||
VariantSetAvailableFormatEntity entity = variantSetAvailableFormatRepository.findById(formatDbId).orElseThrow(
|
||||
() -> new BrAPIServerDbIdNotFoundException("availableFormat", formatDbId, HttpStatus.NOT_FOUND));
|
||||
if (entity.getVariantSet() == null || !variantSetDbId.equals(entity.getVariantSet().getId())) {
|
||||
throw new BrAPIServerDbIdNotFoundException("availableFormat", formatDbId, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void validateFormatRequest(VariantSetAvailableFormatWriteRequest request) throws BrAPIServerException {
|
||||
if (request.getDataFormat() == null || request.getDataFormat().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "dataFormat is required");
|
||||
}
|
||||
if (request.getFileFormat() == null || request.getFileFormat().isBlank()) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "fileFormat is required");
|
||||
}
|
||||
if (GenoFileDataFormatEnum.fromValue(request.getDataFormat()) == null) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "Invalid dataFormat: " + request.getDataFormat());
|
||||
}
|
||||
if (request.getFileURL() != null && !request.getFileURL().isBlank()) {
|
||||
try {
|
||||
new URL(request.getFileURL().trim());
|
||||
} catch (MalformedURLException e) {
|
||||
throw new BrAPIServerException(HttpStatus.BAD_REQUEST, "Invalid fileURL: " + request.getFileURL());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateEntity(VariantSetAvailableFormatEntity entity, VariantSetEntity variantSet,
|
||||
VariantSetAvailableFormatWriteRequest request) {
|
||||
entity.setVariantSet(variantSet);
|
||||
entity.setDataFormat(GenoFileDataFormatEnum.fromValue(request.getDataFormat()));
|
||||
entity.setFileFormat(io.swagger.model.WSMIMEDataTypes.fromValue(request.getFileFormat()));
|
||||
entity.setFileURL(trimToNull(request.getFileURL()));
|
||||
entity.setExpandHomozygotes(request.getExpandHomozygotes());
|
||||
entity.setSepPhased(trimToNull(request.getSepPhased()));
|
||||
entity.setSepUnphased(trimToNull(request.getSepUnphased()));
|
||||
entity.setUnknownString(trimToNull(request.getUnknownString()));
|
||||
}
|
||||
|
||||
private String trimToNull(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
return trimmed.isEmpty() ? null : trimmed;
|
||||
}
|
||||
|
||||
private VariantSetAvailableFormatRecord convertFromEntity(VariantSetAvailableFormatEntity entity) {
|
||||
VariantSetAvailableFormatRecord record = new VariantSetAvailableFormatRecord();
|
||||
record.setFormatDbId(entity.getId());
|
||||
if (entity.getVariantSet() != null) {
|
||||
record.setVariantSetDbId(entity.getVariantSet().getId());
|
||||
}
|
||||
if (entity.getDataFormat() != null) {
|
||||
record.setDataFormat(entity.getDataFormat().toString());
|
||||
}
|
||||
if (entity.getFileFormat() != null) {
|
||||
record.setFileFormat(entity.getFileFormat().toString());
|
||||
}
|
||||
record.setFileURL(entity.getFileURL());
|
||||
record.setExpandHomozygotes(entity.getExpandHomozygotes());
|
||||
record.setSepPhased(entity.getSepPhased());
|
||||
record.setSepUnphased(entity.getSepUnphased());
|
||||
record.setUnknownString(entity.getUnknownString());
|
||||
return record;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user