diff --git a/distro/changelog.xml b/distro/changelog.xml index 2d8259f..6a64ab1 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -8,7 +8,10 @@ Improved error handling in Plugin#convert() - + AddressUtils preserve protocol from URIs/URLs + + internal refactoring + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 44712e8..ca01f40 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.core common-clients - 2.0.2-SNAPSHOT + 2.1.0-SNAPSHOT Common Clients A framework for client APIs diff --git a/src/main/java/org/gcube/common/clients/delegates/ProxyPlugin.java b/src/main/java/org/gcube/common/clients/delegates/ProxyPlugin.java index 1988888..6499d71 100644 --- a/src/main/java/org/gcube/common/clients/delegates/ProxyPlugin.java +++ b/src/main/java/org/gcube/common/clients/delegates/ProxyPlugin.java @@ -28,6 +28,18 @@ public interface ProxyPlugin { * @return the namespace */ String namespace(); + + /** + * Returns the gCube name of the service. + * @return the name + */ + String serviceClass(); + + /** + * Returns the gCube class of the service. + * @return the class + */ + String serviceName(); /** * Converts a fault raised by a {@link Call} into a fault that can be recognised by {@link ProxyDelegate} clients. diff --git a/src/main/java/org/gcube/common/clients/queries/AbstractQuery.java b/src/main/java/org/gcube/common/clients/queries/AbstractQuery.java deleted file mode 100644 index d69c1a0..0000000 --- a/src/main/java/org/gcube/common/clients/queries/AbstractQuery.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.gcube.common.clients.queries; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.gcube.common.clients.delegates.ProxyPlugin; -import org.gcube.common.clients.exceptions.DiscoveryException; - -/** - * Partial implementation of {@link Query}s. - * - * @author Fabio Simeoni - * - * @param the type of service addresses - * @param the type of query results - */ -public abstract class AbstractQuery implements Query { - - private final ProxyPlugin plugin; - private final Map conditions = new HashMap(); - - //default matcher does not filter out any result - private ResultMatcher matcher = new ResultMatcher() { - @Override public boolean match(R doc) { - return true; - } - }; - - /** - * Creates an instance with a {@link ISFacade}, a {@link PluginAdapter}, and a type of IS queries - * @param facade the facade - * @param plugin the plugin - * @param queryClass the query type - */ - protected AbstractQuery(ProxyPlugin plugin) { - this.plugin = plugin; - } - - /** - * Adds a condition to the query. - * @param property an expression that identifies a property of service endpoints - * @param value the value of the property - */ - public void addCondition(String property, String value) { - this.conditions.put(property,value); - } - - /** - * Sets an {@link ResultMatcher} for the query. - * @param matcher the matcher. - */ - public void setMatcher(ResultMatcher matcher) { - this.matcher=matcher; - } - - @Override - public final List fire() throws DiscoveryException { - - //delegate actual execution to subclass-specific mechanisms - List results = fire(conditions); - - //from results to addresses - List endpoints = new ArrayList(); - - for (R result : results) - try { - if (matcher.match(result)) //should we include this? ask matcher - endpoints.add(address(result)); //extract address - } - catch(IllegalArgumentException e) { - //skip result, this is just a signal from subclasses - }; - - return endpoints; - } - - /** - * Executes the query through implementation-specific means. - * @param conditions the conditions to apply on the query prior to its execution - * @return the query results - * @throws DiscoveryException if the query could not be executed - */ - protected abstract List fire(Map conditions) throws DiscoveryException; - - /** - * Returns an endpoint address from a query result. - * @param result the result - * @return the address - * @throws IllegalArgumentException if an address cannot be derived from the result - */ - protected abstract A address(R result) throws IllegalArgumentException; - - /** - * Returns the {@link ProxyPlugin}. - * @return the plugin - */ - protected ProxyPlugin plugin() { - return plugin; - } - - //queries are value objects based on properties - - @Override - public final boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AbstractQuery other = (AbstractQuery) obj; - if (conditions == null) { - if (other.conditions != null) - return false; - } else if (!conditions.equals(other.conditions)) - return false; - return true; - } - - @Override - public final int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((conditions == null) ? 0 : conditions.hashCode()); - return result; - } - - @Override - public final String toString() { - return conditions.toString(); - } -} diff --git a/src/main/java/org/gcube/common/clients/queries/ResultMatcher.java b/src/main/java/org/gcube/common/clients/queries/ResultMatcher.java index 5c8cb8c..ab37c5e 100644 --- a/src/main/java/org/gcube/common/clients/queries/ResultMatcher.java +++ b/src/main/java/org/gcube/common/clients/queries/ResultMatcher.java @@ -9,7 +9,7 @@ package org.gcube.common.clients.queries; * * @param the type of query results * - * @see AbstractQuery + * @see Query * */ public interface ResultMatcher {