Skip to content

Commit afe820f

Browse files
Update experiment API (#1065)
* Update experiment API * Update JavaDoc Co-authored-by: steffengreiner <[email protected]> --------- Co-authored-by: KochTobi <[email protected]> Co-authored-by: steffengreiner <[email protected]>
1 parent 9810423 commit afe820f

File tree

2 files changed

+133
-30
lines changed

2 files changed

+133
-30
lines changed

project-management/src/main/java/life/qbic/projectmanagement/application/api/AsyncProjectService.java

+125-10
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public interface AsyncProjectService {
3636

3737
/**
38-
* Submits a project update request and returns a reactive {@link Mono< ProjectUpdateResponse >}
38+
* Submits a project update request and returns a reactive {@link Mono<ProjectUpdateResponse>}
3939
* object immediately.
4040
* <p>
4141
* The method implementation must be non-blocking.
@@ -65,7 +65,7 @@ public interface AsyncProjectService {
6565

6666
/**
6767
* Submits an experiment update request and returns a reactive
68-
* {@link Mono< ExperimentUpdateResponse >} object immediately.
68+
* {@link Mono<ExperimentUpdateResponse>} object immediately.
6969
* <p>
7070
* The method is non-blocking.
7171
* <p>
@@ -92,7 +92,7 @@ public interface AsyncProjectService {
9292
Mono<ExperimentUpdateResponse> update(ExperimentUpdateRequest request);
9393

9494
/**
95-
* Submits a project creation request and returns a {@link Mono< ProjectCreationResponse >}
95+
* Submits a project creation request and returns a {@link Mono<ProjectCreationResponse>}
9696
* immediately.
9797
* <p>
9898
* This implementation must be non-blocking.
@@ -244,8 +244,9 @@ sealed interface ProjectUpdateResponseBody permits FundingInformation, ProjectCo
244244

245245
}
246246

247-
sealed interface ExperimentUpdateRequestBody permits ConfoundingVariables, ExperimentDescription,
248-
ExperimentalGroups, ExperimentalVariables {
247+
sealed interface ExperimentUpdateRequestBody permits ConfoundingVariableAdditions,
248+
ConfoundingVariableDeletions, ConfoundingVariableUpdates, ExperimentDescription,
249+
ExperimentalGroups, ExperimentalVariableAdditions, ExperimentalVariableDeletions {
249250

250251
}
251252

@@ -331,11 +332,54 @@ record FundingInformation(String grant, String grantId) implements ProjectUpdate
331332
* @param unit the unit of the experimental variable. Can be null if no unit is set
332333
* @since 1.9.0
333334
*/
334-
record ExperimentalVariable(String name, Set<String> levels, @Nullable String unit) {
335+
record ExperimentalVariable(Long id, String name, Set<String> levels, @Nullable String unit) {
335336

336337
public ExperimentalVariable {
337338
levels = Set.copyOf(levels);
338339
}
340+
341+
@Override
342+
public Set<String> levels() {
343+
return Set.copyOf(levels);
344+
}
345+
}
346+
347+
/**
348+
* Information about variables that should be created
349+
*
350+
* @param experimentalVariables
351+
* @since 1.9.2
352+
*/
353+
record ExperimentalVariableAdditions(List<ExperimentalVariable> experimentalVariables) implements
354+
ExperimentUpdateRequestBody {
355+
356+
public ExperimentalVariableAdditions {
357+
experimentalVariables = List.copyOf(experimentalVariables);
358+
}
359+
360+
@Override
361+
public List<ExperimentalVariable> experimentalVariables() {
362+
return List.copyOf(experimentalVariables);
363+
}
364+
}
365+
366+
367+
/**
368+
* Information about variables that should be deleted
369+
*
370+
* @param experimentalVariables
371+
*/
372+
record ExperimentalVariableDeletions(List<ExperimentalVariable> experimentalVariables) implements
373+
ExperimentUpdateRequestBody {
374+
375+
public ExperimentalVariableDeletions {
376+
experimentalVariables = List.copyOf(experimentalVariables);
377+
}
378+
379+
@Override
380+
public List<ExperimentalVariable> experimentalVariables() {
381+
return List.copyOf(experimentalVariables);
382+
}
339383
}
340384

341385
/**
@@ -345,22 +389,29 @@ record ExperimentalVariable(String name, Set<String> levels, @Nullable String un
345389
* @since 1.9.0
346390
*/
347391
record ExperimentalVariables(List<ExperimentalVariable> experimentalVariables) implements
348-
ExperimentUpdateRequestBody, ExperimentUpdateResponseBody {
392+
ExperimentUpdateResponseBody {
393+
349394

350395
public ExperimentalVariables {
351396
experimentalVariables = List.copyOf(experimentalVariables);
352397
}
398+
399+
@Override
400+
public List<ExperimentalVariable> experimentalVariables() {
401+
return List.copyOf(experimentalVariables);
402+
}
353403
}
354404

355405
/**
356406
* A level of an experimental variable
357407
*
408+
* @param variableId the identifier of the variable
358409
* @param variableName the name of the variable
359410
* @param levelValue the value of the level
360411
* @param unit the unit for the value of the level. Can be null if no unit is set
361412
* @since 1.9.0
362413
*/
363-
record VariableLevel(String variableName, String levelValue, @Nullable String unit) {
414+
record VariableLevel(Long variableId, String variableName, String levelValue, @Nullable String unit) {
364415

365416
}
366417

@@ -421,17 +472,81 @@ record ExperimentDescription(String experimentName, Set<String> species, Set<Str
421472
}
422473

423474
/**
424-
* A list of confounding variable information. Can be used in
475+
* A list of confounding variable information for variable addition. Can be used in
476+
* {@link #update(ExperimentUpdateRequest)}
477+
*
478+
* @param confoundingVariables the variable information
479+
*/
480+
record ConfoundingVariableAdditions(
481+
List<ConfoundingVariableInformation> confoundingVariables) implements
482+
ExperimentUpdateRequestBody {
483+
484+
public ConfoundingVariableAdditions {
485+
confoundingVariables = List.copyOf(confoundingVariables);
486+
}
487+
488+
@Override
489+
public List<ConfoundingVariableInformation> confoundingVariables() {
490+
return List.copyOf(confoundingVariables);
491+
}
492+
}
493+
494+
/**
495+
* A list of confounding variable information for variable update. Can be used in
496+
* {@link #update(ExperimentUpdateRequest)}
497+
*
498+
* @param confoundingVariables the variable information
499+
*/
500+
record ConfoundingVariableDeletions(
501+
List<ConfoundingVariableInformation> confoundingVariables) implements
502+
ExperimentUpdateRequestBody {
503+
504+
public ConfoundingVariableDeletions {
505+
confoundingVariables = List.copyOf(confoundingVariables);
506+
}
507+
508+
@Override
509+
public List<ConfoundingVariableInformation> confoundingVariables() {
510+
return List.copyOf(confoundingVariables);
511+
}
512+
}
513+
514+
/**
515+
* A list of confounding variable information for variable deletion. Can be used in
425516
* {@link #update(ExperimentUpdateRequest)}
426517
*
427518
* @param confoundingVariables the variable information
428519
*/
520+
record ConfoundingVariableUpdates(
521+
List<ConfoundingVariableInformation> confoundingVariables) implements
522+
ExperimentUpdateRequestBody {
523+
524+
public ConfoundingVariableUpdates {
525+
confoundingVariables = List.copyOf(confoundingVariables);
526+
}
527+
528+
@Override
529+
public List<ConfoundingVariableInformation> confoundingVariables() {
530+
return List.copyOf(confoundingVariables);
531+
}
532+
}
533+
534+
/**
535+
* A list of confounding variable information.
536+
*
537+
* @param confoundingVariables the variable information
538+
*/
429539
record ConfoundingVariables(List<ConfoundingVariableInformation> confoundingVariables) implements
430-
ExperimentUpdateRequestBody, ExperimentUpdateResponseBody {
540+
ExperimentUpdateResponseBody {
431541

432542
public ConfoundingVariables {
433543
confoundingVariables = List.copyOf(confoundingVariables);
434544
}
545+
546+
@Override
547+
public List<ConfoundingVariableInformation> confoundingVariables() {
548+
return List.copyOf(confoundingVariables);
549+
}
435550
}
436551

437552

project-management/src/main/java/life/qbic/projectmanagement/application/api/AsyncProjectServiceImpl.java

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package life.qbic.projectmanagement.application.api;
22

33
import static life.qbic.projectmanagement.application.authorization.ReactiveSecurityContextUtils.applySecurityContext;
4-
import static life.qbic.projectmanagement.application.authorization.ReactiveSecurityContextUtils.applySecurityContextMany;
54
import static life.qbic.projectmanagement.application.authorization.ReactiveSecurityContextUtils.writeSecurityContext;
5+
import static life.qbic.projectmanagement.application.authorization.ReactiveSecurityContextUtils.applySecurityContextMany;
66
import static life.qbic.projectmanagement.application.authorization.ReactiveSecurityContextUtils.writeSecurityContextMany;
77

88
import java.nio.ByteBuffer;
@@ -12,6 +12,7 @@
1212
import life.qbic.logging.api.Logger;
1313
import life.qbic.logging.service.LoggerFactory;
1414
import life.qbic.projectmanagement.application.ProjectInformationService;
15+
import life.qbic.projectmanagement.application.sample.SampleIdCodeEntry;
1516
import life.qbic.projectmanagement.application.sample.SampleInformationService;
1617
import life.qbic.projectmanagement.application.sample.SamplePreview;
1718
import life.qbic.projectmanagement.domain.model.experiment.ExperimentId;
@@ -164,17 +165,17 @@ public Mono<Sample> findSample(String projectId, String sampleId) {
164165
public Mono<ExperimentUpdateResponse> update(
165166
ExperimentUpdateRequest request) {
166167
Mono<ExperimentUpdateResponse> response = switch (request.body()) {
167-
case ExperimentalVariables experimentalVariables ->
168-
updateExperimentalVariables(request.projectId(), request.experimentId(),
169-
experimentalVariables);
168+
170169
case ExperimentDescription experimentDescription ->
171170
updateExperimentDescription(request.projectId(), request.experimentId(),
172171
experimentDescription);
173172

174-
case ConfoundingVariables confoundingVariables ->
175-
updateConfoundingVariables(request.projectId(), request.experimentId(),
176-
confoundingVariables);
177173
case ExperimentalGroups experimentalGroups -> unknownRequest();
174+
case ConfoundingVariableAdditions confoundingVariableAdditions -> unknownRequest();
175+
case ConfoundingVariableDeletions confoundingVariableDeletions -> unknownRequest();
176+
case ConfoundingVariableUpdates confoundingVariableUpdates -> unknownRequest();
177+
case ExperimentalVariableAdditions experimentalVariableAdditions -> unknownRequest();
178+
case ExperimentalVariableDeletions experimentalVariableDeletions -> unknownRequest();
178179
};
179180

180181
SecurityContext securityContext = SecurityContextHolder.getContext();
@@ -187,26 +188,13 @@ private <T> Mono<T> unknownRequest() {
187188
return Mono.error(() -> new UnknownRequestException("Invalid request body"));
188189
}
189190

190-
private Mono<ExperimentUpdateResponse> updateConfoundingVariables(String projectId,
191-
String experimentId,
192-
ConfoundingVariables confoundingVariables) {
193-
//TODO implement
194-
throw new RuntimeException("Not implemented");
195-
}
196-
197191
private Mono<ExperimentUpdateResponse> updateExperimentDescription(String projectId,
198192
String experimentId,
199193
ExperimentDescription experimentDescription) {
200194
//TODO implement
201195
throw new RuntimeException("Not implemented");
202196
}
203197

204-
private Mono<ExperimentUpdateResponse> updateExperimentalVariables(String projectId,
205-
String experimentId, ExperimentalVariables experimentalVariables) {
206-
//TODO implement
207-
throw new RuntimeException("Not implemented");
208-
}
209-
210198

211199
private Mono<ProjectUpdateResponse> updateProjectDesign(String projectId, ProjectDesign design,
212200
String requestId) {

0 commit comments

Comments
 (0)