-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue-3455 - adding resource info from location when return preferenc… #4130
base: main
Are you sure you want to change the base?
Changes from 1 commit
ea3a2ad
6370db6
9490873
be16ef0
41763c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -33,6 +33,7 @@ | |||||
import org.linuxforhealth.fhir.config.FHIRConfiguration; | ||||||
import org.linuxforhealth.fhir.config.FHIRRequestContext; | ||||||
import org.linuxforhealth.fhir.core.FHIRUtilities; | ||||||
import org.linuxforhealth.fhir.core.HTTPReturnPreference; | ||||||
import org.linuxforhealth.fhir.core.util.handler.IPHandler; | ||||||
import org.linuxforhealth.fhir.model.resource.Basic; | ||||||
import org.linuxforhealth.fhir.model.resource.Bundle; | ||||||
|
@@ -395,7 +396,7 @@ private static void logBundleBatch(AuditLogService auditLogSvc, HttpServletReque | |||||
|
||||||
AuditLogEntry entry = initLogEntry(AuditLogEventType.FHIR_BUNDLE); | ||||||
|
||||||
populateAuditLogEntry(entry, request, responseEntry.getResource(), startTime, endTime, responseStatus); | ||||||
populateBundleAuditLogEntry(entry, responseEntry, request, responseEntry.getResource(), startTime, endTime, responseStatus); | ||||||
if (requestEntry.getRequest() != null && requestEntry.getRequest().getMethod() != null) { | ||||||
boolean operation = requestEntry.getRequest().getUrl().getValue().contains("$") | ||||||
|| requestEntry.getRequest().getUrl().getValue().contains("/%24"); | ||||||
|
@@ -431,7 +432,6 @@ private static void logBundleBatch(AuditLogService auditLogSvc, HttpServletReque | |||||
// Only for BATCH we want to override the REQUEST URI and Status Code | ||||||
StringBuilder builder = new StringBuilder(); | ||||||
builder.append(request.getRequestURI()) | ||||||
.append("/") | ||||||
.append(loc); | ||||||
entry.getContext() | ||||||
.setApiParameters( | ||||||
|
@@ -479,7 +479,7 @@ private static void logBundleTransaction(AuditLogService auditLogSvc, HttpServle | |||||
for (Entry bundleEntry : responseBundle.getEntry()) { | ||||||
Bundle.Entry requestEntry = iter.next(); | ||||||
entry = initLogEntry(AuditLogEventType.FHIR_BUNDLE); | ||||||
populateAuditLogEntry(entry, request, bundleEntry.getResource(), startTime, endTime, responseStatus); | ||||||
populateBundleAuditLogEntry(entry, bundleEntry, request, bundleEntry.getResource(), startTime, endTime, responseStatus); | ||||||
entry.setDescription("FHIR Bundle Transaction request"); | ||||||
entry.getContext().setAction(selectActionForBundleEntry(requestEntry)); | ||||||
auditLogSvc.logEntry(entry); | ||||||
|
@@ -746,6 +746,64 @@ protected static AuditLogEntry populateAuditLogEntry(AuditLogEntry entry, HttpSe | |||||
return entry; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Populates the passed audit log entry for Bundle entry. | ||||||
* This method will populate the resource id, resource type and version id from the | ||||||
* Bundle response entry location when the return preference is "OperationOutcome". | ||||||
* When the return preference is "representation" the populateAuditLogEntry method will | ||||||
* populate the resource id, resource type and version id. | ||||||
* @param entry | ||||||
* The AuditLogEntry to be populated. | ||||||
* @param responseEntry | ||||||
* The Bundle response entry. | ||||||
* @param request | ||||||
* The HttpServletRequest representation of the REST request. | ||||||
* @param resource | ||||||
* The Resource object. | ||||||
* @param startTime | ||||||
* The start time of the request execution. | ||||||
* @param endTime | ||||||
* The end time of the request execution. | ||||||
* @param responseStatus | ||||||
* The response status. | ||||||
* @return AuditLogEntry - an initialized audit log entry. | ||||||
*/ | ||||||
protected static AuditLogEntry populateBundleAuditLogEntry(AuditLogEntry entry, Bundle.Entry responseEntry, HttpServletRequest request, Resource resource, | ||||||
Date startTime, Date endTime, Response.Status responseStatus) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor formatting: for method signatures that span multiple lines we double-indent to offset from the first line of the implementation
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been fixed. |
||||||
final String METHODNAME = "populateBundleAuditLogEntry"; | ||||||
log.entering(CLASSNAME, METHODNAME); | ||||||
|
||||||
// call populateAuditLogEntry to populate common attributes to all rest | ||||||
populateAuditLogEntry(entry, request, resource, startTime, endTime, responseStatus); | ||||||
|
||||||
// Populate the resource id, resource type and version id from the | ||||||
// Bundle response entry location when the return preference is "OperationOutcome". | ||||||
if (HTTPReturnPreference.OPERATION_OUTCOME.equals(FHIRRequestContext.get().getReturnPreference())) { | ||||||
if (responseEntry.getResponse() != null && responseEntry.getResponse().getLocation() != null) { | ||||||
String location = responseEntry.getResponse().getLocation().getValue(); | ||||||
String[] parts = location.split("/"); | ||||||
String resourceType = null; | ||||||
String id = null; | ||||||
String versionId = null; | ||||||
if (parts.length == 10) { | ||||||
resourceType = parts[6]; | ||||||
id = parts[7]; | ||||||
versionId = parts[9]; | ||||||
} else if (parts.length == 4) { | ||||||
resourceType = parts[0]; | ||||||
id = parts[1]; | ||||||
versionId = parts[3]; | ||||||
} | ||||||
lmsurpre marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
entry.getContext().setData(Data.builder().resourceType(resourceType).build()); | ||||||
entry.getContext().getData().setId(id); | ||||||
entry.getContext().getData().setVersionId(versionId); | ||||||
} | ||||||
} | ||||||
|
||||||
log.exiting(CLASSNAME, METHODNAME); | ||||||
return entry; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Builds and returns an AuditLogEntry with the minimum required fields populated. | ||||||
* | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the original test had these commented out too, but it makes me wonder why...