Skip to content

Commit

Permalink
more refactoring of review code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Jul 29, 2024
1 parent a6fb626 commit ee04b9e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.globalbioticinteractions.elton.Elton;
import org.globalbioticinteractions.elton.util.DatasetRegistryUtil;
import org.globalbioticinteractions.elton.util.NodeFactoryNull;
import org.globalbioticinteractions.elton.util.ProgressCursorFactory;
import org.globalbioticinteractions.elton.util.ProgressUtil;
import org.globalbioticinteractions.elton.util.SpecimenNull;
import picocli.CommandLine;
Expand Down Expand Up @@ -131,7 +130,7 @@ private void reviewCachedOrRemote(List<String> namespaces, InputStreamFactory in

private void review(String namespace, DatasetRegistry registry, InputStreamFactory inputStreamFactory) throws StudyImporterException {
ReviewReport report = createReport(namespace, CmdReview.this.reviewId, CmdReview.this.getReviewerName(), CmdReview.this.dateFactory);
ReviewReportLogger reviewReportLogger = new ReviewReportLogger(report, CmdReview.this.getStdout(), getMaxLines(), getProgressCursorFactory());
ReviewReportLogger reviewReportLogger = new ReviewReportLogger(report, getStdout(), getMaxLines(), getProgressCursorFactory());

try {
Dataset dataset = new DatasetFactory(
Expand Down Expand Up @@ -166,7 +165,7 @@ private void review(String namespace, DatasetRegistry registry, InputStreamFacto
reviewReportLogger.warn(null, "no interactions found");
}
getStderr().println("done.");
log(null, dataset.getArchiveURI().toString(), ReviewCommentType.summary, reviewReportLogger.report, reviewReportLogger.stdout);
log(null, dataset.getArchiveURI().toString(), ReviewCommentType.summary, report, getStdout());
} catch (DatasetRegistryException e) {
reviewReportLogger.warn(null, "no local repository at [" + getWorkDir().toString() + "]");
getStderr().println("failed.");
Expand All @@ -178,9 +177,9 @@ private void review(String namespace, DatasetRegistry registry, InputStreamFacto
reviewReportLogger.severe(null, new String(out.toByteArray()));
throw new StudyImporterException(e);
} finally {
log(null, report.getInteractionCounter().get() + " interaction(s)", ReviewCommentType.summary, report, reviewReportLogger.stdout);
log(null, report.getNoteCounter().get() + " note(s)", ReviewCommentType.summary, report, reviewReportLogger.stdout);
log(null, report.getInfoCounter().get() + " info(s)", ReviewCommentType.summary, report, reviewReportLogger.stdout);
log(null, report.getInteractionCounter().get() + " interaction(s)", ReviewCommentType.summary, report, getStdout());
log(null, report.getNoteCounter().get() + " note(s)", ReviewCommentType.summary, report, getStdout());
log(null, report.getInfoCounter().get() + " info(s)", ReviewCommentType.summary, report, getStdout());
}
if (report.getInteractionCounter().get() == 0) {
throw new StudyImporterException("No interactions found, nothing to review. Please check logs.");
Expand Down Expand Up @@ -371,51 +370,4 @@ private static ObjectNode sortJsonObjByPropertyNames(ObjectMapper mapper, JsonNo
return dataContextSorted;
}

private class ReviewReportLogger implements ImportLogger {
private final ReviewReport report;
private final PrintStream stdout;
private final Long maxLines;
private final ProgressCursorFactory factory;

public ReviewReportLogger(ReviewReport report, PrintStream stdout, Long maxLines, ProgressCursorFactory factory) {
this.report = report;
this.stdout = stdout;
this.maxLines = maxLines;
this.factory = factory;
}


@Override
public void info(LogContext ctx, String message) {
logWithCounter(ctx, message, ReviewCommentType.info);
report.getInfoCounter().incrementAndGet();
}

@Override
public void warn(LogContext ctx, String message) {
logWithCounter(ctx, message, ReviewCommentType.note);
report.getNoteCounter().incrementAndGet();
}

@Override
public void severe(LogContext ctx, String message) {
logWithCounter(ctx, message, ReviewCommentType.note);
report.getNoteCounter().incrementAndGet();
}

private void logWithCounter(LogContext ctx, String message, ReviewCommentType commentType) {
if (maxLines == null || report.getLineCount().get() < maxLines) {
log(ctx, message, commentType, report, stdout);
}

long l = report.getLineCount().incrementAndGet();
if (l % ProgressUtil.LOG_ACTIVITY_PROGRESS_BATCH_SIZE == 0) {
factory.createProgressCursor().increment();
}
}




}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.globalbioticinteractions.elton.cmd;

import org.eol.globi.data.ImportLogger;
import org.eol.globi.domain.LogContext;
import org.globalbioticinteractions.elton.util.ProgressCursorFactory;
import org.globalbioticinteractions.elton.util.ProgressUtil;

import java.io.PrintStream;

public class ReviewReportLogger implements ImportLogger {
private final ReviewReport report;
private final PrintStream stdout;
private final Long maxLines;
private final ProgressCursorFactory factory;

public ReviewReportLogger(ReviewReport report, PrintStream stdout, Long maxLines, ProgressCursorFactory factory) {
this.report = report;
this.stdout = stdout;
this.maxLines = maxLines;
this.factory = factory;
}


@Override
public void info(LogContext ctx, String message) {
logWithCounter(ctx, message, ReviewCommentType.info);
report.getInfoCounter().incrementAndGet();
}

@Override
public void warn(LogContext ctx, String message) {
logWithCounter(ctx, message, ReviewCommentType.note);
report.getNoteCounter().incrementAndGet();
}

@Override
public void severe(LogContext ctx, String message) {
logWithCounter(ctx, message, ReviewCommentType.note);
report.getNoteCounter().incrementAndGet();
}

private void logWithCounter(LogContext ctx, String message, ReviewCommentType commentType) {
if (this.maxLines == null || report.getLineCount().get() < this.maxLines) {
CmdReview.log(ctx, message, commentType, report, stdout);
}

long l = report.getLineCount().incrementAndGet();
if (l % ProgressUtil.LOG_ACTIVITY_PROGRESS_BATCH_SIZE == 0) {
factory.createProgressCursor().increment();
}
}




}

0 comments on commit ee04b9e

Please sign in to comment.