/*
 * Copyright 2010 PC-NG Inc. All rights reserved.
 * PC-NG PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nexiwave.search.client.sample;

import com.nexiwave.speechindexing.client.SpeechIndexingStub;
import com.nexiwave.speechindexing.client.SpeechIndexingStub.AddResponse;
import com.nexiwave.speechindexing.client.SpeechIndexingStub.AudioUploadData;
import com.nexiwave.speechindexing.client.SpeechIndexingStub.KeyValue;

public class AddFullExample {
	
	public static void main(String[] s) throws Exception{
		new AddFullExample().addWithCustomIndexedProperties("test@mycompany.com", "mypassword");
	}

	/**
	 * This method demonstrate how to send customIndexedProperties in the add() call.
	 */
	public long addWithCustomIndexedProperties(String email, String passwd) throws Exception {
		// testing add audio:
		SpeechIndexingStub.Add req = new SpeechIndexingStub.Add();

		SpeechIndexingStub.AuthData authData = new SpeechIndexingStub.AuthData();
		authData.setEmail(email);
		authData.setPasswd(passwd);

		req.setAuthData(authData);

		AudioUploadData uploadData = new AudioUploadData();
		uploadData.setMediaURL("http://www.mycompany.com/audio/123.wav");

		{
			KeyValue kv = new KeyValue();
			kv.setKey("myCustomerId"); 
			kv.setValue("12345abc");
			uploadData.addCustomIndexedProperties(kv);
		}
		
		{
			KeyValue kv = new KeyValue();
			kv.setKey("myTestId"); 
			kv.setValue("1234asas5abc");
			uploadData.addCustomIndexedProperties(kv);
		}
		
		req.setData(uploadData);

		SpeechIndexingStub stub = new SpeechIndexingStub(
				"https://api.nexiwave.com/SpeechIndexing/services/SpeechIndexing");

		// make the call:
		AddResponse resAdd = stub.add(req);

		// obtain response:
		long newRecordingId = resAdd.get_return();
		System.out.println("add result " + newRecordingId);

		if (newRecordingId <= 0)
			throw new RuntimeException("Hmm, invalid recording id returned.");

		return newRecordingId;

	}

}
