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
@@ -1,4 +1,4 @@
package org.breedinginsight.brapi.v2;
package org.breedinginsight.api.v1.controller;

import io.micronaut.http.HttpHeaders;
import io.micronaut.http.HttpResponse;
Expand All @@ -9,28 +9,22 @@
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
import lombok.extern.slf4j.Slf4j;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.brapi.v2.model.core.BrAPITrial;
import org.breedinginsight.api.auth.ProgramSecured;
import org.breedinginsight.api.auth.ProgramSecuredRoleGroup;
import org.breedinginsight.api.model.v1.request.query.SearchRequest;
import org.breedinginsight.api.model.v1.response.DataResponse;
import org.breedinginsight.api.model.v1.response.Response;
import org.breedinginsight.api.model.v1.validators.QueryValid;
import org.breedinginsight.brapi.v1.controller.BrapiVersion;
import org.breedinginsight.brapi.v2.model.request.query.ExperimentExportQuery;
import org.breedinginsight.brapi.v2.model.request.query.ExperimentQuery;
import org.breedinginsight.brapi.v2.services.BrAPITrialService;
import org.breedinginsight.model.Dataset;
import org.breedinginsight.model.DownloadFile;
import org.breedinginsight.model.Program;
import org.breedinginsight.services.ProgramService;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.utilities.response.ResponseUtils;
import org.breedinginsight.utilities.response.mappers.ExperimentQueryMapper;

import javax.inject.Inject;
import javax.validation.Valid;
import java.util.*;
import java.util.Optional;
import java.util.UUID;

@Slf4j
@Controller
Expand All @@ -47,48 +41,6 @@ public ExperimentController(BrAPITrialService experimentService, ExperimentQuery
this.programService = programService;
}

@Get("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/trials{?queryParams*}")
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse<Response<DataResponse<List<BrAPITrial>>>> getExperiments(
@PathVariable("programId") UUID programId,
@QueryValue @QueryValid(using = ExperimentQueryMapper.class) @Valid ExperimentQuery queryParams) {
try {
log.debug("fetching trials for program: " + programId);

List<BrAPITrial> experiments = experimentService.getExperiments(programId);
SearchRequest searchRequest = queryParams.constructSearchRequest();
return ResponseUtils.getBrapiQueryResponse(experiments, experimentQueryMapper, queryParams, searchRequest);
} catch (ApiException e) {
log.info(e.getMessage(), e);
return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving experiments");
} catch (DoesNotExistException e) {
log.info(e.getMessage(), e);
return HttpResponse.status(HttpStatus.NOT_FOUND, e.getMessage());
}
}

@Get("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/trials/{trialId}")
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse<Response<BrAPITrial>> getExperimentById(
@PathVariable("programId") UUID programId,
@PathVariable("trialId") UUID trialId,
@QueryValue(defaultValue = "false") Boolean stats){
try {
String logMsg = "fetching trial id:" + trialId +" for program: " + programId;
if(stats){
logMsg += " with stats";
}
log.debug(logMsg);
Response<BrAPITrial> response = new Response<>(experimentService.getTrialDataByUUID(programId, trialId, stats));
return HttpResponse.ok(response);
} catch (DoesNotExistException e) {
log.info(e.getMessage(), e);
return HttpResponse.status(HttpStatus.NOT_FOUND, e.getMessage());
}
}

@Get("/${micronaut.bi.api.version}/programs/{programId}/experiments/{experimentId}/export{?queryParams*}")
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
@Produces(value={"text/csv", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/octet-stream"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public TokenController(SecurityService securityService, TokenService tokenServic

@Get("/api-token{?returnUrl}")
@Secured(SecurityRule.IS_AUTHENTICATED)
public HttpResponse apiToken(@QueryValue @Nullable String returnUrl) {
public HttpResponse<?> apiToken(@QueryValue @Nullable String returnUrl) {

AuthenticatedUser actingUser = securityService.getUser();
Optional<ApiToken> token = tokenService.generateApiToken(actingUser);
Expand All @@ -61,12 +61,12 @@ public HttpResponse apiToken(@QueryValue @Nullable String returnUrl) {
ApiToken apiToken = token.get();

if(returnUrl != null) {
if(StringUtils.trim(returnUrl).isEmpty()) {
if(StringUtils.trim(returnUrl).isEmpty() || "undefined".equalsIgnoreCase(returnUrl)) {
return HttpResponse.badRequest("returnUrl cannot be blank");
}
URI location = UriBuilder.of(returnUrl)
.queryParam("status", 200)
.queryParam("token", apiToken.getAccessToken())
.queryParam("access_token", apiToken.getAccessToken())
.build();

return HttpResponse.seeOther(location)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.breedinginsight.api.v1.controller.auth;

import io.micronaut.context.annotation.Property;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Produces;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
import org.breedinginsight.dao.db.tables.pojos.ProgramEntity;
import org.breedinginsight.daos.ProgramDAO;

import javax.inject.Inject;
import java.util.UUID;

@Controller
@Secured(SecurityRule.IS_ANONYMOUS)
public class OIDCDiscoveryController {

private static final String OIDC_CONFIG = " {\n" +
" \"issuer\": \"%s\",\n" +
" \"authorization_endpoint\": \"%s/programs/%s/brapi/authorize\",\n" +
" \"jwks_uri\": \"\",\n" +
" \"token_endpoint\": \"\",\n" +
" \"grant_types_supported\": [\"implicit\"],\n" +
" \"response_types_supported\": [\"token\"],\n" +
" \"subject_types_supported\": [\"public\"],\n" +
" \"id_token_signing_alg_values_supported\": []\n" +
" }\n";

private final String webUrl;
private final ProgramDAO programDAO;

@Inject
public OIDCDiscoveryController(@Property(name="web.base-url") String webUrl, ProgramDAO programDAO) {
this.webUrl = webUrl;
this.programDAO = programDAO;
}


@Get("/${micronaut.bi.api.version}/programs/{programId}/.well-known/openid-configuration")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse getOpenIdConfig(UUID programId) {
ProgramEntity programEntity = programDAO.fetchOneById(programId);
if(programEntity != null) {
return HttpResponse.ok(String.format(OIDC_CONFIG, webUrl, webUrl, programId));
}

return HttpResponse.notFound("unknown program");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
@Slf4j
@Controller("/${micronaut.bi.api.version}")
@Secured(SecurityRule.IS_AUTHENTICATED)
public class GermplasmController {
public class BrAPIGermplasmController {

private final BrAPIGermplasmService germplasmService;
private final GermplasmQueryMapper germplasmQueryMapper;
Expand All @@ -64,7 +64,7 @@ public class GermplasmController {


@Inject
public GermplasmController(BrAPIGermplasmService germplasmService, GermplasmQueryMapper germplasmQueryMapper, ProgramDAO programDAO, BrAPIGermplasmDAO germplasmDAO, GenotypeService genoService, BrAPIEndpointProvider brAPIEndpointProvider) {
public BrAPIGermplasmController(BrAPIGermplasmService germplasmService, GermplasmQueryMapper germplasmQueryMapper, ProgramDAO programDAO, BrAPIGermplasmDAO germplasmDAO, GenotypeService genoService, BrAPIEndpointProvider brAPIEndpointProvider) {
this.germplasmService = germplasmService;
this.germplasmQueryMapper = germplasmQueryMapper;
this.programDAO = programDAO;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.breedinginsight.brapi.v2;

import io.micronaut.http.HttpResponse;
import io.micronaut.http.annotation.*;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
import lombok.extern.slf4j.Slf4j;
import org.brapi.v2.model.pheno.BrAPIImage;
import org.breedinginsight.api.auth.ProgramSecured;
import org.breedinginsight.api.auth.ProgramSecuredRoleGroup;
import org.breedinginsight.brapi.v1.controller.BrapiVersion;

import java.util.List;
import java.util.UUID;

@Slf4j
@Controller("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2)
@Secured(SecurityRule.IS_AUTHENTICATED)
public class BrAPIImagesController {
/*
TODO
- POST images
- PUT imagesImageDbIdImagecontent
- PUT imagesImageDbIdPut
*/
@Get("/images")
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse imagesGet(@PathVariable("programId") UUID programId,
@QueryValue("imageDbId") String imageDbId,
@QueryValue("imageName") String imageName,
@QueryValue("observationUnitDbId") String observationUnitDbId,
@QueryValue("observationDbId") String observationDbId,
@QueryValue("descriptiveOntologyTerm") String descriptiveOntologyTerm,
@QueryValue("commonCropName") String commonCropName,
@QueryValue("programDbId") String programDbId,
@QueryValue("externalReferenceID") String externalReferenceID,
@QueryValue("externalReferenceId") String externalReferenceId,
@QueryValue("externalReferenceSource") String externalReferenceSource,
@QueryValue("page") Integer page,
@QueryValue("pageSize") Integer pageSize) {
return HttpResponse.notFound();
}

@Get("/images/{imageDbId}")
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse imagesImageDbIdGet(@PathVariable("programId") UUID programId,
@PathVariable("imageDbId") String imageDbId) {
return HttpResponse.notFound();
}

@Put("/images/{imageDbId}/imagecontent")
@Consumes({"image/_*"})
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse imagesImageDbIdImagecontentPut(@PathVariable("programId") UUID programId,
@PathVariable("imageDbId") String imageDbId,
@Body Object body) {
return HttpResponse.notFound();
}

@Put("/images/{imageDbId}")
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse imagesImageDbIdPut(@PathVariable("programId") UUID programId,
@PathVariable("imageDbId") String imageDbId,
@Body BrAPIImage body) {
return HttpResponse.notFound();
}

@Post("/images")
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse imagesPost(@PathVariable("programId") UUID programId, @Body List<BrAPIImage> body) {
return HttpResponse.notFound();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@
@Slf4j
@Controller
@Secured(SecurityRule.IS_AUTHENTICATED)
public class ListController {
public class BrAPIListController {

private final ProgramService programService;
private final BrAPIListService listService;
private final ListQueryMapper listQueryMapper;

@Inject
public ListController(ProgramService programService, BrAPIListService listService,
ListQueryMapper listQueryMapper) {
public BrAPIListController(ProgramService programService, BrAPIListService listService,
ListQueryMapper listQueryMapper) {
this.programService = programService;
this.listService = listService;
this.listQueryMapper = listQueryMapper;
Expand Down
Loading