diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java index 9fe7926..b0e4f53 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/RegistryClientRequester.java @@ -12,12 +12,14 @@ import java.util.Set; import org.gcube.common.authorization.library.provider.AccessTokenProvider; import org.gcube.common.keycloak.KeycloakClient; import org.gcube.common.keycloak.KeycloakClientFactory; +import org.gcube.common.keycloak.model.AccessToken.Access; import org.gcube.common.keycloak.model.ModelUtils; import org.gcube.common.keycloak.model.TokenResponse; -import org.gcube.common.keycloak.model.AccessToken.Access; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.model.reference.entities.Resource; +import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; import org.gcube.informationsystem.types.reference.Type; @@ -25,6 +27,7 @@ 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 @@ -32,7 +35,7 @@ import org.gcube.resourcemanagement.support.shared.types.datamodel.CompleteResou */ public class RegistryClientRequester { - private static ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); + private static ResourceRegistryClient resourceRegistryClient; private static KeycloakClient client = KeycloakClientFactory.newInstance(); @@ -40,21 +43,26 @@ public class RegistryClientRequester { private static final String clientID = "resource-registry-portlet-expieve"; private static final String secret = "179bd3bc-5cc4-11ec-bf63-0242ac130001"; + private static final String rootScope = "/gcube"; + public static final Set getAvailableContexts() throws Exception { - Set contexts = new HashSet(); + Set contextList = new HashSet(); + ScopeProvider.instance.set(rootScope); + AccessTokenProvider.instance.set(getTokenForContext(rootScope)); try { - TokenResponse response = client.queryOIDCToken(new URL(endpoint), clientID, secret); - Map resourceAccess = ModelUtils.getAccessTokenFrom(response).getResourceAccess(); - for (String context : resourceAccess.keySet()) { - try { - ScopeBean scope = new ScopeBean(context.replaceAll("%2F", "/")); - contexts.add(scope.toString()); - }catch (IllegalArgumentException e) { } - } + resourceRegistryClient = ResourceRegistryClientFactory.create(); + + ContextCache contextCache = ContextCache.getInstance(); + + contextList = contextCache.getContextFullNameToUUIDAssociation().keySet(); + } catch (Exception e) { return Collections.emptySet(); + }finally { + AccessTokenProvider.instance.reset(); + ScopeProvider.instance.reset(); } - return contexts; + return contextList; } private static String getTokenForContext(String context) { @@ -84,9 +92,14 @@ public class RegistryClientRequester { ScopeProvider.instance.set(scope); AccessTokenProvider.instance.set(getTokenForContext(scope)); try { - + resourceRegistryClient = ResourceRegistryClientFactory.create(); List types = resourceRegistryClient.getType(Resource.class, true); + + System.out.println("resource type returned "+types.size()); + for (Type t : types) { + System.out.println("resource type found "+t.getName()+ " in "+scope); + String val = null; if (t.getName().equals("EService")) val= "RunningInstance"; @@ -94,7 +107,15 @@ public class RegistryClientRequester { val = "GenericResource"; if (t.getName().equals("HostingNode")) val = "GHN"; - retval.put(val, UtilityResource.getSubResourcesTreeQuery(resourceRegistryClient, t.getName())); + try { + if (val!=null) { + ArrayList subtrees = UtilityResource.getSubResourcesTreeQuery(resourceRegistryClient, t.getName()); + if (!subtrees.isEmpty()) + retval.put(val, subtrees); + } + }catch (Exception e) { + e.printStackTrace(); + } } } catch (Exception e) { @@ -117,7 +138,7 @@ public class RegistryClientRequester { AccessTokenProvider.instance.set(getTokenForContext(scope)); try { - + resourceRegistryClient = ResourceRegistryClientFactory.create(); Listresource=new ArrayList(); switch (type) { diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java index 13dac9d..a67b953 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/server/ServiceProxyImpl.java @@ -260,7 +260,7 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro ServerConsole.trace(LOG_PREFIX, "[GET-SCOPES] getting available scopes"); Vector retval = new Vector(); try { - //TODO + retval.addAll(RegistryClientRequester.getAvailableContexts()); } catch (Exception e) { retval.add("/gcube"); retval.add("/gcube/devsec"); diff --git a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java index 0160aa8..a59106a 100644 --- a/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java +++ b/src/main/java/org/gcube/portlets/admin/resourcemanagement/shared/resource/UtilityResource.java @@ -130,7 +130,12 @@ public class UtilityResource { identifiedFacet="SoftwareFacet"; break; + default: + return new ArrayList<>(0); + } + + String query="SELECT DISTINCT("+field+") AS "+field+" " + "FROM (TRAVERSE outE('IsIdentifiedBy'),inV('"+identifiedFacet+"') FROM "+entity+")"; diff --git a/src/main/resources/org/gcube/portlets/admin/resourcemanagement/ResourceManagementPortlet.gwt.xml b/src/main/resources/org/gcube/portlets/admin/resourcemanagement/ResourceManagementPortlet.gwt.xml index 47eb9e2..225cfd6 100644 --- a/src/main/resources/org/gcube/portlets/admin/resourcemanagement/ResourceManagementPortlet.gwt.xml +++ b/src/main/resources/org/gcube/portlets/admin/resourcemanagement/ResourceManagementPortlet.gwt.xml @@ -4,7 +4,7 @@ - + diff --git a/src/main/webapp/WEB-INF/portlet.xml b/src/main/webapp/WEB-INF/portlet.xml index 0433b79..2068bb2 100644 --- a/src/main/webapp/WEB-INF/portlet.xml +++ b/src/main/webapp/WEB-INF/portlet.xml @@ -2,7 +2,7 @@ resources-management - Resources Management + Resource Registry Management org.gcube.portlets.admin.resourcemanagement.server.portlet.ResourceManagementPortlet view-jsp @@ -13,7 +13,7 @@ text/html - Resources Management + Resource Registry Management Resources Management Resources Management diff --git a/src/main/webapp/WEB-INF/xml/scopedata.xml b/src/main/webapp/WEB-INF/xml/scopedata.xml index 2a50a39..d4a7c69 100644 --- a/src/main/webapp/WEB-INF/xml/scopedata.xml +++ b/src/main/webapp/WEB-INF/xml/scopedata.xml @@ -14,16 +14,6 @@ ServiceMap_devsec.xml /gcube/devsec - - gcube/devNext - ServiceMap_devNext.xml - /gcube/devNext - - - gcube/preprod - ServiceMap_preprod.xml - /gcube/preprod - diff --git a/src/main/webapp/conf/resourcemanagement.properties b/src/main/webapp/conf/resourcemanagement.properties index a3f6f39..1c60db9 100644 --- a/src/main/webapp/conf/resourcemanagement.properties +++ b/src/main/webapp/conf/resourcemanagement.properties @@ -11,7 +11,7 @@ RUNNING_MODE = STANDALONE DEFAULT_USER = massimiliano.assante # The scope that will be used as default -DEFAULT_SCOPE =/gcube/devNext +DEFAULT_SCOPE =/gcube # the target of update notification (if in singleton mode) # mails MUST be separated by ; USERMAIL_TO = m.assante@gmail.com