114 lines
3.8 KiB
Java
114 lines
3.8 KiB
Java
package org.gcube.portlets.admin.resourcemanagement.server;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
import org.gcube.informationsystem.model.entity.Resource;
|
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
|
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
|
import org.gcube.portlets.admin.resourcemanagement.shared.resource.CacheList;
|
|
import org.gcube.portlets.admin.resourcemanagement.shared.resource.UtilityResource;
|
|
import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
|
|
import org.gcube.resourcemanagement.support.shared.types.datamodel.CompleteResourceProfile;
|
|
/**
|
|
*
|
|
* @author pieve mail:alessandro.pieve@isti.cnr.it
|
|
*
|
|
*/
|
|
public class RegistryClientRequester {
|
|
private static ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
/**
|
|
* For all the resource in the scope retrieves their
|
|
* (type, subtype) values.
|
|
* The result is a list of couples of that form.
|
|
* @return a list of string tuples (type, subtype)
|
|
* @throws Exception
|
|
*/
|
|
|
|
//list a resource with a sub category
|
|
public static final HashMap<String, ArrayList<String>> getResourcesTree(String scope) throws Exception {
|
|
|
|
|
|
|
|
|
|
HashMap<String, ArrayList<String>> retval = new HashMap<String, ArrayList<String>>();
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
try {
|
|
List<TypeDefinition> typeDefinitions = resourceRegistryClient.getSchema(Resource.class, true);
|
|
for (TypeDefinition td : typeDefinitions) {
|
|
|
|
if (td.getName().equals("EService"))
|
|
retval.put("RunningInstance", UtilityResource.getSubResourcesTreeQuery(td.getName(),scope));
|
|
if (td.getName().equals("Configuration"))
|
|
retval.put("GenericResource", UtilityResource.getSubResourcesTreeQuery(td.getName(),scope));
|
|
if (td.getName().equals("HostingNode"))
|
|
retval.put("GHN", UtilityResource.getSubResourcesTreeQuery(td.getName(),scope));
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
|
|
|
|
|
|
//list string (xml formatted) for table
|
|
public static final List<String> getResourcesByTypeSubType( String scope,String type,String subType) throws Exception {
|
|
|
|
|
|
//CacheList.resourceid.clear();
|
|
ScopeProvider.instance.set(scope);
|
|
List<String>resource=new ArrayList<String>();
|
|
|
|
switch (type) {
|
|
case "RunningInstance":
|
|
System.out.println("---------------->RunningInstance ");
|
|
resource=UtilityResource.CreateListEservice(scope,type,subType);
|
|
break;
|
|
case "GenericResource":
|
|
System.out.println("---------------->GenericResource ");
|
|
//resource=UtilityResource.CreateListConfiguration(scope,type,subType);
|
|
resource=UtilityResource.CreateListConfigurationQuery(scope,type,subType);
|
|
break;
|
|
case "GHN":
|
|
System.out.println("---------------->GHN ");
|
|
resource=UtilityResource.CreateListHostingNode(scope,type,subType);
|
|
break;
|
|
|
|
}
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static CompleteResourceProfile getResourceByID(
|
|
String xml2htmlMapping, String scope, String type,
|
|
String resID) {
|
|
|
|
String representation=CacheList.resourceid.get(resID).getBody();
|
|
//get resource by id
|
|
String title=CacheList.resourceid.get(resID).getTitle();
|
|
String xmlRepresentation="<Resource>"
|
|
+ "<ID>"+resID+"</ID>"
|
|
+ "<Type>"+type+"</Type>"
|
|
+ "<Scope>"+scope+"</Scope>"
|
|
+ representation
|
|
+ "</Resource>";
|
|
String htmlRepresentation=representation;
|
|
ScopeProvider.instance.set(scope);
|
|
return new CompleteResourceProfile(resID, ResourceTypeDecorator.valueOf(type),title,xmlRepresentation, htmlRepresentation);
|
|
}
|
|
|
|
|
|
}
|