Search in sources :

Example 36 with Context

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

the class HashObjectTest method setUpInternal.

@Override
protected void setUpInternal() throws Exception {
    featureType1 = RevFeatureTypeImpl.build(pointsType);
    featureType2 = RevFeatureTypeImpl.build(linesType);
    featureType1Duplicate = RevFeatureTypeImpl.build(pointsType);
    pointFeature1 = RevFeatureBuilder.build(points1);
    pointFeature2 = RevFeatureBuilder.build(points2);
    pointFeature1Duplicate = RevFeatureBuilder.build(points1);
    CommitBuilder b = new CommitBuilder();
    b.setAuthor("groldan");
    b.setAuthorEmail("groldan@boundlessgeo.com");
    b.setCommitter("jdeolive");
    b.setCommitterEmail("jdeolive@boundlessgeo.com");
    b.setMessage("cool this works");
    b.setCommitterTimestamp(1000);
    b.setCommitterTimeZoneOffset(5);
    ObjectId treeId = ObjectId.forString("fake tree content");
    b.setTreeId(treeId);
    ObjectId parentId1 = ObjectId.forString("fake parent content 1");
    ObjectId parentId2 = ObjectId.forString("fake parent content 2");
    List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2);
    b.setParentIds(parentIds);
    commit1 = b.build();
    commit1Duplicate = b.build();
    b.setMessage(null);
    b.setAuthor(null);
    b.setAuthorEmail(null);
    b.setCommitterTimestamp(-1000);
    b.setCommitterTimeZoneOffset(-5);
    b.setParentIds(ImmutableList.of(parentId1, ObjectId.NULL));
    commit2 = b.build();
    Object boolArray = new boolean[] { true, false, true, true, false };
    Object byteArray = new byte[] { 100, 127, -110, 26, 42 };
    Object charArray = new char[] { 'a', 'b', 'c', 'd', 'e' };
    Object doubleArray = new double[] { 1.5, 1.6, 1.7, 1.8 };
    Object floatArray = new float[] { 1.1f, 3.14f, 6.0f, 0.0f };
    Object intArray = new int[] { 5, 7, 9, 11, 32 };
    Object longArray = new long[] { 100, 200, 300, 400 };
    TestSerializableObject serializableObject = new TestSerializableObject();
    serializableObject.words = "words to serialize";
    SimpleFeatureType coverageFeatureType = DataUtilities.createType("http://geoserver.org/test", "TestType", "str:String," + "str2:String," + "bool:Boolean," + "byte:java.lang.Byte," + "doub:Double," + "bdec:java.math.BigDecimal," + "flt:Float," + "int:Integer," + "bint:java.math.BigInteger," + "boolArray:java.lang.Object," + "byteArray:java.lang.Object," + "charArray:java.lang.Object," + "doubleArray:java.lang.Object," + "floatArray:java.lang.Object," + "intArray:java.lang.Object," + "longArray:java.lang.Object," + "serialized:java.io.Serializable," + "randomClass:java.lang.Object," + "pp:Point:srid=4326," + "lng:java.lang.Long," + "uuid:java.util.UUID");
    coverageRevFeatureType = RevFeatureTypeImpl.build(coverageFeatureType);
    Feature coverageFeature = feature(coverageFeatureType, "TestType.Coverage.1", "StringProp1_1", null, Boolean.TRUE, Byte.valueOf("18"), new Double(100.01), new BigDecimal("1.89e1021"), new Float(12.5), new Integer(1000), new BigInteger("90000000"), boolArray, byteArray, charArray, doubleArray, floatArray, intArray, longArray, serializableObject, new SomeRandomClass(), "POINT(1 1)", new Long(800000), UUID.fromString("bd882d24-0fe9-11e1-a736-03b3c0d0d06d"));
    coverageRevFeature = RevFeatureBuilder.build(coverageFeature);
    hashCommand = new HashObject();
    Context mockCommandLocator = mock(Context.class);
    hashCommand.setContext(mockCommandLocator);
    when(mockCommandLocator.command(eq(DescribeFeatureType.class))).thenReturn(new DescribeFeatureType());
}
Also used : Context(org.locationtech.geogig.api.Context) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) BigInteger(java.math.BigInteger)

Example 37 with Context

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

the class WriteBackTest method setUp.

@Before
public void setUp() {
    Context injector = Guice.createInjector(Modules.override(new GeogigModule()).with(new MemoryModule(null))).getInstance(Context.class);
    odb = injector.objectDatabase();
    indexDb = injector.stagingDatabase();
    odb.open();
    indexDb.open();
    writeBack = injector.command(WriteBack.class);
}
Also used : Context(org.locationtech.geogig.api.Context) GeogigModule(org.locationtech.geogig.di.GeogigModule) MemoryModule(org.locationtech.geogig.api.MemoryModule) Before(org.junit.Before)

Example 38 with Context

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

the class RefParseTest method setUp.

@Before
public void setUp() {
    mockRefDb = mock(RefDatabase.class);
    Builder<String, String> builder = ImmutableMap.builder();
    Map<String, String> allRefs = //
    builder.put("refs/heads/master", //
    forString("refs/heads/master").toString()).put("refs/heads/branch1", //
    forString("refs/heads/branch1").toString()).put("refs/heads/v1.1", //
    forString("refs/heads/v1.1").toString()).put("refs/tags/tag1", //
    forString("refs/tags/tag1").toString()).put("refs/tags/v1.1", //
    forString("refs/tags/v1.1").toString()).put("refs/remotes/origin/master", //
    forString("refs/remotes/origin/master").toString()).put("refs/remotes/origin/branch1", //
    forString("refs/remotes/origin/branch1").toString()).put("refs/remotes/juan/master", //
    forString("refs/remotes/juan/master").toString()).put("refs/remotes/juan/v1.1", //
    forString("refs/remotes/juan/v1.1").toString()).build();
    when(mockRefDb.getAll()).thenReturn(allRefs);
    command = new RefParse();
    for (String name : allRefs.keySet()) {
        when(mockRefDb.getRef(eq(name))).thenReturn(allRefs.get(name));
    }
    Context mockCommandLocator = mock(Context.class);
    when(mockCommandLocator.refDatabase()).thenReturn(mockRefDb);
    command.setContext(mockCommandLocator);
    ResolveObjectType mockResolveObjectType = mock(ResolveObjectType.class);
    when(mockCommandLocator.command(eq(ResolveObjectType.class))).thenReturn(mockResolveObjectType);
    when(mockResolveObjectType.setObjectId((ObjectId) anyObject())).thenReturn(mockResolveObjectType);
    when(mockResolveObjectType.call()).thenReturn(TYPE.COMMIT);
}
Also used : Context(org.locationtech.geogig.api.Context) ObjectId.forString(org.locationtech.geogig.api.ObjectId.forString) RefDatabase(org.locationtech.geogig.storage.RefDatabase) Before(org.junit.Before)

Example 39 with Context

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

the class OsmDownloadWebOp method getRepresentation.

@Override
public Representation getRepresentation(final Variant variant) {
    final Request request = getRequest();
    Context context = getContext(request);
    Form options = getRequest().getResourceRef().getQueryAsForm();
    final String filterFileArg = options.getFirstValue("filter");
    final String bboxArg = options.getFirstValue("bbox");
    final String messageArg = options.getFirstValue("message");
    final boolean update = Boolean.valueOf(options.getFirstValue("update"));
    final boolean rebase = Boolean.valueOf(options.getFirstValue("rebase"));
    final String mappingFileArg = options.getFirstValue("mapping");
    checkArgSpec(filterFileArg != null ^ bboxArg != null || update, "You must specify a filter file or a bounding box");
    checkArgSpec((filterFileArg != null || bboxArg != null) ^ update, "Filters cannot be used when updating");
    checkArgSpec(context.index().isClean() && context.workingTree().isClean(), "Working tree and index are not clean");
    checkArgSpec(!rebase || update, "rebase switch can only be used when updating");
    final File filterFile = parseFile(filterFileArg);
    final File mappingFile = parseFile(mappingFileArg);
    final List<String> bbox = parseBbox(bboxArg);
    checkArgSpec(filterFile == null || filterFile.exists(), "The specified filter file does not exist");
    checkArgSpec(mappingFile == null || mappingFile.exists(), "The specified mapping file does not exist");
    AbstractGeoGigOp<Optional<OSMReport>> command;
    if (update) {
        command = context.command(OSMUpdateOp.class).setRebase(rebase).setMessage(messageArg).setAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT);
    } else {
        command = context.command(OSMDownloadOp.class).setBbox(bbox).setFilterFile(filterFile).setMessage(messageArg).setMappingFile(mappingFile).setOsmAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT);
    }
    AsyncCommand<Optional<OSMReport>> asyncCommand;
    URL repo = context.repository().getLocation();
    String description = String.format("osm download filter: %s, bbox: %s, mapping: %s, update: %s, rebase: %s, repository: %s", filterFileArg, bboxArg, mappingFileArg, update, rebase, repo);
    asyncCommand = AsyncContext.get().run(command, description);
    final String rootPath = request.getRootRef().toString();
    MediaType mediaType = variant.getMediaType();
    Representation rep = new OSMReportRepresentation(mediaType, asyncCommand, rootPath);
    return rep;
}
Also used : Context(org.locationtech.geogig.api.Context) AsyncContext(org.locationtech.geogig.rest.AsyncContext) Optional(com.google.common.base.Optional) Form(org.restlet.data.Form) Request(org.restlet.data.Request) Representation(org.restlet.resource.Representation) URL(java.net.URL) MediaType(org.restlet.data.MediaType) File(java.io.File)

Example 40 with Context

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

the class OsmImportWebOp method getRepresentation.

@Override
public Representation getRepresentation(final Variant variant) {
    final Request request = getRequest();
    final Context context = super.getContext(request);
    Form options = getRequest().getResourceRef().getQueryAsForm();
    final String urlOrFilepath = options.getFirstValue("uri");
    final boolean add = Boolean.valueOf(options.getFirstValue("add"));
    final String mappingFile = options.getFirstValue("mapping");
    Mapping mapping = null;
    if (mappingFile != null) {
        mapping = Mapping.fromFile(mappingFile);
    }
    final boolean noRaw = Boolean.valueOf(options.getFirstValue("noRaw"));
    final String message = options.getFirstValue("message");
    if (urlOrFilepath == null) {
        String msg = "Missing parameter: uri\n" + "Usage: GET <repo context>/osm/import?uri=<osm file URI>[&<arg>=<value>]+\n" + "Arguments:\n" + " * uri: Mandatory. URL or path to OSM data file in the server filesystem\n" + " * add: Optional. true|false. Default: false. If true, do not remove previous data before importing.\n" + " * mapping: Optional. Location of mapping file in the server filesystem\n" + " * noRaw: Optional. true|false. Default: false. If true, do not import raw data when using a mapping\n" + " * message: Optional. Message for the commit to create.";
        throw new CommandSpecException(msg);
    }
    OSMImportOp command = context.command(OSMImportOp.class);
    command.setAdd(add);
    command.setDataSource(urlOrFilepath);
    command.setMapping(mapping);
    command.setMessage(message);
    command.setNoRaw(noRaw);
    AsyncCommand<Optional<OSMReport>> asyncCommand;
    URL repo = context.repository().getLocation();
    String description = String.format("osm import %s, repository: %s", urlOrFilepath, repo);
    asyncCommand = AsyncContext.get().run(command, description);
    final String rootPath = request.getRootRef().toString();
    MediaType mediaType = variant.getMediaType();
    Representation rep = new OSMReportRepresentation(mediaType, asyncCommand, rootPath);
    return rep;
}
Also used : Context(org.locationtech.geogig.api.Context) AsyncContext(org.locationtech.geogig.rest.AsyncContext) Optional(com.google.common.base.Optional) Form(org.restlet.data.Form) Request(org.restlet.data.Request) Mapping(org.locationtech.geogig.osm.internal.Mapping) OSMImportOp(org.locationtech.geogig.osm.internal.OSMImportOp) Representation(org.restlet.resource.Representation) URL(java.net.URL) MediaType(org.restlet.data.MediaType) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException)

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