Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
history bundle url fix, html view url fix for resource url with version
Browse files Browse the repository at this point in the history
  • Loading branch information
hhund committed Jun 29, 2020
1 parent ee3ae1a commit 7ee1245
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,13 @@ private Optional<String> getResourceUrl(T t) throws MalformedURLException
else if (t instanceof Resource && t.getIdElement().getResourceType() != null
&& t.getIdElement().getIdPart() != null)
{
return Optional.of(String.format("%s/%s/%s", serverBaseProvider.getServerBase(),
t.getIdElement().getResourceType(), t.getIdElement().getIdPart()));
if (!uriInfo.getPath().contains("_history"))
return Optional.of(String.format("%s/%s/%s", serverBaseProvider.getServerBase(),
t.getIdElement().getResourceType(), t.getIdElement().getIdPart()));
else
return Optional.of(String.format("%s/%s/%s/_history/%s", serverBaseProvider.getServerBase(),
t.getIdElement().getResourceType(), t.getIdElement().getIdPart(),
t.getIdElement().getVersionIdPart()));
}
else
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@

public class HistoryServiceImpl implements HistoryService, InitializingBean
{
private final String serverBase;
private final int defaultPageCount;
private final ParameterConverter parameterConverter;
private final ExceptionHandler exceptionHandler;
private final ResponseGenerator responseGenerator;
private final HistoryDao historyDao;
private final HistoryUserFilterFactory historyUserFilterFactory;

public HistoryServiceImpl(int defaultPageCount, ParameterConverter parameterConverter,
public HistoryServiceImpl(String serverBase, int defaultPageCount, ParameterConverter parameterConverter,
ExceptionHandler exceptionHandler, ResponseGenerator responseGenerator, HistoryDao historyDao,
HistoryUserFilterFactory historyUserFilterFactory)
{
this.serverBase = serverBase;
this.defaultPageCount = defaultPageCount;
this.parameterConverter = parameterConverter;
this.exceptionHandler = exceptionHandler;
Expand All @@ -51,6 +53,7 @@ public HistoryServiceImpl(int defaultPageCount, ParameterConverter parameterConv
@Override
public void afterPropertiesSet() throws Exception
{
Objects.requireNonNull(serverBase, "serverBase");
Objects.requireNonNull(parameterConverter, "parameterConverter");
Objects.requireNonNull(exceptionHandler, "exceptionHandler");
Objects.requireNonNull(responseGenerator, "responseGenerator");
Expand Down Expand Up @@ -88,19 +91,26 @@ public Bundle getHistory(User user, UriInfo uri, HttpHeaders headers, Class<? ex
SinceParameter sinceParameter = new SinceParameter();
sinceParameter.configure(queryParameters);

String path = null;
History history;
if (resource == null && id == null)
history = exceptionHandler
.handleSqlException(() -> historyDao.readHistory(historyUserFilterFactory.getUserFilters(user),
pageAndCount, atParameter, sinceParameter));
else if (resource != null && id != null)
{
history = exceptionHandler.handleSqlException(() -> historyDao.readHistory(
historyUserFilterFactory.getUserFilter(user, resource), pageAndCount, atParameter, sinceParameter,
resource, parameterConverter.toUuid(getResourceTypeName(resource), id)));
path = resource.getAnnotation(ResourceDef.class).name();
}
else if (resource != null)
{
history = exceptionHandler.handleSqlException(
() -> historyDao.readHistory(historyUserFilterFactory.getUserFilter(user, resource), pageAndCount,
atParameter, sinceParameter, resource));
path = resource.getAnnotation(ResourceDef.class).name();
}
else
throw new WebApplicationException();

Expand All @@ -116,7 +126,13 @@ else if (resource != null)
String format = queryParameters.getFirst(SearchQuery.PARAMETER_FORMAT);
String pretty = queryParameters.getFirst(SearchQuery.PARAMETER_PRETTY);

UriBuilder bundleUri = uri.getAbsolutePathBuilder();
UriBuilder bundleUri = UriBuilder.fromPath(serverBase);
if (path != null)
bundleUri = bundleUri.path(path);
if (path != null && id != null)
bundleUri = bundleUri.path(id);

bundleUri = bundleUri.path("_history");
atParameter.modifyBundleUri(bundleUri);
sinceParameter.modifyBundleUri(bundleUri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
@Configuration
public class HistoryConfig
{
@Value("${org.highmed.dsf.fhir.serverBase}")
private String serverBase;

@Value("${org.highmed.dsf.fhir.defaultPageCount}")
private int defaultPageCount;

Expand All @@ -30,7 +33,7 @@ public HistoryUserFilterFactory historyUserFilterFactory()
@Bean
public HistoryService historyService()
{
return new HistoryServiceImpl(defaultPageCount, helperConfig.parameterConverter(),
return new HistoryServiceImpl(serverBase, defaultPageCount, helperConfig.parameterConverter(),
helperConfig.exceptionHandler(), helperConfig.responseGenerator(), daoConfig.historyDao(),
historyUserFilterFactory());
}
Expand Down

0 comments on commit 7ee1245

Please sign in to comment.