[OLINGO-168] Enhance Edm for Service Document serialization
Also implemented a first version of the service document serializer. This has still to be moved into the commons core.
This commit is contained in:
parent
897db8ef11
commit
44aadbd686
|
@ -21,4 +21,7 @@ package org.apache.olingo.client.api.edm.xml.v4;
|
|||
public interface Parameter extends org.apache.olingo.client.api.edm.xml.CommonParameter {
|
||||
|
||||
String getSrid();
|
||||
|
||||
//TODO: Has this to be moved into CommonParameter?
|
||||
boolean isCollection();
|
||||
}
|
||||
|
|
|
@ -33,5 +33,4 @@ public class EdmActionImpl extends EdmOperationImpl implements EdmAction {
|
|||
private EdmActionImpl(final Edm edm, final FullQualifiedName name, final Action action) {
|
||||
super(edm, name, action, EdmTypeKind.ACTION);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.apache.olingo.client.core.edm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -52,6 +53,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
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;
|
||||
|
@ -368,4 +370,13 @@ public class EdmClientImpl extends AbstractEdmImpl {
|
|||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmSchema> createSchemas() {
|
||||
List<EdmSchema> schemas = new ArrayList<EdmSchema>();
|
||||
for(Schema schema : xmlMetadata.getSchemas()){
|
||||
schemas.add(new EdmSchemaImpl(this, xmlMetadata, schema));
|
||||
}
|
||||
return schemas;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,25 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.client.core.edm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.client.api.UnsupportedInV3Exception;
|
||||
import org.apache.olingo.client.api.edm.xml.CommonFunctionImport;
|
||||
import org.apache.olingo.client.api.edm.xml.EntityContainer;
|
||||
|
@ -46,7 +48,7 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
|
|||
private final XMLMetadata xmlMetadata;
|
||||
|
||||
public EdmEntityContainerImpl(final Edm edm, final FullQualifiedName entityContainerName,
|
||||
final EntityContainer xmlEntityContainer, final XMLMetadata xmlMetadata) {
|
||||
final EntityContainer xmlEntityContainer, final XMLMetadata xmlMetadata) {
|
||||
|
||||
super(edm, entityContainerName);
|
||||
|
||||
|
@ -61,13 +63,13 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
|
|||
}
|
||||
|
||||
final Singleton singleton = ((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).
|
||||
getSingleton(singletonName);
|
||||
getSingleton(singletonName);
|
||||
if (singleton == null) {
|
||||
throw new EdmException("Singleton named '" + singletonName + "' not found in " + entityContainerName);
|
||||
}
|
||||
return new EdmSingletonImpl(edm, this, singletonName,
|
||||
new EdmTypeInfo(singleton.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
|
||||
singleton);
|
||||
new EdmTypeInfo(singleton.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
|
||||
singleton);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,21 +81,20 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
|
|||
|
||||
if (entitySet instanceof org.apache.olingo.client.api.edm.xml.v4.EntitySet) {
|
||||
return new EdmEntitySetImpl(edm, this, entitySetName,
|
||||
new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
|
||||
(org.apache.olingo.client.api.edm.xml.v4.EntitySet) entitySet);
|
||||
new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
|
||||
(org.apache.olingo.client.api.edm.xml.v4.EntitySet) entitySet);
|
||||
} else {
|
||||
return new EdmEntitySetProxy(edm, this, entitySetName,
|
||||
new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
|
||||
xmlMetadata);
|
||||
new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
|
||||
xmlMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EdmActionImport createActionImport(final String actionImportName) {
|
||||
if (xmlEntityContainer instanceof org.apache.olingo.client.api.edm.xml.v4.EntityContainer) {
|
||||
final ActionImport actionImport
|
||||
= ((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).
|
||||
getActionImport(actionImportName);
|
||||
final ActionImport actionImport = ((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).
|
||||
getActionImport(actionImportName);
|
||||
if (actionImport == null) {
|
||||
throw new EdmException("ActionImport named '" + actionImportName + "' not found in " + entityContainerName);
|
||||
}
|
||||
|
@ -116,10 +117,89 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
|
|||
|
||||
if (functionImport instanceof org.apache.olingo.client.api.edm.xml.v4.FunctionImport) {
|
||||
return new EdmFunctionImportImpl(edm, this, functionImportName,
|
||||
(org.apache.olingo.client.api.edm.xml.v4.FunctionImport) functionImport);
|
||||
(org.apache.olingo.client.api.edm.xml.v4.FunctionImport) functionImport);
|
||||
} else {
|
||||
return new EdmFunctionImportProxy(edm, this, functionImportName,
|
||||
(org.apache.olingo.client.api.edm.xml.v3.FunctionImport) functionImport);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllEntitySets() {
|
||||
List<? extends EntitySet> localEntitySets = xmlEntityContainer.getEntitySets();
|
||||
if (localEntitySets != null) {
|
||||
for (EntitySet entitySet : localEntitySets) {
|
||||
EdmEntitySet edmSet;
|
||||
if (entitySet instanceof org.apache.olingo.client.api.edm.xml.v4.EntitySet) {
|
||||
edmSet = new EdmEntitySetImpl(edm, this, entitySet.getName(),
|
||||
new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
|
||||
(org.apache.olingo.client.api.edm.xml.v4.EntitySet) entitySet);
|
||||
} else {
|
||||
edmSet = new EdmEntitySetProxy(edm, this, entitySet.getName(),
|
||||
new EdmTypeInfo(entitySet.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
|
||||
xmlMetadata);
|
||||
}
|
||||
entitySets.put(edmSet.getName(), edmSet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllFunctionImports() {
|
||||
List<? extends CommonFunctionImport> localFunctionImports = xmlEntityContainer.getFunctionImports();
|
||||
if (localFunctionImports != null) {
|
||||
for (CommonFunctionImport functionImport : localFunctionImports) {
|
||||
EdmFunctionImport edmFunctionImport;
|
||||
if (functionImport instanceof org.apache.olingo.client.api.edm.xml.v4.FunctionImport) {
|
||||
edmFunctionImport = new EdmFunctionImportImpl(edm, this, functionImport.getName(),
|
||||
(org.apache.olingo.client.api.edm.xml.v4.FunctionImport) functionImport);
|
||||
} else {
|
||||
edmFunctionImport = new EdmFunctionImportProxy(edm, this, functionImport.getName(),
|
||||
(org.apache.olingo.client.api.edm.xml.v3.FunctionImport) functionImport);
|
||||
}
|
||||
functionImports.put(edmFunctionImport.getName(), edmFunctionImport);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllSingletons() {
|
||||
if (!(xmlEntityContainer instanceof org.apache.olingo.client.api.edm.xml.v4.EntityContainer)) {
|
||||
throw new UnsupportedInV3Exception();
|
||||
}
|
||||
|
||||
List<Singleton> localSingletons =
|
||||
((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).getSingletons();
|
||||
if (localSingletons != null) {
|
||||
for (Singleton singleton : localSingletons) {
|
||||
singletons.put(singleton.getName(), new EdmSingletonImpl(edm, this, singleton.getName(),
|
||||
new EdmTypeInfo(singleton.getEntityType(), entityContainerName.getNamespace()).getFullQualifiedName(),
|
||||
singleton));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllActionImports() {
|
||||
if (xmlEntityContainer instanceof org.apache.olingo.client.api.edm.xml.v4.EntityContainer) {
|
||||
List<ActionImport> localActionImports =
|
||||
((org.apache.olingo.client.api.edm.xml.v4.EntityContainer) xmlEntityContainer).getActionImports();
|
||||
if (actionImports != null) {
|
||||
for (ActionImport actionImport : localActionImports) {
|
||||
actionImports.put(actionImport.getName(), new EdmActionImportImpl(edm, this, actionImport.getName(),
|
||||
actionImport));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<FunctionImport> localFunctionImports = (List<FunctionImport>) xmlEntityContainer.getFunctionImports();
|
||||
if (localFunctionImports != null) {
|
||||
for (FunctionImport functionImport : localFunctionImports) {
|
||||
actionImports.put(functionImport.getName(), new EdmActionImportProxy(edm, this, functionImport.getName(),
|
||||
functionImport));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,10 +26,17 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
|||
|
||||
public class EdmEntitySetImpl extends EdmBindingTargetImpl implements EdmEntitySet {
|
||||
|
||||
private EntitySet entitySet;
|
||||
|
||||
public EdmEntitySetImpl(final Edm edm, final EdmEntityContainer container, final String name,
|
||||
final FullQualifiedName type, final EntitySet entitySet) {
|
||||
|
||||
super(edm, container, name, type, entitySet);
|
||||
this.entitySet = entitySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludeInServiceDocument() {
|
||||
return entitySet.isIncludeInServiceDocument();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
@ -26,13 +26,14 @@ import org.apache.olingo.commons.api.edm.Edm;
|
|||
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.FullQualifiedName;
|
||||
|
||||
public class EdmFunctionImportImpl extends EdmOperationImportImpl implements EdmFunctionImport {
|
||||
|
||||
private final FunctionImport functionImport;
|
||||
|
||||
public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
|
||||
final FunctionImport functionImport) {
|
||||
final FunctionImport functionImport) {
|
||||
|
||||
super(edm, container, name, functionImport.getEntitySet());
|
||||
this.functionImport = functionImport;
|
||||
|
@ -41,8 +42,17 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm
|
|||
@Override
|
||||
public EdmFunction getFunction(final List<String> parameterNames) {
|
||||
return edm.getFunction(
|
||||
new EdmTypeInfo(functionImport.getFunction(), container.getNamespace()).getFullQualifiedName(),
|
||||
null, null, parameterNames);
|
||||
new EdmTypeInfo(functionImport.getFunction(), container.getNamespace()).getFullQualifiedName(),
|
||||
null, null, parameterNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludeInServiceDocument() {
|
||||
return functionImport.isIncludeInServiceDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FullQualifiedName getFunctionFqn() {
|
||||
return new FullQualifiedName(functionImport.getFunction());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.client.api.edm.xml.CommonParameter;
|
||||
import org.apache.olingo.client.api.edm.xml.v4.Parameter;
|
||||
import org.apache.olingo.client.api.edm.xml.v4.Action;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmParameter;
|
||||
|
@ -58,4 +59,22 @@ public abstract class EdmOperationImpl extends AbstractEdmOperation {
|
|||
super(edm, name, kind);
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FullQualifiedName getBindingParameterTypeFqn() {
|
||||
if (isBound()) {
|
||||
Parameter bindingParameter = operation.getParameters().get(0);
|
||||
return new FullQualifiedName(getNamespace(), bindingParameter.getName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isBindingParameterTypeCollection() {
|
||||
if (isBound()) {
|
||||
Parameter bindingParameter = operation.getParameters().get(0);
|
||||
return bindingParameter.isCollection();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.client.core.edm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.client.api.edm.xml.ComplexType;
|
||||
import org.apache.olingo.client.api.edm.xml.EntityContainer;
|
||||
import org.apache.olingo.client.api.edm.xml.EntityType;
|
||||
import org.apache.olingo.client.api.edm.xml.EnumType;
|
||||
import org.apache.olingo.client.api.edm.xml.Schema;
|
||||
import org.apache.olingo.client.api.edm.xml.XMLMetadata;
|
||||
import org.apache.olingo.client.api.edm.xml.v3.FunctionImport;
|
||||
import org.apache.olingo.client.api.edm.xml.v4.Action;
|
||||
import org.apache.olingo.client.api.edm.xml.v4.Function;
|
||||
import org.apache.olingo.client.api.edm.xml.v4.TypeDefinition;
|
||||
import org.apache.olingo.client.core.edm.v3.EdmFunctionProxy;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.core.edm.AbstractEdmSchemaImpl;
|
||||
|
||||
public class EdmSchemaImpl extends AbstractEdmSchemaImpl {
|
||||
|
||||
private final Edm edm;
|
||||
private final XMLMetadata xmlMetadata;
|
||||
private final Schema schema;
|
||||
|
||||
public EdmSchemaImpl(Edm edm, XMLMetadata xmlMetadata, Schema schema) {
|
||||
super(schema.getNamespace(), schema.getAlias());
|
||||
this.edm = edm;
|
||||
this.xmlMetadata = xmlMetadata;
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EdmEntityContainer createEntityContainer() {
|
||||
EntityContainer defaultContainer = schema.getDefaultEntityContainer();
|
||||
if (defaultContainer != null) {
|
||||
FullQualifiedName entityContainerName = new FullQualifiedName(schema.getNamespace(), defaultContainer.getName());
|
||||
return new EdmEntityContainerImpl(edm, entityContainerName, defaultContainer, xmlMetadata);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmTypeDefinition> createTypeDefinitions() {
|
||||
List<EdmTypeDefinition> typeDefinitions = new ArrayList<EdmTypeDefinition>();
|
||||
if (schema instanceof org.apache.olingo.client.api.edm.xml.v4.Schema) {
|
||||
List<TypeDefinition> providerTypeDefinitions =
|
||||
((org.apache.olingo.client.api.edm.xml.v4.Schema) schema).getTypeDefinitions();
|
||||
if (providerTypeDefinitions != null) {
|
||||
for (TypeDefinition def : providerTypeDefinitions) {
|
||||
typeDefinitions.add(new EdmTypeDefinitionImpl(edm, new FullQualifiedName("namespace", def.getName()), def));
|
||||
}
|
||||
}
|
||||
}
|
||||
return typeDefinitions;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmEnumType> createEnumTypes() {
|
||||
List<EdmEnumType> enumTypes = new ArrayList<EdmEnumType>();
|
||||
List<EnumType> providerEnumTypes = schema.getEnumTypes();
|
||||
if (providerEnumTypes != null) {
|
||||
for (EnumType enumType : providerEnumTypes) {
|
||||
enumTypes.add(new EdmEnumTypeImpl(edm, new FullQualifiedName(namespace, enumType.getName()), enumType));
|
||||
}
|
||||
}
|
||||
return enumTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmEntityType> createEntityTypes() {
|
||||
List<EdmEntityType> entityTypes = new ArrayList<EdmEntityType>();
|
||||
List<? extends EntityType> providerEntityTypes = schema.getEntityTypes();
|
||||
if (providerEntityTypes != null) {
|
||||
for (EntityType entityType : providerEntityTypes) {
|
||||
entityTypes.add(EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName(namespace, entityType.getName()),
|
||||
entityType));
|
||||
}
|
||||
}
|
||||
return entityTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmComplexType> createComplexTypes() {
|
||||
List<EdmComplexType> complexTypes = new ArrayList<EdmComplexType>();
|
||||
List<? extends ComplexType> providerComplexTypes = schema.getComplexTypes();
|
||||
if (providerComplexTypes != null) {
|
||||
for (ComplexType complexType : providerComplexTypes) {
|
||||
complexTypes.add(EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName(namespace, complexType.getName()),
|
||||
complexType));
|
||||
}
|
||||
}
|
||||
return complexTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmAction> createActions() {
|
||||
List<EdmAction> actions = new ArrayList<EdmAction>();
|
||||
if (schema instanceof org.apache.olingo.client.api.edm.xml.v4.Schema) {
|
||||
List<Action> providerActions = ((org.apache.olingo.client.api.edm.xml.v4.Schema) schema).getActions();
|
||||
if (providerActions != null) {
|
||||
for (Action action : providerActions) {
|
||||
actions.add(EdmActionImpl.getInstance(edm, new FullQualifiedName(namespace, action.getName()), action));
|
||||
}
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmFunction> createFunctions() {
|
||||
List<EdmFunction> functions = new ArrayList<EdmFunction>();
|
||||
if (schema instanceof org.apache.olingo.client.api.edm.xml.v4.Schema) {
|
||||
List<Function> providerFunctions = ((org.apache.olingo.client.api.edm.xml.v4.Schema) schema).getFunctions();
|
||||
if (providerFunctions != null) {
|
||||
for (Function function : providerFunctions) {
|
||||
functions.add(
|
||||
EdmFunctionImpl.getInstance(edm, new FullQualifiedName(namespace, function.getName()), function));
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
} else {
|
||||
for (EntityContainer providerContainer : schema.getEntityContainers()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<FunctionImport> providerFunctions = (List<FunctionImport>) providerContainer.getFunctionImports();
|
||||
if (providerFunctions != null) {
|
||||
for (FunctionImport function : providerFunctions) {
|
||||
functions.add(
|
||||
EdmFunctionProxy.getInstance(edm, new FullQualifiedName(namespace, function.getName()), function));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
}
|
|
@ -99,4 +99,10 @@ public class EdmEntitySetProxy extends AbstractEdmBindingTarget implements EdmEn
|
|||
return entityContainer.getEntitySet(targetEntitySet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludeInServiceDocument() {
|
||||
//V3 states that all entity sets are included in the service document
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.olingo.commons.api.edm.Edm;
|
|||
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.FullQualifiedName;
|
||||
|
||||
public class EdmFunctionImportProxy extends EdmOperationImportImpl implements EdmFunctionImport {
|
||||
|
||||
|
@ -45,4 +46,16 @@ public class EdmFunctionImportProxy extends EdmOperationImportImpl implements Ed
|
|||
new EdmTypeInfo(functionImport.getName(), container.getNamespace()).getFullQualifiedName(),
|
||||
null, null, parameterNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludeInServiceDocument() {
|
||||
//V3 states that all function imports are included in the service document
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FullQualifiedName getFunctionFqn() {
|
||||
//TODO: Is this right for V3?
|
||||
return new FullQualifiedName(container.getNamespace(), getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,4 +62,16 @@ public class EdmOperationProxy extends AbstractEdmOperation {
|
|||
this.functionImport = functionImport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FullQualifiedName getBindingParameterTypeFqn() {
|
||||
//Not relevant for V3
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isBindingParameterTypeCollection() {
|
||||
//Not relevant for V3
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ public class ParameterImpl extends AbstractParameter implements Parameter {
|
|||
private static final long serialVersionUID = -1067642515116697747L;
|
||||
|
||||
private String srid;
|
||||
|
||||
private boolean isCollection;
|
||||
|
||||
@Override
|
||||
public String getSrid() {
|
||||
|
@ -36,4 +38,14 @@ public class ParameterImpl extends AbstractParameter implements Parameter {
|
|||
this.srid = srid;
|
||||
}
|
||||
|
||||
//TODO: fill during metadata parsing
|
||||
@Override
|
||||
public boolean isCollection() {
|
||||
return isCollection;
|
||||
}
|
||||
|
||||
public void setCollection(boolean isCollection) {
|
||||
this.isCollection = isCollection;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.api;
|
||||
|
||||
public class ODataRuntimeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ODataRuntimeException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public ODataRuntimeException(String msg, Exception e) {
|
||||
super(msg, e);
|
||||
}
|
||||
|
||||
public ODataRuntimeException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
}
|
|
@ -26,6 +26,12 @@ import java.util.List;
|
|||
* Interface representing a Entity Data Model as described in the Conceptual Schema Definition.
|
||||
*/
|
||||
public interface Edm {
|
||||
|
||||
/**
|
||||
* This method DOES NOT support lazy loading. All schemas are loaded completely!
|
||||
* @return all schemas defined for this EDM
|
||||
*/
|
||||
List<EdmSchema> getSchemas();
|
||||
|
||||
/**
|
||||
* Get entity container by full qualified name.
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.api.edm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A CSDL EntityContainer element.
|
||||
*
|
||||
*
|
||||
* <br/>
|
||||
* EdmEntityContainer hold the information of EntitySets, Singletons, ActionImports and FunctionImports contained
|
||||
*/
|
||||
|
@ -33,7 +35,7 @@ public interface EdmEntityContainer extends EdmNamed {
|
|||
|
||||
/**
|
||||
* Get contained Singleton by name.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @return {@link EdmSingleton}
|
||||
*/
|
||||
|
@ -41,7 +43,7 @@ public interface EdmEntityContainer extends EdmNamed {
|
|||
|
||||
/**
|
||||
* Get contained EntitySet by name.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @return {@link EdmEntitySet}
|
||||
*/
|
||||
|
@ -49,7 +51,7 @@ public interface EdmEntityContainer extends EdmNamed {
|
|||
|
||||
/**
|
||||
* Get contained ActionImport by name.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @return {@link EdmActionImport}
|
||||
*/
|
||||
|
@ -57,10 +59,34 @@ public interface EdmEntityContainer extends EdmNamed {
|
|||
|
||||
/**
|
||||
* Get contained FunctionImport by name.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @return {@link EdmFunctionImport}
|
||||
*/
|
||||
EdmFunctionImport getFunctionImport(String name);
|
||||
|
||||
/**
|
||||
* This method <b>DOES NOT</b> support lazy loading
|
||||
* @return returns all entity sets for this container.
|
||||
*/
|
||||
List<EdmEntitySet> getEntitySets();
|
||||
|
||||
/**
|
||||
* This method <b>DOES NOT</b> support lazy loading
|
||||
* @return returns all function imports for this container.
|
||||
*/
|
||||
List<EdmFunctionImport> getFunctionImports();
|
||||
|
||||
/**
|
||||
* This method <b>DOES NOT</b> support lazy loading
|
||||
* @return returns all singletons for this container.
|
||||
*/
|
||||
List<EdmSingleton> getSingletons();
|
||||
|
||||
/**
|
||||
* This method <b>DOES NOT</b> support lazy loading
|
||||
* @return returns all action imports for this container.
|
||||
*/
|
||||
List<EdmActionImport> getActionImports();
|
||||
|
||||
}
|
||||
|
|
|
@ -26,4 +26,9 @@ package org.apache.olingo.commons.api.edm;
|
|||
*/
|
||||
public interface EdmEntitySet extends EdmBindingTarget {
|
||||
|
||||
/**
|
||||
* @return true if entity set must be included in the service document
|
||||
*/
|
||||
boolean isIncludeInServiceDocument();
|
||||
|
||||
}
|
||||
|
|
|
@ -26,5 +26,15 @@ import java.util.List;
|
|||
public interface EdmFunctionImport extends EdmOperationImport {
|
||||
|
||||
EdmFunction getFunction(List<String> parameterNames);
|
||||
|
||||
/**
|
||||
* @return the Fullqualified name for the function as specified in the metadata
|
||||
*/
|
||||
FullQualifiedName getFunctionFqn();
|
||||
|
||||
/**
|
||||
* @return true if the function import must be included in the service document
|
||||
*/
|
||||
boolean isIncludeInServiceDocument();
|
||||
|
||||
}
|
||||
|
|
|
@ -54,4 +54,14 @@ public interface EdmOperation extends EdmType {
|
|||
*/
|
||||
boolean isBound();
|
||||
|
||||
/**
|
||||
* @return the fullqualified type name of the binding parameter
|
||||
*/
|
||||
FullQualifiedName getBindingParameterTypeFqn();
|
||||
|
||||
/**
|
||||
* @return true if binding parameter is of type collection.
|
||||
*/
|
||||
Boolean isBindingParameterTypeCollection();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.api.edm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A csdl schema element
|
||||
*/
|
||||
public interface EdmSchema {
|
||||
|
||||
/**
|
||||
* @return the namespace for this schema
|
||||
*/
|
||||
String getNamespace();
|
||||
|
||||
/**
|
||||
* @return the alias for this schema. May be null.
|
||||
*/
|
||||
String getAlias();
|
||||
|
||||
/**
|
||||
* @return all enum types for this schema
|
||||
*/
|
||||
List<EdmEnumType> getEnumTypes();
|
||||
|
||||
/**
|
||||
* @return all entity types for this schema
|
||||
*/
|
||||
List<EdmEntityType> getEntityTypes();
|
||||
|
||||
/**
|
||||
* @return all complex types for this schema
|
||||
*/
|
||||
List<EdmComplexType> getComplexTypes();
|
||||
|
||||
/**
|
||||
* @return all actions for this schema
|
||||
*/
|
||||
List<EdmAction> getActions();
|
||||
|
||||
/**
|
||||
* @return all functions for this schema
|
||||
*/
|
||||
List<EdmFunction> getFunctions();
|
||||
|
||||
/**
|
||||
* @return the entity container for this schema. May be null.
|
||||
*/
|
||||
EdmEntityContainer getEntityContainer();
|
||||
|
||||
List<EdmTypeDefinition> getTypeDefinitions();
|
||||
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
@ -39,6 +39,16 @@ public class FullQualifiedName {
|
|||
fqn = namespace + "." + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespace.name
|
||||
*/
|
||||
public FullQualifiedName(final String namespaceAndName) {
|
||||
fqn = namespaceAndName;
|
||||
String[] split = namespaceAndName.split(".");
|
||||
namespace = split[0];
|
||||
name = split[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return namespace
|
||||
*/
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.edm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
|
@ -33,13 +35,17 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements
|
|||
|
||||
protected final FullQualifiedName entityContainerName;
|
||||
|
||||
private final Map<String, EdmSingleton> singletons = new HashMap<String, EdmSingleton>();
|
||||
protected final Map<String, EdmSingleton> singletons = new HashMap<String, EdmSingleton>();
|
||||
private boolean allSingletonsLoaded = false;
|
||||
|
||||
private final Map<String, EdmEntitySet> entitySets = new HashMap<String, EdmEntitySet>();
|
||||
protected final Map<String, EdmEntitySet> entitySets = new HashMap<String, EdmEntitySet>();
|
||||
private boolean allEntitySetsLoaded = false;
|
||||
|
||||
private final Map<String, EdmActionImport> actionImports = new HashMap<String, EdmActionImport>();
|
||||
protected final Map<String, EdmActionImport> actionImports = new HashMap<String, EdmActionImport>();
|
||||
private boolean allActionImportsLoaded = false;
|
||||
|
||||
private final Map<String, EdmFunctionImport> functionImports = new HashMap<String, EdmFunctionImport>();
|
||||
protected final Map<String, EdmFunctionImport> functionImports = new HashMap<String, EdmFunctionImport>();
|
||||
private boolean allFunctionImportsLoaded = false;
|
||||
|
||||
public AbstractEdmEntityContainer(final Edm edm, final FullQualifiedName entityContainerName) {
|
||||
super(edm, entityContainerName.getName());
|
||||
|
@ -99,4 +105,47 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements
|
|||
return functionImport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmEntitySet> getEntitySets() {
|
||||
if (!allEntitySetsLoaded) {
|
||||
loadAllEntitySets();
|
||||
allEntitySetsLoaded = true;
|
||||
}
|
||||
return new ArrayList<EdmEntitySet>(entitySets.values());
|
||||
}
|
||||
|
||||
protected abstract void loadAllEntitySets();
|
||||
|
||||
@Override
|
||||
public List<EdmFunctionImport> getFunctionImports() {
|
||||
if (!allFunctionImportsLoaded) {
|
||||
loadAllFunctionImports();
|
||||
allFunctionImportsLoaded = true;
|
||||
}
|
||||
return new ArrayList<EdmFunctionImport>(functionImports.values());
|
||||
}
|
||||
|
||||
protected abstract void loadAllFunctionImports();
|
||||
|
||||
@Override
|
||||
public List<EdmSingleton> getSingletons() {
|
||||
if (!allSingletonsLoaded) {
|
||||
loadAllSingletons();
|
||||
allSingletonsLoaded = true;
|
||||
}
|
||||
return new ArrayList<EdmSingleton>(singletons.values());
|
||||
}
|
||||
|
||||
protected abstract void loadAllSingletons();
|
||||
|
||||
@Override
|
||||
public List<EdmActionImport> getActionImports() {
|
||||
if (!allActionImportsLoaded) {
|
||||
loadAllActionImports();
|
||||
allActionImportsLoaded = true;
|
||||
}
|
||||
return new ArrayList<EdmActionImport>(actionImports.values());
|
||||
}
|
||||
|
||||
protected abstract void loadAllActionImports();
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
@ -29,43 +29,121 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
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;
|
||||
|
||||
public abstract class AbstractEdmImpl implements Edm {
|
||||
|
||||
private final Map<FullQualifiedName, EdmEntityContainer> entityContainers
|
||||
= new HashMap<FullQualifiedName, EdmEntityContainer>();
|
||||
private final Map<FullQualifiedName, EdmEntityContainer> entityContainers =
|
||||
new HashMap<FullQualifiedName, EdmEntityContainer>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmEnumType> enumTypes
|
||||
= new HashMap<FullQualifiedName, EdmEnumType>();
|
||||
private final Map<FullQualifiedName, EdmEnumType> enumTypes = new HashMap<FullQualifiedName, EdmEnumType>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmTypeDefinition> typeDefinitions
|
||||
= new HashMap<FullQualifiedName, EdmTypeDefinition>();
|
||||
private final Map<FullQualifiedName, EdmTypeDefinition> typeDefinitions =
|
||||
new HashMap<FullQualifiedName, EdmTypeDefinition>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmEntityType> entityTypes
|
||||
= new HashMap<FullQualifiedName, EdmEntityType>();
|
||||
private final Map<FullQualifiedName, EdmEntityType> entityTypes = new HashMap<FullQualifiedName, EdmEntityType>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmComplexType> complexTypes
|
||||
= new HashMap<FullQualifiedName, EdmComplexType>();
|
||||
private final Map<FullQualifiedName, EdmComplexType> complexTypes = new HashMap<FullQualifiedName, EdmComplexType>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmAction> unboundActions
|
||||
= new HashMap<FullQualifiedName, EdmAction>();
|
||||
private final Map<FullQualifiedName, EdmAction> unboundActions = new HashMap<FullQualifiedName, EdmAction>();
|
||||
|
||||
private final Map<FunctionMapKey, EdmFunction> unboundFunctions
|
||||
= new HashMap<FunctionMapKey, EdmFunction>();
|
||||
private final Map<FunctionMapKey, EdmFunction> unboundFunctions = new HashMap<FunctionMapKey, EdmFunction>();
|
||||
|
||||
private final Map<ActionMapKey, EdmAction> boundActions
|
||||
= new HashMap<ActionMapKey, EdmAction>();
|
||||
private final Map<ActionMapKey, EdmAction> boundActions = new HashMap<ActionMapKey, EdmAction>();
|
||||
|
||||
private final Map<FunctionMapKey, EdmFunction> boundFunctions
|
||||
= new HashMap<FunctionMapKey, EdmFunction>();
|
||||
private final Map<FunctionMapKey, EdmFunction> boundFunctions = new HashMap<FunctionMapKey, EdmFunction>();
|
||||
|
||||
private EdmServiceMetadata serviceMetadata;
|
||||
|
||||
private Map<String, String> aliasToNamespaceInfo;
|
||||
|
||||
|
||||
private List<EdmSchema> schemas;
|
||||
|
||||
@Override
|
||||
public List<EdmSchema> getSchemas() {
|
||||
if (schemas == null) {
|
||||
schemas = createSchemas();
|
||||
if (schemas != null) {
|
||||
aliasToNamespaceInfo = new HashMap<String, String>();
|
||||
for (EdmSchema schema : schemas) {
|
||||
String namespace = schema.getNamespace();
|
||||
if (schema.getAlias() != null) {
|
||||
aliasToNamespaceInfo.put(schema.getAlias(), namespace);
|
||||
}
|
||||
|
||||
List<EdmEnumType> localEnumTypes = schema.getEnumTypes();
|
||||
if (localEnumTypes != null) {
|
||||
for (EdmEnumType enumType : localEnumTypes) {
|
||||
enumTypes.put(new FullQualifiedName(namespace, enumType.getName()), enumType);
|
||||
}
|
||||
}
|
||||
|
||||
List<EdmTypeDefinition> localTypeDefinitions = schema.getTypeDefinitions();
|
||||
if (localTypeDefinitions != null) {
|
||||
for (EdmTypeDefinition typeDef : localTypeDefinitions) {
|
||||
typeDefinitions.put(new FullQualifiedName(namespace, typeDef.getName()), typeDef);
|
||||
}
|
||||
}
|
||||
|
||||
List<EdmComplexType> localComplexTypes = schema.getComplexTypes();
|
||||
if (localComplexTypes != null) {
|
||||
for (EdmComplexType complexType : localComplexTypes) {
|
||||
complexTypes.put(new FullQualifiedName(namespace, complexType.getName()), complexType);
|
||||
}
|
||||
}
|
||||
|
||||
List<EdmEntityType> localEntityTypes = schema.getEntityTypes();
|
||||
if (localEntityTypes != null) {
|
||||
for (EdmEntityType entityType : localEntityTypes) {
|
||||
entityTypes.put(new FullQualifiedName(namespace, entityType.getName()), entityType);
|
||||
}
|
||||
}
|
||||
|
||||
List<EdmAction> localActions = schema.getActions();
|
||||
if (localActions != null) {
|
||||
for (EdmAction action : localActions) {
|
||||
if (action.isBound()) {
|
||||
ActionMapKey key = new ActionMapKey(new FullQualifiedName(namespace, action.getName()),
|
||||
action.getBindingParameterTypeFqn(), action.isBindingParameterTypeCollection());
|
||||
boundActions.put(key, action);
|
||||
} else {
|
||||
unboundActions.put(new FullQualifiedName(namespace, action.getName()), action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<EdmFunction> 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());
|
||||
|
||||
if (function.isBound()) {
|
||||
boundFunctions.put(key, function);
|
||||
} else {
|
||||
unboundFunctions.put(key, function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EdmEntityContainer entityContainer = schema.getEntityContainer();
|
||||
if(entityContainer != null){
|
||||
entityContainers.put(new FullQualifiedName(namespace, entityContainer.getName()), entityContainer);
|
||||
if(!entityContainers.containsKey(null)){
|
||||
entityContainers.put(null, entityContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return schemas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmEntityContainer getEntityContainer(final FullQualifiedName namespaceOrAliasFQN) {
|
||||
final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN);
|
||||
|
@ -136,7 +214,7 @@ public abstract class AbstractEdmImpl implements Edm {
|
|||
|
||||
@Override
|
||||
public EdmAction getAction(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName,
|
||||
final Boolean isBindingParameterCollection) {
|
||||
final Boolean isBindingParameterCollection) {
|
||||
|
||||
EdmAction action = null;
|
||||
|
||||
|
@ -166,15 +244,15 @@ public abstract class AbstractEdmImpl implements Edm {
|
|||
|
||||
@Override
|
||||
public EdmFunction getFunction(final FullQualifiedName functionName,
|
||||
final FullQualifiedName bindingParameterTypeName,
|
||||
final Boolean isBindingParameterCollection, final List<String> parameterNames) {
|
||||
final FullQualifiedName bindingParameterTypeName,
|
||||
final Boolean isBindingParameterCollection, final List<String> parameterNames) {
|
||||
|
||||
EdmFunction function = null;
|
||||
|
||||
final FullQualifiedName functionFqn = resolvePossibleAlias(functionName);
|
||||
if (bindingParameterTypeName == null) {
|
||||
final FunctionMapKey key = new FunctionMapKey(
|
||||
functionFqn, bindingParameterTypeName, isBindingParameterCollection, parameterNames);
|
||||
functionFqn, bindingParameterTypeName, isBindingParameterCollection, parameterNames);
|
||||
function = unboundFunctions.get(key);
|
||||
if (function == null) {
|
||||
function = createUnboundFunction(functionFqn, parameterNames);
|
||||
|
@ -184,12 +262,12 @@ public abstract class AbstractEdmImpl implements Edm {
|
|||
}
|
||||
} else {
|
||||
final FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName);
|
||||
final FunctionMapKey key
|
||||
= new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames);
|
||||
final FunctionMapKey key =
|
||||
new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames);
|
||||
function = boundFunctions.get(key);
|
||||
if (function == null) {
|
||||
function = createBoundFunction(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection,
|
||||
parameterNames);
|
||||
parameterNames);
|
||||
if (function != null) {
|
||||
boundFunctions.put(key, function);
|
||||
}
|
||||
|
@ -241,12 +319,15 @@ public abstract class AbstractEdmImpl implements Edm {
|
|||
protected abstract EdmFunction createUnboundFunction(FullQualifiedName functionName, List<String> 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<String> parameterNames);
|
||||
FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection,
|
||||
List<String> parameterNames);
|
||||
|
||||
protected abstract EdmServiceMetadata createServiceMetadata();
|
||||
|
||||
protected abstract List<EdmSchema> createSchemas();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.commons.core.edm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
import org.apache.olingo.commons.api.edm.EdmSchema;
|
||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||
|
||||
public abstract class AbstractEdmSchemaImpl implements EdmSchema {
|
||||
|
||||
protected final String namespace;
|
||||
private final String alias;
|
||||
private List<EdmTypeDefinition> typeDefinitions;
|
||||
private List<EdmEnumType> enumTypes;
|
||||
private List<EdmEntityType> entityTypes;
|
||||
private List<EdmComplexType> complexTypes;
|
||||
private List<EdmAction> actions;
|
||||
private List<EdmFunction> functions;
|
||||
private EdmEntityContainer entityContainer;
|
||||
|
||||
public AbstractEdmSchemaImpl(String namespace, String alias) {
|
||||
this.namespace = namespace;
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
protected abstract EdmEntityContainer createEntityContainer();
|
||||
|
||||
protected abstract List<EdmTypeDefinition> createTypeDefinitions();
|
||||
|
||||
protected abstract List<EdmEnumType> createEnumTypes();
|
||||
|
||||
protected abstract List<EdmEntityType> createEntityTypes();
|
||||
|
||||
protected abstract List<EdmComplexType> createComplexTypes();
|
||||
|
||||
protected abstract List<EdmAction> createActions();
|
||||
|
||||
protected abstract List<EdmFunction> createFunctions();
|
||||
|
||||
@Override
|
||||
public List<EdmTypeDefinition> getTypeDefinitions() {
|
||||
if (typeDefinitions == null) {
|
||||
typeDefinitions = createTypeDefinitions();
|
||||
}
|
||||
return typeDefinitions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmEnumType> getEnumTypes() {
|
||||
if (enumTypes == null) {
|
||||
enumTypes = createEnumTypes();
|
||||
}
|
||||
return enumTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmEntityType> getEntityTypes() {
|
||||
if (entityTypes == null) {
|
||||
entityTypes = createEntityTypes();
|
||||
}
|
||||
return entityTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmComplexType> getComplexTypes() {
|
||||
if (complexTypes == null) {
|
||||
complexTypes = createComplexTypes();
|
||||
}
|
||||
return complexTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmAction> getActions() {
|
||||
if (actions == null) {
|
||||
actions = createActions();
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmFunction> getFunctions() {
|
||||
if (functions == null) {
|
||||
functions = createFunctions();
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmEntityContainer getEntityContainer() {
|
||||
if (entityContainer == null) {
|
||||
entityContainer = createEntityContainer();
|
||||
}
|
||||
return entityContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
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;
|
||||
|
@ -52,6 +53,18 @@ public class EdmImplCachingTest {
|
|||
|
||||
private Edm edm;
|
||||
|
||||
@Test
|
||||
public void cacheSchema() {
|
||||
List<EdmSchema> schemas = edm.getSchemas();
|
||||
assertNotNull(schemas);
|
||||
|
||||
assertEquals(1, schemas.size());
|
||||
|
||||
List<EdmSchema> cachedSchemas = edm.getSchemas();
|
||||
assertTrue(schemas == cachedSchemas );
|
||||
assertEquals(schemas, schemas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheEntityContainer() {
|
||||
EdmEntityContainer entityContainer = edm.getEntityContainer(null);
|
||||
|
@ -385,5 +398,13 @@ public class EdmImplCachingTest {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmSchema> createSchemas() {
|
||||
List<EdmSchema> schemas = new ArrayList<EdmSchema>();
|
||||
EdmSchema schema = mock(EdmSchema.class);
|
||||
schemas.add(schema);
|
||||
return schemas;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
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;
|
||||
|
@ -52,6 +53,12 @@ public class EdmImplCallCreateTest {
|
|||
|
||||
private Edm edm;
|
||||
|
||||
@Test
|
||||
public void callCreateSchemas() {
|
||||
List<EdmSchema> schemas = edm.getSchemas();
|
||||
assertNotNull(schemas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void callCreateEntityContainer() {
|
||||
EdmEntityContainer entityContainer = edm.getEntityContainer(FQN);
|
||||
|
@ -264,5 +271,10 @@ public class EdmImplCallCreateTest {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EdmSchema> createSchemas() {
|
||||
return new ArrayList<EdmSchema>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.api;
|
||||
|
||||
public enum ODataFormat {
|
||||
XML, JSON
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.api;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
|
||||
public interface ODataSerializer {
|
||||
|
||||
InputStream metadata(Edm edm);
|
||||
|
||||
InputStream serviceDocument(Edm edm, String serviceRoot);
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.api;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataRuntimeException;
|
||||
|
||||
|
||||
public abstract class ODataServer {
|
||||
|
||||
private static final String IMPLEMENTATION = "org.apache.olingo.server.core.ODataServerImpl";
|
||||
|
||||
public static ODataServer newInstance(){
|
||||
try {
|
||||
final Class<?> clazz = Class.forName(ODataServer.IMPLEMENTATION);
|
||||
|
||||
/*
|
||||
* We explicitly do not use the singleton pattern to keep the server state free
|
||||
* and avoid class loading issues also during hot deployment.
|
||||
*/
|
||||
final Object object = clazz.newInstance();
|
||||
return (ODataServer) object;
|
||||
|
||||
} catch (final Exception e) {
|
||||
//TODO: Change to ODataRuntimeExcfeption
|
||||
throw new ODataRuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public abstract ODataSerializer getSerializer(ODataFormat format);
|
||||
|
||||
}
|
|
@ -179,4 +179,12 @@ public abstract class EdmProvider {
|
|||
public List<Schema> getSchemas() throws ODataException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity container of this edm
|
||||
* @return {@link EntityContainer} of this edm
|
||||
*/
|
||||
public EntityContainer getEntityContainer() throws ODataException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,75 +10,84 @@
|
|||
OF ANY KIND, either express or implied. See the License for the specific
|
||||
language governing permissions and limitations under the License. -->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>olingo-server-core-incubating</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>${project.artifactId}</name>
|
||||
<artifactId>olingo-server-core-incubating</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>${project.artifactId}</name>
|
||||
|
||||
<parent>
|
||||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>olingo-lib-incubating</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>olingo-lib-incubating</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>olingo-server-api-incubating</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>olingo-commons-core-incubating</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-runtime</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>olingo-server-api-incubating</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>olingo-commons-core-incubating</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-runtime</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<version>${antlr.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<version>${antlr.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<!--<arguments><argument>-atn</argument></arguments> -->
|
||||
<listener>true</listener>
|
||||
<visitor>true</visitor>
|
||||
<listener>true</listener>
|
||||
<visitor>true</visitor>
|
||||
<!--maven antlr plugin has trouble with grammer import if the grammerfiles
|
||||
are not directly inside src/main/antlr4, hence we have to set the libDirectory -->
|
||||
<libDirectory>src/main/antlr4/org/apache/olingo/server/core/uri/antlr</libDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<libDirectory>src/main/antlr4/org/apache/olingo/server/core/uri/antlr</libDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,327 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* Circular stream buffer to write/read into/from one single buffer.
|
||||
* With support of {@link InputStream} and {@link OutputStream} access to buffered data.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class CircleStreamBuffer {
|
||||
|
||||
private static final int NEW_BUFFER_RESIZE_FACTOR = 2;
|
||||
private static final int READ_EOF = -1;
|
||||
private static final int DEFAULT_CAPACITY = 8192;
|
||||
private static final int MAX_CAPACITY = DEFAULT_CAPACITY * 32;
|
||||
|
||||
private int currentAllocateCapacity = DEFAULT_CAPACITY;
|
||||
|
||||
private boolean writeMode = true;
|
||||
private boolean writeClosed = false;
|
||||
private boolean readClosed = false;
|
||||
|
||||
private Queue<ByteBuffer> bufferQueue = new LinkedBlockingQueue<ByteBuffer>();
|
||||
private ByteBuffer currentWriteBuffer;
|
||||
|
||||
private InternalInputStream inStream;
|
||||
private InternalOutputStream outStream;
|
||||
|
||||
/**
|
||||
* Creates a {@link CircleStreamBuffer} with default buffer size.
|
||||
*/
|
||||
public CircleStreamBuffer() {
|
||||
this(DEFAULT_CAPACITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link CircleStreamBuffer} with given buffer size in bytes.
|
||||
*
|
||||
* @param bufferSize
|
||||
*/
|
||||
public CircleStreamBuffer(final int bufferSize) {
|
||||
currentAllocateCapacity = bufferSize;
|
||||
createNewWriteBuffer();
|
||||
inStream = new InternalInputStream(this);
|
||||
outStream = new InternalOutputStream(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link InputStream} for data read access.
|
||||
*
|
||||
* @return the stream
|
||||
*/
|
||||
public InputStream getInputStream() {
|
||||
return inStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link OutputStream} for write data.
|
||||
*
|
||||
* @return the stream
|
||||
*/
|
||||
public OutputStream getOutputStream() {
|
||||
return outStream;
|
||||
}
|
||||
|
||||
// #############################################
|
||||
// #
|
||||
// # Common parts
|
||||
// #
|
||||
// #############################################
|
||||
|
||||
/**
|
||||
* Closes the write (input) part of the {@link CircleStreamBuffer}.
|
||||
* After this call the buffer can only be read out.
|
||||
*/
|
||||
public void closeWrite() {
|
||||
writeClosed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the read (output) part of the {@link CircleStreamBuffer}.
|
||||
* After this call it is possible to write into the buffer (but can never be read out).
|
||||
*/
|
||||
public void closeRead() {
|
||||
readClosed = true;
|
||||
// clear references to byte buffers
|
||||
ByteBuffer buffer = bufferQueue.poll();
|
||||
while (buffer != null) {
|
||||
buffer.clear();
|
||||
buffer = bufferQueue.poll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes write and read part (and hence the complete buffer).
|
||||
*/
|
||||
public void close() {
|
||||
closeWrite();
|
||||
closeRead();
|
||||
}
|
||||
|
||||
private int remaining() throws IOException {
|
||||
if (writeMode) {
|
||||
return currentWriteBuffer.remaining();
|
||||
} else {
|
||||
ByteBuffer toRead = getReadBuffer();
|
||||
if (toRead == null) {
|
||||
return 0;
|
||||
}
|
||||
return toRead.remaining();
|
||||
}
|
||||
}
|
||||
|
||||
// #############################################
|
||||
// #
|
||||
// # Reading parts
|
||||
// #
|
||||
// #############################################
|
||||
|
||||
private ByteBuffer getReadBuffer() throws IOException {
|
||||
if (readClosed) {
|
||||
throw new IOException("Tried to read from closed stream.");
|
||||
}
|
||||
|
||||
boolean next = false;
|
||||
ByteBuffer tmp = null;
|
||||
if (writeMode) {
|
||||
writeMode = false;
|
||||
next = true;
|
||||
} else {
|
||||
tmp = bufferQueue.peek();
|
||||
if (tmp != null && !tmp.hasRemaining()) {
|
||||
tmp = bufferQueue.poll();
|
||||
next = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (next) {
|
||||
tmp = bufferQueue.peek();
|
||||
if (tmp != null) {
|
||||
tmp.flip();
|
||||
}
|
||||
tmp = getReadBuffer();
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
private int read(final byte[] b, final int off, final int len) throws IOException {
|
||||
ByteBuffer readBuffer = getReadBuffer();
|
||||
if (readBuffer == null) {
|
||||
return READ_EOF;
|
||||
}
|
||||
|
||||
int toReadLength = readBuffer.remaining();
|
||||
if (len < toReadLength) {
|
||||
toReadLength = len;
|
||||
}
|
||||
readBuffer.get(b, off, toReadLength);
|
||||
return toReadLength;
|
||||
}
|
||||
|
||||
private int read() throws IOException {
|
||||
ByteBuffer readBuffer = getReadBuffer();
|
||||
if (readBuffer == null) {
|
||||
return READ_EOF;
|
||||
}
|
||||
|
||||
return readBuffer.get();
|
||||
}
|
||||
|
||||
// #############################################
|
||||
// #
|
||||
// # Writing parts
|
||||
// #
|
||||
// #############################################
|
||||
|
||||
private void write(final byte[] data, final int off, final int len) throws IOException {
|
||||
ByteBuffer writeBuffer = getWriteBuffer(len);
|
||||
writeBuffer.put(data, off, len);
|
||||
}
|
||||
|
||||
private ByteBuffer getWriteBuffer(final int size) throws IOException {
|
||||
if (writeClosed) {
|
||||
throw new IOException("Tried to write into closed stream.");
|
||||
}
|
||||
|
||||
if (writeMode) {
|
||||
if (remaining() < size) {
|
||||
createNewWriteBuffer(size);
|
||||
}
|
||||
} else {
|
||||
writeMode = true;
|
||||
createNewWriteBuffer();
|
||||
}
|
||||
|
||||
return currentWriteBuffer;
|
||||
}
|
||||
|
||||
private void write(final int b) throws IOException {
|
||||
ByteBuffer writeBuffer = getWriteBuffer(1);
|
||||
writeBuffer.put((byte) b);
|
||||
}
|
||||
|
||||
private void createNewWriteBuffer() {
|
||||
createNewWriteBuffer(currentAllocateCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new buffer (per {@link #allocateBuffer(int)}) with the requested capacity as minimum capacity, add the
|
||||
* new allocated
|
||||
* buffer to the {@link #bufferQueue} and set it as {@link #currentWriteBuffer}.
|
||||
*
|
||||
* @param requestedCapacity minimum capacity for new allocated buffer
|
||||
*/
|
||||
private void createNewWriteBuffer(final int requestedCapacity) {
|
||||
ByteBuffer b = allocateBuffer(requestedCapacity);
|
||||
bufferQueue.add(b);
|
||||
currentWriteBuffer = b;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param requestedCapacity
|
||||
* @return the buffer
|
||||
*/
|
||||
private ByteBuffer allocateBuffer(final int requestedCapacity) {
|
||||
int allocateCapacity = requestedCapacity;
|
||||
if (allocateCapacity < currentAllocateCapacity) {
|
||||
allocateCapacity = currentAllocateCapacity * NEW_BUFFER_RESIZE_FACTOR;
|
||||
}
|
||||
if (allocateCapacity > MAX_CAPACITY) {
|
||||
allocateCapacity = MAX_CAPACITY;
|
||||
}
|
||||
// update current
|
||||
currentAllocateCapacity = allocateCapacity;
|
||||
return ByteBuffer.allocate(allocateCapacity);
|
||||
}
|
||||
|
||||
// #############################################
|
||||
// #
|
||||
// # Inner classes (streams)
|
||||
// #
|
||||
// #############################################
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static class InternalInputStream extends InputStream {
|
||||
|
||||
private final CircleStreamBuffer inBuffer;
|
||||
|
||||
public InternalInputStream(final CircleStreamBuffer csBuffer) {
|
||||
inBuffer = csBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return inBuffer.remaining();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return inBuffer.read();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final byte[] b, final int off, final int len) throws IOException {
|
||||
return inBuffer.read(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
inBuffer.closeRead();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static class InternalOutputStream extends OutputStream {
|
||||
private final CircleStreamBuffer outBuffer;
|
||||
|
||||
public InternalOutputStream(final CircleStreamBuffer csBuffer) {
|
||||
outBuffer = csBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final int b) throws IOException {
|
||||
outBuffer.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final byte[] b, final int off, final int len) throws IOException {
|
||||
outBuffer.write(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
outBuffer.closeWrite();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmSingleton;
|
||||
import org.apache.olingo.server.api.ODataSerializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerationException;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
|
||||
|
||||
public class ODataJsonSerializer implements ODataSerializer {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ODataJsonSerializer.class);
|
||||
|
||||
private static final String DEFAULT_CHARSET = "UTF-8";
|
||||
|
||||
public static final String ODATA_CONTEXT = "@odata.context";
|
||||
public static final String METADATA = "$metadata";
|
||||
public static final String VALUE = "value";
|
||||
public static final String NAME = "name";
|
||||
public static final String URL = "url";
|
||||
public static final String KIND = "kind";
|
||||
|
||||
public static final String FUNCTION_IMPORT = "FunctionImport";
|
||||
public static final String SINGLETON = "Singleton";
|
||||
public static final String SERVICE_DOCUMENT = "ServiceDocument";
|
||||
|
||||
@Override
|
||||
public InputStream metadata(Edm edm) {
|
||||
throw new ODataRuntimeException("Metadata in JSON format not supported!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream serviceDocument(Edm edm, String serviceRoot) {
|
||||
CircleStreamBuffer buffer;
|
||||
BufferedWriter writer;
|
||||
JsonFactory factory;
|
||||
JsonGenerator gen = null;
|
||||
|
||||
try {
|
||||
buffer = new CircleStreamBuffer();
|
||||
writer = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream(), DEFAULT_CHARSET));
|
||||
factory = new JsonFactory();
|
||||
gen = factory.createGenerator(writer);
|
||||
|
||||
gen.setPrettyPrinter(new DefaultPrettyPrinter());
|
||||
|
||||
gen.writeStartObject();
|
||||
|
||||
Object metadataUri = serviceRoot + "/" + METADATA;
|
||||
gen.writeObjectField(ODATA_CONTEXT, metadataUri);
|
||||
gen.writeArrayFieldStart(VALUE);
|
||||
|
||||
writeEntitySets(gen, edm);
|
||||
writeFunctionImports(gen, edm);
|
||||
writeSingletons(gen, edm);
|
||||
|
||||
gen.close();
|
||||
|
||||
// writer.flush();
|
||||
// buffer.closeWrite();
|
||||
|
||||
return buffer.getInputStream();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new ODataRuntimeException(e);
|
||||
} finally {
|
||||
if (gen != null) {
|
||||
try {
|
||||
gen.close();
|
||||
} catch (IOException e) {
|
||||
throw new ODataRuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeEntitySets(JsonGenerator gen, Edm edm) throws JsonGenerationException, IOException {
|
||||
EdmEntityContainer container = edm.getEntityContainer(null);
|
||||
|
||||
for (EdmEntitySet edmEntitySet : container.getEntitySets()) {
|
||||
if (edmEntitySet.isIncludeInServiceDocument()) {
|
||||
gen.writeStartObject();
|
||||
gen.writeObjectField(NAME, edmEntitySet.getName());
|
||||
gen.writeObjectField(URL, edmEntitySet.getName());
|
||||
gen.writeEndObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeFunctionImports(JsonGenerator gen, Edm edm) throws JsonGenerationException, IOException {
|
||||
EdmEntityContainer container = edm.getEntityContainer(null);
|
||||
|
||||
for (EdmFunctionImport edmFunctionImport : container.getFunctionImports()) {
|
||||
if (edmFunctionImport.isIncludeInServiceDocument()) {
|
||||
gen.writeStartObject();
|
||||
gen.writeObjectField(NAME, edmFunctionImport.getName());
|
||||
gen.writeObjectField(URL, edmFunctionImport.getName());
|
||||
gen.writeObjectField(KIND, FUNCTION_IMPORT);
|
||||
gen.writeEndObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSingletons(JsonGenerator gen, Edm edm) throws JsonGenerationException, IOException {
|
||||
EdmEntityContainer container = edm.getEntityContainer(null);
|
||||
|
||||
for (EdmSingleton edmSingleton : container.getSingletons()) {
|
||||
gen.writeStartObject();
|
||||
gen.writeObjectField(NAME, edmSingleton.getName());
|
||||
gen.writeObjectField(URL, edmSingleton.getName());
|
||||
gen.writeObjectField(KIND, SINGLETON);
|
||||
gen.writeEndObject();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.server.api.ODataSerializer;
|
||||
|
||||
public class ODataSerializerImpl implements ODataSerializer {
|
||||
|
||||
@Override
|
||||
public InputStream metadata(Edm edm) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream serviceDocument(Edm edm, String serviceRoot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataRuntimeException;
|
||||
import org.apache.olingo.server.api.ODataFormat;
|
||||
import org.apache.olingo.server.api.ODataSerializer;
|
||||
import org.apache.olingo.server.api.ODataServer;
|
||||
|
||||
public class ODataServerImpl extends ODataServer {
|
||||
|
||||
@Override
|
||||
public ODataSerializer getSerializer(ODataFormat format) {
|
||||
ODataSerializer serializer;
|
||||
switch (format) {
|
||||
case JSON:
|
||||
serializer = new ODataJsonSerializer();
|
||||
break;
|
||||
case XML:
|
||||
serializer = new ODataSerializerImpl();
|
||||
break;
|
||||
default:
|
||||
throw new ODataRuntimeException("Unsupported format: " + format);
|
||||
}
|
||||
|
||||
return serializer;
|
||||
}
|
||||
|
||||
}
|
|
@ -28,10 +28,9 @@ public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmAc
|
|||
|
||||
private final ActionImport actionImport;
|
||||
|
||||
public EdmActionImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
|
||||
final ActionImport actionImport) {
|
||||
public EdmActionImportImpl(final Edm edm, final EdmEntityContainer container, final ActionImport actionImport) {
|
||||
|
||||
super(edm, container, name, actionImport);
|
||||
super(edm, container, actionImport);
|
||||
this.actionImport = actionImport;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,25 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core.edm.provider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataException;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmActionImport;
|
||||
|
@ -25,9 +27,11 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
|||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmSingleton;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.core.edm.AbstractEdmEntityContainer;
|
||||
import org.apache.olingo.server.api.edm.provider.ActionImport;
|
||||
import org.apache.olingo.server.api.edm.provider.EdmProvider;
|
||||
import org.apache.olingo.server.api.edm.provider.EntityContainer;
|
||||
import org.apache.olingo.server.api.edm.provider.EntityContainerInfo;
|
||||
import org.apache.olingo.server.api.edm.provider.EntitySet;
|
||||
import org.apache.olingo.server.api.edm.provider.FunctionImport;
|
||||
|
@ -36,14 +40,22 @@ import org.apache.olingo.server.api.edm.provider.Singleton;
|
|||
public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
|
||||
|
||||
private final EdmProvider provider;
|
||||
private EntityContainer container;
|
||||
|
||||
public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider,
|
||||
final EntityContainerInfo entityContainerInfo) {
|
||||
final EntityContainerInfo entityContainerInfo) {
|
||||
|
||||
super(edm, entityContainerInfo.getContainerName());
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public EdmEntityContainerImpl(Edm edm, EdmProvider provider, FullQualifiedName containerFQN,
|
||||
EntityContainer entityContainer) {
|
||||
super(edm, containerFQN);
|
||||
this.provider = provider;
|
||||
this.container = entityContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EdmSingleton createSingleton(final String singletonName) {
|
||||
EdmSingleton singleton = null;
|
||||
|
@ -83,7 +95,7 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
|
|||
try {
|
||||
final ActionImport providerImport = provider.getActionImport(entityContainerName, actionImportName);
|
||||
if (providerImport != null) {
|
||||
actionImport = new EdmActionImportImpl(edm, this, actionImportName, providerImport);
|
||||
actionImport = new EdmActionImportImpl(edm, this, providerImport);
|
||||
}
|
||||
} catch (ODataException e) {
|
||||
throw new EdmException(e);
|
||||
|
@ -99,7 +111,7 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
|
|||
try {
|
||||
final FunctionImport providerImport = provider.getFunctionImport(entityContainerName, functionImportName);
|
||||
if (providerImport != null) {
|
||||
functionImport = new EdmFunctionImportImpl(edm, this, functionImportName, providerImport);
|
||||
functionImport = new EdmFunctionImportImpl(edm, this, providerImport);
|
||||
}
|
||||
} catch (ODataException e) {
|
||||
throw new EdmException(e);
|
||||
|
@ -108,4 +120,77 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
|
|||
return functionImport;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllEntitySets() {
|
||||
loadContainer();
|
||||
List<EntitySet> providerEntitySets = container.getEntitySets();
|
||||
if (providerEntitySets != null) {
|
||||
for (EntitySet entitySet : providerEntitySets) {
|
||||
if (!entitySets.containsKey(entitySet.getName())) {
|
||||
EdmEntitySetImpl impl = new EdmEntitySetImpl(edm, this, entitySet);
|
||||
entitySets.put(impl.getName(), impl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllFunctionImports() {
|
||||
loadContainer();
|
||||
List<FunctionImport> providerFuctionImports = container.getFunctionImports();
|
||||
if (providerFuctionImports != null) {
|
||||
for (FunctionImport functionImport : providerFuctionImports) {
|
||||
String functionName = functionImport.getName();
|
||||
if (!functionImports.containsKey(functionName)) {
|
||||
EdmFunctionImportImpl impl = new EdmFunctionImportImpl(edm, this, functionImport);
|
||||
functionImports.put(functionName, impl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllSingletons() {
|
||||
loadContainer();
|
||||
List<Singleton> providerSingletons = container.getSingletons();
|
||||
if (providerSingletons != null) {
|
||||
for (Singleton singleton : providerSingletons) {
|
||||
if (!singletons.containsKey(singleton.getName())) {
|
||||
EdmSingletonImpl impl = new EdmSingletonImpl(edm, this, singleton);
|
||||
singletons.put(singleton.getName(), impl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllActionImports() {
|
||||
loadContainer();
|
||||
List<ActionImport> providerActionImports = container.getActionImports();
|
||||
if (providerActionImports != null) {
|
||||
for (ActionImport actionImport : providerActionImports) {
|
||||
if (!actionImports.containsKey(actionImport.getName())) {
|
||||
EdmActionImportImpl impl = new EdmActionImportImpl(edm, this, actionImport);
|
||||
actionImports.put(actionImport.getName(), impl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadContainer() {
|
||||
if (container == null) {
|
||||
try {
|
||||
container = provider.getEntityContainer();
|
||||
if (container == null) {
|
||||
// TODO: Should we throw an exception here?
|
||||
container = new EntityContainer().setName(this.getName());
|
||||
}
|
||||
} catch (ODataException e) {
|
||||
throw new EdmException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,15 @@ import org.apache.olingo.server.api.edm.provider.EntitySet;
|
|||
|
||||
public class EdmEntitySetImpl extends EdmBindingTargetImpl implements EdmEntitySet {
|
||||
|
||||
private EntitySet entitySet;
|
||||
|
||||
public EdmEntitySetImpl(final Edm edm, final EdmEntityContainer container, final EntitySet entitySet) {
|
||||
super(edm, container, entitySet);
|
||||
this.entitySet = entitySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludeInServiceDocument() {
|
||||
return entitySet.isIncludeInServiceDocument();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.Map;
|
|||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef;
|
||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
|
@ -38,8 +37,6 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
|
|||
|
||||
private final EdmStructuredTypeHelper helper;
|
||||
|
||||
private final EntityType entityType;
|
||||
|
||||
public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName name,
|
||||
final EntityType entityType) {
|
||||
|
||||
|
@ -50,9 +47,6 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
|
|||
instance.entityBaseType = null;
|
||||
|
||||
final List<PropertyRef> key = entityType.getKey();
|
||||
if (key == null && !entityType.isAbstract()) {
|
||||
throw new EdmException("Non-Abstract entity types must define a key.");
|
||||
}
|
||||
if (key != null) {
|
||||
final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>();
|
||||
for (PropertyRef ref : key) {
|
||||
|
@ -71,7 +65,6 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
|
|||
super(edm, name, entityType.getBaseType(), entityType.hasStream());
|
||||
|
||||
this.helper = new EdmStructuredTypeHelperImpl(edm, entityType);
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.olingo.server.core.edm.provider;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmMember;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
|
@ -34,7 +35,7 @@ public class EdmEnumTypeImpl extends AbstractEdmEnumType implements EdmEnumType
|
|||
|
||||
private final EnumType enumType;
|
||||
|
||||
public EdmEnumTypeImpl(final EdmProviderImpl edm, final FullQualifiedName enumName, final EnumType enumType) {
|
||||
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final EnumType enumType) {
|
||||
super(edm, enumName, enumType.isFlags());
|
||||
|
||||
if (enumType.getUnderlyingType() == null) {
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
@ -24,16 +24,16 @@ import org.apache.olingo.commons.api.edm.Edm;
|
|||
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.FullQualifiedName;
|
||||
import org.apache.olingo.server.api.edm.provider.FunctionImport;
|
||||
|
||||
public class EdmFunctionImportImpl extends EdmOperationImportImpl implements EdmFunctionImport {
|
||||
|
||||
private final FunctionImport functionImport;
|
||||
|
||||
public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
|
||||
final FunctionImport functionImport) {
|
||||
public EdmFunctionImportImpl(final Edm edm, final EdmEntityContainer container, final FunctionImport functionImport) {
|
||||
|
||||
super(edm, container, name, functionImport);
|
||||
super(edm, container, functionImport);
|
||||
this.functionImport = functionImport;
|
||||
}
|
||||
|
||||
|
@ -42,4 +42,13 @@ public class EdmFunctionImportImpl extends EdmOperationImportImpl implements Edm
|
|||
return edm.getFunction(functionImport.getFunction(), null, null, parameterNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludeInServiceDocument() {
|
||||
return functionImport.isIncludeInServiceDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FullQualifiedName getFunctionFqn() {
|
||||
return functionImport.getFunction();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
@ -59,9 +59,27 @@ public abstract class EdmOperationImpl extends AbstractEdmOperation {
|
|||
}
|
||||
|
||||
protected EdmOperationImpl(final Edm edm, final FullQualifiedName name, final Operation operation,
|
||||
final EdmTypeKind kind) {
|
||||
final EdmTypeKind kind) {
|
||||
|
||||
super(edm, name, kind);
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FullQualifiedName getBindingParameterTypeFqn() {
|
||||
if (isBound()) {
|
||||
Parameter bindingParameter = operation.getParameters().get(0);
|
||||
return bindingParameter.getType();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isBindingParameterTypeCollection() {
|
||||
if (isBound()) {
|
||||
Parameter bindingParameter = operation.getParameters().get(0);
|
||||
return bindingParameter.isCollection();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
@ -25,9 +25,8 @@ import org.apache.olingo.server.api.edm.provider.OperationImport;
|
|||
|
||||
public abstract class EdmOperationImportImpl extends AbstractEdmOperationImport {
|
||||
|
||||
public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container, final String name,
|
||||
final OperationImport operationImport) {
|
||||
|
||||
super(edm, container, name, operationImport.getEntitySet());
|
||||
public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container,
|
||||
final OperationImport operationImport) {
|
||||
super(edm, container, operationImport.getName(), operationImport.getEntitySet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
@ -32,6 +32,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityType;
|
|||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmException;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
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;
|
||||
|
@ -45,6 +46,7 @@ import org.apache.olingo.server.api.edm.provider.EntityType;
|
|||
import org.apache.olingo.server.api.edm.provider.EnumType;
|
||||
import org.apache.olingo.server.api.edm.provider.Function;
|
||||
import org.apache.olingo.server.api.edm.provider.Parameter;
|
||||
import org.apache.olingo.server.api.edm.provider.Schema;
|
||||
import org.apache.olingo.server.api.edm.provider.TypeDefinition;
|
||||
|
||||
public class EdmProviderImpl extends AbstractEdmImpl {
|
||||
|
@ -127,8 +129,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
|
|||
|
||||
@Override
|
||||
public EdmAction createBoundAction(final FullQualifiedName actionName,
|
||||
final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) {
|
||||
|
||||
final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) {
|
||||
|
||||
try {
|
||||
List<Action> actions = actionsMap.get(actionName);
|
||||
if (actions == null) {
|
||||
|
@ -145,8 +147,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
|
|||
final List<Parameter> 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);
|
||||
}
|
||||
|
||||
|
@ -160,9 +162,9 @@ public class EdmProviderImpl extends AbstractEdmImpl {
|
|||
|
||||
@Override
|
||||
public EdmFunction createBoundFunction(final FullQualifiedName functionName,
|
||||
final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection,
|
||||
final List<String> parameterNames) {
|
||||
|
||||
final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection,
|
||||
final List<String> parameterNames) {
|
||||
|
||||
try {
|
||||
List<Function> functions = functionsMap.get(functionName);
|
||||
if (functions == null) {
|
||||
|
@ -173,7 +175,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
|
|||
functionsMap.put(functionName, functions);
|
||||
}
|
||||
}
|
||||
final List<String> parameterNamesCopy = parameterNames == null? Collections.<String>emptyList(): parameterNames;
|
||||
final List<String> parameterNamesCopy =
|
||||
parameterNames == null ? Collections.<String> emptyList() : parameterNames;
|
||||
for (Function function : functions) {
|
||||
if (function.isBound()) {
|
||||
List<Parameter> providerParameters = function.getParameters();
|
||||
|
@ -182,8 +185,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
|
|||
}
|
||||
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<String> providerParameterNames = new ArrayList<String>();
|
||||
for (int i = 1; i < providerParameters.size(); i++) {
|
||||
|
@ -259,7 +262,8 @@ public class EdmProviderImpl extends AbstractEdmImpl {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
final List<String> parameterNamesCopy = parameterNames == null? Collections.<String>emptyList(): parameterNames;
|
||||
final List<String> parameterNamesCopy =
|
||||
parameterNames == null ? Collections.<String> emptyList() : parameterNames;
|
||||
for (Function function : functions) {
|
||||
if (!function.isBound()) {
|
||||
List<Parameter> providerParameters = function.getParameters();
|
||||
|
@ -284,4 +288,16 @@ public class EdmProviderImpl extends AbstractEdmImpl {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmSchema> createSchemas() {
|
||||
try {
|
||||
List<EdmSchema> schemas = new ArrayList<EdmSchema>();
|
||||
for (Schema schema : provider.getSchemas()) {
|
||||
schemas.add(new EdmSchemaImpl(this, provider, schema));
|
||||
}
|
||||
return schemas;
|
||||
} catch (ODataException e) {
|
||||
throw new EdmException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core.edm.provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.core.edm.AbstractEdmSchemaImpl;
|
||||
import org.apache.olingo.server.api.edm.provider.Action;
|
||||
import org.apache.olingo.server.api.edm.provider.ComplexType;
|
||||
import org.apache.olingo.server.api.edm.provider.EdmProvider;
|
||||
import org.apache.olingo.server.api.edm.provider.EntityType;
|
||||
import org.apache.olingo.server.api.edm.provider.EnumType;
|
||||
import org.apache.olingo.server.api.edm.provider.Function;
|
||||
import org.apache.olingo.server.api.edm.provider.Schema;
|
||||
import org.apache.olingo.server.api.edm.provider.TypeDefinition;
|
||||
|
||||
public class EdmSchemaImpl extends AbstractEdmSchemaImpl {
|
||||
|
||||
private final Schema schema;
|
||||
private final Edm edm;
|
||||
private final EdmProvider provider;
|
||||
|
||||
public EdmSchemaImpl(Edm edm, EdmProvider provider, Schema schema) {
|
||||
super(schema.getNamespace(), schema.getAlias());
|
||||
this.edm = edm;
|
||||
this.provider = provider;
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EdmEntityContainer createEntityContainer() {
|
||||
if (schema.getEntityContainer() != null) {
|
||||
FullQualifiedName containerFQN =
|
||||
new FullQualifiedName(namespace, schema.getEntityContainer().getName());
|
||||
return new EdmEntityContainerImpl(edm, provider, containerFQN, schema.getEntityContainer());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmTypeDefinition> createTypeDefinitions() {
|
||||
List<EdmTypeDefinition> typeDefinitions = new ArrayList<EdmTypeDefinition>();
|
||||
List<TypeDefinition> providerTypeDefinitions = schema.getTypeDefinitions();
|
||||
if (providerTypeDefinitions != null) {
|
||||
for (TypeDefinition def : providerTypeDefinitions) {
|
||||
typeDefinitions.add(new EdmTypeDefinitionImpl(edm, new FullQualifiedName("namespace", def.getName()), def));
|
||||
}
|
||||
}
|
||||
return typeDefinitions;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmEnumType> createEnumTypes() {
|
||||
List<EdmEnumType> enumTypes = new ArrayList<EdmEnumType>();
|
||||
List<EnumType> providerEnumTypes = schema.getEnumTypes();
|
||||
if (providerEnumTypes != null) {
|
||||
for (EnumType enumType : providerEnumTypes) {
|
||||
enumTypes.add(new EdmEnumTypeImpl(edm, new FullQualifiedName(namespace, enumType.getName()), enumType));
|
||||
}
|
||||
}
|
||||
return enumTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmEntityType> createEntityTypes() {
|
||||
List<EdmEntityType> entityTypes = new ArrayList<EdmEntityType>();
|
||||
List<EntityType> providerEntityTypes = schema.getEntityTypes();
|
||||
if (providerEntityTypes != null) {
|
||||
for (EntityType entityType : providerEntityTypes) {
|
||||
entityTypes.add(EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName(namespace, entityType.getName()),
|
||||
entityType));
|
||||
}
|
||||
}
|
||||
return entityTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmComplexType> createComplexTypes() {
|
||||
List<EdmComplexType> complexTypes = new ArrayList<EdmComplexType>();
|
||||
List<ComplexType> providerComplexTypes = schema.getComplexTypes();
|
||||
if (providerComplexTypes != null) {
|
||||
for (ComplexType complexType : providerComplexTypes) {
|
||||
complexTypes.add(EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName(namespace, complexType.getName()),
|
||||
complexType));
|
||||
}
|
||||
}
|
||||
return complexTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmAction> createActions() {
|
||||
List<EdmAction> actions = new ArrayList<EdmAction>();
|
||||
List<Action> providerActions = schema.getActions();
|
||||
if (providerActions != null) {
|
||||
for (Action action : providerActions) {
|
||||
actions.add(EdmActionImpl.getInstance(edm, new FullQualifiedName(namespace, action.getName()), action));
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<EdmFunction> createFunctions() {
|
||||
List<EdmFunction> functions = new ArrayList<EdmFunction>();
|
||||
List<Function> providerFunctions = schema.getFunctions();
|
||||
if (providerFunctions != null) {
|
||||
for (Function function : providerFunctions) {
|
||||
functions.add(EdmFunctionImpl.getInstance(edm, new FullQualifiedName(namespace, function.getName()), function));
|
||||
}
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
@ -34,21 +34,22 @@ public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition implements
|
|||
private EdmPrimitiveType edmPrimitiveTypeInstance;
|
||||
|
||||
public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName,
|
||||
final TypeDefinition typeDefinition) {
|
||||
final TypeDefinition typeDefinition) {
|
||||
|
||||
super(edm, typeDefinitionName);
|
||||
this.typeDefinition = typeDefinition;
|
||||
// TODO: Should we check for edmNamespace in the underlying type name?
|
||||
try {
|
||||
edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.valueOf(
|
||||
typeDefinition.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance();
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new EdmException("Invalid underlying type: " + typeDefinitionName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmPrimitiveType getUnderlyingType() {
|
||||
if (edmPrimitiveTypeInstance == null) {
|
||||
try {
|
||||
edmPrimitiveTypeInstance = EdmPrimitiveTypeKind.valueOf(
|
||||
typeDefinition.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance();
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
|
||||
}
|
||||
}
|
||||
return edmPrimitiveTypeInstance;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmSingleton;
|
||||
import org.apache.olingo.server.api.ODataFormat;
|
||||
import org.apache.olingo.server.api.ODataSerializer;
|
||||
import org.apache.olingo.server.api.ODataServer;
|
||||
import org.apache.olingo.server.core.testutil.StringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ServiceDocumentTest {
|
||||
|
||||
private Edm edm;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
|
||||
EdmEntitySet edmEntitySet1 = mock(EdmEntitySet.class);
|
||||
when(edmEntitySet1.getName()).thenReturn("entitySetName1");
|
||||
when(edmEntitySet1.isIncludeInServiceDocument()).thenReturn(true);
|
||||
|
||||
EdmEntitySet edmEntitySet2 = mock(EdmEntitySet.class);
|
||||
when(edmEntitySet2.getName()).thenReturn("entitySetName2");
|
||||
when(edmEntitySet2.isIncludeInServiceDocument()).thenReturn(true);
|
||||
|
||||
EdmEntitySet edmEntitySet3 = mock(EdmEntitySet.class);
|
||||
when(edmEntitySet3.getName()).thenReturn("entitySetName3");
|
||||
when(edmEntitySet3.isIncludeInServiceDocument()).thenReturn(false);
|
||||
|
||||
List<EdmEntitySet> entitySets = new ArrayList<EdmEntitySet>();
|
||||
entitySets.add(edmEntitySet1);
|
||||
entitySets.add(edmEntitySet2);
|
||||
entitySets.add(edmEntitySet3);
|
||||
|
||||
EdmFunctionImport functionImport1 = mock(EdmFunctionImport.class);
|
||||
when(functionImport1.getName()).thenReturn("functionImport1");
|
||||
when(functionImport1.isIncludeInServiceDocument()).thenReturn(true);
|
||||
|
||||
EdmFunctionImport functionImport2 = mock(EdmFunctionImport.class);
|
||||
when(functionImport2.getName()).thenReturn("functionImport2");
|
||||
when(functionImport2.isIncludeInServiceDocument()).thenReturn(true);
|
||||
|
||||
EdmFunctionImport functionImport3 = mock(EdmFunctionImport.class);
|
||||
when(functionImport3.getName()).thenReturn("functionImport3");
|
||||
when(functionImport3.isIncludeInServiceDocument()).thenReturn(false);
|
||||
|
||||
List<EdmFunctionImport> functionImports = new ArrayList<EdmFunctionImport>();
|
||||
functionImports.add(functionImport1);
|
||||
functionImports.add(functionImport2);
|
||||
functionImports.add(functionImport3);
|
||||
|
||||
EdmSingleton singleton1 = mock(EdmSingleton.class);
|
||||
when(singleton1.getName()).thenReturn("singleton1");
|
||||
|
||||
EdmSingleton singleton2 = mock(EdmSingleton.class);
|
||||
when(singleton2.getName()).thenReturn("singleton2");
|
||||
|
||||
EdmSingleton singleton3 = mock(EdmSingleton.class);
|
||||
when(singleton3.getName()).thenReturn("singleton3");
|
||||
|
||||
List<EdmSingleton> singletons = new ArrayList<EdmSingleton>();
|
||||
singletons.add(singleton1);
|
||||
singletons.add(singleton2);
|
||||
singletons.add(singleton3);
|
||||
|
||||
EdmEntityContainer edmEntityContainer = mock(EdmEntityContainer.class);
|
||||
when(edmEntityContainer.getEntitySets()).thenReturn(entitySets);
|
||||
when(edmEntityContainer.getFunctionImports()).thenReturn(functionImports);
|
||||
when(edmEntityContainer.getSingletons()).thenReturn(singletons);
|
||||
|
||||
edm = mock(Edm.class);
|
||||
when(edm.getEntityContainer(null)).thenReturn(edmEntityContainer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeServiceDocumentJson() throws Exception {
|
||||
String serviceRoot = "http://localhost:8080/odata.svc";
|
||||
|
||||
ODataServer server = ODataServer.newInstance();
|
||||
assertNotNull(server);
|
||||
|
||||
ODataSerializer serializer = server.getSerializer(ODataFormat.JSON);
|
||||
assertNotNull(serializer);
|
||||
|
||||
InputStream result = serializer.serviceDocument(edm, serviceRoot);
|
||||
assertNotNull(result);
|
||||
String jsonString = StringUtils.inputStreamToString(result, true);
|
||||
|
||||
assertTrue(jsonString.contains("entitySetName1"));
|
||||
assertTrue(jsonString.contains("entitySetName2"));
|
||||
assertFalse(jsonString.contains("entitySetName3"));
|
||||
|
||||
assertTrue(jsonString.contains("functionImport1"));
|
||||
assertTrue(jsonString.contains("functionImport2"));
|
||||
assertFalse(jsonString.contains("functionImport3"));
|
||||
|
||||
assertTrue(jsonString.contains("singleton1"));
|
||||
assertTrue(jsonString.contains("singleton2"));
|
||||
assertTrue(jsonString.contains("singleton3"));
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
@ -52,8 +52,8 @@ public class EdmActionImportImplTest {
|
|||
FullQualifiedName actionFqn = new FullQualifiedName("namespace", "actionName");
|
||||
FullQualifiedName entityContainerFqn = new FullQualifiedName("namespace", "containerName");
|
||||
Target target = new Target().setEntityContainer(entityContainerFqn).setTargetName("entitySetName");
|
||||
ActionImport providerActionImport
|
||||
= new ActionImport().setName("actionImportName").setAction(actionFqn).setEntitySet(target);
|
||||
ActionImport providerActionImport =
|
||||
new ActionImport().setName("actionImportName").setAction(actionFqn).setEntitySet(target);
|
||||
|
||||
EdmProviderImpl edm = mock(EdmProviderImpl.class);
|
||||
container = mock(EdmEntityContainer.class);
|
||||
|
@ -63,7 +63,7 @@ public class EdmActionImportImplTest {
|
|||
|
||||
entitySet = mock(EdmEntitySet.class);
|
||||
when(container.getEntitySet("entitySetName")).thenReturn(entitySet);
|
||||
actionImport = new EdmActionImportImpl(edm, container, "actionImportName", providerActionImport);
|
||||
actionImport = new EdmActionImportImpl(edm, container, providerActionImport);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -87,8 +87,8 @@ public class EdmActionImportImplTest {
|
|||
public void getReturnedEntitySetNonExistingContainer() {
|
||||
Target target = new Target();
|
||||
ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target);
|
||||
EdmActionImport actionImport
|
||||
= new EdmActionImportImpl(mock(EdmProviderImpl.class), container, "actionImportName", providerActionImport);
|
||||
EdmActionImport actionImport =
|
||||
new EdmActionImportImpl(mock(EdmProviderImpl.class), container, providerActionImport);
|
||||
actionImport.getReturnedEntitySet();
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class EdmActionImportImplTest {
|
|||
ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target);
|
||||
EdmProviderImpl edm = mock(EdmProviderImpl.class);
|
||||
when(edm.getEntityContainer(null)).thenReturn(container);
|
||||
EdmActionImport actionImport = new EdmActionImportImpl(edm, container, "actionImportName", providerActionImport);
|
||||
EdmActionImport actionImport = new EdmActionImportImpl(edm, container, providerActionImport);
|
||||
actionImport.getReturnedEntitySet();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@ import static org.junit.Assert.fail;
|
|||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataException;
|
||||
import org.apache.olingo.commons.api.edm.EdmActionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
|
@ -36,6 +39,7 @@ import org.apache.olingo.commons.api.edm.EdmSingleton;
|
|||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.server.api.edm.provider.ActionImport;
|
||||
import org.apache.olingo.server.api.edm.provider.EdmProvider;
|
||||
import org.apache.olingo.server.api.edm.provider.EntityContainer;
|
||||
import org.apache.olingo.server.api.edm.provider.EntityContainerInfo;
|
||||
import org.apache.olingo.server.api.edm.provider.EntitySet;
|
||||
import org.apache.olingo.server.api.edm.provider.FunctionImport;
|
||||
|
@ -57,6 +61,110 @@ public class EdmEntityContainerImplTest {
|
|||
new EntityContainerInfo().setContainerName(new FullQualifiedName("space", "name"));
|
||||
container = new EdmEntityContainerImpl(edm, provider, entityContainerInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllEntitySetInitial(){
|
||||
List<EdmEntitySet> entitySets = container.getEntitySets();
|
||||
assertNotNull(entitySets);
|
||||
assertEquals(2, entitySets.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllEntitySetsAfterOneWasAlreadyLoaded(){
|
||||
EdmEntitySet entitySet = container.getEntitySet("entitySetName");
|
||||
List<EdmEntitySet> entitySets = container.getEntitySets();
|
||||
assertNotNull(entitySets);
|
||||
assertEquals(2, entitySets.size());
|
||||
boolean contained = false;
|
||||
for(EdmEntitySet es: entitySets){
|
||||
//Already loaded entity set must be the same
|
||||
if(es.getName().equals("entitySetName")){
|
||||
assertTrue(entitySet == es);
|
||||
contained = true;
|
||||
}
|
||||
}
|
||||
if(!contained){
|
||||
fail("Should have found entity set in this list.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllSingletonsInitial(){
|
||||
List<EdmSingleton> singletons = container.getSingletons();
|
||||
assertNotNull(singletons);
|
||||
assertEquals(2, singletons.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllSingletonsAfterOneWasAlreadyLoaded(){
|
||||
EdmSingleton singleton = container.getSingleton("singletonName");
|
||||
List<EdmSingleton> singletons = container.getSingletons();
|
||||
assertNotNull(singletons);
|
||||
assertEquals(2, singletons.size());
|
||||
boolean contained = false;
|
||||
for(EdmSingleton s: singletons){
|
||||
//Already loaded singleton must be the same
|
||||
if(s.getName().equals("singletonName")){
|
||||
assertTrue(singleton == s);
|
||||
contained = true;
|
||||
}
|
||||
}
|
||||
if(!contained){
|
||||
fail("Should have found singleton in this list.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllActionImportsInitial(){
|
||||
List<EdmActionImport> actionImports = container.getActionImports();
|
||||
assertNotNull(actionImports);
|
||||
assertEquals(2, actionImports.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllActionImportsAfterOneWasAlreadyLoaded(){
|
||||
EdmActionImport actionImport = container.getActionImport("actionImportName");
|
||||
List<EdmActionImport> actionImports = container.getActionImports();
|
||||
assertNotNull(actionImports);
|
||||
assertEquals(2, actionImports.size());
|
||||
boolean contained = false;
|
||||
for(EdmActionImport ai: actionImports){
|
||||
//Already loaded action import must be the same
|
||||
if(ai.getName().equals("actionImportName")){
|
||||
assertTrue(actionImport == ai);
|
||||
contained = true;
|
||||
}
|
||||
}
|
||||
if(!contained){
|
||||
fail("Should have found action import in this list.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllFunctionImportsInitial(){
|
||||
List<EdmFunctionImport> functionImports = container.getFunctionImports();
|
||||
assertNotNull(functionImports);
|
||||
assertEquals(2, functionImports.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllFunctionImportsAfterOneWasAlreadyLoaded(){
|
||||
EdmFunctionImport functionImport = container.getFunctionImport("functionImportName");
|
||||
List<EdmFunctionImport> functionImports = container.getFunctionImports();
|
||||
assertNotNull(functionImports);
|
||||
assertEquals(2, functionImports.size());
|
||||
boolean contained = false;
|
||||
for(EdmFunctionImport fi: functionImports){
|
||||
//Already loaded function import must be the same
|
||||
if(fi.getName().equals("functionImportName")){
|
||||
assertTrue(functionImport == fi);
|
||||
contained = true;
|
||||
}
|
||||
}
|
||||
if(!contained){
|
||||
fail("Should have found function import in this list.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkEdmExceptionConversion() throws Exception {
|
||||
|
@ -190,7 +298,7 @@ public class EdmEntityContainerImplTest {
|
|||
public ActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName)
|
||||
throws ODataException {
|
||||
if (actionImportName != null) {
|
||||
return new ActionImport().setName("singletonName");
|
||||
return new ActionImport().setName("actionImportName");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -199,9 +307,35 @@ public class EdmEntityContainerImplTest {
|
|||
public FunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName)
|
||||
throws ODataException {
|
||||
if (functionImportName != null) {
|
||||
return new FunctionImport().setName("singletonName");
|
||||
return new FunctionImport().setName("functionImportName");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityContainer getEntityContainer() throws ODataException {
|
||||
EntityContainer container = new EntityContainer();
|
||||
List<EntitySet> entitySets = new ArrayList<EntitySet>();
|
||||
entitySets.add(new EntitySet().setName("entitySetName"));
|
||||
entitySets.add(new EntitySet().setName("entitySetName2"));
|
||||
container.setEntitySets(entitySets );
|
||||
|
||||
List<Singleton> singletons = new ArrayList<Singleton>();
|
||||
singletons.add(new Singleton().setName("singletonName"));
|
||||
singletons.add(new Singleton().setName("singletonName2"));
|
||||
container.setSingletons(singletons );
|
||||
|
||||
List<ActionImport> actionImports = new ArrayList<ActionImport>();
|
||||
actionImports.add(new ActionImport().setName("actionImportName"));
|
||||
actionImports.add(new ActionImport().setName("actionImportName2"));
|
||||
container.setActionImports(actionImports );
|
||||
|
||||
List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
|
||||
functionImports.add(new FunctionImport().setName("functionImportName"));
|
||||
functionImports.add(new FunctionImport().setName("functionImportName2"));
|
||||
container.setFunctionImports(functionImports );
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,13 +244,6 @@ public class EdmEntityTypeImplTest {
|
|||
assertTrue(property == typeWithBaseType.getProperty("nav2"));
|
||||
}
|
||||
|
||||
@Test(expected = EdmException.class)
|
||||
public void noKeyOnTypeWithoutBaseTypeMustResultInException() {
|
||||
EdmProviderImpl edm = mock(EdmProviderImpl.class);
|
||||
EntityType entityType = new EntityType().setName("n");
|
||||
EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void abstractTypeDoesNotNeedKey() {
|
||||
EdmProviderImpl edm = mock(EdmProviderImpl.class);
|
||||
|
|
|
@ -72,9 +72,9 @@ public class EdmFunctionImportImplTest {
|
|||
when(provider.getFunctionImport(containerName, functionImportName)).thenReturn(functionImportProvider);
|
||||
|
||||
final EdmFunctionImport functionImport =
|
||||
new EdmFunctionImportImpl(edm, entityContainer, "test", functionImportProvider);
|
||||
new EdmFunctionImportImpl(edm, entityContainer, functionImportProvider);
|
||||
assertEquals(functionImportName, entityContainer.getFunctionImport(functionImportName).getName());
|
||||
assertEquals("test", functionImport.getName());
|
||||
assertEquals("functionImport", functionImport.getName());
|
||||
final EdmFunction function = functionImport.getFunction(Collections.<String> emptyList());
|
||||
assertEquals(functionName.getNamespace(), function.getNamespace());
|
||||
assertEquals(functionName.getName(), function.getName());
|
||||
|
|
|
@ -0,0 +1,337 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core.edm.provider;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataException;
|
||||
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.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmSchema;
|
||||
import org.apache.olingo.commons.api.edm.EdmSingleton;
|
||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.server.api.edm.provider.Action;
|
||||
import org.apache.olingo.server.api.edm.provider.ActionImport;
|
||||
import org.apache.olingo.server.api.edm.provider.AliasInfo;
|
||||
import org.apache.olingo.server.api.edm.provider.ComplexType;
|
||||
import org.apache.olingo.server.api.edm.provider.EdmProvider;
|
||||
import org.apache.olingo.server.api.edm.provider.EntityContainer;
|
||||
import org.apache.olingo.server.api.edm.provider.EntityContainerInfo;
|
||||
import org.apache.olingo.server.api.edm.provider.EntitySet;
|
||||
import org.apache.olingo.server.api.edm.provider.EntityType;
|
||||
import org.apache.olingo.server.api.edm.provider.EnumType;
|
||||
import org.apache.olingo.server.api.edm.provider.Function;
|
||||
import org.apache.olingo.server.api.edm.provider.FunctionImport;
|
||||
import org.apache.olingo.server.api.edm.provider.Schema;
|
||||
import org.apache.olingo.server.api.edm.provider.Singleton;
|
||||
import org.apache.olingo.server.api.edm.provider.Term;
|
||||
import org.apache.olingo.server.api.edm.provider.TypeDefinition;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmSchemaImplTest {
|
||||
|
||||
private EdmSchema schema;
|
||||
private Edm edm;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
EdmProvider provider = new LocalProvider();
|
||||
edm = new EdmProviderImpl(provider);
|
||||
schema = edm.getSchemas().get(0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialSchemaTest() {
|
||||
EdmProvider provider = mock(EdmProvider.class);
|
||||
edm = new EdmProviderImpl(provider);
|
||||
edm.getSchemas();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptySchemaTest() throws Exception {
|
||||
ArrayList<Schema> schemas = new ArrayList<Schema>();
|
||||
Schema providerSchema = new Schema();
|
||||
schemas.add(providerSchema );
|
||||
EdmProvider provider = mock(EdmProvider.class);
|
||||
when(provider.getSchemas()).thenReturn(schemas);
|
||||
edm = new EdmProviderImpl(provider);
|
||||
edm.getSchemas();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicGetters() {
|
||||
assertEquals("namespace", schema.getNamespace());
|
||||
assertEquals("alias", schema.getAlias());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTypeDefinitions(){
|
||||
List<EdmTypeDefinition> typeDefinitions = schema.getTypeDefinitions();
|
||||
assertNotNull(typeDefinitions);
|
||||
assertEquals(2, typeDefinitions.size());
|
||||
|
||||
for(EdmTypeDefinition def : typeDefinitions){
|
||||
assertTrue(def == edm.getTypeDefinition(new FullQualifiedName("namespace", def.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEnumTypes() {
|
||||
List<EdmEnumType> enumTypes = schema.getEnumTypes();
|
||||
assertNotNull(enumTypes);
|
||||
assertEquals(2, enumTypes.size());
|
||||
|
||||
for (EdmEnumType enumType : enumTypes) {
|
||||
assertTrue(enumType == edm.getEnumType(new FullQualifiedName("namespace", enumType.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntityTypes() {
|
||||
List<EdmEntityType> entityTypes = schema.getEntityTypes();
|
||||
assertNotNull(entityTypes);
|
||||
assertEquals(2, entityTypes.size());
|
||||
|
||||
for (EdmEntityType entityType : entityTypes) {
|
||||
assertTrue(entityType == edm.getEntityType(new FullQualifiedName("namespace", entityType.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getComplexTypes() {
|
||||
List<EdmComplexType> complexTypes = schema.getComplexTypes();
|
||||
assertNotNull(complexTypes);
|
||||
assertEquals(2, complexTypes.size());
|
||||
|
||||
for (EdmComplexType complexType : complexTypes) {
|
||||
assertTrue(complexType == edm.getComplexType(new FullQualifiedName("namespace", complexType.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getActions() {
|
||||
List<EdmAction> actions = schema.getActions();
|
||||
assertNotNull(actions);
|
||||
assertEquals(2, actions.size());
|
||||
|
||||
for (EdmAction action : actions) {
|
||||
assertTrue(action == edm.getAction(new FullQualifiedName("namespace", action.getName()), null, null));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFunctions() {
|
||||
List<EdmFunction> functions = schema.getFunctions();
|
||||
assertNotNull(functions);
|
||||
assertEquals(2, functions.size());
|
||||
|
||||
for (EdmFunction function : functions) {
|
||||
FullQualifiedName functionName = new FullQualifiedName("namespace", function.getName());
|
||||
assertTrue(function == edm.getFunction(functionName, null, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContainer() {
|
||||
EdmEntityContainer container = schema.getEntityContainer();
|
||||
assertNotNull(container);
|
||||
|
||||
List<EdmEntitySet> entitySets = container.getEntitySets();
|
||||
assertNotNull(entitySets);
|
||||
assertEquals(2, entitySets.size());
|
||||
for (EdmEntitySet obj : entitySets) {
|
||||
assertNotNull(obj.getEntityType());
|
||||
}
|
||||
|
||||
List<EdmSingleton> singletons = container.getSingletons();
|
||||
assertNotNull(singletons);
|
||||
assertEquals(2, singletons.size());
|
||||
for (EdmSingleton obj : singletons) {
|
||||
assertNotNull(obj.getEntityType());
|
||||
}
|
||||
|
||||
List<EdmActionImport> actionImports = container.getActionImports();
|
||||
assertNotNull(actionImports);
|
||||
assertEquals(2, actionImports.size());
|
||||
for (EdmActionImport obj : actionImports) {
|
||||
assertNotNull(obj.getAction());
|
||||
}
|
||||
|
||||
List<EdmFunctionImport> functionImports = container.getFunctionImports();
|
||||
assertNotNull(functionImports);
|
||||
assertEquals(2, functionImports.size());
|
||||
for (EdmFunctionImport obj : functionImports) {
|
||||
assertNotNull(obj.getFunctionFqn());
|
||||
}
|
||||
|
||||
assertTrue(container == edm.getEntityContainer(new FullQualifiedName(schema.getNamespace(), container.getName())));
|
||||
assertTrue(container == edm.getEntityContainer(null));
|
||||
}
|
||||
|
||||
private class LocalProvider extends EdmProvider {
|
||||
|
||||
public EnumType getEnumType(final FullQualifiedName enumTypeName) throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public TypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public EntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public List<Action> getActions(final FullQualifiedName actionName) throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public List<Function> getFunctions(final FullQualifiedName functionName) throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public Term getTerm(final FullQualifiedName termName) throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
|
||||
throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public Singleton getSingleton(final FullQualifiedName entityContainer, final String singletonName)
|
||||
throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public ActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName)
|
||||
throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public FunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName)
|
||||
throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public EntityContainerInfo getEntityContainerInfo(final FullQualifiedName entityContainerName)
|
||||
throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public List<AliasInfo> getAliasInfos() throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
|
||||
public List<Schema> getSchemas() throws ODataException {
|
||||
Schema providerSchema = new Schema();
|
||||
providerSchema.setNamespace("namespace");
|
||||
providerSchema.setAlias("alias");
|
||||
EntityContainer container = new EntityContainer().setName("container");
|
||||
|
||||
List<EntitySet> entitySets = new ArrayList<EntitySet>();
|
||||
entitySets.add(new EntitySet().setName("entitySetName")
|
||||
.setType(new FullQualifiedName("namespace", "entityType1")));
|
||||
entitySets
|
||||
.add(new EntitySet().setName("entitySetName2").setType(new FullQualifiedName("namespace", "entityType2")));
|
||||
container.setEntitySets(entitySets);
|
||||
|
||||
List<Singleton> singletons = new ArrayList<Singleton>();
|
||||
singletons.add(new Singleton().setName("singletonName")
|
||||
.setType(new FullQualifiedName("namespace", "entityType1")));
|
||||
singletons
|
||||
.add(new Singleton().setName("singletonName2").setType(new FullQualifiedName("namespace", "entityType2")));
|
||||
container.setSingletons(singletons);
|
||||
|
||||
List<ActionImport> actionImports = new ArrayList<ActionImport>();
|
||||
actionImports.add(new ActionImport().setName("actionImportName").setAction(
|
||||
new FullQualifiedName("namespace", "action1")));
|
||||
actionImports.add(new ActionImport().setName("actionImportName2").setAction(
|
||||
new FullQualifiedName("namespace", "action2")));
|
||||
container.setActionImports(actionImports);
|
||||
|
||||
List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
|
||||
functionImports.add(new FunctionImport().setName("functionImportName").setFunction(
|
||||
new FullQualifiedName("namespace", "function1")));
|
||||
functionImports.add(new FunctionImport().setName("functionImportName2").setFunction(
|
||||
new FullQualifiedName("namespace", "function2")));
|
||||
container.setFunctionImports(functionImports);
|
||||
providerSchema.setEntityContainer(container);
|
||||
|
||||
List<TypeDefinition> typeDefinitions = new ArrayList<TypeDefinition>();
|
||||
typeDefinitions.add(new TypeDefinition().setName("typeDefinition1"));
|
||||
typeDefinitions.add(new TypeDefinition().setName("typeDefinition2"));
|
||||
providerSchema.setTypeDefinitions(typeDefinitions);
|
||||
|
||||
List<EnumType> enumTypes = new ArrayList<EnumType>();
|
||||
enumTypes.add(new EnumType().setName("enumType1"));
|
||||
enumTypes.add(new EnumType().setName("enumType2"));
|
||||
providerSchema.setEnumTypes(enumTypes);
|
||||
|
||||
List<EntityType> entityTypes = new ArrayList<EntityType>();
|
||||
entityTypes.add(new EntityType().setName("entityType1"));
|
||||
entityTypes.add(new EntityType().setName("entityType2"));
|
||||
providerSchema.setEntityTypes(entityTypes);
|
||||
|
||||
List<ComplexType> complexTypes = new ArrayList<ComplexType>();
|
||||
complexTypes.add(new ComplexType().setName("complexType1"));
|
||||
complexTypes.add(new ComplexType().setName("complexType2"));
|
||||
providerSchema.setComplexTypes(complexTypes);
|
||||
|
||||
List<Action> actions = new ArrayList<Action>();
|
||||
actions.add(new Action().setName("action1"));
|
||||
actions.add(new Action().setName("action2"));
|
||||
providerSchema.setActions(actions);
|
||||
|
||||
List<Function> functions = new ArrayList<Function>();
|
||||
functions.add(new Function().setName("function1"));
|
||||
functions.add(new Function().setName("function2"));
|
||||
providerSchema.setFunctions(functions);
|
||||
ArrayList<Schema> schemas = new ArrayList<Schema>();
|
||||
schemas.add(providerSchema);
|
||||
return schemas;
|
||||
}
|
||||
|
||||
public EntityContainer getEntityContainer() throws ODataException {
|
||||
throw new RuntimeException("Provider must not be called in the schema case");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -69,7 +69,8 @@ public class EdmTypeDefinitionImplTest {
|
|||
FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
|
||||
TypeDefinition providerTypeDef =
|
||||
new TypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("wrong", "wrong"));
|
||||
new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
|
||||
EdmTypeDefinitionImpl def = new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
|
||||
def.getUnderlyingType();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core.testutil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
public static String inputStreamToString(final InputStream in, final boolean preserveLineBreaks) {
|
||||
try {
|
||||
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
String line = null;
|
||||
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
stringBuilder.append(line);
|
||||
if (preserveLineBreaks) {
|
||||
stringBuilder.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
bufferedReader.close();
|
||||
|
||||
final String result = stringBuilder.toString();
|
||||
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue