use of eu.esdihumboldt.hale.ui.service.report.ReportService 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.ui.service.report.ReportService in project hale by halestudio.
the class IOWizard method performFinish.
/**
* @see Wizard#performFinish()
*
* @return <code>true</code> if executing the I/O provider was successful
*/
@Override
public boolean performFinish() {
if (getProvider() == null) {
return false;
}
if (!applyConfiguration()) {
return false;
}
// create default report
IOReporter defReport = provider.createReporter();
// validate and execute provider
try {
// validate configuration
provider.validate();
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
URI projectLoc = ps.getLoadLocation() == null ? null : ps.getLoadLocation();
boolean isProjectResource = false;
if (actionId != null) {
// XXX instead move project resource to action?
ActionUI factory = ActionUIExtension.getInstance().findActionUI(actionId);
isProjectResource = factory.isProjectResource();
}
// prevent loading of duplicate resources
if (isProjectResource && provider instanceof ImportProvider && !getProviderFactory().allowDuplicateResource()) {
String currentResource = ((ImportProvider) provider).getSource().getLocation().toString();
URI currentAbsolute = URI.create(currentResource);
if (projectLoc != null && !currentAbsolute.isAbsolute()) {
currentAbsolute = projectLoc.resolve(currentAbsolute);
}
for (IOConfiguration conf : ((Project) ps.getProjectInfo()).getResources()) {
Value otherResourceValue = conf.getProviderConfiguration().get(ImportProvider.PARAM_SOURCE);
if (otherResourceValue == null) {
continue;
}
String otherResource = otherResourceValue.as(String.class);
URI otherAbsolute = URI.create(otherResource);
if (projectLoc != null && !otherAbsolute.isAbsolute()) {
otherAbsolute = projectLoc.resolve(otherAbsolute);
}
String action = conf.getActionId();
// resource is already loaded into the project
if (currentAbsolute.equals(otherAbsolute) && Objects.equal(actionId, action)) {
// check if the resource is loaded with a provider that
// allows duplicates
boolean allowDuplicate = false;
IOProviderDescriptor providerFactory = IOProviderExtension.getInstance().getFactory(conf.getProviderId());
if (providerFactory != null) {
allowDuplicate = providerFactory.allowDuplicateResource();
}
if (!allowDuplicate) {
log.userError("Resource is already loaded. Loading duplicate resources is aborted!");
return false;
}
}
}
}
// enable provider internal caching
if (isProjectResource && provider instanceof CachingImportProvider) {
((CachingImportProvider) provider).setProvideCache();
}
IOReport report = execute(provider, defReport);
if (report != null) {
// add report to report server
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.addReport(report);
// show message to user
if (report.isSuccess()) {
// let advisor handle results
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Completing operation...", IProgressMonitor.UNKNOWN);
try {
advisor.handleResults(getProvider());
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
log.userError("Error processing results:\n" + e.getCause().getLocalizedMessage(), e.getCause());
return false;
} catch (Exception e) {
log.userError("Error processing results:\n" + e.getLocalizedMessage(), e);
return false;
}
// add to project service if necessary
if (isProjectResource)
ps.rememberIO(actionId, getProviderFactory().getIdentifier(), provider);
return true;
} else {
// error message
log.userError(report.getSummary() + "\nPlease see the report for details.");
return false;
}
} else
return true;
} catch (IOProviderConfigurationException e) {
// user feedback
log.userError("Validation of the provider configuration failed:\n" + e.getLocalizedMessage(), e);
return false;
}
}
use of eu.esdihumboldt.hale.ui.service.report.ReportService in project hale by halestudio.
the class DefaultReportHandler method publishReport.
/**
* @see ReportHandler#publishReport(Report)
*/
@Override
public void publishReport(Report<?> report) {
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.addReport(report);
}
use of eu.esdihumboldt.hale.ui.service.report.ReportService in project hale by halestudio.
the class InstanceExportWizard method performValidation.
/**
* Run the configured validators on the exported instance. May be overriden
* to customize validation process.
*
* @return true if all validations were successful
*/
protected boolean performValidation() {
boolean success = true;
for (InstanceValidator validator : validators) {
// set schemas
List<? extends Locatable> schemas = getProvider().getValidationSchemas();
validator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
// set service provider
validator.setServiceProvider(HaleUI.getServiceProvider());
ExportTarget<?> exportTarget = getSelectTargetPage().getExportTarget();
if (exportTarget instanceof FileTarget) {
LocatableOutputSupplier<? extends OutputStream> target = getProvider().getTarget();
List<String> fileNames = new ArrayList<>();
if (target instanceof MultiLocationOutputSupplier) {
for (URI location : ((MultiLocationOutputSupplier) target).getLocations()) {
if (!"file".equals(location.getScheme())) {
continue;
}
File targetFile = new File(location);
fileNames.add(targetFile.getAbsolutePath());
}
} else {
fileNames.add(((FileTarget<?>) exportTarget).getTargetFileName());
}
for (String fileName : fileNames) {
LocatableInputSupplier<? extends InputStream> source = new FileIOSupplier(new File(fileName));
validator.setSource(source);
validator.setContentType(getContentType());
IOReporter defReport = validator.createReporter();
// validate and execute provider
try {
// validate configuration
validator.validate();
IOReport report = execute(validator, defReport);
if (report != null) {
// add report to report server
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.addReport(report);
if (report.isSuccess()) {
log.info(report.getSummary());
} else {
log.error(report.getSummary());
success = false;
}
}
} catch (IOProviderConfigurationException e) {
log.error(MessageFormat.format("The validator '{0}' could not be executed", validator.getClass().getCanonicalName()), e);
success = false;
}
}
} else {
log.error("No input can be provided for validation (no file target)");
success = false;
}
}
if (success) {
log.userInfo("All validations completed successfully.");
} else {
log.userError("There were validation failures. Please check the report for more details.");
}
return success;
}
use of eu.esdihumboldt.hale.ui.service.report.ReportService 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;
}
Aggregations