diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmActionImportImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmActionImportImpl.java index 594182458..15a9604c1 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmActionImportImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmActionImportImpl.java @@ -30,6 +30,8 @@ public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmAc private final ActionImport actionImport; + private FullQualifiedName actionFQN; + public EdmActionImportImpl(final Edm edm, final EdmEntityContainer container, final String name, final ActionImport actionImport) { @@ -37,18 +39,17 @@ public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmAc this.actionImport = actionImport; } - @Override - public EdmAction getUnboundAction() { - return getBoundAction(null, null); + public FullQualifiedName getActionFQN() { + if (actionFQN == null) { + actionFQN = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(actionImport.getAction()). + setDefaultNamespace(container.getNamespace()).build().getFullQualifiedName(); + } + return actionFQN; } @Override - public EdmAction getBoundAction( - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { - - return edm.getAction(new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(actionImport.getAction()). - setDefaultNamespace(container.getNamespace()).build().getFullQualifiedName(), - bindingParameterTypeName, isBindingParameterCollection); + public EdmAction getUnboundAction() { + return edm.getUnboundAction(getActionFQN()); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java index 52fce983c..21a1dbfcc 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmClientImpl.java @@ -210,6 +210,37 @@ public class EdmClientImpl extends AbstractEdm { return result; } + @Override + protected List createUnboundFunctions(final FullQualifiedName functionName) { + final List result = new ArrayList(); + + final Schema schema = xmlSchemaByNamespace.get(functionName.getNamespace()); + if (schema instanceof org.apache.olingo.client.api.edm.xml.v4.Schema) { + final List functions = ((org.apache.olingo.client.api.edm.xml.v4.Schema) schema). + getFunctions(functionName.getName()); + for (final Iterator itor = functions.iterator(); itor.hasNext();) { + final Function function = itor.next(); + if (!function.isBound()) { + result.add(EdmFunctionImpl.getInstance(this, functionName, function)); + } + } + } else { + for (EntityContainer entityContainer : schema.getEntityContainers()) { + @SuppressWarnings("unchecked") + final List functionImports = + (List) entityContainer.getFunctionImports(functionName.getName()); + for (final Iterator itor = functionImports.iterator(); itor.hasNext();) { + final FunctionImport functionImport = itor.next(); + if (FunctionImportUtils.canProxyFunction(functionImport) && !functionImport.isBindable()) { + result.add(EdmFunctionProxy.getInstance(this, functionName, functionImport)); + } + } + } + } + + return result; + } + @Override protected EdmFunction createUnboundFunction(final FullQualifiedName functionName, final List parameterNames) { EdmFunction result = null; @@ -235,8 +266,8 @@ public class EdmClientImpl extends AbstractEdm { } else { for (EntityContainer entityContainer : schema.getEntityContainers()) { @SuppressWarnings("unchecked") - final List functionImports = (List) entityContainer. - getFunctionImports(functionName.getName()); + final List functionImports = + (List) entityContainer.getFunctionImports(functionName.getName()); boolean found = false; for (final Iterator itor = functionImports.iterator(); itor.hasNext() && !found;) { final FunctionImport functionImport = itor.next(); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmFunctionImportImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmFunctionImportImpl.java index 51ea4e6aa..5c2575e43 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmFunctionImportImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmFunctionImportImpl.java @@ -32,6 +32,8 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm private final FunctionImport functionImport; + private FullQualifiedName functionFQN; + public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final String name, final FunctionImport functionImport) { @@ -40,17 +42,22 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm } @Override - public EdmFunction getUnboundFunction(final List parameterNames) { - return getBoundFunction(parameterNames, null, null); + public FullQualifiedName getFunctionFqn() { + if (functionFQN == null) { + functionFQN = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(functionImport.getFunction()). + setDefaultNamespace(container.getNamespace()).build().getFullQualifiedName(); + } + return functionFQN; } @Override - public EdmFunction getBoundFunction(final List parameterNames, - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { + public List getUnboundFunctions() { + return edm.getUnboundFunctions(getFunctionFqn()); + } - return edm.getFunction(new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(functionImport.getFunction()). - setDefaultNamespace(container.getNamespace()).build().getFullQualifiedName(), - bindingParameterTypeName, isBindingParameterCollection, parameterNames); + @Override + public EdmFunction getUnboundFunction(final List parameterNames) { + return edm.getUnboundFunction(getFunctionFqn(), parameterNames); } @Override @@ -58,8 +65,4 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm return functionImport.isIncludeInServiceDocument(); } - @Override - public FullQualifiedName getFunctionFqn() { - return new FullQualifiedName(functionImport.getFunction()); - } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmActionImportProxy.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmActionImportProxy.java index e39dd23b0..cb9ae27ad 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmActionImportProxy.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmActionImportProxy.java @@ -31,6 +31,8 @@ public class EdmActionImportProxy extends EdmOperationImportImpl implements EdmA private final FunctionImport functionImport; + private FullQualifiedName actionFQN; + public EdmActionImportProxy(final Edm edm, final EdmEntityContainer container, final String name, final FunctionImport functionImport) { @@ -38,19 +40,17 @@ public class EdmActionImportProxy extends EdmOperationImportImpl implements EdmA this.functionImport = functionImport; } - @Override - public EdmAction getUnboundAction() { - return edm.getAction(new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(functionImport.getName()). - setDefaultNamespace(container.getNamespace()).build().getFullQualifiedName(), null, null); + public FullQualifiedName getActionFQN() { + if (actionFQN == null) { + actionFQN = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(functionImport.getName()). + setDefaultNamespace(container.getNamespace()).build().getFullQualifiedName(); + } + return actionFQN; } @Override - public EdmAction getBoundAction( - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { - - return edm.getAction(new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(functionImport.getName()). - setDefaultNamespace(container.getNamespace()).build().getFullQualifiedName(), - bindingParameterTypeName, isBindingParameterCollection); + public EdmAction getUnboundAction() { + return edm.getUnboundAction(getActionFQN()); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmFunctionImportProxy.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmFunctionImportProxy.java index b1dcec83a..b64c9bbbb 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmFunctionImportProxy.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/v3/EdmFunctionImportProxy.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.olingo.client.api.edm.xml.v3.FunctionImport; import org.apache.olingo.client.core.edm.EdmOperationImportImpl; -import org.apache.olingo.commons.core.edm.EdmTypeInfo; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmEntityContainer; import org.apache.olingo.commons.api.edm.EdmFunction; @@ -33,6 +32,8 @@ public class EdmFunctionImportProxy extends EdmOperationImportImpl implements Ed private final FunctionImport functionImport; + private FullQualifiedName functionFQN; + public EdmFunctionImportProxy(final Edm edm, final EdmEntityContainer container, final String name, final FunctionImport functionImport) { @@ -41,27 +42,27 @@ public class EdmFunctionImportProxy extends EdmOperationImportImpl implements Ed } @Override - public EdmFunction getUnboundFunction(final List parameterNames) { - return getBoundFunction(parameterNames, null, null); + public FullQualifiedName getFunctionFqn() { + if (functionFQN == null) { + functionFQN = new FullQualifiedName(container.getNamespace(), getName()); + } + return functionFQN; } @Override - public EdmFunction getBoundFunction(final List parameterNames, - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { + public List getUnboundFunctions() { + return edm.getUnboundFunctions(getFunctionFqn()); + } - return edm.getFunction(new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(functionImport.getName()). - setDefaultNamespace(container.getNamespace()).build().getFullQualifiedName(), - bindingParameterTypeName, isBindingParameterCollection, parameterNames); + @Override + public EdmFunction getUnboundFunction(final List parameterNames) { + return edm.getUnboundFunction(getFunctionFqn(), parameterNames); } @Override public boolean isIncludeInServiceDocument() { - //V3 states that all function imports are included in the service document + // V3 states that all function imports are included in the service document return true; } - @Override - public FullQualifiedName getFunctionFqn() { - return new FullQualifiedName(container.getNamespace(), getName()); - } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java index 48410ccc2..1cc4e1440 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java @@ -48,13 +48,13 @@ import org.apache.olingo.commons.api.domain.v3.ODataEntitySet; import org.apache.olingo.commons.api.domain.v3.ODataProperty; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmAction; -import org.apache.olingo.commons.api.edm.EdmActionImport; import org.apache.olingo.commons.api.edm.EdmEntityContainer; import org.apache.olingo.commons.api.edm.EdmFunction; import org.apache.olingo.commons.api.edm.EdmFunctionImport; import org.apache.olingo.commons.api.edm.EdmParameter; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; +import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ODataPubFormat; import org.apache.olingo.commons.core.edm.EdmTypeInfo; import org.junit.Test; @@ -244,10 +244,10 @@ public class InvokeTestITCase extends AbstractTestITCase { assertNotNull(edm); final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer(); - final EdmActionImport actImp = container.getActionImport(operation.getTitle()); final EdmTypeInfo createdTypeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(created.getName()).build(); - final EdmAction action = actImp.getBoundAction( + final EdmAction action = edm.getBoundAction( + new FullQualifiedName(container.getNamespace(), operation.getTitle()), createdTypeInfo.getFullQualifiedName(), createdTypeInfo.isCollection()); final ODataInvokeRequest req = getClient().getInvokeRequestFactory(). @@ -294,11 +294,11 @@ public class InvokeTestITCase extends AbstractTestITCase { assertNotNull(edm); final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer(); - final EdmActionImport actImp = container.getActionImport("IncreaseSalaries"); final EdmTypeInfo employeesTypeInfo = new EdmTypeInfo.Builder().setEdm(edm). setTypeExpression("Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.Employee)").build(); - final EdmAction action = actImp.getBoundAction( + final EdmAction action = edm.getBoundAction( + new FullQualifiedName(container.getNamespace(), "IncreaseSalaries"), employeesTypeInfo.getFullQualifiedName(), employeesTypeInfo.isCollection()); final EdmParameter param = action.getParameter(action.getParameterNames().get(1)); @@ -308,7 +308,7 @@ public class InvokeTestITCase extends AbstractTestITCase { build(); final ODataInvokeRequest req = getClient().getInvokeRequestFactory().getInvokeRequest( - builder.appendOperationCallSegment(actImp.getName()).build(), action, + builder.appendOperationCallSegment(action.getName()).build(), action, Collections.singletonMap(param.getName(), paramValue)); final ODataInvokeResponse res = req.execute(); assertNotNull(res); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java index d41a370b9..ac4fffe73 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java @@ -189,16 +189,16 @@ public class MetadataTest extends AbstractTest { final EdmEntityType computer = metadata.getEntityType(new FullQualifiedName(container.getNamespace(), "Computer")); assertNotNull(computer); - final EdmFunction getComputer = metadata.getFunction( + final EdmFunction getComputer = metadata.getBoundFunction( new FullQualifiedName(container.getNamespace(), "GetComputer"), new FullQualifiedName(container.getNamespace(), computer.getName()), - Boolean.FALSE, Arrays.asList(new String[] {"computer"})); + Boolean.FALSE, Arrays.asList("computer")); assertNotNull(getComputer); assertEquals(computer, getComputer.getParameter("computer").getType()); assertEquals(computer, getComputer.getReturnType().getType()); - final EdmAction resetDataSource2 = metadata.getAction( - new FullQualifiedName(container.getNamespace(), "ResetDataSource"), null, Boolean.FALSE); + final EdmAction resetDataSource2 = metadata.getUnboundAction( + new FullQualifiedName(container.getNamespace(), "ResetDataSource")); assertNotNull(resetDataSource2); } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java index c90fae5e2..56de140d1 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java @@ -100,7 +100,7 @@ public class MetadataTest extends AbstractTest { assertEquals(folder, user.getNavigationProperty("Inbox").getType()); // 4. Action - final EdmAction move = edm.getAction( + final EdmAction move = edm.getBoundAction( new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Move"), new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder"), false); @@ -209,9 +209,8 @@ public class MetadataTest extends AbstractTest { assertNotNull(fi); assertEquals(demoService.getEntitySet("Products"), fi.getReturnedEntitySet()); - final EdmFunction function = edm.getFunction( - new FullQualifiedName(metadata.getSchema(0).getNamespace(), "ProductsByRating"), - null, Boolean.FALSE, null); + final EdmFunction function = edm.getUnboundFunction( + new FullQualifiedName(metadata.getSchema(0).getNamespace(), "ProductsByRating"), null); assertNotNull(function); assertEquals(function.getName(), fi.getUnboundFunction(null).getName()); assertEquals(function.getNamespace(), fi.getUnboundFunction(null).getNamespace()); diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java index 48230d6a7..fa417f155 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java @@ -27,92 +27,117 @@ import java.util.List; */ public interface Edm { - /** - * This method DOES NOT support lazy loading. All schemas are loaded completely! - * - * @return all schemas defined for this EDM - */ - List getSchemas(); + /** + * This method DOES NOT support lazy loading. All schemas are loaded completely! + * + * @return all schemas defined for this EDM + */ + List getSchemas(); - /** - * Get entity container by full qualified name. - *
- * See {@link EdmEntityContainer} for more information. - * - * @param name - * @return {@link EdmEntityContainer} - */ - EdmEntityContainer getEntityContainer(FullQualifiedName name); + /** + * Get entity container by full qualified name. + *
+ * See {@link EdmEntityContainer} for more information. + * + * @param name + * @return {@link EdmEntityContainer} + */ + EdmEntityContainer getEntityContainer(FullQualifiedName name); - /** - * Get enum type by full qualified name. - *
- * See {@link EdmEnumType} for more information - * - * @param name - * @return {@link EdmEnumType} - */ - EdmEnumType getEnumType(FullQualifiedName name); + /** + * Get enum type by full qualified name. + *
+ * See {@link EdmEnumType} for more information + * + * @param name + * @return {@link EdmEnumType} + */ + EdmEnumType getEnumType(FullQualifiedName name); - /** - * Get a type definition by full qualified name. - *
- * See {@link EdmTypeDefinition} for more information - * - * @param name - * @return {@link EdmTypeDefinition} - */ - EdmTypeDefinition getTypeDefinition(FullQualifiedName name); + /** + * Get a type definition by full qualified name. + *
+ * See {@link EdmTypeDefinition} for more information + * + * @param name + * @return {@link EdmTypeDefinition} + */ + EdmTypeDefinition getTypeDefinition(FullQualifiedName name); - /** - * Get entity type by full qualified name. - *
- * See {@link EdmEntityType} for more information. - * - * @param name - * @return {@link EdmEntityType} - */ - EdmEntityType getEntityType(FullQualifiedName name); + /** + * Get entity type by full qualified name. + *
+ * See {@link EdmEntityType} for more information. + * + * @param name + * @return {@link EdmEntityType} + */ + EdmEntityType getEntityType(FullQualifiedName name); - /** - * Get complex type by full qualified name.. - *
- * See {@link EdmComplexType} for more information. - * - * @param name - * @return {@link EdmComplexType} - */ - EdmComplexType getComplexType(FullQualifiedName name); + /** + * Get complex type by full qualified name.. + *
+ * See {@link EdmComplexType} for more information. + * + * @param name + * @return {@link EdmComplexType} + */ + EdmComplexType getComplexType(FullQualifiedName name); - /** - * Get Action by full qualified name and binding parameter type. - * - * @param actionName must not be null - * @param bindingParameterTypeName may be null if it is an unbound action - * @param isBindingParameterCollection may be null if it is an unbound action - * @return {@link EdmAction} - */ - EdmAction getAction(FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName, - Boolean isBindingParameterCollection); + /** + * Get unbound Action by full qualified name. + * + * @param actionName must not be null + * @return {@link EdmAction} + */ + EdmAction getUnboundAction(FullQualifiedName actionName); - /** - * Get Function by full qualified name and binding parameter type and binding parameter names. - * - * @param functionName - * @param bindingParameterTypeName may be null if it is an unbound function - * @param isBindingParameterCollection may be null if it is an unbound function - * @param parameterNames may be null if it is an unbound function - * @return {@link EdmFunction} - */ - EdmFunction getFunction(FullQualifiedName functionName, FullQualifiedName bindingParameterTypeName, - Boolean isBindingParameterCollection, List parameterNames); + /** + * Get Action by full qualified name and binding parameter type. + * + * @param actionName must not be null + * @param bindingParameterTypeName must not be null + * @param isBindingParameterCollection may be null + * @return {@link EdmAction} + */ + EdmAction getBoundAction(FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName, + Boolean isBindingParameterCollection); - /** - * Get service metadata. - *
- * See {@link EdmServiceMetadata} for more information. - * - * @return {@link EdmServiceMetadata} - */ - EdmServiceMetadata getServiceMetadata(); + /** + * Get Function by full qualified name. + * + * @param functionName must not be null + * @return {@link EdmFunction} + */ + List getUnboundFunctions(FullQualifiedName functionName); + + /** + * Get Function by full qualified name. + * + * @param functionName must not be null + * @param parameterNames may be null: in this case it is considered as empty + * @return {@link EdmFunction} + */ + EdmFunction getUnboundFunction(FullQualifiedName functionName, List parameterNames); + + /** + * Get Function by full qualified name and binding parameter type and binding parameter names. + * + * @param functionName must not be null + * @param bindingParameterTypeName must not be null + * @param isBindingParameterCollection may be null + * @param parameterNames may be null: in this case it is considered as empty + * @return {@link EdmFunction} + */ + EdmFunction getBoundFunction(FullQualifiedName functionName, FullQualifiedName bindingParameterTypeName, + Boolean isBindingParameterCollection, List parameterNames); + + /** + * Get service metadata. + *
+ * See {@link EdmServiceMetadata} for more information. + * + * @return {@link EdmServiceMetadata} + */ + EdmServiceMetadata getServiceMetadata(); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmActionImport.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmActionImport.java index 39a0db2a4..b44f3659b 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmActionImport.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmActionImport.java @@ -29,13 +29,4 @@ public interface EdmActionImport extends EdmOperationImport { * @return unbound action. */ EdmAction getUnboundAction(); - - /** - * Gets bound action. - * - * @param bindingParameterTypeName may be null if it is an unbound function - * @param isBindingParameterCollection may be null if it is an unbound function - * @return bound action with given parameter names - */ - EdmAction getBoundAction(FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection); } diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java index 815ff8db6..e9532a69b 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImport.java @@ -25,6 +25,13 @@ import java.util.List; */ public interface EdmFunctionImport extends EdmOperationImport { + /** + * Gets unbound functions. + * + * @return unbound functions + */ + List getUnboundFunctions(); + /** * Gets unbound function with given parameter names. * @@ -33,17 +40,6 @@ public interface EdmFunctionImport extends EdmOperationImport { */ EdmFunction getUnboundFunction(List parameterNames); - /** - * Gets bound function with given parameter names. - * - * @param parameterNames parameter names - * @param bindingParameterTypeName may be null if it is an unbound function - * @param isBindingParameterCollection may be null if it is an unbound function - * @return bound function with given parameter names - */ - EdmFunction getBoundFunction(List parameterNames, - FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection); - /** * @return the Full qualified name for the function as specified in the metadata */ diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java index 5047192ca..1367e0ea8 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.commons.core.edm; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,12 +38,12 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName; public abstract class AbstractEdm implements Edm { private final Map entityContainers = - new HashMap(); + new HashMap(); private final Map enumTypes = new HashMap(); private final Map typeDefinitions = - new HashMap(); + new HashMap(); private final Map entityTypes = new HashMap(); @@ -50,7 +51,10 @@ public abstract class AbstractEdm implements Edm { private final Map unboundActions = new HashMap(); - private final Map unboundFunctions = new HashMap(); + private final Map> unboundFunctionsByName = + new HashMap>(); + + private final Map unboundFunctionsByKey = new HashMap(); private final Map boundActions = new HashMap(); @@ -69,26 +73,26 @@ public abstract class AbstractEdm implements Edm { if (schemas != null) { aliasToNamespaceInfo = new HashMap(); for (EdmSchema schema : schemas) { - String namespace = schema.getNamespace(); + final String namespace = schema.getNamespace(); if (schema.getAlias() != null) { aliasToNamespaceInfo.put(schema.getAlias(), namespace); } - List localEnumTypes = schema.getEnumTypes(); + final List localEnumTypes = schema.getEnumTypes(); if (localEnumTypes != null) { for (EdmEnumType enumType : localEnumTypes) { enumTypes.put(new FullQualifiedName(namespace, enumType.getName()), enumType); } } - List localTypeDefinitions = schema.getTypeDefinitions(); + final List localTypeDefinitions = schema.getTypeDefinitions(); if (localTypeDefinitions != null) { for (EdmTypeDefinition typeDef : localTypeDefinitions) { typeDefinitions.put(new FullQualifiedName(namespace, typeDef.getName()), typeDef); } } - List localComplexTypes = schema.getComplexTypes(); + final List localComplexTypes = schema.getComplexTypes(); if (localComplexTypes != null) { for (EdmComplexType complexType : localComplexTypes) { complexTypes.put(new FullQualifiedName(namespace, complexType.getName()), complexType); @@ -102,39 +106,45 @@ public abstract class AbstractEdm implements Edm { } } - List localActions = schema.getActions(); + final List localActions = schema.getActions(); if (localActions != null) { for (EdmAction action : localActions) { + final FullQualifiedName name = new FullQualifiedName(namespace, action.getName()); if (action.isBound()) { - ActionMapKey key = new ActionMapKey(new FullQualifiedName(namespace, action.getName()), - action.getBindingParameterTypeFqn(), action.isBindingParameterTypeCollection()); + final ActionMapKey key = new ActionMapKey(name, + action.getBindingParameterTypeFqn(), action.isBindingParameterTypeCollection()); boundActions.put(key, action); } else { - unboundActions.put(new FullQualifiedName(namespace, action.getName()), action); + unboundActions.put(name, action); } } } - List localFunctions = schema.getFunctions(); + final List localFunctions = schema.getFunctions(); if (localFunctions != null) { for (EdmFunction function : localFunctions) { - FunctionMapKey key = - new FunctionMapKey(new FullQualifiedName(namespace, function.getName()), function - .getBindingParameterTypeFqn(), function.isBindingParameterTypeCollection(), function - .getParameterNames()); + final FullQualifiedName name = new FullQualifiedName(namespace, function.getName()); + final FunctionMapKey key = new FunctionMapKey(name, + function.getBindingParameterTypeFqn(), function.isBindingParameterTypeCollection(), + function.getParameterNames()); if (function.isBound()) { boundFunctions.put(key, function); } else { - unboundFunctions.put(key, function); + if (!unboundFunctionsByName.containsKey(name)) { + unboundFunctionsByName.put(name, new ArrayList()); + } + unboundFunctionsByName.get(name).add(function); + + unboundFunctionsByKey.put(key, function); } } } - - EdmEntityContainer entityContainer = schema.getEntityContainer(); - if(entityContainer != null){ + + final EdmEntityContainer entityContainer = schema.getEntityContainer(); + if (entityContainer != null) { entityContainers.put(new FullQualifiedName(namespace, entityContainer.getName()), entityContainer); - if(!entityContainers.containsKey(null)){ + if (!entityContainers.containsKey(null)) { entityContainers.put(null, entityContainer); } } @@ -213,29 +223,12 @@ public abstract class AbstractEdm implements Edm { } @Override - public EdmAction getAction(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection) { - - EdmAction action = null; - - final FullQualifiedName actionFqn = resolvePossibleAlias(actionName); - if (bindingParameterTypeName == null) { - action = unboundActions.get(actionName); - if (action == null) { - action = createUnboundAction(actionFqn); - if (action != null) { - unboundActions.put(actionName, action); - } - } - } else { - final FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName); - final ActionMapKey key = new ActionMapKey(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection); - action = boundActions.get(key); - if (action == null) { - action = createBoundAction(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection); - if (action != null) { - boundActions.put(key, action); - } + public EdmAction getUnboundAction(final FullQualifiedName actionName) { + EdmAction action = unboundActions.get(actionName); + if (action == null) { + action = createUnboundAction(resolvePossibleAlias(actionName)); + if (action != null) { + unboundActions.put(actionName, action); } } @@ -243,34 +236,83 @@ public abstract class AbstractEdm implements Edm { } @Override - public EdmFunction getFunction(final FullQualifiedName functionName, - final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection, final List parameterNames) { + public EdmAction getBoundAction(final FullQualifiedName actionName, + final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { - EdmFunction function = null; + final FullQualifiedName actionFqn = resolvePossibleAlias(actionName); + final FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName); + final ActionMapKey key = new ActionMapKey(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection); + EdmAction action = boundActions.get(key); + if (action == null) { + action = createBoundAction(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection); + if (action != null) { + boundActions.put(key, action); + } + } + return action; + } + + @Override + public List getUnboundFunctions(final FullQualifiedName functionName) { final FullQualifiedName functionFqn = resolvePossibleAlias(functionName); - if (bindingParameterTypeName == null) { - final FunctionMapKey key = new FunctionMapKey( - functionFqn, bindingParameterTypeName, isBindingParameterCollection, parameterNames); - function = unboundFunctions.get(key); - if (function == null) { - function = createUnboundFunction(functionFqn, parameterNames); - if (function != null) { - unboundFunctions.put(key, function); + + List functions = unboundFunctionsByName.get(functionFqn); + if (functions == null) { + functions = createUnboundFunctions(functionFqn); + if (functions != null) { + unboundFunctionsByName.put(functionFqn, functions); + + for (EdmFunction unbound : functions) { + final FunctionMapKey key = new FunctionMapKey( + new FullQualifiedName(unbound.getNamespace(), unbound.getName()), + unbound.getBindingParameterTypeFqn(), + unbound.isBindingParameterTypeCollection(), + unbound.getParameterNames()); + unboundFunctionsByKey.put(key, unbound); } } - } else { - final FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName); - final FunctionMapKey key = - new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames); - function = boundFunctions.get(key); - if (function == null) { - function = createBoundFunction(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, - parameterNames); - if (function != null) { - boundFunctions.put(key, function); + } + + return functions; + } + + @Override + public EdmFunction getUnboundFunction(final FullQualifiedName functionName, final List parameterNames) { + final FullQualifiedName functionFqn = resolvePossibleAlias(functionName); + + final FunctionMapKey key = new FunctionMapKey(functionFqn, null, null, parameterNames); + EdmFunction function = unboundFunctionsByKey.get(key); + if (function == null) { + function = createUnboundFunction(functionFqn, parameterNames); + if (function != null) { + unboundFunctionsByKey.put(key, function); + + if (!unboundFunctionsByName.containsKey(functionFqn)) { + unboundFunctionsByName.put(functionFqn, new ArrayList()); } + unboundFunctionsByName.get(functionFqn).add(function); + } + } + + return function; + } + + @Override + public EdmFunction getBoundFunction(final FullQualifiedName functionName, + final FullQualifiedName bindingParameterTypeName, + final Boolean isBindingParameterCollection, final List parameterNames) { + + final FullQualifiedName functionFqn = resolvePossibleAlias(functionName); + final FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName); + final FunctionMapKey key = + new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames); + EdmFunction function = boundFunctions.get(key); + if (function == null) { + function = createBoundFunction(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, + parameterNames); + if (function != null) { + boundFunctions.put(key, function); } } @@ -316,15 +358,17 @@ public abstract class AbstractEdm implements Edm { protected abstract EdmAction createUnboundAction(FullQualifiedName actionName); + protected abstract List createUnboundFunctions(FullQualifiedName functionName); + protected abstract EdmFunction createUnboundFunction(FullQualifiedName functionName, List parameterNames); protected abstract EdmAction createBoundAction(FullQualifiedName actionName, - FullQualifiedName bindingParameterTypeName, - Boolean isBindingParameterCollection); + FullQualifiedName bindingParameterTypeName, + Boolean isBindingParameterCollection); protected abstract EdmFunction createBoundFunction(FullQualifiedName functionName, - FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection, - List parameterNames); + FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection, + List parameterNames); protected abstract EdmServiceMetadata createServiceMetadata(); diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java index 474a58d1b..287f7c28c 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,7 +42,6 @@ import org.apache.olingo.commons.api.edm.EdmSchema; import org.apache.olingo.commons.api.edm.EdmServiceMetadata; import org.apache.olingo.commons.api.edm.EdmTypeDefinition; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.core.edm.AbstractEdm; import org.junit.Before; import org.junit.Test; @@ -57,14 +57,14 @@ public class EdmImplCachingTest { public void cacheSchema() { List schemas = edm.getSchemas(); assertNotNull(schemas); - + assertEquals(1, schemas.size()); - + List cachedSchemas = edm.getSchemas(); - assertTrue(schemas == cachedSchemas ); + assertTrue(schemas == cachedSchemas); assertEquals(schemas, schemas); } - + @Test public void cacheEntityContainer() { EdmEntityContainer entityContainer = edm.getEntityContainer(null); @@ -158,32 +158,32 @@ public class EdmImplCachingTest { @Test public void cacheUnboundAction() { - EdmAction action = edm.getAction(NAME1, null, null); + EdmAction action = edm.getUnboundAction(NAME1); assertNotNull(action); - EdmAction cachedAction = edm.getAction(NAME1, null, null); + EdmAction cachedAction = edm.getUnboundAction(NAME1); assertNotNull(cachedAction); assertTrue(action == cachedAction); assertEquals(action, cachedAction); - EdmAction action2 = edm.getAction(NAME2, null, false); + EdmAction action2 = edm.getUnboundAction(NAME2); assertNotNull(action2); assertNotSame(action, action2); } @Test public void cacheBoundAction() { - EdmAction action = edm.getAction(NAME1, NAME2, true); + EdmAction action = edm.getBoundAction(NAME1, NAME2, true); assertNotNull(action); - EdmAction cachedAction = edm.getAction(NAME1, NAME2, true); + EdmAction cachedAction = edm.getBoundAction(NAME1, NAME2, true); assertNotNull(cachedAction); assertTrue(action == cachedAction); assertEquals(action, cachedAction); - EdmAction action2 = edm.getAction(NAME2, NAME2, true); + EdmAction action2 = edm.getBoundAction(NAME2, NAME2, true); assertNotNull(action2); assertNotSame(action, action2); @@ -191,16 +191,16 @@ public class EdmImplCachingTest { @Test public void cacheUnboundFunctionNoParameters() { - EdmFunction function = edm.getFunction(NAME1, null, null, null); + EdmFunction function = edm.getUnboundFunction(NAME1, null); assertNotNull(function); - EdmFunction cachedfunction = edm.getFunction(NAME1, null, null, null); + EdmFunction cachedfunction = edm.getUnboundFunction(NAME1, null); assertNotNull(cachedfunction); assertTrue(function == cachedfunction); assertEquals(function, cachedfunction); - EdmFunction function2 = edm.getFunction(NAME2, null, false, null); + EdmFunction function2 = edm.getBoundFunction(NAME2, null, false, null); assertNotNull(function2); assertNotSame(function, function2); @@ -208,16 +208,16 @@ public class EdmImplCachingTest { @Test public void cacheBoundFunction() { - EdmFunction function = edm.getFunction(NAME1, NAME2, true, new ArrayList()); + EdmFunction function = edm.getBoundFunction(NAME1, NAME2, true, new ArrayList()); assertNotNull(function); - EdmFunction cachedfunction = edm.getFunction(NAME1, NAME2, true, new ArrayList()); + EdmFunction cachedfunction = edm.getBoundFunction(NAME1, NAME2, true, new ArrayList()); assertNotNull(cachedfunction); assertTrue(function == cachedfunction); assertEquals(function, cachedfunction); - EdmFunction function2 = edm.getFunction(NAME2, NAME2, true, new ArrayList()); + EdmFunction function2 = edm.getBoundFunction(NAME2, NAME2, true, new ArrayList()); assertNotNull(function2); assertNotSame(function, function2); @@ -228,19 +228,19 @@ public class EdmImplCachingTest { ArrayList parameters1 = new ArrayList(); parameters1.add("A"); parameters1.add("B"); - EdmFunction function = edm.getFunction(NAME1, NAME2, true, parameters1); + EdmFunction function = edm.getBoundFunction(NAME1, NAME2, true, parameters1); assertNotNull(function); ArrayList parameters2 = new ArrayList(); parameters2.add("B"); parameters2.add("A"); - EdmFunction cachedfunction = edm.getFunction(NAME1, NAME2, true, parameters2); + EdmFunction cachedfunction = edm.getBoundFunction(NAME1, NAME2, true, parameters2); assertNotNull(cachedfunction); assertTrue(function == cachedfunction); assertEquals(function, cachedfunction); - EdmFunction function2 = edm.getFunction(NAME2, NAME2, true, new ArrayList()); + EdmFunction function2 = edm.getBoundFunction(NAME2, NAME2, true, new ArrayList()); assertNotNull(function2); assertNotSame(function, function2); @@ -383,6 +383,22 @@ public class EdmImplCachingTest { return null; } + @Override + protected List createUnboundFunctions(final FullQualifiedName fqn) { + if (NAME1.equals(fqn)) { + EdmFunction function = mock(EdmFunction.class); + when(function.getNamespace()).thenReturn(fqn.getNamespace()); + when(function.getName()).thenReturn(fqn.getName()); + return Collections.singletonList(function); + } else if (NAME2.equals(fqn)) { + EdmFunction function = mock(EdmFunction.class); + when(function.getNamespace()).thenReturn(fqn.getNamespace()); + when(function.getName()).thenReturn(fqn.getName()); + return Collections.singletonList(function); + } + return Collections.emptyList(); + } + @Override protected EdmFunction createUnboundFunction(final FullQualifiedName fqn, final List parameterNames) { if (NAME1.equals(fqn)) { diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java index 52d47e210..bc83cafec 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCallCreateTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,7 +42,6 @@ import org.apache.olingo.commons.api.edm.EdmSchema; import org.apache.olingo.commons.api.edm.EdmServiceMetadata; import org.apache.olingo.commons.api.edm.EdmTypeDefinition; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.core.edm.AbstractEdm; import org.junit.Before; import org.junit.Test; @@ -58,7 +58,7 @@ public class EdmImplCallCreateTest { List schemas = edm.getSchemas(); assertNotNull(schemas); } - + @Test public void callCreateEntityContainer() { EdmEntityContainer entityContainer = edm.getEntityContainer(FQN); @@ -116,36 +116,36 @@ public class EdmImplCallCreateTest { @Test public void callCreateAction() { - EdmAction action = edm.getAction(FQN, null, null); + EdmAction action = edm.getUnboundAction(FQN); assertNotNull(action); assertEquals(FQN.getNamespace(), action.getNamespace()); assertEquals(FQN.getName(), action.getName()); - EdmAction action2 = edm.getAction(FQN, FQN, true); + EdmAction action2 = edm.getBoundAction(FQN, FQN, true); assertNotNull(action2); assertEquals(FQN.getNamespace(), action2.getNamespace()); assertEquals(FQN.getName(), action2.getName()); assertNotSame(action, action2); - assertNull(edm.getAction(WRONG_FQN, null, null)); + assertNull(edm.getUnboundAction(WRONG_FQN)); } @Test public void callCreateFunction() { - EdmFunction function = edm.getFunction(FQN, null, null, null); + EdmFunction function = edm.getUnboundFunction(FQN, null); assertNotNull(function); assertEquals(FQN.getNamespace(), function.getNamespace()); assertEquals(FQN.getName(), function.getName()); - EdmFunction function2 = edm.getFunction(FQN, FQN, true, new ArrayList()); + EdmFunction function2 = edm.getBoundFunction(FQN, FQN, true, new ArrayList()); assertNotNull(function2); assertEquals(FQN.getNamespace(), function2.getNamespace()); assertEquals(FQN.getName(), function2.getName()); assertNotSame(function, function2); - assertNull(edm.getFunction(WRONG_FQN, null, null, null)); + assertNull(edm.getUnboundFunction(WRONG_FQN, null)); } @Test @@ -261,6 +261,17 @@ public class EdmImplCallCreateTest { return null; } + @Override + protected List createUnboundFunctions(final FullQualifiedName fqn) { + if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) { + EdmFunction function = mock(EdmFunction.class); + when(function.getNamespace()).thenReturn(fqn.getNamespace()); + when(function.getName()).thenReturn(fqn.getName()); + return Collections.singletonList(function); + } + return Collections.emptyList(); + } + @Override protected EdmFunction createUnboundFunction(final FullQualifiedName fqn, final List parameterNames) { if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) { diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImpl.java index 3e2a9f528..8796671d7 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImpl.java @@ -22,7 +22,6 @@ import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmAction; import org.apache.olingo.commons.api.edm.EdmActionImport; import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.server.api.edm.provider.ActionImport; public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmActionImport { @@ -37,14 +36,7 @@ public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmAc @Override public EdmAction getUnboundAction() { - return getBoundAction(null, null); - } - - @Override - public EdmAction getBoundAction( - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { - - return edm.getAction(actionImport.getAction(), bindingParameterTypeName, isBindingParameterCollection); + return edm.getUnboundAction(actionImport.getAction()); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImpl.java index 2c8a0975b..23111eb61 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImpl.java @@ -38,17 +38,18 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm } @Override - public EdmFunction getUnboundFunction(final List parameterNames) { - return getBoundFunction(parameterNames, null, null); + public FullQualifiedName getFunctionFqn() { + return functionImport.getFunction(); } @Override - public EdmFunction getBoundFunction(final List parameterNames, - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { - - return edm.getFunction(functionImport.getFunction(), - bindingParameterTypeName, isBindingParameterCollection, parameterNames); + public EdmFunction getUnboundFunction(final List parameterNames) { + return edm.getUnboundFunction(getFunctionFqn(), parameterNames); + } + @Override + public List getUnboundFunctions() { + return edm.getUnboundFunctions(getFunctionFqn()); } @Override @@ -56,8 +57,4 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm return functionImport.isIncludeInServiceDocument(); } - @Override - public FullQualifiedName getFunctionFqn() { - return functionImport.getFunction(); - } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java index d35d55dac..b7191a67e 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java @@ -129,7 +129,7 @@ public class EdmProviderImpl extends AbstractEdm { @Override public EdmAction createBoundAction(final FullQualifiedName actionName, - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { + final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) { try { List actions = actionsMap.get(actionName); @@ -147,7 +147,7 @@ public class EdmProviderImpl extends AbstractEdm { final List parameters = action.getParameters(); final Parameter parameter = parameters.get(0); if (bindingParameterTypeName.equals(parameter.getType()) - && isBindingParameterCollection.booleanValue() == parameter.isCollection()) { + && isBindingParameterCollection.booleanValue() == parameter.isCollection()) { return EdmActionImpl.getInstance(this, actionName, action); } @@ -162,8 +162,8 @@ public class EdmProviderImpl extends AbstractEdm { @Override public EdmFunction createBoundFunction(final FullQualifiedName functionName, - final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, - final List parameterNames) { + final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection, + final List parameterNames) { try { List functions = functionsMap.get(functionName); @@ -175,8 +175,8 @@ public class EdmProviderImpl extends AbstractEdm { functionsMap.put(functionName, functions); } } - final List parameterNamesCopy = - parameterNames == null ? Collections. emptyList() : parameterNames; + final List parameterNamesCopy + = parameterNames == null ? Collections.emptyList() : parameterNames; for (Function function : functions) { if (function.isBound()) { List providerParameters = function.getParameters(); @@ -185,7 +185,7 @@ public class EdmProviderImpl extends AbstractEdm { } final Parameter bindingParameter = providerParameters.get(0); if (bindingParameterTypeName.equals(bindingParameter.getType()) - && isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) { + && isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) { if (parameterNamesCopy.size() == providerParameters.size() - 1) { final List providerParameterNames = new ArrayList(); @@ -251,19 +251,44 @@ public class EdmProviderImpl extends AbstractEdm { } @Override - protected EdmFunction createUnboundFunction(final FullQualifiedName functionName, final List parameterNames) { + protected List createUnboundFunctions(final FullQualifiedName functionName) { + List result = new ArrayList(); + try { List functions = functionsMap.get(functionName); if (functions == null) { functions = provider.getFunctions(functionName); if (functions != null) { functionsMap.put(functionName, functions); - } else { - return null; + + for (Function function : functions) { + if (!function.isBound()) { + result.add(EdmFunctionImpl.getInstance(this, functionName, function)); + } + } } } - final List parameterNamesCopy = - parameterNames == null ? Collections. emptyList() : parameterNames; + } catch (ODataException e) { + throw new EdmException(e); + } + + return result; + } + + @Override + protected EdmFunction createUnboundFunction(final FullQualifiedName functionName, final List parameterNames) { + try { + List functions = functionsMap.get(functionName); + if (functions == null) { + functions = provider.getFunctions(functionName); + if (functions == null) { + return null; + } else { + functionsMap.put(functionName, functions); + } + } + final List parameterNamesCopy + = parameterNames == null ? Collections.emptyList() : parameterNames; for (Function function : functions) { if (!function.isBound()) { List providerParameters = function.getParameters(); @@ -271,7 +296,7 @@ public class EdmProviderImpl extends AbstractEdm { providerParameters = Collections.emptyList(); } if (parameterNamesCopy.size() == providerParameters.size()) { - List functionParameterNames = new ArrayList(); + final List functionParameterNames = new ArrayList(); for (Parameter parameter : providerParameters) { functionParameterNames.add(parameter.getName()); } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java index f237fea7a..0039952a1 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java @@ -558,7 +558,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { FullQualifiedName fullBindingTypeName = new FullQualifiedName(source.type.getNamespace(), source.type.getName()); // check for action - EdmAction action = edm.getAction(fullFilterName, fullBindingTypeName, source.isCollection); + EdmAction action = edm.getBoundAction(fullFilterName, fullBindingTypeName, source.isCollection); if (action != null) { UriResourceActionImpl pathInfoAction = new UriResourceActionImpl(); pathInfoAction.setAction(action); @@ -583,7 +583,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { names.add(item.getName()); } - EdmFunction function = edm.getFunction(fullFilterName, fullBindingTypeName, source.isCollection, names); + EdmFunction function = edm.getBoundFunction(fullFilterName, fullBindingTypeName, source.isCollection, names); if (function != null) { UriResourceFunctionImpl pathInfoFunction = new UriResourceFunctionImpl() @@ -597,7 +597,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { } // check for unbound function in the $filter case ( where the previous resource segment is a $it) - function = edm.getFunction(fullFilterName, null, null, names); + function = edm.getUnboundFunction(fullFilterName, names); if (function != null) { UriResourceFunctionImpl pathInfoFunction = new UriResourceFunctionImpl() @@ -1972,7 +1972,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { FullQualifiedName finalTypeName = new FullQualifiedName(prevType.getNamespace(), prevType.getName()); // check for action - EdmAction action = edm.getAction(fullName, finalTypeName, null); + EdmAction action = edm.getBoundAction(fullName, finalTypeName, null); if (action != null) { UriResourceActionImpl uriAction = new UriResourceActionImpl(); @@ -1983,7 +1983,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor { } // check for function - EdmFunction function = edm.getFunction(fullName, finalTypeName, null, null); + EdmFunction function = edm.getBoundFunction(fullName, finalTypeName, null, null); if (function != null) { UriResourceFunctionImpl uriFunction = new UriResourceFunctionImpl(); diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java index c9393aa94..08bdc3e6a 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java @@ -57,7 +57,7 @@ public class EdmActionImportImplTest { container = mock(EdmEntityContainer.class); when(edm.getEntityContainer(entityContainerFqn)).thenReturn(container); action = mock(EdmAction.class); - when(edm.getAction(actionFqn, null, null)).thenReturn(action); + when(edm.getUnboundAction(actionFqn)).thenReturn(action); entitySet = mock(EdmEntitySet.class); when(container.getEntitySet("entitySetName")).thenReturn(entitySet); diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplOverloadingTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplOverloadingTest.java index 1ac09ced4..1a4795f24 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplOverloadingTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplOverloadingTest.java @@ -104,46 +104,46 @@ public class EdmProviderImplOverloadingTest { @Test public void simpleActionGet() { - EdmAction action = edm.getAction(operationName1, null, null); + EdmAction action = edm.getUnboundAction(operationName1); assertNotNull(action); assertEquals(operationName1.getNamespace(), action.getNamespace()); assertEquals(operationName1.getName(), action.getName()); - assertNull(edm.getAction(wrongOperationName, null, null)); + assertNull(edm.getUnboundAction(wrongOperationName)); } @Test public void boundActionOverloading() { - EdmAction action = edm.getAction(operationName1, operationType1, false); + EdmAction action = edm.getBoundAction(operationName1, operationType1, false); assertNotNull(action); assertEquals(operationName1.getNamespace(), action.getNamespace()); assertEquals(operationName1.getName(), action.getName()); - assertTrue(action == edm.getAction(operationName1, operationType1, false)); + assertTrue(action == edm.getBoundAction(operationName1, operationType1, false)); - EdmAction action2 = edm.getAction(operationName1, operationType1, true); + EdmAction action2 = edm.getBoundAction(operationName1, operationType1, true); assertNotNull(action2); assertEquals(operationName1.getNamespace(), action2.getNamespace()); assertEquals(operationName1.getName(), action2.getName()); - assertTrue(action2 == edm.getAction(operationName1, operationType1, true)); + assertTrue(action2 == edm.getBoundAction(operationName1, operationType1, true)); assertNotSame(action, action2); } @Test public void simpleFunctionGet() { - EdmFunction function = edm.getFunction(operationName1, null, null, null); + EdmFunction function = edm.getUnboundFunction(operationName1, null); assertNotNull(function); assertEquals(operationName1.getNamespace(), function.getNamespace()); assertEquals(operationName1.getName(), function.getName()); - EdmFunction function2 = edm.getFunction(operationName1, null, null, new ArrayList()); + EdmFunction function2 = edm.getUnboundFunction(operationName1, new ArrayList()); assertNotNull(function2); assertEquals(operationName1.getNamespace(), function2.getNamespace()); assertEquals(operationName1.getName(), function2.getName()); assertEquals(function, function2); - assertNull(edm.getFunction(wrongOperationName, null, null, new ArrayList())); + assertNull(edm.getUnboundFunction(wrongOperationName, new ArrayList())); } @Test @@ -152,28 +152,28 @@ public class EdmProviderImplOverloadingTest { parameter1Names.add("a"); List parameter2Names = new ArrayList(); parameter2Names.add("b"); - EdmFunction function = edm.getFunction(operationName1, null, null, new ArrayList()); + EdmFunction function = edm.getUnboundFunction(operationName1, new ArrayList()); assertNotNull(function); assertFalse(function.isBound()); - EdmFunction function1 = edm.getFunction(operationName1, null, null, parameter1Names); + EdmFunction function1 = edm.getUnboundFunction(operationName1, parameter1Names); assertNotNull(function1); assertFalse(function1.isBound()); assertFalse(function == function1); assertNotSame(function, function1); - EdmFunction function2 = edm.getFunction(operationName1, null, null, parameter2Names); + EdmFunction function2 = edm.getUnboundFunction(operationName1, parameter2Names); assertNotNull(function2); assertFalse(function2.isBound()); assertFalse(function1 == function2); assertNotSame(function1, function2); - EdmFunction function3 = edm.getFunction(operationName1, operationType1, false, parameter2Names); + EdmFunction function3 = edm.getBoundFunction(operationName1, operationType1, false, parameter2Names); assertNotNull(function3); assertTrue(function3.isBound()); - EdmFunction function4 = edm.getFunction(operationName1, operationType2, false, parameter2Names); + EdmFunction function4 = edm.getBoundFunction(operationName1, operationType2, false, parameter2Names); assertNotNull(function4); assertTrue(function4.isBound()); @@ -192,7 +192,7 @@ public class EdmProviderImplOverloadingTest { @Test(expected = EdmException.class) public void noParametersAtBoundFunctionReslutsInException() { - edm.getFunction(badOperationName, operationType1, true, null); + edm.getBoundFunction(badOperationName, operationType1, true, null); } } diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplTest.java index 66a3f9909..2156077c4 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplTest.java @@ -89,10 +89,10 @@ public class EdmProviderImplTest { when(localProvider.getActions(FQN)).thenReturn(null); when(localProvider.getFunctions(FQN)).thenReturn(null); Edm localEdm = new EdmProviderImpl(localProvider); - localEdm.getAction(FQN, null, null); - localEdm.getFunction(FQN, null, null, null); - localEdm.getAction(FQN, FQN, true); - localEdm.getFunction(FQN, FQN, true, null); + localEdm.getUnboundAction(FQN); + localEdm.getUnboundFunction(FQN, null); + localEdm.getBoundAction(FQN, FQN, true); + localEdm.getBoundFunction(FQN, FQN, true, null); localEdm.getComplexType(FQN); localEdm.getEntityContainer(FQN); localEdm.getEntityType(FQN); @@ -123,24 +123,24 @@ public class EdmProviderImplTest { // seperate because of signature try { - localEdm.getAction(fqn, null, null); + localEdm.getUnboundAction(fqn); } catch (EdmException e) { assertEquals("org.apache.olingo.commons.api.ODataException: msg", e.getMessage()); } try { - localEdm.getFunction(fqn, null, null, null); + localEdm.getUnboundFunction(fqn, null); } catch (EdmException e) { assertEquals("org.apache.olingo.commons.api.ODataException: msg", e.getMessage()); } try { - localEdm.getAction(fqn, fqn, true); + localEdm.getBoundAction(fqn, fqn, true); } catch (EdmException e) { assertEquals("org.apache.olingo.commons.api.ODataException: msg", e.getMessage()); } try { - localEdm.getFunction(fqn, fqn, true, null); + localEdm.getBoundFunction(fqn, fqn, true, null); } catch (EdmException e) { assertEquals("org.apache.olingo.commons.api.ODataException: msg", e.getMessage()); } diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java index ec7e1ee68..c04211d24 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java @@ -149,7 +149,7 @@ public class EdmSchemaImplTest { assertEquals(2, actions.size()); for (EdmAction action : actions) { - assertTrue(action == edm.getAction(new FullQualifiedName("namespace", action.getName()), null, null)); + assertTrue(action == edm.getUnboundAction(new FullQualifiedName("namespace", action.getName()))); } } @@ -161,7 +161,7 @@ public class EdmSchemaImplTest { for (EdmFunction function : functions) { FullQualifiedName functionName = new FullQualifiedName("namespace", function.getName()); - assertTrue(function == edm.getFunction(functionName, null, null, null)); + assertTrue(function == edm.getUnboundFunction(functionName, null)); } } diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java index 51a963854..680e91959 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java @@ -76,7 +76,7 @@ public class UriResourceImplTest { assertEquals("", impl.toString()); // action - EdmAction action = edm.getAction(ActionProvider.nameUARTETParam, null, null); + EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTETParam); impl.setAction(action); assertEquals(action, impl.getAction()); assertEquals(ActionProvider.nameUARTETParam.getName(), impl.toString()); diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java index 91f3ad99e..2902bdc0f 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java @@ -135,7 +135,7 @@ public class ExpressionTest { EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav); // UriResourceImplTyped - EdmAction action = edm.getAction(ActionProvider.nameUARTPrimParam, null, null); + EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTPrimParam); UriInfoResource uriInfo = new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( new UriResourceActionImpl().setAction(action)).asUriInfoResource(); expression.setResourcePath(uriInfo); @@ -149,21 +149,21 @@ public class ExpressionTest { assertEquals(false, expression.isCollection()); // UriResourceImplTyped check collection = true case - action = edm.getAction(ActionProvider.nameUARTPrimCollParam, null, null); + action = edm.getUnboundAction(ActionProvider.nameUARTPrimCollParam); expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( new UriResourceActionImpl().setAction(action)) .asUriInfoResource()); assertEquals(true, expression.isCollection()); // UriResourceImplTyped with filter - action = edm.getAction(ActionProvider.nameUARTPrimParam, null, null); + action = edm.getUnboundAction(ActionProvider.nameUARTPrimParam); expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( new UriResourceActionImpl().setAction(action).setTypeFilter(entityType)) .asUriInfoResource()); assertEquals(entityType, expression.getType()); // UriResourceImplKeyPred - EdmFunction function = edm.getFunction(FunctionProvider.nameUFCRTETKeyNav, null, null, null); + EdmFunction function = edm.getUnboundFunction(FunctionProvider.nameUFCRTETKeyNav, null); expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( new UriResourceFunctionImpl().setFunction(function)) .asUriInfoResource()); @@ -171,8 +171,7 @@ public class ExpressionTest { // UriResourceImplKeyPred typeFilter on entry EdmEntityType entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - function = edm.getFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, null, null, - Arrays.asList(("ParameterInt16"))); + function = edm.getUnboundFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, Arrays.asList("ParameterInt16")); expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( new UriResourceFunctionImpl().setFunction(function).setEntryTypeFilter(entityBaseType)) .asUriInfoResource()); @@ -180,8 +179,7 @@ public class ExpressionTest { // UriResourceImplKeyPred typeFilter on entry entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - function = edm.getFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, null, null, - Arrays.asList(("ParameterInt16"))); + function = edm.getUnboundFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, Arrays.asList("ParameterInt16")); expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( new UriResourceFunctionImpl().setFunction(function).setCollectionTypeFilter(entityBaseType)) .asUriInfoResource()); @@ -189,8 +187,7 @@ public class ExpressionTest { // no typed entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - function = edm.getFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, null, null, - Arrays.asList(("ParameterInt16"))); + function = edm.getUnboundFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, Arrays.asList("ParameterInt16")); expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.all)); assertEquals(null, expression.getType());