Skip to content

Commit dca9c8b

Browse files
committed
Merge branch 'hotfix/5.0.4'
2 parents 29e9f90 + 2867606 commit dca9c8b

File tree

16 files changed

+312
-85
lines changed

16 files changed

+312
-85
lines changed

build.gradle

+11-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ plugins {
1717
id 'war'
1818
}
1919

20-
version "5.0.3"
20+
version "5.0.4-SNAPSHOT"
2121
group "au.org.ala"
2222

2323
apply plugin:"eclipse"
@@ -33,11 +33,12 @@ apply from: 'https://raw.githubusercontent.com/AtlasOfLivingAustralia/travis-bui
3333
repositories {
3434
mavenLocal()
3535
//for missing jai_core.jar
36-
// maven { url "http://download.osgeo.org/webdav/geotools"}
36+
maven { url "https://mvnrepository.com" }
37+
maven { url "http://maven.geotoolkit.org"}
3738
maven { url "https://repo.grails.org/grails/core" }
3839
maven { url "https://nexus.ala.org.au/content/groups/public/" }
40+
3941
mavenCentral()
40-
// maven { url "http://maven.geotoolkit.org"}
4142

4243
}
4344

@@ -46,7 +47,7 @@ def metadataExtractorVersion = "2.6.2"
4647
def imgscalrVersion = "4.2"
4748
def httpmimeVersion = "4.2.1"
4849
def jtsVersion = "1.8"
49-
def geoToolsVersion = "11.1"
50+
def geoToolsVersion = "11.2"
5051
// Set to true it needed only for development
5152
boolean inplace = false
5253

@@ -80,10 +81,11 @@ dependencies {
8081
compile "org.imgscalr:imgscalr-lib:${imgscalrVersion}"
8182
compile "org.apache.httpcomponents:httpmime:${httpmimeVersion}"
8283
compile "com.vividsolutions:jts:${jtsVersion}"
83-
//compile "org.geotools.xsd:gt-xsd-kml:${geoToolsVersion}"
84-
compile ("org.geotools.xsd:gt-xsd-kml:${geoToolsVersion}") {
85-
exclude group: 'javax.media', module: 'jai_core'
86-
}
84+
85+
compile "org.geotools.xsd:gt-xsd-kml:${geoToolsVersion}"
86+
compile "org.geotools:gt-shapefile:${geoToolsVersion}"
87+
compile "org.geotools:gt-geojson:${geoToolsVersion}"
88+
compile "org.geotools:gt-epsg-hsql:${geoToolsVersion}"
8789

8890
compile "joda-time:joda-time:2.3"
8991
// compile "org.codehaus.groovy.modules.http-builder:http-builder:0.7.1"
@@ -133,7 +135,7 @@ dependencies {
133135
compile "org.grails.plugins:ala-admin-plugin:2.1"
134136
if (!inplace) {
135137
compile "org.grails.plugins:ala-map-plugin:3.0"
136-
compile "org.grails.plugins:ecodata-client-plugin:3.0.2"
138+
compile "org.grails.plugins:ecodata-client-plugin:3.0.3"
137139
}
138140
}
139141

grails-app/assets/javascripts/enterBioActivityData.js

+23-18
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,36 @@ function Master(activityId, config) {
6161
* Collect the activity form data into a single javascript object
6262
* @returns JS object containing form data, or null if there is no data
6363
*/
64-
self.collectData = function () {
65-
var activityData, outputs = [], photoPoints;
66-
$.each(this.subscribers, function (i, obj) {
67-
if (obj.model === 'activityModel') {
68-
activityData = obj.get();
69-
} else if (obj.model === 'photoPoints' && obj.isDirty()) {
70-
photoPoints = obj.get();
71-
}
72-
else { // Update outputs unconditionally, backend needs the activityModel and outputs to
73-
// create derived data even if outputs didn't change
74-
outputs.push(obj.get());
64+
self.modelAsJS = function () {
65+
var activityData, outputs = [];
66+
$.each(this.subscribers, function(i, obj) {
67+
if (obj.isDirty()) {
68+
if (obj.model === 'activityModel') {
69+
activityData = obj.get();
70+
}
71+
else {
72+
outputs.push(obj.get());
73+
}
7574
}
76-
7775
});
78-
if (outputs.length === 0 && activityData === undefined && photoPoints === undefined) {
79-
return {validation: false, message: "Nothing need to be updated!"};
80-
}
8176

82-
if (activityData === undefined) {
83-
activityData = {}
77+
if (activityData === undefined && outputs.length == 0) {
78+
return undefined;
79+
}
80+
if (!activityData) {
81+
activityData = {};
8482
}
8583
activityData.outputs = outputs;
84+
8685
return activityData;
8786
};
8887

88+
self.modelAsJSON = function() {
89+
var jsData = self.modelAsJS();
90+
91+
return jsData ? JSON.stringify(jsData) : undefined;
92+
};
93+
8994
self.removeTemporarySite = function () {
9095
if (this.subscribers[0].model.data && this.subscribers[0].model.data.locationSitesArray && this.subscribers[0].model.data.location) {
9196
var sites = this.subscribers[0].model.data.locationSitesArray();
@@ -124,7 +129,7 @@ function Master(activityId, config) {
124129
*/
125130
self.save = function () {
126131
if ($('#validation-container').validationEngine('validate')) {
127-
var toSave = this.collectData();
132+
var toSave = this.modelAsJS();
128133
toSave = JSON.stringify(toSave);
129134

130135
// Don't allow another save to be initiated.

grails-app/conf/application.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ app:
5858
security:
5959
cas:
6060
casProperties: "casServerLoginUrl,serverName,centralServer,casServerName,uriFilterPattern,uriExclusionFilter,uriExclusionFilterPattern,casServerLoginUrlPrefix,gateway,casServerUrlPrefix,contextPath,gatewayStorageClass"
61-
uriExclusionFilterPattern: "/assets/.*,/images.*,/css.*,/js.*,/less.*,/ajax/bulkLookupQuestions,/uploads/.*"
61+
uriExclusionFilterPattern: "/assets/.*,/images.*,/css.*,/js.*,/less.*,/ajax/(bulkLookupQuestions|saveBookmarkLocation|getBookmarkLocations),/uploads/.*"
6262
authenticateOnlyIfLoggedInPattern: ".*"
63-
uriFilterPattern: ".*/user/.*,.*/site/(?!(index|list|elasticsearch|getImages|getPoiImages|ajaxUpdate|checkSiteName|ajaxList)).*,.*/project/(?!(index|search|citizenScience|listRecordImages|projectSummaryReportCallback)).*,.*/activity/(?!index).*,.*/output/(?!index).*,.*/image/(?!index).*,.*/admin/.*,i.*/proxy/speciesListPost,.*/proxy/documentUpdate,.*/proxy/deleteDocument,.*/home/advanced,.*/organisation/(?!index).*,.*/organisation/(?!list).*,.*/bioActivity/create/.*,.*/bioActivity/edit/.*,.*/bioActivity/list,/sight/.*"
63+
uriFilterPattern: ".*/user/.*,.*/site/(?!(index|list|elasticsearch|getImages|getPoiImages|ajaxUpdate|checkSiteName|ajaxList|checkPointInsideProjectAreaAndAddress)).*,.*/project/(?!(index|search|citizenScience|listRecordImages|projectSummaryReportCallback)).*,.*/activity/(?!index).*,.*/output/(?!index).*,.*/image/(?!index).*,.*/admin/.*,i.*/proxy/speciesListPost,.*/proxy/documentUpdate,.*/proxy/deleteDocument,.*/home/advanced,.*/organisation/(?!index).*,.*/organisation/(?!list).*,.*/bioActivity/create/.*,.*/bioActivity/edit/.*,.*/bioActivity/list,/sight/.*"
6464
readOnlyOfficerRole: "ROLE_FC_READ_ONLY"
6565
alaAdminRole : "ROLE_ADMIN"
6666
officerRole : "ROLE_FC_OFFICER"
@@ -116,6 +116,8 @@ ecodata:
116116
google:
117117
maps:
118118
base: "https://maps.googleapis.com/maps/api/js?key="
119+
geocode:
120+
url: "https://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng="
119121

120122
headerAndFooter:
121123
baseURL: "https://www.ala.org.au/commonui-bs2" #"https://www.ala.org.au/commonui-bs2-v2/commonui-bs2"

grails-app/controllers/au/org/ala/biocollect/BioActivityController.groovy

+11-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ class BioActivityController {
206206
}
207207

208208
def mobileCreate(String id) {
209+
if(grailsApplication.config.app.mobile.hub) {
210+
settingService.loadHubConfig(grailsApplication.config.app.mobile.hub)
211+
params.hub = grailsApplication.config.app.mobile.hub
212+
}
213+
209214
Map model = addActivity(id, true)
210215
model.mobile = true
211216
model.userName = request.getHeader(UserService.USER_NAME_HEADER_FIELD)
@@ -214,6 +219,11 @@ class BioActivityController {
214219
}
215220

216221
def mobileEdit(String id) {
222+
if(grailsApplication.config.app.mobile.hub) {
223+
settingService.loadHubConfig(grailsApplication.config.app.mobile.hub)
224+
params.hub = grailsApplication.config.app.mobile.hub
225+
}
226+
217227
Map model = editActivity(id, true)
218228
model.mobile = true
219229
model.userName = request.getHeader(UserService.USER_NAME_HEADER_FIELD)
@@ -366,7 +376,7 @@ class BioActivityController {
366376
String userId = userService.getCurrentUserId(request)
367377
def activity = activityService.get(id, params?.version, userId, true)
368378
if (activity.error){
369-
redirect(controller: "error", action:'notFound', params: [status: 404, errMsg: activity.error])
379+
redirect(controller: "error", action:'response404', params: [status: 404, errMsg: activity.error])
370380
return
371381
}
372382
def pActivity = projectActivityService.get(activity?.projectActivityId, "all", params?.version)

grails-app/controllers/au/org/ala/biocollect/merit/AjaxController.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import org.grails.web.json.JSONObject
55

66
class AjaxController {
77

8-
def authService
98
def locationService
9+
def userInfoService
1010

1111
/**
1212
* Simple action that can be called by long running pages periodically to keep the container session alive.
@@ -18,7 +18,7 @@ class AjaxController {
1818
}
1919

2020
def getBookmarkLocations() {
21-
def userId = authService.userId
21+
def userId = userInfoService.getCurrentUser()?.userId
2222
def result = locationService.getBookmarkLocationsForUser(userId)
2323

2424
if (result.hasProperty("error")) {
@@ -29,7 +29,7 @@ class AjaxController {
2929
}
3030

3131
def saveBookmarkLocation() {
32-
def userId = authService.userId
32+
def userId = userInfoService.getCurrentUser()?.userId
3333
JSONObject bookmark = request.JSON
3434
bookmark.put("userId", userId)
3535
log.debug "post json = ${request.JSON}"

grails-app/controllers/au/org/ala/biocollect/merit/ProjectController.groovy

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import au.org.ala.biocollect.*
44
import au.org.ala.biocollect.merit.hub.HubSettings
55
import au.org.ala.biocollect.projectresult.Builder
66
import au.org.ala.biocollect.projectresult.Initiator
7+
import au.org.ala.ecodata.forms.UserInfoService
78
import au.org.ala.web.AuthService
89
import grails.converters.JSON
910
import org.apache.http.HttpStatus
@@ -39,6 +40,7 @@ class ProjectController {
3940
CollectoryService collectoryService
4041
PdfGenerationService pdfGenerationService
4142
UtilService utilService
43+
UserInfoService userInfoService
4244

4345
//def grailsApplication
4446

@@ -132,7 +134,7 @@ class ProjectController {
132134
model.vocabList = vocabService.getVocabValues ()
133135
println model.pActivityForms
134136
}
135-
model.mobile = params.mobile ?:false
137+
model.mobile = params.getBoolean('mobile', false)
136138
model.showBackButton = request.getHeader('referer') ? true:false
137139
if(projectService.isWorks(project)){
138140
model.activityTypes = projectService.addSpeciesFieldsToActivityTypesList(metadataService.activityTypesList(project.associatedProgram))
@@ -827,7 +829,7 @@ class ProjectController {
827829
if (trimmedParams.mobile) {
828830
String username = request.getHeader(UserService.USER_NAME_HEADER_FIELD)
829831
String key = request.getHeader(UserService.AUTH_KEY_HEADER_FIELD)
830-
fq.push('allParticipants:' + (username && key ? userService.getUserFromAuthKey(username, key)?.userId : ''))
832+
fq.push('allParticipants:' + (username && key ? userInfoService.getUserFromAuthKey(username, key)?.userId : ''))
831833
} else {
832834
fq.push('allParticipants:' + userService.getUser()?.userId);
833835
}

grails-app/controllers/au/org/ala/biocollect/merit/SiteController.groovy

+9
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,15 @@ class SiteController {
830830
}
831831
}
832832

833+
def checkPointInsideProjectAreaAndAddress (String lat, String lng, String projectId) {
834+
if (lat && lng && projectId) {
835+
Map result = siteService.checkPointInsideProjectAreaAndAddress(lat, lng, projectId)
836+
render (text: result as JSON, contentType: 'application/json')
837+
} else {
838+
render(text: "Parameter(s) missing. The following parameters are requied - lat, lng and projectId", status: HttpStatus.SC_BAD_REQUEST);
839+
}
840+
}
841+
833842
/**
834843
* Check each of the site's projects if logged in user is a member
835844
*

grails-app/services/au/org/ala/biocollect/merit/SiteService.groovy

+68
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package au.org.ala.biocollect.merit
22

3+
import au.org.ala.biocollect.GeometryUtils
34
import au.org.ala.biocollect.ProjectActivityService
45
import com.vividsolutions.jts.geom.Geometry
56
import com.vividsolutions.jts.geom.Point
@@ -737,4 +738,71 @@ class SiteService {
737738
"defaultZoomArea" : defaultZoomSiteId
738739
]
739740
}
741+
742+
Map checkPointInsideProjectAreaAndAddress (String lat, String lng, String projectId) {
743+
Map response = [
744+
isPointInsideProjectArea: false,
745+
address: null
746+
]
747+
748+
response.isPointInsideProjectArea = isPointInsideProjectArea(lat, lng, projectId)
749+
if (!response.isPointInsideProjectArea) {
750+
response.address = lookupAddressOfPoint(lat, lng)
751+
}
752+
753+
response
754+
}
755+
756+
String lookupAddressOfPoint (String lat, String lng) {
757+
if (lat && lng) {
758+
Map address = getLocationMetadataForPoint(lat, lng)
759+
return address?.formatted_address
760+
}
761+
}
762+
763+
Map getLocationMetadataForPoint (String lat, String lng) {
764+
if (grailsApplication.config.google.api.key) {
765+
def localityUrl = grailsApplication.config.google.geocode.url + "${lat},${lng}&key=${grailsApplication.config.google.maps.apiKey}"
766+
def result = webService.getJson(localityUrl)
767+
if (!result?.error) {
768+
return result.results ? result.results[0] : null
769+
}
770+
}
771+
}
772+
773+
boolean isPointInsideProjectArea (String lat, String lng, String projectId) {
774+
Map projectArea = getProjectAreaForProject(projectId)
775+
Map pointGeoJSON = createGeoJSONFromPoint(lat, lng)
776+
if ( projectArea?.geoIndex && pointGeoJSON) {
777+
return GeometryUtils.doShapesIntersect(projectArea.geoIndex, pointGeoJSON)
778+
}
779+
780+
false
781+
}
782+
783+
Map getProjectAreaForProject(String projectId) {
784+
Map project = projectService.get(projectId)
785+
if (!project?.error) {
786+
String siteId = project.projectSiteId
787+
Map projectArea = get(siteId)
788+
if (!projectArea?.error) {
789+
return projectArea
790+
}
791+
}
792+
}
793+
794+
Map createGeoJSONFromPoint (String lat, String lng) {
795+
if (lat && lng) {
796+
double latitude = Double.parseDouble(lat)
797+
double longitude = Double.parseDouble(lng)
798+
799+
[
800+
"type" : "Point",
801+
"coordinates" : [
802+
longitude,
803+
latitude
804+
]
805+
]
806+
}
807+
}
740808
}

grails-app/services/au/org/ala/biocollect/merit/UserService.groovy

+4-35
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package au.org.ala.biocollect.merit
22

33
import au.org.ala.biocollect.merit.hub.HubSettings
4+
import au.org.ala.ecodata.forms.UserInfoService
45
import au.org.ala.userdetails.UserDetailsFromIdListResponse
5-
import grails.converters.JSON
6-
import org.apache.http.HttpStatus
7-
8-
import javax.annotation.PostConstruct
96

107
class UserService {
11-
def grailsApplication, authService, webService
8+
def grailsApplication, authService, webService
9+
UserInfoService userInfoService
1210
//def auditBaseUrl = ""
1311

1412
static String USER_NAME_HEADER_FIELD = "userName"
@@ -36,41 +34,12 @@ class UserService {
3634
if (request) {
3735
String username = request.getHeader(UserService.USER_NAME_HEADER_FIELD)
3836
String key = request.getHeader(UserService.AUTH_KEY_HEADER_FIELD)
39-
userId = username && key ? getUserFromAuthKey(username, key)?.userId : ''
37+
userId = username && key ? userInfoService.getUserFromAuthKey(username, key)?.userId : ''
4038
}
4139

4240
userId ?: (getUser()?.userId ?: "")
4341
}
4442

45-
/*
46-
* Get User details for the given user name and auth key.
47-
*
48-
* @param username username
49-
* @param key mobile auth key
50-
* @return userdetails
51-
* */
52-
53-
def UserDetails getUserFromAuthKey(String username, String key) {
54-
String url = grailsApplication.config.mobile.auth.check.url
55-
Map params = [userName: username, authKey: key]
56-
def result = webService.doPostWithParams(url, params)
57-
58-
if (result.statusCode == HttpStatus.SC_OK && result.resp?.status == 'success') {
59-
params = [userName: username]
60-
url = grailsApplication.config.userDetails.url + "userDetails/getUserDetails"
61-
result = webService.doPostWithParams(url, params)
62-
if (result.statusCode == HttpStatus.SC_OK && result.resp) {
63-
return new UserDetails(result.resp.firstName + result.resp.lastName, result.resp.userName, result.resp.userId)
64-
}
65-
} else {
66-
log.error ("Failed to get user details for parameters: ${(params as JSON).toString()}")
67-
log.error ((result as JSON).toString(true))
68-
}
69-
70-
return null
71-
}
72-
73-
7443
public UserDetails getUser() {
7544
def u = authService.userDetails()
7645
def user

0 commit comments

Comments
 (0)