package org.gcube.portlets.user.homelibrary.jcr.manager;

import java.io.IOException;
import java.util.List;

import javax.jcr.PathNotFoundException;
import org.gcube.common.homelibrary.model.exceptions.RepositoryException;
import org.gcube.common.homelibrary.home.Home;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.HomeManager;
import org.gcube.common.homelibrary.home.HomeManagerFactory;
import org.gcube.common.homelibrary.home.User;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
import org.gcube.common.homelibrary.jcr.workspace.JCRWorkspace;
import org.gcube.common.scope.api.ScopeProvider;

public class FindItem {
	static JCRWorkspace ws = null;

	public static void main(String[] args) throws InternalErrorException, HomeNotFoundException, UserNotFoundException, InsufficientPrivilegesException, WorkspaceFolderNotFoundException, ItemAlreadyExistException, WrongDestinationException, ItemNotFoundException, IOException, PathNotFoundException, RepositoryException, InterruptedException {
//		ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
		ScopeProvider.instance.set("/gcube");

		
		HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
		HomeManager manager = factory.getHomeManager();
		User user = manager.createUser("valentina.marioli");
		Home home = manager.getHome(user);
		Workspace ws = home.getWorkspace();
		WorkspaceFolder root = ws.getRoot();
		System.out.println(root.getPath());
		
		
//		List<WorkspaceItem> children = root.getChildren();
//		for (WorkspaceItem child: children){
//			System.out.println(child.getPath());
//		}
//	

// 

//		WorkspaceItem item = ws.getItemByPath("/Workspace/Sample Reports and Templates/FishFinder Species Fact Sheet.d4sT");
//		System.out.println(item.getRemotePath());
//		System.out.println(item.getPublicLink(true));

//		System.out.println("found? " + item.find("test@***°çààà.jpg").getId());
		
//		WorkspaceItem folder = ws.getItemByAbsPath("/Home/valentina.marioli/Workspace/00000/ddd/");
//		WorkspaceItem copied = ws.copy(item.getId(), folder.getId());
//		WorkspaceItem copied = ws.moveItem(item.getId(), folder.getId());
//		System.out.println(copied.getPath());
		
		
		
//		Thread.sleep(100000);
	}


}
