Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.subscription.channel.api.ChannelProducerSettings;
import ca.uhn.fhir.jpa.subscription.channel.subscription.IChannelNamer;
import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionLoader;
import ca.uhn.fhir.mdm.api.IMdmSettings;
import ca.uhn.fhir.mdm.api.MdmConstants;
import ca.uhn.fhir.mdm.log.Logs;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.util.HapiExtensions;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.BooleanType;
Expand Down Expand Up @@ -93,12 +94,24 @@ synchronized public void daoUpdateMdmSubscriptions() {
}

synchronized void updateIfNotPresent(IBaseResource theSubscription) {
try {
mySubscriptionDao.read(theSubscription.getIdElement(), SystemRequestDetails.forAllPartitions());
} catch (ResourceNotFoundException | ResourceGoneException e) {
SearchParameterMap searchParamMap = new SearchParameterMap();
searchParamMap.add(Subscription.SP_RES_ID, new TokenParam(theSubscription.getIdElement().getIdPart()));

// The reason we bother to search instead of reading is that reading a subscription that isn't there throws
// an error in the logs. To cut down on logged errors that might confuse clients, we search first.
IBundleProvider bundleProvider = mySubscriptionDao.search(searchParamMap, SystemRequestDetails.forAllPartitions());

if (bundleProvider.isEmpty()) {
ourLog.info("Creating subscription " + theSubscription.getIdElement());
mySubscriptionDao.update(theSubscription, SystemRequestDetails.forAllPartitions());
}

// try {
// mySubscriptionDao.read(theSubscription.getIdElement(), SystemRequestDetails.forAllPartitions());
// } catch (ResourceNotFoundException | ResourceGoneException e) {
// ourLog.info("Creating subscription " + theSubscription.getIdElement());
// mySubscriptionDao.update(theSubscription, SystemRequestDetails.forAllPartitions());
// }
}

private org.hl7.fhir.dstu3.model.Subscription buildMdmSubscriptionDstu3(String theId, String theCriteria) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import ca.uhn.test.util.LogbackCaptureTestExtension;
import ch.qos.logback.classic.Level;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -260,10 +259,6 @@ private void stubMatcherCall(String expectedQuery, IBaseResource theTargetResour

@Nested
public class MisconfigurationChecks {


// wipjv check for unsupported params during CdrAuthInterceptor scopes->perms translation.

/**
* in case an unsupported perm snuck through the front door.
* Each scope provides positive perm, so unsupported means we can't vote yes. Abstain.
Expand Down Expand Up @@ -321,7 +316,6 @@ public void noMatcherService_unsupportedPerm_noVerdict() {
}

}
// wipjv how to test the difference between patient/*.rs?code=foo and patient/Observation.rs?code=foo?
// We need the builder to set AppliesTypeEnum, and the use that to build the matcher expression.

private AuthorizationInterceptor.Verdict applyRuleToResource(IBaseResource theResource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import org.hamcrest.CustomTypeSafeMatcher;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
Expand Down Expand Up @@ -159,42 +157,11 @@ public static Matcher<ILoggingEvent> eventWithMessageContains(@Nonnull String th
return new LogbackEventMatcher(null, thePartialMessage);
}

/**
* A Hamcrest matcher for junit assertions.
* Matches on level and/or partial message.
*/
public static class LogbackEventMatcher extends CustomTypeSafeMatcher<ILoggingEvent> {
@Nullable
private final Level myLevel;
@Nullable
private final String myString;

public LogbackEventMatcher(@Nullable Level theLevel, @Nullable String thePartialString) {
this("log event", theLevel, thePartialString);
}

public LogbackEventMatcher(String description, @Nullable Level theLevel, @Nullable String thePartialString) {
super(makeDescription(description, theLevel, thePartialString));
myLevel = theLevel;
myString = thePartialString;
}
@Nonnull
private static String makeDescription(String description, Level theLevel, String thePartialString) {
String msg = description;
if (theLevel != null) {
msg = msg + " with level at least " + theLevel;
}
if (thePartialString != null) {
msg = msg + " containing string \"" + thePartialString + "\"";

}
return msg;
}

@Override
protected boolean matchesSafely(ILoggingEvent item) {
return (myLevel == null || item.getLevel().isGreaterOrEqual(myLevel)) &&
(myString == null || item.getFormattedMessage().contains(myString));
}
public static Matcher<ILoggingEvent> eventWithLevelAndMessageAndThrew(@Nonnull Level theLevel,
@Nonnull String thePartialMessage,
@Nonnull String theThrown)
{
return new LogbackEventMatcher(theLevel, thePartialMessage, theThrown);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ca.uhn.test.util;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import org.hamcrest.CustomTypeSafeMatcher;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* A Hamcrest matcher for junit assertions.
* Matches on level, partial message, and/or a portion of the message contained by a throwable, if present.
*/
public class LogbackEventMatcher extends CustomTypeSafeMatcher<ILoggingEvent> {
@Nullable
private final Level myLevel;
@Nullable
private final String myLogMessage;
@Nullable
private final String myThrownMessage;

public LogbackEventMatcher(@Nullable Level theLevel, @Nullable String thePartialString) {
this("log event", theLevel, thePartialString, null);
}

public LogbackEventMatcher(@Nullable Level theLevel, @Nullable String thePartialString, @Nullable String theThrownMessage) {
this("log event", theLevel, thePartialString, theThrownMessage);
}

private LogbackEventMatcher(String description, @Nullable Level theLevel,
@Nullable String thePartialString, @Nullable String theThrownMessage)
{
super(makeDescription(description, theLevel, thePartialString, theThrownMessage));
myLevel = theLevel;
myLogMessage = thePartialString;
myThrownMessage = theThrownMessage;
}

@Nonnull
private static String makeDescription(String description, Level theLevel, String thePartialString, String theThrownMessage) {
String msg = description;
if (theLevel != null) {
msg = msg + " with level at least " + theLevel;
}
if (thePartialString != null) {
msg = msg + " containing string \"" + thePartialString + "\"";

}
if (thePartialString != null) {
msg = msg + " and throwable with error message containing string \"" + theThrownMessage + "\"";

}
return msg;
}

@Override
protected boolean matchesSafely(ILoggingEvent item) {
return (myLevel == null || item.getLevel().isGreaterOrEqual(myLevel)) &&
(myLogMessage == null || item.getFormattedMessage().contains(myLogMessage)) &&
(myThrownMessage == null || item.getThrowableProxy() == null || item.getThrowableProxy().getMessage().contains(myThrownMessage));
}
}