Skip to content

Commit

Permalink
fix: notifications when creationg and updating root networks
Browse files Browse the repository at this point in the history
Signed-off-by: LE SAULNIER Kevin <[email protected]>
  • Loading branch information
LE SAULNIER Kevin committed Dec 18, 2024
1 parent 5249865 commit 231a472
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public class NotificationService {
public static final String MESSAGE_LOG = "Sending message : {}";
public static final String DEFAULT_ERROR_MESSAGE = "Unknown error";

public static final String ROOT_NETWORKS_UPDATED = "rootNetworksUpdated";
public static final String ROOT_NETWORKS_UPDATE_FAILED = "rootNetworksUpdateFailed";

public static final String STUDY_ALERT = "STUDY_ALERT";

private static final String CATEGORY_BROKER_OUTPUT = NotificationService.class.getName() + ".output-broker-messages";
Expand Down Expand Up @@ -427,4 +430,21 @@ public void emitStudyAlert(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid,
LOGGER.error("Unable to notify on study alert", e);
}
}

@PostCompletion
public void emitRootNetworksUpdated(UUID studyUuid) {
sendUpdateMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_UPDATE_TYPE, ROOT_NETWORKS_UPDATED)
.build());
}

@PostCompletion
public void emitRootNetworksUpdateFailed(UUID studyUuid, String errorMessage) {
sendUpdateMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_UPDATE_TYPE, ROOT_NETWORKS_UPDATE_FAILED)
.setHeader(HEADER_ERROR, errorMessage)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,13 @@ public Consumer<Message<String>> consumeCaseImportFailed() {
UUID studyUuid = receiver.getStudyUuid();
String userId = receiver.getUserId();

studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId);
notificationService.emitStudyCreationError(studyUuid, userId, errorMessage);
switch(receiver.getCaseImportAction()) {
case STUDY_CREATION -> {
studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId);
notificationService.emitStudyCreationError(studyUuid, userId, errorMessage);
}
case ROOT_NETWORK_CREATION, ROOT_NETWORK_MODIFICATION -> notificationService.emitRootNetworksUpdateFailed(studyUuid, errorMessage);
}
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ public void createRootNetwork(@NonNull UUID studyUuid, @NonNull RootNetworkInfos
if (rootNetworkCreationRequestEntityOpt.isPresent()) {
rootNetworkService.createRootNetwork(studyEntity, rootNetworkInfos);
rootNetworkService.deleteCreationRequest(rootNetworkCreationRequestEntityOpt.get());
// TODO: send notification to frontend
} else {
rootNetworkService.delete(rootNetworkInfos);
}
notificationService.emitRootNetworksUpdated(studyUuid);
}

@Transactional(readOnly = true)
Expand Down

0 comments on commit 231a472

Please sign in to comment.