From a6bac326bf842785a715379c6607810eeacd3e3d Mon Sep 17 00:00:00 2001 From: christophe mangeat Date: Wed, 10 Jul 2024 21:16:54 +0200 Subject: [PATCH] restore 'restrained' link analysis --- .../repository/specification/LinkSpecs.java | 12 ++++++++++ .../fao/geonet/api/links/MAnalyseProcess.java | 22 +++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/domain/src/main/java/org/fao/geonet/repository/specification/LinkSpecs.java b/domain/src/main/java/org/fao/geonet/repository/specification/LinkSpecs.java index cd77c680549..279096be47f 100644 --- a/domain/src/main/java/org/fao/geonet/repository/specification/LinkSpecs.java +++ b/domain/src/main/java/org/fao/geonet/repository/specification/LinkSpecs.java @@ -146,4 +146,16 @@ public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBu } }; } + + public static Specification filterOnRecords(Integer[] mdIds) { + + return new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) { + query.distinct(true); + Join metadataJoin = (Join) root.fetch(Link_.records, JoinType.LEFT); + return cb.and(metadataJoin.get(MetadataLink_.metadataId).in(mdIds)); + } + }; + } } diff --git a/services/src/main/java/org/fao/geonet/api/links/MAnalyseProcess.java b/services/src/main/java/org/fao/geonet/api/links/MAnalyseProcess.java index 52df584dabe..405d6aa0b3f 100644 --- a/services/src/main/java/org/fao/geonet/api/links/MAnalyseProcess.java +++ b/services/src/main/java/org/fao/geonet/api/links/MAnalyseProcess.java @@ -7,6 +7,7 @@ import org.fao.geonet.kernel.url.UrlAnalyzer; import org.fao.geonet.repository.LinkRepository; import org.fao.geonet.repository.MetadataRepository; +import org.fao.geonet.repository.specification.LinkSpecs; import org.jdom.Element; import org.jdom.JDOMException; import org.springframework.context.ApplicationContext; @@ -143,29 +144,18 @@ public Object doInTransaction(TransactionStatus transaction) throws Throwable { e.printStackTrace(); } } - if (testLink) { - testLink(null); - } + if (!testLink || ids.size() == 0) { + return; } + List links = linkRepository.findAll(LinkSpecs.filterOnRecords(ids.toArray(new Integer[0]))); - public void testLink(List links) throws JDOMException, IOException { - List linkList; - if (links == null) { - linkList = linkRepository.findAll(); - } else { - linkList = linkRepository.findAllByUrlIn(links); - } - urlToCheckCount = linkList.size(); runInNewTransaction("manalyseprocess-testlink", new TransactionTask() { @Override public Object doInTransaction(TransactionStatus transaction) throws Throwable { testLinkDate = System.currentTimeMillis(); - urlToCheckCount = linkList.size(); - linkList - .parallelStream() - .peek(urlAnalyser::testLink) - .forEach(x -> urlChecked.getAndIncrement()); + urlToCheckCount = links.size(); + links.parallelStream().peek(urlAnalyser::testLink).forEach(x -> urlChecked.getAndIncrement()); return null; } });