use of eu.esdihumboldt.hale.common.align.transformation.service.PropertyTransformer in project hale by halestudio.
the class ConceptualSchemaTransformer method transform.
/**
* @see TransformationService#transform(Alignment, InstanceCollection,
* InstanceSink, ServiceProvider, ProgressIndicator)
*/
@Override
public TransformationReport transform(Alignment alignment, InstanceCollection source, InstanceSink target, ServiceProvider serviceProvider, ProgressIndicator progressIndicator) {
TransformationReporter reporter = new DefaultTransformationReporter("Instance transformation", true);
TransformationContext context = new TransformationContext(serviceProvider, alignment);
TransformationFunctionService functions = serviceProvider.getService(TransformationFunctionService.class);
final SubtaskProgressIndicator sub = new SubtaskProgressIndicator(progressIndicator) {
@Override
protected String getCombinedTaskName(String taskName, String subtaskName) {
return taskName + " (" + subtaskName + ")";
}
};
progressIndicator = sub;
target = new CountingInstanceSink(target) {
private long lastUpdate = 0;
@Override
protected void countChanged(int count) {
long now = System.currentTimeMillis();
if (now - lastUpdate > 100) {
// only update every 100
// milliseconds
lastUpdate = now;
sub.subTask(count + " transformed instances");
}
}
};
progressIndicator.begin("Transformation", ProgressIndicator.UNKNOWN);
try {
EngineManager engines = new EngineManager();
PropertyTransformer transformer = new TreePropertyTransformer(alignment, reporter, target, engines, context);
Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
// sort type cell by priority
typeCells = sortTypeCells(typeCells);
for (Cell typeCell : typeCells) {
if (progressIndicator.isCanceled()) {
break;
}
List<TypeTransformationFactory> transformations = functions.getTypeTransformations(typeCell.getTransformationIdentifier());
if (transformations == null || transformations.isEmpty()) {
reporter.error(new TransformationMessageImpl(typeCell, MessageFormat.format("No transformation for function {0} found. Skipped type transformation.", typeCell.getTransformationIdentifier()), null));
} else {
// TODO select based on e.g. preferred transformation
// engine?
TypeTransformationFactory transformation = transformations.iterator().next();
doTypeTransformation(transformation, typeCell, source, target, alignment, engines, transformer, context, reporter, progressIndicator);
}
}
progressIndicator.setCurrentTask("Wait for property transformer to complete");
// wait for the property transformer to complete
// cancel property transformations if process was canceled - this
// may leave transformed instances in inconsistent state
transformer.join(progressIndicator.isCanceled());
engines.dispose();
reporter.setSuccess(true);
return reporter;
} finally {
progressIndicator.end();
}
}
Aggregations