Search in sources :

Example 1 with VersionControl

use of org.geotoolkit.version.VersionControl in project geotoolkit by Geomatys.

the class PostgresSimpleTypeTest method reload.

private void reload(boolean simpleType) throws DataStoreException, VersioningException {
    if (store != null) {
        store.close();
    }
    // open in complex type to delete all types
    params.getOrCreate(PostgresProvider.SIMPLETYPE).setValue(false);
    store = (PostgresStore) DataStores.open(params);
    while (!store.getNames().isEmpty()) {
        // we get the list each type because relations may delete multiple types each time
        final GenericName n = store.getNames().iterator().next();
        final VersionControl vc = store.getVersioning(n.toString());
        vc.dropVersioning();
        store.deleteFeatureType(n.toString());
    }
    assertTrue(store.getNames().isEmpty());
    store.close();
    // reopen the way it was asked
    params.getOrCreate(PostgresProvider.SIMPLETYPE).setValue(simpleType);
    store = (PostgresStore) DataStores.open(params);
    assertTrue(store.getNames().isEmpty());
}
Also used : GenericName(org.opengis.util.GenericName) VersionControl(org.geotoolkit.version.VersionControl)

Example 2 with VersionControl

use of org.geotoolkit.version.VersionControl in project geotoolkit by Geomatys.

the class PostgresVersioningTest method testTrimVersioning.

@Test
public void testTrimVersioning() throws DataStoreException, VersioningException {
    reload(true);
    List<Version> versions;
    Feature feature;
    ResourceId fid;
    Version v0;
    Version v1;
    Version v2;
    FeatureIterator ite;
    Query qb = new Query();
    // create table
    final FeatureType refType = FTYPE_SIMPLE;
    store.createFeatureType(refType);
    assertEquals(1, store.getNames().size());
    // get version control
    final VersionControl vc = store.getVersioning(refType.getName().toString());
    assertNotNull(vc);
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    // start versioning /////////////////////////////////////////////////////
    vc.startVersioning();
    assertTrue(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // make an insert ///////////////////////////////////////////////////////
    final Point firstPoint = GF.createPoint(new Coordinate(56, 45));
    feature = refType.newInstance();
    feature.setPropertyValue("id", "0");
    feature.setPropertyValue("boolean", Boolean.TRUE);
    feature.setPropertyValue("integer", 14);
    feature.setPropertyValue("point", firstPoint);
    feature.setPropertyValue("string", "someteststring");
    store.addFeatures(refType.getName().toString(), Collections.singleton(feature));
    // we should have one version
    versions = vc.list();
    assertEquals(1, versions.size());
    // get identifier
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make an update ///////////////////////////////////////////////////////
    final Point secondPoint = GF.createPoint(new Coordinate(-12, 21));
    final Map<String, Object> updates = new HashMap<>();
    updates.put("boolean", Boolean.FALSE);
    updates.put("integer", -3);
    updates.put("point", secondPoint);
    updates.put("string", "anothertextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates);
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make a 2nd update ///////////////////////////////////////////////////////
    final Point thirdPoint = GF.createPoint(new Coordinate(145, -221));
    final Map<String, Object> updates2 = new HashMap<>();
    updates2.put("boolean", Boolean.FALSE);
    updates2.put("integer", 150);
    updates2.put("point", thirdPoint);
    updates2.put("string", "secondtextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates2);
    // get all versions organized in increase dates order.
    versions = vc.list();
    assertEquals(3, versions.size());
    v0 = versions.get(0);
    v1 = versions.get(1);
    v2 = versions.get(2);
    /* first trim between v1 date and v2 date (named middle date) to verify
         * deletion of first version and update v1 date at trim date.*/
    final Date middle = new Date((v1.getDate().getTime() + v2.getDate().getTime()) >> 1);
    vc.trim(middle);
    versions = vc.list();
    assertEquals(2, versions.size());
    // ensure version 0 does not exist
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v0.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure version v1 begin at middle date.
    assertEquals(vc.list().get(0).getDate().getTime(), middle.getTime());
    /* second trim at exactely the begining of the third version to verify,
         * deletion of second version and third version existence.*/
    vc.trim(v2);
    versions = vc.list();
    assertEquals(1, versions.size());
    // ensure version 1 does not exist
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure version v2 begin time doesn't change.
    assertEquals(vc.list().get(0).getDate().getTime(), v2.getDate().getTime());
    /* third trim just after v3 version date, to verify that v3
         * version date become trim date */
    final long lastDate = v2.getDate().getTime() + 400;
    vc.trim(new Date(lastDate));
    versions = vc.list();
    assertEquals(1, versions.size());
    // ensure version v2 begin time become lastDate.
    assertEquals(vc.list().get(0).getDate().getTime(), lastDate);
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) Point(org.locationtech.jts.geom.Point) Feature(org.opengis.feature.Feature) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Version(org.geotoolkit.version.Version) ResourceId(org.opengis.filter.ResourceId) Coordinate(org.locationtech.jts.geom.Coordinate) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Test(org.junit.Test)

Example 3 with VersionControl

use of org.geotoolkit.version.VersionControl in project geotoolkit by Geomatys.

the class PostgresVersioningTest method testRevertVersioning.

@Test
public void testRevertVersioning() throws DataStoreException, VersioningException {
    reload(true);
    List<Version> versions;
    Feature feature;
    ResourceId fid;
    Version v0;
    Version v1;
    Version v2;
    FeatureIterator ite;
    Query qb = new Query();
    // create table
    final FeatureType refType = FTYPE_SIMPLE;
    store.createFeatureType(refType);
    assertEquals(1, store.getNames().size());
    // get version control
    final VersionControl vc = store.getVersioning(refType.getName().toString());
    assertNotNull(vc);
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    // start versioning /////////////////////////////////////////////////////
    vc.startVersioning();
    assertTrue(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // make an insert ///////////////////////////////////////////////////////
    final Point firstPoint = GF.createPoint(new Coordinate(56, 45));
    feature = refType.newInstance();
    feature.setPropertyValue("id", "0");
    feature.setPropertyValue("boolean", Boolean.TRUE);
    feature.setPropertyValue("integer", 14);
    feature.setPropertyValue("point", firstPoint);
    feature.setPropertyValue("string", "someteststring");
    store.addFeatures(refType.getName().toString(), Collections.singleton(feature));
    // we should have one version
    versions = vc.list();
    assertEquals(1, versions.size());
    // get identifier
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make an update ///////////////////////////////////////////////////////
    final Point secondPoint = GF.createPoint(new Coordinate(-12, 21));
    final Map<String, Object> updates = new HashMap<>();
    updates.put("boolean", Boolean.FALSE);
    updates.put("integer", -3);
    updates.put("point", secondPoint);
    updates.put("string", "anothertextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates);
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make a remove ///////////////////////////////////////////////////////
    store.removeFeatures(refType.getName().toString(), fid);
    // ensure test table is empty
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // get all versions organized in increase dates order.
    versions = vc.list();
    assertEquals(3, versions.size());
    v0 = versions.get(0);
    v1 = versions.get(1);
    v2 = versions.get(2);
    /* first revert between v1 date and v2 date (named middle date) to verify
         * re - insertion of feature in the original base and update v2 ending date become null.*/
    // =/2
    final Date middle = new Date((v1.getDate().getTime() + v2.getDate().getTime()) >> 1);
    vc.revert(middle);
    versions = vc.list();
    assertEquals(2, versions.size());
    // ensure version v2 does not exist
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v2.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure test table contain feature from version 1
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertFalse(store.createSession(true).getFeatureCollection(qb).isEmpty());
    Feature featV1;
    Feature feat;
    // feature from test base result.
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feat = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    // feature from version v1.
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        featV1 = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    assertTrue(feat.getProperty("boolean").equals(featV1.getProperty("boolean")));
    assertTrue(feat.getProperty("integer").equals(featV1.getProperty("integer")));
    assertTrue(feat.getProperty("point").equals(featV1.getProperty("point")));
    assertTrue(feat.getProperty("string").equals(featV1.getProperty("string")));
    /* second revert at v0 begin date to verify update roll back, and verify
         * feature update from history table into original base.*/
    vc.revert(v0.getDate());
    versions = vc.list();
    assertEquals(1, versions.size());
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure test table contain feature from version 1
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertFalse(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // feature from test base result.
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feat = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    // feature from version v1.
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v0.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        featV1 = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    assertTrue(feat.getProperty("boolean").equals(featV1.getProperty("boolean")));
    assertTrue(feat.getProperty("integer").equals(featV1.getProperty("integer")));
    assertTrue(feat.getProperty("point").equals(featV1.getProperty("point")));
    assertTrue(feat.getProperty("string").equals(featV1.getProperty("string")));
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) Point(org.locationtech.jts.geom.Point) Feature(org.opengis.feature.Feature) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Version(org.geotoolkit.version.Version) ResourceId(org.opengis.filter.ResourceId) Coordinate(org.locationtech.jts.geom.Coordinate) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Test(org.junit.Test)

Example 4 with VersionControl

use of org.geotoolkit.version.VersionControl in project geotoolkit by Geomatys.

the class PostgresVersioningTest method testSimpleTypeVersioning.

@Test
public void testSimpleTypeVersioning() throws DataStoreException, VersioningException {
    reload(true);
    List<Version> versions;
    Version version;
    Feature feature;
    ResourceId fid;
    Version v1;
    Version v2;
    Version v3;
    FeatureIterator ite;
    Query qb = new Query();
    // create table
    final FeatureType refType = FTYPE_SIMPLE;
    store.createFeatureType(refType);
    assertEquals(1, store.getNames().size());
    assertNotNull(store.getQueryCapabilities());
    assertTrue(store.getQueryCapabilities().handleVersioning());
    // get version control
    final VersionControl vc = store.getVersioning(refType.getName().toString());
    assertNotNull(vc);
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    // //////////////////////////////////////////////////////////////////////
    // start versioning /////////////////////////////////////////////////////
    vc.startVersioning();
    assertTrue(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // check the version table is not visible in the feature types
    store.refreshMetaModel();
    final Set<GenericName> names = store.getNames();
    assertEquals(1, names.size());
    // //////////////////////////////////////////////////////////////////////
    // make an insert ///////////////////////////////////////////////////////
    final Point firstPoint = GF.createPoint(new Coordinate(56, 45));
    feature = refType.newInstance();
    feature.setPropertyValue("id", "0");
    feature.setPropertyValue("boolean", Boolean.TRUE);
    feature.setPropertyValue("integer", 14);
    feature.setPropertyValue("point", firstPoint);
    feature.setPropertyValue("string", "someteststring");
    store.addFeatures(refType.getName().toString(), Collections.singleton(feature));
    // we should have one version
    versions = vc.list();
    assertEquals(1, versions.size());
    version = versions.get(0);
    Date date = version.getDate();
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    // ensure normal reading is correct with version-------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(version.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // //////////////////////////////////////////////////////////////////////
    // make an update ///////////////////////////////////////////////////////
    final Point secondPoint = GF.createPoint(new Coordinate(-12, 21));
    final Map<String, Object> updates = new HashMap<>();
    updates.put("boolean", Boolean.FALSE);
    updates.put("integer", -3);
    updates.put("point", secondPoint);
    updates.put("string", "anothertextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates);
    // we should have two versions
    versions = vc.list();
    assertEquals(2, versions.size());
    v1 = versions.get(0);
    v2 = versions.get(1);
    // should be ordered starting from the oldest
    assertTrue(v1.getDate().compareTo(v2.getDate()) < 0);
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.FALSE, feature.getPropertyValue("boolean"));
        assertEquals(-3, feature.getPropertyValue("integer"));
        assertEquals(secondPoint, feature.getPropertyValue("point"));
        assertEquals("anothertextupdated", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // ensure normal reading is correct with version-------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v2.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.FALSE, feature.getPropertyValue("boolean"));
        assertEquals(-3, feature.getPropertyValue("integer"));
        assertEquals(secondPoint, feature.getPropertyValue("point"));
        assertEquals("anothertextupdated", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // ensure reading a previous version works ------------------------------
    qb = new Query();
    ;
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // ensure reading a previous version using not exact date----------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionDate(new Date(v1.getDate().getTime() + 400));
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // //////////////////////////////////////////////////////////////////////
    // delete record ////////////////////////////////////////////////////////
    store.removeFeatures(refType.getName().toString(), fid);
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertEquals(0, store.getCount(qb));
    // we should have three versions
    versions = vc.list();
    assertEquals(3, versions.size());
    v1 = versions.get(0);
    v2 = versions.get(1);
    v3 = versions.get(2);
    // should be ordered starting from the oldest
    assertTrue(v2.getDate().compareTo(v1.getDate()) > 0);
    assertTrue(v3.getDate().compareTo(v2.getDate()) > 0);
    // ensure we have nothing if no version set -----------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // ensure we have nothing if latest version set -------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v3.getLabel());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // ensure we have nothing with date after deletion ----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionDate(new Date(v3.getDate().getTime() + 400));
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // ensure reading version 1 works ---------------------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getProperty("boolean").getValue());
        assertEquals(14, feature.getProperty("integer").getValue());
        assertEquals(firstPoint, feature.getProperty("point").getValue());
        assertEquals("someteststring", feature.getProperty("string").getValue());
    } finally {
        ite.close();
    }
    // ensure reading version 2 works ---------------------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v2.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.FALSE, feature.getProperty("boolean").getValue());
        assertEquals(-3, feature.getProperty("integer").getValue());
        assertEquals(secondPoint, feature.getProperty("point").getValue());
        assertEquals("anothertextupdated", feature.getProperty("string").getValue());
    } finally {
        ite.close();
    }
    // //////////////////////////////////////////////////////////////////////
    // drop versioning //////////////////////////////////////////////////////
    vc.dropVersioning();
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // ensure we have no record----------------------------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) Point(org.locationtech.jts.geom.Point) Feature(org.opengis.feature.Feature) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) GenericName(org.opengis.util.GenericName) Version(org.geotoolkit.version.Version) ResourceId(org.opengis.filter.ResourceId) Coordinate(org.locationtech.jts.geom.Coordinate) Test(org.junit.Test)

Example 5 with VersionControl

use of org.geotoolkit.version.VersionControl in project geotoolkit by Geomatys.

the class PGCVersioningTest method testVersioning.

@Test
public void testVersioning() throws DataStoreException, VersioningException {
    reload();
    final GeneralDirectPosition upperLeft = new GeneralDirectPosition(CommonCRS.WGS84.geographic());
    final Dimension dimension = new Dimension(20, 20);
    final Calendar calendar = Calendar.getInstance(GMT0);
    upperLeft.setOrdinate(0, -90);
    upperLeft.setOrdinate(1, +180);
    List<Version> versions;
    Version version;
    PyramidalCoverageResource cref;
    Pyramid pyramid;
    Mosaic mosaic;
    GridCoverage coverage;
    final GenericName name = NamesExt.create(null, "versLayer");
    store.add(new DefiningCoverageResource(name));
    final VersionControl vc = store.getVersioning(name);
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // create version 1 -----------------------------------------------------
    calendar.setTimeInMillis(0);
    final Date date1 = calendar.getTime();
    version = vc.createVersion(date1);
    cref = (PyramidalCoverageResource) store.findResource(name, version);
    assertNotNull(cref);
    // we need to create a pyramid otherwise the version not really be created
    pyramid = (Pyramid) cref.createModel(new DefiningPyramid(CommonCRS.WGS84.geographic()));
    mosaic = pyramid.createMosaic(new DefiningMosaic(null, upperLeft, 1, dimension, new Dimension(1, 1)));
    mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.RED), new Point(0, 0))), null);
    versions = vc.list();
    assertEquals(1, versions.size());
    assertEquals(versions.get(0).getDate().getTime(), 0);
    assertEquals(date1.getTime(), versions.get(0).getDate().getTime());
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.RED);
    // create version 2 -----------------------------------------------------
    calendar.setTimeInMillis(50000);
    final Date date2 = calendar.getTime();
    version = vc.createVersion(date2);
    cref = (PyramidalCoverageResource) store.findResource(name, version);
    assertNotNull(cref);
    // we need to create a pyramid otherwise the version not really be created
    pyramid = (Pyramid) cref.createModel(new DefiningPyramid(CommonCRS.WGS84.geographic()));
    mosaic = pyramid.createMosaic(new DefiningMosaic(null, upperLeft, 1, dimension, new Dimension(1, 1)));
    mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.BLUE), new Point(0, 0))), null);
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.BLUE);
    versions = vc.list();
    assertEquals(2, versions.size());
    assertEquals(versions.get(0).getDate().getTime(), 0);
    assertEquals(versions.get(1).getDate().getTime(), 50000);
    // create version 3 -----------------------------------------------------
    calendar.setTimeInMillis(20000);
    final Date date3 = calendar.getTime();
    version = vc.createVersion(date3);
    cref = (PyramidalCoverageResource) store.findResource(name, version);
    assertNotNull(cref);
    // we need to create a pyramid otherwise the version not really be created
    pyramid = (Pyramid) cref.createModel(new DefiningPyramid(CommonCRS.WGS84.geographic()));
    mosaic = pyramid.createMosaic(new DefiningMosaic(null, upperLeft, 1, dimension, new Dimension(1, 1)));
    mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.BLUE), new Point(0, 0))), null);
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.GREEN);
    versions = vc.list();
    assertEquals(3, versions.size());
    assertEquals(versions.get(0).getDate().getTime(), 0);
    assertEquals(versions.get(1).getDate().getTime(), 20000);
    assertEquals(versions.get(2).getDate().getTime(), 50000);
    // try accesing different version ---------------------------------------
    cref = (PyramidalCoverageResource) store.findResource(name.toString());
    // we should have the blue image
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.BLUE);
    // grab by version
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(0));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.RED);
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(1));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.GREEN);
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(2));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.BLUE);
    // drop some versions ---------------------------------------------------
    vc.dropVersion(versions.get(1));
    versions = vc.list();
    assertEquals(2, versions.size());
    assertEquals(versions.get(0).getDate().getTime(), 0);
    assertEquals(versions.get(1).getDate().getTime(), 50000);
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(0));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.RED);
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(1));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.BLUE);
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) Calendar(java.util.Calendar) DefiningCoverageResource(org.geotoolkit.storage.coverage.DefiningCoverageResource) DefiningMosaic(org.geotoolkit.data.multires.DefiningMosaic) DefaultImageTile(org.geotoolkit.storage.coverage.DefaultImageTile) Dimension(java.awt.Dimension) Point(java.awt.Point) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) Pyramid(org.geotoolkit.data.multires.Pyramid) DefiningPyramid(org.geotoolkit.data.multires.DefiningPyramid) GenericName(org.opengis.util.GenericName) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) Version(org.geotoolkit.version.Version) PyramidalCoverageResource(org.geotoolkit.storage.coverage.PyramidalCoverageResource) DefiningPyramid(org.geotoolkit.data.multires.DefiningPyramid) DefiningMosaic(org.geotoolkit.data.multires.DefiningMosaic) Mosaic(org.geotoolkit.data.multires.Mosaic) Test(org.junit.Test)

Aggregations

VersionControl (org.geotoolkit.version.VersionControl)13 Version (org.geotoolkit.version.Version)8 GenericName (org.opengis.util.GenericName)8 Test (org.junit.Test)7 Date (java.util.Date)6 HashMap (java.util.HashMap)6 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)6 Query (org.geotoolkit.storage.feature.query.Query)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 Point (org.locationtech.jts.geom.Point)6 Feature (org.opengis.feature.Feature)6 FeatureType (org.opengis.feature.FeatureType)6 ResourceId (org.opengis.filter.ResourceId)6 FeatureStoreRuntimeException (org.geotoolkit.storage.feature.FeatureStoreRuntimeException)3 Calendar (java.util.Calendar)2 DataStoreException (org.apache.sis.storage.DataStoreException)2 Session (org.geotoolkit.storage.feature.session.Session)2 VersioningException (org.geotoolkit.version.VersioningException)2 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1