// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Files implements FilesColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_FILES).build();
// 
// 	public static final String[] DEFAULT_COLUMNS = { ID, NAME, FILENAME,
// 			COMMENT, NODE_ID };
// 	public static final String DEFAULT_SORT = NAME + " ASC";
// 
// 	public static String getId(Uri uri) {
// 		return uri.getLastPathSegment();
// 	}
// 
// 	public static String getFilename(Uri uri) {
// 		return uri.getPathSegments().get(1);
// 	}
// 
// 	public static Uri buildFilenameUri(String filename) {
// 		return CONTENT_URI.buildUpon().appendPath(filename)
// 				.appendPath("filename").build();
// 	}
// 
// 	public static Uri buildIdUri(Long fileId) {
// 		return CONTENT_URI.buildUpon().appendPath(fileId.toString()).build();
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class OrgData implements OrgDataColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_ORGDATA).build();
// 
// 	public static final Uri CONTENT_URI_TODOS =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TODOS).build();
// 	public static final String DEFAULT_SORT = ID + " ASC";
// 	public static final String NAME_SORT = NAME + " ASC";
// 	public static final String POSITION_SORT = POSITION + " ASC";
// 	public static final String[] DEFAULT_COLUMNS = {ID, NAME, TODO, TAGS, TAGS_INHERITED,
// 			PARENT_ID, PAYLOAD, LEVEL, PRIORITY, FILE_ID, POSITION, SCHEDULED, SCHEDULED_DATE_ONLY, DEADLINE, DEADLINE_DATE_ONLY};
// 
// 	public static String getId(Uri uri) {
// 		return uri.getPathSegments().get(1);
// 	}
// 
// 	public static Uri buildIdUri(String id) {
// 		return CONTENT_URI.buildUpon().appendPath(id).build();
// 	}
// 
// 	public static Uri buildIdUri(Long id) {
// 		return buildIdUri(id.toString());
// 	}
// 
// 	public static Uri buildChildrenUri(String parentId) {
// 		return CONTENT_URI.buildUpon().appendPath(parentId).appendPath("children").build();
// 	}
// 
// 	public static Uri buildChildrenUri(long node_id) {
// 		return buildChildrenUri(Long.toString(node_id));
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Priorities implements PrioritiesColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_PRIORITIES).build();
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Tags implements TagsColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TAGS).build();
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Timestamps implements TimestampsColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TIMESTAMPS).build();
// 	public static final String[] DEFAULT_COLUMNS = {NODE_ID, FILE_ID, TYPE, TIMESTAMP, ALL_DAY};
// 
// 	public static Uri buildIdUri(Long id) {
// 		return CONTENT_URI.buildUpon().appendPath(id.toString()).build();
// 	}
// 
// 	public static String getId(Uri uri) {
// 		return uri.getLastPathSegment();
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Todos implements TodosColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TODOS).build();
// 
// 	public static final String[] DEFAULT_COLUMNS = {NAME, ID, GROUP, ISDONE};
// }


import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import com.matburt.mobileorg.orgdata.OrgContract.Files;
import com.matburt.mobileorg.orgdata.OrgContract.OrgData;
import com.matburt.mobileorg.orgdata.OrgContract.Priorities;
import com.matburt.mobileorg.orgdata.OrgContract.Tags;
import com.matburt.mobileorg.orgdata.OrgContract.Timestamps;
import com.matburt.mobileorg.orgdata.OrgContract.Todos;
import com.matburt.mobileorg.util.OrgFileNotFoundException;
import com.matburt.mobileorg.util.OrgNodeNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

	public static ArrayList<OrgNode> getOrgNodePathFromTopLevel(long node_id, ContentResolver resolver) {
		ArrayList<OrgNode> nodes = new ArrayList<OrgNode>();
		
		long currentId = node_id;
		while(currentId >= 0) {
			try {
				OrgNode node = new OrgNode(currentId, resolver);
				nodes.add(node);
				currentId = node.parentId;
			} catch (OrgNodeNotFoundException e) {
				throw new IllegalStateException("Couldn't build entire path to root from a given node");
			}
		}
		
		Collections.reverse(nodes);
		return nodes;
	}


	public static void clearDB(ContentResolver resolver) {
		resolver.delete(OrgData.CONTENT_URI, null, null);
		resolver.delete(Files.CONTENT_URI, null, null);
		resolver.delete(Timestamps.CONTENT_URI, null, null);
	}
	
	public static boolean isTodoActive(String todo, ContentResolver resolver) {
		if(TextUtils.isEmpty(todo))
			return true;

// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Files implements FilesColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_FILES).build();
// 
// 	public static final String[] DEFAULT_COLUMNS = { ID, NAME, FILENAME,
// 			COMMENT, NODE_ID };
// 	public static final String DEFAULT_SORT = NAME + " ASC";
// 
// 	public static String getId(Uri uri) {
// 		return uri.getLastPathSegment();
// 	}
// 
// 	public static String getFilename(Uri uri) {
// 		return uri.getPathSegments().get(1);
// 	}
// 
// 	public static Uri buildFilenameUri(String filename) {
// 		return CONTENT_URI.buildUpon().appendPath(filename)
// 				.appendPath("filename").build();
// 	}
// 
// 	public static Uri buildIdUri(Long fileId) {
// 		return CONTENT_URI.buildUpon().appendPath(fileId.toString()).build();
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class OrgData implements OrgDataColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_ORGDATA).build();
// 
// 	public static final Uri CONTENT_URI_TODOS =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TODOS).build();
// 	public static final String DEFAULT_SORT = ID + " ASC";
// 	public static final String NAME_SORT = NAME + " ASC";
// 	public static final String POSITION_SORT = POSITION + " ASC";
// 	public static final String[] DEFAULT_COLUMNS = {ID, NAME, TODO, TAGS, TAGS_INHERITED,
// 			PARENT_ID, PAYLOAD, LEVEL, PRIORITY, FILE_ID, POSITION, SCHEDULED, SCHEDULED_DATE_ONLY, DEADLINE, DEADLINE_DATE_ONLY};
// 
// 	public static String getId(Uri uri) {
// 		return uri.getPathSegments().get(1);
// 	}
// 
// 	public static Uri buildIdUri(String id) {
// 		return CONTENT_URI.buildUpon().appendPath(id).build();
// 	}
// 
// 	public static Uri buildIdUri(Long id) {
// 		return buildIdUri(id.toString());
// 	}
// 
// 	public static Uri buildChildrenUri(String parentId) {
// 		return CONTENT_URI.buildUpon().appendPath(parentId).appendPath("children").build();
// 	}
// 
// 	public static Uri buildChildrenUri(long node_id) {
// 		return buildChildrenUri(Long.toString(node_id));
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Priorities implements PrioritiesColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_PRIORITIES).build();
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Tags implements TagsColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TAGS).build();
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Timestamps implements TimestampsColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TIMESTAMPS).build();
// 	public static final String[] DEFAULT_COLUMNS = {NODE_ID, FILE_ID, TYPE, TIMESTAMP, ALL_DAY};
// 
// 	public static Uri buildIdUri(Long id) {
// 		return CONTENT_URI.buildUpon().appendPath(id.toString()).build();
// 	}
// 
// 	public static String getId(Uri uri) {
// 		return uri.getLastPathSegment();
// 	}
// }
// 
// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgContract.java
// public static class Todos implements TodosColumns {
// 	public static final Uri CONTENT_URI =
// 			BASE_CONTENT_URI.buildUpon().appendPath(PATH_TODOS).build();
// 
// 	public static final String[] DEFAULT_COLUMNS = {NAME, ID, GROUP, ISDONE};
// }


// Path: MobileOrg/src/main/java/com/matburt/mobileorg/orgdata/OrgProviderUtils.java
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import com.matburt.mobileorg.orgdata.OrgContract.Files;
import com.matburt.mobileorg.orgdata.OrgContract.OrgData;
import com.matburt.mobileorg.orgdata.OrgContract.Priorities;
import com.matburt.mobileorg.orgdata.OrgContract.Tags;
import com.matburt.mobileorg.orgdata.OrgContract.Timestamps;
import com.matburt.mobileorg.orgdata.OrgContract.Todos;
import com.matburt.mobileorg.util.OrgFileNotFoundException;
import com.matburt.mobileorg.util.OrgNodeNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;


	public static ArrayList<OrgNode> getOrgNodePathFromTopLevel(long node_id, ContentResolver resolver) {
		ArrayList<OrgNode> nodes = new ArrayList<OrgNode>();
		
		long currentId = node_id;
		while(currentId >= 0) {
			try {
				OrgNode node = new OrgNode(currentId, resolver);
				nodes.add(node);
				currentId = node.parentId;
			} catch (OrgNodeNotFoundException e) {
				throw new IllegalStateException("Couldn't build entire path to root from a given node");
			}
		}
		
		Collections.reverse(nodes);
		return nodes;
	}


	public static void clearDB(ContentResolver resolver) {
		resolver.delete(OrgData.CONTENT_URI, null, null);
		resolver.delete(Files.CONTENT_URI, null, null);
		resolver.delete(Timestamps.CONTENT_URI, null, null);
	}
	
	public static boolean isTodoActive(String todo, ContentResolver resolver) {
		if(TextUtils.isEmpty(todo))
			return true;

		Cursor cursor = resolver.query(Todos.CONTENT_URI, Todos.DEFAULT_COLUMNS, Todos.NAME + " = ?",