コード例 #1
0
ファイル: GeoGitTest.java プロジェクト: ryantxu/jeo-contrib
  @Before
  public void setUp() throws IOException {
    Injector i =
        Guice.createInjector(Modules.override(new GeogitModule()).with(new JEStorageModule()));

    GeoGIT gg = new GeoGIT(i, Tests.newTmpDir("geogit", "tmp"));

    Repository repo = gg.getOrCreateRepository();
    repo.command(ConfigOp.class)
        .setAction(ConfigAction.CONFIG_SET)
        .setName("user.name")
        .setValue("Wile E Coyote")
        .call();
    repo.command(ConfigOp.class)
        .setAction(ConfigAction.CONFIG_SET)
        .setName("user.email")
        .setValue("*****@*****.**")
        .call();

    addShp(TestData.states(), repo);
    addShp(TestData.point(), repo);
    addShp(TestData.line(), repo);
    addShp(TestData.polygon(), repo);

    repo.command(BranchCreateOp.class).setName("scratch").call();
    ws = new GeoGitWorkspace(gg, null);
  }
コード例 #2
0
ファイル: GeoGitTest.java プロジェクト: hjanetzek/jeo
  void addShp(VectorDataset data, Repository repo) throws IOException {
    String name = data.getName();
    repo.getWorkingTree()
        .insert(
            name, GT.iterator(data.cursor(new Query())), new NullProgressListener(), null, null);
    data.close();

    AddOp add = repo.command(AddOp.class);
    add.call();

    CommitOp commit = repo.command(CommitOp.class);
    commit.setMessage("initial commit of " + name);
    commit.call();
  }
コード例 #3
0
ファイル: RepositoryTestCase.java プロジェクト: dwins/GeoGig
 public boolean delete(GeogitTransaction transaction, Feature f) throws Exception {
   final WorkingTree workTree =
       (transaction != null ? transaction.getWorkingTree() : repo.getWorkingTree());
   Name name = f.getType().getName();
   String localPart = name.getLocalPart();
   String id = f.getIdentifier().getID();
   boolean existed = workTree.delete(localPart, id);
   return existed;
 }
コード例 #4
0
ファイル: RepositoryTestCase.java プロジェクト: dwins/GeoGig
 /** Inserts the feature to the index but does not stages it to be committed */
 public ObjectId insert(GeogitTransaction transaction, Feature f) throws Exception {
   final WorkingTree workTree =
       (transaction != null ? transaction.getWorkingTree() : repo.getWorkingTree());
   Name name = f.getType().getName();
   String parentPath = name.getLocalPart();
   Node ref = workTree.insert(parentPath, f);
   ObjectId objectId = ref.getObjectId();
   return objectId;
 }
コード例 #5
0
ファイル: RepositoryTestCase.java プロジェクト: dwins/GeoGig
 @After
 public final void tearDown() throws Exception {
   setup = false;
   tearDownInternal();
   if (repo != null) {
     repo.close();
   }
   repo = null;
   injector = null;
 }
コード例 #6
0
ファイル: ObjectFinder.java プロジェクト: ROGUE-JCTD/GeoGit
  @Override
  public Resource findTarget(Request request, Response response) {

    if (request.getAttributes().containsKey("id")) {
      final Optional<GeoGIT> ggit = getGeogit(request);
      Preconditions.checkState(ggit.isPresent());

      final String id = (String) request.getAttributes().get("id");
      final ObjectId oid = ObjectId.valueOf(id);

      GeoGIT geogit = ggit.get();
      Repository repository = geogit.getRepository();
      boolean blobExists = repository.blobExists(oid);
      if (blobExists) {
        ObjectResource objectResource = new ObjectResource(oid, geogit);
        objectResource.init(getContext(), request, response);
        return objectResource;
      }
    }

    return super.findTarget(request, response);
  }
コード例 #7
0
 @Override
 public Feature apply(final Ref featureRef) {
   String featureId = featureRef.getName();
   ObjectId contentId = featureRef.getObjectId();
   StagingDatabase database = repo.getIndex().getDatabase();
   Feature feature;
   try {
     ObjectReader<Feature> featureReader =
         serialisingFactory.createFeatureReader(type, featureId);
     feature = database.get(contentId, featureReader);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   return VersionedFeatureWrapper.wrap(feature, featureRef.getObjectId().toString());
 }
コード例 #8
0
  @Override
  public <I> I decorate(I subject) {
    if (listener == null) {
      listener =
          new RepositoryListener() {

            @Override
            public void opened(Repository repo) {
              service.startAsync().awaitRunning();
            }

            @Override
            public void closed() {
              service.stopAsync();
            }
          };
      ((Repository) subject).addListener(listener);
    }
    return subject;
  }
コード例 #9
0
ファイル: ObjectFinder.java プロジェクト: ROGUE-JCTD/GeoGit
 @Override
 public void write(OutputStream out) throws IOException {
   Repository repository = ggit.getRepository();
   RevObject rawObject = repository.objectDatabase().get(oid);
   serialFac.createObjectWriter(rawObject.getType()).write(rawObject, out);
 }
コード例 #10
0
  /**
   * This function takes all of the changes introduced by a commit on the sparse repository and
   * creates a new commit on the full repository with those changes.
   *
   * @param commitId the commit id of commit from the sparse repository
   * @param from the sparse repository
   * @param to the full repository
   */
  protected void pushSparseCommit(ObjectId commitId) {
    Repository from = localRepository;
    Repository to = remoteGeoGit.getRepository();
    Optional<RevObject> object = from.command(RevObjectParse.class).setObjectId(commitId).call();
    if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
      RevCommit commit = (RevCommit) object.get();
      ObjectId parent = ObjectId.NULL;
      List<ObjectId> newParents = new LinkedList<ObjectId>();
      for (int i = 0; i < commit.getParentIds().size(); i++) {
        ObjectId parentId = commit.getParentIds().get(i);
        if (i != 0) {
          Optional<ObjectId> commonAncestor =
              from.getGraphDatabase()
                  .findLowestCommonAncestor(commit.getParentIds().get(0), parentId);
          if (commonAncestor.isPresent()) {
            if (from.getGraphDatabase().isSparsePath(parentId, commonAncestor.get())) {
              // This should be the base commit to preserve the sparse changes that
              // were filtered
              // out.
              newParents.add(0, from.getGraphDatabase().getMapping(parentId));
              continue;
            }
          }
        }
        newParents.add(from.getGraphDatabase().getMapping(parentId));
      }
      if (newParents.size() > 0) {
        parent = from.getGraphDatabase().getMapping(newParents.get(0));
      }
      Iterator<DiffEntry> diffIter =
          from.command(DiffOp.class)
              .setNewVersion(commitId)
              .setOldVersion(parent)
              .setReportTrees(true)
              .call();

      LocalCopyingDiffIterator changes = new LocalCopyingDiffIterator(diffIter, from, to);

      RevTree rootTree = RevTree.EMPTY;

      if (newParents.size() > 0) {
        ObjectId mappedCommit = newParents.get(0);

        Optional<ObjectId> treeId =
            to.command(ResolveTreeish.class).setTreeish(mappedCommit).call();
        if (treeId.isPresent()) {
          rootTree = to.getTree(treeId.get());
        }
      }

      // Create new commit
      ObjectId newTreeId =
          to.command(WriteTree.class)
              .setOldRoot(Suppliers.ofInstance(rootTree))
              .setDiffSupplier(Suppliers.ofInstance((Iterator<DiffEntry>) changes))
              .call();

      CommitBuilder builder = new CommitBuilder(commit);
      builder.setParentIds(newParents);
      builder.setTreeId(newTreeId);

      RevCommit mapped = builder.build();
      to.getObjectDatabase().put(mapped);

      from.getGraphDatabase().map(commit.getId(), mapped.getId());
      from.getGraphDatabase().map(mapped.getId(), commit.getId());
    }
  }
コード例 #11
0
ファイル: RepositoryTestCase.java プロジェクト: dwins/GeoGig
  protected final void doSetUp() throws IOException, SchemaException, ParseException, Exception {
    envHome = repositoryTempFolder.getRoot();

    injector = createInjector();

    geogit = new GeoGIT(injector, envHome);
    repo = geogit.getOrCreateRepository();
    repo.command(ConfigOp.class)
        .setAction(ConfigAction.CONFIG_SET)
        .setName("user.name")
        .setValue("Gabriel Roldan")
        .call();
    repo.command(ConfigOp.class)
        .setAction(ConfigAction.CONFIG_SET)
        .setName("user.email")
        .setValue("*****@*****.**")
        .call();

    pointsType = DataUtilities.createType(pointsNs, pointsName, pointsTypeSpec);
    modifiedPointsType = DataUtilities.createType(pointsNs, pointsName, modifiedPointsTypeSpec);

    points1 = feature(pointsType, idP1, "StringProp1_1", new Integer(1000), "POINT(1 1)");
    points1_modified = feature(pointsType, idP1, "StringProp1_1a", new Integer(1001), "POINT(1 2)");
    points1B =
        feature(
            modifiedPointsType,
            idP1,
            "StringProp1_1",
            new Integer(1000),
            "POINT(1 1)",
            "ExtraString");

    points1B_modified =
        feature(
            modifiedPointsType,
            idP1,
            "StringProp1_1a",
            new Integer(1001),
            "POINT(1 2)",
            "ExtraStringB");

    points2 = feature(pointsType, idP2, "StringProp1_2", new Integer(2000), "POINT(2 2)");
    points3 = feature(pointsType, idP3, "StringProp1_3", new Integer(3000), "POINT(3 3)");

    linesType = DataUtilities.createType(linesNs, linesName, linesTypeSpec);

    lines1 = feature(linesType, idL1, "StringProp2_1", new Integer(1000), "LINESTRING (1 1, 2 2)");
    lines2 = feature(linesType, idL2, "StringProp2_2", new Integer(2000), "LINESTRING (3 3, 4 4)");
    lines3 = feature(linesType, idL3, "StringProp2_3", new Integer(3000), "LINESTRING (5 5, 6 6)");

    polyType = DataUtilities.createType(polyNs, polyName, polyTypeSpec);

    poly1 =
        feature(
            polyType,
            idPG1,
            "StringProp3_1",
            new Integer(1000),
            "POLYGON ((1 1, 2 2, 3 3, 4 4, 1 1))");
    poly2 =
        feature(
            polyType,
            idPG2,
            "StringProp3_2",
            new Integer(2000),
            "POLYGON ((6 6, 7 7, 8 8, 9 9, 6 6))");
    poly3 =
        feature(
            polyType,
            idPG3,
            "StringProp3_3",
            new Integer(3000),
            "POLYGON ((11 11, 12 12, 13 13, 14 14, 11 11))");

    setUpInternal();
  }