Skip to content

Commit 1f5a165

Browse files
committed
Update portal url and item, change to username/password auth
1 parent b83f580 commit 1f5a165

File tree

4 files changed

+71
-165
lines changed

4 files changed

+71
-165
lines changed

src/main/java/com/esri/samples/tiledlayers/export_vector_tiles/AuthenticationDialog.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@
2121
import javafx.scene.control.Alert;
2222
import javafx.scene.control.ButtonType;
2323
import javafx.scene.control.Dialog;
24+
import javafx.scene.control.PasswordField;
2425
import javafx.scene.control.TextField;
2526

27+
import com.esri.arcgisruntime.security.Credential;
2628
import com.esri.arcgisruntime.security.OAuthConfiguration;
29+
import com.esri.arcgisruntime.security.UserCredential;
2730

2831
/**
2932
* Custom dialog for getting an OAuthConfiguration.
3033
*/
31-
class AuthenticationDialog extends Dialog<OAuthConfiguration> {
34+
class AuthenticationDialog extends Dialog<Credential> {
3235

33-
@FXML private TextField portalURL;
34-
@FXML private TextField clientID;
35-
@FXML private TextField redirectURI;
36+
@FXML private TextField username;
37+
@FXML private PasswordField password;
3638
@FXML private ButtonType cancelButton;
3739
@FXML private ButtonType continueButton;
3840

3941
AuthenticationDialog() {
40-
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/oauth_auth_dialog.fxml"));
42+
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/export_vector_tiles_auth_dialog.fxml"));
4143
loader.setRoot(this);
4244
loader.setController(this);
4345

@@ -51,23 +53,15 @@ class AuthenticationDialog extends Dialog<OAuthConfiguration> {
5153

5254
setResultConverter(dialogButton -> {
5355
if (dialogButton == continueButton) {
54-
if (!portalURL.getText().equals("") && !clientID.getText().equals("") && !redirectURI.getText().equals("")) {
55-
try {
56-
return new OAuthConfiguration(portalURL.getText(), clientID.getText(), redirectURI.getText());
57-
} catch (Exception e) {
58-
showMessage(e.getMessage());
59-
}
60-
} else {
61-
showMessage("missing credentials");
56+
try {
57+
return new UserCredential(username.getText(), password.getText());
58+
} catch (Exception e) {
59+
Alert alert = new Alert(Alert.AlertType.ERROR, e.getMessage());
60+
alert.show();
6261
}
6362
}
6463
return null;
6564
});
6665
}
6766

68-
private void showMessage(String message) {
69-
Alert alert = new Alert(Alert.AlertType.ERROR);
70-
alert.setContentText(message);
71-
alert.show();
72-
}
7367
}

src/main/java/com/esri/samples/tiledlayers/export_vector_tiles/ExportVectorTilesSample.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242
import com.esri.arcgisruntime.loadable.LoadStatus;
4343
import com.esri.arcgisruntime.mapping.ArcGISMap;
4444
import com.esri.arcgisruntime.mapping.Basemap;
45+
import com.esri.arcgisruntime.mapping.ItemResourceCache;
4546
import com.esri.arcgisruntime.mapping.view.Graphic;
4647
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
4748
import com.esri.arcgisruntime.mapping.view.MapView;
4849
import com.esri.arcgisruntime.portal.Portal;
4950
import com.esri.arcgisruntime.portal.PortalItem;
5051
import com.esri.arcgisruntime.security.AuthenticationManager;
52+
import com.esri.arcgisruntime.security.Credential;
5153
import com.esri.arcgisruntime.security.OAuthConfiguration;
5254
import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
5355
import com.esri.arcgisruntime.tasks.vectortilecache.ExportVectorTilesJob;
@@ -77,22 +79,18 @@ public void start(Stage stage) throws Exception {
7779
// set the map to the map view
7880
mapView = new MapView();
7981

82+
// authenticate with an organization account on arcgis.com
8083
AuthenticationDialog authenticationDialog = new AuthenticationDialog();
81-
authenticationDialog.show();
8284
authenticationDialog.setOnCloseRequest(r -> {
8385

84-
OAuthConfiguration configuration = authenticationDialog.getResult();
86+
Credential credential = authenticationDialog.getResult();
8587
// check that configuration was made
86-
if (configuration != null) {
87-
AuthenticationManager.addOAuthConfiguration(configuration);
88-
89-
Portal portal = new Portal("http://" + configuration.getPortalUrl(), true);
88+
if (credential != null) {
9089

91-
// setup the handler that will prompt an authentication challenge to the user
92-
OAuthChallengeHandler challengeHandler = new OAuthChallengeHandler(portal);
93-
AuthenticationManager.setAuthenticationChallengeHandler(challengeHandler);
90+
Portal portal = new Portal("http://www.arcgis.com", true);
91+
portal.setCredential(credential);
9492

95-
PortalItem portalItem = new PortalItem(portal, "8e848d9302e84dcba0de7aff8ac429dc");
93+
PortalItem portalItem = new PortalItem(portal, "86f556a2d1fd468181855a35e344567f");
9694

9795
// loading the vector tiled layer will invoke the authentication challenge
9896
ArcGISVectorTiledLayer vectorTiledLayer = new ArcGISVectorTiledLayer(portalItem);
@@ -101,8 +99,12 @@ public void start(Stage stage) throws Exception {
10199
// set the layer as the map's basemap
102100
ArcGISMap map = new ArcGISMap(new Basemap(vectorTiledLayer));
103101
mapView.setMap(map);
102+
} else {
103+
Alert alert = new Alert(Alert.AlertType.ERROR, "Item requires authentication.");
104+
alert.show();
104105
}
105106
});
107+
authenticationDialog.show();
106108

107109
// create a graphics overlay for the map view
108110
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
@@ -143,31 +145,34 @@ public void start(Stage stage) throws Exception {
143145
// when the button is clicked, export the tiles to a temporary file
144146
exportTilesButton.setOnAction(e -> {
145147
try {
146-
File tempFile = File.createTempFile("tiles", ".vtpk");
147-
File styleDir = Files.createTempDirectory("StyleItemResources").toFile();
148+
File vtpkFile = File.createTempFile("tiles", ".vtpk");
149+
File resDir = Files.createTempDirectory("StyleItemResources").toFile();
148150
progressBar.setVisible(true);
149151
Layer layer = mapView.getMap().getBasemap().getBaseLayers().get(0);
150152
double maxScale = layer.getMaxScale();
151153
ExportVectorTilesTask task = new ExportVectorTilesTask((PortalItem) layer.getItem());
152-
ListenableFuture<ExportVectorTilesParameters> createParams = task.createDefaultExportVectorTilesParametersAsync(downloadArea
153-
.getGeometry(), maxScale);
154+
ListenableFuture<ExportVectorTilesParameters> createParams = task
155+
.createDefaultExportVectorTilesParametersAsync(downloadArea.getGeometry(), maxScale);
154156
createParams.addDoneListener(() -> {
155157
try {
156158
ExportVectorTilesParameters params = createParams.get();
157-
ExportVectorTilesJob job = task.exportVectorTiles(params, tempFile.getAbsolutePath(), styleDir.getAbsolutePath());
159+
ExportVectorTilesJob job = task.exportVectorTiles(params, vtpkFile.getAbsolutePath(), resDir
160+
.getAbsolutePath());
158161
job.start();
159162
job.addProgressChangedListener(() -> progressBar.setProgress(job.getProgress() / 100.0));
160163
job.addJobDoneListener(() -> {
161164
if (job.getStatus() == Job.Status.SUCCEEDED) {
162165
// show preview of exported tiles in alert
163166
ExportVectorTilesResult tilesResult = job.getResult();
164167
VectorTileCache tileCache = tilesResult.getVectorTileCache();
168+
ItemResourceCache resourceCache = tilesResult.getItemResourceCache();
165169
Alert preview = new Alert(Alert.AlertType.INFORMATION);
166170
preview.setTitle("Preview");
167-
preview.setHeaderText("Exported to " + tileCache.getPath());
171+
preview.setHeaderText("Exported tiles to " + tileCache.getPath() + "\n Exported resources to " +
172+
resourceCache.getPath());
168173
MapView mapPreview = new MapView();
169174
mapPreview.setMinSize(400, 400);
170-
ArcGISVectorTiledLayer tiledLayerPreview = new ArcGISVectorTiledLayer(tileCache, tilesResult.getItemResourceCache());
175+
ArcGISVectorTiledLayer tiledLayerPreview = new ArcGISVectorTiledLayer(tileCache, resourceCache);
171176
ArcGISMap previewMap = new ArcGISMap(new Basemap(tiledLayerPreview));
172177
mapPreview.setMap(previewMap);
173178
preview.getDialogPane().setContent(mapPreview);

src/main/java/com/esri/samples/tiledlayers/export_vector_tiles/OAuthChallengeHandler.java

Lines changed: 0 additions & 130 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2017 Esri.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
~ use this file except in compliance with the License. You may obtain a copy of
7+
~ the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
~ License for the specific language governing permissions and limitations under
15+
~ the License.
16+
-->
17+
18+
<?import javafx.scene.control.ButtonType?>
19+
<?import javafx.scene.control.Dialog?>
20+
<?import javafx.scene.control.DialogPane?>
21+
<?import javafx.scene.control.PasswordField?>
22+
<?import javafx.scene.control.TextField?>
23+
<?import javafx.scene.layout.VBox?>
24+
<fx:root type="javafx.scene.control.Dialog" xmlns:fx="http://javafx.com/fxml">
25+
<dialogPane>
26+
<DialogPane>
27+
<content>
28+
<VBox spacing="10">
29+
<TextField fx:id="username" promptText="username"/>
30+
<PasswordField fx:id="password" promptText="password"/>
31+
</VBox>
32+
</content>
33+
<ButtonType fx:id="cancelButton" buttonData="CANCEL_CLOSE" text="Cancel"/>
34+
<ButtonType fx:id="continueButton" buttonData="FINISH" text="Continue"/>
35+
</DialogPane>
36+
</dialogPane>
37+
</fx:root>

0 commit comments

Comments
 (0)