Skip to content
Merged
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.model.v1.request.query;
Comment thread
nickpalladino marked this conversation as resolved.

import io.micronaut.core.annotation.Introspected;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Getter
@Introspected
public class GenotypeImportQuery extends QueryParams {

private String sampleSubmissionId;
private String projectNameForSampleSubmission;
private String sampleSubmissionCreatedBy;
private String genotypingFileName;
private String genotypingImportDate;
private String genotypingImportBy;

public SearchRequest constructSearchRequest() {
List<FilterRequest> filters = new ArrayList<>();

if (!StringUtils.isBlank(getSampleSubmissionId())) {
filters.add(constructFilterRequest("sampleSubmissionId", getSampleSubmissionId()));
}
if (!StringUtils.isBlank(getProjectNameForSampleSubmission())) {
filters.add(constructFilterRequest("projectNameForSampleSubmission", getProjectNameForSampleSubmission()));
}
if (!StringUtils.isBlank(getSampleSubmissionCreatedBy())) {
filters.add(constructFilterRequest("sampleSubmissionCreatedBy", getSampleSubmissionCreatedBy()));
}
if (!StringUtils.isBlank(getGenotypingFileName())) {
filters.add(constructFilterRequest("genotypingFileName", getGenotypingFileName()));
}
if (!StringUtils.isBlank(getGenotypingImportDate())) {
filters.add(constructFilterRequest("genotypingImportDate", getGenotypingImportDate()));
}
if (!StringUtils.isBlank(getGenotypingImportBy())) {
filters.add(constructFilterRequest("genotypingImportBy", getGenotypingImportBy()));
}

return new SearchRequest(filters);
}

private FilterRequest constructFilterRequest(String field, String value) {
return FilterRequest.builder()
.field(field)
.value(value)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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.geno;

import io.micronaut.http.HttpResponse;
Expand All @@ -6,30 +22,65 @@
import io.micronaut.http.multipart.CompletedFileUpload;
import lombok.extern.slf4j.Slf4j;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.breedinginsight.api.auth.AuthenticatedUser;
import org.breedinginsight.api.auth.ProgramSecured;
import org.breedinginsight.api.auth.ProgramSecuredRole;
import org.breedinginsight.api.auth.SecurityService;
import org.breedinginsight.api.auth.*;
import org.breedinginsight.api.model.v1.request.query.GenotypeImportQuery;
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.api.v1.controller.metadata.AddMetadata;
import org.breedinginsight.brapps.importer.model.response.ImportResponse;
import org.breedinginsight.model.GenotypeImportDetails;
import org.breedinginsight.model.Program;
import org.breedinginsight.services.ProgramService;
import org.breedinginsight.services.exceptions.AuthorizationException;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.services.geno.GenotypeService;
import org.breedinginsight.utilities.response.ResponseUtils;
import org.breedinginsight.utilities.response.mappers.GenotypeImportQueryMapper;

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

@Slf4j
@Controller("/${micronaut.bi.api.version}")
public class GenotypeDataUploadController {
private final GenotypeService genoService;
private final SecurityService securityService;
private final ProgramService programService;
private final GenotypeImportQueryMapper genotypeImportQueryMapper;

@Inject
public GenotypeDataUploadController(GenotypeService genoService, SecurityService securityService) {
public GenotypeDataUploadController(GenotypeService genoService, SecurityService securityService,
ProgramService programService, GenotypeImportQueryMapper genotypeImportQueryMapper) {
this.genoService = genoService;
this.securityService = securityService;
this.programService = programService;
this.genotypeImportQueryMapper = genotypeImportQueryMapper;
}

@Get("programs/{programId}/geno/imports{?genotypeImportQuery*}")
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES)
public HttpResponse<Response<DataResponse<GenotypeImportDetails>>> getGenotypeImports(
@PathVariable UUID programId,
@QueryValue @QueryValid(using = GenotypeImportQueryMapper.class) @Valid GenotypeImportQuery genotypeImportQuery) {
Optional<Program> program = programService.getById(programId);
if (program.isEmpty()) {
log.info("programId not found: {}", programId.toString());
return HttpResponse.notFound();
}

SearchRequest searchRequest = genotypeImportQuery.constructSearchRequest();

return ResponseUtils.getQueryResponse(
genoService.getGenotypeImports(programId),
genotypeImportQueryMapper,
searchRequest,
genotypeImportQuery
);
}

@Post("programs/{programId}/submissions/{submissionId}/geno/import")
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/org/breedinginsight/daos/GenotypeImportDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.daos;

import io.micronaut.http.HttpStatus;
import org.breedinginsight.dao.db.tables.BiUserTable;
import org.breedinginsight.dao.db.tables.daos.GenotypeImportDao;
import org.breedinginsight.dao.db.tables.pojos.GenotypeImportEntity;
import org.breedinginsight.model.GenotypeImportDetails;
import org.jooq.Configuration;
import org.jooq.DSLContext;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.UUID;

import static org.breedinginsight.dao.db.Tables.*;

@Singleton
public class GenotypeImportDAO extends GenotypeImportDao {

private final DSLContext dsl;

@Inject
public GenotypeImportDAO(Configuration config, DSLContext dsl) {
super(config);
this.dsl = dsl;
}

public void createGenotypeImportLink(UUID submissionId, UUID importerImportId, UUID userId) {
OffsetDateTime now = OffsetDateTime.now();

insert(GenotypeImportEntity.builder()
.id(UUID.randomUUID())
.sampleSubmissionId(submissionId)
.importerImportId(importerImportId)
.createdAt(now)
.updatedAt(now)
.createdBy(userId)
.updatedBy(userId)
.build());
}

public List<GenotypeImportDetails> getGenotypeImportsByProgramId(UUID programId) {
BiUserTable sampleSubmissionCreatedByUser = BI_USER.as("sampleSubmissionCreatedByUser");
BiUserTable genotypingImportByUser = BI_USER.as("genotypingImportByUser");

return dsl.select(
SAMPLE_SUBMISSION.ID,
SAMPLE_SUBMISSION.NAME,
sampleSubmissionCreatedByUser.NAME,
IMPORTER_IMPORT.UPLOAD_FILE_NAME,
IMPORTER_IMPORT.CREATED_AT,
genotypingImportByUser.NAME)
.from(GENOTYPE_IMPORT)
.join(SAMPLE_SUBMISSION).on(GENOTYPE_IMPORT.SAMPLE_SUBMISSION_ID.eq(SAMPLE_SUBMISSION.ID))
.join(sampleSubmissionCreatedByUser).on(SAMPLE_SUBMISSION.CREATED_BY.eq(sampleSubmissionCreatedByUser.ID))
.join(IMPORTER_IMPORT).on(GENOTYPE_IMPORT.IMPORTER_IMPORT_ID.eq(IMPORTER_IMPORT.ID))
.join(IMPORTER_PROGRESS).on(IMPORTER_IMPORT.IMPORTER_PROGRESS_ID.eq(IMPORTER_PROGRESS.ID))
.join(genotypingImportByUser).on(IMPORTER_IMPORT.USER_ID.eq(genotypingImportByUser.ID))
.where(SAMPLE_SUBMISSION.PROGRAM_ID.eq(programId))
.and(IMPORTER_IMPORT.PROGRAM_ID.eq(programId))
.and(IMPORTER_PROGRESS.STATUSCODE.eq((short) HttpStatus.OK.getCode()))
.orderBy(IMPORTER_IMPORT.CREATED_AT.desc())
.fetch(record -> GenotypeImportDetails
.parseSqlRecord(record, sampleSubmissionCreatedByUser, genotypingImportByUser));
}

}
65 changes: 65 additions & 0 deletions src/main/java/org/breedinginsight/model/GenotypeImportDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.model;
Comment thread
nickpalladino marked this conversation as resolved.

import io.micronaut.core.annotation.Introspected;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;
import org.breedinginsight.dao.db.tables.BiUserTable;
import org.jooq.Record;

import java.time.OffsetDateTime;
import java.util.UUID;

import static org.breedinginsight.dao.db.Tables.IMPORTER_IMPORT;
import static org.breedinginsight.dao.db.Tables.SAMPLE_SUBMISSION;

@Getter
@Setter
@Accessors(chain = true)
@ToString
@SuperBuilder
@NoArgsConstructor
@Introspected
@Jacksonized
public class GenotypeImportDetails {
private UUID sampleSubmissionId;
private String projectNameForSampleSubmission;
private String sampleSubmissionCreatedBy;
private String genotypingFileName;
private OffsetDateTime genotypingImportDate;
private String genotypingImportBy;

public static GenotypeImportDetails parseSqlRecord(Record record,
BiUserTable sampleSubmissionCreatedByUser,
BiUserTable genotypingImportByUser) {
return GenotypeImportDetails.builder()
.sampleSubmissionId(record.get(SAMPLE_SUBMISSION.ID))
.projectNameForSampleSubmission(record.get(SAMPLE_SUBMISSION.NAME))
.sampleSubmissionCreatedBy(record.get(sampleSubmissionCreatedByUser.NAME))
.genotypingFileName(record.get(IMPORTER_IMPORT.UPLOAD_FILE_NAME))
.genotypingImportDate(record.get(IMPORTER_IMPORT.CREATED_AT))
.genotypingImportBy(record.get(genotypingImportByUser.NAME))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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.services.geno;

import io.micronaut.http.multipart.CompletedFileUpload;
Expand All @@ -6,11 +22,15 @@
import org.breedinginsight.model.GermplasmGenotype;
import org.breedinginsight.services.exceptions.AuthorizationException;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.model.GenotypeImportDetails;

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

public interface GenotypeService {
ImportResponse submitGenotypeData(UUID userId, UUID programId, UUID submissionId, CompletedFileUpload uploadedFile) throws DoesNotExistException, AuthorizationException, ApiException;

GermplasmGenotype retrieveGenotypeData(UUID programId, UUID germplasmId) throws DoesNotExistException, AuthorizationException, ApiException;

List<GenotypeImportDetails> getGenotypeImports(UUID programId);
Comment thread
nickpalladino marked this conversation as resolved.
}
Loading
Loading