use of eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory 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();
}
}
use of eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory in project hale by halestudio.
the class InstanceIndexServiceImpl method addPropertyMappings.
@Override
public boolean addPropertyMappings(Iterable<? extends Cell> cells, ServiceProvider serviceProvider) {
if (serviceProvider == null) {
throw new NullPointerException("Service provider must not be null");
}
boolean result = false;
for (Cell cell : cells) {
List<TypeTransformationFactory> functions = TransformationFunctionUtil.getTypeTransformations(cell.getTransformationIdentifier(), serviceProvider);
if (functions.isEmpty()) {
// Not a type transformation cell
continue;
}
TypeTransformation<?> transformation;
try {
transformation = functions.get(0).createExtensionObject();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
List<List<PropertyEntityDefinition>> indexedProperties = new ArrayList<>();
if (transformation instanceof InstanceIndexContribution) {
InstanceIndexContribution contribution = (InstanceIndexContribution) transformation;
indexedProperties.addAll(contribution.getIndexContribution(cell));
}
if (!indexedProperties.isEmpty()) {
result = true;
for (List<PropertyEntityDefinition> properties : indexedProperties) {
this.addPropertyMapping(properties);
}
}
}
return result;
}
Aggregations