Skip to content

Commit

Permalink
SCRUM-4185 update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgibs committed Jul 9, 2024
1 parent 644e2cb commit 2df4c73
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.alliancegenome.curation_api.exceptions.ObjectUpdateException.ObjectUpdateExceptionData;
import org.alliancegenome.curation_api.interfaces.AGRCurationSchemaVersion;
import org.alliancegenome.curation_api.model.entities.SequenceTargetingReagent;
import org.alliancegenome.curation_api.model.entities.associations.sequenceTargetingReagentAssociations.SequenceTargetingReagentGeneAssociation;
import org.alliancegenome.curation_api.model.entities.bulkloads.BulkFMSLoad;
import org.alliancegenome.curation_api.model.entities.bulkloads.BulkLoadFile;
import org.alliancegenome.curation_api.model.entities.bulkloads.BulkLoadFileHistory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package org.alliancegenome.curation_api.services;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import org.alliancegenome.curation_api.constants.EntityFieldConstants;
import org.alliancegenome.curation_api.dao.SequenceTargetingReagentDAO;
import org.alliancegenome.curation_api.enums.BackendBulkDataProvider;
import org.alliancegenome.curation_api.exceptions.ObjectUpdateException;
import org.alliancegenome.curation_api.interfaces.crud.BaseUpsertServiceInterface;
import org.alliancegenome.curation_api.model.entities.Gene;
import org.alliancegenome.curation_api.model.entities.SequenceTargetingReagent;
import org.alliancegenome.curation_api.model.entities.associations.sequenceTargetingReagentAssociations.SequenceTargetingReagentGeneAssociation;
import org.alliancegenome.curation_api.model.ingest.dto.fms.SequenceTargetingReagentFmsDTO;
import org.alliancegenome.curation_api.services.base.BaseEntityCrudService;
import org.alliancegenome.curation_api.services.validation.dto.fms.SequenceTargetingReagentFmsDTOValidator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@

import org.alliancegenome.curation_api.constants.EntityFieldConstants;
import org.alliancegenome.curation_api.dao.associations.SequenceTargetingReagentGeneAssociationDAO;
import org.alliancegenome.curation_api.dao.associations.alleleAssociations.AlleleGeneAssociationDAO;
import org.alliancegenome.curation_api.enums.BackendBulkDataProvider;
import org.alliancegenome.curation_api.exceptions.ObjectUpdateException;
import org.alliancegenome.curation_api.interfaces.crud.BaseUpsertServiceInterface;
import org.alliancegenome.curation_api.model.entities.Gene;
import org.alliancegenome.curation_api.model.entities.SequenceTargetingReagent;
import org.alliancegenome.curation_api.model.entities.associations.alleleAssociations.AlleleGeneAssociation;
import org.alliancegenome.curation_api.model.entities.associations.sequenceTargetingReagentAssociations.SequenceTargetingReagentGeneAssociation;
import org.alliancegenome.curation_api.model.ingest.dto.associations.alleleAssociations.AlleleGeneAssociationDTO;
import org.alliancegenome.curation_api.model.ingest.dto.fms.SequenceTargetingReagentFmsDTO;
import org.alliancegenome.curation_api.services.base.BaseAssociationDTOCrudService;
import org.alliancegenome.curation_api.services.validation.associations.SequenceTargetingReagentGeneAssociationFmsDTOValidator;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,61 @@

@RequestScoped
public class SequenceTargetingReagentGeneAssociationFmsDTOValidator {
@Inject SequenceTargetingReagentDAO sqtrDAO;
@Inject VocabularyTermService vocabularyTermService;
@Inject GeneService geneService;
@Inject
SequenceTargetingReagentDAO sqtrDAO;
@Inject
VocabularyTermService vocabularyTermService;
@Inject
GeneService geneService;

public List<SequenceTargetingReagentGeneAssociation> validateSQTRGeneAssociationFmsDTO( SequenceTargetingReagentFmsDTO dto, BackendBulkDataProvider beDataProvider) throws ObjectValidationException {
List<SequenceTargetingReagentGeneAssociation> strGeneAssociations = new ArrayList<>();
ObjectResponse<SequenceTargetingReagent> sqtrResponse = new ObjectResponse<>();
public List<SequenceTargetingReagentGeneAssociation> validateSQTRGeneAssociationFmsDTO(SequenceTargetingReagentFmsDTO dto, BackendBulkDataProvider beDataProvider) throws ObjectValidationException {
List<SequenceTargetingReagentGeneAssociation> strGeneAssociations = new ArrayList<>();
ObjectResponse<SequenceTargetingReagent> sqtrResponse = new ObjectResponse<>();

SequenceTargetingReagent sqtr;
SearchResponse<SequenceTargetingReagent> sqtrSearchResponse = sqtrDAO.findByField("modEntityId", dto.getPrimaryId());
SequenceTargetingReagent sqtr;
SearchResponse<SequenceTargetingReagent> sqtrSearchResponse = sqtrDAO.findByField("modEntityId",
dto.getPrimaryId());

if (sqtrSearchResponse == null || sqtrSearchResponse.getSingleResult() == null) {
sqtrResponse.addErrorMessage("modEntityId",
ValidationConstants.INVALID_MESSAGE + " (" + dto.getPrimaryId() + ")");
sqtr = new SequenceTargetingReagent();
} else {
sqtr = sqtrSearchResponse.getSingleResult();
}
if (sqtrSearchResponse == null || sqtrSearchResponse.getSingleResult() == null) {
sqtrResponse.addErrorMessage("modEntityId",
ValidationConstants.INVALID_MESSAGE + " (" + dto.getPrimaryId() + ")");
sqtr = new SequenceTargetingReagent();
} else {
sqtr = sqtrSearchResponse.getSingleResult();
}

VocabularyTerm relation;
SearchResponse<VocabularyTerm> relationSearchResponse = vocabularyTermService.findByField("name", "targets");
if (relationSearchResponse == null || relationSearchResponse.getSingleResult() == null) {
sqtrResponse.addErrorMessage("relation", ValidationConstants.INVALID_MESSAGE + " (" + "targets" + ")");
relation = new VocabularyTerm();
} else {
relation = relationSearchResponse.getSingleResult();
}
VocabularyTerm relation;
SearchResponse<VocabularyTerm> relationSearchResponse = vocabularyTermService.findByField("name", "targets");
if (relationSearchResponse == null || relationSearchResponse.getSingleResult() == null) {
sqtrResponse.addErrorMessage("relation", ValidationConstants.INVALID_MESSAGE + " (" + "targets" + ")");
relation = new VocabularyTerm();
} else {
relation = relationSearchResponse.getSingleResult();
}

if(dto.getTargetGeneIds() != null){
for (String geneId : dto.getTargetGeneIds()) {
Gene gene = geneService.findByIdentifierString(geneId);

if (gene == null) {
sqtrResponse.addErrorMessage("targetGeneIds",
ValidationConstants.INVALID_MESSAGE + " (" + geneId + ")");
} else {
SequenceTargetingReagentGeneAssociation strGeneAssociation = new SequenceTargetingReagentGeneAssociation();
strGeneAssociation.setSequenceTargetingReagentAssociationSubject(sqtr);
strGeneAssociation.setRelation(relation);
strGeneAssociation.setSequenceTargetingReagentGeneAssociationObject(gene);

strGeneAssociations.add(strGeneAssociation);
}

}
}

if (sqtrResponse.hasErrors()) {
throw new ObjectValidationException(dto, sqtrResponse.errorMessagesString());
}
if (dto.getTargetGeneIds() != null) {
for (String geneId : dto.getTargetGeneIds()) {
Gene gene = geneService.findByIdentifierString(geneId);

return strGeneAssociations;
}
if (gene == null) {
sqtrResponse.addErrorMessage("targetGeneIds",
ValidationConstants.INVALID_MESSAGE + " (" + geneId + ")");
} else {
SequenceTargetingReagentGeneAssociation strGeneAssociation = new SequenceTargetingReagentGeneAssociation();
strGeneAssociation.setSequenceTargetingReagentAssociationSubject(sqtr);
strGeneAssociation.setRelation(relation);
strGeneAssociation.setSequenceTargetingReagentGeneAssociationObject(gene);

strGeneAssociations.add(strGeneAssociation);
}

}
}

if (sqtrResponse.hasErrors()) {
throw new ObjectValidationException(dto, sqtrResponse.errorMessagesString());
}

return strGeneAssociations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,17 @@ public void sqtrBulkUploadCheckFields() throws Exception {
@Order(2)
public void sqtrBulkUploadMissingRequiredFields() throws Exception {

checkFailedBulkLoad(
sqtrBulkPostEndpoint,
sqtrTestFilePath + "MR_01_no_name.json",
2,
1,
1
);
checkFailedBulkLoad(
sqtrBulkPostEndpoint,
sqtrTestFilePath + "MR_02_no_taxon.json",
2,
1,
1
);
checkFailedBulkLoad(sqtrBulkPostEndpoint, sqtrTestFilePath + "MR_01_no_name.json", 2, 1, 1);
checkFailedBulkLoad(sqtrBulkPostEndpoint, sqtrTestFilePath + "MR_02_no_taxon.json", 2, 1, 1);
}

@Test
@Order(3)
public void sqtrBulkUploadEmptyRequiredFields() throws Exception {

checkFailedBulkLoad(
sqtrBulkPostEndpoint,
sqtrTestFilePath + "ER_01_empty_name.json",
2,
1,
1
);

checkFailedBulkLoad(
sqtrBulkPostEndpoint,
sqtrTestFilePath + "ER_02_empty_taxon.json",
2,
1,
1
);
checkFailedBulkLoad(sqtrBulkPostEndpoint, sqtrTestFilePath + "ER_01_empty_name.json", 2, 1, 1);

checkFailedBulkLoad(sqtrBulkPostEndpoint, sqtrTestFilePath + "ER_02_empty_taxon.json", 2, 1, 1);

}

Expand Down

0 comments on commit 2df4c73

Please sign in to comment.