Skip to content

[New] List geodatabase versions #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Samples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
004FE87129DF5D8700075217 /* Bristol in Resources */ = {isa = PBXBuildFile; fileRef = 004FE87029DF5D8700075217 /* Bristol */; settings = {ASSET_TAGS = (Animate3DGraphic, ChangeCameraController, OrbitCameraAroundObject, StylePointWithDistanceCompositeSceneSymbol, ); }; };
006C835528B40682004AEB7F /* BrowseBuildingFloorsView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = E0FE32E628747778002C6ACA /* BrowseBuildingFloorsView.swift */; };
006C835628B40682004AEB7F /* DisplayMapFromMobileMapPackageView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = F111CCC0288B5D5600205358 /* DisplayMapFromMobileMapPackageView.swift */; };
007079212DE0E7E800E06300 /* ListGeodatabaseVersionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 007079202DE0E7E200E06300 /* ListGeodatabaseVersionsView.swift */; };
007079222DE104B700E06300 /* ListGeodatabaseVersionsView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 007079202DE0E7E200E06300 /* ListGeodatabaseVersionsView.swift */; };
0072C7F42DBAA65E001502CA /* AddFeatureCollectionLayerFromTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0072C7F32DBAA65B001502CA /* AddFeatureCollectionLayerFromTableView.swift */; };
0072C7F52DBAB714001502CA /* AddFeatureCollectionLayerFromTableView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 0072C7F32DBAA65B001502CA /* AddFeatureCollectionLayerFromTableView.swift */; };
0072C7FA2DBABEAC001502CA /* AddIntegratedMeshLayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0072C7F92DBABEA9001502CA /* AddIntegratedMeshLayerView.swift */; };
Expand Down Expand Up @@ -682,6 +684,7 @@
dstPath = "";
dstSubfolderSpec = 7;
files = (
007079222DE104B700E06300 /* ListGeodatabaseVersionsView.swift in Copy Source Code Files */,
88AF55542DDBFA9C003F146E /* CreateAndSaveMapView.swift in Copy Source Code Files */,
002056E92DDD484B0016B8A9 /* DisplayOGCAPICollectionView.swift in Copy Source Code Files */,
88AF55502DD7EABF003F146E /* BrowseWMSLayersView.swift in Copy Source Code Files */,
Expand Down Expand Up @@ -982,6 +985,7 @@
004A2B9C2BED455B00C297CE /* canyonlands */ = {isa = PBXFileReference; lastKnownFileType = folder; path = canyonlands; sourceTree = "<group>"; };
004A2B9E2BED456500C297CE /* ApplyScheduledUpdatesToPreplannedMapAreaView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplyScheduledUpdatesToPreplannedMapAreaView.swift; sourceTree = "<group>"; };
004FE87029DF5D8700075217 /* Bristol */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Bristol; sourceTree = "<group>"; };
007079202DE0E7E200E06300 /* ListGeodatabaseVersionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListGeodatabaseVersionsView.swift; sourceTree = "<group>"; };
0072C7F32DBAA65B001502CA /* AddFeatureCollectionLayerFromTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeatureCollectionLayerFromTableView.swift; sourceTree = "<group>"; };
0072C7F92DBABEA9001502CA /* AddIntegratedMeshLayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddIntegratedMeshLayerView.swift; sourceTree = "<group>"; };
0072C7FF2DBAF08B001502CA /* AddItemsToPortalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddItemsToPortalView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1455,6 +1459,14 @@
path = "Apply scheduled updates to preplanned map area";
sourceTree = "<group>";
};
0070791E2DE0E7DC00E06300 /* List geodatabase versions */ = {
isa = PBXGroup;
children = (
007079202DE0E7E200E06300 /* ListGeodatabaseVersionsView.swift */,
);
path = "List geodatabase versions";
sourceTree = "<group>";
};
0072C7F12DBAA64C001502CA /* Add feature collection layer from table */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1624,6 +1636,7 @@
D751018A2A2E960300B8FA48 /* Identify layer features */,
D7464F182ACE0445007FEE88 /* Identify raster cell */,
D75E5EE52CC0340100252595 /* List contents of KML file */,
0070791E2DE0E7DC00E06300 /* List geodatabase versions */,
D776880E2B69826B007C3860 /* List spatial reference transformations */,
D718A1E92B575FD900447087 /* Manage bookmarks */,
D752D93C2A3914E5003EB25E /* Manage operational layers */,
Expand Down Expand Up @@ -4274,6 +4287,7 @@
D72F272E2ADA1E4400F906DA /* AugmentRealityToShowTabletopSceneView.swift in Sources */,
10B782082BE5A058007EAE6C /* GenerateOfflineMapWithCustomParametersView.CustomParameters.swift in Sources */,
D76EE6072AF9AFE100DA0325 /* FindRouteAroundBarriersView.Model.swift in Sources */,
007079212DE0E7E800E06300 /* ListGeodatabaseVersionsView.swift in Sources */,
0086F40128E3770A00974721 /* ShowViewshedFromPointInSceneView.swift in Sources */,
0044289229C90C0B00160767 /* GetElevationAtPointOnSurfaceView.swift in Sources */,
00E1D90B2BC0AF97001AEB6A /* SnapGeometryEditsView.SnapSettingsView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Copyright 2025 Esri
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import ArcGIS
import SwiftUI

struct ListGeodatabaseVersionsView: View {
/// The analysis error shown in the error alert.
@State private var analysisError: Error?
/// The task used to perform geoprocessing jobs.
@State private var geoprocessingTask = GeoprocessingTask(
url: URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions")!
)
/// The geodatabase version information.
@State private var geodatabaseVersionInfos: [GeodatabaseVersionInfo]?

var body: some View {
Form {
if let geodatabaseVersionInfos {
ForEach(geodatabaseVersionInfos, id: \.objectID) { version in
Section("OBJECTID: \(version.objectID)") {
LabeledContent("Name", value: version.name)
.lineLimit(1)
.textSelection(.enabled)
LabeledContent("Access", value: version.access)
LabeledContent("Created", value: version.created.formatted(date: .abbreviated, time: .shortened))
LabeledContent("Last Modified", value: version.lastModified.formatted(date: .abbreviated, time: .shortened))
LabeledContent("Is Owner", value: version.isOwner)
LabeledContent("Parent Version", value: version.parentVersionName)
if !version.description.isEmpty {
LabeledContent("Description", value: version.description)
}
}
}
} else {
ProgressView()
.frame(maxWidth: .infinity)
}
}
.task {
do {
let resultFeatures = try await fetchGeodatabaseVersions()
geodatabaseVersionInfos = makeGeodatabaseVersionInfos(from: resultFeatures)
} catch {
analysisError = error
}
}
.errorAlert(presentingError: $analysisError)
}

/// Fetches geodatabase versions using a geoprocessing job.
private func fetchGeodatabaseVersions() async throws -> FeatureSet {
// Creates and configures the job's parameters.
let parameters = try await geoprocessingTask.makeDefaultParameters()

// Creates and starts the job.
let geoprocessingJob = geoprocessingTask.makeJob(parameters: parameters)
geoprocessingJob.start()

// Waits for the job to finish and retrieves the output.
let result = try await withTaskCancellationHandler {
try await geoprocessingJob.output
} onCancel: {
Task.detached {
await geoprocessingJob.cancel()
}
}
guard let versions = result.outputs["Versions"] as? GeoprocessingFeatures,
let featureSet = versions.features else {
fatalError("Expected geoprocessing results to contain 'Versions' output.")
}
return featureSet
}

/// Converts the features to an array of `GeodatabaseVersionInfo`.
/// - Parameter featureSet: The features with version info from the job.
/// - Returns: An array of `GeodatabaseVersionInfo`.
private func makeGeodatabaseVersionInfos(from featureSet: FeatureSet) -> [GeodatabaseVersionInfo] {
featureSet
.features()
.compactMap { version in
GeodatabaseVersionInfo(from: version.attributes)
}
.sorted {
$0.objectID < $1.objectID
}
}

/// A structure representing geodatabase version information.
private struct GeodatabaseVersionInfo {
let objectID: Int64
let name: String
let access: String
let created: Date
let lastModified: Date
let isOwner: String
let parentVersionName: String
let description: String

init?(from dictionary: [String: Sendable]) {
guard let access = dictionary["access"] as? String,
let created = dictionary["created"] as? Date,
let description = dictionary["description"] as? String,
let isOwner = dictionary["isowner"] as? String,
let lastModified = dictionary["lastmodified"] as? Date,
let name = dictionary["name"] as? String,
let objectID = dictionary["ObjectID"] as? Int64,
let parentVersionName = dictionary["parentversionname"] as? String else {
return nil
}

self.objectID = objectID
self.name = name
self.access = access
self.created = created
self.lastModified = lastModified
self.isOwner = isOwner
self.parentVersionName = parentVersionName
self.description = description
}
}
}
42 changes: 42 additions & 0 deletions Shared/Samples/List geodatabase versions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# List geodatabase versions

Connect to a service and list versions of the geodatabase.

![Image of List geodatabase versions sample](list-geodatabase-versions.png)

## Use case

As part of a multi-user editing scenario, you can check with the server to see how many versions of the geodatabase are outstanding before syncing.

## How to use the sample

When the sample loads, a list of geodatabase versions and their properties will be displayed.

## How it works

1. Create a geoprocessing task referring to a **GPServer** with a **ListVersions** task.
2. Use the task to create default parameters.
3. Use the created parameters to create a job.
4. Run the job to get a geoprocessing result.
5. Get a list of geoprocessing features from the **Versions** output parameter of the results.
6. Format the geodatabase versions for display.

## Relevant API

* GeoprocessingFeatures
* GeoprocessingJob
* GeoprocessingParameters
* GeoprocessingResult
* GeoprocessingTask

## About the data

The sample uses a [sample geoprocessing service](https://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions) hosted on ArcGIS Online.

## Additional information

ArcGIS Server does not include a geoprocessing service for listing geodatabase versions. You must configure one using the steps defined in [Geoprocessing service example: list, create, and delete geodatabase versions](https://desktop.arcgis.com/en/arcmap/latest/analyze/sharing-workflows/gp-service-example-list-create-and-delete-geodatabase-versions.htm) in the *ArcMap* documentation.

## Tags

conflict resolution, data management, database, multi-user, sync, version
33 changes: 33 additions & 0 deletions Shared/Samples/List geodatabase versions/README.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"category": "Edit and Manage Data",
"description": "Connect to a service and list versions of the geodatabase.",
"ignore": false,
"images": [
"list-geodatabase-versions.png"
],
"keywords": [
"conflict resolution",
"data management",
"database",
"multi-user",
"sync",
"version",
"GeoprocessingFeatures",
"GeoprocessingJob",
"GeoprocessingParameters",
"GeoprocessingResult",
"GeoprocessingTask"
],
"redirect_from": [],
"relevant_apis": [
"GeoprocessingFeatures",
"GeoprocessingJob",
"GeoprocessingParameters",
"GeoprocessingResult",
"GeoprocessingTask"
],
"snippets": [
"ListGeodatabaseVersionsView.swift"
],
"title": "List geodatabase versions"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading