From f8d7cb9a66eb13ea7f81ff696075fcc0a6e5cd0a Mon Sep 17 00:00:00 2001 From: "nikolas.laskaris" Date: Tue, 18 Feb 2014 09:37:01 +0000 Subject: [PATCH] Added some functions on GenericResource and RuntimeResource to support the Harvesters settings Portlet git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerCore@91811 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../framework/core/util/GenericResource.java | 16 ++++++++ .../framework/core/util/RuntimeResource.java | 40 +++++++++++-------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/gcube/application/framework/core/util/GenericResource.java b/src/main/java/org/gcube/application/framework/core/util/GenericResource.java index a6ea22d..7fdf654 100644 --- a/src/main/java/org/gcube/application/framework/core/util/GenericResource.java +++ b/src/main/java/org/gcube/application/framework/core/util/GenericResource.java @@ -452,6 +452,22 @@ public class GenericResource implements GenericResourceInfoI { } } + public List getGenericResourcesByType(String type) throws RemoteException { + List output = new ArrayList(); + SimpleQuery queryMan = null; + try { + queryMan = queryFor(org.gcube.common.resources.gcore.GenericResource.class); + queryMan.addCondition("$resource/Profile/SecondaryType eq '"+type+"'"); + List results = client.submit(queryMan); + for(org.gcube.common.resources.gcore.GenericResource res : results) + output.add(new ISGenericResource(res.id(),res.profile().name(),res.profile().description(),res.profile().bodyAsString(),res.profile().type())); + return output; + } catch (Exception e) { + logger.error("Exception:", e); + throw new RemoteException(); + } + } + /** * @param id the id of the generic resource diff --git a/src/main/java/org/gcube/application/framework/core/util/RuntimeResource.java b/src/main/java/org/gcube/application/framework/core/util/RuntimeResource.java index 2f568aa..1bc2190 100644 --- a/src/main/java/org/gcube/application/framework/core/util/RuntimeResource.java +++ b/src/main/java/org/gcube/application/framework/core/util/RuntimeResource.java @@ -11,6 +11,7 @@ import java.rmi.RemoteException; import java.util.ArrayList; import java.util.List; +import org.gcube.application.framework.core.GenericResourceInfoI; import org.gcube.application.framework.core.cache.CachesManager; import org.gcube.application.framework.core.genericresources.model.ISGenericResource; import org.gcube.application.framework.core.session.ASLSession; @@ -20,6 +21,7 @@ import org.gcube.common.scope.api.ScopeProvider; import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.ScopedPublisher; +import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +33,7 @@ public class RuntimeResource { protected static ScopedPublisher scopedPublisher = null; - protected static RegistryPublisher publisher = null; +// protected static RegistryPublisher registryPublisher = null; protected static DiscoveryClient client = null; /** @@ -46,7 +48,7 @@ public class RuntimeResource { try { ScopeProvider.instance.set(session.getScope()); scopedPublisher = RegistryPublisherFactory.scopedPublisher(); - publisher = RegistryPublisherFactory.create(); +// registryPublisher = RegistryPublisherFactory.create(); } catch (Exception e) { logger.error("Exception:", e); } @@ -69,7 +71,7 @@ public class RuntimeResource { try { ScopeProvider.instance.set(session.getScope()); scopedPublisher = RegistryPublisherFactory.scopedPublisher(); - publisher = RegistryPublisherFactory.create(); +// registryPublisher = RegistryPublisherFactory.create(); } catch (Exception e) { logger.error("Exception:", e); } @@ -90,28 +92,26 @@ public class RuntimeResource { * @return the id of the newly created runtime resource. * @throws RemoteException */ - public String createRuntimeResource(ServiceEndpoint runtimeResource) throws RemoteException { - try { - List scopes=new ArrayList(); - scopes.add(session.getScope()); - ServiceEndpoint se = scopedPublisher.create(runtimeResource, scopes); - logger.info("Created Generic Resource with id: "+se.id()+" on scope: "+scopes.toString()); - return se.id(); - } catch (Exception e) { - logger.error("Exception:", e); - throw new RemoteException(); - } + public String createRuntimeResource(ServiceEndpoint runtimeResource) throws RegistryNotFoundException { + List scopes = new ArrayList(); + scopes.add(session.getScope()); + ServiceEndpoint se = scopedPublisher.create(runtimeResource, scopes); +// ServiceEndpoint se = registryPublisher.create(runtimeResource); + logger.debug("Created Runtime Resource with id: "+se.id()+" on scope: "+scopes.toString()); + return se.id(); } /** * it replaces the runtime resource with this one * @param runtimeResource * @return + * @throws RemoteException */ public String updateRuntimeResource(ServiceEndpoint runtimeResource) throws RemoteException { try { ServiceEndpoint se = scopedPublisher.update(runtimeResource); - logger.info("Updated Generic Resource with id: "+runtimeResource.id()+"\tNew id : "+se.id()); +// ServiceEndpoint se = registryPublisher.update(runtimeResource); + logger.debug("Updated Runtime Resource with id: "+runtimeResource.id()+"\tNew id : "+se.id()); return se.id(); } catch (Exception e) { logger.error("Exception:", e); @@ -130,7 +130,8 @@ public class RuntimeResource { List scopes=new ArrayList(); scopes.add(session.getScope()); ServiceEndpoint se = scopedPublisher.remove(runtimeResource,scopes); - logger.info("Deleted Generic Resource with id: "+runtimeResource.id()); +// ServiceEndpoint se = registryPublisher.remove(runtimeResource); + logger.debug("Deleted Runtime Resource with id: "+runtimeResource.id()); return se.id(); } catch (Exception e) { logger.error("Exception:", e); @@ -154,6 +155,13 @@ public class RuntimeResource { return resources; } + public List getRuntimeResourceByCategory(String category){ + SimpleQuery query = queryFor(ServiceEndpoint.class); + DiscoveryClient client = clientFor(ServiceEndpoint.class); + query.addCondition("$resource/Profile/Category eq '"+category+"'"); + List resources = client.submit(query); + return resources; + }