Search in sources :

Example 1 with PathUpdate

use of eu.esdihumboldt.hale.common.core.io.PathUpdate 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 2 with PathUpdate

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

the class PathUpdateTest method testProjectSubfolder.

/**
 * Extended real world example - project file in a subfolder and renamed
 */
@Test
public void testProjectSubfolder() {
    String orgPath = "C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/unification/project/t1t2.hale";
    String path = "C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/propmerge/project/t1t2_alt.hale";
    PathUpdate update = new PathUpdate(URI.create("file:/" + orgPath), URI.create("file:/" + path));
    URI file = URI.create("file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/unification/t1.xsd");
    String correct = "file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/propmerge/t1.xsd";
    String newpath = update.changePath(file).toString();
    assertEquals(correct, newpath);
}
Also used : PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) URI(java.net.URI) Test(org.junit.Test)

Example 3 with PathUpdate

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

the class PathUpdateTest method testSubfolder3.

/**
 * Extended real world example - file in a subsubfolder
 */
@Test
public void testSubfolder3() {
    String orgPath = "C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/unification/t1t2.hale";
    String path = "C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/propmerge/t1t2.hale";
    PathUpdate update = new PathUpdate(URI.create("file:/" + orgPath), URI.create("file:/" + path));
    URI file = URI.create("file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/unification/source/schemas/t1.xsd");
    String correct = "file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/propmerge/source/schemas/t1.xsd";
    String newpath = update.changePath(file).toString();
    assertEquals(correct, newpath);
}
Also used : PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) URI(java.net.URI) Test(org.junit.Test)

Example 4 with PathUpdate

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

the class PathUpdateTest method testSubfolder.

/**
 * Extended real world example - file in a subfolder
 */
@Test
public void testSubfolder() {
    PathUpdate update = new PathUpdate(URI.create("file:/C:/Users/sitemple/Entwicklung/humboldt2/_testdata/watercourse%20-%20Kopie/test.hale"), URI.create("file:/C:/Users/sitemple/Entwicklung/humboldt2/_testdata/wva2/test.hale"));
    URI file = URI.create("file:/C:/Users/sitemple/Entwicklung/humboldt2/_testdata/watercourse%20-%20Kopie/inspire3/HydroPhysicalWaters.xsd");
    String correct = "file:/C:/Users/sitemple/Entwicklung/humboldt2/_testdata/wva2/inspire3/HydroPhysicalWaters.xsd";
    String newpath = update.changePath(file).toString();
    assertEquals(correct, newpath);
}
Also used : PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) URI(java.net.URI) Test(org.junit.Test)

Example 5 with PathUpdate

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

the class OmlReader method loadAlignment.

@Override
protected MutableAlignment loadAlignment(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    try {
        progress.begin("Load ontology mapping file", ProgressIndicator.UNKNOWN);
        OmlRdfReader reader = new OmlRdfReader();
        Alignment alignment = reader.read(getSource().getLocation().toURL());
        AlignmentBean align = new AlignmentBean();
        List<CellBean> cells = new ArrayList<CellBean>();
        List<ICell> map = alignment.getMap();
        for (ICell cell : map) {
            // create a new CellBean for each ICell
            CellBean cellBean = new CellBean();
            IEntity entity = cell.getEntity1();
            IEntity entity2 = cell.getEntity2();
            // temporary list to be copied into the CellBean
            List<NamedEntityBean> temp_source = new ArrayList<NamedEntityBean>();
            List<NamedEntityBean> temp_target = new ArrayList<NamedEntityBean>();
            setBeanLists(entity, temp_source, getSourceSchema());
            setBeanLists(entity2, temp_target, getTargetSchema());
            // set source/target lists of the CellBean
            cellBean.setSource(temp_source);
            cellBean.setTarget(temp_target);
            // check if one of the entities has a transformation
            if (entity.getTransformation() != null || entity2.getTransformation() != null) {
                // entity 1 if it has the transformation
                if (entity.getTransformation() != null) {
                    setParameters(cellBean, entity, reporter, cell);
                    setTransformationId(cellBean, entity);
                } else {
                    // else set parameters and transformation id from entity
                    // 2
                    setParameters(cellBean, entity2, reporter, cell);
                    setTransformationId(cellBean, entity2);
                }
            }
            // add the CellBean to a list of CellBeans
            cells.add(cellBean);
        }
        // set the cells for the alignment after the all iterations
        align.setCells(cells);
        MutableAlignment mutableAlignment = align.createAlignment(reporter, getSourceSchema(), getTargetSchema(), new PathUpdate(null, null));
        reporter.setSuccess(true);
        return mutableAlignment;
    } finally {
        progress.end();
    }
}
Also used : IEntity(eu.esdihumboldt.hale.io.oml.internal.model.align.IEntity) ArrayList(java.util.ArrayList) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) ICell(eu.esdihumboldt.hale.io.oml.internal.model.align.ICell) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) Alignment(eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment) CellBean(eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean) NamedEntityBean(eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean) AlignmentBean(eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) OmlRdfReader(eu.esdihumboldt.hale.io.oml.internal.goml.oml.io.OmlRdfReader)

Aggregations

PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)15 URI (java.net.URI)10 Test (org.junit.Test)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)5 IOException (java.io.IOException)5 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)3 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)2 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)2 ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)2 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)2 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)2 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)2 Locatable (eu.esdihumboldt.hale.common.core.io.supplier.Locatable)2 OutputStream (java.io.OutputStream)2 AlignmentReader (eu.esdihumboldt.hale.common.align.io.AlignmentReader)1 JaxbAlignmentReader (eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentReader)1 AlignmentBean (eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean)1 CellBean (eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean)1 NamedEntityBean (eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean)1