use of eu.esdihumboldt.hale.common.core.io.report.IOReporter 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.common.core.io.report.IOReporter in project hale by halestudio.
the class AppSchemaIsolatedWorkspacesMappingTest method testNullWorkspaceConfiguration.
/**
* Isolated attribute must be false, names must match the default ones,
* unique mapping names must not be generated.
*
* @throws IOException
*/
@Test
public void testNullWorkspaceConfiguration() throws IOException {
AppSchemaMappingGenerator generator = new AppSchemaMappingGenerator(alignment, targetSchemaSpace, null, featureChainingConf, null);
IOReporter reporter = new DefaultIOReporter(targetSchemaSpace.getSchemas().iterator().next(), "Generate App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, false);
generator.generateMapping(reporter);
assertEquals(STATIONS_WS_DEFAULT, generator.getMainNamespace().name());
assertFalse((boolean) generator.getMainNamespace().getAttribute(Namespace.ISOLATED));
assertEquals(STATIONS_WS_DEFAULT, generator.getMainWorkspace().name());
assertFalse((boolean) generator.getMainWorkspace().getAttribute(Namespace.ISOLATED));
boolean measurementsNsFound = false;
for (Namespace ns : generator.getSecondaryNamespaces()) {
if (MEASUREMENTS_NS_URI.equals(ns.getAttribute(Namespace.URI))) {
measurementsNsFound = true;
assertEquals(MEASUREMENTS_WS_DEFAULT, ns.name());
assertFalse((boolean) ns.getAttribute(Namespace.ISOLATED));
assertEquals(MEASUREMENTS_WS_DEFAULT, generator.getWorkspace(ns).name());
assertFalse((boolean) generator.getWorkspace(ns).getAttribute(Namespace.ISOLATED));
}
}
assertTrue(measurementsNsFound);
List<FeatureTypeMapping> typeMappings = generator.getGeneratedMapping().getAppSchemaMapping().getTypeMappings().getFeatureTypeMapping();
assertEquals(2, typeMappings.size());
for (FeatureTypeMapping typeMapping : typeMappings) {
assertTrue(Strings.isNullOrEmpty(typeMapping.getMappingName()));
}
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReporter in project hale by halestudio.
the class TestUtil method loadAlignment.
/**
* Loads the specified alignment. Assumes that its base alignments don't
* need a location update.
*
* @param location the URI specifying the location of the alignment
* @param sourceTypes the source type index
* @param targetTypes the target type index
* @return the loaded alignment
* @throws Exception if the alignment or other resources could not be loaded
*/
public static Alignment loadAlignment(final URI location, Schema sourceTypes, Schema targetTypes) throws Exception {
DefaultInputSupplier input = new DefaultInputSupplier(location);
IOReporter report = new DefaultIOReporter(new Locatable() {
@Override
public URI getLocation() {
return location;
}
}, "Load alignment", AlignmentIO.ACTION_LOAD_ALIGNMENT, true);
Alignment alignment;
try {
alignment = CastorAlignmentIO.load(input.getInput(), report, sourceTypes, targetTypes, new PathUpdate(null, null));
} catch (Exception e) {
alignment = JaxbAlignmentIO.load(input.getInput(), report, sourceTypes, targetTypes, new PathUpdate(null, null), null, null);
}
assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
return alignment;
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReporter in project hale by halestudio.
the class ExportJob method run.
/**
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
IOReporter defaultReporter = writer.createReporter();
defaultReporter.setSuccess(false);
IOReport report = defaultReporter;
try {
ATransaction trans = log.begin(defaultReporter.getTaskName());
try {
IOReport result = writer.execute(new ProgressMonitorIndicator(monitor));
if (result != null) {
report = 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));
}
if (monitor.isCanceled()) {
reset();
return Status.CANCEL_STATUS;
}
// add report to report service
reportHandler.publishReport(report);
// show message to user
if (report.isSuccess()) {
// no message, we rely on the report being
// shown/processed
// let advisor handle results
advisor.handleResults(writer);
reset();
return Status.OK_STATUS;
} else {
reset();
log.error(report.getSummary());
return new Status(Status.ERROR, "eu.esdihumboldt.hale.common.headless", report.getSummary(), null);
}
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReporter in project hale by halestudio.
the class ValidationJob method run.
/**
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
boolean successful = true;
for (InstanceValidator validator : this.validators) {
IOReporter defaultReporter = validator.createReporter();
defaultReporter.setSuccess(false);
IOReport report = defaultReporter;
try {
ATransaction trans = log.begin(defaultReporter.getTaskName());
try {
if (writer != null) {
// set validation schemas (may have been determined only
// during writer execution)
// set schemas
List<? extends Locatable> schemas = writer.getValidationSchemas();
validator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
}
validator.setServiceProvider(serviceProvider);
IOReport result = validator.execute(new ProgressMonitorIndicator(monitor));
if (result != null) {
report = 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));
}
if (monitor.isCanceled()) {
reset();
return Status.CANCEL_STATUS;
}
// add report to report service
reportHandler.publishReport(report);
// show message to user
if (report.isSuccess()) {
// info message
log.info(report.getSummary());
} else {
// error message
log.error(report.getSummary());
successful = false;
}
}
reset();
if (successful) {
log.userInfo("All validations completed successfully.");
return Status.OK_STATUS;
} else {
log.userError("There were validation failures. Please check the reports for details.");
return ERROR_STATUS;
}
}
Aggregations