Skip to content

Commit 422c161

Browse files
committed
Provide projectId for security context
1 parent c491770 commit 422c161

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

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

+14-6
Original file line numberDiff line numberDiff line change
@@ -101,54 +101,60 @@ Mono<ProjectCreationResponse> create(ProjectCreationRequest request)
101101
/**
102102
* Requests {@link SamplePreview} for a given experiment.
103103
*
104+
* @param projectId the project ID for the project to get the samples for
104105
* @param experimentId the experiment ID for which the sample preview shall be retrieved
105106
* @return a reactive stream of {@link SamplePreview} objects of the experiment
106107
* @throws RequestFailedException if the request could not be executed
107108
* @since 1.10.0
108109
*/
109-
Flux<SamplePreview> getSamplePreviews(String experimentId) throws RequestFailedException;
110+
Flux<SamplePreview> getSamplePreviews(String projectId, String experimentId) throws RequestFailedException;
110111

111112
/**
112113
* Requests {@link SamplePreview} for a given experiment with pagination support.
113114
*
115+
* @param projectId the project ID for the project to get the samples for
114116
* @param experimentId the experiment ID for which the sample preview shall be retrieved
115117
* @param offset the offset from 0 of all available previews the returned previews should
116118
* start
117119
* @param limit the maximum number of previews that should be returned
118120
* @return a reactive stream of {@link SamplePreview} objects in the experiment
119121
* @since 1.10.0
120122
*/
121-
Flux<SamplePreview> getSamplePreviews(String experimentId, int offset, int limit);
123+
Flux<SamplePreview> getSamplePreviews(String projectId, String experimentId, int offset, int limit);
122124

123125
/**
124126
* Requests all {@link Sample} for a given experiment.
125127
*
128+
* @param projectId the project ID for the project to get the samples for
126129
* @param experimentId the experiment ID for which the samples shall be retrieved
127130
* @return a reactive stream of {@link Sample} objects
128131
* @throws RequestFailedException in case the request cannot be executed
129132
* @since 1.10.0
130133
*/
131-
Flux<Sample> getSamples(String experimentId) throws RequestFailedException;
134+
Flux<Sample> getSamples(String projectId, String experimentId) throws RequestFailedException;
132135

133136
/**
134137
* Requests all {@link Sample} for a given batch
135138
*
136-
* @param batchId the batch ID the samples shall be retrieved for
139+
* @param projectId the project ID for the project to get the samples for
140+
* @param batchId the batch ID the samples shall be retrieved for
137141
* @return a reactive stream of {@link Sample} objects for the given batch
138142
* @throws RequestFailedException in case the request cannot be executed
139143
* @since 1.10.0
140144
*/
141-
Flux<Sample> getSamplesForBatch(String batchId) throws RequestFailedException;
145+
Flux<Sample> getSamplesForBatch(String projectId, String batchId) throws RequestFailedException;
142146

143147
/**
144148
* Find the sample ID for a given sample code
145149
*
150+
* @param projectId the project ID for the project to get the samples for
146151
* @param sampleCode the sample code (e.g. Q2TEST001AE) for the project
147152
* @return a reactive container of {@link SampleIdCodeEntry} for the sample code
148153
* @throws RequestFailedException in case the request cannot be executed
149154
* @since 1.10.0
150155
*/
151-
Mono<SampleIdCodeEntry> findSampleId(String sampleCode) throws RequestFailedException;
156+
Mono<SampleIdCodeEntry> findSampleId(String projectId, String sampleCode)
157+
throws RequestFailedException;
152158

153159
/**
154160
* Container of an update request for a service call and part of the
@@ -429,6 +435,7 @@ record ProjectCreationRequest(ProjectDesign design, ProjectContacts contacts,
429435
* @since 1.10.0
430436
*/
431437
record SampleCreationRequest(String projectId, Collection<SampleRegistrationRequest> requests) {
438+
432439
public SampleCreationRequest(String projectId, Collection<SampleRegistrationRequest> requests) {
433440
this.projectId = projectId;
434441
this.requests = List.copyOf(requests);
@@ -443,6 +450,7 @@ public SampleCreationRequest(String projectId, Collection<SampleRegistrationRequ
443450
* @since 1.10.0
444451
*/
445452
record SampleUpdateRequest(String projectId, Collection<SampleUpdate> requests) {
453+
446454
public SampleUpdateRequest(String projectId, Collection<SampleUpdate> requests) {
447455
this.projectId = projectId;
448456
this.requests = List.copyOf(requests);

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

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

3-
import static life.qbic.logging.service.LoggerFactory.logger;
4-
import static life.qbic.projectmanagement.application.authorization.ReactiveSecurityContextUtils.applySecurityContext;
5-
import static life.qbic.projectmanagement.application.authorization.ReactiveSecurityContextUtils.writeSecurityContext;
6-
73
import java.util.Objects;
84
import life.qbic.logging.api.Logger;
95
import life.qbic.logging.service.LoggerFactory;
106
import life.qbic.projectmanagement.application.ProjectInformationService;
7+
import static life.qbic.projectmanagement.application.authorization.ReactiveSecurityContextUtils.applySecurityContext;
8+
import static life.qbic.projectmanagement.application.authorization.ReactiveSecurityContextUtils.writeSecurityContext;
119
import life.qbic.projectmanagement.application.sample.SampleIdCodeEntry;
1210
import life.qbic.projectmanagement.application.sample.SamplePreview;
1311
import life.qbic.projectmanagement.domain.model.project.ProjectId;
@@ -33,16 +31,21 @@
3331
@Service
3432
public class AsyncProjectServiceImpl implements AsyncProjectService {
3533

34+
private static final Logger log = LoggerFactory.logger(AsyncProjectServiceImpl.class);
3635
private final ProjectInformationService projectService;
3736
private final Scheduler scheduler;
38-
private static final Logger log = LoggerFactory.logger(AsyncProjectServiceImpl.class);
3937

4038
public AsyncProjectServiceImpl(@Autowired ProjectInformationService projectService,
4139
@Autowired Scheduler scheduler) {
4240
this.projectService = Objects.requireNonNull(projectService);
4341
this.scheduler = Objects.requireNonNull(scheduler);
4442
}
4543

44+
private static Retry defaultRetryStrategy() {
45+
return Retry.maxInARow(5)
46+
.doBeforeRetry(retrySignal -> log.warn("Operation failed (" + retrySignal + ")"));
47+
}
48+
4649
@Override
4750
public Mono<ProjectUpdateResponse> update(@NonNull ProjectUpdateRequest request)
4851
throws UnknownRequestException, RequestFailedException, AccessDeniedException {
@@ -67,31 +70,35 @@ public Mono<ProjectCreationResponse> create(ProjectCreationRequest request)
6770
}
6871

6972
@Override
70-
public Flux<SamplePreview> getSamplePreviews(String experimentId) throws RequestFailedException {
73+
public Flux<SamplePreview> getSamplePreviews(String projectId, String experimentId)
74+
throws RequestFailedException {
7175
throw new RuntimeException("not implemented");
7276
}
7377

7478
@Override
75-
public Flux<SamplePreview> getSamplePreviews(String experimentId, int offset, int limit) {
79+
public Flux<SamplePreview> getSamplePreviews(String projectId, String experimentId, int offset,
80+
int limit) {
7681
throw new RuntimeException("not implemented");
7782
}
7883

7984
@Override
80-
public Flux<Sample> getSamples(String experimentId) throws RequestFailedException {
85+
public Flux<Sample> getSamples(String projectId, String experimentId)
86+
throws RequestFailedException {
8187
throw new RuntimeException("not implemented");
8288
}
8389

8490
@Override
85-
public Flux<Sample> getSamplesForBatch(String batchId) throws RequestFailedException {
91+
public Flux<Sample> getSamplesForBatch(String projectId, String batchId)
92+
throws RequestFailedException {
8693
throw new RuntimeException("not implemented");
8794
}
8895

8996
@Override
90-
public Mono<SampleIdCodeEntry> findSampleId(String sampleCode) throws RequestFailedException {
97+
public Mono<SampleIdCodeEntry> findSampleId(String projectId, String sampleCode)
98+
throws RequestFailedException {
9199
throw new RuntimeException("not implemented");
92100
}
93101

94-
95102
@Override
96103
public Mono<ExperimentUpdateResponse> update(
97104
ExperimentUpdateRequest request) {
@@ -115,11 +122,6 @@ public Mono<ExperimentUpdateResponse> update(
115122
.retryWhen(defaultRetryStrategy());
116123
}
117124

118-
private static Retry defaultRetryStrategy() {
119-
return Retry.maxInARow(5)
120-
.doBeforeRetry(retrySignal -> log.warn("Operation failed (" + retrySignal + ")"));
121-
}
122-
123125
private <T> Mono<T> unknownRequest() {
124126
return Mono.error(() -> new UnknownRequestException("Invalid request body"));
125127
}
@@ -145,7 +147,8 @@ private Mono<ExperimentUpdateResponse> updateExperimentalVariables(String projec
145147
}
146148

147149

148-
private Mono<ProjectUpdateResponse> updateProjectDesign(String projectId, ProjectDesign design, String requestId) {
150+
private Mono<ProjectUpdateResponse> updateProjectDesign(String projectId, ProjectDesign design,
151+
String requestId) {
149152
return applySecurityContext(
150153
Mono.<ProjectUpdateResponse>create(sink -> {
151154
try {

0 commit comments

Comments
 (0)