//package org.apache.jackrabbit.j2ee.oak;
//import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
//import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
//
//import org.apache.jackrabbit.oak.api.AuthInfo;
//import org.apache.jackrabbit.oak.api.ContentSession;
//import org.apache.jackrabbit.oak.api.QueryEngine;
//import org.apache.jackrabbit.oak.api.Root;
//import org.apache.jackrabbit.oak.api.Tree;
//import java.io.ByteArrayInputStream;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.net.MalformedURLException;
//import java.net.UnknownHostException;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//import java.util.Set;
//
//import javax.jcr.AccessDeniedException;
//import javax.jcr.Binary;
//import javax.jcr.InvalidItemStateException;
//import javax.jcr.ItemExistsException;
//import javax.jcr.LoginException;
//import javax.jcr.Node;
//import javax.jcr.NodeIterator;
//import javax.jcr.Property;
//import javax.jcr.PropertyIterator;
//import javax.jcr.ReferentialIntegrityException;
//import javax.jcr.Repository;
//import javax.jcr.RepositoryException;
//import javax.jcr.Session;
//import javax.jcr.SimpleCredentials;
//import javax.jcr.UnsupportedRepositoryOperationException;
//import javax.jcr.lock.LockException;
//import javax.jcr.nodetype.ConstraintViolationException;
//import javax.jcr.nodetype.NoSuchNodeTypeException;
//import javax.jcr.nodetype.NodeType;
//import javax.jcr.security.AccessControlException;
//import javax.jcr.security.Privilege;
//import javax.jcr.version.VersionException;
//
//import org.apache.jackrabbit.api.JackrabbitSession;
//import org.apache.jackrabbit.api.JackrabbitWorkspace;
//import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
//import org.apache.jackrabbit.api.security.principal.PrincipalManager;
//import org.apache.jackrabbit.api.security.user.Authorizable;
//import org.apache.jackrabbit.api.security.user.UserManager;
//import org.apache.jackrabbit.core.SessionImpl;
//import org.apache.jackrabbit.j2ee.workspacemanager.ItemDelegateWrapper;
//import org.apache.jackrabbit.j2ee.workspacemanager.accounting.AccoutingNodeWrapper;
//import org.apache.jackrabbit.j2ee.workspacemanager.storage.GCUBEStorage;
//import org.apache.jackrabbit.j2ee.workspacemanager.util.MetaInfo;
//import org.apache.jackrabbit.j2ee.workspacemanager.util.Util;
//import org.apache.jackrabbit.oak.jcr.Jcr;
//import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
//import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
//import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration;
//import org.apache.jackrabbit.rmi.repository.URLRemoteRepository;
//import org.gcube.common.encryption.StringEncrypter;
//import org.gcube.common.homelibary.model.items.ItemDelegate;
//import org.gcube.common.homelibary.model.items.accounting.AccountingDelegate;
//import org.gcube.common.homelibary.model.items.type.ContentType;
//import org.gcube.common.homelibary.model.items.type.FolderItemType;
//import org.gcube.common.homelibary.model.items.type.NodeProperty;
//import org.gcube.common.homelibary.model.items.type.PrimaryNodeType;
//import org.gcube.common.homelibary.model.util.WorkspaceItemAction;
//import org.gcube.common.resources.gcore.ServiceEndpoint;
//import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
//import org.gcube.common.scope.api.ScopeProvider;
//import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
//import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
//import org.gcube.resources.discovery.client.api.DiscoveryClient;
//import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
//
//import com.mongodb.DB;
//import com.mongodb.MongoClient;
//import com.thoughtworks.xstream.XStream;
//
//
//public class GetChildrenOldSession {
//	private static final String nameResource 				= "HomeLibraryRepository";
//	/**
//	 * @param args
//	 * @throws MalformedURLException 
//	 */
//	public static void main(String[] args) throws MalformedURLException {
//
//		String rootScope = "/gcube";
//
//
//		ScopeProvider.instance.set(rootScope);
//
//		SimpleQuery query = queryFor(ServiceEndpoint.class);
//
//		query.addCondition("$resource/Profile/Category/text() eq 'Database' and $resource/Profile/Name eq '"+ nameResource + "' ");
//
//		DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
//
//		List<ServiceEndpoint> resources = client.submit(query);
//
//		try {
//			ServiceEndpoint resource = resources.get(0);
//
//			for (AccessPoint ap:resource.profile().accessPoints()) {
//
//				if (ap.name().equals("JCR")) {
//
//					//					String url = ap.address();
//
//					String url = "http://ws-repo-test.d4science.org/home-library-webapp";
//					//							url = "http://node11.d.d4science.research-infrastructures.eu:8080/jackrabbit-webapp-patched-2.4.3";
//					String user = ap.username();						
//					String pass = StringEncrypter.getEncrypter().decrypt(ap.password());
//
//					//		String url = "http://node11.d.d4science.research-infrastructures.eu:8080/jackrabbit-webapp-2.8.0/";
//					URLRemoteRepository repository = new URLRemoteRepository(url + "/rmi");
//					Session session = repository.login( 
//							new SimpleCredentials(user, pass.toCharArray()));
//
//
//
//					Node root = session.getRootNode().getNode("Share");
////					getChildren(root);
//
//
//					NodeIterator children = root.getNodes();
//					while(children.hasNext()){
//						Node child = children.nextNode();
//						getChildren(child, 0);
//					}
//					
//
//					System.out.println("Done!");
//
//				}
//			}
//		}catch (Exception e) {
//			e.printStackTrace();
//		}
//
//
//
//
//
//	}
//
//
//
//
//
//	private static void getChildren(Node node, int i) throws RepositoryException {
//		//		if (!node.getName().contains(":")){
//		
//		System.out.println(node.getPath());
//		
//		if (node.getName().equals("hl:alreadyV") || (node.getName().equals("hl:visited") || (node.getName().equals("hl:alreadyVisited")))){
//			System.out.println("** found " + node.getPath());
//			node.remove();
//			node.getSession().save();
//		}
//		else if (i<1){
//		
//			NodeIterator children = node.getNodes();
//			while(children.hasNext()){
//				Node child = children.nextNode();
//				getChildren(child, i++);
//			}
//		}
//		//		}
//
//	}
//
//
//}
