Search in sources :

Example 11 with ATransaction

use of de.fhg.igd.slf4jplus.ATransaction in project hale by halestudio.

the class ActionProjectFile method executeProvider.

private <P extends IOProvider> void executeProvider(P provider, IOAdvisor<P> advisor) throws Exception {
    IOReporter reporter = provider.createReporter();
    ATransaction trans = log.begin(reporter.getTaskName());
    try {
        // use advisor to configure provider
        advisor.prepareProvider(provider);
        advisor.updateConfiguration(provider);
        // execute
        IOReport report = provider.execute(new LogProgressIndicator());
        // handle results
        if (report.isSuccess()) {
            advisor.handleResults(provider);
        } else {
            // TODO propagate report errors somehow?
            throw new IOException("Project file action was not successful");
        }
    } finally {
        trans.end();
    }
}
Also used : IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) ATransaction(de.fhg.igd.slf4jplus.ATransaction) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) IOException(java.io.IOException) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)

Example 12 with ATransaction

use of de.fhg.igd.slf4jplus.ATransaction in project hale by halestudio.

the class IOWizard method execute.

/**
 * Execute the given provider
 *
 * @param provider the I/O provider
 * @param defaultReporter the default reporter that is used if the provider
 *            doesn't supply a report
 * @return the execution report, if null it will not give feedback to the
 *         user and the advisor's handleResult method won't be called either
 */
protected IOReport execute(final IOProvider provider, final IOReporter defaultReporter) {
    // execute provider
    final AtomicReference<IOReport> report = new AtomicReference<IOReport>(defaultReporter);
    defaultReporter.setSuccess(false);
    try {
        getContainer().run(true, provider.isCancelable(), new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                ATransaction trans = log.begin(defaultReporter.getTaskName());
                try {
                    IOReport result = provider.execute(new ProgressMonitorIndicator(monitor));
                    if (result != null) {
                        report.set(result);
                    } else {
                        defaultReporter.setSuccess(true);
                    }
                } catch (Throwable e) {
                    defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
                } finally {
                    trans.end();
                }
            }
        });
    } catch (Throwable e) {
        defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
    }
    return report.get();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) ATransaction(de.fhg.igd.slf4jplus.ATransaction) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 13 with ATransaction

use of de.fhg.igd.slf4jplus.ATransaction in project hale by halestudio.

the class ProjectResourcesUtil method executeProvider.

/**
 * Execute the given I/O provider with the given I/O advisor.
 *
 * @param provider the I/O provider
 * @param advisor the I/O advisor
 * @param publishReport if the report should be published
 * @param cacheCallback call back that is notified on cache changes for the
 *            I/O provider, may be <code>null</code>
 * @return the future yielding the report on success
 */
public static ListenableFuture<IOReport> executeProvider(final IOProvider provider, @SuppressWarnings("rawtypes") final IOAdvisor advisor, final boolean publishReport, final CacheCallback cacheCallback) {
    final SettableFuture<IOReport> result = SettableFuture.create();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @SuppressWarnings("unchecked")
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            if (cacheCallback != null && provider instanceof CachingImportProvider) {
                // enable cache generation
                ((CachingImportProvider) provider).setProvideCache();
            }
            IOReporter reporter = provider.createReporter();
            ATransaction trans = log.begin(reporter.getTaskName());
            try {
                // use advisor to configure provider
                advisor.prepareProvider(provider);
                advisor.updateConfiguration(provider);
                // execute
                IOReport report = provider.execute(new ProgressMonitorIndicator(monitor));
                if (publishReport) {
                    // publish report
                    ReportService rs = PlatformUI.getWorkbench().getService(ReportService.class);
                    rs.addReport(report);
                }
                // handle cache update
                if (cacheCallback != null && provider instanceof CachingImportProvider) {
                    CachingImportProvider cip = (CachingImportProvider) provider;
                    if (cip.isCacheUpdate()) {
                        Value cache = cip.getCache();
                        cacheCallback.update(cache);
                    }
                }
                // handle results
                if (report.isSuccess()) {
                    advisor.handleResults(provider);
                }
                result.set(report);
            } catch (Exception e) {
                log.error("Error executing an I/O provider.", e);
                result.setException(e);
            } finally {
                trans.end();
            }
        }
    };
    try {
        ThreadProgressMonitor.runWithProgressDialog(op, provider.isCancelable());
    } catch (Exception e) {
        log.error("Error executing an I/O provider.", e);
        result.setException(e);
    }
    return result;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) CachingImportProvider(eu.esdihumboldt.hale.common.core.io.CachingImportProvider) ATransaction(de.fhg.igd.slf4jplus.ATransaction) Value(eu.esdihumboldt.hale.common.core.io.Value) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 14 with ATransaction

use of de.fhg.igd.slf4jplus.ATransaction in project hale by halestudio.

the class ProjectServiceImpl method internalClean.

private boolean internalClean() {
    if (!changeCheck()) {
        return false;
    }
    // reset current session descriptor
    ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
    repService.updateCurrentSessionDescription();
    // clean
    final IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            ATransaction trans = log.begin("Clean project");
            CleanupService cs = HalePlatform.getService(CleanupService.class);
            if (cs != null) {
                cs.triggerProjectCleanup();
            }
            monitor.beginTask("Clean project", IProgressMonitor.UNKNOWN);
            try {
                synchronized (this) {
                    main = createDefaultProject();
                    projectFile = null;
                    projectLocation = null;
                    changed = false;
                    projectLoadContentType = null;
                    temporarySettings.clear();
                }
                updateWindowTitle();
                notifyClean();
                // schemas aren't valid anymore, clear property resolver
                // cache
                PropertyResolver.clearCache();
            } finally {
                monitor.done();
                trans.end();
            }
            // clean workbench history AFTER other cleans since they can
            // create operations
            IWorkbenchOperationSupport os = PlatformUI.getWorkbench().getOperationSupport();
            os.getOperationHistory().dispose(os.getUndoContext(), true, true, false);
            // suppress the status being set to changed by the clean
            synchronized (ProjectServiceImpl.this) {
                changed = false;
            }
            updateWindowTitle();
        }
    };
    try {
        ThreadProgressMonitor.runWithProgressDialog(op, false);
    } catch (Exception e) {
        log.error("Error cleaning the project.", e);
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) CleanupService(eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService) IWorkbenchOperationSupport(org.eclipse.ui.operations.IWorkbenchOperationSupport) ATransaction(de.fhg.igd.slf4jplus.ATransaction) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

ATransaction (de.fhg.igd.slf4jplus.ATransaction)14 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)6 ProgressMonitorIndicator (eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator)5 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)5 IOException (java.io.IOException)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)3 ExampleProject (eu.esdihumboldt.hale.doc.user.examples.internal.extension.ExampleProject)3 ReportService (eu.esdihumboldt.hale.ui.service.report.ReportService)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)2 QName (javax.xml.namespace.QName)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OIntentMassiveInsert (com.orientechnologies.orient.core.intent.OIntentMassiveInsert)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1