Skip to content

Commit

Permalink
#1570 check if shape file is uploading correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
schoicsiro committed Nov 20, 2023
1 parent 2e1f9ce commit 471cfa7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import static org.apache.http.HttpStatus.*
class MetadataService {
static DateFormat ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")

def grailsApplication, webService, cacheService, settingService, modelService
def grailsApplication, cacheService, settingService, modelService
WebService webService

def activitiesModel() {
return cacheService.get('activity-model',{
Expand Down Expand Up @@ -247,14 +248,14 @@ class MetadataService {
def facetConfig = webService.getJson(grailsApplication.config.ecodata.service.url + "/metadata/getGeographicFacetConfig")
facetConfig.grouped.each { k, v ->
v.each { name, fid ->
def objects = webService.getJson(grailsApplication.config.spatial.baseURL + '/ws/objects/'+fid)
def objects = webService.getJson(grailsApplication.config.spatial.baseURL + '/ws/objects/'+fid, null, true, false, true)
results[k] << [(objects[0].fieldname):objects[0]] // Using the fieldname instead of the name for grouped facets is a temp workaround for the GER.
}

}

facetConfig.contextual.each { name, fid ->
def objects = webService.getJson(grailsApplication.config.spatial.baseURL + '/ws/objects/'+fid)
def objects = webService.getJson(grailsApplication.config.spatial.baseURL + '/ws/objects/'+fid, null, true, false, true)
objects.each {
results[name] << [(it.name):it]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import org.opengis.feature.simple.SimpleFeature

class SiteService {

def webService, grailsApplication, commonService, metadataService, userService
def grailsApplication, commonService, metadataService, userService
def documentService
ActivityService activityService
ProjectService projectService
LinkGenerator grailsLinkGenerator
ReportService reportService
ProjectActivityService projectActivityService
SiteService siteService

WebService webService
def list() {
webService.getJson(grailsApplication.config.ecodata.service.url + '/site/').list
}
Expand Down Expand Up @@ -162,7 +162,7 @@ class SiteService {
def userId = userService.getUser().userId
def url = "${grailsApplication.config.spatial.layersUrl}/shape/upload/shp?user_id=${userId}&api_key=${grailsApplication.config.api_key}"

return webService.postMultipart(url, [:], shapefile)
return webService.postMultipart(url, [:], shapefile, 'files', true)
}

/**
Expand Down
21 changes: 15 additions & 6 deletions grails-app/services/au/org/ala/biocollect/merit/WebService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,16 @@ class WebService {
tokenService.getAuthToken(false).toAuthorizationHeader()
}

def getJson(String url, Integer timeout = null, boolean includeApiKey = false, boolean includeUserId = true) {
def getJson(String url, Integer timeout = null, boolean includeApiKey = false, boolean includeUserId = true, boolean useToken = false) {
def conn = null
try {
conn = configureConnection(url, includeUserId, timeout)
if (includeApiKey) {
conn.setRequestProperty("Authorization", grailsApplication.config.getProperty("api_key"))
if (useToken) {
conn.setRequestProperty("Authorization", getAuthHeader())
} else {
conn.setRequestProperty("Authorization", grailsApplication.config.getProperty("api_key"))
}
}
conn.setRequestProperty(ACCEPT, MediaType.APPLICATION_JSON_VALUE)
def json = responseText(conn)
Expand Down Expand Up @@ -434,9 +438,9 @@ class WebService {
* @param file the Multipart file object to forward.
* @return [status:<request status>, content:<The response content from the server, assumed to be JSON>
*/
def postMultipart(url, Map params, MultipartFile file, fileParam = 'files') {
def postMultipart(url, Map params, MultipartFile file, fileParam = 'files', boolean useToken = false) {

postMultipart(url, params, file.inputStream, file.contentType, file.originalFilename, fileParam)
postMultipart(url, params, file.inputStream, file.contentType, file.originalFilename, fileParam, useToken)
}

/**
Expand All @@ -449,7 +453,7 @@ class WebService {
* @param fileParamName the name of the HTTP parameter that will be used for the post.
* @return [status:<request status>, content:<The response content from the server, assumed to be JSON>
*/
def postMultipart(url, Map params, InputStream contentIn, contentType, originalFilename, fileParamName = 'files') {
def postMultipart(url, Map params, InputStream contentIn, contentType, originalFilename, fileParamName = 'files', boolean useToken = false) {

def result = [:]
def user = userService.getUser()
Expand All @@ -466,7 +470,12 @@ class WebService {
}

addHubUrlPath(headers)
headers."Authorization" = getAuthHeader()
if (useToken) {
headers."Authorization" = getAuthHeader()
} else {
headers."Authorization" = grailsApplication.config.getProperty("api_key")
}

if (user) {
headers[grailsApplication.config.app.http.header.userId] = user.userId
}
Expand Down

0 comments on commit 471cfa7

Please sign in to comment.