Skip to content

Commit

Permalink
RM-90: Create a configuration table to show the last date+time matchi…
Browse files Browse the repository at this point in the history
…ng was run

Addressing codereview comments
  • Loading branch information
veronikaslc committed Jan 15, 2018
1 parent a438fbf commit 53e20f1
Showing 1 changed file with 23 additions and 29 deletions.
Expand Up @@ -97,12 +97,9 @@ public class RemoteMatchFinder implements MatchFinder, Initializable

private XWikiDocument prefsDoc;

private List<String> remoteIdsList;

@Override
public void initialize() throws InitializationException
{
this.remoteIdsList = this.getRemotesList();
this.prefsDoc = this.getMatchingRunInfoDoc();
}

Expand All @@ -113,17 +110,11 @@ private XWikiDocument getMatchingRunInfoDoc()
XWikiDocument doc = context.getWiki().getDocument(MATCHING_RUN_INFO_DOCUMENT, context);

if (doc != null && !doc.isNew()) {

for (String remoteId : this.remoteIdsList) {
BaseObject object = doc.getXObject(MATCHING_RUN_INFO_CLASS, "serverName", remoteId, false);
if (object == null) {
object = doc.newXObject(MATCHING_RUN_INFO_CLASS, context);
object.setStringValue("serverName", remoteId);
}
}
context.getWiki().saveDocument(doc, context);
return doc;
} else {
this.logger.error("Failed to retrieve matching run info document");
}

} catch (XWikiException e) {
this.logger.error("Failed to modify matching run info document: {}", e.getMessage(), e);
}
Expand All @@ -149,7 +140,8 @@ public List<PatientMatch> findMatches(Patient patient)

List<PatientMatch> patientMatches = new LinkedList<>();

for (String remoteId : this.remoteIdsList) {
List<String> remoteIds = this.getRemotesList();
for (String remoteId : remoteIds) {
List<PatientMatch> currentMatches = this.sendAndProcessRequest(patient.getId(), remoteId);
patientMatches.addAll(currentMatches);
}
Expand Down Expand Up @@ -229,34 +221,36 @@ private List<String> getRemotesList()
@Override
public void recordStartMatchesSearch()
{
if (this.prefsDoc == null) {
return;
}

XWikiContext context = this.provider.get();
BaseObject object = this.prefsDoc.getXObject(MATCHING_RUN_INFO_CLASS, "serverName", "localhost", false);
object.setDateValue("startedTime", new Date());
try {
context.getWiki().saveDocument(this.prefsDoc, context);
} catch (XWikiException e) {
this.logger.error("Failed to save matching run start time for localhost {}.");
}
this.recordMatchesSearchTime("startedTime");
}

@Override
public void recordEndMatchesSearch()
{
this.recordMatchesSearchTime("completedTime");
}

private void recordMatchesSearchTime(String propertyName)
{
if (this.prefsDoc == null) {
return;
}

XWikiContext context = this.provider.get();
BaseObject object = this.prefsDoc.getXObject(MATCHING_RUN_INFO_CLASS, "serverName", "localhost", false);
object.setDateValue("completedTime", new Date());
try {
XWikiContext context = this.provider.get();

List<String> remoteIds = this.getRemotesList();
for (String remoteId : remoteIds) {
BaseObject object = this.prefsDoc.getXObject(MATCHING_RUN_INFO_CLASS, "serverName", remoteId, false);
if (object == null) {
object = this.prefsDoc.newXObject(MATCHING_RUN_INFO_CLASS, context);
object.setStringValue("serverName", remoteId);
}
object.setDateValue(propertyName, new Date());
}
context.getWiki().saveDocument(this.prefsDoc, context);
} catch (XWikiException e) {
this.logger.error("Failed to save matching run start time for localhost {}.");
this.logger.error("Failed to save matching run {}.", propertyName);
}
}
}

0 comments on commit 53e20f1

Please sign in to comment.