Skip to content

Commit

Permalink
Merge pull request #1297 from b2ihealthcare/feature/SO-6038-editor-mi…
Browse files Browse the repository at this point in the history
…gration

Small improvements to 9.x related to the event bus and field replacement
  • Loading branch information
cmark committed May 17, 2024
2 parents 4d2dc94 + 3497428 commit ba1b564
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.b2international.snowowl.core.api.SnowowlRuntimeException;
import com.b2international.snowowl.core.events.util.Promise;
import com.b2international.snowowl.core.events.util.Response;
import com.b2international.snowowl.eventbus.IEventBus;
import com.google.common.collect.Iterables;

import jakarta.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -99,8 +100,10 @@ private Response<?> setDeferredResult(DeferredResult<ResponseEntity<?>> result,
// see Spring Security issue not being able to properly prevent duplicate caching headers
// https://github.com/spring-projects/spring-security/issues/12865
responseHeaders.forEach((entry) -> {
// XXX using set header here, for most of our use cases we only need a single response header, so overwrite anything that has been injected by Spring earlier
webRequest.getNativeResponse(HttpServletResponse.class).setHeader(entry.getKey(), entry.getValue());
if (!IEventBus.SEND_STACK_HEADER.equals(entry.getKey())) {
// XXX using set header here, for most of our use cases we only need a single response header, so overwrite anything that has been injected by Spring earlier
webRequest.getNativeResponse(HttpServletResponse.class).setHeader(entry.getKey(), entry.getValue());
}
});

result.setResult(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public final void handle(IMessage message) {
message.fail(e.getCause());
} catch (ApiException e) {
if (IEventBus.RECORD_SEND_STACK) {
System.err.println(message.headers().get("sendStack"));
System.err.println(message.headers().get(IEventBus.SEND_STACK_HEADER));
}

message.fail(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public interface IEventBus {
* Feature flag for send-time stack tracing
*/
boolean RECORD_SEND_STACK = Boolean.getBoolean("eventbus.record.stack");

/**
* The message header used for send-time call stack tracing
*/
String SEND_STACK_HEADER = "sendStack";

/**
* The address where handler registration and un-registration messages are sent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public IEventBus publish(String address, Object message, String tag, Map<String,

final String sendStack = sw.toString();
Map<String, String> headersWithStack = newHashMap(message.headers());
headersWithStack.put("sendStack", sendStack);
headersWithStack.put(SEND_STACK_HEADER, sendStack);
message.headers = Map.copyOf(headersWithStack);

} catch (IOException unexpected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
import com.b2international.snowowl.snomed.datastore.converter.SnomedReferenceSetMemberConverter;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument;
import com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.common.collect.*;

/**
* @since 4.5
Expand All @@ -53,6 +51,16 @@ public final class SnomedRefSetMemberSearchRequest extends SnomedSearchRequest<S

private static final long serialVersionUID = 1L;

// Requesting the "value" field should load "booleanValue", "decimalValue", "integerValue", "stringValue" and "dataType" instead
private static final Multimap<String, String> REPLACE_VALUE_FIELD = ImmutableMultimap.<String, String>builder()
.putAll(SnomedRf2Headers.FIELD_VALUE,
SnomedRefSetMemberIndexEntry.Fields.BOOLEAN_VALUE,
SnomedRefSetMemberIndexEntry.Fields.DECIMAL_VALUE,
SnomedRefSetMemberIndexEntry.Fields.INTEGER_VALUE,
SnomedRefSetMemberIndexEntry.Fields.STRING_VALUE,
SnomedRefSetMemberIndexEntry.Fields.DATA_TYPE)
.build();

private static final SortedMap<String, SnomedRefsetMemberFieldQueryHandler<?>> SUPPORTED_MEMBER_FIELDS = ImmutableSortedMap.<String, SnomedRefsetMemberFieldQueryHandler<?>>naturalOrder()
// String types, ECL support
.put(SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, new SnomedRefsetMemberFieldQueryHandler<>(String.class, SnomedRefSetMemberIndexEntry.Expressions::referencedComponentIds, true))
Expand Down Expand Up @@ -147,6 +155,11 @@ protected Class<SnomedRefSetMemberIndexEntry> getDocumentType() {
return SnomedRefSetMemberIndexEntry.class;
}

@Override
protected Multimap<String, String> collectFieldsToLoadReplacements() {
return REPLACE_VALUE_FIELD;
}

@Override
protected Expression prepareQuery(BranchContext context) {
final Collection<String> referencedComponentIds = getCollection(OptionKey.REFERENCED_COMPONENT, String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
*/
final class SnomedRelationshipSearchRequest extends SnomedComponentSearchRequest<SnomedRelationships, SnomedRelationshipIndexEntry> {

// Requesting the "value" field should load "numericValue", "stringValue" and "valueType" instead
private static final Multimap<String, String> REPLACE_VALUE_FIELD = ImmutableMultimap.<String, String>builder()
.putAll(SnomedRelationship.Fields.VALUE, SnomedRelationshipIndexEntry.Fields.NUMERIC_VALUE, SnomedRelationshipIndexEntry.Fields.STRING_VALUE, SnomedRelationshipIndexEntry.Fields.VALUE_TYPE)
.putAll(SnomedRelationship.Fields.VALUE,
SnomedRelationshipIndexEntry.Fields.NUMERIC_VALUE,
SnomedRelationshipIndexEntry.Fields.STRING_VALUE,
SnomedRelationshipIndexEntry.Fields.VALUE_TYPE)
.build();

enum OptionKey {
Expand Down

0 comments on commit ba1b564

Please sign in to comment.