Skip to content

Commit

Permalink
Provide ExperimentId To batch registration email (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffengreiner authored Dec 17, 2024
1 parent f02489f commit e70a389
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public interface AppContextProvider {
* Returns a resolvable URL to the target project's sample page resource in the application.
*
* @param projectId the project id
* @param experimentId the experiment id
* @return a fully resolvable URL
* @since 1.0.0
*/
String urlToSamplePage(String projectId);
String urlToSamplePage(String projectId, String experimentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import life.qbic.projectmanagement.application.sample.SampleRegistrationService;
import life.qbic.projectmanagement.domain.model.batch.Batch;
import life.qbic.projectmanagement.domain.model.batch.BatchId;
import life.qbic.projectmanagement.domain.model.experiment.ExperimentId;
import life.qbic.projectmanagement.domain.model.project.ProjectId;
import life.qbic.projectmanagement.domain.model.sample.Sample;
import life.qbic.projectmanagement.domain.model.sample.SampleId;
Expand Down Expand Up @@ -70,21 +71,23 @@ public BatchRegistrationService(BatchRepository batchRepository,
* are usually followed by a complete batch that represents the measurements of
* the complete experiment.
* @param projectId id of the project this batch is added to
* @param experimentId id of the experiment this batch is added to
* @return a result object with the response. If the registration failed, a response code will be
* provided.
* @since 1.0.0
*/
@PreAuthorize("hasPermission(#projectId, 'life.qbic.projectmanagement.domain.model.project.Project', 'WRITE')")
public Result<BatchId, ResponseCode> registerBatch(String label, boolean isPilot,
ProjectId projectId) {
ProjectId projectId, ExperimentId experimentId) {
var project = projectInformationService.find(projectId);
if (project.isEmpty()) {
log.error(
"Batch registration aborted. Reason: project with id:" + projectId + " was not found");
return Result.fromError(ResponseCode.BATCH_CREATION_FAILED);
}
String projectTitle = project.get().getProjectIntent().projectTitle().title();
var result = batchDomainService.register(label, isPilot, projectTitle, projectId);
var result = batchDomainService.register(label, isPilot, projectTitle, projectId,
experimentId);
if (result.isError()) {
return Result.fromError(ResponseCode.BATCH_REGISTRATION_FAILED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public Class<? extends DomainEvent> subscribedToEventType() {
@PreAuthorize("hasPermission(#projectId, 'life.qbic.projectmanagement.domain.model.project.Project', 'WRITE')")
public void handleEvent(BatchRegistered event) {
List<RecipientDTO> recipients = getRecipients(event.projectId());
String sampleUri = appContextProvider.urlToSamplePage(event.projectId().value());
String sampleUri = appContextProvider.urlToSamplePage(event.projectId().value(),
event.experimentId().value());
notifyAllRecipients(recipients, event.projectTitle(), event.name(), sampleUri);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ public SampleRegistrationServiceV2(BatchRegistrationService batchRegistrationSer
@PreAuthorize("hasPermission(#projectId, 'life.qbic.projectmanagement.domain.model.project.Project', 'WRITE')")
@Async
public CompletableFuture<Void> registerSamples(Collection<SampleMetadata> sampleMetadata,
ProjectId projectId, String batchLabel, boolean batchIsPilot)
ProjectId projectId, String batchLabel, boolean batchIsPilot, ExperimentId experimentId)
throws RegistrationException {
var result = batchRegistrationService.registerBatch(batchLabel, batchIsPilot, projectId);
var result = batchRegistrationService.registerBatch(batchLabel, batchIsPilot, projectId,
experimentId);
if (result.isError()) {
throw new RegistrationException("Batch registration failed");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Objects;
import life.qbic.domain.concepts.DomainEvent;
import life.qbic.projectmanagement.domain.model.batch.BatchId;
import life.qbic.projectmanagement.domain.model.experiment.ExperimentId;
import life.qbic.projectmanagement.domain.model.project.ProjectId;

/**
Expand All @@ -17,23 +18,27 @@
public class BatchRegistered extends DomainEvent {

@Serial
private static final long serialVersionUID = 580378782496926484L;
private static final long serialVersionUID = 1439070961084871049L;

private final BatchId batchId;
private final String projectTitle;
private final String batchName;
private final ProjectId projectId;
private final ExperimentId experimentId;

private BatchRegistered(BatchId batchId, String batchName, String projectTitle, ProjectId projectId) {
private BatchRegistered(BatchId batchId, String batchName, String projectTitle,
ProjectId projectId,
ExperimentId experimentId) {
this.batchId = Objects.requireNonNull(batchId);
this.projectTitle = Objects.requireNonNull(projectTitle);
this.batchName = Objects.requireNonNull(batchName);
this.projectId = Objects.requireNonNull(projectId);
this.experimentId = Objects.requireNonNull(experimentId);
}

public static BatchRegistered create(String batchName, BatchId id, String projectTitle,
ProjectId projectId) {
return new BatchRegistered(id, batchName, projectTitle, projectId);
ProjectId projectId, ExperimentId experimentId) {
return new BatchRegistered(id, batchName, projectTitle, projectId, experimentId);
}

@JsonGetter("batchId")
Expand All @@ -50,4 +55,8 @@ public BatchId batchId() {
@JsonGetter("projectId")
public ProjectId projectId() { return projectId; }

@JsonGetter("experimentId")
public ExperimentId experimentId() {
return experimentId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import life.qbic.domain.concepts.DomainEventDispatcher;
import life.qbic.projectmanagement.domain.model.batch.Batch;
import life.qbic.projectmanagement.domain.model.batch.BatchId;
import life.qbic.projectmanagement.domain.model.experiment.ExperimentId;
import life.qbic.projectmanagement.domain.model.project.ProjectId;
import life.qbic.projectmanagement.domain.model.project.event.ProjectChanged;
import life.qbic.projectmanagement.domain.model.sample.event.BatchDeleted;
Expand Down Expand Up @@ -42,25 +43,28 @@ public BatchDomainService(BatchRepository batchRepository) {
* measurements of the complete experiment.
* @param projectName the title of the project the batch is added to
* @param projectId id of the project this batch is added to
* @param experimentId id of the experiment this batch is added to
* @return a result object with the response. If the registration failed, a response code will be
* provided.
* @since 1.0.0
*/
public Result<BatchId, ResponseCode> register(String label, boolean isPilot, String projectName,
ProjectId projectId) {
ProjectId projectId, ExperimentId experimentId) {
Batch batch = Batch.create(label, isPilot);
var result = batchRepository.add(batch);
if (result.isError()) {
return Result.fromError(ResponseCode.BATCH_REGISTRATION_FAILED);
} else {
dispatchRegistration(label, batch.batchId(), projectName, projectId);
dispatchRegistration(label, batch.batchId(), projectName, projectId,
experimentId);
}
return Result.fromValue(result.getValue().batchId());
}

private void dispatchRegistration(String name, BatchId id, String projectName,
ProjectId projectId) {
BatchRegistered batchRegistered = BatchRegistered.create(name, id, projectName, projectId);
ProjectId projectId, ExperimentId experimentId) {
BatchRegistered batchRegistered = BatchRegistered.create(name, id, projectName, projectId,
experimentId);
DomainEventDispatcher.instance().dispatch(batchRegistered);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import life.qbic.domain.concepts.DomainEventDispatcher
import life.qbic.domain.concepts.DomainEventSubscriber
import life.qbic.projectmanagement.domain.model.batch.Batch
import life.qbic.projectmanagement.domain.model.batch.BatchId
import life.qbic.projectmanagement.domain.model.experiment.ExperimentId
import life.qbic.projectmanagement.domain.model.project.*
import life.qbic.projectmanagement.domain.model.sample.event.BatchDeleted
import life.qbic.projectmanagement.domain.model.sample.event.BatchRegistered
Expand Down Expand Up @@ -49,7 +50,7 @@ class BatchDomainServiceSpec extends Specification {
DomainEventDispatcher.instance().subscribe(batchRegistered)

when:
domainService.register("test", false, project.projectIntent.projectTitle().title(), project.getId())
domainService.register("test", false, project.projectIntent.projectTitle().title(), project.getId(), ExperimentId.create())

then:
batchRegistered.eventReceived
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public String urlToProject(String projectId) {
}

@Override
public String urlToSamplePage(String projectId) {
public String urlToSamplePage(String projectId, String experimentId) {
try {
return new URL(baseUrlApplication,
Paths.get(baseUrlApplication.getPath(), samplesEndpoint.formatted(projectId))
Paths.get(baseUrlApplication.getPath(),
samplesEndpoint.formatted(projectId, experimentId))
.toString()).toExternalForm();
} catch (MalformedURLException e) {
throw new ApplicationException("Data Manager context creation failed.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private void onRegisterBatchClicked() {
UI ui = event.getSource().getUI().orElseThrow();
CompletableFuture<Void> registrationTask = sampleRegistrationServiceV2.registerSamples(
event.validatedSampleMetadata(),
projectId, event.batchName(), false)
projectId, event.batchName(), false, experimentId)
.orTimeout(5, TimeUnit.MINUTES);
try {
registrationTask
Expand Down
2 changes: 1 addition & 1 deletion user-interface/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ routing.password-reset.reset-parameter=${PASSWORD_RESET_PARAMETER:user-id}
# route to project resource
routing.projects.endpoint=/projects
routing.projects.info.endpoint=/projects/%s/info
routing.projects.samples.enpoint=/projects/%s/samples
routing.projects.samples.enpoint=/projects/%s/experiments/%s/samples
routing.registration.oidc.orcid.endpoint=/register/oidc
routing.registration.error.pending-email-verification=/register/pending-email-confirmation
################## oauth provider ###########################
Expand Down

0 comments on commit e70a389

Please sign in to comment.