use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class OrientInstanceService method performTransformation.
/**
* Perform the transformation
*
* @return if the transformation was successful
*/
protected boolean performTransformation() {
final TransformationService ts = getTransformationService();
if (ts == null) {
log.userError("No transformation service available");
return false;
}
final AtomicBoolean transformationFinished = new AtomicBoolean(false);
final AtomicBoolean transformationCanceled = new AtomicBoolean(false);
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
Alignment alignment = getAlignmentService().getAlignment();
if (alignment.getActiveTypeCells().isEmpty()) {
// early exit if there are no type relations
return;
}
// determine if there are any active type cells w/o source
boolean transformEmpty = false;
for (Cell cell : alignment.getActiveTypeCells()) {
if (cell.getSource() == null || cell.getSource().isEmpty()) {
transformEmpty = true;
break;
}
}
InstanceCollection sources = getInstances(DataSet.SOURCE);
if (!transformEmpty && sources.isEmpty()) {
return;
}
HaleOrientInstanceSink sink = new HaleOrientInstanceSink(transformed, true);
TransformationReport report;
ATransaction trans = log.begin("Instance transformation");
try {
report = ts.transform(alignment, sources, sink, HaleUI.getServiceProvider(), new ProgressMonitorIndicator(monitor));
// publish report
ReportService rs = PlatformUI.getWorkbench().getService(ReportService.class);
rs.addReport(report);
} finally {
try {
sink.close();
} catch (IOException e) {
// ignore
}
trans.end();
}
} finally {
// remember if canceled
if (monitor.isCanceled()) {
transformationCanceled.set(true);
}
// transformation finished
transformationFinished.set(true);
}
}
};
try {
ThreadProgressMonitor.runWithProgressDialog(op, ts.isCancelable());
} catch (Throwable e) {
log.error("Error starting transformation process", e);
}
// wait for transformation to complete
HaleUI.waitFor(transformationFinished);
return !transformationCanceled.get();
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class HaleServiceFactory method create.
/**
* @see AbstractServiceFactory#create(Class, IServiceLocator,
* IServiceLocator)
*/
@Override
public Object create(@SuppressWarnings("rawtypes") Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) {
if (AlignmentService.class.equals(serviceInterface)) {
return new AlignmentServiceUndoSupport(new AlignmentServiceImpl(locator.getService(ProjectService.class)));
}
if (CompatibilityService.class.equals(serviceInterface)) {
return new CompatibilityServiceImpl();
}
if (EntityDefinitionService.class.equals(serviceInterface)) {
return new EntityDefinitionServiceUndoSupport(new EntityDefinitionServiceImpl(locator.getService(AlignmentService.class), locator.getService(ProjectService.class)));
}
if (EntityResolver.class.equals(serviceInterface)) {
return new UserFallbackEntityResolver();
}
if (FunctionService.class.equals(serviceInterface)) {
return new HaleFunctionService(locator.getService(AlignmentService.class));
}
if (GeometrySchemaService.class.equals(serviceInterface)) {
return new ProjectGeometrySchemaService(locator.getService(ProjectService.class));
}
if (GroovyService.class.equals(serviceInterface)) {
return new PreferencesGroovyService(locator.getService(ProjectService.class), locator.getService(AlignmentService.class));
}
if (InstanceSampleService.class.equals(serviceInterface)) {
return new InstanceSampleServiceImpl();
}
if (InstanceService.class.equals(serviceInterface)) {
final InstanceService is = OrientInstanceService.getInstance(locator.getService(SchemaService.class), locator.getService(ProjectService.class), locator.getService(AlignmentService.class), locator.getService(GroovyService.class));
// Add a listener to close all InstanceProcessors when source data
// is cleared
// XXX There may a better place to add this listener
is.addListener(new InstanceServiceAdapter() {
@Override
public void datasetChanged(DataSet type) {
if (type != DataSet.SOURCE) {
return;
}
InstanceCollection instances = is.getInstances(type);
if (instances.isEmpty()) {
// data was cleared, close instance
// processors
final InstanceProcessingExtension ext = new InstanceProcessingExtension(HaleUI.getServiceProvider());
for (InstanceProcessor processor : ext.getInstanceProcessors()) {
try {
processor.close();
} catch (IOException e) {
// Ignore
}
}
}
}
});
return is;
}
if (InstanceValidationService.class.equals(serviceInterface))
return new InstanceValidationServiceImpl(locator.getService(InstanceService.class), locator.getService(ReportService.class));
if (InstanceViewService.class.equals(serviceInterface)) {
return new InstanceViewServiceImpl(locator.getService(ProjectService.class));
}
if (OccurringValuesService.class.equals(serviceInterface)) {
return new OccurringValuesServiceImpl(locator.getService(InstanceService.class), locator.getService(ProjectService.class));
}
if (PopulationService.class.equals(serviceInterface)) {
return new PopulationServiceImpl(locator.getService(InstanceService.class));
}
if (ProjectService.class.equals(serviceInterface)) {
return new ProjectServiceImpl();
}
if (ProjectInfoService.class.equals(serviceInterface)) {
return locator.getService(ProjectService.class);
}
if (RecentProjectsService.class.equals(serviceInterface)) {
return new RecentProjectsServiceImpl();
}
if (RecentResources.class.equals(serviceInterface)) {
return new RecentResourcesService(locator.getService(ProjectService.class));
}
if (ReportService.class.equals(serviceInterface)) {
return new ReportServiceImpl();
}
if (SchemaService.class.equals(serviceInterface)) {
return new SchemaServiceImpl(locator.getService(ProjectService.class));
}
if (TaskService.class.equals(serviceInterface)) {
return new TaskServiceImpl();
}
if (TransformationFunctionService.class.equals(serviceInterface)) {
return new HaleTransformationFunctionService(locator.getService(AlignmentService.class));
}
if (TransformationSchemas.class.equals(serviceInterface)) {
return locator.getService(SchemaService.class);
}
return null;
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class InstanceImportAdvisor method handleResults.
/**
* @see IOAdvisor#handleResults(IOProvider)
*/
@Override
public void handleResults(InstanceReader provider) {
// add instances to instance service
InstanceService is = getService(InstanceService.class);
InstanceCollection instances = provider.getInstances();
ResourceIterator<Instance> it = instances.iterator();
try {
if (!it.hasNext()) {
URI loc = provider.getSource().getLocation();
if (loc != null) {
log.warn(MessageFormat.format("No instances could be imported with the given configuration from {0}", loc.toString()));
} else {
log.warn("No instances could be imported with the given configuration.");
}
}
} finally {
it.close();
}
// apply sampling before adding to the instance service
InstanceViewService ivs = PlatformUI.getWorkbench().getService(InstanceViewService.class);
if (ivs != null) {
instances = ivs.sample(instances);
}
is.addSourceInstances(instances);
super.handleResults(provider);
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class AbstractInstancePainter method update.
/**
* Do a complete update of the way-points. Existing way-points are
* discarded.
*
* @param selection the current selection
*/
public void update(ISelection selection) {
clearWaypoints();
// XXX only mappable type instances for source?!
InstanceCollection instances = instanceService.getInstances(dataSet);
if (selection != null) {
lastSelected = collectReferences(selection);
}
if (instances.isEmpty()) {
return;
}
final AtomicBoolean updateFinished = new AtomicBoolean(false);
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
String taskName;
switch(getDataSet()) {
case SOURCE:
taskName = "Update source data in map";
break;
case TRANSFORMED:
default:
taskName = "Update transformed data in map";
break;
}
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
// add way-points for instances
InstanceCollection instances = instanceService.getInstances(dataSet);
ResourceIterator<Instance> it = instances.iterator();
try {
while (it.hasNext()) {
Instance instance = it.next();
InstanceWaypoint wp = createWaypoint(instance, instanceService);
if (wp != null) {
if (lastSelected.contains(wp.getValue())) {
// refresh can be
wp.setSelected(true, null);
// ignored because
// it's done for
// addWaypoint
}
// no refresher, as
addWaypoint(wp, null);
// refreshAll is executed
}
}
} finally {
it.close();
monitor.done();
updateFinished.set(true);
}
}
};
try {
ThreadProgressMonitor.runWithProgressDialog(op, false);
} catch (Throwable e) {
log.error("Error running painter update", e);
}
HaleUI.waitFor(updateFinished);
refreshAll();
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class XsltTransformationTest method transformData.
@Override
protected List<Instance> transformData(TransformationExample example) throws Exception {
// export alignment to XSLT
XsltExport export = new XsltExport();
export.setAlignment(example.getAlignment());
export.setSourceSchema(new DefaultSchemaSpace().addSchema(example.getSourceSchema()));
export.setTargetSchema(new DefaultSchemaSpace().addSchema(example.getTargetSchema()));
export.setParameter(XsltExport.PARAM_ROOT_ELEMENT_NAMESPACE, Value.of(example.getTargetContainerNamespace()));
export.setParameter(XsltExport.PARAM_ROOT_ELEMENT_NAME, Value.of(example.getTargetContainerName()));
File tempXsltFile = File.createTempFile("xsltest", ".xsl");
export.setTarget(new FileIOSupplier(tempXsltFile));
IOReport res = export.execute(new LogProgressIndicator());
assertTrue("XSLT export not successful", res.isSuccess());
assertTrue("Errors during XSLT export", res.getErrors().isEmpty());
// invoke XSLT on source file to produce target
File target = File.createTempFile("xsltest", ".xml");
executeXslt(example.getSourceDataInput(), tempXsltFile, target);
// load target and return instances
InstanceCollection instances = TestUtil.loadInstances(target.toURI(), example.getTargetSchema());
List<Instance> list = new ArrayList<Instance>();
ResourceIterator<Instance> it = instances.iterator();
try {
while (it.hasNext()) {
list.add(it.next());
}
} finally {
it.close();
}
// clean up
tempXsltFile.delete();
target.delete();
return list;
}
Aggregations