Skip to content

Commit

Permalink
Add elementUuid to the notification header. (#41)
Browse files Browse the repository at this point in the history

Signed-off-by: AAJELLAL <[email protected]>
  • Loading branch information
AAJELLAL authored Jul 19, 2024
1 parent 717a103 commit 56b5193
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class DirectoryNotificationWebSocketHandler implements WebSocketHandler {
static final String HEADER_ELEMENT_NAME = "elementName";
static final String HEADER_IS_ROOT_DIRECTORY = "isRootDirectory";
static final String HEADER_NOTIFICATION_TYPE = "notificationType";
static final String HEADER_STUDY_UUID = "studyUuid";
static final String HEADER_ELEMENT_UUID = "elementUuid";

private ObjectMapper jacksonObjectMapper;

Expand Down Expand Up @@ -110,7 +110,7 @@ private Flux<WebSocketMessage> notificationFlux(WebSocketSession webSocketSessio
return !(filterUpdateType != null && !filterUpdateType.equals(message.getHeaders().get(HEADER_UPDATE_TYPE)));
}).filter(message -> {
Set<String> filterElementUuid = (Set<String>) webSocketSession.getAttributes().get(FILTER_ELEMENT_UUIDS);
return filterElementUuid == null || filterElementUuid.contains(message.getHeaders().get(HEADER_DIRECTORY_UUID)) || filterElementUuid.contains(message.getHeaders().get(HEADER_STUDY_UUID));
return filterElementUuid == null || filterElementUuid.contains(message.getHeaders().get(HEADER_DIRECTORY_UUID)) || filterElementUuid.contains(message.getHeaders().get(HEADER_ELEMENT_UUID));
}).map(m -> {
try {
return jacksonObjectMapper.writeValueAsString(Map.of(
Expand Down Expand Up @@ -142,8 +142,8 @@ private static Map<String, Object> toResultHeader(Map<String, Object> messageHea
if (messageHeader.get(HEADER_ELEMENT_NAME) != null) {
resHeader.put(HEADER_ELEMENT_NAME, messageHeader.get(HEADER_ELEMENT_NAME));
}
if (messageHeader.get(HEADER_STUDY_UUID) != null) {
resHeader.put(HEADER_STUDY_UUID, messageHeader.get(HEADER_STUDY_UUID));
if (messageHeader.get(HEADER_ELEMENT_UUID) != null) {
resHeader.put(HEADER_ELEMENT_UUID, messageHeader.get(HEADER_ELEMENT_UUID));
}
return resHeader;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class DirectoryNotificationWebSocketHandlerTest {
private WebSocketSession ws2;
private HandshakeInfo handshakeinfo;
private Flux<Message<String>> flux;
private static final String STUDY_UUID = UUID.randomUUID().toString();
private static final String ELEMENT_UUID = UUID.randomUUID().toString();

@Before
public void setup() {
Expand Down Expand Up @@ -156,7 +156,6 @@ private void withFilters(String filterUpdateType, String filterElementUuid, bool
Map.of(HEADER_UPDATE_TYPE, "oof"),

Map.of(HEADER_UPDATE_TYPE, "foobar", HEADER_IS_PUBLIC_DIRECTORY, true),
Map.of(HEADER_UPDATE_TYPE, "studies", HEADER_ERROR, "error_message"),

Map.of(HEADER_DIRECTORY_UUID, "public_" + otherUserId, HEADER_UPDATE_TYPE, "foobar", HEADER_IS_PUBLIC_DIRECTORY, true, HEADER_ERROR, "error_message"),
Map.of(HEADER_DIRECTORY_UUID, "public_" + connectedUserId, HEADER_UPDATE_TYPE, "oof", HEADER_USER_ID, connectedUserId, HEADER_IS_PUBLIC_DIRECTORY, true, HEADER_ELEMENT_NAME, "titi"),
Expand All @@ -165,7 +164,7 @@ private void withFilters(String filterUpdateType, String filterElementUuid, bool
Map.of(HEADER_DIRECTORY_UUID, "private_" + otherUserId, HEADER_UPDATE_TYPE, "rab", HEADER_USER_ID, otherUserId, HEADER_IS_PUBLIC_DIRECTORY, false),
Map.of(HEADER_DIRECTORY_UUID, "public_" + otherUserId, HEADER_UPDATE_TYPE, "rab", HEADER_USER_ID, otherUserId, HEADER_IS_PUBLIC_DIRECTORY, true,
HEADER_ERROR, "error_message", HEADER_NOTIFICATION_TYPE, "UPDATE_DIRECTORY", HEADER_IS_ROOT_DIRECTORY, "false", HEADER_ELEMENT_NAME, "tutu"),
Map.of(HEADER_STUDY_UUID, STUDY_UUID, HEADER_USER_ID, connectedUserId))
Map.of(HEADER_ELEMENT_UUID, ELEMENT_UUID, HEADER_USER_ID, connectedUserId))
.map(map -> new GenericMessage<>("", map))
.collect(Collectors.toList());

Expand All @@ -181,15 +180,15 @@ private void withFilters(String filterUpdateType, String filterElementUuid, bool
.filter(m -> {
String userId = (String) m.getHeaders().get(HEADER_USER_ID);
String updateType = (String) m.getHeaders().get(HEADER_UPDATE_TYPE);
String studyUuid = (String) m.getHeaders().get(HEADER_STUDY_UUID);
String elementUuid = (String) m.getHeaders().get(HEADER_ELEMENT_UUID);
String directoryUuid = (String) m.getHeaders().get(HEADER_DIRECTORY_UUID);
Boolean headerIsPublicDirectory = m.getHeaders().get(HEADER_IS_PUBLIC_DIRECTORY, Boolean.class);
if (m.getHeaders().get(HEADER_ERROR) != null && !connectedUserId.equals(userId)) {
return false;
}
return (connectedUserId.equals(userId) || headerIsPublicDirectory != null && headerIsPublicDirectory)
&& (filterUpdateType == null || filterUpdateType.equals(updateType))
&& (filterElementUuid == null || filterElementUuid.equals(studyUuid) || filterElementUuid.equals(directoryUuid));
&& (filterElementUuid == null || filterElementUuid.equals(directoryUuid) || filterElementUuid.equals(elementUuid));
})
.map(GenericMessage::getHeaders)
.map(this::toResultHeader)
Expand Down Expand Up @@ -226,8 +225,8 @@ private Map<String, Object> toResultHeader(Map<String, Object> messageHeader) {
if (messageHeader.get(HEADER_ELEMENT_NAME) != null) {
resHeader.put(HEADER_ELEMENT_NAME, messageHeader.get(HEADER_ELEMENT_NAME));
}
if (messageHeader.get(HEADER_STUDY_UUID) != null) {
resHeader.put(HEADER_STUDY_UUID, messageHeader.get(HEADER_STUDY_UUID));
if (messageHeader.get(HEADER_ELEMENT_UUID) != null) {
resHeader.put(HEADER_ELEMENT_UUID, messageHeader.get(HEADER_ELEMENT_UUID));
}
resHeader.remove(HEADER_TIMESTAMP);

Expand Down Expand Up @@ -255,23 +254,23 @@ public void testTypeFilterInUrl() {
}

@Test
public void testStudyUuidFilterInBody() {
withFilters(null, STUDY_UUID, false);
public void testEncodingCharactersInBody() {
withFilters("foobar", null, false);
}

@Test
public void testStudyUuidFilterInUrl() {
withFilters(null, STUDY_UUID, true);
public void testEncodingCharactersInUrl() {
withFilters("foobar", null, true);
}

@Test
public void testEncodingCharactersInBody() {
withFilters("foobar", null, false);
public void testElementUuidFilterInBody() {
withFilters(null, ELEMENT_UUID, false);
}

@Test
public void testEncodingCharactersInUrl() {
withFilters("foobar", null, true);
public void testElementUuidFilterInUrl() {
withFilters(null, ELEMENT_UUID, true);
}

@Test
Expand Down

0 comments on commit 56b5193

Please sign in to comment.