-
Notifications
You must be signed in to change notification settings - Fork 15
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
Feature/hcat #1591
Merged
Merged
Feature/hcat #1591
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2d06e55
Added 'Reference Assessment' tab in admin project settings, and stub …
jack-brinkman 3a361c6
Added reference & assessment survey selection dropdowns to project admin
jack-brinkman 8e9ba99
Fixed reference activity retrieval in requestRecords endpoint
jack-brinkman 2e84938
Updated gradle.properties to change biocollectVersion
jack-brinkman ea531bc
Added queryParams
jack-brinkman 0f55923
First-pass non functional image assessment view
jack-brinkman d34caef
First-pass interactive record requesting UI
jack-brinkman 42d9259
Moved the requestAssessmentRecords controller view rendering from hub…
jack-brinkman 04f8462
Removed bespoke implementation for assessment record request view, ad…
jack-brinkman 9bb087b
First-pass working implementation of assessment record creation
jack-brinkman 71732c1
Further refactoring to record creation process
jack-brinkman 72c98cc
Fixed image uploading for assessment records, switched knockout-core …
jack-brinkman 708c463
Included de-identify flag in record creation
jack-brinkman 85734f6
Removed bespoke refAssess configuration from application.groovy, fixe…
jack-brinkman 69b7de1
Fixed user hub admin check for static page saving
jack-brinkman cb84903
Switched to /ws/search endpoint for reference activities search
jack-brinkman 2b2c8f3
Added additional data & documents check for reference records
jack-brinkman f40a30f
Fixed serverURL reference in image path generation
jack-brinkman eb0f3b4
Fixed baseUrl variable reference
jack-brinkman b251cfe
Added 'Hide Add new record button' in hub configuration
jack-brinkman 4957f7c
Revert small changes for parity with develop
jack-brinkman ec5e42a
Removed pAssessmentActivitiesVM initialisation (no longer used)
jack-brinkman ef340df
Merge branch 'develop' into feature/hcat
jack-brinkman 343aef2
Merge branch 'develop' into feature/hcat
temi df7e33b
6.8-REFASSESS-SNAPSHOT
temi 242bb11
Refactored config retrieval
jack-brinkman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
grails-app/controllers/au/org/ala/biocollect/ReferenceAssessmentController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package au.org.ala.biocollect | ||
|
||
import au.org.ala.biocollect.merit.* | ||
import grails.converters.JSON | ||
import grails.web.servlet.mvc.GrailsParameterMap | ||
|
||
import java.time.Instant | ||
|
||
class ReferenceAssessmentController { | ||
UserService userService | ||
ProjectActivityService projectActivityService | ||
ActivityService activityService | ||
|
||
|
||
private def createAssessmentRecordFromReference(Object referenceActivity, Object assessProjectActivity, boolean deIdentify) { | ||
def refDoc = referenceActivity.documents[0] | ||
|
||
def baseUrl = '' | ||
if (!refDoc["url"].startsWith('http')) { | ||
baseUrl = grailsApplication.config.grails.serverURL | ||
} | ||
|
||
def assessPhoto = [ | ||
licence: refDoc["licence"], | ||
notes: refDoc["notes"], | ||
filesize: refDoc["filesize"], | ||
staged: true, | ||
url: baseUrl + refDoc["url"], | ||
filename: refDoc["filename"], | ||
attribution: referenceActivity.outputs[0].data["imageAttribution"], | ||
name: refDoc["name"], | ||
documentId: '', | ||
contentType: refDoc["contentType"], | ||
dateTaken: refDoc["dateTaken"], | ||
formattedSize: refDoc["formattedSize"], | ||
thumbnailUrl: baseUrl + refDoc["thumbnailUrl"], | ||
status: "active" | ||
] | ||
|
||
def assessActivity = [ | ||
outputs: [ | ||
[ | ||
outputId: "", | ||
outputNotCompleted: false, | ||
data: [ | ||
recordedBy: userService.getCurrentUserDisplayName(), | ||
upperConditionBound: "0", | ||
lowerConditionBound: "0", | ||
overallConditionBestEstimate: "0", | ||
mvgGroup: referenceActivity.outputs[0].data.vegetationStructureGroup, | ||
huchinsonGroup: referenceActivity.outputs[0].data.huchinsonGroup, | ||
sitePhoto: [assessPhoto], | ||
deIdentify: deIdentify ? "Yes" : "No" | ||
], | ||
name: assessProjectActivity["pActivityFormName"] | ||
] | ||
], | ||
projectActivityId: assessProjectActivity["projectActivityId"], | ||
userId: userService.getCurrentUserId(), | ||
projectStage: "", | ||
embargoed: false, | ||
type: assessProjectActivity["pActivityFormName"], | ||
projectId: assessProjectActivity["projectId"], | ||
mainTheme: "" | ||
] | ||
|
||
// Create the new assessment activity record | ||
activityService.update("", assessActivity) | ||
|
||
// Update the numTimesReferenced field on the reference record | ||
referenceActivity.outputs[0].data.numTimesReferenced = | ||
referenceActivity.outputs[0].data.numTimesReferenced as Integer + 1 | ||
activityService.update(referenceActivity.activityId, referenceActivity) | ||
|
||
// Return the assessment activity | ||
assessActivity | ||
} | ||
|
||
def requestRecords() { | ||
def config = grailsApplication.config.refAssess | ||
def body = request.JSON | ||
def result | ||
|
||
// Ensure BioCollect is configured for reference assessment projects | ||
if (!config) { | ||
response.status = 500 | ||
result = [message: 'The application is not configured for reference assessment projects'] | ||
render result as JSON | ||
return | ||
} | ||
|
||
// Ensure the body of the request contains the required fields | ||
if (!body['vegetationStructureGroups'] || !body['climateGroups'] || !body.keySet().contains('deIdentify')) { | ||
response.status = 400 | ||
result = [message: 'Please ensure the assessment record request contains all relevant fields'] | ||
render result as JSON | ||
return | ||
} | ||
|
||
// Ensure the user is authenticated | ||
if (!userService.getCurrentUserId()) { | ||
response.status = 403 | ||
result = [message: 'User is not authenticated'] | ||
render result as JSON | ||
return | ||
} | ||
|
||
// Get the activity records for the reference survey | ||
def refActivitiesSearch = activityService.search([ | ||
projectActivityId: config.reference.projectActivityId | ||
]) | ||
def refActivities = refActivitiesSearch.resp.activities | ||
def maxRecordsToCreate = config.assessment.maxRecordsToCreate as Integer | ||
|
||
// Ensure the reference records exist | ||
def numRefActivities = refActivities?.size() | ||
if (numRefActivities == 0) { | ||
response.status = 404 | ||
result = [message: 'No reference records found in reference survey'] | ||
render result as JSON | ||
return | ||
} | ||
|
||
// Filter out any records without data or documents | ||
refActivities = refActivities.findAll { | ||
it.outputs[0].keySet().contains('data') && | ||
it.documents.size() > 0 | ||
} | ||
|
||
// Filter out reference activities by the supplied vegetation structure groups & climate groups | ||
refActivities = refActivities.findAll { | ||
body["vegetationStructureGroups"].contains(it.outputs[0].data["vegetationStructureGroup"]) && | ||
body["climateGroups"].contains(it.outputs[0].data["huchinsonGroup"]) | ||
} | ||
|
||
// Split & sort the reference activities into: | ||
// Priority records (assessed <= 3 times), prioritising records assessed the MOST | ||
// Other records (assessed > 3 times), prioritising records assessed the LEAST | ||
|
||
def priorityRecords = refActivities | ||
.findAll { it.outputs[0].data.numTimesReferenced as Integer <= 3 } | ||
.sort{ -(it.outputs[0].data.numTimesReferenced as Integer) } | ||
def otherRecords = refActivities | ||
.findAll { it.outputs[0].data.numTimesReferenced as Integer > 3 } | ||
.sort{ it.outputs[0].data.numTimesReferenced as Integer } | ||
|
||
// Combine the two lists | ||
refActivities = priorityRecords + otherRecords | ||
|
||
// Ensure there are reference records after filtering | ||
if (refActivities.size() == 0) { | ||
response.status = 400 | ||
result = [message: "No reference images matching your criteria could be found."] | ||
render result as JSON | ||
return | ||
} | ||
|
||
def assessProjectActivity = projectActivityService.get(config.assessment.projectActivityId) | ||
def assessActivities = [] | ||
for ( | ||
int projectIndex = 0; | ||
projectIndex < Math.min(maxRecordsToCreate, refActivities.size()); | ||
projectIndex++ | ||
) { | ||
assessActivities.push( | ||
createAssessmentRecordFromReference( | ||
refActivities[projectIndex], | ||
assessProjectActivity, | ||
body['deIdentify'] | ||
) | ||
) | ||
} | ||
|
||
response.status = 200 | ||
result = [message: "Found ${assessActivities.size()} images for assessment, please standby..."] | ||
render result as JSON | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,6 @@ | |
</div> | ||
</g:if> | ||
</g:if> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Use
getProperty
to get config items.grailsApplication.config.getProperty("refAssess", Map)
. A few instances of this are in the codeThere 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.
Fixed