Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
@@ -0,0 +1,49 @@
/*
* 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.model.v1.request.query;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.micronaut.core.annotation.Introspected;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.breedinginsight.api.v1.controller.metadata.SortOrder;
import org.breedinginsight.brapps.importer.model.exports.FileType;

import javax.validation.constraints.Positive;


@Getter
@Setter
@Introspected
@NoArgsConstructor
public class DatasetParams implements FileDownloadParams {

private static String DEFAULT_FILETYPE_NAME = FileType.XLSX.getName();

private String fileExtension;
private String dataset;
private String environments;
@JsonIgnore
private boolean includeTimestamps;

public String getDefaultFileTypeName() {
return DEFAULT_FILETYPE_NAME;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.model.v1.request.query;

public interface FileDownloadParams {

String getDefaultFileTypeName();
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.breedinginsight.brapi.v2;

import io.micronaut.http.HttpHeaders;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
import io.micronaut.http.server.types.files.StreamedFile;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -16,30 +18,33 @@
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.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.HashMap;
import java.util.List;
import java.util.UUID;

@Slf4j
@Controller
@Secured(SecurityRule.IS_AUTHENTICATED)
public class ExperimentController {

private final BrAPITrialService experimentService;
private final ExperimentQueryMapper experimentQueryMapper;
private final ProgramService programService;

@Inject
public ExperimentController(BrAPITrialService experimentService, ExperimentQueryMapper experimentQueryMapper) {
public ExperimentController(BrAPITrialService experimentService, ExperimentQueryMapper experimentQueryMapper, ProgramService programService) {
this.experimentService = experimentService;
this.experimentQueryMapper = experimentQueryMapper;
this.programService = programService;
}

@Get("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/trials{?queryParams*}")
Expand Down Expand Up @@ -83,4 +88,29 @@ public HttpResponse<Response<BrAPITrial>> getExperimentById(
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"})
public HttpResponse<StreamedFile> datasetExport(
@PathVariable("programId") UUID programId, @PathVariable("experimentId") UUID experimentId,
@QueryValue @Valid ExperimentExportQuery queryParams) {
String downloadErrorMessage = "An error occurred while generating the download file. Contact the development team at bidevteam@cornell.edu.";
try {
Program program = programService.getById(programId).orElseThrow(() -> new DoesNotExistException("Program does not exist"));
DownloadFile datasetFile = experimentService.exportObservations(program, experimentId, queryParams);
HttpResponse<StreamedFile> response = HttpResponse
.ok(datasetFile.getStreamedFile())
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + datasetFile.getFileName());
return response;
} catch (Exception e) {
log.info(e.getMessage(), e);
HttpResponse response = HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, downloadErrorMessage).contentType(MediaType.TEXT_PLAIN).body(downloadErrorMessage);
return response;
}


}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.breedinginsight.brapi.v2.model.request.query;

import io.micronaut.core.annotation.Introspected;
import lombok.Getter;
import org.breedinginsight.api.model.v1.request.query.FilterRequest;
import org.breedinginsight.api.model.v1.request.query.SearchRequest;
import org.breedinginsight.brapi.v1.model.request.query.BrapiQuery;
import org.breedinginsight.brapps.importer.model.exports.FileType;
import org.jooq.tools.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

@Getter
@Introspected
public class ExperimentExportQuery {
private FileType fileExtension;
private String dataset;
private String environments;
@NotNull
private boolean includeTimestamps;

}
Loading