diff --git a/grails-app/conf/application.groovy b/grails-app/conf/application.groovy index 81bf9480f..46115fef2 100644 --- a/grails-app/conf/application.groovy +++ b/grails-app/conf/application.groovy @@ -671,7 +671,7 @@ environments { ecodata.use.uuids = false app.external.model.dir = "./models/" grails.serverURL = "http://localhost:8080" - app.uploads.url = "${grails.serverURL}/document/download?filename=" + app.uploads.url = "/document/download/" app.elasticsearch.indexOnGormEvents = true app.elasticsearch.indexAllOnStartup = true diff --git a/grails-app/conf/data/mapping.json b/grails-app/conf/data/mapping.json index 83398842f..24d20c6f7 100644 --- a/grails-app/conf/data/mapping.json +++ b/grails-app/conf/data/mapping.json @@ -88,6 +88,17 @@ "dateCreatedSort" : { "type" : "keyword", "normalizer" : "case_insensitive_sort" }, + "serviceProviderName": { + "type" : "text", + "copy_to": ["organisationName","organisationFacet", "organisationSort"] + }, + "lastUpdated": { + "type" : "date", + "copy_to" : "lastUpdatedSort" + }, + "lastUpdatedSort" : { + "type" : "keyword", "normalizer" : "case_insensitive_sort" + }, "associatedOrgs": { "properties" : { "name" : { diff --git a/grails-app/controllers/au/org/ala/ecodata/ApiKeyInterceptor.groovy b/grails-app/controllers/au/org/ala/ecodata/ApiKeyInterceptor.groovy index 85814cc40..4226a2db0 100644 --- a/grails-app/controllers/au/org/ala/ecodata/ApiKeyInterceptor.groovy +++ b/grails-app/controllers/au/org/ala/ecodata/ApiKeyInterceptor.groovy @@ -41,7 +41,7 @@ class ApiKeyInterceptor { PreAuthorise pa = method.getAnnotation(PreAuthorise) ?: controllerClass.getAnnotation(PreAuthorise) if (pa.basicAuth()) { - au.org.ala.web.UserDetails user = userService.getUserFromJWT() + def user = userService.setUser() request.userId = user?.userId if(permissionService.isUserAlaAdmin(request.userId)) { /* Don't enforce check for ALA admin.*/ diff --git a/grails-app/controllers/au/org/ala/ecodata/AuditInterceptor.groovy b/grails-app/controllers/au/org/ala/ecodata/AuditInterceptor.groovy index 3ae4e7b00..d65ad317c 100644 --- a/grails-app/controllers/au/org/ala/ecodata/AuditInterceptor.groovy +++ b/grails-app/controllers/au/org/ala/ecodata/AuditInterceptor.groovy @@ -7,7 +7,7 @@ import grails.config.Config class AuditInterceptor implements GrailsConfigurationAware { int order = 100 // This needs to be after the @RequireApiKey interceptor which makes the userId available via the authService - String httpRequestHeaderForUserId + static String httpRequestHeaderForUserId UserService userService AuthService authService @@ -16,21 +16,7 @@ class AuditInterceptor implements GrailsConfigurationAware { } boolean before() { - // userId is set from either the request param userId or failing that it tries to get it from - // the UserPrincipal (assumes ecodata is being accessed directly via admin page) - def userId = authService.getUserId() ?: request.getHeader(httpRequestHeaderForUserId) - if (userId) { - def userDetails = userService.setCurrentUser(userId) - if (userDetails) { - // We set the current user details in the request scope because - // the 'afterView' hook can be called prior to the actual rendering (despite the name) - // and the thread local can get clobbered before it is actually required. - // Consumers who have access to the request can simply extract current user details - // from there rather than use the service. - request.setAttribute(UserDetails.REQUEST_USER_DETAILS_KEY, userDetails) - } - } - + userService.setUser() true } diff --git a/grails-app/controllers/au/org/ala/ecodata/ProjectActivityController.groovy b/grails-app/controllers/au/org/ala/ecodata/ProjectActivityController.groovy index a81b62b7a..d72577acb 100644 --- a/grails-app/controllers/au/org/ala/ecodata/ProjectActivityController.groovy +++ b/grails-app/controllers/au/org/ala/ecodata/ProjectActivityController.groovy @@ -52,7 +52,8 @@ class ProjectActivityController { } if (!result) { - result = [status: 404, text: 'Invalid id']; + render status: 404, text: [message: 'Invalid id', status: 404] as JSON + return } } diff --git a/grails-app/services/au/org/ala/ecodata/ElasticSearchService.groovy b/grails-app/services/au/org/ala/ecodata/ElasticSearchService.groovy index 7cc950c7d..a673f11bb 100644 --- a/grails-app/services/au/org/ala/ecodata/ElasticSearchService.groovy +++ b/grails-app/services/au/org/ala/ecodata/ElasticSearchService.groovy @@ -1129,7 +1129,7 @@ class ElasticSearchService { // MERIT project needs private sites to be indexed for faceting purposes but Biocollect does not require private sites. // Some Biocollect project have huge numbers of private sites. This will significantly hurt performance. // Hence the if condition. - if(projectMap.isMERIT){ + if (projectMap.isMERIT) { // Allow ESP sites to be hidden, even on the project explorer. Needs to be tided up a bit as MERIT sites were // already marked as private to avoid discovery via BioCollect @@ -1166,6 +1166,16 @@ class ElasticSearchService { // todo: Check if BioCollect requires all sites in `sites` property. If no, merge `projectArea` with `sites`. projectMap.projectArea = siteService.getSimpleProjectArea(projectMap.projectSiteId) projectMap.containsActivity = activityService.searchAndListActivityDomainObjects([projectId: projectMap.projectId], null, null, null, [max: 1, offset: 0])?.totalCount > 0 + projectMap.projectActivities = projectActivityService.getAllByProject(project.projectId).collect({ + [ + id: it.id, + projectId: it.projectId, + projectActivityId: it.projectActivityId, + name: it.name, + startDate: it.startDate, + endDate: it.endDate, + ] + }) } projectMap.sites?.each { site -> // Not useful for the search index and there is a bug right now that can result in invalid POI @@ -1660,6 +1670,17 @@ class ElasticSearchService { } break + case 'projectactivityrecords': + if (projectActivityId) { + if (userId && (permissionService.isUserAlaAdmin(userId) || permissionService.isUserAdminForProject(userId, projectId) || permissionService.isUserEditorForProject(userId, projectId))) { + forcedQuery = '(docType:activity AND projectActivity.projectActivityId:' + projectActivityId + ')' + } + else { + forcedQuery = '(docType:activity AND projectActivity.projectActivityId:' + projectActivityId + ' AND projectActivity.embargoed:false AND (verificationStatusFacet:approved OR verificationStatusFacet:\"not applicable\" OR (NOT _exists_:verificationStatus)))' + } + } + break + case 'myprojectrecords': if (projectId) { if (userId) { diff --git a/grails-app/services/au/org/ala/ecodata/UserService.groovy b/grails-app/services/au/org/ala/ecodata/UserService.groovy index bb841f529..515d1f806 100644 --- a/grails-app/services/au/org/ala/ecodata/UserService.groovy +++ b/grails-app/services/au/org/ala/ecodata/UserService.groovy @@ -213,4 +213,31 @@ class UserService { return null } } + + def setUser() { + String userId + GrailsWebRequest grailsWebRequest = GrailsWebRequest.lookup() + HttpServletRequest request = grailsWebRequest.getCurrentRequest() + def userDetails = request.getAttribute(UserDetails.REQUEST_USER_DETAILS_KEY) + + if (userDetails) + return userDetails + + // userId is set from either the request param userId or failing that it tries to get it from + // the UserPrincipal (assumes ecodata is being accessed directly via admin page) + userId = getUserFromJWT() ?: authService.getUserId() ?: request.getHeader(AuditInterceptor.httpRequestHeaderForUserId) + + if (userId) { + userDetails = setCurrentUser(userId) + if (userDetails) { + // We set the current user details in the request scope because + // the 'afterView' hook can be called prior to the actual rendering (despite the name) + // and the thread local can get clobbered before it is actually required. + // Consumers who have access to the request can simply extract current user details + // from there rather than use the service. + request.setAttribute(UserDetails.REQUEST_USER_DETAILS_KEY, userDetails) + return userDetails + } + } + } } diff --git a/scripts/data_migration/updateDataResourceIdForProjects.js b/scripts/data_migration/updateDataResourceIdForProjects.js new file mode 100644 index 000000000..23041241f --- /dev/null +++ b/scripts/data_migration/updateDataResourceIdForProjects.js @@ -0,0 +1,439 @@ +var dataProviderId = 'dp3903', + projects = [ + { + "name": "PAW Nestbox Monitoring", + "projectId": "709a7e77-105f-4ba9-9d79-7b087afa43a0", + "collectoryId": "dr19104" + }, + { + "name": "Blackberry biocontrol", + "projectId": "ef09ff0d-2af2-4c58-bee7-3198d4f6db4f", + "collectoryId": "dr18250" + }, + { + "name": "Bringing back the Richmond Birdwing Butterfly to Brisbane", + "projectId": "8aed164a-e3e2-4615-985a-dff45dcc968c", + "collectoryId": "dr19731" + }, + { + "name": "Gorse biocontrol", + "projectId": "f8b5dfbf-1eca-4091-be68-0a958292ba66", + "collectoryId": "dr18278" + }, + { + "name": "Spear thistle biocontrol", + "projectId": "c5b3564b-b170-4105-9e37-6c3de8219e7b", + "collectoryId": "dr18249" + }, + { + "name": "English (scotch) broom biocontrol", + "projectId": "cfd68ff5-10d1-4e52-ae39-4161c9b74c8f", + "collectoryId": "dr18277" + }, + { + "name": "Bridal creeper biocontrol", + "projectId": "450e6de7-95b2-4d24-b3ce-b4e2d3d7e029", + "collectoryId": "dr18276" + }, + { + "name": "Docks biocontrol", + "projectId": "4dd17bc6-6ca8-4551-90d3-362b0210c682", + "collectoryId": "dr18256" + }, + { + "name": "Redlands Weed Spotters", + "projectId": "975552f0-5b47-43d9-8db0-e47dc2199d19", + "collectoryId": "dr19103" + }, + { + "name": "Boneseed biocontrol", + "projectId": "a90d08cf-974d-4441-97e6-af5da34cb118", + "collectoryId": "dr18293" + }, + { + "name": "Onopordum thistle biocontrol", + "projectId": "7b1505b4-dbdf-4ad0-a6db-9068585c02a5", + "collectoryId": "dr18254" + }, + { + "name": "Slender thistle biocontrol ", + "projectId": "56491ea9-f10b-45b0-a645-c7674e31be96", + "collectoryId": "dr18275" + }, + { + "name": "Nodding thistle biocontrol", + "projectId": "36f4b025-73b1-4722-893e-0877e022b0dd", + "collectoryId": "dr18274" + }, + { + "name": "Variegated thistle biocontrol", + "projectId": "ba76374c-2859-43ac-ae9a-b6812a05b32c", + "collectoryId": "dr18273" + }, + { + "name": "Cat's claw creeper biocontrol", + "projectId": "68e5faca-a8df-4cea-a310-8db65965a3e9", + "collectoryId": "dr18272" + }, + { + "name": "Madeira vine biocontrol", + "projectId": "6d55e7aa-5992-4105-bf99-842b70e8698e", + "collectoryId": "dr18271" + }, + { + "name": "Horehound biocontrol", + "projectId": "935994ff-957d-423b-9ebb-6eb39930dfae", + "collectoryId": "dr18270" + }, + { + "name": "Cape broom biocontrol", + "projectId": "45361e8c-91ac-4447-b4da-9cd2a8fa0aae", + "collectoryId": "dr18269" + }, + { + "name": "Tutsan biocontrol", + "projectId": "6b786ef0-5503-4784-8d91-b2571b1323ee", + "collectoryId": "dr18268" + }, + { + "name": "Ragwort biocontrol", + "projectId": "38c288ee-01da-425a-9e54-ddaf94f0e748", + "collectoryId": "dr18267" + }, + { + "name": "Blue heliotrope biocontrol", + "projectId": "ba1af974-d733-4bea-882e-9b93a00892d2", + "collectoryId": "dr18266" + }, + { + "name": "Western Ringtail Possum Project", + "projectId": "69a78bc1-d0fd-483c-8fee-b1426c10f1c7", + "collectoryId": "dr19102" + }, + { + "name": "Wheel cactus biocontrol", + "projectId": "26ae9f28-4916-4579-afc0-7a9af3e19e0a", + "collectoryId": "dr18264" + }, + { + "name": "Tiger pear biocontrol", + "projectId": "ffeb44d7-08d0-4627-a31b-6a6365700a18", + "collectoryId": "dr18263" + }, + { + "name": "Opuntia spp. biocontrol", + "projectId": "15185781-1089-4718-9630-b2828e7b855a", + "collectoryId": "dr18262" + }, + { + "name": "Cylindropuntia spp. biocontrol", + "projectId": "738326b6-125b-49a7-b0ed-360c4c3d0062", + "collectoryId": "dr18261" + }, + { + "name": "Harrisia spp. biocontrol", + "projectId": "f298e305-7e48-4fa9-9c73-8e2c759f7d5f", + "collectoryId": "dr18260" + }, + { + "name": "Nature of Eyre Peninsula BioBlitz", + "projectId": "3595e826-4d38-423a-a9f1-683ed6c34e7a", + "collectoryId": "dr19100" + }, + { + "name": "Alan Anderson Walk Trail Kalamunda - Flora and Fauna", + "projectId": "e1e8d799-c4e7-48b8-8f0f-14db1e0c9bff", + "collectoryId": "dr19099" + }, + { + "name": "Australian elm tree project", + "projectId": "240e13b6-4138-40e8-8fe2-c8ff7ffd23e2", + "collectoryId": "dr19098" + }, + { + "name": "Discovery Circle BioBlitz events", + "projectId": "e3edba35-47ff-404b-9c36-43bfb22d4f41", + "collectoryId": "dr19034" + }, + { + "name": "Manky Parrots: Mapping Psittacine Beak and Feather Disease in Australia", + "projectId": "71330a55-a91a-4456-90b7-9de7bd8ac08d", + "collectoryId": "dr19732" + }, + { + "name": "Blue Mountains Eco Monitoring", + "projectId": "998b3582-6eaf-457c-9981-96842f774e19", + "collectoryId": "dr19096" + }, + { + "name": "Rare Flora of the Sydney Basin Bioregion", + "projectId": "c92698e9-9929-4db2-bbf3-48acf6e92508", + "collectoryId": "dr19095" + }, + { + "name": "Leonora District High School biodiversity inventory", + "projectId": "4f83ba09-7f2e-4a47-a9d4-524ce75f2e0a", + "collectoryId": "dr19094" + }, + { + "name": "Greta Valley Nest Box Monitoring ", + "projectId": "b06aee9c-0596-47ca-83d2-9bd5d7f04ccc", + "collectoryId": "dr19093" + }, + { + "name": "Koala Mapping Mackay, Whitsundays & Central Queensland Areas", + "projectId": "760dc5ab-163a-4779-9e09-bca599c9847b", + "collectoryId": "dr20943" + }, + { + "name": "Upside-down Jellyfish in Lake Macquarie", + "projectId": "95235e3b-65b1-4452-bf48-53c2b2157e5f", + "collectoryId": "dr19090" + }, + { + "name": "Bulimba Creek Catchment Nest Box Monitoring project", + "projectId": "efde3b5d-fc96-4c72-88b4-c8ebb1627166", + "collectoryId": "dr19539" + }, + { + "name": "Wildlife Discovery on your Landcare site using infrared wildlife cameras", + "projectId": "337da9cc-ff8c-4f53-a17a-684fd29cecb2", + "collectoryId": "dr19088" + }, + { + "name": "Agnes Water Turtle Monitoring", + "projectId": "e07e486a-7332-41c4-ab94-b32b9eea875b", + "collectoryId": "dr20147" + }, + { + "name": "Nest box monitoring project Walmer South Nature Conservation Reserve", + "projectId": "e3b3e17b-1cf5-43e3-8dfa-50c11955209f", + "collectoryId": "dr19075" + }, + { + "name": "B4C Road Kill Map", + "projectId": "e8e76e00-ce03-4eab-82a1-c90d86c91930", + "collectoryId": "dr19073" + }, + { + "name": "Wildlife Road Tolls", + "projectId": "b311909a-c3ac-4baf-90cf-ded9b235288d", + "collectoryId": "dr19072" + }, + { + "name": "East Ballina Nest Box Project", + "projectId": "cb659b45-6f78-48be-ade4-599eb78b68c2", + "collectoryId": "dr19071" + }, + { + "name": "Australian tree-kangaroo sightings", + "projectId": "c0c7f4c3-2712-4060-a921-d12f877b8cda", + "collectoryId": "dr19070" + }, + { + "name": "City of Parramatta Wildlife Survey", + "projectId": "34a67738-156b-41bd-834d-1262b5eac86a", + "collectoryId": "dr19069" + }, + { + "name": "Quolls in the Mary River Catchment- A Quoll Seekers Network survey", + "projectId": "ec01e69e-f5db-43bc-8f46-e1653f3b6a53", + "collectoryId": "dr19068" + }, + { + "name": "Mosman Wildlife Sightings ", + "projectId": "d625b411-6c9e-4820-b485-4c32d85e549e", + "collectoryId": "dr19066" + }, + { + "name": "Nest Box Monitoring", + "projectId": "02e5b36a-e7bd-4cb9-8b25-6bf08b95755a", + "collectoryId": "dr19067" + }, + { + "name": "Darebin Creek ", + "projectId": "22b185ee-d0e4-4a2d-b2b4-6a5f753317e4", + "collectoryId": "dr19065" + }, + { + "name": "Entangled Wildlife Australia", + "projectId": "23409a0b-6873-40a1-b291-f7eff3cbe837", + "collectoryId": "dr21370" + }, + { + "name": "Outdoor School - 15 Mile Creek ", + "projectId": "4a55b0c1-64a0-4c2a-9be7-63bbce430ca6", + "collectoryId": "dr19062" + }, + { + "name": "African thistle (Berkheya rigida) in Wyndham", + "projectId": "3fada699-7e26-46e8-a970-b748235ac4ad", + "collectoryId": "dr19061" + }, + { + "name": "Artichoke Thistle Monitoring (Cynara cardunculus)", + "projectId": "dcd863e5-1b3e-4ab8-9a7d-6f5081b8b13b", + "collectoryId": "dr19060" + }, + { + "name": "Cape Tulip (Moraea flaccida and Moraea miniata) in Wyndham", + "projectId": "00609186-21c6-4eff-8271-3f21ea3d59d3", + "collectoryId": "dr19059" + }, + { + "name": "Tree Hollows in Wyndham", + "projectId": "a19df0ed-f12d-433b-946c-e4581d3ed658", + "collectoryId": "dr19058" + }, + { + "name": "Brisbane’s Big Butterfly Count", + "projectId": "aa5b05c5-041e-4e7d-9f6c-60feee565dfb", + "collectoryId": "dr19057" + }, + { + "name": "Koala Sightings Toowoomba Region", + "projectId": "42e66c41-a0b0-45a5-bbfa-2ad0fd07f1ad", + "collectoryId": "dr19056" + }, + { + "name": "Ironbark Gully Nature Revealed", + "projectId": "126acd61-5053-49c4-b611-a3ea540abe01", + "collectoryId": "dr19055" + }, + { + "name": "Little River Victoria - Tiger Pear monitoring program", + "projectId": "3d2e9184-794c-4c90-8fbb-fc0390aca796", + "collectoryId": "dr19054" + }, + { + "name": "St Kilda Mangrove and Saltmarsh monitoring", + "projectId": "c2b16cf9-d4ac-49c7-b70d-53a13645e044", + "collectoryId": "dr19052" + }, + { + "name": "Burnett Koala Program", + "projectId": "322fa927-005f-4309-b569-8d2294f77c72", + "collectoryId": "dr19725" + }, + { + "name": "Indigo Creek nest box project", + "projectId": "c3c93a06-23cf-4e60-bfd9-e9ffcaf24fd8", + "collectoryId": "dr22046" + }, + { + "name": "Getting Curious - Wetland Birds", + "projectId": "ee777788-b430-4a69-922d-c15540e7ea38", + "collectoryId": "dr19048" + }, + { + "name": "Estuarine, salt lake and saltfield records (with occasional freshwater records and other terrestrial habitat flora records)", + "projectId": "665b17e8-c950-4785-b0c3-e7cc89def22b", + "collectoryId": "dr18188" + }, + { + "name": "Community monitoring of pools and watercourses in the Barossa", + "projectId": "f726eb14-bc2e-4eb2-a52b-7cae996c1029", + "collectoryId": "dr19047" + }, + { + "name": "Community monitoring of pools and watercourses in the Clare Valley", + "projectId": "bf63c385-ddf8-4d60-98f5-a906c6eedf4a", + "collectoryId": "dr19046" + }, + { + "name": "Rocky Shore Citizen Science", + "projectId": "1f9b7a1f-279c-4b27-87a6-bee0da748158", + "collectoryId": "dr19045" + }, + { + "name": "NE NSW Grey-headed Flying-fox Habitat Restoration Project", + "projectId": "4dedb5e9-a14c-46ac-98f8-3fbc1d9aff2d", + "collectoryId": "dr20597" + }, + { + "name": "Northern Tablelands Koala Habitat Restoration Project", + "projectId": "ade6b7ab-118c-4a4d-a9a7-6cde01703e92", + "collectoryId": "dr20599" + }, + { + "name": "Sunshine Coast's Big Butterfly Count", + "projectId": "2e519934-0f8a-4e81-a255-d62a3e366516", + "collectoryId": "dr19044" + }, + { + "name": "STREAM- Harrison's Creek Water Quality Monitoring", + "projectId": "c751258a-074f-4658-8b39-e83f78927930", + "collectoryId": "dr19043" + }, + { + "name": "Boonah and District Landcare tube nest project", + "projectId": "334a0530-30d1-411c-a1df-c4e4ea08b6b3", + "collectoryId": "dr20581" + }, + { + "name": "Flora and Fauna of Penrith", + "projectId": "7e356b40-9d48-466c-8549-c08d749aff06", + "collectoryId": "dr19033" + }, + { + "name": "Waterwatch Murraylands and Riverland", + "projectId": "7d2cb9d1-4013-40bd-9327-8853bd71c0b8", + "collectoryId": "dr22084" + }, + { + "name": "Clarence Valley Koala Habitat Restoration Project", + "projectId": "d5c9bd39-ef23-43de-a5a5-5dc31dec6194", + "collectoryId": "dr20598" + }, + { + "name": "Flora Connections", + "projectId": "aa06ceaf-f84a-4f3a-8e45-6ea5e8a7081d", + "collectoryId": "dr19940" + }, + { + "name": "Superb City Wrens", + "projectId": "51a2762f-7cd9-4330-94be-a1a71c205766", + "collectoryId": "dr20483" + }, + { + "name": "Willoughby Wildlife Watch", + "projectId": "a79ef701-85b4-43d1-a778-d77aa661340f", + "collectoryId": "dr19039" + }, + { + "name": "Seed collection for North Coast Local Land Services", + "projectId": "66a8710f-92e0-4770-8ae3-7e832317049e", + "collectoryId": "dr19435" + }, + { + "name": "BioCondition Lite Audits 202122 Ausecology", + "projectId": "996fce1d-a8a1-4f61-ba94-93d3b3a2984c", + "collectoryId": "dr19036" + }, + { + "name": "Jungarra Ngarrian Conservation Project", + "projectId": "723c1751-0449-4a48-a023-c127197a6d3d", + "collectoryId": "dr19136" + }, + { + "name": "NSW Flying-Fox Habitat Restoration Program", + "projectId": "42a524b8-6164-42b5-9c41-73cc9041c777", + "collectoryId": "dr20600" + }, + { + "name": "Northern Rivers 2022 Flood Assessments", + "projectId": "74da0f68-0b50-46f7-9078-f2ce3d22eebf", + "collectoryId": "dr22012" + } + ], + counter = 0; +print("Updating " + projects.length + " projects"); +projects.forEach(function (project) { + var result = db.project.updateOne({projectId: project.projectId}, {$set: {dataProviderId: dataProviderId, dataResourceId: project.collectoryId}}); + if (result.modifiedCount == 0) + print("Project not modified: " + project.name + " (" + project.projectId + ")"); + else + counter += result.modifiedCount; +}); + +print(counter + ' projects updated'); \ No newline at end of file diff --git a/scripts/misc/bioCollectProjectReport.js b/scripts/misc/bioCollectProjectReport.js new file mode 100644 index 000000000..79cb201dd --- /dev/null +++ b/scripts/misc/bioCollectProjectReport.js @@ -0,0 +1,48 @@ +var projects = db.project.find({isMERIT: false, status: {$ne: 'deleted'}}), + project; +var headers = ["Project start date", "Project end date", "Project type", "Project name", "Project status", + "Count of number of members/participants (including casual project participants) for each project", + "Count of number of surveys for each project", + "Count of number of event records/activities for each project", + "Count of the occurrence records (total) for each project"] + +print(headers.join(",")); +while (projects.hasNext()) { + project = projects.next(); + var columns = [] + + columns.push('"' + getDate(project.plannedStartDate) + '"'); + columns.push('"' + getDate(project.plannedEndDate) + '"'); + columns.push('"' + project.projectType + '"'); + columns.push('"' + project.name.replace('"', '""') + '"' ); + columns.push('"' + project.status + '"'); + columns.push(getMembersOfProjectCount(project)); + columns.push(getSurveysCount(project)); + columns.push(getActivitiesCount(project) ); + columns.push(getOccurrencesCount(project)); + print(columns.join(",")); +} + +function getMembersOfProjectCount(project) { + return db.userPermission.find({entityId: project.projectId, entityType: "au.org.ala.ecodata.Project", status: {$ne: 'deleted'}}).count(); +} + +function getSurveysCount(project) { + return db.projectActivity.find({projectId: project.projectId, status: {$ne: 'deleted'}}).count(); +} + +function getActivitiesCount(project) { + return db.activity.find({projectId: project.projectId, status: {$ne: 'deleted'}}).count(); +} + +function getOccurrencesCount(project) { + return db.record.find({projectId: project.projectId, status: {$ne: 'deleted'}}).count(); +} + +function getDate(date){ + if (date) { + var eventDate = date; + return eventDate.getDate() + '/' + (eventDate.getMonth() + 1) + '/' + eventDate.getFullYear(); + } + else return ""; +} \ No newline at end of file diff --git a/src/test/groovy/au/org/ala/ecodata/ElasticSearchIndexServiceSpec.groovy b/src/test/groovy/au/org/ala/ecodata/ElasticSearchIndexServiceSpec.groovy index 3d03f6b74..8eed80562 100644 --- a/src/test/groovy/au/org/ala/ecodata/ElasticSearchIndexServiceSpec.groovy +++ b/src/test/groovy/au/org/ala/ecodata/ElasticSearchIndexServiceSpec.groovy @@ -5,7 +5,6 @@ import grails.test.mongodb.MongoSpec import grails.testing.services.ServiceUnitTest import grails.web.servlet.mvc.GrailsParameterMap import groovy.json.JsonSlurper -import org.elasticsearch.action.get.GetRequest import org.elasticsearch.action.get.GetResponse import org.elasticsearch.action.index.IndexRequest import org.elasticsearch.action.index.IndexRequestBuilder @@ -23,6 +22,7 @@ class ElasticSearchIndexServiceSpec extends MongoSpec implements ServiceUnitTest PermissionService permissionService = Stub(PermissionService) ProgramService programService = Stub(ProgramService) ProjectService projectService = Mock(ProjectService) + ProjectActivityService projectActivityService = Mock(ProjectActivityService) RestHighLevelClient client = GroovyMock(RestHighLevelClient) // Need a groovy mock here due to final methods SiteService siteService = Mock(SiteService) ActivityService activityService = Mock(ActivityService) @@ -37,6 +37,7 @@ class ElasticSearchIndexServiceSpec extends MongoSpec implements ServiceUnitTest service.projectService = projectService service.siteService = siteService service.activityService = activityService + service.projectActivityService = projectActivityService service.documentService = documentService JSON.registerObjectMarshaller(new MapMarshaller())