Search in sources :

Example 31 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class GeogigTransactionState method setTransaction.

@Override
public void setTransaction(@Nullable final Transaction transaction) {
    Preconditions.checkArgument(!Transaction.AUTO_COMMIT.equals(transaction));
    if (transaction != null && this.tx != null) {
        throw new IllegalStateException("New transaction set without closing old transaction first.");
    }
    this.tx = transaction;
    if (transaction == null) {
        // transaction.close())
        if (this.geogigTx != null) {
            // throw new
            // IllegalStateException("Transaction is attempting to "
            // + "close a non committed or aborted geogig transaction");
            geogigTx.abort();
        }
        this.geogigTx = null;
    } else {
        if (this.geogigTx != null) {
            geogigTx.abort();
        }
        GeoGigDataStore dataStore = (GeoGigDataStore) entry.getDataStore();
        Context commandLocator = dataStore.getCommandLocator(this.tx);
        this.geogigTx = commandLocator.command(TransactionBegin.class).call();
        // checkout the working branch
        final String workingBranch = dataStore.getOrFigureOutBranch();
        this.geogigTx.command(CheckoutOp.class).setForce(true).setSource(workingBranch).call();
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CheckoutOp(org.locationtech.geogig.api.porcelain.CheckoutOp)

Example 32 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class GeoGigDataStore method findTypeRefs.

private List<NodeRef> findTypeRefs(@Nullable Transaction tx) {
    final String rootRef = getRootRef(tx);
    Context commandLocator = getCommandLocator(tx);
    List<NodeRef> typeTrees = commandLocator.command(FindFeatureTypeTrees.class).setRootTreeRef(rootRef).call();
    return typeTrees;
}
Also used : Context(org.locationtech.geogig.api.Context) NodeRef(org.locationtech.geogig.api.NodeRef)

Example 33 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class GeogigFeatureSource method getNativeType.

SimpleFeatureType getNativeType() {
    final NodeRef typeRef = getTypeRef();
    final String treePath = typeRef.path();
    final ObjectId metadataId = typeRef.getMetadataId();
    Context commandLocator = getCommandLocator();
    Optional<RevFeatureType> revType = commandLocator.command(RevObjectParse.class).setObjectId(metadataId).call(RevFeatureType.class);
    if (!revType.isPresent()) {
        throw new IllegalStateException(String.format("Feature type for tree %s not found", treePath));
    }
    SimpleFeatureType featureType = (SimpleFeatureType) revType.get().type();
    return featureType;
}
Also used : Context(org.locationtech.geogig.api.Context) NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ObjectId(org.locationtech.geogig.api.ObjectId) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 34 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class GeogigFeatureSource method getTypeTree.

/**
     * @return
     */
RevTree getTypeTree() {
    String refSpec = getRootRef() + ":" + getTypeTreePath();
    Context commandLocator = getCommandLocator();
    Optional<RevTree> ref = commandLocator.command(RevObjectParse.class).setRefSpec(refSpec).call(RevTree.class);
    Preconditions.checkState(ref.isPresent(), "Ref %s not found on working tree", refSpec);
    return ref.get();
}
Also used : Context(org.locationtech.geogig.api.Context) RevTree(org.locationtech.geogig.api.RevTree)

Example 35 with Context

use of org.locationtech.geogig.api.Context in project GeoGig by boundlessgeo.

the class DiffTreeTest method setUp.

@Before
public void setUp() throws Exception {
    File workingDirectory = tempFolder.newFolder("mockWorkingDir");
    Platform testPlatform = new TestPlatform(workingDirectory);
    Context injector = Guice.createInjector(Modules.override(new GeogigModule()).with(new MemoryModule(testPlatform))).getInstance(Context.class);
    geogit = new GeoGIG(injector);
    assertNotNull(geogit.getOrCreateRepository());
    diffTree = geogit.command(DiffTree.class);
    SimpleFeatureType ft = DataUtilities.createType("points", "sp:String,ip:Integer,pp:Point:srid=3857");
    revtype = RevFeatureTypeImpl.build(ft);
    metadataId = revtype.getId();
    geogit.getContext().objectDatabase().put(revtype);
}
Also used : Context(org.locationtech.geogig.api.Context) TestPlatform(org.locationtech.geogig.api.TestPlatform) Platform(org.locationtech.geogig.api.Platform) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) TestPlatform(org.locationtech.geogig.api.TestPlatform) File(java.io.File) GeogigModule(org.locationtech.geogig.di.GeogigModule) MemoryModule(org.locationtech.geogig.api.MemoryModule) GeoGIG(org.locationtech.geogig.api.GeoGIG) Before(org.junit.Before)

Aggregations

Context (org.locationtech.geogig.api.Context)52 CommandContext (org.locationtech.geogig.web.api.CommandContext)24 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)24 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)24 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)16 ObjectId (org.locationtech.geogig.api.ObjectId)13 File (java.io.File)9 GeoGIG (org.locationtech.geogig.api.GeoGIG)9 NodeRef (org.locationtech.geogig.api.NodeRef)8 Ref (org.locationtech.geogig.api.Ref)8 Before (org.junit.Before)7 RevCommit (org.locationtech.geogig.api.RevCommit)7 Optional (com.google.common.base.Optional)6 Platform (org.locationtech.geogig.api.Platform)6 RevTree (org.locationtech.geogig.api.RevTree)6 TestPlatform (org.locationtech.geogig.api.TestPlatform)6 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)5 GeogigModule (org.locationtech.geogig.di.GeogigModule)5 MemoryModule (org.locationtech.geogig.api.MemoryModule)4 RevFeature (org.locationtech.geogig.api.RevFeature)4