Updated resources types support
This commit is contained in:
parent
9dd9943c12
commit
4e27d2fc0b
|
@ -3,10 +3,15 @@ package org.gcube.portlets.admin.resourcemanagement.server;
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
||||
import org.gcube.common.keycloak.KeycloakClient;
|
||||
|
@ -33,7 +38,7 @@ import org.slf4j.LoggerFactory;
|
|||
public class RegistryClientRequester {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RegistryClientRequester.class);
|
||||
|
||||
|
||||
private static ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
private static KeycloakClient client = KeycloakClientFactory.newInstance();
|
||||
|
@ -57,7 +62,7 @@ public class RegistryClientRequester {
|
|||
|
||||
} catch (Exception e) {
|
||||
return Collections.emptySet();
|
||||
}finally {
|
||||
} finally {
|
||||
AccessTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
@ -70,54 +75,96 @@ public class RegistryClientRequester {
|
|||
return response.getAccessToken();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("error getting access token for context "+context, e);
|
||||
throw new RuntimeException("error getting access token for context " + context, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* For all the resource in the scope retrieves their
|
||||
* (type, subtype) values.
|
||||
* 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
|
||||
// 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);
|
||||
AccessTokenProvider.instance.set(getTokenForContext(scope));
|
||||
try {
|
||||
logger.info("GetResourcesTree: [Scope: {}]",scope);
|
||||
|
||||
logger.info("GetResourcesTree: [Scope: {}]", scope);
|
||||
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
List<Type> types = resourceRegistryClient.getType(Resource.class, true);
|
||||
|
||||
logger.info("Resources Types: {}",types.size());
|
||||
logger.info("Resources Types: {}", types.size());
|
||||
|
||||
for (Type t : types) {
|
||||
logger.info("Resource Type: {} in {} ",t.getName(),scope);
|
||||
|
||||
|
||||
logger.info("Resource Type: {} in {} ", t.getName(), scope);
|
||||
if (t.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
String val = null;
|
||||
if (t.getName().equals("EService"))
|
||||
val= "RunningInstance";
|
||||
if (t.getName().equals("Configuration"))
|
||||
switch (t.getName()) {
|
||||
case "Actor":
|
||||
val = "Actor";
|
||||
break;
|
||||
case "LegalBody":
|
||||
val = "LegalBody";
|
||||
break;
|
||||
case "Person":
|
||||
val = "Person";
|
||||
break;
|
||||
case "ConfigurationTemplate":
|
||||
val = "ConfigurationTemplate";
|
||||
break;
|
||||
case "Configuration":
|
||||
val = "GenericResource";
|
||||
if (t.getName().equals("HostingNode"))
|
||||
break;
|
||||
case "Dataset":
|
||||
val = "Dataset";
|
||||
break;
|
||||
case "ConcreteDataset":
|
||||
val = "ConcreteDataset";
|
||||
break;
|
||||
case "Schema":
|
||||
val = "Schema";
|
||||
break;
|
||||
case "EService":
|
||||
val = "RunningInstance";
|
||||
break;
|
||||
case "RunningPlugin":
|
||||
val = "RunningPlugin";
|
||||
break;
|
||||
case "HostingNode":
|
||||
val = "GHN";
|
||||
if (t.getName().equals("VirtualService"))
|
||||
break;
|
||||
case "VirtualService":
|
||||
val = "VirtualService";
|
||||
break;
|
||||
case "Site":
|
||||
val = "Site";
|
||||
break;
|
||||
case "Software":
|
||||
val = "Software";
|
||||
break;
|
||||
case "Plugin":
|
||||
val = "Plugin";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
if (val!=null) {
|
||||
}
|
||||
|
||||
if (val != null) {
|
||||
ArrayList<String> subtrees = new ArrayList<String>();
|
||||
try {
|
||||
subtrees = UtilityResource.getSubResourcesTreeQuery(resourceRegistryClient, t.getName());
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
retval.put(val, subtrees);
|
||||
}
|
||||
|
@ -126,77 +173,131 @@ public class RegistryClientRequester {
|
|||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
} finally {
|
||||
AccessTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
return retval;
|
||||
// Create a list from elements of HashMap
|
||||
LinkedList<String> list = new LinkedList<String>(retval.keySet());
|
||||
|
||||
// Sort the list using lambda expression
|
||||
Collections.sort(list, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
|
||||
logger.info("Sorted Key: {}", list);
|
||||
// put data from sorted list to hashmap
|
||||
HashMap<String, ArrayList<String>> sortedretval = new LinkedHashMap<String, ArrayList<String>>();
|
||||
for (String k : list) {
|
||||
sortedretval.put(k, retval.get(k));
|
||||
}
|
||||
|
||||
|
||||
return sortedretval;
|
||||
}
|
||||
|
||||
// list string (xml formatted) for table
|
||||
public static final List<String> getResourcesByTypeSubType(String scope, String type, String subType)
|
||||
throws Exception {
|
||||
|
||||
//list string (xml formatted) for table
|
||||
public static final List<String> getResourcesByTypeSubType( String scope,String type,String subType) throws Exception {
|
||||
|
||||
|
||||
//CacheList.resourceid.clear();
|
||||
// CacheList.resourceid.clear();
|
||||
ScopeProvider.instance.set(scope);
|
||||
AccessTokenProvider.instance.set(getTokenForContext(scope));
|
||||
try {
|
||||
logger.info("GetResourcesByTypeSubType: [Scope:{}, Type:{}]",scope, type);
|
||||
|
||||
logger.info("GetResourcesByTypeSubType: [Scope:{}, Type:{}]", scope, type);
|
||||
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
List<String>resource=new ArrayList<String>();
|
||||
List<String> resources = new ArrayList<String>();
|
||||
|
||||
switch (type) {
|
||||
case "RunningInstance":
|
||||
logger.info("---------------->RunningInstance ");
|
||||
resource=UtilityResource.createListEservice(resourceRegistryClient, type,subType);
|
||||
case "Actor":
|
||||
logger.info("---------------->Actor");
|
||||
resources = UtilityResource.createListActor(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "GenericResource":
|
||||
logger.info("---------------->GenericResource ");
|
||||
//resource=UtilityResource.CreateListConfiguration(scope,type,subType);
|
||||
resource=UtilityResource.createListConfigurationQuery(resourceRegistryClient, type,subType);
|
||||
case "LegalBody":
|
||||
logger.info("---------------->LegalBody");
|
||||
resources = UtilityResource.createListLegalBody(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "GHN":
|
||||
logger.info("---------------->GHN ");
|
||||
resource=UtilityResource.createListHostingNode(resourceRegistryClient, type,subType);
|
||||
case "Person":
|
||||
logger.info("---------------->Person");
|
||||
resources = UtilityResource.createListPerson(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "VirtualService":
|
||||
logger.info("---------------->VirtualService ");
|
||||
resource=UtilityResource.createListVirtualService(resourceRegistryClient, type,subType);
|
||||
case "ConfigurationTemplate":
|
||||
logger.info("---------------->ConfigurationTemplate");
|
||||
resources = UtilityResource.createListConfigurationTemplate(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "GenericResource":
|
||||
logger.info("---------------->Configuration");
|
||||
resources = UtilityResource.createListConfiguration(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "Dataset":
|
||||
logger.info("---------------->Dataset");
|
||||
resources = UtilityResource.createListDataset(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "ConcreteDataset":
|
||||
logger.info("---------------->ConcreteDataset");
|
||||
resources = UtilityResource.createListConcreteDataset(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "Schema":
|
||||
logger.info("---------------->Schema");
|
||||
resources = UtilityResource.createListSchema(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "RunningInstance":
|
||||
logger.info("---------------->EService");
|
||||
resources = UtilityResource.createListEservice(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "RunningPlugin":
|
||||
logger.info("---------------->RunningPlugin");
|
||||
resources = UtilityResource.createListRunningPlugin(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "GHN":
|
||||
logger.info("---------------->HostingNode");
|
||||
resources = UtilityResource.createListHostingNode(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "VirtualService":
|
||||
logger.info("---------------->VirtualService");
|
||||
resources = UtilityResource.createListVirtualService(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "Site":
|
||||
logger.info("---------------->Site");
|
||||
resources = UtilityResource.createListSite(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "Software":
|
||||
logger.info("---------------->Software");
|
||||
resources = UtilityResource.createListSoftware(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
case "Plugin":
|
||||
logger.info("---------------->Plugin");
|
||||
resources = UtilityResource.createListPlugin(resourceRegistryClient, type, subType);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return resource;
|
||||
}finally {
|
||||
|
||||
return resources;
|
||||
} finally {
|
||||
AccessTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static CompleteResourceProfile getResourceByID(
|
||||
String xml2htmlMapping, String scope, String type,
|
||||
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;
|
||||
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);
|
||||
return new CompleteResourceProfile(resID, ResourceTypeDecorator.valueOf(type), title, xmlRepresentation,
|
||||
htmlRepresentation);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -277,6 +277,19 @@
|
|||
.service-icon {
|
||||
background-image: url(images/resource-icons/orange.png) !important;
|
||||
}
|
||||
.site-icon {
|
||||
background-image: url(images/resource-icons/burlywood.png) !important;
|
||||
}
|
||||
.person-icon {
|
||||
background-image: url(images/resource-icons/pink.png) !important;
|
||||
}
|
||||
.plugin-icon {
|
||||
background-image: url(images/resource-icons/navy.png) !important;
|
||||
}
|
||||
.runningplugin-icon {
|
||||
background-image: url(images/resource-icons/turquoise.png) !important;
|
||||
}
|
||||
|
||||
.wsresources-icon {
|
||||
background-image: url(images/resource-icons/red.png) !important;
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 401 B |
Binary file not shown.
After Width: | Height: | Size: 408 B |
Binary file not shown.
After Width: | Height: | Size: 395 B |
Binary file not shown.
After Width: | Height: | Size: 392 B |
Loading…
Reference in New Issue