Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dsf-bpe/dsf-bpe-process-api-v1-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<executions>
<execution>
<goals>
<!-- for surefire javaagent config -->
<goal>properties</goal>
</goals>
</execution>
Expand Down
13 changes: 13 additions & 0 deletions dsf-bpe/dsf-bpe-process-api-v2-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<!-- for surefire javaagent config -->
<goal>properties</goal>
</goals>
</execution>
<execution>
<id>copy-api-v2-dependencies-to-docker</id>
<phase>pre-integration-test</phase>
Expand Down Expand Up @@ -289,6 +295,13 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:${org.mockito:mockito-core:jar}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
Expand Down
1 change: 1 addition & 0 deletions dsf-bpe/dsf-bpe-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
<executions>
<execution>
<goals>
<!-- for surefire javaagent config -->
<goal>properties</goal>
</goals>
</execution>
Expand Down
1 change: 1 addition & 0 deletions dsf-docker-dev-setup-3dic-ttp/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ services:
--https-certificate-key-file=/run/secrets/keycloak.key.plain
--spi-truststore-file-file=/run/secrets/keycloak_trust_store.jks
--spi-truststore-file-password=password
--features-disabled=twitter-broker,identity-brokering-api

forward-proxy:
build: ./forward-proxy
Expand Down
1 change: 1 addition & 0 deletions dsf-fhir/dsf-fhir-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
<executions>
<execution>
<goals>
<!-- for surefire javaagent config -->
<goal>properties</goal>
</goals>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
*/
package dev.dsf.fhir.dao.command;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;

import javax.sql.DataSource;

import org.hl7.fhir.r4.model.Binary;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.BundleEntryResponseComponent;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,25 +40,119 @@ abstract class AbstractCommandList
{
private static final Logger audit = LoggerFactory.getLogger("dsf-audit-logger");

public static final class CommandResult
{
private final Command command;

private BundleEntryComponent result;
private Exception exception;

public CommandResult(Command command)
{
this.command = command;
}

public Command getCommand()
{
return command;
}

public void setResult(BundleEntryComponent result)
{
Objects.requireNonNull(result, "result");
if (hasException())
throw new IllegalStateException("Exception set");

this.result = result;
}

public BundleEntryComponent getResult()
{
return result;
}

public boolean hasResult()
{
return result != null;
}

public void setException(Exception exception)
{
Objects.requireNonNull(exception, "exception");
if (hasException())
throw new IllegalStateException("Exception set");

this.exception = exception;
}

public void addSuppressedException(Throwable exception)
{
Objects.requireNonNull(exception, "exception");
if (!hasException())
throw new IllegalStateException("Exception not set");

this.exception.addSuppressed(exception);
}

public Exception getException()
{
return exception;
}

public boolean hasException()
{
return exception != null;
}

public void convertExceptionToResult(Function<Exception, Exception> internalServerErrorConverter)
{
if (hasException())
{
result = toEntry(exception, internalServerErrorConverter);
exception = null;
}
}

private BundleEntryComponent toEntry(Exception exception,
Function<Exception, Exception> internalServerErrorConverter)
{
BundleEntryComponent entry = new BundleEntryComponent();
BundleEntryResponseComponent response = entry.getResponse();

if (!(exception instanceof WebApplicationException w)
|| !(w.getResponse().getEntity() instanceof OperationOutcome))
{
exception = internalServerErrorConverter.apply(exception);
}

Response httpResponse = ((WebApplicationException) exception).getResponse();
response.setStatus(httpResponse.getStatusInfo().getStatusCode() + " "
+ httpResponse.getStatusInfo().getReasonPhrase());
response.setOutcome((OperationOutcome) httpResponse.getEntity());

return entry;
}
}

protected final DataSource dataSource;
protected final DataSource permanentDeleteDataSource;
protected final String dbUsersGroup;
protected final ExceptionHandler exceptionHandler;

protected final List<Command> commands = new ArrayList<>();
protected final List<CommandResult> commands;
protected final boolean hasModifyingCommands;
protected final boolean hasBinaryModifyingCommands;

protected AbstractCommandList(DataSource dataSource, DataSource permanentDeleteDataSource, String dbUsersGroup,
ExceptionHandler exceptionHandler, List<? extends Command> commands)
ExceptionHandler exceptionHandler, List<? extends Command> commands, Comparator<Command> sortOrder)
{
this.dataSource = dataSource;
this.permanentDeleteDataSource = permanentDeleteDataSource;
this.dbUsersGroup = dbUsersGroup;
this.exceptionHandler = exceptionHandler;

if (commands != null)
this.commands.addAll(commands);
this.commands = commands == null ? List.of()
: commands.stream().sorted(sortOrder).map(CommandResult::new).toList();

hasModifyingCommands = hasModifyingCommands(commands);
hasBinaryModifyingCommands = hasModifyingCommands && hasBinaryModifyingCommands(commands);
Expand All @@ -72,8 +169,19 @@ private static boolean hasBinaryModifyingCommands(List<? extends Command> comman
&& Binary.class.getAnnotation(ResourceDef.class).name().equals(m.getResourceTypeName()));
}

protected void auditLogResult(CommandResult commandResult)
{
if (commandResult.hasException())
throw new IllegalArgumentException("CommandResult has exception");

auditLogResult(commandResult.getCommand(), commandResult.getResult());
}

protected void auditLogResult(Command command, BundleEntryComponent result)
{
Objects.requireNonNull(command, "command");
Objects.requireNonNull(result, "result");

String resultOutcome = failed(result) ? "failed" : "successful";

if (command instanceof DeleteCommand)
Expand Down Expand Up @@ -129,7 +237,7 @@ else if (command instanceof ReadCommand r)

private boolean failed(BundleEntryComponent result)
{
if (result != null && result.hasResponse() && result.getResponse().hasStatus())
if (result.hasResponse() && result.getResponse().hasStatus())
{
String status = result.getResponse().getStatus();
if (status.length() >= 3 && status.matches("[0-9]{3}.*"))
Expand All @@ -140,24 +248,5 @@ private boolean failed(BundleEntryComponent result)
return false;
}

protected BundleEntryComponent toEntry(Exception exception)
{
var entry = new BundleEntryComponent();
var response = entry.getResponse();

if (!(exception instanceof WebApplicationException w)
|| !(w.getResponse().getEntity() instanceof OperationOutcome))
{
exception = internalServerError(exception);
}

Response httpResponse = ((WebApplicationException) exception).getResponse();
response.setStatus(
httpResponse.getStatusInfo().getStatusCode() + " " + httpResponse.getStatusInfo().getReasonPhrase());
response.setOutcome((OperationOutcome) httpResponse.getEntity());

return entry;
}

protected abstract Exception internalServerError(Exception exception);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import dev.dsf.fhir.prefer.PreferReturnType;
import dev.dsf.fhir.service.ReferenceExtractor;
import dev.dsf.fhir.service.ReferenceResolver;
import dev.dsf.fhir.validation.ValidationRules;

public abstract class AbstractCommandWithResource<R extends Resource, D extends ResourceDao<R>> extends AbstractCommand
implements Command
Expand All @@ -35,12 +36,13 @@ public abstract class AbstractCommandWithResource<R extends Resource, D extends
protected final D dao;
protected final ExceptionHandler exceptionHandler;
protected final ParameterConverter parameterConverter;
protected final ValidationRules validationRules;
protected final ReferencesHelper<R> referencesHelper;

public AbstractCommandWithResource(int transactionPriority, int index, Identity identity,
PreferReturnType returnType, Bundle bundle, BundleEntryComponent entry, String serverBase,
AuthorizationHelper authorizationHelper, R resource, D dao, ExceptionHandler exceptionHandler,
ParameterConverter parameterConverter, ResponseGenerator responseGenerator,
ParameterConverter parameterConverter, ValidationRules validationRules, ResponseGenerator responseGenerator,
ReferenceExtractor referenceExtractor, ReferenceResolver referenceResolver)
{
super(transactionPriority, index, identity, returnType, bundle, entry, serverBase, authorizationHelper);
Expand All @@ -49,6 +51,7 @@ public AbstractCommandWithResource(int transactionPriority, int index, Identity
this.dao = dao;
this.exceptionHandler = exceptionHandler;
this.parameterConverter = parameterConverter;
this.validationRules = validationRules;

referencesHelper = new ReferencesHelperImpl<>(index, resource, serverBase, referenceExtractor,
referenceResolver, responseGenerator);
Expand Down
Loading
Loading