/*
 * 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 java.io.File;

import javax.activation.DataHandler;

import com.nexiwave.search.client.SearchService2Stub;

public class UploadWithContextualDocumentTest extends AbstractSampleClient{
	
	public UploadWithContextualDocumentTest(String serverLoc, String userId, String passwd)
			throws Exception {
		super(serverLoc, 0, userId, passwd);
	}

	/**
	 * This method will upload a local audio to nexiwave. It also attach a "Contextual Document" to the request.
	 * 
	 * Contextual Data is a nice way to enhance the accruacy of speech indexing result. 
	 * 
	 * For more information on Contexutal data, visit: http://nexiwave.com/index.php/documentation/tips
	 * 
	 * @param audio
	 * @param contextDoc
	 * @return
	 * @throws Exception
	 */
	public long testUploadWithContextualDoc(File audio, File contextDoc)throws Exception{
		
		// prepare suecirity data: authData:
		SearchService2Stub.AuthData authData=new SearchService2Stub.AuthData();
		authData.setEmail(data.getUserId());
		authData.setPasswd(data.getPasswd());
		authData.setGroupId(data.getChildAccountGroupId());

		// prepare the audio loc and attach contexutal document: 
		SearchService2Stub.AudioUploadData data=new SearchService2Stub.AudioUploadData();
		
		// audio:
		data.setMediaFileData(new DataHandler(audio.toURI().toURL()));
		
		// contextual data:
		data.setContextualDocumentFileData(new DataHandler(contextDoc.toURI().toURL()));
		
		// make the request:
		SearchService2Stub.Add req = new SearchService2Stub.Add();
		req.setAuthData(authData);
		req.setData(data);
		
		// send and get response:
		SearchService2Stub.AddResponse res = getStub().add(req);
		
		// exam the result:
		System.out.println("query result " + res.get_return());
		return res.get_return();
	}

}
