use of eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.InstanceVisitor in project hale by halestudio.
the class TreePropertyTransformer method publish.
/**
* @see PropertyTransformer#publish(FamilyInstance, MutableInstance,
* TransformationLog, Cell)
*/
@Override
public void publish(final FamilyInstance source, final MutableInstance target, final TransformationLog typeLog, final Cell typeCell) {
instanceCounter.adjustOrPutValue(typeCell, 1, 1);
// increase output type counter
reporter.stats().at("createdPerType").at(target.getDefinition().getName().toString()).next();
Runnable job = new Runnable() {
@Override
public void run() {
try {
SimpleLogContext.withLog(typeLog, () -> {
// Add the meta data ID of the source as SourceID to the
// target
Collection<Instance> sources = InstanceUtil.getInstanceOutOfFamily(source);
Set<Object> ids = new HashSet<Object>();
for (Instance inst : sources) {
// Merge instances may have multiple IDs
List<Object> sourceIDs = inst.getMetaData(InstanceMetadata.METADATA_ID);
if (sourceIDs != null) {
ids.addAll(sourceIDs);
}
}
InstanceMetadata.setSourceID(target, ids.toArray());
// identify transformations to be executed on given
// instances
// create/get a transformation tree
TransformationTree tree = treePool.getTree(typeCell);
// State: base tree
HooksUtil.executeTreeHooks(treeHooks, TreeState.MINIMAL, tree, target);
// apply instance value to transformation tree
InstanceVisitor instanceVisitor = new InstanceVisitor(source, tree, typeLog);
tree.accept(instanceVisitor);
// State: basic source populated tree
// duplicate subtree as necessary
DuplicationVisitor duplicationVisitor = new DuplicationVisitor(tree, typeLog);
tree.accept(duplicationVisitor);
duplicationVisitor.doAugmentationTrackback();
// State: source populated tree (duplication complete)
HooksUtil.executeTreeHooks(treeHooks, TreeState.SOURCE_POPULATED, tree, target);
// apply functions
for (FunctionExecutor functionExecutor : executors) {
functionExecutor.setTypeCell(typeCell);
tree.accept(functionExecutor);
}
// State: full tree (target populated)
HooksUtil.executeTreeHooks(treeHooks, TreeState.FULL, tree, target);
// fill instance
builder.populate(target, tree, typeLog);
// generate the rest of the metadatas
metaworkerthread.get().generate(target);
// XXX ok to add to sink in any thread?!
// XXX addInstance and close were made synchronized in
// OrientInstanceSink
// XXX instead collect instances and write them in only
// one
// thread?
// after property transformations, publish target
// instance
sink.addInstance(target);
// and release the tree for further use
treePool.releaseTree(tree);
});
} catch (Throwable e) {
/*
* Catch any error, as exceptions in the executor service
* will only result in a message on the console.
*/
typeLog.error(typeLog.createMessage("Error performing property transformations", e));
}
}
};
if (executorService != null) {
executorService.execute(job);
} else {
job.run();
}
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.InstanceVisitor in project hale by halestudio.
the class TransformationTreeContentProvider method createInstanceTree.
/**
* Create a transformation tree based on a source instance.
*
* @param instance the source instance
* @param typeCell the type cell
* @param alignment the alignment
* @return the transformation tree or <code>null</code>
*/
private TransformationTree createInstanceTree(Instance instance, Cell typeCell, Alignment alignment) {
TransformationTree tree = new TransformationTreeImpl(alignment, typeCell);
ReportLog<TransformationMessage> reporter = new DefaultTransformationReporter("Transformation tree", true);
TransformationLog log = new CellLog(reporter, typeCell);
// context matching
// XXX instead through service/extension point?
ContextMatcher matcher = new AsDeepAsPossible(null);
matcher.findMatches(tree);
// process and annotate the tree
InstanceVisitor visitor = new InstanceVisitor(new FamilyInstanceImpl(instance), tree, log);
tree.accept(visitor);
// duplicate subtree as necessary
DuplicationVisitor duplicationVisitor = new DuplicationVisitor(tree, log);
tree.accept(duplicationVisitor);
duplicationVisitor.doAugmentationTrackback();
return tree;
}
Aggregations