use of edu.harvard.iq.dataverse.worldmapauth.WorldMapToken in project dataverse by IQSS.
the class MapLayerMetadataServiceBean method deleteMapLayerFromWorldMap.
/*
* This method calls GeoConnect and requests that a map layer for this
* DataFile is deleted, from WorldMap and GeoConnect itself.
* The use case here is when a user restricts a tabular file for which
* a geospatial map has already been made.
* This process is initiated on the Dataverse side, without any GeoConnect
* UI in the picture. (The way a user normally deletes a layer map is by
* clicking 'Delete' on the GeoConnect map page).
* Otherwise this call follows the scheme used when accessing the
* /shapefile/map-it on GeoConnect - we send along a WorldMap token and a
* callback url for GC to download the file metadata.metadata
* Depending on how it goes we receive a yes or no response from the server.
*/
public void deleteMapLayerFromWorldMap(DataFile dataFile, AuthenticatedUser user) throws IOException {
if (dataFile == null) {
logger.severe("dataFile cannot be null");
return;
}
if (user == null) {
logger.severe("user cannot be null");
return;
}
// Worldmap token:
WorldMapToken token = tokenServiceBean.getNewToken(dataFile, user);
if (token == null) {
logger.severe("token should NOT be null");
return;
}
logger.info("-- new token id: " + token.getId());
// Callback url for geoConnect:
String callback_url = URLEncoder.encode(systemConfig.getDataverseSiteUrl() + WorldMapRelatedData.GET_WORLDMAP_DATAFILE_API_PATH);
String geoConnectAddress = token.getApplication().getMapitLink();
/*
* this is a bit of a hack - there should be a cleaner way to get the base
* geoconnect URL from the token!
*/
geoConnectAddress = geoConnectAddress.replace("/shapefile/map-it", "");
logger.log(Level.INFO, "callback_url: {0}", callback_url);
// String geoConnectCommand = geoConnectAddress + GEOCONNECT_MAP_DELETE_API + token.getApplication().getMapitLink() + "/" + token.getToken() + "/?cb=" + callback_url;
String geoConnectCommand = geoConnectAddress + GEOCONNECT_MAP_DELETE_API + token.getToken() + "/?cb=" + callback_url;
logger.info("-- new token id 2: " + token.getId());
logger.info("Attempting to call GeoConnect to request that the WorldMap layer for DataFile " + dataFile.getId() + ":\n" + geoConnectCommand);
URL geoConnectUrl = new URL(geoConnectCommand);
HttpURLConnection geoConnectConnection = (HttpURLConnection) geoConnectUrl.openConnection();
geoConnectConnection.setRequestMethod("GET");
geoConnectConnection.connect();
int code = geoConnectConnection.getResponseCode();
logger.info("response code: " + code);
if (code != 200) {
throw new IOException("Failed to delete Map Layer via GeoConnect. /tabular/delete-map HTTP code response: " + code + "");
}
logger.info("response :" + geoConnectConnection.getContent());
}
Aggregations