use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class InterpolationHelper method getInterpolation.
/**
* Get the interpolation algorithm for a given instance reader.
*
* @param instanceReader the instance reader
* @param factory the geometry factory
* @return the interpolation algorithm
*/
public static InterpolationAlgorithm getInterpolation(IOProvider instanceReader, GeometryFactory factory) {
// FIXME weak cache based on reader?
String algorithmId = instanceReader.getParameter(PARAMETER_INTERPOLATION_ALGORITHM).as(String.class, DEFAULT_ALGORITHM);
InterpolationAlgorithmFactory fact = InterpolationExtension.getInstance().getFactory(algorithmId);
if (fact == null) {
log.warn("Could not find interpolation algorithm with ID " + algorithmId);
fact = InterpolationExtension.getInstance().getFactory(DEFAULT_ALGORITHM);
}
if (fact == null) {
throw new IllegalStateException("Default interpolation algorithm could not be found");
}
InterpolationAlgorithm result;
try {
result = fact.createExtensionObject();
} catch (Exception e) {
log.error("Interpolation algorithm could be created", e);
result = new SplitInterpolation();
}
double maxPositionalError = getMaxPositionalError(instanceReader);
// configure the algorithm
Map<String, Value> configuration = new HashMap<>();
instanceReader.storeConfiguration(configuration);
Map<String, String> properties = new HashMap<>();
for (Entry<String, Value> entry : configuration.entrySet()) {
if (!entry.getValue().isRepresentedAsDOM()) {
properties.put(entry.getKey(), entry.getValue().getStringRepresentation());
}
}
result.configure(factory, maxPositionalError, properties);
return result;
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class InstanceViewPreferencePage method performOk.
@Override
public boolean performOk() {
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
if (changed) {
if (!MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Reload source data", "Applying the new settings will result in the source data being reloaded.")) {
return false;
}
// save the enabled state
ps.getConfigurationService().setBoolean(InstanceViewPreferences.KEY_ENABLED, enabled.getSelection());
// store the current editor value in the map
if (currentEditor != null) {
// store value for current sampler
Value setting = currentEditor.getValue();
samplerSettings.put(InstanceViewPreferences.SAMPLERS.inverse().get(currentSampler), setting);
}
// store the map in the configuration
for (Entry<String, Value> entry : samplerSettings.entrySet()) {
ps.getConfigurationService().setProperty(InstanceViewPreferences.KEY_SETTINGS_PREFIX + entry.getKey(), entry.getValue());
}
// store the selected sampler
Sampler selectedSampler = null;
if (!samplers.getSelection().isEmpty()) {
selectedSampler = (Sampler) ((IStructuredSelection) samplers.getSelection()).getFirstElement();
}
if (selectedSampler != null) {
ps.getConfigurationService().set(InstanceViewPreferences.KEY_SAMPLER, InstanceViewPreferences.SAMPLERS.inverse().get(selectedSampler));
}
// reload the data
ps.reloadSourceData();
changed = false;
}
if (ov_changed) {
ps.getConfigurationService().setBoolean(InstanceViewPreferences.KEY_OCCURRING_VALUES_USE_EXTERNAL, occurringValuesComplete.getSelection());
ov_changed = false;
}
return true;
}
use of eu.esdihumboldt.hale.common.core.io.Value 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;
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class ProjectServiceImpl method executeConfiguration.
/**
* Execute a single I/O configuration.
*
* @param conf the I/O configuration
*/
private void executeConfiguration(final IOConfiguration conf) {
// work with a cloned configuration for the case that we make a relative
// URI absolute
IOConfiguration cloned = conf.clone();
updater.updateIOConfiguration(cloned, false);
ProjectResourcesUtil.executeConfiguration(cloned, new CacheCallback() {
@Override
public void update(Value cache) {
// update the original configuration with the new cache value
conf.setCache(cache);
// set the project status to changed
setChanged();
}
});
}
use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.
the class ProjectServiceImpl method removeResource.
@Override
public void removeResource(String resourceId) {
Resource removedResource = null;
synchronized (this) {
Iterator<IOConfiguration> iter = main.getResources().iterator();
while (iter.hasNext()) {
IOConfiguration conf = iter.next();
Value idValue = conf.getProviderConfiguration().get(ImportProvider.PARAM_RESOURCE_ID);
if (idValue != null) {
String id = idValue.as(String.class);
if (resourceId.equals(id)) {
// match found, remove
iter.remove();
removedResource = new IOConfigurationResource(conf, projectLocation);
break;
}
}
}
}
if (removedResource != null) {
setChanged();
notifyResourcesRemoved(removedResource.getActionId(), Collections.singletonList(removedResource));
}
}
Aggregations