Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8203961
Remove flushalls, batch pedigree lookups from germplasm
jloux-brapi Feb 17, 2025
accc26f
Add createEntitiesInBatch method for PedigreeService to optimize batc…
jloux-brapi Feb 25, 2025
52dd04c
Batch pedigree edge functionality
jloux-brapi Mar 5, 2025
afeded8
Clean up updateEntitiesWithEdgesInBatch
jloux-brapi Mar 19, 2025
53f5919
Prevent DTO converting on pedigree for Germplasm POST Path, as data i…
jloux-brapi Mar 10, 2025
f020388
Add exref checking method to UpdateUtility
jloux-brapi Mar 10, 2025
3088807
Simplify updateGermplasmPedigree method
jloux-brapi Mar 20, 2025
76292ab
Batch crop and breeding method lookups on germ creation
jloux-brapi Mar 21, 2025
c430ebf
Apply Map optimizations on PedigreeService
jloux-brapi Mar 21, 2025
48bd507
Fix bugs related to default pagination
jloux-brapi Mar 21, 2025
6af2e8f
Add batching props to application.properties
jloux-brapi Mar 21, 2025
9b54e8d
Remove erroneous property
jloux-brapi Mar 21, 2025
d12ce0c
Add additional properties for debugging, with comments
jloux-brapi Mar 21, 2025
83b2937
Merge branch 'germ-search-opts' into germ-importer-opts
jloux-brapi Mar 21, 2025
b0a5d4b
Add general findByIdIn to BrAPIRepository to be used by importer
jloux-brapi Mar 24, 2025
ab35a5d
Merge branch 'germ-search-opts' into germ-importer-opts
jloux-brapi Apr 2, 2025
4836f33
Simplify resultingNodes logic, fix connectedNode typo
jloux-brapi Apr 3, 2025
fb1a01f
Handle empty name search use case in GermService, add mother/father w…
jloux-brapi Apr 3, 2025
449263f
Fix mispell for updateChildEdges method
jloux-brapi Apr 4, 2025
e1051b1
Rename gId to dbId in PedigreeService
jloux-brapi Apr 23, 2025
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 @@ -199,8 +199,9 @@ public ResponseEntity<GermplasmListResponse> germplasmPost(@RequestBody List<Ger
log.debug("Request: " + request.getRequestURI());
validateSecurityContext(request, "ROLE_USER");
validateAcceptHeader(request);

List<Germplasm> data = germplasmService.saveGermplasm(body);
pedigreeService.updateGermplasmPedigree(data);
pedigreeService.updateGermplasmPedigreeForPost(data);
return responseOK(new GermplasmListResponse(), new GermplasmListResponseResult(), data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.NoRepositoryBean;

@NoRepositoryBean
Expand All @@ -30,4 +31,6 @@ public interface BrAPIRepository<T extends BrAPIPrimaryEntity, ID extends Serial
public <S extends T> void refresh(S entity);

public void fetchXrefs(Page<T> page, Class<T> searchClass) throws InvalidPagingException;

List<T> findByIdIn(List<ID> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public Optional<T> findById(ID id) {
return response;
}

public List<T> findByIdIn(List<ID> ids) {
return super.findAllById(ids);
}

public <S extends T> S save(S entity) {
entity.setAuthUserId(SecurityUtils.getCurrentUserId());
return super.save(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;

public interface CropRepository extends BrAPIRepository<CropEntity, String>{
public Page<CropEntity> findByCropName(String cropName, Pageable pageRequest);

public List<CropEntity> findByCropNameIn(List<String> names);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
import org.brapi.test.BrAPITestServer.model.entity.germ.BreedingMethodEntity;
import org.brapi.test.BrAPITestServer.repository.BrAPIRepository;

public interface BreedingMethodRepository extends BrAPIRepository<BreedingMethodEntity, String>{

public interface BreedingMethodRepository extends BrAPIRepository<BreedingMethodEntity, String> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
import org.brapi.test.BrAPITestServer.repository.BrAPIRepository;

public interface CrossingProjectRepository extends BrAPIRepository<CrossingProjectEntity, String> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface GermplasmRepository extends BrAPIRepository<GermplasmEntity, St
@Transactional
@Query("UPDATE GermplasmEntity g SET g.softDeleted = :softDeleted WHERE g.id IN :germplasmIds")
int updateSoftDeletedStatusBatch(@Param("germplasmIds") List<String> germplasmIds, @Param("softDeleted") boolean softDeleted);

List<GermplasmEntity> findByGermplasmNameIn(List<String> germplasmNames);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

public interface PedigreeRepository extends BrAPIRepository<PedigreeNodeEntity, String>, PedigreeRepositoryCustom {
public List<PedigreeNodeEntity> findByGermplasm_Id(String germplasmDbId);

public List<PedigreeNodeEntity> findByGermplasm_IdIn(List<String> germplasmDbIds);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.brapi.test.BrAPITestServer.service;

import io.swagger.model.BrAPIDataModel;
import io.swagger.model.ExternalReferences;
import io.swagger.model.ExternalReferencesInner;
import org.brapi.test.BrAPITestServer.model.entity.BrAPIPrimaryEntity;
import org.brapi.test.BrAPITestServer.model.entity.ExternalReferenceEntity;

import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;

public class UpdateUtility {

Expand Down Expand Up @@ -34,12 +38,60 @@ public static <T extends BrAPIDataModel> T convertFromEntity(BrAPIPrimaryEntity
}

public static <T extends BrAPIPrimaryEntity> T updateEntity(BrAPIDataModel model, T entity) {
updateAdditionalInfo(model, entity);
if (model.getExternalReferences() != null) {
entity.setExternalReferences(model.getExternalReferences());
}
return entity;
}

private static <T extends BrAPIPrimaryEntity> void updateAdditionalInfo(BrAPIDataModel model, T entity) {
if (model.getAdditionalInfo() != null) {
entity.setAdditionalInfo(model.getAdditionalInfo());
}
}

/*
Call this method when external references are eagerly loaded for bulk updates to entities to ensure
unnecessary deletions and insertions don't occur. This will improve performance in these use cases.

WARN: If refs aren't eagerly loaded, hibernate will generate a query on the entity.getReferences() call. This could slow performance.

This method will check if the external references in the model already exist in the entity, and will prevent setting
the entity with the model's refs.

TODO: See if migrating all callers of updateEntity to this method can be done.
*/
public static <T extends BrAPIPrimaryEntity> T updateEntityCheckExRefs(BrAPIDataModel model, T entity) {
updateAdditionalInfo(model, entity);
if (model.getExternalReferences() != null) {
entity.setExternalReferences(model.getExternalReferences());

ExternalReferences exRefs = model.getExternalReferences();

Map<String, List<ExternalReferenceEntity>> existingRefsById =
entity.getExternalReferences() != null ?
entity.getExternalReferences().stream().collect(Collectors.groupingBy(ExternalReferenceEntity::getExternalReferenceId))
: Collections.emptyMap();


List<ExternalReferencesInner> newExRefs = exRefs.stream().filter(exRef -> {
List<ExternalReferenceEntity> existingEntityRefList = existingRefsById.get(exRef.getReferenceID());

if (existingEntityRefList == null || existingEntityRefList.isEmpty()) {
return true;
}

ExternalReferenceEntity existingEntityRef = existingEntityRefList.get(0);

return !existingEntityRef.getExternalReferenceSource().equals(exRef.getReferenceSource());
}).collect(Collectors.toList());

if (!newExRefs.isEmpty()) {
// Detected different ex refs than what is in the original entity. Updating entity exRefs.
entity.setExternalReferences(model.getExternalReferences());
}
// If there are no new exRefs no update is made.
}
return entity;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ public CropEntity getCropEntity(String commonCropName) throws BrAPIServerExcepti
return entity;
}

public List<CropEntity> findCropsByNames(List<String> names) {
return cropRepository.findByCropNameIn(names);
}

public CropEntity saveCropEntity(String commonCropName) throws BrAPIServerException {
CropEntity entity = null;
if (commonCropName != null) {
entity = new CropEntity();
entity.setCropName(commonCropName);
entity = cropRepository.saveAndFlush(entity);
entity = cropRepository.save(entity);
}
return entity;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.brapi.test.BrAPITestServer.service.germ;

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerDbIdNotFoundException;
import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerException;
Expand Down Expand Up @@ -52,6 +54,10 @@ public BreedingMethodEntity getBreedingMethodEntity(String breedingMethodDbId, H
return breedingMethodEntity;
}

public List<BreedingMethodEntity> findBreedingMethodsByIds(List<String> ids) {
return breedingMethodRepository.findByIdIn(ids);
}

private BreedingMethod convertFromEntity(BreedingMethodEntity entity) {
BreedingMethod method = new BreedingMethod();
method.setAbbreviation(entity.getAbbreviation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Optional;

import io.swagger.model.IndexPagination;
import jakarta.validation.Valid;

import org.brapi.test.BrAPITestServer.exceptions.BrAPIServerDbIdNotFoundException;
Expand Down Expand Up @@ -69,6 +70,10 @@ public List<CrossingProject> findCrossingProjects(String crossingProjectDbId, St
return crossingProjects;
}

public List<CrossingProjectEntity> findCrossingProjectsByIds(List<String> crossingProjectIds) {
return crossingProjectRepository.findByIdIn(crossingProjectIds);
}

public CrossingProject getCrossingProject(String crossingProjectDbId) throws BrAPIServerException {
return convertFromEntity(getCrossingProjectEntity(crossingProjectDbId, HttpStatus.NOT_FOUND));
}
Expand Down
Loading