Skip to content

Commit

Permalink
Merge pull request #959 from AtlasOfLivingAustralia/feature/issue958
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala authored May 22, 2024
2 parents 4f3466a + 81a2cb7 commit be58424
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
3 changes: 2 additions & 1 deletion grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,9 @@ class ParatooService {
ArrayDeque<String> modelVisitStack = new ArrayDeque<>()
documentation = deepCopy(documentation)
Map components = deepCopy(getComponents(documentation))
boolean record = config.createSpeciesRecord

Map template = [dataModel: [], viewModel: [], modelName: capitalizeModelName(protocol.attributes.name), record: true, relationships: [ecodata: [:], apiOutput: [:]]]
Map template = [dataModel: [], viewModel: [], modelName: capitalizeModelName(protocol.attributes.name), record: record, relationships: [ecodata: [:], apiOutput: [:]]]
Map properties = deepCopy(findProtocolEndpointDefinition(protocol, documentation))
if (properties == null) {
throw new NotFoundException("No protocol endpoint found for ${protocol.attributes.endpointPrefix}/bulk")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ParatooProtocolConfig {
String name
String apiEndpoint
boolean usesPlotLayout = true
boolean createSpeciesRecord = true
List tags
String geometryType = 'Polygon'

Expand Down
88 changes: 88 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,94 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
'guid-10' | AccessLevel.admin | false | false // Note guid-10 doesn't exist/isn't attached to the project.
}

def "buildTemplateForProtocol must switch record generation on or off" (createSpeciesRecord, expected) {
setup:
def documentation = [
components: [schemas: [:]],
paths: [
"opportunes/bulk": [
post: [
requestBody:
[
content: [
"application/json": [
schema: [
"properties": [
"data": [
"properties": [
"collections": [
"items": [
"properties": [
"surveyId": [
"properties": [
"projectId": [
"type": "string"
],
"protocol" : [
"properties": [
"id" : [
"type": "string"
],
"version": [
"type": "integer"
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
def config = new ParatooProtocolConfig(
"name" : "Opportune",
"usesPlotLayout": false,
"tags" : ["survey"],
"apiEndpoint" : "s1s",
"overrides" : [
"dataModel": null,
"viewModel": null
]
)

if (createSpeciesRecord != "DO NOT ADD" ) {
config.createSpeciesRecord = createSpeciesRecord
}

def protocol = [
attributes: [
endpointPrefix: "opportunes",
workflow: [
[modelName: 'plot-layout'],
[modelName: 'other-model']
]
]
]

when:
Map result = service.buildTemplateForProtocol(protocol, documentation, config)

then:
result.record == expected

where:
createSpeciesRecord | expected
true | true
false | false
null | false
"DO NOT ADD" | true
}

private Map getNormalDefinition() {
def input = """
{
Expand Down

0 comments on commit be58424

Please sign in to comment.