use of eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter in project hale by halestudio.
the class GroovyCreatePage method validate.
@Override
protected boolean validate(String document) {
super.validate(document);
Type typeEntity = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
if (typeEntity == null) {
// not yet selected (NewRelationWizard)
return false;
}
InstanceBuilder builder = new InstanceBuilder(false);
Cell cell = getWizard().getUnfinishedCell();
CellLog log = new CellLog(new DefaultTransformationReporter("dummy", false), cell);
ExecutionContext context = new DummyExecutionContext(HaleUI.getServiceProvider());
Binding binding = GroovyUtil.createBinding(builder, cell, cell, log, context, typeEntity.getDefinition().getDefinition());
binding.setProperty(BINDING_INDEX, 0);
GroovyService service = HaleUI.getServiceProvider().getService(GroovyService.class);
Script script = null;
try {
script = service.parseScript(document, binding);
GroovyUtil.evaluateAll(script, builder, typeEntity.getDefinition().getDefinition(), service, log);
} catch (final Exception e) {
return handleValidationResult(script, e);
}
return handleValidationResult(script, null);
}
use of eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter in project hale by halestudio.
the class GroovyJoinPage method validate.
@Override
protected boolean validate(String document) {
ParameterValue param = CellUtil.getFirstParameter(getWizard().getUnfinishedCell(), JoinFunction.PARAMETER_JOIN);
JoinParameter joinParameter = param.as(JoinParameter.class);
// check Join parameter
if (joinParameter == null) {
// setValidationError("Missing join configuration");
return false;
} else {
String error = joinParameter.validate();
if (!setValidationError(error)) {
return false;
}
}
// target type
Type targetType = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
if (targetType == null) {
// not yet selected (NewRelationWizard)
return false;
}
/*
* FIXME use JoinParameter to fake joined instances!
*
* XXX for now just base instance
*/
TypeEntityDefinition sourceType = joinParameter.getTypes().get(0);
InstanceBuilder builder = new InstanceBuilder(false);
Instance instance = getTestValues().get(sourceType);
if (instance == null) {
// use an empty instance as input for the script
instance = new DefaultInstance(sourceType.getDefinition(), DataSet.SOURCE);
}
FamilyInstance source = new FamilyInstanceImpl(instance);
// prepare binding
Cell cell = getWizard().getUnfinishedCell();
CellLog log = new CellLog(new DefaultTransformationReporter("dummy", false), cell);
ExecutionContext context = new DummyExecutionContext(HaleUI.getServiceProvider());
Binding binding = GroovyRetype.createBinding(source, cell, builder, log, context, targetType.getDefinition().getDefinition());
GroovyService service = HaleUI.getServiceProvider().getService(GroovyService.class);
Script script = null;
try {
script = service.parseScript(document, binding);
GroovyUtil.evaluateAll(script, builder, targetType.getDefinition().getDefinition(), service, log);
} catch (final Exception e) {
return handleValidationResult(script, e);
}
return handleValidationResult(script, null);
}
use of eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter 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.transformation.report.impl.DefaultTransformationReporter in project hale by halestudio.
the class GroovyRetypePage method validate.
@Override
protected boolean validate(String document) {
super.validate(document);
Type targetType = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
Type sourceType = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getSource());
if (sourceType == null || targetType == null) {
// not yet selected (NewRelationWizard)
return false;
}
InstanceBuilder builder = new InstanceBuilder(false);
Instance instance = testValues.get(sourceType.getDefinition());
if (instance == null) {
// use an empty instance as input for the script
instance = new DefaultInstance(sourceType.getDefinition().getDefinition(), DataSet.SOURCE);
}
FamilyInstance source = new FamilyInstanceImpl(instance);
Cell cell = getWizard().getUnfinishedCell();
CellLog log = new CellLog(new DefaultTransformationReporter("dummy", false), cell);
ExecutionContext context = new DummyExecutionContext(HaleUI.getServiceProvider());
Binding binding = GroovyRetype.createBinding(source, cell, builder, log, context, targetType.getDefinition().getDefinition());
GroovyService service = HaleUI.getServiceProvider().getService(GroovyService.class);
Script script = null;
try {
script = service.parseScript(document, binding);
GroovyUtil.evaluateAll(script, builder, targetType.getDefinition().getDefinition(), service, log);
} catch (final Exception e) {
return handleValidationResult(script, e);
}
return handleValidationResult(script, null);
}
use of eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter in project hale by halestudio.
the class GroovyTransformationPage method validate.
@Override
protected boolean validate(String document) {
super.validate(document);
List<PropertyValue> values = new ArrayList<PropertyValue>();
for (EntityDefinition var : getVariables()) {
if (var instanceof PropertyEntityDefinition) {
PropertyEntityDefinition property = (PropertyEntityDefinition) var;
values.add(new PropertyValueImpl(testValues.get(property), property));
}
}
Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
if (targetProperty == null) {
// not yet selected (NewRelationWizard)
return false;
}
InstanceBuilder builder = GroovyTransformation.createBuilder(targetProperty.getDefinition());
Cell cell = getWizard().getUnfinishedCell();
boolean useInstanceValues = CellUtil.getOptionalParameter(cell, GroovyTransformation.PARAM_INSTANCE_VARIABLES, Value.of(false)).as(Boolean.class);
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
GroovyService gs = HaleUI.getServiceProvider().getService(GroovyService.class);
Script script = null;
try {
Collection<? extends Cell> typeCells = as.getAlignment().getTypeCells(cell);
// select one matching type cell, the script has to run for all
// matching cells
// if there is no matching cell it may produce a npe, which is okay
Cell typeCell = null;
if (!typeCells.isEmpty()) {
typeCell = typeCells.iterator().next();
}
CellLog log = new CellLog(new DefaultTransformationReporter("dummy", false), cell);
ExecutionContext context = new DummyExecutionContext(HaleUI.getServiceProvider());
groovy.lang.Binding binding;
if (cell.getTransformationIdentifier().equals(GroovyGreedyTransformation.ID)) {
binding = GroovyGreedyTransformation.createGroovyBinding(values, null, cell, typeCell, builder, useInstanceValues, log, context, targetProperty.getDefinition().getDefinition().getPropertyType());
} else {
binding = GroovyTransformation.createGroovyBinding(values, null, cell, typeCell, builder, useInstanceValues, log, context, targetProperty.getDefinition().getDefinition().getPropertyType());
}
script = gs.parseScript(document, binding);
GroovyTransformation.evaluate(script, builder, targetProperty.getDefinition().getDefinition().getPropertyType(), gs, log);
} catch (NoResultException e) {
// continue
} catch (final Exception e) {
return handleValidationResult(script, e);
}
return handleValidationResult(script, null);
}
Aggregations