transaction.putProperty("VersioningCommitAuthor", username); transaction.putProperty("VersioningCommitMessage", request.getHandle()); Object propKey = e.getKey(); Object propValue = e.getValue(); transaction.putProperty(propKey, propValue);
protected DefaultTransaction getDatastoreTransaction(TransactionType request) throws IOException { DefaultTransaction transaction = new DefaultTransaction(); // use handle as the log messages String username = "anonymous"; Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if(principal instanceof UserDetails) { username = ((UserDetails) principal).getUsername(); } transaction.putProperty(VersionedPostgisDataStore.AUTHOR, username); transaction.putProperty(VersionedPostgisDataStore.MESSAGE, request.getHandle()); return transaction; }
@Test public void testTransactionCommitAuthorAndEmail() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); DefaultTransaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { points.addFeatures(collection); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_AUTHOR, "john"); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_MESSAGE, "test message"); tx.putProperty("fullname", "John Doe"); tx.putProperty("email", "jd@example.com"); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } List<RevCommit> commits = toList(geogig.command(LogOp.class).call()); assertFalse(commits.isEmpty()); assertTrue(commits.get(0).getAuthor().getName().isPresent()); assertEquals("John Doe", commits.get(0).getAuthor().getName().orNull()); assertEquals("jd@example.com", commits.get(0).getAuthor().getEmail().orNull()); }
@Test public void testTransactionCommitAuthorAndEmail() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); DefaultTransaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { points.addFeatures(collection); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_AUTHOR, "john"); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_MESSAGE, "test message"); tx.putProperty("fullname", "John Doe"); tx.putProperty("email", "jd@example.com"); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } List<RevCommit> commits = toList(geogig.command(LogOp.class).call()); assertFalse(commits.isEmpty()); assertTrue(commits.get(0).getAuthor().getName().isPresent()); assertEquals("John Doe", commits.get(0).getAuthor().getName().orNull()); assertEquals("jd@example.com", commits.get(0).getAuthor().getEmail().orNull()); }
@Test public void testTransactionCommitMessage() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); DefaultTransaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { points.addFeatures(collection); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_AUTHOR, "John Doe"); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_MESSAGE, "test message"); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } List<RevCommit> commits = toList(geogig.command(LogOp.class).call()); assertFalse(commits.isEmpty()); assertTrue(commits.get(0).getAuthor().getName().isPresent()); assertEquals("John Doe", commits.get(0).getAuthor().getName().get()); assertEquals("test message", commits.get(0).getMessage()); }
@Test public void testTransactionCommitMessage() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); DefaultTransaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { points.addFeatures(collection); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_AUTHOR, "John Doe"); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_MESSAGE, "test message"); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } List<RevCommit> commits = toList(geogig.command(LogOp.class).call()); assertFalse(commits.isEmpty()); assertTrue(commits.get(0).getAuthor().getName().isPresent()); assertEquals("John Doe", commits.get(0).getAuthor().getName().get()); assertEquals("test message", commits.get(0).getMessage()); }