Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -41,12 +41,12 @@
@Slf4j
@Controller("/${micronaut.bi.api.version}")
@Secured(SecurityRule.IS_AUTHENTICATED)
public class CropController {
public class BrAPICropController {

private final ProgramService programService;

@Inject
public CropController(ProgramService programService) {
public BrAPICropController(ProgramService programService) {
this.programService = programService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.breedinginsight.brapi.v2;

import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
Expand All @@ -31,6 +33,7 @@
import org.breedinginsight.api.auth.ProgramSecured;
import org.breedinginsight.api.auth.ProgramSecuredRoleGroup;
import org.breedinginsight.api.auth.SecurityService;
import org.breedinginsight.api.model.v1.response.DataResponse;
import org.breedinginsight.brapi.v1.controller.BrapiVersion;
import org.breedinginsight.model.Program;
import org.breedinginsight.services.ProgramService;
Expand Down Expand Up @@ -125,7 +128,16 @@ public HttpResponse<?> rootProgramsProgramDbIdPut(@PathVariable("programDbId") S


//START - endpoints for within the context of a program
/* Retrieves a list of programs
* If programId supplied will only ever return one program.
*
* @param programId The ID of the program.
*
* @return HttpResponse containing BrAPIProgramListResponse
* Returns HttpResponse.NOT_FOUND if the program is not found.
*/
@Get("/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/programs")
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES})
public HttpResponse<BrAPIProgramListResponse> programsGet(@PathVariable("programId") UUID programId,
@QueryValue("abbreviation") Optional<String> abbreviation,
Expand All @@ -139,7 +151,14 @@ public HttpResponse<BrAPIProgramListResponse> programsGet(@PathVariable("program
@QueryValue("page") Optional<Integer> page,
@QueryValue("pageSize") Optional<Integer> pageSize) {

List<BrAPIProgram> programs = programService.getById(programId).stream().filter(program -> {
//If programId supplied, check if program exists
if (programId != null) {
Optional<Program> optProgram = programService.getById(programId);
if (optProgram.isEmpty()) {
return HttpResponse.status(HttpStatus.NOT_FOUND, "Program not found");
}

List<BrAPIProgram> programs = optProgram.stream().filter(program -> {
boolean matches = abbreviation.map(abbr -> abbr.equals(program.getKey())).orElse(true);
matches = matches && programDbId.map(id -> id.equals(program.getId().toString())).orElse(true);
return matches && programName.map(name -> name.equals(program.getName())).orElse(true);
Expand All @@ -150,6 +169,9 @@ public HttpResponse<BrAPIProgramListResponse> programsGet(@PathVariable("program
.totalCount(programs.size())
.pageSize(programs.size())))
.result(new BrAPIProgramListResponseResult().data(programs)));
} else {
return HttpResponse.status(HttpStatus.NOT_FOUND, "Program not found");
}
}

@Post("/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/programs")
Expand Down
80 changes: 0 additions & 80 deletions src/main/java/org/breedinginsight/brapi/v2/ProgramController.java

This file was deleted.