Search in sources :

Example 1 with IOReporter

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;
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) ActionUI(eu.esdihumboldt.hale.ui.io.action.ActionUI) CachingImportProvider(eu.esdihumboldt.hale.common.core.io.CachingImportProvider) ImportProvider(eu.esdihumboldt.hale.common.core.io.ImportProvider) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) CachingImportProvider(eu.esdihumboldt.hale.common.core.io.CachingImportProvider) Value(eu.esdihumboldt.hale.common.core.io.Value)

Example 2 with IOReporter

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()));
    }
}
Also used : DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) Namespace(eu.esdihumboldt.hale.io.geoserver.Namespace) Test(org.junit.Test)

Example 3 with IOReporter

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;
}
Also used : DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) URI(java.net.URI) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 4 with IOReporter

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);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) 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)

Example 5 with IOReporter

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;
    }
}
Also used : InstanceValidator(eu.esdihumboldt.hale.common.instance.io.InstanceValidator) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) 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) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Aggregations

IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)15 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)7 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)6 ATransaction (de.fhg.igd.slf4jplus.ATransaction)5 URI (java.net.URI)5 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 Locatable (eu.esdihumboldt.hale.common.core.io.supplier.Locatable)4 FeatureTypeMapping (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)4 Namespace (eu.esdihumboldt.hale.io.geoserver.Namespace)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)3 Value (eu.esdihumboldt.hale.common.core.io.Value)3 ReportService (eu.esdihumboldt.hale.ui.service.report.ReportService)3 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)2 CellType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType)2 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)2 ProgressMonitorIndicator (eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2