<commit_before>

import javax.validation.Valid;

import org.apache.commons.codec.binary.Base64;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;



import com.temboo.Library.Dropbox.FileOperations.CreateFolder;
import com.temboo.Library.Dropbox.FileOperations.CreateFolder.CreateFolderInputSet;
import com.temboo.Library.Dropbox.FileOperations.CreateFolder.CreateFolderResultSet;
import com.temboo.Library.Dropbox.FileOperations.DeleteFileOrFolder;
import com.temboo.Library.Dropbox.FileOperations.DeleteFileOrFolder.DeleteFileOrFolderInputSet;
import com.temboo.Library.Dropbox.FileOperations.DeleteFileOrFolder.DeleteFileOrFolderResultSet;
import com.temboo.Library.Dropbox.FilesAndMetadata.UploadFile;
import com.temboo.Library.Dropbox.FilesAndMetadata.UploadFile.UploadFileInputSet;
import com.temboo.Library.Dropbox.FilesAndMetadata.UploadFile.UploadFileResultSet;
import com.temboo.Library.Dropbox.OAuth.FinalizeOAuth;
import com.temboo.Library.Dropbox.OAuth.InitializeOAuth;
import com.temboo.Library.Dropbox.OAuth.FinalizeOAuth.FinalizeOAuthInputSet;
import com.temboo.Library.Dropbox.OAuth.FinalizeOAuth.FinalizeOAuthResultSet;
import com.temboo.Library.Dropbox.OAuth.InitializeOAuth.InitializeOAuthInputSet;
import com.temboo.Library.Dropbox.OAuth.InitializeOAuth.InitializeOAuthResultSet;
import com.temboo.core.TembooSession;



@RestController
public class EasyNoteController {
	
	ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class);
	MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
	TembooSession session;
	{	
	try
	{
	session = new TembooSession("easynotes", "myFirstApp", "803311a1eb9345d9932f9a3de103bd39");
	}
	catch(Exception e)
	{}
	}
	final String DROPBOX_APPKEY = "<KEY>";
	final String DROPBOX_APPKEYSECRET = "trc655astffa97y";
	String accessToken;
	String accessTokenSecret;
	String callbackId;
	String OAuthTokenSecret;
		
	FinalizeOAuth finalizeOAuthChoreo = new FinalizeOAuth(session);
	// Get an InputSet object for the choreo
	FinalizeOAuthInputSet finalizeOAuthInputs;
	
	//1. InitializeOAuth
	@RequestMapping(value="/api/v1/initializeOAuth",method = RequestMethod.GET)
	@ResponseStatus(HttpStatus.OK)
	@ResponseBody
	public String initializeDropbox() throws Exception
	{
	/*{
	try
	{*/
	
	InitializeOAuth initializeOAuthChoreo = new InitializeOAuth(session);

	// Get an InputSet object for the choreo
	InitializeOAuthInputSet initializeOAuthInputs = initializeOAuthChoreo.newInputSet();

	// Set inputs
	initializeOAuthInputs.set_DropboxAppSecret(DROPBOX_APPKEYSECRET);
	initializeOAuthInputs.set_DropboxAppKey(DROPBOX_APPKEY);
	initializeOAuthInputs.set_ForwardingURL("http://localhost:3000");

	//Execute Choreo
	InitializeOAuthResultSet initializeOAuthResults = initializeOAuthChoreo.execute(initializeOAuthInputs);
	
	//Get Outputs
	String authURL = initializeOAuthResults.get_AuthorizationURL();
	callbackId = initializeOAuthResults.get_CallbackID();
	String OAuthTokenSecret = initializeOAuthResults.get_OAuthTokenSecret();
	System.out.println("callbackId  "+callbackId);
	System.out.println("OAuthTokenSecret  "+OAuthTokenSecret);
	
	
	System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"+authURL+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");	
	
	finalizeOAuthInputs = finalizeOAuthChoreo.newInputSet();

	// Set inputs
	finalizeOAuthInputs.set_CallbackID(callbackId);
	finalizeOAuthInputs.set_DropboxAppSecret(DROPBOX_APPKEYSECRET);
	finalizeOAuthInputs.set_OAuthTokenSecret(OAuthTokenSecret);
	finalizeOAuthInputs.set_DropboxAppKey(DROPBOX_APPKEY);
	finalizeOAuthInputs.set_Timeout("60");
		
	
	return authURL;
	}
	//1. Create Notebook
		@RequestMapping(value="/api/v1/notebooks",method = RequestMethod.POST)
		@ResponseStatus(HttpStatus.CREATED)
		@ResponseBody
		public void createNotebook(@Valid @RequestBody Notebook notebook) throws Exception
		{	
						
			String nbname = notebook.getName();
			
			
			CreateFolder createFolderChoreo = new CreateFolder(session);

			// Get an InputSet object for the choreo
			CreateFolderInputSet createFolderInputs = createFolderChoreo.newInputSet();

			// Set inputs
			createFolderInputs.set_NewFolderName("/EasyNotes/"+nbname);
			createFolderInputs.set_AccessToken(accessToken);
			createFolderInputs.set_AppSecret(DROPBOX_APPKEYSECRET);
			createFolderInputs.set_AccessTokenSecret(accessTokenSecret);
			createFolderInputs.set_AppKey(DROPBOX_APPKEY);

			// Execute Choreo
			CreateFolderResultSet createFolderResults = createFolderChoreo.execute(createFolderInputs);
			System.out.println(createFolderResults.get_Response());
		}
		
		
		//2. Create Notes
				@RequestMapping(value="/api/v1/notes",method = RequestMethod.POST)
				@ResponseStatus(HttpStatus.CREATED)
				@ResponseBody
				public void createNotes(@Valid @RequestBody Note note) throws Exception
				{	
								
					String title = note.getTitle();
					String content = note.getContent();
					String nbid = note.getNotebookid();
					
					Notebook nbname = mongoOperation.findOne(new Query(Criteria.where("id").is(nbid)), Notebook.class);
					
					UploadFile uploadFileChoreo = new UploadFile(session);

					// Get an InputSet object for the choreo
					UploadFileInputSet uploadFileInputs = uploadFileChoreo.newInputSet();
					
					byte[] encodednotecontent = Base64.encodeBase64(content.getBytes());
					
					uploadFileInputs.set_Folder("/EasyNotes/"+nbname.getName());
					uploadFileInputs.set_AccessToken(accessToken);
					uploadFileInputs.set_AppSecret(DROPBOX_APPKEYSECRET);
					uploadFileInputs.set_FileName(title+".txt");
					uploadFileInputs.set_AccessTokenSecret(accessTokenSecret);
					uploadFileInputs.set_AppKey(DROPBOX_APPKEY);
					uploadFileInputs.set_FileContents(new String(encodednotecontent));

					// Execute Choreo
					UploadFileResultSet uploadFileResults = uploadFileChoreo.execute(uploadFileInputs);
				}
				
				//3. Delete notes
				@RequestMapping(value="/api/v1/notes",method = RequestMethod.DELETE)
				@ResponseStatus(HttpStatus.OK)
				@ResponseBody
				public void deleteNotes(@Valid @RequestBody Note note) throws Exception
				{	
								
					String title = note.getTitle();
					String nbid = note.getNotebookid();
					String deletepath;
					
					Notebook nbname = mongoOperation.findOne(new Query(Criteria.where("id").is(nbid)), Notebook.class);
					
					
					System.out.println(nbid);
					System.out.println(nbname.getName());
					System.out.println(title);
					
					if(title != null)
						 deletepath = "/EasyNotes/"+nbname.getName()+"/"+title+".txt";
					else
						deletepath = "/EasyNotes/"+nbname.getName();
					
					System.out.println(deletepath);
					<commit_msg>Changes to note creation REST Api<commit_after>

import javax.validation.Valid;

import org.apache.commons.codec.binary.Base64;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;



import com.temboo.Library.Dropbox.FileOperations.CreateFolder;
import com.temboo.Library.Dropbox.FileOperations.CreateFolder.CreateFolderInputSet;
import com.temboo.Library.Dropbox.FileOperations.CreateFolder.CreateFolderResultSet;
import com.temboo.Library.Dropbox.FileOperations.DeleteFileOrFolder;
import com.temboo.Library.Dropbox.FileOperations.DeleteFileOrFolder.DeleteFileOrFolderInputSet;
import com.temboo.Library.Dropbox.FileOperations.DeleteFileOrFolder.DeleteFileOrFolderResultSet;
import com.temboo.Library.Dropbox.FilesAndMetadata.UploadFile;
import com.temboo.Library.Dropbox.FilesAndMetadata.UploadFile.UploadFileInputSet;
import com.temboo.Library.Dropbox.FilesAndMetadata.UploadFile.UploadFileResultSet;
import com.temboo.Library.Dropbox.OAuth.FinalizeOAuth;
import com.temboo.Library.Dropbox.OAuth.InitializeOAuth;
import com.temboo.Library.Dropbox.OAuth.FinalizeOAuth.FinalizeOAuthInputSet;
import com.temboo.Library.Dropbox.OAuth.FinalizeOAuth.FinalizeOAuthResultSet;
import com.temboo.Library.Dropbox.OAuth.InitializeOAuth.InitializeOAuthInputSet;
import com.temboo.Library.Dropbox.OAuth.InitializeOAuth.InitializeOAuthResultSet;
import com.temboo.core.TembooSession;



@RestController
public class EasyNoteController {
	
	ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class);
	MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
	TembooSession session;
	{	
	try
	{
	session = new TembooSession("easynotes", "myFirstApp", "803311a1eb9345d9932f9a3de103bd39");
	}
	catch(Exception e)
	{}
	}
	final String DROPBOX_APPKEY = "<KEY>";
	final String DROPBOX_APPKEYSECRET = "trc655astffa97y";
	String accessToken;
	String accessTokenSecret;
	String callbackId;
	String OAuthTokenSecret;
		
	FinalizeOAuth finalizeOAuthChoreo = new FinalizeOAuth(session);
	// Get an InputSet object for the choreo
	FinalizeOAuthInputSet finalizeOAuthInputs;
	
	//1. InitializeOAuth
	@RequestMapping(value="/api/v1/initializeOAuth",method = RequestMethod.GET)
	@ResponseStatus(HttpStatus.OK)
	@ResponseBody
	public String initializeDropbox() throws Exception
	{
	/*{
	try
	{*/
	
	InitializeOAuth initializeOAuthChoreo = new InitializeOAuth(session);

	// Get an InputSet object for the choreo
	InitializeOAuthInputSet initializeOAuthInputs = initializeOAuthChoreo.newInputSet();

	// Set inputs
	initializeOAuthInputs.set_DropboxAppSecret(DROPBOX_APPKEYSECRET);
	initializeOAuthInputs.set_DropboxAppKey(DROPBOX_APPKEY);
	initializeOAuthInputs.set_ForwardingURL("http://localhost:3000");

	//Execute Choreo
	InitializeOAuthResultSet initializeOAuthResults = initializeOAuthChoreo.execute(initializeOAuthInputs);
	
	//Get Outputs
	String authURL = initializeOAuthResults.get_AuthorizationURL();
	callbackId = initializeOAuthResults.get_CallbackID();
	String OAuthTokenSecret = initializeOAuthResults.get_OAuthTokenSecret();
	System.out.println("callbackId  "+callbackId);
	System.out.println("OAuthTokenSecret  "+OAuthTokenSecret);
	
	
	System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"+authURL+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");	
	
	finalizeOAuthInputs = finalizeOAuthChoreo.newInputSet();

	// Set inputs
	finalizeOAuthInputs.set_CallbackID(callbackId);
	finalizeOAuthInputs.set_DropboxAppSecret(DROPBOX_APPKEYSECRET);
	finalizeOAuthInputs.set_OAuthTokenSecret(OAuthTokenSecret);
	finalizeOAuthInputs.set_DropboxAppKey(DROPBOX_APPKEY);
	finalizeOAuthInputs.set_Timeout("60");
		
	
	return authURL;
	}
	//1. Create Notebook
		@RequestMapping(value="/api/v1/notebooks",method = RequestMethod.POST)
		@ResponseStatus(HttpStatus.CREATED)
		@ResponseBody
		public void createNotebook(@Valid @RequestBody Notebook notebook) throws Exception
		{	
						
			String nbname = notebook.getName();
			
			
			CreateFolder createFolderChoreo = new CreateFolder(session);

			// Get an InputSet object for the choreo
			CreateFolderInputSet createFolderInputs = createFolderChoreo.newInputSet();

			// Set inputs
			createFolderInputs.set_NewFolderName("/EasyNotes/"+nbname);
			createFolderInputs.set_AccessToken(accessToken);
			createFolderInputs.set_AppSecret(DROPBOX_APPKEYSECRET);
			createFolderInputs.set_AccessTokenSecret(accessTokenSecret);
			createFolderInputs.set_AppKey(DROPBOX_APPKEY);

			// Execute Choreo
			CreateFolderResultSet createFolderResults = createFolderChoreo.execute(createFolderInputs);
			System.out.println(createFolderResults.get_Response());
		}
		
		
		//2. Create Notes
				@RequestMapping(value="/api/v1/notes",method = RequestMethod.POST)
				@ResponseStatus(HttpStatus.CREATED)
				@ResponseBody
				public void createNotes(@Valid @RequestBody Note note) throws Exception
				{	
								
					String title = note.getTitle();
					String content = note.getContent();
					String nbid = note.getNotebookid();
					
					System.out.println(title);
					System.out.println(content);
					System.out.println(nbid);
					
					Notebook nbname = mongoOperation.findOne(new Query(Criteria.where("id").is(nbid)), Notebook.class);
					
					UploadFile uploadFileChoreo = new UploadFile(session);
					System.out.println("1");
					// Get an InputSet object for the choreo
					UploadFileInputSet uploadFileInputs = uploadFileChoreo.newInputSet();
					System.out.println("2");

					if(content == null || "".equalsIgnoreCase(content))
					{
						System.out.println("3");
						uploadFileInputs.set_Folder("/"+nbname.getName());
						uploadFileInputs.set_AccessToken(accessToken);
						uploadFileInputs.set_AppSecret(DROPBOX_APPKEYSECRET);
						uploadFileInputs.set_FileName(title+".txt");
						uploadFileInputs.set_AccessTokenSecret(accessTokenSecret);
						uploadFileInputs.set_AppKey(DROPBOX_APPKEY);
						uploadFileInputs.set_FileContents(" 	");
						System.out.println("4");
					}
					else
					{
						System.out.println("5");
						byte[] encodednotecontent = Base64.encodeBase64(content.getBytes());
						
						uploadFileInputs.set_Folder("/"+nbname.getName());
						uploadFileInputs.set_AccessToken(accessToken);
						uploadFileInputs.set_AppSecret(DROPBOX_APPKEYSECRET);
						uploadFileInputs.set_FileName(title+".txt");
						uploadFileInputs.set_AccessTokenSecret(accessTokenSecret);
						uploadFileInputs.set_AppKey(DROPBOX_APPKEY);
						uploadFileInputs.set_FileContents(new String(encodednotecontent));
						System.out.println("6");

					}
					System.out.println("7");
					// Execute Choreo
					UploadFileResultSet uploadFileResults = uploadFileChoreo.execute(uploadFileInputs);
					System.out.println("8");

				}
				
				//3. Delete notes
				@RequestMapping(value="/api/v1/notes",method = RequestMethod.DELETE)
				@ResponseStatus(HttpStatus.OK)
				@ResponseBody
				public void deleteNotes(@Valid @RequestBody Note note) throws Exception
				{	
								
					String title = note.getTitle();
					String nbid = note.getNotebookid();
					String deletepath;
					
					Notebook nbname = mongoOperation.findOne(new Query(Criteria.where("id").is(nbid)), Notebook.class);
					
					
					System.out.println(nbid);
					System.out.println(nbname.getName());
					System.out.println(title);
					
					if(title != null)
						 deletepath = "/EasyNotes/"+nbname.getName()+"/"+title+".txt";
					else
						deletepath = "/EasyNotes/"+nbname.getName();
					
					System.out.println(deletepath);
					
{'fraction_non_alphanumeric': 0.10536422993214697, 'fraction_numerical': 0.006529253616694405, 'mean_word_length': 5.1146771037182, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2409714', 'n_tokens_mistral': 5613, 'n_tokens_neox': 4905, 'n_words': 661}