All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.EdgeMetric.features.FilesObject Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package io.github.EdgeMetric.features;

import static io.restassured.RestAssured.given;

import java.io.File;

import io.restassured.response.Response;
import io.github.EdgeMetric.mammoth.Constants;
import io.github.EdgeMetric.mammoth.MammothConnector;
import io.github.EdgeMetric.mammoth.Utils;

public class FilesObject {

	private Utils utils = new Utils();
	private MammothConnector mc;

	/**
	 * APIs to handle files in Mammoth. eg. upload a file.
	 * @param mc : MammothConnector object. 
	 */
	public FilesObject(MammothConnector mc) {
		this.mc = mc;
	}
	
	/**
	 * Uploads the data file to Mammoth Account.
	 * @param file : Path to the file
	 * @return A file-id.
	 */
	public String fileUpload(File file) {
		Response r1 = given()
				.header(Constants.xAPIKey, mc.getToken())
				.header(Constants.xAccountID, mc.getAccountID())
				.and()
				.multiPart(file)
				.when()
				.post("/files");

		String file_id = r1.jsonPath().get("id").toString();
		return file_id;

	}

	/**
	 * Gets the data-set id.
	 * @param file_id : The file id.
	 * @return A data-set id.
	 */
	public Object getDatasetID(String file_id) {
		Object status = "processing";
		String ds_id = null;
		while(status=="processing") {
			Response r2 = utils.commonHeader(mc.getToken(), mc.getAccountID())
					.and()
					.when()
					.get("/files/" + file_id);

			status = (Object)r2.jsonPath().get("file.additional_data.final_ds_id");

			ds_id = status.toString();
		}
		return ds_id;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy