Commit 44597ca1 authored by Marshall McDonnell's avatar Marshall McDonnell

Add delete method to BATS DataSet

Signed-off-by: default avatarMarshall McDonnell <mcdonnellmt@ornl.gov>

Also, added a getter for fuseki data api
parent 57b264e0
......@@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings
* Jay Jay Billings - Initial API and implementation and/or initial docs
* Marshall McDonnell - Added delete method
*****************************************************************************/
package org.eclipse.ice.bats;
......@@ -20,6 +20,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
......@@ -83,6 +84,7 @@ public class DataSet {
*/
private String name = DEFAULT_NAME;
/**
* This operation sets the name of the data set. The name of the data set is the
* name recognized by the host, not the local machine. It must be set prior to
......@@ -151,6 +153,19 @@ public class DataSet {
return getHost() + ":" + getPort() + "/" + getName();
}
/**
* This operation returns the full URI of the Fuseki Data API location
* for this data set on the remote server
* using the hostname, port, and set name.
*
* @return the Fuseki Data API location
*/
public String getFusekiDatasetsURI() {
String fusekiLocation = host + ":" + port + "/";
String fusekiDataAPILoc = "$/datasets";
return getHost() + ":" + getPort() + "/$/datasets";
}
/**
* This operation creates a dataset with the given name. If no name is provided
* to setName(), the default name with a UUID appended to it will be used such
......@@ -176,9 +191,8 @@ public class DataSet {
// Connect the HTTP client
HttpClient client = HttpClientBuilder.create().build();
String fusekiLocation = host + ":" + port + "/";
String fusekiDataAPILoc = "$/datasets";
HttpPost post = new HttpPost((fusekiLocation + fusekiDataAPILoc));
String fusekiDataLocation = getFusekiDatasetsURI();
HttpPost post = new HttpPost(fusekiDataLocation);
// Add the database parameters into the form with UTF_8 encoding.
List<NameValuePair> form = new ArrayList<NameValuePair>();
......@@ -194,6 +208,24 @@ public class DataSet {
return;
}
/**
* This operation deletes the data set with the given name.
*
* @throws Exception
*/
public void delete() throws Exception {
// Connect the HTTP client
HttpClient client = HttpClientBuilder.create().build();
String fusekiDataLocation = getFusekiDatasetsURI();
HttpDelete delete = new HttpDelete(fusekiDataLocation + "/" + name);
// Delete the data set
HttpResponse response = client.execute(delete);
logger.debug(response.toString());
return;
}
/**
* This operation directs the data set to update and persist any remotely stored
* versions of this model with this version of the model. This action is a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment