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
This commit is contained in:
nikolas.laskaris 2014-02-18 09:37:01 +00:00
parent 5177bde57b
commit f8d7cb9a66
2 changed files with 40 additions and 16 deletions

View File

@ -452,6 +452,22 @@ public class GenericResource implements GenericResourceInfoI {
}
}
public List<ISGenericResource> getGenericResourcesByType(String type) throws RemoteException {
List<ISGenericResource> output = new ArrayList<ISGenericResource>();
SimpleQuery queryMan = null;
try {
queryMan = queryFor(org.gcube.common.resources.gcore.GenericResource.class);
queryMan.addCondition("$resource/Profile/SecondaryType eq '"+type+"'");
List <org.gcube.common.resources.gcore.GenericResource> 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

View File

@ -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<ServiceEndpoint> 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<String> scopes=new ArrayList<String>();
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<String> scopes = new ArrayList<String>();
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<String> scopes=new ArrayList<String>();
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<ServiceEndpoint> getRuntimeResourceByCategory(String category){
SimpleQuery query = queryFor(ServiceEndpoint.class);
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category eq '"+category+"'");
List<ServiceEndpoint> resources = client.submit(query);
return resources;
}