use of eu.esdihumboldt.hale.common.headless.report.ReportFile in project hale by halestudio.
the class TemplateProject method onSuccess.
@Override
protected void onSuccess(Void context, String projectId, File projectFile, Project project, ReportFile reportFile) {
super.onSuccess(context, projectId, projectFile, project, reportFile);
// update locations in project file
LocationUpdater updater = new LocationUpdater(project, projectFile.toURI());
updater.updateProject(false);
resources.clear();
List<Path> invalidSources = new ArrayList<>();
Path projectFolder = getProjectFolder().toPath();
// validate resources
for (IOConfiguration config : project.getResources()) {
Resource resource = new IOConfigurationResource(config, getProjectFile().toURI());
// check if file URIs are valid and inside project folder
URI source = resource.getSource();
if (source != null) {
Path path = null;
if (source.getScheme() == null) {
// is a relative URI
path = projectFile.toPath().resolve(source.toString()).normalize();
} else if ("file".equals(source.getScheme())) {
// is a file URI
path = Paths.get(source).normalize();
}
if (path != null) {
if (!path.startsWith(projectFolder) || !Files.exists(path)) {
// invalid source
invalidSources.add(path);
}
}
}
resources.put(resource.getActionId(), resource);
}
valid = invalidSources.isEmpty();
if (!valid) {
StringBuilder builder = new StringBuilder("Files referenced by the project could not be found: ");
for (int i = 0; i < invalidSources.size(); i++) {
if (i > 0)
builder.append(", ");
Path path = invalidSources.get(i);
builder.append(path.getFileName().toString());
}
notValidMessage = builder.toString();
} else {
notValidMessage = "";
}
// additionally, try to find out cell count
definedRelations = 0;
// check if default alignment file exists
try {
File defAlignmentFile = new File(URI.create(projectFile.toURI().toASCIIString() + "." + AlignmentIO.PROJECT_FILE_ALIGNMENT));
if (defAlignmentFile.exists()) {
try (InputStream in = new BufferedInputStream(new FileInputStream(defAlignmentFile))) {
/*
* Try loading the file with JAXB - only supports 2.6+
* projects.
*/
AlignmentType alignment = JaxbToAlignment.load(in, null);
// XXX ignoring base alignments
int count = 0;
for (Object element : alignment.getCellOrModifier()) {
if (element instanceof CellType) {
count++;
}
}
definedRelations = count;
} catch (Exception e) {
// ignore
}
}
} catch (Exception e) {
// ignore
}
}
use of eu.esdihumboldt.hale.common.headless.report.ReportFile in project hale by halestudio.
the class ProjectReference method update.
/**
* Updates the project status from the configuration and if needed loads the
* project and transformation environment and adds or removes the
* transformation environment.
*
* @param context the update context
*/
public void update(C context) {
File projectFile = getProjectFile();
if (projectFile == null || !projectFile.exists()) {
// no project file
// reset any runtime information
projectInfo = null;
onNotAvailable(context, projectId);
} else {
File reportFile = getLoadReportFile();
if ((projectInfo == null || isForceClearReports()) && reportFile.exists()) {
// delete old reports
reportFile.delete();
}
// store reports in file
ReportFile rf = new ReportFile(reportFile);
// load project info if not yet done
if (projectInfo == null) {
projectInfo = loadProjectInfo(projectFile, rf);
}
if (projectInfo == null) {
// can't load project
onFailure(context, projectId);
} else {
onSuccess(context, projectId, projectFile, projectInfo, rf);
}
}
}
use of eu.esdihumboldt.hale.common.headless.report.ReportFile in project hale by halestudio.
the class ExecTransformation method setupReportHandler.
private void setupReportHandler() {
final ReportHandler delegateTo;
if (context.getReportsOut() != null) {
delegateTo = new ReportFile(context.getReportsOut());
} else {
delegateTo = null;
}
/*
* The report handler writes a summary to std out
*/
reportHandler = new ReportHandler() {
@Override
public void publishReport(Report<?> report) {
ExecUtil.printSummary(report);
if (delegateTo != null) {
delegateTo.publishReport(report);
}
}
};
}
use of eu.esdihumboldt.hale.common.headless.report.ReportFile in project hale by halestudio.
the class TransformationWorkspace method transform.
/**
* Transform the instances provided through the given instance readers and
* by default stores the result in the {@link #getTargetFolder()}.
*
* @param env the transformation environment
* @param sources the instance readers
* @param target the configuration of the target instance writer
* @param customTarget the custom output supplier to use for the target,
* <code>null</code> to use the default target in thet
* {@link #getTargetFolder()}
* @return the future representing the successful completion of the
* transformation (note that a successful completion doesn't
* necessary mean there weren't any internal transformation errors)
* @throws Exception if launching the transformation fails
*/
public ListenableFuture<Boolean> transform(TransformationEnvironment env, List<InstanceReader> sources, IOConfiguration target, LocatableOutputSupplier<? extends OutputStream> customTarget) throws Exception {
InstanceWriter writer = (InstanceWriter) HeadlessIO.loadProvider(target);
// output file
if (customTarget != null) {
writer.setTarget(customTarget);
} else {
File out = new File(targetFolder, "result." + getFileExtension(writer.getContentType()));
writer.setTarget(new FileIOSupplier(out));
}
ListenableFuture<Boolean> result = Transformation.transform(sources, writer, env, new ReportFile(reportFile), workspace.getName(), new DefaultTransformationSettings());
Futures.addCallback(result, new FutureCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
try {
setTransformationSuccess(result);
} catch (IOException e) {
log.error("Failed to set transformation success for workspace", e);
}
}
@Override
public void onFailure(Throwable t) {
try {
setTransformationSuccess(false);
} catch (IOException e) {
log.error("Failed to set transformation success for workspace", e);
}
}
}, MoreExecutors.directExecutor());
return result;
}
Aggregations