package org.gcube.application.geoportal;

import org.gcube.application.geoportal.utils.Workspace;
import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.ItemContainer;
import org.gcube.common.storagehub.client.dsl.ListResolver;
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.items.Item;

public class WSTests {

	public static void main(String[] args) throws StorageHubException {
		TokenSetter.set("/gcube/devNext/NextNext");
		
		StorageHubClient client=Workspace.getClient();
		String id="9e397c1f-0b52-4b59-b247-e5ef301978ed";
		
		ItemContainer item=client.open(id).asItem();
		System.out.println(item.get().getPath());
//		switch(item.getType()) {
//		case FILE : 
//			FileContainer file=(FileContainer) item;
//			file.getAnchestors();
//		}
		System.out.println(path(item));
		
	}
	
	public static String path(ItemContainer item) throws StorageHubException {
		StringBuilder builder=new StringBuilder();
		ListResolver resolver=item.getAnchestors();
		for(Item i:resolver.getItems()) {
			builder.append(i.getName()+" ID : "+i.getId()+"\n");
		}
		return builder.toString();
	}

}
