Skip to content

Commit

Permalink
Expand tags that can disable protcols #1009
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Sep 11, 2024
1 parent 2051935 commit 1ca7946
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
32 changes: 10 additions & 22 deletions grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ class ParatooService {
static final String PARATOO_PROTOCOL_FORM_TYPE = 'EMSA'
static final String PARATOO_PROTOCOLS_KEY = 'paratoo.protocols'
static final String PARATOO_PROTOCOL_DATA_MAPPING_KEY = 'paratoo.surveyData.mapping'
static final String PROGRAM_CONFIG_PARATOO_ITEM = 'supportsParatoo'
static final String PARATOO_APP_NAME = "Monitor"
static final String MONITOR_AUTH_HEADER = "Authorization"
static final List DEFAULT_MODULES =
['Plot Selection and Layout', 'Plot Description', 'Opportune']
static final List ADMIN_ONLY_PROTOCOLS = ['Plot Selection']
static final String INTERVENTION_PROTOCOL_TAG = 'intervention'
static final String DEVELOPMENT_PROTOCOL_TAG = 'development'
static final String PARATOO_UNIT_FIELD_NAME = "x-paratoo-unit"
static final String PARATOO_HINT = "x-paratoo-hint"
static final String PARATOO_MODEL_REF = "x-model-ref"
Expand Down Expand Up @@ -108,16 +106,15 @@ class ParatooService {

List monitoringProtocolCategories = project.getMonitoringProtocolCategories()
if (monitoringProtocolCategories) {
List categoriesWithDefaults = monitoringProtocolCategories + DEFAULT_MODULES
List categoriesWithDefaults = monitoringProtocolCategories + project.getDefaultModules()
protocols += findProtocolsByCategories(categoriesWithDefaults.unique())
if (!project.isParaooAdmin()) {
protocols = protocols.findAll { !(it.name in ADMIN_ONLY_PROTOCOLS) }
}
// Temporarily exclude intervention protocols until they are ready
if (grailsApplication.config.getProperty('paratoo.excludeInterventionProtocols', Boolean.class, true)) {
protocols = protocols.findAll { !(INTERVENTION_PROTOCOL_TAG in it.tags) }
}

// Exclude protocols tagged as excluded
List excludedTags = grailsApplication.config.getProperty('paratoo.excludedTags', List.class, [INTERVENTION_PROTOCOL_TAG, DEVELOPMENT_PROTOCOL_TAG])
protocols = protocols.findAll { !(it.tags?.any{ String tag -> tag in excludedTags}) }
}
protocols
}
Expand Down Expand Up @@ -149,24 +146,13 @@ class ParatooService {

List projects = Project.findAllByProjectIdInListAndStatus(new ArrayList(projectAccessLevels.keySet()), Status.ACTIVE)

// Filter projects that aren't in a program configured to support paratoo or don't have permission
projects = projects.findAll { Project project ->
if (!project.programId) {
return false
}

Program program = Program.findByProgramId(project.programId)
Map config = program.getInheritedConfig()
// The Monitor/Paratoo app is "write only" (i.e. there is no view mode for the data), so we don't support
// the read only role
config?.get(PROGRAM_CONFIG_PARATOO_ITEM) && projectAccessLevels[project.projectId] && projectAccessLevels[project.projectId] != AccessLevel.readOnly
}

List paratooProjects = projects.collect { Project project ->
List<Site> sites = siteService.sitesForProjectWithTypes(project.projectId, [Site.TYPE_PROJECT_AREA, Site.TYPE_SURVEY_AREA])
AccessLevel accessLevel = projectAccessLevels[project.projectId]
mapProject(project, accessLevel, sites)
}

paratooProjects = paratooProjects.findAll { it.isParatooEnabled()}
paratooProjects

}
Expand Down Expand Up @@ -829,6 +815,7 @@ class ParatooService {
// sites from this call
List<Site> plotSelections = sites.findAll{it.externalIds?.find{externalId -> externalId.idType == ExternalId.IdType.MONITOR_PLOT_SELECTION_GUID}}

Program program = Program.findByProgramId(project.programId)
Map attributes = [
id:project.projectId,
name:project.name,
Expand All @@ -837,7 +824,8 @@ class ParatooService {
project:project,
projectArea: projectAreaGeoJson,
projectAreaSite: projectArea,
plots : plotSelections]
plots : plotSelections,
program: program]
new ParatooProject(attributes)

}
Expand Down
31 changes: 30 additions & 1 deletion src/main/groovy/au/org/ala/ecodata/paratoo/ParatooProject.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package au.org.ala.ecodata.paratoo

import au.org.ala.ecodata.AccessLevel
import au.org.ala.ecodata.ActivityForm
import au.org.ala.ecodata.Program
import au.org.ala.ecodata.Project
import au.org.ala.ecodata.Service
import au.org.ala.ecodata.Site
Expand All @@ -10,7 +11,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
/** DTO for a response to the paratoo app */
@JsonIgnoreProperties(['metaClass', 'errors', 'expandoMetaClass'])
class ParatooProject {

static final String PROGRAM_CONFIG_PARATOO_ITEM = 'supportsParatoo'
static final String PARATOO_DEFAULT_MODULES = 'paratooDefaultModules'
static final List DEFAULT_MODULES =
['Plot Selection and Layout', 'Plot Description', 'Opportune']
static String EDITOR = 'authenticated'
static String ADMIN = 'project_admin'
static String PUBLIC = 'public'
Expand All @@ -25,6 +29,31 @@ class ParatooProject {
Map projectArea = null
Site projectAreaSite = null
List<Site> plots = null
Program program

private Map getConfig() {
Map config = program?.getInheritedConfig() ?: [:]
// Support per-project overrides of config
if (project.config) {
config.putAll(project.config)
}
config
}

List<String> getDefaultModules() {
Map config = getConfig()
List modules = DEFAULT_MODULES
if (config.hasProperty(PARATOO_DEFAULT_MODULES)) {
modules = getConfig()?.get(PARATOO_DEFAULT_MODULES)
}
modules
}

boolean isParatooEnabled() {
// The Monitor/Paratoo app is "write only" (i.e. there is no view mode for the data), so we don't support
// the read only role
getConfig()?.get(PROGRAM_CONFIG_PARATOO_ITEM) && accessLevel && accessLevel != AccessLevel.readOnly
}

List<Map> getDataSets() {
project?.custom?.dataSets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
plot.save(failOnError: true, flush: true)
siteService.sitesForProjectWithTypes('p1', [Site.TYPE_PROJECT_AREA, Site.TYPE_SURVEY_AREA]) >> [projectArea, plot]

Program program = new Program(programId: "prog1", name: "A program", config: [(ParatooService.PROGRAM_CONFIG_PARATOO_ITEM): true])
Program program = new Program(programId: "prog1", name: "A program", config: [(ParatooProject.PROGRAM_CONFIG_PARATOO_ITEM): true])
program.save(failOnError: true, flush: true)

Service service = new Service(name: "S1", serviceId: '1', legacyId: 1, outputs: [new ServiceForm(externalId: "guid-2", formName: "aParatooForm", sectionName: null)])
Expand Down

0 comments on commit 1ca7946

Please sign in to comment.