From e676aaba67b8c1a69aea4c5e57599f91fffeceb7 Mon Sep 17 00:00:00 2001 From: Andrew Misyura Date: Wed, 17 Jan 2018 15:54:52 -0500 Subject: [PATCH] PN-252: Run local matches search only for patients updated/created since last search Added more logging and more error catching --- .../finder/internal/LocalMatchFinder.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/matching-notification-api/src/main/java/org/phenotips/matchingnotification/finder/internal/LocalMatchFinder.java b/matching-notification-api/src/main/java/org/phenotips/matchingnotification/finder/internal/LocalMatchFinder.java index 3aa2f40cb..8503f3b6e 100644 --- a/matching-notification-api/src/main/java/org/phenotips/matchingnotification/finder/internal/LocalMatchFinder.java +++ b/matching-notification-api/src/main/java/org/phenotips/matchingnotification/finder/internal/LocalMatchFinder.java @@ -49,7 +49,6 @@ import org.slf4j.LoggerFactory; import com.xpn.xwiki.XWikiContext; -import com.xpn.xwiki.XWikiException; import com.xpn.xwiki.doc.XWikiDocument; import com.xpn.xwiki.objects.BaseObject; @@ -89,9 +88,9 @@ public class LocalMatchFinder implements MatchFinder, Initializable @Override public void initialize() throws InitializationException { - XWikiContext context = this.provider.get(); - try { + XWikiContext context = this.provider.get(); + this.prefsDoc = context.getWiki().getDocument(MATCHING_RUN_INFO_DOCUMENT, context); if (this.prefsDoc != null && !this.prefsDoc.isNew()) { @@ -102,7 +101,7 @@ public void initialize() throws InitializationException context.getWiki().saveDocument(this.prefsDoc, context); } } - } catch (XWikiException e) { + } catch (Exception e) { this.logger.error("Failed to modify matching run info document: {}", e.getMessage(), e); } } @@ -142,21 +141,24 @@ public List findMatches(Patient patient) @Override public void recordStartMatchesSearch() { + // note: error() is used intentionally since this is important information we always want to have in the logs + this.logger.error("Starting find all local matches run..."); + if (this.prefsDoc == null) { return; } - BaseObject object = this.prefsDoc.getXObject(MATCHING_RUN_INFO_CLASS, "serverName", "localhost", false); + try { + BaseObject object = this.prefsDoc.getXObject(MATCHING_RUN_INFO_CLASS, "serverName", "localhost", false); - // cash last started search date to compare with last modification date for patient - this.previousStartedTime = object.getDateValue("startedTime"); - // set new started time - object.setDateValue("startedTime", new Date()); + // cash last started search date to compare with last modification date for patient + this.previousStartedTime = object.getDateValue("startedTime"); + // set new started time + object.setDateValue("startedTime", new Date()); - try { XWikiContext context = this.provider.get(); context.getWiki().saveDocument(this.prefsDoc, context); - } catch (XWikiException e) { + } catch (Exception e) { this.logger.error("Failed to save matching run start time for localhost.", e.getMessage(), e); } } @@ -164,17 +166,19 @@ public void recordStartMatchesSearch() @Override public void recordEndMatchesSearch() { + this.logger.error("Finished find all local matches run"); + if (this.prefsDoc == null) { return; } - BaseObject object = this.prefsDoc.getXObject(MATCHING_RUN_INFO_CLASS, "serverName", "localhost", false); - object.setDateValue("completedTime", new Date()); - try { + BaseObject object = this.prefsDoc.getXObject(MATCHING_RUN_INFO_CLASS, "serverName", "localhost", false); + object.setDateValue("completedTime", new Date()); + XWikiContext context = this.provider.get(); context.getWiki().saveDocument(this.prefsDoc, context); - } catch (XWikiException e) { + } catch (Exception e) { this.logger.error("Failed to save matching run complete time for localhost.", e.getMessage(), e); } }