Skip to content

Commit

Permalink
Merge pull request #1647 from AtlasOfLivingAustralia/feature/issue1644
Browse files Browse the repository at this point in the history
commit progress #1644
  • Loading branch information
temi authored Nov 18, 2024
2 parents ed116c9 + bdb0998 commit 64619b6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,86 @@ class BioActivityController {
render model as JSON
}

/*
* Simplified version to get data/output for an activity
* Handles both session and non session based request.
*
* @param id activityId
*
* @return activity
*
*/
@Operation(
method = "GET",
tags = "biocollect",
operationId = "simplifiedactivityoutputs",
summary = "Get data for an activity",
parameters = [
@Parameter(
name = "id",
in = ParameterIn.PATH,
required = true,
description = "Activity id"
)
],
responses = [
@ApiResponse(
responseCode = "200",
content = @Content(
mediaType = "application/json",
schema = @Schema(
implementation = GetOutputForActivitySimplifiedResponse.class
)
),
headers = [
@Header(name = 'Access-Control-Allow-Headers', description = "CORS header", schema = @Schema(type = "String")),
@Header(name = 'Access-Control-Allow-Methods', description = "CORS header", schema = @Schema(type = "String")),
@Header(name = 'Access-Control-Allow-Origin', description = "CORS header", schema = @Schema(type = "String"))
]
),
@ApiResponse(
responseCode = "401",
content = @Content(
mediaType = "application/json",
schema = @Schema(
implementation = ErrorResponse.class
)
),
headers = [
@Header(name = 'Access-Control-Allow-Headers', description = "CORS header", schema = @Schema(type = "String")),
@Header(name = 'Access-Control-Allow-Methods', description = "CORS header", schema = @Schema(type = "String")),
@Header(name = 'Access-Control-Allow-Origin', description = "CORS header", schema = @Schema(type = "String"))
]
)
],
security = @SecurityRequirement(name="auth")
)
@Path("ws/bioactivity/data/simplified/{id}")
def getOutputForActivitySimplified(String id){
String userId = userService.getCurrentUserId()
def activity = activityService.get(id)
String projectId = activity?.projectId
def model = [:]

if (!userId) {
response.status = 401
model.error = "Access denied: User has not been authenticated."
} else if (!activity) {
model.error = "Invalid activity id"
} else if (!activity) {
model.error = "Invalid activity - ${id}"
} else if (!projectId) {
model.error = "No project associated with the activity"
} else if (projectService.isUserAdminForProject(userId, projectId) || activityService.isUserOwnerForActivity(userId, activity?.activityId)) {
model = [activity: activity]
} else {
response.status = 401
model.error = "Access denied: User is not an owner of this activity ${activity?.activityId}"
}

render model as JSON
}

/*
* Get activity model for a survey/projectActivity
* Handles both session and non session based request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class UrlMappings {
"/ws/attachment/upload"(controller: "image", action: 'upload')
"/ws/bioactivity/model/$id"(controller: "bioActivity", action: 'getActivityModel')
"/ws/bioactivity/data/$id"(controller: "bioActivity", action: 'getOutputForActivity')
"/ws/bioactivity/data/simplified/$id"(controller: "bioActivity", action: 'getOutputForActivitySimplified')
"/ws/species/uniqueId"(controller: "output", action: 'getOutputSpeciesIdentifier')
"/ws/bioactivity/save"(controller: "bioActivity", action: 'ajaxUpdate')
"/ws/bioactivity/site"(controller: "site", action: 'ajaxUpdate')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,10 @@ class ProjectSearchResponse {
Integer total
List<Facet> facets
}

// classes for "ws/bioactivity/data/simplified/{id}
@JsonIgnoreProperties('metaClass')
class GetOutputForActivitySimplifiedResponse {
Map activity
String error
}

0 comments on commit 64619b6

Please sign in to comment.