Search in sources :

Example 6 with Locatable

use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.

the class HaleConnectProjectReader method createReporter.

/**
 * @see eu.esdihumboldt.hale.common.core.io.impl.AbstractImportProvider#createReporter()
 */
@Override
public IOReporter createReporter() {
    if (!(getSource() instanceof HaleConnectInputSupplier) || !HaleConnectUrnBuilder.isValidProjectUrn(getSource().getLocation())) {
        return super.createReporter();
    }
    try {
        BasePathResolver resolver = ((HaleConnectInputSupplier) getSource()).getBasePathResolver();
        URI sourceUri = getSource().getLocation();
        Owner owner = HaleConnectUrnBuilder.extractProjectOwner(sourceUri);
        String projectId = HaleConnectUrnBuilder.extractProjectId(sourceUri);
        String clientBasePath = resolver.getBasePath(HaleConnectServices.WEB_CLIENT);
        Locatable prettifiedTarget = new LocatableURI(HaleConnectUrnBuilder.buildClientAccessUrl(clientBasePath, owner, projectId));
        return new DefaultIOReporter(prettifiedTarget, MessageFormat.format("{0} import", getTypeName()), getActionId(), true);
    } catch (Throwable t) {
        return super.createReporter();
    }
}
Also used : Owner(eu.esdihumboldt.hale.io.haleconnect.Owner) LocatableURI(eu.esdihumboldt.hale.common.core.io.supplier.LocatableURI) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) HaleConnectInputSupplier(eu.esdihumboldt.hale.io.haleconnect.HaleConnectInputSupplier) URI(java.net.URI) LocatableURI(eu.esdihumboldt.hale.common.core.io.supplier.LocatableURI) BasePathResolver(eu.esdihumboldt.hale.io.haleconnect.BasePathResolver) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 7 with Locatable

use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.

the class XmlInstanceValidator method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Validating XML", ProgressIndicator.UNKNOWN);
    List<URI> schemaLocations = new ArrayList<URI>();
    for (Locatable schema : getSchemas()) {
        URI loc = schema.getLocation();
        if (loc != null) {
            schemaLocations.add(loc);
        } else {
            reporter.warn(new IOMessageImpl("No location for schema, may cause validation to fail.", null));
        }
    }
    Validator val = ValidatorFactory.getInstance().createValidator(schemaLocations.toArray(new URI[schemaLocations.size()]));
    InputStream in = getSource().getInput();
    try {
        Report report = val.validate(in);
        // use the report information to populate reporter
        for (SAXParseException warning : report.getWarnings()) {
            reporter.warn(new // 
            IOMessageImpl(// 
            warning.getLocalizedMessage(), // 
            warning, // 
            warning.getLineNumber(), warning.getColumnNumber()));
        }
        for (SAXParseException error : report.getErrors()) {
            reporter.error(new // 
            IOMessageImpl(// 
            error.getLocalizedMessage(), // 
            error, // 
            error.getLineNumber(), error.getColumnNumber()));
        }
        reporter.setSuccess(report.isValid());
        return reporter;
    } finally {
        in.close();
        progress.end();
    }
}
Also used : IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) URI(java.net.URI) AbstractInstanceValidator(eu.esdihumboldt.hale.common.instance.io.impl.AbstractInstanceValidator) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 8 with Locatable

use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.

the class StreamGmlWriterTest method validate.

/**
 * Validate an XML file against the given schemas.
 *
 * @param xmlLocation the location of the XML file
 * @param validationSchemas schemas needed for validation
 * @return the validation report
 * @throws IOProviderConfigurationException if the validator is not
 *             configured correctly
 * @throws IOException if I/O operations fail
 */
public static IOReport validate(URI xmlLocation, List<? extends Locatable> validationSchemas) throws IOProviderConfigurationException, IOException {
    XmlInstanceValidator validator = new XmlInstanceValidator();
    validator.setSchemas(validationSchemas.toArray(new Locatable[validationSchemas.size()]));
    validator.setSource(new DefaultInputSupplier(xmlLocation));
    return validator.execute(null);
}
Also used : XmlInstanceValidator(eu.esdihumboldt.hale.io.xml.validator.XmlInstanceValidator) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 9 with Locatable

use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.

the class StreamGmlWriter method getValidationSchemas.

@Override
public List<? extends Locatable> getValidationSchemas() {
    List<Locatable> result = new ArrayList<Locatable>();
    result.addAll(super.getValidationSchemas());
    for (Locatable schema : additionalSchemas.values()) {
        result.add(schema);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 10 with Locatable

use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.

the class ExecTransformation method setupValidators.

private void setupValidators() {
    if (context.getValidateProviderIds() != null && !context.getValidateProviderIds().isEmpty()) {
        for (int i = 0; i < context.getValidateProviderIds().size(); i++) {
            String validateProviderId = context.getValidateProviderIds().get(i);
            if (!validateProviderId.trim().isEmpty()) {
                final InstanceValidator validator = HaleIO.createIOProvider(InstanceValidator.class, null, validateProviderId);
                if (validator == null) {
                    throw fail("Instance validator with ID " + validateProviderId + " not found");
                }
                // load validator settings
                validator.loadConfiguration(context.getValidateSettings().get(i));
                // set schemas
                List<? extends Locatable> schemas = target.getValidationSchemas();
                validator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
                // set source
                validator.setSource(new DefaultInputSupplier(context.getTarget()));
                // apply target content type
                validator.setContentType(target.getContentType());
                this.validators.add(validator);
            }
        }
    }
}
Also used : InstanceValidator(eu.esdihumboldt.hale.common.instance.io.InstanceValidator) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Aggregations

Locatable (eu.esdihumboldt.hale.common.core.io.supplier.Locatable)13 URI (java.net.URI)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)4 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)4 InstanceValidator (eu.esdihumboldt.hale.common.instance.io.InstanceValidator)4 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)3 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)3 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)3 ArrayList (java.util.ArrayList)3 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)2 LocatableURI (eu.esdihumboldt.hale.common.core.io.supplier.LocatableURI)2 BasePathResolver (eu.esdihumboldt.hale.io.haleconnect.BasePathResolver)2 IOException (java.io.IOException)2 ATransaction (de.fhg.igd.slf4jplus.ATransaction)1 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)1 CellType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType)1 ObjectFactory (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory)1 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)1