Search in sources :

Example 76 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class CastorAlignmentReader method loadAlignment.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected MutableAlignment loadAlignment(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Load hale alignment", ProgressIndicator.UNKNOWN);
    InputStream in = getSource().getInput();
    MutableAlignment alignment = null;
    try {
        alignment = CastorAlignmentIO.load(in, reporter, getSourceSchema(), getTargetSchema(), getPathUpdater());
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
        return alignment;
    } finally {
        in.close();
    }
    progress.end();
    reporter.setSuccess(true);
    return alignment;
}
Also used : InputStream(java.io.InputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 77 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class CastorAlignmentWriter method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save hale alignment", ProgressIndicator.UNKNOWN);
    PathUpdate pathUpdate = new PathUpdate(getProjectLocation(), getTarget().getLocation());
    OutputStream out = getTarget().getOutput();
    try {
        CastorAlignmentIO.save(getAlignment(), out, pathUpdate);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
        return reporter;
    } finally {
        out.close();
    }
    progress.end();
    reporter.setSuccess(true);
    return reporter;
}
Also used : OutputStream(java.io.OutputStream) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 78 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class JaxbAlignmentWriter method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save hale alignment", ProgressIndicator.UNKNOWN);
    PathUpdate pathUpdate = new PathUpdate(getProjectLocation(), getTarget().getLocation());
    AlignmentType alignment;
    try {
        alignment = JaxbAlignmentIO.convert(getAlignment(), reporter, pathUpdate);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl("Error converting alignment to XML model", e));
        reporter.setSuccess(false);
        return reporter;
    }
    OutputStream out = getTarget().getOutput();
    try {
        JaxbAlignmentIO.save(alignment, reporter, out);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
        return reporter;
    } finally {
        out.close();
    }
    progress.end();
    reporter.setSuccess(true);
    return reporter;
}
Also used : AlignmentType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType) OutputStream(java.io.OutputStream) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 79 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class AbstractBaseAlignmentLoader method applyModifiers.

/**
 * Apply modifiers on the alignment.
 *
 * @param alignment the alignment to work on
 * @param modifiers the modifiers to apply
 * @param prefixMapping the mapping of prefixes (see
 *            {@link #getCell(Alignment, String, String, Map, IOReporter)})
 * @param defaultPrefix the default prefix (may be <code>null</code>) (see
 *            {@link #getCell(Alignment, String, String, Map, IOReporter)})
 * @param base whether the added modifiers are from a base alignment or the
 *            main alignment
 * @param reporter the I/O reporter to report any errors to, may be
 *            <code>null</code>
 */
private void applyModifiers(Alignment alignment, Collection<M> modifiers, Map<String, String> prefixMapping, String defaultPrefix, boolean base, IOReporter reporter) {
    for (M modifier : modifiers) {
        Cell cell = getCell(alignment, getModifiedCell(modifier), defaultPrefix, prefixMapping, reporter);
        if (cell == null)
            continue;
        // disabledFor
        for (String disabledForId : getDisabledForList(modifier)) {
            Cell other = getCell(alignment, disabledForId, defaultPrefix, prefixMapping, reporter);
            if (other == null)
                continue;
            else if (!AlignmentUtil.isTypeCell(other)) {
                reporter.warn(new IOMessageImpl("A cell referenced in disable-for is not a type cell.", null));
                continue;
            } else if (!alignment.getPropertyCells(other, true, false).contains(cell)) {
                reporter.warn(new IOMessageImpl("A cell referenced in disable-for does not contain the cell that gets modified.", null));
                continue;
            }
            // so it has to be a BaseAlignmentCell
            if (base)
                ((BaseAlignmentCell) cell).setBaseDisabledFor(other, true);
            else
                ((ModifiableCell) cell).setDisabledFor(other, true);
        }
        // transformation mode
        TransformationMode mode = getTransformationMode(modifier);
        if (mode != null) {
            if (base)
                ((BaseAlignmentCell) cell).setBaseTransformationMode(mode);
            else
                ((ModifiableCell) cell).setTransformationMode(mode);
        }
    // XXX handle additional properties
    }
}
Also used : TransformationMode(eu.esdihumboldt.hale.common.align.model.TransformationMode) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ModifiableCell(eu.esdihumboldt.hale.common.align.model.ModifiableCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell)

Example 80 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class CellBean method createCell.

/**
 * Create a cell based on the information in the cell bean if possible.
 * Otherwise a corresponding error message should be added to the report.
 *
 * @param reporter the I/O reporter to report any errors to, may be
 *            <code>null</code>
 * @param sourceTypes the source types to use for resolving definition
 *            references
 * @param targetTypes the target types to use for resolving definition
 *            references
 * @return the created cell or <code>null</code>
 */
public MutableCell createCell(IOReporter reporter, TypeIndex sourceTypes, TypeIndex targetTypes) {
    MutableCell cell = new DefaultCell();
    cell.setTransformationIdentifier(getTransformationIdentifier());
    if (transformationParameters != null && !transformationParameters.isEmpty()) {
        ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
        for (ParameterValueBean param : transformationParameters) {
            parameters.put(param.getName(), param.createParameterValue());
        }
        cell.setTransformationParameters(parameters);
    }
    cell.setId(id);
    try {
        cell.setSource(createEntities(source, sourceTypes, SchemaSpaceID.SOURCE));
        cell.setTarget(createEntities(target, targetTypes, SchemaSpaceID.TARGET));
    } catch (Throwable e) {
        reporter.error(new IOMessageImpl("Could not create cell", e));
        return null;
    }
    return cell;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)

Aggregations

IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)85 IOException (java.io.IOException)43 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)33 QName (javax.xml.namespace.QName)20 URI (java.net.URI)15 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)14 InputStream (java.io.InputStream)13 File (java.io.File)12 HashMap (java.util.HashMap)11 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)9 FileOutputStream (java.io.FileOutputStream)9 ArrayList (java.util.ArrayList)9 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)8 OutputStream (java.io.OutputStream)8 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)7 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)7 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)6 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)5 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)4 Value (eu.esdihumboldt.hale.common.core.io.Value)4