Skip to content

Commit

Permalink
restore 'restrained' link analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
cmangeat committed Jul 10, 2024
1 parent 2838e0a commit a6bac32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,16 @@ public Predicate toPredicate(Root<Link> root, CriteriaQuery<?> query, CriteriaBu
}
};
}

public static Specification<Link> filterOnRecords(Integer[] mdIds) {

return new Specification<Link>() {
@Override
public Predicate toPredicate(Root<Link> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
query.distinct(true);
Join<Link, MetadataLink> metadataJoin = (Join<Link, MetadataLink>) root.fetch(Link_.records, JoinType.LEFT);
return cb.and(metadataJoin.get(MetadataLink_.metadataId).in(mdIds));
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -143,29 +144,18 @@ public Object doInTransaction(TransactionStatus transaction) throws Throwable {
e.printStackTrace();
}
}
if (testLink) {
testLink(null);
}
if (!testLink || ids.size() == 0) {
return;
}

List<Link> links = linkRepository.findAll(LinkSpecs.filterOnRecords(ids.toArray(new Integer[0])));

public void testLink(List<String> links) throws JDOMException, IOException {
List<Link> linkList;
if (links == null) {
linkList = linkRepository.findAll();
} else {
linkList = linkRepository.findAllByUrlIn(links);
}
urlToCheckCount = linkList.size();
runInNewTransaction("manalyseprocess-testlink", new TransactionTask<Object>() {
@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;
}
});
Expand Down

0 comments on commit a6bac32

Please sign in to comment.