diff --git a/pom.xml b/pom.xml index 262c6b7..906bba9 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ + org.gcube.core common-generic-clients @@ -37,6 +38,28 @@ common-fw-clients + + + org.gcube.common + authorization-client + + + org.gcube.common + common-authorization + + + + + org.gcube.core + common-encryption + + + + + org.gcube.information-system + information-system-model + + org.gcube.information-system resource-registry-api diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/plugin/AbstractPlugin.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/plugin/AbstractPlugin.java deleted file mode 100644 index a2fcfc9..0000000 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/plugin/AbstractPlugin.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.gcube.informationsystem.resourceregistry.publisher.plugin; - -import org.gcube.common.clients.Plugin; -import org.gcube.informationsystem.resourceregistry.Constants; - -/** - * - * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ - * - * @param - * @param

- */ -public abstract class AbstractPlugin implements Plugin { - - public final String name; - - public AbstractPlugin(String name) { - this.name = name; - } - - public String serviceClass() { - return Constants.SERVICE_CLASS; - } - - public String serviceName() { - return Constants.SERVICE_NAME; - } - - public String name() { - return name; - } - -} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/plugin/ResourceRegistryRegistryPlugin.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/plugin/ResourceRegistryPublisherPlugin.java similarity index 60% rename from src/main/java/org/gcube/informationsystem/resourceregistry/publisher/plugin/ResourceRegistryRegistryPlugin.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/publisher/plugin/ResourceRegistryPublisherPlugin.java index a242399..4d29a6e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/plugin/ResourceRegistryRegistryPlugin.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/plugin/ResourceRegistryPublisherPlugin.java @@ -7,22 +7,22 @@ import javax.xml.ws.EndpointReference; import org.gcube.common.clients.config.ProxyConfig; import org.gcube.common.clients.delegates.ProxyDelegate; +import org.gcube.informationsystem.resourceregistry.Constants; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.publisher.proxy.ResourceRegistryPublisher; +import org.gcube.informationsystem.resourceregistry.publisher.proxy.ResourceRegistryPublisherImpl; /** * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ -public class ResourceRegistryRegistryPlugin extends AbstractPlugin{ +public class ResourceRegistryPublisherPlugin extends AbstractPlugin{ - public ResourceRegistryRegistryPlugin(){ - super(ResourceRegistryRegistryPlugin.class.getSimpleName()); + public ResourceRegistryPublisherPlugin(){ + super(Constants.SERVICE_ENTRY_NAME); } @Override public String namespace() { - // TODO Auto-generated method stub return null; } @@ -37,27 +37,18 @@ public class ResourceRegistryRegistryPlugin extends AbstractPlugin config) throws Exception { - // TODO Auto-generated method stub - return null; + return address; } - /* (non-Javadoc) - * @see org.gcube.common.clients.delegates.ProxyPlugin#newProxy(org.gcube.common.clients.delegates.ProxyDelegate) - */ @Override - public ResourceRegistryPublisher newProxy( + public ResourceRegistryPublisherImpl newProxy( ProxyDelegate delegate) { - // TODO Auto-generated method stub - return null; + return new ResourceRegistryPublisherImpl(delegate); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/JaxRSEndpointReference.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/JaxRSEndpointReference.java new file mode 100644 index 0000000..10ffa73 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/JaxRSEndpointReference.java @@ -0,0 +1,63 @@ +/** + * + */ +package org.gcube.informationsystem.resourceregistry.publisher.proxy; + +import java.io.StringReader; +import java.io.StringWriter; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.ws.EndpointReference; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +class JaxRSEndpointReference { + + private static final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + private static final String addressLocalName = "Address"; + //private static final String keyLocalName = "ResourceKey"; + + String address; + //Element key; + + static { + factory.setNamespaceAware(true); + } + + public JaxRSEndpointReference(EndpointReference reference) { + this(serialise(reference)); + } + + public JaxRSEndpointReference(String reference) { + + try { + + Document document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(reference))); + + NodeList addresses = document.getElementsByTagNameNS("*", addressLocalName); + + if (addresses.getLength() == 0) + throw new RuntimeException("reference does not contain an address"); + + address = addresses.item(0).getTextContent(); + + } catch (Exception e) { + throw new IllegalArgumentException("reference is not a gCore reference", e); + } + + } + + @Override + public String toString() { + return address; + } + + // helper + private static String serialise(EndpointReference reference) { + StringWriter writer = new StringWriter(); + reference.writeTo(new StreamResult(writer)); + return writer.toString(); + } +} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java deleted file mode 100644 index 8e60a08..0000000 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java +++ /dev/null @@ -1,462 +0,0 @@ -/** - * - */ -package org.gcube.informationsystem.resourceregistry.publisher.proxy; - -import javax.xml.ws.EndpointReference; - -import org.gcube.common.clients.Call; -import org.gcube.common.clients.delegates.AsyncProxyDelegate; -import org.gcube.common.clients.delegates.ProxyDelegate; -import org.gcube.common.clients.exceptions.ServiceException; -import org.gcube.informationsystem.resourceregistry.api.ContextManagement; -import org.gcube.informationsystem.resourceregistry.api.EntityManagement; -import org.gcube.informationsystem.resourceregistry.api.SchemaManagement; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.FacetNotFoundException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.ResourceNotFoundException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; - -/** - * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ - */ -public class ResourceRegistryPublisher implements ContextManagement, SchemaManagement, EntityManagement { - - private final AsyncProxyDelegate delegate; - - public ResourceRegistryPublisher(ProxyDelegate config) { - this.delegate = new AsyncProxyDelegate(config); - } - - @Override - public String createFacet(String facetType, String jsonRepresentation) - throws ResourceRegistryException { - Call call = new Call() { - - public String call(EndpointReference endpoint) throws Exception { - // TODO - return null; - }; - - }; - - try { - return delegate.make(call); - } catch (Exception e) { - throw new ServiceException(e); - } - } - - @Override - public String readFacet(String uuid) throws FacetNotFoundException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String updateFacet(String uuid, String jsonRepresentation) - throws FacetNotFoundException, ResourceRegistryException { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean deleteFacet(String uuid) throws FacetNotFoundException, - ResourceRegistryException { - // TODO Auto-generated method stub - return false; - } - - @Override - public String createResource(String resourceType, String jsonRepresentation) - throws ResourceRegistryException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String readResource(String uuid) throws ResourceNotFoundException { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean deleteResource(String uuid) - throws ResourceNotFoundException, ResourceRegistryException { - // TODO Auto-generated method stub - return false; - } - - @Override - public String registerFacetSchema(String jsonSchema) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getFacetSchema(String facetType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String registerResourceSchema(String jsonSchema) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getResourceSchema(String resourceType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String create(final String parentContextUUID,final String jsonRepresentation) - throws ContextCreationException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String rename(String contextUUID, String newName) - throws ContextNotFoundException, ContextException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String move(String newParentUUID, String contextToMoveUUID) - throws ContextNotFoundException, ContextException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String delete(String uuid) throws ContextNotFoundException, - ContextException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.EntityManagement#readFacet(java.lang.String, java.lang.String) - */ - @Override - public String readFacet(String uuid, String facetType) - throws FacetNotFoundException, ResourceRegistryException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.EntityManagement#readResource(java.lang.String, java.lang.String) - */ - @Override - public String readResource(String uuid, String resourceType) - throws ResourceNotFoundException, ResourceRegistryException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.EntityManagement#attachFacet(java.lang.String, java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public String attachFacet(String resourceUUID, String facetUUID, - String consistOfType, String jsonProperties) - throws FacetNotFoundException, ResourceNotFoundException, - ResourceRegistryException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.EntityManagement#detachFacet(java.lang.String) - */ - @Override - public boolean detachFacet(String consistOfUUID) - throws ResourceRegistryException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.EntityManagement#attachResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public String attachResource(String sourceResourceUUID, - String targetResourceUUID, String relatedToType, - String jsonProperties) throws ResourceNotFoundException, - ResourceRegistryException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.EntityManagement#detachResource(java.lang.String) - */ - @Override - public boolean detachResource(String relatedToUUID) - throws ResourceRegistryException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#registerEntitySchema(java.lang.String) - */ - @Override - public String registerEntitySchema(String jsonSchema) - throws SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#getEntitySchema(java.lang.String) - */ - @Override - public String getEntitySchema(String entityType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#updateEntitySchema(java.lang.String, java.lang.String) - */ - @Override - public String updateEntitySchema(String entityType, String jsonSchema) - throws SchemaNotFoundException, SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#deleteEntitySchema(java.lang.String) - */ - @Override - public String deleteEntitySchema(String entityType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#updateFacetSchema(java.lang.String, java.lang.String) - */ - @Override - public String updateFacetSchema(String facetType, String jsonSchema) - throws SchemaNotFoundException, SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#deleteFacetSchema(java.lang.String) - */ - @Override - public String deleteFacetSchema(String facetType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#updateResourceSchema(java.lang.String, java.lang.String) - */ - @Override - public String updateResourceSchema(String resourceType, String jsonSchema) - throws SchemaNotFoundException, SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#deleteResourceSchema(java.lang.String) - */ - @Override - public String deleteResourceSchema(String resourceType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#registerEmbeddedTypeSchema(java.lang.String) - */ - @Override - public String registerEmbeddedTypeSchema(String jsonSchema) - throws SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#getEmbeddedTypeSchema(java.lang.String) - */ - @Override - public String getEmbeddedTypeSchema(String embeddedType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#updateEmbeddedTypeSchema(java.lang.String, java.lang.String) - */ - @Override - public String updateEmbeddedTypeSchema(String embeddedType, - String jsonSchema) throws SchemaNotFoundException, SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#deleteEmbeddedTypeSchema(java.lang.String) - */ - @Override - public String deleteEmbeddedTypeSchema(String embeddedType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#registerRelationSchema(java.lang.String) - */ - @Override - public String registerRelationSchema(String jsonSchema) - throws SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#getRelationSchema(java.lang.String) - */ - @Override - public String getRelationSchema(String relationType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#updateRelationSchema(java.lang.String, java.lang.String) - */ - @Override - public String updateRelationSchema(String relationType, String jsonSchema) - throws SchemaNotFoundException, SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#deleteRelationSchema(java.lang.String) - */ - @Override - public String deleteRelationSchema(String relationType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#registerConsistOfSchema(java.lang.String) - */ - @Override - public String registerConsistOfSchema(String jsonSchema) - throws SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#getConsistOfSchema(java.lang.String) - */ - @Override - public String getConsistOfSchema(String consistOfType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#updateConsistOfSchema(java.lang.String, java.lang.String) - */ - @Override - public String updateConsistOfSchema(String consistOfType, String jsonSchema) - throws SchemaNotFoundException, SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#deleteConsistOfSchema(java.lang.String) - */ - @Override - public String deleteConsistOfSchema(String consistOfType) - throws SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#registerRelatedToSchema(java.lang.String) - */ - @Override - public String registerRelatedToSchema(String jsonSchema) - throws SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#getRelatedToSchema(java.lang.String) - */ - @Override - public String getRelatedToSchema(String relatedToType) - throws SchemaNotFoundException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#updateRelatedToSchema(java.lang.String, java.lang.String) - */ - @Override - public String updateRelatedToSchema(String relatedToType, String jsonSchema) - throws SchemaNotFoundException, SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.SchemaManagement#deleteRelatedToSchema(java.lang.String) - */ - @Override - public String deleteRelatedToSchema(String relatedToType) - throws SchemaException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.gcube.informationsystem.resourceregistry.api.ContextManagement#read(java.lang.String) - */ - @Override - public String read(String contextUUID) throws ContextNotFoundException, - ContextException { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherFactory.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherFactory.java new file mode 100644 index 0000000..b08f109 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherFactory.java @@ -0,0 +1,17 @@ +package org.gcube.informationsystem.resourceregistry.publisher.proxy; + + +public class ResourceRegistryPublisherFactory { + + private static ResourceRegistryPublisher singleton = new ResourceRegistryPublisherImpl(); + + public static ResourceRegistryPublisher create(){ + return singleton; + } + + + public static void setPublisher(ResourceRegistryPublisher registryPublisher){ + singleton = registryPublisher; + } + +} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java new file mode 100644 index 0000000..a074873 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java @@ -0,0 +1,192 @@ +package org.gcube.informationsystem.resourceregistry.publisher.proxy; + +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import org.gcube.common.authorization.client.Constants; +import org.gcube.common.authorization.library.AuthorizationEntry; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.resources.gcore.GCoreEndpoint; +import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.impl.utils.Entities; +import org.gcube.informationsystem.model.embedded.Embedded; +import org.gcube.informationsystem.model.entity.Facet; +import org.gcube.informationsystem.model.entity.Resource; +import org.gcube.informationsystem.model.relation.ConsistsOf; +import org.gcube.informationsystem.model.relation.IsRelatedTo; +import org.gcube.informationsystem.resourceregistry.api.rest.EntityPath; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.gcube.resources.discovery.icclient.ICFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher { + + private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisher.class); + + private static final Random random; + + protected final List endpoints; + + static { + random = new Random(); + } + + protected static List getServiceEndpoint(){ + SimpleQuery query = ICFactory.queryFor(GCoreEndpoint.class); + query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'", org.gcube.informationsystem.resourceregistry.Constants.SERVICE_CLASS)); + query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'", org.gcube.informationsystem.resourceregistry.Constants.SERVICE_NAME)); + query.setResult("$resource"); + + DiscoveryClient client = ICFactory.clientFor(GCoreEndpoint.class); + return client.submit(query); + } + + protected ResourceRegistryPublisherImpl(){ + this.endpoints = getServiceEndpoint(); + }; + + private static int randInt(int min, int max) { + int randomNum = random.nextInt((max - min) + 1) + min; + return randomNum; + } + + protected URL getBaseURL() throws MalformedURLException { + GCoreEndpoint gCoreEndpoint = endpoints.get(randInt(0, endpoints.size()-1)); + Endpoint endpoint = gCoreEndpoint.profile().endpointMap().get(org.gcube.informationsystem.resourceregistry.Constants.SERVICE_ENTRY_NAME); + return endpoint.uri().toURL(); + } + + protected AuthorizationEntry getAuthorizationEntry() { + try{ + AuthorizationEntry info = Constants.authorizationService().get(SecurityTokenProvider.instance.get()); + logger.info("Context is {} ",info.getContext()); + return info; + }catch(Exception e){ + String error = "Error retreiving security token"; + logger.warn(error,e); + throw new RuntimeException(error,e); + } + } + + private HttpURLConnection makeRequest(URL url, String method) throws Exception{ + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + if (SecurityTokenProvider.instance.get()==null) { + if(ScopeProvider.instance.get()==null){ + throw new RuntimeException("Null Token and Scope. Please set your token first."); + } + connection.setRequestProperty("gcube-scope", ScopeProvider.instance.get()); + }else{ + connection.setRequestProperty(Constants.TOKEN_HEADER_ENTRY, SecurityTokenProvider.instance.get()); + } + connection.setRequestMethod(method); + connection.setDoOutput(true); + return connection; + } + + protected HttpURLConnection getHttpURLConnection(String path, String method, Map paramenter) throws Exception { + URL url = new URL(getBaseURL(), path); + HttpURLConnection connection = makeRequest(url, method); + return connection; + } + + @Override + public E createEmbedded(E embedded) { + return null; + } + + @Override + public E updateEmbedded(E embedded) { + // TODO Auto-generated method stub + return null; + } + + @Override + public E deleteEmbedded(E embedded) { + // TODO Auto-generated method stub + return null; + } + + + @Override + public F createFacet(F facet) { + String marshalledFacet = Entities.marshal(facet); + String path = EntityPath.ENTITY_PATH_PART + "/" + EntityPath.FACET_PATH_PART + "/" + facet.NAME + "?" + EntityPath.DEFINITION_PARAM + "=" + marshalledFacet; + HttpURLConnection connection = getHttpURLConnection(path,); + + // TODO Auto-generated method stub + return null; + } + + @Override + public F updateFacet(F facet) { + // TODO Auto-generated method stub + return null; + } + + @Override + public F deleteFacet(F facet) { + // TODO Auto-generated method stub + return null; + } + + @Override + public R createResource(R resource) { + // TODO Auto-generated method stub + return null; + } + + @Override + public R deleteResource(R resource) { + // TODO Auto-generated method stub + return null; + } + + @Override + public > C createConsistsOf( + C consistsOf) { + // TODO Auto-generated method stub + return null; + } + + @Override + public > C updateConsistsOf( + C consistsOf) { + // TODO Auto-generated method stub + return null; + } + + @Override + public > C deleteConsistsOf( + C consistsOf) { + // TODO Auto-generated method stub + return null; + } + + @Override + public > I create(I isRelatedTo) { + // TODO Auto-generated method stub + return null; + } + + @Override + public > I update(I isRelatedTo) { + // TODO Auto-generated method stub + return null; + } + + @Override + public > I delete(I isRelatedTo) { + // TODO Auto-generated method stub + return null; + } + +}