Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1570 check if shape file is uploading correctly #1575

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, false, false, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

includeUserId should be 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, false, false, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

includeUserId should be true i.e. default value.

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 All @@ -183,7 +183,7 @@ class SiteService {

def url = "${baseUrl}/${shapeFileId}/${siteId}"

def result = webService.doPost(url, site)
def result = webService.doPost(url, site, true)

String error
if (!result?.resp?.id) {
Expand Down Expand Up @@ -245,7 +245,7 @@ class SiteService {
Geometry geom = placemark.getDefaultGeometry()
def site = [name:name, description: description, user_id:userId, api_key:grailsApplication.config.api_key, wkt:geom.toText()]

def result = webService.doPost(url, site)
def result = webService.doPost(url, site, true)
if (!result.error) {
def id = result.resp.id
if (!result.resp.error) {
Expand Down
30 changes: 23 additions & 7 deletions grails-app/services/au/org/ala/biocollect/merit/WebService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,18 @@ 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) {
temi marked this conversation as resolved.
Show resolved Hide resolved
conn.setRequestProperty("Authorization", grailsApplication.config.getProperty("api_key"))
}

if (useToken) {
conn.setRequestProperty("Authorization", getAuthHeader())
}

conn.setRequestProperty(ACCEPT, MediaType.APPLICATION_JSON_VALUE)
def json = responseText(conn)
def result = JSON.parse(json)
Expand Down Expand Up @@ -281,14 +286,20 @@ class WebService {
}
}

def doPost(String url, Map postBody) {
def doPost(String url, Map postBody, boolean useToken = false) {
def conn = null
def charEncoding = 'utf-8'
try {
conn = new URL(url).openConnection()
conn.setDoOutput(true)
conn.setRequestProperty("Content-Type", "application/json;charset=${charEncoding}")
conn.setRequestProperty("Authorization", grailsApplication.config.getProperty("api_key"))

if (useToken) {
conn.setRequestProperty("Authorization", getAuthHeader())
} else {
conn.setRequestProperty("Authorization", grailsApplication.config.getProperty("api_key"))
}

addHubUrlPath(conn)

def user = getUserService().getUser()
Expand Down Expand Up @@ -434,9 +445,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 +460,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 +477,12 @@ class WebService {
}

addHubUrlPath(headers)
headers."Authorization" = grailsApplication.config.getProperty("api_key")
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
Loading