From ca6b5eb2666a97552af5e3546fafdbe3460f7ca6 Mon Sep 17 00:00:00 2001 From: Ryan Taylor <90803397+rtaylorzfin@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:31:45 -0800 Subject: [PATCH] Fix publication repository tests with workaround (#1215) --- .../service/CurationDTOConversionService.java | 11 ++++++++++- .../org/zfin/search/service/RelatedDataService.java | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/source/org/zfin/curation/service/CurationDTOConversionService.java b/source/org/zfin/curation/service/CurationDTOConversionService.java index 8f58be3cc9..65682a6dd7 100644 --- a/source/org/zfin/curation/service/CurationDTOConversionService.java +++ b/source/org/zfin/curation/service/CurationDTOConversionService.java @@ -213,10 +213,19 @@ public DashboardPublicationBean toDashboardPublicationBean(PublicationTrackingHi public void setRelatedLinks(DashboardPublicationList result) { List ids = result.getPublications().stream().map(DashboardPublicationBean::getZdbId).toList(); - Map> relatedLinks = relatedDataService.getRelatedLinksForPubIDs(ids); + Map> relatedLinks = getRelatedDataService().getRelatedLinksForPubIDs(ids); for (DashboardPublicationBean bean : result.getPublications()) { bean.setRelatedLinks(relatedLinks.get(bean.getZdbId())); } } + + private RelatedDataService getRelatedDataService() { + //TODO: This method shouldn't be necessary, but for some reason + // tests like PublicationRepositoryTest don't autowire multiple levels + if (relatedDataService == null) { + relatedDataService = new RelatedDataService(); + } + return relatedDataService; + } } diff --git a/source/org/zfin/search/service/RelatedDataService.java b/source/org/zfin/search/service/RelatedDataService.java index 09e519f16c..8fe777b22d 100644 --- a/source/org/zfin/search/service/RelatedDataService.java +++ b/source/org/zfin/search/service/RelatedDataService.java @@ -428,7 +428,7 @@ public List getXrefLinks(SearchResult result) { public List getXrefsLinks(String id, String category, String type) { List links = new ArrayList<>(); - QueryResponse response = solrService.getRelatedDataResponse(id); + QueryResponse response = getSolrService().getRelatedDataResponse(id); FacetField facetField = response.getFacetField("category"); @@ -603,4 +603,13 @@ public static String lookup(String resultCategory, String resultType, String rel } } + private SolrService getSolrService() { + //TODO: This method shouldn't be necessary, but for some reason + // tests like PublicationRepositoryTest don't autowire multiple levels + if (solrService == null) { + solrService = new SolrService(); + } + return solrService; + } + }