Editor tracking

ArcGIS Runtime SDK for Java supports tracking edits made to features in an ArcGISFeatureLayer and, starting at version 10.2.4, in a GeodatabaseFeatureTable and GeodatabaseFeatureServiceTable.

Editor tracking records:

  • which user created the feature
  • the date and time the feature was created
  • which user last edited the feature
  • the date and time the last edit took place

See the ArcGIS for Server topic Editor tracking for feature services for more information on editor tracking.

Get the editor tracking fields

A feature service which has editor tracking capabilities has 'Edit Fields Info' about the layer which matches the four properties above to a field name from the layer's fields. In a Runtime Java application, when an ArcGISFeatureLayer is created from a service layer and initialized, you can obtain this information from the initialized layer as in the code snippet below:

// listen for the layer to be initialized
arcGISFeatureLayer.addLayerInitializeCompleteListener(
  new LayerInitializeCompleteListener() {

  @Override
  public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
    if (e.getLayer().getStatus() == LayerStatus.INITIALIZED) {
      // get the EditFieldsInfo from the initialized feature layer
      EditFieldsInfo efinfo = arcGISFeatureLayer.getEditFieldsInfo();
      // the relevant editor tracking field names can be obtained/stored as below
      String creatorField = efinfo.getCreatorField();
      String creationDateField = efinfo.getCreationDateField();
      String editorField = efinfo.getEditorField();
      String editDateField = efinfo.getEditDateField();
    }
  }
});

If you are using a GeodatabaseFeatureTable or GeodatabaseFeatureServiceTable (in conjunction with a FeatureLayer to display the data on a map), obtain the Edit Fields Info from the table instance rather than from the feature layer, as in the following example:

featureServiceTable = new GeodatabaseFeatureServiceTable(URL, credentials, LAYER_ID);
// ... initialize the table

FeatureLayer featureLayer = new FeatureLayer(featureServiceTable);
featureLayer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {
  @Override
  public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
    // get the EditFieldsInfo from the feature service table
    EditFieldsInfo efinfo = featureServiceTable.getEditFieldsInfo();
    // etc.
  }
});

You can now use these field names in your application. For example, you could show a map tip over a feature displaying the last editor of this feature and the time of the last edit.

Track and control edits

In a secured feature service, meaning one which you can only access with a valid username and password combination, the relevant editor tracking fields will be populated automatically when an edit is made, with the editor and/or creator field matching the username. If no authenticated user is provided and anonymous access is enabled on the feature service, the creator and editor fields are left set to the empty string. When you edit a feature in your Java application and apply the edits to the server, the time at which you have created or edited the feature gets automatically stored in the relevant field.

Note:

Take care to differentiate between edits made anonymously, where the username populated as the creator/editor is the empty string, and edits made by the Admin user, where the username populated is null.

Ownership-based access control can be enabled on a feature service, for example to limit the ability of users to update or delete features they did not create; see the ArcGIS for Server topic Ownership-based access control for feature services for more information. For a given user and a given graphic, you can programmatically have access to whether this user can create, update, or delete the graphic. You can then incorporate this into your editing workflow if desired.

An example workflow using ArcGISFeatureLayer is shown in the code below:

// user accesses the secure feature service as 'user1'
UserCredentials credentials = new UserCredentials();
credentials.setUserAccount("user1", password);

// supply the credentials when you create the ArcGISFeatureLayer
ArcGISFeatureLayer agsFeatureLayer = new ArcGISFeatureLayer(
   "http://sampleserver6.arcgisonline.com/arcgis/rest/services/SaveTheBay/FeatureServer/0",
   credentials);

// control the editing environment
// for example, say 'user1' selects 'graphic' via a mouse-click to delete it:
if (agsFeatureLayer.getEditCapabilities(graphic).isDelete()) {
	 // 'user1' is allowed to delete this graphic so delete the graphic
} else {
	 // 'user1' is not allowed to delete this graphic so inform user of this restriction
}

If you are using a GeodatabaseFeatureTable or GeodatabaseFeatureServiceTable instead, the methods to check for specific editing permissions (create, update, delete) are slightly different:

// user accesses the secure feature service as 'user1'
UserCredentials credentials = new UserCredentials();
credentials.setUserAccount("user1", password);

featureServiceTable = new GeodatabaseFeatureServiceTable(URL, credentials, LAYER_ID);
// ... initialize the table

// for example, say 'user1' selects a feature via a mouse-click to delete it:
 if (featureServiceTable.canDelete(selectedFeature.getId())) {
	 // 'user1' is allowed to delete this feature
} else {
	 // 'user1' is not allowed to delete this feature
}

Note:

Ownership-based access control permissions are in addition to any editing restrictions set on the service layer as a whole. For example, if the 'Delete' capability is not present on the layer globally, than no users can delete any features, whether they created them or not, and canDelete will always return false.

Sample code

To see editor tracking in action, please have a look at the interactive Editor Tracking sample in the ArcGIS Runtime SDK for Java samples, under the table of content heading Editing.