All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.icij.extract.tasks.ViewReportTask Maven / Gradle / Ivy

package org.icij.extract.tasks;

import org.icij.extract.document.TikaDocument;
import org.icij.extract.document.DocumentFactory;
import org.icij.extract.report.Report;
import org.icij.extract.report.ReportMap;
import org.icij.extract.report.ReportMapFactory;
import org.icij.task.DefaultTask;
import org.icij.task.annotation.OptionsClass;
import org.icij.task.annotation.Task;

/**
 * CLI class for viewing a single report.
 */
@Task("View a single report.")
@OptionsClass(ReportMapFactory.class)
public class ViewReportTask extends DefaultTask {

	@Override
	public Void call() throws Exception {
		throw new RuntimeException("No ID or path supplied.");
	}

	@Override
	public Void call(final String[] arguments) throws Exception {
		final ReportMapFactory reportMapFactory = new ReportMapFactory(options);
		final DocumentFactory documentFactory = new DocumentFactory().configure(options);
		reportMapFactory.withDocumentFactory(documentFactory);

		try (final ReportMap reportMap = reportMapFactory.createShared()) {
			for (String path: arguments) {
				final TikaDocument tikaDocument = documentFactory.create(path);
				final Report report = reportMap.get(tikaDocument);

				System.out.println("Status:");
				System.out.println(report.getStatus());

				report.getException().ifPresent(e -> {
					System.out.println("Exception:");
					e.printStackTrace(System.out);
				});
			}
		} catch (Exception e) {
			throw new RuntimeException("Unexpected exception while viewing report.", e);
		}

		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy