You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/04/04 19:05:07 UTC
[01/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Star deleting
unnecessary abstract edm classes
Repository: olingo-odata4
Updated Branches:
refs/heads/OLINGO-549-ODataV4-JPA b0a6b8478 -> 758143fd2
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
index 5c9e2c1..a8bb8d9 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
@@ -18,25 +18,29 @@
*/
package org.apache.olingo.commons.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.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.commons.api.edm.EdmReferentialConstraint;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.NavigationProperty;
import org.apache.olingo.commons.api.edm.provider.ReferentialConstraint;
-import org.apache.olingo.commons.core.edm.AbstractEdmNavigationProperty;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-
-import java.util.ArrayList;
-import java.util.List;
-public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty {
+public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavigationProperty {
private final FullQualifiedName structuredTypeName;
private final NavigationProperty navigationProperty;
private List<EdmReferentialConstraint> referentialConstraints;
private final EdmAnnotationHelper helper;
+ private EdmEntityType typeImpl;
+ private EdmNavigationProperty partnerNavigationProperty;
public EdmNavigationPropertyImpl(
final Edm edm, final FullQualifiedName structuredTypeName, final NavigationProperty navigationProperty) {
@@ -47,11 +51,6 @@ public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty {
}
@Override
- protected FullQualifiedName getTypeFQN() {
- return navigationProperty.getTypeFQN();
- }
-
- @Override
public boolean isCollection() {
return navigationProperty.isCollection();
}
@@ -67,8 +66,36 @@ public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty {
}
@Override
- protected String internatGetPartner() {
- return navigationProperty.getPartner();
+ public EdmEntityType getType() {
+ if (typeImpl == null) {
+ typeImpl = edm.getEntityType(navigationProperty.getTypeFQN());
+ if (typeImpl == null) {
+ throw new EdmException("Cannot find type with name: " + navigationProperty.getTypeFQN());
+ }
+ }
+ return typeImpl;
+ }
+
+ @Override
+ public EdmNavigationProperty getPartner() {
+ if (partnerNavigationProperty == null) {
+ String partner = navigationProperty.getPartner();
+ if (partner != null) {
+ EdmStructuredType type = getType();
+ EdmNavigationProperty property = null;
+ final String[] split = partner.split("/");
+ for (String element : split) {
+ property = type.getNavigationProperty(element);
+ if (property == null) {
+ throw new EdmException("Cannot find navigation property with name: " + element
+ + " at type " + type.getName());
+ }
+ type = property.getType();
+ }
+ partnerNavigationProperty = property;
+ }
+ }
+ return partnerNavigationProperty;
}
@Override
@@ -91,8 +118,7 @@ public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty {
referentialConstraints = new ArrayList<EdmReferentialConstraint>();
if (providerConstraints != null) {
for (ReferentialConstraint constraint : providerConstraints) {
- referentialConstraints.add(
- new EdmReferentialConstraintImpl(edm, constraint));
+ referentialConstraints.add(new EdmReferentialConstraintImpl(edm, constraint));
}
}
}
@@ -100,6 +126,16 @@ public class EdmNavigationPropertyImpl extends AbstractEdmNavigationProperty {
}
@Override
+ public TargetType getAnnotationsTargetType() {
+ return TargetType.NavigationProperty;
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return getName();
+ }
+
+ @Override
public FullQualifiedName getAnnotationsTargetFQN() {
return structuredTypeName;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
index 009eadc..f8d69bf 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
@@ -19,23 +19,33 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmOperation;
import org.apache.olingo.commons.api.edm.EdmParameter;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.Operation;
import org.apache.olingo.commons.api.edm.provider.Parameter;
-import org.apache.olingo.commons.core.edm.AbstractEdmOperation;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-public abstract class EdmOperationImpl extends AbstractEdmOperation {
+public abstract class EdmOperationImpl extends EdmTypeImpl implements EdmOperation {
protected final Operation operation;
protected final EdmAnnotationHelper helper;
+ private final Map<String, EdmParameter> parameters = new LinkedHashMap<String, EdmParameter>();
+ private String entitySetPath;
+ private boolean isBound;
+ private EdmReturnType returnType;
+ private List<String> parameterNames;
protected static <T extends EdmOperationImpl> T getInstance(final T instance) {
final List<Parameter> providerParameters = instance.operation.getParameters();
@@ -68,6 +78,68 @@ public abstract class EdmOperationImpl extends AbstractEdmOperation {
this.operation = operation;
this.helper = new EdmAnnotationHelperImpl(edm, operation);
}
+
+ protected void setParameters(final List<EdmParameter> _parameters) {
+ for (EdmParameter parameter : _parameters) {
+ parameters.put(parameter.getName(), parameter);
+ }
+ }
+
+ protected void setEntitySetPath(final String entitySetPath) {
+ this.entitySetPath = entitySetPath;
+ }
+
+ protected void setIsBound(final boolean isBound) {
+ this.isBound = isBound;
+ }
+
+ protected void setReturnType(final EdmReturnType returnType) {
+ this.returnType = returnType;
+ }
+
+ @Override
+ public EdmParameter getParameter(final String name) {
+ return parameters.get(name);
+ }
+
+ @Override
+ public List<String> getParameterNames() {
+ if (parameterNames == null) {
+ parameterNames = new ArrayList<String>(parameters.size());
+ for (String parameterName : parameters.keySet()) {
+ parameterNames.add(parameterName);
+ }
+ }
+ return parameterNames;
+ }
+
+ @Override
+ public EdmEntitySet getReturnedEntitySet(final EdmEntitySet bindingParameterEntitySet) {
+ EdmEntitySet returnedEntitySet = null;
+ if (bindingParameterEntitySet != null && entitySetPath != null) {
+ final EdmBindingTarget relatedBindingTarget = bindingParameterEntitySet.getRelatedBindingTarget(entitySetPath);
+ if (relatedBindingTarget == null) {
+ throw new EdmException("Cannot find entity set with path: " + entitySetPath);
+ }
+ if (relatedBindingTarget instanceof EdmEntitySet) {
+ returnedEntitySet = (EdmEntitySet) relatedBindingTarget;
+ } else {
+ throw new EdmException("BindingTarget with name: " + relatedBindingTarget.getName()
+ + " must be an entity set");
+ }
+ }
+ return returnedEntitySet;
+ }
+
+ @Override
+ public EdmReturnType getReturnType() {
+ return returnType;
+ }
+
+ @Override
+ public boolean isBound() {
+ return isBound;
+ }
@Override
public FullQualifiedName getBindingParameterTypeFqn() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
index c55d525..ee5891d 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
@@ -18,26 +18,67 @@
*/
package org.apache.olingo.commons.core.edm.provider;
+import java.util.List;
+
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmOperationImport;
import org.apache.olingo.commons.api.edm.EdmTerm;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.commons.api.edm.provider.OperationImport;
-import org.apache.olingo.commons.core.edm.AbstractEdmOperationImport;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-import java.util.List;
-
-public abstract class EdmOperationImportImpl extends AbstractEdmOperationImport {
+public abstract class EdmOperationImportImpl extends EdmNamedImpl implements EdmOperationImport {
+ protected final EdmEntityContainer container;
+ private final Target entitySet;
+ private EdmEntitySet returnedEntitySet;
private final EdmAnnotationHelper helper;
-
+
public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container,
final OperationImport operationImport) {
- super(edm, container, operationImport.getName(), new Target.Builder(operationImport.getEntitySet(), container
- ).build());
+ super(edm, operationImport.getName());
+ this.container = container;
this.helper = new EdmAnnotationHelperImpl(edm, operationImport);
+ this.entitySet = new Target.Builder(operationImport.getEntitySet(), container).build();
+ }
+
+ @Override
+ public FullQualifiedName getFullQualifiedName() {
+ return new FullQualifiedName(container.getNamespace(), getName());
+ }
+
+ @Override
+ public EdmEntitySet getReturnedEntitySet() {
+ if (entitySet != null && returnedEntitySet == null) {
+ EdmEntityContainer entityContainer = edm.getEntityContainer(entitySet.getEntityContainer());
+ if (entityContainer == null) {
+ throw new EdmException("Can´t find entity container with name: " + entitySet.getEntityContainer());
+ }
+ returnedEntitySet = entityContainer.getEntitySet(entitySet.getTargetName());
+ if (returnedEntitySet == null) {
+ throw new EdmException("Can´t find entity set with name: " + entitySet.getTargetName());
+ }
+ }
+ return returnedEntitySet;
+ }
+
+ @Override
+ public EdmEntityContainer getEntityContainer() {
+ return container;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return container.getFullQualifiedName();
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return getName();
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
index e1d3229..f5a25fa 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
@@ -22,22 +22,26 @@ import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmMapping;
+import org.apache.olingo.commons.api.edm.EdmParameter;
import org.apache.olingo.commons.api.edm.EdmTerm;
+import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.Parameter;
-import org.apache.olingo.commons.core.edm.AbstractEdmParameter;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-public class EdmParameterImpl extends AbstractEdmParameter {
+public class EdmParameterImpl extends EdmElementImpl implements EdmParameter {
private final Parameter parameter;
private final EdmAnnotationHelper helper;
+ private final EdmTypeInfo typeInfo;
+ private EdmType typeImpl;
public EdmParameterImpl(final Edm edm, final Parameter parameter) {
- super(edm, parameter.getName(), parameter.getTypeFQN());
+ super(edm, parameter.getName());
this.parameter = parameter;
this.helper = new EdmAnnotationHelperImpl(edm, parameter);
+ this.typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(parameter.getType()).build();
}
@Override
@@ -84,4 +88,16 @@ public class EdmParameterImpl extends AbstractEdmParameter {
public List<EdmAnnotation> getAnnotations() {
return helper.getAnnotations();
}
+
+ @Override
+ public EdmType getType() {
+ if (typeImpl == null) {
+ typeImpl = typeInfo.getType();
+ if (typeImpl == null) {
+ throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
+ }
+ }
+
+ return typeImpl;
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
index 9f14925..61b6a22 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
@@ -22,21 +22,22 @@ import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmMapping;
+import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmTerm;
+import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.Property;
-import org.apache.olingo.commons.core.edm.AbstractEdmProperty;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-public class EdmPropertyImpl extends AbstractEdmProperty {
+public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty {
private final FullQualifiedName structuredTypeName;
private final Property property;
private final EdmTypeInfo typeInfo;
private EdmAnnotationHelper helper;
+ private EdmType propertyType;
public EdmPropertyImpl(final Edm edm, final FullQualifiedName structuredTypeName, final Property property) {
super(edm, property.getName());
@@ -48,10 +49,17 @@ public class EdmPropertyImpl extends AbstractEdmProperty {
}
@Override
- public EdmTypeInfo getTypeInfo() {
- return typeInfo;
+ public EdmType getType() {
+ if (propertyType == null) {
+ propertyType = typeInfo.getType();
+ if (propertyType == null) {
+ throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
+ }
+ }
+
+ return propertyType;
}
-
+
@Override
public boolean isCollection() {
return property.isCollection();
@@ -103,6 +111,16 @@ public class EdmPropertyImpl extends AbstractEdmProperty {
}
@Override
+ public TargetType getAnnotationsTargetType() {
+ return TargetType.Property;
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return getName();
+ }
+
+ @Override
public FullQualifiedName getAnnotationsTargetFQN() {
return structuredTypeName;
}
@@ -116,4 +134,9 @@ public class EdmPropertyImpl extends AbstractEdmProperty {
public List<EdmAnnotation> getAnnotations() {
return helper.getAnnotations();
}
+
+ @Override
+ public boolean isPrimitive() {
+ return typeInfo.isPrimitiveType();
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
index 9cf07ab..e8dbc23 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
@@ -22,21 +22,32 @@ import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmReferentialConstraint;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.provider.ReferentialConstraint;
-import org.apache.olingo.commons.core.edm.AbstractEdmReferentialConstraint;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-public class EdmReferentialConstraintImpl extends AbstractEdmReferentialConstraint {
+public class EdmReferentialConstraintImpl implements EdmReferentialConstraint {
private final EdmAnnotationHelper helper;
+ private final ReferentialConstraint constraint;
+
public EdmReferentialConstraintImpl(final Edm edm, final ReferentialConstraint constraint) {
- super(constraint.getProperty(), constraint.getReferencedProperty());
+ this.constraint = constraint;
this.helper = new EdmAnnotationHelperImpl(edm, constraint);
}
@Override
+ public String getPropertyName() {
+ return constraint.getProperty();
+ }
+
+ @Override
+ public String getReferencedPropertyName() {
+ return constraint.getReferencedProperty();
+ }
+
+ @Override
public EdmAnnotation getAnnotation(final EdmTerm term) {
return helper.getAnnotation(term);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java
index 80eef43..e2d9331 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java
@@ -19,17 +19,22 @@
package org.apache.olingo.commons.core.edm.provider;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.ReturnType;
-import org.apache.olingo.commons.core.edm.AbstractEdmReturnType;
-public class EdmReturnTypeImpl extends AbstractEdmReturnType {
+public class EdmReturnTypeImpl implements EdmReturnType {
private final ReturnType returnType;
-
+ private final EdmTypeInfo typeInfo;
+ private EdmType typeImpl;
+
+
public EdmReturnTypeImpl(final Edm edm, final ReturnType returnType) {
- super(edm, returnType.getTypeFQN());
this.returnType = returnType;
+ this.typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(returnType.getType()).build();
}
@Override
@@ -61,4 +66,16 @@ public class EdmReturnTypeImpl extends AbstractEdmReturnType {
public SRID getSrid() {
return returnType.getSrid();
}
+
+ @Override
+ public EdmType getType() {
+ if (typeImpl == null) {
+ typeImpl = typeInfo.getType();
+ if (typeImpl == null) {
+ throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
+ }
+ }
+
+ return typeImpl;
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
index 2ef1c27..f31d5d8 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
@@ -19,6 +19,7 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
@@ -30,6 +31,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.EdmTerm;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -44,22 +46,144 @@ import org.apache.olingo.commons.api.edm.provider.Function;
import org.apache.olingo.commons.api.edm.provider.Schema;
import org.apache.olingo.commons.api.edm.provider.Term;
import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
-import org.apache.olingo.commons.core.edm.AbstractEdmSchema;
-public class EdmSchemaImpl extends AbstractEdmSchema {
+public class EdmSchemaImpl implements EdmSchema {
private final Schema schema;
private final Edm edm;
private final EdmProvider provider;
+
+ protected final String namespace;
+ private final String alias;
+ private List<EdmEnumType> enumTypes;
+ private List<EdmEntityType> entityTypes;
+ private List<EdmComplexType> complexTypes;
+ private List<EdmAction> actions;
+ private List<EdmFunction> functions;
+ private List<EdmTypeDefinition> typeDefinitions;
+ private List<EdmTerm> terms;
+ private List<EdmAnnotations> annotationGroups;
+ private List<EdmAnnotation> annotations;
+ private EdmEntityContainer entityContainer;
public EdmSchemaImpl(final Edm edm, final EdmProvider provider, final Schema schema) {
- super(schema.getNamespace(), schema.getAlias());
this.edm = edm;
this.provider = provider;
this.schema = schema;
+ this.namespace = schema.getNamespace();
+ this.alias = schema.getAlias();
}
@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 List<EdmTypeDefinition> getTypeDefinitions() {
+ if (typeDefinitions == null) {
+ typeDefinitions = createTypeDefinitions();
+ }
+ return typeDefinitions;
+ }
+
+ @Override
+ public List<EdmTerm> getTerms() {
+ if (terms == null) {
+ terms = createTerms();
+ }
+ return terms;
+ }
+
+ @Override
+ public List<EdmAnnotations> getAnnotationGroups() {
+ if (annotationGroups == null) {
+ annotationGroups = createAnnotationGroups();
+ }
+ return annotationGroups;
+ }
+
+ @Override
+ public List<EdmAnnotation> getAnnotations() {
+ if (annotations == null) {
+ annotations = createAnnotations();
+ }
+ return annotations;
+ }
+
+ @Override
+ public EdmEntityContainer getEntityContainer() {
+ if (entityContainer == null) {
+ entityContainer = createEntityContainer();
+ }
+ return entityContainer;
+ }
+
+ @Override
+ public List<EdmEntityContainer> getEntityContainers() {
+ if (getEntityContainer() == null) {
+ return Collections.<EdmEntityContainer> emptyList();
+ } else {
+ return Collections.singletonList(getEntityContainer());
+ }
+ }
+
+ @Override
+ public EdmEntityContainer getEntityContainer(final FullQualifiedName name) {
+ return getEntityContainer() == null
+ ? null
+ : name == null
+ ? getEntityContainer()
+ : name.equals(getEntityContainer().getFullQualifiedName())
+ ? getEntityContainer()
+ : null;
+ }
+
+ @Override
+ public String getNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public String getAlias() {
+ return alias;
+ }
+
protected EdmEntityContainer createEntityContainer() {
if (schema.getEntityContainer() != null) {
FullQualifiedName containerFQN = new FullQualifiedName(namespace, schema.getEntityContainer().getName());
@@ -68,7 +192,6 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
return null;
}
- @Override
protected List<EdmTypeDefinition> createTypeDefinitions() {
final List<EdmTypeDefinition> typeDefinitions = new ArrayList<EdmTypeDefinition>();
final List<TypeDefinition> providerTypeDefinitions = schema.getTypeDefinitions();
@@ -80,7 +203,6 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
return typeDefinitions;
}
- @Override
protected List<EdmEnumType> createEnumTypes() {
final List<EdmEnumType> enumTypes = new ArrayList<EdmEnumType>();
final List<EnumType> providerEnumTypes = schema.getEnumTypes();
@@ -92,7 +214,6 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
return enumTypes;
}
- @Override
protected List<EdmEntityType> createEntityTypes() {
final List<EdmEntityType> entityTypes = new ArrayList<EdmEntityType>();
final List<EntityType> providerEntityTypes = schema.getEntityTypes();
@@ -105,7 +226,6 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
return entityTypes;
}
- @Override
protected List<EdmComplexType> createComplexTypes() {
final List<EdmComplexType> complexTypes = new ArrayList<EdmComplexType>();
final List<ComplexType> providerComplexTypes = schema.getComplexTypes();
@@ -118,7 +238,6 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
return complexTypes;
}
- @Override
protected List<EdmAction> createActions() {
final List<EdmAction> actions = new ArrayList<EdmAction>();
final List<Action> providerActions = schema.getActions();
@@ -130,7 +249,6 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
return actions;
}
- @Override
protected List<EdmFunction> createFunctions() {
final List<EdmFunction> functions = new ArrayList<EdmFunction>();
final List<Function> providerFunctions = schema.getFunctions();
@@ -142,7 +260,6 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
return functions;
}
- @Override
protected List<EdmTerm> createTerms() {
final List<EdmTerm> terms = new ArrayList<EdmTerm>();
final List<Term> providerTerms = schema.getTerms();
@@ -154,7 +271,6 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
return terms;
}
- @Override
protected List<EdmAnnotations> createAnnotationGroups() {
final List<EdmAnnotations> annotationGroups = new ArrayList<EdmAnnotations>();
final List<Annotations> providerAnnotations =
@@ -167,7 +283,6 @@ public class EdmSchemaImpl extends AbstractEdmSchema {
return annotationGroups;
}
- @Override
protected List<EdmAnnotation> createAnnotations() {
final List<EdmAnnotation> annotations = new ArrayList<EdmAnnotation>();
final List<Annotation> providerAnnotations =
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelper.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelper.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelper.java
new file mode 100644
index 0000000..e00a28b
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelper.java
@@ -0,0 +1,35 @@
+/*
+ * 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.provider;
+
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+
+import java.util.Map;
+
+public interface EdmStructuredTypeHelper {
+
+ Map<String, EdmProperty> getProperties();
+
+ Map<String, EdmNavigationProperty> getNavigationProperties();
+
+ boolean isOpenType();
+
+ boolean isAbstract();
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
index 1ec265d..f72eef1 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
@@ -25,7 +25,6 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.NavigationProperty;
import org.apache.olingo.commons.api.edm.provider.Property;
import org.apache.olingo.commons.api.edm.provider.StructuralType;
-import org.apache.olingo.commons.core.edm.EdmStructuredTypeHelper;
import java.util.LinkedHashMap;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
new file mode 100644
index 0000000..893f3dc
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
@@ -0,0 +1,152 @@
+/*
+ * 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.provider;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmElement;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public abstract class EdmStructuredTypeImpl extends EdmTypeImpl implements EdmStructuredType {
+
+ protected EdmStructuredType baseType;
+
+ protected FullQualifiedName baseTypeName;
+
+ private List<String> propertyNames;
+
+ private List<String> navigationPropertyNames;
+
+ public EdmStructuredTypeImpl(
+ final Edm edm,
+ final FullQualifiedName typeName,
+ final EdmTypeKind kind,
+ final FullQualifiedName baseTypeName) {
+
+ super(edm, typeName, kind);
+ this.baseTypeName = baseTypeName;
+ }
+
+ protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName);
+
+ protected abstract Map<String, EdmProperty> getProperties();
+
+ protected abstract Map<String, EdmNavigationProperty> getNavigationProperties();
+
+ protected abstract void checkBaseType();
+
+ @Override
+ public List<String> getPropertyNames() {
+ if (propertyNames == null) {
+ propertyNames = new ArrayList<String>();
+ checkBaseType();
+ if (baseType != null) {
+ propertyNames.addAll(baseType.getPropertyNames());
+ }
+ propertyNames.addAll(getProperties().keySet());
+ }
+ return propertyNames;
+ }
+
+ @Override
+ public List<String> getNavigationPropertyNames() {
+ if (navigationPropertyNames == null) {
+ navigationPropertyNames = new ArrayList<String>();
+ checkBaseType();
+ if (baseType != null) {
+ navigationPropertyNames.addAll(baseType.getNavigationPropertyNames());
+ }
+ navigationPropertyNames.addAll(getNavigationProperties().keySet());
+ }
+ return navigationPropertyNames;
+ }
+
+ @Override
+ public EdmElement getProperty(final String name) {
+ EdmElement property = getStructuralProperty(name);
+ if (property == null) {
+ property = getNavigationProperty(name);
+ }
+ return property;
+ }
+
+ @Override
+ public EdmProperty getStructuralProperty(final String name) {
+ EdmProperty property = null;
+ checkBaseType();
+ if (baseType != null) {
+ property = baseType.getStructuralProperty(name);
+ }
+ if (property == null) {
+ property = getProperties().get(name);
+ }
+ return property;
+ }
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty(final String name) {
+ EdmNavigationProperty property = null;
+ checkBaseType();
+ if (baseType != null) {
+ property = baseType.getNavigationProperty(name);
+ }
+ if (property == null) {
+ property = getNavigationProperties().get(name);
+ }
+ return property;
+ }
+
+ @Override
+ public boolean compatibleTo(final EdmType targetType) {
+ EdmStructuredType sourceType = this;
+ if (targetType == null) {
+ throw new EdmException("Target type must not be null");
+ }
+ while (!sourceType.getName().equals(targetType.getName())
+ || !sourceType.getNamespace().equals(targetType.getNamespace())) {
+
+ sourceType = sourceType.getBaseType();
+ if (sourceType == null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return null;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return getFullQualifiedName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
index e2b34a5..cc3f11f 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
@@ -30,9 +30,6 @@ import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.Term;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-import org.apache.olingo.commons.core.edm.EdmNamedImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
index 1e81179..d04f6dd 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
@@ -24,24 +24,27 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmTerm;
+import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
-import org.apache.olingo.commons.core.edm.AbstractEdmTypeDefinition;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition {
+public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefinition {
private TypeDefinition typeDefinition;
- private EdmPrimitiveType edmPrimitiveTypeInstance;
+ private final EdmPrimitiveType edmPrimitiveTypeInstance;
private final EdmAnnotationHelper helper;
+ private FullQualifiedName typeDefinitionName;
public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName,
final TypeDefinition typeDefinition) {
- super(edm, typeDefinitionName);
+ super(edm, typeDefinitionName.getName());
+ this.typeDefinitionName = typeDefinitionName;
this.typeDefinition = typeDefinition;
try {
if (typeDefinition.getUnderlyingType() == null) {
@@ -57,15 +60,22 @@ public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition {
}
@Override
+ public FullQualifiedName getFullQualifiedName() {
+ return typeDefinitionName;
+ }
+
+ @Override
+ public String getNamespace() {
+ return typeDefinitionName.getNamespace();
+ }
+
+ @Override
+ public EdmTypeKind getKind() {
+ return EdmTypeKind.DEFINITION;
+ }
+
+ @Override
public EdmPrimitiveType getUnderlyingType() {
- if (edmPrimitiveTypeInstance == null) {
- try {
- edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance(
- EdmPrimitiveTypeKind.valueOfFQN(typeDefinition.getUnderlyingType()));
- } catch (IllegalArgumentException e) {
- throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
- }
- }
return edmPrimitiveTypeInstance;
}
@@ -93,8 +103,64 @@ public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition {
public Boolean isUnicode() {
return typeDefinition.isUnicode();
}
+
+ @Override
+ public boolean isCompatible(final EdmPrimitiveType primitiveType) {
+ return getUnderlyingType().isCompatible(primitiveType);
+ }
+
+ @Override
+ public Class<?> getDefaultType() {
+ return getUnderlyingType().getDefaultType();
+ }
+
+ @Override
+ public boolean validate(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode) {
+
+ return getUnderlyingType().validate(value, isNullable, maxLength, precision, scale, isUnicode);
+ }
@Override
+ public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
+
+ return getUnderlyingType().
+ valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
+ }
+
+ @Override
+ public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale,
+ final Boolean isUnicode) throws EdmPrimitiveTypeException {
+
+ return getUnderlyingType().valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
+ }
+
+ @Override
+ public String toUriLiteral(final String literal) {
+ return getUnderlyingType().toUriLiteral(literal);
+ }
+
+ @Override
+ public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
+ return getUnderlyingType().fromUriLiteral(literal);
+ }
+
+
+ @Override
+ public TargetType getAnnotationsTargetType() {
+ return TargetType.TypeDefinition;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return getFullQualifiedName();
+ }
+
+ @Override
public EdmAnnotation getAnnotation(final EdmTerm term) {
return helper.getAnnotation(term);
}
@@ -103,5 +169,10 @@ public class EdmTypeDefinitionImpl extends AbstractEdmTypeDefinition {
public List<EdmAnnotation> getAnnotations() {
return helper.getAnnotations();
}
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return getName();
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
new file mode 100644
index 0000000..ea05c24
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
@@ -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.commons.core.edm.provider;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+
+public class EdmTypeImpl extends EdmNamedImpl implements EdmType {
+
+ protected final FullQualifiedName typeName;
+
+ protected final EdmTypeKind kind;
+
+ public EdmTypeImpl(final Edm edm, final FullQualifiedName typeName, final EdmTypeKind kind) {
+ super(edm, typeName.getName());
+ this.typeName = typeName;
+ this.kind = kind;
+ }
+
+ @Override
+ public FullQualifiedName getFullQualifiedName() {
+ return typeName;
+ }
+
+ @Override
+ public String getNamespace() {
+ return typeName.getNamespace();
+ }
+
+ @Override
+ public EdmTypeKind getKind() {
+ return kind;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeInfo.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeInfo.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeInfo.java
new file mode 100644
index 0000000..768ec00
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeInfo.java
@@ -0,0 +1,244 @@
+/*
+ * 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.provider;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+
+public class EdmTypeInfo {
+
+ public static class Builder {
+
+ private String typeExpression;
+
+ private String defaultNamespace;
+
+ private Edm edm;
+
+ public Builder setTypeExpression(final String typeExpression) {
+ this.typeExpression = typeExpression;
+ return this;
+ }
+
+ public Builder setDefaultNamespace(final String defaultNamespace) {
+ this.defaultNamespace = defaultNamespace;
+ return this;
+ }
+
+ public Builder setEdm(final Edm edm) {
+ this.edm = edm;
+ return this;
+ }
+
+ public EdmTypeInfo build() {
+ return new EdmTypeInfo(edm, typeExpression.indexOf('.') == -1 && StringUtils.isNotBlank(defaultNamespace)
+ ? defaultNamespace + "." + typeExpression
+ : typeExpression);
+ }
+ }
+
+ private final Edm edm;
+
+ private final boolean collection;
+
+ private final FullQualifiedName fullQualifiedName;
+
+ private EdmPrimitiveTypeKind primitiveType;
+
+ private EdmTypeDefinition typeDefinition;
+
+ private EdmEnumType enumType;
+
+ private EdmComplexType complexType;
+
+ private EdmEntityType entityType;
+
+ private EdmTypeInfo(final Edm edm, final String typeExpression) {
+ this.edm = edm;
+
+ String baseType;
+ final int collStartIdx = typeExpression.indexOf("Collection(");
+ final int collEndIdx = typeExpression.lastIndexOf(')');
+ if (collStartIdx == -1) {
+ baseType = typeExpression;
+ collection = false;
+ } else {
+ if (collEndIdx == -1) {
+ throw new IllegalArgumentException("Malformed type: " + typeExpression);
+ }
+
+ collection = true;
+ baseType = typeExpression.substring(collStartIdx + 11, collEndIdx);
+ }
+
+ baseType = baseType.replaceAll("^#", "");
+
+ final String typeName;
+ final String namespace;
+
+ final int lastDotIdx = baseType.lastIndexOf('.');
+ if (lastDotIdx == -1) {
+ namespace = EdmPrimitiveType.EDM_NAMESPACE;
+ typeName = baseType;
+ baseType = new FullQualifiedName(EdmPrimitiveType.EDM_NAMESPACE, baseType).toString();
+ } else {
+ namespace = baseType.substring(0, lastDotIdx);
+ typeName = baseType.substring(lastDotIdx + 1);
+ }
+
+ if (StringUtils.isBlank(typeName)) {
+ throw new IllegalArgumentException("Null or empty type name in " + typeExpression);
+ }
+
+ final StringBuilder exp = new StringBuilder();
+ exp.append(baseType);
+
+ fullQualifiedName = new FullQualifiedName(namespace, typeName);
+
+ try {
+ primitiveType = EdmPrimitiveTypeKind.valueOf(fullQualifiedName.getName());
+ } catch (final IllegalArgumentException e) {
+ primitiveType = null;
+ }
+ if (primitiveType == null && this.edm != null) {
+ typeDefinition = this.edm.getTypeDefinition(fullQualifiedName);
+ if (typeDefinition == null) {
+ enumType = this.edm.getEnumType(fullQualifiedName);
+ if (enumType == null) {
+ complexType = this.edm.getComplexType(fullQualifiedName);
+ if (complexType == null) {
+ entityType = this.edm.getEntityType(fullQualifiedName);
+ }
+ }
+ }
+ }
+ }
+
+ public String internal() {
+ final StringBuilder deserialize = new StringBuilder();
+
+ if (isCollection()) {
+ deserialize.append("Collection(");
+ }
+
+ deserialize.append(getFullQualifiedName().toString());
+
+ if (isCollection()) {
+ deserialize.append(")");
+ }
+
+ return deserialize.toString();
+ }
+
+ public String external() {
+ final StringBuilder serialize = new StringBuilder();
+
+ if (isCollection()) {
+ serialize.append('#');
+ serialize.append("Collection(");
+ }
+
+ if (isPrimitiveType()) {
+ serialize.append(getFullQualifiedName().getName());
+ }else{
+ serialize.append(getFullQualifiedName().toString());
+ }
+
+ if (isCollection()) {
+ serialize.append(")");
+ }
+
+ if (!isPrimitiveType() && !isCollection()) {
+ serialize.insert(0, '#');
+ }
+
+ return serialize.toString();
+ }
+
+ public boolean isCollection() {
+ return collection;
+ }
+
+ public FullQualifiedName getFullQualifiedName() {
+ return fullQualifiedName;
+ }
+
+ public boolean isPrimitiveType() {
+ return primitiveType != null;
+ }
+
+ public EdmPrimitiveTypeKind getPrimitiveTypeKind() {
+ return primitiveType;
+ }
+
+ public boolean isTypeDefinition() {
+ return typeDefinition != null;
+ }
+
+ public EdmTypeDefinition getTypeDefinition() {
+ return typeDefinition;
+ }
+
+ public boolean isEnumType() {
+ return enumType != null;
+ }
+
+ public EdmEnumType getEnumType() {
+ return enumType;
+ }
+
+ public boolean isComplexType() {
+ return complexType != null;
+ }
+
+ public EdmComplexType getComplexType() {
+ return complexType;
+ }
+
+ public boolean isEntityType() {
+ return entityType != null;
+ }
+
+ public EdmEntityType getEntityType() {
+ return entityType;
+ }
+
+ public EdmType getType() {
+ return isPrimitiveType()
+ ? EdmPrimitiveTypeFactory.getInstance(getPrimitiveTypeKind())
+ : isTypeDefinition()
+ ? getTypeDefinition()
+ : isEnumType()
+ ? getEnumType()
+ : isComplexType()
+ ? getComplexType()
+ : isEntityType()
+ ? getEntityType()
+ : null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java
index dcfb328..1a50c26 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java
@@ -66,7 +66,7 @@ import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import com.fasterxml.aalto.stax.InputFactoryImpl;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
index 6c36116..b6d9a74 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
@@ -50,8 +50,8 @@ import org.apache.olingo.commons.core.data.AbstractODataObject;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import com.fasterxml.aalto.stax.OutputFactoryImpl;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
index 929ad95..fc7e4f8 100755
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
@@ -56,7 +56,7 @@ import org.apache.olingo.commons.core.data.ComplexValueImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java
index 5596fb3..b63950b 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java
@@ -41,7 +41,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.core.data.AnnotationImpl;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java
index b6a32ef..b0fce7c 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java
@@ -30,7 +30,7 @@ import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.ODataOperation;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import com.fasterxml.jackson.core.JsonGenerator;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonGeoValueDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonGeoValueDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonGeoValueDeserializer.java
index 8c439f7..355f321 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonGeoValueDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonGeoValueDeserializer.java
@@ -36,8 +36,8 @@ import org.apache.olingo.commons.api.edm.geo.MultiPolygon;
import org.apache.olingo.commons.api.edm.geo.Point;
import org.apache.olingo.commons.api.edm.geo.Polygon;
import org.apache.olingo.commons.api.edm.geo.SRID;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import com.fasterxml.jackson.databind.JsonNode;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java
index ade76ed..9a9498e 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java
@@ -32,7 +32,7 @@ import org.apache.olingo.commons.api.data.ValueType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.core.data.AnnotationImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java
index da28791..f6ddd58 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java
@@ -27,7 +27,7 @@ import org.apache.olingo.commons.api.data.Annotation;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import com.fasterxml.jackson.core.JsonGenerator;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
index f054be5..012d3a3 100755
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
@@ -47,8 +47,8 @@ import org.apache.olingo.commons.api.edm.geo.Geospatial;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.serialization.ODataSerializer;
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java
index e5f364f..60897c1 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java
@@ -19,7 +19,7 @@
package org.apache.olingo.server.core.edm.provider;
import org.apache.olingo.commons.api.edm.EdmNamed;
-import org.apache.olingo.commons.core.edm.EdmNamedImpl;
+import org.apache.olingo.commons.core.edm.provider.EdmNamedImpl;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
index 141ff32..38938fd 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
@@ -21,7 +21,7 @@ package org.apache.olingo.server.core.edm.provider;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.core.edm.EdmTypeImpl;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeImpl;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
[23/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin example
Posted by ch...@apache.org.
OLINGO-573: New processing framework on server side with single interface with TripPin example
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/8668b097
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/8668b097
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/8668b097
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 8668b097192674b47ba48e8978633665858f5d32
Parents: 62f1001
Author: Ramesh Reddy <ra...@jboss.org>
Authored: Mon Mar 30 12:40:32 2015 -0500
Committer: Ramesh Reddy <ra...@jboss.org>
Committed: Mon Mar 30 12:40:32 2015 -0500
----------------------------------------------------------------------
.../ExpandWithSystemQueryOptionsITCase.java | 65 +-
.../apache/olingo/commons/core/DecoderTest.java | 10 +-
.../apache/olingo/commons/core/EncoderTest.java | 10 +-
lib/pom.xml | 1 +
.../api/deserializer/ODataDeserializer.java | 31 +-
.../EntityCollectionSerializerOptions.java | 18 +-
.../api/serializer/EntitySerializerOptions.java | 18 +-
.../server/api/serializer/ODataSerializer.java | 26 +-
.../api/serializer/SerializerException.java | 8 +-
lib/server-core-ext/pom.xml | 117 +++
.../apache/olingo/server/core/ErrorHandler.java | 125 +++
.../olingo/server/core/MetadataParser.java | 679 +++++++++++++++
.../olingo/server/core/OData4HttpHandler.java | 123 +++
.../apache/olingo/server/core/OData4Impl.java | 45 +
.../server/core/RequestURLHierarchyVisitor.java | 333 ++++++++
.../olingo/server/core/RequestURLVisitor.java | 127 +++
.../server/core/ReturnRepresentation.java | 23 +
.../server/core/SchemaBasedEdmProvider.java | 303 +++++++
.../olingo/server/core/ServiceDispatcher.java | 227 +++++
.../olingo/server/core/ServiceHandler.java | 263 ++++++
.../olingo/server/core/ServiceRequest.java | 253 ++++++
.../core/legacy/ProcessorServiceHandler.java | 433 ++++++++++
.../server/core/requests/ActionRequest.java | 120 +++
.../server/core/requests/BatchRequest.java | 197 +++++
.../server/core/requests/DataRequest.java | 769 +++++++++++++++++
.../server/core/requests/FunctionRequest.java | 122 +++
.../server/core/requests/MediaRequest.java | 99 +++
.../server/core/requests/MetadataRequest.java | 61 ++
.../server/core/requests/OperationRequest.java | 118 +++
.../core/requests/ServiceDocumentRequest.java | 57 ++
.../server/core/responses/CountResponse.java | 60 ++
.../server/core/responses/EntityResponse.java | 140 +++
.../core/responses/EntitySetResponse.java | 82 ++
.../server/core/responses/MetadataResponse.java | 62 ++
.../core/responses/NoContentResponse.java | 100 +++
.../core/responses/PrimitiveValueResponse.java | 105 +++
.../server/core/responses/PropertyResponse.java | 144 ++++
.../core/responses/ServiceDocumentResponse.java | 63 ++
.../server/core/responses/ServiceResponse.java | 119 +++
.../core/responses/ServiceResponseVisior.java | 71 ++
.../server/core/responses/StreamResponse.java | 54 ++
.../olingo/server/core/MetadataParserTest.java | 185 ++++
.../server/core/ServiceDispatcherTest.java | 417 +++++++++
.../olingo/server/example/TripPinDataModel.java | 843 +++++++++++++++++++
.../olingo/server/example/TripPinHandler.java | 546 ++++++++++++
.../server/example/TripPinServiceTest.java | 756 +++++++++++++++++
.../olingo/server/example/TripPinServlet.java | 75 ++
.../src/test/resources/OlingoOrangeTM.png | Bin 0 -> 93316 bytes
.../src/test/resources/airlines.json | 64 ++
.../src/test/resources/airports.json | 394 +++++++++
.../src/test/resources/event.json | 157 ++++
.../src/test/resources/flight-links.json | 52 ++
.../src/test/resources/flight.json | 66 ++
.../src/test/resources/people-links.json | 94 +++
.../src/test/resources/people.json | 323 +++++++
.../src/test/resources/photos.json | 64 ++
.../src/test/resources/trip-links.json | 28 +
.../src/test/resources/trip.json | 224 +++++
.../src/test/resources/trippin.xml | 356 ++++++++
.../json/ODataJsonDeserializer.java | 86 +-
.../serializer/json/ODataJsonSerializer.java | 138 ++-
.../serializer/utils/ContextURLBuilder.java | 9 +-
.../serializer/xml/ODataXmlSerializerImpl.java | 19 +-
.../server/core/uri/UriResourceActionImpl.java | 14 +-
.../server/core/uri/validator/UriValidator.java | 8 +-
.../server-core-exceptions-i18n.properties | 2 +
.../json/ODataJsonDeserializerBasicTest.java | 38 +-
.../json/ODataJsonSerializerTest.java | 13 +-
.../olingo/server/tecsvc/TechnicalServlet.java | 8 +-
.../olingo/server/tecsvc/data/DataCreator.java | 134 ++-
.../olingo/server/tecsvc/data/DataProvider.java | 31 +-
.../olingo/server/tecsvc/data/FunctionData.java | 7 +-
.../processor/TechnicalEntityProcessor.java | 28 +-
.../TechnicalPrimitiveComplexProcessor.java | 15 +-
.../server/tecsvc/data/DataProviderTest.java | 2 +-
.../json/ODataJsonDeserializerEntityTest.java | 4 +-
.../json/ODataJsonSerializerTest.java | 60 +-
.../core/uri/antlr/TestUriParserImpl.java | 11 +-
.../core/uri/validator/UriValidatorTest.java | 18 +-
.../olingo/server/sample/data/DataProvider.java | 13 +-
.../server/sample/processor/CarsProcessor.java | 16 +-
81 files changed, 10840 insertions(+), 259 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
index 2db9535..e5ad3ca 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
@@ -6,9 +6,9 @@
* 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
@@ -69,13 +69,16 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractBaseTestITCase {
entity.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
if (propInt16.equals(1) && propString.equals("1")) {
- assertEquals(1, inlineEntitySet.getEntities().size());
- final ODataEntity inlineEntity = inlineEntitySet.getEntities().get(0);
-
- assertEquals(1, inlineEntity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
- assertEquals("2", inlineEntity.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
+ assertEquals(2, inlineEntitySet.getEntities().size());
+ for (ODataEntity e:inlineEntitySet.getEntities()) {
+ assertEquals(1, e.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
+ String strValue = (String)e.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue();
+ if (!strValue.equals("2") && !strValue.equals("1")) {
+ fail();
+ }
+ }
} else if (propInt16.equals(1) && propString.equals("2")) {
- assertEquals(0, inlineEntitySet.getEntities().size());
+ assertEquals(1, inlineEntitySet.getEntities().size());
} else if (propInt16.equals(2) && propString.equals("1")) {
assertEquals(1, inlineEntitySet.getEntities().size());
final ODataEntity inlineEntity = inlineEntitySet.getEntities().get(0);
@@ -108,14 +111,13 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractBaseTestITCase {
if (propInt16.equals(1) && propString.equals("1")) {
assertEquals(2, inlineEntitySet.getEntities().size());
- final ODataEntity inlineEntity1 = inlineEntitySet.getEntities().get(0);
- final ODataEntity inlineEntity2 = inlineEntitySet.getEntities().get(1);
-
- assertEquals(1, inlineEntity1.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
- assertEquals("2", inlineEntity1.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
-
- assertEquals(1, inlineEntity2.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
- assertEquals("1", inlineEntity2.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
+ for (ODataEntity e:inlineEntitySet.getEntities()) {
+ assertEquals(1, e.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
+ String strValue = (String)e.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue();
+ if (!strValue.equals("2") && !strValue.equals("1")) {
+ fail();
+ }
+ }
}
}
}
@@ -136,15 +138,15 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractBaseTestITCase {
entity.getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
if (propInt16.equals(1)) {
- assertEquals(1, inlineEntitySet.getEntities().size());
+ assertEquals(2, inlineEntitySet.getEntities().size());
final ODataEntity inlineEntity = inlineEntitySet.getEntities().get(0);
- assertEquals(2, inlineEntity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals(1, inlineEntity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
} else if (propInt16.equals(2)) {
- assertEquals(1, inlineEntitySet.getEntities().size());
+ assertEquals(2, inlineEntitySet.getEntities().size());
final ODataEntity inlineEntity = inlineEntitySet.getEntities().get(0);
- assertEquals(3, inlineEntity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals(2, inlineEntity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
} else if (propInt16.equals(3)) {
assertEquals(0, inlineEntitySet.getEntities().size());
}
@@ -167,12 +169,12 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractBaseTestITCase {
entity.getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
if (propInt16.equals(1)) {
- assertEquals(1, inlineEntitySet.getEntities().size());
+ assertEquals(2, inlineEntitySet.getEntities().size());
final ODataEntity inlineEntity = inlineEntitySet.getEntities().get(0);
assertEquals(1, inlineEntity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
} else if (propInt16.equals(2)) {
- assertEquals(1, inlineEntitySet.getEntities().size());
+ assertEquals(2, inlineEntitySet.getEntities().size());
final ODataEntity inlineEntity = inlineEntitySet.getEntities().get(0);
assertEquals(2, inlineEntity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
@@ -201,15 +203,18 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractBaseTestITCase {
entity.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
if (propInt16.equals(1) && propString.equals("1")) {
- assertEquals(1, inlineEntitySet.getEntities().size());
- final ODataEntity inlineEntity = inlineEntitySet.getEntities().get(0);
-
- assertEquals(1, inlineEntity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
- assertEquals("2", inlineEntity.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
+ assertEquals(2, inlineEntitySet.getEntities().size());
+ for (ODataEntity e:inlineEntitySet.getEntities()) {
+ assertEquals(1, e.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
+ String strValue = (String)e.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue();
+ if (!strValue.equals("2") && !strValue.equals("1")) {
+ fail();
+ }
+ }
} else if (propInt16.equals(1) && propString.equals("2")) {
- assertEquals(0, inlineEntitySet.getEntities().size());
+ assertEquals(1, inlineEntitySet.getEntities().size());
} else if (propInt16.equals(2) && propString.equals("1")) {
- assertEquals(0, inlineEntitySet.getEntities().size());
+ assertEquals(1, inlineEntitySet.getEntities().size());
} else if (propInt16.equals(3) && propString.equals("1")) {
assertEquals(0, inlineEntitySet.getEntities().size());
} else {
@@ -274,7 +279,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractBaseTestITCase {
final ODataEntitySet entitySet =
response.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
- assertEquals(1, entitySet.getEntities().size());
+ assertEquals(2, entitySet.getEntities().size());
assertEquals(1, entitySet.getEntities().get(0).getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java
index 019ef5a..09f2326 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java
@@ -6,9 +6,9 @@
* 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
@@ -18,13 +18,13 @@
******************************************************************************/
package org.apache.olingo.commons.core;
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import org.junit.Test;
+
/**
- *
+ *
*/
public class DecoderTest {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java
index 74eb1af..7db30ce 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java
@@ -6,9 +6,9 @@
* 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
@@ -18,16 +18,16 @@
******************************************************************************/
package org.apache.olingo.commons.core;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
/**
* Tests for percent-encoding.
- *
+ *
*/
public class EncoderTest {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/pom.xml
----------------------------------------------------------------------
diff --git a/lib/pom.xml b/lib/pom.xml
index 6843ff3..d1e8864 100644
--- a/lib/pom.xml
+++ b/lib/pom.xml
@@ -42,6 +42,7 @@
<module>client-core</module>
<module>server-api</module>
<module>server-core</module>
+ <module>server-core-ext</module>
<module>server-tecsvc</module>
<module>server-test</module>
</modules>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
index d5f7343..3bbcc66 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
@@ -6,9 +6,9 @@
* 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
@@ -19,11 +19,15 @@
package org.apache.olingo.server.api.deserializer;
import java.io.InputStream;
+import java.net.URI;
+import java.util.List;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmProperty;
/**
* Deserializer on OData server side.
@@ -32,7 +36,7 @@ public interface ODataDeserializer {
/**
* Deserializes an entity stream into an {@link Entity} object.
- * Validates: property types, no double properties, correct json types
+ * Validates: property types, no double properties, correct json types
* @param stream
* @param edmEntityType
* @return deserialized {@link Entity} object
@@ -48,7 +52,7 @@ public interface ODataDeserializer {
* @throws DeserializerException
*/
EntitySet entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
-
+
/**
* Deserializes an action-parameters stream into an {@link Entity} object.
* Validates: parameter types, no double parameters, correct json types.
@@ -58,4 +62,23 @@ public interface ODataDeserializer {
* @throws DeserializerException
*/
Entity actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
+
+
+ /**
+ * Deserializes the Property or collections of properties (primitive & complex)
+ * @param stream
+ * @param edmProperty
+ * @return deserialized {@link Property}
+ * @throws DeserializerException
+ */
+ Property property(InputStream stream, EdmProperty edmProperty) throws DeserializerException;
+
+ /**
+ * Read entity references from the provided document
+ * @param stream
+ * @param keys
+ * @return
+ * @throws DeserializerException
+ */
+ List<URI> entityReferences(InputStream stream) throws DeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
index 14c588d..e5dd6b0 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
@@ -6,9 +6,9 @@
* 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
@@ -30,6 +30,7 @@ public class EntityCollectionSerializerOptions {
private CountOption count;
private ExpandOption expand;
private SelectOption select;
+ private boolean onlyReferences;
/** Gets the {@link ContextURL}. */
public ContextURL getContextURL() {
@@ -51,6 +52,11 @@ public class EntityCollectionSerializerOptions {
return select;
}
+ /** only writes the references of the entities*/
+ public boolean onlyReferences() {
+ return onlyReferences;
+ }
+
/** Initializes the options builder. */
public static Builder with() {
return new Builder();
@@ -59,7 +65,7 @@ public class EntityCollectionSerializerOptions {
/** Builder of OData serializer options. */
public static final class Builder {
- private EntityCollectionSerializerOptions options;
+ private final EntityCollectionSerializerOptions options;
private Builder() {
options = new EntityCollectionSerializerOptions();
@@ -89,6 +95,12 @@ public class EntityCollectionSerializerOptions {
return this;
}
+ /** Sets to serialize only references */
+ public Builder setWriteOnlyReferences(final boolean ref) {
+ options.onlyReferences = ref;
+ return this;
+ }
+
/** Builds the OData serializer options. */
public EntityCollectionSerializerOptions build() {
return options;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java
index fcbd150..0abb31c 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java
@@ -6,9 +6,9 @@
* 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
@@ -27,6 +27,7 @@ public class EntitySerializerOptions {
private ContextURL contextURL;
private ExpandOption expand;
private SelectOption select;
+ private boolean onlyReferences;
/** Gets the {@link ContextURL}. */
public ContextURL getContextURL() {
@@ -43,6 +44,11 @@ public class EntitySerializerOptions {
return select;
}
+ /** only writes the references of the entities*/
+ public boolean onlyReferences() {
+ return onlyReferences;
+ }
+
private EntitySerializerOptions() {}
/** Initializes the options builder. */
@@ -53,7 +59,7 @@ public class EntitySerializerOptions {
/** Builder of OData serializer options. */
public static final class Builder {
- private EntitySerializerOptions options;
+ private final EntitySerializerOptions options;
private Builder() {
options = new EntitySerializerOptions();
@@ -77,6 +83,12 @@ public class EntitySerializerOptions {
return this;
}
+ /** Sets to serialize only references */
+ public Builder setWriteOnlyReferences(final boolean ref) {
+ options.onlyReferences = ref;
+ return this;
+ }
+
/** Builds the OData serializer options. */
public EntitySerializerOptions build() {
return options;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index 72f8ee8..55377ce 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -6,9 +6,9 @@
* 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
@@ -39,7 +39,7 @@ public interface ODataSerializer {
/**
* Writes the service document into an InputStream.
* @param edm the Entity Data Model
- * @param serviceRoot the service-root URI of this OData service
+ * @param serviceRoot the service-root URI of this OData service
*/
InputStream serviceDocument(Edm edm, String serviceRoot) throws SerializerException;
@@ -58,21 +58,23 @@ public interface ODataSerializer {
/**
* Writes entity-collection data into an InputStream.
+ * @param metadata Metadata for the service
* @param entityType the {@link EdmEntityType}
* @param entitySet the data of the entity set
* @param options options for the serializer
*/
- InputStream entityCollection(EdmEntityType entityType, EntitySet entitySet,
- EntityCollectionSerializerOptions options) throws SerializerException;
+ InputStream entityCollection(ServiceMetadata metadata, EdmEntityType entityType,
+ EntitySet entitySet, EntityCollectionSerializerOptions options) throws SerializerException;
/**
* Writes entity data into an InputStream.
+ * @param metadata Metadata for the service
* @param entityType the {@link EdmEntityType}
* @param entity the data of the entity
* @param options options for the serializer
*/
- InputStream entity(EdmEntityType entityType, Entity entity, EntitySerializerOptions options)
- throws SerializerException;
+ InputStream entity(ServiceMetadata metadata, EdmEntityType entityType, Entity entity,
+ EntitySerializerOptions options) throws SerializerException;
/**
* Writes primitive-type instance data into an InputStream.
@@ -85,12 +87,13 @@ public interface ODataSerializer {
/**
* Writes complex-type instance data into an InputStream.
+ * @param metadata Metadata for the service
* @param type complex type
* @param property property value
* @param options options for the serializer
*/
- InputStream complex(EdmComplexType type, Property property, ComplexSerializerOptions options)
- throws SerializerException;
+ InputStream complex(ServiceMetadata metadata, EdmComplexType type, Property property,
+ ComplexSerializerOptions options) throws SerializerException;
/**
* Writes data of a collection of primitive-type instances into an InputStream.
@@ -103,10 +106,11 @@ public interface ODataSerializer {
/**
* Writes data of a collection of complex-type instances into an InputStream.
+ * @param metadata Metadata for the service
* @param type complex type
* @param property property value
* @param options options for the serializer
*/
- InputStream complexCollection(EdmComplexType type, Property property, ComplexSerializerOptions options)
- throws SerializerException;
+ InputStream complexCollection(ServiceMetadata metadata, EdmComplexType type, Property property,
+ ComplexSerializerOptions options) throws SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
index 1583241..a7d067f 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
@@ -6,9 +6,9 @@
* 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
@@ -37,7 +37,9 @@ public class SerializerException extends ODataTranslatedException {
/** parameter: property name */ INCONSISTENT_PROPERTY_TYPE,
/** parameter: property name */ MISSING_PROPERTY,
/** parameters: property name, property value */ WRONG_PROPERTY_VALUE,
- /** parameters: primitive-type name, value */ WRONG_PRIMITIVE_VALUE;
+ /** parameters: primitive-type name, value */ WRONG_PRIMITIVE_VALUE,
+ UNKNOWN_TYPE,
+ WRONG_BASE_TYPE;
@Override
public String getKey() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/pom.xml
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/pom.xml b/lib/server-core-ext/pom.xml
new file mode 100644
index 0000000..a5730c0
--- /dev/null
+++ b/lib/server-core-ext/pom.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<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>
+
+ <artifactId>odata-server-core-ext</artifactId>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-lib</artifactId>
+ <version>4.0.0-beta-03-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <properties>
+ <jetty-version>9.2.7.v20150116</jetty-version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-server-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-server-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-commons-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-runtime</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <scope>test</scope>
+ <version>${jetty-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <version>${jetty-version}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-http</artifactId>
+ <version>${jetty-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-client</artifactId>
+ <scope>test</scope>
+ <version>${jetty-version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
new file mode 100644
index 0000000..199c62d
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
@@ -0,0 +1,125 @@
+/*
+ * 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.ByteArrayInputStream;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataServerError;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
+import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.core.uri.parser.Parser;
+import org.apache.olingo.server.core.uri.parser.UriParserException;
+import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
+import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
+import org.apache.olingo.server.core.uri.validator.UriValidationException;
+
+public class ErrorHandler {
+ private final OData odata;
+ private final ServiceMetadata metadata;
+ private final CustomContentTypeSupport customContent;
+
+ public ErrorHandler(OData odata, ServiceMetadata metadata, CustomContentTypeSupport customContent) {
+ this.odata = odata;
+ this.metadata = metadata;
+ this.customContent = customContent;
+ }
+
+ public void handleException(Exception e, ODataRequest request, ODataResponse response) {
+ if (e instanceof UriValidationException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((UriValidationException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof UriParserSemanticException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((UriParserSemanticException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof UriParserSyntaxException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((UriParserSyntaxException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof UriParserException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((UriParserException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof ContentNegotiatorException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((ContentNegotiatorException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof SerializerException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((SerializerException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof BatchDeserializerException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((BatchDeserializerException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof DeserializerException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((DeserializerException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof ODataHandlerException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((ODataHandlerException)e, null);
+ handleServerError(request, response, serverError);
+ } else {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
+ handleServerError(request, response, serverError);
+ }
+ }
+
+ void handleServerError(final ODataRequest request, final ODataResponse response,
+ final ODataServerError serverError) {
+ ContentType requestedContentType;
+ try {
+ UriInfo uriInfo = new Parser().parseUri(request.getRawODataPath(), request.getRawQueryPath(),
+ null, this.metadata.getEdm());
+ requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
+ request, this.customContent, RepresentationType.ERROR);
+ } catch (final ContentNegotiatorException e) {
+ requestedContentType = ODataFormat.JSON.getContentType();
+ } catch (UriParserException e) {
+ requestedContentType = ODataFormat.JSON.getContentType();
+ }
+ processError(response, serverError, requestedContentType);
+ }
+
+ void processError(ODataResponse response, ODataServerError serverError,
+ ContentType requestedContentType) {
+ try {
+ ODataSerializer serializer = this.odata.createSerializer(ODataFormat
+ .fromContentType(requestedContentType));
+ response.setContent(serializer.error(serverError));
+ response.setStatusCode(serverError.getStatusCode());
+ response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
+ } catch (Exception e) {
+ // This should never happen but to be sure we have this catch here
+ // to prevent sending a stacktrace to a client.
+ String responseContent = "{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred during "
+ + "error processing with message: " + e.getMessage() + "\"}}"; //$NON-NLS-1$ //$NON-NLS-2$
+ response.setContent(new ByteArrayInputStream(responseContent.getBytes()));
+ response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
+ response.setHeader(HttpHeader.CONTENT_TYPE,
+ ContentType.APPLICATION_JSON.toContentTypeString());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java
new file mode 100644
index 0000000..e34a28a
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java
@@ -0,0 +1,679 @@
+/*
+ * 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.Reader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.Action;
+import org.apache.olingo.commons.api.edm.provider.ActionImport;
+import org.apache.olingo.commons.api.edm.provider.ComplexType;
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.commons.api.edm.provider.EntityContainer;
+import org.apache.olingo.commons.api.edm.provider.EntitySet;
+import org.apache.olingo.commons.api.edm.provider.EntityType;
+import org.apache.olingo.commons.api.edm.provider.EnumMember;
+import org.apache.olingo.commons.api.edm.provider.EnumType;
+import org.apache.olingo.commons.api.edm.provider.Function;
+import org.apache.olingo.commons.api.edm.provider.FunctionImport;
+import org.apache.olingo.commons.api.edm.provider.NavigationProperty;
+import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
+import org.apache.olingo.commons.api.edm.provider.OnDelete;
+import org.apache.olingo.commons.api.edm.provider.OnDeleteAction;
+import org.apache.olingo.commons.api.edm.provider.Operation;
+import org.apache.olingo.commons.api.edm.provider.Parameter;
+import org.apache.olingo.commons.api.edm.provider.Property;
+import org.apache.olingo.commons.api.edm.provider.PropertyRef;
+import org.apache.olingo.commons.api.edm.provider.ReferentialConstraint;
+import org.apache.olingo.commons.api.edm.provider.ReturnType;
+import org.apache.olingo.commons.api.edm.provider.Schema;
+import org.apache.olingo.commons.api.edm.provider.Singleton;
+import org.apache.olingo.commons.api.edm.provider.Term;
+import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
+
+/**
+ * This class can convert a CSDL document into EDMProvider object
+ */
+public class MetadataParser {
+
+ public EdmProvider buildEdmProvider(Reader csdl) throws XMLStreamException {
+ XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
+ XMLEventReader reader = xmlInputFactory.createXMLEventReader(csdl);
+
+ SchemaBasedEdmProvider provider = new SchemaBasedEdmProvider();
+ new ElementReader<SchemaBasedEdmProvider>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, SchemaBasedEdmProvider provider,
+ String name) throws XMLStreamException {
+ String version = attr(element, "Version");
+ if (version.equals("4.0")) {
+ readDataServicesAndReference(reader, element, provider);
+ }
+ }
+ }.read(reader, null, provider, "Edmx");
+
+ return provider;
+ }
+
+ private void readDataServicesAndReference(XMLEventReader reader, StartElement element,
+ SchemaBasedEdmProvider provider) throws XMLStreamException {
+ new ElementReader<SchemaBasedEdmProvider>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, SchemaBasedEdmProvider provider,
+ String name) throws XMLStreamException {
+ if (name.equals("DataServices")) {
+ readSchema(reader, element, provider);
+ } else if (name.equals("Reference")) {
+ readReference(reader, element, provider, "Reference");
+ }
+ }
+ }.read(reader, element, provider, "DataServices", "Reference");
+ }
+
+ private void readReference(XMLEventReader reader, StartElement element,
+ SchemaBasedEdmProvider provider, String name) throws XMLStreamException {
+ new ElementReader<SchemaBasedEdmProvider>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, SchemaBasedEdmProvider t, String name)
+ throws XMLStreamException {
+ // TODO:
+ }
+ }.read(reader, element, provider, name);
+ }
+
+ private void readSchema(XMLEventReader reader, StartElement element,
+ SchemaBasedEdmProvider provider) throws XMLStreamException {
+
+ Schema schema = new Schema();
+ schema.setComplexTypes(new ArrayList<ComplexType>());
+ schema.setActions(new ArrayList<Action>());
+ schema.setEntityTypes(new ArrayList<EntityType>());
+ schema.setEnumTypes(new ArrayList<EnumType>());
+ schema.setFunctions(new ArrayList<Function>());
+ schema.setTerms(new ArrayList<Term>());
+ schema.setTypeDefinitions(new ArrayList<TypeDefinition>());
+
+ new ElementReader<Schema>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, Schema schema, String name)
+ throws XMLStreamException {
+ schema.setNamespace(attr(element, "Namespace"));
+ schema.setAlias(attr(element, "Alias"));
+ readSchemaContents(reader, schema);
+ }
+ }.read(reader, element, schema, "Schema");
+ provider.addSchema(schema);
+ }
+
+ private void readSchemaContents(XMLEventReader reader, Schema schema) throws XMLStreamException {
+ new ElementReader<Schema>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, Schema schema, String name)
+ throws XMLStreamException {
+ if (name.equals("Action")) {
+ readAction(reader, element, schema);
+ } else if (name.equals("Annotations")) {
+ // TODO:
+ } else if (name.equals("Annotation")) {
+ // TODO:
+ } else if (name.equals("ComplexType")) {
+ readComplexType(reader, element, schema);
+ } else if (name.equals("EntityContainer")) {
+ readEntityContainer(reader, element, schema);
+ } else if (name.equals("EntityType")) {
+ readEntityType(reader, element, schema);
+ } else if (name.equals("EnumType")) {
+ readEnumType(reader, element, schema);
+ } else if (name.equals("Function")) {
+ readFunction(reader, element, schema);
+ } else if (name.equals("Term")) {
+ schema.getTerms().add(readTerm(element));
+ } else if (name.equals("TypeDefinition")) {
+ schema.getTypeDefinitions().add(readTypeDefinition(element));
+ }
+ }
+ }.read(reader, null, schema, "Action", "Annotations", "Annotation", "ComplexType",
+ "EntityContainer", "EntityType", "EnumType", "Function", "Term", "TypeDefinition");
+ }
+
+ private void readAction(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+
+ Action action = new Action();
+ action.setParameters(new ArrayList<Parameter>());
+ action.setName(attr(element, "Name"));
+ action.setBound(Boolean.parseBoolean(attr(element, "IsBound")));
+ String entitySetPath = attr(element, "EntitySetPath");
+ if (entitySetPath != null) {
+ // TODO: need to parse into binding and path.
+ action.setEntitySetPath(entitySetPath);
+ }
+ readOperationParameters(reader, action);
+ schema.getActions().add(action);
+ }
+
+ private FullQualifiedName readType(StartElement element) {
+ String type = attr(element, "Type");
+ if (type.startsWith("Collection(") && type.endsWith(")")) {
+ return new FullQualifiedName(type.substring(11, type.length() - 1));
+ }
+ return new FullQualifiedName(type);
+ }
+
+ private boolean isCollectionType(StartElement element) {
+ String type = attr(element, "Type");
+ if (type.startsWith("Collection(") && type.endsWith(")")) {
+ return true;
+ }
+ return false;
+ }
+
+ private void readReturnType(StartElement element, Operation operation) {
+ ReturnType returnType = new ReturnType();
+ returnType.setType(readType(element));
+ returnType.setCollection(isCollectionType(element));
+ returnType.setNullable(Boolean.parseBoolean(attr(element, "Nullable")));
+
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ returnType.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ returnType.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ returnType.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ operation.setReturnType(returnType);
+ }
+
+ private void readParameter(StartElement element, Operation operation) {
+ Parameter parameter = new Parameter();
+ parameter.setName(attr(element, "Name"));
+ parameter.setType(readType(element));
+ parameter.setCollection(isCollectionType(element));
+ parameter.setNullable(Boolean.parseBoolean(attr(element, "Nullable")));
+
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ parameter.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ parameter.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ parameter.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ operation.getParameters().add(parameter);
+ }
+
+ private TypeDefinition readTypeDefinition(StartElement element) {
+ TypeDefinition td = new TypeDefinition();
+ td.setName(attr(element, "Name"));
+ td.setUnderlyingType(new FullQualifiedName(attr(element, "UnderlyingType")));
+ td.setUnicode(Boolean.parseBoolean(attr(element, "Unicode")));
+
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ td.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ td.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ td.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ return td;
+ }
+
+ private Term readTerm(StartElement element) {
+ Term term = new Term();
+ term.setName(attr(element, "Name"));
+ term.setType(attr(element, "Type"));
+ if (attr(element, "BaseTerm") != null) {
+ term.setBaseTerm(attr(element, "BaseTerm"));
+ }
+ if (attr(element, "DefaultValue") != null) {
+ term.setDefaultValue(attr(element, "DefaultValue"));
+ }
+ if (attr(element, "AppliesTo") != null) {
+ term.setAppliesTo(Arrays.asList(attr(element, "AppliesTo")));
+ }
+ term.setNullable(Boolean.parseBoolean(attr(element, "Nullable")));
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ term.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ term.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ term.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ return term;
+ }
+
+ private void readFunction(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ Function function = new Function();
+ function.setParameters(new ArrayList<Parameter>());
+ function.setName(attr(element, "Name"));
+ function.setBound(Boolean.parseBoolean(attr(element, "IsBound")));
+ function.setComposable(Boolean.parseBoolean(attr(element, "IsComposable")));
+ String entitySetPath = attr(element, "EntitySetPath");
+ if (entitySetPath != null) {
+ // TODO: need to parse into binding and path.
+ function.setEntitySetPath(entitySetPath);
+ }
+ readOperationParameters(reader, function);
+ schema.getFunctions().add(function);
+ }
+
+ private void readOperationParameters(XMLEventReader reader, final Operation operation)
+ throws XMLStreamException {
+ new ElementReader<Operation>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, Operation operation, String name)
+ throws XMLStreamException {
+ if (name.equals("Parameter")) {
+ readParameter(element, operation);
+ } else if (name.equals("ReturnType")) {
+ readReturnType(element, operation);
+ }
+ }
+ }.read(reader, null, operation, "Parameter", "ReturnType");
+ }
+
+ private void readEnumType(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ EnumType type = new EnumType();
+ type.setMembers(new ArrayList<EnumMember>());
+ type.setName(attr(element, "Name"));
+ if (attr(element, "UnderlyingType") != null) {
+ type.setUnderlyingType(new FullQualifiedName(attr(element, "UnderlyingType")));
+ }
+ type.setFlags(Boolean.parseBoolean(attr(element, "IsFlags")));
+
+ readEnumMembers(reader, element, type);
+ schema.getEnumTypes().add(type);
+ }
+
+ private void readEnumMembers(XMLEventReader reader, StartElement element, EnumType type)
+ throws XMLStreamException {
+ new ElementReader<EnumType>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, EnumType type, String name)
+ throws XMLStreamException {
+ EnumMember member = new EnumMember();
+ member.setName(attr(element, "Name"));
+ member.setValue(attr(element, "Value"));
+ type.getMembers().add(member);
+ }
+ }.read(reader, element, type, "Member");
+ }
+
+ private void readEntityType(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ EntityType entityType = new EntityType();
+ entityType.setProperties(new ArrayList<Property>());
+ entityType.setNavigationProperties(new ArrayList<NavigationProperty>());
+ entityType.setKey(new ArrayList<PropertyRef>());
+ entityType.setName(attr(element, "Name"));
+ if (attr(element, "BaseType") != null) {
+ entityType.setBaseType(new FullQualifiedName(attr(element, "BaseType")));
+ }
+ entityType.setAbstract(Boolean.parseBoolean(attr(element, "Abstract")));
+ entityType.setOpenType(Boolean.parseBoolean(attr(element, "OpenType")));
+ entityType.setHasStream(Boolean.parseBoolean(attr(element, "HasStream")));
+ readEntityProperties(reader, entityType);
+ schema.getEntityTypes().add(entityType);
+ }
+
+ private void readEntityProperties(XMLEventReader reader, EntityType entityType)
+ throws XMLStreamException {
+ new ElementReader<EntityType>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, EntityType entityType, String name)
+ throws XMLStreamException {
+ if (name.equals("Property")) {
+ entityType.getProperties().add(readProperty(element));
+ } else if (name.equals("NavigationProperty")) {
+ entityType.getNavigationProperties().add(readNavigationProperty(reader, element));
+ } else if (name.equals("Key")) {
+ readKey(reader, element, entityType);
+ }
+ }
+ }.read(reader, null, entityType, "Property", "NavigationProperty", "Key");
+ }
+
+ private void readKey(XMLEventReader reader, StartElement element, EntityType entityType)
+ throws XMLStreamException {
+ new ElementReader<EntityType>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, EntityType entityType, String name)
+ throws XMLStreamException {
+ PropertyRef ref = new PropertyRef();
+ ref.setName(attr(element, "Name"));
+ ref.setAlias(attr(element, "Alias"));
+ entityType.getKey().add(ref);
+ }
+ }.read(reader, element, entityType, "PropertyRef");
+ }
+
+ private NavigationProperty readNavigationProperty(XMLEventReader reader, StartElement element)
+ throws XMLStreamException {
+ NavigationProperty property = new NavigationProperty();
+ property.setReferentialConstraints(new ArrayList<ReferentialConstraint>());
+
+ property.setName(attr(element, "Name"));
+ property.setType(readType(element));
+ property.setCollection(isCollectionType(element));
+ property.setNullable(Boolean.parseBoolean(attr(element, "Nullable")));
+ property.setPartner(attr(element, "Partner"));
+ property.setContainsTarget(Boolean.parseBoolean(attr(element, "ContainsTarget")));
+
+ new ElementReader<NavigationProperty>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, NavigationProperty property,
+ String name) throws XMLStreamException {
+ if (name.equals("ReferentialConstraint")) {
+ ReferentialConstraint constraint = new ReferentialConstraint();
+ constraint.setProperty(attr(element, "Property"));
+ constraint.setReferencedProperty(attr(element, "ReferencedProperty"));
+ property.getReferentialConstraints().add(constraint);
+ } else if (name.equals("OnDelete")) {
+ property.setOnDelete(new OnDelete().setAction(OnDeleteAction.valueOf(attr(element, "Action"))));
+ }
+ }
+ }.read(reader, element, property, "ReferentialConstraint", "OnDelete");
+ return property;
+ }
+
+ private String attr(StartElement element, String name) {
+ Attribute attr = element.getAttributeByName(new QName(name));
+ if (attr != null) {
+ return attr.getValue();
+ }
+ return null;
+ }
+
+ private Property readProperty(StartElement element) {
+ Property property = new Property();
+ property.setName(attr(element, "Name"));
+ property.setType(readType(element));
+ property.setCollection(isCollectionType(element));
+ property.setNullable(Boolean.parseBoolean(attr(element, "Nullable") == null ? "true" : attr(
+ element, "Nullable")));
+ property.setUnicode(Boolean.parseBoolean(attr(element, "Unicode")));
+
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ property.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ property.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ property.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ String defaultValue = attr(element, "DefaultValue");
+ if (defaultValue != null) {
+ property.setDefaultValue(defaultValue);
+ }
+ return property;
+ }
+
+ private void readEntityContainer(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ final EntityContainer container = new EntityContainer();
+ container.setName(attr(element, "Name"));
+ if (attr(element, "Extends") != null) {
+ container.setExtendsContainer(attr(element, "Extends"));
+ }
+ container.setActionImports(new ArrayList<ActionImport>());
+ container.setFunctionImports(new ArrayList<FunctionImport>());
+ container.setEntitySets(new ArrayList<EntitySet>());
+ container.setSingletons(new ArrayList<Singleton>());
+
+ new ElementReader<Schema>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, Schema schema, String name)
+ throws XMLStreamException {
+ if (name.equals("EntitySet")) {
+ readEntitySet(reader, element, container);
+ } else if (name.equals("Singleton")) {
+ readSingleton(reader, element, container);
+ } else if (name.equals("ActionImport")) {
+ readActionImport(element, container);
+ } else if (name.equals("FunctionImport")) {
+ readFunctionImport(element, container);
+ }
+ }
+
+ private void readFunctionImport(StartElement element, EntityContainer container) {
+ FunctionImport functionImport = new FunctionImport();
+ functionImport.setName(attr(element, "Name"));
+ functionImport.setFunction(new FullQualifiedName(attr(element, "Function")));
+ functionImport.setIncludeInServiceDocument(Boolean.parseBoolean(attr(element,
+ "IncludeInServiceDocument")));
+
+ String entitySet = attr(element, "EntitySet");
+ if (entitySet != null) {
+ functionImport.setEntitySet(entitySet);
+ }
+ container.getFunctionImports().add(functionImport);
+ }
+
+ private void readActionImport(StartElement element, EntityContainer container) {
+ ActionImport actionImport = new ActionImport();
+ actionImport.setName(attr(element, "Name"));
+ actionImport.setAction(new FullQualifiedName(attr(element, "Action")));
+
+ String entitySet = attr(element, "EntitySet");
+ if (entitySet != null) {
+ actionImport.setEntitySet(entitySet);
+ }
+ container.getActionImports().add(actionImport);
+ }
+
+ private void readSingleton(XMLEventReader reader, StartElement element,
+ EntityContainer container) throws XMLStreamException {
+ Singleton singleton = new Singleton();
+ singleton.setNavigationPropertyBindings(new ArrayList<NavigationPropertyBinding>());
+ singleton.setName(attr(element, "Name"));
+ singleton.setType(new FullQualifiedName(attr(element, "Type")));
+ singleton.setNavigationPropertyBindings(new ArrayList<NavigationPropertyBinding>());
+ readNavigationPropertyBindings(reader, element, singleton.getNavigationPropertyBindings());
+ container.getSingletons().add(singleton);
+ }
+
+ private void readEntitySet(XMLEventReader reader, StartElement element,
+ EntityContainer container) throws XMLStreamException {
+ EntitySet entitySet = new EntitySet();
+ entitySet.setName(attr(element, "Name"));
+ entitySet.setType(new FullQualifiedName(attr(element, "EntityType")));
+ entitySet.setIncludeInServiceDocument(Boolean.parseBoolean(attr(element,
+ "IncludeInServiceDocument")));
+ entitySet.setNavigationPropertyBindings(new ArrayList<NavigationPropertyBinding>());
+ readNavigationPropertyBindings(reader, element, entitySet.getNavigationPropertyBindings());
+ container.getEntitySets().add(entitySet);
+ }
+
+ private void readNavigationPropertyBindings(XMLEventReader reader, StartElement element,
+ List<NavigationPropertyBinding> bindings) throws XMLStreamException {
+ new ElementReader<List<NavigationPropertyBinding>>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element,
+ List<NavigationPropertyBinding> bindings, String name) throws XMLStreamException {
+ NavigationPropertyBinding binding = new NavigationPropertyBinding();
+ binding.setPath(attr(element, "Path"));
+ binding.setTarget(attr(element, "Target"));
+ bindings.add(binding);
+ }
+
+ }.read(reader, element, bindings, "NavigationPropertyBinding");
+ ;
+ }
+ }.read(reader, element, schema, "EntitySet", "Singleton", "ActionImport", "FunctionImport");
+ schema.setEntityContainer(container);
+ }
+
+ private void readComplexType(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ ComplexType complexType = new ComplexType();
+ complexType.setProperties(new ArrayList<Property>());
+ complexType.setNavigationProperties(new ArrayList<NavigationProperty>());
+ complexType.setName(attr(element, "Name"));
+ if (attr(element, "BaseType") != null) {
+ complexType.setBaseType(new FullQualifiedName(attr(element, "BaseType")));
+ }
+ complexType.setAbstract(Boolean.parseBoolean(attr(element, "Abstract")));
+ complexType.setOpenType(Boolean.parseBoolean(attr(element, "OpenType")));
+ readProperties(reader, complexType);
+
+ schema.getComplexTypes().add(complexType);
+ }
+
+ private void readProperties(XMLEventReader reader, ComplexType complexType)
+ throws XMLStreamException {
+ new ElementReader<ComplexType>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, ComplexType complexType, String name)
+ throws XMLStreamException {
+ if (name.equals("Property")) {
+ complexType.getProperties().add(readProperty(element));
+ } else if (name.equals("NavigationProperty")) {
+ complexType.getNavigationProperties().add(readNavigationProperty(reader, element));
+ }
+ }
+ }.read(reader, null, complexType, "Property", "NavigationProperty");
+ }
+
+ abstract class ElementReader<T> {
+ void read(XMLEventReader reader, StartElement element, T t, String... names)
+ throws XMLStreamException {
+ while (reader.hasNext()) {
+ XMLEvent event = reader.peek();
+
+ event = skipAnnotations(reader, event);
+
+ if (!event.isStartElement() && !event.isEndElement()) {
+ reader.nextEvent();
+ continue;
+ }
+
+ boolean hit = false;
+
+ for (int i = 0; i < names.length; i++) {
+ if (event.isStartElement()) {
+ element = event.asStartElement();
+ if (element.getName().getLocalPart().equals(names[i])) {
+ reader.nextEvent(); // advance cursor
+ // System.out.println("reading = "+names[i]);
+ build(reader, element, t, names[i]);
+ hit = true;
+ }
+ }
+ if (event.isEndElement()) {
+ EndElement e = event.asEndElement();
+ if (e.getName().getLocalPart().equals(names[i])) {
+ reader.nextEvent(); // advance cursor
+ // System.out.println("done reading = "+names[i]);
+ hit = true;
+ }
+ }
+ }
+ if (!hit) {
+ break;
+ }
+ }
+ }
+
+ private XMLEvent skipAnnotations(XMLEventReader reader, XMLEvent event)
+ throws XMLStreamException {
+ boolean skip = false;
+
+ while (reader.hasNext()) {
+ if (event.isStartElement()) {
+ StartElement element = event.asStartElement();
+ if (element.getName().getLocalPart().equals("Annotation")) {
+ skip = true;
+ }
+ }
+ if (event.isEndElement()) {
+ EndElement element = event.asEndElement();
+ if (element.getName().getLocalPart().equals("Annotation")) {
+ return reader.peek();
+ }
+ }
+ if (skip) {
+ event = reader.nextEvent();
+ } else {
+ return event;
+ }
+ }
+ return event;
+ }
+
+ abstract void build(XMLEventReader reader, StartElement element, T t, String name)
+ throws XMLStreamException;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java
new file mode 100644
index 0000000..ddb8e6b
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java
@@ -0,0 +1,123 @@
+/*
+ * 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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.processor.Processor;
+import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.legacy.ProcessorServiceHandler;
+
+public class OData4HttpHandler extends ODataHttpHandlerImpl {
+ private ServiceHandler handler;
+ private final ServiceMetadata serviceMetadata;
+ private final OData odata;
+ private CustomContentTypeSupport customContentTypeSupport;
+
+
+ public OData4HttpHandler(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ this.odata = odata;
+ this.serviceMetadata = serviceMetadata;
+ // this is support old interfaces
+ this.handler = new ProcessorServiceHandler();
+ this.handler.init(odata, serviceMetadata);
+ }
+
+ @Override
+ public void process(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) {
+ ODataRequest request = null;
+ ODataResponse response = new ODataResponse();
+
+ try {
+ request = createODataRequest(httpRequest, 0);
+ validateODataVersion(request, response);
+
+ ServiceDispatcher dispatcher = new ServiceDispatcher(this.odata, this.serviceMetadata,
+ handler, this.customContentTypeSupport);
+ dispatcher.execute(request, response);
+
+ } catch (Exception e) {
+ ErrorHandler handler = new ErrorHandler(this.odata, this.serviceMetadata,
+ this.customContentTypeSupport);
+ handler.handleException(e, request, response);
+ }
+ convertToHttp(httpResponse, response);
+ }
+
+
+ ODataRequest createODataRequest(final HttpServletRequest httpRequest, final int split)
+ throws ODataTranslatedException {
+ try {
+ ODataRequest odRequest = new ODataRequest();
+
+ odRequest.setBody(httpRequest.getInputStream());
+ extractHeaders(odRequest, httpRequest);
+ extractMethod(odRequest, httpRequest);
+ extractUri(odRequest, httpRequest, split);
+
+ return odRequest;
+ } catch (final IOException e) {
+ throw new SerializerException(
+ "An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION); //$NON-NLS-1$
+ }
+ }
+
+ void validateODataVersion(final ODataRequest request, final ODataResponse response)
+ throws ODataHandlerException {
+ final String maxVersion = request.getHeader(HttpHeader.ODATA_MAX_VERSION);
+ response.setHeader(HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString());
+
+ if (maxVersion != null) {
+ if (ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) {
+ throw new ODataHandlerException("ODataVersion not supported: " + maxVersion, //$NON-NLS-1$
+ ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion);
+ }
+ }
+ }
+
+ @Override
+ public void register(final Processor processor) {
+
+ if (processor instanceof ServiceHandler) {
+ this.handler = (ServiceHandler) processor;
+ this.handler.init(this.odata, this.serviceMetadata);
+ }
+
+ if (this.handler instanceof ProcessorServiceHandler) {
+ ((ProcessorServiceHandler)this.handler).register(processor);
+ }
+ }
+
+ @Override
+ public void register(final CustomContentTypeSupport customContentTypeSupport) {
+ this.customContentTypeSupport = customContentTypeSupport;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4Impl.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4Impl.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4Impl.java
new file mode 100644
index 0000000..bde9c96
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4Impl.java
@@ -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.OData;
+import org.apache.olingo.server.api.ODataHttpHandler;
+import org.apache.olingo.server.api.ServiceMetadata;
+
+public class OData4Impl extends ODataImpl {
+
+ public static OData newInstance() {
+ try {
+ final Class<?> clazz = Class.forName(OData4Impl.class.getName());
+ final Object object = clazz.newInstance();
+ return (OData) object;
+ } catch (final Exception e) {
+ throw new ODataRuntimeException(e);
+ }
+ }
+
+ private OData4Impl() {
+ }
+
+ @Override
+ public ODataHttpHandler createHandler(final ServiceMetadata edm) {
+ return new OData4HttpHandler(this, edm);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java
new file mode 100644
index 0000000..ee00638
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java
@@ -0,0 +1,333 @@
+/*
+ * 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.util.List;
+
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoAll;
+import org.apache.olingo.server.api.uri.UriInfoBatch;
+import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
+import org.apache.olingo.server.api.uri.UriInfoEntityId;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.UriInfoMetadata;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.UriInfoService;
+import org.apache.olingo.server.api.uri.UriResource;
+import org.apache.olingo.server.api.uri.UriResourceAction;
+import org.apache.olingo.server.api.uri.UriResourceComplexProperty;
+import org.apache.olingo.server.api.uri.UriResourceCount;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.api.uri.UriResourceIt;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAll;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAny;
+import org.apache.olingo.server.api.uri.UriResourceLambdaVariable;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
+import org.apache.olingo.server.api.uri.UriResourceRef;
+import org.apache.olingo.server.api.uri.UriResourceRoot;
+import org.apache.olingo.server.api.uri.UriResourceSingleton;
+import org.apache.olingo.server.api.uri.UriResourceValue;
+import org.apache.olingo.server.api.uri.queryoption.CountOption;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.server.api.uri.queryoption.FilterOption;
+import org.apache.olingo.server.api.uri.queryoption.FormatOption;
+import org.apache.olingo.server.api.uri.queryoption.IdOption;
+import org.apache.olingo.server.api.uri.queryoption.OrderByOption;
+import org.apache.olingo.server.api.uri.queryoption.SearchOption;
+import org.apache.olingo.server.api.uri.queryoption.SelectOption;
+import org.apache.olingo.server.api.uri.queryoption.SkipOption;
+import org.apache.olingo.server.api.uri.queryoption.SkipTokenOption;
+import org.apache.olingo.server.api.uri.queryoption.TopOption;
+
+public class RequestURLHierarchyVisitor implements RequestURLVisitor {
+
+ private UriInfo uriInfo;
+
+ public UriInfo getUriInfo() {
+ return this.uriInfo;
+ }
+
+ @Override
+ public void visit(UriInfo info) {
+ this.uriInfo = info;
+
+ UriInfoKind kind = info.getKind();
+ switch (kind) {
+ case all:
+ visit(info.asUriInfoAll());
+ break;
+ case batch:
+ visit(info.asUriInfoBatch());
+ break;
+ case crossjoin:
+ visit(info.asUriInfoCrossjoin());
+ break;
+ case entityId:
+ visit(info.asUriInfoEntityId());
+ break;
+ case metadata:
+ visit(info.asUriInfoMetadata());
+ break;
+ case resource:
+ visit(info.asUriInfoResource());
+ break;
+ case service:
+ visit(info.asUriInfoService());
+ break;
+ }
+ }
+
+ @Override
+ public void visit(UriInfoService info) {
+ }
+
+ @Override
+ public void visit(UriInfoAll info) {
+ }
+
+ @Override
+ public void visit(UriInfoBatch info) {
+ }
+
+ @Override
+ public void visit(UriInfoCrossjoin info) {
+ }
+
+ @Override
+ public void visit(UriInfoEntityId info) {
+ visit(info.getSelectOption());
+
+ if (info.getExpandOption() != null) {
+ visit(info.getExpandOption());
+ }
+ if (info.getFormatOption() != null) {
+ visit(info.getFormatOption());
+ }
+ if (info.getIdOption() != null) {
+ visit(info.getIdOption(), info.getEntityTypeCast());
+ }
+ }
+
+ @Override
+ public void visit(UriInfoMetadata info) {
+ }
+
+ @Override
+ public void visit(UriInfoResource info) {
+ List<UriResource> parts = info.getUriResourceParts();
+ for (UriResource resource : parts) {
+ switch (resource.getKind()) {
+ case action:
+ visit((UriResourceAction) resource);
+ break;
+ case complexProperty:
+ visit((UriResourceComplexProperty) resource);
+ break;
+ case count:
+ visit((UriResourceCount) resource);
+ break;
+ case entitySet:
+ visit((UriResourceEntitySet) resource);
+ break;
+ case function:
+ visit((UriResourceFunction) resource);
+ break;
+ case it:
+ visit((UriResourceIt) resource);
+ break;
+ case lambdaAll:
+ visit((UriResourceLambdaAll) resource);
+ break;
+ case lambdaAny:
+ visit((UriResourceLambdaAny) resource);
+ break;
+ case lambdaVariable:
+ visit((UriResourceLambdaVariable) resource);
+ break;
+ case navigationProperty:
+ visit((UriResourceNavigation) resource);
+ break;
+ case ref:
+ visit((UriResourceRef) resource);
+ break;
+ case root:
+ visit((UriResourceRoot) resource);
+ break;
+ case primitiveProperty:
+ visit((UriResourcePrimitiveProperty) resource);
+ break;
+ case singleton:
+ visit((UriResourceSingleton) resource);
+ break;
+ case value:
+ visit((UriResourceValue) resource);
+ break;
+ }
+ }
+
+ // http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Toc372793682
+ if (info.getSearchOption() != null) {
+ visit(info.getSearchOption());
+ }
+
+ if (info.getFilterOption() != null) {
+ visit(info.getFilterOption());
+ }
+
+ if (info.getCountOption() != null) {
+ visit(info.getCountOption());
+ }
+
+ visit(info.getOrderByOption());
+
+ if (info.getSkipOption() != null) {
+ visit(info.getSkipOption());
+ }
+
+ if (info.getTopOption() != null) {
+ visit(info.getTopOption());
+ }
+
+ if (info.getExpandOption() != null) {
+ visit(info.getExpandOption());
+ }
+
+ visit(info.getSelectOption());
+
+ if (info.getFormatOption() != null) {
+ visit(info.getFormatOption());
+ }
+
+ if (info.getIdOption() != null) {
+ visit(info.getIdOption(), null);
+ }
+
+ if (info.getSkipTokenOption() != null) {
+ visit(info.getSkipTokenOption());
+ }
+
+ }
+
+ @Override
+ public void visit(ExpandOption option) {
+ }
+
+ @Override
+ public void visit(FilterOption info) {
+ }
+
+ @Override
+ public void visit(FormatOption info) {
+ }
+
+ @Override
+ public void visit(IdOption info, EdmEntityType type) {
+ }
+
+ @Override
+ public void visit(CountOption info) {
+ }
+
+ @Override
+ public void visit(OrderByOption option) {
+ }
+
+ @Override
+ public void visit(SearchOption option) {
+ }
+
+ @Override
+ public void visit(SelectOption option) {
+ }
+
+ @Override
+ public void visit(SkipOption option) {
+ }
+
+ @Override
+ public void visit(SkipTokenOption option) {
+ }
+
+ @Override
+ public void visit(TopOption option) {
+ }
+
+ @Override
+ public void visit(UriResourceCount option) {
+ }
+
+ @Override
+ public void visit(UriResourceRef info) {
+ }
+
+ @Override
+ public void visit(UriResourceRoot info) {
+ }
+
+ @Override
+ public void visit(UriResourceValue info) {
+ }
+
+ @Override
+ public void visit(UriResourceAction info) {
+ }
+
+ @Override
+ public void visit(UriResourceEntitySet info) {
+ }
+
+ @Override
+ public void visit(UriResourceFunction info) {
+ }
+
+ @Override
+ public void visit(UriResourceIt info) {
+ }
+
+ @Override
+ public void visit(UriResourceLambdaAll info) {
+ }
+
+ @Override
+ public void visit(UriResourceLambdaAny info) {
+ }
+
+ @Override
+ public void visit(UriResourceLambdaVariable info) {
+ }
+
+ @Override
+ public void visit(UriResourceNavigation info) {
+ }
+
+ @Override
+ public void visit(UriResourceSingleton info) {
+ }
+
+ @Override
+ public void visit(UriResourceComplexProperty info) {
+ }
+
+ @Override
+ public void visit(UriResourcePrimitiveProperty info) {
+ }
+}
[35/50] [abbrv] olingo-odata4 git commit: [OLINGO-545] TecSvc EDM
enhanced
Posted by ch...@apache.org.
[OLINGO-545] TecSvc EDM enhanced
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/15cfa375
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/15cfa375
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/15cfa375
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 15cfa375e8f3c4e33d6e6a92612f60b2fab8b069
Parents: 3e8c506
Author: Christian Holzer <c....@sap.com>
Authored: Tue Mar 31 18:47:57 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Tue Mar 31 18:48:35 2015 +0200
----------------------------------------------------------------------
.../olingo/fit/tecsvc/client/BasicITCase.java | 2 +-
.../olingo/fit/tecsvc/client/BindingITCase.java | 3 +-
.../fit/tecsvc/client/DeepInsertITCase.java | 25 ++++----
.../tecsvc/client/FilterSystemQueryITCase.java | 4 +-
.../olingo/server/tecsvc/data/DataCreator.java | 2 +-
.../server/tecsvc/provider/ActionProvider.java | 52 ++++++++++++++---
.../tecsvc/provider/ComplexTypeProvider.java | 19 ++++--
.../tecsvc/provider/ContainerProvider.java | 61 ++++++++++++++++++--
.../tecsvc/provider/EntityTypeProvider.java | 21 +++++--
.../tecsvc/provider/FunctionProvider.java | 54 +++++++++++++++--
.../tecsvc/provider/PropertyProvider.java | 55 +++++++++++++++++-
.../server/tecsvc/provider/SchemaProvider.java | 12 +++-
.../olingo/server/core/ODataHandlerTest.java | 2 +-
.../serializer/xml/MetadataDocumentTest.java | 6 +-
.../core/uri/antlr/TestFullResourcePath.java | 2 +-
15 files changed, 265 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
index 6ca841a..b7bac00 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
@@ -359,7 +359,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
final ODataEntity entity = entityResponse.getBody();
assertNotNull(entity);
final ODataComplexValue complex = entity.getProperty("PropertyCompCompNav").getComplexValue()
- .get("PropertyComp").getComplexValue();
+ .get("PropertyCompNav").getComplexValue();
assertNotNull(complex);
final ODataProperty property = complex.get("PropertyInt16");
assertNotNull(property);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
index 66f2149..d0435b2 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
@@ -61,7 +61,6 @@ public class BindingITCase extends AbstractBaseTestITCase {
private static final String CT_NAV_FIVE_PROP = "CTNavFiveProp";
private static final String PROPERTY_INT16 = "PropertyInt16";
private static final String PROPERTY_STRING = "PropertyString";
- private static final String PROPERTY_COMP = "PropertyComp";
private static final String PROPERTY_COMP_NAV = "PropertyCompNav";
private static final String PROPERTY_COMP_COMP_NAV = "PropertyCompCompNav";
private static final String PROPERTY_COMP_TWO_PRIM = "PropertyCompTwoPrim";
@@ -96,7 +95,7 @@ public class BindingITCase extends AbstractBaseTestITCase {
entity.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
// Bind existing entities via binding synatx
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
index 29b2baa..4e15ca0 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
@@ -64,7 +64,6 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
private static final String CT_NAV_FIVE_PROP = "CTNavFiveProp";
private static final String PROPERTY_INT16 = "PropertyInt16";
private static final String PROPERTY_STRING = "PropertyString";
- private static final String PROPERTY_COMP = "PropertyComp";
private static final String PROPERTY_COMP_NAV = "PropertyCompNav";
private static final String PROPERTY_COMP_COMP_NAV = "PropertyCompCompNav";
private static final String PROPERTY_COMP_TWO_PRIM = "PropertyCompTwoPrim";
@@ -103,7 +102,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
entity.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
// Non collection navigation property
@@ -114,7 +113,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
inlineEntitySingle.getProperties()
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("43")));
inlineEntitySingle.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 431)))));
inlineEntitySingle.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
@@ -130,7 +129,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
inlineEntityCol1.getProperties()
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("44")));
inlineEntityCol1.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 441)))));
inlineEntityCol1.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
@@ -143,7 +142,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
inlineEntityCol2.getProperties()
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("45")));
inlineEntityCol2.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 451)))));
inlineEntityCol2.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
@@ -184,7 +183,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
// Check nav. property NavPropertyETTwoKeyNavOne
assertNotNull(esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE));
assertEquals(431, esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE).getComplexValue().get(
- PROPERTY_COMP).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ PROPERTY_COMP_NAV).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
// Check nav. property NavPropertyETTwoKeyNavMany
assertNotNull(esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY));
@@ -193,10 +192,10 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
Iterator<ODataValue> twoKeyNavManyIterator =
esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).getCollectionValue().iterator();
final ODataValue firstTwoKeyNavEnity = twoKeyNavManyIterator.next(); // First entity
- assertEquals(441, firstTwoKeyNavEnity.asComplex().get(PROPERTY_COMP).getValue().asComplex().get(
+ assertEquals(441, firstTwoKeyNavEnity.asComplex().get(PROPERTY_COMP_NAV).getValue().asComplex().get(
PROPERTY_INT16).getPrimitiveValue().toValue());
final ODataValue secondTwoKeyNavEnity = twoKeyNavManyIterator.next(); // Second entity
- assertEquals(451, secondTwoKeyNavEnity.asComplex().get(PROPERTY_COMP).getValue().asComplex().get(
+ assertEquals(451, secondTwoKeyNavEnity.asComplex().get(PROPERTY_COMP_NAV).getValue().asComplex().get(
PROPERTY_INT16).getPrimitiveValue().toValue());
// Fetch ESTwoKeyNav entities and check if available and the partner relation have been set up
@@ -218,7 +217,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
.getEntityRequest(esTwoKeyNavEntitySingleURI);
esTwoKeyNavSingleRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ODataEntity> esTwoKeyNavSingleResponse = esTwoKeyNavSingleRequest.execute();
- assertEquals(431, esTwoKeyNavSingleResponse.getBody().getProperty(PROPERTY_COMP).getComplexValue().get(
+ assertEquals(431, esTwoKeyNavSingleResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(
PROPERTY_INT16).getPrimitiveValue().toValue());
// Check ESTwoKeyNav(Created via NavPropertyETTwoKeyNavMany(0))
@@ -236,7 +235,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
esTwoKeyNavManyOneRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ODataEntity> esTwoKeyNavManyOneResponse = esTwoKeyNavManyOneRequest.execute();
- assertEquals(441, esTwoKeyNavManyOneResponse.getBody().getProperty(PROPERTY_COMP).getComplexValue().get(
+ assertEquals(441, esTwoKeyNavManyOneResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(
PROPERTY_INT16).getPrimitiveValue().toValue());
assertNotNull(esTwoKeyNavManyOneResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue());
assertEquals(propertyInt16.getPrimitiveValue().toValue(), esTwoKeyNavManyOneResponse.getBody().getProperty(
@@ -257,7 +256,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
esTwoKeyNavManyTwoRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ODataEntity> esTwoKeyNavManyTwoResponse = esTwoKeyNavManyTwoRequest.execute();
- assertEquals(451, esTwoKeyNavManyTwoResponse.getBody().getProperty(PROPERTY_COMP).getComplexValue().get(
+ assertEquals(451, esTwoKeyNavManyTwoResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(
PROPERTY_INT16).getPrimitiveValue().toValue());
assertNotNull(esTwoKeyNavManyTwoResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue());
assertEquals(propertyInt16.getPrimitiveValue().toValue(), esTwoKeyNavManyTwoResponse.getBody().getProperty(
@@ -289,7 +288,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
entity.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
// Prepare inline entity(EntitySet: ESKeyNav, Type: ETKeyNav)
@@ -312,7 +311,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("431")))
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder()
.buildInt16((short) 431)))))));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
index af75958..8cb249d 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
@@ -959,11 +959,11 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase {
// Do the filter request
ODataRetrieveResponse<ODataEntitySet> result =
- sendRequest("ESKeyNav", "PropertyCompCompNav/PropertyComp/PropertyInt16 eq 1", cookie);
+ sendRequest("ESKeyNav", "PropertyCompCompNav/PropertyCompNav/PropertyInt16 eq 1", cookie);
assertEquals(3, result.getBody().getEntities().size());
// Try filter all entries where PropertyCompComp is null
- result = sendRequest("ESKeyNav", "PropertyCompCompNav/PropertyComp/PropertyInt16 eq null", cookie);
+ result = sendRequest("ESKeyNav", "PropertyCompCompNav/PropertyCompNav/PropertyInt16 eq null", cookie);
assertEquals(1, result.getBody().getEntities().size());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index e6193df..413ef34 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@ -138,7 +138,7 @@ public class DataCreator {
createKeyNavAllPrimComplexValue("PropertyComp"))))
.addProperty(createComplex("PropertyCompCompNav",
createPrimitive("PropertyString", "1"),
- createComplex("PropertyComp", createPrimitive("PropertyInt16", 1))));
+ createComplex("PropertyCompNav", createPrimitive("PropertyInt16", 1))));
}
private EntitySet createESTwoKeyNav() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
index dee0681..4318353 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
@@ -37,6 +37,9 @@ public class ActionProvider {
public static final FullQualifiedName nameBAESTwoKeyNavRTESTwoKeyNav =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BAESTwoKeyNavRTESTwoKeyNav");
+ public static final FullQualifiedName nameBAESTwoKeyNavRTESKeyNav =
+ new FullQualifiedName(SchemaProvider.NAMESPACE, "BAESTwoKeyNavRTESKeyNav");
+
public static final FullQualifiedName nameBAETBaseTwoKeyNavRTETBaseTwoKeyNav =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BAETBaseTwoKeyNavRTETBaseTwoKeyNav");
@@ -45,7 +48,10 @@ public class ActionProvider {
public static final FullQualifiedName nameBAETTwoKeyNavRTETTwoKeyNav =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BAETTwoKeyNavRTETTwoKeyNav");
-
+
+ public static final FullQualifiedName nameBAETAllPrimRT =
+ new FullQualifiedName(SchemaProvider.NAMESPACE, "BAESAllPrimRT");
+
// Unbound Actions
public static final FullQualifiedName nameUARTString = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UARTString");
@@ -69,7 +75,6 @@ public class ActionProvider {
public static final FullQualifiedName nameUARTTwoParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTTwoParam");
-
public List<Action> getActions(final FullQualifiedName actionName) throws ODataException {
if (actionName.equals(nameUARTString)) {
return Arrays.asList(
@@ -80,7 +85,8 @@ public class ActionProvider {
return Arrays.asList(
new Action().setName(nameUARTCollStringTwoParam.getName())
.setParameters(Arrays.asList(
- new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
+ new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16),
+ new Parameter().setName("ParameterDuration").setType(PropertyProvider.nameDuration)))
.setReturnType(new ReturnType().setType(PropertyProvider.nameString).setCollection(true))
);
@@ -91,7 +97,7 @@ public class ActionProvider {
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)
.setNullable(false)))
.setReturnType(
- new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim))
+ new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim).setNullable(false))
);
} else if (actionName.equals(nameUARTCollCTTwoPrimParam)) {
@@ -134,7 +140,8 @@ public class ActionProvider {
return Arrays.asList(
new Action().setName(nameUARTCollETAllPrimParam.getName())
.setParameters(Arrays.asList(
- new Parameter().setName("ParameterTimeOfDay").setType(PropertyProvider.nameInt16)))
+ new Parameter().setName("ParameterTimeOfDay")
+ .setType(PropertyProvider.nameTimeOfDay)))
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETAllPrim).setCollection(true))
);
@@ -199,7 +206,20 @@ public class ActionProvider {
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav).setCollection(true))
);
-
+
+ } else if(actionName.equals(nameBAESTwoKeyNavRTESKeyNav)) {
+ return Arrays.asList(
+ new Action().setName("BAESTwoKeyNavRTESKeyNav")
+ .setBound(true)
+ .setEntitySetPath("BindingParam/NavPropertyETKeyNavMany")
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterETTwoKeyNav")
+ .setType(EntityTypeProvider.nameETTwoKeyNav)
+ .setCollection(true)
+ .setNullable(false)
+ ))
+ .setReturnType(new ReturnType().setType(EntityTypeProvider.nameETKeyNav).setCollection(true))
+ );
} else if (actionName.equals(nameBAETBaseTwoKeyNavRTETBaseTwoKeyNav)) {
return Arrays.asList(
new Action().setName("BAETBaseTwoKeyNavRTETBaseTwoKeyNav")
@@ -222,7 +242,25 @@ public class ActionProvider {
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETBaseTwoKeyNav))
);
- }
+ } else if(actionName.equals(nameBAETAllPrimRT)) {
+ return Arrays.asList(
+ new Action().setName("BAETAllPrimRT")
+ .setBound(true)
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterETAllPrim")
+ .setNullable(false)
+ .setType(EntityTypeProvider.nameETAllPrim)
+ )),
+ new Action().setName("BAETAllPrimRT")
+ .setBound(true)
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterETAllPrim")
+ .setNullable(false)
+ .setCollection(true)
+ .setType(EntityTypeProvider.nameETAllPrim)
+ ))
+ );
+ }
return null;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java
index 5e2c556..52761c5 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java
@@ -18,6 +18,7 @@
*/
package org.apache.olingo.server.tecsvc.provider;
+import java.util.ArrayList;
import java.util.Arrays;
import org.apache.olingo.commons.api.ODataException;
@@ -51,6 +52,7 @@ public class ComplexTypeProvider {
public static final FullQualifiedName nameCTTwoPrim = new FullQualifiedName(SchemaProvider.NAMESPACE, "CTTwoPrim");
public static final FullQualifiedName nameCTMixEnumDef = new FullQualifiedName(SchemaProvider.NAMESPACE,
"CTMixEnumDef");
+ public static final FullQualifiedName nameCTNavCont = new FullQualifiedName(SchemaProvider.NAMESPACE, "CTNavCont");
public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
@@ -65,12 +67,11 @@ public class ComplexTypeProvider {
.setProperties(
Arrays.asList(PropertyProvider.propertyString, PropertyProvider.propertyBinary,
PropertyProvider.propertyBoolean, PropertyProvider.propertyByte, PropertyProvider.propertyDate,
- PropertyProvider.propertyDateTimeOffset, PropertyProvider.propertyDecimal,
+ PropertyProvider.propertyDateTimeOffset, PropertyProvider.propertyDecimal_Scale_Precision,
PropertyProvider.propertySingle, PropertyProvider.propertyDouble, PropertyProvider.propertyDuration,
PropertyProvider.propertyGuid, PropertyProvider.propertyInt16, PropertyProvider.propertyInt32,
PropertyProvider.propertyInt64, PropertyProvider.propertySByte, PropertyProvider.propertyTimeOfDay
));
-
} else if (complexTypeName.equals(nameCTCollAllPrim)) {
return new ComplexType()
.setName("CTCollAllPrim")
@@ -96,7 +97,7 @@ public class ComplexTypeProvider {
return new ComplexType()
.setName("CTCompNav")
.setProperties(Arrays.asList(PropertyProvider.propertyString,
- PropertyProvider.propertyComp_CTNavFiveProp));
+ PropertyProvider.propertyCompNav_CTNavFiveProp));
} else if (complexTypeName.equals(nameCTMixPrimCollComp)) {
return new ComplexType()
@@ -148,7 +149,17 @@ public class ComplexTypeProvider {
.setName("NavPropertyETMediaMany")
.setType(EntityTypeProvider.nameETMedia).setCollection(true)
)));
-
+
+ } else if(complexTypeName.equals(nameCTNavCont)) {
+ return new ComplexType()
+ .setName("CTNavCont")
+ .setProperties(new ArrayList<Property>())
+ .setNavigationProperties(Arrays.asList(
+ PropertyProvider.collectionNavPropertyETKeyNavContMany_CT_ETKeyNav,
+ PropertyProvider.navPropertyETKeyNavContOne_CT_ETeyNav,
+ PropertyProvider.collectionNavPropertyETTwoKeyNavContMany_CT_ETKeyNav,
+ PropertyProvider.navPropertyETTwoKeyNavContOne_CT_ETKeyNav));
+
} else if (complexTypeName.equals(nameCTBasePrimCompNav)) {
return new ComplexType()
.setName("CTBasePrimCompNav")
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
index ee62068..12cdb6f 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
@@ -288,7 +288,7 @@ public class ContainerProvider {
.setPath("NavPropertyETMediaMany")
.setTarget("ESMedia"),
new NavigationPropertyBinding()
- .setPath("PropertyCompNav/NavPropertyETTwoKeyNavOn")
+ .setPath("PropertyCompNav/NavPropertyETTwoKeyNavOne")
.setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/NavPropertyETTwoKeyNavMany")
@@ -370,15 +370,55 @@ public class ContainerProvider {
.setPath("NavPropertyETTwoBaseTwoKeyNavOne")
.setTarget("ESBaseTwoKeyNav"),
new NavigationPropertyBinding()
- .setPath("NavPropertySINav")
- .setTarget("SINav")
+ .setPath("ETBaseTwoKeyNav/CollPropertyCompNav/NavPropertyETTwoKeyNavMany")
+ .setTarget("ESTwoKeyNav"),
+ new NavigationPropertyBinding()
+ .setPath("ETBaseTwoKeyNav/NavPropertyETTwoBaseTwoKeyNavOne")
+ .setTarget("ESBaseTwoKeyNav"),
+ new NavigationPropertyBinding()
+ .setPath("NavPropertySINav")
+ .setTarget("SINav")
));
+
+ } else if(name.equals("ESKeyNavCont")) {
+ return new EntitySet()
+ .setName("ESKeyNavCont")
+ .setType(EntityTypeProvider.nameETKeyNavCont)
+ .setNavigationPropertyBindings(Arrays.asList(
+ new NavigationPropertyBinding()
+ .setPath("NavPropertyETTwoKeyNavContOne/NavPropertyETKeyNavOne")
+ .setTarget("ESKeyNav"),
+ new NavigationPropertyBinding()
+ .setPath("NavPropertyETTwoKeyNavContMany/NavPropertyETKeyNavOne")
+ .setTarget("ESKeyNav"),
+ new NavigationPropertyBinding()
+ .setPath("PropertyCompNavCont/NavPropertyETKeyNavContMany/NavPropertyETKeyNavOne")
+ .setTarget("ESKeyNav"),
+ new NavigationPropertyBinding()
+ .setPath("PropertyCompNavCont/NavPropertyETKeyNavContOne/NavPropertyETKeyNavOne")
+ .setTarget("ESKeyNav"),
+ new NavigationPropertyBinding()
+ .setPath("PropertyCompNavCont/NavPropertyETTwoKeyNavContMany/NavPropertyETKeyNavOne")
+ .setTarget("ESKeyNav"),
+ new NavigationPropertyBinding()
+ .setPath("PropertyCompNavCont/NavPropertyETTwoKeyNavContOne/NavPropertyETKeyNavOne")
+ .setTarget("ESKeyNav")
+ ));
} else if (name.equals("ESBaseTwoKeyNav")) {
return new EntitySet()
.setName("ESBaseTwoKeyNav")
- .setType(EntityTypeProvider.nameETBaseTwoKeyNav);
-
+ .setType(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .setNavigationPropertyBindings(Arrays.asList(
+ new NavigationPropertyBinding()
+ .setPath("NavPropertyETKeyNavMany")
+ .setTarget("ESKeyNav"))
+ );
+ } else if(name.equals("ESTwoBaseTwoKeyNav")) {
+ return new EntitySet()
+ .setName("ESTwoBaseTwoKeyNav")
+ .setType(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
+
} else if (name.equals("ESCompMixPrimCollComp")) {
return new EntitySet()
.setName("ESCompMixPrimCollComp")
@@ -434,11 +474,13 @@ public class ContainerProvider {
} else if (name.equals(AIRTES_ALL_PRIM_PARAM)) {
return new ActionImport()
.setName(AIRTES_ALL_PRIM_PARAM)
+ .setEntitySet("ESAllPrim")
.setAction(ActionProvider.nameUARTETAllPrimParam);
} else if (name.equals(AIRT_COLL_ES_ALL_PRIM_PARAM)) {
return new ActionImport()
.setName(AIRT_COLL_ES_ALL_PRIM_PARAM)
+ .setEntitySet("ESAllPrim")
.setAction(ActionProvider.nameUARTCollETAllPrimParam);
} else if (name.equals(AIRT)) {
@@ -605,7 +647,14 @@ public class ContainerProvider {
.setNavigationPropertyBindings(Arrays.asList(
new NavigationPropertyBinding()
.setPath("NavPropertyETTwoKeyNavMany")
- .setTarget("ESTwoKeyNav")));
+ .setTarget("ESTwoKeyNav"),
+ new NavigationPropertyBinding()
+ .setPath("NavPropertyETTwoKeyNavOne")
+ .setTarget("ESTwoKeyNav"),
+ new NavigationPropertyBinding()
+ .setPath("NavPropertyETKeyNavOne")
+ .setTarget("ESKeyNav")
+ ));
} else if (name.equals("SIMedia")) {
return new Singleton()
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
index a0cd6bb..4eb1b41 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
@@ -55,6 +55,8 @@ public class EntityTypeProvider {
public static final FullQualifiedName nameETKeyNav = new FullQualifiedName(SchemaProvider.NAMESPACE, "ETKeyNav");
public static final FullQualifiedName nameETKeyPrimNav = new FullQualifiedName(SchemaProvider.NAMESPACE,
"ETKeyPrimNav");
+ public static final FullQualifiedName nameETKeyNavCont = new FullQualifiedName(SchemaProvider.NAMESPACE,
+ "ETKeyNavCont");
public static final FullQualifiedName nameETKeyTwoKeyComp = new FullQualifiedName(SchemaProvider.NAMESPACE,
"ETKeyTwoKeyComp");
public static final FullQualifiedName nameETMedia = new FullQualifiedName(SchemaProvider.NAMESPACE, "ETMedia");
@@ -89,7 +91,7 @@ public class EntityTypeProvider {
PropertyProvider.propertyInt16_NotNullable, PropertyProvider.propertyString,
PropertyProvider.propertyBoolean, PropertyProvider.propertyByte, PropertyProvider.propertySByte,
PropertyProvider.propertyInt32, PropertyProvider.propertyInt64,
- PropertyProvider.propertySingle, PropertyProvider.propertyDouble, PropertyProvider.propertyDecimal,
+ PropertyProvider.propertySingle, PropertyProvider.propertyDouble, PropertyProvider.propertyDecimal_Scale,
PropertyProvider.propertyBinary, PropertyProvider.propertyDate, PropertyProvider.propertyDateTimeOffset,
PropertyProvider.propertyDuration, PropertyProvider.propertyGuid, PropertyProvider.propertyTimeOfDay
))
@@ -319,8 +321,7 @@ public class EntityTypeProvider {
PropertyProvider.navPropertyETKeyNavOne_ETKeyNav,
PropertyProvider.collectionNavPropertyETKeyNavMany_ETKeyNav,
PropertyProvider.navPropertyETMediaOne_ETMedia,
- PropertyProvider.collectionNavPropertyETMediaMany_ETMedia
- ));
+ PropertyProvider.collectionNavPropertyETMediaMany_ETMedia));
} else if (entityTypeName.equals(nameETKeyPrimNav)) {
return new EntityType()
.setName("ETKeyPrimNav")
@@ -330,6 +331,17 @@ public class EntityTypeProvider {
.setNavigationProperties(
Arrays.asList(
PropertyProvider.navPropertyETKeyPrimNavOne_ETKeyPrimNav));
+ } else if(entityTypeName.equals(nameETKeyNavCont)) {
+ return new EntityType()
+ .setName("ETKeyNavCont")
+ .setKey(Arrays.asList(new PropertyRef().setName("PropertyInt16")))
+ .setProperties(Arrays.asList(
+ PropertyProvider.propertyInt16_NotNullable, PropertyProvider.propertyString_NotNullable,
+ PropertyProvider.propertyCompNavCont))
+ .setNavigationProperties(Arrays.asList(
+ PropertyProvider.navPropertyETTwoKeyNavContOneCT_ETTwoKeyNav,
+ PropertyProvider.collectionNavPropertyETTwoKeyNavContMany_CT_ETTwoKeyNav
+ ));
} else if (entityTypeName.equals(nameETTwoKeyNav)) {
return new EntityType()
@@ -358,7 +370,8 @@ public class EntityTypeProvider {
.setReferencedProperty("PropertyInt16"))),
PropertyProvider.collectionNavPropertyETKeyNavMany_ETKeyNav,
PropertyProvider.navPropertyETTwoKeyNavOne_ETTwoKeyNav,
- PropertyProvider.collectionNavPropertyETTwoKeyNavMany_ETTwoKeyNav));
+ PropertyProvider.collectionNavPropertyETTwoKeyNavMany_ETTwoKeyNav,
+ PropertyProvider.collectionNavPropertySINav));
} else if (entityTypeName.equals(nameETBaseTwoKeyNav)) {
return new EntityType()
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
index 7a56d8c..84f57ff 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
@@ -118,7 +118,10 @@ public class FunctionProvider {
public static final FullQualifiedName nameBFCESTwoKeyNavRTCollCTNavFiveProp = new FullQualifiedName(
SchemaProvider.NAMESPACE, "BFCESTwoKeyNavRTCollCTNavFiveProp");
-
+
+ public static final FullQualifiedName nameBFCESKeyNavRTESTwoKeyNav =
+ new FullQualifiedName(SchemaProvider.NAMESPACE, "BFCESKeyNavRTESTwoKeyNav");
+
// Unbound Functions
public static final FullQualifiedName nameUFCRTCollCTTwoPrim =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UFCRTCollCTTwoPrim");
@@ -163,7 +166,10 @@ public class FunctionProvider {
public static final FullQualifiedName nameUFCRTCollETMixPrimCollCompTwoParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UFCRTCollETMixPrimCollCompTwoParam");
-
+
+ public static final FullQualifiedName nameUFCRTCollETKeyNavContParam =
+ new FullQualifiedName(SchemaProvider.NAMESPACE, "UFCRTCollETKeyNavContParam");
+
public static final FullQualifiedName nameUFNRTInt16 =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UFNRTInt16");
@@ -263,6 +269,21 @@ public class FunctionProvider {
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav).setCollection(true).setNullable(false))
);
+
+ } else if(functionName.equals(nameUFCRTCollETKeyNavContParam)) {
+ return Arrays.asList(
+ new Function()
+ .setName("UFCRTCollETKeyNavContParam")
+ .setBound(true)
+ .setComposable(true)
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterInt16")
+ .setNullable(false)
+ .setType(PropertyProvider.nameInt16)))
+ .setReturnType(new ReturnType().setType(EntityTypeProvider.nameETKeyNavCont)
+ .setCollection(true)
+ .setNullable(false))
+ );
} else if (functionName.equals(nameUFCRTString)) {
return Arrays.asList(
@@ -317,7 +338,7 @@ public class FunctionProvider {
.setName("UFCRTCTTwoPrimParam")
.setParameters(Arrays.asList(
new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16).setNullable(false),
- new Parameter().setName("ParameterString").setType(PropertyProvider.nameString).setNullable(true)))
+ new Parameter().setName("ParameterString").setType(PropertyProvider.nameString).setNullable(false)))
.setComposable(true)
.setReturnType(
new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim).setNullable(false))
@@ -358,7 +379,9 @@ public class FunctionProvider {
return Arrays.asList(
new Function()
.setName("UFCRTETMedia")
- .setParameters(new ArrayList<Parameter>())
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterInt16").setNullable(false).setType(PropertyProvider.nameInt16)
+ ))
.setComposable(true)
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETMedia).setNullable(false))
@@ -730,6 +753,7 @@ public class FunctionProvider {
.setParameters(Arrays.asList(
new Parameter().setName("BindingParam").setType(EntityTypeProvider.nameETKeyNav).setNullable(false)))
.setComposable(true)
+ .setEntitySetPath("BindingParam/NavPropertyETKeyNavOne")
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETKeyNav).setNullable(false))
);
@@ -747,7 +771,27 @@ public class FunctionProvider {
new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav).setCollection(true).setNullable(false))
);
-
+ } else if(functionName.equals(nameBFCESKeyNavRTESTwoKeyNav)) {
+ return Arrays.asList(
+ new Function()
+ .setName("BFCESKeyNavRTESTwoKeyNav")
+ .setEntitySetPath("BindingParam/NavPropertyETTwoKeyNavMany")
+ .setBound(true)
+ .setComposable(true)
+ .setParameters(Arrays.asList(
+ new Parameter().setName("BindingParam")
+ .setNullable(false)
+ .setType(EntityTypeProvider.nameETKeyNav)
+ .setCollection(true),
+ new Parameter().setName("ParameterString")
+ .setNullable(false)
+ .setType(PropertyProvider.nameString)))
+ .setReturnType(new ReturnType()
+ .setNullable(false)
+ .setType(EntityTypeProvider.nameETTwoKeyNav)
+ .setCollection(true))
+ );
+
} else if (functionName.equals(nameBFCETTwoKeyNavRTETTwoKeyNav)) {
return Arrays.asList(
new Function()
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
index c21fbce..ff2ad65 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
@@ -393,11 +393,17 @@ public class PropertyProvider {
.setType(nameDateTimeOffset)
.setNullable(true);
- public static final Property propertyDecimal = new Property()
+ public static final Property propertyDecimal_Scale_Precision = new Property()
.setName("PropertyDecimal")
.setScale(10)
+ .setPrecision(11)
.setType(nameDecimal);
-
+
+ public static final Property propertyDecimal_Scale = new Property()
+ .setName("PropertyDecimal")
+ .setScale(10)
+ .setType(nameDecimal);
+
public static final Property propertyDecimal_NotNullable = new Property()
.setName("PropertyDecimal")
.setType(nameDecimal)
@@ -579,7 +585,7 @@ public class PropertyProvider {
public static final Property propertyComp_CTNavFiveProp = new Property()
.setName("PropertyComp")
.setType(ComplexTypeProvider.nameCTNavFiveProp);
-
+
public static final Property propertyCompNav_CTNavFiveProp = new Property()
.setName("PropertyCompNav")
.setType(ComplexTypeProvider.nameCTNavFiveProp);
@@ -598,6 +604,10 @@ public class PropertyProvider {
.setType(ComplexTypeProvider.nameCTTwoPrim)
.setNullable(false);
+ public static final Property propertyCompNavCont = new Property()
+ .setName("PropertyCompNavCont")
+ .setType(ComplexTypeProvider.nameCTNavCont);
+
public static final Property propertyCompAllPrim_CTAllPrim = new Property()
.setName("PropertyCompAllPrim")
.setType(ComplexTypeProvider.nameCTAllPrim);
@@ -665,6 +675,23 @@ public class PropertyProvider {
.setType(EntityTypeProvider.nameETAllPrim)
.setCollection(true);
+ public static final NavigationProperty collectionNavPropertySINav = new NavigationProperty()
+ .setName("NavPropertySINav")
+ .setCollection(true)
+ .setType(EntityTypeProvider.nameETTwoKeyNav);
+
+ public static final NavigationProperty collectionNavPropertyETKeyNavContMany_CT_ETKeyNav = new NavigationProperty()
+ .setName("NavPropertyETKeyNavContMany")
+ .setCollection(true)
+ .setContainsTarget(true)
+ .setType(EntityTypeProvider.nameETKeyNav);
+
+ public static final NavigationProperty collectionNavPropertyETTwoKeyNavContMany_CT_ETKeyNav = new NavigationProperty()
+ .setName("NavPropertyETTwoKeyNavContMany")
+ .setCollection(true)
+ .setContainsTarget(true)
+ .setType(EntityTypeProvider.nameETKeyNav);
+
public static final NavigationProperty navPropertyETKeyNavOne_ETKeyNav = new NavigationProperty()
.setName("NavPropertyETKeyNavOne")
.setType(EntityTypeProvider.nameETKeyNav);
@@ -695,6 +722,28 @@ public class PropertyProvider {
.setName("NavPropertyETAllPrimOne")
.setType(EntityTypeProvider.nameETAllPrim);
+ public static final NavigationProperty navPropertyETKeyNavContOne_CT_ETeyNav = new NavigationProperty()
+ .setName("NavPropertyETKeyNavContOne")
+ .setContainsTarget(true)
+ .setType(EntityTypeProvider.nameETKeyNav);
+
+ public static final NavigationProperty navPropertyETTwoKeyNavContOne_CT_ETKeyNav = new NavigationProperty()
+ .setName("NavPropertyETTwoKeyNavContOne")
+ .setContainsTarget(true)
+ .setType(EntityTypeProvider.nameETKeyNav);
+
+ public static final NavigationProperty navPropertyETTwoKeyNavContOneCT_ETTwoKeyNav = new NavigationProperty()
+ .setName("NavPropertyETKeyNavContOne")
+ .setContainsTarget(true)
+ .setType(EntityTypeProvider.nameETTwoKeyNav);
+
+ public static final NavigationProperty collectionNavPropertyETTwoKeyNavContMany_CT_ETTwoKeyNav
+ = new NavigationProperty()
+ .setName("NavPropertyETTwoKeyNavContMany")
+ .setContainsTarget(true)
+ .setCollection(true)
+ .setType(EntityTypeProvider.nameETTwoKeyNav);
+
// EnumProperties --------------------------------------------------------------------------------------------------
public static final Property propertyEnumString_ENString = new Property()
.setName("PropertyEnumString")
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
index 057f4c9..ad3693c 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
@@ -79,7 +79,8 @@ public class SchemaProvider {
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETAbstract));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETAbstractBase));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETMixEnumDefCollComp));
-
+ entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETKeyNavCont));
+
// ComplexTypes
List<ComplexType> complexType = new ArrayList<ComplexType>();
schema.setComplexTypes(complexType);
@@ -98,7 +99,8 @@ public class SchemaProvider {
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoBasePrimCompNav));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTCompNav));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTMixEnumDef));
-
+ complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTNavCont));
+
// TypeDefinitions
List<TypeDefinition> typeDefinitions = new ArrayList<TypeDefinition>();
schema.setTypeDefinitions(typeDefinitions);
@@ -107,8 +109,10 @@ public class SchemaProvider {
// Actions
List<Action> actions = new ArrayList<Action>();
schema.setActions(actions);
+ actions.addAll(prov.getActions(ActionProvider.nameBAETAllPrimRT));
actions.addAll(prov.getActions(ActionProvider.nameBAETTwoKeyNavRTETTwoKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAESAllPrimRTETAllPrim));
+ actions.addAll(prov.getActions(ActionProvider.nameBAESTwoKeyNavRTESKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAESTwoKeyNavRTESTwoKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAETBaseTwoKeyNavRTETBaseTwoKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav));
@@ -131,6 +135,7 @@ public class SchemaProvider {
functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTInt16));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNav));
+ functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETKeyNavContParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNavParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNavParamCTTwoPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTStringTwoParam));
@@ -168,6 +173,7 @@ public class SchemaProvider {
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCCollCTPrimCompRTESAllPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESKeyNavRTETKeyNav));
+ functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESKeyNavRTESTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCETKeyNavRTETKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFESTwoKeyNavRTESTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCETTwoKeyNavRTETTwoKeyNav));
@@ -180,7 +186,7 @@ public class SchemaProvider {
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESKeyNavRTETKeyNavParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCCTPrimCompRTETTwoKeyNavParam));
// functions.addAll(prov.getFunctions(FunctionProvider.nameBFCCTPrimCompRTESTwoKeyNavParam));
-
+
// EntityContainer
schema.setEntityContainer(prov.getEntityContainer());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
index c317d0c..0ed13fe 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
@@ -369,7 +369,7 @@ public class ODataHandlerTest {
dispatchMethodNotAllowed(HttpMethod.PUT, complexCountUri, complexCountProcessor);
dispatchMethodNotAllowed(HttpMethod.DELETE, complexCountUri, complexCountProcessor);
- final String mediaUri = "FICRTESMedia()/$value";
+ final String mediaUri = "FICRTESMedia(ParameterInt16=1)/$value";
final MediaEntityProcessor mediaProcessor = mock(MediaEntityProcessor.class);
dispatch(HttpMethod.GET, mediaUri, mediaProcessor);
verify(mediaProcessor).readMediaEntity(
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
index 1101ded..f673787 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
@@ -88,8 +88,8 @@ public class MetadataDocumentTest {
assertThat(metadata, containsString("<Action Name=\"UARTCTTwoPrimParam\" IsBound=\"false\">"
+ "<Parameter Name=\"ParameterInt16\" Type=\"Edm.Int16\" Nullable=\"false\"/>"
- + "<ReturnType Type=\"Namespace1_Alias.CTTwoPrim\"/></Action>"));
-
+ + "<ReturnType Type=\"Namespace1_Alias.CTTwoPrim\" Nullable=\"false\"/></Action>"));
+
assertThat(metadata,
containsString("<Action Name=\"BAESAllPrimRTETAllPrim\" IsBound=\"true\">"
+ "<Parameter Name=\"ParameterESAllPrim\" "
@@ -114,6 +114,8 @@ public class MetadataDocumentTest {
assertThat(metadata,
containsString("<Singleton Name=\"SINav\" EntityType=\"Namespace1_Alias.ETTwoKeyNav\">"
+ "<NavigationPropertyBinding Path=\"NavPropertyETTwoKeyNavMany\" Target=\"ESTwoKeyNav\"/>"
+ + "<NavigationPropertyBinding Path=\"NavPropertyETTwoKeyNavOne\" Target=\"ESTwoKeyNav\"/>"
+ + "<NavigationPropertyBinding Path=\"NavPropertyETKeyNavOne\" Target=\"ESKeyNav\"/>"
+ "</Singleton>"));
assertThat(metadata,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/15cfa375/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index c7f6faf..863b800 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -1724,7 +1724,7 @@ public class TestFullResourcePath {
.isKeyPredicate(0, "PropertyInt16", "2")
.isKeyPredicate(1, "PropertyString", "'3'");
- testUri.run("FICRTESMedia()/$value")
+ testUri.run("FICRTESMedia(ParameterInt16=1)/$value")
.isKind(UriInfoKind.resource).goPath()
.first()
.isFunctionImport("FICRTESMedia")
[42/50] [abbrv] olingo-odata4 git commit: [OLINGO-573] Merge branch
'master' into OLINGO-573
Posted by ch...@apache.org.
[OLINGO-573] Merge branch 'master' into OLINGO-573
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/3f79ced1
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/3f79ced1
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/3f79ced1
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 3f79ced17ab9f7bd92851c264a231d2cb31d7ca3
Parents: de3f7fd fd9ba8b
Author: Michael Bolz <mi...@sap.com>
Authored: Wed Apr 1 20:51:25 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Apr 2 08:22:39 2015 +0200
----------------------------------------------------------------------
.../proxy/commons/EntityInvocationHandler.java | 2 +-
.../org/apache/olingo/fit/AbstractServices.java | 10 +-
.../api/communication/request/ODataRequest.java | 2 -
.../cud/ODataReferenceAddingRequest.java | 20 +-
.../response/ODataBatchResponse.java | 2 +-
.../response/ODataReferenceAddingResponse.java | 2 +-
.../olingo/client/api/uri/URIBuilder.java | 2 +-
.../apache/olingo/client/api/uri/URIFilter.java | 2 +-
.../request/AbstractODataRequest.java | 2 -
.../olingo/client/core/uri/FilterConst.java | 2 +-
.../olingo/client/core/uri/FilterLiteral.java | 2 +-
.../olingo/client/core/uri/FilterProperty.java | 2 +-
.../apache/olingo/client/core/uri/URIUtils.java | 1 -
.../commons/api/domain/ODataComplexValue.java | 1 -
.../commons/api/domain/ODataInlineEntity.java | 2 -
.../olingo/commons/api/domain/ODataLink.java | 1 -
.../commons/api/domain/ODataLinkType.java | 1 -
.../olingo/commons/api/edm/EdmOperation.java | 4 +-
.../commons/api/edm/EdmPrimitiveTypeKind.java | 2 -
.../commons/api/edm/constants/EdmTypeKind.java | 2 +-
.../olingo/commons/api/edm/provider/Schema.java | 4 +-
.../olingo/commons/api/format/ODataFormat.java | 1 -
.../serialization/JsonDeltaDeserializer.java | 12 +-
.../core/serialization/JsonDeserializer.java | 50 +--
.../serialization/JsonEntityDeserializer.java | 70 +++--
.../JsonEntitySetDeserializer.java | 18 +-
.../JsonODataErrorDeserializer.java | 4 +-
.../serialization/JsonPropertyDeserializer.java | 7 +-
.../api/deserializer/DeserializerException.java | 4 +-
.../api/serializer/FixedFormatSerializer.java | 2 +-
.../json/ODataJsonDeserializer.java | 57 ++--
.../serializer/json/ODataJsonSerializer.java | 15 +-
.../server-core-exceptions-i18n.properties | 2 +
.../core/edm/provider/EdmTypeImplTest.java | 4 +-
.../olingo/server/tecsvc/data/DataCreator.java | 308 ++++++++-----------
.../server/tecsvc/provider/ActionProvider.java | 182 ++++++-----
.../tecsvc/provider/ContainerProvider.java | 36 ++-
.../tecsvc/provider/FunctionProvider.java | 19 +-
.../tecsvc/provider/PropertyProvider.java | 2 +-
.../server/tecsvc/provider/SchemaProvider.java | 1 +
...ataJsonDeserializerActionParametersTest.java | 31 ++
.../core/uri/testutil/FilterValidator.java | 2 +-
.../core/uri/testutil/ParserValidator.java | 6 +-
43 files changed, 445 insertions(+), 456 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3f79ced1/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3f79ced1/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --cc lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index 5956e82,aab6624..a7ce16b
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@@ -147,9 -145,8 +147,12 @@@ public class ODataJsonSerializer implem
json.writeNumberField(Constants.JSON_COUNT, entitySet.getCount());
}
json.writeFieldName(Constants.VALUE);
- writeEntitySet(metadata, entityType, entitySet, options == null ? null : options.getExpand(),
- options == null ? null : options.getSelect(),
- options == null ? false : options.onlyReferences(), json);
- writeEntitySet(entityType, entitySet,
- options == null ? null : options.getExpand(), options == null ? null : options.getSelect(), json);
++ if(options == null) {
++ writeEntitySet(metadata, entityType, entitySet, null, null, false, json);
++ } else {
++ writeEntitySet(metadata, entityType, entitySet,
++ options.getExpand(), options.getSelect(), options.onlyReferences(), json);
++ }
if (entitySet.getNext() != null) {
json.writeStringField(Constants.JSON_NEXT_LINK, entitySet.getNext().toASCIIString());
}
@@@ -227,63 -214,9 +230,65 @@@
}
}
}
- writeProperties(entityType, entity.getProperties(), select, json);
- writeNavigationProperties(entityType, entity, expand, json);
- json.writeEndObject();
+ if (onlyReference) {
+ json.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
+ } else {
+ EdmEntityType resolvedType = resolveEntityType(metadata, entityType, entity.getType());
+ if (!resolvedType.equals(entityType)) {
+ json.writeStringField(Constants.JSON_TYPE, "#"+entity.getType());
+ }
+ writeProperties(resolvedType, entity.getProperties(), select, json);
+ writeNavigationProperties(metadata, resolvedType, entity, expand, json);
+ json.writeEndObject();
+ }
+ }
+
+ protected EdmEntityType resolveEntityType(ServiceMetadata metadata, EdmEntityType baseType,
+ String derivedTypeName) throws SerializerException {
- if (baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
++ if (derivedTypeName == null ||
++ baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
+ return baseType;
+ }
+ EdmEntityType derivedType = metadata.getEdm().getEntityType(new FullQualifiedName(derivedTypeName));
+ if (derivedType == null) {
+ throw new SerializerException("EntityType not found",
+ SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName);
+ }
+ EdmEntityType type = derivedType.getBaseType();
+ while (type != null) {
+ if (type.getFullQualifiedName().getFullQualifiedNameAsString()
+ .equals(baseType.getFullQualifiedName().getFullQualifiedNameAsString())) {
+ return derivedType;
+ }
+ type = type.getBaseType();
+ }
+ throw new SerializerException("Wrong base type",
+ SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType
+ .getFullQualifiedName().getFullQualifiedNameAsString());
+ }
+
+ protected EdmComplexType resolveComplexType(ServiceMetadata metadata, EdmComplexType baseType,
+ String derivedTypeName) throws SerializerException {
- if (baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
++ if (derivedTypeName == null ||
++ baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
+ return baseType;
+ }
+ EdmComplexType derivedType = metadata.getEdm().getComplexType(new FullQualifiedName(derivedTypeName));
+ if (derivedType == null) {
+ throw new SerializerException("Complex Type not found",
+ SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName);
+ }
+ EdmComplexType type = derivedType.getBaseType();
+ while (type != null) {
+ if (type.getFullQualifiedName().getFullQualifiedNameAsString()
+ .equals(baseType.getFullQualifiedName().getFullQualifiedNameAsString())) {
+ return derivedType;
+ }
+ type = type.getBaseType();
+ }
+ throw new SerializerException("Wrong base type",
+ SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType
+ .getFullQualifiedName().getFullQualifiedNameAsString());
}
protected void writeProperties(final EdmStructuredType type, final List<Property> properties,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3f79ced1/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3f79ced1/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --cc lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index 45fd740,413ef34..9de7166
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@@ -92,8 -92,8 +92,7 @@@ public class DataCreator
EntitySet entitySet = new EntitySetImpl();
for (int i = 1; i <= 503; i++) {
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", i))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", i))
.addProperty(createPrimitive("PropertyString", "Number:" + i)));
}
@@@ -112,32 -112,32 +111,20 @@@
@SuppressWarnings("unchecked")
private Entity createETKeyNavEntity(int propertyInt16, String propertyString) {
-- return new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", propertyInt16))
++ return new EntityImpl().addProperty(createPrimitive("PropertyInt16", propertyInt16))
.addProperty(createPrimitive("PropertyString", propertyString))
-- .addProperty(createComplex("PropertyCompNav",
-- createPrimitive("PropertyInt16", 1)))
-- .addProperty(createKeyNavAllPrimComplexValue("PropertyCompAllPrim"))
-- .addProperty(createComplex("PropertyCompTwoPrim",
-- createPrimitive("PropertyInt16", 16),
-- createPrimitive("PropertyString", "Test123")))
-- .addProperty(createPrimitiveCollection("CollPropertyString",
-- "Employee1@company.example",
-- "Employee2@company.example",
-- "Employee3@company.example"))
-- .addProperty(createPrimitiveCollection("CollPropertyInt16", 1000, 2000, 30112))
-- .addProperty(createComplexCollection("CollPropertyComp",
-- Arrays.asList(
-- createPrimitive("PropertyInt16", 1),
-- createKeyNavAllPrimComplexValue("PropertyComp")),
-- Arrays.asList(
-- createPrimitive("PropertyInt16", 2),
-- createKeyNavAllPrimComplexValue("PropertyComp")),
-- Arrays.asList(
-- createPrimitive("PropertyInt16", 3),
-- createKeyNavAllPrimComplexValue("PropertyComp"))))
-- .addProperty(createComplex("PropertyCompCompNav",
-- createPrimitive("PropertyString", "1"),
++ .addProperty(createComplex("PropertyCompNav", createPrimitive("PropertyInt16", 1)))
++ .addProperty(createKeyNavAllPrimComplexValue("PropertyCompAllPrim")).addProperty(
++ createComplex("PropertyCompTwoPrim", createPrimitive("PropertyInt16", 16),
++ createPrimitive("PropertyString", "Test123"))).addProperty(
++ createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
++ "Employee3@company.example"))
++ .addProperty(createPrimitiveCollection("CollPropertyInt16", 1000, 2000, 30112)).addProperty(
++ createComplexCollection("CollPropertyComp",
++ Arrays.asList(createPrimitive("PropertyInt16", 1), createKeyNavAllPrimComplexValue("PropertyComp")),
++ Arrays.asList(createPrimitive("PropertyInt16", 2), createKeyNavAllPrimComplexValue("PropertyComp")),
++ Arrays.asList(createPrimitive("PropertyInt16", 3), createKeyNavAllPrimComplexValue("PropertyComp"))))
++ .addProperty(createComplex("PropertyCompCompNav", createPrimitive("PropertyString", "1"),
createComplex("PropertyCompNav", createPrimitive("PropertyInt16", 1))));
}
@@@ -154,55 -154,56 +141,40 @@@
@SuppressWarnings("unchecked")
private Entity createESTwoKeyNavEntity(int propertyInt16, String propertyString) {
-- return new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", propertyInt16))
-- .addProperty(createPrimitive("PropertyString", propertyString))
-- .addProperty(createComplex("PropertyComp",
-- createPrimitive("PropertyInt16", 11),
-- createComplex("PropertyComp",
-- createPrimitive("PropertyString", "StringValue"),
-- createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }),
-- createPrimitive("PropertyBoolean", true),
-- createPrimitive("PropertyByte", 255),
-- createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 7, 16, 23)),
-- createPrimitive("PropertyDecimal", 34),
-- createPrimitive("PropertySingle", 179000000000000000000D),
-- createPrimitive("PropertyDouble", -179000000000000000000D),
-- createPrimitive("PropertyDuration", 6),
-- createPrimitive("PropertyGuid", UUID.fromString("01234567-89ab-cdef-0123-456789abcdef")),
-- createPrimitive("PropertyInt16", Short.MAX_VALUE),
-- createPrimitive("PropertyInt32", Integer.MAX_VALUE),
-- createPrimitive("PropertyInt64", Long.MAX_VALUE),
-- createPrimitive("PropertySByte", Byte.MAX_VALUE),
-- createPrimitive("PropertyTimeOfDay", getTime(21, 5, 59)))))
-- .addProperty(createComplex("PropertyCompNav",
-- createPrimitive("PropertyInt16", 1),
-- createKeyNavAllPrimComplexValue("PropertyComp")))
++ return new EntityImpl().addProperty(createPrimitive("PropertyInt16", propertyInt16))
++ .addProperty(createPrimitive("PropertyString", propertyString)).addProperty(
++ createComplex("PropertyComp", createPrimitive("PropertyInt16", 11),
++ createComplex("PropertyComp", createPrimitive("PropertyString", "StringValue"),
++ createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }),
++ createPrimitive("PropertyBoolean", true), createPrimitive("PropertyByte", 255),
++ createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 7, 16, 23)),
++ createPrimitive("PropertyDecimal", 34), createPrimitive("PropertySingle", 179000000000000000000D),
++ createPrimitive("PropertyDouble", -179000000000000000000D), createPrimitive("PropertyDuration", 6),
++ createPrimitive("PropertyGuid", UUID.fromString("01234567-89ab-cdef-0123-456789abcdef")),
++ createPrimitive("PropertyInt16", Short.MAX_VALUE),
++ createPrimitive("PropertyInt32", Integer.MAX_VALUE),
++ createPrimitive("PropertyInt64", Long.MAX_VALUE), createPrimitive("PropertySByte", Byte.MAX_VALUE),
++ createPrimitive("PropertyTimeOfDay", getTime(21, 5, 59))))).addProperty(
++ createComplex("PropertyCompNav", createPrimitive("PropertyInt16", 1),
++ createKeyNavAllPrimComplexValue("PropertyComp")))
.addProperty(createComplexCollection("CollPropertyComp"))
-- .addProperty(createComplexCollection("CollPropertyCompNav",
-- Arrays.asList(createPrimitive("PropertyInt16", 1))))
-- .addProperty(createPrimitiveCollection("CollPropertyString", 1, 2))
- .addProperty(createComplex("PropertyCompTwoPrim", createPrimitive("PropertyInt16", 11),
- .addProperty(createComplex("PropertyCompTwoPrim",
- createPrimitive("PropertyInt16", 11),
-- createPrimitive("PropertyString", "11")));
++ .addProperty(createComplexCollection("CollPropertyCompNav", Arrays.asList(createPrimitive("PropertyInt16", 1))))
++ .addProperty(createPrimitiveCollection("CollPropertyString", 1, 2)).addProperty(
++ createComplex("PropertyCompTwoPrim", createPrimitive("PropertyInt16", 11),
++ createPrimitive("PropertyString", "11")));
}
private Property createKeyNavAllPrimComplexValue(final String name) {
-- return createComplex(name,
-- createPrimitive("PropertyString", "First Resource - positive values"),
++ return createComplex(name, createPrimitive("PropertyString", "First Resource - positive values"),
createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }),
-- createPrimitive("PropertyBoolean", true),
-- createPrimitive("PropertyByte", 255),
++ createPrimitive("PropertyBoolean", true), createPrimitive("PropertyByte", 255),
createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 7, 16, 23)),
createPrimitive("PropertyDateTimeOffset", getTimestamp(2012, 12, 3, 7, 16, 23, 0)),
-- createPrimitive("PropertyDecimal", 34),
-- createPrimitive("PropertySingle", 179000000000000000000D),
-- createPrimitive("PropertyDouble", -179000000000000000000D),
-- createPrimitive("PropertyDuration", 6),
++ createPrimitive("PropertyDecimal", 34), createPrimitive("PropertySingle", 179000000000000000000D),
++ createPrimitive("PropertyDouble", -179000000000000000000D), createPrimitive("PropertyDuration", 6),
createPrimitive("PropertyGuid", UUID.fromString("01234567-89ab-cdef-0123-456789abcdef")),
-- createPrimitive("PropertyInt16", Short.MAX_VALUE),
-- createPrimitive("PropertyInt32", Integer.MAX_VALUE),
-- createPrimitive("PropertyInt64", Long.MAX_VALUE),
-- createPrimitive("PropertySByte", Byte.MAX_VALUE),
++ createPrimitive("PropertyInt16", Short.MAX_VALUE), createPrimitive("PropertyInt32", Integer.MAX_VALUE),
++ createPrimitive("PropertyInt64", Long.MAX_VALUE), createPrimitive("PropertySByte", Byte.MAX_VALUE),
createPrimitive("PropertyTimeOfDay", getTime(21, 5, 59)));
}
@@@ -210,25 -211,33 +182,23 @@@
private EntitySet createESCompCollComp() {
final EntitySet entitySet = new EntitySetImpl();
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
- .addProperty(createComplex("PropertyComp",
- createComplexCollection("CollPropertyComp",
- Arrays.asList(
- createPrimitive("PropertyInt16", 555),
- createPrimitive("PropertyString", "1 Test Complex in Complex Property")),
- Arrays.asList(
- createPrimitive("PropertyInt16", 666),
- createPrimitive("PropertyString", "2 Test Complex in Complex Property")),
- Arrays.asList(
- createPrimitive("PropertyInt16", 777),
- createPrimitive("PropertyString", "3 Test Complex in Complex Property"))))));
-
- entitySet.getEntities().add(new EntityImpl()
- .addProperty(createPrimitive("PropertyInt16", 12345))
- .addProperty(createComplex("PropertyComp",
- createComplexCollection("CollPropertyComp",
- Arrays.asList(
- createPrimitive("PropertyInt16", 888),
- createPrimitive("PropertyString", "11 Test Complex in Complex Property")),
- Arrays.asList(
- createPrimitive("PropertyInt16", 999),
- createPrimitive("PropertyString", "12 Test Complex in Complex Property")),
- Arrays.asList(
- createPrimitive("PropertyInt16", 0),
- createPrimitive("PropertyString", "13 Test Complex in Complex Property"))))));
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
+ .addProperty(createComplex("PropertyComp", createComplexCollection("CollPropertyComp", Arrays
+ .asList(createPrimitive("PropertyInt16", 555),
+ createPrimitive("PropertyString", "1 Test Complex in Complex Property")), Arrays
+ .asList(createPrimitive("PropertyInt16", 666),
+ createPrimitive("PropertyString", "2 Test Complex in Complex Property")), Arrays
+ .asList(createPrimitive("PropertyInt16", 777),
+ createPrimitive("PropertyString", "3 Test Complex in Complex Property"))))));
+
- entitySet.getEntities().add(new EntityImpl()
- .addProperty(createPrimitive("PropertyInt16", 12345))
- .addProperty(createComplex("PropertyComp", createComplexCollection("CollPropertyComp", Arrays
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 12345)).addProperty(
++ createComplex("PropertyComp", createComplexCollection("CollPropertyComp", Arrays
+ .asList(createPrimitive("PropertyInt16", 888),
+ createPrimitive("PropertyString", "11 Test Complex in Complex Property")), Arrays
+ .asList(createPrimitive("PropertyInt16", 999),
+ createPrimitive("PropertyString", "12 Test Complex in Complex Property")), Arrays
+ .asList(createPrimitive("PropertyInt16", 0),
+ createPrimitive("PropertyString", "13 Test Complex in Complex Property"))))));
return entitySet;
}
@@@ -236,20 -245,20 +206,16 @@@
private EntitySet createESTwoPrim() {
EntitySet entitySet = new EntitySetImpl();
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", 32766))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 32766))
.addProperty(createPrimitive("PropertyString", "Test String1")));
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", -365))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", -365))
.addProperty(createPrimitive("PropertyString", "Test String2")));
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", -32766))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", -32766))
.addProperty(createPrimitive("PropertyString", null)));
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
.addProperty(createPrimitive("PropertyString", "Test String4")));
return entitySet;
@@@ -289,16 -305,16 +255,11 @@@
.addProperty(createPrimitive("PropertyGuid", UUID.fromString("76543201-23ab-cdef-0123-456789dddfff")))
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(23, 49, 14))));
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", 0))
-- .addProperty(createPrimitive("PropertyString", ""))
-- .addProperty(createPrimitive("PropertyBoolean", false))
-- .addProperty(createPrimitive("PropertyByte", 0))
-- .addProperty(createPrimitive("PropertySByte", 0))
-- .addProperty(createPrimitive("PropertyInt32", 0))
-- .addProperty(createPrimitive("PropertyInt64", 0))
-- .addProperty(createPrimitive("PropertySingle", 0))
-- .addProperty(createPrimitive("PropertyDouble", 0))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 0))
++ .addProperty(createPrimitive("PropertyString", "")).addProperty(createPrimitive("PropertyBoolean", false))
++ .addProperty(createPrimitive("PropertyByte", 0)).addProperty(createPrimitive("PropertySByte", 0))
++ .addProperty(createPrimitive("PropertyInt32", 0)).addProperty(createPrimitive("PropertyInt64", 0))
++ .addProperty(createPrimitive("PropertySingle", 0)).addProperty(createPrimitive("PropertyDouble", 0))
.addProperty(createPrimitive("PropertyDecimal", 0))
.addProperty(createPrimitive("PropertyBinary", new byte[] {}))
.addProperty(createPrimitive("PropertyDate", getDateTime(1970, 1, 1, 0, 0, 0)))
@@@ -315,24 -331,24 +276,17 @@@
Entity entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE));
-- entity.addProperty(createComplex("PropertyComp",
-- createPrimitive("PropertyString", "First Resource - first"),
++ entity.addProperty(createComplex("PropertyComp", createPrimitive("PropertyString", "First Resource - first"),
createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
-- createPrimitive("PropertyBoolean", true),
-- createPrimitive("PropertyByte", 255),
++ createPrimitive("PropertyBoolean", true), createPrimitive("PropertyByte", 255),
createPrimitive("PropertyDate", getDateTime(2012, 10, 3, 0, 0, 0)),
createPrimitive("PropertyDateTimeOffset", getTimestamp(2012, 10, 3, 7, 16, 23, 123456700)),
-- createPrimitive("PropertyDecimal", 34.27),
-- createPrimitive("PropertySingle", 1.79000000E+20),
-- createPrimitive("PropertyDouble", -1.7900000000000000E+19),
-- createPrimitive("PropertyDuration", 6),
-- createPrimitive("PropertyGuid", GUID),
-- createPrimitive("PropertyInt16", Short.MAX_VALUE),
-- createPrimitive("PropertyInt32", Integer.MAX_VALUE),
-- createPrimitive("PropertyInt64", Long.MAX_VALUE),
-- createPrimitive("PropertySByte", Byte.MAX_VALUE),
-- createPrimitive("PropertyTimeOfDay", getTime(1, 0, 1))));
++ createPrimitive("PropertyDecimal", 34.27), createPrimitive("PropertySingle", 1.79000000E+20),
++ createPrimitive("PropertyDouble", -1.7900000000000000E+19), createPrimitive("PropertyDuration", 6),
++ createPrimitive("PropertyGuid", GUID), createPrimitive("PropertyInt16", Short.MAX_VALUE),
++ createPrimitive("PropertyInt32", Integer.MAX_VALUE), createPrimitive("PropertyInt64", Long.MAX_VALUE),
++ createPrimitive("PropertySByte", Byte.MAX_VALUE), createPrimitive("PropertyTimeOfDay", getTime(1, 0, 1))));
entitySet.getEntities().add(entity);
entity = new EntityImpl();
@@@ -372,10 -401,10 +326,9 @@@
private EntitySet createESCollAllPrim() {
EntitySet entitySet = new EntitySetImpl();
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", 1))
-- .addProperty(createPrimitiveCollection("CollPropertyString",
-- "Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 1)).addProperty(
++ createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
++ "Employee3@company.example"))
.addProperty(createPrimitiveCollection("CollPropertyBoolean", true, false, true))
.addProperty(createPrimitiveCollection("CollPropertyByte", 50, 200, 249))
.addProperty(createPrimitiveCollection("CollPropertySByte", -120, 120, 126))
@@@ -383,28 -412,28 +336,22 @@@
.addProperty(createPrimitiveCollection("CollPropertyInt32", 23232323, 11223355, 10000001))
.addProperty(createPrimitiveCollection("CollPropertyInt64", 929292929292L, 333333333333L, 444444444444L))
.addProperty(createPrimitiveCollection("CollPropertySingle", 1.79000000E+03, 2.66000000E+04, 3.21000000E+03))
-- .addProperty(createPrimitiveCollection("CollPropertyDouble",
-- -1.7900000000000000E+04, -2.7800000000000000E+07, 3.2100000000000000E+03))
-- .addProperty(createPrimitiveCollection("CollPropertyDecimal", 12, -2, 1234))
-- .addProperty(createPrimitiveCollection("CollPropertyBinary",
-- new byte[] { (byte) 0xAB, (byte) 0xCD, (byte) 0xEF },
-- new byte[] { 0x01, 0x23, 0x45 },
-- new byte[] { 0x54, 0x67, (byte) 0x89 }))
-- .addProperty(createPrimitiveCollection("CollPropertyDate",
-- getDateTime(1958, 12, 3, 0, 0, 0),
-- getDateTime(1999, 8, 5, 0, 0, 0),
-- getDateTime(2013, 6, 25, 0, 0, 0)))
-- .addProperty(createPrimitiveCollection("CollPropertyDateTimeOffset",
-- getDateTime(2015, 8, 12, 3, 8, 34),
-- getDateTime(1970, 3, 28, 12, 11, 10),
-- getDateTime(1948, 2, 17, 9, 9, 9)))
-- .addProperty(createPrimitiveCollection("CollPropertyDuration", 13, 19680, 3600))
-- .addProperty(createPrimitiveCollection("CollPropertyGuid",
-- UUID.fromString("ffffff67-89ab-cdef-0123-456789aaaaaa"),
-- UUID.fromString("eeeeee67-89ab-cdef-0123-456789bbbbbb"),
-- UUID.fromString("cccccc67-89ab-cdef-0123-456789cccccc")))
-- .addProperty(createPrimitiveCollection("CollPropertyTimeOfDay",
-- getTime(4, 14, 13), getTime(23, 59, 59), getTime(1, 12, 33))));
++ .addProperty(createPrimitiveCollection("CollPropertyDouble", -1.7900000000000000E+04, -2.7800000000000000E+07,
++ 3.2100000000000000E+03)).addProperty(createPrimitiveCollection("CollPropertyDecimal", 12, -2, 1234))
++ .addProperty(
++ createPrimitiveCollection("CollPropertyBinary", new byte[] { (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }, new
++ byte[] { 0x01, 0x23, 0x45 },
++ new byte[] { 0x54, 0x67, (byte) 0x89 })).addProperty(
++ createPrimitiveCollection("CollPropertyDate", getDateTime(1958, 12, 3, 0, 0, 0),
++ getDateTime(1999, 8, 5, 0, 0, 0), getDateTime(2013, 6, 25, 0, 0, 0))).addProperty(
++ createPrimitiveCollection("CollPropertyDateTimeOffset", getDateTime(2015, 8, 12, 3, 8, 34),
++ getDateTime(1970, 3, 28, 12, 11, 10), getDateTime(1948, 2, 17, 9, 9, 9)))
++ .addProperty(createPrimitiveCollection("CollPropertyDuration", 13, 19680, 3600)).addProperty(
++ createPrimitiveCollection("CollPropertyGuid", UUID.fromString("ffffff67-89ab-cdef-0123-456789aaaaaa"),
++ UUID.fromString("eeeeee67-89ab-cdef-0123-456789bbbbbb"),
++ UUID.fromString("cccccc67-89ab-cdef-0123-456789cccccc"))).addProperty(
++ createPrimitiveCollection("CollPropertyTimeOfDay", getTime(4, 14, 13), getTime(23, 59, 59),
++ getTime(1, 12, 33))));
Entity entity = new EntityImpl();
entity.getProperties().addAll(entitySet.getEntities().get(0).getProperties());
@@@ -420,39 -449,40 +367,31 @@@
}
private EntitySet createESMixPrimCollComp() {
-- @SuppressWarnings("unchecked")
-- final Property complexCollection = createComplexCollection("CollPropertyComp",
++ @SuppressWarnings("unchecked") final Property complexCollection = createComplexCollection("CollPropertyComp",
Arrays.asList(createPrimitive("PropertyInt16", 123), createPrimitive("PropertyString", "TEST 1")),
Arrays.asList(createPrimitive("PropertyInt16", 456), createPrimitive("PropertyString", "TEST 2")),
Arrays.asList(createPrimitive("PropertyInt16", 789), createPrimitive("PropertyString", "TEST 3")));
EntitySet entitySet = new EntitySetImpl();
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
-- .addProperty(createPrimitiveCollection("CollPropertyString",
-- "Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
-- .addProperty(createComplex("PropertyComp",
-- createPrimitive("PropertyInt16", 111),
-- createPrimitive("PropertyString", "TEST A")))
-- .addProperty(complexCollection));
--
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", 7))
- .addProperty(createPrimitiveCollection("CollPropertyString",
- "Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
- createPrimitive("PropertyInt16", 222),
- createPrimitive("PropertyString", "TEST B")))
- .addProperty(complexCollection));
-
- entitySet.getEntities().add(new EntityImpl()
- .addProperty(createPrimitive("PropertyInt16", 0))
- .addProperty(createPrimitiveCollection("CollPropertyString",
- "Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
- createPrimitive("PropertyInt16", 333),
- createPrimitive("PropertyString", "TEST C")))
- .addProperty(complexCollection));
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
+ .addProperty(
+ createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
- "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp", createPrimitive("PropertyInt16", 222),
- createPrimitive("PropertyString", "TEST B")))
- .addProperty(complexCollection));
-
- entitySet.getEntities().add(new EntityImpl()
- .addProperty(createPrimitive("PropertyInt16", 0))
- .addProperty(createPrimitiveCollection("CollPropertyString", "Employee1@company.example",
- "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp", createPrimitive("PropertyInt16", 333),
- createPrimitive("PropertyString", "TEST C")))
- .addProperty(complexCollection));
++ "Employee3@company.example")).addProperty(
++ createComplex("PropertyComp", createPrimitive("PropertyInt16", 111),
++ createPrimitive("PropertyString", "TEST A"))).addProperty(complexCollection));
++
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 7)).addProperty(
++ createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
++ "Employee3@company.example")).addProperty(
++ createComplex("PropertyComp", createPrimitive("PropertyInt16", 222),
++ createPrimitive("PropertyString", "TEST B"))).addProperty(complexCollection));
++
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", 0)).addProperty(
++ createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
++ "Employee3@company.example")).addProperty(
++ createComplex("PropertyComp", createPrimitive("PropertyInt16", 333),
++ createPrimitive("PropertyString", "TEST C"))).addProperty(complexCollection));
return entitySet;
}
@@@ -469,22 -501,23 +408,18 @@@
.addProperty(createPrimitive("PropertyDecimal", 34))
.addProperty(createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 0, 0, 0)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2012, 12, 3, 7, 16, 23)))
- .addProperty(createPrimitive("PropertyDuration", 6))
- .addProperty(createPrimitive("PropertyGuid", GUID))
+ .addProperty(createPrimitive("PropertyDuration", 6)).addProperty(createPrimitive("PropertyGuid", GUID))
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(2, 48, 21))));
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyString", "Second"))
-- .addProperty(createPrimitive("PropertyBoolean", true))
-- .addProperty(createPrimitive("PropertyByte", 254))
-- .addProperty(createPrimitive("PropertySByte", 124))
-- .addProperty(createPrimitive("PropertyInt16", 32764))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyString", "Second"))
++ .addProperty(createPrimitive("PropertyBoolean", true)).addProperty(createPrimitive("PropertyByte", 254))
++ .addProperty(createPrimitive("PropertySByte", 124)).addProperty(createPrimitive("PropertyInt16", 32764))
.addProperty(createPrimitive("PropertyInt32", 2147483644))
.addProperty(createPrimitive("PropertyInt64", 9223372036854775804L))
.addProperty(createPrimitive("PropertyDecimal", 34))
.addProperty(createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 0, 0, 0)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2012, 12, 3, 7, 16, 23)))
-- .addProperty(createPrimitive("PropertyDuration", 6))
-- .addProperty(createPrimitive("PropertyGuid", GUID))
++ .addProperty(createPrimitive("PropertyDuration", 6)).addProperty(createPrimitive("PropertyGuid", GUID))
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(2, 48, 21))));
return entitySet;
@@@ -496,8 -529,8 +431,7 @@@
Entity entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 1));
entity.addProperty(createComplex("PropertyComp",
-- createComplex("PropertyComp",
-- createPrimitive("PropertyInt16", 123),
++ createComplex("PropertyComp", createPrimitive("PropertyInt16", 123),
createPrimitive("PropertyString", "String 1"))));
entitySet.getEntities().add(entity);
@@@ -514,26 -548,26 +448,22 @@@
private EntitySet createESMedia() {
EntitySet entitySet = new EntitySetImpl();
-- Entity entity = new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", 1))
++ Entity entity = new EntityImpl().addProperty(createPrimitive("PropertyInt16", 1))
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("darkturquoise")));
entity.setMediaContentType("image/svg+xml");
entitySet.getEntities().add(entity);
-- entity = new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", 2))
++ entity = new EntityImpl().addProperty(createPrimitive("PropertyInt16", 2))
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("royalblue")));
entity.setMediaContentType("image/svg+xml");
entitySet.getEntities().add(entity);
-- entity = new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", 3))
++ entity = new EntityImpl().addProperty(createPrimitive("PropertyInt16", 3))
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("crimson")));
entity.setMediaContentType("image/svg+xml");
entitySet.getEntities().add(entity);
-- entity = new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", 4))
++ entity = new EntityImpl().addProperty(createPrimitive("PropertyInt16", 4))
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("black")));
entity.setMediaContentType("image/svg+xml");
entitySet.getEntities().add(entity);
@@@ -545,9 -579,9 +475,7 @@@
return ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 100 100\">\n"
+ " <g stroke=\"darkmagenta\" stroke-width=\"16\" fill=\"" + color + "\">\n"
-- + " <circle cx=\"50\" cy=\"50\" r=\"42\"/>\n"
-- + " </g>\n"
-- + "</svg>\n").getBytes(Charset.forName("UTF-8"));
++ + " <circle cx=\"50\" cy=\"50\" r=\"42\"/>\n" + " </g>\n" + "</svg>\n").getBytes(Charset.forName("UTF-8"));
}
private void linkESTwoPrim(Map<String, EntitySet> data) {
@@@ -566,8 -601,8 +494,8 @@@
setLinks(entitySet.getEntities().get(0), "NavPropertyETTwoPrimMany", targetEntities.get(1));
setLink(entitySet.getEntities().get(0), "NavPropertyETTwoPrimOne", targetEntities.get(3));
-- setLinks(entitySet.getEntities().get(2), "NavPropertyETTwoPrimMany",
-- targetEntities.get(0), targetEntities.get(2), targetEntities.get(3));
++ setLinks(entitySet.getEntities().get(2), "NavPropertyETTwoPrimMany", targetEntities.get(0), targetEntities.get(2),
++ targetEntities.get(3));
}
private void linkESKeyNav(Map<String, EntitySet> data) {
@@@ -613,12 -650,12 +541,9 @@@
setLink(entitySet.getEntities().get(3), "NavPropertyETKeyNavOne", esKeyNavTargets.get(2));
// NavPropertyETKeyNavMany
-- setLinks(entitySet.getEntities().get(0), "NavPropertyETKeyNavMany",
-- esKeyNavTargets.get(0), esKeyNavTargets.get(1));
-- setLinks(entitySet.getEntities().get(1), "NavPropertyETKeyNavMany",
-- esKeyNavTargets.get(0), esKeyNavTargets.get(1));
-- setLinks(entitySet.getEntities().get(2), "NavPropertyETKeyNavMany",
-- esKeyNavTargets.get(1), esKeyNavTargets.get(2));
++ setLinks(entitySet.getEntities().get(0), "NavPropertyETKeyNavMany", esKeyNavTargets.get(0), esKeyNavTargets.get(1));
++ setLinks(entitySet.getEntities().get(1), "NavPropertyETKeyNavMany", esKeyNavTargets.get(0), esKeyNavTargets.get(1));
++ setLinks(entitySet.getEntities().get(2), "NavPropertyETKeyNavMany", esKeyNavTargets.get(1), esKeyNavTargets.get(2));
// NavPropertyETTwoKeyNavOne
setLink(entitySet.getEntities().get(0), "NavPropertyETTwoKeyNavOne", esTwoKeyNavTargets.get(0));
@@@ -626,8 -663,8 +551,8 @@@
setLink(entitySet.getEntities().get(3), "NavPropertyETTwoKeyNavOne", esTwoKeyNavTargets.get(2));
// NavPropertyETTwoKeyNavMany
-- setLinks(entitySet.getEntities().get(0), "NavPropertyETTwoKeyNavMany",
-- esTwoKeyNavTargets.get(0), esTwoKeyNavTargets.get(1));
++ setLinks(entitySet.getEntities().get(0), "NavPropertyETTwoKeyNavMany", esTwoKeyNavTargets.get(0),
++ esTwoKeyNavTargets.get(1));
setLinks(entitySet.getEntities().get(1), "NavPropertyETTwoKeyNavMany", esTwoKeyNavTargets.get(0));
setLinks(entitySet.getEntities().get(2), "NavPropertyETTwoKeyNavMany", esTwoKeyNavTargets.get(1));
}
@@@ -640,6 -677,6 +565,10 @@@
return new PropertyImpl(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(values));
}
++ protected static Property createComplex(final String name, String type, final Property... properties) {
++ return createComplex(name, properties);
++ }
++
protected static Property createComplex(final String name, final Property... properties) {
ComplexValue complexValue = new ComplexValueImpl();
for (final Property property : properties) {
@@@ -648,6 -685,6 +577,11 @@@
return new PropertyImpl(null, name, ValueType.COMPLEX, complexValue);
}
++ protected static Property createComplexCollection(final String name, String type, final List<Property>...
++ propertiesList) {
++ return createComplexCollection(name, propertiesList);
++ }
++
protected static Property createComplexCollection(final String name, final List<Property>... propertiesList) {
List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
for (final List<Property> properties : propertiesList) {
[08/50] [abbrv] olingo-odata4 git commit: [OLINGO-603] dispatcher
improvements
Posted by ch...@apache.org.
[OLINGO-603] dispatcher improvements
Change-Id: Ic4fbb99fbce1c23d41df36ddc090f2b7f2ec1c22
Signed-off-by: Christian Amend <ch...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/4f33c704
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/4f33c704
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/4f33c704
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 4f33c704cf6b47bc969f0c981bf1f9e84d381c2f
Parents: 6421f54
Author: Klaus Straubinger <kl...@sap.com>
Authored: Fri Mar 27 10:27:35 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Mar 27 10:42:36 2015 +0100
----------------------------------------------------------------------
.../apache/olingo/server/core/ODataHandler.java | 289 ++++++++-----------
1 file changed, 124 insertions(+), 165 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4f33c704/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
index 6d98b5e..b01970d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
@@ -24,7 +24,6 @@ import java.util.List;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmFunction;
-import org.apache.olingo.commons.api.edm.EdmFunctionImport;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmReturnType;
import org.apache.olingo.commons.api.edm.EdmType;
@@ -101,8 +100,8 @@ public class ODataHandler {
odata = server;
this.serviceMetadata = serviceMetadata;
- register(new DefaultProcessor());
register(new DefaultRedirectProcessor());
+ register(new DefaultProcessor());
}
public ODataResponse process(final ODataRequest request) {
@@ -158,31 +157,23 @@ public class ODataHandler {
switch (uriInfo.getKind()) {
case metadata:
- if (method == HttpMethod.GET) {
- final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
- request, customContentTypeSupport, RepresentationType.METADATA);
- selectProcessor(MetadataProcessor.class)
- .readMetadata(request, response, uriInfo, requestedContentType);
- } else {
- throw new ODataHandlerException("HttpMethod " + method + " not allowed for metadata document",
- ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
- }
+ checkMethod(method, HttpMethod.GET);
+ final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
+ request, customContentTypeSupport, RepresentationType.METADATA);
+ selectProcessor(MetadataProcessor.class)
+ .readMetadata(request, response, uriInfo, requestedContentType);
break;
case service:
- if (method == HttpMethod.GET) {
- if ("".equals(request.getRawODataPath())) {
- selectProcessor(RedirectProcessor.class).redirect(request, response);
- } else {
- final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
- request, customContentTypeSupport, RepresentationType.SERVICE);
-
- selectProcessor(ServiceDocumentProcessor.class)
- .readServiceDocument(request, response, uriInfo, requestedContentType);
- }
+ checkMethod(method, HttpMethod.GET);
+ if ("".equals(request.getRawODataPath())) {
+ selectProcessor(RedirectProcessor.class)
+ .redirect(request, response);
} else {
- throw new ODataHandlerException("HttpMethod " + method + " not allowed for service document",
- ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
+ final ContentType serviceContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
+ request, customContentTypeSupport, RepresentationType.SERVICE);
+ selectProcessor(ServiceDocumentProcessor.class)
+ .readServiceDocument(request, response, uriInfo, serviceContentType);
}
break;
@@ -191,14 +182,9 @@ public class ODataHandler {
break;
case batch:
- if (method == HttpMethod.POST) {
- final BatchProcessor bp = selectProcessor(BatchProcessor.class);
- final BatchHandler handler = new BatchHandler(this, bp);
- handler.process(request, response, true);
- } else {
- throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
- ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
- }
+ checkMethod(method, HttpMethod.POST);
+ new BatchHandler(this, selectProcessor(BatchProcessor.class))
+ .process(request, response, true);
break;
default:
@@ -237,29 +223,33 @@ public class ODataHandler {
switch (lastPathSegment.getKind()) {
case action:
+ checkMethod(request.getMethod(), HttpMethod.POST);
handleActionDispatching(request, response, (UriResourceAction) lastPathSegment);
break;
case function:
+ checkMethod(request.getMethod(), HttpMethod.GET);
handleFunctionDispatching(request, response, (UriResourceFunction) lastPathSegment);
break;
case entitySet:
case navigationProperty:
- handleEntityDispatching(request, response, (UriResourcePartTyped) lastPathSegment);
+ handleEntityDispatching(request, response,
+ ((UriResourcePartTyped) lastPathSegment).isCollection(), isMedia(lastPathSegment));
break;
case count:
+ checkMethod(request.getMethod(), HttpMethod.GET);
handleCountDispatching(request, response, lastPathSegmentIndex);
break;
case primitiveProperty:
- handlePrimitivePropertyDispatching(request, response, false,
+ handlePrimitiveDispatching(request, response,
((UriResourceProperty) lastPathSegment).isCollection());
break;
case complexProperty:
- handleComplexPropertyDispatching(request, response, false,
+ handleComplexDispatching(request, response,
((UriResourceProperty) lastPathSegment).isCollection());
break;
@@ -279,86 +269,97 @@ public class ODataHandler {
private void handleFunctionDispatching(final ODataRequest request, final ODataResponse response,
final UriResourceFunction uriResourceFunction)
- throws ODataHandlerException, SerializerException, ContentNegotiatorException,
- ODataApplicationException, DeserializerException {
- final HttpMethod method = request.getMethod();
- if (method != HttpMethod.GET) {
- throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
- ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
- }
-
- EdmFunctionImport functionImport = uriResourceFunction.getFunctionImport();
- // could be null for bound functions
- if (functionImport == null) {
- throw new ODataHandlerException("Bound functions are not implemented yet",
- ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
+ SerializerException, DeserializerException {
+ EdmFunction function = uriResourceFunction.getFunction();
+ if (function == null) {
+ function = uriResourceFunction.getFunctionImport().getUnboundFunctions().get(0);
}
-
- List<EdmFunction> unboundFunctions = functionImport.getUnboundFunctions();
- if (unboundFunctions == null || unboundFunctions.isEmpty()) {
- throw new ODataHandlerException("No unbound function defined for function import",
+ final EdmReturnType returnType = function.getReturnType();
+ switch (returnType.getType().getKind()) {
+ case ENTITY:
+ handleEntityDispatching(request, response,
+ returnType.isCollection() && uriResourceFunction.getKeyPredicates().isEmpty(),
+ false);
+ break;
+ case PRIMITIVE:
+ handlePrimitiveDispatching(request, response, returnType.isCollection());
+ break;
+ case COMPLEX:
+ handleComplexDispatching(request, response, returnType.isCollection());
+ break;
+ default:
+ throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
- if(uriResourceFunction.getKeyPredicates().isEmpty()) {
- EdmReturnType returnType = unboundFunctions.get(0).getReturnType();
- handleOperationDispatching(request, response, false, returnType);
- } else {
- handleEntityDispatching(request, response, false, false, false);
- }
}
private void handleActionDispatching(final ODataRequest request, final ODataResponse response,
final UriResourceAction uriResourceAction)
- throws ODataHandlerException, SerializerException, ContentNegotiatorException,
- ODataApplicationException, DeserializerException {
-
- final HttpMethod method = request.getMethod();
- if (request.getMethod() != HttpMethod.POST) {
- throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
- ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
- }
-
+ throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
+ SerializerException, DeserializerException {
final EdmAction action = uriResourceAction.getAction();
- if (action == null) {
- throw new ODataHandlerException("No action defined for action import.",
- ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
- }
final EdmReturnType returnType = action.getReturnType();
+ final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
+ checkContentTypeSupport(requestFormat, RepresentationType.ACTION_PARAMETERS);
+
if (returnType == null) {
- final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
- checkContentTypeSupport(requestFormat, RepresentationType.ACTION_PARAMETERS);
selectProcessor(ActionVoidProcessor.class)
.processActionVoid(request, response, uriInfo, requestFormat);
} else {
- handleOperationDispatching(request, response, true, returnType);
- }
- }
-
- private void handleOperationDispatching(final ODataRequest request, final ODataResponse response,
- final boolean isAction, final EdmReturnType edmReturnType)
- throws ODataHandlerException, SerializerException, ContentNegotiatorException,
- ODataApplicationException, DeserializerException {
+ final boolean isCollection = returnType.isCollection();
+ ContentType responseFormat = null;
+ switch (returnType.getType().getKind()) {
+ case ENTITY:
+ responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
+ request, customContentTypeSupport,
+ isCollection ? RepresentationType.COLLECTION_ENTITY : RepresentationType.ENTITY);
+ if (isCollection) {
+ selectProcessor(ActionEntityCollectionProcessor.class)
+ .processActionEntityCollection(request, response, uriInfo, requestFormat, responseFormat);
+ } else {
+ selectProcessor(ActionEntityProcessor.class)
+ .processActionEntity(request, response, uriInfo, requestFormat, responseFormat);
+ }
+ break;
+
+ case PRIMITIVE:
+ responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
+ request, customContentTypeSupport,
+ isCollection ? RepresentationType.COLLECTION_PRIMITIVE : RepresentationType.PRIMITIVE);
+ if (isCollection) {
+ selectProcessor(ActionPrimitiveCollectionProcessor.class)
+ .processActionPrimitiveCollection(request, response, uriInfo, requestFormat, responseFormat);
+ } else {
+ selectProcessor(ActionPrimitiveProcessor.class)
+ .processActionPrimitive(request, response, uriInfo, requestFormat, responseFormat);
+ }
+ break;
+
+ case COMPLEX:
+ responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
+ request, customContentTypeSupport,
+ isCollection ? RepresentationType.COLLECTION_COMPLEX : RepresentationType.COMPLEX);
+ if (isCollection) {
+ selectProcessor(ActionComplexCollectionProcessor.class)
+ .processActionComplexCollection(request, response, uriInfo, requestFormat, responseFormat);
+ } else {
+ selectProcessor(ActionComplexProcessor.class)
+ .processActionComplex(request, response, uriInfo, requestFormat, responseFormat);
+ }
+ break;
- switch (edmReturnType.getType().getKind()) {
- case ENTITY:
- handleEntityDispatching(request, response, edmReturnType.isCollection(), false, isAction);
- break;
- case PRIMITIVE:
- handlePrimitivePropertyDispatching(request, response, isAction, edmReturnType.isCollection());
- break;
- case COMPLEX:
- handleComplexPropertyDispatching(request, response, isAction, edmReturnType.isCollection());
- break;
- default:
- throw new ODataHandlerException("not implemented",
- ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ default:
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ }
}
}
private void handleReferenceDispatching(final ODataRequest request, final ODataResponse response,
final int lastPathSegmentIndex)
- throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
- DeserializerException {
+ throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
+ SerializerException, DeserializerException {
final HttpMethod method = request.getMethod();
if (((UriResourcePartTyped) uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1)).isCollection()) {
if (method == HttpMethod.GET) {
@@ -397,8 +398,8 @@ public class ODataHandler {
private void handleValueDispatching(final ODataRequest request, final ODataResponse response,
final int lastPathSegmentIndex)
- throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
- DeserializerException {
+ throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
+ SerializerException, DeserializerException {
final HttpMethod method = request.getMethod();
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
if (resource instanceof UriResourceProperty
@@ -449,11 +450,10 @@ public class ODataHandler {
}
}
- private void handleComplexPropertyDispatching(final ODataRequest request, final ODataResponse response,
- final boolean isAction, final boolean isCollection)
- throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
- DeserializerException {
-
+ private void handleComplexDispatching(final ODataRequest request, final ODataResponse response,
+ final boolean isCollection)
+ throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
+ SerializerException, DeserializerException {
final HttpMethod method = request.getMethod();
final RepresentationType complexRepresentationType = isCollection ?
RepresentationType.COLLECTION_COMPLEX : RepresentationType.COMPLEX;
@@ -479,18 +479,6 @@ public class ODataHandler {
selectProcessor(ComplexProcessor.class)
.updateComplex(request, response, uriInfo, requestFormat, responseFormat);
}
- } else if (method == HttpMethod.POST && isAction) {
- final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
- checkContentTypeSupport(requestFormat, RepresentationType.ACTION_PARAMETERS);
- final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
- request, customContentTypeSupport, complexRepresentationType);
- if (isCollection) {
- selectProcessor(ActionComplexCollectionProcessor.class)
- .processActionComplexCollection(request, response, uriInfo, requestFormat, responseFormat);
- } else {
- selectProcessor(ActionComplexProcessor.class)
- .processActionComplex(request, response, uriInfo, requestFormat, responseFormat);
- }
} else if (method == HttpMethod.DELETE) {
if (isCollection) {
selectProcessor(ComplexCollectionProcessor.class)
@@ -505,11 +493,10 @@ public class ODataHandler {
}
}
- private void handlePrimitivePropertyDispatching(final ODataRequest request, final ODataResponse response,
- boolean isAction, final boolean isCollection)
- throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
- DeserializerException {
-
+ private void handlePrimitiveDispatching(final ODataRequest request, final ODataResponse response,
+ final boolean isCollection)
+ throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
+ SerializerException, DeserializerException {
final HttpMethod method = request.getMethod();
final RepresentationType representationType = isCollection ?
RepresentationType.COLLECTION_PRIMITIVE : RepresentationType.PRIMITIVE;
@@ -543,18 +530,6 @@ public class ODataHandler {
selectProcessor(PrimitiveProcessor.class)
.deletePrimitive(request, response, uriInfo);
}
- } else if (method == HttpMethod.POST && isAction) {
- final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
- checkContentTypeSupport(requestFormat, RepresentationType.ACTION_PARAMETERS);
- final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
- request, customContentTypeSupport, representationType);
- if (isCollection) {
- selectProcessor(ActionPrimitiveCollectionProcessor.class)
- .processActionPrimitiveCollection(request, response, uriInfo, requestFormat, responseFormat);
- } else {
- selectProcessor(ActionPrimitiveProcessor.class)
- .processActionPrimitive(request, response, uriInfo, requestFormat, responseFormat);
- }
} else {
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
@@ -563,8 +538,7 @@ public class ODataHandler {
private void handleCountDispatching(final ODataRequest request, final ODataResponse response,
final int lastPathSegmentIndex)
- throws ODataApplicationException, SerializerException, ODataHandlerException {
-
+ throws ODataHandlerException, ODataApplicationException, SerializerException {
final HttpMethod method = request.getMethod();
if (method == HttpMethod.GET) {
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
@@ -590,42 +564,25 @@ public class ODataHandler {
}
private void handleEntityDispatching(final ODataRequest request, final ODataResponse response,
- final UriResourcePartTyped uriResourcePart)
- throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
- DeserializerException {
- handleEntityDispatching(request, response, uriResourcePart.isCollection(), isMedia(uriResourcePart), false);
- }
-
- private void handleEntityDispatching(final ODataRequest request, final ODataResponse response,
- final boolean isCollection, final boolean isMedia, boolean isAction)
- throws ContentNegotiatorException, ODataApplicationException, SerializerException, ODataHandlerException,
- DeserializerException {
-
+ final boolean isCollection, final boolean isMedia)
+ throws ODataHandlerException, ContentNegotiatorException, ODataApplicationException,
+ SerializerException, DeserializerException {
final HttpMethod method = request.getMethod();
if (isCollection) {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.COLLECTION_ENTITY);
-
selectProcessor(EntityCollectionProcessor.class)
.readEntityCollection(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.POST) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
+ final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
+ request, customContentTypeSupport, RepresentationType.ENTITY);
if (isMedia) {
- final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
- request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(MediaEntityProcessor.class)
.createMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
- } else if (isAction) {
- checkContentTypeSupport(requestFormat, RepresentationType.ACTION_PARAMETERS);
- final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
- request, customContentTypeSupport, RepresentationType.COLLECTION_ENTITY);
- selectProcessor(ActionEntityCollectionProcessor.class)
- .processActionEntityCollection(request, response, uriInfo, requestFormat, responseFormat);
} else {
checkContentTypeSupport(requestFormat, RepresentationType.ENTITY);
- final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
- request, customContentTypeSupport, RepresentationType.ENTITY);
selectProcessor(EntityProcessor.class)
.createEntity(request, response, uriInfo, requestFormat, responseFormat);
}
@@ -637,21 +594,15 @@ public class ODataHandler {
if (method == HttpMethod.GET) {
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
-
- selectProcessor(EntityProcessor.class).readEntity(request, response, uriInfo, requestedContentType);
+ selectProcessor(EntityProcessor.class)
+ .readEntity(request, response, uriInfo, requestedContentType);
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
checkContentTypeSupport(requestFormat, RepresentationType.ENTITY);
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
request, customContentTypeSupport, RepresentationType.ENTITY);
- selectProcessor(EntityProcessor.class).updateEntity(request, response, uriInfo, requestFormat, responseFormat);
- } else if (method == HttpMethod.POST && isAction) {
- final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
- checkContentTypeSupport(requestFormat, RepresentationType.ACTION_PARAMETERS);
- final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
- request, customContentTypeSupport, RepresentationType.ENTITY);
- selectProcessor(ActionEntityProcessor.class).processActionEntity(
- request, response, uriInfo, requestFormat, responseFormat);
+ selectProcessor(EntityProcessor.class)
+ .updateEntity(request, response, uriInfo, requestFormat, responseFormat);
} else if (method == HttpMethod.DELETE) {
selectProcessor(isMedia ? MediaEntityProcessor.class : EntityProcessor.class)
.deleteEntity(request, response, uriInfo);
@@ -662,6 +613,14 @@ public class ODataHandler {
}
}
+ private void checkMethod(final HttpMethod requestMethod, final HttpMethod allowedMethod)
+ throws ODataHandlerException {
+ if (requestMethod != allowedMethod) {
+ throw new ODataHandlerException("HTTP method " + requestMethod + " is not allowed.",
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, requestMethod.toString());
+ }
+ }
+
private void checkContentTypeSupport(ContentType requestFormat, RepresentationType representationType)
throws ODataHandlerException, ContentNegotiatorException {
if (!ContentNegotiator.isSupported(requestFormat, customContentTypeSupport, representationType)) {
[06/50] [abbrv] olingo-odata4 git commit: [OLINGO-600] Fix: OData
client deserializer processes all navigation properties
Posted by ch...@apache.org.
[OLINGO-600] Fix: OData client deserializer processes all navigation
properties
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/0113414e
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/0113414e
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/0113414e
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 0113414e2624be103448d9bc08fada08f08ce86e
Parents: fcab8b0
Author: Christian Holzer <c....@sap.com>
Authored: Thu Mar 26 13:09:03 2015 +0100
Committer: Christian Holzer <c....@sap.com>
Committed: Thu Mar 26 15:03:27 2015 +0100
----------------------------------------------------------------------
.../olingo/fit/tecsvc/client/BasicITCase.java | 81 ++++++++++++++++----
.../core/serialization/ODataBinderImpl.java | 2 +-
2 files changed, 68 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0113414e/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
index 5bbde27..62d13bd 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
@@ -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.
*/
@@ -54,6 +54,8 @@ import org.apache.olingo.commons.api.domain.ODataComplexValue;
import org.apache.olingo.commons.api.domain.ODataEntity;
import org.apache.olingo.commons.api.domain.ODataEntitySet;
import org.apache.olingo.commons.api.domain.ODataError;
+import org.apache.olingo.commons.api.domain.ODataInlineEntity;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
import org.apache.olingo.commons.api.domain.ODataObjectFactory;
import org.apache.olingo.commons.api.domain.ODataProperty;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
@@ -330,17 +332,17 @@ public class BasicITCase extends AbstractBaseTestITCase {
newEntity.getProperties().add(factory.newComplexProperty("PropertyCompComp", null));
// The following properties must not be null
newEntity.getProperties().add(factory.newPrimitiveProperty("PropertyString",
- factory.newPrimitiveValueBuilder().buildString("Test")));
+ factory.newPrimitiveValueBuilder().buildString("Test")));
newEntity.getProperties().add(
factory.newComplexProperty("PropertyCompTwoPrim",
factory.newComplexValue("CTTwoPrim")
.add(factory.newPrimitiveProperty(
- "PropertyInt16",
- factory.newPrimitiveValueBuilder().buildInt16((short) 1)))
+ "PropertyInt16",
+ factory.newPrimitiveValueBuilder().buildInt16((short) 1)))
.add(factory.newPrimitiveProperty(
- "PropertyString",
- factory.newPrimitiveValueBuilder().buildString("Test2")))));
-
+ "PropertyString",
+ factory.newPrimitiveValueBuilder().buildString("Test2")))));
+
final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESKeyNav").appendKeySegment(1).build();
final ODataEntityUpdateRequest<ODataEntity> request = client.getCUDRequestFactory().getEntityUpdateRequest(
uri, UpdateType.REPLACE, newEntity);
@@ -388,6 +390,57 @@ public class BasicITCase extends AbstractBaseTestITCase {
assertNull(property2.getPrimitiveValue());
}
+ @Test
+ public void readEntityWithExpandedNavigationProperty() {
+ final ODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI);
+ client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
+
+ final URI uri = client.newURIBuilder(SERVICE_URI)
+ .appendEntitySetSegment("ESKeyNav")
+ .appendKeySegment(1)
+ .expand("NavPropertyETKeyNavOne", "NavPropertyETKeyNavMany")
+ .build();
+
+ final ODataRetrieveResponse<ODataEntity> response = client.getRetrieveRequestFactory()
+ .getEntityRequest(uri)
+ .execute();
+
+ assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
+
+ // Check if all inlined entities are available
+ // NavPropertyETKeyNavOne
+ assertNotNull(response.getBody().getNavigationLink("NavPropertyETKeyNavOne"));
+ final ODataInlineEntity inlineEntity = response.getBody()
+ .getNavigationLink("NavPropertyETKeyNavOne")
+ .asInlineEntity();
+ assertNotNull(inlineEntity);
+ assertEquals(Integer.valueOf(2), inlineEntity.getEntity()
+ .getProperty("PropertyInt16")
+ .getPrimitiveValue()
+ .toValue());
+
+ // NavPropertyETKeyNavMany
+ assertNotNull(response.getBody().getNavigationLink("NavPropertyETKeyNavMany"));
+ final ODataInlineEntitySet inlineEntitySet = response.getBody()
+ .getNavigationLink("NavPropertyETKeyNavMany")
+ .asInlineEntitySet();
+ assertNotNull(inlineEntitySet);
+ assertEquals(2, inlineEntitySet.getEntitySet().getEntities().size());
+ assertEquals(1, inlineEntitySet.getEntitySet()
+ .getEntities()
+ .get(0)
+ .getProperty("PropertyInt16")
+ .getPrimitiveValue()
+ .toValue());
+
+ assertEquals(2, inlineEntitySet.getEntitySet()
+ .getEntities()
+ .get(1)
+ .getProperty("PropertyInt16")
+ .getPrimitiveValue()
+ .toValue());
+ }
+
@Override
protected ODataClient getClient() {
ODataClient odata = ODataClientFactory.getClient();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0113414e/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
index e74e3fa..4e22b0d 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
@@ -662,7 +662,7 @@ public class ODataBinderImpl implements ODataBinder {
if (edmProperty instanceof EdmNavigationProperty) {
final String propertyTypeName = propertyType.getFullQualifiedName().getFullQualifiedNameAsString();
entity.addLink(createLinkFromNavigationProperty(property, propertyTypeName));
- break;
+ continue;
}
}
}
[36/50] [abbrv] olingo-odata4 git commit: [OLINGO-612] Changed 'is*'
behavior for Valuable
Posted by ch...@apache.org.
[OLINGO-612] Changed 'is*' behavior for Valuable
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/26be7d2e
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/26be7d2e
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/26be7d2e
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 26be7d2e7ccaa01968ab9a3e1d7259f48a762679
Parents: 15cfa37
Author: Michael Bolz <mi...@sap.com>
Authored: Wed Apr 1 10:49:39 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Wed Apr 1 11:02:53 2015 +0200
----------------------------------------------------------------------
.../org/apache/olingo/fit/AbstractServices.java | 18 +++----
.../core/serialization/ODataBinderImpl.java | 22 ++++----
.../olingo/commons/api/data/Valuable.java | 55 ++++++++++++++++++++
.../commons/core/data/AbstractValuable.java | 24 +++++++++
.../core/serialization/AtomSerializer.java | 2 +-
.../serialization/JsonPropertySerializer.java | 4 +-
.../core/serialization/JsonSerializer.java | 10 ++--
7 files changed, 108 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26be7d2e/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index 63a53af..a2ccbae 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -1914,15 +1914,7 @@ public abstract class AbstractServices {
alink.setRel(Constants.get(ConstantKey.ATOM_LINK_REL) + property.getName());
- if (property.isComplex()) {
- Entity inline = new EntityImpl();
- inline.setType(navProperties.get(property.getName()).getType());
- for (Property prop : property.asComplex().getValue()) {
- inline.getProperties().add(prop);
- }
- alink.setInlineEntity(inline);
-
- } else if (property.isCollection()) {
+ if (property.isCollection()) {
EntitySet inline = new EntitySetImpl();
for (Object value : property.asCollection()) {
Entity inlineEntity = new EntityImpl();
@@ -1933,6 +1925,14 @@ public abstract class AbstractServices {
inline.getEntities().add(inlineEntity);
}
alink.setInlineEntitySet(inline);
+ } else if (property.isComplex()) {
+ Entity inline = new EntityImpl();
+ inline.setType(navProperties.get(property.getName()).getType());
+ for (Property prop : property.asComplex().getValue()) {
+ inline.getProperties().add(prop);
+ }
+ alink.setInlineEntity(inline);
+
} else {
throw new IllegalStateException("Invalid navigation property " + property);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26be7d2e/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
index 4e22b0d..2ae47f1 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
@@ -740,13 +740,22 @@ public class ODataBinderImpl implements ODataBinder {
// fixes enum values treated as primitive when no type information is available
if (client instanceof EdmEnabledODataClient && type != null) {
final EdmEnumType edmType = ((EdmEnabledODataClient) client).getEdm(metadataETag).getEnumType(type);
- if (valuable.isPrimitive() && edmType != null) {
+ if (!valuable.isCollection() && valuable.isPrimitive() && edmType != null) {
valuable.setValue(ValueType.ENUM, valuable.asPrimitive());
}
}
ODataValue value = null;
- if (valuable.isEnum()) {
+
+ if (valuable.isCollection()) {
+ value = client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
+
+ for (Object _value : valuable.asCollection()) {
+ final Property fake = new PropertyImpl();
+ fake.setValue(valuable.getValueType().getBaseType(), _value);
+ value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
+ }
+ } else if (valuable.isEnum()) {
value = client.getObjectFactory().newEnumValue(type == null ? null : type.toString(),
valuable.asEnum().toString());
} else if (valuable.isComplex()) {
@@ -833,15 +842,6 @@ public class ODataBinderImpl implements ODataBinder {
}
value = cValue;
- } else if (valuable.isCollection()) {
- value =
- client.getObjectFactory().newCollectionValue(type == null ? null : "Collection(" + type.toString() + ")");
-
- for (Object _value : valuable.asCollection()) {
- final Property fake = new PropertyImpl();
- fake.setValue(valuable.getValueType().getBaseType(), _value);
- value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
- }
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26be7d2e/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Valuable.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Valuable.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Valuable.java
index ca660a8..78989b3 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Valuable.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Valuable.java
@@ -30,26 +30,81 @@ public interface Valuable {
boolean isNull();
+ /**
+ * Check if Valuable contains a PRIMITIVE or COLLECTION_PRIMITIVE ValueType
+ *
+ * @return true if ValueType is a PRIMITIVE or COLLECTION_PRIMITIVE, otherwise false
+ */
boolean isPrimitive();
+ /**
+ * Check if Valuable contains a GEOSPATIAL or COLLECTION_GEOSPATIAL ValueType
+ *
+ * @return true if ValueType is a GEOSPATIAL or COLLECTION_GEOSPATIAL, otherwise false
+ */
boolean isGeospatial();
+ /**
+ * Check if Valuable contains a ENUM or COLLECTION_ENUM ValueType
+ *
+ * @return true if ValueType is a ENUM or COLLECTION_ENUM, otherwise false
+ */
boolean isEnum();
+ /**
+ * Check if Valuable contains a COMPLEX or COLLECTION_COMPLEX ValueType
+ *
+ * @return true if ValueType is a COMPLEX or COLLECTION_COMPLEX, otherwise false
+ */
boolean isComplex();
+ /**
+ * Check if Valuable contains a COLLECTION_* ValueType
+ *
+ * @return true if ValueType is a COLLECTION_*, otherwise false
+ */
boolean isCollection();
+ /**
+ * Get the value
+ *
+ * @return the value
+ */
Object getValue();
+ /**
+ * Get the value in its primitive representation or null if it is not based on a primitive ValueType
+ *
+ * @return primitive representation or null if it is not based on a primitive ValueType
+ */
Object asPrimitive();
+ /**
+ * Get the value in its enum representation or null if it is not based on a enum ValueType
+ *
+ * @return enum representation or null if it is not based on a enum ValueType
+ */
Object asEnum();
+ /**
+ * Get the value in its geospatial representation or null if it is not based on a geospatial ValueType
+ *
+ * @return geospatial representation or null if it is not based on a geospatial ValueType
+ */
Geospatial asGeospatial();
+ /**
+ * Get the value in its complex representation or null if it is not based on a complex ValueType
+ *
+ * @return primitive complex or null if it is not based on a complex ValueType
+ */
ComplexValue asComplex();
+ /**
+ * Get the value as collection or null if it is not a collection ValueType
+ *
+ * @return collection or null if it is not a collection ValueType
+ */
List<?> asCollection();
void setValue(ValueType valuetype, Object value);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26be7d2e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java
index 6a5a96f..3a06511 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java
@@ -56,21 +56,33 @@ public abstract class AbstractValuable implements Valuable, Annotatable {
@Override
public boolean isPrimitive() {
+ if(isCollection()) {
+ return valueType.getBaseType() == ValueType.PRIMITIVE;
+ }
return valueType == ValueType.PRIMITIVE;
}
@Override
public boolean isGeospatial() {
+ if(isCollection()) {
+ return valueType.getBaseType() == ValueType.GEOSPATIAL;
+ }
return valueType == ValueType.GEOSPATIAL;
}
@Override
public boolean isEnum() {
+ if(isCollection()) {
+ return valueType.getBaseType() == ValueType.ENUM;
+ }
return valueType == ValueType.ENUM;
}
@Override
public boolean isComplex() {
+ if(isCollection()) {
+ return valueType.getBaseType() == ValueType.COMPLEX;
+ }
return valueType == ValueType.COMPLEX;
}
@@ -81,21 +93,33 @@ public abstract class AbstractValuable implements Valuable, Annotatable {
@Override
public Object asPrimitive() {
+ if(isCollection()) {
+ return null;
+ }
return isPrimitive() ? value : null;
}
@Override
public Geospatial asGeospatial() {
+ if(isCollection()) {
+ return null;
+ }
return isGeospatial() ? (Geospatial) value : null;
}
@Override
public Object asEnum() {
+ if(isCollection()) {
+ return null;
+ }
return isEnum() ? value : null;
}
@Override
public ComplexValue asComplex() {
+ if(isCollection()) {
+ return null;
+ }
return isComplex() ? (ComplexValue) value : null;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26be7d2e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
index 6bd5fbb..de06008 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
@@ -141,7 +141,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
value(writer, property.getValueType(), typeInfo == null ? null : typeInfo.getPrimitiveTypeKind(),
property.getValue());
- if (!property.isNull() && property.isComplex()) {
+ if (!property.isNull() && property.isComplex() && !property.isCollection()) {
links(writer, property.asComplex().getAssociationLinks());
links(writer, property.asComplex().getNavigationLinks());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26be7d2e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java
index f6ddd58..870cabd 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertySerializer.java
@@ -67,6 +67,8 @@ public class JsonPropertySerializer extends JsonSerializer {
if (property.isNull()) {
jgen.writeBooleanField(Constants.JSON_NULL, true);
+ } else if (property.isGeospatial() || property.isCollection()) {
+ valuable(jgen, property, Constants.VALUE);
} else if (property.isPrimitive()) {
final EdmTypeInfo typeInfo = property.getType() == null
? null
@@ -76,8 +78,6 @@ public class JsonPropertySerializer extends JsonSerializer {
primitiveValue(jgen, typeInfo, property.asPrimitive());
} else if (property.isEnum()) {
jgen.writeStringField(Constants.VALUE, property.asEnum().toString());
- } else if (property.isGeospatial() || property.isCollection()) {
- valuable(jgen, property, Constants.VALUE);
} else if (property.isComplex()) {
for (Property cproperty : property.asComplex().getValue()) {
valuable(jgen, cproperty, cproperty.getName());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26be7d2e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
index 012d3a3..fd3fda1 100755
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
@@ -336,6 +336,8 @@ public class JsonSerializer implements ODataSerializer {
if (value.isNull()) {
jgen.writeNull();
+ } else if (value.isCollection()) {
+ collection(jgen, typeInfo, value.getValueType(), value.asCollection());
} else if (value.isPrimitive()) {
primitiveValue(jgen, typeInfo, value.asPrimitive());
} else if (value.isEnum()) {
@@ -344,8 +346,6 @@ public class JsonSerializer implements ODataSerializer {
jgen.writeStartObject();
geoSerializer.serialize(jgen, value.asGeospatial());
jgen.writeEndObject();
- } else if (value.isCollection()) {
- collection(jgen, typeInfo, value.getValueType(), value.asCollection());
} else if (value.isComplex()) {
complexValue(jgen, typeInfo, value.asComplex().getValue(), value.asComplex());
}
@@ -355,10 +355,12 @@ public class JsonSerializer implements ODataSerializer {
throws IOException, EdmPrimitiveTypeException {
if (!Constants.VALUE.equals(name) && !(valuable instanceof Annotation)
- && !valuable.isComplex() && !valuable.isComplex()) {
+ && !(valuable.isComplex() && !valuable.isCollection())) {
String type = valuable.getType();
- if (StringUtils.isBlank(type) && valuable.isPrimitive() || valuable.isNull()) {
+ if ((!valuable.isCollection() &&
+ StringUtils.isBlank(type) &&
+ valuable.isPrimitive()) || valuable.isNull()) {
type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString();
}
if (StringUtils.isNotBlank(type) && format != ODataFormat.JSON_NO_METADATA) {
[37/50] [abbrv] olingo-odata4 git commit: [OLINGO-573] Merge branch
'master' into OLINGO-573
Posted by ch...@apache.org.
[OLINGO-573] Merge branch 'master' into OLINGO-573
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/de3f7fd3
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/de3f7fd3
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/de3f7fd3
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: de3f7fd3e7008f497a6e2ff6e67b8599fd295992
Parents: bce3ca6 26be7d2
Author: Michael Bolz <mi...@sap.com>
Authored: Wed Apr 1 13:17:12 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Wed Apr 1 13:17:12 2015 +0200
----------------------------------------------------------------------
.../org/apache/olingo/fit/AbstractServices.java | 18 +-
.../olingo/fit/tecsvc/client/BasicITCase.java | 2 +-
.../olingo/fit/tecsvc/client/BindingITCase.java | 3 +-
.../fit/tecsvc/client/DeepInsertITCase.java | 25 +-
.../tecsvc/client/FilterSystemQueryITCase.java | 4 +-
.../core/serialization/ODataBinderImpl.java | 22 +-
.../olingo/commons/api/data/Valuable.java | 55 ++++
.../commons/core/data/AbstractValuable.java | 24 ++
.../core/serialization/AtomSerializer.java | 2 +-
.../serialization/JsonPropertySerializer.java | 4 +-
.../core/serialization/JsonSerializer.java | 10 +-
.../olingo/server/tecsvc/data/DataCreator.java | 255 +++++++------------
.../server/tecsvc/provider/ActionProvider.java | 52 +++-
.../tecsvc/provider/ComplexTypeProvider.java | 19 +-
.../tecsvc/provider/ContainerProvider.java | 61 ++++-
.../tecsvc/provider/EntityTypeProvider.java | 21 +-
.../tecsvc/provider/FunctionProvider.java | 54 +++-
.../tecsvc/provider/PropertyProvider.java | 55 +++-
.../server/tecsvc/provider/SchemaProvider.java | 12 +-
.../olingo/server/core/ODataHandlerTest.java | 2 +-
.../serializer/xml/MetadataDocumentTest.java | 6 +-
.../core/uri/antlr/TestFullResourcePath.java | 2 +-
22 files changed, 460 insertions(+), 248 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/de3f7fd3/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --cc lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index 1f28900,413ef34..45fd740
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@@ -190,21 -175,15 +175,14 @@@ public class DataCreator
createPrimitive("PropertyInt64", Long.MAX_VALUE),
createPrimitive("PropertySByte", Byte.MAX_VALUE),
createPrimitive("PropertyTimeOfDay", getTime(21, 5, 59)))))
- .addProperty(
- createComplex("PropertyCompNav",
- ComplexTypeProvider.nameCTCompNav.getFullQualifiedNameAsString(),
+ .addProperty(createComplex("PropertyCompNav",
createPrimitive("PropertyInt16", 1),
createKeyNavAllPrimComplexValue("PropertyComp")))
- .addProperty(createComplexCollection("CollPropertyComp", null))
- .addProperty(
- createComplexCollection("CollPropertyCompNav",
- ComplexTypeProvider.nameCTCompNav.getFullQualifiedNameAsString(),
+ .addProperty(createComplexCollection("CollPropertyComp"))
+ .addProperty(createComplexCollection("CollPropertyCompNav",
Arrays.asList(createPrimitive("PropertyInt16", 1))))
.addProperty(createPrimitiveCollection("CollPropertyString", 1, 2))
- .addProperty(
- createComplex("PropertyCompTwoPrim",
- ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
- .addProperty(createComplex("PropertyCompTwoPrim",
-- createPrimitive("PropertyInt16", 11),
++ .addProperty(createComplex("PropertyCompTwoPrim", createPrimitive("PropertyInt16", 11),
createPrimitive("PropertyString", "11")));
}
@@@ -234,36 -213,32 +212,24 @@@
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
- .addProperty(createComplex("PropertyComp", null,
- createComplexCollection("CollPropertyComp", ComplexTypeProvider.nameCTTwoPrim
- .getFullQualifiedNameAsString(),
- .addProperty(createComplex("PropertyComp",
- createComplexCollection("CollPropertyComp",
-- Arrays.asList(
-- createPrimitive("PropertyInt16", 555),
-- createPrimitive("PropertyString", "1 Test Complex in Complex Property")),
-- Arrays.asList(
-- createPrimitive("PropertyInt16", 666),
-- createPrimitive("PropertyString", "2 Test Complex in Complex Property")),
-- Arrays.asList(
-- createPrimitive("PropertyInt16", 777),
-- createPrimitive("PropertyString", "3 Test Complex in Complex Property"))))));
++ .addProperty(createComplex("PropertyComp", createComplexCollection("CollPropertyComp", Arrays
++ .asList(createPrimitive("PropertyInt16", 555),
++ createPrimitive("PropertyString", "1 Test Complex in Complex Property")), Arrays
++ .asList(createPrimitive("PropertyInt16", 666),
++ createPrimitive("PropertyString", "2 Test Complex in Complex Property")), Arrays
++ .asList(createPrimitive("PropertyInt16", 777),
++ createPrimitive("PropertyString", "3 Test Complex in Complex Property"))))));
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", 12345))
- .addProperty(createComplex("PropertyComp",null,
- createComplexCollection("CollPropertyComp", ComplexTypeProvider.nameCTTwoPrim
- .getFullQualifiedNameAsString(),
- .addProperty(createComplex("PropertyComp",
- createComplexCollection("CollPropertyComp",
-- Arrays.asList(
-- createPrimitive("PropertyInt16", 888),
-- createPrimitive("PropertyString", "11 Test Complex in Complex Property")),
-- Arrays.asList(
-- createPrimitive("PropertyInt16", 999),
-- createPrimitive("PropertyString", "12 Test Complex in Complex Property")),
-- Arrays.asList(
-- createPrimitive("PropertyInt16", 0),
-- createPrimitive("PropertyString", "13 Test Complex in Complex Property"))))));
- for (Entity en:entitySet.getEntities()) {
- en.setType(EntityTypeProvider.nameETCompCollComp.getFullQualifiedNameAsString());
- }
++ .addProperty(createComplex("PropertyComp", createComplexCollection("CollPropertyComp", Arrays
++ .asList(createPrimitive("PropertyInt16", 888),
++ createPrimitive("PropertyString", "11 Test Complex in Complex Property")), Arrays
++ .asList(createPrimitive("PropertyInt16", 999),
++ createPrimitive("PropertyString", "12 Test Complex in Complex Property")), Arrays
++ .asList(createPrimitive("PropertyInt16", 0),
++ createPrimitive("PropertyString", "13 Test Complex in Complex Property"))))));
+
return entitySet;
}
@@@ -294,37 -267,37 +258,30 @@@
private EntitySet createESAllPrim() {
EntitySet entitySet = new EntitySetImpl();
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
.addProperty(createPrimitive("PropertyString", "First Resource - positive values"))
-- .addProperty(createPrimitive("PropertyBoolean", true))
-- .addProperty(createPrimitive("PropertyByte", 255))
++ .addProperty(createPrimitive("PropertyBoolean", true)).addProperty(createPrimitive("PropertyByte", 255))
.addProperty(createPrimitive("PropertySByte", Byte.MAX_VALUE))
.addProperty(createPrimitive("PropertyInt32", Integer.MAX_VALUE))
.addProperty(createPrimitive("PropertyInt64", Long.MAX_VALUE))
.addProperty(createPrimitive("PropertySingle", 1.79000000E+20))
.addProperty(createPrimitive("PropertyDouble", -1.7900000000000000E+19))
-- .addProperty(createPrimitive("PropertyDecimal", 34))
-- .addProperty(createPrimitive("PropertyBinary",
++ .addProperty(createPrimitive("PropertyDecimal", 34)).addProperty(createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }))
.addProperty(createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 0, 0, 0)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2012, 12, 3, 7, 16, 23)))
-- .addProperty(createPrimitive("PropertyDuration", 6))
-- .addProperty(createPrimitive("PropertyGuid", GUID))
++ .addProperty(createPrimitive("PropertyDuration", 6)).addProperty(createPrimitive("PropertyGuid", GUID))
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(3, 26, 5))));
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyInt16", Short.MIN_VALUE))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyInt16", Short.MIN_VALUE))
.addProperty(createPrimitive("PropertyString", "Second Resource - negative values"))
-- .addProperty(createPrimitive("PropertyBoolean", false))
-- .addProperty(createPrimitive("PropertyByte", 0))
++ .addProperty(createPrimitive("PropertyBoolean", false)).addProperty(createPrimitive("PropertyByte", 0))
.addProperty(createPrimitive("PropertySByte", Byte.MIN_VALUE))
.addProperty(createPrimitive("PropertyInt32", Integer.MIN_VALUE))
.addProperty(createPrimitive("PropertyInt64", Long.MIN_VALUE))
.addProperty(createPrimitive("PropertySingle", -1.79000000E+08))
.addProperty(createPrimitive("PropertyDouble", -1.7900000000000000E+05))
-- .addProperty(createPrimitive("PropertyDecimal", -34))
-- .addProperty(createPrimitive("PropertyBinary",
++ .addProperty(createPrimitive("PropertyDecimal", -34)).addProperty(createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }))
.addProperty(createPrimitive("PropertyDate", getDateTime(2015, 11, 5, 0, 0, 0)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2005, 12, 3, 7, 17, 8)))
@@@ -382,50 -353,48 +337,35 @@@
entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 7));
- entity.addProperty(createComplex("PropertyComp",ctPropComp,
- entity.addProperty(createComplex("PropertyComp",
-- createPrimitive("PropertyString", "Second Resource - second"),
++ entity.addProperty(createComplex("PropertyComp", createPrimitive("PropertyString", "Second Resource - second"),
createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
-- createPrimitive("PropertyBoolean", true),
-- createPrimitive("PropertyByte", 255),
++ createPrimitive("PropertyBoolean", true), createPrimitive("PropertyByte", 255),
createPrimitive("PropertyDate", getDateTime(2013, 11, 4, 0, 0, 0)),
createPrimitive("PropertyDateTimeOffset", getDateTime(2013, 11, 4, 7, 16, 23)),
-- createPrimitive("PropertyDecimal", 34.27),
-- createPrimitive("PropertySingle", 1.79000000E+20),
-- createPrimitive("PropertyDouble", -1.7900000000000000E+02),
-- createPrimitive("PropertyDuration", 6),
-- createPrimitive("PropertyGuid", GUID),
-- createPrimitive("PropertyInt16", 25),
-- createPrimitive("PropertyInt32", Integer.MAX_VALUE),
-- createPrimitive("PropertyInt64", Long.MAX_VALUE),
++ createPrimitive("PropertyDecimal", 34.27), createPrimitive("PropertySingle", 1.79000000E+20),
++ createPrimitive("PropertyDouble", -1.7900000000000000E+02), createPrimitive("PropertyDuration", 6),
++ createPrimitive("PropertyGuid", GUID), createPrimitive("PropertyInt16", 25),
++ createPrimitive("PropertyInt32", Integer.MAX_VALUE), createPrimitive("PropertyInt64", Long.MAX_VALUE),
createPrimitive("PropertySByte", Byte.MAX_VALUE),
createPrimitive("PropertyTimeOfDay", getTimestamp(1, 1, 1, 7, 45, 12, 765432100))));
entitySet.getEntities().add(entity);
entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 0));
- entity.addProperty(createComplex("PropertyComp",ctPropComp,
- entity.addProperty(createComplex("PropertyComp",
-- createPrimitive("PropertyString", "Third Resource - third"),
++ entity.addProperty(createComplex("PropertyComp", createPrimitive("PropertyString", "Third Resource - third"),
createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
-- createPrimitive("PropertyBoolean", true),
-- createPrimitive("PropertyByte", 255),
++ createPrimitive("PropertyBoolean", true), createPrimitive("PropertyByte", 255),
createPrimitive("PropertyDate", getDateTime(2014, 12, 5, 0, 0, 0)),
createPrimitive("PropertyDateTimeOffset", getTimestamp(2014, 12, 5, 8, 17, 45, 123456700)),
-- createPrimitive("PropertyDecimal", 17.98),
-- createPrimitive("PropertySingle", 1.79000000E+20),
-- createPrimitive("PropertyDouble", -1.7900000000000000E+02),
-- createPrimitive("PropertyDuration", 6),
-- createPrimitive("PropertyGuid", GUID),
-- createPrimitive("PropertyInt16", -25),
-- createPrimitive("PropertyInt32", Integer.MAX_VALUE),
-- createPrimitive("PropertyInt64", Long.MAX_VALUE),
-- createPrimitive("PropertySByte", Byte.MAX_VALUE),
-- createPrimitive("PropertyTimeOfDay", getTime(13, 27, 45))));
++ createPrimitive("PropertyDecimal", 17.98), createPrimitive("PropertySingle", 1.79000000E+20),
++ createPrimitive("PropertyDouble", -1.7900000000000000E+02), createPrimitive("PropertyDuration", 6),
++ createPrimitive("PropertyGuid", GUID), createPrimitive("PropertyInt16", -25),
++ createPrimitive("PropertyInt32", Integer.MAX_VALUE), createPrimitive("PropertyInt64", Long.MAX_VALUE),
++ createPrimitive("PropertySByte", Byte.MAX_VALUE), createPrimitive("PropertyTimeOfDay", getTime(13, 27, 45))));
entitySet.getEntities().add(entity);
- for (Entity en:entitySet.getEntities()) {
- en.setType(EntityTypeProvider.nameETCompAllPrim.getFullQualifiedNameAsString());
- }
+
return entitySet;
}
@@@ -501,34 -468,32 +439,29 @@@
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", 7))
-- .addProperty(createPrimitiveCollection("CollPropertyString",
-- "Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",ctPropComp,
- .addProperty(createComplex("PropertyComp",
-- createPrimitive("PropertyInt16", 222),
++ .addProperty(
++ createPrimitiveCollection("CollPropertyString", "Employee1@company.example", "Employee2@company.example",
++ "Employee3@company.example"))
++ .addProperty(createComplex("PropertyComp", createPrimitive("PropertyInt16", 222),
createPrimitive("PropertyString", "TEST B")))
.addProperty(complexCollection));
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", 0))
-- .addProperty(createPrimitiveCollection("CollPropertyString",
-- "Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",ctPropComp,
- .addProperty(createComplex("PropertyComp",
-- createPrimitive("PropertyInt16", 333),
++ .addProperty(createPrimitiveCollection("CollPropertyString", "Employee1@company.example",
++ "Employee2@company.example", "Employee3@company.example"))
++ .addProperty(createComplex("PropertyComp", createPrimitive("PropertyInt16", 333),
createPrimitive("PropertyString", "TEST C")))
.addProperty(complexCollection));
- for (Entity en:entitySet.getEntities()) {
- en.setType(EntityTypeProvider.nameETMixPrimCollComp.getFullQualifiedNameAsString());
- }
+
return entitySet;
}
private EntitySet createESAllKey() {
EntitySet entitySet = new EntitySetImpl();
-- entitySet.getEntities().add(new EntityImpl()
-- .addProperty(createPrimitive("PropertyString", "First"))
-- .addProperty(createPrimitive("PropertyBoolean", true))
-- .addProperty(createPrimitive("PropertyByte", 255))
++ entitySet.getEntities().add(new EntityImpl().addProperty(createPrimitive("PropertyString", "First"))
++ .addProperty(createPrimitive("PropertyBoolean", true)).addProperty(createPrimitive("PropertyByte", 255))
.addProperty(createPrimitive("PropertySByte", Byte.MAX_VALUE))
.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
.addProperty(createPrimitive("PropertyInt32", Integer.MAX_VALUE))
@@@ -536,8 -501,8 +469,7 @@@
.addProperty(createPrimitive("PropertyDecimal", 34))
.addProperty(createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 0, 0, 0)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2012, 12, 3, 7, 16, 23)))
-- .addProperty(createPrimitive("PropertyDuration", 6))
-- .addProperty(createPrimitive("PropertyGuid", GUID))
++ .addProperty(createPrimitive("PropertyDuration", 6)).addProperty(createPrimitive("PropertyGuid", GUID))
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(2, 48, 21))));
entitySet.getEntities().add(new EntityImpl()
@@@ -573,14 -536,12 +503,11 @@@
entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 2));
- entity.addProperty(createComplex("PropertyComp", null,
- createComplex("PropertyComp",ctPropComp,
- createPrimitive("PropertyInt16", 987),
+ entity.addProperty(createComplex("PropertyComp",
- createComplex("PropertyComp",
- createPrimitive("PropertyInt16", 987),
++ createComplex("PropertyComp", createPrimitive("PropertyInt16", 987),
createPrimitive("PropertyString", "String 2"))));
entitySet.getEntities().add(entity);
- for (Entity en:entitySet.getEntities()) {
- en.setType(EntityTypeProvider.nameETCompComp.getFullQualifiedNameAsString());
- }
+
return entitySet;
}
@@@ -629,8 -588,8 +554,7 @@@
final EntitySet entitySet = data.get("ESTwoPrim");
final List<Entity> targetEntities = data.get("ESAllPrim").getEntities();
-- setLinks(entitySet.getEntities().get(1), "NavPropertyETAllPrimMany",
-- targetEntities.get(1), targetEntities.get(2));
++ setLinks(entitySet.getEntities().get(1), "NavPropertyETAllPrimMany", targetEntities.get(1), targetEntities.get(2));
setLink(entitySet.getEntities().get(3), "NavPropertyETAllPrimOne", targetEntities.get(0));
}
@@@ -653,10 -612,10 +577,8 @@@
final List<Entity> esMediaTargets = data.get("ESMedia").getEntities();
// NavPropertyETKeyNavMany
-- setLinks(entitySet.getEntities().get(0), "NavPropertyETKeyNavMany",
-- esKeyNavTargets.get(0), esKeyNavTargets.get(1));
-- setLinks(entitySet.getEntities().get(1), "NavPropertyETKeyNavMany",
-- esKeyNavTargets.get(1), esKeyNavTargets.get(2));
++ setLinks(entitySet.getEntities().get(0), "NavPropertyETKeyNavMany", esKeyNavTargets.get(0), esKeyNavTargets.get(1));
++ setLinks(entitySet.getEntities().get(1), "NavPropertyETKeyNavMany", esKeyNavTargets.get(1), esKeyNavTargets.get(2));
// NavPropertyETKeyNavOne
setLink(entitySet.getEntities().get(0), "NavPropertyETKeyNavOne", esKeyNavTargets.get(1));
@@@ -668,8 -627,8 +590,8 @@@
setLink(entitySet.getEntities().get(2), "NavPropertyETTwoKeyNavOne", esTwoKeyNavTargets.get(2));
// NavPropertyETTwoKeyNavMany
-- setLinks(entitySet.getEntities().get(0), "NavPropertyETTwoKeyNavMany",
-- esTwoKeyNavTargets.get(0), esTwoKeyNavTargets.get(1));
++ setLinks(entitySet.getEntities().get(0), "NavPropertyETTwoKeyNavMany", esTwoKeyNavTargets.get(0),
++ esTwoKeyNavTargets.get(1));
setLinks(entitySet.getEntities().get(1), "NavPropertyETTwoKeyNavMany", esTwoKeyNavTargets.get(2));
setLinks(entitySet.getEntities().get(2), "NavPropertyETTwoKeyNavMany", esTwoKeyNavTargets.get(3));
@@@ -786,4 -744,4 +707,4 @@@
link.getInlineEntitySet().getEntities().addAll(Arrays.asList(targets));
}
}
--}
++}
[13/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Edm Cleanup
part 2
Posted by ch...@apache.org.
[OLINGO-575] Edm Cleanup part 2
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/898d745b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/898d745b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/898d745b
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 898d745bf552c7600d82f2ee762db4e9c30a9a19
Parents: 4d8a2a4
Author: Christian Amend <ch...@apache.org>
Authored: Fri Mar 27 16:43:43 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Mar 27 16:44:14 2015 +0100
----------------------------------------------------------------------
.../apache/olingo/commons/api/edm/Target.java | 89 ------------------
.../edm/provider/AbstractEdmAnnotatable.java | 10 +-
.../core/edm/provider/AbstractEdmBase.java | 31 -------
.../edm/provider/AbstractEdmBindingTarget.java | 9 +-
.../core/edm/provider/AbstractEdmOperation.java | 91 +++++++------------
.../provider/AbstractEdmOperationImport.java | 9 +-
.../edm/provider/AbstractEdmStructuredType.java | 26 +++---
.../core/edm/provider/EdmActionImpl.java | 6 +-
.../core/edm/provider/EdmAnnotationsImpl.java | 3 +-
.../core/edm/provider/EdmComplexTypeImpl.java | 7 +-
.../edm/provider/EdmEntityContainerImpl.java | 96 +++++++++-----------
.../core/edm/provider/EdmEntityTypeImpl.java | 13 +--
.../core/edm/provider/EdmEnumTypeImpl.java | 3 +-
.../core/edm/provider/EdmFunctionImpl.java | 6 +-
.../edm/provider/EdmNavigationPropertyImpl.java | 3 +-
.../core/edm/provider/EdmProviderImpl.java | 14 +--
.../core/edm/provider/EdmReturnTypeImpl.java | 1 -
.../core/edm/provider/EdmSchemaImpl.java | 32 +++----
.../commons/core/edm/provider/Target.java | 66 ++++++++++++++
.../xml/MetadataDocumentXmlSerializer.java | 5 +-
.../core/edm/provider/EdmActionImplTest.java | 6 +-
.../edm/provider/EdmActionImportImplTest.java | 25 +++--
.../edm/provider/EdmComplexTypeImplTest.java | 8 +-
.../provider/EdmEntityContainerImplTest.java | 52 +----------
.../core/edm/provider/EdmEntitySetImplTest.java | 17 ++--
.../edm/provider/EdmEntityTypeImplTest.java | 24 ++---
.../core/edm/provider/EdmFunctionImplTest.java | 4 +-
.../core/edm/provider/EdmSingletonImplTest.java | 35 ++++---
.../core/serializer/json/ComplexTypeHelper.java | 2 +-
.../serializer/utils/ContextURLBuilderTest.java | 2 +-
.../xml/MetadataDocumentXmlSerializerTest.java | 2 +-
.../tecsvc/provider/ContainerProvider.java | 91 +++++++++----------
.../sample/edmprovider/CarsEdmProvider.java | 8 +-
33 files changed, 330 insertions(+), 466 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Target.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Target.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Target.java
deleted file mode 100644
index 5fb2259..0000000
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Target.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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;
-
-/**
- * An Edm target element. It contains a target as a String name as well as the {@link FullQualifiedName} of the entity
- * container it is contained in.
- */
-public class Target {
-
- private String targetName;
-
- private FullQualifiedName entityContainer;
-
- public static class Builder {
-
- private final Target instance;
-
- public Builder(final String target, final EdmEntityContainer defaultContainer) {
- if (target != null) {
- final String[] bindingTargetParts = target.split("/");
- instance = new Target();
- if (bindingTargetParts.length == 1) {
- instance.setEntityContainer(defaultContainer.getFullQualifiedName()).
- setTargetName(bindingTargetParts[0]);
- } else {
- instance.setEntityContainer(new FullQualifiedName(bindingTargetParts[0])).
- setTargetName(bindingTargetParts[1]);
- }
- } else {
- instance = null;
- }
-
- }
-
- public Target build() {
- return instance;
- }
- }
-
- /**
- * @return name of the target as a String
- */
- public String getTargetName() {
- return targetName;
- }
-
- public Target setTargetName(final String targetPathName) {
- targetName = targetPathName;
- return this;
- }
-
- /**
- * @return {@link FullQualifiedName} of the entity container this target is contained in.
- */
- public FullQualifiedName getEntityContainer() {
- return entityContainer;
- }
-
- public Target setEntityContainer(final FullQualifiedName entityContainer) {
- this.entityContainer = entityContainer;
- return this;
- }
-
- @Override
- public String toString() {
- if(entityContainer == null){
- return targetName;
- }
- return entityContainer.getFullQualifiedNameAsString() + "/" + targetName;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java
index d36c3a2..ccc8801 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java
@@ -26,15 +26,17 @@ import org.apache.olingo.commons.api.edm.provider.Annotatable;
import org.apache.olingo.commons.api.edm.provider.Annotation;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-public abstract class AbstractEdmAnnotatable extends AbstractEdmBase implements EdmAnnotatable {
+public abstract class AbstractEdmAnnotatable implements EdmAnnotatable {
private final Annotatable annotatable;
private List<EdmAnnotation> annotations;
+ protected final Edm edm;
public AbstractEdmAnnotatable(final Edm edm, final Annotatable annotatable) {
- super(edm);
+ this.edm = edm;
this.annotatable = annotatable;
}
@@ -54,12 +56,12 @@ public abstract class AbstractEdmAnnotatable extends AbstractEdmBase implements
public List<EdmAnnotation> getAnnotations() {
if (annotations == null) {
annotations = new ArrayList<EdmAnnotation>();
- if(annotatable != null) {
+ if (annotatable != null) {
for (Annotation annotation : annotatable.getAnnotations()) {
annotations.add(new EdmAnnotationImpl(edm, annotation));
}
}
}
- return annotations;
+ return Collections.unmodifiableList(annotations);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBase.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBase.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBase.java
deleted file mode 100644
index e6d3c6a..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBase.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.provider;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotatable;
-
-public abstract class AbstractEdmBase implements EdmAnnotatable {
-
- protected final Edm edm;
-
- public AbstractEdmBase(final Edm edm) {
- this.edm = edm;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java
index 61bba66..d64270d 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java
@@ -19,6 +19,7 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -29,7 +30,6 @@ import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.commons.api.edm.provider.BindingTarget;
import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
@@ -57,7 +57,7 @@ public abstract class AbstractEdmBindingTarget extends AbstractEdmNamed implemen
}
}
}
- return navigationPropertyBindings;
+ return Collections.unmodifiableList(navigationPropertyBindings);
}
@Override
@@ -96,8 +96,11 @@ public abstract class AbstractEdmBindingTarget extends AbstractEdmNamed implemen
&& !found;) {
final EdmNavigationPropertyBinding binding = itor.next();
+ if(binding.getPath() == null || binding.getTarget() == null){
+ throw new EdmException("Path or Target in navigation property binding must not be null!");
+ }
if (path.startsWith(binding.getPath())) {
- final Target edmTarget = new Target.Builder(binding.getTarget(), container).build();
+ final Target edmTarget = new Target(binding.getTarget(), container);
final EdmEntityContainer entityContainer = edm.getEntityContainer(edmTarget.getEntityContainer());
if (entityContainer == null) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java
index 788a974..936a5ff 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java
@@ -19,6 +19,7 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -37,85 +38,58 @@ import org.apache.olingo.commons.api.edm.provider.Parameter;
public abstract class AbstractEdmOperation extends EdmTypeImpl implements EdmOperation {
- protected final Operation operation;
- private final Map<String, EdmParameter> parameters = new LinkedHashMap<String, EdmParameter>();
- private String entitySetPath;
- private boolean isBound;
- private EdmReturnType returnType;
+ private final Operation operation;
+ private Map<String, EdmParameter> parameters;
private List<String> parameterNames;
-
- protected static <T extends AbstractEdmOperation> T getInstance(final T instance) {
- final List<Parameter> providerParameters = instance.operation.getParameters();
- if (providerParameters != null) {
- final List<EdmParameter> _parameters = new ArrayList<EdmParameter>(providerParameters.size());
- for (Parameter parameter : providerParameters) {
- _parameters.add(new EdmParameterImpl(instance.edm, parameter));
- }
- instance.setParameters(_parameters);
- }
-
- final String entitySetPath = instance.operation.getEntitySetPath();
- if (entitySetPath != null) {
- instance.setEntitySetPath(entitySetPath);
- }
-
- instance.setIsBound(instance.operation.isBound());
-
- if (instance.operation.getReturnType() != null) {
- instance.setReturnType(new EdmReturnTypeImpl(instance.edm, instance.operation.getReturnType()));
- }
-
- return instance;
- }
+ private EdmReturnType returnType;
protected AbstractEdmOperation(final Edm edm, final FullQualifiedName name, final Operation operation,
- final EdmTypeKind kind) {
+ final EdmTypeKind kind) {
super(edm, name, kind, operation);
this.operation = operation;
}
-
- protected void setParameters(final List<EdmParameter> _parameters) {
- for (EdmParameter parameter : _parameters) {
- parameters.put(parameter.getName(), parameter);
- }
- }
-
- protected void setEntitySetPath(final String entitySetPath) {
- this.entitySetPath = entitySetPath;
- }
-
- protected void setIsBound(final boolean isBound) {
- this.isBound = isBound;
- }
-
- protected void setReturnType(final EdmReturnType returnType) {
- this.returnType = returnType;
- }
@Override
public EdmParameter getParameter(final String name) {
+ if (parameters == null) {
+ createParameters();
+ }
return parameters.get(name);
}
@Override
public List<String> getParameterNames() {
if (parameterNames == null) {
- parameterNames = new ArrayList<String>(parameters.size());
- for (String parameterName : parameters.keySet()) {
- parameterNames.add(parameterName);
+ createParameters();
+ }
+ return Collections.unmodifiableList(parameterNames);
+ }
+
+ private void createParameters() {
+ parameters = new LinkedHashMap<String, EdmParameter>();
+
+ final List<Parameter> providerParameters = operation.getParameters();
+ if (providerParameters != null) {
+ parameterNames = new ArrayList<String>(providerParameters.size());
+ for (Parameter parameter : providerParameters) {
+ parameters.put(parameter.getName(), new EdmParameterImpl(edm, parameter));
+ parameterNames.add(parameter.getName());
}
+
+ } else {
+ parameterNames = Collections.emptyList();
}
- return parameterNames;
}
@Override
public EdmEntitySet getReturnedEntitySet(final EdmEntitySet bindingParameterEntitySet) {
EdmEntitySet returnedEntitySet = null;
- if (bindingParameterEntitySet != null && entitySetPath != null) {
- final EdmBindingTarget relatedBindingTarget = bindingParameterEntitySet.getRelatedBindingTarget(entitySetPath);
+ if (bindingParameterEntitySet != null && operation.getEntitySetPath() != null) {
+ final EdmBindingTarget relatedBindingTarget =
+ bindingParameterEntitySet.getRelatedBindingTarget(operation.getEntitySetPath());
if (relatedBindingTarget == null) {
- throw new EdmException("Cannot find entity set with path: " + entitySetPath);
+ throw new EdmException("Cannot find entity set with path: " + operation.getEntitySetPath());
}
if (relatedBindingTarget instanceof EdmEntitySet) {
returnedEntitySet = (EdmEntitySet) relatedBindingTarget;
@@ -129,12 +103,15 @@ public abstract class AbstractEdmOperation extends EdmTypeImpl implements EdmOpe
@Override
public EdmReturnType getReturnType() {
+ if (returnType == null && operation.getReturnType() != null) {
+ returnType = new EdmReturnTypeImpl(edm, operation.getReturnType());
+ }
return returnType;
}
@Override
public boolean isBound() {
- return isBound;
+ return operation.isBound();
}
@Override
@@ -156,7 +133,7 @@ public abstract class AbstractEdmOperation extends EdmTypeImpl implements EdmOpe
}
@Override
- public String getEntitySetPath(){
+ public String getEntitySetPath() {
return operation.getEntitySetPath();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java
index 82c3465..27aa72b 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java
@@ -24,7 +24,6 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmOperationImport;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.commons.api.edm.provider.OperationImport;
public abstract class AbstractEdmOperationImport extends AbstractEdmNamed implements EdmOperationImport {
@@ -34,10 +33,14 @@ public abstract class AbstractEdmOperationImport extends AbstractEdmNamed implem
private EdmEntitySet returnedEntitySet;
public AbstractEdmOperationImport(final Edm edm, final EdmEntityContainer container,
- final OperationImport operationImport) {
+ final OperationImport operationImport) {
super(edm, operationImport.getName(), operationImport);
this.container = container;
- this.entitySet = new Target.Builder(operationImport.getEntitySet(), container).build();
+ if (operationImport.getEntitySet() != null) {
+ this.entitySet = new Target(operationImport.getEntitySet(), container);
+ } else {
+ this.entitySet = null;
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java
index 1d773ea..555652f 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java
@@ -32,6 +32,7 @@ import org.apache.olingo.commons.api.edm.provider.Property;
import org.apache.olingo.commons.api.edm.provider.StructuralType;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -40,12 +41,13 @@ public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements E
protected EdmStructuredType baseType;
protected FullQualifiedName baseTypeName;
+
+ private final StructuralType providerStructuredType;
private List<String> propertyNames;
- private List<String> navigationPropertyNames;
private Map<String, EdmProperty> properties;
+ private List<String> navigationPropertyNames;
private Map<String, EdmNavigationProperty> navigationProperties;
- private final StructuralType structuredType;
public AbstractEdmStructuredType(
final Edm edm,
@@ -55,7 +57,7 @@ public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements E
super(edm, typeName, kind, structuredType);
this.baseTypeName = structuredType.getBaseTypeFQN();
- this.structuredType = structuredType;
+ this.providerStructuredType = structuredType;
}
protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName);
@@ -72,7 +74,7 @@ public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements E
}
propertyNames.addAll(getProperties().keySet());
}
- return propertyNames;
+ return Collections.unmodifiableList(propertyNames);
}
@Override
@@ -85,7 +87,7 @@ public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements E
}
navigationPropertyNames.addAll(getNavigationProperties().keySet());
}
- return navigationPropertyNames;
+ return Collections.unmodifiableList(navigationPropertyNames);
}
@Override
@@ -154,31 +156,31 @@ public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements E
public Map<String, EdmProperty> getProperties() {
if (properties == null) {
properties = new LinkedHashMap<String, EdmProperty>();
- for (Property property : structuredType.getProperties()) {
+ for (Property property : providerStructuredType.getProperties()) {
properties.put(property.getName(), new EdmPropertyImpl(edm, typeName, property));
}
}
- return properties;
+ return Collections.unmodifiableMap(properties);
}
public Map<String, EdmNavigationProperty> getNavigationProperties() {
if (navigationProperties == null) {
navigationProperties = new LinkedHashMap<String, EdmNavigationProperty>();
- if (structuredType.getNavigationProperties() != null) {
- for (NavigationProperty navigationProperty : structuredType.getNavigationProperties()) {
+ if (providerStructuredType.getNavigationProperties() != null) {
+ for (NavigationProperty navigationProperty : providerStructuredType.getNavigationProperties()) {
navigationProperties.put(navigationProperty.getName(),
new EdmNavigationPropertyImpl(edm, typeName, navigationProperty));
}
}
}
- return navigationProperties;
+ return Collections.unmodifiableMap(navigationProperties);
}
public boolean isOpenType() {
- return structuredType.isOpenType();
+ return providerStructuredType.isOpenType();
}
public boolean isAbstract() {
- return structuredType.isAbstract();
+ return providerStructuredType.isAbstract();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java
index 822ebc8..32276c5 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java
@@ -26,11 +26,7 @@ import org.apache.olingo.commons.api.edm.provider.Action;
public class EdmActionImpl extends AbstractEdmOperation implements EdmAction {
- public static EdmActionImpl getInstance(final Edm edm, final FullQualifiedName name, final Action action) {
- return AbstractEdmOperation.getInstance(new EdmActionImpl(edm, name, action));
- }
-
- private EdmActionImpl(final Edm edm, final FullQualifiedName name, final Action action) {
+ public EdmActionImpl(final Edm edm, final FullQualifiedName name, final Action action) {
super(edm, name, action, EdmTypeKind.ACTION);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java
index d64056d..a779bf1 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java
@@ -19,6 +19,7 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
@@ -137,7 +138,7 @@ public class EdmAnnotationsImpl implements EdmAnnotations {
annotations.add(new EdmAnnotationImpl(edm, annotation));
}
}
- return annotations;
+ return Collections.unmodifiableList(annotations);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
index 4949d24..7a14ae1 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
@@ -28,12 +28,7 @@ import org.apache.olingo.commons.api.edm.provider.ComplexType;
public class EdmComplexTypeImpl extends AbstractEdmStructuredType implements EdmComplexType {
- public static EdmComplexTypeImpl getInstance(
- final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
- return new EdmComplexTypeImpl(edm, name, complexType);
- }
-
- private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
+ public EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
super(edm, name, EdmTypeKind.COMPLEX, complexType);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
index bcca96a..df6adcb 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
@@ -19,7 +19,8 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -45,22 +46,22 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
private final EdmProvider provider;
private EntityContainer container;
- protected final FullQualifiedName entityContainerName;
+ private final FullQualifiedName entityContainerName;
private final FullQualifiedName parentContainerName;
- protected final Map<String, EdmSingleton> singletons = new HashMap<String, EdmSingleton>();
- private boolean allSingletonsLoaded = false;
+ private final Map<String, EdmSingleton> singletonCache = new LinkedHashMap<String, EdmSingleton>();
+ private List<EdmSingleton> singletons;
- protected final Map<String, EdmEntitySet> entitySets = new HashMap<String, EdmEntitySet>();
- private boolean allEntitySetsLoaded = false;
+ private final Map<String, EdmEntitySet> entitySetCache = new LinkedHashMap<String, EdmEntitySet>();
+ private List<EdmEntitySet> entitySets;
- protected final Map<String, EdmActionImport> actionImports = new HashMap<String, EdmActionImport>();
- private boolean allActionImportsLoaded = false;
+ private final Map<String, EdmActionImport> actionImportCache = new LinkedHashMap<String, EdmActionImport>();
+ private List<EdmActionImport> actionImports;
- protected final Map<String, EdmFunctionImport> functionImports = new HashMap<String, EdmFunctionImport>();
- private boolean allFunctionImportsLoaded = false;
+ private final Map<String, EdmFunctionImport> functionImportCache = new LinkedHashMap<String, EdmFunctionImport>();
+ private List<EdmFunctionImport> functionImports;
- public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider,
+ public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider,
final EntityContainerInfo entityContainerInfo) {
super(edm, entityContainerInfo.getContainerName().getName(), null);
this.provider = provider;
@@ -89,11 +90,11 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
@Override
public EdmSingleton getSingleton(final String singletonName) {
- EdmSingleton singleton = singletons.get(singletonName);
+ EdmSingleton singleton = singletonCache.get(singletonName);
if (singleton == null) {
singleton = createSingleton(singletonName);
if (singleton != null) {
- singletons.put(singletonName, singleton);
+ singletonCache.put(singletonName, singleton);
}
}
return singleton;
@@ -101,11 +102,11 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
@Override
public EdmEntitySet getEntitySet(final String entitySetName) {
- EdmEntitySet entitySet = entitySets.get(entitySetName);
+ EdmEntitySet entitySet = entitySetCache.get(entitySetName);
if (entitySet == null) {
entitySet = createEntitySet(entitySetName);
if (entitySet != null) {
- entitySets.put(entitySetName, entitySet);
+ entitySetCache.put(entitySetName, entitySet);
}
}
return entitySet;
@@ -113,11 +114,11 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
@Override
public EdmActionImport getActionImport(final String actionImportName) {
- EdmActionImport actionImport = actionImports.get(actionImportName);
+ EdmActionImport actionImport = actionImportCache.get(actionImportName);
if (actionImport == null) {
actionImport = createActionImport(actionImportName);
if (actionImport != null) {
- actionImports.put(actionImportName, actionImport);
+ actionImportCache.put(actionImportName, actionImport);
}
}
return actionImport;
@@ -125,11 +126,11 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
@Override
public EdmFunctionImport getFunctionImport(final String functionImportName) {
- EdmFunctionImport functionImport = functionImports.get(functionImportName);
+ EdmFunctionImport functionImport = functionImportCache.get(functionImportName);
if (functionImport == null) {
functionImport = createFunctionImport(functionImportName);
if (functionImport != null) {
- functionImports.put(functionImportName, functionImport);
+ functionImportCache.put(functionImportName, functionImport);
}
}
return functionImport;
@@ -137,38 +138,34 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
@Override
public List<EdmEntitySet> getEntitySets() {
- if (!allEntitySetsLoaded) {
+ if (entitySets == null) {
loadAllEntitySets();
- allEntitySetsLoaded = true;
}
- return new ArrayList<EdmEntitySet>(entitySets.values());
+ return Collections.unmodifiableList(entitySets);
}
@Override
public List<EdmFunctionImport> getFunctionImports() {
- if (!allFunctionImportsLoaded) {
+ if (functionImports == null) {
loadAllFunctionImports();
- allFunctionImportsLoaded = true;
}
- return new ArrayList<EdmFunctionImport>(functionImports.values());
+ return Collections.unmodifiableList(functionImports);
}
@Override
public List<EdmSingleton> getSingletons() {
- if (!allSingletonsLoaded) {
+ if (singletons == null) {
loadAllSingletons();
- allSingletonsLoaded = true;
}
- return new ArrayList<EdmSingleton>(singletons.values());
+ return Collections.unmodifiableList(singletons);
}
@Override
public List<EdmActionImport> getActionImports() {
- if (!allActionImportsLoaded) {
+ if (actionImports == null) {
loadAllActionImports();
- allActionImportsLoaded = true;
}
- return new ArrayList<EdmActionImport>(actionImports.values());
+ return Collections.unmodifiableList(actionImports);
}
@Override
@@ -176,7 +173,6 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
return parentContainerName;
}
-
protected EdmSingleton createSingleton(final String singletonName) {
EdmSingleton singleton = null;
@@ -240,12 +236,12 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
protected void loadAllEntitySets() {
loadContainer();
List<EntitySet> providerEntitySets = container.getEntitySets();
+ entitySets = new ArrayList<EdmEntitySet>();
if (providerEntitySets != null) {
for (EntitySet entitySet : providerEntitySets) {
- if (!entitySets.containsKey(entitySet.getName())) {
- EdmEntitySetImpl impl = new EdmEntitySetImpl(edm, this, entitySet);
- entitySets.put(impl.getName(), impl);
- }
+ EdmEntitySetImpl impl = new EdmEntitySetImpl(edm, this, entitySet);
+ entitySetCache.put(impl.getName(), impl);
+ entitySets.add(impl);
}
}
}
@@ -253,13 +249,12 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
protected void loadAllFunctionImports() {
loadContainer();
List<FunctionImport> providerFunctionImports = container.getFunctionImports();
+ functionImports = new ArrayList<EdmFunctionImport>();
if (providerFunctionImports != null) {
for (FunctionImport functionImport : providerFunctionImports) {
- String functionName = functionImport.getName();
- if (!functionImports.containsKey(functionName)) {
- functionImports.put(functionName,
- new EdmFunctionImportImpl(edm, this, functionImport));
- }
+ EdmFunctionImportImpl impl = new EdmFunctionImportImpl(edm, this, functionImport);
+ functionImportCache.put(impl.getName(), impl);
+ functionImports.add(impl);
}
}
@@ -268,12 +263,12 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
protected void loadAllSingletons() {
loadContainer();
List<Singleton> providerSingletons = container.getSingletons();
+ singletons = new ArrayList<EdmSingleton>();
if (providerSingletons != null) {
for (Singleton singleton : providerSingletons) {
- if (!singletons.containsKey(singleton.getName())) {
- EdmSingletonImpl impl = new EdmSingletonImpl(edm, this, singleton);
- singletons.put(singleton.getName(), impl);
- }
+ EdmSingletonImpl impl = new EdmSingletonImpl(edm, this, singleton);
+ singletonCache.put(singleton.getName(), impl);
+ singletons.add(impl);
}
}
@@ -282,12 +277,12 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
protected void loadAllActionImports() {
loadContainer();
List<ActionImport> providerActionImports = container.getActionImports();
+ actionImports = new ArrayList<EdmActionImport>();
if (providerActionImports != null) {
for (ActionImport actionImport : providerActionImports) {
- if (!actionImports.containsKey(actionImport.getName())) {
- EdmActionImportImpl impl = new EdmActionImportImpl(edm, this, actionImport);
- actionImports.put(actionImport.getName(), impl);
- }
+ EdmActionImportImpl impl = new EdmActionImportImpl(edm, this, actionImport);
+ actionImportCache.put(actionImport.getName(), impl);
+ actionImports.add(impl);
}
}
@@ -298,7 +293,6 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
try {
container = provider.getEntityContainer();
if (container == null) {
- // TODO: Should we throw an exception here?
container = new EntityContainer().setName(getName());
}
} catch (ODataException e) {
@@ -316,7 +310,7 @@ public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntit
public FullQualifiedName getAnnotationsTargetFQN() {
return getFullQualifiedName();
}
-
+
@Override
public TargetType getAnnotationsTargetType() {
return TargetType.EntityContainer;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
index cdb51f5..ac68499 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
@@ -19,6 +19,7 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -43,13 +44,7 @@ public class EdmEntityTypeImpl extends AbstractEdmStructuredType implements EdmE
private final Map<String, EdmKeyPropertyRef> keyPropertyRefs = new LinkedHashMap<String, EdmKeyPropertyRef>();
private List<EdmKeyPropertyRef> keyPropertyRefsList;
- public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName name,
- final EntityType entityType) {
-
- return new EdmEntityTypeImpl(edm, name, entityType);
- }
-
- private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName name, final EntityType entityType) {
+ public EdmEntityTypeImpl(final Edm edm, final FullQualifiedName name, final EntityType entityType) {
super(edm, name, EdmTypeKind.ENTITY, entityType);
this.entityType = entityType;
hasStream = entityType.hasStream();
@@ -113,7 +108,7 @@ public class EdmEntityTypeImpl extends AbstractEdmStructuredType implements EdmE
if (keyPredicateNames.isEmpty() && baseType != null) {
return entityBaseType.getKeyPredicateNames();
}
- return keyPredicateNames;
+ return Collections.unmodifiableList(keyPredicateNames);
}
@Override
@@ -125,7 +120,7 @@ public class EdmEntityTypeImpl extends AbstractEdmStructuredType implements EdmE
if (keyPropertyRefsList.isEmpty() && entityBaseType != null) {
return entityBaseType.getKeyPropertyRefs();
}
- return keyPropertyRefsList;
+ return Collections.unmodifiableList(keyPropertyRefsList);
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
index af56e38..55fddce 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
@@ -20,6 +20,7 @@ package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -94,7 +95,7 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
if (memberNames == null) {
createEdmMembers();
}
- return memberNames;
+ return Collections.unmodifiableList(memberNames);
}
private void createEdmMembers() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java
index 0279a78..fa21fb6 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java
@@ -30,11 +30,7 @@ public class EdmFunctionImpl extends AbstractEdmOperation implements EdmFunction
private final Function function;
- public static EdmFunctionImpl getInstance(final Edm edm, final FullQualifiedName name, final Function function) {
- return AbstractEdmOperation.getInstance(new EdmFunctionImpl(edm, name, function));
- }
-
- private EdmFunctionImpl(final Edm edm, final FullQualifiedName name, final Function function) {
+ public EdmFunctionImpl(final Edm edm, final FullQualifiedName name, final Function function) {
super(edm, name, function, EdmTypeKind.FUNCTION);
this.function = function;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
index db75e0c..11b4cae 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
@@ -19,6 +19,7 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
@@ -119,7 +120,7 @@ public class EdmNavigationPropertyImpl extends AbstractEdmNamed implements EdmEl
}
}
}
- return referentialConstraints;
+ return Collections.unmodifiableList(referentialConstraints);
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java
index 79fe22c..3da0536 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java
@@ -110,7 +110,7 @@ public class EdmProviderImpl extends AbstractEdm {
try {
EntityType entityType = provider.getEntityType(entityTypeName);
if (entityType != null) {
- return EdmEntityTypeImpl.getInstance(this, entityTypeName, entityType);
+ return new EdmEntityTypeImpl(this, entityTypeName, entityType);
}
return null;
} catch (ODataException e) {
@@ -123,7 +123,7 @@ public class EdmProviderImpl extends AbstractEdm {
try {
final ComplexType complexType = provider.getComplexType(complexTypeName);
if (complexType != null) {
- return EdmComplexTypeImpl.getInstance(this, complexTypeName, complexType);
+ return new EdmComplexTypeImpl(this, complexTypeName, complexType);
}
return null;
} catch (ODataException e) {
@@ -153,7 +153,7 @@ public class EdmProviderImpl extends AbstractEdm {
if (bindingParameterTypeName.equals(parameter.getTypeFQN())
&& isBindingParameterCollection.booleanValue() == parameter.isCollection()) {
- return EdmActionImpl.getInstance(this, actionName, action);
+ return new EdmActionImpl(this, actionName, action);
}
}
@@ -197,7 +197,7 @@ public class EdmProviderImpl extends AbstractEdm {
providerParameterNames.add(providerParameters.get(i).getName());
}
if (parameterNamesCopy.containsAll(providerParameterNames)) {
- return EdmFunctionImpl.getInstance(this, functionName, function);
+ return new EdmFunctionImpl(this, functionName, function);
}
}
}
@@ -240,7 +240,7 @@ public class EdmProviderImpl extends AbstractEdm {
// Search for first unbound action
for (Action action : actions) {
if (!action.isBound()) {
- return EdmActionImpl.getInstance(this, actionName, action);
+ return new EdmActionImpl(this, actionName, action);
}
}
return null;
@@ -264,7 +264,7 @@ public class EdmProviderImpl extends AbstractEdm {
if (functions != null) {
for (Function function : functions) {
if (!function.isBound()) {
- result.add(EdmFunctionImpl.getInstance(this, functionName, function));
+ result.add(new EdmFunctionImpl(this, functionName, function));
}
}
}
@@ -303,7 +303,7 @@ public class EdmProviderImpl extends AbstractEdm {
}
if (parameterNamesCopy.containsAll(functionParameterNames)) {
- return EdmFunctionImpl.getInstance(this, functionName, function);
+ return new EdmFunctionImpl(this, functionName, function);
}
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java
index e2d9331..7c0c006 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReturnTypeImpl.java
@@ -31,7 +31,6 @@ public class EdmReturnTypeImpl implements EdmReturnType {
private final EdmTypeInfo typeInfo;
private EdmType typeImpl;
-
public EdmReturnTypeImpl(final Edm edm, final ReturnType returnType) {
this.returnType = returnType;
this.typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(returnType.getType()).build();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
index f31d5d8..7e09b2d 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
@@ -52,7 +52,7 @@ public class EdmSchemaImpl implements EdmSchema {
private final Schema schema;
private final Edm edm;
private final EdmProvider provider;
-
+
protected final String namespace;
private final String alias;
private List<EdmEnumType> enumTypes;
@@ -79,7 +79,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (enumTypes == null) {
enumTypes = createEnumTypes();
}
- return enumTypes;
+ return Collections.unmodifiableList(enumTypes);
}
@Override
@@ -87,7 +87,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (entityTypes == null) {
entityTypes = createEntityTypes();
}
- return entityTypes;
+ return Collections.unmodifiableList(entityTypes);
}
@Override
@@ -95,7 +95,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (complexTypes == null) {
complexTypes = createComplexTypes();
}
- return complexTypes;
+ return Collections.unmodifiableList(complexTypes);
}
@Override
@@ -103,7 +103,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (actions == null) {
actions = createActions();
}
- return actions;
+ return Collections.unmodifiableList(actions);
}
@Override
@@ -111,7 +111,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (functions == null) {
functions = createFunctions();
}
- return functions;
+ return Collections.unmodifiableList(functions);
}
@Override
@@ -119,7 +119,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (typeDefinitions == null) {
typeDefinitions = createTypeDefinitions();
}
- return typeDefinitions;
+ return Collections.unmodifiableList(typeDefinitions);
}
@Override
@@ -127,7 +127,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (terms == null) {
terms = createTerms();
}
- return terms;
+ return Collections.unmodifiableList(terms);
}
@Override
@@ -135,7 +135,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (annotationGroups == null) {
annotationGroups = createAnnotationGroups();
}
- return annotationGroups;
+ return Collections.unmodifiableList(annotationGroups);
}
@Override
@@ -143,7 +143,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (annotations == null) {
annotations = createAnnotations();
}
- return annotations;
+ return Collections.unmodifiableList(annotations);
}
@Override
@@ -159,7 +159,7 @@ public class EdmSchemaImpl implements EdmSchema {
if (getEntityContainer() == null) {
return Collections.<EdmEntityContainer> emptyList();
} else {
- return Collections.singletonList(getEntityContainer());
+ return Collections.unmodifiableList(Collections.singletonList(getEntityContainer()));
}
}
@@ -183,7 +183,7 @@ public class EdmSchemaImpl implements EdmSchema {
public String getAlias() {
return alias;
}
-
+
protected EdmEntityContainer createEntityContainer() {
if (schema.getEntityContainer() != null) {
FullQualifiedName containerFQN = new FullQualifiedName(namespace, schema.getEntityContainer().getName());
@@ -219,7 +219,7 @@ public class EdmSchemaImpl implements EdmSchema {
final List<EntityType> providerEntityTypes = schema.getEntityTypes();
if (providerEntityTypes != null) {
for (EntityType entityType : providerEntityTypes) {
- entityTypes.add(EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName(namespace, entityType.getName()),
+ entityTypes.add(new EdmEntityTypeImpl(edm, new FullQualifiedName(namespace, entityType.getName()),
entityType));
}
}
@@ -231,7 +231,7 @@ public class EdmSchemaImpl implements EdmSchema {
final List<ComplexType> providerComplexTypes = schema.getComplexTypes();
if (providerComplexTypes != null) {
for (ComplexType complexType : providerComplexTypes) {
- complexTypes.add(EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName(namespace, complexType.getName()),
+ complexTypes.add(new EdmComplexTypeImpl(edm, new FullQualifiedName(namespace, complexType.getName()),
complexType));
}
}
@@ -243,7 +243,7 @@ public class EdmSchemaImpl implements EdmSchema {
final List<Action> providerActions = schema.getActions();
if (providerActions != null) {
for (Action action : providerActions) {
- actions.add(EdmActionImpl.getInstance(edm, new FullQualifiedName(namespace, action.getName()), action));
+ actions.add(new EdmActionImpl(edm, new FullQualifiedName(namespace, action.getName()), action));
}
}
return actions;
@@ -254,7 +254,7 @@ public class EdmSchemaImpl implements EdmSchema {
final List<Function> providerFunctions = schema.getFunctions();
if (providerFunctions != null) {
for (Function function : providerFunctions) {
- functions.add(EdmFunctionImpl.getInstance(edm, new FullQualifiedName(namespace, function.getName()), function));
+ functions.add(new EdmFunctionImpl(edm, new FullQualifiedName(namespace, function.getName()), function));
}
}
return functions;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/Target.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/Target.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/Target.java
new file mode 100644
index 0000000..4f45ccd
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/Target.java
@@ -0,0 +1,66 @@
+/*
+ * 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.provider;
+
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+
+/**
+ * An Edm target element. It contains a target as a String name as well as the {@link FullQualifiedName} of the entity
+ * container it is contained in.
+ */
+public class Target {
+
+ private String targetName;
+ private FullQualifiedName entityContainer;
+
+ public Target(String target, EdmEntityContainer defaultContainer) {
+ final String[] bindingTargetParts = target.split("/");
+ if (bindingTargetParts.length == 1) {
+ entityContainer = defaultContainer.getFullQualifiedName();
+ targetName = bindingTargetParts[0];
+ } else {
+ entityContainer = new FullQualifiedName(bindingTargetParts[0]);
+ targetName = bindingTargetParts[1];
+ }
+ }
+
+ /**
+ * @return name of the target as a String
+ */
+ public String getTargetName() {
+ return targetName;
+ }
+
+ /**
+ * @return {@link FullQualifiedName} of the entity container this target is contained in.
+ */
+ public FullQualifiedName getEntityContainer() {
+ return entityContainer;
+ }
+
+ @Override
+ public String toString() {
+ if (entityContainer == null) {
+ return targetName;
+ }
+ return entityContainer.getFullQualifiedNameAsString() + "/" + targetName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
index 17a02d6..a2f54c7 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
@@ -18,6 +18,7 @@
*/
package org.apache.olingo.server.core.serializer.xml;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -471,7 +472,7 @@ public class MetadataDocumentXmlSerializer {
private void appendNavigationProperties(final XMLStreamWriter writer, final EdmStructuredType type)
throws XMLStreamException {
- List<String> navigationPropertyNames = type.getNavigationPropertyNames();
+ List<String> navigationPropertyNames = new ArrayList<String>(type.getNavigationPropertyNames());
if (type.getBaseType() != null) {
navigationPropertyNames.removeAll(type.getBaseType().getNavigationPropertyNames());
}
@@ -504,7 +505,7 @@ public class MetadataDocumentXmlSerializer {
}
private void appendProperties(final XMLStreamWriter writer, final EdmStructuredType type) throws XMLStreamException {
- List<String> propertyNames = type.getPropertyNames();
+ List<String> propertyNames = new ArrayList<String>(type.getPropertyNames());
if (type.getBaseType() != null) {
propertyNames.removeAll(type.getBaseType().getPropertyNames());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImplTest.java
index ca91ad0..8a3dc87 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImplTest.java
@@ -58,19 +58,19 @@ public class EdmActionImplTest {
parameters.add(new Parameter().setName("Id").setType(new FullQualifiedName("namespace", "name")));
FullQualifiedName action1Name = new FullQualifiedName("namespace", "action1");
Action action1 = new Action().setName("action1").setBound(true).setParameters(parameters);
- actionImpl1 = EdmActionImpl.getInstance(provider, action1Name, action1);
+ actionImpl1 = new EdmActionImpl(provider, action1Name, action1);
FullQualifiedName action2Name = new FullQualifiedName("namespace", "action2");
FullQualifiedName returnTypeName = new FullQualifiedName("Edm", "String");
ReturnType returnType = new ReturnType().setType(returnTypeName);
Action action2 = new Action().setName("action2").setParameters(parameters).setReturnType(returnType);
- actionImpl2 = EdmActionImpl.getInstance(provider, action2Name, action2);
+ actionImpl2 = new EdmActionImpl(provider, action2Name, action2);
FullQualifiedName action3Name = new FullQualifiedName("namespace", "action3");
Action action3 =
new Action().setName("action3").setParameters(parameters).setReturnType(returnType).setEntitySetPath(
"path/Id");
- actionImpl3 = EdmActionImpl.getInstance(provider, action3Name, action3);
+ actionImpl3 = new EdmActionImpl(provider, action3Name, action3);
}
@Test
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
index e4ad2dd..950112f 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmActionImportImplTest.java
@@ -18,25 +18,24 @@
*/
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 org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmActionImport;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.commons.api.edm.provider.ActionImport;
import org.apache.olingo.commons.core.edm.provider.EdmActionImportImpl;
import org.apache.olingo.commons.core.edm.provider.EdmProviderImpl;
import org.junit.Before;
import org.junit.Test;
-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;
-
public class EdmActionImportImplTest {
EdmEntityContainer container;
@@ -51,9 +50,9 @@ public class EdmActionImportImplTest {
public void setup() {
FullQualifiedName actionFqn = new FullQualifiedName("namespace", "actionName");
FullQualifiedName entityContainerFqn = new FullQualifiedName("namespace", "containerName");
- Target target = new Target().setEntityContainer(entityContainerFqn).setTargetName("entitySetName");
+ String target = entityContainerFqn.getFullQualifiedNameAsString() + "/entitySetName";
ActionImport providerActionImport =
- new ActionImport().setName("actionImportName").setAction(actionFqn).setEntitySet(target.toString());
+ new ActionImport().setName("actionImportName").setAction(actionFqn).setEntitySet(target);
EdmProviderImpl edm = mock(EdmProviderImpl.class);
container = mock(EdmEntityContainer.class);
@@ -85,8 +84,8 @@ public class EdmActionImportImplTest {
@Test(expected = EdmException.class)
public void getReturnedEntitySetNonExistingContainer() {
- Target target = new Target().setEntityContainer(new FullQualifiedName("alias.nonexisting")).setTargetName("Es");
- ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target.toString());
+ String target = "alias.nonexisting/Es";
+ ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target);
EdmActionImport actionImport =
new EdmActionImportImpl(mock(EdmProviderImpl.class), container, providerActionImport);
actionImport.getReturnedEntitySet();
@@ -94,8 +93,8 @@ public class EdmActionImportImplTest {
@Test(expected = EdmException.class)
public void getReturnedEntitySetNonExistingEntitySet() {
- Target target = new Target().setTargetName("nonExisting");
- ActionImport providerActionImport = new ActionImport().setName("actionImportName").setEntitySet(target.toString());
+ String target = "nonExisting";
+ 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, providerActionImport);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
index a02e356..917f60b 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmComplexTypeImplTest.java
@@ -65,7 +65,7 @@ public class EdmComplexTypeImplTest {
.setNavigationProperties(baseNavigationProperties);
when(provider.getComplexType(baseName)).thenReturn(baseComplexType);
- baseType = EdmComplexTypeImpl.getInstance(edm, baseName, baseComplexType);
+ baseType = new EdmComplexTypeImpl(edm, baseName, baseComplexType);
FullQualifiedName name = new FullQualifiedName("namespace", "typeName");
ComplexType complexType = new ComplexType().setBaseType(baseName);
@@ -77,14 +77,14 @@ public class EdmComplexTypeImplTest {
.setNavigationProperties(navigationProperties);
when(provider.getComplexType(name)).thenReturn(complexType);
- type = EdmComplexTypeImpl.getInstance(edm, name, complexType);
+ type = new EdmComplexTypeImpl(edm, name, complexType);
}
@Test
public void noPropertiesAndNoNavPropertiesMustNotResultInException() {
EdmProviderImpl edm = mock(EdmProviderImpl.class);
ComplexType complexType = new ComplexType().setName("n");
- EdmComplexTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), complexType);
+ new EdmComplexTypeImpl(edm, new FullQualifiedName("n", "n"), complexType);
}
@Test
@@ -163,7 +163,7 @@ public class EdmComplexTypeImplTest {
complexTypeForNonexistingBaseType.setName("typeName");
when(provider.getComplexType(typeWithNonexistingBaseTypeName)).thenReturn(complexTypeForNonexistingBaseType);
EdmComplexTypeImpl instance =
- EdmComplexTypeImpl.getInstance(edm, typeWithNonexistingBaseTypeName, complexTypeForNonexistingBaseType);
+ new EdmComplexTypeImpl(edm, typeWithNonexistingBaseTypeName, complexTypeForNonexistingBaseType);
instance.getBaseType();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
index 33f8b64..5eba34f 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
@@ -71,21 +71,10 @@ public class EdmEntityContainerImplTest {
@Test
public void getAllEntitySetsAfterOneWasAlreadyLoaded() {
- EdmEntitySet entitySet = container.getEntitySet("entitySetName");
+ 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
@@ -97,21 +86,10 @@ public class EdmEntityContainerImplTest {
@Test
public void getAllSingletonsAfterOneWasAlreadyLoaded() {
- EdmSingleton singleton = container.getSingleton("singletonName");
+ 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
@@ -123,21 +101,10 @@ public class EdmEntityContainerImplTest {
@Test
public void getAllActionImportsAfterOneWasAlreadyLoaded() {
- EdmActionImport actionImport = container.getActionImport("actionImportName");
+ 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
@@ -149,21 +116,10 @@ public class EdmEntityContainerImplTest {
@Test
public void getAllFunctionImportsAfterOneWasAlreadyLoaded() {
- EdmFunctionImport functionImport = container.getFunctionImport("functionImportName");
+ 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
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java
index 95de14e..4e9dad0 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntitySetImplTest.java
@@ -18,12 +18,18 @@
*/
package org.apache.olingo.server.core.edm.provider;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+
import org.apache.olingo.commons.api.edm.EdmBindingTarget;
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.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.commons.api.edm.provider.EdmProvider;
import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo;
import org.apache.olingo.commons.api.edm.provider.EntitySet;
@@ -35,13 +41,6 @@ import org.apache.olingo.commons.core.edm.provider.EdmEntitySetImpl;
import org.apache.olingo.commons.core.edm.provider.EdmProviderImpl;
import org.junit.Test;
-import java.util.Arrays;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
public class EdmEntitySetImplTest {
@Test
@@ -67,7 +66,7 @@ public class EdmEntitySetImplTest {
.setIncludeInServiceDocument(true)
.setNavigationPropertyBindings(Arrays.asList(
new NavigationPropertyBinding().setPath("path")
- .setTarget(new Target().setEntityContainer(containerName).setTargetName(entitySetName).toString())));
+ .setTarget(containerName.getFullQualifiedNameAsString() + "/" + entitySetName)));
when(provider.getEntitySet(containerName, entitySetName)).thenReturn(entitySetProvider);
final EdmEntitySet entitySet = new EdmEntitySetImpl(edm, entityContainer, entitySetProvider);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
index e6ddf40..045c1a7 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityTypeImplTest.java
@@ -76,7 +76,7 @@ public class EdmEntityTypeImplTest {
baseType.setNavigationProperties(navigationProperties);
when(provider.getEntityType(baseName)).thenReturn(baseType);
- this.baseType = EdmEntityTypeImpl.getInstance(edm, baseName, baseType);
+ this.baseType = new EdmEntityTypeImpl(edm, baseName, baseType);
FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName");
EntityType type = new EntityType();
@@ -93,7 +93,7 @@ public class EdmEntityTypeImplTest {
type.setNavigationProperties(typeNavigationProperties);
when(provider.getEntityType(typeName)).thenReturn(type);
- typeWithBaseType = EdmEntityTypeImpl.getInstance(edm, typeName, type);
+ typeWithBaseType = new EdmEntityTypeImpl(edm, typeName, type);
FullQualifiedName typeWithComplexKeyName = new FullQualifiedName("namespace", "typeName");
EntityType typeWithComplexKeyProvider = new EntityType();
@@ -117,7 +117,7 @@ public class EdmEntityTypeImplTest {
typeWithComplexKeyProvider.setKey(keyForTypeWithComplexKey);
when(provider.getEntityType(typeWithComplexKeyName)).thenReturn(typeWithComplexKeyProvider);
- typeWithComplexKey = EdmEntityTypeImpl.getInstance(edm, typeWithComplexKeyName, typeWithComplexKeyProvider);
+ typeWithComplexKey = new EdmEntityTypeImpl(edm, typeWithComplexKeyName, typeWithComplexKeyProvider);
}
@Test
@@ -137,7 +137,7 @@ public class EdmEntityTypeImplTest {
baseType.setNavigationProperties(navigationProperties);
when(provider.getEntityType(baseName)).thenReturn(baseType);
baseType.setAbstract(true);
- EdmEntityType edmAbstarctBaseType = EdmEntityTypeImpl.getInstance(edm, baseName, baseType);
+ EdmEntityType edmAbstarctBaseType = new EdmEntityTypeImpl(edm, baseName, baseType);
assertEquals(2, edmAbstarctBaseType.getPropertyNames().size());
assertEquals("Id", edmAbstarctBaseType.getPropertyNames().get(0));
@@ -161,7 +161,7 @@ public class EdmEntityTypeImplTest {
type.setNavigationProperties(typeNavigationProperties);
when(provider.getEntityType(typeName)).thenReturn(type);
- EdmEntityType edmType = EdmEntityTypeImpl.getInstance(edm, typeName, type);
+ EdmEntityType edmType = new EdmEntityTypeImpl(edm, typeName, type);
assertNotNull(edmType.getBaseType());
assertEquals(2, edmAbstarctBaseType.getPropertyNames().size());
@@ -200,7 +200,7 @@ public class EdmEntityTypeImplTest {
baseType.setNavigationProperties(navigationProperties);
when(provider.getEntityType(baseName)).thenReturn(baseType);
baseType.setAbstract(true);
- EdmEntityType edmAbstarctBaseType = EdmEntityTypeImpl.getInstance(edm, baseName, baseType);
+ EdmEntityType edmAbstarctBaseType = new EdmEntityTypeImpl(edm, baseName, baseType);
FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName");
EntityType type = new EntityType();
@@ -216,7 +216,7 @@ public class EdmEntityTypeImplTest {
typeNavigationProperties.add(new NavigationProperty().setName("nav2"));
type.setNavigationProperties(typeNavigationProperties);
when(provider.getEntityType(typeName)).thenReturn(type);
- EdmEntityType edmType = EdmEntityTypeImpl.getInstance(edm, typeName, type);
+ EdmEntityType edmType = new EdmEntityTypeImpl(edm, typeName, type);
assertNotNull(edmType.getBaseType());
assertEquals(2, edmAbstarctBaseType.getPropertyNames().size());
@@ -304,7 +304,9 @@ public class EdmEntityTypeImplTest {
assertNotNull(keyPropertyRefs);
assertEquals(1, keyPropertyRefs.size());
assertEquals("Id", keyPropertyRefs.get(0).getName());
- assertTrue(keyPropertyRefs == typeWithBaseType.getKeyPropertyRefs());
+ for(int i = 0; i < keyPropertyRefs.size(); i++){
+ assertEquals(keyPropertyRefs.get(i).getName(), typeWithBaseType.getKeyPropertyRefs().get(i).getName());
+ }
}
@Test
@@ -365,14 +367,14 @@ public class EdmEntityTypeImplTest {
public void abstractTypeDoesNotNeedKey() {
EdmProviderImpl edm = mock(EdmProviderImpl.class);
EntityType entityType = new EntityType().setName("n").setAbstract(true);
- EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
+ new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType);
}
@Test(expected = EdmException.class)
public void invalidBaseType() {
EdmProviderImpl edm = mock(EdmProviderImpl.class);
EntityType entityType = new EntityType().setName("n").setBaseType(new FullQualifiedName("wrong", "wrong"));
- EdmEntityTypeImpl instance = EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
+ EdmEntityTypeImpl instance = new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType);
instance.getBaseType();
}
@@ -383,7 +385,7 @@ public class EdmEntityTypeImplTest {
FullQualifiedName baseName = new FullQualifiedName("n", "base");
when(provider.getEntityType(baseName)).thenReturn(new EntityType().setName("base").setAbstract(true));
EntityType entityType = new EntityType().setName("n").setAbstract(true).setBaseType(baseName);
- EdmEntityTypeImpl.getInstance(edm, new FullQualifiedName("n", "n"), entityType);
+ new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImplTest.java
index 3a553b3..a58ee2b 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImplTest.java
@@ -46,9 +46,9 @@ public class EdmFunctionImplTest {
EdmProviderImpl provider = mock(EdmProviderImpl.class);
Function function1 = new Function().setReturnType(new ReturnType().setType(new FullQualifiedName("Edm", "String")));
- functionImpl1 = EdmFunctionImpl.getInstance(provider, new FullQualifiedName("namespace", "name"), function1);
+ functionImpl1 = new EdmFunctionImpl(provider, new FullQualifiedName("namespace", "name"), function1);
Function function2 = new Function().setComposable(true);
- functionImpl2 = EdmFunctionImpl.getInstance(provider, new FullQualifiedName("namespace", "name"), function2);
+ functionImpl2 = new EdmFunctionImpl(provider, new FullQualifiedName("namespace", "name"), function2);
}
@Test
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java
index 9816a81..c80daa1 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java
@@ -18,13 +18,19 @@
*/
package org.apache.olingo.server.core.edm.provider;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+
import org.apache.olingo.commons.api.edm.EdmBindingTarget;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmSingleton;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.commons.api.edm.provider.EdmProvider;
import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo;
import org.apache.olingo.commons.api.edm.provider.EntityType;
@@ -36,13 +42,6 @@ import org.apache.olingo.commons.core.edm.provider.EdmProviderImpl;
import org.apache.olingo.commons.core.edm.provider.EdmSingletonImpl;
import org.junit.Test;
-import java.util.Arrays;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
public class EdmSingletonImplTest {
@Test
@@ -62,12 +61,14 @@ public class EdmSingletonImplTest {
final EdmEntityContainer entityContainer = new EdmEntityContainerImpl(edm, provider, containerInfo);
final String singletonName = "singleton";
- final Singleton singletonProvider = new Singleton()
- .setName(singletonName)
- .setType(typeName)
- .setNavigationPropertyBindings(Arrays.asList(
- new NavigationPropertyBinding().setPath("path")
- .setTarget(new Target().setEntityContainer(containerName).setTargetName(singletonName).toString())));
+ final Singleton singletonProvider =
+ new Singleton()
+ .setName(singletonName)
+ .setType(typeName)
+ .setNavigationPropertyBindings(
+ Arrays.asList(
+ new NavigationPropertyBinding().setPath("path").setTarget(
+ containerName.getFullQualifiedNameAsString() + "/" + singletonName)));
when(provider.getSingleton(containerName, singletonName)).thenReturn(singletonProvider);
final EdmSingleton singleton = new EdmSingletonImpl(edm, entityContainer, singletonProvider);
@@ -95,7 +96,7 @@ public class EdmSingletonImplTest {
final Singleton singletonProvider = new Singleton()
.setNavigationPropertyBindings(Arrays.asList(
new NavigationPropertyBinding().setPath("path")
- .setTarget(new Target().setEntityContainer(containerName).setTargetName("wrong").toString())));
+ .setTarget(containerName.getFullQualifiedNameAsString() + "/wrong")));
when(provider.getSingleton(containerName, singletonName)).thenReturn(singletonProvider);
final EdmSingleton singleton = new EdmSingletonImpl(edm, null, singletonProvider);
@@ -111,9 +112,7 @@ public class EdmSingletonImplTest {
final String singletonName = "singleton";
final Singleton singletonProvider = new Singleton()
.setNavigationPropertyBindings(Arrays.asList(
- new NavigationPropertyBinding().setPath("path")
- .setTarget(new Target().setEntityContainer(new FullQualifiedName("ns", "wrongContainer"))
- .setTargetName(singletonName).toString())));
+ new NavigationPropertyBinding().setPath("path").setTarget("ns.wrongContainer/" + singletonName)));
when(provider.getSingleton(containerName, singletonName)).thenReturn(singletonProvider);
final EdmSingleton singleton = new EdmSingletonImpl(edm, null, singletonProvider);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ComplexTypeHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ComplexTypeHelper.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ComplexTypeHelper.java
index a2481e1..7979159 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ComplexTypeHelper.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ComplexTypeHelper.java
@@ -62,6 +62,6 @@ public class ComplexTypeHelper {
.setNavigationProperties(navigationProperties);
when(provider.getComplexType(name)).thenReturn(complexType);
- return EdmComplexTypeImpl.getInstance(edm, name, complexType);
+ return new EdmComplexTypeImpl(edm, name, complexType);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
index 1112c8f..e9e21ab 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java
@@ -189,7 +189,7 @@ public class ContextURLBuilderTest {
.setNavigationProperties(baseNavigationProperties);
when(provider.getComplexType(baseName)).thenReturn(baseComplexType);
- EdmComplexType baseType = EdmComplexTypeImpl.getInstance(edm, baseName, baseComplexType);
+ EdmComplexType baseType = new EdmComplexTypeImpl(edm, baseName, baseComplexType);
EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
Mockito.when(entitySet.getName()).thenReturn("Customers");
[19/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java
new file mode 100644
index 0000000..19a0387
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java
@@ -0,0 +1,546 @@
+/*
+ * 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.example;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Locale;
+import java.util.Random;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmSingleton;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.commons.core.data.EntitySetImpl;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.requests.ServiceDocumentRequest;
+import org.apache.olingo.server.core.responses.CountResponse;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.ServiceDocumentResponse;
+import org.apache.olingo.server.core.responses.ServiceResponse;
+import org.apache.olingo.server.core.responses.ServiceResponseVisior;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public class TripPinHandler implements ServiceHandler {
+ private OData odata;
+ private ServiceMetadata serviceMetadata;
+ private final TripPinDataModel dataModel;
+
+ public TripPinHandler(TripPinDataModel datamodel) {
+ this.dataModel = datamodel;
+ }
+
+ @Override
+ public void init(OData odata, ServiceMetadata serviceMetadata) {
+ this.odata = odata;
+ this.serviceMetadata = serviceMetadata;
+ }
+
+ @Override
+ public void readMetadata(MetadataRequest request, MetadataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ response.writeMetadata();
+ }
+
+ @Override
+ public void readServiceDocument(ServiceDocumentRequest request, ServiceDocumentResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ response.writeServiceDocument(request.getODataRequest().getRawBaseUri());
+ }
+
+ static class EntityDetails {
+ EntitySet entitySet = null;
+ Entity entity = null;
+ EdmEntityType entityType;
+ String navigationProperty;
+ Entity parentEntity = null;
+ }
+
+ private EntityDetails process(final DataRequest request) throws ODataApplicationException {
+ EntitySet entitySet = null;
+ Entity entity = null;
+ EdmEntityType entityType;
+ Entity parentEntity = null;
+
+ if (request.isSingleton()) {
+ EdmSingleton singleton = request.getUriResourceSingleton().getSingleton();
+ entityType = singleton.getEntityType();
+ if (singleton.getName().equals("Me")) {
+ entitySet = this.dataModel.getEntitySet("People");
+ entity = entitySet.getEntities().get(0);
+ }
+ } else {
+ final EdmEntitySet edmEntitySet = request.getEntitySet();
+ entityType = edmEntitySet.getEntityType();
+ List<UriParameter> keys = request.getKeyPredicates();
+
+ // TODO: This example so far ignores all system options; but a real
+ // service should not
+ if (keys != null && !keys.isEmpty()) {
+ entity = this.dataModel.getEntity(edmEntitySet.getName(), keys);
+ } else {
+ int skip = 0;
+ if (request.getUriInfo().getSkipTokenOption() != null) {
+ skip = Integer.parseInt(request.getUriInfo().getSkipTokenOption().getValue());
+ }
+ int pageSize = getPageSize(request);
+ entitySet = this.dataModel.getEntitySet(edmEntitySet.getName(), skip, pageSize);
+ if (entitySet.getEntities().size() == pageSize) {
+ try {
+ entitySet.setNext(new URI(request.getODataRequest().getRawRequestUri() + "?$skiptoken="
+ + (skip + pageSize)));
+ } catch (URISyntaxException e) {
+ throw new ODataApplicationException(e.getMessage(), 500, Locale.getDefault());
+ }
+ }
+ }
+ }
+ EntityDetails details = new EntityDetails();
+
+ if (!request.getNavigations().isEmpty() && entity != null) {
+ UriResourceNavigation lastNavigation = request.getNavigations().getLast();
+ for (UriResourceNavigation nav : request.getNavigations()) {
+ entityType = nav.getProperty().getType();
+ if (nav.isCollection()) {
+ entitySet = this.dataModel.getNavigableEntitySet(entity, nav);
+ } else {
+ parentEntity = entity;
+ entity = this.dataModel.getNavigableEntity(parentEntity, nav);
+ }
+ }
+ details.navigationProperty = lastNavigation.getProperty().getName();
+ }
+
+ details.entity = entity;
+ details.entitySet = entitySet;
+ details.entityType = entityType;
+ details.parentEntity = parentEntity;
+ return details;
+ }
+
+ @Override
+ public <T extends ServiceResponse> void read(final DataRequest request, final T response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ final EntityDetails details = process(request);
+
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(CountResponse response) throws ODataTranslatedException, ODataApplicationException {
+ response.writeCount(details.entitySet.getCount());
+ }
+
+ @Override
+ public void visit(PrimitiveValueResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
+ Property property = details.entity.getProperty(edmProperty.getName());
+ response.write(property.getValue());
+ }
+
+ @Override
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
+ Property property = details.entity.getProperty(edmProperty.getName());
+ response.writeProperty(edmProperty.getType(), property);
+ }
+
+ @Override
+ public void visit(StreamResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ // stream property response
+ response.writeStreamResponse(new ByteArrayInputStream("dummy".getBytes()),
+ ContentType.APPLICATION_OCTET_STREAM);
+ }
+
+ @Override
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (request.getPreference("odata.maxpagesize") != null) {
+ response.writeHeader("Preference-Applied", request.getPreference("odata.maxpagesize"));
+ }
+ if (details.entity == null && !request.getNavigations().isEmpty()) {
+ response.writeReadEntitySet(details.entityType, new EntitySetImpl());
+ } else {
+ response.writeReadEntitySet(details.entityType, details.entitySet);
+ }
+ }
+
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (details.entity == null && !request.getNavigations().isEmpty()) {
+ response.writeNoContent(true);
+ } else {
+ response.writeReadEntity(details.entityType, details.entity);
+ }
+ }
+ });
+ }
+
+ private int getPageSize(DataRequest request) {
+ String size = request.getPreference("odata.maxpagesize");
+ if (size == null) {
+ return 8;
+ }
+ return Integer.parseInt(size);
+ }
+
+ @Override
+ public void createEntity(DataRequest request, Entity entity, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ EdmEntitySet edmEntitySet = request.getEntitySet();
+
+ String location = buildLocation(entity, edmEntitySet.getName(), edmEntitySet.getEntityType());
+ Entity created = this.dataModel.createEntity(edmEntitySet.getName(), entity, location);
+
+ try {
+ // create references, they come in "@odata.bind" value
+ List<Link> bindings = entity.getNavigationBindings();
+ if (bindings != null & !bindings.isEmpty()) {
+ for (Link link : bindings) {
+ String navigationProperty = link.getTitle();
+ String uri = link.getBindingLink();
+ if (uri != null) {
+ DataRequest bindingRequest = request.parseLink(new URI(uri));
+
+ Entity reference = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(),
+ bindingRequest.getKeyPredicates());
+
+ this.dataModel.addNavigationLink(navigationProperty, created, reference);
+
+ } else {
+ for (String binding : link.getBindingLinks()) {
+ DataRequest bindingRequest = request.parseLink(new URI(binding));
+
+ Entity reference = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(),
+ bindingRequest.getKeyPredicates());
+
+ this.dataModel.addNavigationLink(navigationProperty, created, reference);
+ }
+ }
+ }
+ }
+ } catch (URISyntaxException e) {
+ throw new ODataApplicationException(e.getMessage(), 500, Locale.getDefault());
+ }
+
+ response.writeCreatedEntity(edmEntitySet.getEntityType(), created, location);
+ }
+
+ static String buildLocation(Entity entity, String name, EdmEntityType type) {
+ String location = "/" + name + "(";
+ int i = 0;
+ boolean usename = type.getKeyPredicateNames().size() > 1;
+
+ for (String key : type.getKeyPredicateNames()) {
+ if (i > 0) {
+ location += ",";
+ }
+ i++;
+ if (usename) {
+ location += (key + "=");
+ }
+ if (entity.getProperty(key).getType().equals("Edm.String")) {
+ location = location + "'" + entity.getProperty(key).getValue().toString() + "'";
+ } else {
+ location = location + entity.getProperty(key).getValue().toString();
+ }
+ }
+ location += ")";
+ return location;
+ }
+
+ @Override
+ public void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
+ EntityResponse response) throws ODataTranslatedException, ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ @Override
+ public void deleteEntity(DataRequest request, String eTag, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ EdmEntitySet edmEntitySet = request.getEntitySet();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), request.getKeyPredicates());
+ if (entity == null) {
+ response.writeNotFound(true);
+ return;
+ }
+ String key = edmEntitySet.getEntityType().getKeyPredicateNames().get(0);
+ boolean removed = this.dataModel.deleteEntity(edmEntitySet.getName(), eTag, key, entity
+ .getProperty(key).getValue());
+
+ if (removed) {
+ response.writeDeletedEntityOrReference();
+ } else {
+ response.writeNotFound(true);
+ }
+ }
+
+ @Override
+ public void updateProperty(DataRequest request, final Property property, boolean merge,
+ String entityETag, PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+
+ EdmEntitySet edmEntitySet = request.getEntitySet();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), request.getKeyPredicates());
+ if (entity == null) {
+ response.writeNotFound(true);
+ return;
+ }
+
+ String key = edmEntitySet.getEntityType().getKeyPredicateNames().get(0);
+ boolean replaced = this.dataModel.updateProperty(edmEntitySet.getName(), entityETag, key,
+ entity.getProperty(key).getValue(), property);
+
+ if (replaced) {
+ if (property.getValue() == null) {
+ response.writePropertyDeleted();
+ } else {
+ response.writePropertyUpdated();
+ }
+ } else {
+ response.writeServerError(true);
+ }
+ }
+
+ @Override
+ public <T extends ServiceResponse> void invoke(FunctionRequest request, HttpMethod method,
+ T response) throws ODataTranslatedException, ODataApplicationException {
+ EdmFunction function = request.getFunction();
+ if (function.getName().equals("GetNearestAirport")) {
+
+ final EdmEntityType type = serviceMetadata.getEdm().getEntityContainer(null)
+ .getEntitySet("Airports").getEntityType();
+
+ EntitySet es = this.dataModel.getEntitySet("Airports");
+ int i = new Random().nextInt(es.getEntities().size());
+ final Entity entity = es.getEntities().get(i);
+
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeReadEntity(type, entity);
+ }
+ });
+ }
+ }
+
+ @Override
+ public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response)
+ throws ODataTranslatedException, ODataApplicationException {
+ EdmAction action = request.getAction();
+ if (action.getName().equals("ResetDataSource")) {
+ try {
+ this.dataModel.loadData();
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(NoContentResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeNoContent();
+ }
+ });
+ } catch (Exception e) {
+ response.writeServerError(true);
+ }
+ } else {
+ response.writeServerError(true);
+ }
+ }
+
+ @Override
+ public void readMediaStream(MediaRequest request, StreamResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ final EdmEntitySet edmEntitySet = request.getEntitySet();
+ List<UriParameter> keys = request.getKeyPredicates();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), keys);
+
+ InputStream contents = this.dataModel.readMedia(entity);
+ response.writeStreamResponse(contents, request.getResponseContentType());
+ }
+
+ @Override
+ public void upsertMediaStream(MediaRequest request, String entityETag, InputStream mediaContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ final EdmEntitySet edmEntitySet = request.getEntitySet();
+ List<UriParameter> keys = request.getKeyPredicates();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), keys);
+
+ if (mediaContent == null) {
+ boolean deleted = this.dataModel.deleteMedia(entity);
+ if (deleted) {
+ response.writeNoContent();
+ } else {
+ response.writeNotFound();
+ }
+ } else {
+ boolean updated = this.dataModel.updateMedia(entity, mediaContent);
+ if (updated) {
+ response.writeNoContent();
+ } else {
+ response.writeServerError(true);
+ }
+ }
+ }
+
+ @Override
+ public void upsertStreamProperty(DataRequest request, String entityETag, InputStream streamContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ final EdmEntitySet edmEntitySet = request.getEntitySet();
+ List<UriParameter> keys = request.getKeyPredicates();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), keys);
+
+ EdmProperty property = request.getUriResourceProperty().getProperty();
+
+ if (streamContent == null) {
+ boolean deleted = this.dataModel.deleteStream(entity, property);
+ if (deleted) {
+ response.writeNoContent();
+ } else {
+ response.writeNotFound();
+ }
+ } else {
+ boolean updated = this.dataModel.updateStream(entity, property, streamContent);
+ if (updated) {
+ response.writeNoContent();
+ } else {
+ response.writeServerError(true);
+ }
+ }
+ }
+
+ @Override
+ public void addReference(DataRequest request, String entityETag, List<URI> references,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+
+ final EntityDetails details = process(request);
+
+ for (URI reference : references) {
+ DataRequest bindingRequest = request.parseLink(reference);
+ Entity linkEntity = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(),
+ bindingRequest.getKeyPredicates());
+ this.dataModel.addNavigationLink(details.navigationProperty, details.entity, linkEntity);
+ }
+ response.writeNoContent();
+ }
+
+ @Override
+ public void updateReference(DataRequest request, String entityETag, URI updateId,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ // this single valued navigation.
+ final EntityDetails details = process(request);
+ DataRequest updateRequest = request.parseLink(updateId);
+ Entity updateEntity = this.dataModel.getEntity(updateRequest.getEntitySet().getName(),
+ updateRequest.getKeyPredicates());
+ boolean updated = false;
+ if (updateEntity != null) {
+ updated = this.dataModel.updateNavigationLink(details.navigationProperty,
+ details.parentEntity, updateEntity);
+ }
+
+ if (updated) {
+ response.writeNoContent();
+ } else {
+ response.writeServerError(true);
+ }
+ }
+
+ @Override
+ public void deleteReference(DataRequest request, URI deleteId, String entityETag,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ boolean removed = false;
+ if (deleteId != null) {
+ final EntityDetails details = process(request);
+ DataRequest deleteRequest = request.parseLink(deleteId);
+ Entity deleteEntity = this.dataModel.getEntity(deleteRequest.getEntitySet().getName(),
+ deleteRequest.getKeyPredicates());
+ if (deleteEntity != null) {
+ removed = this.dataModel.removeNavigationLink(details.navigationProperty, details.entity,
+ deleteEntity);
+ }
+ } else {
+ // this single valued navigation.
+ final EntityDetails details = process(request);
+ removed = this.dataModel.removeNavigationLink(details.navigationProperty,
+ details.parentEntity, details.entity);
+ }
+ if (removed) {
+ response.writeNoContent();
+ } else {
+ response.writeServerError(true);
+ }
+ }
+
+ @Override
+ public void anyUnsupported(ODataRequest request, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ response.setStatusCode(500);
+ }
+
+ @Override
+ public String startTransaction() {
+ return null;
+ }
+
+ @Override
+ public void commit(String txnId) {
+ }
+
+ @Override
+ public void rollback(String txnId) {
+ }
+
+ @Override
+ public void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response) {
+ response.setStatusCode(200);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
new file mode 100644
index 0000000..4b26b8e
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
@@ -0,0 +1,756 @@
+/*
+ * 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.example;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+
+import org.apache.olingo.commons.core.Encoder;
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.api.ContentProvider;
+import org.eclipse.jetty.client.api.ContentResponse;
+import org.eclipse.jetty.http.HttpMethod;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+
+/**
+ * Please note that NONE of the system query options are developed in the sample
+ * service like $filter, $orderby etc. So using those options will be ignored
+ * right now. These tests designed to test the framework, all options are responsibilities
+ * of service developer.
+ */
+public class TripPinServiceTest {
+ private static Server server = new Server();
+ private static String baseURL;
+ private static HttpClient http = new HttpClient();
+
+ @BeforeClass
+ public static void beforeTest() throws Exception {
+ ServerConnector connector = new ServerConnector(server);
+ server.setConnectors(new Connector[] { connector });
+
+ ServletContextHandler context = new ServletContextHandler();
+ context.setContextPath("/trippin");
+ context.addServlet(new ServletHolder(new TripPinServlet()), "/*");
+ server.setHandler(context);
+ server.start();
+ int port = connector.getLocalPort();
+ http.start();
+ baseURL = "http://localhost:"+port+"/trippin";
+ }
+
+ @AfterClass
+ public static void afterTest() throws Exception {
+ server.stop();
+ }
+
+ @Test
+ public void testEntitySet() throws Exception {
+ ContentResponse response = http.newRequest(baseURL + "/People")
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .method(HttpMethod.GET)
+ .send();
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+ assertEquals(baseURL+"/People?$skiptoken=8", node.get("@odata.nextLink").asText());
+
+ JsonNode person = ((ArrayNode)node.get("value")).get(0);
+ assertEquals("russellwhyte", person.get("UserName").asText());
+ }
+
+ private JsonNode getJSONNode(ContentResponse response) throws IOException,
+ JsonProcessingException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ JsonNode node = objectMapper.readTree(response.getContent());
+ return node;
+ }
+
+ @Test
+ public void testReadEntitySetWithPaging() throws Exception {
+ ContentResponse response = http.newRequest(baseURL + "/People")
+ .header("Prefer", "odata.maxpagesize=10").send();
+
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+ assertEquals(baseURL+"/People?$skiptoken=10", node.get("@odata.nextLink").asText());
+
+ JsonNode person = ((ArrayNode)node.get("value")).get(0);
+ assertEquals("russellwhyte", person.get("UserName").asText());
+
+ assertNotNull(response.getHeaders().get("Preference-Applied"));
+ }
+
+ @Test
+ public void testReadEntityWithKey() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('AA')");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Airlines/$entity", node.get("@odata.context").asText());
+ assertEquals("American Airlines", node.get("Name").asText());
+ }
+
+ @Test
+ public void testReadEntityWithNonExistingKey() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('OO')");
+ assertEquals(404, response.getStatus());
+ }
+
+ @Test
+ public void testRead$Count() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines/$count");
+ assertEquals(200, response.getStatus());
+ assertEquals("15", response.getContentAsString());
+ }
+
+ @Test
+ public void testReadPrimitiveProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('AA')/Name");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Airlines('AA')/Name", node.get("@odata.context").asText());
+ assertEquals("American Airlines", node.get("value").asText());
+ }
+
+ @Test
+ public void testReadNonExistentProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('AA')/Unknown");
+ assertEquals(404, response.getStatus());
+ }
+
+ @Test
+ public void testReadPrimitiveArrayProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russellwhyte')/Emails");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Emails", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("Russell@example.com", ((ArrayNode)node.get("value")).get(0).asText());
+ assertEquals("Russell@contoso.com", ((ArrayNode)node.get("value")).get(1).asText());
+ }
+
+ @Test
+ public void testReadPrimitivePropertyValue() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('AA')/Name/$value");
+ assertEquals(200, response.getStatus());
+ assertEquals("American Airlines", response.getContentAsString());
+ }
+
+ @Test @Ignore
+ // TODO: Support geometry types to make this run
+ public void testReadComplexProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airports('KSFO')/Location");
+ fail("support geometry type");
+ }
+
+ @Test
+ public void testReadComplexArrayProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russellwhyte')/AddressInfo");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/AddressInfo", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("187 Suffolk Ln.", ((ArrayNode)node.get("value")).get(0).get("Address").asText());
+ }
+
+ @Test
+ public void testReadMedia() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Photos(1)/$value");
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testCreateMedia() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Photos(1)/$value";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content("bytecontents"), "image/jpeg")
+ .method(HttpMethod.PUT)
+ .send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testDeleteMedia() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Photos(1)/$value";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content("bytecontents"), "image/jpeg")
+ .method(HttpMethod.DELETE)
+ .send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testCreateStream() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content("bytecontents"), "image/jpeg")
+ .method(HttpMethod.POST)
+ .send();
+ // method not allowed
+ assertEquals(405, response.getStatus());
+ }
+
+ @Test
+ public void testCreateStream2() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content("bytecontents"), "image/jpeg")
+ .method(HttpMethod.PUT)
+ .send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testDeleteStream() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ ContentResponse response = http.newRequest(editUrl)
+ .method(HttpMethod.DELETE)
+ .send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testReadStream() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ ContentResponse response = http.newRequest(editUrl)
+ .method(HttpMethod.GET)
+ .send();
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testLambdaAny() throws Exception {
+ // this is just testing to see the labba expresions are going through the
+ // framework, none of the system options are not implemented in example service
+ String query = "Friends/any(d:d/UserName eq 'foo')";
+ ContentResponse response = http.newRequest(baseURL + "/People?$filter="+Encoder.encode(query))
+ .method(HttpMethod.GET)
+ .send();
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testSingleton() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Me");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Me", node.get("@odata.context").asText());
+ assertEquals("russellwhyte", node.get("UserName").asText());
+ }
+
+ @Test
+ public void testSelectOption() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russellwhyte')?$select=FirstName,LastName");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People(FirstName,LastName)/$entity", node.get("@odata.context").asText());
+ assertEquals("Russell", node.get("FirstName").asText());
+ }
+
+ @Test
+ public void testActionImportWithNoResponse() throws Exception {
+ ContentResponse response = http.POST(baseURL + "/ResetDataSource").send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testFunctionImport() throws Exception {
+ //TODO: fails because of lack of geometery support
+ ContentResponse response = http.GET(baseURL + "/GetNearestAirport(lat=23.0,lon=34.0)");
+ }
+
+ @Test
+ public void testBadReferences() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russelwhyte')/$ref");
+ assertEquals(405, response.getStatus());
+ }
+
+ @Test
+ public void testReadReferences() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russellwhyte')/Friends/$ref");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Collection($ref)", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("/People('scottketchum')", ((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
+ }
+
+ @Test
+ public void testAddCollectionReferences() throws Exception {
+ //GET
+ ContentResponse response = http.GET(baseURL + "/People('kristakemp')/Friends/$ref");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+
+ assertTrue(node.get("value").isArray());
+ assertEquals("/People('genevievereeves')", ((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
+ assertNull(((ArrayNode)node.get("value")).get(1));
+
+ //ADD
+ String payload = "{\n" +
+ " \"@odata.context\": \""+baseURL+"/$metadata#Collection($ref)\",\n" +
+ " \"value\": [\n" +
+ " { \"@odata.id\": \"People('russellwhyte')\" },\n" +
+ " { \"@odata.id\": \"People('scottketchum')\" } \n" +
+ " ]\n" +
+ "}";
+ response = http.POST(baseURL + "/People('kristakemp')/Friends/$ref")
+ .content(content(payload), "application/json")
+ .send();
+ assertEquals(204, response.getStatus());
+
+ //GET
+ response = http.GET(baseURL + "/People('kristakemp')/Friends/$ref");
+ assertEquals(200, response.getStatus());
+ node = getJSONNode(response);
+
+ assertTrue(node.get("value").isArray());
+ assertEquals("/People('genevievereeves')", ((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
+ assertEquals("/People('russellwhyte')", ((ArrayNode)node.get("value")).get(1).get("@odata.id").asText());
+ assertEquals("/People('scottketchum')", ((ArrayNode)node.get("value")).get(2).get("@odata.id").asText());
+ }
+
+
+ @Test
+ public void testEntityId() throws Exception {
+ ContentResponse response = http.GET(baseURL+"/$entity?$id="+baseURL + "/People('kristakemp')");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People/$entity", node.get("@odata.context").asText());
+ assertEquals("kristakemp", node.get("UserName").asText());
+
+ // using relative URL
+ response = http.GET(baseURL+"/$entity?$id="+"People('kristakemp')");
+ assertEquals(200, response.getStatus());
+ node = getJSONNode(response);
+ assertEquals("$metadata#People/$entity", node.get("@odata.context").asText());
+ assertEquals("kristakemp", node.get("UserName").asText());
+ }
+
+ @Test
+ public void testCreateReadDeleteEntity() throws Exception {
+ String payload = "{\n" +
+ " \"UserName\":\"olingodude\",\n" +
+ " \"FirstName\":\"Olingo\",\n" +
+ " \"LastName\":\"Apache\",\n" +
+ " \"Emails\":[\n" +
+ " \"olingo@apache.org\"\n" +
+ " ],\n" +
+ " \"AddressInfo\":[\n" +
+ " {\n" +
+ " \"Address\":\"100 apache Ln.\",\n" +
+ " \"City\":{\n" +
+ " \"CountryRegion\":\"United States\",\n" +
+ " \"Name\":\"Boise\",\n" +
+ " \"Region\":\"ID\"\n" +
+ " }\n" +
+ " }\n" +
+ " ],\n" +
+ " \"Gender\":\"0\",\n" +
+ " \"Concurrency\":635585295719432047\n" +
+ "}";
+ ContentResponse response = http.POST(baseURL + "/People")
+ .content(content(payload), "application/json")
+ .header("Prefer", "return=minimal")
+ .send();
+ // the below woud be 204, if minimal was not supplied
+ assertEquals(204, response.getStatus());
+ assertEquals("/People('olingodude')", response.getHeaders().get("Location"));
+ assertEquals("return=minimal", response.getHeaders().get("Preference-Applied"));
+
+ String location = baseURL+response.getHeaders().get("Location");
+ response = http.GET(location);
+ assertEquals(200, response.getStatus());
+
+ response = http.newRequest(location).method(HttpMethod.DELETE).send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(location);
+ assertEquals(404, response.getStatus());
+ }
+
+
+ @Test
+ public void testCreateEntityWithLinkToRelatedEntities() throws Exception {
+ String payload = "{\n" +
+ " \"UserName\":\"olingo\",\n" +
+ " \"FirstName\":\"Olingo\",\n" +
+ " \"LastName\":\"Apache\",\n" +
+ " \"Emails\":[\n" +
+ " \"olingo@apache.org\"\n" +
+ " ],\n" +
+ " \"AddressInfo\":[\n" +
+ " {\n" +
+ " \"Address\":\"100 apache Ln.\",\n" +
+ " \"City\":{\n" +
+ " \"CountryRegion\":\"United States\",\n" +
+ " \"Name\":\"Boise\",\n" +
+ " \"Region\":\"ID\"\n" +
+ " }\n" +
+ " }\n" +
+ " ],\n" +
+ " \"Gender\":\"0\",\n" +
+ " \"Concurrency\":635585295719432047,\n" +
+ "\"Friends@odata.bind\":[\"" +
+ baseURL+"/People('russellwhyte')\",\""+
+ baseURL+"/People('scottketchum')\""+
+ "]"+
+ "}";
+ ContentResponse response = http.POST(baseURL + "/People")
+ .content(content(payload), "application/json")
+ .header("Prefer", "return=minimal")
+ .send();
+ // the below woud be 204, if minimal was not supplied
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(baseURL+"/People('olingo')/Friends");
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("scottketchum", ((ArrayNode)node.get("value")).get(1).get("UserName").asText());
+ }
+
+ @Test
+ public void testUpdatePrimitiveProperty() throws Exception {
+ String payload = "{"
+ + " \"value\":\"Pilar Ackerman\""
+ + "}";
+
+ String editUrl = baseURL + "/People('russellwhyte')/FirstName";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content(payload), "application/json")
+ .method(HttpMethod.PUT)
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/FirstName", node.get("@odata.context").asText());
+ assertEquals("Pilar Ackerman", node.get("value").asText());
+ }
+
+ @Test
+ public void testUpdatePrimitiveArrayProperty() throws Exception {
+ String payload = "{"
+ + " \"value\": [\n" +
+ " \"olingo@apache.com\"\n" +
+ " ]"
+ + "}";
+
+ String editUrl = baseURL + "/People('russellwhyte')/Emails";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content(payload), "application/json")
+ .method(HttpMethod.PUT)
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Emails", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("olingo@apache.com", ((ArrayNode)node.get("value")).get(0).asText());
+ }
+
+ @Test
+ public void testDeleteProperty() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/FirstName";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("Russell", node.get("value").asText());
+
+ response = http.newRequest(editUrl)
+ .method(HttpMethod.DELETE)
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(editUrl);
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityCollection() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Friends";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+
+ JsonNode person = ((ArrayNode)node.get("value")).get(0);
+ assertEquals("scottketchum", person.get("UserName").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityCollection2() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Friends('scottketchum')/Trips";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Friends('scottketchum')/Trips",
+ node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("1001", ((ArrayNode)node.get("value")).get(0).get("TripId").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntity() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips/$entity",
+ node.get("@odata.context").asText());
+ assertEquals("f94e9116-8bdd-4dac-ab61-08438d0d9a71", node.get("ShareId").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityNotExisting() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(9999)";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntitySetNotExisting() throws Exception {
+ String editUrl = baseURL + "/People('jhondoe')/Trips";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('jhondoe')/Trips",
+ node.get("@odata.context").asText());
+ assertEquals(0, ((ArrayNode)node.get("value")).size());
+ }
+
+ @Test
+ public void testBadNavigationProperty() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Unknown";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(404, response.getStatus());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityProperty() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode",
+ node.get("@odata.context").asText());
+
+ assertEquals("JH58494", node.get("value").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityMultipleDerivedTypes() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)/PlanItems";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems",
+ node.get("@odata.context").asText());
+
+ assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Flight",
+ ((ArrayNode) node.get("value")).get(0).get("@odata.type").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityCoolectionDerivedFilter() throws Exception {
+ String editUrl = baseURL
+ + "/People('russellwhyte')/Trips(1003)/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Event";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/"
+ + "Microsoft.OData.SampleService.Models.TripPin.Event",
+ node.get("@odata.context").asText());
+
+ assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Event",
+ ((ArrayNode) node.get("value")).get(0).get("@odata.type").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityDerivedFilter() throws Exception {
+ String editUrl = baseURL+ "/People('russellwhyte')/Trips(1003)/PlanItems(56)/"
+ + "Microsoft.OData.SampleService.Models.TripPin.Event";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/"
+ + "Microsoft.OData.SampleService.Models.TripPin.Event/$entity",
+ node.get("@odata.context").asText());
+
+ assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Event", node.get("@odata.type").asText());
+ assertEquals("56", node.get("PlanItemId").asText());
+ }
+
+ @Test
+ public void testUpdateReference() throws Exception {
+ ContentResponse response = http.GET(baseURL+"/People('ronaldmundy')/Photo/$ref");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("/Photos(12)", node.get("@odata.id").asText());
+
+ String msg = "{\n" +
+ "\"@odata.id\": \"/Photos(11)\"\n" +
+ "}";
+ String editUrl = baseURL + "/People('ronaldmundy')/Photo/$ref";
+ response = http.newRequest(editUrl)
+ .method(HttpMethod.PUT)
+ .content(content(msg))
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(baseURL+"/People('ronaldmundy')/Photo/$ref");
+ assertEquals(200, response.getStatus());
+ node = getJSONNode(response);
+ assertEquals("/Photos(11)", node.get("@odata.id").asText());
+ }
+
+ @Test
+ public void testAddDelete2ReferenceCollection() throws Exception {
+ // add
+ String msg = "{\n" +
+ "\"@odata.id\": \"/People('russellwhyte')\"\n" +
+ "}";
+ String editUrl = baseURL + "/People('vincentcalabrese')/Friends/$ref";
+ ContentResponse response = http.newRequest(editUrl)
+ .method(HttpMethod.POST)
+ .content(content(msg))
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .send();
+ assertEquals(204, response.getStatus());
+
+ // get
+ response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("/People('russellwhyte')",
+ ((ArrayNode) node.get("value")).get(2).get("@odata.id").asText());
+
+ //delete
+ response = http.newRequest(editUrl+"?$id="+baseURL+"/People('russellwhyte')")
+ .method(HttpMethod.DELETE)
+ .content(content(msg))
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .send();
+ assertEquals(204, response.getStatus());
+
+ // get
+ response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ node = getJSONNode(response);
+ assertNull("/People('russellwhyte')", ((ArrayNode) node.get("value")).get(2));
+ }
+
+ @Test
+ public void testDeleteReference() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Photo/$ref";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ response = http.newRequest(editUrl)
+ .method(HttpMethod.DELETE)
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(editUrl);
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testCrossJoin() throws Exception {
+ String editUrl = baseURL + "/$crossjoin(People,Airlines)";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ }
+
+ public static ContentProvider content(final String msg) {
+ return new ContentProvider() {
+ boolean hasNext = true;
+
+ @Override
+ public Iterator<ByteBuffer> iterator() {
+ return new Iterator<ByteBuffer>() {
+ @Override
+ public boolean hasNext() {
+ return hasNext;
+ }
+ @Override
+ public ByteBuffer next() {
+ hasNext = false;
+ return ByteBuffer.wrap(msg.getBytes());
+ }
+ @Override
+ public void remove() {
+ }
+ };
+ }
+ @Override
+ public long getLength() {
+ return msg.length();
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServlet.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServlet.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServlet.java
new file mode 100644
index 0000000..2c05d65
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServlet.java
@@ -0,0 +1,75 @@
+/*
+ * 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.example;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collections;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataHttpHandler;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.core.MetadataParser;
+import org.apache.olingo.server.core.OData4Impl;
+
+public class TripPinServlet extends HttpServlet {
+ private static final long serialVersionUID = 2663595419366214401L;
+ private TripPinDataModel dataModel;
+
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ }
+
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ OData odata = OData4Impl.newInstance();
+ MetadataParser parser = new MetadataParser();
+ EdmProvider edmProvider = null;
+
+ try {
+ edmProvider = parser.buildEdmProvider(new FileReader("src/test/resources/trippin.xml"));
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
+ }
+
+ ServiceMetadata metadata = odata.createServiceMetadata(edmProvider, Collections.EMPTY_LIST);
+
+ ODataHttpHandler handler = odata.createHandler(metadata);
+
+ if (this.dataModel == null) {
+ try {
+ this.dataModel = new TripPinDataModel(metadata);
+ } catch (Exception e) {
+ throw new IOException("Failed to load data for TripPin Service");
+ }
+ }
+
+ handler.register(new TripPinHandler(this.dataModel));
+ handler.process(request, response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/OlingoOrangeTM.png
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/OlingoOrangeTM.png b/lib/server-core-ext/src/test/resources/OlingoOrangeTM.png
new file mode 100644
index 0000000..d614f1a
Binary files /dev/null and b/lib/server-core-ext/src/test/resources/OlingoOrangeTM.png differ
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/airlines.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/airlines.json b/lib/server-core-ext/src/test/resources/airlines.json
new file mode 100644
index 0000000..78eccdc
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/airlines.json
@@ -0,0 +1,64 @@
+{
+ "value":[
+ {
+ "AirlineCode":"AA",
+ "Name":"American Airlines"
+ },
+ {
+ "AirlineCode":"FM",
+ "Name":"Shanghai Airline"
+ },
+ {
+ "AirlineCode":"MU",
+ "Name":"China Eastern Airlines"
+ },
+ {
+ "AirlineCode":"AF",
+ "Name":"Air France"
+ },
+ {
+ "AirlineCode":"AZ",
+ "Name":"Alitalia"
+ },
+ {
+ "AirlineCode":"AC",
+ "Name":"Air Canada"
+ },
+ {
+ "AirlineCode":"OS",
+ "Name":"Austrian Airlines"
+ },
+ {
+ "AirlineCode":"TK",
+ "Name":"Turkish Airlines"
+ },
+ {
+ "AirlineCode":"JL",
+ "Name":"Japan Airlines"
+ },
+ {
+ "AirlineCode":"SQ",
+ "Name":"Singapore Airlines"
+ },
+ {
+ "AirlineCode":"KE",
+ "Name":"Korean Air"
+ },
+ {
+ "AirlineCode":"CZ",
+ "Name":"China Southern"
+ },
+ {
+ "AirlineCode":"AK",
+ "Name":"AirAsia"
+ },
+ {
+ "AirlineCode":"HX",
+ "Name":"Hong Kong Airlines"
+ },
+ {
+ "AirlineCode":"EK",
+ "Name":"Emirates"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/airports.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/airports.json b/lib/server-core-ext/src/test/resources/airports.json
new file mode 100644
index 0000000..c06a5cf
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/airports.json
@@ -0,0 +1,394 @@
+{
+ "value":[
+ {
+ "IcaoCode":"KSFO",
+ "Name":"San Francisco International Airport",
+ "IataCode":"SFO",
+ "Location":{
+ "Address":"South McDonnell Road, San Francisco, CA 94128",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"San Francisco",
+ "Region":"California"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -122.374722222222,
+ 37.6188888888889
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KLAX",
+ "Name":"Los Angeles International Airport",
+ "IataCode":"LAX",
+ "Location":{
+ "Address":"1 World Way, Los Angeles, CA, 90045",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Los Angeles",
+ "Region":"California"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -118.408055555556,
+ 33.9425
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"ZSSS",
+ "Name":"Shanghai Hongqiao International Airport",
+ "IataCode":"SHA",
+ "Location":{
+ "Address":"Hongqiao Road 2550, Changning District",
+ "City":{
+ "CountryRegion":"China",
+ "Name":"Shanghai",
+ "Region":"Shanghai"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 121.336111111111,
+ 31.1977777777778
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"ZBAA",
+ "Name":"Beijing Capital International Airport",
+ "IataCode":"PEK",
+ "Location":{
+ "Address":"Airport Road, Chaoyang District, Beijing, 100621",
+ "City":{
+ "CountryRegion":"China",
+ "Name":"Beijing",
+ "Region":"Beijing"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 116.584444444444,
+ 40.08
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KJFK",
+ "Name":"John F. Kennedy International Airport",
+ "IataCode":"JFK",
+ "Location":{
+ "Address":"Jamaica, New York, NY 11430",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"New York City",
+ "Region":"New York"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -73.7788888888889,
+ 40.6397222222222
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"LIRA",
+ "Name":"Rome Ciampino Airport",
+ "IataCode":"CIA",
+ "Location":{
+ "Address":"Via Appia Nuova, 1651",
+ "City":{
+ "CountryRegion":"Italy",
+ "Name":"Rome",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 12.5947222222222,
+ 41.7991666666667
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"CYYZ",
+ "Name":"Toronto Pearson International Airport",
+ "IataCode":"YYZ",
+ "Location":{
+ "Address":"6301 Silver Dart Dr Mississauga",
+ "City":{
+ "CountryRegion":"Canada",
+ "Name":"Mississauga",
+ "Region":"Ontario"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -79.6305555555555,
+ 43.6772222222222
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"YSSY",
+ "Name":"Sydney Airport",
+ "IataCode":"SYD",
+ "Location":{
+ "Address":"Airport Dr Sydney NSW 2020",
+ "City":{
+ "CountryRegion":"Australia",
+ "Name":"Sydney",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 151.177222222222,
+ -33.9461111111111
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"LTBA",
+ "Name":"Istanbul Ataturk Airport",
+ "IataCode":"IST",
+ "Location":{
+ "Address":"Ye\u015filk\u00f6y Mh.34149 \u0130stanbul",
+ "City":{
+ "CountryRegion":"Turkey",
+ "Name":"Istanbul",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 28.8211111111111,
+ 40.9766666666667
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"WSSS",
+ "Name":"Singapore Changi Airport",
+ "IataCode":"SIN",
+ "Location":{
+ "Address":"Airport Blvd, Singapore",
+ "City":{
+ "CountryRegion":"Singapore",
+ "Name":"Changi",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 103.987222222222,
+ 1.35555555555556
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"OMAA",
+ "Name":"Abu Dhabi International Airport",
+ "IataCode":"AUH",
+ "Location":{
+ "Address":"Sheik Maktoum Bin Rashid Rd Abu Dhabi",
+ "City":{
+ "CountryRegion":"United Arab Emirates",
+ "Name":"Abu Dhabi",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 54.6511111111111,
+ 24.4327777777778
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"ZGGG",
+ "Name":"Guangzhou Baiyun International Airport",
+ "IataCode":"CAN",
+ "Location":{
+ "Address":"Jichang Road, Renhezhen, Huadu",
+ "City":{
+ "CountryRegion":"China",
+ "Name":"Guangzhou",
+ "Region":"Guangdong"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 113.265833333333,
+ 23.1841666666667
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KORD",
+ "Name":"O'Hare International Airport",
+ "IataCode":"ORD",
+ "Location":{
+ "Address":"10000 W O'Hare Ave",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Chicago",
+ "Region":"Illinois"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -87.9044444444445,
+ 41.9794444444444
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KATL",
+ "Name":"Hartsfield-Jackson Atlanta International Airport",
+ "IataCode":"ATL",
+ "Location":{
+ "Address":"6000 N Terminal Pkwy",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Atlanta",
+ "Region":"Georgia"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -84.4269444444444,
+ 33.6402777777778
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KSEA",
+ "Name":"Seattle-Tacoma International Airport",
+ "IataCode":"SEA",
+ "Location":{
+ "Address":"17801 International Blvd",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"SeaTac",
+ "Region":"Washington"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -122.309166666667,
+ 47.4488888888889
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/event.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/event.json b/lib/server-core-ext/src/test/resources/event.json
new file mode 100644
index 0000000..eb19dde
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/event.json
@@ -0,0 +1,157 @@
+{
+ "value":[
+ {
+ "PlanItemId": 50,
+ "Description": "Client Meeting",
+ "ConfirmationCode": "4372899DD",
+ "StartsAt": "2014-01-02T13:00:00Z",
+ "EndsAt": "2014-01-02T16:00:00Z",
+ "Duration": "PT3H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Regus Business Center",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "100 Church Street, 8th Floor, Manhattan, 10007"
+ }
+ },
+ {
+ "PlanItemId": 51,
+ "Description": "Visit the Brooklyn Bridge Park",
+ "ConfirmationCode": "4372899AA",
+ "StartsAt": "2014-01-01T15:00:00Z",
+ "EndsAt": "2014-01-01T16:00:00Z",
+ "Duration": "PT1H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Brooklyn Bridge Park, at Fulton Ferry Landing",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "Main St Dumbo Brooklyn 11201"
+ }
+ },
+ {
+ "PlanItemId": 52,
+ "Description": "Empire State Building",
+ "ConfirmationCode": "4372899BB",
+ "StartsAt": "2014-01-03T10:00:00Z",
+ "EndsAt": "2014-01-03T12:00:00Z",
+ "Duration": "PT2H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Empire State Building",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "Empire State Building, 350 5th Ave"
+ }
+ },
+ {
+ "PlanItemId": 53,
+ "Description": "Coney Island",
+ "ConfirmationCode": "4372899CC",
+ "StartsAt": "2014-01-03T14:00:00Z",
+ "EndsAt": "2014-01-03T20:00:00Z",
+ "Duration": "PT6H",
+ "OccursAt":
+ {
+ "BuildingInfo": "",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "1208 Surf Ave, Brooklyn"
+ }
+ },
+ {
+ "PlanItemId": 54,
+ "Description": "Shopping at Times Square",
+ "ConfirmationCode": "4372899DD",
+ "StartsAt": "2014-01-04T10:00:00Z",
+ "EndsAt": "2014-01-04T15:00:00Z",
+ "Duration": "PT5H",
+ "OccursAt":
+ {
+ "BuildingInfo": "",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "Broadway, 7th Avenue, 42nd and 47th Streets"
+ }
+ },
+ {
+ "PlanItemId": 55,
+ "Description": "Dinner",
+ "ConfirmationCode": "4372899EE",
+ "StartsAt": "2014-02-02T18:00:00Z",
+ "EndsAt": "2014-02-02T21:00:00Z",
+ "Duration": "PT3H",
+ "OccursAt":
+ {
+ "Address": "10 Beijing Street, 100000",
+ "City":
+ {
+ "Name": "Beijing",
+ "CountryRegion": "China",
+ "Region": "Beijing"
+ },
+ "BuildingInfo": "Beijing Restaurant"
+ }
+ },
+ {
+ "PlanItemId": 56,
+ "Description": "Dinner",
+ "ConfirmationCode": "4372899FF",
+ "StartsAt": "2014-02-02T18:00:00Z",
+ "EndsAt": "2014-02-02T21:00:00Z",
+ "Duration": "PT3H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Beijing Restaurant",
+ "City":
+ {
+ "Name": "Beijing",
+ "CountryRegion": "China",
+ "Region": "Beijing"
+ },
+ "Address": "10 Beijing Street, 100000"
+ }
+ },
+ {
+ "PlanItemId": 57,
+ "Description": "Dinner",
+ "ConfirmationCode": "4372899GG",
+ "StartsAt": "2014-02-02T18:00:00Z",
+ "EndsAt": "2014-02-02T21:00:00Z",
+ "Duration": "PT3H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Beijing Restaurant",
+ "City":
+ {
+ "Name": "Beijing",
+ "CountryRegion": "China",
+ "Region": "Beijing"
+ },
+ "Address": "10 Beijing Street, 100000"
+ }
+ }
+ ]
+}
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/flight-links.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/flight-links.json b/lib/server-core-ext/src/test/resources/flight-links.json
new file mode 100644
index 0000000..17741d0
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/flight-links.json
@@ -0,0 +1,52 @@
+{
+ "value":[
+ {
+ "PlanItemId": 1,
+ "Airline": "AA",
+ "From": "ORD",
+ "To": "JFK"
+ },
+ {
+ "PlanItemId": 2,
+ "Airline": "AA",
+ "From": "JFK",
+ "To": "ORD"
+ },
+ {
+ "PlanItemId": 3,
+ "Airline": "FM",
+ "From": "SHA",
+ "To": "PEK"
+ },
+ {
+ "PlanItemId": 4,
+ "Airline": "MU",
+ "From": "PEK",
+ "To": "SHA"
+ },
+ {
+ "PlanItemId": 5,
+ "Airline": "FM",
+ "From": "SHA",
+ "To": "PEK"
+ },
+ {
+ "PlanItemId": 6,
+ "Airline": "MU",
+ "From": "PEK",
+ "To": "SHA"
+ },
+ {
+ "PlanItemId": 7,
+ "Airline": "FM",
+ "From": "SHA",
+ "To": "PEK"
+ },
+ {
+ "PlanItemId": 8,
+ "Airline": "MU",
+ "From": "PEK",
+ "To": "SHA"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/flight.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/flight.json b/lib/server-core-ext/src/test/resources/flight.json
new file mode 100644
index 0000000..af06998
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/flight.json
@@ -0,0 +1,66 @@
+{
+ "value":[
+ {
+ "PlanItemId": 1,
+ "ConfirmationCode": "JH58493",
+ "FlightNumber": "AA26",
+ "StartsAt": "2014-01-01T06:15:00Z",
+ "EndsAt": "2014-01-01T11:35:00Z"
+ },
+ {
+ "PlanItemId": 2,
+ "ConfirmationCode": "JH38143",
+ "FlightNumber": "AA4035",
+ "StartsAt": "2014-01-04T17:55:00Z",
+ "EndsAt": "2014-01-04T20:45:00Z"
+ },
+ {
+ "PlanItemId": 3,
+ "ConfirmationCode": "JH58494",
+ "FlightNumber": "FM1930",
+ "StartsAt": "2014-02-01T08:00:00Z",
+ "EndsAt": "2014-02-01T09:20:00Z",
+ "SeatNumber": "B11"
+ },
+ {
+ "PlanItemId": 4,
+ "ConfirmationCode": "JH58495",
+ "FlightNumber": "MU1930",
+ "StartsAt": "2014-02-10T15:00:00Z",
+ "EndsAt": "2014-02-10T16:30:00Z",
+ "SeatNumber": "A32"
+ },
+ {
+ "PlanItemId": 5,
+ "ConfirmationCode": "JH58494",
+ "FlightNumber": "FM1930",
+ "StartsAt": "2014-02-01T08:00:00Z",
+ "EndsAt": "2014-02-01T09:20:00Z",
+ "SeatNumber": "B11"
+ },
+ {
+ "PlanItemId": 6,
+ "ConfirmationCode": "JH58495",
+ "FlightNumber": "MU1930",
+ "StartsAt": "2014-02-10T15:00:00Z",
+ "EndsAt": "2014-02-10T16:30:00Z",
+ "SeatNumber": "A32"
+ },
+ {
+ "PlanItemId": 7,
+ "ConfirmationCode": "JH58494",
+ "FlightNumber": "FM1930",
+ "StartsAt": "2014-02-01T08:00:00Z",
+ "EndsAt": "2014-02-01T09:20:00Z",
+ "SeatNumber": "B12"
+ },
+ {
+ "PlanItemId": 8,
+ "ConfirmationCode": "JH58495",
+ "FlightNumber": "MU1930",
+ "StartsAt": "2014-02-10T16:30:00Z",
+ "EndsAt": "2014-02-10T16:30:00Z",
+ "SeatNumber": "A33"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/people-links.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/people-links.json b/lib/server-core-ext/src/test/resources/people-links.json
new file mode 100644
index 0000000..878d6ce
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/people-links.json
@@ -0,0 +1,94 @@
+{
+ "value":[
+ {
+ "UserName":"russellwhyte",
+ "Friends": ["scottketchum", "ronaldmundy", "javieralfred", "angelhuffman"],
+ "Trips": [1001, 1003, 1007],
+ "Photo": 1
+ },
+ {
+ "UserName":"scottketchum",
+ "Friends": ["russellwhyte", "ronaldmundy"],
+ "Trips": [1001, 2004],
+ "Photo": 11
+ },
+ {
+ "UserName":"ronaldmundy",
+ "Friends": ["russellwhyte", "scottketchum"],
+ "Trips": [3009],
+ "Photo": 12
+ },
+ {
+ "UserName":"javieralfred",
+ "Friends": ["willieashmore", "vincentcalabrese", "georginabarlow"],
+ "Trips": [4005]
+ },
+ {
+ "UserName":"willieashmore",
+ "Friends": ["javieralfred", "vincentcalabrese"],
+ "Trips": [5007, 5008]
+ },
+ {
+ "UserName":"vincentcalabrese",
+ "Friends": ["javieralfred", "willieashmore"],
+ "Trips": [7010]
+ },
+ {
+ "UserName":"clydeguess",
+ "Friends": ["keithpinckney", "ursulabright"],
+ "Trips": [8011]
+ },
+ {
+ "UserName":"keithpinckney",
+ "Friends": ["clydeguess", "marshallgaray"],
+ "Trips": []
+ },
+ {
+ "UserName":"marshallgaray",
+ "Friends": ["keithpinckney", "elainestewart", "jonirosales"]
+ },
+ {
+ "UserName":"elainestewart",
+ "Friends": ["marshallgaray"]
+ },
+ {
+ "UserName":"salliesampson",
+ "Friends": [""],
+ "Trips": [13012]
+ },
+ {
+ "UserName":"jonirosales",
+ "Friends": ["marshallgaray"],
+ "Trips": [14013]
+ },
+ {
+ "UserName":"georginabarlow",
+ "Friends": ["javieralfred"]
+ },
+ {
+ "UserName":"angelhuffman",
+ "Friends": ["russellwhyte"],
+ "Trips": [16014]
+ },
+ {
+ "UserName":"laurelosborn",
+ "Friends": ["sandyosborn"]
+ },
+ {
+ "UserName":"sandyosborn",
+ "Friends": ["laurelosborn"]
+ },
+ {
+ "UserName":"ursulabright",
+ "Friends": ["keithpinckney"]
+ },
+ {
+ "UserName":"genevievereeves",
+ "Friends": ["kristakemp"]
+ },
+ {
+ "UserName":"kristakemp",
+ "Friends": ["genevievereeves"]
+ }
+ ]
+}
[47/50] [abbrv] olingo-odata4 git commit: [OLINGO-617] Derserializer
and Serializer result refactoring, ExpandBuilder
Posted by ch...@apache.org.
[OLINGO-617] Derserializer and Serializer result refactoring, ExpandBuilder
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/502f7ced
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/502f7ced
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/502f7ced
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 502f7cedee18749ab92fd55b700cf64b75a11a16
Parents: 61b0daa
Author: Christian Holzer <c....@sap.com>
Authored: Thu Apr 2 14:55:51 2015 +0200
Committer: Christian Holzer <ch...@t-online.de>
Committed: Fri Apr 3 12:41:55 2015 +0200
----------------------------------------------------------------------
.../fit/tecsvc/client/DeepInsertITCase.java | 132 ++++++++++++++++++-
.../api/deserializer/DeserializerResult.java | 69 ++++++++++
.../api/deserializer/ODataDeserializer.java | 25 ++--
.../server/api/processor/DefaultProcessor.java | 6 +-
.../server/api/serializer/ODataSerializer.java | 18 +--
.../server/api/serializer/SerializerResult.java | 32 +++++
.../apache/olingo/server/core/ErrorHandler.java | 2 +-
.../server/core/requests/DataRequest.java | 6 +-
.../server/core/responses/EntityResponse.java | 4 +-
.../core/responses/EntitySetResponse.java | 3 +-
.../server/core/responses/MetadataResponse.java | 2 +-
.../server/core/responses/PropertyResponse.java | 8 +-
.../core/responses/ServiceDocumentResponse.java | 2 +-
.../olingo/server/example/TripPinDataModel.java | 2 +-
.../deserializer/DeserializerResultImpl.java | 126 ++++++++++++++++++
.../deserializer/helper/ExpandTreeBuilder.java | 40 ++++++
.../helper/ExpandTreeBuilderImpl.java | 67 ++++++++++
.../json/ODataJsonDeserializer.java | 66 ++++++----
.../core/serializer/SerializerResultImpl.java | 53 ++++++++
.../serializer/json/ODataJsonSerializer.java | 37 +++---
.../serializer/xml/ODataXmlSerializerImpl.java | 24 ++--
.../json/ODataJsonDeserializerBasicTest.java | 5 +-
.../json/ODataErrorSerializerTest.java | 14 +-
.../json/ODataJsonSerializerTest.java | 2 +-
.../xml/MetadataDocumentXmlSerializerTest.java | 10 +-
.../processor/TechnicalEntityProcessor.java | 18 ++-
.../TechnicalPrimitiveComplexProcessor.java | 8 +-
.../json/ODataDeserializerDeepInsertTest.java | 8 +-
.../ODataDeserializerEntityCollectionTest.java | 9 +-
...ataJsonDeserializerActionParametersTest.java | 4 +-
.../json/ODataJsonDeserializerEntityTest.java | 56 +++++---
.../json/ODataJsonSerializerTest.java | 48 +++----
.../serializer/json/ServiceDocumentTest.java | 2 +-
.../serializer/xml/MetadataDocumentTest.java | 2 +-
.../server/sample/processor/CarsProcessor.java | 8 +-
35 files changed, 732 insertions(+), 186 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
index 4e15ca0..ba33e3f 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.olingo.client.api.ODataClient;
@@ -45,7 +46,6 @@ import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
-import org.junit.AfterClass;
import org.junit.Test;
public class DeepInsertITCase extends AbstractBaseTestITCase {
@@ -72,11 +72,133 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
private static final String NAV_PROPERTY_ET_TWO_KEY_NAV_ONE = "NavPropertyETTwoKeyNavOne";
private static final String NAV_PROPERTY_ET_TWO_KEY_NAV_MANY = "NavPropertyETTwoKeyNavMany";
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- //Nothing needed here.
- }
+ @Test
+ public void testDeepInsertExpandedResponse() {
+ final ODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI);
+ client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
+ final URI createURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
+ final ODataObjectFactory of = client.getObjectFactory();
+ final ODataEntity entity = of.newEntity(ET_KEY_NAV);
+
+ // Root entity
+ entity.getProperties().add(
+ of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("String Property level 0")));
+ entity.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 41)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 0, complex level 1")))));
+
+ // First level NavPropertyETTwoKeyNavOne => Type ETTwoKeyNav
+ final ODataEntity firstLevelTwoKeyNav = of.newEntity(ET_TWO_KEY_NAV);
+ firstLevelTwoKeyNav.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 1, complex level 1")))));
+ final ODataInlineEntity firstLevelTwoKeyOneInline =
+ of.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, firstLevelTwoKeyNav);
+ entity.addLink(firstLevelTwoKeyOneInline);
+
+ // Second level NavPropertyETTwoKeyNavOne => Type ETTwoKeyNav
+ final ODataEntity secondLevelTwoKeyNav = of.newEntity(ET_TWO_KEY_NAV);
+ secondLevelTwoKeyNav.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 421)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 2, complex level 1")))));
+
+ // Binding links
+ secondLevelTwoKeyNav.addLink(of.newEntityNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, client.newURIBuilder(
+ SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(new LinkedHashMap<String, Object>() {
+ private static final long serialVersionUID = 3109256773218160485L;
+ {
+ put(PROPERTY_INT16, 3);
+ put(PROPERTY_STRING, "1");
+ }
+ }).build()));
+
+ final ODataInlineEntity secondLevelTwoKeyOneInline =
+ of.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, secondLevelTwoKeyNav);
+ firstLevelTwoKeyNav.addLink(secondLevelTwoKeyOneInline);
+
+ // Third level NavPropertyETTwoKeyNavMany => Type ETTwoKeyNav
+ final ODataEntity thirdLevelTwoKeyNavMany1 = of.newEntity(ET_TWO_KEY_NAV);
+ thirdLevelTwoKeyNavMany1.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 431)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 3, complex level 1")))));
+
+ final ODataEntity thirdLevelTwoKeyNavMany2 = of.newEntity(ET_TWO_KEY_NAV);
+ thirdLevelTwoKeyNavMany2.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 432)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 3, complex level 1")))));
+
+ final ODataEntitySet entitySetThirdLevelTwoKeyNavMany = of.newEntitySet();
+ entitySetThirdLevelTwoKeyNavMany.getEntities().add(thirdLevelTwoKeyNavMany1);
+ entitySetThirdLevelTwoKeyNavMany.getEntities().add(thirdLevelTwoKeyNavMany2);
+ secondLevelTwoKeyNav.addLink(of.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY,
+ entitySetThirdLevelTwoKeyNavMany));
+
+ // First level NavPropertyETTwoKeyNavMany => Type ETTwoKeyNav
+ final ODataEntity firstLevelTwoKeyNavMany1 = of.newEntity(ET_TWO_KEY_NAV);
+ firstLevelTwoKeyNavMany1.getProperties().add(
+ of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 422)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
+ "String Property level 1, complex level 1")))));
+
+ final ODataEntitySet entitySetfirstLevelTwoKeyNavMany = of.newEntitySet();
+ entitySetfirstLevelTwoKeyNavMany.getEntities().add(firstLevelTwoKeyNavMany1);
+ entity.addLink(of.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY,
+ entitySetfirstLevelTwoKeyNavMany));
+
+ final ODataEntityCreateResponse<ODataEntity> createResponse =
+ client.getCUDRequestFactory().getEntityCreateRequest(createURI, entity).execute();
+ // Check response
+ final ODataEntity resultEntityFirstLevel =
+ createResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE).asInlineEntity().getEntity();
+ assertEquals(42, resultEntityFirstLevel.getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_INT16)
+ .getPrimitiveValue().toValue());
+ assertEquals("String Property level 1, complex level 1", resultEntityFirstLevel.getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_STRING)
+ .getPrimitiveValue().toValue());
+
+ final ODataEntity resultEntitySecondLevel =
+ resultEntityFirstLevel.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE).asInlineEntity().getEntity();
+ assertEquals(421, resultEntitySecondLevel.getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_INT16)
+ .getPrimitiveValue().toValue());
+ assertEquals("String Property level 2, complex level 1", resultEntitySecondLevel.getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_STRING)
+ .getPrimitiveValue().toValue());
+
+ final ODataEntitySet thirdLevelEntitySetNavMany =
+ resultEntitySecondLevel.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
+ assertEquals(2, thirdLevelEntitySetNavMany.getEntities().size());
+
+ assertEquals(431, thirdLevelEntitySetNavMany.getEntities().get(0).getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals("String Property level 3, complex level 1", thirdLevelEntitySetNavMany.getEntities().get(0)
+ .getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_STRING).getPrimitiveValue().toValue());
+
+ assertEquals(432, thirdLevelEntitySetNavMany.getEntities().get(1).getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals("String Property level 3, complex level 1", thirdLevelEntitySetNavMany.getEntities().get(1)
+ .getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_STRING).getPrimitiveValue().toValue());
+
+ final ODataEntitySet firstLevelEntitySetNavMany =
+ createResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
+ assertEquals(1, firstLevelEntitySetNavMany.getEntities().size());
+ assertEquals(422, firstLevelEntitySetNavMany.getEntities().get(0).getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals("String Property level 1, complex level 1", firstLevelEntitySetNavMany.getEntities().get(0)
+ .getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_STRING).getPrimitiveValue().toValue());
+ }
+
@Test
public void testSimpleDeepInsert() throws EdmPrimitiveTypeException {
final ODataClient client = getClient();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerResult.java
new file mode 100644
index 0000000..3f36939
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerResult.java
@@ -0,0 +1,69 @@
+/*
+ * 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.deserializer;
+
+import java.net.URI;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Parameter;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.commons.api.data.Property;
+
+/**
+ * Result type for {@link ODataDeserializer} methods
+ */
+public interface DeserializerResult {
+ /**
+ * Return an entity
+ * @return an {@link Entity} or null
+ */
+ Entity getEntity();
+
+ /**
+ * Returns a entity set
+ * @return an {@link EntitySet} or null
+ */
+ EntitySet getEntityCollection();
+
+ /**
+ * Returns the ExpandOptions for serialized entities
+ * @return an {@link ExpandOption} or null
+ */
+ ExpandOption getExpandTree();
+
+ /**
+ * Returns the deserialized action-parameters of an {@link Entity} object.
+ * @return a collection {@link Parameter}
+ */
+ List<Parameter> getActionParameter();
+
+ /**
+ * Returns a Property or collections of properties (primitive & complex)
+ * @return {@link Property} or collections of properties (primitive & complex) or null
+ */
+ Property getProperty();
+
+ /**
+ * Returns the entity references from the provided document
+ * @return a collection of entity reference
+ */
+ List<URI> getEntityReferences();
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
index 9aabf33..f014ad6 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
@@ -19,13 +19,9 @@
package org.apache.olingo.server.api.deserializer;
import java.io.InputStream;
-import java.net.URI;
-import java.util.List;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.Parameter;
-import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmProperty;
@@ -38,47 +34,48 @@ public interface ODataDeserializer {
/**
* Deserializes an entity stream into an {@link Entity} object.
* Validates: property types, no double properties, correct json types
+ * Returns a deserialized {@link Entity} object and an {@link ExpandOption} object
* @param stream
* @param edmEntityType
- * @return deserialized {@link Entity} object
+ * @return {@link DeserializerResult#getEntity()} and {@link DeserializerResult#getExpandTree()}
* @throws DeserializerException
*/
- Entity entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
+ DeserializerResult entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
/**
* Deserializes an entity collection stream into an {@link EntitySet} object.
* @param stream
* @param edmEntityType
- * @return deserialized {@link EntitySet} object
+ * @return {@link DeserializerResult#getEntityCollection()}
* @throws DeserializerException
*/
- EntitySet entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
+ DeserializerResult entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
/**
* Deserializes an action-parameters stream into an {@link Entity} object.
* Validates: parameter types, no double parameters, correct json types.
* @param stream
* @param edmAction
- * @return deserialized list of {@link Parameter} objects
+ * @return {@link DeserializerResult#getActionParameter()}
* @throws DeserializerException
*/
- List<Parameter> actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
+ DeserializerResult actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
/**
* Deserializes the Property or collections of properties (primitive & complex)
* @param stream
* @param edmProperty
- * @return deserialized {@link Property}
+ * @return {@link DeserializerResult#getProperty()}
* @throws DeserializerException
*/
- Property property(InputStream stream, EdmProperty edmProperty) throws DeserializerException;
+ DeserializerResult property(InputStream stream, EdmProperty edmProperty) throws DeserializerException;
/**
* Read entity references from the provided document
* @param stream
* @param keys
- * @return
+ * @return {@link DeserializerResult#getEntityReferences()}}
* @throws DeserializerException
*/
- List<URI> entityReferences(InputStream stream) throws DeserializerException;
+ DeserializerResult entityReferences(InputStream stream) throws DeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
index f62c6c7..f2da16e 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/DefaultProcessor.java
@@ -56,7 +56,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
public void readServiceDocument(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
- response.setContent(serializer.serviceDocument(serviceMetadata.getEdm(), null));
+ response.setContent(serializer.serviceDocument(serviceMetadata.getEdm(), null).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
@@ -65,7 +65,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
public void readMetadata(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
final ContentType requestedContentType) throws ODataApplicationException, SerializerException {
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
- response.setContent(serializer.metadataDocument(serviceMetadata));
+ response.setContent(serializer.metadataDocument(serviceMetadata).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
@@ -75,7 +75,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
ContentType requestedContentType) {
try {
ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
- response.setContent(serializer.error(serverError));
+ response.setContent(serializer.error(serverError).getContent());
response.setStatusCode(serverError.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index 55377ce..01db1a4 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -41,20 +41,20 @@ public interface ODataSerializer {
* @param edm the Entity Data Model
* @param serviceRoot the service-root URI of this OData service
*/
- InputStream serviceDocument(Edm edm, String serviceRoot) throws SerializerException;
+ SerializerResult serviceDocument(Edm edm, String serviceRoot) throws SerializerException;
/**
* Writes the metadata document into an InputStream.
* @param serviceMetadata the metadata information for the service
*/
- InputStream metadataDocument(ServiceMetadata serviceMetadata) throws SerializerException;
+ SerializerResult metadataDocument(ServiceMetadata serviceMetadata) throws SerializerException;
/**
* Writes an ODataError into an InputStream.
* @param error the main error
* @return inputStream containing the OData-formatted error
*/
- InputStream error(ODataServerError error) throws SerializerException;
+ SerializerResult error(ODataServerError error) throws SerializerException;
/**
* Writes entity-collection data into an InputStream.
@@ -63,7 +63,7 @@ public interface ODataSerializer {
* @param entitySet the data of the entity set
* @param options options for the serializer
*/
- InputStream entityCollection(ServiceMetadata metadata, EdmEntityType entityType,
+ SerializerResult entityCollection(ServiceMetadata metadata, EdmEntityType entityType,
EntitySet entitySet, EntityCollectionSerializerOptions options) throws SerializerException;
/**
@@ -73,7 +73,7 @@ public interface ODataSerializer {
* @param entity the data of the entity
* @param options options for the serializer
*/
- InputStream entity(ServiceMetadata metadata, EdmEntityType entityType, Entity entity,
+ SerializerResult entity(ServiceMetadata metadata, EdmEntityType entityType, Entity entity,
EntitySerializerOptions options) throws SerializerException;
/**
@@ -82,7 +82,7 @@ public interface ODataSerializer {
* @param property property value
* @param options options for the serializer
*/
- InputStream primitive(EdmPrimitiveType type, Property property, PrimitiveSerializerOptions options)
+ SerializerResult primitive(EdmPrimitiveType type, Property property, PrimitiveSerializerOptions options)
throws SerializerException;
/**
@@ -92,7 +92,7 @@ public interface ODataSerializer {
* @param property property value
* @param options options for the serializer
*/
- InputStream complex(ServiceMetadata metadata, EdmComplexType type, Property property,
+ SerializerResult complex(ServiceMetadata metadata, EdmComplexType type, Property property,
ComplexSerializerOptions options) throws SerializerException;
/**
@@ -101,7 +101,7 @@ public interface ODataSerializer {
* @param property property value
* @param options options for the serializer
*/
- InputStream primitiveCollection(EdmPrimitiveType type, Property property, PrimitiveSerializerOptions options)
+ SerializerResult primitiveCollection(EdmPrimitiveType type, Property property, PrimitiveSerializerOptions options)
throws SerializerException;
/**
@@ -111,6 +111,6 @@ public interface ODataSerializer {
* @param property property value
* @param options options for the serializer
*/
- InputStream complexCollection(ServiceMetadata metadata, EdmComplexType type, Property property,
+ SerializerResult complexCollection(ServiceMetadata metadata, EdmComplexType type, Property property,
ComplexSerializerOptions options) throws SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
new file mode 100644
index 0000000..5249bb4
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
@@ -0,0 +1,32 @@
+/*
+ * 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.serializer;
+
+import java.io.InputStream;
+
+/**
+* Result type for {@link ODataSerializer} methods
+ */
+public interface SerializerResult {
+ /**
+ * Returns the serialized content
+ * @return serialized content
+ */
+ InputStream getContent();
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
index 199c62d..b83d383 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
@@ -108,7 +108,7 @@ public class ErrorHandler {
try {
ODataSerializer serializer = this.odata.createSerializer(ODataFormat
.fromContentType(requestedContentType));
- response.setContent(serializer.error(serverError));
+ response.setContent(serializer.error(serverError).getContent());
response.setStatusCode(serverError.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
index 32bf26a..cebaf64 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
@@ -315,7 +315,7 @@ public class DataRequest extends ServiceRequest {
private Entity getEntityFromClient() throws DeserializerException {
ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
.fromContentType(getRequestContentType()));
- return deserializer.entity(getODataRequest().getBody(), getEntitySet().getEntityType());
+ return deserializer.entity(getODataRequest().getBody(), getEntitySet().getEntityType()).getEntity();
}
@Override
@@ -431,7 +431,7 @@ public class DataRequest extends ServiceRequest {
private List<URI> getPayload() throws DeserializerException {
ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
.fromContentType(getRequestContentType()));
- return deserializer.entityReferences(getODataRequest().getBody());
+ return deserializer.entityReferences(getODataRequest().getBody()).getEntityReferences();
}
@Override
@@ -664,7 +664,7 @@ public class DataRequest extends ServiceRequest {
// for now it is responsibility of the user
ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
.fromContentType(getRequestContentType()));
- return deserializer.property(getODataRequest().getBody(), edmProperty);
+ return deserializer.property(getODataRequest().getBody(), edmProperty).getProperty();
}
static ContextURL.Builder buildEntitySetContextURL(UriHelper helper,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
index fd29bbd..e90681d 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
@@ -82,7 +82,7 @@ public class EntityResponse extends ServiceResponse {
}
// write the entity to response
- this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options));
+ this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options).getContent());
writeOK(this.responseContentType.toContentTypeString());
close();
}
@@ -107,7 +107,7 @@ public class EntityResponse extends ServiceResponse {
}
// return the content of the created entity
- this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options));
+ this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options).getContent());
writeCreated(false);
writeHeader(HttpHeader.LOCATION, locationHeader);
writeHeader("Preference-Applied", "return=representation"); //$NON-NLS-1$ //$NON-NLS-2$
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
index 40276d2..c70854b 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
@@ -69,7 +69,8 @@ public class EntitySetResponse extends ServiceResponse {
}
// write the whole collection to response
- this.response.setContent(this.serializer.entityCollection(metadata, entityType, entitySet, this.options));
+ this.response.setContent(this.serializer.entityCollection(metadata, entityType, entitySet, this.options)
+ .getContent());
writeOK(this.responseContentType.toContentTypeString());
close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
index 055c0b0..b325421 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
@@ -49,7 +49,7 @@ public class MetadataResponse extends ServiceResponse {
public void writeMetadata()throws ODataTranslatedException {
assert (!isClosed());
- this.response.setContent(this.serializer.metadataDocument(this.metadata));
+ this.response.setContent(this.serializer.metadataDocument(this.metadata).getContent());
writeOK(this.responseContentType.toContentTypeString());
close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
index e6b951d..79ac90d 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
@@ -106,10 +106,10 @@ public class PropertyResponse extends ServiceResponse {
throws SerializerException {
if (this.collection) {
this.response.setContent(this.serializer.complexCollection(this.metadata, type, property,
- this.complexOptions));
+ this.complexOptions).getContent());
} else {
this.response.setContent(this.serializer.complex(this.metadata, type, property,
- this.complexOptions));
+ this.complexOptions).getContent());
}
writeOK(this.responseContentType.toContentTypeString());
close();
@@ -118,9 +118,9 @@ public class PropertyResponse extends ServiceResponse {
private void writePrimitiveProperty(EdmPrimitiveType type, Property property)
throws SerializerException {
if(this.collection) {
- this.response.setContent(this.serializer.primitiveCollection(type, property, this.primitiveOptions));
+ this.response.setContent(this.serializer.primitiveCollection(type, property, this.primitiveOptions).getContent());
} else {
- this.response.setContent(this.serializer.primitive(type, property, this.primitiveOptions));
+ this.response.setContent(this.serializer.primitive(type, property, this.primitiveOptions).getContent());
}
writeOK(this.responseContentType.toContentTypeString());
close();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
index 86c420b..8b77684 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
@@ -50,7 +50,7 @@ public class ServiceDocumentResponse extends ServiceResponse {
public void writeServiceDocument(String serviceRoot)
throws ODataTranslatedException {
assert (!isClosed());
- this.response.setContent(this.serializer.serviceDocument(this.metadata.getEdm(), serviceRoot));
+ this.response.setContent(this.serializer.serviceDocument(this.metadata.getEdm(), serviceRoot).getContent());
writeOK(this.responseContentType.toContentTypeString());
close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
index 904f4d8..055f073 100644
--- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
@@ -124,7 +124,7 @@ public class TripPinDataModel {
ODataJsonDeserializer deserializer = new ODataJsonDeserializer();
EntitySet set = deserializer.entityCollection(new FileInputStream(new File(
- "src/test/resources/" + entitySetName.toLowerCase() + ".json")), type);
+ "src/test/resources/" + entitySetName.toLowerCase() + ".json")), type).getEntityCollection();
// TODO: the count needs to be part of deserializer
set.setCount(set.getEntities().size());
for (Entity entity : set.getEntities()) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/DeserializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/DeserializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/DeserializerResultImpl.java
new file mode 100644
index 0000000..84d64ea
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/DeserializerResultImpl.java
@@ -0,0 +1,126 @@
+/*
+ * 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.deserializer;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Parameter;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.server.api.deserializer.DeserializerResult;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+
+public class DeserializerResultImpl implements DeserializerResult {
+ private Entity entity;
+ private EntitySet entitySet;
+ private ExpandOption expandOption;
+ private Property property;
+ private List<Parameter> actionParametes;
+ private List<URI> entityReferences;
+
+ private DeserializerResultImpl() {}
+
+ @Override
+ public Entity getEntity() {
+ return entity;
+ }
+
+ @Override
+ public EntitySet getEntityCollection() {
+ return entitySet;
+ }
+
+ @Override
+ public ExpandOption getExpandTree() {
+ return expandOption;
+ }
+
+ @Override
+ public List<Parameter> getActionParameter() {
+ return actionParametes;
+ }
+
+ @Override
+ public Property getProperty() {
+ return property;
+ }
+
+ @Override
+ public List<URI> getEntityReferences() {
+ return entityReferences;
+ }
+
+ public static DeserializerResultBuilder with() {
+ return new DeserializerResultBuilder();
+ }
+
+ public static class DeserializerResultBuilder {
+ private Entity entity;
+ private EntitySet entitySet;
+ private ExpandOption expandOption;
+ private Property property;
+ private List<Parameter> actionParametes;
+ private List<URI> entityReferences;
+
+ public DeserializerResult build() {
+ DeserializerResultImpl result = new DeserializerResultImpl();
+ result.entity = entity;
+ result.entitySet = entitySet;
+ result.expandOption = expandOption;
+ result.property = property;
+ result.entityReferences = (entityReferences == null) ? new ArrayList<URI>() : entityReferences;
+ result.actionParametes = (actionParametes == null) ? new ArrayList<Parameter>() : actionParametes;
+
+ return result;
+ }
+
+ public DeserializerResultBuilder entity(final Entity entity) {
+ this.entity = entity;
+ return this;
+ }
+
+ public DeserializerResultBuilder entityCollection(final EntitySet entitySet) {
+ this.entitySet = entitySet;
+ return this;
+ }
+
+ public DeserializerResultBuilder expandOption(final ExpandOption expandOption) {
+ this.expandOption = expandOption;
+ return this;
+ }
+
+ public DeserializerResultBuilder property(final Property property) {
+ this.property = property;
+ return this;
+ }
+
+ public DeserializerResultBuilder entityReferences(final List<URI> entityReferences) {
+ this.entityReferences = entityReferences;
+ return this;
+ }
+
+ public DeserializerResultBuilder actionParameters(final List<Parameter> actionParameters) {
+ this.actionParametes = actionParameters;
+ return this;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilder.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilder.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilder.java
new file mode 100644
index 0000000..5e279bd
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilder.java
@@ -0,0 +1,40 @@
+/*
+ * 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.deserializer.helper;
+
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.server.core.uri.UriInfoImpl;
+import org.apache.olingo.server.core.uri.UriResourceNavigationPropertyImpl;
+import org.apache.olingo.server.core.uri.queryoption.ExpandItemImpl;
+
+public abstract class ExpandTreeBuilder {
+ public abstract ExpandTreeBuilder expand(EdmNavigationProperty edmNavigationProperty);
+
+ protected ExpandItemImpl buildExpandItem(final EdmNavigationProperty edmNavigationProperty) {
+ final ExpandItemImpl expandItem = new ExpandItemImpl();
+ final UriInfoImpl uriInfo = new UriInfoImpl();
+ final UriResourceNavigationPropertyImpl resourceNavigation = new UriResourceNavigationPropertyImpl();
+
+ resourceNavigation.setNavigationProperty(edmNavigationProperty);
+ uriInfo.addResourcePart(resourceNavigation);
+ expandItem.setResourcePath(uriInfo);
+
+ return expandItem;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilderImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilderImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilderImpl.java
new file mode 100644
index 0000000..4161af1
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/helper/ExpandTreeBuilderImpl.java
@@ -0,0 +1,67 @@
+/*
+ * 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.deserializer.helper;
+
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.server.core.uri.queryoption.ExpandItemImpl;
+import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
+
+public class ExpandTreeBuilderImpl extends ExpandTreeBuilder {
+
+ private ExpandOptionImpl expandOption = null;
+
+ @Override
+ public ExpandTreeBuilder expand(EdmNavigationProperty edmNavigationProperty) {
+ ExpandItemImpl expandItem = buildExpandItem(edmNavigationProperty);
+
+ if(expandOption == null) {
+ expandOption = new ExpandOptionImpl();
+ }
+ expandOption.addExpandItem(expandItem);
+
+ return new ExpandTreeBuilderInner(expandItem);
+ }
+
+ public ExpandOption build() {
+ return expandOption;
+ }
+
+ private class ExpandTreeBuilderInner extends ExpandTreeBuilder {
+ private ExpandItemImpl parent;
+
+ public ExpandTreeBuilderInner(ExpandItemImpl expandItem) {
+ parent = expandItem;
+ }
+
+ @Override
+ public ExpandTreeBuilder expand(EdmNavigationProperty edmNavigationProperty) {
+ if(parent.getExpandOption() == null) {
+ final ExpandOptionImpl expandOption = new ExpandOptionImpl();
+ parent.setSystemQueryOption(expandOption);
+ }
+
+ final ExpandItemImpl expandItem = buildExpandItem(edmNavigationProperty);
+ ((ExpandOptionImpl)parent.getExpandOption()).addExpandItem(expandItem);
+
+ return new ExpandTreeBuilderInner(expandItem);
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index 8d2701e..538e95c 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -57,7 +57,11 @@ import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.commons.core.data.ParameterImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.deserializer.DeserializerResult;
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
+import org.apache.olingo.server.core.deserializer.DeserializerResultImpl;
+import org.apache.olingo.server.core.deserializer.helper.ExpandTreeBuilder;
+import org.apache.olingo.server.core.deserializer.helper.ExpandTreeBuilderImpl;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
@@ -76,11 +80,13 @@ public class ODataJsonDeserializer implements ODataDeserializer {
private static final String ODATA_CONTROL_INFORMATION_PREFIX = "@odata.";
@Override
- public EntitySet entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException {
+ public DeserializerResult entityCollection(InputStream stream, EdmEntityType edmEntityType)
+ throws DeserializerException {
try {
final ObjectNode tree = parseJsonTree(stream);
-
- return consumeEntitySetNode(edmEntityType, tree);
+
+ return DeserializerResultImpl.with().entityCollection(consumeEntitySetNode(edmEntityType, tree, null))
+ .build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
@@ -92,8 +98,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
}
- private EntitySet consumeEntitySetNode(EdmEntityType edmEntityType, final ObjectNode tree)
- throws DeserializerException {
+ private EntitySet consumeEntitySetNode(EdmEntityType edmEntityType, final ObjectNode tree,
+ final ExpandTreeBuilder expandBuilder) throws DeserializerException {
EntitySetImpl entitySet = new EntitySetImpl();
// Consume entities
@@ -104,7 +110,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
}
- entitySet.getEntities().addAll(consumeEntitySetArray(edmEntityType, jsonNode));
+ entitySet.getEntities().addAll(consumeEntitySetArray(edmEntityType, jsonNode, expandBuilder));
tree.remove(Constants.VALUE);
} else {
throw new DeserializerException("Could not find value array.",
@@ -131,8 +137,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
return entitySet;
}
- private List<Entity> consumeEntitySetArray(EdmEntityType edmEntityType, JsonNode jsonNode)
- throws DeserializerException {
+ private List<Entity> consumeEntitySetArray(EdmEntityType edmEntityType, JsonNode jsonNode,
+ final ExpandTreeBuilder expandBuilder) throws DeserializerException {
List<Entity> entities = new ArrayList<Entity>();
for (JsonNode arrayElement : jsonNode) {
if (arrayElement.isArray() || arrayElement.isValueNode()) {
@@ -140,17 +146,20 @@ public class ODataJsonDeserializer implements ODataDeserializer {
DeserializerException.MessageKeys.INVALID_ENTITY);
}
- entities.add(consumeEntityNode(edmEntityType, (ObjectNode) arrayElement));
+ entities.add(consumeEntityNode(edmEntityType, (ObjectNode) arrayElement, expandBuilder));
}
return entities;
}
@Override
- public Entity entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException {
+ public DeserializerResult entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException {
try {
final ObjectNode tree = parseJsonTree(stream);
-
- return consumeEntityNode(edmEntityType, tree);
+ final ExpandTreeBuilderImpl expandBuilder = new ExpandTreeBuilderImpl();
+
+ return DeserializerResultImpl.with().entity(consumeEntityNode(edmEntityType, tree, expandBuilder))
+ .expandOption(expandBuilder.build())
+ .build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
@@ -164,7 +173,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
- private Entity consumeEntityNode(EdmEntityType edmEntityType, final ObjectNode tree) throws DeserializerException {
+ private Entity consumeEntityNode(EdmEntityType edmEntityType, final ObjectNode tree,
+ final ExpandTreeBuilder expandBuilder) throws DeserializerException {
EntityImpl entity = new EntityImpl();
entity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
@@ -172,7 +182,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
consumeEntityProperties(edmEntityType, tree, entity);
// Check and consume all expanded Navigation Properties
- consumeExpandedNavigationProperties(edmEntityType, tree, entity);
+ consumeExpandedNavigationProperties(edmEntityType, tree, entity, expandBuilder);
// consume remaining json node fields
consumeRemainingJsonNodeFields(edmEntityType, tree, entity);
@@ -183,13 +193,14 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
@Override
- public List<Parameter> actionParameters(InputStream stream, final EdmAction edmAction) throws DeserializerException {
+ public DeserializerResult actionParameters(InputStream stream, final EdmAction edmAction)
+ throws DeserializerException {
try {
ObjectNode tree = parseJsonTree(stream);
List<Parameter> parameters = new ArrayList<Parameter>();
consumeParameters(edmAction, tree, parameters);
assertJsonNodeIsEmpty(tree);
- return parameters;
+ return DeserializerResultImpl.with().actionParameters(parameters).build();
} catch (final JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
@@ -203,7 +214,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
}
- private ObjectNode parseJsonTree(InputStream stream) throws IOException, JsonParseException, JsonProcessingException {
+ private ObjectNode parseJsonTree(InputStream stream)
+ throws IOException, JsonParseException, JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
@@ -314,7 +326,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
private void consumeExpandedNavigationProperties(final EdmEntityType edmEntityType, final ObjectNode node,
- final EntityImpl entity) throws DeserializerException {
+ final EntityImpl entity, final ExpandTreeBuilder expandBuilder) throws DeserializerException {
List<String> navigationPropertyNames = edmEntityType.getNavigationPropertyNames();
for (String navigationPropertyName : navigationPropertyNames) {
// read expanded navigation property
@@ -329,16 +341,20 @@ public class ODataJsonDeserializer implements ODataDeserializer {
LinkImpl link = new LinkImpl();
link.setTitle(navigationPropertyName);
+ final ExpandTreeBuilder childExpandBuilder = (expandBuilder != null) ?
+ expandBuilder.expand(edmNavigationProperty) : null;
if (jsonNode.isArray() && edmNavigationProperty.isCollection()) {
link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString());
EntitySetImpl inlineEntitySet = new EntitySetImpl();
- inlineEntitySet.getEntities().addAll(consumeEntitySetArray(edmNavigationProperty.getType(), jsonNode));
+ inlineEntitySet.getEntities().addAll(consumeEntitySetArray(edmNavigationProperty.getType(), jsonNode,
+ childExpandBuilder));
link.setInlineEntitySet(inlineEntitySet);
} else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull())
&& !edmNavigationProperty.isCollection()) {
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
if (!jsonNode.isNull()) {
- Entity inlineEntity = consumeEntityNode(edmNavigationProperty.getType(), (ObjectNode) jsonNode);
+ Entity inlineEntity = consumeEntityNode(edmNavigationProperty.getType(), (ObjectNode) jsonNode,
+ childExpandBuilder);
link.setInlineEntity(inlineEntity);
}
} else {
@@ -732,7 +748,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
@Override
- public Property property(InputStream stream, EdmProperty edmProperty)
+ public DeserializerResult property(InputStream stream, EdmProperty edmProperty)
throws DeserializerException {
try {
ObjectMapper objectMapper = new ObjectMapper();
@@ -756,7 +772,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
edmProperty.isUnicode(), edmProperty.getMapping(),
tree);
}
- return property;
+ return DeserializerResultImpl.with().property(property).build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
@@ -768,7 +784,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
}
- public List<URI> entityReferences(InputStream stream) throws DeserializerException {
+ public DeserializerResult entityReferences(InputStream stream) throws DeserializerException {
try {
ArrayList<URI> parsedValues = new ArrayList<URI>();
ObjectMapper objectMapper = new ObjectMapper();
@@ -789,10 +805,10 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
tree.remove(Constants.VALUE);
// if this is value there can be only one property
- return parsedValues;
+ return DeserializerResultImpl.with().entityReferences(parsedValues).build();
}
parsedValues.add(new URI(tree.get(key).asText()));
- return parsedValues;
+ return DeserializerResultImpl.with().entityReferences(parsedValues).build();
} catch (JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
new file mode 100644
index 0000000..b7b16a2
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -0,0 +1,53 @@
+/*
+ * 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.serializer;
+
+import java.io.InputStream;
+
+import org.apache.olingo.server.api.serializer.SerializerResult;
+
+public class SerializerResultImpl implements SerializerResult {
+ private InputStream content;
+
+ @Override
+ public InputStream getContent() {
+ return content;
+ }
+
+ public static SerializerResultBuilder with() {
+ return new SerializerResultBuilder();
+ }
+
+ public static class SerializerResultBuilder {
+ private InputStream content;
+
+ public SerializerResultBuilder content(final InputStream input) {
+ content = input;
+
+ return this;
+ }
+
+ public SerializerResult build() {
+ SerializerResultImpl result = new SerializerResultImpl();
+ result.content = content;
+
+ return result;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index a7ce16b..c9944c7 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -19,7 +19,6 @@
package org.apache.olingo.server.core.serializer.json;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -52,9 +51,11 @@ import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.serializer.SerializerResult;
import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
+import org.apache.olingo.server.core.serializer.SerializerResultImpl;
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder;
import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
@@ -76,7 +77,7 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
+ public SerializerResult serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
CircleStreamBuffer buffer;
JsonGenerator gen = null;
@@ -89,7 +90,7 @@ public class ODataJsonSerializer implements ODataSerializer {
gen.close();
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final IOException e) {
log.error(e.getMessage(), e);
@@ -108,13 +109,13 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
+ public SerializerResult metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
throw new SerializerException("Metadata in JSON format not supported!",
SerializerException.MessageKeys.JSON_METADATA);
}
@Override
- public InputStream error(final ODataServerError error) throws SerializerException {
+ public SerializerResult error(final ODataServerError error) throws SerializerException {
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
@@ -124,11 +125,11 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream entityCollection(final ServiceMetadata metadata,
+ public SerializerResult entityCollection(final ServiceMetadata metadata,
final EdmEntityType entityType, final EntitySet entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -161,11 +162,11 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream entity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ public SerializerResult entity(final ServiceMetadata metadata, final EdmEntityType entityType,
final Entity entity, final EntitySerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -180,7 +181,7 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
private ContextURL checkContextURL(final ContextURL contextURL) throws SerializerException {
@@ -515,7 +516,7 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream primitive(final EdmPrimitiveType type, final Property property,
+ public SerializerResult primitive(final EdmPrimitiveType type, final Property property,
final PrimitiveSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -544,11 +545,11 @@ public class ODataJsonSerializer implements ODataSerializer {
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
property.getName(), property.getValue().toString());
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream complex(final ServiceMetadata metadata, final EdmComplexType type,
+ public SerializerResult complex(final ServiceMetadata metadata, final EdmComplexType type,
final Property property, final ComplexSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -575,11 +576,11 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream primitiveCollection(final EdmPrimitiveType type, final Property property,
+ public SerializerResult primitiveCollection(final EdmPrimitiveType type, final Property property,
final PrimitiveSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -604,11 +605,11 @@ public class ODataJsonSerializer implements ODataSerializer {
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
property.getName(), property.getValue().toString());
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
@Override
- public InputStream complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
+ public SerializerResult complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
final Property property, final ComplexSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -630,6 +631,6 @@ public class ODataJsonSerializer implements ODataSerializer {
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE,
property.getName(), property.getValue().toString());
}
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
index 34756c1..6143727 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
@@ -18,8 +18,6 @@
*/
package org.apache.olingo.server.core.serializer.xml;
-import java.io.InputStream;
-
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
@@ -39,6 +37,8 @@ import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.core.serializer.SerializerResultImpl;
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,13 +51,13 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
private static final Logger log = LoggerFactory.getLogger(ODataXmlSerializerImpl.class);
@Override
- public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
+ public SerializerResultImpl serviceDocument(final Edm edm, final String serviceRoot) throws SerializerException {
throw new SerializerException("Service Document not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
+ public SerializerResult metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
CircleStreamBuffer buffer;
XMLStreamWriter xmlStreamWriter = null;
@@ -69,7 +69,7 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
xmlStreamWriter.flush();
xmlStreamWriter.close();
- return buffer.getInputStream();
+ return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
log.error(e.getMessage(), e);
throw new SerializerException("An I/O exception occurred.", e,
@@ -87,14 +87,14 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream entity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ public SerializerResult entity(final ServiceMetadata metadata, final EdmEntityType entityType,
final Entity entity, final EntitySerializerOptions options) throws SerializerException {
throw new SerializerException("Entity serialization not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream entityCollection(final ServiceMetadata metadata,
+ public SerializerResult entityCollection(final ServiceMetadata metadata,
final EdmEntityType entityType, final EntitySet entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
throw new SerializerException("Entityset serialization not implemented for XML format",
@@ -102,34 +102,34 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream error(ODataServerError error) throws SerializerException {
+ public SerializerResult error(ODataServerError error) throws SerializerException {
throw new SerializerException("error serialization not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream primitive(final EdmPrimitiveType type, final Property property,
+ public SerializerResult primitive(final EdmPrimitiveType type, final Property property,
final PrimitiveSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream complex(final ServiceMetadata metadata, final EdmComplexType type,
+ public SerializerResult complex(final ServiceMetadata metadata, final EdmComplexType type,
final Property property, final ComplexSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream primitiveCollection(final EdmPrimitiveType type, final Property property,
+ public SerializerResult primitiveCollection(final EdmPrimitiveType type, final Property property,
final PrimitiveSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
+ public SerializerResult complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
final Property property, final ComplexSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
index a301c3d..b63181d 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
@@ -57,7 +57,8 @@ public class ODataJsonDeserializerBasicTest {
" ]\n" +
"}";
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
- List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()));
+ List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
+ .getEntityReferences();
assertEquals(2, values.size());
assertEquals("Orders(10643)", values.get(0).toASCIIString());
assertEquals("Orders(10759)", values.get(1).toASCIIString());
@@ -71,7 +72,7 @@ public class ODataJsonDeserializerBasicTest {
"}";
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload
- .getBytes()));
+ .getBytes())).getEntityReferences();
assertEquals(1, values.size());
assertEquals("Orders(10643)", values.get(0).toASCIIString());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
index 4e44db4..de5a25e 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java
@@ -52,7 +52,7 @@ public class ODataErrorSerializerTest {
public void basicODataErrorNoCode() throws Exception {
ODataServerError error = new ODataServerError();
error.setMessage("ErrorMessage");
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\"}}", jsonString);
}
@@ -61,7 +61,7 @@ public class ODataErrorSerializerTest {
public void basicODataErrorWithCode() throws Exception {
ODataServerError error = new ODataServerError();
error.setCode("Code").setMessage("ErrorMessage");
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\"}}", jsonString);
}
@@ -70,7 +70,7 @@ public class ODataErrorSerializerTest {
public void basicODataErrorWithCodeAndTarget() throws Exception {
ODataServerError error = new ODataServerError();
error.setCode("Code").setMessage("ErrorMessage").setTarget("Target");
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\",\"target\":\"Target\"}}", jsonString);
}
@@ -84,7 +84,7 @@ public class ODataErrorSerializerTest {
public void emptyDetailsList() throws Exception {
ODataServerError error = new ODataServerError();
error.setMessage("ErrorMessage").setDetails(new ArrayList<ODataErrorDetail>());
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\",\"details\":[]}}", jsonString);
}
@@ -92,7 +92,7 @@ public class ODataErrorSerializerTest {
@Test
public void nothingSetAtODataErrorObject() throws Exception {
ODataServerError error = new ODataServerError();
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":null,\"message\":null}}", jsonString);
}
@@ -102,7 +102,7 @@ public class ODataErrorSerializerTest {
List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>();
details.add(new ODataErrorDetail());
ODataServerError error = new ODataServerError().setDetails(details);
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
String jsonString = IOUtils.toString(stream);
assertEquals("{\"error\":{\"code\":null,\"message\":null,\"details\":[{\"code\":null,\"message\":null}]}}",
jsonString);
@@ -114,7 +114,7 @@ public class ODataErrorSerializerTest {
details.add(new ODataErrorDetail().setCode("detailCode").setMessage("detailMessage").setTarget("detailTarget"));
ODataServerError error =
new ODataServerError().setCode("Code").setMessage("Message").setTarget("Target").setDetails(details);
- InputStream stream = ser.error(error);
+ InputStream stream = ser.error(error).getContent();
JsonNode tree = new ObjectMapper().readTree(stream);
assertNotNull(tree);
tree = tree.get("error");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 1e4537f..1fc89e8 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -50,7 +50,7 @@ public class ODataJsonSerializerTest {
final ComplexSerializerOptions options = ComplexSerializerOptions.with()
.contextURL(ContextURL.with().selectList("ComplexCollection").build()).build();
final InputStream in = serializer.complexCollection(null, ComplexTypeHelper.createType(),
- complexCollection, options);
+ complexCollection, options).getContent();
final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
index d092ae9..a7bd86e 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
@@ -88,7 +88,7 @@ public class MetadataDocumentXmlSerializerTest {
assertEquals("<?xml version='1.0' encoding='UTF-8'?>"
+ "<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">"
+ "<edmx:DataServices/></edmx:Edmx>",
- IOUtils.toString(serializer.metadataDocument(metadata)));
+ IOUtils.toString(serializer.metadataDocument(metadata).getContent()));
}
/** Writes simplest (empty) Schema. */
@@ -101,7 +101,7 @@ public class MetadataDocumentXmlSerializerTest {
ServiceMetadata serviceMetadata = mock(ServiceMetadata.class);
when(serviceMetadata.getEdm()).thenReturn(edm);
- InputStream metadata = serializer.metadataDocument(serviceMetadata);
+ InputStream metadata = serializer.metadataDocument(serviceMetadata).getContent();
assertNotNull(metadata);
assertEquals("<?xml version='1.0' encoding='UTF-8'?>" +
"<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" +
@@ -167,7 +167,7 @@ public class MetadataDocumentXmlSerializerTest {
when(serviceMetadata.getEdm()).thenReturn(edm);
when(serviceMetadata.getReferences()).thenReturn(edmxReferences);
- InputStream metadata = serializer.metadataDocument(serviceMetadata);
+ InputStream metadata = serializer.metadataDocument(serviceMetadata).getContent();
assertNotNull(metadata);
final String metadataString = IOUtils.toString(metadata);
// edmx reference
@@ -214,7 +214,7 @@ public class MetadataDocumentXmlSerializerTest {
public void aliasTest() throws Exception {
EdmProvider provider = new LocalProvider();
ServiceMetadata serviceMetadata = new ServiceMetadataImpl(provider, Collections.<EdmxReference> emptyList());
- InputStream metadataStream = serializer.metadataDocument(serviceMetadata);
+ InputStream metadataStream = serializer.metadataDocument(serviceMetadata).getContent();
String metadata = IOUtils.toString(metadataStream);
assertNotNull(metadata);
@@ -255,7 +255,7 @@ public class MetadataDocumentXmlSerializerTest {
when(schema.getComplexTypes()).thenReturn(complexTypes);
- InputStream metadataStream = serializer.metadataDocument(serviceMetadata);
+ InputStream metadataStream = serializer.metadataDocument(serviceMetadata).getContent();
String metadata = IOUtils.toString(metadataStream);
assertTrue(metadata.contains("<ComplexType Name=\"ComplexType\" Abstract=\"true\">"
+ "<Property Name=\"prop1\" Type=\"Edm.String\"/>"
[09/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Edm cleanup:
Remove EdmAnnotationHelperImpl
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
deleted file mode 100644
index 014184d..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * 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.provider;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmElement;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.EdmType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.api.edm.provider.NavigationProperty;
-import org.apache.olingo.commons.api.edm.provider.Property;
-import org.apache.olingo.commons.api.edm.provider.StructuralType;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public abstract class EdmStructuredTypeImpl extends EdmTypeImpl implements EdmStructuredType {
-
- protected EdmStructuredType baseType;
- protected FullQualifiedName baseTypeName;
-
- private List<String> propertyNames;
- private List<String> navigationPropertyNames;
- private Map<String, EdmProperty> properties;
- private Map<String, EdmNavigationProperty> navigationProperties;
- private final StructuralType structuredType;
-
- public EdmStructuredTypeImpl(
- final Edm edm,
- final FullQualifiedName typeName,
- final EdmTypeKind kind,
- final StructuralType structuredType) {
-
- super(edm, typeName, kind);
- this.baseTypeName = structuredType.getBaseTypeFQN();
- this.structuredType = structuredType;
- }
-
- protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName);
-
- protected abstract void checkBaseType();
-
- @Override
- public List<String> getPropertyNames() {
- if (propertyNames == null) {
- propertyNames = new ArrayList<String>();
- checkBaseType();
- if (baseType != null) {
- propertyNames.addAll(baseType.getPropertyNames());
- }
- propertyNames.addAll(getProperties().keySet());
- }
- return propertyNames;
- }
-
- @Override
- public List<String> getNavigationPropertyNames() {
- if (navigationPropertyNames == null) {
- navigationPropertyNames = new ArrayList<String>();
- checkBaseType();
- if (baseType != null) {
- navigationPropertyNames.addAll(baseType.getNavigationPropertyNames());
- }
- navigationPropertyNames.addAll(getNavigationProperties().keySet());
- }
- return navigationPropertyNames;
- }
-
- @Override
- public EdmElement getProperty(final String name) {
- EdmElement property = getStructuralProperty(name);
- if (property == null) {
- property = getNavigationProperty(name);
- }
- return property;
- }
-
- @Override
- public EdmProperty getStructuralProperty(final String name) {
- EdmProperty property = null;
- checkBaseType();
- if (baseType != null) {
- property = baseType.getStructuralProperty(name);
- }
- if (property == null) {
- property = getProperties().get(name);
- }
- return property;
- }
-
- @Override
- public EdmNavigationProperty getNavigationProperty(final String name) {
- EdmNavigationProperty property = null;
- checkBaseType();
- if (baseType != null) {
- property = baseType.getNavigationProperty(name);
- }
- if (property == null) {
- property = getNavigationProperties().get(name);
- }
- return property;
- }
-
- @Override
- public boolean compatibleTo(final EdmType targetType) {
- EdmStructuredType sourceType = this;
- if (targetType == null) {
- throw new EdmException("Target type must not be null");
- }
- while (!sourceType.getName().equals(targetType.getName())
- || !sourceType.getNamespace().equals(targetType.getNamespace())) {
-
- sourceType = sourceType.getBaseType();
- if (sourceType == null) {
- return false;
- }
- }
-
- return true;
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return null;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return getFullQualifiedName();
- }
-
- public Map<String, EdmProperty> getProperties() {
- if (properties == null) {
- properties = new LinkedHashMap<String, EdmProperty>();
- for (Property property : structuredType.getProperties()) {
- properties.put(property.getName(), new EdmPropertyImpl(edm, typeName, property));
- }
- }
- return properties;
- }
-
- public Map<String, EdmNavigationProperty> getNavigationProperties() {
- if (navigationProperties == null) {
- navigationProperties = new LinkedHashMap<String, EdmNavigationProperty>();
- if (structuredType.getNavigationProperties() != null) {
- for (NavigationProperty navigationProperty : structuredType.getNavigationProperties()) {
- navigationProperties.put(navigationProperty.getName(),
- new EdmNavigationPropertyImpl(edm, typeName, navigationProperty));
- }
- }
- }
- return navigationProperties;
- }
-
- public boolean isOpenType() {
- return structuredType.isOpenType();
- }
-
- public boolean isAbstract() {
- return structuredType.isAbstract();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
index e1f7ce0..146ff7e 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
@@ -23,7 +23,6 @@ import java.util.List;
import org.apache.commons.lang3.ClassUtils;
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.EdmType;
@@ -34,24 +33,22 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class EdmTermImpl extends EdmNamedImpl implements EdmTerm {
+public class EdmTermImpl extends AbstractEdmNamed implements EdmTerm {
private static final Logger LOG = LoggerFactory.getLogger(EdmTermImpl.class);
private final Term term;
private final FullQualifiedName fqn;
private final EdmTypeInfo typeInfo;
- private final EdmAnnotationHelperImpl helper;
private EdmType termType;
private EdmTerm baseTerm;
private List<Class<?>> appliesTo;
public EdmTermImpl(final Edm edm, final String namespace, final Term term) {
- super(edm, term.getName());
+ super(edm, term.getName(), term);
this.term = term;
this.fqn = new FullQualifiedName(namespace, term.getName());
this.typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(term.getType()).build();
- this.helper = new EdmAnnotationHelperImpl(edm, term);
}
@Override
@@ -146,15 +143,4 @@ public class EdmTermImpl extends EdmNamedImpl implements EdmTerm {
public String getAnnotationsTargetPath() {
return null;
}
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
index 6831f07..9c6155f 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
@@ -18,15 +18,11 @@
*/
package org.apache.olingo.commons.core.edm.provider;
-import java.util.List;
-
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
@@ -34,20 +30,17 @@ import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefinition {
+public class EdmTypeDefinitionImpl extends AbstractEdmNamed implements EdmTypeDefinition {
private TypeDefinition typeDefinition;
private FullQualifiedName typeDefinitionName;
private EdmPrimitiveType edmPrimitiveTypeInstance;
- private final EdmAnnotationHelperImpl helper;
public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName,
final TypeDefinition typeDefinition) {
- super(edm, typeDefinitionName.getName());
+ super(edm, typeDefinitionName.getName(), typeDefinition);
this.typeDefinitionName = typeDefinitionName;
this.typeDefinition = typeDefinition;
-
- this.helper = new EdmAnnotationHelperImpl(edm, typeDefinition);
}
@Override
@@ -164,18 +157,7 @@ public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefini
}
@Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
-
- @Override
public String getAnnotationsTargetPath() {
return getName();
}
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
index 337d700..ff3cd65 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
@@ -22,14 +22,16 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.edm.provider.Annotatable;
-public class EdmTypeImpl extends EdmNamedImpl implements EdmType {
+public class EdmTypeImpl extends AbstractEdmNamed implements EdmType {
protected final FullQualifiedName typeName;
protected final EdmTypeKind kind;
- public EdmTypeImpl(final Edm edm, final FullQualifiedName typeName, final EdmTypeKind kind) {
- super(edm, typeName.getName());
+ public EdmTypeImpl(final Edm edm, final FullQualifiedName typeName, final EdmTypeKind kind,
+ final Annotatable annotatable) {
+ super(edm, typeName.getName(), annotatable);
this.typeName = typeName;
this.kind = kind;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeInfo.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeInfo.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeInfo.java
index 768ec00..c11e880 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeInfo.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeInfo.java
@@ -35,9 +35,7 @@ public class EdmTypeInfo {
public static class Builder {
private String typeExpression;
-
private String defaultNamespace;
-
private Edm edm;
public Builder setTypeExpression(final String typeExpression) {
@@ -62,25 +60,15 @@ public class EdmTypeInfo {
}
}
- private final Edm edm;
-
private final boolean collection;
-
private final FullQualifiedName fullQualifiedName;
-
private EdmPrimitiveTypeKind primitiveType;
-
private EdmTypeDefinition typeDefinition;
-
private EdmEnumType enumType;
-
private EdmComplexType complexType;
-
private EdmEntityType entityType;
private EdmTypeInfo(final Edm edm, final String typeExpression) {
- this.edm = edm;
-
String baseType;
final int collStartIdx = typeExpression.indexOf("Collection(");
final int collEndIdx = typeExpression.lastIndexOf(')');
@@ -105,7 +93,6 @@ public class EdmTypeInfo {
if (lastDotIdx == -1) {
namespace = EdmPrimitiveType.EDM_NAMESPACE;
typeName = baseType;
- baseType = new FullQualifiedName(EdmPrimitiveType.EDM_NAMESPACE, baseType).toString();
} else {
namespace = baseType.substring(0, lastDotIdx);
typeName = baseType.substring(lastDotIdx + 1);
@@ -115,9 +102,6 @@ public class EdmTypeInfo {
throw new IllegalArgumentException("Null or empty type name in " + typeExpression);
}
- final StringBuilder exp = new StringBuilder();
- exp.append(baseType);
-
fullQualifiedName = new FullQualifiedName(namespace, typeName);
try {
@@ -125,14 +109,14 @@ public class EdmTypeInfo {
} catch (final IllegalArgumentException e) {
primitiveType = null;
}
- if (primitiveType == null && this.edm != null) {
- typeDefinition = this.edm.getTypeDefinition(fullQualifiedName);
+ if (primitiveType == null && edm != null) {
+ typeDefinition = edm.getTypeDefinition(fullQualifiedName);
if (typeDefinition == null) {
- enumType = this.edm.getEnumType(fullQualifiedName);
+ enumType = edm.getEnumType(fullQualifiedName);
if (enumType == null) {
- complexType = this.edm.getComplexType(fullQualifiedName);
+ complexType = edm.getComplexType(fullQualifiedName);
if (complexType == null) {
- entityType = this.edm.getEntityType(fullQualifiedName);
+ entityType = edm.getEntityType(fullQualifiedName);
}
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/AbstractEdmNamedTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/AbstractEdmNamedTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/AbstractEdmNamedTest.java
new file mode 100644
index 0000000..04f0556
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/AbstractEdmNamedTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.olingo.commons.api.edm.EdmAnnotatable;
+import org.apache.olingo.commons.api.edm.EdmNamed;
+import org.apache.olingo.commons.api.edm.provider.Annotatable;
+import org.apache.olingo.commons.api.edm.provider.Annotation;
+import org.apache.olingo.commons.core.edm.provider.AbstractEdmNamed;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class AbstractEdmNamedTest {
+
+ @Test
+ public void getNameTest() {
+ EdmNamed obj = new EdmNamedImplTester("Name");
+ assertEquals("Name", obj.getName());
+ EdmAnnotatable an = (EdmAnnotatable) obj;
+ assertNotNull(an.getAnnotations().get(0));
+ }
+
+ private class EdmNamedImplTester extends AbstractEdmNamed {
+
+ public EdmNamedImplTester(final String name) {
+ super(null, name, new AnnoTester());
+ }
+ }
+
+ private class AnnoTester implements Annotatable {
+ @Override
+ public List<Annotation> getAnnotations() {
+ Annotation annotation = new Annotation();
+ annotation.setTerm("NS.SimpleTerm");
+ return Arrays.asList(annotation);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java
deleted file mode 100644
index 60897c1..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmNamed;
-import org.apache.olingo.commons.core.edm.provider.EdmNamedImpl;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class EdmNamedImplTest {
-
- @Test
- public void getNameTest() {
- EdmNamed obj = new EdmNamedImplTester("Name");
- assertEquals("Name", obj.getName());
- }
-
- private class EdmNamedImplTester extends EdmNamedImpl {
-
- public EdmNamedImplTester(final String name) {
- super(null, name);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
index 38938fd..ddfd15d 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
@@ -18,13 +18,20 @@
*/
package org.apache.olingo.server.core.edm.provider;
+import org.apache.olingo.commons.api.edm.EdmAnnotatable;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.edm.provider.Annotatable;
+import org.apache.olingo.commons.api.edm.provider.Annotation;
import org.apache.olingo.commons.core.edm.provider.EdmTypeImpl;
import org.junit.Test;
+import java.util.Arrays;
+import java.util.List;
+
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
public class EdmTypeImplTest {
@@ -34,12 +41,22 @@ public class EdmTypeImplTest {
assertEquals("name", type.getName());
assertEquals("namespace", type.getNamespace());
assertEquals(EdmTypeKind.UNDEFINED, type.getKind());
+ EdmAnnotatable an = (EdmAnnotatable) type;
+ assertNotNull(an.getAnnotations().get(0));
}
private class EdmTypeImplTester extends EdmTypeImpl {
public EdmTypeImplTester(final FullQualifiedName name, final EdmTypeKind kind) {
- super(null, name, kind);
+ super(null, name, kind, new AnnoTester());
}
}
+ private class AnnoTester implements Annotatable {
+ @Override
+ public List<Annotation> getAnnotations() {
+ Annotation annotation = new Annotation();
+ annotation.setTerm("NS.SimpleTerm");
+ return Arrays.asList(annotation);
+ }
+ }
}
[26/50] [abbrv] olingo-odata4 git commit: [OLINGO-603] Refactor
action parameter deserialization part 1
Posted by ch...@apache.org.
[OLINGO-603] Refactor action parameter deserialization part 1
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/3e8c5064
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/3e8c5064
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/3e8c5064
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 3e8c50646e12bde57d24bbc783372442df82a40c
Parents: d94edf5
Author: Christian Amend <ch...@apache.org>
Authored: Tue Mar 31 14:42:08 2015 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Tue Mar 31 14:42:08 2015 +0200
----------------------------------------------------------------------
.../olingo/commons/api/data/Parameter.java | 32 +++++++++++
.../olingo/commons/api/data/ValueType.java | 5 +-
.../commons/core/data/AbstractValuable.java | 11 ++++
.../commons/core/data/AnnotationImpl.java | 11 ----
.../olingo/commons/core/data/ParameterImpl.java | 47 ++++++++++++++++
.../olingo/commons/core/data/PropertyImpl.java | 15 +----
.../core/serialization/AtomSerializer.java | 4 ++
.../api/deserializer/ODataDeserializer.java | 6 +-
.../json/ODataJsonDeserializer.java | 58 +++++++++++---------
...ataJsonDeserializerActionParametersTest.java | 33 +++++------
10 files changed, 150 insertions(+), 72 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Parameter.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Parameter.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Parameter.java
new file mode 100644
index 0000000..87058ec
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Parameter.java
@@ -0,0 +1,32 @@
+/*
+ * 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.data;
+
+public interface Parameter extends Valuable {
+
+ /**
+ * @return name of the parameter
+ */
+ String getName();
+
+ boolean isEntity();
+
+ Entity asEntity();
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ValueType.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ValueType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ValueType.java
index 7b6d942..6dc460f 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ValueType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/ValueType.java
@@ -19,11 +19,12 @@
package org.apache.olingo.commons.api.data;
public enum ValueType {
- PRIMITIVE, GEOSPATIAL, ENUM, COMPLEX,
+ PRIMITIVE, GEOSPATIAL, ENUM, COMPLEX, ENTITY,
COLLECTION_PRIMITIVE(PRIMITIVE),
COLLECTION_GEOSPATIAL(GEOSPATIAL),
COLLECTION_ENUM(ENUM),
- COLLECTION_COMPLEX(COMPLEX);
+ COLLECTION_COMPLEX(COMPLEX),
+ COLLECTION_ENTITY(ENTITY);
private final ValueType baseType;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java
index 15a7a03..6a5a96f 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractValuable.java
@@ -37,6 +37,7 @@ public abstract class AbstractValuable implements Valuable, Annotatable {
private ValueType valueType = null;
private Object value = null;
private final List<Annotation> annotations = new ArrayList<Annotation>();
+ private String type;
@Override
public boolean isNull() {
@@ -44,6 +45,16 @@ public abstract class AbstractValuable implements Valuable, Annotatable {
}
@Override
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ @Override
public boolean isPrimitive() {
return valueType == ValueType.PRIMITIVE;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AnnotationImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AnnotationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AnnotationImpl.java
index 6a53ef3..4e9953b 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AnnotationImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AnnotationImpl.java
@@ -23,7 +23,6 @@ import org.apache.olingo.commons.api.data.Annotation;
public class AnnotationImpl extends AbstractValuable implements Annotation {
private String term;
- private String type;
@Override
public String getTerm() {
@@ -34,14 +33,4 @@ public class AnnotationImpl extends AbstractValuable implements Annotation {
public void setTerm(final String term) {
this.term = term;
}
-
- @Override
- public String getType() {
- return type;
- }
-
- @Override
- public void setType(final String type) {
- this.type = type;
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ParameterImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ParameterImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ParameterImpl.java
new file mode 100644
index 0000000..fc2a1a9
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/ParameterImpl.java
@@ -0,0 +1,47 @@
+/*
+ * 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.data;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.Parameter;
+import org.apache.olingo.commons.api.data.ValueType;
+
+public class ParameterImpl extends AbstractValuable implements Parameter {
+
+ String name;
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean isEntity() {
+ return getValueType() == ValueType.ENTITY;
+ }
+
+ @Override
+ public Entity asEntity() {
+ return isEntity() ? (Entity) getValue() : null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java
index 31583e3..7b31da7 100755
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java
@@ -24,13 +24,12 @@ import org.apache.olingo.commons.api.data.ValueType;
public class PropertyImpl extends AbstractValuable implements Property {
private String name;
- private String type;
public PropertyImpl() {}
public PropertyImpl(final String type, final String name) {
this.name = name;
- this.type = type;
+ super.setType(type);
}
public PropertyImpl(String type, String name, ValueType valueType, Object value) {
@@ -49,17 +48,7 @@ public class PropertyImpl extends AbstractValuable implements Property {
}
@Override
- public String getType() {
- return type;
- }
-
- @Override
- public void setType(final String type) {
- this.type = type;
- }
-
- @Override
public boolean isNull() {
- return getValue() == null || "Edm.Null".equals(type);
+ return getValue() == null || "Edm.Null".equals(getType());
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
index b6d9a74..6bd5fbb 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomSerializer.java
@@ -30,6 +30,7 @@ import javax.xml.stream.XMLStreamWriter;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.commons.api.Constants;
+import org.apache.olingo.commons.api.ODataRuntimeException;
import org.apache.olingo.commons.api.data.Annotation;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.ContextURL;
@@ -113,6 +114,9 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
property(writer, property, false);
}
break;
+ case ENTITY:
+ case COLLECTION_ENTITY:
+ throw new ODataRuntimeException("Entities cannot appear in this payload");
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
index d5f7343..b361844 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
@@ -19,9 +19,11 @@
package org.apache.olingo.server.api.deserializer;
import java.io.InputStream;
+import java.util.List;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Parameter;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmEntityType;
@@ -54,8 +56,8 @@ public interface ODataDeserializer {
* Validates: parameter types, no double parameters, correct json types.
* @param stream
* @param edmAction
- * @return deserialized {@link Entity} object
+ * @return deserialized list of {@link Parameter} objects
* @throws DeserializerException
*/
- Entity actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
+ List<Parameter> actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index ed3454c..74c73c8 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -31,6 +31,7 @@ import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Parameter;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ValueType;
import org.apache.olingo.commons.api.domain.ODataLinkType;
@@ -51,6 +52,7 @@ import org.apache.olingo.commons.core.data.ComplexValueImpl;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
+import org.apache.olingo.commons.core.data.ParameterImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
@@ -58,6 +60,7 @@ import org.apache.olingo.server.api.deserializer.ODataDeserializer;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
@@ -72,10 +75,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
@Override
public EntitySet entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException {
try {
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
- JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
- final ObjectNode tree = parser.getCodec().readTree(parser);
+ final ObjectNode tree = parseJsonTree(stream);
return consumeEntitySetNode(edmEntityType, tree);
} catch (JsonParseException e) {
@@ -145,10 +145,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
@Override
public Entity entity(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException {
try {
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
- JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
- final ObjectNode tree = parser.getCodec().readTree(parser);
+ final ObjectNode tree = parseJsonTree(stream);
return consumeEntityNode(edmEntityType, tree);
@@ -183,16 +180,13 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
@Override
- public Entity actionParameters(InputStream stream, final EdmAction edmAction) throws DeserializerException {
+ public List<Parameter> actionParameters(InputStream stream, final EdmAction edmAction) throws DeserializerException {
try {
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
- JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
- ObjectNode tree = parser.getCodec().readTree(parser);
- EntityImpl entity = new EntityImpl();
- consumeParameters(edmAction, tree, entity);
+ ObjectNode tree = parseJsonTree(stream);
+ ArrayList<Parameter> parameters = new ArrayList<Parameter>();
+ consumeParameters(edmAction, tree, parameters);
assertJsonNodeIsEmpty(tree);
- return entity;
+ return parameters;
} catch (final JsonParseException e) {
throw new DeserializerException("An JsonParseException occurred", e,
@@ -206,22 +200,36 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
}
- private void consumeParameters(final EdmAction edmAction, ObjectNode node, EntityImpl entity)
+ private ObjectNode parseJsonTree(InputStream stream) throws IOException, JsonParseException, JsonProcessingException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
+ JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
+ ObjectNode tree = parser.getCodec().readTree(parser);
+ return tree;
+ }
+
+ private void consumeParameters(final EdmAction edmAction, ObjectNode node, ArrayList<Parameter> parameters)
throws DeserializerException {
for (final String name : edmAction.getParameterNames()) {
- final EdmParameter parameter = edmAction.getParameter(name);
+ final EdmParameter edmParameter = edmAction.getParameter(name);
+ ParameterImpl parameter = new ParameterImpl();
+ parameter.setName(name);
JsonNode jsonNode = node.get(name);
if (jsonNode == null) {
- if (!parameter.isNullable()) {
+ if (!edmParameter.isNullable()) {
// TODO: new message key.
throw new DeserializerException("Non-nullable parameter not present or null",
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, name);
}
} else {
- entity.addProperty(consumePropertyNode(parameter.getName(), parameter.getType(), parameter.isCollection(),
- parameter.isNullable(), parameter.getMaxLength(), parameter.getPrecision(), parameter.getScale(),
- true, parameter.getMapping(),
- jsonNode));
+ Property consumePropertyNode =
+ consumePropertyNode(edmParameter.getName(), edmParameter.getType(), edmParameter.isCollection(),
+ edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter
+ .getScale(),
+ true, edmParameter.getMapping(),
+ jsonNode);
+ parameter.setValue(consumePropertyNode.getValueType(), consumePropertyNode.getValue());
+ parameters.add(parameter);
node.remove(name);
}
}
@@ -302,7 +310,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
EntitySetImpl inlineEntitySet = new EntitySetImpl();
inlineEntitySet.getEntities().addAll(consumeEntitySetArray(edmNavigationProperty.getType(), jsonNode));
link.setInlineEntitySet(inlineEntitySet);
- } else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull())
+ } else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull())
&& !edmNavigationProperty.isCollection()) {
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
if (!jsonNode.isNull()) {
@@ -623,7 +631,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
/**
* Check if JsonNode is a value node (<code>jsonNode.isValueNode()</code>) and if not throw
* an DeserializerException.
- * @param name name of property which is checked
+ * @param name name of property which is checked
* @param jsonNode node which is checked
* @throws DeserializerException is thrown if json node is not a value node
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3e8c5064/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
index 2e6a181..80668eb 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
@@ -26,8 +26,7 @@ import java.io.ByteArrayInputStream;
import java.math.BigDecimal;
import java.util.List;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.Parameter;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.server.api.OData;
@@ -39,27 +38,23 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
@Test
public void empty() throws Exception {
final String input = "{}";
- final Entity entity = deserialize(input, "UART");
- assertNotNull(entity);
- final List<Property> properties = entity.getProperties();
- assertNotNull(properties);
- assertTrue(properties.isEmpty());
+ final List<Parameter> parameters = deserialize(input, "UART");
+ assertNotNull(parameters);
+ assertTrue(parameters.isEmpty());
}
@Test
public void primitive() throws Exception {
final String input = "{\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}";
- final Entity entity = deserialize(input, "UARTTwoParam");
- assertNotNull(entity);
- final List<Property> properties = entity.getProperties();
- assertNotNull(properties);
- assertEquals(2, properties.size());
- Property property = properties.get(0);
- assertNotNull(property);
- assertEquals((short) 42, property.getValue());
- property = properties.get(1);
- assertNotNull(property);
- assertEquals(BigDecimal.valueOf(3669753), property.getValue());
+ final List<Parameter> parameters = deserialize(input, "UARTTwoParam");
+ assertNotNull(parameters);
+ assertEquals(2, parameters.size());
+ Parameter parameter = parameters.get(0);
+ assertNotNull(parameter);
+ assertEquals((short) 42, parameter.getValue());
+ parameter = parameters.get(1);
+ assertNotNull(parameter);
+ assertEquals(BigDecimal.valueOf(3669753), parameter.getValue());
}
@Test(expected = DeserializerException.class)
@@ -77,7 +72,7 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
deserialize("{\"ParameterInt16\":\"42\"}", "UARTParam");
}
- private Entity deserialize(final String input, final String actionName) throws DeserializerException {
+ private List<Parameter> deserialize(final String input, final String actionName) throws DeserializerException {
return OData.newInstance().createDeserializer(ODataFormat.JSON)
.actionParameters(new ByteArrayInputStream(input.getBytes()),
edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName)));
[16/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Finish Edm
Refactoring
Posted by ch...@apache.org.
[OLINGO-575] Finish Edm Refactoring
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/62f10014
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/62f10014
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/62f10014
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 62f100148a9dd8c7389c0ced8e9dd08e8f687515
Parents: af1417b
Author: Christian Amend <ch...@apache.org>
Authored: Mon Mar 30 15:14:40 2015 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Mon Mar 30 15:14:40 2015 +0200
----------------------------------------------------------------------
.../olingo/ext/pojogen/AbstractPOJOGenMojo.java | 53 +++---
.../ext/pojogen/NavPropertyBindingDetails.java | 51 +++---
.../org/apache/olingo/commons/api/edm/Edm.java | 9 +
.../olingo/commons/api/edm/EdmSchema.java | 18 --
.../olingo/commons/core/edm/AbstractEdm.java | 166 +++++++++----------
.../core/edm/provider/EdmAnnotationsImpl.java | 38 +++--
.../core/edm/provider/EdmProviderImpl.java | 6 +-
.../core/edm/provider/EdmSchemaImpl.java | 126 +++++++-------
8 files changed, 225 insertions(+), 242 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/62f10014/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
index 5caeafb..9321c64 100644
--- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
+++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
@@ -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.
*/
@@ -112,12 +112,12 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
protected File mkPkgDir(final String path) {
return StringUtils.isBlank(basePackage)
- ? mkdir(path)
- : mkdir(basePackage.replace('.', File.separatorChar) + File.separator + path);
+ ? mkdir(path)
+ : mkdir(basePackage.replace('.', File.separatorChar) + File.separator + path);
}
protected void writeFile(final String name, final File path, final VelocityContext ctx, final Template template,
- final boolean append) throws MojoExecutionException {
+ final boolean append) throws MojoExecutionException {
if (!path.exists()) {
throw new IllegalArgumentException("Invalid base path '" + path.getAbsolutePath() + "'");
@@ -152,30 +152,30 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
}
protected void parseObj(final File base, final String pkg, final String name, final String out)
- throws MojoExecutionException {
+ throws MojoExecutionException {
- parseObj(base, false, pkg, name, out, Collections.<String, Object>emptyMap());
+ parseObj(base, false, pkg, name, out, Collections.<String, Object> emptyMap());
}
protected void parseObj(
- final File base,
- final String pkg,
- final String name,
- final String out,
- final Map<String, Object> objs)
- throws MojoExecutionException {
+ final File base,
+ final String pkg,
+ final String name,
+ final String out,
+ final Map<String, Object> objs)
+ throws MojoExecutionException {
parseObj(base, false, pkg, name, out, objs);
}
protected void parseObj(
- final File base,
- final boolean append,
- final String pkg,
- final String name,
- final String out,
- final Map<String, Object> objs)
- throws MojoExecutionException {
+ final File base,
+ final boolean append,
+ final String pkg,
+ final String name,
+ final String out,
+ final Map<String, Object> objs)
+ throws MojoExecutionException {
final VelocityContext ctx = newContext();
ctx.put("package", pkg);
@@ -351,7 +351,8 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
}
// write container and top entity sets into the base package
- for (EdmEntityContainer container : schema.getEntityContainers()) {
+ EdmEntityContainer container = schema.getEntityContainer();
+ if(container != null){
objs.clear();
objs.put("container", container);
objs.put("namespace", schema.getNamespace());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/62f10014/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java
index 48bf288..75f2105 100644
--- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java
+++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java
@@ -60,21 +60,19 @@ public class NavPropertyBindingDetails {
}
private EdmBindingTarget getNavigationBindingDetails(final EdmStructuredType type) {
- for (EdmSchema sc : edm.getSchemas()) {
- for (EdmEntityContainer c : sc.getEntityContainers()) {
- for (EdmEntitySet es : c.getEntitySets()) {
- if (es.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) {
- return es;
- }
+ EdmEntityContainer c = edm.getEntityContainer();
+ if (c != null) {
+ for (EdmEntitySet es : c.getEntitySets()) {
+ if (es.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) {
+ return es;
}
+ }
- for (EdmSingleton s : c.getSingletons()) {
- if (s.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) {
- return s;
- }
+ for (EdmSingleton s : c.getSingletons()) {
+ if (s.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) {
+ return s;
}
}
-
}
throw new IllegalStateException("EntitySet for '" + type.getName() + "' not found");
@@ -83,26 +81,25 @@ public class NavPropertyBindingDetails {
private EdmBindingTarget getNavigationBindingDetails(
final EdmStructuredType sourceType, final EdmNavigationProperty property) {
- for (EdmSchema sc : edm.getSchemas()) {
- for (EdmEntityContainer c : sc.getEntityContainers()) {
- for (EdmEntitySet es : c.getEntitySets()) {
- if (es.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) {
- for (EdmNavigationPropertyBinding binding : es.getNavigationPropertyBindings()) {
- if (binding.getPath().equals(property.getName())
- || binding.getPath().endsWith("/" + property.getName())) {
- return es.getRelatedBindingTarget(binding.getPath());
- }
+ EdmEntityContainer c = edm.getEntityContainer();
+ if (c != null) {
+ for (EdmEntitySet es : c.getEntitySets()) {
+ if (es.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) {
+ for (EdmNavigationPropertyBinding binding : es.getNavigationPropertyBindings()) {
+ if (binding.getPath().equals(property.getName())
+ || binding.getPath().endsWith("/" + property.getName())) {
+ return es.getRelatedBindingTarget(binding.getPath());
}
}
}
+ }
- for (EdmSingleton s : c.getSingletons()) {
- if (s.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) {
- for (EdmNavigationPropertyBinding binding : s.getNavigationPropertyBindings()) {
- if (binding.getPath().equals(property.getName())
- || binding.getPath().endsWith("/" + property.getName())) {
- return s.getRelatedBindingTarget(binding.getPath());
- }
+ for (EdmSingleton s : c.getSingletons()) {
+ if (s.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) {
+ for (EdmNavigationPropertyBinding binding : s.getNavigationPropertyBindings()) {
+ if (binding.getPath().equals(property.getName())
+ || binding.getPath().endsWith("/" + property.getName())) {
+ return s.getRelatedBindingTarget(binding.getPath());
}
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/62f10014/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java
index 8790afb..7b9376a 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/Edm.java
@@ -43,6 +43,15 @@ public interface Edm {
EdmSchema getSchema(String namespace);
/**
+ * Get main entity container.
+ * <br/>
+ * See {@link EdmEntityContainer} for more information.
+ *
+ * @return {@link EdmEntityContainer}
+ */
+ EdmEntityContainer getEntityContainer();
+
+ /**
* Get entity container by full qualified name.
* <br/>
* See {@link EdmEntityContainer} for more information.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/62f10014/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java
index 1f4667c..837514e 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSchema.java
@@ -80,22 +80,4 @@ public interface EdmSchema extends EdmAnnotatable {
*/
EdmEntityContainer getEntityContainer();
- /**
- * Returns the list of entity containers for this schema.
- * <br/>
- * According to CSDL specifications, this method will always return a singleton list for OData 4.0, containing the
- * same container as returned by {@link #getEntityContainer()}.
- *
- * @return the list of entity containers for this schema; singleton list for OData 4.0
- */
- List<EdmEntityContainer> getEntityContainers();
-
- /**
- * Returns the entity container for the given name, or null if not found.
- *
- * @param name entity container full qualified name
- * @return the entity container for the given name, or null if not found
- */
- EdmEntityContainer getEntityContainer(FullQualifiedName name);
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/62f10014/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java
index bc0b304..e865aa6 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java
@@ -79,13 +79,17 @@ public abstract class AbstractEdm implements Edm {
@Override
public List<EdmSchema> getSchemas() {
- initSchemas();
+ if (schemaList == null) {
+ initSchemas();
+ }
return schemaList;
}
@Override
public EdmSchema getSchema(final String namespace) {
- initSchemas();
+ if (schemas == null) {
+ initSchemas();
+ }
EdmSchema schema = schemas.get(namespace);
if (schema == null) {
@@ -99,94 +103,20 @@ public abstract class AbstractEdm implements Edm {
}
private void initSchemas() {
+ aliasToNamespaceInfo = new HashMap<String, String>();
+ schemas = createSchemas();
if (schemas == null) {
- schemas = createSchemas();
- if (schemas != null) {
- schemaList = Collections.unmodifiableList(new ArrayList<EdmSchema>(schemas.values()));
- aliasToNamespaceInfo = new HashMap<String, String>();
- for (EdmSchema schema : schemas.values()) {
- final String namespace = schema.getNamespace();
-
- if (schema.getAlias() != null) {
- aliasToNamespaceInfo.put(schema.getAlias(), namespace);
- }
-
- final List<EdmEnumType> localEnumTypes = schema.getEnumTypes();
- if (localEnumTypes != null) {
- for (EdmEnumType enumType : localEnumTypes) {
- enumTypes.put(new FullQualifiedName(namespace, enumType.getName()), enumType);
- }
- }
-
- final List<EdmTypeDefinition> localTypeDefinitions = schema.getTypeDefinitions();
- if (localTypeDefinitions != null) {
- for (EdmTypeDefinition typeDef : localTypeDefinitions) {
- typeDefinitions.put(new FullQualifiedName(namespace, typeDef.getName()), typeDef);
- }
- }
-
- final 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);
- }
- }
-
- final List<EdmAction> localActions = schema.getActions();
- if (localActions != null) {
- for (EdmAction action : localActions) {
- final FullQualifiedName name = new FullQualifiedName(namespace, action.getName());
- if (action.isBound()) {
- final ActionMapKey key = new ActionMapKey(name,
- action.getBindingParameterTypeFqn(), action.isBindingParameterTypeCollection());
- boundActions.put(key, action);
- } else {
- unboundActions.put(name, action);
- }
- }
- }
-
- final List<EdmFunction> localFunctions = schema.getFunctions();
- if (localFunctions != null) {
- for (EdmFunction function : localFunctions) {
- final FullQualifiedName name = new FullQualifiedName(namespace, function.getName());
- final FunctionMapKey key = new FunctionMapKey(name,
- function.getBindingParameterTypeFqn(), function.isBindingParameterTypeCollection(),
- function.getParameterNames());
-
- if (function.isBound()) {
- boundFunctions.put(key, function);
- } else {
- if (!unboundFunctionsByName.containsKey(name)) {
- unboundFunctionsByName.put(name, new ArrayList<EdmFunction>());
- }
- unboundFunctionsByName.get(name).add(function);
-
- unboundFunctionsByKey.put(key, function);
- }
- }
- }
-
- final EdmEntityContainer entityContainer = schema.getEntityContainer();
- if (entityContainer != null) {
- entityContainers.put(new FullQualifiedName(namespace, entityContainer.getName()), entityContainer);
- if (!entityContainers.containsKey(null)) {
- entityContainers.put(null, entityContainer);
- }
- }
- }
- }
+ schemas = Collections.emptyMap();
}
+ schemaList = Collections.unmodifiableList(new ArrayList<EdmSchema>(schemas.values()));
}
@Override
+ public EdmEntityContainer getEntityContainer() {
+ return getEntityContainer(null);
+ }
+
+ @Override
public EdmEntityContainer getEntityContainer(final FullQualifiedName namespaceOrAliasFQN) {
final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN);
EdmEntityContainer container = entityContainers.get(fqn);
@@ -419,16 +349,43 @@ public abstract class AbstractEdm implements Edm {
protected abstract Map<String, String> createAliasToNamespaceInfo();
+ public void cacheAliasNamespaceInfo(String alias, String namespace) {
+ if (aliasToNamespaceInfo == null) {
+ aliasToNamespaceInfo = new HashMap<String, String>();
+ }
+ aliasToNamespaceInfo.put(alias, namespace);
+ }
+
protected abstract EdmEntityContainer createEntityContainer(FullQualifiedName containerName);
+ public void cacheEntityContainer(FullQualifiedName containerFQN, EdmEntityContainer container) {
+ entityContainers.put(containerFQN, container);
+ }
+
protected abstract EdmEnumType createEnumType(FullQualifiedName enumName);
+ public void cacheEnumType(FullQualifiedName enumName, EdmEnumType enumType) {
+ enumTypes.put(enumName, enumType);
+ }
+
protected abstract EdmTypeDefinition createTypeDefinition(FullQualifiedName typeDefinitionName);
+ public void cacheTypeDefinition(FullQualifiedName typeDefName, EdmTypeDefinition typeDef) {
+ typeDefinitions.put(typeDefName, typeDef);
+ }
+
protected abstract EdmEntityType createEntityType(FullQualifiedName entityTypeName);
+ public void cacheEntityType(FullQualifiedName entityTypeName, EdmEntityType entityType) {
+ entityTypes.put(entityTypeName, entityType);
+ }
+
protected abstract EdmComplexType createComplexType(FullQualifiedName complexTypeName);
+ public void cacheComplexType(FullQualifiedName compelxTypeName, EdmComplexType complexType) {
+ complexTypes.put(compelxTypeName, complexType);
+ }
+
protected abstract EdmAction createUnboundAction(FullQualifiedName actionName);
protected abstract List<EdmFunction> createUnboundFunctions(FullQualifiedName functionName);
@@ -443,9 +400,48 @@ public abstract class AbstractEdm implements Edm {
FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection,
List<String> parameterNames);
+ public void cacheFunction(FullQualifiedName functionName, EdmFunction function) {
+ final FunctionMapKey key = new FunctionMapKey(functionName,
+ function.getBindingParameterTypeFqn(), function.isBindingParameterTypeCollection(),
+ function.getParameterNames());
+
+ if (function.isBound()) {
+ boundFunctions.put(key, function);
+ } else {
+ if (!unboundFunctionsByName.containsKey(functionName)) {
+ unboundFunctionsByName.put(functionName, new ArrayList<EdmFunction>());
+ }
+ unboundFunctionsByName.get(functionName).add(function);
+
+ unboundFunctionsByKey.put(key, function);
+ }
+ }
+
+ public void cacheAction(FullQualifiedName actionName, EdmAction action) {
+ if (action.isBound()) {
+ final ActionMapKey key = new ActionMapKey(actionName,
+ action.getBindingParameterTypeFqn(), action.isBindingParameterTypeCollection());
+ boundActions.put(key, action);
+ } else {
+ unboundActions.put(actionName, action);
+ }
+ }
+
protected abstract EdmTerm createTerm(FullQualifiedName termName);
+
+ public void cacheTerm(FullQualifiedName termName, EdmTerm term) {
+ terms.put(termName, term);
+ }
protected abstract EdmAnnotations createAnnotationGroup(FullQualifiedName targetName);
+
+ public void cacheAnnotationGroup(FullQualifiedName annotationsGroupName, EdmAnnotations annotationsGroup) {
+ annotationGroups.put(annotationsGroupName, annotationsGroup);
+ }
protected abstract List<EdmAnnotation> createAnnotations(FullQualifiedName annotatedName);
+
+// public void cacheAnnotation(FullQualifiedName annotationsGroupName, EdmAnnotations annotationsGroup) {
+// annotationGroups.put(annotationsGroupName, annotationsGroup);
+// }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/62f10014/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java
index a779bf1..4de911c 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationsImpl.java
@@ -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.
*/
@@ -54,8 +54,8 @@ public class EdmAnnotationsImpl implements EdmAnnotations {
EdmAnnotationsTarget _target = null;
if (structured != null) {
_target = path == null
- ? structured
- : structured.getStructuralProperty(path);
+ ? structured
+ : structured.getStructuralProperty(path);
if (_target == null) {
_target = structured.getNavigationProperty(path);
}
@@ -67,8 +67,8 @@ public class EdmAnnotationsImpl implements EdmAnnotations {
EdmAnnotationsTarget _target = null;
if (enumType != null) {
_target = path == null
- ? enumType
- : enumType.getMember(path);
+ ? enumType
+ : enumType.getMember(path);
}
return _target;
}
@@ -80,23 +80,25 @@ public class EdmAnnotationsImpl implements EdmAnnotations {
final FullQualifiedName base = new FullQualifiedName(splitted[0]);
final String path = splitted.length > 1 ? splitted[1] : null;
- final EdmEntityContainer baseEntityContainer = schema.getEntityContainer(base);
-
- target = baseEntityContainer == null? null: baseEntityContainer.getActionImport(path);
+ final EdmEntityContainer baseEntityContainer = schema.getEntityContainer();
+
+ target = baseEntityContainer == null ? null : baseEntityContainer.getActionImport(path);
if (target == null) {
target = getTarget(edm.getComplexType(base), path);
if (target == null) {
- target = baseEntityContainer;
+ if(baseEntityContainer != null && baseEntityContainer.getFullQualifiedName().equals(base)){
+ target = baseEntityContainer;
+ }
if (target == null) {
- target = baseEntityContainer == null? null: baseEntityContainer.getEntitySet(path);
+ target = baseEntityContainer == null ? null : baseEntityContainer.getEntitySet(path);
if (target == null) {
target = getTarget(edm.getEntityType(base), path);
if (target == null) {
target = getTarget(edm.getEnumType(base), path);
if (target == null) {
- target = baseEntityContainer == null? null: baseEntityContainer.getFunctionImport(path);
+ target = baseEntityContainer == null ? null : baseEntityContainer.getFunctionImport(path);
if (target == null) {
- target = baseEntityContainer == null? null: baseEntityContainer.getSingleton(path);
+ target = baseEntityContainer == null ? null : baseEntityContainer.getSingleton(path);
if (target == null) {
target = edm.getTerm(base);
if (target == null) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/62f10014/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java
index 3da0536..daa0e87 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmProviderImpl.java
@@ -317,11 +317,11 @@ public class EdmProviderImpl extends AbstractEdm {
@Override
protected Map<String, EdmSchema> createSchemas() {
try {
- final Map<String, EdmSchema> _schemas = new LinkedHashMap<String, EdmSchema>();
+ final Map<String, EdmSchema> providerSchemas = new LinkedHashMap<String, EdmSchema>();
for (Schema schema : provider.getSchemas()) {
- _schemas.put(schema.getNamespace(), new EdmSchemaImpl(this, provider, schema));
+ providerSchemas.put(schema.getNamespace(), new EdmSchemaImpl(this, provider, schema));
}
- return _schemas;
+ return providerSchemas;
} catch (ODataException e) {
throw new EdmException(e);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/62f10014/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
index 7e09b2d..ea44dc6 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSchemaImpl.java
@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Collections;
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.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmAnnotations;
@@ -50,7 +49,7 @@ import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
public class EdmSchemaImpl implements EdmSchema {
private final Schema schema;
- private final Edm edm;
+ private final EdmProviderImpl edm;
private final EdmProvider provider;
protected final String namespace;
@@ -66,115 +65,81 @@ public class EdmSchemaImpl implements EdmSchema {
private List<EdmAnnotation> annotations;
private EdmEntityContainer entityContainer;
- public EdmSchemaImpl(final Edm edm, final EdmProvider provider, final Schema schema) {
+ public EdmSchemaImpl(final EdmProviderImpl edm, final EdmProvider provider, final Schema schema) {
this.edm = edm;
this.provider = provider;
this.schema = schema;
this.namespace = schema.getNamespace();
this.alias = schema.getAlias();
+
+ if (alias != null) {
+ edm.cacheAliasNamespaceInfo(alias, namespace);
+ }
+
+ enumTypes = createEnumTypes();
+ typeDefinitions = createTypeDefinitions();
+ entityTypes = createEntityTypes();
+ complexTypes = createComplexTypes();
+ actions = createActions();
+ functions = createFunctions();
+ entityContainer = createEntityContainer();
+ annotationGroups = createAnnotationGroups();
+ annotations = createAnnotations();
+ terms = createTerms();
+
}
@Override
public List<EdmEnumType> getEnumTypes() {
- if (enumTypes == null) {
- enumTypes = createEnumTypes();
- }
return Collections.unmodifiableList(enumTypes);
}
@Override
public List<EdmEntityType> getEntityTypes() {
- if (entityTypes == null) {
- entityTypes = createEntityTypes();
- }
return Collections.unmodifiableList(entityTypes);
}
@Override
public List<EdmComplexType> getComplexTypes() {
- if (complexTypes == null) {
- complexTypes = createComplexTypes();
- }
return Collections.unmodifiableList(complexTypes);
}
@Override
public List<EdmAction> getActions() {
- if (actions == null) {
- actions = createActions();
- }
return Collections.unmodifiableList(actions);
}
@Override
public List<EdmFunction> getFunctions() {
- if (functions == null) {
- functions = createFunctions();
- }
return Collections.unmodifiableList(functions);
}
@Override
public List<EdmTypeDefinition> getTypeDefinitions() {
- if (typeDefinitions == null) {
- typeDefinitions = createTypeDefinitions();
- }
return Collections.unmodifiableList(typeDefinitions);
}
@Override
public List<EdmTerm> getTerms() {
- if (terms == null) {
- terms = createTerms();
- }
return Collections.unmodifiableList(terms);
}
@Override
public List<EdmAnnotations> getAnnotationGroups() {
- if (annotationGroups == null) {
- annotationGroups = createAnnotationGroups();
- }
return Collections.unmodifiableList(annotationGroups);
}
@Override
public List<EdmAnnotation> getAnnotations() {
- if (annotations == null) {
- annotations = createAnnotations();
- }
return Collections.unmodifiableList(annotations);
}
@Override
public EdmEntityContainer getEntityContainer() {
- if (entityContainer == null) {
- entityContainer = createEntityContainer();
- }
return entityContainer;
}
@Override
- public List<EdmEntityContainer> getEntityContainers() {
- if (getEntityContainer() == null) {
- return Collections.<EdmEntityContainer> emptyList();
- } else {
- return Collections.unmodifiableList(Collections.singletonList(getEntityContainer()));
- }
- }
-
- @Override
- public EdmEntityContainer getEntityContainer(final FullQualifiedName name) {
- return getEntityContainer() == null
- ? null
- : name == null
- ? getEntityContainer()
- : name.equals(getEntityContainer().getFullQualifiedName())
- ? getEntityContainer()
- : null;
- }
-
- @Override
public String getNamespace() {
return namespace;
}
@@ -187,7 +152,10 @@ public class EdmSchemaImpl implements EdmSchema {
protected EdmEntityContainer createEntityContainer() {
if (schema.getEntityContainer() != null) {
FullQualifiedName containerFQN = new FullQualifiedName(namespace, schema.getEntityContainer().getName());
- return new EdmEntityContainerImpl(edm, provider, containerFQN, schema.getEntityContainer());
+ EdmEntityContainer impl = new EdmEntityContainerImpl(edm, provider, containerFQN, schema.getEntityContainer());
+ edm.cacheEntityContainer(containerFQN, impl);
+ edm.cacheEntityContainer(null, impl);
+ return impl;
}
return null;
}
@@ -197,7 +165,10 @@ public class EdmSchemaImpl implements EdmSchema {
final List<TypeDefinition> providerTypeDefinitions = schema.getTypeDefinitions();
if (providerTypeDefinitions != null) {
for (TypeDefinition def : providerTypeDefinitions) {
- typeDefinitions.add(new EdmTypeDefinitionImpl(edm, new FullQualifiedName(namespace, def.getName()), def));
+ FullQualifiedName typeDefName = new FullQualifiedName(namespace, def.getName());
+ EdmTypeDefinitionImpl typeDefImpl = new EdmTypeDefinitionImpl(edm, typeDefName, def);
+ typeDefinitions.add(typeDefImpl);
+ edm.cacheTypeDefinition(typeDefName, typeDefImpl);
}
}
return typeDefinitions;
@@ -208,7 +179,10 @@ public class EdmSchemaImpl implements EdmSchema {
final List<EnumType> providerEnumTypes = schema.getEnumTypes();
if (providerEnumTypes != null) {
for (EnumType enumType : providerEnumTypes) {
- enumTypes.add(new EdmEnumTypeImpl(edm, new FullQualifiedName(namespace, enumType.getName()), enumType));
+ FullQualifiedName enumName = new FullQualifiedName(namespace, enumType.getName());
+ EdmEnumType enumTypeImpl = new EdmEnumTypeImpl(edm, enumName, enumType);
+ enumTypes.add(enumTypeImpl);
+ edm.cacheEnumType(enumName, enumTypeImpl);
}
}
return enumTypes;
@@ -219,8 +193,10 @@ public class EdmSchemaImpl implements EdmSchema {
final List<EntityType> providerEntityTypes = schema.getEntityTypes();
if (providerEntityTypes != null) {
for (EntityType entityType : providerEntityTypes) {
- entityTypes.add(new EdmEntityTypeImpl(edm, new FullQualifiedName(namespace, entityType.getName()),
- entityType));
+ FullQualifiedName entityTypeName = new FullQualifiedName(namespace, entityType.getName());
+ EdmEntityTypeImpl entityTypeImpl = new EdmEntityTypeImpl(edm, entityTypeName, entityType);
+ entityTypes.add(entityTypeImpl);
+ edm.cacheEntityType(entityTypeName, entityTypeImpl);
}
}
return entityTypes;
@@ -231,8 +207,10 @@ public class EdmSchemaImpl implements EdmSchema {
final List<ComplexType> providerComplexTypes = schema.getComplexTypes();
if (providerComplexTypes != null) {
for (ComplexType complexType : providerComplexTypes) {
- complexTypes.add(new EdmComplexTypeImpl(edm, new FullQualifiedName(namespace, complexType.getName()),
- complexType));
+ FullQualifiedName comlexTypeName = new FullQualifiedName(namespace, complexType.getName());
+ EdmComplexTypeImpl complexTypeImpl = new EdmComplexTypeImpl(edm, comlexTypeName, complexType);
+ complexTypes.add(complexTypeImpl);
+ edm.cacheComplexType(comlexTypeName, complexTypeImpl);
}
}
return complexTypes;
@@ -243,7 +221,10 @@ public class EdmSchemaImpl implements EdmSchema {
final List<Action> providerActions = schema.getActions();
if (providerActions != null) {
for (Action action : providerActions) {
- actions.add(new EdmActionImpl(edm, new FullQualifiedName(namespace, action.getName()), action));
+ FullQualifiedName actionName = new FullQualifiedName(namespace, action.getName());
+ EdmActionImpl edmActionImpl = new EdmActionImpl(edm, actionName, action);
+ actions.add(edmActionImpl);
+ edm.cacheAction(actionName, edmActionImpl);
}
}
return actions;
@@ -254,7 +235,10 @@ public class EdmSchemaImpl implements EdmSchema {
final List<Function> providerFunctions = schema.getFunctions();
if (providerFunctions != null) {
for (Function function : providerFunctions) {
- functions.add(new EdmFunctionImpl(edm, new FullQualifiedName(namespace, function.getName()), function));
+ FullQualifiedName functionName = new FullQualifiedName(namespace, function.getName());
+ EdmFunctionImpl functionImpl = new EdmFunctionImpl(edm, functionName, function);
+ functions.add(functionImpl);
+ edm.cacheFunction(functionName, functionImpl);
}
}
return functions;
@@ -265,7 +249,10 @@ public class EdmSchemaImpl implements EdmSchema {
final List<Term> providerTerms = schema.getTerms();
if (providerTerms != null) {
for (Term term : providerTerms) {
- terms.add(new EdmTermImpl(edm, getNamespace(), term));
+ FullQualifiedName termName = new FullQualifiedName(namespace, term.getName());
+ EdmTermImpl termImpl = new EdmTermImpl(edm, getNamespace(), term);
+ terms.add(termImpl);
+ edm.cacheTerm(termName, termImpl);
}
}
return terms;
@@ -277,7 +264,15 @@ public class EdmSchemaImpl implements EdmSchema {
schema.getAnnotationGroups();
if (providerAnnotations != null) {
for (Annotations annotationGroup : providerAnnotations) {
- annotationGroups.add(new EdmAnnotationsImpl(edm, this, annotationGroup));
+ FullQualifiedName annotationsGroupName;
+ if (annotationGroup.getTarget().contains(".")) {
+ annotationsGroupName = new FullQualifiedName(annotationGroup.getTarget());
+ } else {
+ annotationsGroupName = new FullQualifiedName(namespace, annotationGroup.getTarget());
+ }
+ EdmAnnotationsImpl annotationsImpl = new EdmAnnotationsImpl(edm, this, annotationGroup);
+ annotationGroups.add(annotationsImpl);
+ edm.cacheAnnotationGroup(annotationsGroupName, annotationsImpl);
}
}
return annotationGroups;
@@ -289,7 +284,8 @@ public class EdmSchemaImpl implements EdmSchema {
schema.getAnnotations();
if (providerAnnotations != null) {
for (Annotation annotation : providerAnnotations) {
- annotations.add(new EdmAnnotationImpl(edm, annotation));
+ EdmAnnotationImpl annotationImpl = new EdmAnnotationImpl(edm, annotation);
+ annotations.add(annotationImpl);
}
}
return annotations;
[04/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Edm cleanup
part 1
Posted by ch...@apache.org.
[OLINGO-575] Edm cleanup part 1
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/4d059b94
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/4d059b94
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/4d059b94
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 4d059b94d6fab23bf6a8a1b1df9839ee9d88cbb6
Parents: 3a6293b
Author: Christian Amend <ch...@apache.org>
Authored: Wed Mar 25 17:19:42 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Mar 25 17:19:42 2015 +0100
----------------------------------------------------------------------
.../api/edm/provider/FunctionImport.java | 1 +
.../api/edm/provider/OperationImport.java | 2 -
.../core/edm/provider/EdmAnnotationHelper.java | 24 -----------
.../edm/provider/EdmAnnotationHelperImpl.java | 3 +-
.../core/edm/provider/EdmAnnotationImpl.java | 6 +--
.../core/edm/provider/EdmBindingTargetImpl.java | 2 +-
.../core/edm/provider/EdmComplexTypeImpl.java | 5 +--
.../edm/provider/EdmEntityContainerImpl.java | 2 +-
.../core/edm/provider/EdmEntityTypeImpl.java | 4 +-
.../core/edm/provider/EdmEnumTypeImpl.java | 44 ++++++++++----------
.../core/edm/provider/EdmMemberImpl.java | 2 +-
.../edm/provider/EdmNavigationPropertyImpl.java | 2 +-
.../core/edm/provider/EdmOperationImpl.java | 2 +-
.../edm/provider/EdmOperationImportImpl.java | 2 +-
.../core/edm/provider/EdmParameterImpl.java | 2 +-
.../core/edm/provider/EdmPropertyImpl.java | 2 +-
.../provider/EdmReferentialConstraintImpl.java | 3 +-
.../edm/provider/EdmStructuredTypeHelper.java | 35 ----------------
.../provider/EdmStructuredTypeHelperImpl.java | 6 +--
.../commons/core/edm/provider/EdmTermImpl.java | 9 +---
.../edm/provider/EdmTypeDefinitionImpl.java | 27 ++++++------
.../commons/core/edm/provider/EdmTypeImpl.java | 1 -
.../tecsvc/provider/ContainerProvider.java | 1 +
23 files changed, 57 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/FunctionImport.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/FunctionImport.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/FunctionImport.java
index 71223ae..84d6789 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/FunctionImport.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/FunctionImport.java
@@ -27,6 +27,7 @@ public class FunctionImport extends OperationImport {
private FullQualifiedName function;
+ //Default include in service document is false for function imports
private boolean includeInServiceDocument;
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/OperationImport.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/OperationImport.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/OperationImport.java
index 8aa29db..7de9623 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/OperationImport.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/OperationImport.java
@@ -26,9 +26,7 @@ public abstract class OperationImport extends AbstractEdmItem implements Named,
private static final long serialVersionUID = -8928186067970681061L;
protected String name;
-
protected String entitySet;
-
protected final List<Annotation> annotations = new ArrayList<Annotation>();
public String getName() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelper.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelper.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelper.java
deleted file mode 100644
index bbbf136..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelper.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.provider;
-
-import org.apache.olingo.commons.api.edm.EdmAnnotatable;
-
-public interface EdmAnnotationHelper extends EdmAnnotatable {
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
index 106584a..e4b9d9b 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
@@ -22,12 +22,13 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAnnotatable;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.provider.Annotatable;
import org.apache.olingo.commons.api.edm.provider.Annotation;
-public class EdmAnnotationHelperImpl implements EdmAnnotationHelper {
+public class EdmAnnotationHelperImpl implements EdmAnnotatable {
private final Edm edm;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
index cd32570..60eb0b4 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
@@ -63,13 +63,9 @@ import org.apache.olingo.commons.core.edm.annotation.EdmUrlRefImpl;
public class EdmAnnotationImpl implements EdmAnnotation {
private final Edm edm;
-
private final Annotation annotation;
-
- private final EdmAnnotationHelper helper;
-
+ private final EdmAnnotationHelperImpl helper;
private EdmTerm term;
-
private EdmAnnotationExpression expression;
public EdmAnnotationImpl(final Edm edm, final Annotation annotation) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
index e4a1ba7..b4b035f 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
@@ -38,7 +38,7 @@ import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
public abstract class EdmBindingTargetImpl extends EdmNamedImpl implements EdmBindingTarget {
private final BindingTarget target;
- private final EdmAnnotationHelper helper;
+ private final EdmAnnotationHelperImpl helper;
private final EdmEntityContainer container;
private List<EdmNavigationPropertyBinding> navigationPropertyBindings;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
index 432a09f..7fdc0b8 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
@@ -35,13 +35,12 @@ import org.apache.olingo.commons.api.edm.provider.ComplexType;
public class EdmComplexTypeImpl extends EdmStructuredTypeImpl implements EdmComplexType {
- private final EdmStructuredTypeHelper helper;
+ private final EdmStructuredTypeHelperImpl helper;
- private EdmAnnotationHelper annotationHelper;
+ private EdmAnnotationHelperImpl annotationHelper;
public static EdmComplexTypeImpl getInstance(
final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
-
return new EdmComplexTypeImpl(edm, name, complexType);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
index 94b7d4d..5d3eef3 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
@@ -47,7 +47,7 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
private final EdmProvider provider;
private EntityContainer container;
- private EdmAnnotationHelper helper;
+ private EdmAnnotationHelperImpl helper;
protected final FullQualifiedName entityContainerName;
private final FullQualifiedName parentContainerName;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
index 0ee22e7..b561151 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
@@ -39,10 +39,10 @@ import org.apache.olingo.commons.api.edm.provider.PropertyRef;
public class EdmEntityTypeImpl extends EdmStructuredTypeImpl implements EdmEntityType {
- private final EdmStructuredTypeHelper helper;
+ private final EdmStructuredTypeHelperImpl helper;
private EntityType entityType;
private boolean baseTypeChecked = false;
- private EdmAnnotationHelper annotationHelper;
+ private EdmAnnotationHelperImpl annotationHelper;
private final boolean hasStream;
protected EdmEntityType entityBaseType;
private final List<String> keyPredicateNames = new ArrayList<String>();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
index 1fdf73b..df09c3c 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
@@ -19,10 +19,10 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.apache.olingo.commons.api.edm.Edm;
@@ -55,8 +55,7 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
private final String uriPrefix;
private final String uriSuffix;
private List<String> memberNames;
- private List<EdmMember> members;
- private Map<String, EdmMember> membersMap;
+ private LinkedHashMap<String, EdmMember> membersMap;
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final EnumType enumType) {
super(edm, enumName, EdmTypeKind.ENUM);
@@ -81,14 +80,11 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
public EdmPrimitiveType getUnderlyingType() {
return underlyingType;
}
-
+
@Override
public EdmMember getMember(final String name) {
if (membersMap == null) {
- membersMap = new LinkedHashMap<String, EdmMember>();
- for (final EdmMember member : getMembers()) {
- membersMap.put(member.getName(), member);
- }
+ createEdmMembers();
}
return membersMap.get(name);
}
@@ -96,12 +92,20 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
@Override
public List<String> getMemberNames() {
if (memberNames == null) {
- memberNames = new ArrayList<String>();
- for (final EdmMember member : getMembers()) {
+ createEdmMembers();
+ }
+ return memberNames;
+ }
+
+ private void createEdmMembers() {
+ membersMap = new LinkedHashMap<String, EdmMember>();
+ memberNames = new ArrayList<String>();
+ if (enumType.getMembers() != null) {
+ for (final EnumMember member : enumType.getMembers()) {
+ membersMap.put(member.getName(), new EdmMemberImpl(edm, getFullQualifiedName(), member));
memberNames.add(member.getName());
}
}
- return memberNames;
}
@Override
@@ -186,6 +190,13 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
return result.toString();
}
+ private Collection<EdmMember> getMembers() {
+ if(membersMap == null){
+ createEdmMembers();
+ }
+ return membersMap.values();
+ }
+
@Override
public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
@@ -242,15 +253,4 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
public FullQualifiedName getAnnotationsTargetFQN() {
return getFullQualifiedName();
}
-
- protected List<EdmMember> getMembers() {
- if (members == null) {
- members = new ArrayList<EdmMember>(enumType.getMembers().size());
- for (EnumMember member : enumType.getMembers()) {
- members.add(new EdmMemberImpl(edm, getFullQualifiedName(), member));
- }
- }
- return members;
- }
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
index 0bdf441..a7d1366 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
@@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.edm.provider.EnumMember;
public class EdmMemberImpl extends EdmNamedImpl implements EdmMember {
- private final EdmAnnotationHelper helper;
+ private final EdmAnnotationHelperImpl helper;
private final FullQualifiedName enumFQN;
private final EnumMember member;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
index a8bb8d9..e72a98e 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
@@ -37,8 +37,8 @@ public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavi
private final FullQualifiedName structuredTypeName;
private final NavigationProperty navigationProperty;
+ private final EdmAnnotationHelperImpl helper;
private List<EdmReferentialConstraint> referentialConstraints;
- private final EdmAnnotationHelper helper;
private EdmEntityType typeImpl;
private EdmNavigationProperty partnerNavigationProperty;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
index f8d69bf..217c732 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
@@ -40,7 +40,7 @@ import org.apache.olingo.commons.api.edm.provider.Parameter;
public abstract class EdmOperationImpl extends EdmTypeImpl implements EdmOperation {
protected final Operation operation;
- protected final EdmAnnotationHelper helper;
+ protected final EdmAnnotationHelperImpl helper;
private final Map<String, EdmParameter> parameters = new LinkedHashMap<String, EdmParameter>();
private String entitySetPath;
private boolean isBound;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
index ee5891d..3ace167 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
@@ -36,7 +36,7 @@ public abstract class EdmOperationImportImpl extends EdmNamedImpl implements Edm
protected final EdmEntityContainer container;
private final Target entitySet;
private EdmEntitySet returnedEntitySet;
- private final EdmAnnotationHelper helper;
+ private final EdmAnnotationHelperImpl helper;
public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container,
final OperationImport operationImport) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
index f5a25fa..157a779 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
@@ -33,7 +33,7 @@ import org.apache.olingo.commons.api.edm.provider.Parameter;
public class EdmParameterImpl extends EdmElementImpl implements EdmParameter {
private final Parameter parameter;
- private final EdmAnnotationHelper helper;
+ private final EdmAnnotationHelperImpl helper;
private final EdmTypeInfo typeInfo;
private EdmType typeImpl;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
index 61b6a22..973640e 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
@@ -36,7 +36,7 @@ public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty {
private final FullQualifiedName structuredTypeName;
private final Property property;
private final EdmTypeInfo typeInfo;
- private EdmAnnotationHelper helper;
+ private EdmAnnotationHelperImpl helper;
private EdmType propertyType;
public EdmPropertyImpl(final Edm edm, final FullQualifiedName structuredTypeName, final Property property) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
index e8dbc23..4a8d7d8 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
@@ -28,10 +28,9 @@ import org.apache.olingo.commons.api.edm.provider.ReferentialConstraint;
public class EdmReferentialConstraintImpl implements EdmReferentialConstraint {
- private final EdmAnnotationHelper helper;
+ private final EdmAnnotationHelperImpl helper;
private final ReferentialConstraint constraint;
-
public EdmReferentialConstraintImpl(final Edm edm, final ReferentialConstraint constraint) {
this.constraint = constraint;
this.helper = new EdmAnnotationHelperImpl(edm, constraint);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelper.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelper.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelper.java
deleted file mode 100644
index e00a28b..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelper.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.provider;
-
-import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-
-import java.util.Map;
-
-public interface EdmStructuredTypeHelper {
-
- Map<String, EdmProperty> getProperties();
-
- Map<String, EdmNavigationProperty> getNavigationProperties();
-
- boolean isOpenType();
-
- boolean isAbstract();
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
index f72eef1..9a78bcd 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
@@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.edm.provider.StructuralType;
import java.util.LinkedHashMap;
import java.util.Map;
-public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper {
+public class EdmStructuredTypeHelperImpl {
private final Edm edm;
private final FullQualifiedName structuredTypeName;
@@ -44,7 +44,6 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper {
this.structuredType = structuredType;
}
- @Override
public Map<String, EdmProperty> getProperties() {
if (properties == null) {
properties = new LinkedHashMap<String, EdmProperty>();
@@ -57,7 +56,6 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper {
return properties;
}
- @Override
public Map<String, EdmNavigationProperty> getNavigationProperties() {
if (navigationProperties == null) {
navigationProperties = new LinkedHashMap<String, EdmNavigationProperty>();
@@ -71,12 +69,10 @@ public class EdmStructuredTypeHelperImpl implements EdmStructuredTypeHelper {
return navigationProperties;
}
- @Override
public boolean isOpenType() {
return structuredType.isOpenType();
}
- @Override
public boolean isAbstract() {
return structuredType.isAbstract();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
index cc3f11f..e1f7ce0 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTermImpl.java
@@ -37,19 +37,12 @@ import org.slf4j.LoggerFactory;
public class EdmTermImpl extends EdmNamedImpl implements EdmTerm {
private static final Logger LOG = LoggerFactory.getLogger(EdmTermImpl.class);
-
private final Term term;
-
private final FullQualifiedName fqn;
-
private final EdmTypeInfo typeInfo;
-
- private final EdmAnnotationHelper helper;
-
+ private final EdmAnnotationHelperImpl helper;
private EdmType termType;
-
private EdmTerm baseTerm;
-
private List<Class<?>> appliesTo;
public EdmTermImpl(final Edm edm, final String namespace, final Term term) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
index d04f6dd..6831f07 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeDefinitionImpl.java
@@ -37,25 +37,16 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefinition {
private TypeDefinition typeDefinition;
- private final EdmPrimitiveType edmPrimitiveTypeInstance;
- private final EdmAnnotationHelper helper;
private FullQualifiedName typeDefinitionName;
+ private EdmPrimitiveType edmPrimitiveTypeInstance;
+ private final EdmAnnotationHelperImpl helper;
public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName,
final TypeDefinition typeDefinition) {
super(edm, typeDefinitionName.getName());
this.typeDefinitionName = typeDefinitionName;
this.typeDefinition = typeDefinition;
- try {
- if (typeDefinition.getUnderlyingType() == null) {
- throw new EdmException("Underlying Type for type definition: "
- + typeDefinitionName.getFullQualifiedNameAsString() + " must not be null.");
- }
- this.edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance(
- EdmPrimitiveTypeKind.valueOfFQN(typeDefinition.getUnderlyingType()));
- } catch (IllegalArgumentException e) {
- throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
- }
+
this.helper = new EdmAnnotationHelperImpl(edm, typeDefinition);
}
@@ -76,6 +67,18 @@ public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefini
@Override
public EdmPrimitiveType getUnderlyingType() {
+ if(edmPrimitiveTypeInstance == null){
+ try {
+ if (typeDefinition.getUnderlyingType() == null) {
+ throw new EdmException("Underlying Type for type definition: "
+ + typeDefinitionName.getFullQualifiedNameAsString() + " must not be null.");
+ }
+ this.edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance(
+ EdmPrimitiveTypeKind.valueOfFQN(typeDefinition.getUnderlyingType()));
+ } catch (IllegalArgumentException e) {
+ throw new EdmException("Invalid underlying type: " + typeDefinition.getUnderlyingType(), e);
+ }
+ }
return edmPrimitiveTypeInstance;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
index ea05c24..337d700 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmTypeImpl.java
@@ -26,7 +26,6 @@ import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
public class EdmTypeImpl extends EdmNamedImpl implements EdmType {
protected final FullQualifiedName typeName;
-
protected final EdmTypeKind kind;
public EdmTypeImpl(final Edm edm, final FullQualifiedName typeName, final EdmTypeKind kind) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d059b94/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
index 3882705..90ffca1 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
@@ -251,6 +251,7 @@ public class ContainerProvider {
} else if (name.equals("ESInvisible")) {
return new EntitySet()
.setName("ESInvisible")
+ .setIncludeInServiceDocument(false)
.setType(EntityTypeProvider.nameETAllPrim);
} else if (name.equals("ESServerSidePaging")) {
[21/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
new file mode 100644
index 0000000..32bf26a
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
@@ -0,0 +1,769 @@
+/*
+ * 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.requests;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.ContextURL.Suffix;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.core.data.PropertyImpl;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmStream;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
+import org.apache.olingo.server.api.deserializer.ODataDeserializer;
+import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.uri.UriHelper;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResource;
+import org.apache.olingo.server.api.uri.UriResourceComplexProperty;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
+import org.apache.olingo.server.api.uri.UriResourceProperty;
+import org.apache.olingo.server.api.uri.UriResourceSingleton;
+import org.apache.olingo.server.core.ContentNegotiator;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.responses.CountResponse;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public class DataRequest extends ServiceRequest {
+ protected UriResourceEntitySet uriResourceEntitySet;
+ private boolean countRequest;
+ private UriResourceProperty uriResourceProperty;
+ private boolean valueRequest;
+ private final LinkedList<UriResourceNavigation> uriNavigations = new LinkedList<UriResourceNavigation>();
+ private boolean references;
+
+ private RequestType type;
+ private UriResourceSingleton uriResourceSingleton;
+
+ /**
+ * This sub-categorizes the request so that code can be simplified
+ */
+ interface RequestType {
+ public boolean allowedMethod();
+
+ public ContentType getResponseContentType() throws ContentNegotiatorException;
+
+ public ContextURL getContextURL(OData odata) throws SerializerException;
+
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+ }
+
+ public DataRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ public UriResourceEntitySet getUriResourceEntitySet() {
+ return uriResourceEntitySet;
+ }
+
+ public void setUriResourceEntitySet(UriResourceEntitySet uriResourceEntitySet) {
+ this.uriResourceEntitySet = uriResourceEntitySet;
+ this.type = new EntityRequest();
+ }
+
+ public void setCrossJoin(UriInfoCrossjoin info) {
+ this.type = new CrossJoinRequest(info.getEntitySetNames());
+ }
+
+ public boolean isSingleton() {
+ return this.uriResourceSingleton != null;
+ }
+
+ public boolean isCollection() {
+ if (!this.uriNavigations.isEmpty()) {
+ return this.uriNavigations.getLast().isCollection();
+ }
+ return this.uriResourceEntitySet != null && this.uriResourceEntitySet.isCollection();
+ }
+
+ public EdmEntitySet getEntitySet() {
+ return this.uriResourceEntitySet.getEntitySet();
+ }
+
+ public boolean isCountRequest() {
+ return countRequest;
+ }
+
+ public void setCountRequest(boolean countRequest) {
+ this.countRequest = countRequest;
+ this.type = new CountRequest();
+ }
+
+ public boolean isPropertyRequest() {
+ return this.uriResourceProperty != null;
+ }
+
+ public boolean isPropertyComplex() {
+ return (this.uriResourceProperty instanceof UriResourceComplexProperty);
+ }
+
+ public boolean isPropertyStream() {
+ if (isPropertyComplex()) {
+ return false;
+ }
+ EdmProperty property = ((UriResourcePrimitiveProperty)this.uriResourceProperty).getProperty();
+ return (property.getType() instanceof EdmStream);
+ }
+
+ public UriResourceProperty getUriResourceProperty() {
+ return uriResourceProperty;
+ }
+
+ public void setUriResourceProperty(UriResourceProperty uriResourceProperty) {
+ this.uriResourceProperty = uriResourceProperty;
+ this.type = new PropertyRequest();
+ }
+
+ public LinkedList<UriResourceNavigation> getNavigations() {
+ return this.uriNavigations;
+ }
+
+ public void addUriResourceNavigation(UriResourceNavigation uriResourceNavigation) {
+ this.uriNavigations.add(uriResourceNavigation);
+ }
+
+ public UriResourceSingleton getUriResourceSingleton() {
+ return this.uriResourceSingleton;
+ }
+
+ public void setUriResourceSingleton(UriResourceSingleton info) {
+ this.uriResourceSingleton = info;
+ this.type = new SingletonRequest();
+ }
+
+ public List<UriParameter> getKeyPredicates() {
+ if (this.uriResourceEntitySet != null) {
+ return this.uriResourceEntitySet.getKeyPredicates();
+ }
+ return null;
+ }
+
+ public boolean isReferenceRequest() {
+ return this.references;
+ }
+
+ public void setReferenceRequest(boolean ref) {
+ this.references = ref;
+ this.type = new ReferenceRequest();
+ }
+
+ public boolean isValueRequest() {
+ return valueRequest;
+ }
+
+ private boolean hasMediaStream() {
+ return this.uriResourceEntitySet != null && this.uriResourceEntitySet.getEntityType().hasStream();
+ }
+
+ private InputStream getMediaStream() {
+ return this.request.getBody();
+ }
+
+ public void setValueRequest(boolean valueRequest) {
+ this.valueRequest = valueRequest;
+ this.type = new ValueRequest();
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ return this.type.allowedMethod();
+ }
+
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ return type.getContextURL(odata);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!this.type.allowedMethod()) {
+ methodNotAllowed();
+ }
+
+ this.type.execute(handler, response);
+ }
+
+ @Override
+ public <T> T getSerializerOptions(Class<T> serilizerOptions, ContextURL contextUrl, boolean references)
+ throws ContentNegotiatorException {
+ if (serilizerOptions.isAssignableFrom(PrimitiveSerializerOptions.class)) {
+ return (T) PrimitiveSerializerOptions.with().contextURL(contextUrl)
+ .facetsFrom(getUriResourceProperty().getProperty()).build();
+ }
+ return super.getSerializerOptions(serilizerOptions, contextUrl, references);
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return type.getResponseContentType();
+ }
+
+ class EntityRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ // the create/update/delete to navigation property is done through references
+ // see # 11.4.6
+ if (!getNavigations().isEmpty() && !isGET()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), getODataRequest(),
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_ENTITY
+ : RepresentationType.ENTITY);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ EntityResponse entityResponse = EntityResponse.getInstance(DataRequest.this,
+ getContextURL(odata), false, response);
+
+ if (isGET()) {
+ if (isCollection()) {
+ handler.read(DataRequest.this,
+ EntitySetResponse.getInstance(DataRequest.this, getContextURL(odata), false, response));
+ } else {
+ handler.read(DataRequest.this,entityResponse);
+ }
+ } else if (isPUT() || isPATCH()) {
+ // RFC 2616: he result of a request having both an If-Match header field and either
+ // an If-None-Match or an If-Modified-Since header fields is undefined
+ // by this specification.
+ boolean ifMatch = getHeader(HttpHeader.IF_MATCH) != null;
+ boolean ifNoneMatch = getHeader(HttpHeader.IF_NONE_MATCH).equals("*");
+ if(ifMatch) {
+ handler.updateEntity(DataRequest.this, getEntityFromClient(), isPATCH(), getETag(),
+ entityResponse);
+ } else if (ifNoneMatch) {
+ // 11.4.4
+ entityResponse = EntityResponse.getInstance(DataRequest.this,
+ getContextURL(odata), false, response, getReturnRepresentation());
+ handler.createEntity(DataRequest.this, getEntityFromClient(), entityResponse);
+ } else {
+ handler.updateEntity(DataRequest.this, getEntityFromClient(), isPATCH(), getETag(),
+ entityResponse);
+ }
+ } else if (isPOST()) {
+ entityResponse = EntityResponse.getInstance(DataRequest.this,
+ getContextURL(odata), false, response, getReturnRepresentation());
+ handler.createEntity(DataRequest.this, getEntityFromClient(),entityResponse);
+ } else if (isDELETE()) {
+ handler.deleteEntity(DataRequest.this, getETag(), entityResponse);
+ }
+ }
+
+ private Entity getEntityFromClient() throws DeserializerException {
+ ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
+ .fromContentType(getRequestContentType()));
+ return deserializer.entity(getODataRequest().getBody(), getEntitySet().getEntityType());
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ // EntitySet based return
+ final UriHelper helper = odata.createUriHelper();
+ ContextURL.Builder builder = buildEntitySetContextURL(helper, getEntitySet(),
+ getKeyPredicates(), getUriInfo(), getNavigations(), isCollection(), false);
+ return builder.build();
+ }
+ }
+
+ class CountRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ return isGET();
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentType.TEXT_PLAIN;
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ handler.read(DataRequest.this, CountResponse.getInstance(DataRequest.this, response));
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ return null;
+ }
+ }
+
+ /**
+ * Is NavigationProperty Reference.
+ */
+ class ReferenceRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ // references are only allowed on the navigation properties
+ if (getNavigations().isEmpty()) {
+ return false;
+ }
+
+ // 11.4.6.1 - post allowed on only collection valued navigation
+ if (isPOST() && !getNavigations().getLast().isCollection()) {
+ return false;
+ }
+
+ // 11.4.6.3 - PUT allowed on single valued navigation
+ if (isPUT() && getNavigations().getLast().isCollection()) {
+ return false;
+ }
+
+ // No defined behavior in spec
+ if (isPATCH()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), getODataRequest(),
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_REFERENCE
+ : RepresentationType.REFERENCE);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ if (isGET()) {
+ if (isCollection()) {
+ handler.read(DataRequest.this,
+ EntitySetResponse.getInstance(DataRequest.this, getContextURL(odata), true, response));
+ } else {
+ handler.read(DataRequest.this,
+ EntityResponse.getInstance(DataRequest.this, getContextURL(odata), true, response));
+ }
+ } else if (isDELETE()) {
+ // if this against the collection, user need to look at $id param for entity ref #11.4.6.2
+ String id = getQueryParameter("$id");
+ if (id == null) {
+ handler.deleteReference(DataRequest.this, null, getETag(), new NoContentResponse(
+ getServiceMetaData(), response));
+ } else {
+ try {
+ handler.deleteReference(DataRequest.this, new URI(id), getETag(), new NoContentResponse(
+ getServiceMetaData(), response));
+ } catch (URISyntaxException e) {
+ throw new DeserializerException("failed to read $id", e, MessageKeys.UNKOWN_CONTENT);
+ }
+ }
+ } else if (isPUT()) {
+ // note this is always against single reference
+ handler.updateReference(DataRequest.this, getETag(), getPayload().get(0), new NoContentResponse(
+ getServiceMetaData(), response));
+ } else if (isPOST()) {
+ // this needs to be against collection of references
+ handler.addReference(DataRequest.this, getETag(), getPayload(), new NoContentResponse(
+ getServiceMetaData(), response));
+ }
+ }
+
+ // http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os
+ // /odata-json-format-v4.0-errata02-os-complete.html#_Toc403940643
+ // The below code reads as property and converts to an URI
+ private List<URI> getPayload() throws DeserializerException {
+ ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
+ .fromContentType(getRequestContentType()));
+ return deserializer.entityReferences(getODataRequest().getBody());
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ ContextURL.Builder builder = ContextURL.with().suffix(Suffix.REFERENCE);
+ if (isCollection()) {
+ builder.asCollection();
+ }
+ return builder.build();
+ }
+ }
+
+ class PropertyRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ // create of properties is not allowed,
+ // only read, update, delete. Note that delete is
+ // same as update with null
+ if (isPOST()) {
+ return false;
+ }
+
+ // 11.4.9.4, collection properties are not supported with merge
+ if (isPATCH() && (isCollection() || isPropertyStream())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ if (isPropertyComplex()) {
+ return ContentNegotiator.doContentNegotiation(getUriInfo().getFormatOption(),
+ getODataRequest(), getCustomContentTypeSupport(),
+ isCollection() ? RepresentationType.COLLECTION_COMPLEX : RepresentationType.COMPLEX);
+ } else if (isPropertyStream()) {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request,
+ getCustomContentTypeSupport(), RepresentationType.BINARY);
+ }
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), getODataRequest(),
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_PRIMITIVE
+ : RepresentationType.PRIMITIVE);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ EdmProperty edmProperty = getUriResourceProperty().getProperty();
+
+ if (isGET()) {
+ if (isPropertyStream()) {
+ handler.read(DataRequest.this, new StreamResponse(getServiceMetaData(), response));
+ } else {
+ handler.read(DataRequest.this, buildResponse(response, edmProperty));
+ }
+ } else if (isPATCH()) {
+ handler.updateProperty(DataRequest.this, getPropertyValueFromClient(edmProperty), true,
+ getETag(), buildResponse(response, edmProperty));
+ } else if (isPUT()) {
+ if (isPropertyStream()) {
+ handler.upsertStreamProperty(DataRequest.this, getETag(), request.getBody(),
+ new NoContentResponse(getServiceMetaData(), response));
+ } else {
+ handler.updateProperty(DataRequest.this, getPropertyValueFromClient(edmProperty), false,
+ getETag(), buildResponse(response, edmProperty));
+ }
+ } else if (isDELETE()) {
+ if (isPropertyStream()) {
+ handler.upsertStreamProperty(DataRequest.this, getETag(), request.getBody(),
+ new NoContentResponse(getServiceMetaData(), response));
+ } else {
+ Property property = new PropertyImpl();
+ property.setName(edmProperty.getName());
+ property.setType(edmProperty.getType().getFullQualifiedName()
+ .getFullQualifiedNameAsString());
+ handler.updateProperty(DataRequest.this, property, false, getETag(),
+ buildResponse(response, edmProperty));
+ }
+ }
+ }
+
+ private PropertyResponse buildResponse(ODataResponse response, EdmProperty edmProperty)
+ throws ContentNegotiatorException, SerializerException {
+ PropertyResponse propertyResponse = PropertyResponse.getInstance(DataRequest.this, response,
+ edmProperty.getType(), getContextURL(odata), edmProperty.isCollection());
+ return propertyResponse;
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ final UriHelper helper = odata.createUriHelper();
+ EdmProperty edmProperty = getUriResourceProperty().getProperty();
+
+ ContextURL.Builder builder = ContextURL.with().entitySet(getEntitySet());
+ builder = ContextURL.with().entitySet(getEntitySet());
+ builder.keyPath(helper.buildContextURLKeyPredicate(getUriResourceEntitySet()
+ .getKeyPredicates()));
+ String navPath = buildNavPath(helper, getEntitySet().getEntityType(), getNavigations(), true);
+ if (navPath != null && !navPath.isEmpty()) {
+ builder.navOrPropertyPath(navPath+"/"+edmProperty.getName());
+ } else {
+ builder.navOrPropertyPath(edmProperty.getName());
+ }
+ if (isPropertyComplex()) {
+ EdmComplexType type = ((UriResourceComplexProperty) uriResourceProperty).getComplexType();
+ String select = helper.buildContextURLSelectList(type, getUriInfo().getExpandOption(),
+ getUriInfo().getSelectOption());
+ builder.selectList(select);
+ }
+ return builder.build();
+ }
+ }
+
+ class ValueRequest extends PropertyRequest {
+
+ @Override
+ public boolean allowedMethod() {
+ //part2-url-conventions # 4.2
+ if (isPropertyStream() && isGET()) {
+ return false;
+ }
+
+ return isGET() || isDELETE() || isPUT();
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ RepresentationType valueRepresentationType = uriResourceProperty.getType() == EdmPrimitiveTypeFactory
+ .getInstance(EdmPrimitiveTypeKind.Binary) ? RepresentationType.BINARY
+ : RepresentationType.VALUE;
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request,
+ getCustomContentTypeSupport(), valueRepresentationType);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ EdmProperty edmProperty = getUriResourceProperty().getProperty();
+ if (isGET()) {
+ handler.read(DataRequest.this, PrimitiveValueResponse.getInstance(DataRequest.this,
+ response, isCollection(), getUriResourceProperty().getProperty()));
+ } else if (isDELETE()) {
+ Property property = new PropertyImpl();
+ property.setName(edmProperty.getName());
+ property.setType(edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString());
+
+ PropertyResponse propertyResponse = PropertyResponse.getInstance(DataRequest.this, response,
+ edmProperty.getType(), getContextURL(odata), edmProperty.isCollection());
+ handler.updateProperty(DataRequest.this, property, false, getETag(), propertyResponse);
+ } else if (isPUT()) {
+ PropertyResponse propertyResponse = PropertyResponse.getInstance(DataRequest.this, response,
+ edmProperty.getType(), getContextURL(odata), edmProperty.isCollection());
+ handler.updateProperty(DataRequest.this, getPropertyValueFromClient(edmProperty), false,
+ getETag(), propertyResponse);
+ }
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ return null;
+ }
+ }
+
+ class SingletonRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ return isGET();
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), getODataRequest(),
+ getCustomContentTypeSupport(), RepresentationType.ENTITY);
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ final UriHelper helper = odata.createUriHelper();
+ ContextURL.Builder builder = buildEntitySetContextURL(helper,
+ uriResourceSingleton.getSingleton(), null, getUriInfo(), getNavigations(), isCollection(), true);
+ return builder.build();
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ handler.read(DataRequest.this,
+ EntityResponse.getInstance(DataRequest.this, getContextURL(odata), false, response));
+ }
+ }
+
+ class CrossJoinRequest implements RequestType {
+ private final List<String> entitySetNames;
+
+ public CrossJoinRequest(List<String> entitySetNames) {
+ this.entitySetNames = entitySetNames;
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ return isGET();
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(getUriInfo().getFormatOption(),
+ getODataRequest(), getCustomContentTypeSupport(), RepresentationType.COLLECTION_COMPLEX);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ handler.crossJoin(DataRequest.this, this.entitySetNames, response);
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ ContextURL.Builder builder = ContextURL.with().asCollection();
+ return builder.build();
+ }
+ }
+
+ private org.apache.olingo.commons.api.data.Property getPropertyValueFromClient(
+ EdmProperty edmProperty) throws DeserializerException {
+ // TODO:this is not right, we should be deserializing the property
+ // (primitive, complex, collection of)
+ // for now it is responsibility of the user
+ ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
+ .fromContentType(getRequestContentType()));
+ return deserializer.property(getODataRequest().getBody(), edmProperty);
+ }
+
+ static ContextURL.Builder buildEntitySetContextURL(UriHelper helper,
+ EdmBindingTarget edmEntitySet, List<UriParameter> keyPredicates, UriInfo uriInfo,
+ LinkedList<UriResourceNavigation> navigations, boolean collectionReturn, boolean singleton)
+ throws SerializerException {
+
+ ContextURL.Builder builder = ContextURL.with().entitySetOrSingletonOrType(edmEntitySet.getName());
+ String select = helper.buildContextURLSelectList(edmEntitySet.getEntityType(),
+ uriInfo.getExpandOption(), uriInfo.getSelectOption());
+ if (!singleton) {
+ builder.suffix(collectionReturn ? null : Suffix.ENTITY);
+ }
+
+ builder.selectList(select);
+
+ final UriInfoResource resource = uriInfo.asUriInfoResource();
+ final List<UriResource> resourceParts = resource.getUriResourceParts();
+ final List<String> path = getPropertyPath(resourceParts);
+ String propertyPath = buildPropertyPath(path);
+ final String navPath = buildNavPath(helper, edmEntitySet.getEntityType(), navigations, collectionReturn);
+ if (navPath != null && !navPath.isEmpty()) {
+ if (keyPredicates != null) {
+ builder.keyPath(helper.buildContextURLKeyPredicate(keyPredicates));
+ }
+ if (propertyPath != null) {
+ propertyPath = navPath+"/"+propertyPath;
+ } else {
+ propertyPath = navPath;
+ }
+ }
+ builder.navOrPropertyPath(propertyPath);
+ return builder;
+ }
+
+ private static List<String> getPropertyPath(final List<UriResource> path) {
+ List<String> result = new LinkedList<String>();
+ int index = 1;
+ while (index < path.size() && path.get(index) instanceof UriResourceProperty) {
+ result.add(((UriResourceProperty) path.get(index)).getProperty().getName());
+ index++;
+ }
+ return result;
+ }
+
+ private static String buildPropertyPath(final List<String> path) {
+ StringBuilder result = new StringBuilder();
+ for (final String segment : path) {
+ result.append(result.length() == 0 ? "" : '/').append(segment); //$NON-NLS-1$
+ }
+ return result.length() == 0?null:result.toString();
+ }
+
+ static String buildNavPath(UriHelper helper, EdmEntityType rootType,
+ LinkedList<UriResourceNavigation> navigations, boolean includeLastPredicates)
+ throws SerializerException {
+ if (navigations.isEmpty()) {
+ return null;
+ }
+ StringBuilder sb = new StringBuilder();
+ boolean containsTarget = false;
+ EdmEntityType type = rootType;
+ for (UriResourceNavigation nav:navigations) {
+ String name = nav.getProperty().getName();
+ EdmNavigationProperty property = type.getNavigationProperty(name);
+ if (property.containsTarget()) {
+ containsTarget = true;
+ }
+ type = nav.getProperty().getType();
+ }
+
+ if (containsTarget) {
+ for (int i = 0; i < navigations.size(); i++) {
+ UriResourceNavigation nav = navigations.get(i);
+ if (i > 0) {
+ sb.append("/");
+ }
+ sb.append(nav.getProperty().getName());
+
+ boolean skipKeys = false;
+ if (navigations.size() == i+1 && !includeLastPredicates ) {
+ skipKeys = true;
+ }
+
+ if (!skipKeys && !nav.getKeyPredicates().isEmpty()) {
+ sb.append("(");
+ sb.append(helper.buildContextURLKeyPredicate(nav.getKeyPredicates()));
+ sb.append(")");
+ }
+
+ if (nav.getTypeFilterOnCollection() != null) {
+ sb.append("/")
+ .append(nav.getTypeFilterOnCollection().getFullQualifiedName().getFullQualifiedNameAsString());
+ } else if (nav.getTypeFilterOnEntry() != null) {
+ sb.append("/")
+ .append(nav.getTypeFilterOnEntry().getFullQualifiedName().getFullQualifiedNameAsString());
+ }
+ }
+ }
+ return sb.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/FunctionRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/FunctionRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/FunctionRequest.java
new file mode 100644
index 0000000..a9f9341
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/FunctionRequest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.requests;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+
+public class FunctionRequest extends OperationRequest {
+ private UriResourceFunction uriResourceFunction;
+
+ public FunctionRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+
+ // Functions always have return per 11.5.3
+ if (isReturnTypePrimitive()) {
+ // functions can not return a typed property in the context of entity, so
+ // it must be treated
+ // as value based response
+ handler.invoke(this, getODataRequest().getMethod(),
+ PrimitiveValueResponse.getInstance(this, response, isCollection(), getReturnType()));
+ } else if (isReturnTypeComplex()) {
+ handler.invoke(this, getODataRequest().getMethod(), PropertyResponse.getInstance(this, response,
+ getReturnType().getType(), getContextURL(this.odata), isCollection()));
+ } else {
+ // returnType.getType().getKind() == EdmTypeKind.ENTITY
+ if (isCollection()) {
+ handler.invoke(this, getODataRequest().getMethod(),
+ EntitySetResponse.getInstance(this, getContextURL(odata), false, response));
+ } else {
+ handler.invoke(this, getODataRequest().getMethod(),
+ EntityResponse.getInstance(this, getContextURL(odata), false, response));
+ }
+ }
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ // look for discussion about composable functions in odata-discussion
+ // group with thread "Clarification on "Function" invocations"
+ if (getFunction().isComposable()) {
+ return (isGET() || isPATCH() || isDELETE() || isPOST() || isPUT());
+ }
+ return isGET();
+ }
+
+ public UriResourceFunction getUriResourceFunction() {
+ return uriResourceFunction;
+ }
+
+ public void setUriResourceFunction(UriResourceFunction uriResourceFunction) {
+ this.uriResourceFunction = uriResourceFunction;
+ }
+
+ @Override
+ public boolean isBound() {
+ return this.uriResourceFunction.getFunctionImport() != null;
+ }
+
+ public EdmFunction getFunction() {
+ return this.uriResourceFunction.getFunction();
+ }
+
+ public List<UriParameter> getParameters() {
+ return this.uriResourceFunction.getParameters();
+ }
+
+ @Override
+ public boolean isCollection() {
+ return getFunction().getReturnType().isCollection();
+ }
+
+ @Override
+ public EdmReturnType getReturnType() {
+ return getFunction().getReturnType();
+ }
+
+ @Override
+ public boolean hasReturnType() {
+ // Part3 {12.1} says must have return type
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MediaRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MediaRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MediaRequest.java
new file mode 100644
index 0000000..a4a333a
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MediaRequest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.requests;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public class MediaRequest extends ServiceRequest {
+ private UriResourceEntitySet uriResourceEntitySet;
+
+ public MediaRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+ // POST will not be here, because the media is created as part of media
+ // entity creation
+ if (isGET()) {
+ handler.readMediaStream(this, new StreamResponse(getServiceMetaData(), response));
+ } else if (isPUT()) {
+ handler.upsertMediaStream(this, getETag(), getMediaStream(), new NoContentResponse(
+ getServiceMetaData(), response));
+ } else if (isDELETE()) {
+ handler.upsertMediaStream(this, getETag(), null, new NoContentResponse(getServiceMetaData(),
+ response));
+ }
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ // the request must specify the content type requested.
+ return getRequestContentType();
+ }
+
+ public EdmEntitySet getEntitySet() {
+ return this.uriResourceEntitySet.getEntitySet();
+ }
+
+ public EdmEntityType getEntityType() {
+ return this.uriResourceEntitySet.getEntitySet().getEntityType();
+ }
+
+ public void setUriResourceEntitySet(UriResourceEntitySet uriResourceEntitySet) {
+ this.uriResourceEntitySet = uriResourceEntitySet;
+ }
+
+ public List<UriParameter> getKeyPredicates() {
+ if (this.uriResourceEntitySet != null) {
+ return this.uriResourceEntitySet.getKeyPredicates();
+ }
+ return null;
+ }
+
+ private InputStream getMediaStream() {
+ return this.request.getBody();
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ return isGET() || isPUT() || isDELETE();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MetadataRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MetadataRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MetadataRequest.java
new file mode 100644
index 0000000..e2c5c54
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MetadataRequest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.requests;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.api.uri.UriInfoMetadata;
+import org.apache.olingo.server.core.ContentNegotiator;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+
+public class MetadataRequest extends ServiceRequest {
+
+ public MetadataRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(this.uriInfo.getFormatOption(), this.request,
+ this.customContentType, RepresentationType.METADATA);
+ }
+
+ public UriInfoMetadata getUriInfoMetadata() {
+ return uriInfo.asUriInfoMetadata();
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+
+ handler.readMetadata(this, MetadataResponse.getInstance(this, response));
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/OperationRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/OperationRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/OperationRequest.java
new file mode 100644
index 0000000..1f1b194
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/OperationRequest.java
@@ -0,0 +1,118 @@
+/*
+ * 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.requests;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.uri.UriHelper;
+import org.apache.olingo.server.core.ContentNegotiator;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public abstract class OperationRequest extends ServiceRequest {
+
+ public OperationRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ if (!hasReturnType()) {
+ // this default content type
+ return ContentType.APPLICATION_OCTET_STREAM;
+ }
+
+ if (isReturnTypePrimitive()) {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), this.request,
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_PRIMITIVE
+ : RepresentationType.PRIMITIVE);
+ } else if (isReturnTypeComplex()) {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), this.request,
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_COMPLEX
+ : RepresentationType.COMPLEX);
+ } else {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), this.request,
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_ENTITY
+ : RepresentationType.ENTITY);
+ }
+ }
+
+ public abstract boolean isBound();
+
+ public abstract boolean isCollection();
+
+ public abstract EdmReturnType getReturnType();
+
+ public abstract boolean hasReturnType();
+
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ if (!hasReturnType()) {
+ return null;
+ }
+
+ final UriHelper helper = odata.createUriHelper();
+
+ if (isReturnTypePrimitive() || isReturnTypeComplex()) {
+ // Part 1 {10.14, 10.14} since the function return properties does not
+ // represent a Entity property
+ ContextURL.Builder builder = ContextURL.with().type(getReturnType().getType());
+ if (isCollection()) {
+ builder.asCollection();
+ }
+ return builder.build();
+ }
+
+ /*
+ // EdmTypeKind.ENTITY;
+ if (isBound()) {
+ // Bound means, we know the EnitySet of the return type. Part 1 {10.2,
+ // 10.3}
+ EdmEntitySet entitySet = this.uriResourceFunction.getFunctionImport().getReturnedEntitySet();
+ ContextURL.Builder builder = DataRequest.buildEntitySetContextURL(helper, entitySet,
+ this.uriInfo, isCollection(), false);
+ return builder.build();
+ }
+ */
+
+ // EdmTypeKind.ENTITY; Not Bound
+ // Here we do not know the EntitySet, then follow directions from
+ // Part-1{10.2. 10.3} to use
+ // {context-url}#{type-name}
+ ContextURL.Builder builder = ContextURL.with().type(getReturnType().getType());
+ if (isCollection()) {
+ builder.asCollection();
+ }
+ return builder.build();
+ }
+
+ public boolean isReturnTypePrimitive() {
+ return getReturnType().getType().getKind() == EdmTypeKind.PRIMITIVE;
+ }
+
+ public boolean isReturnTypeComplex() {
+ return getReturnType().getType().getKind() == EdmTypeKind.COMPLEX;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ServiceDocumentRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ServiceDocumentRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ServiceDocumentRequest.java
new file mode 100644
index 0000000..f99aaf5
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ServiceDocumentRequest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.requests;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.core.ContentNegotiator;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.responses.ServiceDocumentResponse;
+
+public class ServiceDocumentRequest extends ServiceRequest {
+
+ public ServiceDocumentRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(getUriInfo().getFormatOption(),
+ getODataRequest(), getCustomContentTypeSupport(), RepresentationType.SERVICE);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+ handler.readServiceDocument(this,
+ ServiceDocumentResponse.getInstace(this, response, getResponseContentType()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/CountResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/CountResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/CountResponse.java
new file mode 100644
index 0000000..f7cde33
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/CountResponse.java
@@ -0,0 +1,60 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.http.HttpContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.FixedFormatSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class CountResponse extends ServiceResponse {
+ private final FixedFormatSerializer serializer;
+
+ public static CountResponse getInstance(ServiceRequest request, ODataResponse response) {
+ FixedFormatSerializer serializer = request.getOdata().createFixedFormatSerializer();
+ return new CountResponse(request.getServiceMetaData(), serializer, response,
+ request.getPreferences());
+ }
+
+ private CountResponse(ServiceMetadata metadata, FixedFormatSerializer serializer,
+ ODataResponse response, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ }
+
+ public void writeCount(int count) throws SerializerException {
+ assert (!isClosed());
+
+ this.response.setContent(this.serializer.count(count));
+ writeOK(HttpContentType.TEXT_PLAIN);
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
new file mode 100644
index 0000000..fd29bbd
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
@@ -0,0 +1,140 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ReturnRepresentation;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class EntityResponse extends ServiceResponse {
+ private final ReturnRepresentation returnRepresentation;
+ private final ODataSerializer serializer;
+ private final EntitySerializerOptions options;
+ private final ContentType responseContentType;
+
+ private EntityResponse(ServiceMetadata metadata, ODataResponse response,
+ ODataSerializer serializer, EntitySerializerOptions options, ContentType responseContentType,
+ Map<String, String> preferences, ReturnRepresentation returnRepresentation) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.options = options;
+ this.responseContentType = responseContentType;
+ this.returnRepresentation = returnRepresentation;
+ }
+
+ public static EntityResponse getInstance(ServiceRequest request, ContextURL contextURL,
+ boolean references, ODataResponse response, ReturnRepresentation returnRepresentation)
+ throws ContentNegotiatorException, SerializerException {
+ EntitySerializerOptions options = request.getSerializerOptions(EntitySerializerOptions.class,
+ contextURL, references);
+ return new EntityResponse(request.getServiceMetaData(), response, request.getSerializer(),
+ options, request.getResponseContentType(), request.getPreferences(), returnRepresentation);
+ }
+
+ public static EntityResponse getInstance(ServiceRequest request, ContextURL contextURL,
+ boolean references, ODataResponse response)
+ throws ContentNegotiatorException, SerializerException {
+ EntitySerializerOptions options = request.getSerializerOptions(EntitySerializerOptions.class,
+ contextURL, references);
+ return new EntityResponse(request.getServiceMetaData(), response, request.getSerializer(),
+ options, request.getResponseContentType(), request.getPreferences(), null);
+ }
+
+ // write single entity
+ public void writeReadEntity(EdmEntityType entityType, Entity entity) throws SerializerException {
+
+ assert (!isClosed());
+
+ if (entity == null) {
+ writeNotFound(true);
+ return;
+ }
+
+ // write the entity to response
+ this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options));
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ public void writeCreatedEntity(EdmEntityType entityType, Entity entity, String locationHeader)
+ throws SerializerException {
+ // upsert/insert must created a entity, otherwise should have throw an
+ // exception
+ assert (entity != null);
+
+ // Note that if media written just like Stream, but on entity URL
+
+ // 8.2.8.7
+ if (this.returnRepresentation == ReturnRepresentation.MINIMAL) {
+ writeNoContent(false);
+ writeHeader(HttpHeader.LOCATION, locationHeader);
+ writeHeader("Preference-Applied", "return=minimal"); //$NON-NLS-1$ //$NON-NLS-2$
+ // 8.3.3
+ writeHeader("OData-EntityId", entity.getId().toASCIIString()); //$NON-NLS-1$
+ close();
+ return;
+ }
+
+ // return the content of the created entity
+ this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options));
+ writeCreated(false);
+ writeHeader(HttpHeader.LOCATION, locationHeader);
+ writeHeader("Preference-Applied", "return=representation"); //$NON-NLS-1$ //$NON-NLS-2$
+ writeHeader(HttpHeader.CONTENT_TYPE, this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ public void writeUpdatedEntity() {
+ // spec says just success response; so either 200 or 204. 200 typically has
+ // payload
+ writeNoContent(true);
+ }
+
+ public void writeDeletedEntityOrReference() {
+ writeNoContent(true);
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+
+ public void writeCreated(boolean closeResponse) {
+ this.response.setStatusCode(HttpStatusCode.CREATED.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
new file mode 100644
index 0000000..40276d2
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
@@ -0,0 +1,82 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class EntitySetResponse extends ServiceResponse {
+ private final ODataSerializer serializer;
+ private final EntityCollectionSerializerOptions options;
+ private final ContentType responseContentType;
+
+ private EntitySetResponse(ServiceMetadata metadata, ODataResponse response, ODataSerializer serializer,
+ EntityCollectionSerializerOptions options,
+ ContentType responseContentType, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.options = options;
+ this.responseContentType = responseContentType;
+ }
+
+ public static EntitySetResponse getInstance(ServiceRequest request, ContextURL contextURL,
+ boolean referencesOnly, ODataResponse response) throws ContentNegotiatorException, SerializerException {
+ EntityCollectionSerializerOptions options = request.getSerializerOptions(
+ EntityCollectionSerializerOptions.class, contextURL, referencesOnly);
+ return new EntitySetResponse(request.getServiceMetaData(),response, request.getSerializer(), options,
+ request.getResponseContentType(), request.getPreferences());
+ }
+
+ // write collection of entities
+ // TODO: server paging needs to be implemented.
+ public void writeReadEntitySet(EdmEntityType entityType, EntitySet entitySet)
+ throws SerializerException {
+
+ assert (!isClosed());
+
+ if (entitySet == null) {
+ writeNotFound(true);
+ return;
+ }
+
+ // write the whole collection to response
+ this.response.setContent(this.serializer.entityCollection(metadata, entityType, entitySet, this.options));
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
new file mode 100644
index 0000000..055c0b0
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
@@ -0,0 +1,62 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class MetadataResponse extends ServiceResponse {
+ private final ODataSerializer serializer;
+ private final ContentType responseContentType;
+
+ public static MetadataResponse getInstance(ServiceRequest request,
+ ODataResponse response) throws ContentNegotiatorException, SerializerException {
+ return new MetadataResponse(request.getServiceMetaData(), response, request.getSerializer(),
+ request.getResponseContentType(), request.getPreferences());
+ }
+
+ private MetadataResponse(ServiceMetadata metadata, ODataResponse response, ODataSerializer serializer,
+ ContentType responseContentType, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.responseContentType = responseContentType;
+ }
+
+ public void writeMetadata()throws ODataTranslatedException {
+ assert (!isClosed());
+ this.response.setContent(this.serializer.metadataDocument(this.metadata));
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/NoContentResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/NoContentResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/NoContentResponse.java
new file mode 100644
index 0000000..eb16365
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/NoContentResponse.java
@@ -0,0 +1,100 @@
+/*
+ * 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.responses;
+
+import java.util.Collections;
+
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+
+public class NoContentResponse extends ServiceResponse {
+
+ public NoContentResponse(ServiceMetadata metadata, ODataResponse response) {
+ super(metadata, response, Collections.EMPTY_MAP);
+ }
+
+ // 200
+ public void writeOK() {
+ this.response.setStatusCode(HttpStatusCode.OK.getStatusCode());
+ close();
+ }
+
+ // 201
+ public void writeCreated() {
+ this.response.setStatusCode(HttpStatusCode.CREATED.getStatusCode());
+ close();
+ }
+
+ // 202
+ public void writeAccepted() {
+ this.response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
+ close();
+ }
+
+ // 204
+ public void writeNoContent() {
+ writeNoContent(true);
+ }
+
+ // 304
+ public void writeNotModified() {
+ this.response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
+ close();
+ }
+
+ // error response codes
+
+ // 404
+ public void writeNotFound() {
+ writeNotFound(true);
+ }
+
+ // 501
+ public void writeNotImplemented() {
+ this.response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
+ close();
+ }
+
+ // 405
+ public void writeMethodNotAllowed() {
+ this.response.setStatusCode(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode());
+ close();
+ }
+
+ // 410
+ public void writeGone() {
+ this.response.setStatusCode(HttpStatusCode.GONE.getStatusCode());
+ close();
+ }
+
+ // 412
+ public void writePreConditionFailed() {
+ this.response.setStatusCode(HttpStatusCode.PRECONDITION_FAILED.getStatusCode());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PrimitiveValueResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PrimitiveValueResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PrimitiveValueResponse.java
new file mode 100644
index 0000000..005bfca
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PrimitiveValueResponse.java
@@ -0,0 +1,105 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.commons.api.http.HttpContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.FixedFormatSerializer;
+import org.apache.olingo.server.api.serializer.PrimitiveValueSerializerOptions;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class PrimitiveValueResponse extends ServiceResponse {
+ private final boolean returnCollection;
+ private EdmProperty type;
+ private EdmReturnType returnType;
+ private final FixedFormatSerializer serializer;
+
+ public static PrimitiveValueResponse getInstance(ServiceRequest request, ODataResponse response,
+ boolean collection, EdmProperty type) {
+ FixedFormatSerializer serializer = request.getOdata().createFixedFormatSerializer();
+ return new PrimitiveValueResponse(request.getServiceMetaData(), serializer, response,
+ collection, type, request.getPreferences());
+ }
+
+ public static PrimitiveValueResponse getInstance(ServiceRequest request, ODataResponse response,
+ boolean collection, EdmReturnType type) {
+ FixedFormatSerializer serializer = request.getOdata().createFixedFormatSerializer();
+ return new PrimitiveValueResponse(request.getServiceMetaData(), serializer, response,
+ collection, type, request.getPreferences());
+ }
+
+ private PrimitiveValueResponse(ServiceMetadata metadata, FixedFormatSerializer serializer,
+ ODataResponse response, boolean collection, EdmProperty type, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.returnCollection = collection;
+ this.type = type;
+ this.serializer = serializer;
+ }
+
+ private PrimitiveValueResponse(ServiceMetadata metadata, FixedFormatSerializer serializer,
+ ODataResponse response, boolean collection, EdmReturnType type,
+ Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.returnCollection = collection;
+ this.returnType = type;
+ this.serializer = serializer;
+ }
+
+ public void write(Object value) throws SerializerException {
+ if (value == null) {
+ writeNoContent(true);
+ return;
+ }
+
+ if (this.type != null) {
+ PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with()
+ .facetsFrom(this.type).build();
+
+ this.response.setContent(this.serializer.primitiveValue((EdmPrimitiveType) this.type.getType(),
+ value, options));
+ } else {
+ PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with()
+ .nullable(this.returnType.isNullable()).maxLength(this.returnType.getMaxLength())
+ .precision(this.returnType.getPrecision()).scale(this.returnType.getScale()).build();
+ this.response.setContent(this.serializer.primitiveValue(
+ (EdmPrimitiveType) this.returnType.getType(), value, options));
+ }
+
+ writeOK(HttpContentType.TEXT_PLAIN);
+ }
+
+ public boolean isReturnCollection() {
+ return returnCollection;
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
new file mode 100644
index 0000000..e6b951d
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
@@ -0,0 +1,144 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class PropertyResponse extends ServiceResponse {
+ private PrimitiveSerializerOptions primitiveOptions;
+ private ComplexSerializerOptions complexOptions;
+ private final ContentType responseContentType;
+ private final ODataSerializer serializer;
+ private final boolean collection;
+
+ public static PropertyResponse getInstance(ServiceRequest request, ODataResponse response,
+ EdmType edmType, ContextURL contextURL, boolean collection) throws ContentNegotiatorException,
+ SerializerException {
+ if (edmType.getKind() == EdmTypeKind.PRIMITIVE) {
+ PrimitiveSerializerOptions options = request.getSerializerOptions(
+ PrimitiveSerializerOptions.class, contextURL, false);
+ ContentType type = request.getResponseContentType();
+ return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response,
+ options, type, collection, request.getPreferences());
+ }
+ ComplexSerializerOptions options = request.getSerializerOptions(ComplexSerializerOptions.class,
+ contextURL, false);
+ ContentType type = request.getResponseContentType();
+ return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response,
+ options, type, collection, request.getPreferences());
+ }
+
+ private PropertyResponse(ServiceMetadata metadata, ODataSerializer serializer,
+ ODataResponse response, PrimitiveSerializerOptions options, ContentType contentType,
+ boolean collection, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.primitiveOptions = options;
+ this.responseContentType = contentType;
+ this.collection = collection;
+ }
+
+ private PropertyResponse(ServiceMetadata metadata, ODataSerializer serializer, ODataResponse response,
+ ComplexSerializerOptions options, ContentType contentType, boolean collection,
+ Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.complexOptions = options;
+ this.responseContentType = contentType;
+ this.collection = collection;
+ }
+
+ public void writeProperty(EdmType edmType, Property property) throws SerializerException {
+ assert (!isClosed());
+
+ if (property == null) {
+ writeNotFound(true);
+ return;
+ }
+
+ if (property.getValue() == null) {
+ writeNoContent(true);
+ return;
+ }
+
+ if (edmType.getKind() == EdmTypeKind.PRIMITIVE) {
+ writePrimitiveProperty((EdmPrimitiveType) edmType, property);
+ } else {
+ writeComplexProperty((EdmComplexType) edmType, property);
+ }
+ }
+
+ private void writeComplexProperty(EdmComplexType type, Property property)
+ throws SerializerException {
+ if (this.collection) {
+ this.response.setContent(this.serializer.complexCollection(this.metadata, type, property,
+ this.complexOptions));
+ } else {
+ this.response.setContent(this.serializer.complex(this.metadata, type, property,
+ this.complexOptions));
+ }
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ private void writePrimitiveProperty(EdmPrimitiveType type, Property property)
+ throws SerializerException {
+ if(this.collection) {
+ this.response.setContent(this.serializer.primitiveCollection(type, property, this.primitiveOptions));
+ } else {
+ this.response.setContent(this.serializer.primitive(type, property, this.primitiveOptions));
+ }
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+
+ public void writePropertyUpdated() {
+ // spec says just success response; so either 200 or 204. 200 typically has
+ // payload
+ writeNoContent(true);
+ }
+
+ public void writePropertyDeleted() {
+ writeNoContent(true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
new file mode 100644
index 0000000..86c420b
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
@@ -0,0 +1,63 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class ServiceDocumentResponse extends ServiceResponse {
+ private final ODataSerializer serializer;
+ private final ContentType responseContentType;
+
+ public static ServiceDocumentResponse getInstace(ServiceRequest request, ODataResponse respose,
+ ContentType responseContentType) throws ContentNegotiatorException, SerializerException {
+ return new ServiceDocumentResponse(request.getServiceMetaData(), respose,
+ request.getSerializer(), responseContentType, request.getPreferences());
+ }
+
+ private ServiceDocumentResponse(ServiceMetadata metadata, ODataResponse respose,
+ ODataSerializer serializer, ContentType responseContentType, Map<String, String> preferences) {
+ super(metadata, respose, preferences);
+ this.serializer = serializer;
+ this.responseContentType = responseContentType;
+ }
+
+ public void writeServiceDocument(String serviceRoot)
+ throws ODataTranslatedException {
+ assert (!isClosed());
+ this.response.setContent(this.serializer.serviceDocument(this.metadata.getEdm(), serviceRoot));
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
[38/50] [abbrv] olingo-odata4 git commit: [OLINGO-603] Action
Parameter deserialization based on type kind
Posted by ch...@apache.org.
[OLINGO-603] Action Parameter deserialization based on type kind
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/ef6ed4e3
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/ef6ed4e3
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/ef6ed4e3
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: ef6ed4e3efea2464faa5c08bdffad6f50bf2cccd
Parents: 26be7d2
Author: Christian Amend <ch...@apache.org>
Authored: Wed Apr 1 10:18:52 2015 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Apr 1 14:29:02 2015 +0200
----------------------------------------------------------------------
.../commons/api/edm/constants/EdmTypeKind.java | 2 +-
.../api/deserializer/DeserializerException.java | 4 +++-
.../json/ODataJsonDeserializer.java | 20 ++++++++++++++++----
.../server-core-exceptions-i18n.properties | 2 ++
.../core/edm/provider/EdmTypeImplTest.java | 4 ++--
5 files changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef6ed4e3/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/EdmTypeKind.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/EdmTypeKind.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/EdmTypeKind.java
index bf24673..b55ec16 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/EdmTypeKind.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/constants/EdmTypeKind.java
@@ -23,6 +23,6 @@ package org.apache.olingo.commons.api.edm.constants;
*/
public enum EdmTypeKind {
- UNDEFINED, PRIMITIVE, ENUM, DEFINITION, COMPLEX, ENTITY, NAVIGATION, ACTION, FUNCTION, SYSTEM
+ PRIMITIVE, ENUM, DEFINITION, COMPLEX, ENTITY, NAVIGATION, ACTION, FUNCTION
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef6ed4e3/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerException.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerException.java
index 8ccb253..1989df1 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerException.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/DeserializerException.java
@@ -45,7 +45,9 @@ public class DeserializerException extends ODataTranslatedException {
/** parameter: navigationPropertyName */NAVIGATION_PROPERTY_NOT_FOUND,
/** parameter: annotationName */INVALID_ANNOTATION_TYPE,
/** parameter: annotationName */INVALID_NULL_ANNOTATION,
- /** parameter: binding link */INVALID_ENTITY_BINDING_LINK;
+ /** parameter: binding link */INVALID_ENTITY_BINDING_LINK,
+ /** parameter: action parameter name */INVALID_ACTION_PARAMETER_TYPE,
+ /** parameter: parameterName */ INVALID_NULL_PARAMETER;
@Override
public String getKey() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef6ed4e3/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index 74c73c8..b9fe770 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -215,13 +215,17 @@ public class ODataJsonDeserializer implements ODataDeserializer {
ParameterImpl parameter = new ParameterImpl();
parameter.setName(name);
JsonNode jsonNode = node.get(name);
- if (jsonNode == null) {
+ if (jsonNode == null || jsonNode.isNull()) {
if (!edmParameter.isNullable()) {
- // TODO: new message key.
throw new DeserializerException("Non-nullable parameter not present or null",
- DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, name);
+ DeserializerException.MessageKeys.INVALID_NULL_PARAMETER, name);
}
- } else {
+ }
+
+ switch (edmParameter.getType().getKind()) {
+ case PRIMITIVE:
+ case DEFINITION:
+ case ENUM:
Property consumePropertyNode =
consumePropertyNode(edmParameter.getName(), edmParameter.getType(), edmParameter.isCollection(),
edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter
@@ -231,6 +235,14 @@ public class ODataJsonDeserializer implements ODataDeserializer {
parameter.setValue(consumePropertyNode.getValueType(), consumePropertyNode.getValue());
parameters.add(parameter);
node.remove(name);
+ break;
+ case COMPLEX:
+ case ENTITY:
+ throw new DeserializerException("Entity an complex parameters currently not Implemented",
+ DeserializerException.MessageKeys.NOT_IMPLEMENTED);
+ default:
+ throw new DeserializerException("Invalid type kind " + edmParameter.getType().getKind().toString()
+ + " for action parameter: " + name, DeserializerException.MessageKeys.INVALID_ACTION_PARAMETER_TYPE, name);
}
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef6ed4e3/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index 76266ea..71013d2 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -115,6 +115,8 @@ DeserializerException.UNKNOWN_PRIMITIVE_TYPE=Unknown primitive type '%1$s' for p
DeserializerException.NAVIGATION_PROPERTY_NOT_FOUND=Can`t find navigation property with name: '%1$s'.
DeserializerException.INVALID_ANNOTATION_TYPE=The annotation '%1$s' has the wrong JSON type.
DeserializerException.INVALID_ENTITY_BINDING_LINK=The binding link '%1$s' is malformed.
+DeserializerException.INVALID_ACTION_PARAMETER_TYPE=The action parameter '%1$s' must be either primitive, complex or an entity or a collection of those types.
+DeserializerException.INVALID_NULL_PARAMETER=The parameter '%1$s' must not be null.
BatchDeserializerException.INVALID_BOUNDARY=Invalid boundary at line '%1$s'.
BatchDeserializerException.INVALID_CHANGESET_METHOD=Invalid method: a ChangeSet cannot contain retrieve requests at line '%1$s'.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ef6ed4e3/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
index ddfd15d..b9f6db6 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
@@ -37,10 +37,10 @@ public class EdmTypeImplTest {
@Test
public void getterTest() {
- EdmType type = new EdmTypeImplTester(new FullQualifiedName("namespace", "name"), EdmTypeKind.UNDEFINED);
+ EdmType type = new EdmTypeImplTester(new FullQualifiedName("namespace", "name"), EdmTypeKind.PRIMITIVE);
assertEquals("name", type.getName());
assertEquals("namespace", type.getNamespace());
- assertEquals(EdmTypeKind.UNDEFINED, type.getKind());
+ assertEquals(EdmTypeKind.PRIMITIVE, type.getKind());
EdmAnnotatable an = (EdmAnnotatable) type;
assertNotNull(an.getAnnotations().get(0));
}
[49/50] [abbrv] olingo-odata4 git commit: [OLINGO-616] Fix:
BatchReferenceRewriter
Posted by ch...@apache.org.
[OLINGO-616] Fix: BatchReferenceRewriter
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/97a01784
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/97a01784
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/97a01784
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 97a017843249093d4c71838ea59d5a1d472140c5
Parents: 189de7b
Author: Christian Holzer <c....@sap.com>
Authored: Thu Apr 2 13:41:07 2015 +0200
Committer: Christian Holzer <ch...@t-online.de>
Committed: Fri Apr 3 12:42:03 2015 +0200
----------------------------------------------------------------------
.../fit/tecsvc/client/BatchClientITCase.java | 74 ++++++++++++++++++--
.../BatchReferenceRewriter.java | 3 +-
2 files changed, 69 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/97a01784/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
index ed249fd..a46644c 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
@@ -20,8 +20,8 @@ package org.apache.olingo.fit.tecsvc.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URI;
@@ -30,6 +30,7 @@ import java.util.HashMap;
import java.util.Iterator;
import org.apache.olingo.client.api.ODataBatchConstants;
+import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.request.batch.BatchManager;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
@@ -48,6 +49,7 @@ import org.apache.olingo.client.core.communication.request.batch.ODataChangesetR
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.domain.ODataEntity;
import org.apache.olingo.commons.api.domain.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.ODataObjectFactory;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ContentType;
@@ -62,6 +64,11 @@ import org.junit.Test;
public class BatchClientITCase extends AbstractTestITCase {
private final static String ACCEPT = ContentType.APPLICATION_OCTET_STREAM.toContentTypeString();
private static final String SERVICE_URI = TecSvcConst.BASE_URI;
+ private static final String SERVICE_NAMESPACE = "olingo.odata.test1";
+ private static final String ES_NOT_AVAILABLE_NAME = "ESNotAvailable";
+ private static final FullQualifiedName ES_NOT_AVAILABLE = new FullQualifiedName(SERVICE_NAMESPACE,
+ ES_NOT_AVAILABLE_NAME);
+ private static final String PROPERTY_STRING = "PropertyString";
@Before
public void setup() {
@@ -69,6 +76,59 @@ public class BatchClientITCase extends AbstractTestITCase {
}
@Test
+ public void testBadRequestInChangeSet() {
+ /*
+ * A bad request (status code >= 400) without "continue on error prefer header" in a changeset
+ * should return a single response with Content-Type: application/http
+ *
+ * See:
+ * OData Version 4.0 Part 1: Protocol Plus Errata 01
+ * 11.7.4 Responding to a Batch Request
+ *
+ * When a request within a change set fails, the change set response is not represented using
+ * the multipart/mixed media type. Instead, a single response, using the application/http media type
+ * and a Content-Transfer-Encoding header with a value of binary, is returned that applies to all requests
+ * in the change set and MUST be formatted according to the Error Handling defined
+ * for the particular response format.
+ */
+
+ final ODataClient client = getClient();
+ final ODataObjectFactory of = client.getObjectFactory();
+
+ // Try to create entity, with invalid type
+ final ODataEntity entity = of.newEntity(ES_NOT_AVAILABLE);
+ entity.getProperties().add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder()
+ .buildString("1")));
+ final ODataBatchRequest batchRequest = client.getBatchRequestFactory().getBatchRequest(SERVICE_URI);
+ batchRequest.setAccept(ACCEPT);
+ final BatchManager payloadManager = batchRequest.payloadManager();
+ final ODataChangeset changeset = payloadManager.addChangeset();
+ final URI targetURI = client.newURIBuilder(SERVICE_URI)
+ .appendEntitySetSegment(ES_NOT_AVAILABLE_NAME)
+ .build();
+ final ODataEntityCreateRequest<ODataEntity> createRequest = client.getCUDRequestFactory()
+ .getEntityCreateRequest(targetURI, entity);
+ changeset.addRequest(createRequest);
+
+ final ODataBatchResponse response = payloadManager.getResponse();
+ assertEquals(HttpStatusCode.ACCEPTED.getStatusCode(), response.getStatusCode());
+
+ // Check response items
+ final Iterator<ODataBatchResponseItem> responseBodyIter = response.getBody();
+ assertTrue(responseBodyIter.hasNext());
+
+ final ODataBatchResponseItem changeSetResponse = responseBodyIter.next();
+ assertTrue(changeSetResponse.isChangeset());
+ assertTrue(changeSetResponse.hasNext());
+
+ final ODataResponse updateResponse = changeSetResponse.next();
+ assertTrue(changeSetResponse.isBreaking());
+
+ assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), updateResponse.getStatusCode());
+ assertEquals(ODataFormat.JSON.toString(), updateResponse.getContentType());
+ }
+
+ @Test
public void emptyBatchRequest() {
// create your request
final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(SERVICE_URI);
@@ -191,7 +251,7 @@ public class BatchClientITCase extends AbstractTestITCase {
// Check if third request is available
assertFalse(iter.hasNext());
}
-
+
@Test
public void testInvalidAbsoluteUri() throws URISyntaxException {
final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(SERVICE_URI);
@@ -209,14 +269,14 @@ public class BatchClientITCase extends AbstractTestITCase {
final Iterator<ODataBatchResponseItem> bodyIterator = response.getBody();
assertTrue(bodyIterator.hasNext());
-
+
ODataBatchResponseItem item = bodyIterator.next();
assertFalse(item.isChangeset());
-
+
final ODataResponse oDataResponse = item.next();
assertEquals(400, oDataResponse.getStatusCode());
}
-
+
@Test
@Ignore
public void testInvalidHost() throws URISyntaxException {
@@ -233,7 +293,7 @@ public class BatchClientITCase extends AbstractTestITCase {
final ODataBatchResponse response = payload.getResponse();
assertEquals(400, response.getStatusCode());
}
-
+
@Test
@Ignore
public void testInvalidAbsoluteRequest() throws URISyntaxException {
@@ -250,7 +310,7 @@ public class BatchClientITCase extends AbstractTestITCase {
final ODataBatchResponse response = payload.getResponse();
assertEquals(400, response.getStatusCode());
}
-
+
@Test
public void testErrorWithContinueOnErrorPreferHeader() throws URISyntaxException {
client.getConfiguration().setContinueOnError(true);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/97a01784/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java
index 772fd9d..9f0429a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java
@@ -78,7 +78,8 @@ public class BatchReferenceRewriter {
if (request.getMethod() == HttpMethod.POST) {
// Create entity
// The URI of the new resource will be generated by the server and published in the location header
- resourceUri = parseODataPath(response.getHeaders().get(HttpHeader.LOCATION), request.getRawBaseUri());
+ final String locationHeader = response.getHeaders().get(HttpHeader.LOCATION);
+ resourceUri = locationHeader == null ? null : parseODataPath(locationHeader, request.getRawBaseUri());
} else {
// Update, Upsert (PUT, PATCH, Delete)
// These methods still addresses a given resource, so we use the URI given by the request
[14/50] [abbrv] olingo-odata4 git commit: [OLINGO-603]
deserialization of action parameters
Posted by ch...@apache.org.
[OLINGO-603] deserialization of action parameters
Change-Id: I49a0a39eb25eb34cf856d723c019afac304111f0
Signed-off-by: Christian Amend <ch...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/6d41513f
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/6d41513f
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/6d41513f
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 6d41513f47312ef168a2e2442e030953206681c1
Parents: 898d745
Author: Klaus Straubinger <kl...@sap.com>
Authored: Fri Mar 27 16:41:56 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Mar 27 16:46:07 2015 +0100
----------------------------------------------------------------------
.../api/deserializer/ODataDeserializer.java | 12 +-
.../json/ODataJsonDeserializer.java | 257 +++++++++++--------
.../processor/TechnicalEntityProcessor.java | 12 +-
.../server/tecsvc/provider/ActionProvider.java | 3 +-
...ataJsonDeserializerActionParametersTest.java | 85 ++++++
.../serializer/xml/MetadataDocumentTest.java | 2 +-
6 files changed, 265 insertions(+), 106 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d41513f/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
index 46567ae..d5f7343 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmEntityType;
/**
@@ -48,6 +49,13 @@ public interface ODataDeserializer {
*/
EntitySet entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
-
-
+ /**
+ * Deserializes an action-parameters stream into an {@link Entity} object.
+ * Validates: parameter types, no double parameters, correct json types.
+ * @param stream
+ * @param edmAction
+ * @return deserialized {@link Entity} object
+ * @throws DeserializerException
+ */
+ Entity actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d41513f/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index 4533c6a..a15d84a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -34,14 +34,18 @@ import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ValueType;
import org.apache.olingo.commons.api.domain.ODataLinkType;
+import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmMapping;
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmParameter;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.core.data.ComplexValueImpl;
import org.apache.olingo.commons.core.data.EntityImpl;
@@ -178,6 +182,51 @@ public class ODataJsonDeserializer implements ODataDeserializer {
return entity;
}
+ @Override
+ public Entity actionParameters(InputStream stream, final EdmAction edmAction) throws DeserializerException {
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
+ JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
+ ObjectNode tree = parser.getCodec().readTree(parser);
+ EntityImpl entity = new EntityImpl();
+ consumeParameters(edmAction, tree, entity);
+ assertJsonNodeIsEmpty(tree);
+ return entity;
+
+ } catch (final JsonParseException e) {
+ throw new DeserializerException("An JsonParseException occurred", e,
+ DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
+ } catch (final JsonMappingException e) {
+ throw new DeserializerException("Duplicate property detected", e,
+ DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
+ } catch (final IOException e) {
+ throw new DeserializerException("An IOException occurred", e,
+ DeserializerException.MessageKeys.IO_EXCEPTION);
+ }
+ }
+
+ private void consumeParameters(final EdmAction edmAction, ObjectNode node, EntityImpl entity)
+ throws DeserializerException {
+ for (final String name : edmAction.getParameterNames()) {
+ final EdmParameter parameter = edmAction.getParameter(name);
+ JsonNode jsonNode = node.get(name);
+ if (jsonNode == null) {
+ if (!parameter.isNullable()) {
+ // TODO: new message key.
+ throw new DeserializerException("Non-nullable parameter not present or null",
+ DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, name);
+ }
+ } else {
+ entity.addProperty(consumePropertyNode(parameter.getName(), parameter.getType(), parameter.isCollection(),
+ parameter.isNullable(), parameter.getMaxLength(), parameter.getPrecision(), parameter.getScale(),
+ true, parameter.getMapping(),
+ jsonNode));
+ node.remove(name);
+ }
+ }
+ }
+
/**
* Consume all remaining fields of Json ObjectNode and try to map found values
* to according Entity fields and omit to be ignored OData fields (e.g. control information).
@@ -188,8 +237,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
* @throws DeserializerException if an exception during consummation occurs
*/
private void consumeRemainingJsonNodeFields(final EdmEntityType edmEntityType, final ObjectNode node,
- final EntityImpl
- entity) throws DeserializerException {
+ final EntityImpl entity) throws DeserializerException {
final List<String> toRemove = new ArrayList<String>();
Iterator<Entry<String, JsonNode>> fieldsIterator = node.fields();
while (fieldsIterator.hasNext()) {
@@ -218,11 +266,15 @@ public class ODataJsonDeserializer implements ODataDeserializer {
JsonNode jsonNode = node.get(propertyName);
if (jsonNode != null) {
EdmProperty edmProperty = (EdmProperty) edmEntityType.getProperty(propertyName);
- if (jsonNode.isNull() && !isNullable(edmProperty)) {
+ if (jsonNode.isNull() && !edmProperty.isNullable()) {
throw new DeserializerException("Property: " + propertyName + " must not be null.",
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, propertyName);
}
- Property property = consumePropertyNode(edmProperty, jsonNode);
+ Property property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(),
+ edmProperty.isCollection(),
+ edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(),
+ edmProperty.isUnicode(), edmProperty.getMapping(),
+ jsonNode);
entity.addProperty(property);
node.remove(propertyName);
}
@@ -316,50 +368,56 @@ public class ODataJsonDeserializer implements ODataDeserializer {
}
}
- private Property consumePropertyNode(final EdmProperty edmProperty, final JsonNode jsonNode)
- throws DeserializerException {
+ private Property consumePropertyNode(final String name, final EdmType type, final boolean isCollection,
+ final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
+ final boolean isUnicode, final EdmMapping mapping, JsonNode jsonNode) throws DeserializerException {
Property property = new PropertyImpl();
- property.setName(edmProperty.getName());
- property.setType(edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString());
- if (edmProperty.isCollection()) {
- consumePropertyCollectionNode(edmProperty, jsonNode, property);
+ property.setName(name);
+ property.setType(type.getFullQualifiedName().getFullQualifiedNameAsString());
+ if (isCollection) {
+ consumePropertyCollectionNode(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
+ jsonNode, property);
} else {
- consumePropertySingleNode(edmProperty, jsonNode, property);
+ consumePropertySingleNode(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
+ jsonNode, property);
}
return property;
}
- private void consumePropertySingleNode(final EdmProperty edmProperty,
- final JsonNode jsonNode, final Property property)
+ private void consumePropertySingleNode(final String name, final EdmType type,
+ final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
+ final boolean isUnicode, final EdmMapping mapping, JsonNode jsonNode, Property property)
throws DeserializerException {
- switch (edmProperty.getType().getKind()) {
+ switch (type.getKind()) {
case PRIMITIVE:
- Object value = readPrimitiveValue(edmProperty, jsonNode);
+ Object value = readPrimitiveValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
+ jsonNode);
property.setValue(ValueType.PRIMITIVE, value);
break;
case DEFINITION:
- value = readTypeDefinitionValue(edmProperty, jsonNode);
+ value = readTypeDefinitionValue(name, type, isNullable, mapping, jsonNode);
property.setValue(ValueType.PRIMITIVE, value);
break;
case ENUM:
- value = readEnumValue(edmProperty, jsonNode);
+ value = readEnumValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
+ jsonNode);
property.setValue(ValueType.PRIMITIVE, value);
break;
case COMPLEX:
- value = readComplexNode(edmProperty, jsonNode);
+ value = readComplexNode(name, type, isNullable, jsonNode);
property.setValue(ValueType.COMPLEX, value);
break;
default:
- throw new DeserializerException("Invalid Type Kind for a property found: " + edmProperty.getType().getKind(),
- DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, edmProperty.getName());
+ throw new DeserializerException("Invalid Type Kind for a property found: " + type.getKind(),
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, name);
}
}
- private Object readComplexNode(final EdmProperty edmProperty, final JsonNode jsonNode)
+ private Object readComplexNode(final String name, final EdmType type, final boolean isNullable, JsonNode jsonNode)
throws DeserializerException {
// read and add all complex properties
- ComplexValue value = readComplexValue(edmProperty, jsonNode);
+ ComplexValue value = readComplexValue(name, type, isNullable, jsonNode);
final List<String> toRemove = new ArrayList<String>();
Iterator<Entry<String, JsonNode>> fieldsIterator = jsonNode.fields();
@@ -384,20 +442,22 @@ public class ODataJsonDeserializer implements ODataDeserializer {
return value;
}
- private void consumePropertyCollectionNode(final EdmProperty edmProperty, final JsonNode jsonNode,
- final Property property) throws DeserializerException {
+ private void consumePropertyCollectionNode(final String name, final EdmType type,
+ final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
+ final boolean isUnicode, final EdmMapping mapping, JsonNode jsonNode, Property property)
+ throws DeserializerException {
if (!jsonNode.isArray()) {
- throw new DeserializerException("Value for property: " + edmProperty.getName()
- + " must be an array but is not.", DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY,
- edmProperty.getName());
+ throw new DeserializerException("Value for property: " + name + " must be an array but is not.",
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, name);
}
List<Object> valueArray = new ArrayList<Object>();
Iterator<JsonNode> iterator = jsonNode.iterator();
- switch (edmProperty.getType().getKind()) {
+ switch (type.getKind()) {
case PRIMITIVE:
while (iterator.hasNext()) {
JsonNode arrayElement = iterator.next();
- Object value = readPrimitiveValue(edmProperty, arrayElement);
+ Object value = readPrimitiveValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
+ arrayElement);
valueArray.add(value);
}
property.setValue(ValueType.COLLECTION_PRIMITIVE, valueArray);
@@ -405,7 +465,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
case DEFINITION:
while (iterator.hasNext()) {
JsonNode arrayElement = iterator.next();
- Object value = readTypeDefinitionValue(edmProperty, arrayElement);
+ Object value = readTypeDefinitionValue(name, type, isNullable, mapping, arrayElement);
valueArray.add(value);
}
property.setValue(ValueType.COLLECTION_PRIMITIVE, valueArray);
@@ -413,7 +473,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
case ENUM:
while (iterator.hasNext()) {
JsonNode arrayElement = iterator.next();
- Object value = readEnumValue(edmProperty, arrayElement);
+ Object value = readEnumValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
+ arrayElement);
valueArray.add(value);
}
property.setValue(ValueType.COLLECTION_ENUM, valueArray);
@@ -421,40 +482,44 @@ public class ODataJsonDeserializer implements ODataDeserializer {
case COMPLEX:
while (iterator.hasNext()) {
// read and add all complex properties
- Object value = readComplexNode(edmProperty, iterator.next());
+ Object value = readComplexNode(name, type, isNullable, iterator.next());
valueArray.add(value);
}
property.setValue(ValueType.COLLECTION_COMPLEX, valueArray);
break;
default:
- throw new DeserializerException("Invalid Type Kind for a property found: " + edmProperty.getType().getKind(),
- DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, edmProperty.getName());
+ throw new DeserializerException("Invalid Type Kind for a property found: " + type.getKind(),
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, name);
}
}
- private ComplexValue readComplexValue(EdmProperty edmComplexProperty, JsonNode jsonNode)
- throws DeserializerException {
- if (isValidNull(edmComplexProperty, jsonNode)) {
+ private ComplexValue readComplexValue(final String name, final EdmType type,
+ final boolean isNullable, JsonNode jsonNode) throws DeserializerException {
+ if (isValidNull(name, isNullable, jsonNode)) {
return null;
}
if (jsonNode.isArray() || !jsonNode.isContainerNode()) {
throw new DeserializerException(
- "Invalid value for property: " + edmComplexProperty.getName() + " must not be an array or primitive value.",
- DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, edmComplexProperty.getName());
+ "Invalid value for property: " + name + " must not be an array or primitive value.",
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, name);
}
// Even if there are no properties defined we have to give back an empty list
ComplexValueImpl complexValue = new ComplexValueImpl();
- EdmComplexType edmType = (EdmComplexType) edmComplexProperty.getType();
+ EdmComplexType edmType = (EdmComplexType) type;
// Check and consume all Properties
for (String propertyName : edmType.getPropertyNames()) {
JsonNode subNode = jsonNode.get(propertyName);
if (subNode != null) {
EdmProperty edmProperty = (EdmProperty) edmType.getProperty(propertyName);
- if (subNode.isNull() && !isNullable(edmProperty)) {
+ if (subNode.isNull() && !edmProperty.isNullable()) {
throw new DeserializerException("Property: " + propertyName + " must not be null.",
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, propertyName);
}
- Property property = consumePropertyNode(edmProperty, subNode);
+ Property property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(),
+ edmProperty.isCollection(),
+ edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(),
+ edmProperty.isUnicode(), edmProperty.getMapping(),
+ subNode);
complexValue.getValue().add(property);
((ObjectNode) jsonNode).remove(propertyName);
}
@@ -462,120 +527,110 @@ public class ODataJsonDeserializer implements ODataDeserializer {
return complexValue;
}
- private boolean isNullable(EdmProperty edmProperty) {
- return edmProperty.isNullable();
- }
-
- private Object readTypeDefinitionValue(EdmProperty edmProperty, JsonNode jsonNode) throws DeserializerException {
- checkForValueNode(edmProperty, jsonNode);
- if (isValidNull(edmProperty, jsonNode)) {
+ private Object readTypeDefinitionValue(final String name, final EdmType type,
+ final boolean isNullable, final EdmMapping mapping, JsonNode jsonNode) throws DeserializerException {
+ checkForValueNode(name, jsonNode);
+ if (isValidNull(name, isNullable, jsonNode)) {
return null;
}
try {
- EdmTypeDefinition edmTypeDefinition = (EdmTypeDefinition) edmProperty.getType();
- checkJsonTypeBasedOnPrimitiveType(edmProperty.getName(), edmTypeDefinition.getUnderlyingType().getName(),
+ EdmTypeDefinition edmTypeDefinition = (EdmTypeDefinition) type;
+ checkJsonTypeBasedOnPrimitiveType(name, edmTypeDefinition.getUnderlyingType().getName(),
jsonNode);
- Class<?> javaClass = getJavaClassForPrimitiveType(edmProperty, edmTypeDefinition.getUnderlyingType());
- return edmTypeDefinition.valueOfString(jsonNode.asText(), edmProperty.isNullable(),
+ Class<?> javaClass = getJavaClassForPrimitiveType(mapping, edmTypeDefinition.getUnderlyingType());
+ return edmTypeDefinition.valueOfString(jsonNode.asText(), isNullable,
edmTypeDefinition.getMaxLength(),
edmTypeDefinition.getPrecision(), edmTypeDefinition.getScale(), edmTypeDefinition.isUnicode(),
javaClass);
} catch (EdmPrimitiveTypeException e) {
throw new DeserializerException(
- "Invalid value: " + jsonNode.asText() + " for property: " + edmProperty.getName(), e,
- DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, edmProperty.getName());
+ "Invalid value: " + jsonNode.asText() + " for property: " + name, e,
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
}
}
- private boolean isValidNull(EdmProperty edmProperty, JsonNode jsonNode) throws DeserializerException {
+ private boolean isValidNull(final String name, final boolean isNullable, final JsonNode jsonNode)
+ throws DeserializerException {
if (jsonNode.isNull()) {
- if (isNullable(edmProperty)) {
+ if (isNullable) {
return true;
} else {
- throw new DeserializerException("Property: " + edmProperty.getName() + " must not be null.",
- DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, edmProperty.getName());
+ throw new DeserializerException("Property: " + name + " must not be null.",
+ DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, name);
}
}
return false;
}
- private Object readEnumValue(EdmProperty edmProperty, JsonNode jsonNode) throws DeserializerException {
- checkForValueNode(edmProperty, jsonNode);
- if (isValidNull(edmProperty, jsonNode)) {
+ private Object readEnumValue(final String name, final EdmType type,
+ final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
+ final boolean isUnicode, final EdmMapping mapping, JsonNode jsonNode) throws DeserializerException {
+ checkForValueNode(name, jsonNode);
+ if (isValidNull(name, isNullable, jsonNode)) {
return null;
}
try {
- EdmEnumType edmEnumType = (EdmEnumType) edmProperty.getType();
+ EdmEnumType edmEnumType = (EdmEnumType) type;
// Enum values must be strings
if (!jsonNode.isTextual()) {
- throw new DeserializerException("Invalid json type: " + jsonNode.getNodeType() + " for enum property: "
- + edmProperty.getName(), DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, edmProperty
- .getName());
+ throw new DeserializerException("Invalid json type: " + jsonNode.getNodeType() + " for enum property: " + name,
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
}
- Class<?> javaClass = getJavaClassForPrimitiveType(edmProperty, edmEnumType.getUnderlyingType());
- return edmEnumType
- .valueOfString(jsonNode.asText(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty
- .getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), javaClass);
+ Class<?> javaClass = getJavaClassForPrimitiveType(mapping, edmEnumType.getUnderlyingType());
+ return edmEnumType.valueOfString(jsonNode.asText(),
+ isNullable, maxLength, precision, scale, isUnicode, javaClass);
} catch (EdmPrimitiveTypeException e) {
throw new DeserializerException(
- "Invalid value: " + jsonNode.asText() + " for property: " + edmProperty.getName(), e,
- DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, edmProperty.getName());
+ "Invalid value: " + jsonNode.asText() + " for property: " + name, e,
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
}
}
- private Object readPrimitiveValue(EdmProperty edmProperty, JsonNode jsonNode) throws DeserializerException {
- checkForValueNode(edmProperty, jsonNode);
- if (isValidNull(edmProperty, jsonNode)) {
+ private Object readPrimitiveValue(final String name, final EdmType type,
+ final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
+ final boolean isUnicode, final EdmMapping mapping, JsonNode jsonNode) throws DeserializerException {
+ checkForValueNode(name, jsonNode);
+ if (isValidNull(name, isNullable, jsonNode)) {
return null;
}
try {
- EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmProperty.getType();
- checkJsonTypeBasedOnPrimitiveType(edmProperty.getName(), edmPrimitiveType.getName(), jsonNode);
- Class<?> javaClass = getJavaClassForPrimitiveType(edmProperty, edmPrimitiveType);
- return edmPrimitiveType.valueOfString(jsonNode.asText(), edmProperty.isNullable(),
- edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(),
- edmProperty.isUnicode(), javaClass);
+ EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) type;
+ checkJsonTypeBasedOnPrimitiveType(name, edmPrimitiveType.getName(), jsonNode);
+ Class<?> javaClass = getJavaClassForPrimitiveType(mapping, edmPrimitiveType);
+ return edmPrimitiveType.valueOfString(jsonNode.asText(),
+ isNullable, maxLength, precision, scale, isUnicode, javaClass);
} catch (EdmPrimitiveTypeException e) {
throw new DeserializerException(
- "Invalid value: " + jsonNode.asText() + " for property: " + edmProperty.getName(), e,
- DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, edmProperty.getName());
+ "Invalid value: " + jsonNode.asText() + " for property: " + name, e,
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
}
}
/**
* This method either returns the primitive types default class or the manually mapped class if present.
- * @param edmProperty
+ * @param edmMapping
* @param edmPrimitiveType
* @return the java class to be used during deserialization
*/
- private Class<?> getJavaClassForPrimitiveType(EdmProperty edmProperty, EdmPrimitiveType edmPrimitiveType) {
- Class<?> javaClass = null;
- if (edmProperty.getMapping() != null && edmProperty.getMapping().getMappedJavaClass() != null) {
- javaClass = edmProperty.getMapping().getMappedJavaClass();
- } else {
- javaClass = edmPrimitiveType.getDefaultType();
- }
-
- edmPrimitiveType.getDefaultType();
- return javaClass;
+ private Class<?> getJavaClassForPrimitiveType(EdmMapping mapping, EdmPrimitiveType edmPrimitiveType) {
+ return mapping == null || mapping.getMappedJavaClass() == null ?
+ edmPrimitiveType.getDefaultType() :
+ mapping.getMappedJavaClass();
}
/**
* Check if JsonNode is a value node (<code>jsonNode.isValueNode()</code>) and if not throw
* an DeserializerException.
- *
- * @param edmProperty property which is checked
+ * @param name name of property which is checked
* @param jsonNode node which is checked
* @throws DeserializerException is thrown if json node is not a value node
*/
- private void checkForValueNode(final EdmProperty edmProperty, final JsonNode jsonNode)
- throws DeserializerException {
+ private void checkForValueNode(final String name, final JsonNode jsonNode) throws DeserializerException {
if (!jsonNode.isValueNode()) {
- throw new DeserializerException(
- "Invalid value for property: " + edmProperty.getName() + " must not be an object or array.",
- DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, edmProperty.getName());
+ throw new DeserializerException("Invalid value for property: " + name + " must not be an object or array.",
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, name);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d41513f/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 109a192..f610fc2b 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -25,6 +25,7 @@ import org.apache.olingo.commons.api.data.ContextURL.Builder;
import org.apache.olingo.commons.api.data.ContextURL.Suffix;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.format.ContentType;
@@ -51,6 +52,7 @@ import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriResourceAction;
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
import org.apache.olingo.server.api.uri.UriResourceFunction;
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
@@ -281,13 +283,21 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
public void processActionEntity(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat, final ContentType responseFormat)
throws ODataApplicationException, DeserializerException, SerializerException {
- throw new ODataApplicationException("Process entity is not supported yet.",
+ throw new ODataApplicationException("Any action returning an entity is not supported yet.",
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
}
@Override
public void processActionVoid(final ODataRequest request, ODataResponse response, final UriInfo uriInfo,
final ContentType requestFormat) throws ODataApplicationException, DeserializerException {
+ final UriResourceAction resource =
+ ((UriResourceAction) uriInfo.getUriResourceParts().get(uriInfo.getUriResourceParts().size() - 1));
+ final EdmAction action = resource.getAction();
+ if (action.getParameterNames().size() - (action.isBound() ? 1 : 0) > 0) {
+ checkRequestFormat(requestFormat);
+ odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
+ .actionParameters(request.getBody(), action);
+ }
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d41513f/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
index 78ada0a..dee0681 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
@@ -88,7 +88,8 @@ public class ActionProvider {
return Arrays.asList(
new Action().setName(nameUARTCTTwoPrimParam.getName())
.setParameters(Arrays.asList(
- new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
+ new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)
+ .setNullable(false)))
.setReturnType(
new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim))
);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d41513f/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
new file mode 100644
index 0000000..2e6a181
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.deserializer.json;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.math.BigDecimal;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.junit.Test;
+
+public class ODataJsonDeserializerActionParametersTest extends AbstractODataDeserializerTest {
+
+ @Test
+ public void empty() throws Exception {
+ final String input = "{}";
+ final Entity entity = deserialize(input, "UART");
+ assertNotNull(entity);
+ final List<Property> properties = entity.getProperties();
+ assertNotNull(properties);
+ assertTrue(properties.isEmpty());
+ }
+
+ @Test
+ public void primitive() throws Exception {
+ final String input = "{\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}";
+ final Entity entity = deserialize(input, "UARTTwoParam");
+ assertNotNull(entity);
+ final List<Property> properties = entity.getProperties();
+ assertNotNull(properties);
+ assertEquals(2, properties.size());
+ Property property = properties.get(0);
+ assertNotNull(property);
+ assertEquals((short) 42, property.getValue());
+ property = properties.get(1);
+ assertNotNull(property);
+ assertEquals(BigDecimal.valueOf(3669753), property.getValue());
+ }
+
+ @Test(expected = DeserializerException.class)
+ public void missingParameter() throws Exception {
+ deserialize("{}", "UARTCTTwoPrimParam");
+ }
+
+ @Test(expected = DeserializerException.class)
+ public void parameterTwice() throws Exception {
+ deserialize("{\"ParameterInt16\":1,\"ParameterInt16\":2}", "UARTParam");
+ }
+
+ @Test(expected = DeserializerException.class)
+ public void wrongType() throws Exception {
+ deserialize("{\"ParameterInt16\":\"42\"}", "UARTParam");
+ }
+
+ private Entity deserialize(final String input, final String actionName) throws DeserializerException {
+ return OData.newInstance().createDeserializer(ODataFormat.JSON)
+ .actionParameters(new ByteArrayInputStream(input.getBytes()),
+ edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName)));
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6d41513f/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
index 2dfb67e..1101ded 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
@@ -87,7 +87,7 @@ public class MetadataDocumentTest {
+ "<Property Name=\"AdditionalPropString\" Type=\"Edm.String\"/></ComplexType>"));
assertThat(metadata, containsString("<Action Name=\"UARTCTTwoPrimParam\" IsBound=\"false\">"
- + "<Parameter Name=\"ParameterInt16\" Type=\"Edm.Int16\"/>"
+ + "<Parameter Name=\"ParameterInt16\" Type=\"Edm.Int16\" Nullable=\"false\"/>"
+ "<ReturnType Type=\"Namespace1_Alias.CTTwoPrim\"/></Action>"));
assertThat(metadata,
[41/50] [abbrv] olingo-odata4 git commit: [OLINGO-545] TecSvc EDM
enhanced
Posted by ch...@apache.org.
[OLINGO-545] TecSvc EDM enhanced
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/fd9ba8bf
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/fd9ba8bf
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/fd9ba8bf
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: fd9ba8bf27e80d99ef5012b821daa67e4148d669
Parents: 5855c6b
Author: Christian Holzer <c....@sap.com>
Authored: Wed Apr 1 15:20:11 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Wed Apr 1 15:32:48 2015 +0200
----------------------------------------------------------------------
.../server/tecsvc/provider/ActionProvider.java | 27 ++++++++++-----
.../tecsvc/provider/ContainerProvider.java | 36 +++++++++++++++-----
.../tecsvc/provider/FunctionProvider.java | 19 ++++++++++-
.../tecsvc/provider/PropertyProvider.java | 2 +-
.../server/tecsvc/provider/SchemaProvider.java | 1 +
5 files changed, 66 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd9ba8bf/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
index d00b953..6426327 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
@@ -49,6 +49,9 @@ public class ActionProvider {
public static final FullQualifiedName nameBAETTwoKeyNavRTETTwoKeyNav =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BAETTwoKeyNavRTETTwoKeyNav");
+ public static final FullQualifiedName nameBAESAllPrimRT =
+ new FullQualifiedName(SchemaProvider.NAMESPACE, "BAESAllPrimRT");
+
public static final FullQualifiedName nameBAETAllPrimRT =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BAETAllPrimRT");
@@ -75,6 +78,7 @@ public class ActionProvider {
public static final FullQualifiedName nameUARTTwoParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "UARTTwoParam");
+
public List<Action> getActions(final FullQualifiedName actionName) throws ODataException {
if (actionName.equals(nameUARTString)) {
return Collections.singletonList(
@@ -237,15 +241,20 @@ public class ActionProvider {
.setParameters(Arrays.asList(
new Parameter().setName("ParameterETAllPrim")
.setNullable(false)
- .setType(EntityTypeProvider.nameETAllPrim))),
- new Action().setName("BAETAllPrimRT")
- .setBound(true)
- .setParameters(Arrays.asList(
- new Parameter().setName("ParameterETAllPrim")
- .setNullable(false)
- .setCollection(true)
- .setType(EntityTypeProvider.nameETAllPrim))));
- }
+ .setType(EntityTypeProvider.nameETAllPrim)
+ )));
+ } else if(actionName.equals(nameBAESAllPrimRT)) {
+ return Arrays.asList(
+ new Action().setName("BAESAllPrimRT")
+ .setBound(true)
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterETAllPrim")
+ .setNullable(false)
+ .setCollection(true)
+ .setType(EntityTypeProvider.nameETAllPrim)
+ ))
+ );
+ }
return null;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd9ba8bf/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
index 12cdb6f..9b982aa 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
@@ -98,7 +98,9 @@ public class ContainerProvider {
entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, "ESCompMixPrimCollComp"));
entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, "ESFourKeyAlias"));
entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, "ESMixEnumDefCollComp"));
-
+ entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, "ESTwoBaseTwoKeyNav"));
+ entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, "ESKeyNavCont"));
+
// Singletons
List<Singleton> singletons = new ArrayList<Singleton>();
container.setSingletons(singletons);
@@ -135,6 +137,7 @@ public class ContainerProvider {
functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTCTAllPrimTwoParam"));
functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTESMixPrimCollCompTwoParam"));
functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTCollETMixPrimCollCompTwoParam"));
+ functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FINRTCollETMixPrimCollCompTwoParam"));
functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTCollCTTwoPrim"));
functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTESMedia"));
functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTCollESMedia"));
@@ -144,7 +147,9 @@ public class ContainerProvider {
functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTString"));
functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTCollESTwoKeyNavParam"));
functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTCollCTTwoPrimParam"));
-
+ functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FINRTCollCTNavFiveProp"));
+ functionImports.add(prov.getFunctionImport(ContainerProvider.nameContainer, "FICRTCollESKeyNavContParam"));
+
return container;
}
@@ -364,9 +369,6 @@ public class ContainerProvider {
.setPath("CollPropertyCompNav/NavPropertyETMediaMany")
.setTarget("ESMedia"),
new NavigationPropertyBinding()
- .setPath("CollPropertyCompNav/NavPropertyETTwoKeyNavMany")
- .setTarget("ESTwoKeyNav"),
- new NavigationPropertyBinding()
.setPath("NavPropertyETTwoBaseTwoKeyNavOne")
.setTarget("ESBaseTwoKeyNav"),
new NavigationPropertyBinding()
@@ -563,7 +565,13 @@ public class ContainerProvider {
.setName(name)
.setFunction(FunctionProvider.nameUFCRTESMixPrimCollCompTwoParam)
.setIncludeInServiceDocument(true);
-
+
+ } else if(name.equals("FINRTCollETMixPrimCollCompTwoParam")) {
+ return new FunctionImport()
+ .setName(name)
+ .setFunction(FunctionProvider.nameUFNRTCollETMixPrimCollCompTwoParam)
+ .setIncludeInServiceDocument(true);
+
} else if (name.equals("FICRTCollETMixPrimCollCompTwoParam")) {
return new FunctionImport()
.setName(name)
@@ -625,10 +633,22 @@ public class ContainerProvider {
.setName(name)
.setFunction(FunctionProvider.nameUFCRTCollCTTwoPrimParam)
.setIncludeInServiceDocument(true);
-
+
+ } else if(name.equals("FINRTCollCTNavFiveProp")) {
+ return new FunctionImport()
+ .setName(name)
+ .setFunction(FunctionProvider.nameUFNRTCollCTNavFiveProp)
+ .setIncludeInServiceDocument(true);
+
+ } else if(name.equals("FICRTCollESKeyNavContParam")) {
+ return new FunctionImport()
+ .setName(name)
+ .setFunction(FunctionProvider.nameUFCRTCollETKeyNavContParam)
+ .setEntitySet("ESKeyNavCont")
+ .setIncludeInServiceDocument(true);
}
}
-
+
return null;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd9ba8bf/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
index 84f57ff..bcf0863 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
@@ -176,6 +176,9 @@ public class FunctionProvider {
public static final FullQualifiedName nameUFNRTCollCTNavFiveProp = new FullQualifiedName(SchemaProvider.NAMESPACE,
"UFNRTCollCTNavFiveProp");
+ public static final FullQualifiedName nameUFNRTCollETMixPrimCollCompTwoParam
+ = new FullQualifiedName(SchemaProvider.NAMESPACE, "UFNRTCollETMixPrimCollCompTwoParam");
+
public List<Function> getFunctions(final FullQualifiedName functionName) throws ODataException {
if (functionName.equals(nameUFNRTInt16)) {
@@ -332,6 +335,20 @@ public class FunctionProvider {
new ReturnType().setType(ComplexTypeProvider.nameCTAllPrim).setNullable(false))
);
+ } else if(functionName.equals(nameUFNRTCollETMixPrimCollCompTwoParam)) {
+ return Arrays.asList(
+ new Function()
+ .setName("UFNRTCollETMixPrimCollCompTwoParam")
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterString").setType(PropertyProvider.nameString).setNullable(false),
+ new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16).setNullable(false)))
+ .setComposable(false)
+ .setBound(false)
+ .setReturnType(
+ new ReturnType().setType(ComplexTypeProvider.nameCTMixPrimCollComp)
+ .setNullable(false)
+ .setCollection(true))
+ );
} else if (functionName.equals(nameUFCRTCTTwoPrimParam)) {
return Arrays.asList(
new Function()
@@ -855,7 +872,7 @@ public class FunctionProvider {
Arrays.asList(
new Parameter().setName("BindingParam").setType(EntityTypeProvider.nameETTwoKeyNav)
.setCollection(true).setNullable(false),
- new Parameter().setName("ParameterComplex").setType(ComplexTypeProvider.nameCTTwoPrim)
+ new Parameter().setName("ParameterComp").setType(ComplexTypeProvider.nameCTTwoPrim)
.setNullable(false)))
.setComposable(true)
.setReturnType(
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd9ba8bf/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
index ff2ad65..07fbd25 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
@@ -733,7 +733,7 @@ public class PropertyProvider {
.setType(EntityTypeProvider.nameETKeyNav);
public static final NavigationProperty navPropertyETTwoKeyNavContOneCT_ETTwoKeyNav = new NavigationProperty()
- .setName("NavPropertyETKeyNavContOne")
+ .setName("NavPropertyETTwoKeyNavContOne")
.setContainsTarget(true)
.setType(EntityTypeProvider.nameETTwoKeyNav);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd9ba8bf/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
index ad3693c..b8e5ad3 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
@@ -185,6 +185,7 @@ public class SchemaProvider {
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTStringParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESKeyNavRTETKeyNavParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCCTPrimCompRTETTwoKeyNavParam));
+ functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTCollETMixPrimCollCompTwoParam));
// functions.addAll(prov.getFunctions(FunctionProvider.nameBFCCTPrimCompRTESTwoKeyNavParam));
// EntityContainer
[15/50] [abbrv] olingo-odata4 git commit: [OLINGO-545] TecSvc EDM
enhanced
Posted by ch...@apache.org.
[OLINGO-545] TecSvc EDM enhanced
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/af1417b3
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/af1417b3
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/af1417b3
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: af1417b3c731f08e15956cbd364c00b7e9a1f43f
Parents: 6d41513
Author: Christian Holzer <c....@sap.com>
Authored: Fri Mar 27 17:09:55 2015 +0100
Committer: Christian Holzer <c....@sap.com>
Committed: Fri Mar 27 17:10:07 2015 +0100
----------------------------------------------------------------------
.../olingo/fit/tecsvc/client/BasicITCase.java | 4 +--
.../olingo/fit/tecsvc/client/BindingITCase.java | 8 +++--
.../fit/tecsvc/client/DeepInsertITCase.java | 19 +++++-----
.../tecsvc/client/FilterSystemQueryITCase.java | 6 ++--
.../fit/tecsvc/client/NavigationITCase.java | 2 +-
.../olingo/server/tecsvc/data/DataCreator.java | 4 +--
.../tecsvc/provider/EntityTypeProvider.java | 9 ++---
.../tecsvc/provider/PropertyProvider.java | 14 ++++++++
.../tecsvc/provider/TypeDefinitionProvider.java | 2 +-
.../server/core/uri/UriResourceImplTest.java | 2 +-
.../core/uri/antlr/TestFullResourcePath.java | 38 ++++++++++----------
11 files changed, 63 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
index cc9be57..6ca841a 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
@@ -330,7 +330,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
final ODataClient client = getClient();
final ODataObjectFactory factory = client.getObjectFactory();
ODataEntity newEntity = factory.newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
- newEntity.getProperties().add(factory.newComplexProperty("PropertyCompComp", null));
+ newEntity.getProperties().add(factory.newComplexProperty("PropertyCompCompNav", null));
// The following properties must not be null
newEntity.getProperties().add(factory.newPrimitiveProperty("PropertyString",
factory.newPrimitiveValueBuilder().buildString("Test")));
@@ -358,7 +358,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
assertEquals(HttpStatusCode.OK.getStatusCode(), entityResponse.getStatusCode());
final ODataEntity entity = entityResponse.getBody();
assertNotNull(entity);
- final ODataComplexValue complex = entity.getProperty("PropertyCompComp").getComplexValue()
+ final ODataComplexValue complex = entity.getProperty("PropertyCompCompNav").getComplexValue()
.get("PropertyComp").getComplexValue();
assertNotNull(complex);
final ODataProperty property = complex.get("PropertyInt16");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
index 82280bc..66f2149 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
@@ -62,13 +62,15 @@ public class BindingITCase extends AbstractBaseTestITCase {
private static final String PROPERTY_INT16 = "PropertyInt16";
private static final String PROPERTY_STRING = "PropertyString";
private static final String PROPERTY_COMP = "PropertyComp";
- private static final String PROPERTY_COMP_COMP = "PropertyCompComp";
+ private static final String PROPERTY_COMP_NAV = "PropertyCompNav";
+ private static final String PROPERTY_COMP_COMP_NAV = "PropertyCompCompNav";
private static final String PROPERTY_COMP_TWO_PRIM = "PropertyCompTwoPrim";
private static final String PROPERTY_COMP_ALL_PRIM = "PropertyCompAllPrim";
private static final String NAV_PROPERTY_ET_KEY_NAV_ONE = "NavPropertyETKeyNavOne";
private static final String NAV_PROPERTY_ET_KEY_NAV_MANY = "NavPropertyETKeyNavMany";
private static final String NAV_PROPERTY_ET_TWO_KEY_NAV_MANY = "NavPropertyETTwoKeyNavMany";
+
@Test
public void testCreateBindingSimple() throws EdmPrimitiveTypeException {
final ODataClient client = getClient();
@@ -82,7 +84,7 @@ public class BindingITCase extends AbstractBaseTestITCase {
entity.getProperties()
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")));
entity.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))));
entity.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_ALL_PRIM, of.newComplexValue(CT_ALL_PRIM)
@@ -92,7 +94,7 @@ public class BindingITCase extends AbstractBaseTestITCase {
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))));
entity.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP_COMP, of.newComplexValue(CT_PRIM_COMP)
+ .add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))
.add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
index eab370e..29b2baa 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
@@ -65,7 +65,8 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
private static final String PROPERTY_INT16 = "PropertyInt16";
private static final String PROPERTY_STRING = "PropertyString";
private static final String PROPERTY_COMP = "PropertyComp";
- private static final String PROPERTY_COMP_COMP = "PropertyCompComp";
+ private static final String PROPERTY_COMP_NAV = "PropertyCompNav";
+ private static final String PROPERTY_COMP_COMP_NAV = "PropertyCompCompNav";
private static final String PROPERTY_COMP_TWO_PRIM = "PropertyCompTwoPrim";
private static final String PROPERTY_COMP_ALL_PRIM = "PropertyCompAllPrim";
private static final String NAV_PROPERTY_ET_KEY_NAV_ONE = "NavPropertyETKeyNavOne";
@@ -90,7 +91,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
entity.getProperties()
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")));
entity.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))));
entity.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_ALL_PRIM, of.newComplexValue(CT_ALL_PRIM)
@@ -100,7 +101,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))));
entity.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP_COMP, of.newComplexValue(CT_PRIM_COMP)
+ .add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))
.add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
@@ -276,7 +277,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
entity.getProperties()
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")));
entity.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))));
entity.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_ALL_PRIM, of.newComplexValue(CT_ALL_PRIM)
@@ -286,7 +287,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))));
entity.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP_COMP, of.newComplexValue(CT_PRIM_COMP)
+ .add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))
.add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
@@ -298,7 +299,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
innerEntity.getProperties()
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("43")));
innerEntity.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 431)))));
innerEntity.getProperties()
.add(of.newComplexProperty(PROPERTY_COMP_ALL_PRIM, of.newComplexValue(CT_ALL_PRIM)
@@ -309,7 +310,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("431")))));
innerEntity
.getProperties()
- .add(of.newComplexProperty(PROPERTY_COMP_COMP, of.newComplexValue(CT_PRIM_COMP)
+ .add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("431")))
.add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_NAV_FIVE_PROP)
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder()
@@ -335,7 +336,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
// Check values
assertEquals(431, entityResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(
- PROPERTY_COMP).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ PROPERTY_COMP_NAV).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
Short innerEntityInt16Key =
entityResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(PROPERTY_INT16)
@@ -349,7 +350,7 @@ public class DeepInsertITCase extends AbstractBaseTestITCase {
innerRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
ODataRetrieveResponse<ODataEntity> innerResponse = innerRequest.execute();
- assertEquals(431, innerResponse.getBody().getProperty(PROPERTY_COMP).getComplexValue().get(PROPERTY_INT16)
+ assertEquals(431, innerResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(PROPERTY_INT16)
.getPrimitiveValue().toValue());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
index 58fd14b..af75958 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
@@ -927,7 +927,7 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase {
final ODataClient client = getClient();
final ODataObjectFactory factory = client.getObjectFactory();
ODataEntity newEntity = factory.newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
- newEntity.getProperties().add(factory.newComplexProperty("PropertyCompComp", null));
+ newEntity.getProperties().add(factory.newComplexProperty("PropertyCompCompNav", null));
newEntity.getProperties().add(factory.newPrimitiveProperty("PropertyInt16",
factory.newPrimitiveValueBuilder().buildInt16((short) 4)));
newEntity.getProperties().add(factory.newPrimitiveProperty("PropertyString",
@@ -959,11 +959,11 @@ public class FilterSystemQueryITCase extends AbstractBaseTestITCase {
// Do the filter request
ODataRetrieveResponse<ODataEntitySet> result =
- sendRequest("ESKeyNav", "PropertyCompComp/PropertyComp/PropertyInt16 eq 1", cookie);
+ sendRequest("ESKeyNav", "PropertyCompCompNav/PropertyComp/PropertyInt16 eq 1", cookie);
assertEquals(3, result.getBody().getEntities().size());
// Try filter all entries where PropertyCompComp is null
- result = sendRequest("ESKeyNav", "PropertyCompComp/PropertyComp/PropertyInt16 eq null", cookie);
+ result = sendRequest("ESKeyNav", "PropertyCompCompNav/PropertyComp/PropertyInt16 eq null", cookie);
assertEquals(1, result.getBody().getEntities().size());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/NavigationITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/NavigationITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/NavigationITCase.java
index e8b679f..fedf7d9 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/NavigationITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/NavigationITCase.java
@@ -122,7 +122,7 @@ public final class NavigationITCase extends AbstractBaseTestITCase {
.appendEntitySetSegment("ESKeyNav").appendKeySegment(1)
.appendNavigationSegment("NavPropertyETKeyNavOne")
.appendNavigationSegment("NavPropertyETKeyNavMany").appendKeySegment(3)
- .appendPropertySegment("PropertyComp").appendPropertySegment("PropertyInt16").build())
+ .appendPropertySegment("PropertyCompNav").appendPropertySegment("PropertyInt16").build())
.execute();
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index 28781a3..e6193df 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@ -115,7 +115,7 @@ public class DataCreator {
return new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", propertyInt16))
.addProperty(createPrimitive("PropertyString", propertyString))
- .addProperty(createComplex("PropertyComp",
+ .addProperty(createComplex("PropertyCompNav",
createPrimitive("PropertyInt16", 1)))
.addProperty(createKeyNavAllPrimComplexValue("PropertyCompAllPrim"))
.addProperty(createComplex("PropertyCompTwoPrim",
@@ -136,7 +136,7 @@ public class DataCreator {
Arrays.asList(
createPrimitive("PropertyInt16", 3),
createKeyNavAllPrimComplexValue("PropertyComp"))))
- .addProperty(createComplex("PropertyCompComp",
+ .addProperty(createComplex("PropertyCompCompNav",
createPrimitive("PropertyString", "1"),
createComplex("PropertyComp", createPrimitive("PropertyInt16", 1))));
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
index 7f0381e..a0cd6bb 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EntityTypeProvider.java
@@ -305,12 +305,12 @@ public class EntityTypeProvider {
.setProperties(
Arrays.asList(
PropertyProvider.propertyInt16_NotNullable, PropertyProvider.propertyString_NotNullable,
- PropertyProvider.propertyComp_CTNavFiveProp,
+ PropertyProvider.propertyCompNav_CTNavFiveProp,
PropertyProvider.propertyCompAllPrim_CTAllPrim, PropertyProvider.propertyCompTwoPrim_CTTwoPrim,
PropertyProvider.collPropertyString, PropertyProvider.collPropertyInt16,
PropertyProvider.collPropertyComp_CTPrimComp,
new Property()
- .setName("PropertyCompComp").setType(ComplexTypeProvider.nameCTCompNav)
+ .setName("PropertyCompCompNav").setType(ComplexTypeProvider.nameCTCompNav)
))
.setNavigationProperties(
Arrays.asList(
@@ -396,8 +396,9 @@ public class EntityTypeProvider {
new PropertyRef().setName("PropertyComp/PropertyString").setAlias("KeyAlias2"),
new PropertyRef().setName("PropertyCompComp/PropertyComp/PropertyString").setAlias("KeyAlias3")))
.setProperties(
- Arrays.asList(PropertyProvider.propertyInt16_NotNullable, PropertyProvider.propertyComp_CTTwoPrim,
- PropertyProvider.propertyCompComp_CTCompComp));
+ Arrays.asList(PropertyProvider.propertyInt16_NotNullable,
+ PropertyProvider.propertyComp_CTTwoPrim_NotNullable,
+ PropertyProvider.propertyCompComp_CTCompComp_NotNullable));
} else if (entityTypeName.equals(nameETCompMixPrimCollComp)) {
return new EntityType()
.setName("ETCompMixPrimCollComp")
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
index 5dfa548..bd2ec5b 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
@@ -580,6 +580,10 @@ public class PropertyProvider {
.setName("PropertyComp")
.setType(ComplexTypeProvider.nameCTNavFiveProp);
+ public static final Property propertyCompNav_CTNavFiveProp = new Property()
+ .setName("PropertyCompNav")
+ .setType(ComplexTypeProvider.nameCTNavFiveProp);
+
public static final Property propertyComp_CTPrimComp_NotNullable = new Property()
.setName("PropertyComp")
.setType(ComplexTypeProvider.nameCTPrimComp)
@@ -589,6 +593,11 @@ public class PropertyProvider {
.setName("PropertyComp")
.setType(ComplexTypeProvider.nameCTTwoPrim);
+ public static final Property propertyComp_CTTwoPrim_NotNullable = new Property()
+ .setName("PropertyComp")
+ .setType(ComplexTypeProvider.nameCTTwoPrim)
+ .setNullable(false);
+
public static final Property propertyCompAllPrim_CTAllPrim = new Property()
.setName("PropertyCompAllPrim")
.setType(ComplexTypeProvider.nameCTAllPrim);
@@ -597,6 +606,11 @@ public class PropertyProvider {
.setName("PropertyCompComp")
.setType(ComplexTypeProvider.nameCTCompComp);
+ public static final Property propertyCompComp_CTCompComp_NotNullable = new Property()
+ .setName("PropertyCompComp")
+ .setType(ComplexTypeProvider.nameCTCompComp)
+ .setNullable(false);
+
public static final Property propertyCompTwoPrim_CTTwoPrim = new Property()
.setName("PropertyCompTwoPrim")
.setType(ComplexTypeProvider.nameCTTwoPrim);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java
index 9c99e79..74cdbb1 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java
@@ -29,7 +29,7 @@ public class TypeDefinitionProvider {
public TypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) {
if (nameTDString.equals(typeDefinitionName)) {
return new TypeDefinition().setName(nameTDString.getName()).setUnderlyingType(
- EdmPrimitiveTypeKind.String.getFullQualifiedName());
+ EdmPrimitiveTypeKind.String.getFullQualifiedName()).setMaxLength(15);
}
return null;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java
index ab197e7..a6d9792 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java
@@ -136,7 +136,7 @@ public class UriResourceImplTest {
assertEquals(UriResourceKind.complexProperty, impl.getKind());
EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav);
- EdmProperty property = (EdmProperty) entityType.getProperty("PropertyComp");
+ EdmProperty property = (EdmProperty) entityType.getProperty("PropertyCompNav");
impl.setProperty(property);
assertEquals(property, impl.getProperty());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af1417b3/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 3ace90e..c7f6faf 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -460,36 +460,36 @@ public class TestFullResourcePath {
@Test
public void runBfuncBnEsRtEntityPpCp() throws Exception {
- testUri.run("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyComp")
+ testUri.run("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyCompNav")
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESKeyNav")
.n()
.isFunction("BFCESKeyNavRTETKeyNav")
.n()
- .isComplex("PropertyComp")
+ .isComplex("PropertyCompNav")
.isType(ComplexTypeProvider.nameCTNavFiveProp);
- testUri.run("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyComp/PropertyInt16")
+ testUri.run("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyCompNav/PropertyInt16")
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESKeyNav")
.n()
.isFunction("BFCESKeyNavRTETKeyNav")
.n()
- .isComplex("PropertyComp")
+ .isComplex("PropertyCompNav")
.isType(ComplexTypeProvider.nameCTNavFiveProp)
.n()
.isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
- testUri.run("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyComp/PropertyInt16/$value")
+ testUri.run("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyCompNav/PropertyInt16/$value")
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESKeyNav")
.n()
.isFunction("BFCESKeyNavRTETKeyNav")
.n()
- .isComplex("PropertyComp")
+ .isComplex("PropertyCompNav")
.isType(ComplexTypeProvider.nameCTNavFiveProp)
.n()
.isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false)
@@ -1351,7 +1351,7 @@ public class TestFullResourcePath {
.n()
.isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
- testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)/PropertyComp")
+ testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)/PropertyCompNav")
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESKeyNav")
@@ -1360,7 +1360,7 @@ public class TestFullResourcePath {
.isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
.isKeyPredicate(0, "PropertyInt16", "2")
.n()
- .isComplex("PropertyComp");
+ .isComplex("PropertyCompNav");
testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)/NavPropertyETKeyNavOne")
.isKind(UriInfoKind.resource).goPath()
@@ -1387,13 +1387,13 @@ public class TestFullResourcePath {
.isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
.isKeyPredicate(0, "PropertyInt16", "4");
- testUri.run("ESKeyNav(1)/PropertyComp/NavPropertyETTwoKeyNavOne")
+ testUri.run("ESKeyNav(1)/PropertyCompNav/NavPropertyETTwoKeyNavOne")
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESKeyNav")
.isKeyPredicate(0, "PropertyInt16", "1")
.n()
- .isComplex("PropertyComp")
+ .isComplex("PropertyCompNav")
.n()
.isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false);
@@ -2500,7 +2500,7 @@ public class TestFullResourcePath {
.isSelectText("PropertyInt16")
.goSelectItem(0).isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
- testUri.run("ESKeyNav", "$expand=NavPropertyETKeyNavOne($select=PropertyComp/PropertyInt16)")
+ testUri.run("ESKeyNav", "$expand=NavPropertyETKeyNavOne($select=PropertyCompNav/PropertyInt16)")
.isKind(UriInfoKind.resource)
.goPath().first()
.goExpand().first()
@@ -2508,7 +2508,7 @@ public class TestFullResourcePath {
.isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
.isType(EntityTypeProvider.nameETKeyNav)
.goUpExpandValidator()
- .isSelectText("PropertyComp/PropertyInt16");
+ .isSelectText("PropertyCompNav/PropertyInt16");
testUri.runEx("ESKeyNav", "$expand=undefined")
.isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE);
@@ -4330,8 +4330,8 @@ public class TestFullResourcePath {
.goParameter(0).isTypedLiteral(EntityTypeProvider.nameETBaseTwoKeyNav);
testFilter
- .runOnETKeyNav("isof(olingo.odata.test1.ETBaseTwoKeyNav) eq true and PropertyComp/PropertyInt16 eq 1")
- .is("<<<isof(<olingo.odata.test1.ETBaseTwoKeyNav>)> eq <true>> and <<PropertyComp/PropertyInt16> eq <1>>>")
+ .runOnETKeyNav("isof(olingo.odata.test1.ETBaseTwoKeyNav) eq true and PropertyCompNav/PropertyInt16 eq 1")
+ .is("<<<isof(<olingo.odata.test1.ETBaseTwoKeyNav>)> eq <true>> and <<PropertyCompNav/PropertyInt16> eq <1>>>")
.root().isBinary(BinaryOperatorKind.AND)
.left().isBinary(BinaryOperatorKind.EQ)
.left().isMethod(MethodKind.ISOF, 1)
@@ -4378,12 +4378,12 @@ public class TestFullResourcePath {
.goParameter(0).goPath().isIt().goUpFilterValidator()
.root().left().goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTTwoBase);
- testFilter.runOnETKeyNav("isof(PropertyComp/PropertyInt16,Edm.Int32)")
- .is("<isof(<PropertyComp/PropertyInt16>,<Edm.Int32>)>")
+ testFilter.runOnETKeyNav("isof(PropertyCompNav/PropertyInt16,Edm.Int32)")
+ .is("<isof(<PropertyCompNav/PropertyInt16>,<Edm.Int32>)>")
.root()
.isMethod(MethodKind.ISOF, 2)
.goParameter(0).goPath()
- .first().isComplex("PropertyComp")
+ .first().isComplex("PropertyCompNav")
.n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false)
.goUpFilterValidator()
.root().goParameter(1).isTypedLiteral(PropertyProvider.nameInt32);
@@ -4860,10 +4860,10 @@ public class TestFullResourcePath {
.first().isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
.n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
- testFilter.runOrderByOnETTwoKeyNav("NavPropertyETKeyNavOne/PropertyComp")
+ testFilter.runOrderByOnETTwoKeyNav("NavPropertyETKeyNavOne/PropertyCompNav")
.isSortOrder(0, false).goOrder(0).goPath()
.first().isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
- .n().isComplex("PropertyComp");
+ .n().isComplex("PropertyCompNav");
testFilter.runOrderByOnETTwoKeyNav("PropertyComp/PropertyComp/PropertyInt16 eq 1")
.isSortOrder(0, false).goOrder(0).left().goPath()
[33/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin as example
Posted by ch...@apache.org.
OLINGO-573: New processing framework on server side with single interface with TripPin as example
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/2b73abcc
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/2b73abcc
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/2b73abcc
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 2b73abcce03e5b44ce61061c59dccde513265848
Parents: 3e8c506
Author: Ramesh Reddy <ra...@jboss.org>
Authored: Mon Mar 30 12:40:32 2015 -0500
Committer: Ramesh Reddy <ra...@jboss.org>
Committed: Tue Mar 31 10:55:01 2015 -0500
----------------------------------------------------------------------
.../apache/olingo/commons/core/DecoderTest.java | 10 +-
.../apache/olingo/commons/core/EncoderTest.java | 10 +-
lib/pom.xml | 1 +
.../api/deserializer/ODataDeserializer.java | 29 +-
.../EntityCollectionSerializerOptions.java | 18 +-
.../api/serializer/EntitySerializerOptions.java | 18 +-
.../server/api/serializer/ODataSerializer.java | 26 +-
.../api/serializer/SerializerException.java | 8 +-
lib/server-core-ext/pom.xml | 117 +++
.../apache/olingo/server/core/ErrorHandler.java | 125 +++
.../olingo/server/core/MetadataParser.java | 679 +++++++++++++++
.../olingo/server/core/OData4HttpHandler.java | 123 +++
.../apache/olingo/server/core/OData4Impl.java | 45 +
.../server/core/RequestURLHierarchyVisitor.java | 333 ++++++++
.../olingo/server/core/RequestURLVisitor.java | 127 +++
.../server/core/ReturnRepresentation.java | 23 +
.../server/core/SchemaBasedEdmProvider.java | 315 +++++++
.../olingo/server/core/ServiceDispatcher.java | 227 +++++
.../olingo/server/core/ServiceHandler.java | 263 ++++++
.../olingo/server/core/ServiceRequest.java | 253 ++++++
.../core/legacy/ProcessorServiceHandler.java | 433 ++++++++++
.../server/core/requests/ActionRequest.java | 120 +++
.../server/core/requests/BatchRequest.java | 197 +++++
.../server/core/requests/DataRequest.java | 769 +++++++++++++++++
.../server/core/requests/FunctionRequest.java | 122 +++
.../server/core/requests/MediaRequest.java | 99 +++
.../server/core/requests/MetadataRequest.java | 61 ++
.../server/core/requests/OperationRequest.java | 118 +++
.../core/requests/ServiceDocumentRequest.java | 57 ++
.../server/core/responses/CountResponse.java | 60 ++
.../server/core/responses/EntityResponse.java | 140 +++
.../core/responses/EntitySetResponse.java | 82 ++
.../server/core/responses/MetadataResponse.java | 62 ++
.../core/responses/NoContentResponse.java | 100 +++
.../core/responses/PrimitiveValueResponse.java | 105 +++
.../server/core/responses/PropertyResponse.java | 144 ++++
.../core/responses/ServiceDocumentResponse.java | 63 ++
.../server/core/responses/ServiceResponse.java | 119 +++
.../core/responses/ServiceResponseVisior.java | 71 ++
.../server/core/responses/StreamResponse.java | 54 ++
.../olingo/server/core/MetadataParserTest.java | 185 ++++
.../server/core/ServiceDispatcherTest.java | 417 +++++++++
.../olingo/server/example/TripPinDataModel.java | 843 +++++++++++++++++++
.../olingo/server/example/TripPinHandler.java | 546 ++++++++++++
.../server/example/TripPinServiceTest.java | 756 +++++++++++++++++
.../olingo/server/example/TripPinServlet.java | 75 ++
.../src/test/resources/OlingoOrangeTM.png | Bin 0 -> 93316 bytes
.../src/test/resources/airlines.json | 64 ++
.../src/test/resources/airports.json | 394 +++++++++
.../src/test/resources/event.json | 157 ++++
.../src/test/resources/flight-links.json | 52 ++
.../src/test/resources/flight.json | 66 ++
.../src/test/resources/people-links.json | 94 +++
.../src/test/resources/people.json | 323 +++++++
.../src/test/resources/photos.json | 64 ++
.../src/test/resources/trip-links.json | 28 +
.../src/test/resources/trip.json | 224 +++++
.../src/test/resources/trippin.xml | 356 ++++++++
.../json/ODataJsonDeserializer.java | 86 +-
.../serializer/json/ODataJsonSerializer.java | 138 ++-
.../serializer/utils/ContextURLBuilder.java | 9 +-
.../serializer/xml/ODataXmlSerializerImpl.java | 19 +-
.../server/core/uri/UriResourceActionImpl.java | 14 +-
.../server/core/uri/validator/UriValidator.java | 8 +-
.../server-core-exceptions-i18n.properties | 2 +
.../json/ODataJsonDeserializerBasicTest.java | 38 +-
.../json/ODataJsonSerializerTest.java | 13 +-
.../olingo/server/tecsvc/TechnicalServlet.java | 8 +-
.../olingo/server/tecsvc/data/DataCreator.java | 134 ++-
.../olingo/server/tecsvc/data/DataProvider.java | 31 +-
.../olingo/server/tecsvc/data/FunctionData.java | 7 +-
.../processor/TechnicalEntityProcessor.java | 34 +-
.../TechnicalPrimitiveComplexProcessor.java | 15 +-
.../server/tecsvc/data/DataProviderTest.java | 2 +-
.../json/ODataJsonDeserializerEntityTest.java | 4 +-
.../json/ODataJsonSerializerTest.java | 60 +-
.../core/uri/antlr/TestUriParserImpl.java | 11 +-
.../core/uri/validator/UriValidatorTest.java | 18 +-
.../olingo/server/sample/data/DataProvider.java | 13 +-
.../server/sample/processor/CarsProcessor.java | 16 +-
80 files changed, 10821 insertions(+), 229 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java
index 019ef5a..09f2326 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/DecoderTest.java
@@ -6,9 +6,9 @@
* 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
@@ -18,13 +18,13 @@
******************************************************************************/
package org.apache.olingo.commons.core;
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import org.junit.Test;
+
/**
- *
+ *
*/
public class DecoderTest {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java
index 74eb1af..7db30ce 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/EncoderTest.java
@@ -6,9 +6,9 @@
* 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
@@ -18,16 +18,16 @@
******************************************************************************/
package org.apache.olingo.commons.core;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
/**
* Tests for percent-encoding.
- *
+ *
*/
public class EncoderTest {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/pom.xml
----------------------------------------------------------------------
diff --git a/lib/pom.xml b/lib/pom.xml
index 6843ff3..d1e8864 100644
--- a/lib/pom.xml
+++ b/lib/pom.xml
@@ -42,6 +42,7 @@
<module>client-core</module>
<module>server-api</module>
<module>server-core</module>
+ <module>server-core-ext</module>
<module>server-tecsvc</module>
<module>server-test</module>
</modules>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
index b361844..9aabf33 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
@@ -6,9 +6,9 @@
* 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
@@ -19,13 +19,16 @@
package org.apache.olingo.server.api.deserializer;
import java.io.InputStream;
+import java.net.URI;
import java.util.List;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Parameter;
+import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.EdmAction;
import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmProperty;
/**
* Deserializer on OData server side.
@@ -34,7 +37,7 @@ public interface ODataDeserializer {
/**
* Deserializes an entity stream into an {@link Entity} object.
- * Validates: property types, no double properties, correct json types
+ * Validates: property types, no double properties, correct json types
* @param stream
* @param edmEntityType
* @return deserialized {@link Entity} object
@@ -50,7 +53,7 @@ public interface ODataDeserializer {
* @throws DeserializerException
*/
EntitySet entityCollection(InputStream stream, EdmEntityType edmEntityType) throws DeserializerException;
-
+
/**
* Deserializes an action-parameters stream into an {@link Entity} object.
* Validates: parameter types, no double parameters, correct json types.
@@ -60,4 +63,22 @@ public interface ODataDeserializer {
* @throws DeserializerException
*/
List<Parameter> actionParameters(InputStream stream, EdmAction edmAction) throws DeserializerException;
+
+ /**
+ * Deserializes the Property or collections of properties (primitive & complex)
+ * @param stream
+ * @param edmProperty
+ * @return deserialized {@link Property}
+ * @throws DeserializerException
+ */
+ Property property(InputStream stream, EdmProperty edmProperty) throws DeserializerException;
+
+ /**
+ * Read entity references from the provided document
+ * @param stream
+ * @param keys
+ * @return
+ * @throws DeserializerException
+ */
+ List<URI> entityReferences(InputStream stream) throws DeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
index 14c588d..e5dd6b0 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
@@ -6,9 +6,9 @@
* 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
@@ -30,6 +30,7 @@ public class EntityCollectionSerializerOptions {
private CountOption count;
private ExpandOption expand;
private SelectOption select;
+ private boolean onlyReferences;
/** Gets the {@link ContextURL}. */
public ContextURL getContextURL() {
@@ -51,6 +52,11 @@ public class EntityCollectionSerializerOptions {
return select;
}
+ /** only writes the references of the entities*/
+ public boolean onlyReferences() {
+ return onlyReferences;
+ }
+
/** Initializes the options builder. */
public static Builder with() {
return new Builder();
@@ -59,7 +65,7 @@ public class EntityCollectionSerializerOptions {
/** Builder of OData serializer options. */
public static final class Builder {
- private EntityCollectionSerializerOptions options;
+ private final EntityCollectionSerializerOptions options;
private Builder() {
options = new EntityCollectionSerializerOptions();
@@ -89,6 +95,12 @@ public class EntityCollectionSerializerOptions {
return this;
}
+ /** Sets to serialize only references */
+ public Builder setWriteOnlyReferences(final boolean ref) {
+ options.onlyReferences = ref;
+ return this;
+ }
+
/** Builds the OData serializer options. */
public EntityCollectionSerializerOptions build() {
return options;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java
index fcbd150..0abb31c 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntitySerializerOptions.java
@@ -6,9 +6,9 @@
* 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
@@ -27,6 +27,7 @@ public class EntitySerializerOptions {
private ContextURL contextURL;
private ExpandOption expand;
private SelectOption select;
+ private boolean onlyReferences;
/** Gets the {@link ContextURL}. */
public ContextURL getContextURL() {
@@ -43,6 +44,11 @@ public class EntitySerializerOptions {
return select;
}
+ /** only writes the references of the entities*/
+ public boolean onlyReferences() {
+ return onlyReferences;
+ }
+
private EntitySerializerOptions() {}
/** Initializes the options builder. */
@@ -53,7 +59,7 @@ public class EntitySerializerOptions {
/** Builder of OData serializer options. */
public static final class Builder {
- private EntitySerializerOptions options;
+ private final EntitySerializerOptions options;
private Builder() {
options = new EntitySerializerOptions();
@@ -77,6 +83,12 @@ public class EntitySerializerOptions {
return this;
}
+ /** Sets to serialize only references */
+ public Builder setWriteOnlyReferences(final boolean ref) {
+ options.onlyReferences = ref;
+ return this;
+ }
+
/** Builds the OData serializer options. */
public EntitySerializerOptions build() {
return options;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index 72f8ee8..55377ce 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -6,9 +6,9 @@
* 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
@@ -39,7 +39,7 @@ public interface ODataSerializer {
/**
* Writes the service document into an InputStream.
* @param edm the Entity Data Model
- * @param serviceRoot the service-root URI of this OData service
+ * @param serviceRoot the service-root URI of this OData service
*/
InputStream serviceDocument(Edm edm, String serviceRoot) throws SerializerException;
@@ -58,21 +58,23 @@ public interface ODataSerializer {
/**
* Writes entity-collection data into an InputStream.
+ * @param metadata Metadata for the service
* @param entityType the {@link EdmEntityType}
* @param entitySet the data of the entity set
* @param options options for the serializer
*/
- InputStream entityCollection(EdmEntityType entityType, EntitySet entitySet,
- EntityCollectionSerializerOptions options) throws SerializerException;
+ InputStream entityCollection(ServiceMetadata metadata, EdmEntityType entityType,
+ EntitySet entitySet, EntityCollectionSerializerOptions options) throws SerializerException;
/**
* Writes entity data into an InputStream.
+ * @param metadata Metadata for the service
* @param entityType the {@link EdmEntityType}
* @param entity the data of the entity
* @param options options for the serializer
*/
- InputStream entity(EdmEntityType entityType, Entity entity, EntitySerializerOptions options)
- throws SerializerException;
+ InputStream entity(ServiceMetadata metadata, EdmEntityType entityType, Entity entity,
+ EntitySerializerOptions options) throws SerializerException;
/**
* Writes primitive-type instance data into an InputStream.
@@ -85,12 +87,13 @@ public interface ODataSerializer {
/**
* Writes complex-type instance data into an InputStream.
+ * @param metadata Metadata for the service
* @param type complex type
* @param property property value
* @param options options for the serializer
*/
- InputStream complex(EdmComplexType type, Property property, ComplexSerializerOptions options)
- throws SerializerException;
+ InputStream complex(ServiceMetadata metadata, EdmComplexType type, Property property,
+ ComplexSerializerOptions options) throws SerializerException;
/**
* Writes data of a collection of primitive-type instances into an InputStream.
@@ -103,10 +106,11 @@ public interface ODataSerializer {
/**
* Writes data of a collection of complex-type instances into an InputStream.
+ * @param metadata Metadata for the service
* @param type complex type
* @param property property value
* @param options options for the serializer
*/
- InputStream complexCollection(EdmComplexType type, Property property, ComplexSerializerOptions options)
- throws SerializerException;
+ InputStream complexCollection(ServiceMetadata metadata, EdmComplexType type, Property property,
+ ComplexSerializerOptions options) throws SerializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
index 1583241..a7d067f 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerException.java
@@ -6,9 +6,9 @@
* 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
@@ -37,7 +37,9 @@ public class SerializerException extends ODataTranslatedException {
/** parameter: property name */ INCONSISTENT_PROPERTY_TYPE,
/** parameter: property name */ MISSING_PROPERTY,
/** parameters: property name, property value */ WRONG_PROPERTY_VALUE,
- /** parameters: primitive-type name, value */ WRONG_PRIMITIVE_VALUE;
+ /** parameters: primitive-type name, value */ WRONG_PRIMITIVE_VALUE,
+ UNKNOWN_TYPE,
+ WRONG_BASE_TYPE;
@Override
public String getKey() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/pom.xml
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/pom.xml b/lib/server-core-ext/pom.xml
new file mode 100644
index 0000000..a5730c0
--- /dev/null
+++ b/lib/server-core-ext/pom.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<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>
+
+ <artifactId>odata-server-core-ext</artifactId>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-lib</artifactId>
+ <version>4.0.0-beta-03-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <properties>
+ <jetty-version>9.2.7.v20150116</jetty-version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-server-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-server-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-commons-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-runtime</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <scope>test</scope>
+ <version>${jetty-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <version>${jetty-version}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-http</artifactId>
+ <version>${jetty-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-client</artifactId>
+ <scope>test</scope>
+ <version>${jetty-version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
new file mode 100644
index 0000000..199c62d
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java
@@ -0,0 +1,125 @@
+/*
+ * 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.ByteArrayInputStream;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataServerError;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
+import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.core.uri.parser.Parser;
+import org.apache.olingo.server.core.uri.parser.UriParserException;
+import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
+import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
+import org.apache.olingo.server.core.uri.validator.UriValidationException;
+
+public class ErrorHandler {
+ private final OData odata;
+ private final ServiceMetadata metadata;
+ private final CustomContentTypeSupport customContent;
+
+ public ErrorHandler(OData odata, ServiceMetadata metadata, CustomContentTypeSupport customContent) {
+ this.odata = odata;
+ this.metadata = metadata;
+ this.customContent = customContent;
+ }
+
+ public void handleException(Exception e, ODataRequest request, ODataResponse response) {
+ if (e instanceof UriValidationException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((UriValidationException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof UriParserSemanticException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((UriParserSemanticException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof UriParserSyntaxException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((UriParserSyntaxException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof UriParserException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((UriParserException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof ContentNegotiatorException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((ContentNegotiatorException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof SerializerException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((SerializerException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof BatchDeserializerException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((BatchDeserializerException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof DeserializerException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((DeserializerException)e, null);
+ handleServerError(request, response, serverError);
+ } else if(e instanceof ODataHandlerException) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject((ODataHandlerException)e, null);
+ handleServerError(request, response, serverError);
+ } else {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
+ handleServerError(request, response, serverError);
+ }
+ }
+
+ void handleServerError(final ODataRequest request, final ODataResponse response,
+ final ODataServerError serverError) {
+ ContentType requestedContentType;
+ try {
+ UriInfo uriInfo = new Parser().parseUri(request.getRawODataPath(), request.getRawQueryPath(),
+ null, this.metadata.getEdm());
+ requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
+ request, this.customContent, RepresentationType.ERROR);
+ } catch (final ContentNegotiatorException e) {
+ requestedContentType = ODataFormat.JSON.getContentType();
+ } catch (UriParserException e) {
+ requestedContentType = ODataFormat.JSON.getContentType();
+ }
+ processError(response, serverError, requestedContentType);
+ }
+
+ void processError(ODataResponse response, ODataServerError serverError,
+ ContentType requestedContentType) {
+ try {
+ ODataSerializer serializer = this.odata.createSerializer(ODataFormat
+ .fromContentType(requestedContentType));
+ response.setContent(serializer.error(serverError));
+ response.setStatusCode(serverError.getStatusCode());
+ response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
+ } catch (Exception e) {
+ // This should never happen but to be sure we have this catch here
+ // to prevent sending a stacktrace to a client.
+ String responseContent = "{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred during "
+ + "error processing with message: " + e.getMessage() + "\"}}"; //$NON-NLS-1$ //$NON-NLS-2$
+ response.setContent(new ByteArrayInputStream(responseContent.getBytes()));
+ response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
+ response.setHeader(HttpHeader.CONTENT_TYPE,
+ ContentType.APPLICATION_JSON.toContentTypeString());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java
new file mode 100644
index 0000000..e34a28a
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/MetadataParser.java
@@ -0,0 +1,679 @@
+/*
+ * 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.Reader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.Action;
+import org.apache.olingo.commons.api.edm.provider.ActionImport;
+import org.apache.olingo.commons.api.edm.provider.ComplexType;
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.commons.api.edm.provider.EntityContainer;
+import org.apache.olingo.commons.api.edm.provider.EntitySet;
+import org.apache.olingo.commons.api.edm.provider.EntityType;
+import org.apache.olingo.commons.api.edm.provider.EnumMember;
+import org.apache.olingo.commons.api.edm.provider.EnumType;
+import org.apache.olingo.commons.api.edm.provider.Function;
+import org.apache.olingo.commons.api.edm.provider.FunctionImport;
+import org.apache.olingo.commons.api.edm.provider.NavigationProperty;
+import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
+import org.apache.olingo.commons.api.edm.provider.OnDelete;
+import org.apache.olingo.commons.api.edm.provider.OnDeleteAction;
+import org.apache.olingo.commons.api.edm.provider.Operation;
+import org.apache.olingo.commons.api.edm.provider.Parameter;
+import org.apache.olingo.commons.api.edm.provider.Property;
+import org.apache.olingo.commons.api.edm.provider.PropertyRef;
+import org.apache.olingo.commons.api.edm.provider.ReferentialConstraint;
+import org.apache.olingo.commons.api.edm.provider.ReturnType;
+import org.apache.olingo.commons.api.edm.provider.Schema;
+import org.apache.olingo.commons.api.edm.provider.Singleton;
+import org.apache.olingo.commons.api.edm.provider.Term;
+import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
+
+/**
+ * This class can convert a CSDL document into EDMProvider object
+ */
+public class MetadataParser {
+
+ public EdmProvider buildEdmProvider(Reader csdl) throws XMLStreamException {
+ XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
+ XMLEventReader reader = xmlInputFactory.createXMLEventReader(csdl);
+
+ SchemaBasedEdmProvider provider = new SchemaBasedEdmProvider();
+ new ElementReader<SchemaBasedEdmProvider>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, SchemaBasedEdmProvider provider,
+ String name) throws XMLStreamException {
+ String version = attr(element, "Version");
+ if (version.equals("4.0")) {
+ readDataServicesAndReference(reader, element, provider);
+ }
+ }
+ }.read(reader, null, provider, "Edmx");
+
+ return provider;
+ }
+
+ private void readDataServicesAndReference(XMLEventReader reader, StartElement element,
+ SchemaBasedEdmProvider provider) throws XMLStreamException {
+ new ElementReader<SchemaBasedEdmProvider>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, SchemaBasedEdmProvider provider,
+ String name) throws XMLStreamException {
+ if (name.equals("DataServices")) {
+ readSchema(reader, element, provider);
+ } else if (name.equals("Reference")) {
+ readReference(reader, element, provider, "Reference");
+ }
+ }
+ }.read(reader, element, provider, "DataServices", "Reference");
+ }
+
+ private void readReference(XMLEventReader reader, StartElement element,
+ SchemaBasedEdmProvider provider, String name) throws XMLStreamException {
+ new ElementReader<SchemaBasedEdmProvider>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, SchemaBasedEdmProvider t, String name)
+ throws XMLStreamException {
+ // TODO:
+ }
+ }.read(reader, element, provider, name);
+ }
+
+ private void readSchema(XMLEventReader reader, StartElement element,
+ SchemaBasedEdmProvider provider) throws XMLStreamException {
+
+ Schema schema = new Schema();
+ schema.setComplexTypes(new ArrayList<ComplexType>());
+ schema.setActions(new ArrayList<Action>());
+ schema.setEntityTypes(new ArrayList<EntityType>());
+ schema.setEnumTypes(new ArrayList<EnumType>());
+ schema.setFunctions(new ArrayList<Function>());
+ schema.setTerms(new ArrayList<Term>());
+ schema.setTypeDefinitions(new ArrayList<TypeDefinition>());
+
+ new ElementReader<Schema>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, Schema schema, String name)
+ throws XMLStreamException {
+ schema.setNamespace(attr(element, "Namespace"));
+ schema.setAlias(attr(element, "Alias"));
+ readSchemaContents(reader, schema);
+ }
+ }.read(reader, element, schema, "Schema");
+ provider.addSchema(schema);
+ }
+
+ private void readSchemaContents(XMLEventReader reader, Schema schema) throws XMLStreamException {
+ new ElementReader<Schema>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, Schema schema, String name)
+ throws XMLStreamException {
+ if (name.equals("Action")) {
+ readAction(reader, element, schema);
+ } else if (name.equals("Annotations")) {
+ // TODO:
+ } else if (name.equals("Annotation")) {
+ // TODO:
+ } else if (name.equals("ComplexType")) {
+ readComplexType(reader, element, schema);
+ } else if (name.equals("EntityContainer")) {
+ readEntityContainer(reader, element, schema);
+ } else if (name.equals("EntityType")) {
+ readEntityType(reader, element, schema);
+ } else if (name.equals("EnumType")) {
+ readEnumType(reader, element, schema);
+ } else if (name.equals("Function")) {
+ readFunction(reader, element, schema);
+ } else if (name.equals("Term")) {
+ schema.getTerms().add(readTerm(element));
+ } else if (name.equals("TypeDefinition")) {
+ schema.getTypeDefinitions().add(readTypeDefinition(element));
+ }
+ }
+ }.read(reader, null, schema, "Action", "Annotations", "Annotation", "ComplexType",
+ "EntityContainer", "EntityType", "EnumType", "Function", "Term", "TypeDefinition");
+ }
+
+ private void readAction(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+
+ Action action = new Action();
+ action.setParameters(new ArrayList<Parameter>());
+ action.setName(attr(element, "Name"));
+ action.setBound(Boolean.parseBoolean(attr(element, "IsBound")));
+ String entitySetPath = attr(element, "EntitySetPath");
+ if (entitySetPath != null) {
+ // TODO: need to parse into binding and path.
+ action.setEntitySetPath(entitySetPath);
+ }
+ readOperationParameters(reader, action);
+ schema.getActions().add(action);
+ }
+
+ private FullQualifiedName readType(StartElement element) {
+ String type = attr(element, "Type");
+ if (type.startsWith("Collection(") && type.endsWith(")")) {
+ return new FullQualifiedName(type.substring(11, type.length() - 1));
+ }
+ return new FullQualifiedName(type);
+ }
+
+ private boolean isCollectionType(StartElement element) {
+ String type = attr(element, "Type");
+ if (type.startsWith("Collection(") && type.endsWith(")")) {
+ return true;
+ }
+ return false;
+ }
+
+ private void readReturnType(StartElement element, Operation operation) {
+ ReturnType returnType = new ReturnType();
+ returnType.setType(readType(element));
+ returnType.setCollection(isCollectionType(element));
+ returnType.setNullable(Boolean.parseBoolean(attr(element, "Nullable")));
+
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ returnType.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ returnType.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ returnType.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ operation.setReturnType(returnType);
+ }
+
+ private void readParameter(StartElement element, Operation operation) {
+ Parameter parameter = new Parameter();
+ parameter.setName(attr(element, "Name"));
+ parameter.setType(readType(element));
+ parameter.setCollection(isCollectionType(element));
+ parameter.setNullable(Boolean.parseBoolean(attr(element, "Nullable")));
+
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ parameter.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ parameter.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ parameter.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ operation.getParameters().add(parameter);
+ }
+
+ private TypeDefinition readTypeDefinition(StartElement element) {
+ TypeDefinition td = new TypeDefinition();
+ td.setName(attr(element, "Name"));
+ td.setUnderlyingType(new FullQualifiedName(attr(element, "UnderlyingType")));
+ td.setUnicode(Boolean.parseBoolean(attr(element, "Unicode")));
+
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ td.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ td.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ td.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ return td;
+ }
+
+ private Term readTerm(StartElement element) {
+ Term term = new Term();
+ term.setName(attr(element, "Name"));
+ term.setType(attr(element, "Type"));
+ if (attr(element, "BaseTerm") != null) {
+ term.setBaseTerm(attr(element, "BaseTerm"));
+ }
+ if (attr(element, "DefaultValue") != null) {
+ term.setDefaultValue(attr(element, "DefaultValue"));
+ }
+ if (attr(element, "AppliesTo") != null) {
+ term.setAppliesTo(Arrays.asList(attr(element, "AppliesTo")));
+ }
+ term.setNullable(Boolean.parseBoolean(attr(element, "Nullable")));
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ term.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ term.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ term.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ return term;
+ }
+
+ private void readFunction(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ Function function = new Function();
+ function.setParameters(new ArrayList<Parameter>());
+ function.setName(attr(element, "Name"));
+ function.setBound(Boolean.parseBoolean(attr(element, "IsBound")));
+ function.setComposable(Boolean.parseBoolean(attr(element, "IsComposable")));
+ String entitySetPath = attr(element, "EntitySetPath");
+ if (entitySetPath != null) {
+ // TODO: need to parse into binding and path.
+ function.setEntitySetPath(entitySetPath);
+ }
+ readOperationParameters(reader, function);
+ schema.getFunctions().add(function);
+ }
+
+ private void readOperationParameters(XMLEventReader reader, final Operation operation)
+ throws XMLStreamException {
+ new ElementReader<Operation>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, Operation operation, String name)
+ throws XMLStreamException {
+ if (name.equals("Parameter")) {
+ readParameter(element, operation);
+ } else if (name.equals("ReturnType")) {
+ readReturnType(element, operation);
+ }
+ }
+ }.read(reader, null, operation, "Parameter", "ReturnType");
+ }
+
+ private void readEnumType(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ EnumType type = new EnumType();
+ type.setMembers(new ArrayList<EnumMember>());
+ type.setName(attr(element, "Name"));
+ if (attr(element, "UnderlyingType") != null) {
+ type.setUnderlyingType(new FullQualifiedName(attr(element, "UnderlyingType")));
+ }
+ type.setFlags(Boolean.parseBoolean(attr(element, "IsFlags")));
+
+ readEnumMembers(reader, element, type);
+ schema.getEnumTypes().add(type);
+ }
+
+ private void readEnumMembers(XMLEventReader reader, StartElement element, EnumType type)
+ throws XMLStreamException {
+ new ElementReader<EnumType>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, EnumType type, String name)
+ throws XMLStreamException {
+ EnumMember member = new EnumMember();
+ member.setName(attr(element, "Name"));
+ member.setValue(attr(element, "Value"));
+ type.getMembers().add(member);
+ }
+ }.read(reader, element, type, "Member");
+ }
+
+ private void readEntityType(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ EntityType entityType = new EntityType();
+ entityType.setProperties(new ArrayList<Property>());
+ entityType.setNavigationProperties(new ArrayList<NavigationProperty>());
+ entityType.setKey(new ArrayList<PropertyRef>());
+ entityType.setName(attr(element, "Name"));
+ if (attr(element, "BaseType") != null) {
+ entityType.setBaseType(new FullQualifiedName(attr(element, "BaseType")));
+ }
+ entityType.setAbstract(Boolean.parseBoolean(attr(element, "Abstract")));
+ entityType.setOpenType(Boolean.parseBoolean(attr(element, "OpenType")));
+ entityType.setHasStream(Boolean.parseBoolean(attr(element, "HasStream")));
+ readEntityProperties(reader, entityType);
+ schema.getEntityTypes().add(entityType);
+ }
+
+ private void readEntityProperties(XMLEventReader reader, EntityType entityType)
+ throws XMLStreamException {
+ new ElementReader<EntityType>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, EntityType entityType, String name)
+ throws XMLStreamException {
+ if (name.equals("Property")) {
+ entityType.getProperties().add(readProperty(element));
+ } else if (name.equals("NavigationProperty")) {
+ entityType.getNavigationProperties().add(readNavigationProperty(reader, element));
+ } else if (name.equals("Key")) {
+ readKey(reader, element, entityType);
+ }
+ }
+ }.read(reader, null, entityType, "Property", "NavigationProperty", "Key");
+ }
+
+ private void readKey(XMLEventReader reader, StartElement element, EntityType entityType)
+ throws XMLStreamException {
+ new ElementReader<EntityType>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, EntityType entityType, String name)
+ throws XMLStreamException {
+ PropertyRef ref = new PropertyRef();
+ ref.setName(attr(element, "Name"));
+ ref.setAlias(attr(element, "Alias"));
+ entityType.getKey().add(ref);
+ }
+ }.read(reader, element, entityType, "PropertyRef");
+ }
+
+ private NavigationProperty readNavigationProperty(XMLEventReader reader, StartElement element)
+ throws XMLStreamException {
+ NavigationProperty property = new NavigationProperty();
+ property.setReferentialConstraints(new ArrayList<ReferentialConstraint>());
+
+ property.setName(attr(element, "Name"));
+ property.setType(readType(element));
+ property.setCollection(isCollectionType(element));
+ property.setNullable(Boolean.parseBoolean(attr(element, "Nullable")));
+ property.setPartner(attr(element, "Partner"));
+ property.setContainsTarget(Boolean.parseBoolean(attr(element, "ContainsTarget")));
+
+ new ElementReader<NavigationProperty>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, NavigationProperty property,
+ String name) throws XMLStreamException {
+ if (name.equals("ReferentialConstraint")) {
+ ReferentialConstraint constraint = new ReferentialConstraint();
+ constraint.setProperty(attr(element, "Property"));
+ constraint.setReferencedProperty(attr(element, "ReferencedProperty"));
+ property.getReferentialConstraints().add(constraint);
+ } else if (name.equals("OnDelete")) {
+ property.setOnDelete(new OnDelete().setAction(OnDeleteAction.valueOf(attr(element, "Action"))));
+ }
+ }
+ }.read(reader, element, property, "ReferentialConstraint", "OnDelete");
+ return property;
+ }
+
+ private String attr(StartElement element, String name) {
+ Attribute attr = element.getAttributeByName(new QName(name));
+ if (attr != null) {
+ return attr.getValue();
+ }
+ return null;
+ }
+
+ private Property readProperty(StartElement element) {
+ Property property = new Property();
+ property.setName(attr(element, "Name"));
+ property.setType(readType(element));
+ property.setCollection(isCollectionType(element));
+ property.setNullable(Boolean.parseBoolean(attr(element, "Nullable") == null ? "true" : attr(
+ element, "Nullable")));
+ property.setUnicode(Boolean.parseBoolean(attr(element, "Unicode")));
+
+ String maxLength = attr(element, "MaxLength");
+ if (maxLength != null) {
+ property.setMaxLength(Integer.parseInt(maxLength));
+ }
+ String precision = attr(element, "Precision");
+ if (precision != null) {
+ property.setPrecision(Integer.parseInt(precision));
+ }
+ String scale = attr(element, "Scale");
+ if (scale != null) {
+ property.setScale(Integer.parseInt(scale));
+ }
+ String srid = attr(element, "SRID");
+ if (srid != null) {
+ // TODO: no olingo support yet.
+ }
+ String defaultValue = attr(element, "DefaultValue");
+ if (defaultValue != null) {
+ property.setDefaultValue(defaultValue);
+ }
+ return property;
+ }
+
+ private void readEntityContainer(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ final EntityContainer container = new EntityContainer();
+ container.setName(attr(element, "Name"));
+ if (attr(element, "Extends") != null) {
+ container.setExtendsContainer(attr(element, "Extends"));
+ }
+ container.setActionImports(new ArrayList<ActionImport>());
+ container.setFunctionImports(new ArrayList<FunctionImport>());
+ container.setEntitySets(new ArrayList<EntitySet>());
+ container.setSingletons(new ArrayList<Singleton>());
+
+ new ElementReader<Schema>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, Schema schema, String name)
+ throws XMLStreamException {
+ if (name.equals("EntitySet")) {
+ readEntitySet(reader, element, container);
+ } else if (name.equals("Singleton")) {
+ readSingleton(reader, element, container);
+ } else if (name.equals("ActionImport")) {
+ readActionImport(element, container);
+ } else if (name.equals("FunctionImport")) {
+ readFunctionImport(element, container);
+ }
+ }
+
+ private void readFunctionImport(StartElement element, EntityContainer container) {
+ FunctionImport functionImport = new FunctionImport();
+ functionImport.setName(attr(element, "Name"));
+ functionImport.setFunction(new FullQualifiedName(attr(element, "Function")));
+ functionImport.setIncludeInServiceDocument(Boolean.parseBoolean(attr(element,
+ "IncludeInServiceDocument")));
+
+ String entitySet = attr(element, "EntitySet");
+ if (entitySet != null) {
+ functionImport.setEntitySet(entitySet);
+ }
+ container.getFunctionImports().add(functionImport);
+ }
+
+ private void readActionImport(StartElement element, EntityContainer container) {
+ ActionImport actionImport = new ActionImport();
+ actionImport.setName(attr(element, "Name"));
+ actionImport.setAction(new FullQualifiedName(attr(element, "Action")));
+
+ String entitySet = attr(element, "EntitySet");
+ if (entitySet != null) {
+ actionImport.setEntitySet(entitySet);
+ }
+ container.getActionImports().add(actionImport);
+ }
+
+ private void readSingleton(XMLEventReader reader, StartElement element,
+ EntityContainer container) throws XMLStreamException {
+ Singleton singleton = new Singleton();
+ singleton.setNavigationPropertyBindings(new ArrayList<NavigationPropertyBinding>());
+ singleton.setName(attr(element, "Name"));
+ singleton.setType(new FullQualifiedName(attr(element, "Type")));
+ singleton.setNavigationPropertyBindings(new ArrayList<NavigationPropertyBinding>());
+ readNavigationPropertyBindings(reader, element, singleton.getNavigationPropertyBindings());
+ container.getSingletons().add(singleton);
+ }
+
+ private void readEntitySet(XMLEventReader reader, StartElement element,
+ EntityContainer container) throws XMLStreamException {
+ EntitySet entitySet = new EntitySet();
+ entitySet.setName(attr(element, "Name"));
+ entitySet.setType(new FullQualifiedName(attr(element, "EntityType")));
+ entitySet.setIncludeInServiceDocument(Boolean.parseBoolean(attr(element,
+ "IncludeInServiceDocument")));
+ entitySet.setNavigationPropertyBindings(new ArrayList<NavigationPropertyBinding>());
+ readNavigationPropertyBindings(reader, element, entitySet.getNavigationPropertyBindings());
+ container.getEntitySets().add(entitySet);
+ }
+
+ private void readNavigationPropertyBindings(XMLEventReader reader, StartElement element,
+ List<NavigationPropertyBinding> bindings) throws XMLStreamException {
+ new ElementReader<List<NavigationPropertyBinding>>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element,
+ List<NavigationPropertyBinding> bindings, String name) throws XMLStreamException {
+ NavigationPropertyBinding binding = new NavigationPropertyBinding();
+ binding.setPath(attr(element, "Path"));
+ binding.setTarget(attr(element, "Target"));
+ bindings.add(binding);
+ }
+
+ }.read(reader, element, bindings, "NavigationPropertyBinding");
+ ;
+ }
+ }.read(reader, element, schema, "EntitySet", "Singleton", "ActionImport", "FunctionImport");
+ schema.setEntityContainer(container);
+ }
+
+ private void readComplexType(XMLEventReader reader, StartElement element, Schema schema)
+ throws XMLStreamException {
+ ComplexType complexType = new ComplexType();
+ complexType.setProperties(new ArrayList<Property>());
+ complexType.setNavigationProperties(new ArrayList<NavigationProperty>());
+ complexType.setName(attr(element, "Name"));
+ if (attr(element, "BaseType") != null) {
+ complexType.setBaseType(new FullQualifiedName(attr(element, "BaseType")));
+ }
+ complexType.setAbstract(Boolean.parseBoolean(attr(element, "Abstract")));
+ complexType.setOpenType(Boolean.parseBoolean(attr(element, "OpenType")));
+ readProperties(reader, complexType);
+
+ schema.getComplexTypes().add(complexType);
+ }
+
+ private void readProperties(XMLEventReader reader, ComplexType complexType)
+ throws XMLStreamException {
+ new ElementReader<ComplexType>() {
+ @Override
+ void build(XMLEventReader reader, StartElement element, ComplexType complexType, String name)
+ throws XMLStreamException {
+ if (name.equals("Property")) {
+ complexType.getProperties().add(readProperty(element));
+ } else if (name.equals("NavigationProperty")) {
+ complexType.getNavigationProperties().add(readNavigationProperty(reader, element));
+ }
+ }
+ }.read(reader, null, complexType, "Property", "NavigationProperty");
+ }
+
+ abstract class ElementReader<T> {
+ void read(XMLEventReader reader, StartElement element, T t, String... names)
+ throws XMLStreamException {
+ while (reader.hasNext()) {
+ XMLEvent event = reader.peek();
+
+ event = skipAnnotations(reader, event);
+
+ if (!event.isStartElement() && !event.isEndElement()) {
+ reader.nextEvent();
+ continue;
+ }
+
+ boolean hit = false;
+
+ for (int i = 0; i < names.length; i++) {
+ if (event.isStartElement()) {
+ element = event.asStartElement();
+ if (element.getName().getLocalPart().equals(names[i])) {
+ reader.nextEvent(); // advance cursor
+ // System.out.println("reading = "+names[i]);
+ build(reader, element, t, names[i]);
+ hit = true;
+ }
+ }
+ if (event.isEndElement()) {
+ EndElement e = event.asEndElement();
+ if (e.getName().getLocalPart().equals(names[i])) {
+ reader.nextEvent(); // advance cursor
+ // System.out.println("done reading = "+names[i]);
+ hit = true;
+ }
+ }
+ }
+ if (!hit) {
+ break;
+ }
+ }
+ }
+
+ private XMLEvent skipAnnotations(XMLEventReader reader, XMLEvent event)
+ throws XMLStreamException {
+ boolean skip = false;
+
+ while (reader.hasNext()) {
+ if (event.isStartElement()) {
+ StartElement element = event.asStartElement();
+ if (element.getName().getLocalPart().equals("Annotation")) {
+ skip = true;
+ }
+ }
+ if (event.isEndElement()) {
+ EndElement element = event.asEndElement();
+ if (element.getName().getLocalPart().equals("Annotation")) {
+ return reader.peek();
+ }
+ }
+ if (skip) {
+ event = reader.nextEvent();
+ } else {
+ return event;
+ }
+ }
+ return event;
+ }
+
+ abstract void build(XMLEventReader reader, StartElement element, T t, String name)
+ throws XMLStreamException;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java
new file mode 100644
index 0000000..ddb8e6b
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4HttpHandler.java
@@ -0,0 +1,123 @@
+/*
+ * 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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.processor.Processor;
+import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.legacy.ProcessorServiceHandler;
+
+public class OData4HttpHandler extends ODataHttpHandlerImpl {
+ private ServiceHandler handler;
+ private final ServiceMetadata serviceMetadata;
+ private final OData odata;
+ private CustomContentTypeSupport customContentTypeSupport;
+
+
+ public OData4HttpHandler(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ this.odata = odata;
+ this.serviceMetadata = serviceMetadata;
+ // this is support old interfaces
+ this.handler = new ProcessorServiceHandler();
+ this.handler.init(odata, serviceMetadata);
+ }
+
+ @Override
+ public void process(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) {
+ ODataRequest request = null;
+ ODataResponse response = new ODataResponse();
+
+ try {
+ request = createODataRequest(httpRequest, 0);
+ validateODataVersion(request, response);
+
+ ServiceDispatcher dispatcher = new ServiceDispatcher(this.odata, this.serviceMetadata,
+ handler, this.customContentTypeSupport);
+ dispatcher.execute(request, response);
+
+ } catch (Exception e) {
+ ErrorHandler handler = new ErrorHandler(this.odata, this.serviceMetadata,
+ this.customContentTypeSupport);
+ handler.handleException(e, request, response);
+ }
+ convertToHttp(httpResponse, response);
+ }
+
+
+ ODataRequest createODataRequest(final HttpServletRequest httpRequest, final int split)
+ throws ODataTranslatedException {
+ try {
+ ODataRequest odRequest = new ODataRequest();
+
+ odRequest.setBody(httpRequest.getInputStream());
+ extractHeaders(odRequest, httpRequest);
+ extractMethod(odRequest, httpRequest);
+ extractUri(odRequest, httpRequest, split);
+
+ return odRequest;
+ } catch (final IOException e) {
+ throw new SerializerException(
+ "An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION); //$NON-NLS-1$
+ }
+ }
+
+ void validateODataVersion(final ODataRequest request, final ODataResponse response)
+ throws ODataHandlerException {
+ final String maxVersion = request.getHeader(HttpHeader.ODATA_MAX_VERSION);
+ response.setHeader(HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString());
+
+ if (maxVersion != null) {
+ if (ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) {
+ throw new ODataHandlerException("ODataVersion not supported: " + maxVersion, //$NON-NLS-1$
+ ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion);
+ }
+ }
+ }
+
+ @Override
+ public void register(final Processor processor) {
+
+ if (processor instanceof ServiceHandler) {
+ this.handler = (ServiceHandler) processor;
+ this.handler.init(this.odata, this.serviceMetadata);
+ }
+
+ if (this.handler instanceof ProcessorServiceHandler) {
+ ((ProcessorServiceHandler)this.handler).register(processor);
+ }
+ }
+
+ @Override
+ public void register(final CustomContentTypeSupport customContentTypeSupport) {
+ this.customContentTypeSupport = customContentTypeSupport;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4Impl.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4Impl.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4Impl.java
new file mode 100644
index 0000000..bde9c96
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/OData4Impl.java
@@ -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.OData;
+import org.apache.olingo.server.api.ODataHttpHandler;
+import org.apache.olingo.server.api.ServiceMetadata;
+
+public class OData4Impl extends ODataImpl {
+
+ public static OData newInstance() {
+ try {
+ final Class<?> clazz = Class.forName(OData4Impl.class.getName());
+ final Object object = clazz.newInstance();
+ return (OData) object;
+ } catch (final Exception e) {
+ throw new ODataRuntimeException(e);
+ }
+ }
+
+ private OData4Impl() {
+ }
+
+ @Override
+ public ODataHttpHandler createHandler(final ServiceMetadata edm) {
+ return new OData4HttpHandler(this, edm);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java
new file mode 100644
index 0000000..ee00638
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLHierarchyVisitor.java
@@ -0,0 +1,333 @@
+/*
+ * 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.util.List;
+
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoAll;
+import org.apache.olingo.server.api.uri.UriInfoBatch;
+import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
+import org.apache.olingo.server.api.uri.UriInfoEntityId;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.UriInfoMetadata;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.UriInfoService;
+import org.apache.olingo.server.api.uri.UriResource;
+import org.apache.olingo.server.api.uri.UriResourceAction;
+import org.apache.olingo.server.api.uri.UriResourceComplexProperty;
+import org.apache.olingo.server.api.uri.UriResourceCount;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.api.uri.UriResourceIt;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAll;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAny;
+import org.apache.olingo.server.api.uri.UriResourceLambdaVariable;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
+import org.apache.olingo.server.api.uri.UriResourceRef;
+import org.apache.olingo.server.api.uri.UriResourceRoot;
+import org.apache.olingo.server.api.uri.UriResourceSingleton;
+import org.apache.olingo.server.api.uri.UriResourceValue;
+import org.apache.olingo.server.api.uri.queryoption.CountOption;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.server.api.uri.queryoption.FilterOption;
+import org.apache.olingo.server.api.uri.queryoption.FormatOption;
+import org.apache.olingo.server.api.uri.queryoption.IdOption;
+import org.apache.olingo.server.api.uri.queryoption.OrderByOption;
+import org.apache.olingo.server.api.uri.queryoption.SearchOption;
+import org.apache.olingo.server.api.uri.queryoption.SelectOption;
+import org.apache.olingo.server.api.uri.queryoption.SkipOption;
+import org.apache.olingo.server.api.uri.queryoption.SkipTokenOption;
+import org.apache.olingo.server.api.uri.queryoption.TopOption;
+
+public class RequestURLHierarchyVisitor implements RequestURLVisitor {
+
+ private UriInfo uriInfo;
+
+ public UriInfo getUriInfo() {
+ return this.uriInfo;
+ }
+
+ @Override
+ public void visit(UriInfo info) {
+ this.uriInfo = info;
+
+ UriInfoKind kind = info.getKind();
+ switch (kind) {
+ case all:
+ visit(info.asUriInfoAll());
+ break;
+ case batch:
+ visit(info.asUriInfoBatch());
+ break;
+ case crossjoin:
+ visit(info.asUriInfoCrossjoin());
+ break;
+ case entityId:
+ visit(info.asUriInfoEntityId());
+ break;
+ case metadata:
+ visit(info.asUriInfoMetadata());
+ break;
+ case resource:
+ visit(info.asUriInfoResource());
+ break;
+ case service:
+ visit(info.asUriInfoService());
+ break;
+ }
+ }
+
+ @Override
+ public void visit(UriInfoService info) {
+ }
+
+ @Override
+ public void visit(UriInfoAll info) {
+ }
+
+ @Override
+ public void visit(UriInfoBatch info) {
+ }
+
+ @Override
+ public void visit(UriInfoCrossjoin info) {
+ }
+
+ @Override
+ public void visit(UriInfoEntityId info) {
+ visit(info.getSelectOption());
+
+ if (info.getExpandOption() != null) {
+ visit(info.getExpandOption());
+ }
+ if (info.getFormatOption() != null) {
+ visit(info.getFormatOption());
+ }
+ if (info.getIdOption() != null) {
+ visit(info.getIdOption(), info.getEntityTypeCast());
+ }
+ }
+
+ @Override
+ public void visit(UriInfoMetadata info) {
+ }
+
+ @Override
+ public void visit(UriInfoResource info) {
+ List<UriResource> parts = info.getUriResourceParts();
+ for (UriResource resource : parts) {
+ switch (resource.getKind()) {
+ case action:
+ visit((UriResourceAction) resource);
+ break;
+ case complexProperty:
+ visit((UriResourceComplexProperty) resource);
+ break;
+ case count:
+ visit((UriResourceCount) resource);
+ break;
+ case entitySet:
+ visit((UriResourceEntitySet) resource);
+ break;
+ case function:
+ visit((UriResourceFunction) resource);
+ break;
+ case it:
+ visit((UriResourceIt) resource);
+ break;
+ case lambdaAll:
+ visit((UriResourceLambdaAll) resource);
+ break;
+ case lambdaAny:
+ visit((UriResourceLambdaAny) resource);
+ break;
+ case lambdaVariable:
+ visit((UriResourceLambdaVariable) resource);
+ break;
+ case navigationProperty:
+ visit((UriResourceNavigation) resource);
+ break;
+ case ref:
+ visit((UriResourceRef) resource);
+ break;
+ case root:
+ visit((UriResourceRoot) resource);
+ break;
+ case primitiveProperty:
+ visit((UriResourcePrimitiveProperty) resource);
+ break;
+ case singleton:
+ visit((UriResourceSingleton) resource);
+ break;
+ case value:
+ visit((UriResourceValue) resource);
+ break;
+ }
+ }
+
+ // http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Toc372793682
+ if (info.getSearchOption() != null) {
+ visit(info.getSearchOption());
+ }
+
+ if (info.getFilterOption() != null) {
+ visit(info.getFilterOption());
+ }
+
+ if (info.getCountOption() != null) {
+ visit(info.getCountOption());
+ }
+
+ visit(info.getOrderByOption());
+
+ if (info.getSkipOption() != null) {
+ visit(info.getSkipOption());
+ }
+
+ if (info.getTopOption() != null) {
+ visit(info.getTopOption());
+ }
+
+ if (info.getExpandOption() != null) {
+ visit(info.getExpandOption());
+ }
+
+ visit(info.getSelectOption());
+
+ if (info.getFormatOption() != null) {
+ visit(info.getFormatOption());
+ }
+
+ if (info.getIdOption() != null) {
+ visit(info.getIdOption(), null);
+ }
+
+ if (info.getSkipTokenOption() != null) {
+ visit(info.getSkipTokenOption());
+ }
+
+ }
+
+ @Override
+ public void visit(ExpandOption option) {
+ }
+
+ @Override
+ public void visit(FilterOption info) {
+ }
+
+ @Override
+ public void visit(FormatOption info) {
+ }
+
+ @Override
+ public void visit(IdOption info, EdmEntityType type) {
+ }
+
+ @Override
+ public void visit(CountOption info) {
+ }
+
+ @Override
+ public void visit(OrderByOption option) {
+ }
+
+ @Override
+ public void visit(SearchOption option) {
+ }
+
+ @Override
+ public void visit(SelectOption option) {
+ }
+
+ @Override
+ public void visit(SkipOption option) {
+ }
+
+ @Override
+ public void visit(SkipTokenOption option) {
+ }
+
+ @Override
+ public void visit(TopOption option) {
+ }
+
+ @Override
+ public void visit(UriResourceCount option) {
+ }
+
+ @Override
+ public void visit(UriResourceRef info) {
+ }
+
+ @Override
+ public void visit(UriResourceRoot info) {
+ }
+
+ @Override
+ public void visit(UriResourceValue info) {
+ }
+
+ @Override
+ public void visit(UriResourceAction info) {
+ }
+
+ @Override
+ public void visit(UriResourceEntitySet info) {
+ }
+
+ @Override
+ public void visit(UriResourceFunction info) {
+ }
+
+ @Override
+ public void visit(UriResourceIt info) {
+ }
+
+ @Override
+ public void visit(UriResourceLambdaAll info) {
+ }
+
+ @Override
+ public void visit(UriResourceLambdaAny info) {
+ }
+
+ @Override
+ public void visit(UriResourceLambdaVariable info) {
+ }
+
+ @Override
+ public void visit(UriResourceNavigation info) {
+ }
+
+ @Override
+ public void visit(UriResourceSingleton info) {
+ }
+
+ @Override
+ public void visit(UriResourceComplexProperty info) {
+ }
+
+ @Override
+ public void visit(UriResourcePrimitiveProperty info) {
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLVisitor.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLVisitor.java
new file mode 100644
index 0000000..f3f4027
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLVisitor.java
@@ -0,0 +1,127 @@
+/*
+ * 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.edm.EdmEntityType;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoAll;
+import org.apache.olingo.server.api.uri.UriInfoBatch;
+import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
+import org.apache.olingo.server.api.uri.UriInfoEntityId;
+import org.apache.olingo.server.api.uri.UriInfoMetadata;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.UriInfoService;
+import org.apache.olingo.server.api.uri.UriResourceAction;
+import org.apache.olingo.server.api.uri.UriResourceComplexProperty;
+import org.apache.olingo.server.api.uri.UriResourceCount;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.api.uri.UriResourceIt;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAll;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAny;
+import org.apache.olingo.server.api.uri.UriResourceLambdaVariable;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
+import org.apache.olingo.server.api.uri.UriResourceRef;
+import org.apache.olingo.server.api.uri.UriResourceRoot;
+import org.apache.olingo.server.api.uri.UriResourceSingleton;
+import org.apache.olingo.server.api.uri.UriResourceValue;
+import org.apache.olingo.server.api.uri.queryoption.CountOption;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.server.api.uri.queryoption.FilterOption;
+import org.apache.olingo.server.api.uri.queryoption.FormatOption;
+import org.apache.olingo.server.api.uri.queryoption.IdOption;
+import org.apache.olingo.server.api.uri.queryoption.OrderByOption;
+import org.apache.olingo.server.api.uri.queryoption.SearchOption;
+import org.apache.olingo.server.api.uri.queryoption.SelectOption;
+import org.apache.olingo.server.api.uri.queryoption.SkipOption;
+import org.apache.olingo.server.api.uri.queryoption.SkipTokenOption;
+import org.apache.olingo.server.api.uri.queryoption.TopOption;
+
+public interface RequestURLVisitor {
+
+ void visit(UriInfo info);
+
+ void visit(UriInfoService info);
+
+ void visit(UriInfoAll info);
+
+ void visit(UriInfoBatch info);
+
+ void visit(UriInfoCrossjoin info);
+
+ void visit(UriInfoEntityId info);
+
+ void visit(UriInfoMetadata info);
+
+ void visit(UriInfoResource info);
+
+ // Walk UriInfoResource
+ void visit(ExpandOption option);
+
+ void visit(FilterOption info);
+
+ void visit(FormatOption info);
+
+ void visit(IdOption info, EdmEntityType type);
+
+ void visit(CountOption info);
+
+ void visit(OrderByOption option);
+
+ void visit(SearchOption option);
+
+ void visit(SelectOption option);
+
+ void visit(SkipOption option);
+
+ void visit(SkipTokenOption option);
+
+ void visit(TopOption option);
+
+ void visit(UriResourceCount option);
+
+ void visit(UriResourceRef info);
+
+ void visit(UriResourceRoot info);
+
+ void visit(UriResourceValue info);
+
+ void visit(UriResourceAction info);
+
+ void visit(UriResourceEntitySet info);
+
+ void visit(UriResourceFunction info);
+
+ void visit(UriResourceIt info);
+
+ void visit(UriResourceLambdaAll info);
+
+ void visit(UriResourceLambdaAny info);
+
+ void visit(UriResourceLambdaVariable info);
+
+ void visit(UriResourceNavigation info);
+
+ void visit(UriResourceSingleton info);
+
+ void visit(UriResourceComplexProperty info);
+
+ void visit(UriResourcePrimitiveProperty info);
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ReturnRepresentation.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ReturnRepresentation.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ReturnRepresentation.java
new file mode 100644
index 0000000..e9a213e
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ReturnRepresentation.java
@@ -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.core;
+
+public enum ReturnRepresentation {
+ REPRESENTATION, MINIMAL
+}
\ No newline at end of file
[02/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Star deleting
unnecessary abstract edm classes
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmTypeDefinition.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmTypeDefinition.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmTypeDefinition.java
deleted file mode 100644
index 6179f7f..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmTypeDefinition.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-
-public abstract class AbstractEdmTypeDefinition extends EdmNamedImpl implements EdmTypeDefinition {
-
- private final String namespace;
-
- public AbstractEdmTypeDefinition(final Edm edm, final FullQualifiedName typeDefinitionName) {
- super(edm, typeDefinitionName.getName());
- namespace = typeDefinitionName.getNamespace();
- }
-
- @Override
- public abstract EdmPrimitiveType getUnderlyingType();
-
- @Override
- public boolean isCompatible(final EdmPrimitiveType primitiveType) {
- return getUnderlyingType().isCompatible(primitiveType);
- }
-
- @Override
- public Class<?> getDefaultType() {
- return getUnderlyingType().getDefaultType();
- }
-
- @Override
- public boolean validate(final String value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale,
- final Boolean isUnicode) {
-
- return getUnderlyingType().validate(value, isNullable, maxLength, precision, scale, isUnicode);
- }
-
- @Override
- public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale,
- final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
-
- return getUnderlyingType().
- valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
- }
-
- @Override
- public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale,
- final Boolean isUnicode) throws EdmPrimitiveTypeException {
-
- return getUnderlyingType().valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
- }
-
- @Override
- public String toUriLiteral(final String literal) {
- return getUnderlyingType().toUriLiteral(literal);
- }
-
- @Override
- public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
- return getUnderlyingType().fromUriLiteral(literal);
- }
-
- @Override
- public FullQualifiedName getFullQualifiedName() {
- return new FullQualifiedName(getNamespace(), getName());
- }
-
- @Override
- public String getNamespace() {
- return namespace;
- }
-
- @Override
- public EdmTypeKind getKind() {
- return EdmTypeKind.DEFINITION;
- }
-
- @Override
- public abstract Integer getMaxLength();
-
- @Override
- public abstract Integer getPrecision();
-
- @Override
- public abstract Integer getScale();
-
- @Override
- public abstract Boolean isUnicode();
-
- @Override
- public TargetType getAnnotationsTargetType() {
- return TargetType.TypeDefinition;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return getFullQualifiedName();
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmActionImportInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmActionImportInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmActionImportInfoImpl.java
deleted file mode 100644
index 903cafb..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmActionImportInfoImpl.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmActionImportInfo;
-import org.apache.olingo.commons.api.edm.EdmException;
-
-import java.net.URI;
-
-public class EdmActionImportInfoImpl extends EdmOperationImportInfoImpl implements EdmActionImportInfo {
-
- private String actionImportName;
-
- public EdmActionImportInfoImpl(final String entityContainerName, final String actionImportName) {
- super(entityContainerName);
- this.actionImportName = actionImportName;
- }
-
- @Override
- public String getActionImportName() {
- return actionImportName;
- }
-
- @Override
- public URI getActionImportUri() {
- throw new EdmException("Not yet implemented");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationHelper.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationHelper.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationHelper.java
deleted file mode 100644
index 36fbcf9..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmAnnotationHelper.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmAnnotatable;
-
-public interface EdmAnnotationHelper extends EdmAnnotatable {
-//No additional methods needed for now.
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmElementImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmElementImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmElementImpl.java
deleted file mode 100644
index a757e38..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmElementImpl.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmElement;
-
-public abstract class EdmElementImpl extends EdmNamedImpl implements EdmElement {
-
- public EdmElementImpl(final Edm edm, final String name) {
- super(edm, name);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetInfoImpl.java
deleted file mode 100644
index ed1e6a1..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEntitySetInfoImpl.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmEntitySetInfo;
-import org.apache.olingo.commons.api.edm.EdmException;
-
-import java.net.URI;
-
-public class EdmEntitySetInfoImpl implements EdmEntitySetInfo {
-
- private final String entityContainerName;
-
- private final String entitySetName;
-
- public EdmEntitySetInfoImpl(final String entityContainerName, final String entitySetName) {
- this.entityContainerName = entityContainerName;
- this.entitySetName = entitySetName;
- }
-
- @Override
- public String getEntityContainerName() {
- return entityContainerName;
- }
-
- @Override
- public String getEntitySetName() {
- return entitySetName;
- }
-
- @Override
- public URI getEntitySetUri() {
- throw new EdmException("Not yet implemented");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportInfoImpl.java
deleted file mode 100644
index 928fae5..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmFunctionImportInfoImpl.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmFunctionImportInfo;
-
-import java.net.URI;
-
-public class EdmFunctionImportInfoImpl extends EdmOperationImportInfoImpl implements EdmFunctionImportInfo {
-
- private String functionImportName;
-
- public EdmFunctionImportInfoImpl(final String entityContainerName, final String functionImportName) {
- super(entityContainerName);
- this.functionImportName = functionImportName;
- }
-
- @Override
- public String getFunctionImportName() {
- return functionImportName;
- }
-
- @Override
- public URI getFunctionImportUri() {
- throw new EdmException("Not yet implemented");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNamedImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNamedImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNamedImpl.java
deleted file mode 100644
index 14d0059..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNamedImpl.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmNamed;
-
-public abstract class EdmNamedImpl implements EdmNamed {
-
- protected final Edm edm;
-
- private final String name;
-
- public EdmNamedImpl(final Edm edm, final String name) {
- this.edm = edm;
- this.name = name;
- }
-
- @Override
- public String getName() {
- return name;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNavigationPropertyBindingImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNavigationPropertyBindingImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNavigationPropertyBindingImpl.java
deleted file mode 100644
index 5815a6c..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmNavigationPropertyBindingImpl.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding;
-
-public class EdmNavigationPropertyBindingImpl implements EdmNavigationPropertyBinding {
-
- private final String path;
- private final String target;
-
- public EdmNavigationPropertyBindingImpl(final String path, final String target) {
- this.path = path;
- this.target = target;
- }
-
- @Override
- public String getPath() {
- return path;
- }
-
- @Override
- public String getTarget() {
- return target;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOperationImportInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOperationImportInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOperationImportInfoImpl.java
deleted file mode 100644
index a57849f..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmOperationImportInfoImpl.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmOperationImportInfo;
-
-public abstract class EdmOperationImportInfoImpl implements EdmOperationImportInfo {
-
- protected String entityContainerName;
-
- public EdmOperationImportInfoImpl(final String entityContainerName) {
- this.entityContainerName = entityContainerName;
- }
-
- @Override
- public String getEntityContainerName() {
- return entityContainerName;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmSingletonInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmSingletonInfoImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmSingletonInfoImpl.java
deleted file mode 100644
index c8cf569..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmSingletonInfoImpl.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmSingletonInfo;
-
-import java.net.URI;
-
-public class EdmSingletonInfoImpl implements EdmSingletonInfo {
-
- private final String entityContainerName;
-
- private final String singletonName;
-
- public EdmSingletonInfoImpl(final String entityContainerName, final String singletonName) {
- this.entityContainerName = entityContainerName;
- this.singletonName = singletonName;
- }
-
- @Override
- public String getEntityContainerName() {
- return entityContainerName;
- }
-
- @Override
- public String getSingletonName() {
- return singletonName;
- }
-
- @Override
- public URI getEntitySetUri() {
- throw new EdmException("Not yet implemented");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmStructuredTypeHelper.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmStructuredTypeHelper.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmStructuredTypeHelper.java
deleted file mode 100644
index 5790734..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmStructuredTypeHelper.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-
-import java.util.Map;
-
-public interface EdmStructuredTypeHelper {
-
- Map<String, EdmProperty> getProperties();
-
- Map<String, EdmNavigationProperty> getNavigationProperties();
-
- boolean isOpenType();
-
- boolean isAbstract();
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
deleted file mode 100644
index 3a174e2..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeImpl.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-
-public class EdmTypeImpl extends EdmNamedImpl implements EdmType {
-
- protected final FullQualifiedName typeName;
-
- protected final EdmTypeKind kind;
-
- public EdmTypeImpl(final Edm edm, final FullQualifiedName typeName, final EdmTypeKind kind) {
- super(edm, typeName.getName());
- this.typeName = typeName;
- this.kind = kind;
- }
-
- @Override
- public FullQualifiedName getFullQualifiedName() {
- return typeName;
- }
-
- @Override
- public String getNamespace() {
- return typeName.getNamespace();
- }
-
- @Override
- public EdmTypeKind getKind() {
- return kind;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
deleted file mode 100644
index c6adc5e..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * 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 org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmComplexType;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmEnumType;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmType;
-import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-
-public class EdmTypeInfo {
-
- public static class Builder {
-
- private String typeExpression;
-
- private String defaultNamespace;
-
- private Edm edm;
-
- public Builder setTypeExpression(final String typeExpression) {
- this.typeExpression = typeExpression;
- return this;
- }
-
- public Builder setDefaultNamespace(final String defaultNamespace) {
- this.defaultNamespace = defaultNamespace;
- return this;
- }
-
- public Builder setEdm(final Edm edm) {
- this.edm = edm;
- return this;
- }
-
- public EdmTypeInfo build() {
- return new EdmTypeInfo(edm, typeExpression.indexOf('.') == -1 && StringUtils.isNotBlank(defaultNamespace)
- ? defaultNamespace + "." + typeExpression
- : typeExpression);
- }
- }
-
- private final Edm edm;
-
- private final boolean collection;
-
- private final FullQualifiedName fullQualifiedName;
-
- private EdmPrimitiveTypeKind primitiveType;
-
- private EdmTypeDefinition typeDefinition;
-
- private EdmEnumType enumType;
-
- private EdmComplexType complexType;
-
- private EdmEntityType entityType;
-
- private EdmTypeInfo(final Edm edm, final String typeExpression) {
- this.edm = edm;
-
- String baseType;
- final int collStartIdx = typeExpression.indexOf("Collection(");
- final int collEndIdx = typeExpression.lastIndexOf(')');
- if (collStartIdx == -1) {
- baseType = typeExpression;
- collection = false;
- } else {
- if (collEndIdx == -1) {
- throw new IllegalArgumentException("Malformed type: " + typeExpression);
- }
-
- collection = true;
- baseType = typeExpression.substring(collStartIdx + 11, collEndIdx);
- }
-
- baseType = baseType.replaceAll("^#", "");
-
- final String typeName;
- final String namespace;
-
- final int lastDotIdx = baseType.lastIndexOf('.');
- if (lastDotIdx == -1) {
- namespace = EdmPrimitiveType.EDM_NAMESPACE;
- typeName = baseType;
- baseType = new FullQualifiedName(EdmPrimitiveType.EDM_NAMESPACE, baseType).toString();
- } else {
- namespace = baseType.substring(0, lastDotIdx);
- typeName = baseType.substring(lastDotIdx + 1);
- }
-
- if (StringUtils.isBlank(typeName)) {
- throw new IllegalArgumentException("Null or empty type name in " + typeExpression);
- }
-
- final StringBuilder exp = new StringBuilder();
- exp.append(baseType);
-
- fullQualifiedName = new FullQualifiedName(namespace, typeName);
-
- try {
- primitiveType = EdmPrimitiveTypeKind.valueOf(fullQualifiedName.getName());
- } catch (final IllegalArgumentException e) {
- primitiveType = null;
- }
- if (primitiveType == null && this.edm != null) {
- typeDefinition = this.edm.getTypeDefinition(fullQualifiedName);
- if (typeDefinition == null) {
- enumType = this.edm.getEnumType(fullQualifiedName);
- if (enumType == null) {
- complexType = this.edm.getComplexType(fullQualifiedName);
- if (complexType == null) {
- entityType = this.edm.getEntityType(fullQualifiedName);
- }
- }
- }
- }
- }
-
- public String internal() {
- final StringBuilder deserialize = new StringBuilder();
-
- if (isCollection()) {
- deserialize.append("Collection(");
- }
-
- deserialize.append(getFullQualifiedName().toString());
-
- if (isCollection()) {
- deserialize.append(")");
- }
-
- return deserialize.toString();
- }
-
- public String external() {
- final StringBuilder serialize = new StringBuilder();
-
- if (isCollection()) {
- serialize.append('#');
- serialize.append("Collection(");
- }
-
- if (isPrimitiveType()) {
- serialize.append(getFullQualifiedName().getName());
- }else{
- serialize.append(getFullQualifiedName().toString());
- }
-
- if (isCollection()) {
- serialize.append(")");
- }
-
- if (!isPrimitiveType() && !isCollection()) {
- serialize.insert(0, '#');
- }
-
- return serialize.toString();
- }
-
- public boolean isCollection() {
- return collection;
- }
-
- public FullQualifiedName getFullQualifiedName() {
- return fullQualifiedName;
- }
-
- public boolean isPrimitiveType() {
- return primitiveType != null;
- }
-
- public EdmPrimitiveTypeKind getPrimitiveTypeKind() {
- return primitiveType;
- }
-
- public boolean isTypeDefinition() {
- return typeDefinition != null;
- }
-
- public EdmTypeDefinition getTypeDefinition() {
- return typeDefinition;
- }
-
- public boolean isEnumType() {
- return enumType != null;
- }
-
- public EdmEnumType getEnumType() {
- return enumType;
- }
-
- public boolean isComplexType() {
- return complexType != null;
- }
-
- public EdmComplexType getComplexType() {
- return complexType;
- }
-
- public boolean isEntityType() {
- return entityType != null;
- }
-
- public EdmEntityType getEntityType() {
- return entityType;
- }
-
- public EdmType getType() {
- return isPrimitiveType()
- ? EdmPrimitiveTypeFactory.getInstance(getPrimitiveTypeKind())
- : isTypeDefinition()
- ? getTypeDefinition()
- : isEnumType()
- ? getEnumType()
- : isComplexType()
- ? getComplexType()
- : isEntityType()
- ? getEntityType()
- : null;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmCastImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmCastImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmCastImpl.java
index 419adea..371a4a2 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmCastImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmCastImpl.java
@@ -24,7 +24,7 @@ import org.apache.olingo.commons.api.edm.annotation.EdmCast;
import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpression;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.annotation.Cast;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
public class EdmCastImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmCast {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmIsOfImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmIsOfImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmIsOfImpl.java
index 03ae319..a1005c0 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmIsOfImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmIsOfImpl.java
@@ -24,7 +24,7 @@ import org.apache.olingo.commons.api.edm.annotation.EdmDynamicAnnotationExpressi
import org.apache.olingo.commons.api.edm.annotation.EdmIsOf;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.annotation.IsOf;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
public class EdmIsOfImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmIsOf {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java
index cd71c6c..4aaf731 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/annotation/EdmRecordImpl.java
@@ -24,7 +24,7 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.annotation.EdmPropertyValue;
import org.apache.olingo.commons.api.edm.annotation.EdmRecord;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
public class EdmRecordImpl extends AbstractEdmAnnotatableDynamicAnnotationExpression implements EdmRecord {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelper.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelper.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelper.java
new file mode 100644
index 0000000..bbbf136
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelper.java
@@ -0,0 +1,24 @@
+/*
+ * 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.provider;
+
+import org.apache.olingo.commons.api.edm.EdmAnnotatable;
+
+public interface EdmAnnotationHelper extends EdmAnnotatable {
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
index f4f0b6f..106584a 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
@@ -26,7 +26,6 @@ import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.provider.Annotatable;
import org.apache.olingo.commons.api.edm.provider.Annotation;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
public class EdmAnnotationHelperImpl implements EdmAnnotationHelper {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
index 9bebd12..cd32570 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
@@ -34,7 +34,6 @@ import org.apache.olingo.commons.api.edm.provider.Annotation;
import org.apache.olingo.commons.api.edm.provider.annotation.AnnotationExpression;
import org.apache.olingo.commons.api.edm.provider.annotation.DynamicAnnotationExpression;
import org.apache.olingo.commons.api.edm.provider.annotation.PropertyValue;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
import org.apache.olingo.commons.core.edm.annotation.EdmAndImpl;
import org.apache.olingo.commons.core.edm.annotation.EdmAnnotationPathImpl;
import org.apache.olingo.commons.core.edm.annotation.EdmApplyImpl;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
index d6bb531..e4a1ba7 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
@@ -19,27 +19,33 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmBindingTarget;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding;
import org.apache.olingo.commons.api.edm.EdmTerm;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.commons.api.edm.provider.BindingTarget;
import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
-import org.apache.olingo.commons.core.edm.AbstractEdmBindingTarget;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-import org.apache.olingo.commons.core.edm.EdmNavigationPropertyBindingImpl;
-public abstract class EdmBindingTargetImpl extends AbstractEdmBindingTarget {
+public abstract class EdmBindingTargetImpl extends EdmNamedImpl implements EdmBindingTarget {
private final BindingTarget target;
- private List<EdmNavigationPropertyBinding> navigationPropertyBindings;
private final EdmAnnotationHelper helper;
+ private final EdmEntityContainer container;
+
+ private List<EdmNavigationPropertyBinding> navigationPropertyBindings;
public EdmBindingTargetImpl(final Edm edm, final EdmEntityContainer container, final BindingTarget target) {
- super(edm, container, target.getName(), target.getTypeFQN());
+ super(edm, target.getName());
+ this.container = container;
this.target = target;
this.helper = new EdmAnnotationHelperImpl(edm, target);
}
@@ -57,7 +63,71 @@ public abstract class EdmBindingTargetImpl extends AbstractEdmBindingTarget {
}
return navigationPropertyBindings;
}
-
+
+ @Override
+ public EdmEntityContainer getEntityContainer() {
+ return container;
+ }
+
+ @Override
+ public EdmEntityType getEntityType() {
+ final EdmEntityType entityType = edm.getEntityType(target.getTypeFQN());
+ if (entityType == null) {
+ throw new EdmException("Can´t find entity type: " + target.getTypeFQN() + " for entity set or singleton: "
+ + getName());
+ }
+ return entityType;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return container.getFullQualifiedName();
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return getName();
+ }
+
+ @Override
+ public EdmBindingTarget getRelatedBindingTarget(final String path) {
+ if (path == null) {
+ return null;
+ }
+ EdmBindingTarget bindingTarget = null;
+ boolean found = false;
+ for (final Iterator<EdmNavigationPropertyBinding> itor = getNavigationPropertyBindings().iterator(); itor.hasNext()
+ && !found;) {
+
+ final EdmNavigationPropertyBinding binding = itor.next();
+ if (path.startsWith(binding.getPath())) {
+ final Target edmTarget = new Target.Builder(binding.getTarget(), container).build();
+
+ final EdmEntityContainer entityContainer = edm.getEntityContainer(edmTarget.getEntityContainer());
+ if (entityContainer == null) {
+ throw new EdmException("Cannot find entity container with name: " + edmTarget.getEntityContainer());
+ }
+ try {
+ bindingTarget = entityContainer.getEntitySet(edmTarget.getTargetName());
+
+ if (bindingTarget == null) {
+ throw new EdmException("Cannot find EntitySet " + edmTarget.getTargetName());
+ }
+ } catch (EdmException e) {
+ // try with singletons ...
+ bindingTarget = entityContainer.getSingleton(edmTarget.getTargetName());
+
+ if (bindingTarget == null) {
+ throw new EdmException("Cannot find Singleton " + edmTarget.getTargetName());
+ }
+ } finally {
+ found = bindingTarget != null;
+ }
+ }
+ }
+
+ return bindingTarget;
+ }
@Override
public EdmAnnotation getAnnotation(final EdmTerm term) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
index 5b641ba..432a09f 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
@@ -18,21 +18,22 @@
*/
package org.apache.olingo.commons.core.edm.provider;
+import java.util.List;
+import java.util.Map;
+
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.ComplexType;
-import org.apache.olingo.commons.core.edm.AbstractEdmComplexType;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-import org.apache.olingo.commons.core.edm.EdmStructuredTypeHelper;
-import java.util.List;
-import java.util.Map;
-
-public class EdmComplexTypeImpl extends AbstractEdmComplexType {
+public class EdmComplexTypeImpl extends EdmStructuredTypeImpl implements EdmComplexType {
private final EdmStructuredTypeHelper helper;
@@ -45,7 +46,7 @@ public class EdmComplexTypeImpl extends AbstractEdmComplexType {
}
private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
- super(edm, name, complexType.getBaseTypeFQN());
+ super(edm, name, EdmTypeKind.COMPLEX, complexType.getBaseTypeFQN());
this.helper = new EdmStructuredTypeHelperImpl(edm, name, complexType);
this.annotationHelper = new EdmAnnotationHelperImpl(edm, complexType);
}
@@ -79,4 +80,35 @@ public class EdmComplexTypeImpl extends AbstractEdmComplexType {
public List<EdmAnnotation> getAnnotations() {
return annotationHelper == null ? null : annotationHelper.getAnnotations();
}
+
+ @Override
+ protected EdmStructuredType buildBaseType(final FullQualifiedName baseTypeName) {
+ EdmComplexType baseType = null;
+ if (baseTypeName != null) {
+ baseType = edm.getComplexType(baseTypeName);
+ if (baseType == null) {
+ throw new EdmException("Can't find base type with name: " + baseTypeName + " for complex type: "
+ + getName());
+ }
+ }
+ return baseType;
+ }
+
+ @Override
+ public EdmComplexType getBaseType() {
+ checkBaseType();
+ return (EdmComplexType) baseType;
+ }
+
+ @Override
+ protected void checkBaseType() {
+ if (baseTypeName != null && baseType == null) {
+ baseType = buildBaseType(baseTypeName);
+ }
+ }
+
+ @Override
+ public TargetType getAnnotationsTargetType() {
+ return TargetType.ComplexType;
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmElementImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmElementImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmElementImpl.java
new file mode 100644
index 0000000..686e45d
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmElementImpl.java
@@ -0,0 +1,29 @@
+/*
+ * 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.provider;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmElement;
+
+public abstract class EdmElementImpl extends EdmNamedImpl implements EdmElement {
+
+ public EdmElementImpl(final Edm edm, final String name) {
+ super(edm, name);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
index 6c768ce..94b7d4d 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
@@ -18,13 +18,17 @@
*/
package org.apache.olingo.commons.core.edm.provider;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmActionImport;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
@@ -38,30 +42,146 @@ import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo;
import org.apache.olingo.commons.api.edm.provider.EntitySet;
import org.apache.olingo.commons.api.edm.provider.FunctionImport;
import org.apache.olingo.commons.api.edm.provider.Singleton;
-import org.apache.olingo.commons.core.edm.AbstractEdmEntityContainer;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
+public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityContainer {
private final EdmProvider provider;
private EntityContainer container;
private EdmAnnotationHelper helper;
- public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider,
+ protected final FullQualifiedName entityContainerName;
+ private final FullQualifiedName parentContainerName;
+
+ protected final Map<String, EdmSingleton> singletons = new HashMap<String, EdmSingleton>();
+ private boolean allSingletonsLoaded = false;
+
+ protected final Map<String, EdmEntitySet> entitySets = new HashMap<String, EdmEntitySet>();
+ private boolean allEntitySetsLoaded = false;
+
+ protected final Map<String, EdmActionImport> actionImports = new HashMap<String, EdmActionImport>();
+ private boolean allActionImportsLoaded = false;
+
+ protected final Map<String, EdmFunctionImport> functionImports = new HashMap<String, EdmFunctionImport>();
+ private boolean allFunctionImportsLoaded = false;
+
+ public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider,
final EntityContainerInfo entityContainerInfo) {
- super(edm, entityContainerInfo.getContainerName(), entityContainerInfo.getExtendsContainer());
+ super(edm, entityContainerInfo.getContainerName().getName());
this.provider = provider;
+ this.entityContainerName = entityContainerInfo.getContainerName();
+ this.parentContainerName = entityContainerInfo.getExtendsContainer();
}
public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider, final FullQualifiedName containerFQN,
final EntityContainer entityContainer) {
- super(edm, containerFQN, entityContainer.getExtendsContainerFQN());
+ super(edm, containerFQN.getName());
this.provider = provider;
container = entityContainer;
+ this.entityContainerName = containerFQN;
+ this.parentContainerName = entityContainer.getExtendsContainerFQN();
this.helper = new EdmAnnotationHelperImpl(edm, entityContainer);
}
@Override
+ public String getNamespace() {
+ return entityContainerName.getNamespace();
+ }
+
+ @Override
+ public FullQualifiedName getFullQualifiedName() {
+ return entityContainerName;
+ }
+
+ @Override
+ public EdmSingleton getSingleton(final String singletonName) {
+ EdmSingleton singleton = singletons.get(singletonName);
+ if (singleton == null) {
+ singleton = createSingleton(singletonName);
+ if (singleton != null) {
+ singletons.put(singletonName, singleton);
+ }
+ }
+ return singleton;
+ }
+
+ @Override
+ public EdmEntitySet getEntitySet(final String entitySetName) {
+ EdmEntitySet entitySet = entitySets.get(entitySetName);
+ if (entitySet == null) {
+ entitySet = createEntitySet(entitySetName);
+ if (entitySet != null) {
+ entitySets.put(entitySetName, entitySet);
+ }
+ }
+ return entitySet;
+ }
+
+ @Override
+ public EdmActionImport getActionImport(final String actionImportName) {
+ EdmActionImport actionImport = actionImports.get(actionImportName);
+ if (actionImport == null) {
+ actionImport = createActionImport(actionImportName);
+ if (actionImport != null) {
+ actionImports.put(actionImportName, actionImport);
+ }
+ }
+ return actionImport;
+ }
+
+ @Override
+ public EdmFunctionImport getFunctionImport(final String functionImportName) {
+ EdmFunctionImport functionImport = functionImports.get(functionImportName);
+ if (functionImport == null) {
+ functionImport = createFunctionImport(functionImportName);
+ if (functionImport != null) {
+ functionImports.put(functionImportName, functionImport);
+ }
+ }
+ return functionImport;
+ }
+
+ @Override
+ public List<EdmEntitySet> getEntitySets() {
+ if (!allEntitySetsLoaded) {
+ loadAllEntitySets();
+ allEntitySetsLoaded = true;
+ }
+ return new ArrayList<EdmEntitySet>(entitySets.values());
+ }
+
+ @Override
+ public List<EdmFunctionImport> getFunctionImports() {
+ if (!allFunctionImportsLoaded) {
+ loadAllFunctionImports();
+ allFunctionImportsLoaded = true;
+ }
+ return new ArrayList<EdmFunctionImport>(functionImports.values());
+ }
+
+ @Override
+ public List<EdmSingleton> getSingletons() {
+ if (!allSingletonsLoaded) {
+ loadAllSingletons();
+ allSingletonsLoaded = true;
+ }
+ return new ArrayList<EdmSingleton>(singletons.values());
+ }
+
+ @Override
+ public List<EdmActionImport> getActionImports() {
+ if (!allActionImportsLoaded) {
+ loadAllActionImports();
+ allActionImportsLoaded = true;
+ }
+ return new ArrayList<EdmActionImport>(actionImports.values());
+ }
+
+ @Override
+ public FullQualifiedName getParentContainerName() {
+ return parentContainerName;
+ }
+
+
protected EdmSingleton createSingleton(final String singletonName) {
EdmSingleton singleton = null;
@@ -77,7 +197,6 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
return singleton;
}
- @Override
protected EdmEntitySet createEntitySet(final String entitySetName) {
EdmEntitySet entitySet = null;
@@ -93,7 +212,6 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
return entitySet;
}
- @Override
protected EdmActionImport createActionImport(final String actionImportName) {
EdmActionImport actionImport = null;
@@ -109,7 +227,6 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
return actionImport;
}
- @Override
protected EdmFunctionImport createFunctionImport(final String functionImportName) {
EdmFunctionImport functionImport = null;
@@ -125,7 +242,6 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
return functionImport;
}
- @Override
protected void loadAllEntitySets() {
loadContainer();
List<EntitySet> providerEntitySets = container.getEntitySets();
@@ -139,7 +255,6 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
}
}
- @Override
protected void loadAllFunctionImports() {
loadContainer();
List<FunctionImport> providerFunctionImports = container.getFunctionImports();
@@ -155,7 +270,6 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
}
- @Override
protected void loadAllSingletons() {
loadContainer();
List<Singleton> providerSingletons = container.getSingletons();
@@ -170,7 +284,6 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
}
- @Override
protected void loadAllActionImports() {
loadContainer();
List<ActionImport> providerActionImports = container.getActionImports();
@@ -200,6 +313,16 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer {
}
@Override
+ public String getAnnotationsTargetPath() {
+ return null;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return getFullQualifiedName();
+ }
+
+ @Override
public TargetType getAnnotationsTargetType() {
return TargetType.EntityContainer;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
index b6cbec6..0ee22e7 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
@@ -18,33 +18,36 @@
*/
package org.apache.olingo.commons.core.edm.provider;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
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;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.EntityType;
import org.apache.olingo.commons.api.edm.provider.PropertyRef;
-import org.apache.olingo.commons.core.edm.AbstractEdmEntityType;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-import org.apache.olingo.commons.core.edm.EdmStructuredTypeHelper;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-public class EdmEntityTypeImpl extends AbstractEdmEntityType {
+public class EdmEntityTypeImpl extends EdmStructuredTypeImpl implements EdmEntityType {
private final EdmStructuredTypeHelper helper;
-
private EntityType entityType;
-
private boolean baseTypeChecked = false;
-
private EdmAnnotationHelper annotationHelper;
+ private final boolean hasStream;
+ protected EdmEntityType entityBaseType;
+ private final List<String> keyPredicateNames = new ArrayList<String>();
+ private final Map<String, EdmKeyPropertyRef> keyPropertyRefs = new LinkedHashMap<String, EdmKeyPropertyRef>();
+ private List<EdmKeyPropertyRef> keyPropertyRefsList;
public static EdmEntityTypeImpl getInstance(final Edm edm, final FullQualifiedName name,
final EntityType entityType) {
@@ -53,9 +56,10 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
}
private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName name, final EntityType entityType) {
- super(edm, name, entityType.getBaseTypeFQN(), entityType.hasStream());
+ super(edm, name, EdmTypeKind.ENTITY, entityType.getBaseTypeFQN());
this.entityType = entityType;
helper = new EdmStructuredTypeHelperImpl(edm, name, entityType);
+ hasStream = entityType.hasStream();
}
@Override
@@ -76,7 +80,7 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
entityBaseType = (EdmEntityType) baseType;
}
if (baseType == null
- || (baseType.isAbstract() && ((AbstractEdmEntityType) baseType).getKeyPropertyRefs().size() == 0)) {
+ || (baseType.isAbstract() && ((EdmEntityType) baseType).getKeyPropertyRefs().size() == 0)) {
final List<PropertyRef> key = entityType.getKey();
if (key != null) {
final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>();
@@ -90,6 +94,77 @@ public class EdmEntityTypeImpl extends AbstractEdmEntityType {
}
}
+ protected void setEdmKeyPropertyRef(final List<EdmKeyPropertyRef> edmKey) {
+ for (EdmKeyPropertyRef ref : edmKey) {
+ if (ref.getAlias() == null) {
+ keyPredicateNames.add(ref.getName());
+ keyPropertyRefs.put(ref.getName(), ref);
+ } else {
+ keyPredicateNames.add(ref.getAlias());
+ keyPropertyRefs.put(ref.getAlias(), ref);
+ }
+ }
+ }
+
+ @Override
+ protected EdmStructuredType buildBaseType(final FullQualifiedName baseTypeName) {
+ EdmEntityType baseType = null;
+ if (baseTypeName != null) {
+ baseType = edm.getEntityType(baseTypeName);
+ if (baseType == null) {
+ throw new EdmException("Cannot find base type with name: " + baseTypeName + " for entity type: " + getName());
+ }
+ }
+ return baseType;
+ }
+
+ @Override
+ public EdmEntityType getBaseType() {
+ checkBaseType();
+ return entityBaseType;
+ }
+
+ @Override
+ public List<String> getKeyPredicateNames() {
+ checkBaseType();
+ if (keyPredicateNames.isEmpty() && baseType != null) {
+ return entityBaseType.getKeyPredicateNames();
+ }
+ return keyPredicateNames;
+ }
+
+ @Override
+ public List<EdmKeyPropertyRef> getKeyPropertyRefs() {
+ checkBaseType();
+ if (keyPropertyRefsList == null) {
+ keyPropertyRefsList = new ArrayList<EdmKeyPropertyRef>(keyPropertyRefs.values());
+ }
+ if (keyPropertyRefsList.isEmpty() && entityBaseType != null) {
+ return entityBaseType.getKeyPropertyRefs();
+ }
+ return keyPropertyRefsList;
+ }
+
+ @Override
+ public EdmKeyPropertyRef getKeyPropertyRef(final String keyPredicateName) {
+ checkBaseType();
+ final EdmKeyPropertyRef edmKeyPropertyRef = keyPropertyRefs.get(keyPredicateName);
+ if (edmKeyPropertyRef == null && entityBaseType != null) {
+ return entityBaseType.getKeyPropertyRef(keyPredicateName);
+ }
+ return edmKeyPropertyRef;
+ }
+
+ @Override
+ public boolean hasStream() {
+ return hasStream;
+ }
+
+ @Override
+ public TargetType getAnnotationsTargetType() {
+ return TargetType.EntityType;
+ }
+
@Override
public boolean isOpenType() {
return helper.isOpenType();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
index 9b4ca6a..1fdf73b 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
@@ -20,21 +20,26 @@ package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmMember;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.EnumMember;
import org.apache.olingo.commons.api.edm.provider.EnumType;
-import org.apache.olingo.commons.core.edm.AbstractEdmEnumType;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-public class EdmEnumTypeImpl extends AbstractEdmEnumType {
+public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
private static final Set<EdmPrimitiveTypeKind> VALID_UNDERLYING_TYPES = new HashSet<EdmPrimitiveTypeKind>();
{
@@ -46,13 +51,15 @@ public class EdmEnumTypeImpl extends AbstractEdmEnumType {
};
private final EdmPrimitiveType underlyingType;
-
private final EnumType enumType;
-
+ private final String uriPrefix;
+ private final String uriSuffix;
+ private List<String> memberNames;
private List<EdmMember> members;
+ private Map<String, EdmMember> membersMap;
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final EnumType enumType) {
- super(edm, enumName, enumType.isFlags());
+ super(edm, enumName, EdmTypeKind.ENUM);
if (enumType.getUnderlyingType() == null) {
underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
@@ -66,14 +73,176 @@ public class EdmEnumTypeImpl extends AbstractEdmEnumType {
}
this.enumType = enumType;
+ this.uriPrefix = enumName.getFullQualifiedNameAsString() + '\'';
+ this.uriSuffix = "'";
}
@Override
public EdmPrimitiveType getUnderlyingType() {
return underlyingType;
}
+
+ @Override
+ public EdmMember getMember(final String name) {
+ if (membersMap == null) {
+ membersMap = new LinkedHashMap<String, EdmMember>();
+ for (final EdmMember member : getMembers()) {
+ membersMap.put(member.getName(), member);
+ }
+ }
+ return membersMap.get(name);
+ }
+
+ @Override
+ public List<String> getMemberNames() {
+ if (memberNames == null) {
+ memberNames = new ArrayList<String>();
+ for (final EdmMember member : getMembers()) {
+ memberNames.add(member.getName());
+ }
+ }
+ return memberNames;
+ }
+
+ @Override
+ public boolean isCompatible(final EdmPrimitiveType primitiveType) {
+ return equals(primitiveType);
+ }
@Override
+ public Class<?> getDefaultType() {
+ return getUnderlyingType().getDefaultType();
+ }
+
+ @Override
+ public boolean validate(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale, final Boolean isUnicode) {
+
+ try {
+ valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, getDefaultType());
+ return true;
+ } catch (final EdmPrimitiveTypeException e) {
+ return false;
+ }
+ }
+
+ private Long parseEnumValue(final String value) throws EdmPrimitiveTypeException {
+ Long result = null;
+ for (final String memberValue : value.split(",", isFlags() ? -1 : 1)) {
+ Long memberValueLong = null;
+ for (final EdmMember member : getMembers()) {
+ if (member.getName().equals(memberValue) || member.getValue().equals(memberValue)) {
+ memberValueLong = Long.decode(member.getValue());
+ }
+ }
+ if (memberValueLong == null) {
+ throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
+ }
+ result = result == null ? memberValueLong : result | memberValueLong;
+ }
+ return result;
+ }
+
+ @Override
+ public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
+ throws EdmPrimitiveTypeException {
+
+ if (value == null) {
+ if (isNullable != null && !isNullable) {
+ throw new EdmPrimitiveTypeException("The literal 'null' is not allowed.");
+ }
+ return null;
+ }
+
+ try {
+ return EdmInt64.convertNumber(parseEnumValue(value), returnType);
+ } catch (final IllegalArgumentException e) {
+ throw new EdmPrimitiveTypeException("The literal '" + value
+ + "' cannot be converted to value type " + returnType + ".", e);
+ } catch (final ClassCastException e) {
+ throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
+ }
+ }
+
+ protected String constructEnumValue(final long value) throws EdmPrimitiveTypeException {
+ long remaining = value;
+ StringBuilder result = new StringBuilder();
+
+ for (final EdmMember member : getMembers()) {
+ final long memberValue = Long.parseLong(member.getValue());
+ if ((memberValue & remaining) == memberValue) {
+ if (result.length() > 0) {
+ result.append(',');
+ }
+ result.append(member.getName());
+ remaining ^= memberValue;
+ }
+ }
+
+ if (remaining != 0) {
+ throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
+ }
+ return result.toString();
+ }
+
+ @Override
+ public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+
+ if (value == null) {
+ if (isNullable != null && !isNullable) {
+ throw new EdmPrimitiveTypeException("The value NULL is not allowed.");
+ }
+ return null;
+ }
+ if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
+ return constructEnumValue(((Number) value).longValue());
+ } else {
+ throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
+ }
+ }
+
+ @Override
+ public String toUriLiteral(final String literal) {
+ return literal == null ? null
+ : uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix;
+ }
+
+ @Override
+ public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
+ if (literal == null) {
+ return null;
+ } else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) {
+ return literal;
+ } else if (literal.length() >= uriPrefix.length() + uriSuffix.length()
+ && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) {
+ return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
+ } else {
+ throw new EdmPrimitiveTypeException("The literal '" + literal + "' has illegal content.");
+ }
+ }
+
+ @Override
+ public boolean isFlags() {
+ return enumType.isFlags();
+ }
+
+ @Override
+ public TargetType getAnnotationsTargetType() {
+ return TargetType.EnumType;
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return null;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return getFullQualifiedName();
+ }
+
protected List<EdmMember> getMembers() {
if (members == null) {
members = new ArrayList<EdmMember>(enumType.getMembers().size());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmKeyPropertyRefImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmKeyPropertyRefImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmKeyPropertyRefImpl.java
index a7f291d..1122f74 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmKeyPropertyRefImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmKeyPropertyRefImpl.java
@@ -19,15 +19,20 @@
package org.apache.olingo.commons.core.edm.provider;
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.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.provider.PropertyRef;
-import org.apache.olingo.commons.core.edm.AbstractEdmKeyPropertyRef;
-public class EdmKeyPropertyRefImpl extends AbstractEdmKeyPropertyRef {
+public class EdmKeyPropertyRefImpl implements EdmKeyPropertyRef {
private final PropertyRef ref;
+ private EdmEntityType edmEntityType;
+ private EdmProperty property;
public EdmKeyPropertyRefImpl(final EdmEntityType edmEntityType, final PropertyRef ref) {
- super(edmEntityType);
+ this.edmEntityType = edmEntityType;
this.ref = ref;
}
@@ -40,4 +45,39 @@ public class EdmKeyPropertyRefImpl extends AbstractEdmKeyPropertyRef {
public String getAlias() {
return ref.getAlias();
}
+
+ @Override
+ public EdmProperty getProperty() {
+ if (property == null) {
+ if (getAlias() == null) {
+ property = edmEntityType.getStructuralProperty(getName());
+ if (property == null) {
+ throw new EdmException("Invalid key property ref specified. Can´t find property with name: "
+ + getName());
+ }
+ } else {
+ if (getName() == null || getName().isEmpty()) {
+ throw new EdmException("Alias but no path specified for propertyRef");
+ }
+ final String[] splitPath = getName().split("/");
+ EdmStructuredType structType = edmEntityType;
+ for (int i = 0; i < splitPath.length - 1; i++) {
+ final EdmProperty _property = structType.getStructuralProperty(splitPath[i]);
+ if (_property == null) {
+ throw new EdmException("Invalid property ref specified. Can´t find property with name: " + splitPath[i]
+ + " at type: " + structType.getNamespace() + "." + structType.getName());
+ }
+ structType = (EdmStructuredType) _property.getType();
+ }
+ property = structType.getStructuralProperty(splitPath[splitPath.length - 1]);
+ if (property == null) {
+ throw new EdmException("Invalid property ref specified. Can´t find property with name: "
+ + splitPath[splitPath.length - 1] + " at type: " + structType.getNamespace() + "."
+ + structType.getName());
+ }
+ }
+ }
+
+ return property;
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
index 6c840fd..0bdf441 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
@@ -22,20 +22,43 @@ import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmMember;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.EnumMember;
-import org.apache.olingo.commons.core.edm.AbstractEdmMember;
-import org.apache.olingo.commons.core.edm.EdmAnnotationHelper;
-public class EdmMemberImpl extends AbstractEdmMember {
+public class EdmMemberImpl extends EdmNamedImpl implements EdmMember {
private final EdmAnnotationHelper helper;
+ private final FullQualifiedName enumFQN;
+ private final EnumMember member;
public EdmMemberImpl(final Edm edm, final FullQualifiedName enumFQN, final EnumMember member) {
- super(edm, enumFQN, member.getName(), member.getValue());
+ super(edm, member.getName());
+ this.enumFQN = enumFQN;
+ this.member = member;
this.helper = new EdmAnnotationHelperImpl(edm, member);
}
+
+ @Override
+ public TargetType getAnnotationsTargetType() {
+ return TargetType.Member;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return enumFQN;
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return getName();
+ }
+
+ @Override
+ public String getValue() {
+ return member.getValue();
+ }
@Override
public EdmAnnotation getAnnotation(final EdmTerm term) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNamedImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNamedImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNamedImpl.java
new file mode 100644
index 0000000..93e7583
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNamedImpl.java
@@ -0,0 +1,39 @@
+/*
+ * 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.provider;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmNamed;
+
+public abstract class EdmNamedImpl implements EdmNamed {
+
+ protected final Edm edm;
+
+ private final String name;
+
+ public EdmNamedImpl(final Edm edm, final String name) {
+ this.edm = edm;
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyBindingImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyBindingImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyBindingImpl.java
new file mode 100644
index 0000000..ac534b2
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyBindingImpl.java
@@ -0,0 +1,43 @@
+/*
+ * 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.provider;
+
+import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding;
+
+public class EdmNavigationPropertyBindingImpl implements EdmNavigationPropertyBinding {
+
+ private final String path;
+ private final String target;
+
+ public EdmNavigationPropertyBindingImpl(final String path, final String target) {
+ this.path = path;
+ this.target = target;
+ }
+
+ @Override
+ public String getPath() {
+ return path;
+ }
+
+ @Override
+ public String getTarget() {
+ return target;
+ }
+
+}
[18/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/people.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/people.json b/lib/server-core-ext/src/test/resources/people.json
new file mode 100644
index 0000000..64699bb
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/people.json
@@ -0,0 +1,323 @@
+{
+ "value":[
+ {
+ "UserName":"russellwhyte",
+ "FirstName":"Russell",
+ "LastName":"Whyte",
+ "Emails":[
+ "Russell@example.com",
+ "Russell@contoso.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"187 Suffolk Ln.",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Boise",
+ "Region":"ID"
+ }
+ }
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"scottketchum",
+ "FirstName":"Scott",
+ "LastName":"Ketchum",
+ "Emails":[
+ "Scott@example.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"2817 Milton Dr.",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Albuquerque",
+ "Region":"NM"
+ }
+ }
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"ronaldmundy",
+ "FirstName":"Ronald",
+ "LastName":"Mundy",
+ "Emails":[
+ "Ronald@example.com",
+ "Ronald@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"javieralfred",
+ "FirstName":"Javier",
+ "LastName":"Alfred",
+ "Emails":[
+ "Javier@example.com",
+ "Javier@contoso.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"89 Jefferson Way Suite 2",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Portland",
+ "Region":"WA"
+ }
+ }
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"willieashmore",
+ "FirstName":"Willie",
+ "LastName":"Ashmore",
+ "Emails":[
+ "Willie@example.com",
+ "Willie@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"vincentcalabrese",
+ "FirstName":"Vincent",
+ "LastName":"Calabrese",
+ "Emails":[
+ "Vincent@example.com",
+ "Vincent@contoso.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"55 Grizzly Peak Rd.",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Butte",
+ "Region":"MT"
+ }
+ }
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"clydeguess",
+ "FirstName":"Clyde",
+ "LastName":"Guess",
+ "Emails":[
+ "Clyde@example.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"keithpinckney",
+ "FirstName":"Keith",
+ "LastName":"Pinckney",
+ "Emails":[
+ "Keith@example.com",
+ "Keith@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"marshallgaray",
+ "FirstName":"Marshall",
+ "LastName":"Garay",
+ "Emails":[
+ "Marshall@example.com",
+ "Marshall@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"ryantheriault",
+ "FirstName":"Ryan",
+ "LastName":"Theriault",
+ "Emails":[
+ "Ryan@example.com",
+ "Ryan@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"elainestewart",
+ "FirstName":"Elaine",
+ "LastName":"Stewart",
+ "Emails":[
+ "Elaine@example.com",
+ "Elaine@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"salliesampson",
+ "FirstName":"Sallie",
+ "LastName":"Sampson",
+ "Emails":[
+ "Sallie@example.com",
+ "Sallie@contoso.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"87 Polk St. Suite 5",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"San Francisco",
+ "Region":"CA"
+ }
+ },
+ {
+ "Address":"89 Chiaroscuro Rd.",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Portland",
+ "Region":"OR"
+ }
+ }
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"jonirosales",
+ "FirstName":"Joni",
+ "LastName":"Rosales",
+ "Emails":[
+ "Joni@example.com",
+ "Joni@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"georginabarlow",
+ "FirstName":"Georgina",
+ "LastName":"Barlow",
+ "Emails":[
+ "Georgina@example.com",
+ "Georgina@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"angelhuffman",
+ "FirstName":"Angel",
+ "LastName":"Huffman",
+ "Emails":[
+ "Angel@example.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"laurelosborn",
+ "FirstName":"Laurel",
+ "LastName":"Osborn",
+ "Emails":[
+ "Laurel@example.com",
+ "Laurel@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"sandyosborn",
+ "FirstName":"Sandy",
+ "LastName":"Osborn",
+ "Emails":[
+ "Sandy@example.com",
+ "Sandy@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"ursulabright",
+ "FirstName":"Ursula",
+ "LastName":"Bright",
+ "Emails":[
+ "Ursula@example.com",
+ "Ursula@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"genevievereeves",
+ "FirstName":"Genevieve",
+ "LastName":"Reeves",
+ "Emails":[
+ "Genevieve@example.com",
+ "Genevieve@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"kristakemp",
+ "FirstName":"Krista",
+ "LastName":"Kemp",
+ "Emails":[
+ "Krista@example.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/photos.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/photos.json b/lib/server-core-ext/src/test/resources/photos.json
new file mode 100644
index 0000000..127d195
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/photos.json
@@ -0,0 +1,64 @@
+{
+ "value":[
+ {
+ "Id":1,
+ "Name":"My Photo 1"
+ },
+ {
+ "Id":11,
+ "Name":"Trip Photo 11"
+ },
+ {
+ "Id":12,
+ "Name":"Trip Photo 12"
+ },
+ {
+ "Id":13,
+ "Name":"Trip Photo 13"
+ },
+ {
+ "Id":14,
+ "Name":"Trip Photo 14"
+ },
+ {
+ "Id":2,
+ "Name":"My Photo 2"
+ },
+ {
+ "Id":21,
+ "Name":"Trip Photo 21"
+ },
+ {
+ "Id":22,
+ "Name":"Trip Photo 22"
+ },
+ {
+ "Id":23,
+ "Name":"Trip Photo 23"
+ },
+ {
+ "Id":24,
+ "Name":"Trip Photo 24"
+ },
+ {
+ "Id":3,
+ "Name":"My Photo 3"
+ },
+ {
+ "Id":31,
+ "Name":"Trip Photo 31"
+ },
+ {
+ "Id":32,
+ "Name":"Trip Photo 32"
+ },
+ {
+ "Id":33,
+ "Name":"Trip Photo 33"
+ },
+ {
+ "Id":34,
+ "Name":"Trip Photo 34"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/trip-links.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/trip-links.json b/lib/server-core-ext/src/test/resources/trip-links.json
new file mode 100644
index 0000000..df8f9b8
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/trip-links.json
@@ -0,0 +1,28 @@
+{
+ "value":[
+ {
+ "TripId": 1001,
+ "Flights": [1, 2],
+ "Events": [51, 52, 53, 54, 55],
+ "Photos": [21, 22]
+ },
+ {
+ "TripId":2,
+ "Flights": [3, 4],
+ "Events": [55],
+ "Photos": [13, 14]
+ },
+ {
+ "TripId": 1003,
+ "Flights": [5, 6],
+ "Events": [56, 57],
+ "Photos": [23, 24]
+ },
+ {
+ "TripId": 2004,
+ "Flights": [7, 8],
+ "Events": [55, 57],
+ "Photos": [33, 34]
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/trip.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/trip.json b/lib/server-core-ext/src/test/resources/trip.json
new file mode 100644
index 0000000..79c6104
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/trip.json
@@ -0,0 +1,224 @@
+{
+ "value":[
+ {
+ "TripId": 1001,
+ "ShareId": "9d9b2fa0-efbf-490e-a5e3-bac8f7d47354",
+ "Description": "Trip from San Francisco to New York City. Nice trip with two friends. It is a 4 days' trip. We actually had a client meeting, but we also took one to go sightseeings in New York.",
+ "Name": "Trip in US",
+ "Budget": 3000.0,
+ "StartsAt":"2014-01-01T00:00:00Z",
+ "EndsAt": "2014-01-04T00:00:00Z",
+ "Tags": ["Trip in New York", "business","sightseeing"]
+ },
+ {
+ "TripId":2,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Description": "Trip from Shanghai to Beijing",
+ "Name":"Trip in Beijing",
+ "Budget": 3000.0,
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 3,
+ "ShareId": "9ce142c3-5fd6-4a71-848e-5220ebf1e9f3",
+ "Name": "Honeymoon",
+ "Budget": 800.0,
+ "Description": "Happy honeymoon trip",
+ "Tags": ["Travel", "honeymoon"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 4,
+ "ShareId": "4CCFB043-C79C-44EF-8CFE-CD493CED6654",
+ "Name": "Business trip to OData",
+ "Budget": 324.6,
+ "Description": "Business trip to OData",
+ "Tags": ["business", "odata"],
+ "StartsAt": "2013-01-01T00:00:00Z",
+ "EndsAt": "2013-01-04T00:00:00Z"
+ },
+ {
+ "TripId": 5,
+ "ShareId": "4546F419-0070-45F7-BA2C-19E4BC3647E1",
+ "Name": "Travel trip in US",
+ "Budget": 1250.0,
+ "Description": "Travel trip in US",
+ "Tags": ["travel", "overseas"],
+ "StartsAt": "2013-01-19T00:00:00Z",
+ "EndsAt": "2013-01-28T00:00:00Z"
+ },
+ {
+ "TripId": 6,
+ "ShareId": "26F0E8F6-657A-4561-BF3B-719366EF04FA",
+ "Name": "Study music in Europe",
+ "Budget": 3200.0,
+ "Description": "Study music in Europe",
+ "Tags": ["study", "overseas"],
+ "StartsAt": "2013-03-01T00:00:00Z",
+ "EndsAt": "2013-05-04T00:00:00Z"
+ },
+ {
+ "TripId": 7,
+ "ShareId": "2E77BF06-A354-454B-8BCA-5F004C1AFB59",
+ "Name": "Conference talk about OData",
+ "Budget": 2120.55,
+ "Description": "Conference talk about ODatan",
+ "Tags": ["odata", "overseas"],
+ "StartsAt": "2013-07-02T00:00:00Z",
+ "EndsAt": "2013-07-05T00:00:00Z"
+ },
+ {
+ "TripId": 8,
+ "ShareId": "E6E23FB2-C428-439E-BDAB-9283482F49F0",
+ "Name": "Vocation at hometown",
+ "Budget": 1500.0,
+ "Description": "Vocation at hometown",
+ "Tags": ["voaction"],
+ "StartsAt": "2013-10-01T00:00:00Z",
+ "EndsAt": "2013-10-05T00:00:00Z"
+ },
+ {
+ "TripId": 9,
+ "ShareId": "FAE31279-35CE-4119-9BDC-53F6E19DD1C5",
+ "Name": "Business trip for tech training",
+ "Budget": 100.0,
+ "Description": "Business trip for tech training",
+ "Tags": ["business"],
+ "StartsAt": "2013-09-01T00:00:00Z",
+ "EndsAt": "2013-09-04T00:00:00Z"
+ },
+ {
+ "TripId": 3009,
+ "ShareId": "dd6a09c0-e59b-4745-8612-f4499b676c47",
+ "Name": "Gradutaion trip",
+ "Budget": 6000.0,
+ "Description": "Gradution trip with friends",
+ "Tags": ["Travel"],
+ "StartsAt": "2013-05-01T00:00:00Z",
+ "EndsAt": "2013-05-08T00:00:00Z"
+ },
+ {
+ "TripId": 2004,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Name": "Trip in Beijing",
+ "Budget": 11000.0,
+ "Description": "Trip from Shanghai to Beijing",
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2013-02-02T00:00:00Z"
+ },
+ {
+ "TripId": 4005,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Name": "Trip in Beijing",
+ "Budget": 800.0,
+ "Description": "Trip from Shanghai to Beijing",
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 5007,
+ "ShareId": "5ae142c3-5ad6-4a71-768e-5220ebf1e9f3",
+ "Name": "Business Trip",
+ "Budget": 3800.5,
+ "Description": "This is my first business trip",
+ "Tags": ["business", "first"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 5008,
+ "ShareId": "9ce32ac3-5fd6-4a72-848e-2250ebf1e9f3",
+ "Name": "Trip in Europe",
+ "Budget": 2000.0,
+ "Description": "The trip is currently in plan.",
+ "Tags": ["Travel", "plan"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 1003,
+ "Name": "Trip in Beijing",
+ "Budget": 2000.0,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Description": "Trip from Shanghai to Beijing",
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 2004,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Name": "Trip in Beijing",
+ "Budget": 11000.0,
+ "Description": "Trip from Shanghai to Beijing",
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 1007,
+ "ShareId": "9ce142c3-5fd6-4a71-848e-5220ebf1e9f3",
+ "Name": "Honeymoon",
+ "Budget": 2650.0,
+ "Description": "Happy honeymoon trip",
+ "Tags": ["Travel", "honeymoon"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 7010,
+ "ShareId": "dd6a09c0-e59b-4745-8612-f4499b676c47",
+ "Name": "Gradutaion trip",
+ "Budget": 1000.0,
+ "Description": "Gradution trip with friends",
+ "Tags": ["Travel"],
+ "StartsAt": "2013-05-01T00:00:00Z",
+ "EndsAt": "2013-05-08T00:00:00Z"
+ },
+ {
+ "TripId": 8011,
+ "ShareId": "a88f675d-9199-4392-9656-b08e3b46df8a",
+ "Name": "Study trip",
+ "Budget": 1550.3,
+ "Description": "This is a 2 weeks study trip",
+ "Tags": ["study"],
+ "StartsAt": "2014-01-01T00:00:00Z",
+ "EndsAt": "2013-01-14T00:00:00Z"
+ },
+ {
+ "TripId": 13012,
+ "ShareId": "a88f675d-9199-4392-9656-b08e3b46df8a",
+ "Name": "Study trip",
+ "Budget": 600.0,
+ "Description": "This is a 2 weeks study trip",
+ "Tags": ["study"],
+ "StartsAt": "2014-01-01T00:00:00Z",
+ "EndsAt": "2013-01-14T00:00:00Z"
+ },
+ {
+ "TripId": 14013,
+ "ShareId": "a88f675d-9199-4392-9656-b08e3b46df8a",
+ "Name": "Study trip",
+ "Budget": 2000.0,
+ "Description": "This is a 2 weeks study trip",
+ "Tags": ["study"],
+ "StartsAt": "2014-01-01T00:00:00Z",
+ "EndsAt": "2013-01-14T00:00:00Z"
+ },
+ {
+ "TripId": 16014,
+ "ShareId": "cb0b8acb-79cb-4127-8316-772bc4302824",
+ "Name": "DIY Trip",
+ "Budget": 1500.3,
+ "Description": "This is a DIY trip",
+ "Tags": ["Travel", "DIY"],
+ "StartsAt": "2011-02-11T00:00:00Z",
+ "EndsAt": "2011-02-14T00:00:00Z"
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/resources/trippin.xml
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/trippin.xml b/lib/server-core-ext/src/test/resources/trippin.xml
new file mode 100644
index 0000000..5970793
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/trippin.xml
@@ -0,0 +1,356 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
+ <edmx:DataServices>
+ <Schema Namespace="Microsoft.OData.SampleService.Models.TripPin" xmlns="http://docs.oasis-open.org/odata/ns/edm">
+ <EnumType Name="PersonGender">
+ <Member Name="Male" Value="0" />
+ <Member Name="Female" Value="1" />
+ <Member Name="Unknown" Value="2" />
+ </EnumType>
+ <ComplexType Name="City">
+ <Property Name="CountryRegion" Type="Edm.String" Nullable="false" />
+ <Property Name="Name" Type="Edm.String" Nullable="false" />
+ <Property Name="Region" Type="Edm.String" Nullable="false" />
+ </ComplexType>
+ <ComplexType Name="Location" OpenType="true">
+ <Property Name="Address" Type="Edm.String" Nullable="false" />
+ <Property Name="City" Type="Microsoft.OData.SampleService.Models.TripPin.City" Nullable="false" />
+ </ComplexType>
+ <ComplexType Name="EventLocation" BaseType="Microsoft.OData.SampleService.Models.TripPin.Location" OpenType="true">
+ <Property Name="BuildingInfo" Type="Edm.String" />
+ </ComplexType>
+ <ComplexType Name="AirportLocation" BaseType="Microsoft.OData.SampleService.Models.TripPin.Location" OpenType="true">
+ <Property Name="Loc" Type="Edm.GeographyPoint" Nullable="false" SRID="4326" />
+ </ComplexType>
+ <EntityType Name="Photo" HasStream="true">
+ <Key>
+ <PropertyRef Name="Id" />
+ </Key>
+ <Property Name="Id" Type="Edm.Int64" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="Name" Type="Edm.String" />
+ <Annotation Term="Org.OData.Core.V1.AcceptableMediaTypes">
+ <Collection>
+ <String>image/jpeg</String>
+ </Collection>
+ </Annotation>
+ </EntityType>
+ <EntityType Name="Person" OpenType="true">
+ <Key>
+ <PropertyRef Name="UserName" />
+ </Key>
+ <Property Name="UserName" Type="Edm.String" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="FirstName" Type="Edm.String" Nullable="true" />
+ <Property Name="LastName" Type="Edm.String" Nullable="false" />
+ <Property Name="Emails" Type="Collection(Edm.String)" />
+ <Property Name="AddressInfo" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Location)" />
+ <Property Name="Gender" Type="Microsoft.OData.SampleService.Models.TripPin.PersonGender" />
+ <Property Name="Concurrency" Type="Edm.Int64" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Computed" Bool="true" />
+ </Property>
+ <NavigationProperty Name="Friends" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Person)" />
+ <NavigationProperty Name="Trips" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Trip)" ContainsTarget="true" />
+ <NavigationProperty Name="Photo" Type="Microsoft.OData.SampleService.Models.TripPin.Photo" />
+ </EntityType>
+ <EntityType Name="Airline">
+ <Key>
+ <PropertyRef Name="AirlineCode" />
+ </Key>
+ <Property Name="AirlineCode" Type="Edm.String" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="Name" Type="Edm.String" Nullable="false" />
+ <Property Name="Picture" Type="Edm.Stream" Nullable="true" />
+ </EntityType>
+ <EntityType Name="Airport">
+ <Key>
+ <PropertyRef Name="IcaoCode" />
+ </Key>
+ <Property Name="IcaoCode" Type="Edm.String" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="Name" Type="Edm.String" Nullable="false" />
+ <Property Name="IataCode" Type="Edm.String" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Immutable" Bool="true" />
+ </Property>
+ <Property Name="Location" Type="Microsoft.OData.SampleService.Models.TripPin.AirportLocation" Nullable="false" />
+ </EntityType>
+ <EntityType Name="PlanItem">
+ <Key>
+ <PropertyRef Name="PlanItemId" />
+ </Key>
+ <Property Name="PlanItemId" Type="Edm.Int32" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="ConfirmationCode" Type="Edm.String" />
+ <Property Name="StartsAt" Type="Edm.DateTimeOffset" />
+ <Property Name="EndsAt" Type="Edm.DateTimeOffset" />
+ <Property Name="Duration" Type="Edm.Duration" />
+ </EntityType>
+ <EntityType Name="PublicTransportation" BaseType="Microsoft.OData.SampleService.Models.TripPin.PlanItem">
+ <Property Name="SeatNumber" Type="Edm.String" />
+ </EntityType>
+ <EntityType Name="Flight" BaseType="Microsoft.OData.SampleService.Models.TripPin.PublicTransportation">
+ <Property Name="FlightNumber" Type="Edm.String" Nullable="false" />
+ <NavigationProperty Name="From" Type="Microsoft.OData.SampleService.Models.TripPin.Airport" Nullable="false" />
+ <NavigationProperty Name="To" Type="Microsoft.OData.SampleService.Models.TripPin.Airport" Nullable="false" />
+ <NavigationProperty Name="Airline" Type="Microsoft.OData.SampleService.Models.TripPin.Airline" Nullable="false" />
+ </EntityType>
+ <EntityType Name="Event" BaseType="Microsoft.OData.SampleService.Models.TripPin.PlanItem" OpenType="true">
+ <Property Name="Description" Type="Edm.String" />
+ <Property Name="OccursAt" Type="Microsoft.OData.SampleService.Models.TripPin.EventLocation" Nullable="false" />
+ </EntityType>
+ <EntityType Name="Trip">
+ <Key>
+ <PropertyRef Name="TripId" />
+ </Key>
+ <Property Name="TripId" Type="Edm.Int32" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="ShareId" Type="Edm.Guid" />
+ <Property Name="Description" Type="Edm.String" />
+ <Property Name="Name" Type="Edm.String" Nullable="false" />
+ <Property Name="Budget" Type="Edm.Single" Nullable="false">
+ <Annotation Term="Org.OData.Measures.V1.ISOCurrency" String="USD" />
+ <Annotation Term="Org.OData.Measures.V1.Scale" Int="2" />
+ </Property>
+ <Property Name="StartsAt" Type="Edm.DateTimeOffset" Nullable="false" />
+ <Property Name="EndsAt" Type="Edm.DateTimeOffset" Nullable="false" />
+ <Property Name="Tags" Type="Collection(Edm.String)" Nullable="false" />
+ <NavigationProperty Name="Photos" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Photo)" />
+ <NavigationProperty Name="PlanItems" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.PlanItem)" ContainsTarget="true" />
+ </EntityType>
+ <Function Name="GetFavoriteAirline" IsBound="true" EntitySetPath="person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline" IsComposable="true">
+ <Parameter Name="person" Type="Microsoft.OData.SampleService.Models.TripPin.Person" Nullable="false" />
+ <ReturnType Type="Microsoft.OData.SampleService.Models.TripPin.Airline" Nullable="false" />
+ </Function>
+ <Function Name="GetInvolvedPeople" IsBound="true" IsComposable="true">
+ <Parameter Name="trip" Type="Microsoft.OData.SampleService.Models.TripPin.Trip" Nullable="false" />
+ <ReturnType Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Person)" Nullable="false" />
+ </Function>
+ <Function Name="GetFriendsTrips" IsBound="true" EntitySetPath="person/Friends/Trips" IsComposable="true">
+ <Parameter Name="person" Type="Microsoft.OData.SampleService.Models.TripPin.Person" Nullable="false" />
+ <Parameter Name="userName" Type="Edm.String" Nullable="false" />
+ <ReturnType Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Trip)" Nullable="false" />
+ </Function>
+ <Function Name="GetNearestAirport" IsComposable="true">
+ <Parameter Name="lat" Type="Edm.Double" Nullable="false" />
+ <Parameter Name="lon" Type="Edm.Double" Nullable="false" />
+ <ReturnType Type="Microsoft.OData.SampleService.Models.TripPin.Airport" Nullable="false" />
+ </Function>
+ <Action Name="ResetDataSource" />
+ <Action Name="ShareTrip" IsBound="true">
+ <Parameter Name="person" Type="Microsoft.OData.SampleService.Models.TripPin.Person" Nullable="false" />
+ <Parameter Name="userName" Type="Edm.String" Nullable="false" />
+ <Parameter Name="tripId" Type="Edm.Int32" Nullable="false" />
+ </Action>
+ <EntityContainer Name="DefaultContainer">
+ <EntitySet Name="Photos" EntityType="Microsoft.OData.SampleService.Models.TripPin.Photo">
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Photos" />
+ <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
+ <Record>
+ <PropertyValue Property="Searchable" Bool="true" />
+ <PropertyValue Property="UnsupportedExpressions">
+ <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.InsertRestrictions">
+ <Record>
+ <PropertyValue Property="Insertable" Bool="true" />
+ <PropertyValue Property="NonInsertableNavigationProperties">
+ <Collection />
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ </EntitySet>
+ <EntitySet Name="People" EntityType="Microsoft.OData.SampleService.Models.TripPin.Person">
+ <NavigationPropertyBinding Path="Friends" Target="People" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/Airline" Target="Airlines" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/From" Target="Airports" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/To" Target="Airports" />
+ <NavigationPropertyBinding Path="Photo" Target="Photos" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Trip/Photos" Target="Photos" />
+ <Annotation Term="Org.OData.Core.V1.OptimisticConcurrency">
+ <Collection>
+ <PropertyPath>Concurrency</PropertyPath>
+ </Collection>
+ </Annotation>
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="People" />
+ <Annotation Term="Org.OData.Capabilities.V1.NavigationRestrictions">
+ <Record>
+ <PropertyValue Property="Navigability">
+ <EnumMember>Org.OData.Capabilities.V1.NavigationType/None</EnumMember>
+ </PropertyValue>
+ <PropertyValue Property="RestrictedProperties">
+ <Collection>
+ <Record>
+ <PropertyValue Property="NavigationProperty" NavigationPropertyPath="Friends" />
+ <PropertyValue Property="Navigability">
+ <EnumMember>Org.OData.Capabilities.V1.NavigationType/Recursive</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Collection>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
+ <Record>
+ <PropertyValue Property="Searchable" Bool="true" />
+ <PropertyValue Property="UnsupportedExpressions">
+ <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.InsertRestrictions">
+ <Record>
+ <PropertyValue Property="Insertable" Bool="true" />
+ <PropertyValue Property="NonInsertableNavigationProperties">
+ <Collection>
+ <NavigationPropertyPath>Trips</NavigationPropertyPath>
+ <NavigationPropertyPath>Friends</NavigationPropertyPath>
+ </Collection>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ </EntitySet>
+ <EntitySet Name="Airlines" EntityType="Microsoft.OData.SampleService.Models.TripPin.Airline">
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Airlines" />
+ <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
+ <Record>
+ <PropertyValue Property="Searchable" Bool="true" />
+ <PropertyValue Property="UnsupportedExpressions">
+ <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.InsertRestrictions">
+ <Record>
+ <PropertyValue Property="Insertable" Bool="true" />
+ <PropertyValue Property="NonInsertableNavigationProperties">
+ <Collection />
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ </EntitySet>
+ <EntitySet Name="Airports" EntityType="Microsoft.OData.SampleService.Models.TripPin.Airport">
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Airports" />
+ <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
+ <Record>
+ <PropertyValue Property="Searchable" Bool="true" />
+ <PropertyValue Property="UnsupportedExpressions">
+ <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.InsertRestrictions">
+ <Record>
+ <PropertyValue Property="Insertable" Bool="false" />
+ <PropertyValue Property="NonInsertableNavigationProperties">
+ <Collection />
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.DeleteRestrictions">
+ <Record>
+ <PropertyValue Property="Deletable" Bool="false" />
+ <PropertyValue Property="NonDeletableNavigationProperties">
+ <Collection />
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ </EntitySet>
+ <Singleton Name="Me" Type="Microsoft.OData.SampleService.Models.TripPin.Person">
+ <NavigationPropertyBinding Path="Friends" Target="People" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/Airline" Target="Airlines" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/From" Target="Airports" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/To" Target="Airports" />
+ <NavigationPropertyBinding Path="Photo" Target="Photos" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Trip/Photos" Target="Photos" />
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Me" />
+ </Singleton>
+ <FunctionImport Name="GetNearestAirport" Function="Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport" EntitySet="Airports" IncludeInServiceDocument="true">
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport" />
+ </FunctionImport>
+ <ActionImport Name="ResetDataSource" Action="Microsoft.OData.SampleService.Models.TripPin.ResetDataSource" />
+ <Annotation Term="Org.OData.Core.V1.Description" String="TripPin service is a sample service for OData V4." />
+ </EntityContainer>
+ <Annotations Target="Microsoft.OData.SampleService.Models.TripPin.DefaultContainer">
+ <Annotation Term="Org.OData.Core.V1.DereferenceableIDs" Bool="true" />
+ <Annotation Term="Org.OData.Core.V1.ConventionalIDs" Bool="true" />
+ <Annotation Term="Org.OData.Capabilities.V1.ConformanceLevel">
+ <EnumMember>Org.OData.Capabilities.V1.ConformanceLevelType/Advanced</EnumMember>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.SupportedFormats">
+ <Collection>
+ <String>application/json;odata.metadata=full;IEEE754Compatible=false;odata.streaming=true</String>
+ <String>application/json;odata.metadata=minimal;IEEE754Compatible=false;odata.streaming=true</String>
+ <String>application/json;odata.metadata=none;IEEE754Compatible=false;odata.streaming=true</String>
+ </Collection>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.AsynchronousRequestsSupported" Bool="true" />
+ <Annotation Term="Org.OData.Capabilities.V1.BatchContinueOnErrorSupported" Bool="false" />
+ <Annotation Term="Org.OData.Capabilities.V1.FilterFunctions">
+ <Collection>
+ <String>contains</String>
+ <String>endswith</String>
+ <String>startswith</String>
+ <String>length</String>
+ <String>indexof</String>
+ <String>substring</String>
+ <String>tolower</String>
+ <String>toupper</String>
+ <String>trim</String>
+ <String>concat</String>
+ <String>year</String>
+ <String>month</String>
+ <String>day</String>
+ <String>hour</String>
+ <String>minute</String>
+ <String>second</String>
+ <String>round</String>
+ <String>floor</String>
+ <String>ceiling</String>
+ <String>cast</String>
+ <String>isof</String>
+ </Collection>
+ </Annotation>
+ </Annotations>
+ </Schema>
+ </edmx:DataServices>
+</edmx:Edmx>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index a15d84a..a1c42ad 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -20,6 +20,8 @@ package org.apache.olingo.server.core.deserializer.json;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -62,6 +64,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class ODataJsonDeserializer implements ODataDeserializer {
@@ -259,8 +262,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
node.remove(toRemove);
}
- private void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node, final EntityImpl
- entity) throws DeserializerException {
+ private void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node,
+ final EntityImpl entity) throws DeserializerException {
List<String> propertyNames = edmEntityType.getPropertyNames();
for (String propertyName : propertyNames) {
JsonNode jsonNode = node.get(propertyName);
@@ -401,7 +404,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
case ENUM:
value = readEnumValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
jsonNode);
- property.setValue(ValueType.PRIMITIVE, value);
+ property.setValue(ValueType.ENUM, value);
break;
case COMPLEX:
value = readComplexNode(name, type, isNullable, jsonNode);
@@ -698,4 +701,81 @@ public class ODataJsonDeserializer implements ODataDeserializer {
DeserializerException.MessageKeys.NOT_IMPLEMENTED);
}
}
+
+ @Override
+ public Property property(InputStream stream, EdmProperty edmProperty)
+ throws DeserializerException {
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
+ JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
+ final ObjectNode tree = parser.getCodec().readTree(parser);
+
+ Property property = null;
+ JsonNode jsonNode = tree.get(Constants.VALUE);
+ if (jsonNode != null) {
+ property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(),
+ edmProperty.isCollection(),
+ edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(),
+ edmProperty.isUnicode(), edmProperty.getMapping(),
+ jsonNode);
+ tree.remove(Constants.VALUE);
+ } else {
+ property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(),
+ edmProperty.isCollection(),
+ edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(),
+ edmProperty.isUnicode(), edmProperty.getMapping(),
+ tree);
+ }
+ return property;
+ } catch (JsonParseException e) {
+ throw new DeserializerException("An JsonParseException occurred", e,
+ DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
+ } catch (JsonMappingException e) {
+ throw new DeserializerException("Duplicate property detected", e,
+ DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
+ } catch (IOException e) {
+ throw new DeserializerException("An IOException occurred", e, DeserializerException.MessageKeys.IO_EXCEPTION);
+ }
+ }
+
+ public List<URI> entityReferences(InputStream stream) throws DeserializerException {
+ try {
+ ArrayList<URI> parsedValues = new ArrayList<URI>();
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
+ JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
+ final ObjectNode tree = parser.getCodec().readTree(parser);
+ final String key = "@odata.id";
+ JsonNode jsonNode = tree.get(Constants.VALUE);
+ if (jsonNode != null) {
+ if (jsonNode.isArray()) {
+ ArrayNode arrayNode = (ArrayNode)jsonNode;
+ Iterator<JsonNode> it = arrayNode.iterator();
+ while(it.hasNext()) {
+ parsedValues.add(new URI(it.next().get(key).asText()));
+ }
+ } else {
+ parsedValues.add(new URI(jsonNode.asText()));
+ }
+ tree.remove(Constants.VALUE);
+ // if this is value there can be only one property
+ return parsedValues;
+ }
+ parsedValues.add(new URI(tree.get(key).asText()));
+ return parsedValues;
+ } catch (JsonParseException e) {
+ throw new DeserializerException("An JsonParseException occurred", e,
+ DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
+ } catch (JsonMappingException e) {
+ throw new DeserializerException("Duplicate property detected", e,
+ DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
+ } catch (IOException e) {
+ throw new DeserializerException("An IOException occurred", e,
+ DeserializerException.MessageKeys.IO_EXCEPTION);
+ } catch (URISyntaxException e) {
+ throw new DeserializerException("failed to read @odata.id", e,
+ DeserializerException.MessageKeys.UNKOWN_CONTENT);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index aab6624..5956e82 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -6,9 +6,9 @@
* 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
@@ -41,6 +41,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.ODataServerError;
@@ -127,7 +128,8 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream entityCollection(final EdmEntityType entityType, final EntitySet entitySet,
+ public InputStream entityCollection(final ServiceMetadata metadata,
+ final EdmEntityType entityType, final EntitySet entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
@@ -145,8 +147,9 @@ public class ODataJsonSerializer implements ODataSerializer {
json.writeNumberField(Constants.JSON_COUNT, entitySet.getCount());
}
json.writeFieldName(Constants.VALUE);
- writeEntitySet(entityType, entitySet,
- options == null ? null : options.getExpand(), options == null ? null : options.getSelect(), json);
+ writeEntitySet(metadata, entityType, entitySet, options == null ? null : options.getExpand(),
+ options == null ? null : options.getSelect(),
+ options == null ? false : options.onlyReferences(), json);
if (entitySet.getNext() != null) {
json.writeStringField(Constants.JSON_NEXT_LINK, entitySet.getNext().toASCIIString());
}
@@ -159,14 +162,16 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream entity(final EdmEntityType entityType, final Entity entity,
- final EntitySerializerOptions options) throws SerializerException {
+ public InputStream entity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ final Entity entity, final EntitySerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
- writeEntity(entityType, entity, contextURL,
- options == null ? null : options.getExpand(), options == null ? null : options.getSelect(), json);
+ writeEntity(metadata, entityType, entity, contextURL,
+ options == null ? null : options.getExpand(),
+ options == null ? null : options.getSelect(),
+ options == null ? false: options.onlyReferences(), json);
json.close();
} catch (final IOException e) {
throw new SerializerException("An I/O exception occurred.", e,
@@ -184,18 +189,26 @@ public class ODataJsonSerializer implements ODataSerializer {
return contextURL;
}
- protected void writeEntitySet(final EdmEntityType entityType, final EntitySet entitySet,
- final ExpandOption expand, final SelectOption select, final JsonGenerator json)
- throws IOException, SerializerException {
+ protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
+ final EntitySet entitySet, final ExpandOption expand, final SelectOption select,
+ final boolean onlyReference, final JsonGenerator json) throws IOException,
+ SerializerException {
json.writeStartArray();
for (final Entity entity : entitySet.getEntities()) {
- writeEntity(entityType, entity, null, expand, select, json);
+ if (onlyReference) {
+ json.writeStartObject();
+ json.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
+ json.writeEndObject();
+ } else {
+ writeEntity(metadata, entityType, entity, null, expand, select, false, json);
+ }
}
json.writeEndArray();
}
- protected void writeEntity(final EdmEntityType entityType, final Entity entity, final ContextURL contextURL,
- final ExpandOption expand, final SelectOption select, final JsonGenerator json)
+ protected void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ final Entity entity, final ContextURL contextURL, final ExpandOption expand,
+ final SelectOption select, boolean onlyReference, final JsonGenerator json)
throws IOException, SerializerException {
json.writeStartObject();
if (format != ODataFormat.JSON_NO_METADATA) {
@@ -214,9 +227,63 @@ public class ODataJsonSerializer implements ODataSerializer {
}
}
}
- writeProperties(entityType, entity.getProperties(), select, json);
- writeNavigationProperties(entityType, entity, expand, json);
- json.writeEndObject();
+ if (onlyReference) {
+ json.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
+ } else {
+ EdmEntityType resolvedType = resolveEntityType(metadata, entityType, entity.getType());
+ if (!resolvedType.equals(entityType)) {
+ json.writeStringField(Constants.JSON_TYPE, "#"+entity.getType());
+ }
+ writeProperties(resolvedType, entity.getProperties(), select, json);
+ writeNavigationProperties(metadata, resolvedType, entity, expand, json);
+ json.writeEndObject();
+ }
+ }
+
+ protected EdmEntityType resolveEntityType(ServiceMetadata metadata, EdmEntityType baseType,
+ String derivedTypeName) throws SerializerException {
+ if (baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
+ return baseType;
+ }
+ EdmEntityType derivedType = metadata.getEdm().getEntityType(new FullQualifiedName(derivedTypeName));
+ if (derivedType == null) {
+ throw new SerializerException("EntityType not found",
+ SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName);
+ }
+ EdmEntityType type = derivedType.getBaseType();
+ while (type != null) {
+ if (type.getFullQualifiedName().getFullQualifiedNameAsString()
+ .equals(baseType.getFullQualifiedName().getFullQualifiedNameAsString())) {
+ return derivedType;
+ }
+ type = type.getBaseType();
+ }
+ throw new SerializerException("Wrong base type",
+ SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType
+ .getFullQualifiedName().getFullQualifiedNameAsString());
+ }
+
+ protected EdmComplexType resolveComplexType(ServiceMetadata metadata, EdmComplexType baseType,
+ String derivedTypeName) throws SerializerException {
+ if (baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
+ return baseType;
+ }
+ EdmComplexType derivedType = metadata.getEdm().getComplexType(new FullQualifiedName(derivedTypeName));
+ if (derivedType == null) {
+ throw new SerializerException("Complex Type not found",
+ SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName);
+ }
+ EdmComplexType type = derivedType.getBaseType();
+ while (type != null) {
+ if (type.getFullQualifiedName().getFullQualifiedNameAsString()
+ .equals(baseType.getFullQualifiedName().getFullQualifiedNameAsString())) {
+ return derivedType;
+ }
+ type = type.getBaseType();
+ }
+ throw new SerializerException("Wrong base type",
+ SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType
+ .getFullQualifiedName().getFullQualifiedNameAsString());
}
protected void writeProperties(final EdmStructuredType type, final List<Property> properties,
@@ -235,8 +302,9 @@ public class ODataJsonSerializer implements ODataSerializer {
}
}
- protected void writeNavigationProperties(final EdmStructuredType type, final Linked linked,
- final ExpandOption expand, final JsonGenerator json) throws SerializerException, IOException {
+ protected void writeNavigationProperties(final ServiceMetadata metadata,
+ final EdmStructuredType type, final Linked linked, final ExpandOption expand,
+ final JsonGenerator json) throws SerializerException, IOException {
if (ExpandSelectHelper.hasExpand(expand)) {
final boolean expandAll = ExpandSelectHelper.isExpandAll(expand);
final Set<String> expanded = expandAll ? null :
@@ -251,7 +319,7 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("Expand options $ref and $levels are not supported.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
- writeExpandedNavigationProperty(property, navigationLink,
+ writeExpandedNavigationProperty(metadata, property, navigationLink,
innerOptions == null ? null : innerOptions.getExpandOption(),
innerOptions == null ? null : innerOptions.getSelectOption(),
json);
@@ -260,7 +328,8 @@ public class ODataJsonSerializer implements ODataSerializer {
}
}
- protected void writeExpandedNavigationProperty(final EdmNavigationProperty property, final Link navigationLink,
+ protected void writeExpandedNavigationProperty(final ServiceMetadata metadata,
+ final EdmNavigationProperty property, final Link navigationLink,
final ExpandOption innerExpand, final SelectOption innerSelect, JsonGenerator json)
throws IOException, SerializerException {
json.writeFieldName(property.getName());
@@ -269,13 +338,15 @@ public class ODataJsonSerializer implements ODataSerializer {
json.writeStartArray();
json.writeEndArray();
} else {
- writeEntitySet(property.getType(), navigationLink.getInlineEntitySet(), innerExpand, innerSelect, json);
+ writeEntitySet(metadata, property.getType(), navigationLink.getInlineEntitySet(), innerExpand,
+ innerSelect, false, json);
}
} else {
if (navigationLink == null || navigationLink.getInlineEntity() == null) {
json.writeNull();
} else {
- writeEntity(property.getType(), navigationLink.getInlineEntity(), null, innerExpand, innerSelect, json);
+ writeEntity(metadata, property.getType(), navigationLink.getInlineEntity(), null,
+ innerExpand, innerSelect, false, json);
}
}
}
@@ -316,6 +387,11 @@ public class ODataJsonSerializer implements ODataSerializer {
} else if (property.isComplex()) {
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asComplex().getValue(),
selectedPaths, json);
+ } else if (property.isEnum()) {
+ writePrimitive((EdmPrimitiveType) edmProperty.getType(), property,
+ edmProperty.isNullable(), edmProperty.getMaxLength(),
+ edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
+ json);
} else {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
@@ -467,8 +543,8 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream complex(final EdmComplexType type, final Property property,
- final ComplexSerializerOptions options) throws SerializerException {
+ public InputStream complex(final ServiceMetadata metadata, final EdmComplexType type,
+ final Property property, final ComplexSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
@@ -477,11 +553,15 @@ public class ODataJsonSerializer implements ODataSerializer {
if (contextURL != null) {
json.writeStringField(Constants.JSON_CONTEXT, ContextURLBuilder.create(contextURL).toASCIIString());
}
+ EdmComplexType resolvedType = resolveComplexType(metadata, type, property.getType());
+ if (!resolvedType.equals(type)) {
+ json.writeStringField(Constants.JSON_TYPE, "#"+property.getType());
+ }
final List<Property> values =
property.isNull() ? Collections.<Property> emptyList() : property.asComplex().getValue();
writeProperties(type, values, options == null ? null : options.getSelect(), json);
if (!property.isNull() && property.isComplex()) {
- writeNavigationProperties(type, property.asComplex(),
+ writeNavigationProperties(metadata, type, property.asComplex(),
options == null ? null : options.getExpand(), json);
}
json.writeEndObject();
@@ -523,8 +603,8 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream complexCollection(final EdmComplexType type, final Property property,
- final ComplexSerializerOptions options) throws SerializerException {
+ public InputStream complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
+ final Property property, final ComplexSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
index 4a3f82a..ac33759 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
@@ -66,7 +66,14 @@ public final class ContextURLBuilder {
if (contextURL.getEntitySetOrSingletonOrType() != null) {
throw new IllegalArgumentException("ContextURL: $ref with Entity Set");
}
- result.append('#').append(ContextURL.Suffix.REFERENCE.getRepresentation());
+ if(contextURL.isCollection()) {
+ result.append('#');
+ result.append("Collection(")
+ .append(ContextURL.Suffix.REFERENCE.getRepresentation())
+ .append(")");
+ } else {
+ result.append('#').append(ContextURL.Suffix.REFERENCE.getRepresentation());
+ }
} else if (contextURL.getSuffix() != null) {
if (contextURL.getEntitySetOrSingletonOrType() == null) {
throw new IllegalArgumentException("ContextURL: Suffix without preceding Entity Set!");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
index acd1ded..34756c1 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
@@ -6,9 +6,9 @@
* 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
@@ -87,14 +87,15 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream entity(final EdmEntityType entityType, final Entity entity,
- final EntitySerializerOptions options) throws SerializerException {
+ public InputStream entity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ final Entity entity, final EntitySerializerOptions options) throws SerializerException {
throw new SerializerException("Entity serialization not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream entityCollection(final EdmEntityType entityType, final EntitySet entitySet,
+ public InputStream entityCollection(final ServiceMetadata metadata,
+ final EdmEntityType entityType, final EntitySet entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
throw new SerializerException("Entityset serialization not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
@@ -114,8 +115,8 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream complex(final EdmComplexType type, final Property property,
- final ComplexSerializerOptions options) throws SerializerException {
+ public InputStream complex(final ServiceMetadata metadata, final EdmComplexType type,
+ final Property property, final ComplexSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@@ -128,8 +129,8 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream complexCollection(final EdmComplexType type, final Property property,
- final ComplexSerializerOptions options) throws SerializerException {
+ public InputStream complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
+ final Property property, final ComplexSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
index 82fe743..a78d79f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
@@ -6,9 +6,9 @@
* 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
@@ -56,12 +56,18 @@ public class UriResourceActionImpl extends UriResourceTypedImpl implements UriRe
@Override
public boolean isCollection() {
- return action.getReturnType() !=null && action.getReturnType().isCollection();
+ if (action.getReturnType() != null) {
+ return action.getReturnType().isCollection();
+ }
+ return false;
}
@Override
public EdmType getType() {
- return action.getReturnType() == null ? null : action.getReturnType().getType();
+ if (action.getReturnType() != null) {
+ return action.getReturnType().getType();
+ }
+ return null;
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
index 0b3a5f9..cf54938 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
@@ -6,9 +6,9 @@
* 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
@@ -60,7 +60,7 @@ public class UriValidator {
/* entitySetCount 7 */ { true , false, false, false, false, false, true, false, false, false, false },
/* entity 8 */ { false, true , true , false, false, false, false, true , false, false, false },
/* mediaStream 9 */ { false, false, false, false, false, false, false, false, false, false, false },
- /* references 10 */ { true , true , false, false, false, true , true , false, true , true , true },
+ /* references 10 */ { true , true , false, true, false, true , true , false, true , true , true },
/* reference 11 */ { false, true , false, false, false, false, false, false, false, false, false },
/* propertyComplex 12 */ { false, true , true , false, false, false, false, true , false, false, false },
/* propertyComplexCollection 13 */ { true , true , true , false, true , true , false, true , true , true , true },
@@ -78,7 +78,7 @@ public class UriValidator {
/* GET 0 */ { true , true , true , true, true , true , true , true , true , true , true },
/* POST 0 */ { true , false , true , false, false , true , false , true , false , false , false },
/* PUT 0 */ { false , false , false , false, false , false , false , false , false , false , false },
- /* DELETE 0 */ { false , false , false , false, false , false, false , false, false , false , false },
+ /* DELETE 0 */ { false , false , false , true, false , false, false , false, false , false , false },
/* PATCH 0 */ { false , false , false , false, false , false , false , false , false , false , false }
};
//CHECKSTYLE:ON
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index 76266ea..b8254c3 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -96,6 +96,8 @@ SerializerException.INCONSISTENT_PROPERTY_TYPE=An inconsistency has been detecte
SerializerException.MISSING_PROPERTY=The non-nullable property '%1$s' is missing.
SerializerException.WRONG_PROPERTY_VALUE=The value '%2$s' is not valid for property '%1$s'.
SerializerException.WRONG_PRIMITIVE_VALUE=The value '%2$s' is not valid for the primitive type '%1$s' and the given facets.
+SerializerException.UNKNOWN_TYPE=Type '%1s' not found in metadata.
+SerializerException.WRONG_BASE_TYPE=Type '%1s' is not derived from '%2s'.
DeserializerException.NOT_IMPLEMENTED=The requested deserialization method has not been implemented yet.
DeserializerException.IO_EXCEPTION=An I/O exception occurred.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
index f3e22ef..a301c3d 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
@@ -6,9 +6,9 @@
* 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
@@ -18,8 +18,13 @@
*/
package org.apache.olingo.server.core.deserializer.json;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.ByteArrayInputStream;
+import java.net.URI;
+import java.util.List;
+
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
@@ -41,4 +46,33 @@ public class ODataJsonDeserializerBasicTest {
assertNotNull(deserializer);
deserializer = null;
}
+
+ @Test
+ public void testReadingCollectionProperties() throws Exception {
+ String payload = "{\n" +
+ " \"@odata.context\": \"http://host/service/$metadata#Collection($ref)\",\n" +
+ " \"value\": [\n" +
+ " { \"@odata.id\": \"Orders(10643)\" },\n" +
+ " { \"@odata.id\": \"Orders(10759)\" }\n" +
+ " ]\n" +
+ "}";
+ ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
+ List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()));
+ assertEquals(2, values.size());
+ assertEquals("Orders(10643)", values.get(0).toASCIIString());
+ assertEquals("Orders(10759)", values.get(1).toASCIIString());
+ }
+
+ @Test
+ public void testReadingProperties() throws Exception {
+ String payload = "{\n" +
+ " \"@odata.context\": \"http://host/service/$metadata#$ref\",\n" +
+ " \"@odata.id\": \"Orders(10643)\"\n" +
+ "}";
+ ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
+ List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload
+ .getBytes()));
+ assertEquals(1, values.size());
+ assertEquals("Orders(10643)", values.get(0).toASCIIString());
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 742c5d5..1e4537f 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -6,9 +6,9 @@
* 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
@@ -49,14 +49,17 @@ public class ODataJsonSerializerTest {
final ODataJsonSerializer serializer = new ODataJsonSerializer(ODataFormat.APPLICATION_JSON);
final ComplexSerializerOptions options = ComplexSerializerOptions.with()
.contextURL(ContextURL.with().selectList("ComplexCollection").build()).build();
- final InputStream in = serializer.complexCollection(ComplexTypeHelper.createType(), complexCollection, options);
+ final InputStream in = serializer.complexCollection(null, ComplexTypeHelper.createType(),
+ complexCollection, options);
final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("value")) {
- assertEquals("{\"@odata.context\":\"$metadata(ComplexCollection)\",\"value\":"
- + "[{\"prop1\":\"test1\",\"prop2\":\"test11\"},{\"prop1\":\"test2\",\"prop2\":\"test22\"}]}", line);
+ assertEquals(
+ "{\"@odata.context\":\"$metadata(ComplexCollection)\",\"value\":"
+ + "[{\"prop1\":\"test1\",\"prop2\":\"test11\"},{\"prop1\":\"test2\",\"prop2\":\"test22\"}]}",
+ line);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java
index 7fa981b..4137db0 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java
@@ -6,9 +6,9 @@
* 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
@@ -66,8 +66,8 @@ public class TechnicalServlet extends HttpServlet {
}
ODataHttpHandler handler = odata.createHandler(serviceMetadata);
- handler.register(new TechnicalEntityProcessor(dataProvider));
- handler.register(new TechnicalPrimitiveComplexProcessor(dataProvider));
+ handler.register(new TechnicalEntityProcessor(dataProvider, serviceMetadata));
+ handler.register(new TechnicalPrimitiveComplexProcessor(dataProvider, serviceMetadata));
handler.register(new TechnicalBatchProcessor(dataProvider));
handler.process(req, resp);
} catch (RuntimeException e) {
[10/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Edm cleanup:
Remove EdmAnnotationHelperImpl
Posted by ch...@apache.org.
[OLINGO-575] Edm cleanup: Remove EdmAnnotationHelperImpl
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/16b94eb4
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/16b94eb4
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/16b94eb4
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 16b94eb47e3b9f0274fd9ec66e68b729b00d5a17
Parents: 4f33c70
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Mar 27 13:41:03 2015 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Mar 27 13:45:00 2015 +0100
----------------------------------------------------------------------
.../edm/provider/AbstractEdmAnnotatable.java | 65 +++++++
.../core/edm/provider/AbstractEdmBase.java | 31 ++++
.../edm/provider/AbstractEdmBindingTarget.java | 127 +++++++++++++
.../core/edm/provider/AbstractEdmNamed.java | 38 ++++
.../core/edm/provider/AbstractEdmOperation.java | 162 ++++++++++++++++
.../provider/AbstractEdmOperationImport.java | 77 ++++++++
.../edm/provider/AbstractEdmStructuredType.java | 184 +++++++++++++++++++
.../core/edm/provider/EdmActionImpl.java | 4 +-
.../core/edm/provider/EdmActionImportImpl.java | 2 +-
.../edm/provider/EdmAnnotationHelperImpl.java | 67 -------
.../core/edm/provider/EdmAnnotationImpl.java | 18 +-
.../core/edm/provider/EdmBindingTargetImpl.java | 141 --------------
.../core/edm/provider/EdmComplexTypeImpl.java | 19 +-
.../core/edm/provider/EdmElementImpl.java | 29 ---
.../edm/provider/EdmEntityContainerImpl.java | 21 +--
.../core/edm/provider/EdmEntitySetImpl.java | 2 +-
.../core/edm/provider/EdmEntityTypeImpl.java | 16 +-
.../core/edm/provider/EdmEnumTypeImpl.java | 6 +-
.../core/edm/provider/EdmFunctionImpl.java | 4 +-
.../edm/provider/EdmFunctionImportImpl.java | 2 +-
.../core/edm/provider/EdmMemberImpl.java | 21 +--
.../commons/core/edm/provider/EdmNamedImpl.java | 39 ----
.../edm/provider/EdmNavigationPropertyImpl.java | 19 +-
.../core/edm/provider/EdmOperationImpl.java | 176 ------------------
.../edm/provider/EdmOperationImportImpl.java | 93 ----------
.../core/edm/provider/EdmParameterImpl.java | 21 +--
.../core/edm/provider/EdmPropertyImpl.java | 21 +--
.../provider/EdmReferentialConstraintImpl.java | 19 +-
.../core/edm/provider/EdmSingletonImpl.java | 2 +-
.../edm/provider/EdmStructuredTypeImpl.java | 184 -------------------
.../commons/core/edm/provider/EdmTermImpl.java | 18 +-
.../edm/provider/EdmTypeDefinitionImpl.java | 22 +--
.../commons/core/edm/provider/EdmTypeImpl.java | 8 +-
.../commons/core/edm/provider/EdmTypeInfo.java | 26 +--
.../core/edm/provider/AbstractEdmNamedTest.java | 59 ++++++
.../core/edm/provider/EdmNamedImplTest.java | 42 -----
.../core/edm/provider/EdmTypeImplTest.java | 19 +-
37 files changed, 806 insertions(+), 998 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java
new file mode 100644
index 0000000..d36c3a2
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmAnnotatable.java
@@ -0,0 +1,65 @@
+/*
+ * 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.provider;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAnnotatable;
+import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmTerm;
+import org.apache.olingo.commons.api.edm.provider.Annotatable;
+import org.apache.olingo.commons.api.edm.provider.Annotation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractEdmAnnotatable extends AbstractEdmBase implements EdmAnnotatable {
+
+ private final Annotatable annotatable;
+ private List<EdmAnnotation> annotations;
+
+ public AbstractEdmAnnotatable(final Edm edm, final Annotatable annotatable) {
+ super(edm);
+ this.annotatable = annotatable;
+ }
+
+ @Override
+ public EdmAnnotation getAnnotation(final EdmTerm term) {
+ EdmAnnotation result = null;
+ for (EdmAnnotation annotation : getAnnotations()) {
+ if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) {
+ result = annotation;
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public List<EdmAnnotation> getAnnotations() {
+ if (annotations == null) {
+ annotations = new ArrayList<EdmAnnotation>();
+ if(annotatable != null) {
+ for (Annotation annotation : annotatable.getAnnotations()) {
+ annotations.add(new EdmAnnotationImpl(edm, annotation));
+ }
+ }
+ }
+ return annotations;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBase.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBase.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBase.java
new file mode 100644
index 0000000..e6d3c6a
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBase.java
@@ -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.commons.core.edm.provider;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAnnotatable;
+
+public abstract class AbstractEdmBase implements EdmAnnotatable {
+
+ protected final Edm edm;
+
+ public AbstractEdmBase(final Edm edm) {
+ this.edm = edm;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java
new file mode 100644
index 0000000..61bba66
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmBindingTarget.java
@@ -0,0 +1,127 @@
+/*
+ * 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.provider;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.Target;
+import org.apache.olingo.commons.api.edm.provider.BindingTarget;
+import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
+
+public abstract class AbstractEdmBindingTarget extends AbstractEdmNamed implements EdmBindingTarget {
+
+ private final BindingTarget target;
+ private final EdmEntityContainer container;
+
+ private List<EdmNavigationPropertyBinding> navigationPropertyBindings;
+
+ public AbstractEdmBindingTarget(final Edm edm, final EdmEntityContainer container, final BindingTarget target) {
+ super(edm, target.getName(), target);
+ this.container = container;
+ this.target = target;
+ }
+
+ @Override
+ public List<EdmNavigationPropertyBinding> getNavigationPropertyBindings() {
+ if (navigationPropertyBindings == null) {
+ List<NavigationPropertyBinding> providerBindings = target.getNavigationPropertyBindings();
+ navigationPropertyBindings = new ArrayList<EdmNavigationPropertyBinding>();
+ if (providerBindings != null) {
+ for (NavigationPropertyBinding binding : providerBindings) {
+ navigationPropertyBindings.add(new EdmNavigationPropertyBindingImpl(binding.getPath(), binding.getTarget()));
+ }
+ }
+ }
+ return navigationPropertyBindings;
+ }
+
+ @Override
+ public EdmEntityContainer getEntityContainer() {
+ return container;
+ }
+
+ @Override
+ public EdmEntityType getEntityType() {
+ final EdmEntityType entityType = edm.getEntityType(target.getTypeFQN());
+ if (entityType == null) {
+ throw new EdmException("Can´t find entity type: " + target.getTypeFQN() + " for entity set or singleton: "
+ + getName());
+ }
+ return entityType;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return container.getFullQualifiedName();
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return getName();
+ }
+
+ @Override
+ public EdmBindingTarget getRelatedBindingTarget(final String path) {
+ if (path == null) {
+ return null;
+ }
+ EdmBindingTarget bindingTarget = null;
+ boolean found = false;
+ for (final Iterator<EdmNavigationPropertyBinding> itor = getNavigationPropertyBindings().iterator(); itor.hasNext()
+ && !found;) {
+
+ final EdmNavigationPropertyBinding binding = itor.next();
+ if (path.startsWith(binding.getPath())) {
+ final Target edmTarget = new Target.Builder(binding.getTarget(), container).build();
+
+ final EdmEntityContainer entityContainer = edm.getEntityContainer(edmTarget.getEntityContainer());
+ if (entityContainer == null) {
+ throw new EdmException("Cannot find entity container with name: " + edmTarget.getEntityContainer());
+ }
+ try {
+ bindingTarget = entityContainer.getEntitySet(edmTarget.getTargetName());
+
+ if (bindingTarget == null) {
+ throw new EdmException("Cannot find EntitySet " + edmTarget.getTargetName());
+ }
+ } catch (EdmException e) {
+ // try with singletons ...
+ bindingTarget = entityContainer.getSingleton(edmTarget.getTargetName());
+
+ if (bindingTarget == null) {
+ throw new EdmException("Cannot find Singleton " + edmTarget.getTargetName());
+ }
+ } finally {
+ found = bindingTarget != null;
+ }
+ }
+ }
+
+ return bindingTarget;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmNamed.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmNamed.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmNamed.java
new file mode 100644
index 0000000..8835bc5
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmNamed.java
@@ -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.commons.core.edm.provider;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmNamed;
+import org.apache.olingo.commons.api.edm.provider.Annotatable;
+
+public abstract class AbstractEdmNamed extends AbstractEdmAnnotatable implements EdmNamed {
+
+ private final String name;
+
+ public AbstractEdmNamed(final Edm edm, final String name, final Annotatable annotatable) {
+ super(edm, annotatable);
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java
new file mode 100644
index 0000000..788a974
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperation.java
@@ -0,0 +1,162 @@
+/*
+ * 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.provider;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmOperation;
+import org.apache.olingo.commons.api.edm.EdmParameter;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.edm.provider.Operation;
+import org.apache.olingo.commons.api.edm.provider.Parameter;
+
+public abstract class AbstractEdmOperation extends EdmTypeImpl implements EdmOperation {
+
+ protected final Operation operation;
+ private final Map<String, EdmParameter> parameters = new LinkedHashMap<String, EdmParameter>();
+ private String entitySetPath;
+ private boolean isBound;
+ private EdmReturnType returnType;
+ private List<String> parameterNames;
+
+ protected static <T extends AbstractEdmOperation> T getInstance(final T instance) {
+ final List<Parameter> providerParameters = instance.operation.getParameters();
+ if (providerParameters != null) {
+ final List<EdmParameter> _parameters = new ArrayList<EdmParameter>(providerParameters.size());
+ for (Parameter parameter : providerParameters) {
+ _parameters.add(new EdmParameterImpl(instance.edm, parameter));
+ }
+ instance.setParameters(_parameters);
+ }
+
+ final String entitySetPath = instance.operation.getEntitySetPath();
+ if (entitySetPath != null) {
+ instance.setEntitySetPath(entitySetPath);
+ }
+
+ instance.setIsBound(instance.operation.isBound());
+
+ if (instance.operation.getReturnType() != null) {
+ instance.setReturnType(new EdmReturnTypeImpl(instance.edm, instance.operation.getReturnType()));
+ }
+
+ return instance;
+ }
+
+ protected AbstractEdmOperation(final Edm edm, final FullQualifiedName name, final Operation operation,
+ final EdmTypeKind kind) {
+
+ super(edm, name, kind, operation);
+ this.operation = operation;
+ }
+
+ protected void setParameters(final List<EdmParameter> _parameters) {
+ for (EdmParameter parameter : _parameters) {
+ parameters.put(parameter.getName(), parameter);
+ }
+ }
+
+ protected void setEntitySetPath(final String entitySetPath) {
+ this.entitySetPath = entitySetPath;
+ }
+
+ protected void setIsBound(final boolean isBound) {
+ this.isBound = isBound;
+ }
+
+ protected void setReturnType(final EdmReturnType returnType) {
+ this.returnType = returnType;
+ }
+
+ @Override
+ public EdmParameter getParameter(final String name) {
+ return parameters.get(name);
+ }
+
+ @Override
+ public List<String> getParameterNames() {
+ if (parameterNames == null) {
+ parameterNames = new ArrayList<String>(parameters.size());
+ for (String parameterName : parameters.keySet()) {
+ parameterNames.add(parameterName);
+ }
+ }
+ return parameterNames;
+ }
+
+ @Override
+ public EdmEntitySet getReturnedEntitySet(final EdmEntitySet bindingParameterEntitySet) {
+ EdmEntitySet returnedEntitySet = null;
+ if (bindingParameterEntitySet != null && entitySetPath != null) {
+ final EdmBindingTarget relatedBindingTarget = bindingParameterEntitySet.getRelatedBindingTarget(entitySetPath);
+ if (relatedBindingTarget == null) {
+ throw new EdmException("Cannot find entity set with path: " + entitySetPath);
+ }
+ if (relatedBindingTarget instanceof EdmEntitySet) {
+ returnedEntitySet = (EdmEntitySet) relatedBindingTarget;
+ } else {
+ throw new EdmException("BindingTarget with name: " + relatedBindingTarget.getName()
+ + " must be an entity set");
+ }
+ }
+ return returnedEntitySet;
+ }
+
+ @Override
+ public EdmReturnType getReturnType() {
+ return returnType;
+ }
+
+ @Override
+ public boolean isBound() {
+ return isBound;
+ }
+
+ @Override
+ public FullQualifiedName getBindingParameterTypeFqn() {
+ if (isBound()) {
+ Parameter bindingParameter = operation.getParameters().get(0);
+ return bindingParameter.getTypeFQN();
+ }
+ return null;
+ }
+
+ @Override
+ public Boolean isBindingParameterTypeCollection() {
+ if (isBound()) {
+ Parameter bindingParameter = operation.getParameters().get(0);
+ return bindingParameter.isCollection();
+ }
+ return null;
+ }
+
+ @Override
+ public String getEntitySetPath(){
+ return operation.getEntitySetPath();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java
new file mode 100644
index 0000000..82c3465
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmOperationImport.java
@@ -0,0 +1,77 @@
+/*
+ * 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.provider;
+
+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.EdmException;
+import org.apache.olingo.commons.api.edm.EdmOperationImport;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.Target;
+import org.apache.olingo.commons.api.edm.provider.OperationImport;
+
+public abstract class AbstractEdmOperationImport extends AbstractEdmNamed implements EdmOperationImport {
+
+ protected final EdmEntityContainer container;
+ private final Target entitySet;
+ private EdmEntitySet returnedEntitySet;
+
+ public AbstractEdmOperationImport(final Edm edm, final EdmEntityContainer container,
+ final OperationImport operationImport) {
+ super(edm, operationImport.getName(), operationImport);
+ this.container = container;
+ this.entitySet = new Target.Builder(operationImport.getEntitySet(), container).build();
+ }
+
+ @Override
+ public FullQualifiedName getFullQualifiedName() {
+ return new FullQualifiedName(container.getNamespace(), getName());
+ }
+
+ @Override
+ public EdmEntitySet getReturnedEntitySet() {
+ if (entitySet != null && returnedEntitySet == null) {
+ EdmEntityContainer entityContainer = edm.getEntityContainer(entitySet.getEntityContainer());
+ if (entityContainer == null) {
+ throw new EdmException("Can´t find entity container with name: " + entitySet.getEntityContainer());
+ }
+ returnedEntitySet = entityContainer.getEntitySet(entitySet.getTargetName());
+ if (returnedEntitySet == null) {
+ throw new EdmException("Can´t find entity set with name: " + entitySet.getTargetName());
+ }
+ }
+ return returnedEntitySet;
+ }
+
+ @Override
+ public EdmEntityContainer getEntityContainer() {
+ return container;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return container.getFullQualifiedName();
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return getName();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java
new file mode 100644
index 0000000..1d773ea
--- /dev/null
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/AbstractEdmStructuredType.java
@@ -0,0 +1,184 @@
+/*
+ * 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.provider;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmElement;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.edm.provider.NavigationProperty;
+import org.apache.olingo.commons.api.edm.provider.Property;
+import org.apache.olingo.commons.api.edm.provider.StructuralType;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements EdmStructuredType {
+
+ protected EdmStructuredType baseType;
+ protected FullQualifiedName baseTypeName;
+
+ private List<String> propertyNames;
+ private List<String> navigationPropertyNames;
+ private Map<String, EdmProperty> properties;
+ private Map<String, EdmNavigationProperty> navigationProperties;
+ private final StructuralType structuredType;
+
+ public AbstractEdmStructuredType(
+ final Edm edm,
+ final FullQualifiedName typeName,
+ final EdmTypeKind kind,
+ final StructuralType structuredType) {
+
+ super(edm, typeName, kind, structuredType);
+ this.baseTypeName = structuredType.getBaseTypeFQN();
+ this.structuredType = structuredType;
+ }
+
+ protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName);
+
+ protected abstract void checkBaseType();
+
+ @Override
+ public List<String> getPropertyNames() {
+ if (propertyNames == null) {
+ propertyNames = new ArrayList<String>();
+ checkBaseType();
+ if (baseType != null) {
+ propertyNames.addAll(baseType.getPropertyNames());
+ }
+ propertyNames.addAll(getProperties().keySet());
+ }
+ return propertyNames;
+ }
+
+ @Override
+ public List<String> getNavigationPropertyNames() {
+ if (navigationPropertyNames == null) {
+ navigationPropertyNames = new ArrayList<String>();
+ checkBaseType();
+ if (baseType != null) {
+ navigationPropertyNames.addAll(baseType.getNavigationPropertyNames());
+ }
+ navigationPropertyNames.addAll(getNavigationProperties().keySet());
+ }
+ return navigationPropertyNames;
+ }
+
+ @Override
+ public EdmElement getProperty(final String name) {
+ EdmElement property = getStructuralProperty(name);
+ if (property == null) {
+ property = getNavigationProperty(name);
+ }
+ return property;
+ }
+
+ @Override
+ public EdmProperty getStructuralProperty(final String name) {
+ EdmProperty property = null;
+ checkBaseType();
+ if (baseType != null) {
+ property = baseType.getStructuralProperty(name);
+ }
+ if (property == null) {
+ property = getProperties().get(name);
+ }
+ return property;
+ }
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty(final String name) {
+ EdmNavigationProperty property = null;
+ checkBaseType();
+ if (baseType != null) {
+ property = baseType.getNavigationProperty(name);
+ }
+ if (property == null) {
+ property = getNavigationProperties().get(name);
+ }
+ return property;
+ }
+
+ @Override
+ public boolean compatibleTo(final EdmType targetType) {
+ EdmStructuredType sourceType = this;
+ if (targetType == null) {
+ throw new EdmException("Target type must not be null");
+ }
+ while (!sourceType.getName().equals(targetType.getName())
+ || !sourceType.getNamespace().equals(targetType.getNamespace())) {
+
+ sourceType = sourceType.getBaseType();
+ if (sourceType == null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public String getAnnotationsTargetPath() {
+ return null;
+ }
+
+ @Override
+ public FullQualifiedName getAnnotationsTargetFQN() {
+ return getFullQualifiedName();
+ }
+
+ public Map<String, EdmProperty> getProperties() {
+ if (properties == null) {
+ properties = new LinkedHashMap<String, EdmProperty>();
+ for (Property property : structuredType.getProperties()) {
+ properties.put(property.getName(), new EdmPropertyImpl(edm, typeName, property));
+ }
+ }
+ return properties;
+ }
+
+ public Map<String, EdmNavigationProperty> getNavigationProperties() {
+ if (navigationProperties == null) {
+ navigationProperties = new LinkedHashMap<String, EdmNavigationProperty>();
+ if (structuredType.getNavigationProperties() != null) {
+ for (NavigationProperty navigationProperty : structuredType.getNavigationProperties()) {
+ navigationProperties.put(navigationProperty.getName(),
+ new EdmNavigationPropertyImpl(edm, typeName, navigationProperty));
+ }
+ }
+ }
+ return navigationProperties;
+ }
+
+ public boolean isOpenType() {
+ return structuredType.isOpenType();
+ }
+
+ public boolean isAbstract() {
+ return structuredType.isAbstract();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java
index 292f234..822ebc8 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImpl.java
@@ -24,10 +24,10 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.Action;
-public class EdmActionImpl extends EdmOperationImpl implements EdmAction {
+public class EdmActionImpl extends AbstractEdmOperation implements EdmAction {
public static EdmActionImpl getInstance(final Edm edm, final FullQualifiedName name, final Action action) {
- return EdmOperationImpl.getInstance(new EdmActionImpl(edm, name, action));
+ return AbstractEdmOperation.getInstance(new EdmActionImpl(edm, name, action));
}
private EdmActionImpl(final Edm edm, final FullQualifiedName name, final Action action) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java
index 5d9c68a..7d93e9a 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmActionImportImpl.java
@@ -24,7 +24,7 @@ import org.apache.olingo.commons.api.edm.EdmActionImport;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.provider.ActionImport;
-public class EdmActionImportImpl extends EdmOperationImportImpl implements EdmActionImport {
+public class EdmActionImportImpl extends AbstractEdmOperationImport implements EdmActionImport {
private final ActionImport actionImport;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
deleted file mode 100644
index e4b9d9b..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationHelperImpl.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.provider;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotatable;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
-import org.apache.olingo.commons.api.edm.EdmTerm;
-import org.apache.olingo.commons.api.edm.provider.Annotatable;
-import org.apache.olingo.commons.api.edm.provider.Annotation;
-
-public class EdmAnnotationHelperImpl implements EdmAnnotatable {
-
- private final Edm edm;
-
- private final Annotatable annotatable;
-
- private List<EdmAnnotation> annotations;
-
- public EdmAnnotationHelperImpl(final Edm edm, final Annotatable annotatable) {
- this.edm = edm;
- this.annotatable = annotatable;
- }
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- EdmAnnotation result = null;
- for (EdmAnnotation annotation : getAnnotations()) {
- if (term.getFullQualifiedName().equals(annotation.getTerm().getFullQualifiedName())) {
- result = annotation;
- }
- }
-
- return result;
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- if (annotations == null) {
- annotations = new ArrayList<EdmAnnotation>();
- for (Annotation annotation : annotatable.getAnnotations()) {
- annotations.add(new EdmAnnotationImpl(edm, annotation));
- }
- }
- return annotations;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
index 60eb0b4..07523e6 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmAnnotationImpl.java
@@ -60,18 +60,15 @@ import org.apache.olingo.commons.core.edm.annotation.EdmPropertyValueImpl;
import org.apache.olingo.commons.core.edm.annotation.EdmRecordImpl;
import org.apache.olingo.commons.core.edm.annotation.EdmUrlRefImpl;
-public class EdmAnnotationImpl implements EdmAnnotation {
+public class EdmAnnotationImpl extends AbstractEdmAnnotatable implements EdmAnnotation {
- private final Edm edm;
private final Annotation annotation;
- private final EdmAnnotationHelperImpl helper;
private EdmTerm term;
private EdmAnnotationExpression expression;
public EdmAnnotationImpl(final Edm edm, final Annotation annotation) {
- this.edm = edm;
+ super(edm, annotation);
this.annotation = annotation;
- this.helper = new EdmAnnotationHelperImpl(edm, annotation);
}
@Override
@@ -225,15 +222,4 @@ public class EdmAnnotationImpl implements EdmAnnotation {
}
return expression;
}
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
deleted file mode 100644
index b4b035f..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmBindingTargetImpl.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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.provider;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding;
-import org.apache.olingo.commons.api.edm.EdmTerm;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
-import org.apache.olingo.commons.api.edm.provider.BindingTarget;
-import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
-
-public abstract class EdmBindingTargetImpl extends EdmNamedImpl implements EdmBindingTarget {
-
- private final BindingTarget target;
- private final EdmAnnotationHelperImpl helper;
- private final EdmEntityContainer container;
-
- private List<EdmNavigationPropertyBinding> navigationPropertyBindings;
-
- public EdmBindingTargetImpl(final Edm edm, final EdmEntityContainer container, final BindingTarget target) {
- super(edm, target.getName());
- this.container = container;
- this.target = target;
- this.helper = new EdmAnnotationHelperImpl(edm, target);
- }
-
- @Override
- public List<EdmNavigationPropertyBinding> getNavigationPropertyBindings() {
- if (navigationPropertyBindings == null) {
- List<NavigationPropertyBinding> providerBindings = target.getNavigationPropertyBindings();
- navigationPropertyBindings = new ArrayList<EdmNavigationPropertyBinding>();
- if (providerBindings != null) {
- for (NavigationPropertyBinding binding : providerBindings) {
- navigationPropertyBindings.add(new EdmNavigationPropertyBindingImpl(binding.getPath(), binding.getTarget()));
- }
- }
- }
- return navigationPropertyBindings;
- }
-
- @Override
- public EdmEntityContainer getEntityContainer() {
- return container;
- }
-
- @Override
- public EdmEntityType getEntityType() {
- final EdmEntityType entityType = edm.getEntityType(target.getTypeFQN());
- if (entityType == null) {
- throw new EdmException("Can´t find entity type: " + target.getTypeFQN() + " for entity set or singleton: "
- + getName());
- }
- return entityType;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return container.getFullQualifiedName();
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return getName();
- }
-
- @Override
- public EdmBindingTarget getRelatedBindingTarget(final String path) {
- if (path == null) {
- return null;
- }
- EdmBindingTarget bindingTarget = null;
- boolean found = false;
- for (final Iterator<EdmNavigationPropertyBinding> itor = getNavigationPropertyBindings().iterator(); itor.hasNext()
- && !found;) {
-
- final EdmNavigationPropertyBinding binding = itor.next();
- if (path.startsWith(binding.getPath())) {
- final Target edmTarget = new Target.Builder(binding.getTarget(), container).build();
-
- final EdmEntityContainer entityContainer = edm.getEntityContainer(edmTarget.getEntityContainer());
- if (entityContainer == null) {
- throw new EdmException("Cannot find entity container with name: " + edmTarget.getEntityContainer());
- }
- try {
- bindingTarget = entityContainer.getEntitySet(edmTarget.getTargetName());
-
- if (bindingTarget == null) {
- throw new EdmException("Cannot find EntitySet " + edmTarget.getTargetName());
- }
- } catch (EdmException e) {
- // try with singletons ...
- bindingTarget = entityContainer.getSingleton(edmTarget.getTargetName());
-
- if (bindingTarget == null) {
- throw new EdmException("Cannot find Singleton " + edmTarget.getTargetName());
- }
- } finally {
- found = bindingTarget != null;
- }
- }
- }
-
- return bindingTarget;
- }
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
index 16ba237..4949d24 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
@@ -18,21 +18,15 @@
*/
package org.apache.olingo.commons.core.edm.provider;
-import java.util.List;
-
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.ComplexType;
-public class EdmComplexTypeImpl extends EdmStructuredTypeImpl implements EdmComplexType {
-
- private EdmAnnotationHelperImpl annotationHelper;
+public class EdmComplexTypeImpl extends AbstractEdmStructuredType implements EdmComplexType {
public static EdmComplexTypeImpl getInstance(
final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
@@ -41,20 +35,9 @@ public class EdmComplexTypeImpl extends EdmStructuredTypeImpl implements EdmComp
private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
super(edm, name, EdmTypeKind.COMPLEX, complexType);
- this.annotationHelper = new EdmAnnotationHelperImpl(edm, complexType);
}
@Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return annotationHelper == null ? null : annotationHelper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return annotationHelper == null ? null : annotationHelper.getAnnotations();
- }
-
- @Override
protected EdmStructuredType buildBaseType(final FullQualifiedName baseTypeName) {
EdmComplexType baseType = null;
if (baseTypeName != null) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmElementImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmElementImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmElementImpl.java
deleted file mode 100644
index 686e45d..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmElementImpl.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.provider;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmElement;
-
-public abstract class EdmElementImpl extends EdmNamedImpl implements EdmElement {
-
- public EdmElementImpl(final Edm edm, final String name) {
- super(edm, name);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
index 5d3eef3..bcca96a 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityContainerImpl.java
@@ -19,7 +19,6 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -27,13 +26,11 @@ import java.util.Map;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmActionImport;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
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.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.ActionImport;
import org.apache.olingo.commons.api.edm.provider.EdmProvider;
@@ -43,11 +40,10 @@ import org.apache.olingo.commons.api.edm.provider.EntitySet;
import org.apache.olingo.commons.api.edm.provider.FunctionImport;
import org.apache.olingo.commons.api.edm.provider.Singleton;
-public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityContainer {
+public class EdmEntityContainerImpl extends AbstractEdmNamed implements EdmEntityContainer {
private final EdmProvider provider;
private EntityContainer container;
- private EdmAnnotationHelperImpl helper;
protected final FullQualifiedName entityContainerName;
private final FullQualifiedName parentContainerName;
@@ -66,7 +62,7 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider,
final EntityContainerInfo entityContainerInfo) {
- super(edm, entityContainerInfo.getContainerName().getName());
+ super(edm, entityContainerInfo.getContainerName().getName(), null);
this.provider = provider;
this.entityContainerName = entityContainerInfo.getContainerName();
this.parentContainerName = entityContainerInfo.getExtendsContainer();
@@ -74,12 +70,11 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
public EdmEntityContainerImpl(final Edm edm, final EdmProvider provider, final FullQualifiedName containerFQN,
final EntityContainer entityContainer) {
- super(edm, containerFQN.getName());
+ super(edm, containerFQN.getName(), entityContainer);
this.provider = provider;
container = entityContainer;
this.entityContainerName = containerFQN;
this.parentContainerName = entityContainer.getExtendsContainerFQN();
- this.helper = new EdmAnnotationHelperImpl(edm, entityContainer);
}
@Override
@@ -326,14 +321,4 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
public TargetType getAnnotationsTargetType() {
return TargetType.EntityContainer;
}
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper == null ? null : helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper == null ? Collections.<EdmAnnotation> emptyList() : helper.getAnnotations();
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntitySetImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntitySetImpl.java
index d69f6fe..867b82c 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntitySetImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntitySetImpl.java
@@ -23,7 +23,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.provider.EntitySet;
-public class EdmEntitySetImpl extends EdmBindingTargetImpl implements EdmEntitySet {
+public class EdmEntitySetImpl extends AbstractEdmBindingTarget implements EdmEntitySet {
private EntitySet entitySet;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
index 84445aa..cdb51f5 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
@@ -24,22 +24,19 @@ import java.util.List;
import java.util.Map;
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
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.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.EntityType;
import org.apache.olingo.commons.api.edm.provider.PropertyRef;
-public class EdmEntityTypeImpl extends EdmStructuredTypeImpl implements EdmEntityType {
+public class EdmEntityTypeImpl extends AbstractEdmStructuredType implements EdmEntityType {
private EntityType entityType;
private boolean baseTypeChecked = false;
- private EdmAnnotationHelperImpl annotationHelper;
private final boolean hasStream;
protected EdmEntityType entityBaseType;
private final List<String> keyPredicateNames = new ArrayList<String>();
@@ -56,7 +53,6 @@ public class EdmEntityTypeImpl extends EdmStructuredTypeImpl implements EdmEntit
super(edm, name, EdmTypeKind.ENTITY, entityType);
this.entityType = entityType;
hasStream = entityType.hasStream();
- this.annotationHelper = new EdmAnnotationHelperImpl(edm, entityType);
}
@Override
@@ -151,14 +147,4 @@ public class EdmEntityTypeImpl extends EdmStructuredTypeImpl implements EdmEntit
public TargetType getAnnotationsTargetType() {
return TargetType.EntityType;
}
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return annotationHelper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return annotationHelper.getAnnotations();
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
index df09c3c..af56e38 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEnumTypeImpl.java
@@ -42,13 +42,13 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
private static final Set<EdmPrimitiveTypeKind> VALID_UNDERLYING_TYPES = new HashSet<EdmPrimitiveTypeKind>();
- {
+ static {
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Byte);
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.SByte);
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Int16);
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Int32);
VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Int64);
- };
+ }
private final EdmPrimitiveType underlyingType;
private final EnumType enumType;
@@ -58,7 +58,7 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
private LinkedHashMap<String, EdmMember> membersMap;
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final EnumType enumType) {
- super(edm, enumName, EdmTypeKind.ENUM);
+ super(edm, enumName, EdmTypeKind.ENUM, enumType);
if (enumType.getUnderlyingType() == null) {
underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java
index 4a29d83..0279a78 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImpl.java
@@ -26,12 +26,12 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.Function;
-public class EdmFunctionImpl extends EdmOperationImpl implements EdmFunction {
+public class EdmFunctionImpl extends AbstractEdmOperation implements EdmFunction {
private final Function function;
public static EdmFunctionImpl getInstance(final Edm edm, final FullQualifiedName name, final Function function) {
- return EdmOperationImpl.getInstance(new EdmFunctionImpl(edm, name, function));
+ return AbstractEdmOperation.getInstance(new EdmFunctionImpl(edm, name, function));
}
private EdmFunctionImpl(final Edm edm, final FullQualifiedName name, final Function function) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImportImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImportImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImportImpl.java
index ead3116..b2e2397 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImportImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmFunctionImportImpl.java
@@ -27,7 +27,7 @@ import org.apache.olingo.commons.api.edm.EdmFunctionImport;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.FunctionImport;
-public class EdmFunctionImportImpl extends EdmOperationImportImpl implements EdmFunctionImport {
+public class EdmFunctionImportImpl extends AbstractEdmOperationImport implements EdmFunctionImport {
private final FunctionImport functionImport;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
index a7d1366..b3a6f1e 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmMemberImpl.java
@@ -18,26 +18,20 @@
*/
package org.apache.olingo.commons.core.edm.provider;
-import java.util.List;
-
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmMember;
-import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.EnumMember;
-public class EdmMemberImpl extends EdmNamedImpl implements EdmMember {
+public class EdmMemberImpl extends AbstractEdmNamed implements EdmMember {
- private final EdmAnnotationHelperImpl helper;
private final FullQualifiedName enumFQN;
private final EnumMember member;
public EdmMemberImpl(final Edm edm, final FullQualifiedName enumFQN, final EnumMember member) {
- super(edm, member.getName());
+ super(edm, member.getName(), member);
this.enumFQN = enumFQN;
this.member = member;
- this.helper = new EdmAnnotationHelperImpl(edm, member);
}
@Override
@@ -59,15 +53,4 @@ public class EdmMemberImpl extends EdmNamedImpl implements EdmMember {
public String getValue() {
return member.getValue();
}
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNamedImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNamedImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNamedImpl.java
deleted file mode 100644
index 93e7583..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNamedImpl.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.provider;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmNamed;
-
-public abstract class EdmNamedImpl implements EdmNamed {
-
- protected final Edm edm;
-
- private final String name;
-
- public EdmNamedImpl(final Edm edm, final String name) {
- this.edm = edm;
- this.name = name;
- }
-
- @Override
- public String getName() {
- return name;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
index e72a98e..db75e0c 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
@@ -22,32 +22,29 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmElement;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.commons.api.edm.EdmReferentialConstraint;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.NavigationProperty;
import org.apache.olingo.commons.api.edm.provider.ReferentialConstraint;
-public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavigationProperty {
+public class EdmNavigationPropertyImpl extends AbstractEdmNamed implements EdmElement, EdmNavigationProperty {
private final FullQualifiedName structuredTypeName;
private final NavigationProperty navigationProperty;
- private final EdmAnnotationHelperImpl helper;
private List<EdmReferentialConstraint> referentialConstraints;
private EdmEntityType typeImpl;
private EdmNavigationProperty partnerNavigationProperty;
public EdmNavigationPropertyImpl(
final Edm edm, final FullQualifiedName structuredTypeName, final NavigationProperty navigationProperty) {
- super(edm, navigationProperty.getName());
+ super(edm, navigationProperty.getName(), navigationProperty);
this.structuredTypeName = structuredTypeName;
this.navigationProperty = navigationProperty;
- this.helper = new EdmAnnotationHelperImpl(edm, navigationProperty);
}
@Override
@@ -139,14 +136,4 @@ public class EdmNavigationPropertyImpl extends EdmElementImpl implements EdmNavi
public FullQualifiedName getAnnotationsTargetFQN() {
return structuredTypeName;
}
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
deleted file mode 100644
index 217c732..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImpl.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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.provider;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmOperation;
-import org.apache.olingo.commons.api.edm.EdmParameter;
-import org.apache.olingo.commons.api.edm.EdmReturnType;
-import org.apache.olingo.commons.api.edm.EdmTerm;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.api.edm.provider.Operation;
-import org.apache.olingo.commons.api.edm.provider.Parameter;
-
-public abstract class EdmOperationImpl extends EdmTypeImpl implements EdmOperation {
-
- protected final Operation operation;
- protected final EdmAnnotationHelperImpl helper;
- private final Map<String, EdmParameter> parameters = new LinkedHashMap<String, EdmParameter>();
- private String entitySetPath;
- private boolean isBound;
- private EdmReturnType returnType;
- private List<String> parameterNames;
-
- protected static <T extends EdmOperationImpl> T getInstance(final T instance) {
- final List<Parameter> providerParameters = instance.operation.getParameters();
- if (providerParameters != null) {
- final List<EdmParameter> _parameters = new ArrayList<EdmParameter>(providerParameters.size());
- for (Parameter parameter : providerParameters) {
- _parameters.add(new EdmParameterImpl(instance.edm, parameter));
- }
- instance.setParameters(_parameters);
- }
-
- final String entitySetPath = instance.operation.getEntitySetPath();
- if (entitySetPath != null) {
- instance.setEntitySetPath(entitySetPath);
- }
-
- instance.setIsBound(instance.operation.isBound());
-
- if (instance.operation.getReturnType() != null) {
- instance.setReturnType(new EdmReturnTypeImpl(instance.edm, instance.operation.getReturnType()));
- }
-
- return instance;
- }
-
- protected EdmOperationImpl(final Edm edm, final FullQualifiedName name, final Operation operation,
- final EdmTypeKind kind) {
-
- super(edm, name, kind);
- this.operation = operation;
- this.helper = new EdmAnnotationHelperImpl(edm, operation);
- }
-
- protected void setParameters(final List<EdmParameter> _parameters) {
- for (EdmParameter parameter : _parameters) {
- parameters.put(parameter.getName(), parameter);
- }
- }
-
- protected void setEntitySetPath(final String entitySetPath) {
- this.entitySetPath = entitySetPath;
- }
-
- protected void setIsBound(final boolean isBound) {
- this.isBound = isBound;
- }
-
- protected void setReturnType(final EdmReturnType returnType) {
- this.returnType = returnType;
- }
-
- @Override
- public EdmParameter getParameter(final String name) {
- return parameters.get(name);
- }
-
- @Override
- public List<String> getParameterNames() {
- if (parameterNames == null) {
- parameterNames = new ArrayList<String>(parameters.size());
- for (String parameterName : parameters.keySet()) {
- parameterNames.add(parameterName);
- }
- }
- return parameterNames;
- }
-
- @Override
- public EdmEntitySet getReturnedEntitySet(final EdmEntitySet bindingParameterEntitySet) {
- EdmEntitySet returnedEntitySet = null;
- if (bindingParameterEntitySet != null && entitySetPath != null) {
- final EdmBindingTarget relatedBindingTarget = bindingParameterEntitySet.getRelatedBindingTarget(entitySetPath);
- if (relatedBindingTarget == null) {
- throw new EdmException("Cannot find entity set with path: " + entitySetPath);
- }
- if (relatedBindingTarget instanceof EdmEntitySet) {
- returnedEntitySet = (EdmEntitySet) relatedBindingTarget;
- } else {
- throw new EdmException("BindingTarget with name: " + relatedBindingTarget.getName()
- + " must be an entity set");
- }
- }
- return returnedEntitySet;
- }
-
- @Override
- public EdmReturnType getReturnType() {
- return returnType;
- }
-
- @Override
- public boolean isBound() {
- return isBound;
- }
-
- @Override
- public FullQualifiedName getBindingParameterTypeFqn() {
- if (isBound()) {
- Parameter bindingParameter = operation.getParameters().get(0);
- return bindingParameter.getTypeFQN();
- }
- return null;
- }
-
- @Override
- public Boolean isBindingParameterTypeCollection() {
- if (isBound()) {
- Parameter bindingParameter = operation.getParameters().get(0);
- return bindingParameter.isCollection();
- }
- return null;
- }
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
-
- @Override
- public String getEntitySetPath(){
- return operation.getEntitySetPath();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
deleted file mode 100644
index 3ace167..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmOperationImportImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.provider;
-
-import java.util.List;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmOperationImport;
-import org.apache.olingo.commons.api.edm.EdmTerm;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
-import org.apache.olingo.commons.api.edm.provider.OperationImport;
-
-public abstract class EdmOperationImportImpl extends EdmNamedImpl implements EdmOperationImport {
-
- protected final EdmEntityContainer container;
- private final Target entitySet;
- private EdmEntitySet returnedEntitySet;
- private final EdmAnnotationHelperImpl helper;
-
- public EdmOperationImportImpl(final Edm edm, final EdmEntityContainer container,
- final OperationImport operationImport) {
- super(edm, operationImport.getName());
- this.container = container;
- this.helper = new EdmAnnotationHelperImpl(edm, operationImport);
- this.entitySet = new Target.Builder(operationImport.getEntitySet(), container).build();
- }
-
- @Override
- public FullQualifiedName getFullQualifiedName() {
- return new FullQualifiedName(container.getNamespace(), getName());
- }
-
- @Override
- public EdmEntitySet getReturnedEntitySet() {
- if (entitySet != null && returnedEntitySet == null) {
- EdmEntityContainer entityContainer = edm.getEntityContainer(entitySet.getEntityContainer());
- if (entityContainer == null) {
- throw new EdmException("Can´t find entity container with name: " + entitySet.getEntityContainer());
- }
- returnedEntitySet = entityContainer.getEntitySet(entitySet.getTargetName());
- if (returnedEntitySet == null) {
- throw new EdmException("Can´t find entity set with name: " + entitySet.getTargetName());
- }
- }
- return returnedEntitySet;
- }
-
- @Override
- public EdmEntityContainer getEntityContainer() {
- return container;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return container.getFullQualifiedName();
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return getName();
- }
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
index 157a779..0973185 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmParameterImpl.java
@@ -18,29 +18,24 @@
*/
package org.apache.olingo.commons.core.edm.provider;
-import java.util.List;
-
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmElement;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmMapping;
import org.apache.olingo.commons.api.edm.EdmParameter;
-import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.Parameter;
-public class EdmParameterImpl extends EdmElementImpl implements EdmParameter {
+public class EdmParameterImpl extends AbstractEdmNamed implements EdmParameter, EdmElement {
private final Parameter parameter;
- private final EdmAnnotationHelperImpl helper;
private final EdmTypeInfo typeInfo;
private EdmType typeImpl;
public EdmParameterImpl(final Edm edm, final Parameter parameter) {
- super(edm, parameter.getName());
+ super(edm, parameter.getName(), parameter);
this.parameter = parameter;
- this.helper = new EdmAnnotationHelperImpl(edm, parameter);
this.typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(parameter.getType()).build();
}
@@ -80,16 +75,6 @@ public class EdmParameterImpl extends EdmElementImpl implements EdmParameter {
}
@Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
-
- @Override
public EdmType getType() {
if (typeImpl == null) {
typeImpl = typeInfo.getType();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
index 973640e..14c3faf 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmPropertyImpl.java
@@ -18,34 +18,29 @@
*/
package org.apache.olingo.commons.core.edm.provider;
-import java.util.List;
-
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
+import org.apache.olingo.commons.api.edm.EdmElement;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmMapping;
import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.Property;
-public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty {
+public class EdmPropertyImpl extends AbstractEdmNamed implements EdmProperty, EdmElement {
private final FullQualifiedName structuredTypeName;
private final Property property;
private final EdmTypeInfo typeInfo;
- private EdmAnnotationHelperImpl helper;
private EdmType propertyType;
public EdmPropertyImpl(final Edm edm, final FullQualifiedName structuredTypeName, final Property property) {
- super(edm, property.getName());
+ super(edm, property.getName(), property);
this.structuredTypeName = structuredTypeName;
this.property = property;
typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(property.getType().toString()).build();
- this.helper = new EdmAnnotationHelperImpl(edm, property);
}
@Override
@@ -126,16 +121,6 @@ public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty {
}
@Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
-
- @Override
public boolean isPrimitive() {
return typeInfo.isPrimitiveType();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
index 4a8d7d8..ac38d20 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmReferentialConstraintImpl.java
@@ -18,22 +18,17 @@
*/
package org.apache.olingo.commons.core.edm.provider;
-import java.util.List;
-
import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmReferentialConstraint;
-import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.provider.ReferentialConstraint;
-public class EdmReferentialConstraintImpl implements EdmReferentialConstraint {
+public class EdmReferentialConstraintImpl extends AbstractEdmAnnotatable implements EdmReferentialConstraint {
- private final EdmAnnotationHelperImpl helper;
private final ReferentialConstraint constraint;
public EdmReferentialConstraintImpl(final Edm edm, final ReferentialConstraint constraint) {
+ super(edm, constraint);
this.constraint = constraint;
- this.helper = new EdmAnnotationHelperImpl(edm, constraint);
}
@Override
@@ -45,14 +40,4 @@ public class EdmReferentialConstraintImpl implements EdmReferentialConstraint {
public String getReferencedPropertyName() {
return constraint.getReferencedProperty();
}
-
- @Override
- public EdmAnnotation getAnnotation(final EdmTerm term) {
- return helper.getAnnotation(term);
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- return helper.getAnnotations();
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/16b94eb4/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSingletonImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSingletonImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSingletonImpl.java
index ca953dc..764a6c6 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSingletonImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmSingletonImpl.java
@@ -23,7 +23,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmSingleton;
import org.apache.olingo.commons.api.edm.provider.Singleton;
-public class EdmSingletonImpl extends EdmBindingTargetImpl implements EdmSingleton {
+public class EdmSingletonImpl extends AbstractEdmBindingTarget implements EdmSingleton {
public EdmSingletonImpl(final Edm edm, final EdmEntityContainer container, final Singleton singleton) {
super(edm, container, singleton);
[48/50] [abbrv] olingo-odata4 git commit: [OLINGO-545] Fix: Bind
operations are applyed before creating deep insert entities
Posted by ch...@apache.org.
[OLINGO-545] Fix: Bind operations are applyed before creating deep insert entities
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/189de7b2
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/189de7b2
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/189de7b2
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 189de7b2d70f84260d76ed323e22d85bf9cd6d57
Parents: 502f7ce
Author: Christian Holzer <c....@sap.com>
Authored: Thu Apr 2 15:04:00 2015 +0200
Committer: Christian Holzer <ch...@t-online.de>
Committed: Fri Apr 3 12:42:00 2015 +0200
----------------------------------------------------------------------
.../olingo/fit/tecsvc/client/BindingITCase.java | 47 ++++++++++++++++++++
.../olingo/server/tecsvc/data/DataProvider.java | 15 ++++---
2 files changed, 56 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/189de7b2/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
index d0435b2..75cadd0 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BindingITCase.java
@@ -25,6 +25,7 @@ import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
+import org.apache.olingo.client.api.EdmEnabledODataClient;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.request.cud.UpdateType;
@@ -34,6 +35,7 @@ import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResp
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.core.ODataClientFactory;
import org.apache.olingo.commons.api.domain.ODataEntity;
+import org.apache.olingo.commons.api.domain.ODataInlineEntity;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.ODataObjectFactory;
import org.apache.olingo.commons.api.domain.ODataProperty;
@@ -310,6 +312,51 @@ public class BindingITCase extends AbstractBaseTestITCase {
}
}
+ @Test
+ public void testDeepInsertWithBindingSameNavigationProperty() {
+ final EdmEnabledODataClient client = ODataClientFactory.getEdmEnabledClient(SERVICE_URI);
+ client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
+ final ODataObjectFactory of = client.getObjectFactory();
+
+ final ODataEntity entity = of.newEntity(ET_KEY_NAV);
+ entity.getProperties().add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder()
+ .buildString("1")));
+ entity.getProperties().add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short)1)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("1")))));
+
+ final ODataEntity innerEntity = of.newEntity(ET_KEY_NAV);
+ innerEntity.getProperties().add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder()
+ .buildString("2")));
+ innerEntity.getProperties().add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
+ .add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 1)))
+ .add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("2")))));
+
+ final ODataInlineEntity inlineLink = of.newDeepInsertEntity(NAV_PROPERTY_ET_KEY_NAV_ONE, innerEntity);
+ entity.addLink(inlineLink);
+
+ final URI bindingURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
+ .appendKeySegment(3)
+ .build();
+
+ entity.addLink(of.newEntityNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE, bindingURI));
+
+ final URI targetURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
+ final ODataEntityCreateResponse<ODataEntity> response =
+ client.getCUDRequestFactory().getEntityCreateRequest(targetURI, entity).execute();
+
+ assertEquals(HttpStatusCode.CREATED.getStatusCode(), response.getStatusCode());
+
+ assertEquals(1, response.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE)
+ .asInlineEntity()
+ .getEntity()
+ .getProperty(PROPERTY_COMP_TWO_PRIM)
+ .getComplexValue()
+ .get(PROPERTY_INT16)
+ .getPrimitiveValue()
+ .toValue());
+ }
+
@Override
protected ODataClient getClient() {
ODataClient odata = ODataClientFactory.getClient();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/189de7b2/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
index e4bb0a2..96f0cd7 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
@@ -243,18 +243,21 @@ public class DataProvider {
patch);
}
}
-
+
+ // For insert operations collection navigation property bind operations and deep insert operations can be combined.
+ // In this case, the bind operations MUST appear before the deep insert operations in the payload.
+ // => Apply bindings first
+ final boolean navigationBindingsAvailable = !changedEntity.getNavigationBindings().isEmpty();
+ if (navigationBindingsAvailable) {
+ applyNavigationBinding(rawBaseUri, edmEntitySet, entity, changedEntity.getNavigationBindings());
+ }
+
// Deep insert (only if not an update)
if (isInsert) {
handleDeepInsert(rawBaseUri, edmEntitySet, entity, changedEntity);
} else {
handleDeleteSingleNavigationProperties(edmEntitySet, entity, changedEntity);
}
-
- final boolean navigationBindingsAvailable = !changedEntity.getNavigationBindings().isEmpty();
- if (navigationBindingsAvailable) {
- applyNavigationBinding(rawBaseUri, edmEntitySet, entity, changedEntity.getNavigationBindings());
- }
}
private void handleDeleteSingleNavigationProperties(EdmEntitySet edmEntitySet, Entity entity, Entity changedEntity)
[30/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin as example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java
new file mode 100644
index 0000000..a306551
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java
@@ -0,0 +1,119 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+
+public abstract class ServiceResponse {
+ protected ServiceMetadata metadata;
+ protected ODataResponse response;
+ protected Map<String, String> preferences;
+ private boolean closed;
+ private boolean strictApplyPreferences = true;
+
+ public ServiceResponse(ServiceMetadata metadata, ODataResponse response,
+ Map<String, String> preferences) {
+ this.metadata = metadata;
+ this.response = response;
+ this.preferences = preferences;
+ }
+
+ public ODataResponse getODataResponse() {
+ return this.response;
+ }
+
+ protected boolean isClosed() {
+ return this.closed;
+ }
+
+ protected void close() {
+ if (!this.closed) {
+ if (this.strictApplyPreferences) {
+ if (!preferences.isEmpty()) {
+ assert(this.response.getHeaders().get("Preference-Applied") != null);
+ }
+ }
+ this.closed = true;
+ }
+ }
+
+ public void writeNoContent(boolean closeResponse) {
+ this.response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+
+ public void writeNotFound(boolean closeResponse) {
+ response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+
+ public void writeServerError(boolean closeResponse) {
+ response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+
+ public void writeBadRequest(boolean closeResponse) {
+ response.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+
+ public void writeOK(String contentType) {
+ this.response.setStatusCode(HttpStatusCode.OK.getStatusCode());
+ this.response.setHeader(HttpHeader.CONTENT_TYPE, contentType);
+ }
+
+ public void writeHeader(String key, String value) {
+ if ("Preference-Applied".equals(key)) {
+ String previous = this.response.getHeaders().get(key);
+ if (previous != null) {
+ value = previous+";"+value;
+ }
+ this.response.setHeader(key, value);
+ } else {
+ this.response.setHeader(key, value);
+ }
+ }
+
+ /**
+ * When true; the "Preference-Applied" header is strictly checked.
+ * @param flag
+ */
+ public void setStrictlyApplyPreferences(boolean flag) {
+ this.strictApplyPreferences = flag;
+ }
+
+ public abstract void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException;
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponseVisior.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponseVisior.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponseVisior.java
new file mode 100644
index 0000000..4f11cb8
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponseVisior.java
@@ -0,0 +1,71 @@
+/*
+ * 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.responses;
+
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataTranslatedException;
+
+@SuppressWarnings("unused")
+public class ServiceResponseVisior {
+
+ public void visit(CountResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(MetadataResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(NoContentResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(PrimitiveValueResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(ServiceDocumentResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(StreamResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/StreamResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/StreamResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/StreamResponse.java
new file mode 100644
index 0000000..ec7db03
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/StreamResponse.java
@@ -0,0 +1,54 @@
+/*
+ * 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.responses;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Collections;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+
+public class StreamResponse extends ServiceResponse {
+
+ public StreamResponse(ServiceMetadata metadata, ODataResponse response) {
+ super(metadata, response, Collections.EMPTY_MAP);
+ }
+
+ public void writeStreamResponse(InputStream streamContent, ContentType contentType) {
+ this.response.setContent(streamContent);
+ writeOK(contentType.toContentTypeString());
+ close();
+ }
+
+ public void writeBinaryResponse(byte[] streamContent, ContentType contentType) {
+ this.response.setContent(new ByteArrayInputStream(streamContent));
+ writeOK(contentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/MetadataParserTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/MetadataParserTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/MetadataParserTest.java
new file mode 100644
index 0000000..9749a6c
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/MetadataParserTest.java
@@ -0,0 +1,185 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileReader;
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.Action;
+import org.apache.olingo.commons.api.edm.provider.ActionImport;
+import org.apache.olingo.commons.api.edm.provider.ComplexType;
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.commons.api.edm.provider.EntitySet;
+import org.apache.olingo.commons.api.edm.provider.EntityType;
+import org.apache.olingo.commons.api.edm.provider.EnumType;
+import org.apache.olingo.commons.api.edm.provider.Function;
+import org.apache.olingo.commons.api.edm.provider.FunctionImport;
+import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
+import org.apache.olingo.commons.api.edm.provider.Parameter;
+import org.apache.olingo.commons.api.edm.provider.Property;
+import org.apache.olingo.commons.api.edm.provider.Singleton;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MetadataParserTest {
+ final String NS = "Microsoft.OData.SampleService.Models.TripPin";
+ final FullQualifiedName NSF = new FullQualifiedName(NS);
+
+ EdmProvider provider = null;
+
+ @Before
+ public void setUp() throws Exception {
+ MetadataParser parser = new MetadataParser();
+ provider = parser.buildEdmProvider(new FileReader("src/test/resources/trippin.xml"));
+ }
+
+ @Test
+ public void testAction() throws ODataException {
+ // test action
+ List<Action> actions = provider.getActions(new FullQualifiedName(NS, "ResetDataSource"));
+ assertNotNull(actions);
+ assertEquals(1, actions.size());
+ }
+
+ @Test
+ public void testFunction() throws ODataException {
+ // test function
+ List<Function> functions = provider
+ .getFunctions(new FullQualifiedName(NS, "GetFavoriteAirline"));
+ assertNotNull(functions);
+ assertEquals(1, functions.size());
+ assertEquals("GetFavoriteAirline", functions.get(0).getName());
+ assertTrue(functions.get(0).isBound());
+ assertTrue(functions.get(0).isComposable());
+ assertEquals(
+ "person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline",
+ functions.get(0).getEntitySetPath());
+
+ List<Parameter> parameters = functions.get(0).getParameters();
+ assertNotNull(parameters);
+ assertEquals(1, parameters.size());
+ assertEquals("person", parameters.get(0).getName());
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Person",parameters.get(0).getType());
+ assertFalse(parameters.get(0).isNullable());
+
+ assertNotNull(functions.get(0).getReturnType());
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Airline",
+ functions.get(0).getReturnType().getType());
+ assertFalse(functions.get(0).getReturnType().isNullable());
+ }
+
+ @Test
+ public void testEnumType() throws ODataException {
+ // test enum type
+ EnumType enumType = provider.getEnumType(new FullQualifiedName(NS, "PersonGender"));
+ assertNotNull(enumType);
+ assertEquals("Male", enumType.getMembers().get(0).getName());
+ assertEquals("Female", enumType.getMembers().get(1).getName());
+ assertEquals("Unknown", enumType.getMembers().get(2).getName());
+ assertEquals("0", enumType.getMembers().get(0).getValue());
+ assertEquals("1", enumType.getMembers().get(1).getValue());
+ assertEquals("2", enumType.getMembers().get(2).getValue());
+ }
+
+ @Test
+ public void testEntityType() throws ODataException {
+ // test Entity Type
+ EntityType et = provider.getEntityType(new FullQualifiedName(NS, "Photo"));
+ assertNotNull(et);
+ assertNotNull(et.getKey());
+ assertEquals("Id", et.getKey().get(0).getName());
+ assertTrue(et.hasStream());
+ assertEquals("Id", et.getProperties().get(0).getName());
+ assertEquals("Edm.Int64", et.getProperties().get(0).getType());
+ assertEquals("Name", et.getProperties().get(1).getName());
+ assertEquals("Edm.String", et.getProperties().get(1).getType());
+ }
+
+ @Test
+ public void testComplexType() throws ODataException {
+ // Test Complex Type
+ ComplexType ct = provider.getComplexType(new FullQualifiedName(NS, "City"));
+ assertNotNull(ct);
+ assertEquals(3, ct.getProperties().size());
+ Property p = ct.getProperties().get(0);
+ assertEquals("CountryRegion", p.getName());
+ assertEquals("Edm.String", p.getType());
+ assertEquals(false, p.isNullable());
+
+ ct = provider.getComplexType(new FullQualifiedName(NS, "Location"));
+ assertNotNull(ct);
+
+ ct = provider.getComplexType(new FullQualifiedName(NS, "EventLocation"));
+ assertNotNull(ct);
+ }
+
+ @Test
+ public void testEntitySet() throws Exception {
+ EntitySet es = provider.getEntitySet(NSF, "People");
+ assertNotNull(es);
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Person",es.getType());
+
+ List<NavigationPropertyBinding> bindings = es.getNavigationPropertyBindings();
+ assertNotNull(bindings);
+ assertEquals(6, bindings.size());
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Flight/From", bindings.get(2)
+ .getPath());
+ assertEquals("Airports", bindings.get(2).getTarget());
+ }
+
+ @Test
+ public void testFunctionImport() throws Exception {
+ FunctionImport fi = provider.getFunctionImport(NSF, "GetNearestAirport");
+ assertNotNull(fi);
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport", fi.getFunction());
+ assertEquals("Airports", fi.getEntitySet());
+ assertTrue(fi.isIncludeInServiceDocument());
+ }
+
+ @Test
+ public void testActionImport() throws Exception {
+ ActionImport ai = provider.getActionImport(NSF, "ResetDataSource");
+ assertNotNull(ai);
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.ResetDataSource", ai.getAction());
+ assertNull(ai.getEntitySet());
+ }
+
+ @Test
+ public void testSingleton() throws Exception {
+ Singleton single = this.provider.getSingleton(NSF, "Me");
+ assertNotNull(single);
+
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Person",single.getType());
+
+ List<NavigationPropertyBinding> bindings = single.getNavigationPropertyBindings();
+ assertNotNull(bindings);
+ assertEquals(6, bindings.size());
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Flight/From", bindings.get(2).getPath());
+ assertEquals("Airports", bindings.get(2).getTarget());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
new file mode 100644
index 0000000..16caa1a
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
@@ -0,0 +1,417 @@
+/*
+ * 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.assertEquals;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataHttpHandler;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.responses.CountResponse;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.StreamResponse;
+import org.apache.olingo.server.example.TripPinServiceTest;
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+public class ServiceDispatcherTest {
+ private Server server;
+
+ public class SampleODataServlet extends HttpServlet {
+ private final ServiceHandler handler; // must be stateless
+ private final EdmProvider provider; // must be stateless
+
+ public SampleODataServlet(ServiceHandler handler, EdmProvider provider) {
+ this.handler = handler;
+ this.provider = provider;
+ }
+
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+ OData odata = OData4Impl.newInstance();
+ ServiceMetadata metadata = odata.createServiceMetadata(this.provider, Collections.EMPTY_LIST);
+
+ ODataHttpHandler handler = odata.createHandler(metadata);
+
+ handler.register(this.handler);
+ handler.process(request, response);
+ }
+ }
+
+ public int beforeTest(ServiceHandler serviceHandler) throws Exception {
+ MetadataParser parser = new MetadataParser();
+ EdmProvider edmProvider = parser.buildEdmProvider(new FileReader(
+ "src/test/resources/trippin.xml"));
+
+ this.server = new Server();
+
+ ServerConnector connector = new ServerConnector(this.server);
+ this.server.setConnectors(new Connector[] { connector });
+
+ ServletContextHandler context = new ServletContextHandler();
+ context.setContextPath("/trippin");
+ context
+ .addServlet(new ServletHolder(new SampleODataServlet(serviceHandler, edmProvider)), "/*");
+ this.server.setHandler(context);
+ this.server.start();
+
+ return connector.getLocalPort();
+ }
+
+ public void afterTest() throws Exception {
+ this.server.stop();
+ }
+
+ interface TestResult {
+ void validate() throws Exception;
+ }
+
+ private void helpGETTest(ServiceHandler handler, String path, TestResult validator)
+ throws Exception {
+ int port = beforeTest(handler);
+ HttpClient http = new HttpClient();
+ http.start();
+ http.GET("http://localhost:" + port + "/" + path);
+ validator.validate();
+ afterTest();
+ }
+
+ private void helpTest(ServiceHandler handler, String path, String method, String payload,
+ TestResult validator) throws Exception {
+ int port = beforeTest(handler);
+ HttpClient http = new HttpClient();
+ http.start();
+ String editUrl = "http://localhost:" + port + "/" + path;
+ http.newRequest(editUrl).method(method)
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .content(TripPinServiceTest.content(payload)).send();
+ validator.validate();
+ afterTest();
+ }
+
+ @Test
+ public void testMetadata() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/$metadata", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<MetadataRequest> arg1 = ArgumentCaptor.forClass(MetadataRequest.class);
+ ArgumentCaptor<MetadataResponse> arg2 = ArgumentCaptor.forClass(MetadataResponse.class);
+ Mockito.verify(handler).readMetadata(arg1.capture(), arg2.capture());
+ }
+ });
+ }
+
+ @Test
+ public void testEntitySet() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<EntityResponse> arg2 = ArgumentCaptor.forClass(EntityResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ // Need toString on ContextURL class
+ // assertEquals("",
+ // request.getContextURL(request.getOdata()).toString());
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testEntitySetCount() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports/$count", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<CountResponse> arg2 = ArgumentCaptor.forClass(CountResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ // Need toString on ContextURL class
+ // assertEquals("",
+ // request.getContextURL(request.getOdata()).toString());
+ assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testEntity() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<EntityResponse> arg2 = ArgumentCaptor.forClass(EntityResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadProperty() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')/IataCode", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<PropertyResponse> arg2 = ArgumentCaptor.forClass(PropertyResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(true, request.isPropertyRequest());
+ assertEquals(false, request.isPropertyComplex());
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadComplexProperty() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')/Location", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<PropertyResponse> arg2 = ArgumentCaptor.forClass(PropertyResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(true, request.isPropertyRequest());
+ assertEquals(true, request.isPropertyComplex());
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadProperty$Value() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')/IataCode/$value", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<PrimitiveValueResponse> arg2 = ArgumentCaptor
+ .forClass(PrimitiveValueResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(true, request.isPropertyRequest());
+ assertEquals(false, request.isPropertyComplex());
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadPropertyRef() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')/IataCode/$value", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<PrimitiveValueResponse> arg2 = ArgumentCaptor
+ .forClass(PrimitiveValueResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(true, request.isPropertyRequest());
+ assertEquals(false, request.isPropertyComplex());
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testFunctionImport() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/GetNearestAirport(lat=12.11,lon=34.23)", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<FunctionRequest> arg1 = ArgumentCaptor.forClass(FunctionRequest.class);
+ ArgumentCaptor<PropertyResponse> arg3 = ArgumentCaptor.forClass(PropertyResponse.class);
+ ArgumentCaptor<HttpMethod> arg2 = ArgumentCaptor.forClass(HttpMethod.class);
+ Mockito.verify(handler).invoke(arg1.capture(), arg2.capture(), arg3.capture());
+
+ FunctionRequest request = arg1.getValue();
+ }
+ });
+ }
+
+ @Test
+ public void testActionImport() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpTest(handler, "trippin/ResetDataSource", "POST", "", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<ActionRequest> arg1 = ArgumentCaptor.forClass(ActionRequest.class);
+ ArgumentCaptor<NoContentResponse> arg2 = ArgumentCaptor.forClass(NoContentResponse.class);
+ Mockito.verify(handler).invoke(arg1.capture(), Mockito.anyString(), arg2.capture());
+
+ ActionRequest request = arg1.getValue();
+ }
+ });
+ }
+
+ @Test
+ public void testReadMedia() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Photos(1)/$value", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<MediaRequest> arg1 = ArgumentCaptor.forClass(MediaRequest.class);
+ ArgumentCaptor<StreamResponse> arg2 = ArgumentCaptor.forClass(StreamResponse.class);
+ Mockito.verify(handler).readMediaStream(arg1.capture(), arg2.capture());
+
+ MediaRequest request = arg1.getValue();
+ assertEquals("application/octet-stream", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadNavigation() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/People('russelwhyte')/Friends", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<EntitySetResponse> arg2 = ArgumentCaptor.forClass(EntitySetResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadReference() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/People('russelwhyte')/Friends/$ref", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<EntitySetResponse> arg2 = ArgumentCaptor.forClass(EntitySetResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testWriteReferenceCollection() throws Exception {
+ String payload = "{\n" + "\"@odata.id\": \"/Photos(11)\"\n" + "}";
+
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpTest(handler, "trippin/People('russelwhyte')/Friends/$ref", "POST", payload,
+ new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<List> arg3 = ArgumentCaptor.forClass(List.class);
+ ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
+ .forClass(NoContentResponse.class);
+ Mockito.verify(handler).addReference(arg1.capture(), arg2.capture(), arg3.capture(),
+ arg4.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals("application/json;odata.metadata=minimal", request
+ .getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testWriteReference() throws Exception {
+ String payload = "{\n" + "\"@odata.id\": \"/Photos(11)\"\n" + "}";
+
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpTest(handler, "trippin/People('russelwhyte')/Friends('someone')/Photo/$ref", "PUT", payload,
+ new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<URI> arg3 = ArgumentCaptor.forClass(URI.class);
+ ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
+ .forClass(NoContentResponse.class);
+ Mockito.verify(handler).updateReference(arg1.capture(), arg2.capture(), arg3.capture(),
+ arg4.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals("application/json;odata.metadata=minimal", request
+ .getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
new file mode 100644
index 0000000..904f4d8
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
@@ -0,0 +1,843 @@
+/*
+ * 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.example;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Property;
+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.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.core.data.EntityImpl;
+import org.apache.olingo.commons.core.data.EntitySetImpl;
+import org.apache.olingo.commons.core.data.LinkImpl;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.core.deserializer.json.ODataJsonDeserializer;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class TripPinDataModel {
+ private final ServiceMetadata metadata;
+ private HashMap<String, EntitySet> entitySetMap;
+ private Map<Integer, Map> tripLinks;
+ private Map<String, Map> peopleLinks;
+ private Map<Integer, Map> flightLinks;
+
+ public TripPinDataModel(ServiceMetadata metadata) throws Exception {
+ this.metadata = metadata;
+ loadData();
+ }
+
+ public void loadData() throws Exception {
+ this.entitySetMap = new HashMap<String, EntitySet>();
+ this.tripLinks = new HashMap<Integer, Map>();
+ this.peopleLinks = new HashMap<String, Map>();
+ this.flightLinks = new HashMap<Integer, Map>();
+
+ EdmEntityContainer ec = metadata.getEdm().getEntityContainer(null);
+ for (EdmEntitySet edmEntitySet : ec.getEntitySets()) {
+ String entitySetName = edmEntitySet.getName();
+ EntitySet set = loadEnities(entitySetName, edmEntitySet.getEntityType());
+ if (set != null) {
+ this.entitySetMap.put(entitySetName, set);
+ }
+ }
+
+ EdmEntityType type = metadata.getEdm().getEntityType(
+ new FullQualifiedName("Microsoft.OData.SampleService.Models.TripPin", "Trip"));
+ this.entitySetMap.put("Trip", loadEnities("Trip", type));
+
+ type = metadata.getEdm().getEntityType(
+ new FullQualifiedName("Microsoft.OData.SampleService.Models.TripPin", "Flight"));
+ this.entitySetMap.put("Flight", loadEnities("Flight", type));
+
+ type = metadata.getEdm().getEntityType(
+ new FullQualifiedName("Microsoft.OData.SampleService.Models.TripPin", "Event"));
+ this.entitySetMap.put("Event", loadEnities("Event", type));
+
+ ObjectMapper mapper = new ObjectMapper();
+ Map tripLinks = mapper.readValue(new FileInputStream(new File(
+ "src/test/resources/trip-links.json")), Map.class);
+ for (Object link : (ArrayList) tripLinks.get("value")) {
+ Map map = (Map) link;
+ this.tripLinks.put((Integer) map.get("TripId"), map);
+ }
+
+ Map peopleLinks = mapper.readValue(new FileInputStream(new File(
+ "src/test/resources/people-links.json")), Map.class);
+ for (Object link : (ArrayList) peopleLinks.get("value")) {
+ Map map = (Map) link;
+ this.peopleLinks.put((String) map.get("UserName"), map);
+ }
+
+ Map flightLinks = mapper.readValue(new FileInputStream(new File(
+ "src/test/resources/flight-links.json")), Map.class);
+ for (Object link : (ArrayList) flightLinks.get("value")) {
+ Map map = (Map) link;
+ this.flightLinks.put((Integer) map.get("PlanItemId"), map);
+ }
+ }
+
+ private EntitySet loadEnities(String entitySetName, EdmEntityType type) {
+ try {
+ ODataJsonDeserializer deserializer = new ODataJsonDeserializer();
+
+ EntitySet set = deserializer.entityCollection(new FileInputStream(new File(
+ "src/test/resources/" + entitySetName.toLowerCase() + ".json")), type);
+ // TODO: the count needs to be part of deserializer
+ set.setCount(set.getEntities().size());
+ for (Entity entity : set.getEntities()) {
+ ((EntityImpl) entity).setETag(UUID.randomUUID().toString());
+ ((EntityImpl) entity).setId(new URI(TripPinHandler.buildLocation(entity, entitySetName,
+ type)));
+ ((EntityImpl) entity).setType(type.getFullQualifiedName().getFullQualifiedNameAsString());
+ }
+ return set;
+ } catch (FileNotFoundException e) {
+ // keep going
+ e.printStackTrace();
+ } catch (DeserializerException e) {
+ // keep going
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ // keep going
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public EntitySet getEntitySet(String name) {
+ return getEntitySet(name, -1, -1);
+ }
+
+ public EntitySet getEntitySet(String name, int skip, int pageSize) {
+ EntitySet set = this.entitySetMap.get(name);
+ if (set == null) {
+ return null;
+ }
+
+ EntitySetImpl modifiedES = new EntitySetImpl();
+ int i = 0;
+ for (Entity e : set.getEntities()) {
+ if (skip >= 0 && i >= skip && modifiedES.getEntities().size() < pageSize) {
+ modifiedES.getEntities().add(e);
+ }
+ i++;
+ }
+ modifiedES.setCount(i);
+ set.setCount(i);
+
+ if (skip == -1 && pageSize == -1) {
+ return set;
+ }
+ return modifiedES;
+ }
+
+ private List<Entity> getMatch(UriParameter param, List<Entity> es)
+ throws ODataApplicationException {
+ ArrayList<Entity> list = new ArrayList<Entity>();
+ for (Entity entity : es) {
+
+ EdmEntityType entityType = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(entity.getType()));
+
+ EdmProperty property = (EdmProperty) entityType.getProperty(param.getName());
+ EdmType type = property.getType();
+ if (type.getKind() == EdmTypeKind.PRIMITIVE) {
+ Object match = readPrimitiveValue(property, param.getText());
+ Property entityValue = entity.getProperty(param.getName());
+ if (match.equals(entityValue.asPrimitive())) {
+ list.add(entity);
+ }
+ } else {
+ throw new RuntimeException("Can not compare complex objects");
+ }
+ }
+ return list;
+ }
+
+ static Object readPrimitiveValue(EdmProperty edmProperty, String value)
+ throws ODataApplicationException {
+ if (value == null) {
+ return null;
+ }
+ try {
+ if (value.startsWith("'") && value.endsWith("'")) {
+ value = value.substring(1,value.length()-1);
+ }
+ EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmProperty.getType();
+ Class<?> javaClass = getJavaClassForPrimitiveType(edmProperty, edmPrimitiveType);
+ return edmPrimitiveType.valueOfString(value, edmProperty.isNullable(),
+ edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(),
+ edmProperty.isUnicode(), javaClass);
+ } catch (EdmPrimitiveTypeException e) {
+ throw new ODataApplicationException("Invalid value: " + value + " for property: "
+ + edmProperty.getName(), 500, Locale.getDefault());
+ }
+ }
+
+ static Class<?> getJavaClassForPrimitiveType(EdmProperty edmProperty, EdmPrimitiveType edmPrimitiveType) {
+ Class<?> javaClass = null;
+ if (edmProperty.getMapping() != null && edmProperty.getMapping().getMappedJavaClass() != null) {
+ javaClass = edmProperty.getMapping().getMappedJavaClass();
+ } else {
+ javaClass = edmPrimitiveType.getDefaultType();
+ }
+
+ edmPrimitiveType.getDefaultType();
+ return javaClass;
+ }
+
+ public Entity getEntity(String name, List<UriParameter> keys) throws ODataApplicationException {
+ EntitySet es = getEntitySet(name);
+ return getEntity(es, keys);
+ }
+
+ public Entity getEntity(EntitySet es, List<UriParameter> keys) throws ODataApplicationException {
+ List<Entity> search = es.getEntities();
+ for (UriParameter param : keys) {
+ search = getMatch(param, search);
+ }
+ if (search.isEmpty()) {
+ return null;
+ }
+ return search.get(0);
+ }
+
+ private EntitySet getFriends(String userName) {
+ Map<String, Object> map = this.peopleLinks.get(userName);
+ if (map == null) {
+ return null;
+ }
+ ArrayList<String> friends = (ArrayList<String>) map.get("Friends");
+ EntitySet set = getEntitySet("People");
+
+ EntitySetImpl result = new EntitySetImpl();
+ int i = 0;
+ if (friends != null) {
+ for (String friend : friends) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("UserName").getValue().equals(friend)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private EntitySet getTrips(String userName) {
+ Map<String, Object> map = this.peopleLinks.get(userName);
+ if (map == null) {
+ return null;
+ }
+
+ ArrayList<Integer> trips = (ArrayList<Integer>) map.get("Trips");
+ EntitySet set = getEntitySet("Trip");
+
+ EntitySetImpl result = new EntitySetImpl();
+ int i = 0;
+ if (trips != null) {
+ for (int trip : trips) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("TripId").getValue().equals(trip)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private Entity getPhoto(String userName) {
+ Map<String, Object> map = this.peopleLinks.get(userName);
+ if (map == null) {
+ return null;
+ }
+
+ Integer photoID = (Integer) map.get("Photo");
+ EntitySet set = getEntitySet("Photos");
+ if (photoID != null) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("Id").getValue().equals(photoID.longValue())) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ private EntitySet getPlanItems(int tripId, EntitySetImpl result) {
+ getFlights(tripId, result);
+ getEvents(tripId, result);
+ return result;
+ }
+
+ private EntitySet getEvents(int tripId, EntitySetImpl result) {
+ Map<Integer, Object> map = this.tripLinks.get(tripId);
+ if (map == null) {
+ return null;
+ }
+
+ ArrayList<Integer> events = (ArrayList<Integer>) map.get("Events");
+ EntitySet set = getEntitySet("Event");
+ int i = result.getEntities().size();
+ if (events != null) {
+ for (int event : events) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("PlanItemId").getValue().equals(event)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private EntitySet getFlights(int tripId, EntitySetImpl result) {
+ Map<Integer, Object> map = this.tripLinks.get(tripId);
+ if (map == null) {
+ return null;
+ }
+
+ ArrayList<Integer> flights = (ArrayList<Integer>) map.get("Flights");
+ EntitySet set = getEntitySet("Flight");
+ int i = result.getEntities().size();
+ if (flights != null) {
+ for (int flight : flights) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("PlanItemId").getValue().equals(flight)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private EntitySet getTripPhotos(int tripId) {
+ Map<Integer, Object> map = this.tripLinks.get(tripId);
+ if (map == null) {
+ return null;
+ }
+
+ ArrayList<Integer> photos = (ArrayList<Integer>) map.get("Photos");
+
+ EntitySet set = getEntitySet("Photos");
+ EntitySetImpl result = new EntitySetImpl();
+ int i = 0;
+ if (photos != null) {
+ for (int photo : photos) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("Id").getValue().equals(photo)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private Entity getFlightFrom(int flighID) {
+ Map<String, Object> map = this.flightLinks.get(flighID);
+ if (map == null) {
+ return null;
+ }
+
+ String from = (String) map.get("From");
+ EntitySet set = getEntitySet("Airports");
+
+ if (from != null) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("IataCode").getValue().equals(from)) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ private Entity getFlightTo(int flighID) {
+ Map<String, Object> map = this.flightLinks.get(flighID);
+ if (map == null) {
+ return null;
+ }
+
+ String to = (String) map.get("To");
+ EntitySet set = getEntitySet("Airports");
+
+ if (to != null) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("IataCode").getValue().equals(to)) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ private Entity getFlightAirline(int flighID) {
+ Map<String, Object> map = this.flightLinks.get(flighID);
+ if (map == null) {
+ return null;
+ }
+
+ String airline = (String) map.get("Airline");
+ EntitySet set = getEntitySet("Airlines");
+
+ if (airline != null) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("AirlineCode").getValue().equals(airline)) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ public void addNavigationLink(String navigation, Entity parentEntity, Entity childEntity) {
+
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+ String key = type.getKeyPredicateNames().get(0);
+ if (type.getName().equals("Person") && navigation.equals("Friends")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.peopleLinks.put((String) parentEntity.getProperty(key).getValue(), map);
+ }
+
+ ArrayList<String> friends = (ArrayList<String>) map.get("Friends");
+ if (friends == null) {
+ friends = new ArrayList<String>();
+ map.put("Friends", friends);
+ }
+ friends.add((String) childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Person") && navigation.equals("Trips")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.peopleLinks.put((String) parentEntity.getProperty(key).getValue(), map);
+ }
+
+ ArrayList<Integer> trips = (ArrayList<Integer>) map.get("Trips");
+ if (trips == null) {
+ trips = new ArrayList<Integer>();
+ map.put("Trips", trips);
+ }
+ trips.add((Integer) childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Person") && navigation.equals("Photo")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.peopleLinks.put((String) parentEntity.getProperty(key).getValue(), map);
+ }
+ map.put("Photo", childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Trip") && navigation.equals("PlanItems")) {
+ Map map = this.tripLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.tripLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ if (childEntity.getType().equals("Flight")) {
+ ArrayList<Integer> flights = (ArrayList<Integer>) map.get("Flights");
+ if (flights == null) {
+ flights = new ArrayList<Integer>();
+ map.put("Flights", flights);
+ }
+ flights.add((Integer) childEntity.getProperty(key).getValue());
+ } else {
+ ArrayList<Integer> events = (ArrayList<Integer>) map.get("Events");
+ if (events == null) {
+ events = new ArrayList<Integer>();
+ map.put("Events", events);
+ }
+ events.add((Integer) childEntity.getProperty(key).getValue());
+ }
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Trip") && navigation.equals("Photo")) {
+ Map map = this.tripLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.tripLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ ArrayList<Integer> photos = (ArrayList<Integer>) map.get("Photos");
+ if (photos == null) {
+ photos = new ArrayList<Integer>();
+ map.put("Photos", photos);
+ }
+ photos.add((Integer) childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Flight") && navigation.equals("From")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.flightLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ map.put("From", childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Flight") && navigation.equals("To")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.flightLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ map.put("To", childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Flight") && navigation.equals("Airline")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.flightLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ map.put("Airline", childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ }
+
+ protected static void setLink(Entity entity, final String navigationPropertyName,
+ final Entity target) {
+ Link link = new LinkImpl();
+ link.setTitle(navigationPropertyName);
+ link.setInlineEntity(target);
+ entity.getNavigationLinks().add(link);
+ }
+
+ public boolean updateNavigationLink(String navigationProperty, Entity parentEntity,
+ Entity updateEntity) {
+ boolean updated = false;
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+ String key = type.getKeyPredicateNames().get(0);
+
+ EdmEntityType updateType = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(updateEntity.getType()));
+ String updateKey = updateType.getKeyPredicateNames().get(0);
+
+ if (type.getName().equals("Person") && navigationProperty.equals("Photo")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.put("Photo", ((Long) updateEntity.getProperty(updateKey).getValue()).intValue());
+ updated = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("From")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.put("From", updateEntity.getProperty(updateKey).getValue());
+ updated = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("To")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.put("To", updateEntity.getProperty(updateKey).getValue());
+ updated = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("Airline")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.put("Airline", updateEntity.getProperty(updateKey).getValue());
+ updated = true;
+ }
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ return updated;
+ }
+
+ public Entity createEntity(String entitySetName, Entity entity, String location)
+ throws ODataApplicationException {
+
+ EntitySet set = this.entitySetMap.get(entitySetName);
+ EntityImpl copy = new EntityImpl();
+ copy.setType(entity.getType());
+ for (Property p : entity.getProperties()) {
+ copy.addProperty(p);
+ }
+
+ try {
+ copy.setId(new URI(location));
+ copy.setETag(UUID.randomUUID().toString());
+ } catch (URISyntaxException e) {
+ throw new ODataApplicationException("Failed to create ID for entity", 500,
+ Locale.getDefault());
+ }
+
+ set.getEntities().add(copy);
+ return copy;
+ }
+
+ public boolean deleteEntity(String entitySetName, String eTag, String key, Object keyValue) {
+ EntitySet set = getEntitySet(entitySetName);
+ Iterator<Entity> it = set.getEntities().iterator();
+ boolean removed = false;
+ while (it.hasNext()) {
+ Entity entity = it.next();
+ if (entity.getProperty(key).getValue().equals(keyValue) && eTag.equals("*")
+ || eTag.equals(entity.getETag())) {
+ it.remove();
+ removed = true;
+ break;
+ }
+ }
+ return removed;
+ }
+
+ public boolean updateProperty(String entitySetName, String eTag, String key, Object keyValue,
+ Property property) {
+ EntitySet set = getEntitySet(entitySetName);
+ Iterator<Entity> it = set.getEntities().iterator();
+ boolean replaced = false;
+ while (it.hasNext()) {
+ Entity entity = it.next();
+ if (entity.getProperty(key).getValue().equals(keyValue) && eTag.equals("*")
+ || eTag.equals(entity.getETag())) {
+ entity.getProperty(property.getName()).setValue(property.getValueType(),
+ property.getValue());
+ replaced = true;
+ break;
+ }
+ }
+ return replaced;
+ }
+
+ public EntitySet getNavigableEntitySet(Entity parentEntity, UriResourceNavigation navigation) {
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+
+ String key = type.getKeyPredicateNames().get(0);
+ String linkName = navigation.getProperty().getName();
+
+ EntitySet results = null;
+ if (type.getName().equals("Person") && linkName.equals("Friends")) {
+ results = getFriends((String) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Person") && linkName.equals("Trips")) {
+ results = getTrips((String) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Trip") && linkName.equals("PlanItems")) {
+ EntitySetImpl planitems = new EntitySetImpl();
+ if (navigation.getTypeFilterOnCollection() == null) {
+ results = getPlanItems((Integer) parentEntity.getProperty(key).getValue(), planitems);
+ } else if (navigation.getTypeFilterOnCollection().getName().equals("Flight")) {
+ results = getFlights((Integer) parentEntity.getProperty(key).getValue(), planitems);
+ } else if (navigation.getTypeFilterOnCollection().getName().equals("Event")) {
+ results = getEvents((Integer) parentEntity.getProperty(key).getValue(), planitems);
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ } else if (type.getName().equals("Trip") && linkName.equals("Photos")) {
+ results = getTripPhotos((Integer) parentEntity.getProperty(key).getValue());
+ }
+ return results;
+ }
+
+ public Entity getNavigableEntity(Entity parentEntity, UriResourceNavigation navigation)
+ throws ODataApplicationException {
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+
+ String key = type.getKeyPredicateNames().get(0);
+ String linkName = navigation.getProperty().getName();
+
+ EntitySet results = null;
+ if (navigation.getProperty().isCollection()) {
+ results = getNavigableEntitySet(parentEntity, navigation);
+ return this.getEntity(results, navigation.getKeyPredicates());
+ }
+ if (type.getName().equals("Person") && linkName.equals("Photo")) {
+ return getPhoto((String) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Flight") && linkName.equals("From")) {
+ return getFlightFrom((Integer) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Flight") && linkName.equals("To")) {
+ return getFlightTo((Integer) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Flight") && linkName.equals("Airline")) {
+ return getFlightAirline((Integer) parentEntity.getProperty(key).getValue());
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ }
+
+ public boolean removeNavigationLink(String navigationProperty, Entity parentEntity,
+ Entity deleteEntity) {
+ boolean removed = false;
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+ String key = type.getKeyPredicateNames().get(0);
+
+ if (type.getName().equals("Person") && navigationProperty.equals("Friends")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ ArrayList<String> friends = (ArrayList<String>) map.get("Friends");
+ if (friends != null) {
+ friends.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ }
+ } else if (type.getName().equals("Person") && navigationProperty.equals("Trips")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ ArrayList<Integer> trips = (ArrayList<Integer>) map.get("Trips");
+ if (trips != null) {
+ trips.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ }
+ } else if (type.getName().equals("Person") && navigationProperty.equals("Photo")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.remove("Photo");
+ removed = true;
+ }
+ } else if (type.getName().equals("Trip") && navigationProperty.equals("PlanItems")) {
+ Map map = this.tripLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ if (deleteEntity.getType().equals("Flight")) {
+ ArrayList<Integer> flights = (ArrayList<Integer>) map.get("Flights");
+ if (flights != null) {
+ flights.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ } else {
+ ArrayList<Integer> events = (ArrayList<Integer>) map.get("Events");
+ if (events != null) {
+ events.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ }
+ }
+ } else if (type.getName().equals("Trip") && navigationProperty.equals("Photo")) {
+ Map map = this.tripLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ ArrayList<Integer> photos = (ArrayList<Integer>) map.get("Photos");
+ if (photos != null) {
+ photos.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("From")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.remove("From");
+ removed = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("To")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.remove("To");
+ removed = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("Airline")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.remove("Airline");
+ removed = true;
+ }
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ return removed;
+ }
+
+ // note these are not tied to entities for simplicity sake
+ public boolean updateMedia(Entity entity, InputStream mediaContent)
+ throws ODataApplicationException {
+ checkForMedia(entity);
+ return true;
+ }
+
+ // note these are not tied to entities for simplicity sake
+ public InputStream readMedia(Entity entity) throws ODataApplicationException {
+ checkForMedia(entity);
+ try {
+ return new FileInputStream(new File("src/test/resources/OlingoOrangeTM.png"));
+ } catch (FileNotFoundException e) {
+ throw new ODataApplicationException("image not found", 500, Locale.getDefault());
+ }
+ }
+
+ // note these are not tied to entities for simplicity sake
+ public boolean deleteMedia(Entity entity) throws ODataApplicationException {
+ checkForMedia(entity);
+ return true;
+ }
+
+ private void checkForMedia(Entity entity) throws ODataApplicationException {
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(entity.getType()));
+ if (!type.hasStream()) {
+ throw new ODataApplicationException("No Media proeprty on the entity", 500,
+ Locale.getDefault());
+ }
+ }
+
+ public boolean deleteStream(Entity entity, EdmProperty property) {
+ // should remove stream links
+ return true;
+ }
+
+ public boolean updateStream(Entity entity, EdmProperty property, InputStream streamContent) {
+ // should add stream links
+ return true;
+ }
+}
\ No newline at end of file
[22/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLVisitor.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLVisitor.java
new file mode 100644
index 0000000..f3f4027
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/RequestURLVisitor.java
@@ -0,0 +1,127 @@
+/*
+ * 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.edm.EdmEntityType;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoAll;
+import org.apache.olingo.server.api.uri.UriInfoBatch;
+import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
+import org.apache.olingo.server.api.uri.UriInfoEntityId;
+import org.apache.olingo.server.api.uri.UriInfoMetadata;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.UriInfoService;
+import org.apache.olingo.server.api.uri.UriResourceAction;
+import org.apache.olingo.server.api.uri.UriResourceComplexProperty;
+import org.apache.olingo.server.api.uri.UriResourceCount;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.api.uri.UriResourceIt;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAll;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAny;
+import org.apache.olingo.server.api.uri.UriResourceLambdaVariable;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
+import org.apache.olingo.server.api.uri.UriResourceRef;
+import org.apache.olingo.server.api.uri.UriResourceRoot;
+import org.apache.olingo.server.api.uri.UriResourceSingleton;
+import org.apache.olingo.server.api.uri.UriResourceValue;
+import org.apache.olingo.server.api.uri.queryoption.CountOption;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.server.api.uri.queryoption.FilterOption;
+import org.apache.olingo.server.api.uri.queryoption.FormatOption;
+import org.apache.olingo.server.api.uri.queryoption.IdOption;
+import org.apache.olingo.server.api.uri.queryoption.OrderByOption;
+import org.apache.olingo.server.api.uri.queryoption.SearchOption;
+import org.apache.olingo.server.api.uri.queryoption.SelectOption;
+import org.apache.olingo.server.api.uri.queryoption.SkipOption;
+import org.apache.olingo.server.api.uri.queryoption.SkipTokenOption;
+import org.apache.olingo.server.api.uri.queryoption.TopOption;
+
+public interface RequestURLVisitor {
+
+ void visit(UriInfo info);
+
+ void visit(UriInfoService info);
+
+ void visit(UriInfoAll info);
+
+ void visit(UriInfoBatch info);
+
+ void visit(UriInfoCrossjoin info);
+
+ void visit(UriInfoEntityId info);
+
+ void visit(UriInfoMetadata info);
+
+ void visit(UriInfoResource info);
+
+ // Walk UriInfoResource
+ void visit(ExpandOption option);
+
+ void visit(FilterOption info);
+
+ void visit(FormatOption info);
+
+ void visit(IdOption info, EdmEntityType type);
+
+ void visit(CountOption info);
+
+ void visit(OrderByOption option);
+
+ void visit(SearchOption option);
+
+ void visit(SelectOption option);
+
+ void visit(SkipOption option);
+
+ void visit(SkipTokenOption option);
+
+ void visit(TopOption option);
+
+ void visit(UriResourceCount option);
+
+ void visit(UriResourceRef info);
+
+ void visit(UriResourceRoot info);
+
+ void visit(UriResourceValue info);
+
+ void visit(UriResourceAction info);
+
+ void visit(UriResourceEntitySet info);
+
+ void visit(UriResourceFunction info);
+
+ void visit(UriResourceIt info);
+
+ void visit(UriResourceLambdaAll info);
+
+ void visit(UriResourceLambdaAny info);
+
+ void visit(UriResourceLambdaVariable info);
+
+ void visit(UriResourceNavigation info);
+
+ void visit(UriResourceSingleton info);
+
+ void visit(UriResourceComplexProperty info);
+
+ void visit(UriResourcePrimitiveProperty info);
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ReturnRepresentation.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ReturnRepresentation.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ReturnRepresentation.java
new file mode 100644
index 0000000..e9a213e
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ReturnRepresentation.java
@@ -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.core;
+
+public enum ReturnRepresentation {
+ REPRESENTATION, MINIMAL
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java
new file mode 100644
index 0000000..7e607d9
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java
@@ -0,0 +1,303 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.Action;
+import org.apache.olingo.commons.api.edm.provider.ActionImport;
+import org.apache.olingo.commons.api.edm.provider.AliasInfo;
+import org.apache.olingo.commons.api.edm.provider.ComplexType;
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.commons.api.edm.provider.EntityContainer;
+import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.commons.api.edm.provider.EntitySet;
+import org.apache.olingo.commons.api.edm.provider.EntityType;
+import org.apache.olingo.commons.api.edm.provider.EnumType;
+import org.apache.olingo.commons.api.edm.provider.Function;
+import org.apache.olingo.commons.api.edm.provider.FunctionImport;
+import org.apache.olingo.commons.api.edm.provider.Schema;
+import org.apache.olingo.commons.api.edm.provider.Singleton;
+import org.apache.olingo.commons.api.edm.provider.Term;
+import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
+
+public class SchemaBasedEdmProvider extends EdmProvider {
+ private final List<Schema> edmSchemas = new ArrayList<Schema>();
+
+ protected void addSchema(Schema schema) {
+ this.edmSchemas.add(schema);
+ }
+
+ private Schema getSchema(String ns) {
+ for (Schema s : this.edmSchemas) {
+ if (s.getNamespace().equals(ns)) {
+ return s;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EnumType getEnumType(FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<EnumType> types = schema.getEnumTypes();
+ if (types != null) {
+ for (EnumType type : types) {
+ if (type.getName().equals(fqn.getName())) {
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public TypeDefinition getTypeDefinition(FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<TypeDefinition> types = schema.getTypeDefinitions();
+ if (types != null) {
+ for (TypeDefinition type : types) {
+ if (type.getName().equals(fqn.getName())) {
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Function> getFunctions(FullQualifiedName fqn) throws ODataException {
+ ArrayList<Function> foundFuncs = new ArrayList<Function>();
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<Function> functions = schema.getFunctions();
+ if (functions != null) {
+ for (Function func : functions) {
+ if (func.getName().equals(fqn.getName())) {
+ foundFuncs.add(func);
+ }
+ }
+ }
+ }
+ return foundFuncs;
+ }
+
+ @Override
+ public Term getTerm(FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<Term> terms = schema.getTerms();
+ if (terms != null) {
+ for (Term term : terms) {
+ if (term.getName().equals(fqn.getName())) {
+ return term;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(FullQualifiedName fqn, String entitySetName) throws ODataException {
+ Schema schema = getSchema(fqn.getFullQualifiedNameAsString());
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null && ec.getEntitySets() != null) {
+ for (EntitySet es : ec.getEntitySets()) {
+ if (es.getName().equals(entitySetName)) {
+ return es;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Singleton getSingleton(FullQualifiedName fqn, String singletonName) throws ODataException {
+ Schema schema = getSchema(fqn.getFullQualifiedNameAsString());
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null && ec.getSingletons() != null) {
+ for (Singleton es : ec.getSingletons()) {
+ if (es.getName().equals(singletonName)) {
+ return es;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ActionImport getActionImport(FullQualifiedName fqn, String actionImportName)
+ throws ODataException {
+ Schema schema = getSchema(fqn.getFullQualifiedNameAsString());
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null && ec.getActionImports() != null) {
+ for (ActionImport es : ec.getActionImports()) {
+ if (es.getName().equals(actionImportName)) {
+ return es;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(FullQualifiedName fqn, String functionImportName)
+ throws ODataException {
+ Schema schema = getSchema(fqn.getFullQualifiedNameAsString());
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null && ec.getFunctionImports() != null) {
+ for (FunctionImport es : ec.getFunctionImports()) {
+ if (es.getName().equals(functionImportName)) {
+ return es;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(FullQualifiedName fqn) throws ODataException {
+ Schema schema = null;
+
+ if (fqn == null) {
+ for (Schema s : this.edmSchemas) {
+ if (s.getEntityContainer() != null) {
+ schema = s;
+ break;
+ }
+ }
+ } else {
+ schema = getSchema(fqn.getFullQualifiedNameAsString());
+ }
+
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null) {
+ EntityContainerInfo info = new EntityContainerInfo();
+ info.setContainerName(new FullQualifiedName(schema.getNamespace()));
+ if (schema.getEntityContainer().getExtendsContainer() != null) {
+ info.setExtendsContainer(new FullQualifiedName(schema.getEntityContainer().getExtendsContainer()));
+ }
+ return info;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<AliasInfo> getAliasInfos() throws ODataException {
+ Schema schema = null;
+ for (Schema s : this.edmSchemas) {
+ if (s.getEntityContainer() != null) {
+ schema = s;
+ break;
+ }
+ }
+
+ if (schema == null) {
+ schema = this.edmSchemas.get(0);
+ }
+
+ AliasInfo ai = new AliasInfo();
+ ai.setAlias(schema.getAlias());
+ ai.setNamespace(schema.getNamespace());
+ return Arrays.asList(ai);
+ }
+
+ @Override
+ public EntityContainer getEntityContainer() throws ODataException {
+ // note that there can be many schemas, but only one needs to contain the
+ // entity container in a given metadata document.
+ for (Schema s : this.edmSchemas) {
+ if (s.getEntityContainer() != null) {
+ return s.getEntityContainer();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ return new ArrayList<Schema>(this.edmSchemas);
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ if (schema.getEntityTypes() != null) {
+ for (EntityType type : schema.getEntityTypes()) {
+ if (type.getName().equals(fqn.getName())) {
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ if (schema.getComplexTypes() != null) {
+ for (ComplexType type : schema.getComplexTypes()) {
+ if (type.getName().equals(fqn.getName())) {
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Action> getActions(final FullQualifiedName fqn) throws ODataException {
+ ArrayList<Action> actions = new ArrayList<Action>();
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<Action> types = schema.getActions();
+ if (types != null) {
+ for (Action type : types) {
+ if (type.getName().equals(fqn.getName())) {
+ actions.add(type);
+ }
+ }
+ }
+ }
+ return actions;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
new file mode 100644
index 0000000..839d877
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
@@ -0,0 +1,227 @@
+/*
+ * 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.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoBatch;
+import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
+import org.apache.olingo.server.api.uri.UriInfoEntityId;
+import org.apache.olingo.server.api.uri.UriInfoMetadata;
+import org.apache.olingo.server.api.uri.UriInfoService;
+import org.apache.olingo.server.api.uri.UriResourceAction;
+import org.apache.olingo.server.api.uri.UriResourceComplexProperty;
+import org.apache.olingo.server.api.uri.UriResourceCount;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
+import org.apache.olingo.server.api.uri.UriResourceRef;
+import org.apache.olingo.server.api.uri.UriResourceSingleton;
+import org.apache.olingo.server.api.uri.UriResourceValue;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.BatchRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.requests.ServiceDocumentRequest;
+import org.apache.olingo.server.core.uri.parser.Parser;
+import org.apache.olingo.server.core.uri.validator.UriValidator;
+
+public class ServiceDispatcher extends RequestURLHierarchyVisitor {
+ private final OData odata;
+ protected ServiceMetadata metadata;
+ protected ServiceHandler handler;
+ protected CustomContentTypeSupport customContentSupport;
+ private String idOption;
+ protected ServiceRequest request;
+
+ public ServiceDispatcher(OData odata, ServiceMetadata metadata, ServiceHandler handler,
+ CustomContentTypeSupport customContentSupport) {
+ this.odata = odata;
+ this.metadata = metadata;
+ this.handler = handler;
+ this.customContentSupport = customContentSupport;
+ }
+
+ public void execute(ODataRequest odRequest, ODataResponse odResponse)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ UriInfo uriInfo = new Parser().parseUri(odRequest.getRawODataPath(), odRequest.getRawQueryPath(), null,
+ this.metadata.getEdm());
+
+ new UriValidator().validate(uriInfo, odRequest.getMethod());
+
+ visit(uriInfo);
+
+ // this should cover for any unsupported calls until they are implemented
+ if (this.request == null) {
+ this.request = new ServiceRequest(this.odata, this.metadata) {
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentType.APPLICATION_JSON;
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ handler.anyUnsupported(getODataRequest(), response);
+ }
+ };
+ }
+
+ // To handle $entity?$id=http://localhost/EntitySet(key) as
+ // http://localhost/EntitySet(key)
+ if (this.idOption != null) {
+ try {
+ this.request = this.request.parseLink(new URI(this.idOption));
+ } catch (URISyntaxException e) {
+ throw new ODataHandlerException("Invalid $id value",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED, this.idOption);
+ }
+ }
+
+ this.request.setODataRequest(odRequest);
+ this.request.setUriInfo(uriInfo);
+ this.request.setCustomContentTypeSupport(this.customContentSupport);
+ this.request.execute(this.handler, odResponse);
+ }
+
+ @Override
+ public void visit(UriInfoMetadata info) {
+ this.request = new MetadataRequest(this.odata, this.metadata);
+ }
+
+ @Override
+ public void visit(UriInfoService info) {
+ this.request = new ServiceDocumentRequest(this.odata, this.metadata);
+ }
+
+ @Override
+ public void visit(UriResourceEntitySet info) {
+ DataRequest dataRequest = new DataRequest(this.odata, this.metadata);
+ dataRequest.setUriResourceEntitySet(info);
+ this.request = dataRequest;
+ }
+
+ @Override
+ public void visit(UriResourceCount option) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.setCountRequest(option != null);
+ }
+
+ @Override
+ public void visit(UriResourceComplexProperty info) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.setUriResourceProperty(info);
+ }
+
+ @Override
+ public void visit(UriResourcePrimitiveProperty info) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.setUriResourceProperty(info);
+ }
+
+ @Override
+ public void visit(UriResourceValue info) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ if (dataRequest.isPropertyRequest()) {
+ dataRequest.setValueRequest(info != null);
+ } else {
+ MediaRequest mediaRequest = new MediaRequest(this.odata, this.metadata);
+ mediaRequest.setUriResourceEntitySet(dataRequest.getUriResourceEntitySet());
+ this.request = mediaRequest;
+ }
+ }
+
+ @Override
+ public void visit(UriResourceAction info) {
+ ActionRequest actionRequest = new ActionRequest(this.odata, this.metadata);
+ actionRequest.setUriResourceAction(info);
+ this.request = actionRequest;
+ }
+
+ @Override
+ public void visit(UriResourceFunction info) {
+ FunctionRequest functionRequest = new FunctionRequest(this.odata, this.metadata);
+ functionRequest.setUriResourceFunction(info);
+ this.request = functionRequest;
+ }
+
+ @Override
+ public void visit(UriResourceNavigation info) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.addUriResourceNavigation(info);
+ }
+
+ @Override
+ public void visit(UriResourceRef info) {
+ // this is same as data, but return is just entity references.
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.setReferenceRequest(info != null);
+ }
+
+ @Override
+ public void visit(UriInfoBatch info) {
+ this.request = new BatchRequest(this.odata, this.metadata);
+ }
+
+ @Override
+ public void visit(UriResourceSingleton info) {
+ DataRequest dataRequest = new DataRequest(this.odata, this.metadata);
+ dataRequest.setUriResourceSingleton(info);
+ this.request = dataRequest;
+ }
+
+ @Override
+ public void visit(UriInfoEntityId info) {
+ DataRequest dataRequest = new DataRequest(this.odata, this.metadata);
+ this.request = dataRequest;
+
+ // this can relative or absolute form
+ String id = info.getIdOption().getValue();
+ try {
+ URL url = new URL(id);
+ this.idOption = url.getPath();
+ } catch (MalformedURLException e) {
+ this.idOption = id;
+ }
+ super.visit(info);
+ }
+
+ @Override
+ public void visit(UriInfoCrossjoin info) {
+ DataRequest dataRequest = new DataRequest(this.odata, this.metadata);
+ dataRequest.setCrossJoin(info);
+ this.request = dataRequest;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
new file mode 100644
index 0000000..8a9c610
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
@@ -0,0 +1,263 @@
+/*
+ * 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 java.net.URI;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.processor.Processor;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.requests.ServiceDocumentRequest;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.ServiceDocumentResponse;
+import org.apache.olingo.server.core.responses.ServiceResponse;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public interface ServiceHandler extends Processor {
+
+ /**
+ * Read CSDL document of the Service
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void readMetadata(MetadataRequest request, MetadataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Read ServiceDocument of the service
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void readServiceDocument(ServiceDocumentRequest request, ServiceDocumentResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Read operation for EntitySets, Entities, Properties, Media etc. Based on the type of request
+ * the response object is different. Even the navigation based queries are handled by this method.
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ <T extends ServiceResponse> void read(DataRequest request, T response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Create new entity in the service based on the entity object provided
+ * @param request
+ * @param entity
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void createEntity(DataRequest request, Entity entity, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update the entity object.
+ * @param request
+ * @param entity
+ * @param merge - true if merge operation, false it needs to be replaced
+ * @param entityETag - previous entity tag if provided by the user. "*" means allow.
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
+ EntityResponse response) throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Delete the Entity
+ * @param request
+ * @param entityETag - entity tag to match, if provided by the user. "*" means allow
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void deleteEntity(DataRequest request, String entityETag, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update a non-media/stream property.if the value of property NULL, it should be treated as
+ * DeleteProperty 11.4.9.2
+ * @param request
+ * @param property - Updated property.
+ * @param merge - if the property is complex, true here means merge, false is replace
+ * @param entityETag - entity tag to match before update operation, "*" allows all.
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void updateProperty(DataRequest request, Property property, boolean merge, String entityETag,
+ PropertyResponse response) throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update Stream property, if StreamContent is null, it should treated as delete request
+ * @param request
+ * @param entityETag - entity tag to match before update operation, "*" allows all.
+ * @param streamContent - updated stream content
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void upsertStreamProperty(DataRequest request, String entityETag, InputStream streamContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Invocation of a Function. The response object will be based on metadata defined for service
+ * @param request
+ * @param method
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ <T extends ServiceResponse> void invoke(FunctionRequest request, HttpMethod method, T response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Invocation of a Function. The response object will be based on metadata defined for service
+ * @param request
+ * @param eTag
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Read media stream content of a Entity
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void readMediaStream(MediaRequest request, StreamResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update of Media Stream Content of a Entity. If the mediaContent is null it should be treated
+ * as delete request.
+ * @param request
+ * @param entityETag - entity etag to match before update operation, "*" allows all.
+ * @param mediaContent - if null, must be treated as delete request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void upsertMediaStream(MediaRequest request, String entityETag, InputStream mediaContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Any Unsupported one will be directed here.
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void anyUnsupported(ODataRequest request, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Add references (relationships) to Entity.
+ * @param request
+ * @param entityETag - entity etag to match before add operation, "*" allows all.
+ * @param idReferences - references to add
+ * @param response - return always should be 204
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void addReference(DataRequest request, String entityETag, List<URI> idReferences, NoContentResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update references (relationships) in an Entity
+ * @param request
+ * @param entityETag
+ * @param referenceId
+ * @param response - always should be 204
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void updateReference(DataRequest request, String entityETag, URI referenceId, NoContentResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Delete references (relationships) in an Entity
+ * @param request
+ * @param deleteId
+ * @param entityETag
+ * @param response - always should be 204
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void deleteReference(DataRequest request, URI deleteId, String entityETag, NoContentResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+
+ /**
+ * During a batch operation, this method starts the transaction (if any) before any operation is handled
+ * by the service. No nested transactions.
+ * @return must return a unique transaction id that references a atomic operation.
+ */
+ String startTransaction();
+
+ /**
+ * When a batch operation is complete and all the intermediate service requests are successful, then
+ * commit is called with transaction id returned in the startTransaction method.
+ * @param txnId
+ */
+ void commit(String txnId);
+ /**
+ * When a batch operation is in-complete due to an error in the middle of changeset, then rollback is
+ * called with transaction id, that returned from startTransaction method.
+ * @param txnId
+ */
+ void rollback(String txnId);
+
+ /**
+ * This is not complete, more URL parsing changes required. Cross join between two entities.
+ * @param dataRequest
+ * @param entitySetNames
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
new file mode 100644
index 0000000..e9a8cfe
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
@@ -0,0 +1,253 @@
+/*
+ * 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.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
+import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
+import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.uri.parser.Parser;
+import org.apache.olingo.server.core.uri.parser.UriParserException;
+
+public abstract class ServiceRequest {
+ protected OData odata;
+ protected UriInfo uriInfo;
+ protected ServiceMetadata serviceMetadata;
+ protected CustomContentTypeSupport customContentType;
+ protected ODataRequest request;
+
+ public ServiceRequest(OData odata, ServiceMetadata serviceMetadata) {
+ this.odata = odata;
+ this.serviceMetadata = serviceMetadata;
+ }
+
+ public OData getOdata() {
+ return odata;
+ }
+
+ public ServiceMetadata getServiceMetaData() {
+ return this.serviceMetadata;
+ }
+
+ public UriInfo getUriInfo() {
+ return uriInfo;
+ }
+
+ protected void setUriInfo(UriInfo uriInfo) {
+ this.uriInfo = uriInfo;
+ }
+
+ public boolean allowedMethod() {
+ return isGET();
+ }
+
+ public CustomContentTypeSupport getCustomContentTypeSupport() {
+ return this.customContentType;
+ }
+
+ public void setCustomContentTypeSupport(CustomContentTypeSupport support) {
+ this.customContentType = support;
+ }
+
+ public ODataRequest getODataRequest() {
+ return this.request;
+ }
+
+ protected void setODataRequest(ODataRequest request) {
+ this.request = request;
+ }
+
+ public ContentType getRequestContentType() {
+ if (this.request.getHeader(HttpHeader.CONTENT_TYPE) != null) {
+ return ContentType.parse(this.request.getHeader(HttpHeader.CONTENT_TYPE));
+ }
+ return ContentType.APPLICATION_OCTET_STREAM;
+ }
+
+ public abstract void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ public abstract ContentType getResponseContentType() throws ContentNegotiatorException;
+
+ public void methodNotAllowed() throws ODataHandlerException {
+ throw new ODataHandlerException("HTTP method " + this.request.getMethod() + " is not allowed.",
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, this.request.getMethod()
+ .toString());
+ }
+
+ public void notImplemented() throws ODataHandlerException {
+ throw new ODataHandlerException("not implemented", //$NON-NLS-1$
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ }
+
+ protected boolean isGET() {
+ return this.request.getMethod() == HttpMethod.GET;
+ }
+
+ protected boolean isPUT() {
+ return this.request.getMethod() == HttpMethod.PUT;
+ }
+
+ protected boolean isDELETE() {
+ return this.request.getMethod() == HttpMethod.DELETE;
+ }
+
+ protected boolean isPATCH() {
+ return this.request.getMethod() == HttpMethod.PATCH;
+ }
+
+ protected boolean isPOST() {
+ return this.request.getMethod() == HttpMethod.POST;
+ }
+
+ public <T> T getSerializerOptions(Class<T> serilizerOptions, ContextURL contextUrl,
+ boolean references) throws ContentNegotiatorException {
+ final ODataFormat format = ODataFormat.fromContentType(getResponseContentType());
+
+ if (serilizerOptions.isAssignableFrom(EntitySerializerOptions.class)) {
+ return (T) EntitySerializerOptions.with()
+ .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : contextUrl)
+ .expand(uriInfo.getExpandOption()).select(this.uriInfo.getSelectOption())
+ .setWriteOnlyReferences(references).build();
+ } else if (serilizerOptions.isAssignableFrom(EntityCollectionSerializerOptions.class)) {
+ return (T) EntityCollectionSerializerOptions.with()
+ .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : contextUrl)
+ .count(uriInfo.getCountOption()).expand(uriInfo.getExpandOption())
+ .select(uriInfo.getSelectOption()).setWriteOnlyReferences(references).build();
+ } else if (serilizerOptions.isAssignableFrom(ComplexSerializerOptions.class)) {
+ return (T) ComplexSerializerOptions.with().contextURL(contextUrl)
+ .expand(this.uriInfo.getExpandOption()).select(this.uriInfo.getSelectOption()).build();
+ }
+ return null;
+ }
+
+ public ReturnRepresentation getReturnRepresentation() {
+ String prefer = this.request.getHeader(HttpHeader.PREFER);
+ if (prefer == null) {
+ return ReturnRepresentation.REPRESENTATION;
+ }
+ if (prefer.contains("return=minimal")) { //$NON-NLS-1$
+ return ReturnRepresentation.MINIMAL;
+ }
+ return ReturnRepresentation.REPRESENTATION;
+ }
+
+ public String getHeader(String key) {
+ return this.request.getHeader(key);
+ }
+
+ public String getETag() {
+ String etag = getHeader(HttpHeader.IF_MATCH);
+ if (etag == null) {
+ etag = getHeader(HttpHeader.IF_NONE_MATCH);
+ }
+ return ((etag == null) ? "*" : etag); //$NON-NLS-1$
+ }
+
+ public ODataSerializer getSerializer() throws ContentNegotiatorException,
+ SerializerException {
+ ODataFormat format = ODataFormat.fromContentType(getResponseContentType());
+ return this.odata.createSerializer(format);
+ }
+
+ public Map<String, String> getPreferences(){
+ HashMap<String, String> map = new HashMap<String, String>();
+ List<String> headers = request.getHeaders(HttpHeader.PREFER);
+ if (headers != null) {
+ for (String header:headers) {
+ int idx = header.indexOf('=');
+ if (idx != -1) {
+ String key = header.substring(0, idx);
+ String value = header.substring(idx+1);
+ if (value.startsWith("\"")) {
+ value = value.substring(1);
+ }
+ if (value.endsWith("\"")) {
+ value = value.substring(0, value.length()-1);
+ }
+ map.put(key, value);
+ } else {
+ map.put(header, "true");
+ }
+ }
+ }
+ return map;
+ }
+
+ public String getPreference(String key) {
+ return getPreferences().get(key);
+ }
+
+ public String getQueryParameter(String param) {
+ String queryPath = getODataRequest().getRawQueryPath();
+ if (queryPath != null) {
+ StringTokenizer st = new StringTokenizer(queryPath, ",");
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken();
+ int index = token.indexOf('=');
+ if (index != -1) {
+ String key = token.substring(0, index);
+ String value = token.substring(index+1);
+ if (key.equals(param)) {
+ return value;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public DataRequest parseLink(URI uri) throws UriParserException {
+ String rawPath = uri.getPath();
+ int e = rawPath.indexOf("/", 1);
+ if (-1 == e) {
+ rawPath = uri.getPath();
+ } else {
+ rawPath = rawPath.substring(e);
+ }
+
+ UriInfo uriInfo = new Parser().parseUri(rawPath, uri.getQuery(), null,
+ this.serviceMetadata.getEdm());
+ ServiceDispatcher dispatcher = new ServiceDispatcher(odata, serviceMetadata, null, customContentType);
+ dispatcher.visit(uriInfo);
+ return (DataRequest)dispatcher.request;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java
new file mode 100644
index 0000000..fa8f445
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java
@@ -0,0 +1,433 @@
+/*
+ * 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.legacy;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.processor.ComplexCollectionProcessor;
+import org.apache.olingo.server.api.processor.ComplexProcessor;
+import org.apache.olingo.server.api.processor.CountComplexCollectionProcessor;
+import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
+import org.apache.olingo.server.api.processor.CountPrimitiveCollectionProcessor;
+import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
+import org.apache.olingo.server.api.processor.EntityProcessor;
+import org.apache.olingo.server.api.processor.MediaEntityProcessor;
+import org.apache.olingo.server.api.processor.MetadataProcessor;
+import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
+import org.apache.olingo.server.api.processor.PrimitiveProcessor;
+import org.apache.olingo.server.api.processor.PrimitiveValueProcessor;
+import org.apache.olingo.server.api.processor.Processor;
+import org.apache.olingo.server.api.processor.ReferenceProcessor;
+import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
+import org.apache.olingo.server.core.ODataHandlerException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.requests.ServiceDocumentRequest;
+import org.apache.olingo.server.core.responses.CountResponse;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.ServiceDocumentResponse;
+import org.apache.olingo.server.core.responses.ServiceResponse;
+import org.apache.olingo.server.core.responses.ServiceResponseVisior;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public class ProcessorServiceHandler implements ServiceHandler {
+ private final List<Processor> processors = new LinkedList<Processor>();
+ private OData odata;
+ private ServiceMetadata serviceMetadata;
+
+ @Override
+ public void init(OData odata, ServiceMetadata serviceMetadata) {
+ this.odata = odata;
+ this.serviceMetadata = serviceMetadata;
+ }
+
+ public void register(Processor processor) {
+ this.processors.add(processor);
+ processor.init(odata, serviceMetadata);
+ }
+
+ private <T extends Processor> T selectProcessor(final Class<T> cls) throws ODataHandlerException {
+ for (final Processor processor : processors) {
+ if (cls.isAssignableFrom(processor.getClass())) {
+ processor.init(odata, serviceMetadata);
+ return cls.cast(processor);
+ }
+ }
+ throw new ODataHandlerException("Processor: " + cls.getSimpleName() + " not registered.",
+ ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED, cls.getSimpleName());
+ }
+
+ @Override
+ public void readMetadata(MetadataRequest request, MetadataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(MetadataProcessor.class).readMetadata(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public void readServiceDocument(ServiceDocumentRequest request, ServiceDocumentResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(ServiceDocumentProcessor.class).readServiceDocument(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public <T extends ServiceResponse> void read(final DataRequest request, final T response)
+ throws ODataTranslatedException, ODataApplicationException {
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(CountResponse response) throws ODataTranslatedException, ODataApplicationException {
+ if (request.getUriResourceProperty() != null) {
+ EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
+ if (edmProperty.isPrimitive()) {
+ selectProcessor(CountPrimitiveCollectionProcessor.class).countPrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo());
+ } else {
+ selectProcessor(CountComplexCollectionProcessor.class).countComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo());
+ }
+ } else {
+ selectProcessor(CountEntityCollectionProcessor.class).countEntityCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo());
+ }
+ }
+
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityProcessor.class).readEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public void visit(PrimitiveValueResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(PrimitiveValueProcessor.class).readPrimitiveValue(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+
+ @Override
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
+ if (edmProperty.isPrimitive()) {
+ if(edmProperty.isCollection()) {
+ selectProcessor(PrimitiveCollectionProcessor.class).readPrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(PrimitiveProcessor.class).readPrimitive(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ } else {
+ if(edmProperty.isCollection()) {
+ selectProcessor(ComplexCollectionProcessor.class).readComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(ComplexProcessor.class).readComplex(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ }
+ }
+ }
+
+ @Override
+ public void visit(StreamResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ @Override
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityCollectionProcessor.class).readEntityCollection(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+ });
+ }
+
+ @Override
+ public void createEntity(DataRequest request, Entity entity, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ if (request.getEntitySet().getEntityType().hasStream()) {
+ selectProcessor(MediaEntityProcessor.class).createMediaEntity(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(),request.getResponseContentType());
+ } else {
+ selectProcessor(EntityProcessor.class).createEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getRequestContentType(),
+ request.getResponseContentType());
+ }
+ }
+
+ @Override
+ public void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
+ EntityResponse response) throws ODataTranslatedException, ODataApplicationException {
+ if (request.getEntitySet().getEntityType().hasStream()) {
+ selectProcessor(MediaEntityProcessor.class).updateMediaEntity(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(),request.getResponseContentType());
+ } else {
+ selectProcessor(EntityProcessor.class).updateEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getRequestContentType(),
+ request.getResponseContentType());
+ }
+ }
+
+ @Override
+ public void deleteEntity(DataRequest request, String entityETag, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(EntityProcessor.class).deleteEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo());
+ }
+
+ @Override
+ public void updateProperty(DataRequest request, Property property, boolean merge,
+ String entityETag, PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (property.isPrimitive()) {
+ if (property.isCollection()) {
+ selectProcessor(PrimitiveCollectionProcessor.class).updatePrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ } else {
+ selectProcessor(PrimitiveProcessor.class).updatePrimitive(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ }
+ } else {
+ if (property.isCollection()) {
+ selectProcessor(ComplexCollectionProcessor.class).updateComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ } else {
+ selectProcessor(ComplexProcessor.class).updateComplex(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ }
+ }
+ }
+
+ @Override
+ public void upsertStreamProperty(DataRequest request, String entityETag,
+ InputStream streamContent, NoContentResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ }
+
+ @Override
+ public <T extends ServiceResponse> void invoke(final FunctionRequest request, HttpMethod method,
+ final T response) throws ODataTranslatedException, ODataApplicationException {
+ if (method != HttpMethod.GET) {
+ throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
+ }
+
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityProcessor.class).readEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (request.isReturnTypePrimitive()) {
+ if(request.isCollection()) {
+ selectProcessor(PrimitiveCollectionProcessor.class).readPrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(PrimitiveProcessor.class).readPrimitive(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ } else {
+ if(request.isCollection()) {
+ selectProcessor(ComplexCollectionProcessor.class).readComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(ComplexProcessor.class).readComplex(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ }
+ }
+ @Override
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityCollectionProcessor.class).readEntityCollection(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+ });
+ }
+
+ @Override
+ public <T extends ServiceResponse> void invoke(final ActionRequest request, String eTag, final T response)
+ throws ODataTranslatedException, ODataApplicationException {
+ final HttpMethod method = request.getODataRequest().getMethod();
+ if (method != HttpMethod.POST) {
+ throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
+ }
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityProcessor.class).readEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (request.isReturnTypePrimitive()) {
+ if(request.isCollection()) {
+ selectProcessor(PrimitiveCollectionProcessor.class).readPrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(PrimitiveProcessor.class).readPrimitive(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ } else {
+ if(request.isCollection()) {
+ selectProcessor(ComplexCollectionProcessor.class).readComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(ComplexProcessor.class).readComplex(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ }
+ }
+ @Override
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityCollectionProcessor.class).readEntityCollection(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+ });
+ }
+
+
+ @Override
+ public void readMediaStream(MediaRequest request, StreamResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(MediaEntityProcessor.class).readMediaEntity(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+
+ @Override
+ public void upsertMediaStream(MediaRequest request, String entityETag, InputStream mediaContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(MediaEntityProcessor.class).updateMediaEntity(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ }
+
+ @Override
+ public void anyUnsupported(ODataRequest request, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ }
+
+ @Override
+ public void addReference(DataRequest request, String entityETag, List<URI> idReferences,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(ReferenceProcessor.class).createReference(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+
+ @Override
+ public void updateReference(DataRequest request, String entityETag, URI referenceId,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(ReferenceProcessor.class).updateReference(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+
+ @Override
+ public void deleteReference(DataRequest request, URI deleteId, String entityETag,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(ReferenceProcessor.class).deleteReference(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo());
+ }
+
+ @Override
+ public String startTransaction() {
+ return null;
+ }
+
+ @Override
+ public void commit(String txnId) {
+ }
+
+ @Override
+ public void rollback(String txnId) {
+ }
+
+ @Override
+ public void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ActionRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ActionRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ActionRequest.java
new file mode 100644
index 0000000..133ee3e
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ActionRequest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.requests;
+
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.uri.UriResourceAction;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+
+public class ActionRequest extends OperationRequest {
+ private UriResourceAction uriResourceAction;
+
+ public ActionRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+ // Actions MAY return data but MUST NOT be further composed with additional
+ // path segments.
+ // On success, the response is 201 Created for actions that create entities,
+ // 200 OK for actions
+ // that return results or 204 No Content for action without a return type.
+ // The client can request
+ // whether any results from the action be returned using the Prefer header.
+
+ if (!hasReturnType()) {
+ handler.invoke(this, getETag(), new NoContentResponse(getServiceMetaData(), response));
+ } else {
+ if (isReturnTypePrimitive()) {
+ handler.invoke(this, getETag(),
+ PrimitiveValueResponse.getInstance(this, response, isCollection(), getReturnType()));
+ } else if (isReturnTypeComplex()) {
+ handler.invoke(this, getETag(), PropertyResponse.getInstance(this, response,
+ getReturnType().getType(), getContextURL(this.odata), isCollection()));
+ } else {
+ // EdmTypeKind.ENTITY
+ if (isCollection()) {
+ handler.invoke(this, getETag(),
+ EntitySetResponse.getInstance(this, getContextURL(odata), false, response));
+ } else {
+ handler.invoke(this, getETag(),
+ EntityResponse.getInstance(this, getContextURL(odata), false, response));
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ // 11.5.4.1 Invoking an Action - only allows POST
+ return (isPOST());
+ }
+
+ public UriResourceAction getUriResourceAction() {
+ return uriResourceAction;
+ }
+
+ public void setUriResourceAction(UriResourceAction uriResourceAction) {
+ this.uriResourceAction = uriResourceAction;
+ }
+
+ @Override
+ public boolean isBound() {
+ return this.uriResourceAction.getActionImport() != null;
+ }
+
+ public EdmAction getAction() {
+ return this.uriResourceAction.getAction();
+ }
+
+ @Override
+ public boolean isCollection() {
+ assert (hasReturnType());
+ return getAction().getReturnType().isCollection();
+ }
+
+ @Override
+ public EdmReturnType getReturnType() {
+ assert (hasReturnType());
+ return getAction().getReturnType();
+ }
+
+ @Override
+ public boolean hasReturnType() {
+ return getAction().getReturnType() != null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
new file mode 100644
index 0000000..25af023
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
@@ -0,0 +1,197 @@
+/*
+ * 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.requests;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.UUID;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
+import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
+import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
+import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ErrorHandler;
+import org.apache.olingo.server.core.ServiceDispatcher;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.batchhandler.referenceRewriting.BatchReferenceRewriter;
+import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
+
+public class BatchRequest extends ServiceRequest {
+ private static final String PREFERENCE_CONTINUE_ON_ERROR = "odata.continue-on-error";
+ private final BatchReferenceRewriter rewriter;
+
+ public BatchRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ this.rewriter = new BatchReferenceRewriter();
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+
+ validateContentType();
+ boolean continueOnError = isContinueOnError();
+ final String boundary = extractBoundary(getRequestContentType());
+
+ final BatchOptions options = BatchOptions.with().rawBaseUri(request.getRawBaseUri())
+ .rawServiceResolutionUri(this.request.getRawServiceResolutionUri()).build();
+
+ final List<BatchRequestPart> parts = this.odata.createFixedFormatDeserializer()
+ .parseBatchRequest(request.getBody(), boundary, options);
+
+ ODataResponsePart partResponse = null;
+ final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
+
+ for (BatchRequestPart part : parts) {
+ if (part.isChangeSet()) {
+ String txnId = handler.startTransaction();
+ partResponse = processChangeSet(part, handler);
+ if (partResponse.getResponses().get(0).getStatusCode() > 400) {
+ handler.rollback(txnId);
+ }
+ handler.commit(txnId);
+ } else {
+ // single request, a static request
+ ODataRequest partRequest = part.getRequests().get(0);
+ partResponse = process(partRequest, handler);
+ }
+ responseParts.add(partResponse);
+
+ // on error, should we continue?
+ final int statusCode = partResponse.getResponses().get(0).getStatusCode();
+ if ((statusCode >= 400 && statusCode <= 600) && !continueOnError) {
+ break;
+ }
+ }
+
+ // send response
+ final String responseBoundary = "batch_" + UUID.randomUUID().toString();
+ ;
+ final InputStream responseContent = odata.createFixedFormatSerializer().batchResponse(
+ responseParts, responseBoundary);
+ response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.MULTIPART_MIXED + ";boundary="
+ + responseBoundary);
+ response.setContent(responseContent);
+ response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
+ }
+
+ ODataResponsePart process(ODataRequest partRequest, ServiceHandler serviceHandler) {
+ ODataResponse partResponse = executeSingleRequest(partRequest, serviceHandler);
+ addContentID(partRequest, partResponse);
+ return new ODataResponsePart(partResponse, false);
+ }
+
+ ODataResponsePart processChangeSet(BatchRequestPart partRequest, ServiceHandler serviceHandler)
+ throws BatchDeserializerException {
+ List<ODataResponse> changeSetResponses = new ArrayList<ODataResponse>();
+ // change set need to be a in a atomic operation
+ for (ODataRequest changeSetPartRequest : partRequest.getRequests()) {
+
+ this.rewriter.replaceReference(changeSetPartRequest);
+
+ ODataResponse partResponse = executeSingleRequest(changeSetPartRequest, serviceHandler);
+
+ this.rewriter.addMapping(changeSetPartRequest, partResponse);
+ addContentID(changeSetPartRequest, partResponse);
+
+ if (partResponse.getStatusCode() < 400) {
+ changeSetResponses.add(partResponse);
+ } else {
+ // 11.7.4 Responding to a Batch Request
+ return new ODataResponsePart(partResponse, false);
+ }
+ }
+ return new ODataResponsePart(changeSetResponses, true);
+ }
+
+ ODataResponse executeSingleRequest(ODataRequest singleRequest, ServiceHandler handler) {
+ ServiceDispatcher dispatcher = new ServiceDispatcher(this.odata, this.serviceMetadata, handler,
+ this.customContentType);
+ ODataResponse res = new ODataResponse();
+ try {
+ dispatcher.execute(singleRequest, res);
+ } catch (Exception e) {
+ ErrorHandler ehandler = new ErrorHandler(this.odata, this.serviceMetadata,
+ getCustomContentTypeSupport());
+ ehandler.handleException(e, singleRequest, res);
+ }
+ return res;
+ }
+
+ private void addContentID(ODataRequest batchPartRequest, ODataResponse batchPartResponse) {
+ final String contentId = batchPartRequest.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
+ if (contentId != null) {
+ batchPartResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, contentId);
+ }
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ return isPOST();
+ }
+
+ private void validateContentType() throws ODataApplicationException {
+ final String contentType = getRequestContentType().toContentTypeString();
+
+ if (contentType == null
+ || !BatchParserCommon.PATTERN_MULTIPART_BOUNDARY.matcher(contentType).matches()) {
+ throw new ODataApplicationException("Invalid content type",
+ HttpStatusCode.PRECONDITION_FAILED.getStatusCode(), Locale.getDefault());
+ }
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return null;
+ }
+
+ private boolean isContinueOnError() {
+ final List<String> preferValues = this.request.getHeaders(HttpHeader.PREFER);
+
+ if (preferValues != null) {
+ for (final String preference : preferValues) {
+ if (PREFERENCE_CONTINUE_ON_ERROR.equals(preference)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private String extractBoundary(ContentType contentType) throws BatchDeserializerException {
+ return BatchParserCommon.getBoundary(contentType.toContentTypeString(), 0);
+ }
+}
[32/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin as example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java
new file mode 100644
index 0000000..8641a69
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java
@@ -0,0 +1,315 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.Action;
+import org.apache.olingo.commons.api.edm.provider.ActionImport;
+import org.apache.olingo.commons.api.edm.provider.AliasInfo;
+import org.apache.olingo.commons.api.edm.provider.Annotatable;
+import org.apache.olingo.commons.api.edm.provider.Annotations;
+import org.apache.olingo.commons.api.edm.provider.ComplexType;
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.commons.api.edm.provider.EntityContainer;
+import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.commons.api.edm.provider.EntitySet;
+import org.apache.olingo.commons.api.edm.provider.EntityType;
+import org.apache.olingo.commons.api.edm.provider.EnumType;
+import org.apache.olingo.commons.api.edm.provider.Function;
+import org.apache.olingo.commons.api.edm.provider.FunctionImport;
+import org.apache.olingo.commons.api.edm.provider.Schema;
+import org.apache.olingo.commons.api.edm.provider.Singleton;
+import org.apache.olingo.commons.api.edm.provider.Term;
+import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
+
+public class SchemaBasedEdmProvider implements EdmProvider {
+ private final List<Schema> edmSchemas = new ArrayList<Schema>();
+
+ protected void addSchema(Schema schema) {
+ this.edmSchemas.add(schema);
+ }
+
+ private Schema getSchema(String ns) {
+ for (Schema s : this.edmSchemas) {
+ if (s.getNamespace().equals(ns)) {
+ return s;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EnumType getEnumType(FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<EnumType> types = schema.getEnumTypes();
+ if (types != null) {
+ for (EnumType type : types) {
+ if (type.getName().equals(fqn.getName())) {
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public TypeDefinition getTypeDefinition(FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<TypeDefinition> types = schema.getTypeDefinitions();
+ if (types != null) {
+ for (TypeDefinition type : types) {
+ if (type.getName().equals(fqn.getName())) {
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Function> getFunctions(FullQualifiedName fqn) throws ODataException {
+ ArrayList<Function> foundFuncs = new ArrayList<Function>();
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<Function> functions = schema.getFunctions();
+ if (functions != null) {
+ for (Function func : functions) {
+ if (func.getName().equals(fqn.getName())) {
+ foundFuncs.add(func);
+ }
+ }
+ }
+ }
+ return foundFuncs;
+ }
+
+ @Override
+ public Term getTerm(FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<Term> terms = schema.getTerms();
+ if (terms != null) {
+ for (Term term : terms) {
+ if (term.getName().equals(fqn.getName())) {
+ return term;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(FullQualifiedName fqn, String entitySetName) throws ODataException {
+ Schema schema = getSchema(fqn.getFullQualifiedNameAsString());
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null && ec.getEntitySets() != null) {
+ for (EntitySet es : ec.getEntitySets()) {
+ if (es.getName().equals(entitySetName)) {
+ return es;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Singleton getSingleton(FullQualifiedName fqn, String singletonName) throws ODataException {
+ Schema schema = getSchema(fqn.getFullQualifiedNameAsString());
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null && ec.getSingletons() != null) {
+ for (Singleton es : ec.getSingletons()) {
+ if (es.getName().equals(singletonName)) {
+ return es;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ActionImport getActionImport(FullQualifiedName fqn, String actionImportName)
+ throws ODataException {
+ Schema schema = getSchema(fqn.getFullQualifiedNameAsString());
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null && ec.getActionImports() != null) {
+ for (ActionImport es : ec.getActionImports()) {
+ if (es.getName().equals(actionImportName)) {
+ return es;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(FullQualifiedName fqn, String functionImportName)
+ throws ODataException {
+ Schema schema = getSchema(fqn.getFullQualifiedNameAsString());
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null && ec.getFunctionImports() != null) {
+ for (FunctionImport es : ec.getFunctionImports()) {
+ if (es.getName().equals(functionImportName)) {
+ return es;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(FullQualifiedName fqn) throws ODataException {
+ Schema schema = null;
+
+ if (fqn == null) {
+ for (Schema s : this.edmSchemas) {
+ if (s.getEntityContainer() != null) {
+ schema = s;
+ break;
+ }
+ }
+ } else {
+ schema = getSchema(fqn.getFullQualifiedNameAsString());
+ }
+
+ if (schema != null) {
+ EntityContainer ec = schema.getEntityContainer();
+ if (ec != null) {
+ EntityContainerInfo info = new EntityContainerInfo();
+ info.setContainerName(new FullQualifiedName(schema.getNamespace()));
+ if (schema.getEntityContainer().getExtendsContainer() != null) {
+ info.setExtendsContainer(new FullQualifiedName(schema.getEntityContainer().getExtendsContainer()));
+ }
+ return info;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<AliasInfo> getAliasInfos() throws ODataException {
+ Schema schema = null;
+ for (Schema s : this.edmSchemas) {
+ if (s.getEntityContainer() != null) {
+ schema = s;
+ break;
+ }
+ }
+
+ if (schema == null) {
+ schema = this.edmSchemas.get(0);
+ }
+
+ AliasInfo ai = new AliasInfo();
+ ai.setAlias(schema.getAlias());
+ ai.setNamespace(schema.getNamespace());
+ return Arrays.asList(ai);
+ }
+
+ @Override
+ public EntityContainer getEntityContainer() throws ODataException {
+ // note that there can be many schemas, but only one needs to contain the
+ // entity container in a given metadata document.
+ for (Schema s : this.edmSchemas) {
+ if (s.getEntityContainer() != null) {
+ return s.getEntityContainer();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ return new ArrayList<Schema>(this.edmSchemas);
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ if (schema.getEntityTypes() != null) {
+ for (EntityType type : schema.getEntityTypes()) {
+ if (type.getName().equals(fqn.getName())) {
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName fqn) throws ODataException {
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ if (schema.getComplexTypes() != null) {
+ for (ComplexType type : schema.getComplexTypes()) {
+ if (type.getName().equals(fqn.getName())) {
+ return type;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Action> getActions(final FullQualifiedName fqn) throws ODataException {
+ ArrayList<Action> actions = new ArrayList<Action>();
+ Schema schema = getSchema(fqn.getNamespace());
+ if (schema != null) {
+ List<Action> types = schema.getActions();
+ if (types != null) {
+ for (Action type : types) {
+ if (type.getName().equals(fqn.getName())) {
+ actions.add(type);
+ }
+ }
+ }
+ }
+ return actions;
+ }
+
+ @Override
+ public Annotations getAnnotationsGroup(FullQualifiedName targetName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public Annotatable getAnnoatatable(FullQualifiedName annotatedName) throws ODataException {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
new file mode 100644
index 0000000..839d877
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
@@ -0,0 +1,227 @@
+/*
+ * 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.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoBatch;
+import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
+import org.apache.olingo.server.api.uri.UriInfoEntityId;
+import org.apache.olingo.server.api.uri.UriInfoMetadata;
+import org.apache.olingo.server.api.uri.UriInfoService;
+import org.apache.olingo.server.api.uri.UriResourceAction;
+import org.apache.olingo.server.api.uri.UriResourceComplexProperty;
+import org.apache.olingo.server.api.uri.UriResourceCount;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
+import org.apache.olingo.server.api.uri.UriResourceRef;
+import org.apache.olingo.server.api.uri.UriResourceSingleton;
+import org.apache.olingo.server.api.uri.UriResourceValue;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.BatchRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.requests.ServiceDocumentRequest;
+import org.apache.olingo.server.core.uri.parser.Parser;
+import org.apache.olingo.server.core.uri.validator.UriValidator;
+
+public class ServiceDispatcher extends RequestURLHierarchyVisitor {
+ private final OData odata;
+ protected ServiceMetadata metadata;
+ protected ServiceHandler handler;
+ protected CustomContentTypeSupport customContentSupport;
+ private String idOption;
+ protected ServiceRequest request;
+
+ public ServiceDispatcher(OData odata, ServiceMetadata metadata, ServiceHandler handler,
+ CustomContentTypeSupport customContentSupport) {
+ this.odata = odata;
+ this.metadata = metadata;
+ this.handler = handler;
+ this.customContentSupport = customContentSupport;
+ }
+
+ public void execute(ODataRequest odRequest, ODataResponse odResponse)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ UriInfo uriInfo = new Parser().parseUri(odRequest.getRawODataPath(), odRequest.getRawQueryPath(), null,
+ this.metadata.getEdm());
+
+ new UriValidator().validate(uriInfo, odRequest.getMethod());
+
+ visit(uriInfo);
+
+ // this should cover for any unsupported calls until they are implemented
+ if (this.request == null) {
+ this.request = new ServiceRequest(this.odata, this.metadata) {
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentType.APPLICATION_JSON;
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ handler.anyUnsupported(getODataRequest(), response);
+ }
+ };
+ }
+
+ // To handle $entity?$id=http://localhost/EntitySet(key) as
+ // http://localhost/EntitySet(key)
+ if (this.idOption != null) {
+ try {
+ this.request = this.request.parseLink(new URI(this.idOption));
+ } catch (URISyntaxException e) {
+ throw new ODataHandlerException("Invalid $id value",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED, this.idOption);
+ }
+ }
+
+ this.request.setODataRequest(odRequest);
+ this.request.setUriInfo(uriInfo);
+ this.request.setCustomContentTypeSupport(this.customContentSupport);
+ this.request.execute(this.handler, odResponse);
+ }
+
+ @Override
+ public void visit(UriInfoMetadata info) {
+ this.request = new MetadataRequest(this.odata, this.metadata);
+ }
+
+ @Override
+ public void visit(UriInfoService info) {
+ this.request = new ServiceDocumentRequest(this.odata, this.metadata);
+ }
+
+ @Override
+ public void visit(UriResourceEntitySet info) {
+ DataRequest dataRequest = new DataRequest(this.odata, this.metadata);
+ dataRequest.setUriResourceEntitySet(info);
+ this.request = dataRequest;
+ }
+
+ @Override
+ public void visit(UriResourceCount option) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.setCountRequest(option != null);
+ }
+
+ @Override
+ public void visit(UriResourceComplexProperty info) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.setUriResourceProperty(info);
+ }
+
+ @Override
+ public void visit(UriResourcePrimitiveProperty info) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.setUriResourceProperty(info);
+ }
+
+ @Override
+ public void visit(UriResourceValue info) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ if (dataRequest.isPropertyRequest()) {
+ dataRequest.setValueRequest(info != null);
+ } else {
+ MediaRequest mediaRequest = new MediaRequest(this.odata, this.metadata);
+ mediaRequest.setUriResourceEntitySet(dataRequest.getUriResourceEntitySet());
+ this.request = mediaRequest;
+ }
+ }
+
+ @Override
+ public void visit(UriResourceAction info) {
+ ActionRequest actionRequest = new ActionRequest(this.odata, this.metadata);
+ actionRequest.setUriResourceAction(info);
+ this.request = actionRequest;
+ }
+
+ @Override
+ public void visit(UriResourceFunction info) {
+ FunctionRequest functionRequest = new FunctionRequest(this.odata, this.metadata);
+ functionRequest.setUriResourceFunction(info);
+ this.request = functionRequest;
+ }
+
+ @Override
+ public void visit(UriResourceNavigation info) {
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.addUriResourceNavigation(info);
+ }
+
+ @Override
+ public void visit(UriResourceRef info) {
+ // this is same as data, but return is just entity references.
+ DataRequest dataRequest = (DataRequest) this.request;
+ dataRequest.setReferenceRequest(info != null);
+ }
+
+ @Override
+ public void visit(UriInfoBatch info) {
+ this.request = new BatchRequest(this.odata, this.metadata);
+ }
+
+ @Override
+ public void visit(UriResourceSingleton info) {
+ DataRequest dataRequest = new DataRequest(this.odata, this.metadata);
+ dataRequest.setUriResourceSingleton(info);
+ this.request = dataRequest;
+ }
+
+ @Override
+ public void visit(UriInfoEntityId info) {
+ DataRequest dataRequest = new DataRequest(this.odata, this.metadata);
+ this.request = dataRequest;
+
+ // this can relative or absolute form
+ String id = info.getIdOption().getValue();
+ try {
+ URL url = new URL(id);
+ this.idOption = url.getPath();
+ } catch (MalformedURLException e) {
+ this.idOption = id;
+ }
+ super.visit(info);
+ }
+
+ @Override
+ public void visit(UriInfoCrossjoin info) {
+ DataRequest dataRequest = new DataRequest(this.odata, this.metadata);
+ dataRequest.setCrossJoin(info);
+ this.request = dataRequest;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
new file mode 100644
index 0000000..8a9c610
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
@@ -0,0 +1,263 @@
+/*
+ * 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 java.net.URI;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.processor.Processor;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.requests.ServiceDocumentRequest;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.ServiceDocumentResponse;
+import org.apache.olingo.server.core.responses.ServiceResponse;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public interface ServiceHandler extends Processor {
+
+ /**
+ * Read CSDL document of the Service
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void readMetadata(MetadataRequest request, MetadataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Read ServiceDocument of the service
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void readServiceDocument(ServiceDocumentRequest request, ServiceDocumentResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Read operation for EntitySets, Entities, Properties, Media etc. Based on the type of request
+ * the response object is different. Even the navigation based queries are handled by this method.
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ <T extends ServiceResponse> void read(DataRequest request, T response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Create new entity in the service based on the entity object provided
+ * @param request
+ * @param entity
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void createEntity(DataRequest request, Entity entity, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update the entity object.
+ * @param request
+ * @param entity
+ * @param merge - true if merge operation, false it needs to be replaced
+ * @param entityETag - previous entity tag if provided by the user. "*" means allow.
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
+ EntityResponse response) throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Delete the Entity
+ * @param request
+ * @param entityETag - entity tag to match, if provided by the user. "*" means allow
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void deleteEntity(DataRequest request, String entityETag, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update a non-media/stream property.if the value of property NULL, it should be treated as
+ * DeleteProperty 11.4.9.2
+ * @param request
+ * @param property - Updated property.
+ * @param merge - if the property is complex, true here means merge, false is replace
+ * @param entityETag - entity tag to match before update operation, "*" allows all.
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void updateProperty(DataRequest request, Property property, boolean merge, String entityETag,
+ PropertyResponse response) throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update Stream property, if StreamContent is null, it should treated as delete request
+ * @param request
+ * @param entityETag - entity tag to match before update operation, "*" allows all.
+ * @param streamContent - updated stream content
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void upsertStreamProperty(DataRequest request, String entityETag, InputStream streamContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Invocation of a Function. The response object will be based on metadata defined for service
+ * @param request
+ * @param method
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ <T extends ServiceResponse> void invoke(FunctionRequest request, HttpMethod method, T response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Invocation of a Function. The response object will be based on metadata defined for service
+ * @param request
+ * @param eTag
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Read media stream content of a Entity
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void readMediaStream(MediaRequest request, StreamResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update of Media Stream Content of a Entity. If the mediaContent is null it should be treated
+ * as delete request.
+ * @param request
+ * @param entityETag - entity etag to match before update operation, "*" allows all.
+ * @param mediaContent - if null, must be treated as delete request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void upsertMediaStream(MediaRequest request, String entityETag, InputStream mediaContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Any Unsupported one will be directed here.
+ * @param request
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void anyUnsupported(ODataRequest request, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Add references (relationships) to Entity.
+ * @param request
+ * @param entityETag - entity etag to match before add operation, "*" allows all.
+ * @param idReferences - references to add
+ * @param response - return always should be 204
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void addReference(DataRequest request, String entityETag, List<URI> idReferences, NoContentResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Update references (relationships) in an Entity
+ * @param request
+ * @param entityETag
+ * @param referenceId
+ * @param response - always should be 204
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void updateReference(DataRequest request, String entityETag, URI referenceId, NoContentResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ /**
+ * Delete references (relationships) in an Entity
+ * @param request
+ * @param deleteId
+ * @param entityETag
+ * @param response - always should be 204
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void deleteReference(DataRequest request, URI deleteId, String entityETag, NoContentResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+
+ /**
+ * During a batch operation, this method starts the transaction (if any) before any operation is handled
+ * by the service. No nested transactions.
+ * @return must return a unique transaction id that references a atomic operation.
+ */
+ String startTransaction();
+
+ /**
+ * When a batch operation is complete and all the intermediate service requests are successful, then
+ * commit is called with transaction id returned in the startTransaction method.
+ * @param txnId
+ */
+ void commit(String txnId);
+ /**
+ * When a batch operation is in-complete due to an error in the middle of changeset, then rollback is
+ * called with transaction id, that returned from startTransaction method.
+ * @param txnId
+ */
+ void rollback(String txnId);
+
+ /**
+ * This is not complete, more URL parsing changes required. Cross join between two entities.
+ * @param dataRequest
+ * @param entitySetNames
+ * @param response
+ * @throws ODataTranslatedException
+ * @throws ODataApplicationException
+ */
+ void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
new file mode 100644
index 0000000..e9a8cfe
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
@@ -0,0 +1,253 @@
+/*
+ * 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.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
+import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
+import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.uri.parser.Parser;
+import org.apache.olingo.server.core.uri.parser.UriParserException;
+
+public abstract class ServiceRequest {
+ protected OData odata;
+ protected UriInfo uriInfo;
+ protected ServiceMetadata serviceMetadata;
+ protected CustomContentTypeSupport customContentType;
+ protected ODataRequest request;
+
+ public ServiceRequest(OData odata, ServiceMetadata serviceMetadata) {
+ this.odata = odata;
+ this.serviceMetadata = serviceMetadata;
+ }
+
+ public OData getOdata() {
+ return odata;
+ }
+
+ public ServiceMetadata getServiceMetaData() {
+ return this.serviceMetadata;
+ }
+
+ public UriInfo getUriInfo() {
+ return uriInfo;
+ }
+
+ protected void setUriInfo(UriInfo uriInfo) {
+ this.uriInfo = uriInfo;
+ }
+
+ public boolean allowedMethod() {
+ return isGET();
+ }
+
+ public CustomContentTypeSupport getCustomContentTypeSupport() {
+ return this.customContentType;
+ }
+
+ public void setCustomContentTypeSupport(CustomContentTypeSupport support) {
+ this.customContentType = support;
+ }
+
+ public ODataRequest getODataRequest() {
+ return this.request;
+ }
+
+ protected void setODataRequest(ODataRequest request) {
+ this.request = request;
+ }
+
+ public ContentType getRequestContentType() {
+ if (this.request.getHeader(HttpHeader.CONTENT_TYPE) != null) {
+ return ContentType.parse(this.request.getHeader(HttpHeader.CONTENT_TYPE));
+ }
+ return ContentType.APPLICATION_OCTET_STREAM;
+ }
+
+ public abstract void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+
+ public abstract ContentType getResponseContentType() throws ContentNegotiatorException;
+
+ public void methodNotAllowed() throws ODataHandlerException {
+ throw new ODataHandlerException("HTTP method " + this.request.getMethod() + " is not allowed.",
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, this.request.getMethod()
+ .toString());
+ }
+
+ public void notImplemented() throws ODataHandlerException {
+ throw new ODataHandlerException("not implemented", //$NON-NLS-1$
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ }
+
+ protected boolean isGET() {
+ return this.request.getMethod() == HttpMethod.GET;
+ }
+
+ protected boolean isPUT() {
+ return this.request.getMethod() == HttpMethod.PUT;
+ }
+
+ protected boolean isDELETE() {
+ return this.request.getMethod() == HttpMethod.DELETE;
+ }
+
+ protected boolean isPATCH() {
+ return this.request.getMethod() == HttpMethod.PATCH;
+ }
+
+ protected boolean isPOST() {
+ return this.request.getMethod() == HttpMethod.POST;
+ }
+
+ public <T> T getSerializerOptions(Class<T> serilizerOptions, ContextURL contextUrl,
+ boolean references) throws ContentNegotiatorException {
+ final ODataFormat format = ODataFormat.fromContentType(getResponseContentType());
+
+ if (serilizerOptions.isAssignableFrom(EntitySerializerOptions.class)) {
+ return (T) EntitySerializerOptions.with()
+ .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : contextUrl)
+ .expand(uriInfo.getExpandOption()).select(this.uriInfo.getSelectOption())
+ .setWriteOnlyReferences(references).build();
+ } else if (serilizerOptions.isAssignableFrom(EntityCollectionSerializerOptions.class)) {
+ return (T) EntityCollectionSerializerOptions.with()
+ .contextURL(format == ODataFormat.JSON_NO_METADATA ? null : contextUrl)
+ .count(uriInfo.getCountOption()).expand(uriInfo.getExpandOption())
+ .select(uriInfo.getSelectOption()).setWriteOnlyReferences(references).build();
+ } else if (serilizerOptions.isAssignableFrom(ComplexSerializerOptions.class)) {
+ return (T) ComplexSerializerOptions.with().contextURL(contextUrl)
+ .expand(this.uriInfo.getExpandOption()).select(this.uriInfo.getSelectOption()).build();
+ }
+ return null;
+ }
+
+ public ReturnRepresentation getReturnRepresentation() {
+ String prefer = this.request.getHeader(HttpHeader.PREFER);
+ if (prefer == null) {
+ return ReturnRepresentation.REPRESENTATION;
+ }
+ if (prefer.contains("return=minimal")) { //$NON-NLS-1$
+ return ReturnRepresentation.MINIMAL;
+ }
+ return ReturnRepresentation.REPRESENTATION;
+ }
+
+ public String getHeader(String key) {
+ return this.request.getHeader(key);
+ }
+
+ public String getETag() {
+ String etag = getHeader(HttpHeader.IF_MATCH);
+ if (etag == null) {
+ etag = getHeader(HttpHeader.IF_NONE_MATCH);
+ }
+ return ((etag == null) ? "*" : etag); //$NON-NLS-1$
+ }
+
+ public ODataSerializer getSerializer() throws ContentNegotiatorException,
+ SerializerException {
+ ODataFormat format = ODataFormat.fromContentType(getResponseContentType());
+ return this.odata.createSerializer(format);
+ }
+
+ public Map<String, String> getPreferences(){
+ HashMap<String, String> map = new HashMap<String, String>();
+ List<String> headers = request.getHeaders(HttpHeader.PREFER);
+ if (headers != null) {
+ for (String header:headers) {
+ int idx = header.indexOf('=');
+ if (idx != -1) {
+ String key = header.substring(0, idx);
+ String value = header.substring(idx+1);
+ if (value.startsWith("\"")) {
+ value = value.substring(1);
+ }
+ if (value.endsWith("\"")) {
+ value = value.substring(0, value.length()-1);
+ }
+ map.put(key, value);
+ } else {
+ map.put(header, "true");
+ }
+ }
+ }
+ return map;
+ }
+
+ public String getPreference(String key) {
+ return getPreferences().get(key);
+ }
+
+ public String getQueryParameter(String param) {
+ String queryPath = getODataRequest().getRawQueryPath();
+ if (queryPath != null) {
+ StringTokenizer st = new StringTokenizer(queryPath, ",");
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken();
+ int index = token.indexOf('=');
+ if (index != -1) {
+ String key = token.substring(0, index);
+ String value = token.substring(index+1);
+ if (key.equals(param)) {
+ return value;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public DataRequest parseLink(URI uri) throws UriParserException {
+ String rawPath = uri.getPath();
+ int e = rawPath.indexOf("/", 1);
+ if (-1 == e) {
+ rawPath = uri.getPath();
+ } else {
+ rawPath = rawPath.substring(e);
+ }
+
+ UriInfo uriInfo = new Parser().parseUri(rawPath, uri.getQuery(), null,
+ this.serviceMetadata.getEdm());
+ ServiceDispatcher dispatcher = new ServiceDispatcher(odata, serviceMetadata, null, customContentType);
+ dispatcher.visit(uriInfo);
+ return (DataRequest)dispatcher.request;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java
new file mode 100644
index 0000000..fa8f445
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java
@@ -0,0 +1,433 @@
+/*
+ * 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.legacy;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.processor.ComplexCollectionProcessor;
+import org.apache.olingo.server.api.processor.ComplexProcessor;
+import org.apache.olingo.server.api.processor.CountComplexCollectionProcessor;
+import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
+import org.apache.olingo.server.api.processor.CountPrimitiveCollectionProcessor;
+import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
+import org.apache.olingo.server.api.processor.EntityProcessor;
+import org.apache.olingo.server.api.processor.MediaEntityProcessor;
+import org.apache.olingo.server.api.processor.MetadataProcessor;
+import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
+import org.apache.olingo.server.api.processor.PrimitiveProcessor;
+import org.apache.olingo.server.api.processor.PrimitiveValueProcessor;
+import org.apache.olingo.server.api.processor.Processor;
+import org.apache.olingo.server.api.processor.ReferenceProcessor;
+import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
+import org.apache.olingo.server.core.ODataHandlerException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.requests.ServiceDocumentRequest;
+import org.apache.olingo.server.core.responses.CountResponse;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.ServiceDocumentResponse;
+import org.apache.olingo.server.core.responses.ServiceResponse;
+import org.apache.olingo.server.core.responses.ServiceResponseVisior;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public class ProcessorServiceHandler implements ServiceHandler {
+ private final List<Processor> processors = new LinkedList<Processor>();
+ private OData odata;
+ private ServiceMetadata serviceMetadata;
+
+ @Override
+ public void init(OData odata, ServiceMetadata serviceMetadata) {
+ this.odata = odata;
+ this.serviceMetadata = serviceMetadata;
+ }
+
+ public void register(Processor processor) {
+ this.processors.add(processor);
+ processor.init(odata, serviceMetadata);
+ }
+
+ private <T extends Processor> T selectProcessor(final Class<T> cls) throws ODataHandlerException {
+ for (final Processor processor : processors) {
+ if (cls.isAssignableFrom(processor.getClass())) {
+ processor.init(odata, serviceMetadata);
+ return cls.cast(processor);
+ }
+ }
+ throw new ODataHandlerException("Processor: " + cls.getSimpleName() + " not registered.",
+ ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED, cls.getSimpleName());
+ }
+
+ @Override
+ public void readMetadata(MetadataRequest request, MetadataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(MetadataProcessor.class).readMetadata(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public void readServiceDocument(ServiceDocumentRequest request, ServiceDocumentResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(ServiceDocumentProcessor.class).readServiceDocument(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public <T extends ServiceResponse> void read(final DataRequest request, final T response)
+ throws ODataTranslatedException, ODataApplicationException {
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(CountResponse response) throws ODataTranslatedException, ODataApplicationException {
+ if (request.getUriResourceProperty() != null) {
+ EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
+ if (edmProperty.isPrimitive()) {
+ selectProcessor(CountPrimitiveCollectionProcessor.class).countPrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo());
+ } else {
+ selectProcessor(CountComplexCollectionProcessor.class).countComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo());
+ }
+ } else {
+ selectProcessor(CountEntityCollectionProcessor.class).countEntityCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo());
+ }
+ }
+
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityProcessor.class).readEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public void visit(PrimitiveValueResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(PrimitiveValueProcessor.class).readPrimitiveValue(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+
+ @Override
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
+ if (edmProperty.isPrimitive()) {
+ if(edmProperty.isCollection()) {
+ selectProcessor(PrimitiveCollectionProcessor.class).readPrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(PrimitiveProcessor.class).readPrimitive(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ } else {
+ if(edmProperty.isCollection()) {
+ selectProcessor(ComplexCollectionProcessor.class).readComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(ComplexProcessor.class).readComplex(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ }
+ }
+ }
+
+ @Override
+ public void visit(StreamResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ @Override
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityCollectionProcessor.class).readEntityCollection(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+ });
+ }
+
+ @Override
+ public void createEntity(DataRequest request, Entity entity, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ if (request.getEntitySet().getEntityType().hasStream()) {
+ selectProcessor(MediaEntityProcessor.class).createMediaEntity(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(),request.getResponseContentType());
+ } else {
+ selectProcessor(EntityProcessor.class).createEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getRequestContentType(),
+ request.getResponseContentType());
+ }
+ }
+
+ @Override
+ public void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
+ EntityResponse response) throws ODataTranslatedException, ODataApplicationException {
+ if (request.getEntitySet().getEntityType().hasStream()) {
+ selectProcessor(MediaEntityProcessor.class).updateMediaEntity(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(),request.getResponseContentType());
+ } else {
+ selectProcessor(EntityProcessor.class).updateEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getRequestContentType(),
+ request.getResponseContentType());
+ }
+ }
+
+ @Override
+ public void deleteEntity(DataRequest request, String entityETag, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(EntityProcessor.class).deleteEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo());
+ }
+
+ @Override
+ public void updateProperty(DataRequest request, Property property, boolean merge,
+ String entityETag, PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (property.isPrimitive()) {
+ if (property.isCollection()) {
+ selectProcessor(PrimitiveCollectionProcessor.class).updatePrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ } else {
+ selectProcessor(PrimitiveProcessor.class).updatePrimitive(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ }
+ } else {
+ if (property.isCollection()) {
+ selectProcessor(ComplexCollectionProcessor.class).updateComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ } else {
+ selectProcessor(ComplexProcessor.class).updateComplex(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ }
+ }
+ }
+
+ @Override
+ public void upsertStreamProperty(DataRequest request, String entityETag,
+ InputStream streamContent, NoContentResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ }
+
+ @Override
+ public <T extends ServiceResponse> void invoke(final FunctionRequest request, HttpMethod method,
+ final T response) throws ODataTranslatedException, ODataApplicationException {
+ if (method != HttpMethod.GET) {
+ throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
+ }
+
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityProcessor.class).readEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (request.isReturnTypePrimitive()) {
+ if(request.isCollection()) {
+ selectProcessor(PrimitiveCollectionProcessor.class).readPrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(PrimitiveProcessor.class).readPrimitive(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ } else {
+ if(request.isCollection()) {
+ selectProcessor(ComplexCollectionProcessor.class).readComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(ComplexProcessor.class).readComplex(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ }
+ }
+ @Override
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityCollectionProcessor.class).readEntityCollection(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+ });
+ }
+
+ @Override
+ public <T extends ServiceResponse> void invoke(final ActionRequest request, String eTag, final T response)
+ throws ODataTranslatedException, ODataApplicationException {
+ final HttpMethod method = request.getODataRequest().getMethod();
+ if (method != HttpMethod.POST) {
+ throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
+ ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
+ }
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityProcessor.class).readEntity(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+
+ @Override
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (request.isReturnTypePrimitive()) {
+ if(request.isCollection()) {
+ selectProcessor(PrimitiveCollectionProcessor.class).readPrimitiveCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(PrimitiveProcessor.class).readPrimitive(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ } else {
+ if(request.isCollection()) {
+ selectProcessor(ComplexCollectionProcessor.class).readComplexCollection(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+
+ } else {
+ selectProcessor(ComplexProcessor.class).readComplex(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+ }
+ }
+ @Override
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ selectProcessor(EntityCollectionProcessor.class).readEntityCollection(request.getODataRequest(),
+ response.getODataResponse(), request.getUriInfo(), request.getResponseContentType());
+ }
+ });
+ }
+
+
+ @Override
+ public void readMediaStream(MediaRequest request, StreamResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(MediaEntityProcessor.class).readMediaEntity(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+
+ @Override
+ public void upsertMediaStream(MediaRequest request, String entityETag, InputStream mediaContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(MediaEntityProcessor.class).updateMediaEntity(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getRequestContentType(), request.getResponseContentType());
+ }
+
+ @Override
+ public void anyUnsupported(ODataRequest request, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ }
+
+ @Override
+ public void addReference(DataRequest request, String entityETag, List<URI> idReferences,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(ReferenceProcessor.class).createReference(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+
+ @Override
+ public void updateReference(DataRequest request, String entityETag, URI referenceId,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(ReferenceProcessor.class).updateReference(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo(),
+ request.getResponseContentType());
+ }
+
+ @Override
+ public void deleteReference(DataRequest request, URI deleteId, String entityETag,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ selectProcessor(ReferenceProcessor.class).deleteReference(
+ request.getODataRequest(), response.getODataResponse(), request.getUriInfo());
+ }
+
+ @Override
+ public String startTransaction() {
+ return null;
+ }
+
+ @Override
+ public void commit(String txnId) {
+ }
+
+ @Override
+ public void rollback(String txnId) {
+ }
+
+ @Override
+ public void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ throw new ODataHandlerException("not implemented",
+ ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ActionRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ActionRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ActionRequest.java
new file mode 100644
index 0000000..133ee3e
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ActionRequest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.requests;
+
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.uri.UriResourceAction;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+
+public class ActionRequest extends OperationRequest {
+ private UriResourceAction uriResourceAction;
+
+ public ActionRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+ // Actions MAY return data but MUST NOT be further composed with additional
+ // path segments.
+ // On success, the response is 201 Created for actions that create entities,
+ // 200 OK for actions
+ // that return results or 204 No Content for action without a return type.
+ // The client can request
+ // whether any results from the action be returned using the Prefer header.
+
+ if (!hasReturnType()) {
+ handler.invoke(this, getETag(), new NoContentResponse(getServiceMetaData(), response));
+ } else {
+ if (isReturnTypePrimitive()) {
+ handler.invoke(this, getETag(),
+ PrimitiveValueResponse.getInstance(this, response, isCollection(), getReturnType()));
+ } else if (isReturnTypeComplex()) {
+ handler.invoke(this, getETag(), PropertyResponse.getInstance(this, response,
+ getReturnType().getType(), getContextURL(this.odata), isCollection()));
+ } else {
+ // EdmTypeKind.ENTITY
+ if (isCollection()) {
+ handler.invoke(this, getETag(),
+ EntitySetResponse.getInstance(this, getContextURL(odata), false, response));
+ } else {
+ handler.invoke(this, getETag(),
+ EntityResponse.getInstance(this, getContextURL(odata), false, response));
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ // 11.5.4.1 Invoking an Action - only allows POST
+ return (isPOST());
+ }
+
+ public UriResourceAction getUriResourceAction() {
+ return uriResourceAction;
+ }
+
+ public void setUriResourceAction(UriResourceAction uriResourceAction) {
+ this.uriResourceAction = uriResourceAction;
+ }
+
+ @Override
+ public boolean isBound() {
+ return this.uriResourceAction.getActionImport() != null;
+ }
+
+ public EdmAction getAction() {
+ return this.uriResourceAction.getAction();
+ }
+
+ @Override
+ public boolean isCollection() {
+ assert (hasReturnType());
+ return getAction().getReturnType().isCollection();
+ }
+
+ @Override
+ public EdmReturnType getReturnType() {
+ assert (hasReturnType());
+ return getAction().getReturnType();
+ }
+
+ @Override
+ public boolean hasReturnType() {
+ return getAction().getReturnType() != null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
new file mode 100644
index 0000000..25af023
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
@@ -0,0 +1,197 @@
+/*
+ * 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.requests;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.UUID;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
+import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
+import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
+import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ErrorHandler;
+import org.apache.olingo.server.core.ServiceDispatcher;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.batchhandler.referenceRewriting.BatchReferenceRewriter;
+import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
+
+public class BatchRequest extends ServiceRequest {
+ private static final String PREFERENCE_CONTINUE_ON_ERROR = "odata.continue-on-error";
+ private final BatchReferenceRewriter rewriter;
+
+ public BatchRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ this.rewriter = new BatchReferenceRewriter();
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+
+ validateContentType();
+ boolean continueOnError = isContinueOnError();
+ final String boundary = extractBoundary(getRequestContentType());
+
+ final BatchOptions options = BatchOptions.with().rawBaseUri(request.getRawBaseUri())
+ .rawServiceResolutionUri(this.request.getRawServiceResolutionUri()).build();
+
+ final List<BatchRequestPart> parts = this.odata.createFixedFormatDeserializer()
+ .parseBatchRequest(request.getBody(), boundary, options);
+
+ ODataResponsePart partResponse = null;
+ final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
+
+ for (BatchRequestPart part : parts) {
+ if (part.isChangeSet()) {
+ String txnId = handler.startTransaction();
+ partResponse = processChangeSet(part, handler);
+ if (partResponse.getResponses().get(0).getStatusCode() > 400) {
+ handler.rollback(txnId);
+ }
+ handler.commit(txnId);
+ } else {
+ // single request, a static request
+ ODataRequest partRequest = part.getRequests().get(0);
+ partResponse = process(partRequest, handler);
+ }
+ responseParts.add(partResponse);
+
+ // on error, should we continue?
+ final int statusCode = partResponse.getResponses().get(0).getStatusCode();
+ if ((statusCode >= 400 && statusCode <= 600) && !continueOnError) {
+ break;
+ }
+ }
+
+ // send response
+ final String responseBoundary = "batch_" + UUID.randomUUID().toString();
+ ;
+ final InputStream responseContent = odata.createFixedFormatSerializer().batchResponse(
+ responseParts, responseBoundary);
+ response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.MULTIPART_MIXED + ";boundary="
+ + responseBoundary);
+ response.setContent(responseContent);
+ response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
+ }
+
+ ODataResponsePart process(ODataRequest partRequest, ServiceHandler serviceHandler) {
+ ODataResponse partResponse = executeSingleRequest(partRequest, serviceHandler);
+ addContentID(partRequest, partResponse);
+ return new ODataResponsePart(partResponse, false);
+ }
+
+ ODataResponsePart processChangeSet(BatchRequestPart partRequest, ServiceHandler serviceHandler)
+ throws BatchDeserializerException {
+ List<ODataResponse> changeSetResponses = new ArrayList<ODataResponse>();
+ // change set need to be a in a atomic operation
+ for (ODataRequest changeSetPartRequest : partRequest.getRequests()) {
+
+ this.rewriter.replaceReference(changeSetPartRequest);
+
+ ODataResponse partResponse = executeSingleRequest(changeSetPartRequest, serviceHandler);
+
+ this.rewriter.addMapping(changeSetPartRequest, partResponse);
+ addContentID(changeSetPartRequest, partResponse);
+
+ if (partResponse.getStatusCode() < 400) {
+ changeSetResponses.add(partResponse);
+ } else {
+ // 11.7.4 Responding to a Batch Request
+ return new ODataResponsePart(partResponse, false);
+ }
+ }
+ return new ODataResponsePart(changeSetResponses, true);
+ }
+
+ ODataResponse executeSingleRequest(ODataRequest singleRequest, ServiceHandler handler) {
+ ServiceDispatcher dispatcher = new ServiceDispatcher(this.odata, this.serviceMetadata, handler,
+ this.customContentType);
+ ODataResponse res = new ODataResponse();
+ try {
+ dispatcher.execute(singleRequest, res);
+ } catch (Exception e) {
+ ErrorHandler ehandler = new ErrorHandler(this.odata, this.serviceMetadata,
+ getCustomContentTypeSupport());
+ ehandler.handleException(e, singleRequest, res);
+ }
+ return res;
+ }
+
+ private void addContentID(ODataRequest batchPartRequest, ODataResponse batchPartResponse) {
+ final String contentId = batchPartRequest.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
+ if (contentId != null) {
+ batchPartResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, contentId);
+ }
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ return isPOST();
+ }
+
+ private void validateContentType() throws ODataApplicationException {
+ final String contentType = getRequestContentType().toContentTypeString();
+
+ if (contentType == null
+ || !BatchParserCommon.PATTERN_MULTIPART_BOUNDARY.matcher(contentType).matches()) {
+ throw new ODataApplicationException("Invalid content type",
+ HttpStatusCode.PRECONDITION_FAILED.getStatusCode(), Locale.getDefault());
+ }
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return null;
+ }
+
+ private boolean isContinueOnError() {
+ final List<String> preferValues = this.request.getHeaders(HttpHeader.PREFER);
+
+ if (preferValues != null) {
+ for (final String preference : preferValues) {
+ if (PREFERENCE_CONTINUE_ON_ERROR.equals(preference)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private String extractBoundary(ContentType contentType) throws BatchDeserializerException {
+ return BatchParserCommon.getBoundary(contentType.toContentTypeString(), 0);
+ }
+}
[29/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin as example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java
new file mode 100644
index 0000000..19a0387
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java
@@ -0,0 +1,546 @@
+/*
+ * 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.example;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Locale;
+import java.util.Random;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmSingleton;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.commons.core.data.EntitySetImpl;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.requests.ServiceDocumentRequest;
+import org.apache.olingo.server.core.responses.CountResponse;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.ServiceDocumentResponse;
+import org.apache.olingo.server.core.responses.ServiceResponse;
+import org.apache.olingo.server.core.responses.ServiceResponseVisior;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public class TripPinHandler implements ServiceHandler {
+ private OData odata;
+ private ServiceMetadata serviceMetadata;
+ private final TripPinDataModel dataModel;
+
+ public TripPinHandler(TripPinDataModel datamodel) {
+ this.dataModel = datamodel;
+ }
+
+ @Override
+ public void init(OData odata, ServiceMetadata serviceMetadata) {
+ this.odata = odata;
+ this.serviceMetadata = serviceMetadata;
+ }
+
+ @Override
+ public void readMetadata(MetadataRequest request, MetadataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ response.writeMetadata();
+ }
+
+ @Override
+ public void readServiceDocument(ServiceDocumentRequest request, ServiceDocumentResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ response.writeServiceDocument(request.getODataRequest().getRawBaseUri());
+ }
+
+ static class EntityDetails {
+ EntitySet entitySet = null;
+ Entity entity = null;
+ EdmEntityType entityType;
+ String navigationProperty;
+ Entity parentEntity = null;
+ }
+
+ private EntityDetails process(final DataRequest request) throws ODataApplicationException {
+ EntitySet entitySet = null;
+ Entity entity = null;
+ EdmEntityType entityType;
+ Entity parentEntity = null;
+
+ if (request.isSingleton()) {
+ EdmSingleton singleton = request.getUriResourceSingleton().getSingleton();
+ entityType = singleton.getEntityType();
+ if (singleton.getName().equals("Me")) {
+ entitySet = this.dataModel.getEntitySet("People");
+ entity = entitySet.getEntities().get(0);
+ }
+ } else {
+ final EdmEntitySet edmEntitySet = request.getEntitySet();
+ entityType = edmEntitySet.getEntityType();
+ List<UriParameter> keys = request.getKeyPredicates();
+
+ // TODO: This example so far ignores all system options; but a real
+ // service should not
+ if (keys != null && !keys.isEmpty()) {
+ entity = this.dataModel.getEntity(edmEntitySet.getName(), keys);
+ } else {
+ int skip = 0;
+ if (request.getUriInfo().getSkipTokenOption() != null) {
+ skip = Integer.parseInt(request.getUriInfo().getSkipTokenOption().getValue());
+ }
+ int pageSize = getPageSize(request);
+ entitySet = this.dataModel.getEntitySet(edmEntitySet.getName(), skip, pageSize);
+ if (entitySet.getEntities().size() == pageSize) {
+ try {
+ entitySet.setNext(new URI(request.getODataRequest().getRawRequestUri() + "?$skiptoken="
+ + (skip + pageSize)));
+ } catch (URISyntaxException e) {
+ throw new ODataApplicationException(e.getMessage(), 500, Locale.getDefault());
+ }
+ }
+ }
+ }
+ EntityDetails details = new EntityDetails();
+
+ if (!request.getNavigations().isEmpty() && entity != null) {
+ UriResourceNavigation lastNavigation = request.getNavigations().getLast();
+ for (UriResourceNavigation nav : request.getNavigations()) {
+ entityType = nav.getProperty().getType();
+ if (nav.isCollection()) {
+ entitySet = this.dataModel.getNavigableEntitySet(entity, nav);
+ } else {
+ parentEntity = entity;
+ entity = this.dataModel.getNavigableEntity(parentEntity, nav);
+ }
+ }
+ details.navigationProperty = lastNavigation.getProperty().getName();
+ }
+
+ details.entity = entity;
+ details.entitySet = entitySet;
+ details.entityType = entityType;
+ details.parentEntity = parentEntity;
+ return details;
+ }
+
+ @Override
+ public <T extends ServiceResponse> void read(final DataRequest request, final T response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ final EntityDetails details = process(request);
+
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(CountResponse response) throws ODataTranslatedException, ODataApplicationException {
+ response.writeCount(details.entitySet.getCount());
+ }
+
+ @Override
+ public void visit(PrimitiveValueResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
+ Property property = details.entity.getProperty(edmProperty.getName());
+ response.write(property.getValue());
+ }
+
+ @Override
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ EdmProperty edmProperty = request.getUriResourceProperty().getProperty();
+ Property property = details.entity.getProperty(edmProperty.getName());
+ response.writeProperty(edmProperty.getType(), property);
+ }
+
+ @Override
+ public void visit(StreamResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ // stream property response
+ response.writeStreamResponse(new ByteArrayInputStream("dummy".getBytes()),
+ ContentType.APPLICATION_OCTET_STREAM);
+ }
+
+ @Override
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (request.getPreference("odata.maxpagesize") != null) {
+ response.writeHeader("Preference-Applied", request.getPreference("odata.maxpagesize"));
+ }
+ if (details.entity == null && !request.getNavigations().isEmpty()) {
+ response.writeReadEntitySet(details.entityType, new EntitySetImpl());
+ } else {
+ response.writeReadEntitySet(details.entityType, details.entitySet);
+ }
+ }
+
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ if (details.entity == null && !request.getNavigations().isEmpty()) {
+ response.writeNoContent(true);
+ } else {
+ response.writeReadEntity(details.entityType, details.entity);
+ }
+ }
+ });
+ }
+
+ private int getPageSize(DataRequest request) {
+ String size = request.getPreference("odata.maxpagesize");
+ if (size == null) {
+ return 8;
+ }
+ return Integer.parseInt(size);
+ }
+
+ @Override
+ public void createEntity(DataRequest request, Entity entity, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ EdmEntitySet edmEntitySet = request.getEntitySet();
+
+ String location = buildLocation(entity, edmEntitySet.getName(), edmEntitySet.getEntityType());
+ Entity created = this.dataModel.createEntity(edmEntitySet.getName(), entity, location);
+
+ try {
+ // create references, they come in "@odata.bind" value
+ List<Link> bindings = entity.getNavigationBindings();
+ if (bindings != null & !bindings.isEmpty()) {
+ for (Link link : bindings) {
+ String navigationProperty = link.getTitle();
+ String uri = link.getBindingLink();
+ if (uri != null) {
+ DataRequest bindingRequest = request.parseLink(new URI(uri));
+
+ Entity reference = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(),
+ bindingRequest.getKeyPredicates());
+
+ this.dataModel.addNavigationLink(navigationProperty, created, reference);
+
+ } else {
+ for (String binding : link.getBindingLinks()) {
+ DataRequest bindingRequest = request.parseLink(new URI(binding));
+
+ Entity reference = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(),
+ bindingRequest.getKeyPredicates());
+
+ this.dataModel.addNavigationLink(navigationProperty, created, reference);
+ }
+ }
+ }
+ }
+ } catch (URISyntaxException e) {
+ throw new ODataApplicationException(e.getMessage(), 500, Locale.getDefault());
+ }
+
+ response.writeCreatedEntity(edmEntitySet.getEntityType(), created, location);
+ }
+
+ static String buildLocation(Entity entity, String name, EdmEntityType type) {
+ String location = "/" + name + "(";
+ int i = 0;
+ boolean usename = type.getKeyPredicateNames().size() > 1;
+
+ for (String key : type.getKeyPredicateNames()) {
+ if (i > 0) {
+ location += ",";
+ }
+ i++;
+ if (usename) {
+ location += (key + "=");
+ }
+ if (entity.getProperty(key).getType().equals("Edm.String")) {
+ location = location + "'" + entity.getProperty(key).getValue().toString() + "'";
+ } else {
+ location = location + entity.getProperty(key).getValue().toString();
+ }
+ }
+ location += ")";
+ return location;
+ }
+
+ @Override
+ public void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag,
+ EntityResponse response) throws ODataTranslatedException, ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ @Override
+ public void deleteEntity(DataRequest request, String eTag, EntityResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ EdmEntitySet edmEntitySet = request.getEntitySet();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), request.getKeyPredicates());
+ if (entity == null) {
+ response.writeNotFound(true);
+ return;
+ }
+ String key = edmEntitySet.getEntityType().getKeyPredicateNames().get(0);
+ boolean removed = this.dataModel.deleteEntity(edmEntitySet.getName(), eTag, key, entity
+ .getProperty(key).getValue());
+
+ if (removed) {
+ response.writeDeletedEntityOrReference();
+ } else {
+ response.writeNotFound(true);
+ }
+ }
+
+ @Override
+ public void updateProperty(DataRequest request, final Property property, boolean merge,
+ String entityETag, PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+
+ EdmEntitySet edmEntitySet = request.getEntitySet();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), request.getKeyPredicates());
+ if (entity == null) {
+ response.writeNotFound(true);
+ return;
+ }
+
+ String key = edmEntitySet.getEntityType().getKeyPredicateNames().get(0);
+ boolean replaced = this.dataModel.updateProperty(edmEntitySet.getName(), entityETag, key,
+ entity.getProperty(key).getValue(), property);
+
+ if (replaced) {
+ if (property.getValue() == null) {
+ response.writePropertyDeleted();
+ } else {
+ response.writePropertyUpdated();
+ }
+ } else {
+ response.writeServerError(true);
+ }
+ }
+
+ @Override
+ public <T extends ServiceResponse> void invoke(FunctionRequest request, HttpMethod method,
+ T response) throws ODataTranslatedException, ODataApplicationException {
+ EdmFunction function = request.getFunction();
+ if (function.getName().equals("GetNearestAirport")) {
+
+ final EdmEntityType type = serviceMetadata.getEdm().getEntityContainer(null)
+ .getEntitySet("Airports").getEntityType();
+
+ EntitySet es = this.dataModel.getEntitySet("Airports");
+ int i = new Random().nextInt(es.getEntities().size());
+ final Entity entity = es.getEntities().get(i);
+
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeReadEntity(type, entity);
+ }
+ });
+ }
+ }
+
+ @Override
+ public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response)
+ throws ODataTranslatedException, ODataApplicationException {
+ EdmAction action = request.getAction();
+ if (action.getName().equals("ResetDataSource")) {
+ try {
+ this.dataModel.loadData();
+ response.accepts(new ServiceResponseVisior() {
+ @Override
+ public void visit(NoContentResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeNoContent();
+ }
+ });
+ } catch (Exception e) {
+ response.writeServerError(true);
+ }
+ } else {
+ response.writeServerError(true);
+ }
+ }
+
+ @Override
+ public void readMediaStream(MediaRequest request, StreamResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ final EdmEntitySet edmEntitySet = request.getEntitySet();
+ List<UriParameter> keys = request.getKeyPredicates();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), keys);
+
+ InputStream contents = this.dataModel.readMedia(entity);
+ response.writeStreamResponse(contents, request.getResponseContentType());
+ }
+
+ @Override
+ public void upsertMediaStream(MediaRequest request, String entityETag, InputStream mediaContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ final EdmEntitySet edmEntitySet = request.getEntitySet();
+ List<UriParameter> keys = request.getKeyPredicates();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), keys);
+
+ if (mediaContent == null) {
+ boolean deleted = this.dataModel.deleteMedia(entity);
+ if (deleted) {
+ response.writeNoContent();
+ } else {
+ response.writeNotFound();
+ }
+ } else {
+ boolean updated = this.dataModel.updateMedia(entity, mediaContent);
+ if (updated) {
+ response.writeNoContent();
+ } else {
+ response.writeServerError(true);
+ }
+ }
+ }
+
+ @Override
+ public void upsertStreamProperty(DataRequest request, String entityETag, InputStream streamContent,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ final EdmEntitySet edmEntitySet = request.getEntitySet();
+ List<UriParameter> keys = request.getKeyPredicates();
+ Entity entity = this.dataModel.getEntity(edmEntitySet.getName(), keys);
+
+ EdmProperty property = request.getUriResourceProperty().getProperty();
+
+ if (streamContent == null) {
+ boolean deleted = this.dataModel.deleteStream(entity, property);
+ if (deleted) {
+ response.writeNoContent();
+ } else {
+ response.writeNotFound();
+ }
+ } else {
+ boolean updated = this.dataModel.updateStream(entity, property, streamContent);
+ if (updated) {
+ response.writeNoContent();
+ } else {
+ response.writeServerError(true);
+ }
+ }
+ }
+
+ @Override
+ public void addReference(DataRequest request, String entityETag, List<URI> references,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+
+ final EntityDetails details = process(request);
+
+ for (URI reference : references) {
+ DataRequest bindingRequest = request.parseLink(reference);
+ Entity linkEntity = this.dataModel.getEntity(bindingRequest.getEntitySet().getName(),
+ bindingRequest.getKeyPredicates());
+ this.dataModel.addNavigationLink(details.navigationProperty, details.entity, linkEntity);
+ }
+ response.writeNoContent();
+ }
+
+ @Override
+ public void updateReference(DataRequest request, String entityETag, URI updateId,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ // this single valued navigation.
+ final EntityDetails details = process(request);
+ DataRequest updateRequest = request.parseLink(updateId);
+ Entity updateEntity = this.dataModel.getEntity(updateRequest.getEntitySet().getName(),
+ updateRequest.getKeyPredicates());
+ boolean updated = false;
+ if (updateEntity != null) {
+ updated = this.dataModel.updateNavigationLink(details.navigationProperty,
+ details.parentEntity, updateEntity);
+ }
+
+ if (updated) {
+ response.writeNoContent();
+ } else {
+ response.writeServerError(true);
+ }
+ }
+
+ @Override
+ public void deleteReference(DataRequest request, URI deleteId, String entityETag,
+ NoContentResponse response) throws ODataTranslatedException, ODataApplicationException {
+ boolean removed = false;
+ if (deleteId != null) {
+ final EntityDetails details = process(request);
+ DataRequest deleteRequest = request.parseLink(deleteId);
+ Entity deleteEntity = this.dataModel.getEntity(deleteRequest.getEntitySet().getName(),
+ deleteRequest.getKeyPredicates());
+ if (deleteEntity != null) {
+ removed = this.dataModel.removeNavigationLink(details.navigationProperty, details.entity,
+ deleteEntity);
+ }
+ } else {
+ // this single valued navigation.
+ final EntityDetails details = process(request);
+ removed = this.dataModel.removeNavigationLink(details.navigationProperty,
+ details.parentEntity, details.entity);
+ }
+ if (removed) {
+ response.writeNoContent();
+ } else {
+ response.writeServerError(true);
+ }
+ }
+
+ @Override
+ public void anyUnsupported(ODataRequest request, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ response.setStatusCode(500);
+ }
+
+ @Override
+ public String startTransaction() {
+ return null;
+ }
+
+ @Override
+ public void commit(String txnId) {
+ }
+
+ @Override
+ public void rollback(String txnId) {
+ }
+
+ @Override
+ public void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response) {
+ response.setStatusCode(200);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
new file mode 100644
index 0000000..4b26b8e
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
@@ -0,0 +1,756 @@
+/*
+ * 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.example;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+
+import org.apache.olingo.commons.core.Encoder;
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.api.ContentProvider;
+import org.eclipse.jetty.client.api.ContentResponse;
+import org.eclipse.jetty.http.HttpMethod;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+
+/**
+ * Please note that NONE of the system query options are developed in the sample
+ * service like $filter, $orderby etc. So using those options will be ignored
+ * right now. These tests designed to test the framework, all options are responsibilities
+ * of service developer.
+ */
+public class TripPinServiceTest {
+ private static Server server = new Server();
+ private static String baseURL;
+ private static HttpClient http = new HttpClient();
+
+ @BeforeClass
+ public static void beforeTest() throws Exception {
+ ServerConnector connector = new ServerConnector(server);
+ server.setConnectors(new Connector[] { connector });
+
+ ServletContextHandler context = new ServletContextHandler();
+ context.setContextPath("/trippin");
+ context.addServlet(new ServletHolder(new TripPinServlet()), "/*");
+ server.setHandler(context);
+ server.start();
+ int port = connector.getLocalPort();
+ http.start();
+ baseURL = "http://localhost:"+port+"/trippin";
+ }
+
+ @AfterClass
+ public static void afterTest() throws Exception {
+ server.stop();
+ }
+
+ @Test
+ public void testEntitySet() throws Exception {
+ ContentResponse response = http.newRequest(baseURL + "/People")
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .method(HttpMethod.GET)
+ .send();
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+ assertEquals(baseURL+"/People?$skiptoken=8", node.get("@odata.nextLink").asText());
+
+ JsonNode person = ((ArrayNode)node.get("value")).get(0);
+ assertEquals("russellwhyte", person.get("UserName").asText());
+ }
+
+ private JsonNode getJSONNode(ContentResponse response) throws IOException,
+ JsonProcessingException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ JsonNode node = objectMapper.readTree(response.getContent());
+ return node;
+ }
+
+ @Test
+ public void testReadEntitySetWithPaging() throws Exception {
+ ContentResponse response = http.newRequest(baseURL + "/People")
+ .header("Prefer", "odata.maxpagesize=10").send();
+
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+ assertEquals(baseURL+"/People?$skiptoken=10", node.get("@odata.nextLink").asText());
+
+ JsonNode person = ((ArrayNode)node.get("value")).get(0);
+ assertEquals("russellwhyte", person.get("UserName").asText());
+
+ assertNotNull(response.getHeaders().get("Preference-Applied"));
+ }
+
+ @Test
+ public void testReadEntityWithKey() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('AA')");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Airlines/$entity", node.get("@odata.context").asText());
+ assertEquals("American Airlines", node.get("Name").asText());
+ }
+
+ @Test
+ public void testReadEntityWithNonExistingKey() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('OO')");
+ assertEquals(404, response.getStatus());
+ }
+
+ @Test
+ public void testRead$Count() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines/$count");
+ assertEquals(200, response.getStatus());
+ assertEquals("15", response.getContentAsString());
+ }
+
+ @Test
+ public void testReadPrimitiveProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('AA')/Name");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Airlines('AA')/Name", node.get("@odata.context").asText());
+ assertEquals("American Airlines", node.get("value").asText());
+ }
+
+ @Test
+ public void testReadNonExistentProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('AA')/Unknown");
+ assertEquals(404, response.getStatus());
+ }
+
+ @Test
+ public void testReadPrimitiveArrayProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russellwhyte')/Emails");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Emails", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("Russell@example.com", ((ArrayNode)node.get("value")).get(0).asText());
+ assertEquals("Russell@contoso.com", ((ArrayNode)node.get("value")).get(1).asText());
+ }
+
+ @Test
+ public void testReadPrimitivePropertyValue() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airlines('AA')/Name/$value");
+ assertEquals(200, response.getStatus());
+ assertEquals("American Airlines", response.getContentAsString());
+ }
+
+ @Test @Ignore
+ // TODO: Support geometry types to make this run
+ public void testReadComplexProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Airports('KSFO')/Location");
+ fail("support geometry type");
+ }
+
+ @Test
+ public void testReadComplexArrayProperty() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russellwhyte')/AddressInfo");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/AddressInfo", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("187 Suffolk Ln.", ((ArrayNode)node.get("value")).get(0).get("Address").asText());
+ }
+
+ @Test
+ public void testReadMedia() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Photos(1)/$value");
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testCreateMedia() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Photos(1)/$value";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content("bytecontents"), "image/jpeg")
+ .method(HttpMethod.PUT)
+ .send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testDeleteMedia() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Photos(1)/$value";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content("bytecontents"), "image/jpeg")
+ .method(HttpMethod.DELETE)
+ .send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testCreateStream() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content("bytecontents"), "image/jpeg")
+ .method(HttpMethod.POST)
+ .send();
+ // method not allowed
+ assertEquals(405, response.getStatus());
+ }
+
+ @Test
+ public void testCreateStream2() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content("bytecontents"), "image/jpeg")
+ .method(HttpMethod.PUT)
+ .send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testDeleteStream() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ ContentResponse response = http.newRequest(editUrl)
+ .method(HttpMethod.DELETE)
+ .send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testReadStream() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ ContentResponse response = http.newRequest(editUrl)
+ .method(HttpMethod.GET)
+ .send();
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testLambdaAny() throws Exception {
+ // this is just testing to see the labba expresions are going through the
+ // framework, none of the system options are not implemented in example service
+ String query = "Friends/any(d:d/UserName eq 'foo')";
+ ContentResponse response = http.newRequest(baseURL + "/People?$filter="+Encoder.encode(query))
+ .method(HttpMethod.GET)
+ .send();
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void testSingleton() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/Me");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Me", node.get("@odata.context").asText());
+ assertEquals("russellwhyte", node.get("UserName").asText());
+ }
+
+ @Test
+ public void testSelectOption() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russellwhyte')?$select=FirstName,LastName");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People(FirstName,LastName)/$entity", node.get("@odata.context").asText());
+ assertEquals("Russell", node.get("FirstName").asText());
+ }
+
+ @Test
+ public void testActionImportWithNoResponse() throws Exception {
+ ContentResponse response = http.POST(baseURL + "/ResetDataSource").send();
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testFunctionImport() throws Exception {
+ //TODO: fails because of lack of geometery support
+ ContentResponse response = http.GET(baseURL + "/GetNearestAirport(lat=23.0,lon=34.0)");
+ }
+
+ @Test
+ public void testBadReferences() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russelwhyte')/$ref");
+ assertEquals(405, response.getStatus());
+ }
+
+ @Test
+ public void testReadReferences() throws Exception {
+ ContentResponse response = http.GET(baseURL + "/People('russellwhyte')/Friends/$ref");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Collection($ref)", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("/People('scottketchum')", ((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
+ }
+
+ @Test
+ public void testAddCollectionReferences() throws Exception {
+ //GET
+ ContentResponse response = http.GET(baseURL + "/People('kristakemp')/Friends/$ref");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+
+ assertTrue(node.get("value").isArray());
+ assertEquals("/People('genevievereeves')", ((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
+ assertNull(((ArrayNode)node.get("value")).get(1));
+
+ //ADD
+ String payload = "{\n" +
+ " \"@odata.context\": \""+baseURL+"/$metadata#Collection($ref)\",\n" +
+ " \"value\": [\n" +
+ " { \"@odata.id\": \"People('russellwhyte')\" },\n" +
+ " { \"@odata.id\": \"People('scottketchum')\" } \n" +
+ " ]\n" +
+ "}";
+ response = http.POST(baseURL + "/People('kristakemp')/Friends/$ref")
+ .content(content(payload), "application/json")
+ .send();
+ assertEquals(204, response.getStatus());
+
+ //GET
+ response = http.GET(baseURL + "/People('kristakemp')/Friends/$ref");
+ assertEquals(200, response.getStatus());
+ node = getJSONNode(response);
+
+ assertTrue(node.get("value").isArray());
+ assertEquals("/People('genevievereeves')", ((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
+ assertEquals("/People('russellwhyte')", ((ArrayNode)node.get("value")).get(1).get("@odata.id").asText());
+ assertEquals("/People('scottketchum')", ((ArrayNode)node.get("value")).get(2).get("@odata.id").asText());
+ }
+
+
+ @Test
+ public void testEntityId() throws Exception {
+ ContentResponse response = http.GET(baseURL+"/$entity?$id="+baseURL + "/People('kristakemp')");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People/$entity", node.get("@odata.context").asText());
+ assertEquals("kristakemp", node.get("UserName").asText());
+
+ // using relative URL
+ response = http.GET(baseURL+"/$entity?$id="+"People('kristakemp')");
+ assertEquals(200, response.getStatus());
+ node = getJSONNode(response);
+ assertEquals("$metadata#People/$entity", node.get("@odata.context").asText());
+ assertEquals("kristakemp", node.get("UserName").asText());
+ }
+
+ @Test
+ public void testCreateReadDeleteEntity() throws Exception {
+ String payload = "{\n" +
+ " \"UserName\":\"olingodude\",\n" +
+ " \"FirstName\":\"Olingo\",\n" +
+ " \"LastName\":\"Apache\",\n" +
+ " \"Emails\":[\n" +
+ " \"olingo@apache.org\"\n" +
+ " ],\n" +
+ " \"AddressInfo\":[\n" +
+ " {\n" +
+ " \"Address\":\"100 apache Ln.\",\n" +
+ " \"City\":{\n" +
+ " \"CountryRegion\":\"United States\",\n" +
+ " \"Name\":\"Boise\",\n" +
+ " \"Region\":\"ID\"\n" +
+ " }\n" +
+ " }\n" +
+ " ],\n" +
+ " \"Gender\":\"0\",\n" +
+ " \"Concurrency\":635585295719432047\n" +
+ "}";
+ ContentResponse response = http.POST(baseURL + "/People")
+ .content(content(payload), "application/json")
+ .header("Prefer", "return=minimal")
+ .send();
+ // the below woud be 204, if minimal was not supplied
+ assertEquals(204, response.getStatus());
+ assertEquals("/People('olingodude')", response.getHeaders().get("Location"));
+ assertEquals("return=minimal", response.getHeaders().get("Preference-Applied"));
+
+ String location = baseURL+response.getHeaders().get("Location");
+ response = http.GET(location);
+ assertEquals(200, response.getStatus());
+
+ response = http.newRequest(location).method(HttpMethod.DELETE).send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(location);
+ assertEquals(404, response.getStatus());
+ }
+
+
+ @Test
+ public void testCreateEntityWithLinkToRelatedEntities() throws Exception {
+ String payload = "{\n" +
+ " \"UserName\":\"olingo\",\n" +
+ " \"FirstName\":\"Olingo\",\n" +
+ " \"LastName\":\"Apache\",\n" +
+ " \"Emails\":[\n" +
+ " \"olingo@apache.org\"\n" +
+ " ],\n" +
+ " \"AddressInfo\":[\n" +
+ " {\n" +
+ " \"Address\":\"100 apache Ln.\",\n" +
+ " \"City\":{\n" +
+ " \"CountryRegion\":\"United States\",\n" +
+ " \"Name\":\"Boise\",\n" +
+ " \"Region\":\"ID\"\n" +
+ " }\n" +
+ " }\n" +
+ " ],\n" +
+ " \"Gender\":\"0\",\n" +
+ " \"Concurrency\":635585295719432047,\n" +
+ "\"Friends@odata.bind\":[\"" +
+ baseURL+"/People('russellwhyte')\",\""+
+ baseURL+"/People('scottketchum')\""+
+ "]"+
+ "}";
+ ContentResponse response = http.POST(baseURL + "/People")
+ .content(content(payload), "application/json")
+ .header("Prefer", "return=minimal")
+ .send();
+ // the below woud be 204, if minimal was not supplied
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(baseURL+"/People('olingo')/Friends");
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("scottketchum", ((ArrayNode)node.get("value")).get(1).get("UserName").asText());
+ }
+
+ @Test
+ public void testUpdatePrimitiveProperty() throws Exception {
+ String payload = "{"
+ + " \"value\":\"Pilar Ackerman\""
+ + "}";
+
+ String editUrl = baseURL + "/People('russellwhyte')/FirstName";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content(payload), "application/json")
+ .method(HttpMethod.PUT)
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/FirstName", node.get("@odata.context").asText());
+ assertEquals("Pilar Ackerman", node.get("value").asText());
+ }
+
+ @Test
+ public void testUpdatePrimitiveArrayProperty() throws Exception {
+ String payload = "{"
+ + " \"value\": [\n" +
+ " \"olingo@apache.com\"\n" +
+ " ]"
+ + "}";
+
+ String editUrl = baseURL + "/People('russellwhyte')/Emails";
+ ContentResponse response = http.newRequest(editUrl)
+ .content(content(payload), "application/json")
+ .method(HttpMethod.PUT)
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Emails", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("olingo@apache.com", ((ArrayNode)node.get("value")).get(0).asText());
+ }
+
+ @Test
+ public void testDeleteProperty() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/FirstName";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("Russell", node.get("value").asText());
+
+ response = http.newRequest(editUrl)
+ .method(HttpMethod.DELETE)
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(editUrl);
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityCollection() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Friends";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+
+ JsonNode person = ((ArrayNode)node.get("value")).get(0);
+ assertEquals("scottketchum", person.get("UserName").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityCollection2() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Friends('scottketchum')/Trips";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Friends('scottketchum')/Trips",
+ node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("1001", ((ArrayNode)node.get("value")).get(0).get("TripId").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntity() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips/$entity",
+ node.get("@odata.context").asText());
+ assertEquals("f94e9116-8bdd-4dac-ab61-08438d0d9a71", node.get("ShareId").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityNotExisting() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(9999)";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntitySetNotExisting() throws Exception {
+ String editUrl = baseURL + "/People('jhondoe')/Trips";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('jhondoe')/Trips",
+ node.get("@odata.context").asText());
+ assertEquals(0, ((ArrayNode)node.get("value")).size());
+ }
+
+ @Test
+ public void testBadNavigationProperty() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Unknown";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(404, response.getStatus());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityProperty() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode",
+ node.get("@odata.context").asText());
+
+ assertEquals("JH58494", node.get("value").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityMultipleDerivedTypes() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)/PlanItems";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems",
+ node.get("@odata.context").asText());
+
+ assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Flight",
+ ((ArrayNode) node.get("value")).get(0).get("@odata.type").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityCoolectionDerivedFilter() throws Exception {
+ String editUrl = baseURL
+ + "/People('russellwhyte')/Trips(1003)/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Event";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/"
+ + "Microsoft.OData.SampleService.Models.TripPin.Event",
+ node.get("@odata.context").asText());
+
+ assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Event",
+ ((ArrayNode) node.get("value")).get(0).get("@odata.type").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityDerivedFilter() throws Exception {
+ String editUrl = baseURL+ "/People('russellwhyte')/Trips(1003)/PlanItems(56)/"
+ + "Microsoft.OData.SampleService.Models.TripPin.Event";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/"
+ + "Microsoft.OData.SampleService.Models.TripPin.Event/$entity",
+ node.get("@odata.context").asText());
+
+ assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Event", node.get("@odata.type").asText());
+ assertEquals("56", node.get("PlanItemId").asText());
+ }
+
+ @Test
+ public void testUpdateReference() throws Exception {
+ ContentResponse response = http.GET(baseURL+"/People('ronaldmundy')/Photo/$ref");
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("/Photos(12)", node.get("@odata.id").asText());
+
+ String msg = "{\n" +
+ "\"@odata.id\": \"/Photos(11)\"\n" +
+ "}";
+ String editUrl = baseURL + "/People('ronaldmundy')/Photo/$ref";
+ response = http.newRequest(editUrl)
+ .method(HttpMethod.PUT)
+ .content(content(msg))
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(baseURL+"/People('ronaldmundy')/Photo/$ref");
+ assertEquals(200, response.getStatus());
+ node = getJSONNode(response);
+ assertEquals("/Photos(11)", node.get("@odata.id").asText());
+ }
+
+ @Test
+ public void testAddDelete2ReferenceCollection() throws Exception {
+ // add
+ String msg = "{\n" +
+ "\"@odata.id\": \"/People('russellwhyte')\"\n" +
+ "}";
+ String editUrl = baseURL + "/People('vincentcalabrese')/Friends/$ref";
+ ContentResponse response = http.newRequest(editUrl)
+ .method(HttpMethod.POST)
+ .content(content(msg))
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .send();
+ assertEquals(204, response.getStatus());
+
+ // get
+ response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ JsonNode node = getJSONNode(response);
+ assertEquals("/People('russellwhyte')",
+ ((ArrayNode) node.get("value")).get(2).get("@odata.id").asText());
+
+ //delete
+ response = http.newRequest(editUrl+"?$id="+baseURL+"/People('russellwhyte')")
+ .method(HttpMethod.DELETE)
+ .content(content(msg))
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .send();
+ assertEquals(204, response.getStatus());
+
+ // get
+ response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ node = getJSONNode(response);
+ assertNull("/People('russellwhyte')", ((ArrayNode) node.get("value")).get(2));
+ }
+
+ @Test
+ public void testDeleteReference() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Photo/$ref";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+
+ response = http.newRequest(editUrl)
+ .method(HttpMethod.DELETE)
+ .send();
+ assertEquals(204, response.getStatus());
+
+ response = http.GET(editUrl);
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testCrossJoin() throws Exception {
+ String editUrl = baseURL + "/$crossjoin(People,Airlines)";
+ ContentResponse response = http.GET(editUrl);
+ assertEquals(200, response.getStatus());
+ }
+
+ public static ContentProvider content(final String msg) {
+ return new ContentProvider() {
+ boolean hasNext = true;
+
+ @Override
+ public Iterator<ByteBuffer> iterator() {
+ return new Iterator<ByteBuffer>() {
+ @Override
+ public boolean hasNext() {
+ return hasNext;
+ }
+ @Override
+ public ByteBuffer next() {
+ hasNext = false;
+ return ByteBuffer.wrap(msg.getBytes());
+ }
+ @Override
+ public void remove() {
+ }
+ };
+ }
+ @Override
+ public long getLength() {
+ return msg.length();
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServlet.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServlet.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServlet.java
new file mode 100644
index 0000000..2c05d65
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServlet.java
@@ -0,0 +1,75 @@
+/*
+ * 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.example;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collections;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataHttpHandler;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.core.MetadataParser;
+import org.apache.olingo.server.core.OData4Impl;
+
+public class TripPinServlet extends HttpServlet {
+ private static final long serialVersionUID = 2663595419366214401L;
+ private TripPinDataModel dataModel;
+
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ }
+
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ OData odata = OData4Impl.newInstance();
+ MetadataParser parser = new MetadataParser();
+ EdmProvider edmProvider = null;
+
+ try {
+ edmProvider = parser.buildEdmProvider(new FileReader("src/test/resources/trippin.xml"));
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
+ }
+
+ ServiceMetadata metadata = odata.createServiceMetadata(edmProvider, Collections.EMPTY_LIST);
+
+ ODataHttpHandler handler = odata.createHandler(metadata);
+
+ if (this.dataModel == null) {
+ try {
+ this.dataModel = new TripPinDataModel(metadata);
+ } catch (Exception e) {
+ throw new IOException("Failed to load data for TripPin Service");
+ }
+ }
+
+ handler.register(new TripPinHandler(this.dataModel));
+ handler.process(request, response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/OlingoOrangeTM.png
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/OlingoOrangeTM.png b/lib/server-core-ext/src/test/resources/OlingoOrangeTM.png
new file mode 100644
index 0000000..d614f1a
Binary files /dev/null and b/lib/server-core-ext/src/test/resources/OlingoOrangeTM.png differ
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/airlines.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/airlines.json b/lib/server-core-ext/src/test/resources/airlines.json
new file mode 100644
index 0000000..78eccdc
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/airlines.json
@@ -0,0 +1,64 @@
+{
+ "value":[
+ {
+ "AirlineCode":"AA",
+ "Name":"American Airlines"
+ },
+ {
+ "AirlineCode":"FM",
+ "Name":"Shanghai Airline"
+ },
+ {
+ "AirlineCode":"MU",
+ "Name":"China Eastern Airlines"
+ },
+ {
+ "AirlineCode":"AF",
+ "Name":"Air France"
+ },
+ {
+ "AirlineCode":"AZ",
+ "Name":"Alitalia"
+ },
+ {
+ "AirlineCode":"AC",
+ "Name":"Air Canada"
+ },
+ {
+ "AirlineCode":"OS",
+ "Name":"Austrian Airlines"
+ },
+ {
+ "AirlineCode":"TK",
+ "Name":"Turkish Airlines"
+ },
+ {
+ "AirlineCode":"JL",
+ "Name":"Japan Airlines"
+ },
+ {
+ "AirlineCode":"SQ",
+ "Name":"Singapore Airlines"
+ },
+ {
+ "AirlineCode":"KE",
+ "Name":"Korean Air"
+ },
+ {
+ "AirlineCode":"CZ",
+ "Name":"China Southern"
+ },
+ {
+ "AirlineCode":"AK",
+ "Name":"AirAsia"
+ },
+ {
+ "AirlineCode":"HX",
+ "Name":"Hong Kong Airlines"
+ },
+ {
+ "AirlineCode":"EK",
+ "Name":"Emirates"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/airports.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/airports.json b/lib/server-core-ext/src/test/resources/airports.json
new file mode 100644
index 0000000..c06a5cf
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/airports.json
@@ -0,0 +1,394 @@
+{
+ "value":[
+ {
+ "IcaoCode":"KSFO",
+ "Name":"San Francisco International Airport",
+ "IataCode":"SFO",
+ "Location":{
+ "Address":"South McDonnell Road, San Francisco, CA 94128",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"San Francisco",
+ "Region":"California"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -122.374722222222,
+ 37.6188888888889
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KLAX",
+ "Name":"Los Angeles International Airport",
+ "IataCode":"LAX",
+ "Location":{
+ "Address":"1 World Way, Los Angeles, CA, 90045",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Los Angeles",
+ "Region":"California"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -118.408055555556,
+ 33.9425
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"ZSSS",
+ "Name":"Shanghai Hongqiao International Airport",
+ "IataCode":"SHA",
+ "Location":{
+ "Address":"Hongqiao Road 2550, Changning District",
+ "City":{
+ "CountryRegion":"China",
+ "Name":"Shanghai",
+ "Region":"Shanghai"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 121.336111111111,
+ 31.1977777777778
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"ZBAA",
+ "Name":"Beijing Capital International Airport",
+ "IataCode":"PEK",
+ "Location":{
+ "Address":"Airport Road, Chaoyang District, Beijing, 100621",
+ "City":{
+ "CountryRegion":"China",
+ "Name":"Beijing",
+ "Region":"Beijing"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 116.584444444444,
+ 40.08
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KJFK",
+ "Name":"John F. Kennedy International Airport",
+ "IataCode":"JFK",
+ "Location":{
+ "Address":"Jamaica, New York, NY 11430",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"New York City",
+ "Region":"New York"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -73.7788888888889,
+ 40.6397222222222
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"LIRA",
+ "Name":"Rome Ciampino Airport",
+ "IataCode":"CIA",
+ "Location":{
+ "Address":"Via Appia Nuova, 1651",
+ "City":{
+ "CountryRegion":"Italy",
+ "Name":"Rome",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 12.5947222222222,
+ 41.7991666666667
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"CYYZ",
+ "Name":"Toronto Pearson International Airport",
+ "IataCode":"YYZ",
+ "Location":{
+ "Address":"6301 Silver Dart Dr Mississauga",
+ "City":{
+ "CountryRegion":"Canada",
+ "Name":"Mississauga",
+ "Region":"Ontario"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -79.6305555555555,
+ 43.6772222222222
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"YSSY",
+ "Name":"Sydney Airport",
+ "IataCode":"SYD",
+ "Location":{
+ "Address":"Airport Dr Sydney NSW 2020",
+ "City":{
+ "CountryRegion":"Australia",
+ "Name":"Sydney",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 151.177222222222,
+ -33.9461111111111
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"LTBA",
+ "Name":"Istanbul Ataturk Airport",
+ "IataCode":"IST",
+ "Location":{
+ "Address":"Ye\u015filk\u00f6y Mh.34149 \u0130stanbul",
+ "City":{
+ "CountryRegion":"Turkey",
+ "Name":"Istanbul",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 28.8211111111111,
+ 40.9766666666667
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"WSSS",
+ "Name":"Singapore Changi Airport",
+ "IataCode":"SIN",
+ "Location":{
+ "Address":"Airport Blvd, Singapore",
+ "City":{
+ "CountryRegion":"Singapore",
+ "Name":"Changi",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 103.987222222222,
+ 1.35555555555556
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"OMAA",
+ "Name":"Abu Dhabi International Airport",
+ "IataCode":"AUH",
+ "Location":{
+ "Address":"Sheik Maktoum Bin Rashid Rd Abu Dhabi",
+ "City":{
+ "CountryRegion":"United Arab Emirates",
+ "Name":"Abu Dhabi",
+ "Region":""
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 54.6511111111111,
+ 24.4327777777778
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"ZGGG",
+ "Name":"Guangzhou Baiyun International Airport",
+ "IataCode":"CAN",
+ "Location":{
+ "Address":"Jichang Road, Renhezhen, Huadu",
+ "City":{
+ "CountryRegion":"China",
+ "Name":"Guangzhou",
+ "Region":"Guangdong"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ 113.265833333333,
+ 23.1841666666667
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KORD",
+ "Name":"O'Hare International Airport",
+ "IataCode":"ORD",
+ "Location":{
+ "Address":"10000 W O'Hare Ave",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Chicago",
+ "Region":"Illinois"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -87.9044444444445,
+ 41.9794444444444
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KATL",
+ "Name":"Hartsfield-Jackson Atlanta International Airport",
+ "IataCode":"ATL",
+ "Location":{
+ "Address":"6000 N Terminal Pkwy",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Atlanta",
+ "Region":"Georgia"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -84.4269444444444,
+ 33.6402777777778
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ },
+ {
+ "IcaoCode":"KSEA",
+ "Name":"Seattle-Tacoma International Airport",
+ "IataCode":"SEA",
+ "Location":{
+ "Address":"17801 International Blvd",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"SeaTac",
+ "Region":"Washington"
+ },
+ "Loc":{
+ "type":"Point",
+ "coordinates":[
+ -122.309166666667,
+ 47.4488888888889
+ ],
+ "crs":{
+ "type":"name",
+ "properties":{
+ "name":"EPSG:4326"
+ }
+ }
+ }
+ }
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/event.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/event.json b/lib/server-core-ext/src/test/resources/event.json
new file mode 100644
index 0000000..eb19dde
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/event.json
@@ -0,0 +1,157 @@
+{
+ "value":[
+ {
+ "PlanItemId": 50,
+ "Description": "Client Meeting",
+ "ConfirmationCode": "4372899DD",
+ "StartsAt": "2014-01-02T13:00:00Z",
+ "EndsAt": "2014-01-02T16:00:00Z",
+ "Duration": "PT3H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Regus Business Center",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "100 Church Street, 8th Floor, Manhattan, 10007"
+ }
+ },
+ {
+ "PlanItemId": 51,
+ "Description": "Visit the Brooklyn Bridge Park",
+ "ConfirmationCode": "4372899AA",
+ "StartsAt": "2014-01-01T15:00:00Z",
+ "EndsAt": "2014-01-01T16:00:00Z",
+ "Duration": "PT1H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Brooklyn Bridge Park, at Fulton Ferry Landing",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "Main St Dumbo Brooklyn 11201"
+ }
+ },
+ {
+ "PlanItemId": 52,
+ "Description": "Empire State Building",
+ "ConfirmationCode": "4372899BB",
+ "StartsAt": "2014-01-03T10:00:00Z",
+ "EndsAt": "2014-01-03T12:00:00Z",
+ "Duration": "PT2H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Empire State Building",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "Empire State Building, 350 5th Ave"
+ }
+ },
+ {
+ "PlanItemId": 53,
+ "Description": "Coney Island",
+ "ConfirmationCode": "4372899CC",
+ "StartsAt": "2014-01-03T14:00:00Z",
+ "EndsAt": "2014-01-03T20:00:00Z",
+ "Duration": "PT6H",
+ "OccursAt":
+ {
+ "BuildingInfo": "",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "1208 Surf Ave, Brooklyn"
+ }
+ },
+ {
+ "PlanItemId": 54,
+ "Description": "Shopping at Times Square",
+ "ConfirmationCode": "4372899DD",
+ "StartsAt": "2014-01-04T10:00:00Z",
+ "EndsAt": "2014-01-04T15:00:00Z",
+ "Duration": "PT5H",
+ "OccursAt":
+ {
+ "BuildingInfo": "",
+ "City":
+ {
+ "Name": "New York City",
+ "CountryRegion": "United States",
+ "Region": "New York"
+ },
+ "Address": "Broadway, 7th Avenue, 42nd and 47th Streets"
+ }
+ },
+ {
+ "PlanItemId": 55,
+ "Description": "Dinner",
+ "ConfirmationCode": "4372899EE",
+ "StartsAt": "2014-02-02T18:00:00Z",
+ "EndsAt": "2014-02-02T21:00:00Z",
+ "Duration": "PT3H",
+ "OccursAt":
+ {
+ "Address": "10 Beijing Street, 100000",
+ "City":
+ {
+ "Name": "Beijing",
+ "CountryRegion": "China",
+ "Region": "Beijing"
+ },
+ "BuildingInfo": "Beijing Restaurant"
+ }
+ },
+ {
+ "PlanItemId": 56,
+ "Description": "Dinner",
+ "ConfirmationCode": "4372899FF",
+ "StartsAt": "2014-02-02T18:00:00Z",
+ "EndsAt": "2014-02-02T21:00:00Z",
+ "Duration": "PT3H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Beijing Restaurant",
+ "City":
+ {
+ "Name": "Beijing",
+ "CountryRegion": "China",
+ "Region": "Beijing"
+ },
+ "Address": "10 Beijing Street, 100000"
+ }
+ },
+ {
+ "PlanItemId": 57,
+ "Description": "Dinner",
+ "ConfirmationCode": "4372899GG",
+ "StartsAt": "2014-02-02T18:00:00Z",
+ "EndsAt": "2014-02-02T21:00:00Z",
+ "Duration": "PT3H",
+ "OccursAt":
+ {
+ "BuildingInfo": "Beijing Restaurant",
+ "City":
+ {
+ "Name": "Beijing",
+ "CountryRegion": "China",
+ "Region": "Beijing"
+ },
+ "Address": "10 Beijing Street, 100000"
+ }
+ }
+ ]
+}
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/flight-links.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/flight-links.json b/lib/server-core-ext/src/test/resources/flight-links.json
new file mode 100644
index 0000000..17741d0
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/flight-links.json
@@ -0,0 +1,52 @@
+{
+ "value":[
+ {
+ "PlanItemId": 1,
+ "Airline": "AA",
+ "From": "ORD",
+ "To": "JFK"
+ },
+ {
+ "PlanItemId": 2,
+ "Airline": "AA",
+ "From": "JFK",
+ "To": "ORD"
+ },
+ {
+ "PlanItemId": 3,
+ "Airline": "FM",
+ "From": "SHA",
+ "To": "PEK"
+ },
+ {
+ "PlanItemId": 4,
+ "Airline": "MU",
+ "From": "PEK",
+ "To": "SHA"
+ },
+ {
+ "PlanItemId": 5,
+ "Airline": "FM",
+ "From": "SHA",
+ "To": "PEK"
+ },
+ {
+ "PlanItemId": 6,
+ "Airline": "MU",
+ "From": "PEK",
+ "To": "SHA"
+ },
+ {
+ "PlanItemId": 7,
+ "Airline": "FM",
+ "From": "SHA",
+ "To": "PEK"
+ },
+ {
+ "PlanItemId": 8,
+ "Airline": "MU",
+ "From": "PEK",
+ "To": "SHA"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/flight.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/flight.json b/lib/server-core-ext/src/test/resources/flight.json
new file mode 100644
index 0000000..af06998
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/flight.json
@@ -0,0 +1,66 @@
+{
+ "value":[
+ {
+ "PlanItemId": 1,
+ "ConfirmationCode": "JH58493",
+ "FlightNumber": "AA26",
+ "StartsAt": "2014-01-01T06:15:00Z",
+ "EndsAt": "2014-01-01T11:35:00Z"
+ },
+ {
+ "PlanItemId": 2,
+ "ConfirmationCode": "JH38143",
+ "FlightNumber": "AA4035",
+ "StartsAt": "2014-01-04T17:55:00Z",
+ "EndsAt": "2014-01-04T20:45:00Z"
+ },
+ {
+ "PlanItemId": 3,
+ "ConfirmationCode": "JH58494",
+ "FlightNumber": "FM1930",
+ "StartsAt": "2014-02-01T08:00:00Z",
+ "EndsAt": "2014-02-01T09:20:00Z",
+ "SeatNumber": "B11"
+ },
+ {
+ "PlanItemId": 4,
+ "ConfirmationCode": "JH58495",
+ "FlightNumber": "MU1930",
+ "StartsAt": "2014-02-10T15:00:00Z",
+ "EndsAt": "2014-02-10T16:30:00Z",
+ "SeatNumber": "A32"
+ },
+ {
+ "PlanItemId": 5,
+ "ConfirmationCode": "JH58494",
+ "FlightNumber": "FM1930",
+ "StartsAt": "2014-02-01T08:00:00Z",
+ "EndsAt": "2014-02-01T09:20:00Z",
+ "SeatNumber": "B11"
+ },
+ {
+ "PlanItemId": 6,
+ "ConfirmationCode": "JH58495",
+ "FlightNumber": "MU1930",
+ "StartsAt": "2014-02-10T15:00:00Z",
+ "EndsAt": "2014-02-10T16:30:00Z",
+ "SeatNumber": "A32"
+ },
+ {
+ "PlanItemId": 7,
+ "ConfirmationCode": "JH58494",
+ "FlightNumber": "FM1930",
+ "StartsAt": "2014-02-01T08:00:00Z",
+ "EndsAt": "2014-02-01T09:20:00Z",
+ "SeatNumber": "B12"
+ },
+ {
+ "PlanItemId": 8,
+ "ConfirmationCode": "JH58495",
+ "FlightNumber": "MU1930",
+ "StartsAt": "2014-02-10T16:30:00Z",
+ "EndsAt": "2014-02-10T16:30:00Z",
+ "SeatNumber": "A33"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/people-links.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/people-links.json b/lib/server-core-ext/src/test/resources/people-links.json
new file mode 100644
index 0000000..878d6ce
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/people-links.json
@@ -0,0 +1,94 @@
+{
+ "value":[
+ {
+ "UserName":"russellwhyte",
+ "Friends": ["scottketchum", "ronaldmundy", "javieralfred", "angelhuffman"],
+ "Trips": [1001, 1003, 1007],
+ "Photo": 1
+ },
+ {
+ "UserName":"scottketchum",
+ "Friends": ["russellwhyte", "ronaldmundy"],
+ "Trips": [1001, 2004],
+ "Photo": 11
+ },
+ {
+ "UserName":"ronaldmundy",
+ "Friends": ["russellwhyte", "scottketchum"],
+ "Trips": [3009],
+ "Photo": 12
+ },
+ {
+ "UserName":"javieralfred",
+ "Friends": ["willieashmore", "vincentcalabrese", "georginabarlow"],
+ "Trips": [4005]
+ },
+ {
+ "UserName":"willieashmore",
+ "Friends": ["javieralfred", "vincentcalabrese"],
+ "Trips": [5007, 5008]
+ },
+ {
+ "UserName":"vincentcalabrese",
+ "Friends": ["javieralfred", "willieashmore"],
+ "Trips": [7010]
+ },
+ {
+ "UserName":"clydeguess",
+ "Friends": ["keithpinckney", "ursulabright"],
+ "Trips": [8011]
+ },
+ {
+ "UserName":"keithpinckney",
+ "Friends": ["clydeguess", "marshallgaray"],
+ "Trips": []
+ },
+ {
+ "UserName":"marshallgaray",
+ "Friends": ["keithpinckney", "elainestewart", "jonirosales"]
+ },
+ {
+ "UserName":"elainestewart",
+ "Friends": ["marshallgaray"]
+ },
+ {
+ "UserName":"salliesampson",
+ "Friends": [""],
+ "Trips": [13012]
+ },
+ {
+ "UserName":"jonirosales",
+ "Friends": ["marshallgaray"],
+ "Trips": [14013]
+ },
+ {
+ "UserName":"georginabarlow",
+ "Friends": ["javieralfred"]
+ },
+ {
+ "UserName":"angelhuffman",
+ "Friends": ["russellwhyte"],
+ "Trips": [16014]
+ },
+ {
+ "UserName":"laurelosborn",
+ "Friends": ["sandyosborn"]
+ },
+ {
+ "UserName":"sandyosborn",
+ "Friends": ["laurelosborn"]
+ },
+ {
+ "UserName":"ursulabright",
+ "Friends": ["keithpinckney"]
+ },
+ {
+ "UserName":"genevievereeves",
+ "Friends": ["kristakemp"]
+ },
+ {
+ "UserName":"kristakemp",
+ "Friends": ["genevievereeves"]
+ }
+ ]
+}
[12/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Edm Cleanup
part 2
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
index 47a9136..2e2d4a6 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
@@ -249,7 +249,7 @@ public class MetadataDocumentXmlSerializerTest {
properties.add(new Property().setName("prop2").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
complexType.setProperties(properties);
- EdmComplexTypeImpl c1 = EdmComplexTypeImpl.getInstance(edm, name, complexType);
+ EdmComplexTypeImpl c1 = new EdmComplexTypeImpl(edm, name, complexType);
complexTypes.add(c1);
when(schema.getComplexTypes()).thenReturn(complexTypes);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
index 90ffca1..ee62068 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
@@ -18,9 +18,12 @@
*/
package org.apache.olingo.server.tecsvc.provider;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.commons.api.edm.provider.ActionImport;
import org.apache.olingo.commons.api.edm.provider.EntityContainer;
import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo;
@@ -29,10 +32,6 @@ import org.apache.olingo.commons.api.edm.provider.FunctionImport;
import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
import org.apache.olingo.commons.api.edm.provider.Singleton;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
public class ContainerProvider {
public static final FullQualifiedName nameContainer = new FullQualifiedName(SchemaProvider.NAMESPACE, "Container");
@@ -158,10 +157,10 @@ public class ContainerProvider {
.setNavigationPropertyBindings(Arrays.asList(
new NavigationPropertyBinding()
.setPath("NavPropertyETTwoPrimOne")
- .setTarget(new Target().setTargetName("ESTwoPrim").toString()),
+ .setTarget("ESTwoPrim"),
new NavigationPropertyBinding()
.setPath("NavPropertyETTwoPrimMany")
- .setTarget(new Target().setTargetName("ESTwoPrim").toString())
+ .setTarget("ESTwoPrim")
));
} else if (name.equals("ESCollAllPrim")) {
@@ -176,10 +175,10 @@ public class ContainerProvider {
.setNavigationPropertyBindings(Arrays.asList(
new NavigationPropertyBinding()
.setPath("NavPropertyETAllPrimOne")
- .setTarget(new Target().setTargetName("ESAllPrim").toString()),
+ .setTarget("ESAllPrim"),
new NavigationPropertyBinding()
.setPath("NavPropertyETAllPrimMany")
- .setTarget(new Target().setTargetName("ESAllPrim").toString())
+ .setTarget("ESAllPrim")
));
} else if (name.equals("ESMixPrimCollComp")) {
@@ -272,55 +271,55 @@ public class ContainerProvider {
.setNavigationPropertyBindings(Arrays.asList(
new NavigationPropertyBinding()
.setPath("NavPropertyETKeyNavOne")
- .setTarget(new Target().setTargetName("ESKeyNav").toString()),
+ .setTarget("ESKeyNav"),
new NavigationPropertyBinding()
.setPath("NavPropertyETKeyNavMany")
- .setTarget(new Target().setTargetName("ESKeyNav").toString()),
+ .setTarget("ESKeyNav"),
new NavigationPropertyBinding()
.setPath("NavPropertyETTwoKeyNavOne")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("NavPropertyETMediaOne")
- .setTarget(new Target().setTargetName("ESMedia").toString()),
+ .setTarget("ESMedia"),
new NavigationPropertyBinding()
.setPath("NavPropertyETMediaMany")
- .setTarget(new Target().setTargetName("ESMedia").toString()),
+ .setTarget("ESMedia"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/NavPropertyETTwoKeyNavOn")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/NavPropertyETMediaOne")
- .setTarget(new Target().setTargetName("ESMedia").toString()),
+ .setTarget("ESMedia"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/NavPropertyETMediaMany")
- .setTarget(new Target().setTargetName("ESMedia").toString()),
+ .setTarget("ESMedia"),
new NavigationPropertyBinding()
.setPath("PropertyCompCompNav/PropertyCompNav/NavPropertyETTwoKeyNavOne")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompCompNav/PropertyCompNav/NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompCompNav/PropertyCompNav/NavPropertyETMediaOne")
- .setTarget(new Target().setTargetName("ESMedia").toString()),
+ .setTarget("ESMedia"),
new NavigationPropertyBinding()
.setPath("PropertyCompCompNav/PropertyCompNav/NavPropertyETMediaMany")
- .setTarget(new Target().setTargetName("ESMedia").toString()),
+ .setTarget("ESMedia"),
new NavigationPropertyBinding()
.setPath("ETKeyNav/PropertyCompNav/NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("ETKeyNav/PropertyCompNav/NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/com.corp.odata.test1.CTNavFiveProp/NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString())
+ .setTarget("ESTwoKeyNav")
));
} else if (name.equals("ESTwoKeyNav")) {
@@ -330,49 +329,49 @@ public class ContainerProvider {
.setNavigationPropertyBindings(Arrays.asList(
new NavigationPropertyBinding()
.setPath("NavPropertyETKeyNavOne")
- .setTarget(new Target().setTargetName("ESKeyNav").toString()),
+ .setTarget("ESKeyNav"),
new NavigationPropertyBinding()
.setPath("NavPropertyETKeyNavMany")
- .setTarget(new Target().setTargetName("ESKeyNav").toString()),
+ .setTarget("ESKeyNav"),
new NavigationPropertyBinding()
.setPath("NavPropertyETTwoKeyNavOne")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/NavPropertyETTwoKeyNavOne")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/NavPropertyETKeyNavOne")
- .setTarget(new Target().setTargetName("ESKeyNav").toString()),
+ .setTarget("ESKeyNav"),
new NavigationPropertyBinding()
.setPath("PropertyCompNav/NavPropertyETKeyNavMany")
- .setTarget(new Target().setTargetName("ESKeyNav").toString()),
+ .setTarget("ESKeyNav"),
new NavigationPropertyBinding()
.setPath("CollPropertyCompNav/NavPropertyETTwoKeyNavOne")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("CollPropertyCompNav/NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("CollPropertyCompNav/NavPropertyETMediaOne")
- .setTarget(new Target().setTargetName("ESMedia").toString()),
+ .setTarget("ESMedia"),
new NavigationPropertyBinding()
.setPath("CollPropertyCompNav/NavPropertyETMediaMany")
- .setTarget(new Target().setTargetName("ESMedia").toString()),
+ .setTarget("ESMedia"),
new NavigationPropertyBinding()
.setPath("CollPropertyCompNav/NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString()),
+ .setTarget("ESTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("NavPropertyETTwoBaseTwoKeyNavOne")
- .setTarget(new Target().setTargetName("ESBaseTwoKeyNav").toString()),
+ .setTarget("ESBaseTwoKeyNav"),
new NavigationPropertyBinding()
.setPath("NavPropertySINav")
- .setTarget(new Target().setTargetName("SINav").toString())
+ .setTarget("SINav")
));
} else if (name.equals("ESBaseTwoKeyNav")) {
@@ -491,7 +490,7 @@ public class ContainerProvider {
return new FunctionImport()
.setName(name)
.setFunction(FunctionProvider.nameUFCRTETTwoKeyNav)
- .setEntitySet(new Target().setEntityContainer(entityContainer).setTargetName("ESTwoKeyNav").toString())
+ .setEntitySet(entityContainer.getFullQualifiedNameAsString() + "/ESTwoKeyNav")
.setIncludeInServiceDocument(true);
} else if (name.equals("FICRTETTwoKeyNavParam")) {
return new FunctionImport()
@@ -539,13 +538,13 @@ public class ContainerProvider {
return new FunctionImport()
.setName(name)
.setFunction(FunctionProvider.nameUFCRTETMedia)
- .setEntitySet(new Target().setEntityContainer(entityContainer).setTargetName("ESMedia").toString())
+ .setEntitySet(entityContainer.getFullQualifiedNameAsString() + "/ESMedia")
.setIncludeInServiceDocument(true);
} else if (name.equals("FICRTCollESMedia")) {
return new FunctionImport()
.setName(name)
.setFunction(FunctionProvider.nameUFCRTCollETMedia)
- .setEntitySet(new Target().setEntityContainer(entityContainer).setTargetName("ESMedia").toString())
+ .setEntitySet(entityContainer.getFullQualifiedNameAsString() + "/ESMedia")
.setIncludeInServiceDocument(true);
} else if (name.equals("FICRTCTTwoPrimParam")) {
@@ -576,7 +575,7 @@ public class ContainerProvider {
return new FunctionImport()
.setName(name)
.setFunction(FunctionProvider.nameUFCRTCollETTwoKeyNavParam)
- .setEntitySet(new Target().setEntityContainer(entityContainer).setTargetName("ESTwoKeyNav").toString())
+ .setEntitySet(entityContainer.getFullQualifiedNameAsString() + "/ESTwoKeyNav")
.setIncludeInServiceDocument(true);
} else if (name.equals("FICRTCollCTTwoPrimParam")) {
@@ -606,7 +605,7 @@ public class ContainerProvider {
.setNavigationPropertyBindings(Arrays.asList(
new NavigationPropertyBinding()
.setPath("NavPropertyETTwoKeyNavMany")
- .setTarget(new Target().setTargetName("ESTwoKeyNav").toString())));
+ .setTarget("ESTwoKeyNav")));
} else if (name.equals("SIMedia")) {
return new Singleton()
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/898d745b/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java
----------------------------------------------------------------------
diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java b/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java
index 5f59db4..dac970d 100644
--- a/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java
+++ b/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java
@@ -25,7 +25,6 @@ import java.util.List;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
import org.apache.olingo.commons.api.edm.provider.ComplexType;
import org.apache.olingo.commons.api.edm.provider.EdmProvider;
import org.apache.olingo.commons.api.edm.provider.EntityContainer;
@@ -122,15 +121,14 @@ public class CarsEdmProvider extends EdmProvider {
.setNavigationPropertyBindings(
Arrays.asList(
new NavigationPropertyBinding().setPath("Manufacturer").setTarget(
- new Target().setTargetName(ES_MANUFACTURER_NAME).setEntityContainer(CONTAINER_FQN)
- .toString())));
+ CONTAINER_FQN.getFullQualifiedNameAsString() + "/" + ES_MANUFACTURER_NAME)));
} else if (ES_MANUFACTURER_NAME.equals(entitySetName)) {
return new EntitySet()
.setName(ES_MANUFACTURER_NAME)
.setType(ET_MANUFACTURER).setNavigationPropertyBindings(
Arrays.asList(
- new NavigationPropertyBinding().setPath("Cars").setTarget(
- new Target().setTargetName(ES_CARS_NAME).setEntityContainer(CONTAINER_FQN).toString())));
+ new NavigationPropertyBinding().setPath("Cars")
+ .setTarget(CONTAINER_FQN.getFullQualifiedNameAsString() + "/" + ES_CARS_NAME)));
}
}
[17/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index e6193df..1f28900 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@ -6,9 +6,9 @@
* 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
@@ -41,11 +41,14 @@ import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
+import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
+
public class DataCreator {
private static final UUID GUID = UUID.fromString("01234567-89ab-cdef-0123-456789abcdef");
-
+ private static final String ctPropComp = ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString();
private final Map<String, EntitySet> data;
public DataCreator() {
@@ -96,7 +99,9 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt16", i))
.addProperty(createPrimitive("PropertyString", "Number:" + i)));
}
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETServerSidePaging.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -106,7 +111,9 @@ public class DataCreator {
entitySet.getEntities().add(createETKeyNavEntity(1, "I am String Property 1"));
entitySet.getEntities().add(createETKeyNavEntity(2, "I am String Property 2"));
entitySet.getEntities().add(createETKeyNavEntity(3, "I am String Property 3"));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETKeyNav.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -115,10 +122,12 @@ public class DataCreator {
return new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", propertyInt16))
.addProperty(createPrimitive("PropertyString", propertyString))
- .addProperty(createComplex("PropertyCompNav",
+ .addProperty(createComplex("PropertyCompNav", ctPropComp,
createPrimitive("PropertyInt16", 1)))
.addProperty(createKeyNavAllPrimComplexValue("PropertyCompAllPrim"))
- .addProperty(createComplex("PropertyCompTwoPrim",
+ .addProperty(
+ createComplex("PropertyCompTwoPrim",
+ ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
createPrimitive("PropertyInt16", 16),
createPrimitive("PropertyString", "Test123")))
.addProperty(createPrimitiveCollection("CollPropertyString",
@@ -126,7 +135,9 @@ public class DataCreator {
"Employee2@company.example",
"Employee3@company.example"))
.addProperty(createPrimitiveCollection("CollPropertyInt16", 1000, 2000, 30112))
- .addProperty(createComplexCollection("CollPropertyComp",
+ .addProperty(
+ createComplexCollection("CollPropertyComp", ComplexTypeProvider.nameCTPrimComp
+ .getFullQualifiedNameAsString(),
Arrays.asList(
createPrimitive("PropertyInt16", 1),
createKeyNavAllPrimComplexValue("PropertyComp")),
@@ -136,9 +147,11 @@ public class DataCreator {
Arrays.asList(
createPrimitive("PropertyInt16", 3),
createKeyNavAllPrimComplexValue("PropertyComp"))))
- .addProperty(createComplex("PropertyCompCompNav",
+ .addProperty(
+ createComplex("PropertyCompCompNav",
+ ComplexTypeProvider.nameCTCompComp.getFullQualifiedNameAsString(),
createPrimitive("PropertyString", "1"),
- createComplex("PropertyComp", createPrimitive("PropertyInt16", 1))));
+ createComplex("PropertyComp", ctPropComp, createPrimitive("PropertyInt16", 1))));
}
private EntitySet createESTwoKeyNav() {
@@ -148,7 +161,9 @@ public class DataCreator {
entitySet.getEntities().add(createESTwoKeyNavEntity(1, "2"));
entitySet.getEntities().add(createESTwoKeyNavEntity(2, "1"));
entitySet.getEntities().add(createESTwoKeyNavEntity(3, "1"));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETTwoKeyNav.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -157,9 +172,9 @@ public class DataCreator {
return new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", propertyInt16))
.addProperty(createPrimitive("PropertyString", propertyString))
- .addProperty(createComplex("PropertyComp",
+ .addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 11),
- createComplex("PropertyComp",
+ createComplex("PropertyComp", ctPropComp,
createPrimitive("PropertyString", "StringValue"),
createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }),
createPrimitive("PropertyBoolean", true),
@@ -175,20 +190,26 @@ public class DataCreator {
createPrimitive("PropertyInt64", Long.MAX_VALUE),
createPrimitive("PropertySByte", Byte.MAX_VALUE),
createPrimitive("PropertyTimeOfDay", getTime(21, 5, 59)))))
- .addProperty(createComplex("PropertyCompNav",
+ .addProperty(
+ createComplex("PropertyCompNav",
+ ComplexTypeProvider.nameCTCompNav.getFullQualifiedNameAsString(),
createPrimitive("PropertyInt16", 1),
createKeyNavAllPrimComplexValue("PropertyComp")))
- .addProperty(createComplexCollection("CollPropertyComp"))
- .addProperty(createComplexCollection("CollPropertyCompNav",
+ .addProperty(createComplexCollection("CollPropertyComp", null))
+ .addProperty(
+ createComplexCollection("CollPropertyCompNav",
+ ComplexTypeProvider.nameCTCompNav.getFullQualifiedNameAsString(),
Arrays.asList(createPrimitive("PropertyInt16", 1))))
.addProperty(createPrimitiveCollection("CollPropertyString", 1, 2))
- .addProperty(createComplex("PropertyCompTwoPrim",
+ .addProperty(
+ createComplex("PropertyCompTwoPrim",
+ ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
createPrimitive("PropertyInt16", 11),
createPrimitive("PropertyString", "11")));
}
private Property createKeyNavAllPrimComplexValue(final String name) {
- return createComplex(name,
+ return createComplex(name, ComplexTypeProvider.nameCTAllPrim.getFullQualifiedNameAsString(),
createPrimitive("PropertyString", "First Resource - positive values"),
createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }),
createPrimitive("PropertyBoolean", true),
@@ -213,8 +234,9 @@ public class DataCreator {
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
- .addProperty(createComplex("PropertyComp",
- createComplexCollection("CollPropertyComp",
+ .addProperty(createComplex("PropertyComp", null,
+ createComplexCollection("CollPropertyComp", ComplexTypeProvider.nameCTTwoPrim
+ .getFullQualifiedNameAsString(),
Arrays.asList(
createPrimitive("PropertyInt16", 555),
createPrimitive("PropertyString", "1 Test Complex in Complex Property")),
@@ -227,8 +249,9 @@ public class DataCreator {
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", 12345))
- .addProperty(createComplex("PropertyComp",
- createComplexCollection("CollPropertyComp",
+ .addProperty(createComplex("PropertyComp",null,
+ createComplexCollection("CollPropertyComp", ComplexTypeProvider.nameCTTwoPrim
+ .getFullQualifiedNameAsString(),
Arrays.asList(
createPrimitive("PropertyInt16", 888),
createPrimitive("PropertyString", "11 Test Complex in Complex Property")),
@@ -238,7 +261,9 @@ public class DataCreator {
Arrays.asList(
createPrimitive("PropertyInt16", 0),
createPrimitive("PropertyString", "13 Test Complex in Complex Property"))))));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETCompCollComp.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -260,7 +285,9 @@ public class DataCreator {
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
.addProperty(createPrimitive("PropertyString", "Test String4")));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETTwoPrim.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -322,7 +349,9 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyDuration", 0))
.addProperty(createPrimitive("PropertyGuid", UUID.fromString("76543201-23ab-cdef-0123-456789cccddd")))
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(0, 1, 1))));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETAllPrim.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -331,7 +360,7 @@ public class DataCreator {
Entity entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE));
- entity.addProperty(createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyString", "First Resource - first"),
createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
@@ -353,7 +382,7 @@ public class DataCreator {
entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 7));
- entity.addProperty(createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyString", "Second Resource - second"),
createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
@@ -375,7 +404,7 @@ public class DataCreator {
entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 0));
- entity.addProperty(createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyString", "Third Resource - third"),
createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
@@ -394,7 +423,9 @@ public class DataCreator {
createPrimitive("PropertySByte", Byte.MAX_VALUE),
createPrimitive("PropertyTimeOfDay", getTime(13, 27, 45))));
entitySet.getEntities().add(entity);
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETCompAllPrim.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -444,13 +475,15 @@ public class DataCreator {
entity.getProperties().addAll(entitySet.getEntities().get(0).getProperties());
entity.getProperties().set(0, createPrimitive("PropertyInt16", 3));
entitySet.getEntities().add(entity);
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETCollAllPrim.getFullQualifiedNameAsString());
+ }
return entitySet;
}
private EntitySet createESMixPrimCollComp() {
@SuppressWarnings("unchecked")
- final Property complexCollection = createComplexCollection("CollPropertyComp",
+ final Property complexCollection = createComplexCollection("CollPropertyComp", ctPropComp,
Arrays.asList(createPrimitive("PropertyInt16", 123), createPrimitive("PropertyString", "TEST 1")),
Arrays.asList(createPrimitive("PropertyInt16", 456), createPrimitive("PropertyString", "TEST 2")),
Arrays.asList(createPrimitive("PropertyInt16", 789), createPrimitive("PropertyString", "TEST 3")));
@@ -461,7 +494,7 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
.addProperty(createPrimitiveCollection("CollPropertyString",
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
+ .addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 111),
createPrimitive("PropertyString", "TEST A")))
.addProperty(complexCollection));
@@ -470,7 +503,7 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt16", 7))
.addProperty(createPrimitiveCollection("CollPropertyString",
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
+ .addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 222),
createPrimitive("PropertyString", "TEST B")))
.addProperty(complexCollection));
@@ -479,11 +512,13 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt16", 0))
.addProperty(createPrimitiveCollection("CollPropertyString",
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
+ .addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 333),
createPrimitive("PropertyString", "TEST C")))
.addProperty(complexCollection));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETMixPrimCollComp.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -519,7 +554,9 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyDuration", 6))
.addProperty(createPrimitive("PropertyGuid", GUID))
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(2, 48, 21))));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETAllKey.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -528,20 +565,22 @@ public class DataCreator {
Entity entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 1));
- entity.addProperty(createComplex("PropertyComp",
- createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp", null,
+ createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 123),
createPrimitive("PropertyString", "String 1"))));
entitySet.getEntities().add(entity);
entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 2));
- entity.addProperty(createComplex("PropertyComp",
- createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp", null,
+ createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 987),
createPrimitive("PropertyString", "String 2"))));
entitySet.getEntities().add(entity);
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETCompComp.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -571,7 +610,9 @@ public class DataCreator {
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("black")));
entity.setMediaContentType("image/svg+xml");
entitySet.getEntities().add(entity);
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETMedia.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -677,22 +718,23 @@ public class DataCreator {
return new PropertyImpl(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(values));
}
- protected static Property createComplex(final String name, final Property... properties) {
+ protected static Property createComplex(final String name, String type, final Property... properties) {
ComplexValue complexValue = new ComplexValueImpl();
for (final Property property : properties) {
complexValue.getValue().add(property);
}
- return new PropertyImpl(null, name, ValueType.COMPLEX, complexValue);
+ return new PropertyImpl(type, name, ValueType.COMPLEX, complexValue);
}
- protected static Property createComplexCollection(final String name, final List<Property>... propertiesList) {
+ protected static Property createComplexCollection(final String name, String type,
+ final List<Property>... propertiesList) {
List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
for (final List<Property> properties : propertiesList) {
ComplexValue complexValue = new ComplexValueImpl();
complexValue.getValue().addAll(properties);
complexCollection.add(complexValue);
}
- return new PropertyImpl(null, name, ValueType.COLLECTION_COMPLEX, complexCollection);
+ return new PropertyImpl(type, name, ValueType.COLLECTION_COMPLEX, complexCollection);
}
private Calendar getDateTime(final int year, final int month, final int day,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
index fed499f..4fc9300 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
@@ -6,9 +6,9 @@
* 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
@@ -138,7 +138,7 @@ public class DataProvider {
final List<Entity> entities = entitySet.getEntities();
final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntitySet.getEntityType());
final Entity newEntity = new EntityImpl();
-
+ newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
for (final String keyName : edmEntityType.getKeyPredicateNames()) {
newEntity.addProperty(DataCreator.createPrimitive(keyName, newKey.get(keyName)));
}
@@ -194,7 +194,8 @@ public class DataProvider {
return true;
}
- private void createProperties(final EdmStructuredType type, List<Property> properties) throws DataProviderException {
+ private void createProperties(final EdmStructuredType type, List<Property> properties)
+ throws DataProviderException {
final List<String> keyNames = type instanceof EdmEntityType ?
((EdmEntityType) type).getKeyPredicateNames() : Collections.<String> emptyList();
for (final String propertyName : type.getPropertyNames()) {
@@ -204,11 +205,11 @@ public class DataProvider {
}
}
}
-
- private Property createProperty(final EdmProperty edmProperty, final String propertyName)
+
+ private Property createProperty(final EdmProperty edmProperty, final String propertyName)
throws DataProviderException {
Property newProperty;
-
+
if (edmProperty.isPrimitive()) {
newProperty = edmProperty.isCollection() ?
DataCreator.createPrimitiveCollection(propertyName) :
@@ -216,17 +217,19 @@ public class DataProvider {
} else {
if (edmProperty.isCollection()) {
@SuppressWarnings("unchecked")
- Property newProperty2 = DataCreator.createComplexCollection(propertyName);
+ Property newProperty2 = DataCreator.createComplexCollection(propertyName, edmProperty
+ .getType().getFullQualifiedName().getFullQualifiedNameAsString());
newProperty = newProperty2;
} else {
- newProperty = DataCreator.createComplex(propertyName);
+ newProperty = DataCreator.createComplex(propertyName, edmProperty.getType()
+ .getFullQualifiedName().getFullQualifiedNameAsString());
createProperties((EdmComplexType) edmProperty.getType(), newProperty.asComplex().getValue());
}
}
-
+
return newProperty;
}
-
+
public void update(final String rawBaseUri, final EdmEntitySet edmEntitySet, Entity entity,
final Entity changedEntity, final boolean patch, final boolean isInsert) throws DataProviderException {
@@ -433,7 +436,7 @@ public class DataProvider {
}
}
- private ComplexValue createComplexValue(final EdmProperty edmProperty, final ComplexValue complexValue,
+ private ComplexValue createComplexValue(final EdmProperty edmProperty, final ComplexValue complexValue,
final boolean patch) throws DataProviderException {
final ComplexValueImpl result = new ComplexValueImpl();
final EdmComplexType edmType = (EdmComplexType) edmProperty.getType();
@@ -445,7 +448,7 @@ public class DataProvider {
final Property currentProperty = findProperty(propertyName, givenProperties);
final Property newProperty = createProperty(innerEdmProperty, propertyName);
result.getValue().add(newProperty);
-
+
if (currentProperty != null) {
updateProperty(innerEdmProperty, newProperty, currentProperty, patch);
} else {
@@ -459,7 +462,7 @@ public class DataProvider {
}
}
}
-
+
return result;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
index 5451d5d..316a7b0 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
@@ -31,6 +31,7 @@ import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.uri.UriParameter;
import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException;
+import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
public class FunctionData {
@@ -80,12 +81,12 @@ public class FunctionData {
} else if (name.equals("UFCRTCollString")) {
return data.get("ESCollAllPrim").getEntities().get(0).getProperty("CollPropertyString");
} else if (name.equals("UFCRTCTTwoPrim")) {
- return DataCreator.createComplex(name,
+ return DataCreator.createComplex(name, ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
DataCreator.createPrimitive("PropertyInt16", 16),
DataCreator.createPrimitive("PropertyString", "UFCRTCTTwoPrim string value"));
} else if (name.equals("UFCRTCTTwoPrimParam")) {
try {
- return DataCreator.createComplex(name,
+ return DataCreator.createComplex(name,ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
DataCreator.createPrimitive("PropertyInt16",
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16).valueOfString(
getParameterText("ParameterInt16", parameters),
@@ -99,7 +100,7 @@ public class FunctionData {
throw new DataProviderException("Error in function " + name + ".", e);
}
} else if (name.equals("UFCRTCollCTTwoPrim")) {
- return DataCreator.createComplexCollection(name,
+ return DataCreator.createComplexCollection(name,ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 16),
DataCreator.createPrimitive("PropertyString", "Test123")),
Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 17),
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index f610fc2b..386592f 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -6,9 +6,9 @@
* 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
@@ -38,6 +38,7 @@ import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
import org.apache.olingo.server.api.processor.ActionEntityCollectionProcessor;
@@ -74,8 +75,11 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
EntityProcessor, ActionEntityProcessor, MediaEntityProcessor,
ActionVoidProcessor {
- public TechnicalEntityProcessor(final DataProvider dataProvider) {
+ private final ServiceMetadata serviceMetadata;
+
+ public TechnicalEntityProcessor(final DataProvider dataProvider, ServiceMetadata serviceMetadata) {
super(dataProvider);
+ this.serviceMetadata = serviceMetadata;
}
@Override
@@ -109,21 +113,21 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
entitySet,
edmEntitySet,
request.getRawRequestUri());
-
+
// Apply expand system query option
final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
-
+
// Create a shallow copy of each entity. So the expanded navigation properties can be modified for serialization,
// without affecting the data stored in the database.
final ExpandSystemQueryOptionHandler expandHandler = new ExpandSystemQueryOptionHandler();
final EntitySet entitySetSerialization = expandHandler.copyEntitySetShallowRekursive(entitySet);
expandHandler.applyExpandQueryOptions(entitySetSerialization, edmEntitySet, expand);
-
+
// Serialize
- response.setContent(serializer.entityCollection(edmEntityType, entitySetSerialization,
+ response.setContent(serializer.entityCollection(this.serviceMetadata, edmEntityType, entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, edmEntityType, false, expand, select))
@@ -170,17 +174,17 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
edmEntitySet.getEntityType();
final Entity entity = readEntity(uriInfo);
-
+
final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
-
+
final ExpandSystemQueryOptionHandler expandHandler = new ExpandSystemQueryOptionHandler();
final Entity entitySerialization = expandHandler.copyEntityShallowRekursive(entity);
expandHandler.applyExpandQueryOptions(entitySerialization, edmEntitySet, expand);
-
- response.setContent(serializer.entity(edmEntitySet.getEntityType(), entitySerialization,
+
+ response.setContent(serializer.entity(this.serviceMetadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, edmEntityType, true, expand, select))
@@ -233,7 +237,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
final ODataFormat format = ODataFormat.fromContentType(responseFormat);
ODataSerializer serializer = odata.createSerializer(format);
- response.setContent(serializer.entity(edmEntityType, entity,
+ response.setContent(serializer.entity(this.serviceMetadata, edmEntityType, entity,
EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, edmEntityType, true, null, null))
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
index e36dc6b..b853e48 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
@@ -6,9 +6,9 @@
* 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
@@ -44,6 +44,7 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.processor.ActionComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionComplexProcessor;
@@ -81,8 +82,12 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
ComplexProcessor, ActionComplexProcessor,
ComplexCollectionProcessor, ActionComplexCollectionProcessor {
- public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider) {
+ private final ServiceMetadata serviceMetadata;
+
+ public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider,
+ ServiceMetadata serviceMetadata) {
super(dataProvider);
+ this.serviceMetadata = serviceMetadata;
}
@Override
@@ -246,7 +251,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
.build()));
break;
case COMPLEX:
- response.setContent(serializer.complex((EdmComplexType) type, property,
+ response.setContent(serializer.complex(this.serviceMetadata,(EdmComplexType) type, property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
.build()));
@@ -262,7 +267,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
.build()));
break;
case COLLECTION_COMPLEX:
- response.setContent(serializer.complexCollection((EdmComplexType) type, property,
+ response.setContent(serializer.complexCollection(this.serviceMetadata, (EdmComplexType) type, property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
.build()));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
index 76edb33..4549a03 100644
--- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
+++ b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
@@ -22,9 +22,9 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
index cd421f4..870f7c3 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
@@ -6,9 +6,9 @@
* 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
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 038c668..ee38684 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -41,11 +41,12 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
-import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriHelper;
@@ -64,9 +65,9 @@ import org.junit.Test;
import org.mockito.Mockito;
public class ODataJsonSerializerTest {
-
- private static final Edm edm = OData.newInstance().createServiceMetadata(
- new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
+ private static final ServiceMetadata metadata = OData.newInstance().createServiceMetadata(
+ new EdmTechProvider(), Collections.<EdmxReference> emptyList());
+ private static final Edm edm = metadata.getEdm();
private static final EdmEntityContainer entityContainer = edm.getEntityContainer(
new FullQualifiedName("olingo.odata.test1", "Container"));
private final DataProvider data = new DataProvider();
@@ -77,7 +78,7 @@ public class ODataJsonSerializerTest {
public void entitySimple() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -109,7 +110,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
- final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity,
+ final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(),
+ entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()));
@@ -130,7 +132,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().clear();
- serializer.entity(edmEntitySet.getEntityType(), entity,
+ serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -142,7 +144,7 @@ public class ODataJsonSerializerTest {
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().get(0).setValue(ValueType.PRIMITIVE, false);
try {
- serializer.entity(edmEntitySet.getEntityType(), entity,
+ serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -163,7 +165,7 @@ public class ODataJsonSerializerTest {
entitySet.setNext(URI.create("/next"));
CountOption countOption = Mockito.mock(CountOption.class);
Mockito.when(countOption.getValue()).thenReturn(true);
- InputStream result = serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ InputStream result = serializer.entityCollection(metadata, edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build())
.count(countOption)
@@ -188,7 +190,7 @@ public class ODataJsonSerializerTest {
public void entityCollAllPrim() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().serviceRoot(URI.create("http://host/service/"))
.entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
@@ -224,7 +226,7 @@ public class ODataJsonSerializerTest {
public void entityCompAllPrim() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -257,7 +259,7 @@ public class ODataJsonSerializerTest {
public void entityMixPrimCollComp() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -280,7 +282,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
- final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity,
+ final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()));
@@ -295,7 +297,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA)
- .entity(edmEntitySet.getEntityType(), entity, null);
+ .entity(metadata, edmEntitySet.getEntityType(), entity, null);
final String resultString = IOUtils.toString(result);
final String expectedResult = "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}";
Assert.assertEquals(expectedResult, resultString);
@@ -306,7 +308,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final EntitySet entitySet = data.readAll(edmEntitySet);
InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA)
- .entityCollection(edmEntitySet.getEntityType(), entitySet,
+ .entityCollection(metadata, edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build());
final String resultString = IOUtils.toString(result);
@@ -323,7 +325,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.setMediaETag("theMediaETag");
- final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity,
+ final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(),
+ entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()));
@@ -337,7 +340,8 @@ public class ODataJsonSerializerTest {
public void entitySetMedia() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
final EntitySet entitySet = data.readAll(edmEntitySet);
- final String resultString = IOUtils.toString(serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ final String resultString = IOUtils.toString(serializer.entityCollection(metadata,
+ edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build()));
final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia\",\"value\":["
@@ -358,7 +362,7 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
selectItem1, selectItem2, selectItem2));
InputStream result = serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, null, select))
@@ -380,7 +384,7 @@ public class ODataJsonSerializerTest {
SelectItem selectItem2 = Mockito.mock(SelectItem.class);
Mockito.when(selectItem2.isStar()).thenReturn(true);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem1, selectItem2));
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.select(select)
@@ -399,7 +403,7 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString")));
InputStream result = serializer
- .entityCollection(entityType, entitySet,
+ .entityCollection(metadata, entityType, entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, null, select))
@@ -424,7 +428,7 @@ public class ODataJsonSerializerTest {
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString"),
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp")));
final String resultString = IOUtils.toString(serializer
- .entityCollection(entityType, entitySet,
+ .entityCollection(metadata, entityType, entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, null, select))
@@ -445,7 +449,7 @@ public class ODataJsonSerializerTest {
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne")));
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.expand(expand)
@@ -484,7 +488,7 @@ public class ODataJsonSerializerTest {
Mockito.when(expandItem.getSelectOption()).thenReturn(select);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
final String resultString = IOUtils.toString(serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
@@ -511,7 +515,7 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertySByte")));
final String resultString = IOUtils.toString(serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
@@ -538,7 +542,7 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyTimeOfDay")));
final String resultString = IOUtils.toString(serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
@@ -569,7 +573,7 @@ public class ODataJsonSerializerTest {
Mockito.when(expandItemFirst.getSelectOption()).thenReturn(select);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemFirst));
final String resultString = IOUtils.toString(serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
@@ -646,7 +650,7 @@ public class ODataJsonSerializerTest {
final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp");
final String resultString = IOUtils.toString(serializer
- .complex((EdmComplexType) edmProperty.getType(), property,
+ .complex(metadata, (EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with()
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
@@ -665,7 +669,7 @@ public class ODataJsonSerializerTest {
final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
final String resultString = IOUtils.toString(serializer
- .complexCollection((EdmComplexType) edmProperty.getType(), property,
+ .complexCollection(metadata, (EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with()
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
index 798c5c0..86cbf0e 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
@@ -6,9 +6,9 @@
* 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
@@ -1064,13 +1064,16 @@ public class TestUriParserImpl {
public void testAlias() throws Exception {
testUri.run("ESAllPrim", "$filter=PropertyInt16 eq @p1&@p1=1)")
.goFilter().is("<<PropertyInt16> eq <@p1>>");
- }
-
+ }
+
@Test
public void testLambda() throws Exception {
testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/all( l : true )")
.goFilter().is("<CollPropertyComp/<ALL;<true>>>");
+ testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/all( x : x/PropertyInt16 eq 2)")
+ .goFilter().is("<CollPropertyComp/<ALL;<<x/PropertyInt16> eq <2>>>>");
+
testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/any( l : true )")
.goFilter().is("<CollPropertyComp/<ANY;<true>>>");
testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/any( )")
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
index 1835bef..db3930e 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
@@ -6,9 +6,9 @@
* 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
@@ -18,6 +18,9 @@
*/
package org.apache.olingo.server.core.uri.validator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.commons.core.edm.provider.EdmProviderImpl;
@@ -31,9 +34,6 @@ import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
public class UriValidatorTest {
private static final String URI_ALL = "$all";
@@ -77,7 +77,7 @@ public class UriValidatorTest {
private static final String QO_SKIPTOKEN = "$skiptoken=123";
private static final String QO_TOP = "$top=1";
- private String[][] urisWithValidSystemQueryOptions = {
+ private final String[][] urisWithValidSystemQueryOptions = {
{ URI_ALL, QO_FILTER }, { URI_ALL, QO_FORMAT }, { URI_ALL, QO_EXPAND }, { URI_ALL, QO_COUNT },
{ URI_ALL, QO_ORDERBY }, /* { URI_ALL, QO_SEARCH }, */{ URI_ALL, QO_SELECT }, { URI_ALL, QO_SKIP },
{ URI_ALL, QO_SKIPTOKEN }, { URI_ALL, QO_TOP },
@@ -105,7 +105,7 @@ public class UriValidatorTest {
{ URI_REFERENCES, QO_FILTER }, { URI_REFERENCES, QO_FORMAT }, { URI_REFERENCES, QO_ORDERBY },
/* { URI_REFERENCES, QO_SEARCH }, */{ URI_REFERENCES, QO_SKIP }, { URI_REFERENCES, QO_SKIPTOKEN },
- { URI_REFERENCES, QO_TOP },
+ { URI_REFERENCES, QO_TOP }, { URI_REFERENCES, QO_ID },
{ URI_REFERENCE, QO_FORMAT },
@@ -160,7 +160,7 @@ public class UriValidatorTest {
{ ContainerProvider.AIRT_STRING }
};
- private String[][] urisWithNonValidSystemQueryOptions = {
+ private final String[][] urisWithNonValidSystemQueryOptions = {
{ URI_ALL, QO_ID },
{ URI_BATCH, QO_FILTER }, { URI_BATCH, QO_FORMAT }, { URI_BATCH, QO_ID }, { URI_BATCH, QO_EXPAND },
@@ -199,7 +199,7 @@ public class UriValidatorTest {
/* { URI_MEDIA_STREAM, QO_SEARCH }, */ { URI_MEDIA_STREAM, QO_SELECT }, { URI_MEDIA_STREAM, QO_SKIP },
{ URI_MEDIA_STREAM, QO_SKIPTOKEN }, { URI_MEDIA_STREAM, QO_TOP },
- { URI_REFERENCES, QO_ID }, { URI_REFERENCES, QO_EXPAND }, { URI_REFERENCES, QO_COUNT },
+ { URI_REFERENCES, QO_EXPAND }, { URI_REFERENCES, QO_COUNT },
{ URI_REFERENCES, QO_SELECT },
{ URI_REFERENCE, QO_FILTER }, { URI_REFERENCE, QO_ID }, { URI_REFERENCE, QO_EXPAND },
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java b/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
index d59d251..2e44e35 100644
--- a/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
+++ b/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
@@ -6,9 +6,9 @@
* 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
@@ -37,10 +37,11 @@ import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.sample.edmprovider.CarsEdmProvider;
public class DataProvider {
- private Map<String, EntitySet> data;
+ private final Map<String, EntitySet> data;
public DataProvider() {
data = new HashMap<String, EntitySet>();
@@ -133,6 +134,9 @@ public class DataProvider {
.addProperty(createPrimitive("Price", 167189.00))
.addProperty(createPrimitive("Currency", "EUR")));
+ for (Entity entity:entitySet.getEntities()) {
+ entity.setType(CarsEdmProvider.ET_CAR.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -149,6 +153,9 @@ public class DataProvider {
.addProperty(createPrimitive("Name", "Horse Powered Racing"))
.addProperty(createAddress("Horse Street 1", "Maranello", "41053", "Italy")));
+ for (Entity entity:entitySet.getEntities()) {
+ entity.setType(CarsEdmProvider.ET_MANUFACTURER.getFullQualifiedNameAsString());
+ }
return entitySet;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
----------------------------------------------------------------------
diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
index 891acbb..71b827d 100644
--- a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
+++ b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
@@ -6,9 +6,9 @@
* 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
@@ -74,7 +74,8 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
PrimitiveProcessor, PrimitiveValueProcessor, ComplexProcessor {
private OData odata;
- private DataProvider dataProvider;
+ private final DataProvider dataProvider;
+ private ServiceMetadata edm;
// This constructor is application specific and not mandatory for the Olingo library. We use it here to simulate the
// database access
@@ -85,6 +86,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
@Override
public void init(OData odata, ServiceMetadata edm) {
this.odata = odata;
+ this.edm = edm;
}
@Override
@@ -105,7 +107,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
// Now the content is serialized using the serializer.
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
- InputStream serializedContent = serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ InputStream serializedContent = serializer.entityCollection(edm, edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, false, expand, select, null))
@@ -143,7 +145,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
- InputStream serializedContent = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream serializedContent = serializer.entity(edm, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, true, expand, select, null))
@@ -256,7 +258,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
final ContextURL contextURL = format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, true, null, null, edmProperty.getName());
InputStream serializerContent = complex ?
- serializer.complex((EdmComplexType) edmProperty.getType(), property,
+ serializer.complex(edm, (EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with().contextURL(contextURL).build()) :
serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
PrimitiveSerializerOptions.with()
@@ -273,7 +275,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
}
}
}
-
+
private Entity readEntityInternal(final UriInfoResource uriInfo, final EdmEntitySet entitySet)
throws DataProvider.DataProviderException {
// This method will extract the key values and pass them to the data provider
[05/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Edm cleanup:
Remove not necessary helper
Posted by ch...@apache.org.
[OLINGO-575] Edm cleanup: Remove not necessary helper
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/fcab8b06
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/fcab8b06
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/fcab8b06
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: fcab8b06728303a80abedb28919cb442e4269c19
Parents: 4d059b9
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Mar 26 07:33:23 2015 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Mar 26 07:33:23 2015 +0100
----------------------------------------------------------------------
.../core/edm/provider/EdmComplexTypeImpl.java | 28 +------
.../core/edm/provider/EdmEntityTypeImpl.java | 27 +------
.../provider/EdmStructuredTypeHelperImpl.java | 79 --------------------
.../edm/provider/EdmStructuredTypeImpl.java | 48 ++++++++++--
4 files changed, 43 insertions(+), 139 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fcab8b06/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
index 7fdc0b8..16ba237 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmComplexTypeImpl.java
@@ -19,14 +19,11 @@
package org.apache.olingo.commons.core.edm.provider;
import java.util.List;
-import java.util.Map;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmAnnotation;
import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -35,8 +32,6 @@ import org.apache.olingo.commons.api.edm.provider.ComplexType;
public class EdmComplexTypeImpl extends EdmStructuredTypeImpl implements EdmComplexType {
- private final EdmStructuredTypeHelperImpl helper;
-
private EdmAnnotationHelperImpl annotationHelper;
public static EdmComplexTypeImpl getInstance(
@@ -45,32 +40,11 @@ public class EdmComplexTypeImpl extends EdmStructuredTypeImpl implements EdmComp
}
private EdmComplexTypeImpl(final Edm edm, final FullQualifiedName name, final ComplexType complexType) {
- super(edm, name, EdmTypeKind.COMPLEX, complexType.getBaseTypeFQN());
- this.helper = new EdmStructuredTypeHelperImpl(edm, name, complexType);
+ super(edm, name, EdmTypeKind.COMPLEX, complexType);
this.annotationHelper = new EdmAnnotationHelperImpl(edm, complexType);
}
@Override
- protected Map<String, EdmProperty> getProperties() {
- return helper.getProperties();
- }
-
- @Override
- protected Map<String, EdmNavigationProperty> getNavigationProperties() {
- return helper.getNavigationProperties();
- }
-
- @Override
- public boolean isOpenType() {
- return helper.isOpenType();
- }
-
- @Override
- public boolean isAbstract() {
- return helper.isAbstract();
- }
-
- @Override
public EdmAnnotation getAnnotation(final EdmTerm term) {
return annotationHelper == null ? null : annotationHelper.getAnnotation(term);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fcab8b06/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
index b561151..84445aa 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmEntityTypeImpl.java
@@ -28,8 +28,6 @@ import org.apache.olingo.commons.api.edm.EdmAnnotation;
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;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -39,7 +37,6 @@ import org.apache.olingo.commons.api.edm.provider.PropertyRef;
public class EdmEntityTypeImpl extends EdmStructuredTypeImpl implements EdmEntityType {
- private final EdmStructuredTypeHelperImpl helper;
private EntityType entityType;
private boolean baseTypeChecked = false;
private EdmAnnotationHelperImpl annotationHelper;
@@ -56,20 +53,10 @@ public class EdmEntityTypeImpl extends EdmStructuredTypeImpl implements EdmEntit
}
private EdmEntityTypeImpl(final Edm edm, final FullQualifiedName name, final EntityType entityType) {
- super(edm, name, EdmTypeKind.ENTITY, entityType.getBaseTypeFQN());
+ super(edm, name, EdmTypeKind.ENTITY, entityType);
this.entityType = entityType;
- helper = new EdmStructuredTypeHelperImpl(edm, name, entityType);
hasStream = entityType.hasStream();
- }
-
- @Override
- protected Map<String, EdmProperty> getProperties() {
- return helper.getProperties();
- }
-
- @Override
- protected Map<String, EdmNavigationProperty> getNavigationProperties() {
- return helper.getNavigationProperties();
+ this.annotationHelper = new EdmAnnotationHelperImpl(edm, entityType);
}
@Override
@@ -166,16 +153,6 @@ public class EdmEntityTypeImpl extends EdmStructuredTypeImpl implements EdmEntit
}
@Override
- public boolean isOpenType() {
- return helper.isOpenType();
- }
-
- @Override
- public boolean isAbstract() {
- return helper.isAbstract();
- }
-
- @Override
public EdmAnnotation getAnnotation(final EdmTerm term) {
return annotationHelper.getAnnotation(term);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fcab8b06/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
deleted file mode 100644
index 9a78bcd..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeHelperImpl.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.provider;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.provider.NavigationProperty;
-import org.apache.olingo.commons.api.edm.provider.Property;
-import org.apache.olingo.commons.api.edm.provider.StructuralType;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public class EdmStructuredTypeHelperImpl {
-
- private final Edm edm;
- private final FullQualifiedName structuredTypeName;
- private final StructuralType structuredType;
- private Map<String, EdmProperty> properties;
- private Map<String, EdmNavigationProperty> navigationProperties;
-
- public EdmStructuredTypeHelperImpl(
- final Edm edm, final FullQualifiedName structuredTypeName, final StructuralType structuredType) {
- this.edm = edm;
- this.structuredTypeName = structuredTypeName;
- this.structuredType = structuredType;
- }
-
- public Map<String, EdmProperty> getProperties() {
- if (properties == null) {
- properties = new LinkedHashMap<String, EdmProperty>();
- if (structuredType.getProperties() != null) {
- for (Property property : structuredType.getProperties()) {
- properties.put(property.getName(), new EdmPropertyImpl(edm, structuredTypeName, property));
- }
- }
- }
- return properties;
- }
-
- public Map<String, EdmNavigationProperty> getNavigationProperties() {
- if (navigationProperties == null) {
- navigationProperties = new LinkedHashMap<String, EdmNavigationProperty>();
- if (structuredType.getNavigationProperties() != null) {
- for (NavigationProperty navigationProperty : structuredType.getNavigationProperties()) {
- navigationProperties.put(navigationProperty.getName(),
- new EdmNavigationPropertyImpl(edm, structuredTypeName, navigationProperty));
- }
- }
- }
- return navigationProperties;
- }
-
- public boolean isOpenType() {
- return structuredType.isOpenType();
- }
-
- public boolean isAbstract() {
- return structuredType.isAbstract();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fcab8b06/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
index 893f3dc..014184d 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmStructuredTypeImpl.java
@@ -27,37 +27,39 @@ import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.edm.provider.NavigationProperty;
+import org.apache.olingo.commons.api.edm.provider.Property;
+import org.apache.olingo.commons.api.edm.provider.StructuralType;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public abstract class EdmStructuredTypeImpl extends EdmTypeImpl implements EdmStructuredType {
protected EdmStructuredType baseType;
-
protected FullQualifiedName baseTypeName;
private List<String> propertyNames;
-
private List<String> navigationPropertyNames;
+ private Map<String, EdmProperty> properties;
+ private Map<String, EdmNavigationProperty> navigationProperties;
+ private final StructuralType structuredType;
public EdmStructuredTypeImpl(
final Edm edm,
final FullQualifiedName typeName,
final EdmTypeKind kind,
- final FullQualifiedName baseTypeName) {
+ final StructuralType structuredType) {
super(edm, typeName, kind);
- this.baseTypeName = baseTypeName;
+ this.baseTypeName = structuredType.getBaseTypeFQN();
+ this.structuredType = structuredType;
}
protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName);
- protected abstract Map<String, EdmProperty> getProperties();
-
- protected abstract Map<String, EdmNavigationProperty> getNavigationProperties();
-
protected abstract void checkBaseType();
@Override
@@ -149,4 +151,34 @@ public abstract class EdmStructuredTypeImpl extends EdmTypeImpl implements EdmSt
return getFullQualifiedName();
}
+ public Map<String, EdmProperty> getProperties() {
+ if (properties == null) {
+ properties = new LinkedHashMap<String, EdmProperty>();
+ for (Property property : structuredType.getProperties()) {
+ properties.put(property.getName(), new EdmPropertyImpl(edm, typeName, property));
+ }
+ }
+ return properties;
+ }
+
+ public Map<String, EdmNavigationProperty> getNavigationProperties() {
+ if (navigationProperties == null) {
+ navigationProperties = new LinkedHashMap<String, EdmNavigationProperty>();
+ if (structuredType.getNavigationProperties() != null) {
+ for (NavigationProperty navigationProperty : structuredType.getNavigationProperties()) {
+ navigationProperties.put(navigationProperty.getName(),
+ new EdmNavigationPropertyImpl(edm, typeName, navigationProperty));
+ }
+ }
+ }
+ return navigationProperties;
+ }
+
+ public boolean isOpenType() {
+ return structuredType.isOpenType();
+ }
+
+ public boolean isAbstract() {
+ return structuredType.isAbstract();
+ }
}
[07/50] [abbrv] olingo-odata4 git commit: [OLINGO-545] System query
options also applies to entity requests
Posted by ch...@apache.org.
[OLINGO-545] System query options also applies to entity requests
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/6421f548
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/6421f548
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/6421f548
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 6421f5480398cd53fcd6601c818b3f9e196fec5c
Parents: 0113414
Author: Christian Holzer <c....@sap.com>
Authored: Wed Mar 25 16:45:12 2015 +0100
Committer: Christian Holzer <c....@sap.com>
Committed: Thu Mar 26 15:13:50 2015 +0100
----------------------------------------------------------------------
.../ExpandWithSystemQueryOptionsITCase.java | 71 ++++++++++++++++++--
.../processor/TechnicalEntityProcessor.java | 9 ++-
.../ExpandSystemQueryOptionHandler.java | 36 +++++++---
3 files changed, 99 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6421f548/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
index a6b6eb9..2db9535 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
@@ -39,6 +39,7 @@ import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
+import org.junit.Ignore;
import org.junit.Test;
public class ExpandWithSystemQueryOptionsITCase extends AbstractBaseTestITCase {
@@ -216,20 +217,80 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractBaseTestITCase {
}
}
}
-
+
+ @Test
+ @Ignore("Server do not support navigation property count annotations")
+ public void testCount() {
+ final ODataClient client = getClient();
+ final Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
+ options.put(QueryOption.SELECT, "PropertyInt16");
+ options.put(QueryOption.COUNT, true);
+
+ final URI uri =
+ client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).expandWithOptions(
+ NAV_PROPERTY_ET_TWO_KEY_NAV_MANY, options).addQueryOption(QueryOption.SELECT,
+ "PropertyInt16,PropertyString").build();
+ final ODataRetrieveResponse<ODataEntitySet> response =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uri).execute();
+
+ final List<ODataEntity> entities = response.getBody().getEntities();
+ assertEquals(4, entities.size());
+
+ for (final ODataEntity entity : entities) {
+ final Object propInt16 = entity.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue();
+ final Object propString = entity.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue();
+ final ODataEntitySet entitySet =
+ entity.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
+
+ if (propInt16.equals(1) && propString.equals("1")) {
+ assertEquals(Integer.valueOf(2), entitySet.getCount());
+ } else if (propInt16.equals(1) && propString.equals("2")) {
+ assertEquals(Integer.valueOf(2), entitySet.getCount());
+ } else if (propInt16.equals(2) && propString.equals("1")) {
+ assertEquals(Integer.valueOf(2), entitySet.getCount());
+ } else if (propInt16.equals(3) && propString.equals("1")) {
+ assertEquals(Integer.valueOf(0), entitySet.getCount());
+ } else {
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void testSingleEntiyWithExpand() {
+ /* A single entity request will be dispatched to a different processor method than entity set request */
+ final ODataClient client = getClient();
+ final Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
+ options.put(QueryOption.FILTER, "PropertyInt16 lt 2");
+ final Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("PropertyInt16", 1);
+ keys.put("PropertyString", "1");
+
+ final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(keys)
+ .expandWithOptions(NAV_PROPERTY_ET_KEY_NAV_MANY, options).build();
+ final ODataRetrieveResponse<ODataEntity> response =
+ client.getRetrieveRequestFactory().getEntityRequest(uri).execute();
+ assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
+
+ final ODataEntitySet entitySet =
+ response.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_MANY).asInlineEntitySet().getEntitySet();
+ assertEquals(1, entitySet.getEntities().size());
+ assertEquals(1, entitySet.getEntities().get(0).getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
+ }
+
@Test
public void testURIEscaping() {
final Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
- options.put(QueryOption.FILTER, "PropertyInt16 eq 1"
- + " and PropertyComp/PropertyComp/PropertyDuration eq duration'PT1S' and length(PropertyString) gt 4");
+ options.put(QueryOption.FILTER, "PropertyInt16 eq 1"
+ + " and PropertyComp/PropertyComp/PropertyDuration eq duration'PT1S' and length(PropertyString) gt 4");
final ODataRetrieveResponse<ODataEntitySet> response =
buildRequest(ES_TWO_KEY_NAV, NAV_PROPERTY_ET_TWO_KEY_NAV_MANY, options);
final List<ODataEntity> entities = response.getBody().getEntities();
-
+
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
assertEquals(4, entities.size());
}
-
+
private ODataRetrieveResponse<ODataEntitySet> buildRequest(final String entitySet, final String navigationProperty,
final Map<QueryOption, Object> expandOptions) {
return buildRequest(entitySet, navigationProperty, expandOptions, null);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6421f548/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index ff7bd5f..109a192 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -168,12 +168,17 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
edmEntitySet.getEntityType();
final Entity entity = readEntity(uriInfo);
-
+
final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
- response.setContent(serializer.entity(edmEntitySet.getEntityType(), entity,
+
+ final ExpandSystemQueryOptionHandler expandHandler = new ExpandSystemQueryOptionHandler();
+ final Entity entitySerialization = expandHandler.copyEntityShallowRekursive(entity);
+ expandHandler.applyExpandQueryOptions(entitySerialization, edmEntitySet, expand);
+
+ response.setContent(serializer.entity(edmEntitySet.getEntityType(), entitySerialization,
EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, edmEntityType, true, expand, select))
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6421f548/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java
index 51fe49b..3ae3b3a 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/ExpandSystemQueryOptionHandler.java
@@ -52,23 +52,38 @@ public class ExpandSystemQueryOptionHandler {
public void applyExpandQueryOptions(final EntitySet entitySet, final EdmEntitySet edmEntitySet,
final ExpandOption expandOption) throws ODataApplicationException {
- final EdmEntityType entityType = edmEntitySet.getEntityType();
if (expandOption == null) {
return;
}
+ for (final Entity entity : entitySet.getEntities()) {
+ applyExpandOptionToEntity(entity, edmEntitySet, expandOption);
+ }
+ }
+
+ public void applyExpandQueryOptions(Entity entity, EdmEntitySet edmEntitySet, ExpandOption expandOption)
+ throws ODataApplicationException {
+ if (expandOption == null) {
+ return;
+ }
+
+ applyExpandOptionToEntity(entity, edmEntitySet, expandOption);
+ }
+
+ private void applyExpandOptionToEntity(final Entity entity, final EdmEntitySet edmEntitySet,
+ final ExpandOption expandOption) throws ODataApplicationException {
+ final EdmEntityType entityType = edmEntitySet.getEntityType();
+
for (ExpandItem item : expandOption.getExpandItems()) {
final List<UriResource> uriResourceParts = item.getResourcePath().getUriResourceParts();
if (uriResourceParts.size() == 1 && uriResourceParts.get(0) instanceof UriResourceNavigation) {
final String navPropertyName = ((UriResourceNavigation) uriResourceParts.get(0)).getProperty().getName();
final EdmEntitySet targetEdmEntitySet = (EdmEntitySet) edmEntitySet.getRelatedBindingTarget(navPropertyName);
- for (final Entity entity : entitySet.getEntities()) {
- final Link link = entity.getNavigationLink(navPropertyName);
- if (link != null && entityType.getNavigationProperty(navPropertyName).isCollection()) {
- applyOptionsToEntityCollection(link.getInlineEntitySet(), targetEdmEntitySet, item.getFilterOption(),
- item.getOrderByOption(), item.getCountOption(), item.getSkipOption(), item.getTopOption());
- }
+ final Link link = entity.getNavigationLink(navPropertyName);
+ if (link != null && entityType.getNavigationProperty(navPropertyName).isCollection()) {
+ applyOptionsToEntityCollection(link.getInlineEntitySet(), targetEdmEntitySet, item.getFilterOption(),
+ item.getOrderByOption(), item.getCountOption(), item.getSkipOption(), item.getTopOption());
}
} else {
throw new ODataApplicationException("Not supported resource part in expand system query option",
@@ -83,6 +98,7 @@ public class ExpandSystemQueryOptionHandler {
FilterHandler.applyFilterSystemQuery(filterOption, entitySet, edmEntitySet);
OrderByHandler.applyOrderByOption(orderByOption, entitySet, edmEntitySet);
+ // TODO Add CountHandler
SkipHandler.applySkipSystemQueryHandler(skipOption, entitySet);
TopHandler.applyTopSystemQueryOption(topOption, entitySet);
}
@@ -96,7 +112,7 @@ public class ExpandSystemQueryOptionHandler {
copiedEntitySets.put(entitySet, copiedEntitySet);
copiedEntitySets.put(copiedEntitySet, copiedEntitySet);
-
+
for (Entity entity : entitySet.getEntities()) {
copiedEntitySet.getEntities().add(copyEntityShallowRekursive(entity));
}
@@ -105,7 +121,7 @@ public class ExpandSystemQueryOptionHandler {
return copiedEntitySets.get(entitySet);
}
- private Entity copyEntityShallowRekursive(final Entity entity) {
+ public Entity copyEntityShallowRekursive(final Entity entity) {
if (!copiedEntities.containsKey(entity)) {
final Entity copiedEntity = new EntityImpl();
copiedEntity.getProperties().addAll(entity.getProperties());
@@ -120,7 +136,7 @@ public class ExpandSystemQueryOptionHandler {
copiedEntity.setSelfLink(entity.getSelfLink());
copiedEntity.setType(entity.getType());
copiedEntity.getNavigationBindings().addAll(entity.getNavigationBindings());
-
+
copiedEntities.put(entity, copiedEntity);
copiedEntities.put(copiedEntity, copiedEntity);
[20/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java
new file mode 100644
index 0000000..a306551
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponse.java
@@ -0,0 +1,119 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+
+public abstract class ServiceResponse {
+ protected ServiceMetadata metadata;
+ protected ODataResponse response;
+ protected Map<String, String> preferences;
+ private boolean closed;
+ private boolean strictApplyPreferences = true;
+
+ public ServiceResponse(ServiceMetadata metadata, ODataResponse response,
+ Map<String, String> preferences) {
+ this.metadata = metadata;
+ this.response = response;
+ this.preferences = preferences;
+ }
+
+ public ODataResponse getODataResponse() {
+ return this.response;
+ }
+
+ protected boolean isClosed() {
+ return this.closed;
+ }
+
+ protected void close() {
+ if (!this.closed) {
+ if (this.strictApplyPreferences) {
+ if (!preferences.isEmpty()) {
+ assert(this.response.getHeaders().get("Preference-Applied") != null);
+ }
+ }
+ this.closed = true;
+ }
+ }
+
+ public void writeNoContent(boolean closeResponse) {
+ this.response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+
+ public void writeNotFound(boolean closeResponse) {
+ response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+
+ public void writeServerError(boolean closeResponse) {
+ response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+
+ public void writeBadRequest(boolean closeResponse) {
+ response.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+
+ public void writeOK(String contentType) {
+ this.response.setStatusCode(HttpStatusCode.OK.getStatusCode());
+ this.response.setHeader(HttpHeader.CONTENT_TYPE, contentType);
+ }
+
+ public void writeHeader(String key, String value) {
+ if ("Preference-Applied".equals(key)) {
+ String previous = this.response.getHeaders().get(key);
+ if (previous != null) {
+ value = previous+";"+value;
+ }
+ this.response.setHeader(key, value);
+ } else {
+ this.response.setHeader(key, value);
+ }
+ }
+
+ /**
+ * When true; the "Preference-Applied" header is strictly checked.
+ * @param flag
+ */
+ public void setStrictlyApplyPreferences(boolean flag) {
+ this.strictApplyPreferences = flag;
+ }
+
+ public abstract void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException;
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponseVisior.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponseVisior.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponseVisior.java
new file mode 100644
index 0000000..4f11cb8
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceResponseVisior.java
@@ -0,0 +1,71 @@
+/*
+ * 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.responses;
+
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataTranslatedException;
+
+@SuppressWarnings("unused")
+public class ServiceResponseVisior {
+
+ public void visit(CountResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(EntityResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(MetadataResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(NoContentResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(PrimitiveValueResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(PropertyResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(ServiceDocumentResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(StreamResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+
+ public void visit(EntitySetResponse response) throws ODataTranslatedException,
+ ODataApplicationException {
+ response.writeServerError(true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/StreamResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/StreamResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/StreamResponse.java
new file mode 100644
index 0000000..ec7db03
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/StreamResponse.java
@@ -0,0 +1,54 @@
+/*
+ * 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.responses;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Collections;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+
+public class StreamResponse extends ServiceResponse {
+
+ public StreamResponse(ServiceMetadata metadata, ODataResponse response) {
+ super(metadata, response, Collections.EMPTY_MAP);
+ }
+
+ public void writeStreamResponse(InputStream streamContent, ContentType contentType) {
+ this.response.setContent(streamContent);
+ writeOK(contentType.toContentTypeString());
+ close();
+ }
+
+ public void writeBinaryResponse(byte[] streamContent, ContentType contentType) {
+ this.response.setContent(new ByteArrayInputStream(streamContent));
+ writeOK(contentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/MetadataParserTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/MetadataParserTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/MetadataParserTest.java
new file mode 100644
index 0000000..9749a6c
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/MetadataParserTest.java
@@ -0,0 +1,185 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileReader;
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.Action;
+import org.apache.olingo.commons.api.edm.provider.ActionImport;
+import org.apache.olingo.commons.api.edm.provider.ComplexType;
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.commons.api.edm.provider.EntitySet;
+import org.apache.olingo.commons.api.edm.provider.EntityType;
+import org.apache.olingo.commons.api.edm.provider.EnumType;
+import org.apache.olingo.commons.api.edm.provider.Function;
+import org.apache.olingo.commons.api.edm.provider.FunctionImport;
+import org.apache.olingo.commons.api.edm.provider.NavigationPropertyBinding;
+import org.apache.olingo.commons.api.edm.provider.Parameter;
+import org.apache.olingo.commons.api.edm.provider.Property;
+import org.apache.olingo.commons.api.edm.provider.Singleton;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MetadataParserTest {
+ final String NS = "Microsoft.OData.SampleService.Models.TripPin";
+ final FullQualifiedName NSF = new FullQualifiedName(NS);
+
+ EdmProvider provider = null;
+
+ @Before
+ public void setUp() throws Exception {
+ MetadataParser parser = new MetadataParser();
+ provider = parser.buildEdmProvider(new FileReader("src/test/resources/trippin.xml"));
+ }
+
+ @Test
+ public void testAction() throws ODataException {
+ // test action
+ List<Action> actions = provider.getActions(new FullQualifiedName(NS, "ResetDataSource"));
+ assertNotNull(actions);
+ assertEquals(1, actions.size());
+ }
+
+ @Test
+ public void testFunction() throws ODataException {
+ // test function
+ List<Function> functions = provider
+ .getFunctions(new FullQualifiedName(NS, "GetFavoriteAirline"));
+ assertNotNull(functions);
+ assertEquals(1, functions.size());
+ assertEquals("GetFavoriteAirline", functions.get(0).getName());
+ assertTrue(functions.get(0).isBound());
+ assertTrue(functions.get(0).isComposable());
+ assertEquals(
+ "person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline",
+ functions.get(0).getEntitySetPath());
+
+ List<Parameter> parameters = functions.get(0).getParameters();
+ assertNotNull(parameters);
+ assertEquals(1, parameters.size());
+ assertEquals("person", parameters.get(0).getName());
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Person",parameters.get(0).getType());
+ assertFalse(parameters.get(0).isNullable());
+
+ assertNotNull(functions.get(0).getReturnType());
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Airline",
+ functions.get(0).getReturnType().getType());
+ assertFalse(functions.get(0).getReturnType().isNullable());
+ }
+
+ @Test
+ public void testEnumType() throws ODataException {
+ // test enum type
+ EnumType enumType = provider.getEnumType(new FullQualifiedName(NS, "PersonGender"));
+ assertNotNull(enumType);
+ assertEquals("Male", enumType.getMembers().get(0).getName());
+ assertEquals("Female", enumType.getMembers().get(1).getName());
+ assertEquals("Unknown", enumType.getMembers().get(2).getName());
+ assertEquals("0", enumType.getMembers().get(0).getValue());
+ assertEquals("1", enumType.getMembers().get(1).getValue());
+ assertEquals("2", enumType.getMembers().get(2).getValue());
+ }
+
+ @Test
+ public void testEntityType() throws ODataException {
+ // test Entity Type
+ EntityType et = provider.getEntityType(new FullQualifiedName(NS, "Photo"));
+ assertNotNull(et);
+ assertNotNull(et.getKey());
+ assertEquals("Id", et.getKey().get(0).getName());
+ assertTrue(et.hasStream());
+ assertEquals("Id", et.getProperties().get(0).getName());
+ assertEquals("Edm.Int64", et.getProperties().get(0).getType());
+ assertEquals("Name", et.getProperties().get(1).getName());
+ assertEquals("Edm.String", et.getProperties().get(1).getType());
+ }
+
+ @Test
+ public void testComplexType() throws ODataException {
+ // Test Complex Type
+ ComplexType ct = provider.getComplexType(new FullQualifiedName(NS, "City"));
+ assertNotNull(ct);
+ assertEquals(3, ct.getProperties().size());
+ Property p = ct.getProperties().get(0);
+ assertEquals("CountryRegion", p.getName());
+ assertEquals("Edm.String", p.getType());
+ assertEquals(false, p.isNullable());
+
+ ct = provider.getComplexType(new FullQualifiedName(NS, "Location"));
+ assertNotNull(ct);
+
+ ct = provider.getComplexType(new FullQualifiedName(NS, "EventLocation"));
+ assertNotNull(ct);
+ }
+
+ @Test
+ public void testEntitySet() throws Exception {
+ EntitySet es = provider.getEntitySet(NSF, "People");
+ assertNotNull(es);
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Person",es.getType());
+
+ List<NavigationPropertyBinding> bindings = es.getNavigationPropertyBindings();
+ assertNotNull(bindings);
+ assertEquals(6, bindings.size());
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Flight/From", bindings.get(2)
+ .getPath());
+ assertEquals("Airports", bindings.get(2).getTarget());
+ }
+
+ @Test
+ public void testFunctionImport() throws Exception {
+ FunctionImport fi = provider.getFunctionImport(NSF, "GetNearestAirport");
+ assertNotNull(fi);
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport", fi.getFunction());
+ assertEquals("Airports", fi.getEntitySet());
+ assertTrue(fi.isIncludeInServiceDocument());
+ }
+
+ @Test
+ public void testActionImport() throws Exception {
+ ActionImport ai = provider.getActionImport(NSF, "ResetDataSource");
+ assertNotNull(ai);
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.ResetDataSource", ai.getAction());
+ assertNull(ai.getEntitySet());
+ }
+
+ @Test
+ public void testSingleton() throws Exception {
+ Singleton single = this.provider.getSingleton(NSF, "Me");
+ assertNotNull(single);
+
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Person",single.getType());
+
+ List<NavigationPropertyBinding> bindings = single.getNavigationPropertyBindings();
+ assertNotNull(bindings);
+ assertEquals(6, bindings.size());
+ assertEquals("Microsoft.OData.SampleService.Models.TripPin.Flight/From", bindings.get(2).getPath());
+ assertEquals("Airports", bindings.get(2).getTarget());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
new file mode 100644
index 0000000..16caa1a
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
@@ -0,0 +1,417 @@
+/*
+ * 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.assertEquals;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataHttpHandler;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.core.requests.ActionRequest;
+import org.apache.olingo.server.core.requests.DataRequest;
+import org.apache.olingo.server.core.requests.FunctionRequest;
+import org.apache.olingo.server.core.requests.MediaRequest;
+import org.apache.olingo.server.core.requests.MetadataRequest;
+import org.apache.olingo.server.core.responses.CountResponse;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.StreamResponse;
+import org.apache.olingo.server.example.TripPinServiceTest;
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+public class ServiceDispatcherTest {
+ private Server server;
+
+ public class SampleODataServlet extends HttpServlet {
+ private final ServiceHandler handler; // must be stateless
+ private final EdmProvider provider; // must be stateless
+
+ public SampleODataServlet(ServiceHandler handler, EdmProvider provider) {
+ this.handler = handler;
+ this.provider = provider;
+ }
+
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+ OData odata = OData4Impl.newInstance();
+ ServiceMetadata metadata = odata.createServiceMetadata(this.provider, Collections.EMPTY_LIST);
+
+ ODataHttpHandler handler = odata.createHandler(metadata);
+
+ handler.register(this.handler);
+ handler.process(request, response);
+ }
+ }
+
+ public int beforeTest(ServiceHandler serviceHandler) throws Exception {
+ MetadataParser parser = new MetadataParser();
+ EdmProvider edmProvider = parser.buildEdmProvider(new FileReader(
+ "src/test/resources/trippin.xml"));
+
+ this.server = new Server();
+
+ ServerConnector connector = new ServerConnector(this.server);
+ this.server.setConnectors(new Connector[] { connector });
+
+ ServletContextHandler context = new ServletContextHandler();
+ context.setContextPath("/trippin");
+ context
+ .addServlet(new ServletHolder(new SampleODataServlet(serviceHandler, edmProvider)), "/*");
+ this.server.setHandler(context);
+ this.server.start();
+
+ return connector.getLocalPort();
+ }
+
+ public void afterTest() throws Exception {
+ this.server.stop();
+ }
+
+ interface TestResult {
+ void validate() throws Exception;
+ }
+
+ private void helpGETTest(ServiceHandler handler, String path, TestResult validator)
+ throws Exception {
+ int port = beforeTest(handler);
+ HttpClient http = new HttpClient();
+ http.start();
+ http.GET("http://localhost:" + port + "/" + path);
+ validator.validate();
+ afterTest();
+ }
+
+ private void helpTest(ServiceHandler handler, String path, String method, String payload,
+ TestResult validator) throws Exception {
+ int port = beforeTest(handler);
+ HttpClient http = new HttpClient();
+ http.start();
+ String editUrl = "http://localhost:" + port + "/" + path;
+ http.newRequest(editUrl).method(method)
+ .header("Content-Type", "application/json;odata.metadata=minimal")
+ .content(TripPinServiceTest.content(payload)).send();
+ validator.validate();
+ afterTest();
+ }
+
+ @Test
+ public void testMetadata() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/$metadata", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<MetadataRequest> arg1 = ArgumentCaptor.forClass(MetadataRequest.class);
+ ArgumentCaptor<MetadataResponse> arg2 = ArgumentCaptor.forClass(MetadataResponse.class);
+ Mockito.verify(handler).readMetadata(arg1.capture(), arg2.capture());
+ }
+ });
+ }
+
+ @Test
+ public void testEntitySet() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<EntityResponse> arg2 = ArgumentCaptor.forClass(EntityResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ // Need toString on ContextURL class
+ // assertEquals("",
+ // request.getContextURL(request.getOdata()).toString());
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testEntitySetCount() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports/$count", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<CountResponse> arg2 = ArgumentCaptor.forClass(CountResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ // Need toString on ContextURL class
+ // assertEquals("",
+ // request.getContextURL(request.getOdata()).toString());
+ assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testEntity() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<EntityResponse> arg2 = ArgumentCaptor.forClass(EntityResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadProperty() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')/IataCode", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<PropertyResponse> arg2 = ArgumentCaptor.forClass(PropertyResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(true, request.isPropertyRequest());
+ assertEquals(false, request.isPropertyComplex());
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadComplexProperty() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')/Location", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<PropertyResponse> arg2 = ArgumentCaptor.forClass(PropertyResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(true, request.isPropertyRequest());
+ assertEquals(true, request.isPropertyComplex());
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadProperty$Value() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')/IataCode/$value", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<PrimitiveValueResponse> arg2 = ArgumentCaptor
+ .forClass(PrimitiveValueResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(true, request.isPropertyRequest());
+ assertEquals(false, request.isPropertyComplex());
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadPropertyRef() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Airports('0')/IataCode/$value", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<PrimitiveValueResponse> arg2 = ArgumentCaptor
+ .forClass(PrimitiveValueResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals(true, request.isPropertyRequest());
+ assertEquals(false, request.isPropertyComplex());
+ assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+ assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testFunctionImport() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/GetNearestAirport(lat=12.11,lon=34.23)", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<FunctionRequest> arg1 = ArgumentCaptor.forClass(FunctionRequest.class);
+ ArgumentCaptor<PropertyResponse> arg3 = ArgumentCaptor.forClass(PropertyResponse.class);
+ ArgumentCaptor<HttpMethod> arg2 = ArgumentCaptor.forClass(HttpMethod.class);
+ Mockito.verify(handler).invoke(arg1.capture(), arg2.capture(), arg3.capture());
+
+ FunctionRequest request = arg1.getValue();
+ }
+ });
+ }
+
+ @Test
+ public void testActionImport() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpTest(handler, "trippin/ResetDataSource", "POST", "", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<ActionRequest> arg1 = ArgumentCaptor.forClass(ActionRequest.class);
+ ArgumentCaptor<NoContentResponse> arg2 = ArgumentCaptor.forClass(NoContentResponse.class);
+ Mockito.verify(handler).invoke(arg1.capture(), Mockito.anyString(), arg2.capture());
+
+ ActionRequest request = arg1.getValue();
+ }
+ });
+ }
+
+ @Test
+ public void testReadMedia() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/Photos(1)/$value", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<MediaRequest> arg1 = ArgumentCaptor.forClass(MediaRequest.class);
+ ArgumentCaptor<StreamResponse> arg2 = ArgumentCaptor.forClass(StreamResponse.class);
+ Mockito.verify(handler).readMediaStream(arg1.capture(), arg2.capture());
+
+ MediaRequest request = arg1.getValue();
+ assertEquals("application/octet-stream", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadNavigation() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/People('russelwhyte')/Friends", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<EntitySetResponse> arg2 = ArgumentCaptor.forClass(EntitySetResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testReadReference() throws Exception {
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpGETTest(handler, "trippin/People('russelwhyte')/Friends/$ref", new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<EntitySetResponse> arg2 = ArgumentCaptor.forClass(EntitySetResponse.class);
+ Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+ .toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testWriteReferenceCollection() throws Exception {
+ String payload = "{\n" + "\"@odata.id\": \"/Photos(11)\"\n" + "}";
+
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpTest(handler, "trippin/People('russelwhyte')/Friends/$ref", "POST", payload,
+ new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<List> arg3 = ArgumentCaptor.forClass(List.class);
+ ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
+ .forClass(NoContentResponse.class);
+ Mockito.verify(handler).addReference(arg1.capture(), arg2.capture(), arg3.capture(),
+ arg4.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals("application/json;odata.metadata=minimal", request
+ .getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+
+ @Test
+ public void testWriteReference() throws Exception {
+ String payload = "{\n" + "\"@odata.id\": \"/Photos(11)\"\n" + "}";
+
+ final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+ helpTest(handler, "trippin/People('russelwhyte')/Friends('someone')/Photo/$ref", "PUT", payload,
+ new TestResult() {
+ @Override
+ public void validate() throws Exception {
+ ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+ ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<URI> arg3 = ArgumentCaptor.forClass(URI.class);
+ ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
+ .forClass(NoContentResponse.class);
+ Mockito.verify(handler).updateReference(arg1.capture(), arg2.capture(), arg3.capture(),
+ arg4.capture());
+
+ DataRequest request = arg1.getValue();
+ assertEquals("application/json;odata.metadata=minimal", request
+ .getResponseContentType().toContentTypeString());
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8668b097/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
new file mode 100644
index 0000000..904f4d8
--- /dev/null
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinDataModel.java
@@ -0,0 +1,843 @@
+/*
+ * 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.example;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Property;
+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.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.core.data.EntityImpl;
+import org.apache.olingo.commons.core.data.EntitySetImpl;
+import org.apache.olingo.commons.core.data.LinkImpl;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.core.deserializer.json.ODataJsonDeserializer;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class TripPinDataModel {
+ private final ServiceMetadata metadata;
+ private HashMap<String, EntitySet> entitySetMap;
+ private Map<Integer, Map> tripLinks;
+ private Map<String, Map> peopleLinks;
+ private Map<Integer, Map> flightLinks;
+
+ public TripPinDataModel(ServiceMetadata metadata) throws Exception {
+ this.metadata = metadata;
+ loadData();
+ }
+
+ public void loadData() throws Exception {
+ this.entitySetMap = new HashMap<String, EntitySet>();
+ this.tripLinks = new HashMap<Integer, Map>();
+ this.peopleLinks = new HashMap<String, Map>();
+ this.flightLinks = new HashMap<Integer, Map>();
+
+ EdmEntityContainer ec = metadata.getEdm().getEntityContainer(null);
+ for (EdmEntitySet edmEntitySet : ec.getEntitySets()) {
+ String entitySetName = edmEntitySet.getName();
+ EntitySet set = loadEnities(entitySetName, edmEntitySet.getEntityType());
+ if (set != null) {
+ this.entitySetMap.put(entitySetName, set);
+ }
+ }
+
+ EdmEntityType type = metadata.getEdm().getEntityType(
+ new FullQualifiedName("Microsoft.OData.SampleService.Models.TripPin", "Trip"));
+ this.entitySetMap.put("Trip", loadEnities("Trip", type));
+
+ type = metadata.getEdm().getEntityType(
+ new FullQualifiedName("Microsoft.OData.SampleService.Models.TripPin", "Flight"));
+ this.entitySetMap.put("Flight", loadEnities("Flight", type));
+
+ type = metadata.getEdm().getEntityType(
+ new FullQualifiedName("Microsoft.OData.SampleService.Models.TripPin", "Event"));
+ this.entitySetMap.put("Event", loadEnities("Event", type));
+
+ ObjectMapper mapper = new ObjectMapper();
+ Map tripLinks = mapper.readValue(new FileInputStream(new File(
+ "src/test/resources/trip-links.json")), Map.class);
+ for (Object link : (ArrayList) tripLinks.get("value")) {
+ Map map = (Map) link;
+ this.tripLinks.put((Integer) map.get("TripId"), map);
+ }
+
+ Map peopleLinks = mapper.readValue(new FileInputStream(new File(
+ "src/test/resources/people-links.json")), Map.class);
+ for (Object link : (ArrayList) peopleLinks.get("value")) {
+ Map map = (Map) link;
+ this.peopleLinks.put((String) map.get("UserName"), map);
+ }
+
+ Map flightLinks = mapper.readValue(new FileInputStream(new File(
+ "src/test/resources/flight-links.json")), Map.class);
+ for (Object link : (ArrayList) flightLinks.get("value")) {
+ Map map = (Map) link;
+ this.flightLinks.put((Integer) map.get("PlanItemId"), map);
+ }
+ }
+
+ private EntitySet loadEnities(String entitySetName, EdmEntityType type) {
+ try {
+ ODataJsonDeserializer deserializer = new ODataJsonDeserializer();
+
+ EntitySet set = deserializer.entityCollection(new FileInputStream(new File(
+ "src/test/resources/" + entitySetName.toLowerCase() + ".json")), type);
+ // TODO: the count needs to be part of deserializer
+ set.setCount(set.getEntities().size());
+ for (Entity entity : set.getEntities()) {
+ ((EntityImpl) entity).setETag(UUID.randomUUID().toString());
+ ((EntityImpl) entity).setId(new URI(TripPinHandler.buildLocation(entity, entitySetName,
+ type)));
+ ((EntityImpl) entity).setType(type.getFullQualifiedName().getFullQualifiedNameAsString());
+ }
+ return set;
+ } catch (FileNotFoundException e) {
+ // keep going
+ e.printStackTrace();
+ } catch (DeserializerException e) {
+ // keep going
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ // keep going
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public EntitySet getEntitySet(String name) {
+ return getEntitySet(name, -1, -1);
+ }
+
+ public EntitySet getEntitySet(String name, int skip, int pageSize) {
+ EntitySet set = this.entitySetMap.get(name);
+ if (set == null) {
+ return null;
+ }
+
+ EntitySetImpl modifiedES = new EntitySetImpl();
+ int i = 0;
+ for (Entity e : set.getEntities()) {
+ if (skip >= 0 && i >= skip && modifiedES.getEntities().size() < pageSize) {
+ modifiedES.getEntities().add(e);
+ }
+ i++;
+ }
+ modifiedES.setCount(i);
+ set.setCount(i);
+
+ if (skip == -1 && pageSize == -1) {
+ return set;
+ }
+ return modifiedES;
+ }
+
+ private List<Entity> getMatch(UriParameter param, List<Entity> es)
+ throws ODataApplicationException {
+ ArrayList<Entity> list = new ArrayList<Entity>();
+ for (Entity entity : es) {
+
+ EdmEntityType entityType = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(entity.getType()));
+
+ EdmProperty property = (EdmProperty) entityType.getProperty(param.getName());
+ EdmType type = property.getType();
+ if (type.getKind() == EdmTypeKind.PRIMITIVE) {
+ Object match = readPrimitiveValue(property, param.getText());
+ Property entityValue = entity.getProperty(param.getName());
+ if (match.equals(entityValue.asPrimitive())) {
+ list.add(entity);
+ }
+ } else {
+ throw new RuntimeException("Can not compare complex objects");
+ }
+ }
+ return list;
+ }
+
+ static Object readPrimitiveValue(EdmProperty edmProperty, String value)
+ throws ODataApplicationException {
+ if (value == null) {
+ return null;
+ }
+ try {
+ if (value.startsWith("'") && value.endsWith("'")) {
+ value = value.substring(1,value.length()-1);
+ }
+ EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmProperty.getType();
+ Class<?> javaClass = getJavaClassForPrimitiveType(edmProperty, edmPrimitiveType);
+ return edmPrimitiveType.valueOfString(value, edmProperty.isNullable(),
+ edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(),
+ edmProperty.isUnicode(), javaClass);
+ } catch (EdmPrimitiveTypeException e) {
+ throw new ODataApplicationException("Invalid value: " + value + " for property: "
+ + edmProperty.getName(), 500, Locale.getDefault());
+ }
+ }
+
+ static Class<?> getJavaClassForPrimitiveType(EdmProperty edmProperty, EdmPrimitiveType edmPrimitiveType) {
+ Class<?> javaClass = null;
+ if (edmProperty.getMapping() != null && edmProperty.getMapping().getMappedJavaClass() != null) {
+ javaClass = edmProperty.getMapping().getMappedJavaClass();
+ } else {
+ javaClass = edmPrimitiveType.getDefaultType();
+ }
+
+ edmPrimitiveType.getDefaultType();
+ return javaClass;
+ }
+
+ public Entity getEntity(String name, List<UriParameter> keys) throws ODataApplicationException {
+ EntitySet es = getEntitySet(name);
+ return getEntity(es, keys);
+ }
+
+ public Entity getEntity(EntitySet es, List<UriParameter> keys) throws ODataApplicationException {
+ List<Entity> search = es.getEntities();
+ for (UriParameter param : keys) {
+ search = getMatch(param, search);
+ }
+ if (search.isEmpty()) {
+ return null;
+ }
+ return search.get(0);
+ }
+
+ private EntitySet getFriends(String userName) {
+ Map<String, Object> map = this.peopleLinks.get(userName);
+ if (map == null) {
+ return null;
+ }
+ ArrayList<String> friends = (ArrayList<String>) map.get("Friends");
+ EntitySet set = getEntitySet("People");
+
+ EntitySetImpl result = new EntitySetImpl();
+ int i = 0;
+ if (friends != null) {
+ for (String friend : friends) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("UserName").getValue().equals(friend)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private EntitySet getTrips(String userName) {
+ Map<String, Object> map = this.peopleLinks.get(userName);
+ if (map == null) {
+ return null;
+ }
+
+ ArrayList<Integer> trips = (ArrayList<Integer>) map.get("Trips");
+ EntitySet set = getEntitySet("Trip");
+
+ EntitySetImpl result = new EntitySetImpl();
+ int i = 0;
+ if (trips != null) {
+ for (int trip : trips) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("TripId").getValue().equals(trip)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private Entity getPhoto(String userName) {
+ Map<String, Object> map = this.peopleLinks.get(userName);
+ if (map == null) {
+ return null;
+ }
+
+ Integer photoID = (Integer) map.get("Photo");
+ EntitySet set = getEntitySet("Photos");
+ if (photoID != null) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("Id").getValue().equals(photoID.longValue())) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ private EntitySet getPlanItems(int tripId, EntitySetImpl result) {
+ getFlights(tripId, result);
+ getEvents(tripId, result);
+ return result;
+ }
+
+ private EntitySet getEvents(int tripId, EntitySetImpl result) {
+ Map<Integer, Object> map = this.tripLinks.get(tripId);
+ if (map == null) {
+ return null;
+ }
+
+ ArrayList<Integer> events = (ArrayList<Integer>) map.get("Events");
+ EntitySet set = getEntitySet("Event");
+ int i = result.getEntities().size();
+ if (events != null) {
+ for (int event : events) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("PlanItemId").getValue().equals(event)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private EntitySet getFlights(int tripId, EntitySetImpl result) {
+ Map<Integer, Object> map = this.tripLinks.get(tripId);
+ if (map == null) {
+ return null;
+ }
+
+ ArrayList<Integer> flights = (ArrayList<Integer>) map.get("Flights");
+ EntitySet set = getEntitySet("Flight");
+ int i = result.getEntities().size();
+ if (flights != null) {
+ for (int flight : flights) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("PlanItemId").getValue().equals(flight)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private EntitySet getTripPhotos(int tripId) {
+ Map<Integer, Object> map = this.tripLinks.get(tripId);
+ if (map == null) {
+ return null;
+ }
+
+ ArrayList<Integer> photos = (ArrayList<Integer>) map.get("Photos");
+
+ EntitySet set = getEntitySet("Photos");
+ EntitySetImpl result = new EntitySetImpl();
+ int i = 0;
+ if (photos != null) {
+ for (int photo : photos) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("Id").getValue().equals(photo)) {
+ result.getEntities().add(e);
+ i++;
+ break;
+ }
+ }
+ }
+ }
+ result.setCount(i);
+ return result;
+ }
+
+ private Entity getFlightFrom(int flighID) {
+ Map<String, Object> map = this.flightLinks.get(flighID);
+ if (map == null) {
+ return null;
+ }
+
+ String from = (String) map.get("From");
+ EntitySet set = getEntitySet("Airports");
+
+ if (from != null) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("IataCode").getValue().equals(from)) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ private Entity getFlightTo(int flighID) {
+ Map<String, Object> map = this.flightLinks.get(flighID);
+ if (map == null) {
+ return null;
+ }
+
+ String to = (String) map.get("To");
+ EntitySet set = getEntitySet("Airports");
+
+ if (to != null) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("IataCode").getValue().equals(to)) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ private Entity getFlightAirline(int flighID) {
+ Map<String, Object> map = this.flightLinks.get(flighID);
+ if (map == null) {
+ return null;
+ }
+
+ String airline = (String) map.get("Airline");
+ EntitySet set = getEntitySet("Airlines");
+
+ if (airline != null) {
+ for (Entity e : set.getEntities()) {
+ if (e.getProperty("AirlineCode").getValue().equals(airline)) {
+ return e;
+ }
+ }
+ }
+ return null;
+ }
+
+ public void addNavigationLink(String navigation, Entity parentEntity, Entity childEntity) {
+
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+ String key = type.getKeyPredicateNames().get(0);
+ if (type.getName().equals("Person") && navigation.equals("Friends")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.peopleLinks.put((String) parentEntity.getProperty(key).getValue(), map);
+ }
+
+ ArrayList<String> friends = (ArrayList<String>) map.get("Friends");
+ if (friends == null) {
+ friends = new ArrayList<String>();
+ map.put("Friends", friends);
+ }
+ friends.add((String) childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Person") && navigation.equals("Trips")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.peopleLinks.put((String) parentEntity.getProperty(key).getValue(), map);
+ }
+
+ ArrayList<Integer> trips = (ArrayList<Integer>) map.get("Trips");
+ if (trips == null) {
+ trips = new ArrayList<Integer>();
+ map.put("Trips", trips);
+ }
+ trips.add((Integer) childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Person") && navigation.equals("Photo")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.peopleLinks.put((String) parentEntity.getProperty(key).getValue(), map);
+ }
+ map.put("Photo", childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Trip") && navigation.equals("PlanItems")) {
+ Map map = this.tripLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.tripLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ if (childEntity.getType().equals("Flight")) {
+ ArrayList<Integer> flights = (ArrayList<Integer>) map.get("Flights");
+ if (flights == null) {
+ flights = new ArrayList<Integer>();
+ map.put("Flights", flights);
+ }
+ flights.add((Integer) childEntity.getProperty(key).getValue());
+ } else {
+ ArrayList<Integer> events = (ArrayList<Integer>) map.get("Events");
+ if (events == null) {
+ events = new ArrayList<Integer>();
+ map.put("Events", events);
+ }
+ events.add((Integer) childEntity.getProperty(key).getValue());
+ }
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Trip") && navigation.equals("Photo")) {
+ Map map = this.tripLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.tripLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ ArrayList<Integer> photos = (ArrayList<Integer>) map.get("Photos");
+ if (photos == null) {
+ photos = new ArrayList<Integer>();
+ map.put("Photos", photos);
+ }
+ photos.add((Integer) childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Flight") && navigation.equals("From")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.flightLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ map.put("From", childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Flight") && navigation.equals("To")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.flightLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ map.put("To", childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else if (type.getName().equals("Flight") && navigation.equals("Airline")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map == null) {
+ map = new HashMap();
+ this.flightLinks.put((Integer) parentEntity.getProperty(key).getValue(), map);
+ }
+ map.put("Airline", childEntity.getProperty(key).getValue());
+ setLink(parentEntity, navigation, childEntity);
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ }
+
+ protected static void setLink(Entity entity, final String navigationPropertyName,
+ final Entity target) {
+ Link link = new LinkImpl();
+ link.setTitle(navigationPropertyName);
+ link.setInlineEntity(target);
+ entity.getNavigationLinks().add(link);
+ }
+
+ public boolean updateNavigationLink(String navigationProperty, Entity parentEntity,
+ Entity updateEntity) {
+ boolean updated = false;
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+ String key = type.getKeyPredicateNames().get(0);
+
+ EdmEntityType updateType = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(updateEntity.getType()));
+ String updateKey = updateType.getKeyPredicateNames().get(0);
+
+ if (type.getName().equals("Person") && navigationProperty.equals("Photo")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.put("Photo", ((Long) updateEntity.getProperty(updateKey).getValue()).intValue());
+ updated = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("From")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.put("From", updateEntity.getProperty(updateKey).getValue());
+ updated = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("To")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.put("To", updateEntity.getProperty(updateKey).getValue());
+ updated = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("Airline")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.put("Airline", updateEntity.getProperty(updateKey).getValue());
+ updated = true;
+ }
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ return updated;
+ }
+
+ public Entity createEntity(String entitySetName, Entity entity, String location)
+ throws ODataApplicationException {
+
+ EntitySet set = this.entitySetMap.get(entitySetName);
+ EntityImpl copy = new EntityImpl();
+ copy.setType(entity.getType());
+ for (Property p : entity.getProperties()) {
+ copy.addProperty(p);
+ }
+
+ try {
+ copy.setId(new URI(location));
+ copy.setETag(UUID.randomUUID().toString());
+ } catch (URISyntaxException e) {
+ throw new ODataApplicationException("Failed to create ID for entity", 500,
+ Locale.getDefault());
+ }
+
+ set.getEntities().add(copy);
+ return copy;
+ }
+
+ public boolean deleteEntity(String entitySetName, String eTag, String key, Object keyValue) {
+ EntitySet set = getEntitySet(entitySetName);
+ Iterator<Entity> it = set.getEntities().iterator();
+ boolean removed = false;
+ while (it.hasNext()) {
+ Entity entity = it.next();
+ if (entity.getProperty(key).getValue().equals(keyValue) && eTag.equals("*")
+ || eTag.equals(entity.getETag())) {
+ it.remove();
+ removed = true;
+ break;
+ }
+ }
+ return removed;
+ }
+
+ public boolean updateProperty(String entitySetName, String eTag, String key, Object keyValue,
+ Property property) {
+ EntitySet set = getEntitySet(entitySetName);
+ Iterator<Entity> it = set.getEntities().iterator();
+ boolean replaced = false;
+ while (it.hasNext()) {
+ Entity entity = it.next();
+ if (entity.getProperty(key).getValue().equals(keyValue) && eTag.equals("*")
+ || eTag.equals(entity.getETag())) {
+ entity.getProperty(property.getName()).setValue(property.getValueType(),
+ property.getValue());
+ replaced = true;
+ break;
+ }
+ }
+ return replaced;
+ }
+
+ public EntitySet getNavigableEntitySet(Entity parentEntity, UriResourceNavigation navigation) {
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+
+ String key = type.getKeyPredicateNames().get(0);
+ String linkName = navigation.getProperty().getName();
+
+ EntitySet results = null;
+ if (type.getName().equals("Person") && linkName.equals("Friends")) {
+ results = getFriends((String) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Person") && linkName.equals("Trips")) {
+ results = getTrips((String) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Trip") && linkName.equals("PlanItems")) {
+ EntitySetImpl planitems = new EntitySetImpl();
+ if (navigation.getTypeFilterOnCollection() == null) {
+ results = getPlanItems((Integer) parentEntity.getProperty(key).getValue(), planitems);
+ } else if (navigation.getTypeFilterOnCollection().getName().equals("Flight")) {
+ results = getFlights((Integer) parentEntity.getProperty(key).getValue(), planitems);
+ } else if (navigation.getTypeFilterOnCollection().getName().equals("Event")) {
+ results = getEvents((Integer) parentEntity.getProperty(key).getValue(), planitems);
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ } else if (type.getName().equals("Trip") && linkName.equals("Photos")) {
+ results = getTripPhotos((Integer) parentEntity.getProperty(key).getValue());
+ }
+ return results;
+ }
+
+ public Entity getNavigableEntity(Entity parentEntity, UriResourceNavigation navigation)
+ throws ODataApplicationException {
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+
+ String key = type.getKeyPredicateNames().get(0);
+ String linkName = navigation.getProperty().getName();
+
+ EntitySet results = null;
+ if (navigation.getProperty().isCollection()) {
+ results = getNavigableEntitySet(parentEntity, navigation);
+ return this.getEntity(results, navigation.getKeyPredicates());
+ }
+ if (type.getName().equals("Person") && linkName.equals("Photo")) {
+ return getPhoto((String) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Flight") && linkName.equals("From")) {
+ return getFlightFrom((Integer) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Flight") && linkName.equals("To")) {
+ return getFlightTo((Integer) parentEntity.getProperty(key).getValue());
+ } else if (type.getName().equals("Flight") && linkName.equals("Airline")) {
+ return getFlightAirline((Integer) parentEntity.getProperty(key).getValue());
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ }
+
+ public boolean removeNavigationLink(String navigationProperty, Entity parentEntity,
+ Entity deleteEntity) {
+ boolean removed = false;
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(parentEntity.getType()));
+ String key = type.getKeyPredicateNames().get(0);
+
+ if (type.getName().equals("Person") && navigationProperty.equals("Friends")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ ArrayList<String> friends = (ArrayList<String>) map.get("Friends");
+ if (friends != null) {
+ friends.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ }
+ } else if (type.getName().equals("Person") && navigationProperty.equals("Trips")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ ArrayList<Integer> trips = (ArrayList<Integer>) map.get("Trips");
+ if (trips != null) {
+ trips.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ }
+ } else if (type.getName().equals("Person") && navigationProperty.equals("Photo")) {
+ Map map = this.peopleLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.remove("Photo");
+ removed = true;
+ }
+ } else if (type.getName().equals("Trip") && navigationProperty.equals("PlanItems")) {
+ Map map = this.tripLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ if (deleteEntity.getType().equals("Flight")) {
+ ArrayList<Integer> flights = (ArrayList<Integer>) map.get("Flights");
+ if (flights != null) {
+ flights.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ } else {
+ ArrayList<Integer> events = (ArrayList<Integer>) map.get("Events");
+ if (events != null) {
+ events.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ }
+ }
+ } else if (type.getName().equals("Trip") && navigationProperty.equals("Photo")) {
+ Map map = this.tripLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ ArrayList<Integer> photos = (ArrayList<Integer>) map.get("Photos");
+ if (photos != null) {
+ photos.remove(deleteEntity.getProperty(key).getValue());
+ removed = true;
+ }
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("From")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.remove("From");
+ removed = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("To")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.remove("To");
+ removed = true;
+ }
+ } else if (type.getName().equals("Flight") && navigationProperty.equals("Airline")) {
+ Map map = this.flightLinks.get(parentEntity.getProperty(key).getValue());
+ if (map != null) {
+ map.remove("Airline");
+ removed = true;
+ }
+ } else {
+ throw new RuntimeException("unknown relation");
+ }
+ return removed;
+ }
+
+ // note these are not tied to entities for simplicity sake
+ public boolean updateMedia(Entity entity, InputStream mediaContent)
+ throws ODataApplicationException {
+ checkForMedia(entity);
+ return true;
+ }
+
+ // note these are not tied to entities for simplicity sake
+ public InputStream readMedia(Entity entity) throws ODataApplicationException {
+ checkForMedia(entity);
+ try {
+ return new FileInputStream(new File("src/test/resources/OlingoOrangeTM.png"));
+ } catch (FileNotFoundException e) {
+ throw new ODataApplicationException("image not found", 500, Locale.getDefault());
+ }
+ }
+
+ // note these are not tied to entities for simplicity sake
+ public boolean deleteMedia(Entity entity) throws ODataApplicationException {
+ checkForMedia(entity);
+ return true;
+ }
+
+ private void checkForMedia(Entity entity) throws ODataApplicationException {
+ EdmEntityType type = this.metadata.getEdm().getEntityType(
+ new FullQualifiedName(entity.getType()));
+ if (!type.hasStream()) {
+ throw new ODataApplicationException("No Media proeprty on the entity", 500,
+ Locale.getDefault());
+ }
+ }
+
+ public boolean deleteStream(Entity entity, EdmProperty property) {
+ // should remove stream links
+ return true;
+ }
+
+ public boolean updateStream(Entity entity, EdmProperty property, InputStream streamContent) {
+ // should add stream links
+ return true;
+ }
+}
\ No newline at end of file
[39/50] [abbrv] olingo-odata4 git commit: [OLINGO-603] Further
refactoring
Posted by ch...@apache.org.
[OLINGO-603] Further refactoring
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/d067037f
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/d067037f
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/d067037f
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: d067037f40766f10c6b8d95566436cba67755abb
Parents: ef6ed4e
Author: Christian Amend <ch...@apache.org>
Authored: Wed Apr 1 14:23:26 2015 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Apr 1 14:30:27 2015 +0200
----------------------------------------------------------------------
.../proxy/commons/EntityInvocationHandler.java | 2 +-
.../org/apache/olingo/fit/AbstractServices.java | 10 +-
.../api/communication/request/ODataRequest.java | 2 -
.../cud/ODataReferenceAddingRequest.java | 20 +--
.../response/ODataBatchResponse.java | 2 +-
.../response/ODataReferenceAddingResponse.java | 2 +-
.../olingo/client/api/uri/URIBuilder.java | 2 +-
.../apache/olingo/client/api/uri/URIFilter.java | 2 +-
.../request/AbstractODataRequest.java | 2 -
.../olingo/client/core/uri/FilterConst.java | 2 +-
.../olingo/client/core/uri/FilterLiteral.java | 2 +-
.../olingo/client/core/uri/FilterProperty.java | 2 +-
.../apache/olingo/client/core/uri/URIUtils.java | 1 -
.../commons/api/domain/ODataComplexValue.java | 1 -
.../commons/api/domain/ODataInlineEntity.java | 2 -
.../olingo/commons/api/domain/ODataLink.java | 1 -
.../commons/api/domain/ODataLinkType.java | 1 -
.../commons/api/edm/EdmPrimitiveTypeKind.java | 2 -
.../olingo/commons/api/edm/provider/Schema.java | 4 +-
.../olingo/commons/api/format/ODataFormat.java | 1 -
.../api/serializer/FixedFormatSerializer.java | 2 +-
.../json/ODataJsonDeserializer.java | 45 +++---
.../server/tecsvc/provider/ActionProvider.java | 161 +++++++++----------
...ataJsonDeserializerActionParametersTest.java | 31 ++++
.../core/uri/testutil/FilterValidator.java | 2 +-
.../core/uri/testutil/ParserValidator.java | 6 +-
26 files changed, 161 insertions(+), 149 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
index 20ab3a5..d3d7476 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
@@ -277,7 +277,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
/**
* Gets the current ETag defined into the wrapped entity.
*
- * @return
+ * @return the current etag
*/
public String getETag() {
return getEntity().getETag();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index a2ccbae..de8c10e 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -1463,7 +1463,7 @@ public abstract class AbstractServices {
* @param path
* @param format
* @param changes
- * @return
+ * @return response
*/
@PUT
@Path("/{entitySetName}({entityId})/{path:.*}/$value")
@@ -1491,7 +1491,7 @@ public abstract class AbstractServices {
* @param path
* @param format
* @param changes
- * @return
+ * @return response
*/
@MERGE
@Path("/{entitySetName}({entityId})/{path:.*}")
@@ -1519,7 +1519,7 @@ public abstract class AbstractServices {
* @param path
* @param format
* @param changes
- * @return
+ * @return response
*/
@PATCH
@Path("/{entitySetName}({entityId})/{path:.*}")
@@ -1587,7 +1587,7 @@ public abstract class AbstractServices {
* @param path
* @param format
* @param changes
- * @return
+ * @return response
*/
@PUT
@Path("/{entitySetName}({entityId})/{path:.*}")
@@ -1650,7 +1650,7 @@ public abstract class AbstractServices {
* @param entityId
* @param path
* @param format
- * @return
+ * @return response
*/
@DELETE
@Path("/{entitySetName}({entityId})/{path:.*}/$value")
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/ODataRequest.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/ODataRequest.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/ODataRequest.java
index b97085f..55831b7 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/ODataRequest.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/ODataRequest.java
@@ -28,9 +28,7 @@ import org.apache.olingo.commons.api.http.HttpMethod;
/**
* Abstract representation of an OData request. Get instance by using factories.
*
- * @see org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory
* @see org.apache.olingo.client.api.communication.request.cud.CUDRequestFactory
- * @see org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory
* @see org.apache.olingo.client.api.communication.request.batch.BatchRequestFactory
* @see org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/cud/ODataReferenceAddingRequest.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/cud/ODataReferenceAddingRequest.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/cud/ODataReferenceAddingRequest.java
index ad34ecb..82f001a 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/cud/ODataReferenceAddingRequest.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/cud/ODataReferenceAddingRequest.java
@@ -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.
*/
@@ -28,12 +28,12 @@ import org.apache.olingo.client.api.communication.response.ODataReferenceAddingR
* ODataReferenceAdding requests eighter add or change the reference of navigation properties.
*
* If the navigation property is a collection of navigation references, the request adds a new reference to the
- * collection. [OData Protocol 4.0 - 11.4.6.1]
+ * collection. [OData Protocol 4.0 - 11.4.6.1]
*
* If the request addresses an navigation property, which references a single entity, the reference will
* be changed to the value provided by the request. [OData-Protocol 4.0 - 11.4.6.3]
*/
-public interface ODataReferenceAddingRequest
- extends ODataBasicRequest<ODataReferenceAddingResponse>, ODataBatchableRequest {
+public interface ODataReferenceAddingRequest extends ODataBasicRequest<ODataReferenceAddingResponse>,
+ ODataBatchableRequest {
//No additional methods needed for now.
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataBatchResponse.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataBatchResponse.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataBatchResponse.java
index 744758e..358c441 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataBatchResponse.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataBatchResponse.java
@@ -25,7 +25,7 @@ import org.apache.olingo.client.api.communication.request.batch.ODataBatchRespon
/**
* This class implements a response to a batch request.
*
- * @see org.apache.olingo.client.api.communication.request.batch.CommonODataBatchRequest
+ * @see org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest
*/
public interface ODataBatchResponse extends ODataResponse {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataReferenceAddingResponse.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataReferenceAddingResponse.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataReferenceAddingResponse.java
index adae485..51bba0c 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataReferenceAddingResponse.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/response/ODataReferenceAddingResponse.java
@@ -25,7 +25,7 @@ package org.apache.olingo.client.api.communication.response;
* If the request was successful, the service response has status code 204 and
* the body has to be empty.
*
- * @see org.apache.olingo.client.api.communication.request.cud.api.request.cud.v4.ODataReferenceAddingRequest
+ * @see org.apache.olingo.client.api.communication.request.cud.ODataReferenceAddingRequest
*/
public interface ODataReferenceAddingResponse extends ODataResponse {
//No additional methods needed for now.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIBuilder.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIBuilder.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIBuilder.java
index d0eaac9..af6beb7 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIBuilder.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIBuilder.java
@@ -175,7 +175,7 @@ public interface URIBuilder {
* @return current URIBuilder instance
* @see QueryOption#FILTER
* @see URIFilter
- * @see org.apache.olingo.client.api.uri.CommonFilterFactory
+ * @see org.apache.olingo.client.api.uri.FilterFactory
*/
URIBuilder filter(URIFilter filter);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIFilter.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIFilter.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIFilter.java
index 2162b87..517079d 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIFilter.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/URIFilter.java
@@ -21,7 +21,7 @@ package org.apache.olingo.client.api.uri;
/**
* Interface for any available filter; obtain instances via <tt>FilterFactory</tt>.
*
- * @see org.apache.olingo.client.api.uri.CommonFilterFactory
+ * @see org.apache.olingo.client.api.uri.FilterFactory
*/
public interface URIFilter {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java
index d10960a..bdfd118 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java
@@ -47,9 +47,7 @@ import org.apache.olingo.commons.api.http.HttpMethod;
/**
* Abstract representation of an OData request. Get instance by using factories.
*
- * @see org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory
* @see org.apache.olingo.client.api.communication.request.cud.CUDRequestFactory
- * @see org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory
* @see org.apache.olingo.client.api.communication.request.batch.BatchRequestFactory
* @see org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterConst.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterConst.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterConst.java
index c3e7669..f1732cc 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterConst.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterConst.java
@@ -23,7 +23,7 @@ import org.apache.olingo.client.api.uri.FilterArg;
/**
* Filter property path; obtain instances via <tt>FilterArgFactory</tt>.
*
- * @see org.apache.olingo.client.api.uri.CommonFilterArgFactory
+ * @see org.apache.olingo.client.api.uri.FilterArgFactory
*/
public class FilterConst implements FilterArg {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java
index 4842a96..501a734 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterLiteral.java
@@ -23,7 +23,7 @@ import org.apache.olingo.client.api.uri.FilterArg;
/**
* Filter value literals; obtain instances via <tt>FilterArgFactory</tt>.
*
- * @see org.apache.olingo.client.api.uri.v3.FilterArgFactory
+ * @see org.apache.olingo.client.api.uri.FilterArgFactory
*/
public class FilterLiteral implements FilterArg {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterProperty.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterProperty.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterProperty.java
index bc99eb4..6073112 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterProperty.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/FilterProperty.java
@@ -23,7 +23,7 @@ import org.apache.olingo.client.api.uri.FilterArg;
/**
* Filter property path; obtain instances via <tt>FilterArgFactory</tt>.
*
- * @see org.apache.olingo.client.api.uri.CommonFilterArgFactory
+ * @see org.apache.olingo.client.api.uri.FilterArgFactory
*/
public class FilterProperty implements FilterArg {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
index 26399c2..608dc3a 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
@@ -179,7 +179,6 @@ public final class URIUtils {
/**
* Turns primitive values into their respective URI representation.
*
- * @param version OData protocol version
* @param obj primitive value
* @return URI representation
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataComplexValue.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataComplexValue.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataComplexValue.java
index 04888d7..ad64559 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataComplexValue.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataComplexValue.java
@@ -23,7 +23,6 @@ import java.util.Map;
/**
* OData complex property value.
*
- * @param <OP> The actual ODataProperty interface.
*/
public interface ODataComplexValue extends ODataValue, ODataLinked, ODataAnnotatable, Iterable<ODataProperty> {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntity.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntity.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntity.java
index ff9a420..6ba0ad6 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntity.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataInlineEntity.java
@@ -30,7 +30,6 @@ public class ODataInlineEntity extends ODataLink {
/**
* Constructor.
*
- * @param version OData service version.
* @param uri edit link.
* @param type type.
* @param title title.
@@ -45,7 +44,6 @@ public class ODataInlineEntity extends ODataLink {
/**
* Constructor.
*
- * @param version OData service version.
* @param baseURI base URI.
* @param href href.
* @param type type.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java
index 4bc8bdb..8593679 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLink.java
@@ -105,7 +105,6 @@ public class ODataLink extends ODataItem implements ODataAnnotatable {
/**
* Constructor.
*
- * @param version OData service version.
* @param uri URI.
* @param type type.
* @param title title.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java
index f99aa3e..5ae427c 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/domain/ODataLinkType.java
@@ -73,7 +73,6 @@ public enum ODataLinkType {
* Gets
* <code>LinkType</code> instance from the given rel and type.
*
- * @param version OData protocol version.
* @param rel rel.
* @param type type.
* @return <code>ODataLinkType</code> object.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java
index b7efca7..78dd013 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveTypeKind.java
@@ -81,7 +81,6 @@ public enum EdmPrimitiveTypeKind {
/**
* Gets <tt>EdmPrimitiveTypeKind</tt> from a full-qualified type name, for the given OData protocol version.
*
- * @param version OData protocol version.
* @param fqn full-qualified type name.
* @return <tt>EdmPrimitiveTypeKind</tt> object.
*/
@@ -93,7 +92,6 @@ public enum EdmPrimitiveTypeKind {
* Gets <tt>EdmPrimitiveTypeKind</tt> from a full type expression (as <tt>Edm.Int32</tt>), for the given OData
* protocol version.
*
- * @param version OData protocol version.
* @param fqn string value type.
* @return <tt>EdmPrimitiveTypeKind</tt> object.
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/Schema.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/Schema.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/Schema.java
index 183478f..7ed2704 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/Schema.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/Schema.java
@@ -131,7 +131,7 @@ public class Schema extends AbstractEdmItem implements Annotatable{
/**
* All actions with the given name
* @param name
- * @return
+ * @return a list of actions
*/
public List<Action> getActions(final String name) {
return getAllByName(name, getActions());
@@ -149,7 +149,7 @@ public class Schema extends AbstractEdmItem implements Annotatable{
/**
* All functions with the given name
* @param name
- * @return
+ * @return a list of functions
*/
public List<Function> getFunctions(final String name) {
return getAllByName(name, getFunctions());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ODataFormat.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ODataFormat.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ODataFormat.java
index 6a4b494..52e4bec 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ODataFormat.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ODataFormat.java
@@ -57,7 +57,6 @@ public enum ODataFormat {
/**
* Gets format as {@link ContentType}.
- * @param version OData service version.
* @return format as ContentType.
*/
public ContentType getContentType() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java
index a62531b..9a0e693 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java
@@ -53,7 +53,7 @@ public interface FixedFormatSerializer {
* Serializes a batch response
* @param batchResponses
* @param boundary
- * @return
+ * @return response as an input stream
* @throws BatchSerializerException
*/
InputStream batchResponse(List<ODataResponsePart> batchResponses, String boundary) throws BatchSerializerException;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index b9fe770..22e570e 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -183,7 +183,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
public List<Parameter> actionParameters(InputStream stream, final EdmAction edmAction) throws DeserializerException {
try {
ObjectNode tree = parseJsonTree(stream);
- ArrayList<Parameter> parameters = new ArrayList<Parameter>();
+ List<Parameter> parameters = new ArrayList<Parameter>();
consumeParameters(edmAction, tree, parameters);
assertJsonNodeIsEmpty(tree);
return parameters;
@@ -208,33 +208,42 @@ public class ODataJsonDeserializer implements ODataDeserializer {
return tree;
}
- private void consumeParameters(final EdmAction edmAction, ObjectNode node, ArrayList<Parameter> parameters)
+ private void consumeParameters(final EdmAction edmAction, ObjectNode node, List<Parameter> parameters)
throws DeserializerException {
- for (final String name : edmAction.getParameterNames()) {
+ List<String> parameterNames = edmAction.getParameterNames();
+ if (edmAction.isBound()) {
+ // The binding parameter must not occur in the payload.
+ parameterNames = parameterNames.subList(1, parameterNames.size());
+ }
+ for (final String name : parameterNames) {
final EdmParameter edmParameter = edmAction.getParameter(name);
ParameterImpl parameter = new ParameterImpl();
parameter.setName(name);
JsonNode jsonNode = node.get(name);
- if (jsonNode == null || jsonNode.isNull()) {
- if (!edmParameter.isNullable()) {
- throw new DeserializerException("Non-nullable parameter not present or null",
- DeserializerException.MessageKeys.INVALID_NULL_PARAMETER, name);
- }
- }
switch (edmParameter.getType().getKind()) {
case PRIMITIVE:
case DEFINITION:
case ENUM:
- Property consumePropertyNode =
- consumePropertyNode(edmParameter.getName(), edmParameter.getType(), edmParameter.isCollection(),
- edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter
- .getScale(),
- true, edmParameter.getMapping(),
- jsonNode);
- parameter.setValue(consumePropertyNode.getValueType(), consumePropertyNode.getValue());
- parameters.add(parameter);
- node.remove(name);
+ if (jsonNode == null || jsonNode.isNull()) {
+ if (!edmParameter.isNullable()) {
+ throw new DeserializerException("Non-nullable parameter not present or null",
+ DeserializerException.MessageKeys.INVALID_NULL_PARAMETER, name);
+ }
+ if (edmParameter.isCollection()) {
+ throw new DeserializerException("Collection must not be null for parameter: " + name,
+ DeserializerException.MessageKeys.INVALID_NULL_PARAMETER, name);
+ }
+ parameter.setValue(ValueType.PRIMITIVE, null);
+ } else {
+ Property consumePropertyNode =
+ consumePropertyNode(edmParameter.getName(), edmParameter.getType(), edmParameter.isCollection(),
+ edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter
+ .getScale(), true, edmParameter.getMapping(), jsonNode);
+ parameter.setValue(consumePropertyNode.getValueType(), consumePropertyNode.getValue());
+ parameters.add(parameter);
+ node.remove(name);
+ }
break;
case COMPLEX:
case ENTITY:
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
index 4318353..d00b953 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ActionProvider.java
@@ -50,7 +50,7 @@ public class ActionProvider {
new FullQualifiedName(SchemaProvider.NAMESPACE, "BAETTwoKeyNavRTETTwoKeyNav");
public static final FullQualifiedName nameBAETAllPrimRT =
- new FullQualifiedName(SchemaProvider.NAMESPACE, "BAESAllPrimRT");
+ new FullQualifiedName(SchemaProvider.NAMESPACE, "BAETAllPrimRT");
// Unbound Actions
public static final FullQualifiedName nameUARTString = new FullQualifiedName(SchemaProvider.NAMESPACE,
@@ -77,74 +77,67 @@ public class ActionProvider {
public List<Action> getActions(final FullQualifiedName actionName) throws ODataException {
if (actionName.equals(nameUARTString)) {
- return Arrays.asList(
- new Action().setName(nameUARTString.getName())
- .setReturnType(new ReturnType().setType(PropertyProvider.nameString))
- );
+ return Collections.singletonList(
+ new Action().setName(nameUARTString.getName())
+ .setReturnType(new ReturnType().setType(PropertyProvider.nameString)));
+
} else if (actionName.equals(nameUARTCollStringTwoParam)) {
- return Arrays.asList(
- new Action().setName(nameUARTCollStringTwoParam.getName())
- .setParameters(Arrays.asList(
- new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16),
- new Parameter().setName("ParameterDuration").setType(PropertyProvider.nameDuration)))
- .setReturnType(new ReturnType().setType(PropertyProvider.nameString).setCollection(true))
- );
+ return Collections.singletonList(
+ new Action().setName(nameUARTCollStringTwoParam.getName())
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16),
+ new Parameter().setName("ParameterDuration").setType(PropertyProvider.nameDuration)))
+ .setReturnType(new ReturnType().setType(PropertyProvider.nameString).setCollection(true)));
} else if (actionName.equals(nameUARTCTTwoPrimParam)) {
- return Arrays.asList(
- new Action().setName(nameUARTCTTwoPrimParam.getName())
- .setParameters(Arrays.asList(
- new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)
- .setNullable(false)))
- .setReturnType(
- new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim).setNullable(false))
- );
-
+ return Collections.singletonList(
+ new Action().setName(nameUARTCTTwoPrimParam.getName())
+ .setParameters(Collections.singletonList(
+ new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)
+ .setNullable(false)))
+ .setReturnType(
+ new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim).setNullable(false)));
+
} else if (actionName.equals(nameUARTCollCTTwoPrimParam)) {
- return Arrays.asList(
- new Action().setName(nameUARTCollCTTwoPrimParam.getName())
- .setParameters(Arrays.asList(
- new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
- .setReturnType(
- new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim).setCollection(true))
- );
+ return Collections.singletonList(
+ new Action().setName(nameUARTCollCTTwoPrimParam.getName())
+ .setParameters(Collections.singletonList(
+ new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
+ .setReturnType(
+ new ReturnType().setType(ComplexTypeProvider.nameCTTwoPrim).setCollection(true)));
} else if (actionName.equals(nameUARTETTwoKeyTwoPrimParam)) {
- return Arrays.asList(
- new Action().setName(nameUARTETTwoKeyTwoPrimParam.getName())
- .setParameters(Arrays.asList(
- new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
- .setReturnType(
- new ReturnType().setType(EntityTypeProvider.nameETTwoKeyTwoPrim))
- );
+ return Collections.singletonList(
+ new Action().setName(nameUARTETTwoKeyTwoPrimParam.getName())
+ .setParameters(Collections.singletonList(
+ new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
+ .setReturnType(
+ new ReturnType().setType(EntityTypeProvider.nameETTwoKeyTwoPrim)));
} else if (actionName.equals(nameUARTCollETKeyNavParam)) {
- return Arrays.asList(
- new Action().setName(nameUARTCollETKeyNavParam.getName())
- .setParameters(Arrays.asList(
- new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
- .setReturnType(
- new ReturnType().setType(EntityTypeProvider.nameETKeyNav).setCollection(true))
- );
+ return Collections.singletonList(
+ new Action().setName(nameUARTCollETKeyNavParam.getName())
+ .setParameters(Collections.singletonList(
+ new Parameter().setName("ParameterInt16").setType(PropertyProvider.nameInt16)))
+ .setReturnType(
+ new ReturnType().setType(EntityTypeProvider.nameETKeyNav).setCollection(true)));
} else if (actionName.equals(nameUARTETAllPrimParam)) {
- return Arrays.asList(
- new Action().setName(nameUARTETAllPrimParam.getName())
- .setParameters(Arrays.asList(
- new Parameter().setName("ParameterDate").setType(PropertyProvider.nameDate)))
- .setReturnType(
- new ReturnType().setType(EntityTypeProvider.nameETAllPrim))
- );
+ return Collections.singletonList(
+ new Action().setName(nameUARTETAllPrimParam.getName())
+ .setParameters(Collections.singletonList(
+ new Parameter().setName("ParameterDate").setType(PropertyProvider.nameDate)))
+ .setReturnType(
+ new ReturnType().setType(EntityTypeProvider.nameETAllPrim)));
} else if (actionName.equals(nameUARTCollETAllPrimParam)) {
- return Arrays.asList(
- new Action().setName(nameUARTCollETAllPrimParam.getName())
- .setParameters(Arrays.asList(
- new Parameter().setName("ParameterTimeOfDay")
- .setType(PropertyProvider.nameTimeOfDay)))
- .setReturnType(
- new ReturnType().setType(EntityTypeProvider.nameETAllPrim).setCollection(true))
- );
+ return Collections.singletonList(
+ new Action().setName(nameUARTCollETAllPrimParam.getName())
+ .setParameters(Collections.singletonList(
+ new Parameter().setName("ParameterTimeOfDay")
+ .setType(PropertyProvider.nameTimeOfDay)))
+ .setReturnType(
+ new ReturnType().setType(EntityTypeProvider.nameETAllPrim).setCollection(true)));
} else if (actionName.equals(nameUART)) {
return Collections.singletonList(new Action().setName(nameUART.getName()));
@@ -186,26 +179,22 @@ public class ActionProvider {
} else if (actionName.equals(nameBAESAllPrimRTETAllPrim)) {
return Arrays.asList(
new Action().setName("BAESAllPrimRTETAllPrim")
- .setParameters(
- Arrays.asList(
- new Parameter().setName("ParameterESAllPrim").setType(EntityTypeProvider.nameETAllPrim)
- .setCollection(true).setNullable(false)))
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterESAllPrim").setType(EntityTypeProvider.nameETAllPrim)
+ .setCollection(true).setNullable(false)))
.setBound(true)
.setReturnType(
- new ReturnType().setType(EntityTypeProvider.nameETAllPrim))
- );
+ new ReturnType().setType(EntityTypeProvider.nameETAllPrim)));
} else if (actionName.equals(nameBAESTwoKeyNavRTESTwoKeyNav)) {
return Arrays.asList(
new Action().setName("BAESTwoKeyNavRTESTwoKeyNav")
- .setParameters(
- Arrays.asList(
- new Parameter().setName("ParameterETTwoKeyNav").setType(EntityTypeProvider.nameETTwoKeyNav)
- .setCollection(true).setNullable(false)))
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterETTwoKeyNav").setType(EntityTypeProvider.nameETTwoKeyNav)
+ .setCollection(true).setNullable(false)))
.setBound(true)
.setReturnType(
- new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav).setCollection(true))
- );
+ new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav).setCollection(true)));
} else if(actionName.equals(nameBAESTwoKeyNavRTESKeyNav)) {
return Arrays.asList(
@@ -214,12 +203,12 @@ public class ActionProvider {
.setEntitySetPath("BindingParam/NavPropertyETKeyNavMany")
.setParameters(Arrays.asList(
new Parameter().setName("ParameterETTwoKeyNav")
- .setType(EntityTypeProvider.nameETTwoKeyNav)
- .setCollection(true)
- .setNullable(false)
- ))
- .setReturnType(new ReturnType().setType(EntityTypeProvider.nameETKeyNav).setCollection(true))
- );
+ .setType(EntityTypeProvider.nameETTwoKeyNav)
+ .setCollection(true)
+ .setNullable(false)))
+ .setReturnType(
+ new ReturnType().setType(EntityTypeProvider.nameETKeyNav).setCollection(true)));
+
} else if (actionName.equals(nameBAETBaseTwoKeyNavRTETBaseTwoKeyNav)) {
return Arrays.asList(
new Action().setName("BAETBaseTwoKeyNavRTETBaseTwoKeyNav")
@@ -228,20 +217,19 @@ public class ActionProvider {
.setNullable(false)))
.setBound(true)
.setReturnType(
- new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav))
- );
+ new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav)));
} else if (actionName.equals(nameBAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav)) {
return Arrays.asList(
new Action().setName("BAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav")
- .setParameters(
- Arrays.asList(
- new Parameter().setName("ParameterETTwoBaseTwoKeyNav").setType(
- EntityTypeProvider.nameETTwoBaseTwoKeyNav).setNullable(false)))
+ .setParameters(Arrays.asList(
+ new Parameter().setName("ParameterETTwoBaseTwoKeyNav")
+ .setType(EntityTypeProvider.nameETTwoBaseTwoKeyNav)
+ .setNullable(false)))
.setBound(true)
.setReturnType(
- new ReturnType().setType(EntityTypeProvider.nameETBaseTwoKeyNav))
- );
+ new ReturnType().setType(EntityTypeProvider.nameETBaseTwoKeyNav)));
+
} else if(actionName.equals(nameBAETAllPrimRT)) {
return Arrays.asList(
new Action().setName("BAETAllPrimRT")
@@ -249,17 +237,14 @@ public class ActionProvider {
.setParameters(Arrays.asList(
new Parameter().setName("ParameterETAllPrim")
.setNullable(false)
- .setType(EntityTypeProvider.nameETAllPrim)
- )),
+ .setType(EntityTypeProvider.nameETAllPrim))),
new Action().setName("BAETAllPrimRT")
.setBound(true)
.setParameters(Arrays.asList(
new Parameter().setName("ParameterETAllPrim")
.setNullable(false)
.setCollection(true)
- .setType(EntityTypeProvider.nameETAllPrim)
- ))
- );
+ .setType(EntityTypeProvider.nameETAllPrim))));
}
return null;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
index 80668eb..58777ab 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
@@ -57,6 +57,29 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
assertEquals(BigDecimal.valueOf(3669753), parameter.getValue());
}
+ @Test
+ public void boundEmpty() throws Exception {
+ final String input = "{}";
+ final List<Parameter> parameters = deserialize(input, "BAETAllPrimRT", "ETAllPrim");
+ assertNotNull(parameters);
+ assertTrue(parameters.isEmpty());
+ }
+
+ @Test(expected = DeserializerException.class)
+ public void bindingParameter() throws Exception {
+ deserialize("{\"ParameterETAllPrim\":{\"PropertyInt16\":42}}", "BAETAllPrimRT", "ETAllPrim");
+ }
+
+ @Test(expected = DeserializerException.class)
+ public void wrongName() throws Exception {
+ deserialize("{\"ParameterWrong\":null}", "UARTParam");
+ }
+
+ @Test(expected = DeserializerException.class)
+ public void nullNotNullable() throws Exception {
+ deserialize("{\"ParameterInt16\":null}", "UARTCTTwoPrimParam");
+ }
+
@Test(expected = DeserializerException.class)
public void missingParameter() throws Exception {
deserialize("{}", "UARTCTTwoPrimParam");
@@ -77,4 +100,12 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
.actionParameters(new ByteArrayInputStream(input.getBytes()),
edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName)));
}
+
+ private List<Parameter> deserialize(final String input, final String actionName, final String typeName)
+ throws DeserializerException {
+ return OData.newInstance().createDeserializer(ODataFormat.JSON)
+ .actionParameters(new ByteArrayInputStream(input.getBytes()),
+ edm.getBoundAction(new FullQualifiedName("Namespace1_Alias", actionName),
+ new FullQualifiedName("Namespace1_Alias", typeName), false));
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
index f530456..4d67fcd 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
@@ -286,7 +286,7 @@ public class FilterValidator implements TestValidator {
* Validates the serialized filterTree against a given filterString
* The given expected filterString is compressed before to allow better readable code in the unit tests
* @param toBeCompr
- * @return
+ * @return {@link FilterValidator}
*/
public FilterValidator isCompr(final String toBeCompr) {
return is(compress(toBeCompr));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d067037f/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java
index aeb1309..da65ff0 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java
@@ -57,7 +57,7 @@ public class ParserValidator {
* Used in fast LL Parsing:
* Don't stop the parsing process when the slower full context parsing (with prediction mode SLL) is
* required
- * @return
+ * @return {@link ParserValidator}
*/
public ParserValidator aFC() {
allowFullContext = true;
@@ -68,7 +68,7 @@ public class ParserValidator {
* Used in fast LL Parsing:
* Allows ContextSensitifity Errors which occur often when using the slower full context parsing
* and indicate that there is a context sensitivity ( which may not be an error).
- * @return
+ * @return {@link ParserValidator}
*/
public ParserValidator aCS() {
allowContextSensitifity = true;
@@ -78,7 +78,7 @@ public class ParserValidator {
/**
* Used in fast LL Parsing:
* Allows ambiguities
- * @return
+ * @return {@link ParserValidator}
*/
public ParserValidator aAM() {
allowAmbiguity = true;
[34/50] [abbrv] olingo-odata4 git commit: Merge branch 'OLINGO-573'
of https://git-wip-us.apache.org/repos/asf/olingo-odata4 into OLINGO-573
Posted by ch...@apache.org.
Merge branch 'OLINGO-573' of https://git-wip-us.apache.org/repos/asf/olingo-odata4 into OLINGO-573
Conflicts:
lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/ODataDeserializer.java
lib/server-core-ext/src/main/java/org/apache/olingo/server/core/SchemaBasedEdmProvider.java
lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/bce3ca6c
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/bce3ca6c
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/bce3ca6c
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: bce3ca6c7caf4c52ac5edb33c95b3421d24c3093
Parents: 2b73abc 8668b09
Author: Ramesh Reddy <ra...@jboss.org>
Authored: Tue Mar 31 11:34:03 2015 -0500
Committer: Ramesh Reddy <ra...@jboss.org>
Committed: Tue Mar 31 11:34:03 2015 -0500
----------------------------------------------------------------------
----------------------------------------------------------------------
[46/50] [abbrv] olingo-odata4 git commit: [OLINGO-617] Derserializer
and Serializer result refactoring, ExpandBuilder
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 841eabe..e105a2f 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -40,6 +40,7 @@ import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.deserializer.DeserializerResult;
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
import org.apache.olingo.server.api.processor.ActionEntityCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionEntityProcessor;
@@ -136,7 +137,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
getContextUrl(edmEntitySet, edmEntityType, false, expand, select))
.count(uriInfo.getCountOption())
.expand(expand).select(select)
- .build()));
+ .build()).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
@@ -195,7 +196,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, edmEntityType, true, expand, select))
.expand(expand).select(select)
- .build()));
+ .build()).getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
}
@@ -231,14 +232,16 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
Entity entity = dataProvider.create(edmEntitySet);
+ ExpandOption expand = null;
if (edmEntityType.hasStream()) { // called from createMediaEntity(...), not directly
dataProvider.setMedia(entity, odata.createFixedFormatDeserializer().binary(request.getBody()),
requestFormat.toContentTypeString());
} else {
+ final DeserializerResult deserializerResult = odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
+ .entity(request.getBody(), edmEntityType);
dataProvider.update(request.getRawBaseUri(), edmEntitySet, entity,
- odata.createDeserializer(ODataFormat.fromContentType(requestFormat))
- .entity(request.getBody(), edmEntityType),
- false, true);
+ deserializerResult.getEntity(), false, true);
+ expand = deserializerResult.getExpandTree();
}
final ODataFormat format = ODataFormat.fromContentType(responseFormat);
@@ -247,7 +250,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, edmEntityType, true, null, null))
- .build()));
+ .expand(expand)
+ .build()).getContent());
response.setStatusCode(HttpStatusCode.CREATED.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
response.setHeader(HttpHeader.LOCATION,
@@ -262,7 +266,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
Entity entity = readEntity(uriInfo);
checkRequestFormat(requestFormat);
ODataDeserializer deserializer = odata.createDeserializer(ODataFormat.fromContentType(requestFormat));
- final Entity changedEntity = deserializer.entity(request.getBody(), edmEntitySet.getEntityType());
+ final Entity changedEntity = deserializer.entity(request.getBody(), edmEntitySet.getEntityType()).getEntity();
dataProvider.update(request.getRawBaseUri(), edmEntitySet, entity, changedEntity,
request.getMethod() == HttpMethod.PATCH, false);
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
index b853e48..8a9968f 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
@@ -248,13 +248,13 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
.precision(edmProperty == null ? returnType.getPrecision() : edmProperty.getPrecision())
.scale(edmProperty == null ? returnType.getScale() : edmProperty.getScale())
.unicode(edmProperty == null ? null : edmProperty.isUnicode())
- .build()));
+ .build()).getContent());
break;
case COMPLEX:
response.setContent(serializer.complex(this.serviceMetadata,(EdmComplexType) type, property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
- .build()));
+ .build()).getContent());
break;
case COLLECTION_PRIMITIVE:
response.setContent(serializer.primitiveCollection((EdmPrimitiveType) type, property,
@@ -264,13 +264,13 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
.precision(edmProperty == null ? returnType.getPrecision() : edmProperty.getPrecision())
.scale(edmProperty == null ? returnType.getScale() : edmProperty.getScale())
.unicode(edmProperty == null ? null : edmProperty.isUnicode())
- .build()));
+ .build()).getContent());
break;
case COLLECTION_COMPLEX:
response.setContent(serializer.complexCollection(this.serviceMetadata, (EdmComplexType) type, property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
- .build()));
+ .build()).getContent());
break;
default:
break;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java
index f2a65cd..0347941 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java
@@ -41,8 +41,7 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
public void esAllPrimExpandedToOne() throws Exception {
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimOne.json");
- Entity entity = OData.newInstance().createDeserializer(ODataFormat.JSON).entity(stream, edmEntityType);
-
+ Entity entity = OData.newInstance().createDeserializer(ODataFormat.JSON).entity(stream, edmEntityType).getEntity();
Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimOne");
assertNotNull(navigationLink);
@@ -63,7 +62,7 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
public void esAllPrimExpandedToMany() throws Exception {
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimMany.json");
- Entity entity = OData.newInstance().createDeserializer(ODataFormat.JSON).entity(stream, edmEntityType);
+ Entity entity = OData.newInstance().createDeserializer(ODataFormat.JSON).entity(stream, edmEntityType).getEntity();
Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimMany");
assertNotNull(navigationLink);
@@ -130,7 +129,8 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
+ "}";
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETTwoPrim"));
- final Entity entity = OData.newInstance().createDeserializer(ODataFormat.JSON).entity(stream, edmEntityType);
+ final Entity entity = OData.newInstance().createDeserializer(ODataFormat.JSON).entity(stream, edmEntityType)
+ .getEntity();
assertEquals(1, entity.getNavigationLinks().size());
final Link link = entity.getNavigationLinks().get(0);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java
index 3a17eae..4864d24 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java
@@ -44,7 +44,8 @@ public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserial
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
InputStream stream = getFileAsStream("ESAllPrim.json");
EntitySet entitySet =
- OData.newInstance().createDeserializer(ODataFormat.JSON).entityCollection(stream, edmEntityType);
+ OData.newInstance().createDeserializer(ODataFormat.JSON).entityCollection(stream, edmEntityType)
+ .getEntityCollection();
assertNotNull(entitySet);
assertEquals(3, entitySet.getEntities().size());
@@ -78,7 +79,8 @@ public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserial
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCompCollComp"));
InputStream stream = getFileAsStream("ESCompCollComp.json");
EntitySet entitySet =
- OData.newInstance().createDeserializer(ODataFormat.JSON).entityCollection(stream, edmEntityType);
+ OData.newInstance().createDeserializer(ODataFormat.JSON).entityCollection(stream, edmEntityType)
+ .getEntityCollection();
assertNotNull(entitySet);
assertEquals(2, entitySet.getEntities().size());
@@ -99,7 +101,8 @@ public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserial
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
EntitySet entityCollection =
- OData.newInstance().createDeserializer(ODataFormat.JSON).entityCollection(stream, edmEntityType);
+ OData.newInstance().createDeserializer(ODataFormat.JSON).entityCollection(stream, edmEntityType)
+ .getEntityCollection();
assertNotNull(entityCollection.getEntities());
assertTrue(entityCollection.getEntities().isEmpty());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
index 58777ab..80c7c47 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
@@ -98,7 +98,7 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
private List<Parameter> deserialize(final String input, final String actionName) throws DeserializerException {
return OData.newInstance().createDeserializer(ODataFormat.JSON)
.actionParameters(new ByteArrayInputStream(input.getBytes()),
- edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName)));
+ edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName))).getActionParameter();
}
private List<Parameter> deserialize(final String input, final String actionName, final String typeName)
@@ -106,6 +106,6 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
return OData.newInstance().createDeserializer(ODataFormat.JSON)
.actionParameters(new ByteArrayInputStream(input.getBytes()),
edm.getBoundAction(new FullQualifiedName("Namespace1_Alias", actionName),
- new FullQualifiedName("Namespace1_Alias", typeName), false));
+ new FullQualifiedName("Namespace1_Alias", typeName), false)).getActionParameter();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
index 870f7c3..4a433c3 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
@@ -64,7 +64,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -93,7 +94,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -139,7 +141,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -159,7 +162,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -188,7 +192,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -222,7 +227,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCompAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCompAllPrim")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -263,7 +269,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCollAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCollAllPrim")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -300,7 +307,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -332,7 +340,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -380,7 +389,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
+ .getEntity();
assertNotNull(entity);
}
@@ -437,7 +447,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
+ .getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -455,7 +466,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
+ .getEntity();
assertNotNull(entity);
Link bindingToOne = entity.getNavigationBinding("NavPropertyETTwoPrimOne");
@@ -488,7 +500,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
+ .getEntity();
Link bindingToMany = entity.getNavigationBinding("NavPropertyETTwoPrimMany");
assertNotNull(bindingToMany);
assertTrue(bindingToMany.getBindingLinks().isEmpty());
@@ -500,7 +513,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
deserializer.entity(stream, edm
- .getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")));
+ .getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")))
+ .getEntity();
assertEquals(6, entity.getProperties().size());
@@ -545,7 +559,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity e = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETCollAllPrim")));
+ new FullQualifiedName("Namespace1_Alias", "ETCollAllPrim"))).getEntity();
assertTrue((Boolean) e.getProperty("CollPropertyBoolean").asCollection().get(0));
assertNull(e.getProperty("CollPropertyBoolean").asCollection().get(1));
@@ -560,7 +574,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity = deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias",
- "ETMixPrimCollComp")));
+ "ETMixPrimCollComp"))).getEntity();
assertNull(entity.getProperty("PropertyComp").getValue());
}
@@ -575,7 +589,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
+ new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp"))).getEntity();
List<?> collPropertyComp = entity.getProperty("CollPropertyComp").asCollection();
assertNull(collPropertyComp.get(0));
List<Property> complexPropertyProperties = ((ComplexValue) collPropertyComp.get(1)).getValue();
@@ -591,7 +605,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETCompAllPrim")));
+ new FullQualifiedName("Namespace1_Alias", "ETCompAllPrim"))).getEntity();
assertEquals("TEST A", entity.getProperty("PropertyComp").asComplex().getValue().get(0).getValue());
assertNull(entity.getProperty("PropertyComp").asComplex().getValue().get(1).getValue());
@@ -608,7 +622,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity e = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")));
+ new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp"))).getEntity();
assertEquals((short) 2, e.getProperty("PropertyEnumString").getValue());
Property propertyCompMixedEnumDef = e.getProperty("PropertyCompMixedEnumDef");
@@ -624,7 +638,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity e = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")));
+ new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp"))).getEntity();
assertEquals((short) 3, e.getProperty("PropertyEnumString").getValue());
}
@@ -662,7 +676,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
Entity entity =
- deserializer.entity(stream, entityType);
+ deserializer.entity(stream, entityType).getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index ee38684..f8b1dab 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -81,7 +81,7 @@ public class ODataJsonSerializerTest {
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
- .build());
+ .build()).getContent();
final String resultString = IOUtils.toString(result);
final String expectedResult = "{"
+ "\"@odata.context\":\"$metadata#ESAllPrim/$entity\","
@@ -114,7 +114,7 @@ public class ODataJsonSerializerTest {
entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
- .build()));
+ .build()).getContent());
final String expectedResult = "{\"@odata.context\":\"$metadata#ESAllPrim/$entity\","
+ "\"PropertyInt16\":32767,"
+ "\"PropertyString\":null,\"PropertyBoolean\":null,"
@@ -169,7 +169,7 @@ public class ODataJsonSerializerTest {
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build())
.count(countOption)
- .build());
+ .build()).getContent();
final String resultString = IOUtils.toString(result);
Assert.assertThat(resultString, CoreMatchers.startsWith("{"
@@ -194,7 +194,7 @@ public class ODataJsonSerializerTest {
EntitySerializerOptions.with()
.contextURL(ContextURL.with().serviceRoot(URI.create("http://host/service/"))
.entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
- .build());
+ .build()).getContent();
final String resultString = IOUtils.toString(result);
final String expectedResult = "{"
+ "\"@odata.context\":\"http://host/service/$metadata#ESCollAllPrim/$entity\","
@@ -229,7 +229,7 @@ public class ODataJsonSerializerTest {
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
- .build());
+ .build()).getContent();
final String resultString = IOUtils.toString(result);
final String expectedResult = "{"
+ "\"@odata.context\":\"$metadata#ESCompAllPrim/$entity\","
@@ -262,7 +262,7 @@ public class ODataJsonSerializerTest {
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
- .build());
+ .build()).getContent();
final String resultString = IOUtils.toString(result);
final String expectedResult = "{"
+ "\"@odata.context\":\"$metadata#ESMixPrimCollComp/$entity\","
@@ -285,7 +285,7 @@ public class ODataJsonSerializerTest {
final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
- .build()));
+ .build()).getContent());
final String expectedResult = "{\"@odata.context\":\"$metadata#ESMixPrimCollComp/$entity\","
+ "\"PropertyInt16\":32767,"
+ "\"CollPropertyString\":null,\"PropertyComp\":null,\"CollPropertyComp\":null}";
@@ -297,7 +297,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA)
- .entity(metadata, edmEntitySet.getEntityType(), entity, null);
+ .entity(metadata, edmEntitySet.getEntityType(), entity, null).getContent();
final String resultString = IOUtils.toString(result);
final String expectedResult = "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}";
Assert.assertEquals(expectedResult, resultString);
@@ -310,7 +310,7 @@ public class ODataJsonSerializerTest {
InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA)
.entityCollection(metadata, edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
- .contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build());
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build()).getContent();
final String resultString = IOUtils.toString(result);
final String expectedResult = "{\"value\":["
+ "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"},"
@@ -329,7 +329,7 @@ public class ODataJsonSerializerTest {
entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
- .build()));
+ .build()).getContent());
final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia/$entity\","
+ "\"@odata.mediaEtag\":\"theMediaETag\",\"@odata.mediaContentType\":\"image/svg+xml\","
+ "\"PropertyInt16\":1}";
@@ -343,7 +343,7 @@ public class ODataJsonSerializerTest {
final String resultString = IOUtils.toString(serializer.entityCollection(metadata,
edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
- .contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build()));
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build()).getContent());
final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia\",\"value\":["
+ "{\"@odata.mediaContentType\":\"image/svg+xml\",\"PropertyInt16\":1},"
+ "{\"@odata.mediaContentType\":\"image/svg+xml\",\"PropertyInt16\":2},"
@@ -368,7 +368,7 @@ public class ODataJsonSerializerTest {
.selectList(helper.buildContextURLSelectList(entityType, null, select))
.suffix(Suffix.ENTITY).build())
.select(select)
- .build());
+ .build()).getContent();
final String resultString = IOUtils.toString(result);
final String expectedResult = "{"
+ "\"@odata.context\":\"$metadata#ESAllPrim(PropertyBoolean,PropertyDate)/$entity\","
@@ -388,7 +388,7 @@ public class ODataJsonSerializerTest {
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.select(select)
- .build());
+ .build()).getContent();
final String resultString = IOUtils.toString(result);
final String expectedResult = "{\"@odata.context\":\"$metadata#ESTwoPrim/$entity\","
+ "\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}";
@@ -409,7 +409,7 @@ public class ODataJsonSerializerTest {
.selectList(helper.buildContextURLSelectList(entityType, null, select))
.build())
.select(select)
- .build());
+ .build()).getContent();
final String resultString = IOUtils.toString(result);
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESCompComp(PropertyComp/PropertyComp/PropertyString)\","
@@ -434,7 +434,7 @@ public class ODataJsonSerializerTest {
.selectList(helper.buildContextURLSelectList(entityType, null, select))
.build())
.select(select)
- .build()));
+ .build()).getContent());
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESCompComp(PropertyComp/PropertyComp)\","
+ "\"value\":["
@@ -453,7 +453,7 @@ public class ODataJsonSerializerTest {
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.expand(expand)
- .build());
+ .build()).getContent();
final String resultString = IOUtils.toString(result);
Assert.assertEquals("{\"@odata.context\":\"$metadata#ESTwoPrim/$entity\","
+ "\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\","
@@ -494,7 +494,7 @@ public class ODataJsonSerializerTest {
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
.suffix(Suffix.ENTITY).build())
.expand(expand)
- .build()));
+ .build()).getContent());
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESTwoPrim(NavPropertyETAllPrimOne(PropertyDate))/$entity\","
+ "\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\","
@@ -522,7 +522,7 @@ public class ODataJsonSerializerTest {
.suffix(Suffix.ENTITY).build())
.expand(expand)
.select(select)
- .build()));
+ .build()).getContent());
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESAllPrim(PropertySByte)/$entity\","
+ "\"PropertySByte\":127,"
@@ -549,7 +549,7 @@ public class ODataJsonSerializerTest {
.suffix(Suffix.ENTITY).build())
.expand(expand)
.select(select)
- .build()));
+ .build()).getContent());
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESAllPrim(PropertyTimeOfDay)/$entity\","
+ "\"PropertyTimeOfDay\":\"23:49:14\","
@@ -579,7 +579,7 @@ public class ODataJsonSerializerTest {
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
.suffix(Suffix.ENTITY).build())
.expand(expand)
- .build()));
+ .build()).getContent());
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESTwoPrim(NavPropertyETAllPrimMany(PropertyInt32))/$entity\","
+ "\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\","
@@ -604,7 +604,7 @@ public class ODataJsonSerializerTest {
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
.build())
- .build()));
+ .build()).getContent());
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESAllPrim(32767)/PropertyString\","
+ "\"value\":\"First Resource - positive values\"}",
@@ -636,7 +636,7 @@ public class ODataJsonSerializerTest {
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName())
.build())
- .build()));
+ .build()).getContent());
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESCollAllPrim(1)/CollPropertyString\","
+ "\"value\":[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"]}",
@@ -655,7 +655,7 @@ public class ODataJsonSerializerTest {
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
.build())
- .build()));
+ .build()).getContent());
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\","
+ "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"}",
@@ -674,7 +674,7 @@ public class ODataJsonSerializerTest {
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
.build())
- .build()));
+ .build()).getContent());
Assert.assertEquals("{"
+ "\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\","
+ "\"value\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
index de03327..08baea0 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
@@ -114,7 +114,7 @@ public class ServiceDocumentTest {
ODataSerializer serializer = server.createSerializer(ODataFormat.JSON);
assertNotNull(serializer);
- InputStream result = serializer.serviceDocument(edm, serviceRoot);
+ InputStream result = serializer.serviceDocument(edm, serviceRoot).getContent();
assertNotNull(result);
String jsonString = IOUtils.toString(result);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
index dce6589..df7dd79 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
@@ -48,7 +48,7 @@ public class MetadataDocumentTest {
new EdmTechProvider(references), references);
final String metadata = IOUtils.toString(
- odata.createSerializer(ODataFormat.XML).metadataDocument(serviceMetadata));
+ odata.createSerializer(ODataFormat.XML).metadataDocument(serviceMetadata).getContent());
assertNotNull(metadata);
assertThat(metadata,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/502f7ced/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
----------------------------------------------------------------------
diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
index 71b827d..90df224 100644
--- a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
+++ b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
@@ -113,7 +113,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
getContextUrl(edmEntitySet, false, expand, select, null))
.count(uriInfo.getCountOption())
.expand(expand).select(select)
- .build());
+ .build()).getContent();
// Finally we set the response data, headers and status code
response.setContent(serializedContent);
@@ -150,7 +150,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, true, expand, select, null))
.expand(expand).select(select)
- .build());
+ .build()).getContent();
response.setContent(serializedContent);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
@@ -259,7 +259,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
getContextUrl(edmEntitySet, true, null, null, edmProperty.getName());
InputStream serializerContent = complex ?
serializer.complex(edm, (EdmComplexType) edmProperty.getType(), property,
- ComplexSerializerOptions.with().contextURL(contextURL).build()) :
+ ComplexSerializerOptions.with().contextURL(contextURL).build()).getContent() :
serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
PrimitiveSerializerOptions.with()
.contextURL(contextURL)
@@ -267,7 +267,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
.nullable(edmProperty.isNullable())
.precision(edmProperty.getPrecision())
.maxLength(edmProperty.getMaxLength())
- .unicode(edmProperty.isUnicode()).build());
+ .unicode(edmProperty.isUnicode()).build()).getContent();
response.setContent(serializerContent);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, contentType.toContentTypeString());
[45/50] [abbrv] olingo-odata4 git commit: [OLINGO-603] TecSvc
enhancements
Posted by ch...@apache.org.
[OLINGO-603] TecSvc enhancements
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/61b0daa8
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/61b0daa8
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/61b0daa8
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 61b0daa856917fd4623701eb3e572bb73fdbf752
Parents: 2d445e2
Author: Christian Amend <ch...@apache.org>
Authored: Thu Apr 2 14:19:41 2015 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Apr 2 14:24:48 2015 +0200
----------------------------------------------------------------------
.../commons/AbstractPersistenceManager.java | 3 +-
.../olingo/ext/proxy/context/EntityUUID.java | 4 +-
.../commons/api/edm/EdmNavigationProperty.java | 4 +-
.../commons/api/edm/provider/EntitySet.java | 1 +
.../olingo/commons/api/http/HttpHeader.java | 7 +-
.../edm/provider/EdmNavigationPropertyImpl.java | 2 +-
.../xml/MetadataDocumentXmlSerializer.java | 34 +-
.../tecsvc/provider/ComplexTypeProvider.java | 30 +-
.../tecsvc/provider/FunctionProvider.java | 26 +-
.../tecsvc/provider/PropertyProvider.java | 921 ++++++++++---------
.../server/tecsvc/provider/SchemaProvider.java | 38 +-
.../serializer/xml/MetadataDocumentTest.java | 13 +-
.../core/uri/antlr/TestFullResourcePath.java | 4 +-
13 files changed, 565 insertions(+), 522 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
index 238686a..06c190a 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
@@ -540,7 +540,8 @@ abstract class AbstractPersistenceManager implements PersistenceManager {
private AttachedEntityStatus resolveNavigationLink(
final NavigationProperty property, final EntityInvocationHandler handler) {
if (handler.getUUID().getEntitySetURI() == null) {
- final Object key = CoreUtils.getKey(service.getClient(), handler, handler.getTypeRef(), handler.getEntity());
+ //Load key
+ CoreUtils.getKey(service.getClient(), handler, handler.getTypeRef(), handler.getEntity());
handler.updateUUID(CoreUtils.getTargetEntitySetURI(service.getClient(), property), handler.getTypeRef(), null);
service.getContext().entityContext().attach(handler, AttachedEntityStatus.NEW);
return AttachedEntityStatus.NEW;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java
index 1f6bdf0..b8e4fd7 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/context/EntityUUID.java
@@ -27,6 +27,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import java.io.Serializable;
import java.net.URI;
+
import org.apache.olingo.ext.proxy.api.EntityType;
public class EntityUUID implements Serializable {
@@ -38,8 +39,9 @@ public class EntityUUID implements Serializable {
private final Object key;
/**
- * Needed when representing a new entity, where key is potentially null.
+ * Needed when representing a new entity, where key is potentially null. The temp key is used via reflection
*/
+ @SuppressWarnings("unused")
private final int tempKey;
private Class<?> type;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
index ff0936c..445ef5f 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
@@ -36,9 +36,9 @@ public interface EdmNavigationProperty extends EdmElement, EdmAnnotationsTarget,
boolean isNullable();
/**
- * @return true if containsTarget or null if not specified
+ * @return true if containsTarget
*/
- Boolean containsTarget();
+ boolean containsTarget();
/**
* @return the partner navigation property
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EntitySet.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EntitySet.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EntitySet.java
index b6356f7..51d28db 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EntitySet.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EntitySet.java
@@ -26,6 +26,7 @@ public class EntitySet extends BindingTarget {
private static final long serialVersionUID = 5291570018480936643L;
+ //Default for EntitySets is true
private boolean includeInServiceDocument = true;
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java
index 23a396c..7fb6827 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java
@@ -162,11 +162,12 @@ public interface HttpHeader {
*/
public static final String ODATA_MAX_VERSION = "OData-MaxVersion";
+ // CHECKSTYLE:OFF
/**
* OData Prefer Header
- * See {@link <a href="http://docs.oasis-open.org/odata/odata/v4.0/errata01/os/complete/part1-protocol/
- * odata-v4.0-errata01-os-part1-protocol-complete.html#_Toc399426728">OData Version 4.0 Part 1:
- * Protocol Plus Errata 01</a>}
+ * See
+ * {@link <a href="http://docs.oasis-open.org/odata/odata/v4.0/errata01/os/complete/part1-protocol/odata-v4.0-errata01-os-part1-protocol-complete.html#_Toc399426728"> OData Version 4.0 Part 1: Protocol Plus Errata 01</a>}
*/
public static final String PREFER = "Prefer";
+ //CHECKSTYLE:ON
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
index 11b4cae..2dd6dce 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/provider/EdmNavigationPropertyImpl.java
@@ -59,7 +59,7 @@ public class EdmNavigationPropertyImpl extends AbstractEdmNamed implements EdmEl
}
@Override
- public Boolean containsTarget() {
+ public boolean containsTarget() {
return navigationProperty.isContainsTarget();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
index a2f54c7..14fe147 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
@@ -118,6 +118,7 @@ public class MetadataDocumentXmlSerializer {
private final static String NS_EDM = "http://docs.oasis-open.org/odata/ns/edm";
private static final String XML_ENTITY_SET_PATH = "EntitySetPath";
+ private static final String XML_CONTAINS_TARGET = "ContainsTarget";
private final ServiceMetadata serviceMetadata;
private final Map<String, String> namespaceToAlias = new HashMap<String, String>();
@@ -163,15 +164,15 @@ public class MetadataDocumentXmlSerializer {
// EnumTypes
appendEnumTypes(writer, schema.getEnumTypes());
+ // TypeDefinitions
+ appendTypeDefinitions(writer, schema.getTypeDefinitions());
+
// EntityTypes
appendEntityTypes(writer, schema.getEntityTypes());
// ComplexTypes
appendComplexTypes(writer, schema.getComplexTypes());
- // TypeDefinitions
- appendTypeDefinitions(writer, schema.getTypeDefinitions());
-
// Actions
appendActions(writer, schema.getActions());
@@ -227,8 +228,6 @@ public class MetadataDocumentXmlSerializer {
// EntitySets
appendEntitySets(writer, container.getEntitySets());
- // Singletons
- appendSingletons(writer, container.getSingletons());
// ActionImports
appendActionImports(writer, container.getActionImports());
@@ -242,6 +241,9 @@ public class MetadataDocumentXmlSerializer {
}
appendFunctionImports(writer, container.getFunctionImports(), containerNamespace);
+ // Singletons
+ appendSingletons(writer, container.getSingletons());
+
writer.writeEndElement();
}
}
@@ -265,8 +267,10 @@ public class MetadataDocumentXmlSerializer {
if (returnedEntitySet != null) {
writer.writeAttribute(XML_ENTITY_SET, containerNamespace + "." + returnedEntitySet.getName());
}
- writer.writeAttribute(XML_INCLUDE_IN_SERVICE_DOCUMENT, "" + functionImport.isIncludeInServiceDocument());
-
+ // Default is false and we do not write the default
+ if (functionImport.isIncludeInServiceDocument()) {
+ writer.writeAttribute(XML_INCLUDE_IN_SERVICE_DOCUMENT, "" + functionImport.isIncludeInServiceDocument());
+ }
writer.writeEndElement();
}
}
@@ -311,6 +315,9 @@ public class MetadataDocumentXmlSerializer {
writer.writeStartElement(XML_ENTITY_SET);
writer.writeAttribute(XML_NAME, entitySet.getName());
writer.writeAttribute(XML_ENTITY_TYPE, getAliasedFullQualifiedName(entitySet.getEntityType(), false));
+ if (!entitySet.isIncludeInServiceDocument()) {
+ writer.writeAttribute(XML_INCLUDE_IN_SERVICE_DOCUMENT, "" + entitySet.isIncludeInServiceDocument());
+ }
appendNavigationPropertyBindings(writer, entitySet);
writer.writeEndElement();
@@ -325,8 +332,13 @@ public class MetadataDocumentXmlSerializer {
if (function.getEntitySetPath() != null) {
writer.writeAttribute(XML_ENTITY_SET_PATH, function.getEntitySetPath());
}
- writer.writeAttribute(XML_IS_BOUND, "" + function.isBound());
- writer.writeAttribute(XML_IS_COMPOSABLE, "" + function.isComposable());
+ if (function.isBound()) {
+ writer.writeAttribute(XML_IS_BOUND, "" + function.isBound());
+ }
+
+ if (function.isComposable()) {
+ writer.writeAttribute(XML_IS_COMPOSABLE, "" + function.isComposable());
+ }
appendOperationParameters(writer, function);
@@ -492,6 +504,10 @@ public class MetadataDocumentXmlSerializer {
writer.writeAttribute(XML_PARTNER, partner.getName());
}
+ if (navigationProperty.containsTarget()) {
+ writer.writeAttribute(XML_CONTAINS_TARGET, "" + navigationProperty.containsTarget());
+ }
+
if (navigationProperty.getReferentialConstraints() != null) {
for (EdmReferentialConstraint constraint : navigationProperty.getReferentialConstraints()) {
writer.writeEmptyElement("ReferentialConstraint");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java
index 52761c5..b8b4895 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ComplexTypeProvider.java
@@ -67,11 +67,11 @@ public class ComplexTypeProvider {
.setProperties(
Arrays.asList(PropertyProvider.propertyString, PropertyProvider.propertyBinary,
PropertyProvider.propertyBoolean, PropertyProvider.propertyByte, PropertyProvider.propertyDate,
- PropertyProvider.propertyDateTimeOffset, PropertyProvider.propertyDecimal_Scale_Precision,
+ PropertyProvider.propertyDateTimeOffset_Precision, PropertyProvider.propertyDecimal_Scale_Precision,
PropertyProvider.propertySingle, PropertyProvider.propertyDouble, PropertyProvider.propertyDuration,
PropertyProvider.propertyGuid, PropertyProvider.propertyInt16, PropertyProvider.propertyInt32,
- PropertyProvider.propertyInt64, PropertyProvider.propertySByte, PropertyProvider.propertyTimeOfDay
- ));
+ PropertyProvider.propertyInt64, PropertyProvider.propertySByte,
+ PropertyProvider.propertyTimeOfDay_Precision));
} else if (complexTypeName.equals(nameCTCollAllPrim)) {
return new ComplexType()
.setName("CTCollAllPrim")
@@ -91,7 +91,7 @@ public class ComplexTypeProvider {
return new ComplexType()
.setName("CTTwoPrim")
.setProperties(Arrays.asList(PropertyProvider.propertyInt16_NotNullable,
- PropertyProvider.propertyString_NotNullable));
+ PropertyProvider.propertyString_NotNullable));
} else if (complexTypeName.equals(nameCTCompNav)) {
return new ComplexType()
@@ -149,17 +149,17 @@ public class ComplexTypeProvider {
.setName("NavPropertyETMediaMany")
.setType(EntityTypeProvider.nameETMedia).setCollection(true)
)));
-
- } else if(complexTypeName.equals(nameCTNavCont)) {
- return new ComplexType()
- .setName("CTNavCont")
- .setProperties(new ArrayList<Property>())
- .setNavigationProperties(Arrays.asList(
- PropertyProvider.collectionNavPropertyETKeyNavContMany_CT_ETKeyNav,
- PropertyProvider.navPropertyETKeyNavContOne_CT_ETeyNav,
- PropertyProvider.collectionNavPropertyETTwoKeyNavContMany_CT_ETKeyNav,
- PropertyProvider.navPropertyETTwoKeyNavContOne_CT_ETKeyNav));
-
+
+ } else if (complexTypeName.equals(nameCTNavCont)) {
+ return new ComplexType()
+ .setName("CTNavCont")
+ .setProperties(new ArrayList<Property>())
+ .setNavigationProperties(Arrays.asList(
+ PropertyProvider.collectionNavPropertyETKeyNavContMany_CT_ETKeyNav,
+ PropertyProvider.navPropertyETKeyNavContOne_CT_ETeyNav,
+ PropertyProvider.collectionNavPropertyETTwoKeyNavContMany_CT_ETKeyNav,
+ PropertyProvider.navPropertyETTwoKeyNavContOne_CT_ETKeyNav));
+
} else if (complexTypeName.equals(nameCTBasePrimCompNav)) {
return new ComplexType()
.setName("CTBasePrimCompNav")
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
index bcf0863..f641c2a 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
@@ -463,6 +463,7 @@ public class FunctionProvider {
.asList(
new Function()
.setName("BFCESTwoKeyNavRTESTwoKeyNav")
+ .setEntitySetPath("BindingParam/NavPropertyETTwoKeyNavMany")
.setBound(true)
.setParameters(
Arrays.asList(
@@ -496,19 +497,19 @@ public class FunctionProvider {
.setComposable(true)
.setReturnType(
new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav).setCollection(true)
- .setNullable(false)),
- new Function()
- .setName("BFCESTwoKeyNavRTESTwoKeyNav")
- .setBound(true)
- .setParameters(
- Arrays.asList(new Parameter().setName("BindingParam").setType(EntityTypeProvider.nameETKeyNav)
- .setCollection(true).setNullable(false),
- new Parameter().setName("ParameterString").setType(PropertyProvider.nameString)
- .setCollection(false).setNullable(false)))
- .setComposable(true)
- .setReturnType(
- new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav).setCollection(true)
.setNullable(false))
+// new Function()
+// .setName("BFCESTwoKeyNavRTESTwoKeyNav")
+// .setBound(true)
+// .setParameters(
+// Arrays.asList(new Parameter().setName("BindingParam").setType(EntityTypeProvider.nameETKeyNav)
+// .setCollection(true).setNullable(false),
+// new Parameter().setName("ParameterString").setType(PropertyProvider.nameString)
+// .setCollection(false).setNullable(false)))
+// .setComposable(true)
+// .setReturnType(
+// new ReturnType().setType(EntityTypeProvider.nameETTwoKeyNav).setCollection(true)
+// .setNullable(false))
);
} else if (functionName.equals(nameBFCStringRTESTwoKeyNav)) {
@@ -624,6 +625,7 @@ public class FunctionProvider {
return Arrays.asList(
new Function()
.setName("BFCETTwoKeyNavRTESTwoKeyNav")
+ .setEntitySetPath("BindingParam/NavPropertyETTwoKeyNavOne")
.setBound(true)
.setParameters(Arrays.asList(
new Parameter().setName("BindingParam").setType(EntityTypeProvider.nameETTwoKeyNav)
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
index 07fbd25..db19766 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
@@ -32,7 +32,7 @@ public class PropertyProvider {
public static final FullQualifiedName nameDate = EdmPrimitiveTypeKind.Date.getFullQualifiedName();
public static final FullQualifiedName nameDateTimeOffset =
- EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName();
+ EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName();
public static final FullQualifiedName nameDecimal = EdmPrimitiveTypeKind.Decimal.getFullQualifiedName();
public static final FullQualifiedName nameDouble = EdmPrimitiveTypeKind.Double.getFullQualifiedName();
@@ -51,723 +51,732 @@ public class PropertyProvider {
// Primitive Properties --------------------------------------------------------------------------------------------
public static final Property collPropertyBinary = new Property()
- .setName("CollPropertyBinary")
- .setType(nameBinary)
- .setCollection(true);
+ .setName("CollPropertyBinary")
+ .setType(nameBinary)
+ .setCollection(true);
public static final Property collPropertyBinary_ExplicitNullable = new Property()
- .setName("CollPropertyBinary")
- .setType(nameBinary)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyBinary")
+ .setType(nameBinary)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyBinary_NotNullable = new Property()
- .setName("CollPropertyBinary")
- .setType(nameBinary)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyBinary")
+ .setType(nameBinary)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyBoolean = new Property()
- .setName("CollPropertyBoolean")
- .setType(nameBoolean)
- .setCollection(true);
+ .setName("CollPropertyBoolean")
+ .setType(nameBoolean)
+ .setCollection(true);
public static final Property collPropertyBoolean_ExplicitNullable = new Property()
- .setName("CollPropertyBoolean")
- .setType(nameBoolean)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyBoolean")
+ .setType(nameBoolean)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyBoolean_NotNullable = new Property()
- .setName("CollPropertyBoolean")
- .setType(nameBoolean)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyBoolean")
+ .setType(nameBoolean)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyByte = new Property()
- .setName("CollPropertyByte")
- .setType(nameByte)
- .setCollection(true);
+ .setName("CollPropertyByte")
+ .setType(nameByte)
+ .setCollection(true);
public static final Property collPropertyByte_ExplicitNullable = new Property()
- .setName("CollPropertyByte")
- .setType(nameByte)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyByte")
+ .setType(nameByte)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyByte_NotNullable = new Property()
- .setName("CollPropertyByte")
- .setType(nameByte)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyByte")
+ .setType(nameByte)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyDate = new Property()
- .setName("CollPropertyDate")
- .setType(nameDate)
- .setCollection(true);
+ .setName("CollPropertyDate")
+ .setType(nameDate)
+ .setCollection(true);
public static final Property collPropertyDate_ExplicitNullable = new Property()
- .setName("CollPropertyDate")
- .setType(nameDate)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyDate")
+ .setType(nameDate)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyDate_NotNullable = new Property()
- .setName("CollPropertyDate")
- .setType(nameDate)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyDate")
+ .setType(nameDate)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyDateTimeOffset = new Property()
- .setName("CollPropertyDateTimeOffset")
- .setType(nameDateTimeOffset)
- .setCollection(true);
+ .setName("CollPropertyDateTimeOffset")
+ .setType(nameDateTimeOffset)
+ .setCollection(true);
public static final Property collPropertyDateTimeOffset_ExplicitNullable = new Property()
- .setName("CollPropertyDateTimeOffset")
- .setType(nameDateTimeOffset)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyDateTimeOffset")
+ .setType(nameDateTimeOffset)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyDateTimeOffset_NotNullable = new Property()
- .setName("CollPropertyDateTimeOffset")
- .setType(nameDateTimeOffset)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyDateTimeOffset")
+ .setType(nameDateTimeOffset)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyDecimal = new Property()
- .setName("CollPropertyDecimal")
- .setType(nameDecimal)
- .setCollection(true);
+ .setName("CollPropertyDecimal")
+ .setType(nameDecimal)
+ .setCollection(true);
public static final Property collPropertyDecimal_ExplicitNullable = new Property()
- .setName("CollPropertyDecimal")
- .setType(nameDecimal)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyDecimal")
+ .setType(nameDecimal)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyDecimal_NotNullable = new Property()
- .setName("CollPropertyDecimal")
- .setType(nameDecimal)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyDecimal")
+ .setType(nameDecimal)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyDouble = new Property()
- .setName("CollPropertyDouble")
- .setType(nameDouble)
- .setCollection(true);
+ .setName("CollPropertyDouble")
+ .setType(nameDouble)
+ .setCollection(true);
public static final Property collPropertyDouble_ExplicitNullable = new Property()
- .setName("CollPropertyDouble")
- .setType(nameDouble)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyDouble")
+ .setType(nameDouble)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyDouble_NotNullable = new Property()
- .setName("CollPropertyDouble")
- .setType(nameDouble)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyDouble")
+ .setType(nameDouble)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyDuration = new Property()
- .setName("CollPropertyDuration")
- .setType(nameDuration)
- .setCollection(true);
+ .setName("CollPropertyDuration")
+ .setType(nameDuration)
+ .setCollection(true);
public static final Property collPropertyDuration_ExplicitNullable = new Property()
- .setName("CollPropertyDuration")
- .setType(nameDuration)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyDuration")
+ .setType(nameDuration)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyDuration_NotNullable = new Property()
- .setName("CollPropertyDuration")
- .setType(nameDuration)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyDuration")
+ .setType(nameDuration)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyGuid = new Property()
- .setName("CollPropertyGuid")
- .setType(nameGuid)
- .setCollection(true);
+ .setName("CollPropertyGuid")
+ .setType(nameGuid)
+ .setCollection(true);
public static final Property collPropertyGuid_ExplicitNullable = new Property()
- .setName("CollPropertyGuid")
- .setType(nameGuid)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyGuid")
+ .setType(nameGuid)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyGuid_NotNullable = new Property()
- .setName("CollPropertyGuid")
- .setType(nameGuid)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyGuid")
+ .setType(nameGuid)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyInt16 = new Property()
- .setName("CollPropertyInt16")
- .setType(nameInt16)
- .setCollection(true);
+ .setName("CollPropertyInt16")
+ .setType(nameInt16)
+ .setCollection(true);
public static final Property collPropertyInt16_ExplicitNullable = new Property()
- .setName("CollPropertyInt16")
- .setType(nameInt16)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyInt16")
+ .setType(nameInt16)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyInt16_NotNullable = new Property()
- .setName("CollPropertyInt16")
- .setType(nameInt16)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyInt16")
+ .setType(nameInt16)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyInt32 = new Property()
- .setName("CollPropertyInt32")
- .setType(nameInt32)
- .setCollection(true);
+ .setName("CollPropertyInt32")
+ .setType(nameInt32)
+ .setCollection(true);
public static final Property collPropertyInt32_ExplicitNullable = new Property()
- .setName("CollPropertyInt32")
- .setType(nameInt32)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyInt32")
+ .setType(nameInt32)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyInt32_NotNullable = new Property()
- .setName("CollPropertyInt32")
- .setType(nameInt32)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyInt32")
+ .setType(nameInt32)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyInt64 = new Property()
- .setName("CollPropertyInt64")
- .setType(nameInt64)
- .setCollection(true);
+ .setName("CollPropertyInt64")
+ .setType(nameInt64)
+ .setCollection(true);
public static final Property collPropertyInt64_ExplicitNullable = new Property()
- .setName("CollPropertyInt64")
- .setType(nameInt64)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyInt64")
+ .setType(nameInt64)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyInt64_NotNullable = new Property()
- .setName("CollPropertyInt64")
- .setType(nameInt64)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyInt64")
+ .setType(nameInt64)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertySByte = new Property()
- .setName("CollPropertySByte")
- .setType(nameSByte)
- .setCollection(true);
+ .setName("CollPropertySByte")
+ .setType(nameSByte)
+ .setCollection(true);
public static final Property collPropertySByte_ExplicitNullable = new Property()
- .setName("CollPropertySByte")
- .setType(nameSByte)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertySByte")
+ .setType(nameSByte)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertySByte_NotNullable = new Property()
- .setName("CollPropertySByte")
- .setType(nameSByte)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertySByte")
+ .setType(nameSByte)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertySingle = new Property()
- .setName("CollPropertySingle")
- .setType(nameSingle)
- .setCollection(true);
+ .setName("CollPropertySingle")
+ .setType(nameSingle)
+ .setCollection(true);
public static final Property collPropertySingle_ExplicitNullable = new Property()
- .setName("CollPropertySingle")
- .setType(nameSingle)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertySingle")
+ .setType(nameSingle)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertySingle_NotNullable = new Property()
- .setName("CollPropertySingle")
- .setType(nameSingle)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertySingle")
+ .setType(nameSingle)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyString = new Property()
- .setName("CollPropertyString")
- .setType(nameString)
- .setCollection(true);
+ .setName("CollPropertyString")
+ .setType(nameString)
+ .setCollection(true);
public static final Property collPropertyString_ExplicitNullable = new Property()
- .setName("CollPropertyString")
- .setType(nameString)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyString")
+ .setType(nameString)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyString_NotNullable = new Property()
- .setName("CollPropertyString")
- .setType(nameString)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyString")
+ .setType(nameString)
+ .setNullable(false)
+ .setCollection(true);
public static final Property collPropertyTimeOfDay = new Property()
- .setName("CollPropertyTimeOfDay")
- .setType(nameTimeOfDay)
- .setCollection(true);
+ .setName("CollPropertyTimeOfDay")
+ .setType(nameTimeOfDay)
+ .setCollection(true);
public static final Property collPropertyTimeOfDay_ExplicitNullable = new Property()
- .setName("CollPropertyTimeOfDay")
- .setType(nameTimeOfDay)
- .setNullable(true)
- .setCollection(true);
+ .setName("CollPropertyTimeOfDay")
+ .setType(nameTimeOfDay)
+ .setNullable(true)
+ .setCollection(true);
public static final Property collPropertyTimeOfDay_NotNullable = new Property()
- .setName("CollPropertyTimeOfDay")
- .setType(nameTimeOfDay)
- .setNullable(false)
- .setCollection(true);
+ .setName("CollPropertyTimeOfDay")
+ .setType(nameTimeOfDay)
+ .setNullable(false)
+ .setCollection(true);
public static final Property propertyBinary = new Property()
- .setName("PropertyBinary")
- .setType(nameBinary);
+ .setName("PropertyBinary")
+ .setType(nameBinary);
public static final Property propertyBinary_NotNullable = new Property()
- .setName("PropertyBinary")
- .setType(nameBinary)
- .setNullable(false);
+ .setName("PropertyBinary")
+ .setType(nameBinary)
+ .setNullable(false);
public static final Property propertyBinary_ExplicitNullable = new Property()
- .setName("PropertyBinary")
- .setType(nameBinary)
- .setNullable(true);
+ .setName("PropertyBinary")
+ .setType(nameBinary)
+ .setNullable(true);
public static final Property propertyBoolean = new Property()
- .setName("PropertyBoolean")
- .setType(nameBoolean);
+ .setName("PropertyBoolean")
+ .setType(nameBoolean);
public static final Property propertyBoolean_NotNullable = new Property()
- .setName("PropertyBoolean")
- .setType(nameBoolean)
- .setNullable(false);
+ .setName("PropertyBoolean")
+ .setType(nameBoolean)
+ .setNullable(false);
public static final Property propertyBoolean_ExplicitNullable = new Property()
- .setName("PropertyBoolean")
- .setType(nameBoolean)
- .setNullable(true);
+ .setName("PropertyBoolean")
+ .setType(nameBoolean)
+ .setNullable(true);
public static final Property propertyByte = new Property()
- .setName("PropertyByte")
- .setType(nameByte);
+ .setName("PropertyByte")
+ .setType(nameByte);
public static final Property propertyByte_NotNullable = new Property()
- .setName("PropertyByte")
- .setType(nameByte)
- .setNullable(false);
+ .setName("PropertyByte")
+ .setType(nameByte)
+ .setNullable(false);
public static final Property propertyByte_ExplicitNullable = new Property()
- .setName("PropertyByte")
- .setType(nameByte)
- .setNullable(true);
+ .setName("PropertyByte")
+ .setType(nameByte)
+ .setNullable(true);
public static final Property propertyDate = new Property()
- .setName("PropertyDate")
- .setType(nameDate);
+ .setName("PropertyDate")
+ .setType(nameDate);
public static final Property propertyDate_NotNullable = new Property()
- .setName("PropertyDate")
- .setType(nameDate)
- .setNullable(false);
+ .setName("PropertyDate")
+ .setType(nameDate)
+ .setNullable(false);
public static final Property propertyDate_ExplicitNullable = new Property()
- .setName("PropertyDate")
- .setType(nameDate)
- .setNullable(true);
+ .setName("PropertyDate")
+ .setType(nameDate)
+ .setNullable(true);
public static final Property propertyDateTimeOffset = new Property()
- .setName("PropertyDateTimeOffset")
- .setPrecision(20)
- .setType(nameDateTimeOffset);
+ .setName("PropertyDateTimeOffset")
+ .setType(nameDateTimeOffset);
+
+ public static final Property propertyDateTimeOffset_Precision = new Property()
+ .setName("PropertyDateTimeOffset")
+ .setPrecision(12)
+ .setType(nameDateTimeOffset);
public static final Property propertyDateTimeOffset_NotNullable = new Property()
- .setName("PropertyDateTimeOffset")
- .setType(nameDateTimeOffset)
- .setNullable(false);
+ .setName("PropertyDateTimeOffset")
+ .setType(nameDateTimeOffset)
+ .setNullable(false);
public static final Property propertyDateTimeOffset_ExplicitNullable = new Property()
- .setName("PropertyDateTimeOffset")
- .setType(nameDateTimeOffset)
- .setNullable(true);
+ .setName("PropertyDateTimeOffset")
+ .setType(nameDateTimeOffset)
+ .setNullable(true);
public static final Property propertyDecimal_Scale_Precision = new Property()
- .setName("PropertyDecimal")
- .setScale(10)
- .setPrecision(11)
- .setType(nameDecimal);
-
+ .setName("PropertyDecimal")
+ .setScale(5)
+ .setPrecision(11)
+ .setType(nameDecimal);
+
public static final Property propertyDecimal_Scale = new Property()
- .setName("PropertyDecimal")
- .setScale(10)
- .setType(nameDecimal);
-
+ .setName("PropertyDecimal")
+ .setScale(10)
+ .setType(nameDecimal);
+
public static final Property propertyDecimal_NotNullable = new Property()
- .setName("PropertyDecimal")
- .setType(nameDecimal)
- .setNullable(false);
+ .setName("PropertyDecimal")
+ .setType(nameDecimal)
+ .setNullable(false);
public static final Property propertyDecimal_ExplicitNullable = new Property()
- .setName("PropertyDecimal")
- .setType(nameDecimal)
- .setNullable(true);
+ .setName("PropertyDecimal")
+ .setType(nameDecimal)
+ .setNullable(true);
public static final Property propertyDouble = new Property()
- .setName("PropertyDouble")
- .setType(nameDouble);
+ .setName("PropertyDouble")
+ .setType(nameDouble);
public static final Property propertyDouble_NotNullable = new Property()
- .setName("PropertyDouble")
- .setType(nameDouble)
- .setNullable(false);
+ .setName("PropertyDouble")
+ .setType(nameDouble)
+ .setNullable(false);
public static final Property propertyDouble_ExplicitNullable = new Property()
- .setName("PropertyDouble")
- .setType(nameDouble)
- .setNullable(true);
+ .setName("PropertyDouble")
+ .setType(nameDouble)
+ .setNullable(true);
public static final Property propertyDuration = new Property()
- .setName("PropertyDuration")
- .setType(nameDuration);
+ .setName("PropertyDuration")
+ .setType(nameDuration);
public static final Property propertyDuration_NotNullable = new Property()
- .setName("PropertyDuration")
- .setType(nameDuration)
- .setNullable(false);
+ .setName("PropertyDuration")
+ .setType(nameDuration)
+ .setNullable(false);
public static final Property propertyDuration_ExplicitNullable = new Property()
- .setName("PropertyDuration")
- .setType(nameDuration)
- .setNullable(true);
+ .setName("PropertyDuration")
+ .setType(nameDuration)
+ .setNullable(true);
public static final Property propertyGuid = new Property()
- .setName("PropertyGuid")
- .setType(nameGuid);
+ .setName("PropertyGuid")
+ .setType(nameGuid);
public static final Property propertyGuid_NotNullable = new Property()
- .setName("PropertyGuid")
- .setType(nameGuid)
- .setNullable(false);
+ .setName("PropertyGuid")
+ .setType(nameGuid)
+ .setNullable(false);
public static final Property propertyGuid_ExplicitNullable = new Property()
- .setName("PropertyGuid")
- .setType(nameGuid)
- .setNullable(true);
+ .setName("PropertyGuid")
+ .setType(nameGuid)
+ .setNullable(true);
public static final Property propertyInt16 = new Property()
- .setName("PropertyInt16")
- .setType(nameInt16);
+ .setName("PropertyInt16")
+ .setType(nameInt16);
public static final Property propertyInt16_NotNullable = new Property()
- .setName("PropertyInt16")
- .setType(nameInt16)
- .setNullable(false);
+ .setName("PropertyInt16")
+ .setType(nameInt16)
+ .setNullable(false);
public static final Property propertyInt16_ExplicitNullable = new Property()
- .setName("PropertyInt16")
- .setType(nameInt16)
- .setNullable(true);
+ .setName("PropertyInt16")
+ .setType(nameInt16)
+ .setNullable(true);
public static final Property propertyInt32 = new Property()
- .setName("PropertyInt32")
- .setType(nameInt32);
+ .setName("PropertyInt32")
+ .setType(nameInt32);
public static final Property propertyInt32_NotNullable = new Property()
- .setName("PropertyInt32")
- .setType(nameInt32)
- .setNullable(false);
+ .setName("PropertyInt32")
+ .setType(nameInt32)
+ .setNullable(false);
public static final Property propertyInt32_ExplicitNullable = new Property()
- .setName("PropertyInt32")
- .setType(nameInt32)
- .setNullable(true);
+ .setName("PropertyInt32")
+ .setType(nameInt32)
+ .setNullable(true);
public static final Property propertyInt64 = new Property()
- .setName("PropertyInt64")
- .setType(nameInt64);
+ .setName("PropertyInt64")
+ .setType(nameInt64);
public static final Property propertyInt64_NotNullable = new Property()
- .setName("PropertyInt64")
- .setType(nameInt64)
- .setNullable(false);
+ .setName("PropertyInt64")
+ .setType(nameInt64)
+ .setNullable(false);
public static final Property propertyInt64_ExplicitNullable = new Property()
- .setName("PropertyInt64")
- .setType(nameInt64)
- .setNullable(true);
+ .setName("PropertyInt64")
+ .setType(nameInt64)
+ .setNullable(true);
public static final Property propertySByte = new Property()
- .setName("PropertySByte")
- .setType(nameSByte);
+ .setName("PropertySByte")
+ .setType(nameSByte);
public static final Property propertySByte_NotNullable = new Property()
- .setName("PropertySByte")
- .setType(nameSByte)
- .setNullable(false);
+ .setName("PropertySByte")
+ .setType(nameSByte)
+ .setNullable(false);
public static final Property propertySByte_ExplicitNullable = new Property()
- .setName("PropertySByte")
- .setType(nameSByte)
- .setNullable(true);
+ .setName("PropertySByte")
+ .setType(nameSByte)
+ .setNullable(true);
public static final Property propertySingle = new Property()
- .setName("PropertySingle")
- .setType(nameSingle);
+ .setName("PropertySingle")
+ .setType(nameSingle);
public static final Property propertySingle_NotNullable = new Property()
- .setName("PropertySingle")
- .setType(nameSingle)
- .setNullable(false);
+ .setName("PropertySingle")
+ .setType(nameSingle)
+ .setNullable(false);
public static final Property propertySingle_ExplicitNullable = new Property()
- .setName("PropertySingle")
- .setType(nameSingle)
- .setNullable(true);
+ .setName("PropertySingle")
+ .setType(nameSingle)
+ .setNullable(true);
public static final Property propertyString = new Property()
- .setName("PropertyString")
- .setType(nameString);
+ .setName("PropertyString")
+ .setType(nameString);
public static final Property propertyString_NotNullable = new Property()
- .setName("PropertyString")
- .setType(nameString)
- .setNullable(false);
+ .setName("PropertyString")
+ .setType(nameString)
+ .setNullable(false);
public static final Property propertyString_ExplicitNullable = new Property()
- .setName("PropertyString")
- .setType(nameString)
- .setNullable(true);
+ .setName("PropertyString")
+ .setType(nameString)
+ .setNullable(true);
public static final Property propertyTimeOfDay = new Property()
- .setName("PropertyTimeOfDay")
- .setPrecision(10)
- .setType(nameTimeOfDay);
+ .setName("PropertyTimeOfDay")
+ .setType(nameTimeOfDay);
+
+ public static final Property propertyTimeOfDay_Precision = new Property()
+ .setName("PropertyTimeOfDay")
+ .setPrecision(12)
+ .setType(nameTimeOfDay);
public static final Property propertyTimeOfDay_NotNullable = new Property()
- .setName("PropertyTimeOfDay")
- .setType(nameTimeOfDay)
- .setNullable(false);
+ .setName("PropertyTimeOfDay")
+ .setType(nameTimeOfDay)
+ .setNullable(false);
public static final Property propertyTimeOfDay_ExplicitNullable = new Property()
- .setName("PropertyTimeOfDay")
- .setType(nameTimeOfDay)
- .setNullable(true);
+ .setName("PropertyTimeOfDay")
+ .setType(nameTimeOfDay)
+ .setNullable(true);
// Complex Properties ----------------------------------------------------------------------------------------------
public static final Property collPropertyComp_CTPrimComp = new Property()
- .setName("CollPropertyComp")
- .setType(ComplexTypeProvider.nameCTPrimComp)
- .setCollection(true);
+ .setName("CollPropertyComp")
+ .setType(ComplexTypeProvider.nameCTPrimComp)
+ .setCollection(true);
public static final Property collPropertyComp_CTTwoPrim = new Property()
- .setName("CollPropertyComp")
- .setType(ComplexTypeProvider.nameCTTwoPrim)
- .setCollection(true);
+ .setName("CollPropertyComp")
+ .setType(ComplexTypeProvider.nameCTTwoPrim)
+ .setCollection(true);
public static final Property propertyComp_CTAllPrim = new Property()
- .setName("PropertyComp")
- .setType(ComplexTypeProvider.nameCTAllPrim);
+ .setName("PropertyComp")
+ .setType(ComplexTypeProvider.nameCTAllPrim);
public static final Property propertyComp_CTCollAllPrim = new Property()
- .setName("PropertyComp")
- .setType(ComplexTypeProvider.nameCTCollAllPrim);
+ .setName("PropertyComp")
+ .setType(ComplexTypeProvider.nameCTCollAllPrim);
public static final Property propertyComp_CTCompCollComp = new Property()
- .setName("PropertyComp")
- .setType(ComplexTypeProvider.nameCTCompCollComp);
+ .setName("PropertyComp")
+ .setType(ComplexTypeProvider.nameCTCompCollComp);
public static final Property propertyComp_CTCompComp = new Property()
- .setName("PropertyComp")
- .setType(ComplexTypeProvider.nameCTCompComp);
+ .setName("PropertyComp")
+ .setType(ComplexTypeProvider.nameCTCompComp);
public static final Property propertyComp_CTNavFiveProp = new Property()
- .setName("PropertyComp")
- .setType(ComplexTypeProvider.nameCTNavFiveProp);
-
+ .setName("PropertyComp")
+ .setType(ComplexTypeProvider.nameCTNavFiveProp);
+
public static final Property propertyCompNav_CTNavFiveProp = new Property()
- .setName("PropertyCompNav")
- .setType(ComplexTypeProvider.nameCTNavFiveProp);
-
+ .setName("PropertyCompNav")
+ .setType(ComplexTypeProvider.nameCTNavFiveProp);
+
public static final Property propertyComp_CTPrimComp_NotNullable = new Property()
- .setName("PropertyComp")
- .setType(ComplexTypeProvider.nameCTPrimComp)
- .setNullable(false);
+ .setName("PropertyComp")
+ .setType(ComplexTypeProvider.nameCTPrimComp)
+ .setNullable(false);
public static final Property propertyComp_CTTwoPrim = new Property()
- .setName("PropertyComp")
- .setType(ComplexTypeProvider.nameCTTwoPrim);
+ .setName("PropertyComp")
+ .setType(ComplexTypeProvider.nameCTTwoPrim);
public static final Property propertyComp_CTTwoPrim_NotNullable = new Property()
- .setName("PropertyComp")
- .setType(ComplexTypeProvider.nameCTTwoPrim)
- .setNullable(false);
-
- public static final Property propertyCompNavCont = new Property()
- .setName("PropertyCompNavCont")
- .setType(ComplexTypeProvider.nameCTNavCont);
-
+ .setName("PropertyComp")
+ .setType(ComplexTypeProvider.nameCTTwoPrim)
+ .setNullable(false);
+
+ public static final Property propertyCompNavCont = new Property()
+ .setName("PropertyCompNavCont")
+ .setType(ComplexTypeProvider.nameCTNavCont);
+
public static final Property propertyCompAllPrim_CTAllPrim = new Property()
- .setName("PropertyCompAllPrim")
- .setType(ComplexTypeProvider.nameCTAllPrim);
+ .setName("PropertyCompAllPrim")
+ .setType(ComplexTypeProvider.nameCTAllPrim);
public static final Property propertyCompComp_CTCompComp = new Property()
- .setName("PropertyCompComp")
- .setType(ComplexTypeProvider.nameCTCompComp);
+ .setName("PropertyCompComp")
+ .setType(ComplexTypeProvider.nameCTCompComp);
public static final Property propertyCompComp_CTCompComp_NotNullable = new Property()
- .setName("PropertyCompComp")
- .setType(ComplexTypeProvider.nameCTCompComp)
- .setNullable(false);
-
+ .setName("PropertyCompComp")
+ .setType(ComplexTypeProvider.nameCTCompComp)
+ .setNullable(false);
+
public static final Property propertyCompTwoPrim_CTTwoPrim = new Property()
- .setName("PropertyCompTwoPrim")
- .setType(ComplexTypeProvider.nameCTTwoPrim);
+ .setName("PropertyCompTwoPrim")
+ .setType(ComplexTypeProvider.nameCTTwoPrim);
public static final Property propertyMixedPrimCollComp_CTMixPrimCollComp = new Property()
- .setName("PropertyMixedPrimCollComp")
- .setType(ComplexTypeProvider.nameCTMixPrimCollComp);
+ .setName("PropertyMixedPrimCollComp")
+ .setType(ComplexTypeProvider.nameCTMixPrimCollComp);
public static final Property propertyComp_CTMixEnumTypeDefColl = new Property()
- .setName("PropertyCompMixedEnumDef")
- .setType(ComplexTypeProvider.nameCTMixEnumDef);
+ .setName("PropertyCompMixedEnumDef")
+ .setType(ComplexTypeProvider.nameCTMixEnumDef);
public static final Property propertyCompColl_CTMixEnumTypeDefColl = new Property()
- .setName("CollPropertyCompMixedEnumDef")
- .setType(ComplexTypeProvider.nameCTMixEnumDef)
- .setCollection(true);
+ .setName("CollPropertyCompMixedEnumDef")
+ .setType(ComplexTypeProvider.nameCTMixEnumDef)
+ .setCollection(true);
// Navigation Properties -------------------------------------------------------------------------------------------
public static final NavigationProperty collectionNavPropertyETKeyNavMany_ETKeyNav = new NavigationProperty()
- .setName("NavPropertyETKeyNavMany")
- .setType(EntityTypeProvider.nameETKeyNav)
- .setCollection(true);
+ .setName("NavPropertyETKeyNavMany")
+ .setType(EntityTypeProvider.nameETKeyNav)
+ .setCollection(true);
public static final NavigationProperty collectionNavPropertyETMediaMany_ETMedia = new NavigationProperty()
- .setName("NavPropertyETMediaMany")
- .setType(EntityTypeProvider.nameETMedia)
- .setCollection(true);
-
- public static final NavigationProperty collectionNavPropertyETTwoKeyNavMany_ETTwoKeyNav_WithPartnerERKeyNavOne
- = new NavigationProperty()
- .setName("NavPropertyETTwoKeyNavMany")
- .setType(EntityTypeProvider.nameETTwoKeyNav)
- .setCollection(true)
- .setPartner("NavPropertyETKeyNavOne");
-
+ .setName("NavPropertyETMediaMany")
+ .setType(EntityTypeProvider.nameETMedia)
+ .setCollection(true);
+
+ public static final NavigationProperty collectionNavPropertyETTwoKeyNavMany_ETTwoKeyNav_WithPartnerERKeyNavOne =
+ new NavigationProperty()
+ .setName("NavPropertyETTwoKeyNavMany")
+ .setType(EntityTypeProvider.nameETTwoKeyNav)
+ .setCollection(true)
+ .setPartner("NavPropertyETKeyNavOne");
+
public static final NavigationProperty collectionNavPropertyETTwoKeyNavMany_ETTwoKeyNav = new NavigationProperty()
- .setName("NavPropertyETTwoKeyNavMany")
- .setType(EntityTypeProvider.nameETTwoKeyNav)
- .setCollection(true);
-
+ .setName("NavPropertyETTwoKeyNavMany")
+ .setType(EntityTypeProvider.nameETTwoKeyNav)
+ .setCollection(true);
+
public static final NavigationProperty collectionNavPropertyETTwoKeyNavOne_ETTwoKeyNav = new NavigationProperty()
- .setName("NavPropertyETTwoKeyNavOne")
- .setType(EntityTypeProvider.nameETTwoKeyNav);
+ .setName("NavPropertyETTwoKeyNavOne")
+ .setType(EntityTypeProvider.nameETTwoKeyNav);
public static final NavigationProperty collectionNavPropertyETTwoPrimMany_ETTwoPrim = new NavigationProperty()
- .setName("NavPropertyETTwoPrimMany")
- .setType(EntityTypeProvider.nameETTwoPrim)
- .setCollection(true);
+ .setName("NavPropertyETTwoPrimMany")
+ .setType(EntityTypeProvider.nameETTwoPrim)
+ .setCollection(true);
public static final NavigationProperty collectionNavPropertyETAllPrimMany_ETAllPrim = new NavigationProperty()
- .setName("NavPropertyETAllPrimMany")
- .setType(EntityTypeProvider.nameETAllPrim)
- .setCollection(true);
+ .setName("NavPropertyETAllPrimMany")
+ .setType(EntityTypeProvider.nameETAllPrim)
+ .setCollection(true);
public static final NavigationProperty collectionNavPropertySINav = new NavigationProperty()
- .setName("NavPropertySINav")
- .setCollection(true)
- .setType(EntityTypeProvider.nameETTwoKeyNav);
-
+ .setName("NavPropertySINav")
+ .setCollection(true)
+ .setType(EntityTypeProvider.nameETTwoKeyNav);
+
public static final NavigationProperty collectionNavPropertyETKeyNavContMany_CT_ETKeyNav = new NavigationProperty()
- .setName("NavPropertyETKeyNavContMany")
- .setCollection(true)
- .setContainsTarget(true)
- .setType(EntityTypeProvider.nameETKeyNav);
-
- public static final NavigationProperty collectionNavPropertyETTwoKeyNavContMany_CT_ETKeyNav = new NavigationProperty()
- .setName("NavPropertyETTwoKeyNavContMany")
- .setCollection(true)
- .setContainsTarget(true)
- .setType(EntityTypeProvider.nameETKeyNav);
-
- public static final NavigationProperty navPropertyETKeyNavOne_ETKeyNav = new NavigationProperty()
- .setName("NavPropertyETKeyNavOne")
+ .setName("NavPropertyETKeyNavContMany")
+ .setCollection(true)
+ .setContainsTarget(true)
+ .setType(EntityTypeProvider.nameETKeyNav);
+
+ public static final NavigationProperty collectionNavPropertyETTwoKeyNavContMany_CT_ETKeyNav =
+ new NavigationProperty()
+ .setName("NavPropertyETTwoKeyNavContMany")
+ .setCollection(true)
+ .setContainsTarget(true)
.setType(EntityTypeProvider.nameETKeyNav);
+ public static final NavigationProperty navPropertyETKeyNavOne_ETKeyNav = new NavigationProperty()
+ .setName("NavPropertyETKeyNavOne")
+ .setType(EntityTypeProvider.nameETKeyNav);
+
public static final NavigationProperty navPropertyETMediaOne_ETMedia = new NavigationProperty()
- .setName("NavPropertyETMediaOne")
- .setType(EntityTypeProvider.nameETMedia);
+ .setName("NavPropertyETMediaOne")
+ .setType(EntityTypeProvider.nameETMedia);
public static final NavigationProperty navPropertyETKeyPrimNavOne_ETKeyPrimNav = new NavigationProperty()
- .setName("NavPropertyETKeyPrimNavOne")
- .setType(EntityTypeProvider.nameETKeyPrimNav);
+ .setName("NavPropertyETKeyPrimNavOne")
+ .setType(EntityTypeProvider.nameETKeyPrimNav);
public static final NavigationProperty navPropertyETTwoKeyNavOne_ETTwoKeyNav_NotNullable = new NavigationProperty()
- .setName("NavPropertyETTwoKeyNavOne")
- .setType(EntityTypeProvider.nameETTwoKeyNav)
- .setNullable(false);
+ .setName("NavPropertyETTwoKeyNavOne")
+ .setType(EntityTypeProvider.nameETTwoKeyNav)
+ .setNullable(false);
public static final NavigationProperty navPropertyETTwoKeyNavOne_ETTwoKeyNav = new NavigationProperty()
- .setName("NavPropertyETTwoKeyNavOne")
- .setType(EntityTypeProvider.nameETTwoKeyNav);
+ .setName("NavPropertyETTwoKeyNavOne")
+ .setType(EntityTypeProvider.nameETTwoKeyNav);
public static final NavigationProperty navPropertyETTwoPrimOne_ETTwoPrim = new NavigationProperty()
- .setName("NavPropertyETTwoPrimOne")
- .setType(EntityTypeProvider.nameETTwoPrim)
- .setNullable(false);
+ .setName("NavPropertyETTwoPrimOne")
+ .setType(EntityTypeProvider.nameETTwoPrim)
+ .setNullable(false);
public static final NavigationProperty navPropertyETAllPrimOne_ETAllPrim = new NavigationProperty()
- .setName("NavPropertyETAllPrimOne")
- .setType(EntityTypeProvider.nameETAllPrim);
+ .setName("NavPropertyETAllPrimOne")
+ .setType(EntityTypeProvider.nameETAllPrim);
public static final NavigationProperty navPropertyETKeyNavContOne_CT_ETeyNav = new NavigationProperty()
- .setName("NavPropertyETKeyNavContOne")
- .setContainsTarget(true)
- .setType(EntityTypeProvider.nameETKeyNav);
-
+ .setName("NavPropertyETKeyNavContOne")
+ .setContainsTarget(true)
+ .setType(EntityTypeProvider.nameETKeyNav);
+
public static final NavigationProperty navPropertyETTwoKeyNavContOne_CT_ETKeyNav = new NavigationProperty()
- .setName("NavPropertyETTwoKeyNavContOne")
- .setContainsTarget(true)
- .setType(EntityTypeProvider.nameETKeyNav);
-
+ .setName("NavPropertyETTwoKeyNavContOne")
+ .setContainsTarget(true)
+ .setType(EntityTypeProvider.nameETKeyNav);
+
public static final NavigationProperty navPropertyETTwoKeyNavContOneCT_ETTwoKeyNav = new NavigationProperty()
- .setName("NavPropertyETTwoKeyNavContOne")
- .setContainsTarget(true)
- .setType(EntityTypeProvider.nameETTwoKeyNav);
-
- public static final NavigationProperty collectionNavPropertyETTwoKeyNavContMany_CT_ETTwoKeyNav
- = new NavigationProperty()
- .setName("NavPropertyETTwoKeyNavContMany")
- .setContainsTarget(true)
- .setCollection(true)
- .setType(EntityTypeProvider.nameETTwoKeyNav);
-
+ .setName("NavPropertyETTwoKeyNavContOne")
+ .setContainsTarget(true)
+ .setType(EntityTypeProvider.nameETTwoKeyNav);
+
+ public static final NavigationProperty collectionNavPropertyETTwoKeyNavContMany_CT_ETTwoKeyNav =
+ new NavigationProperty()
+ .setName("NavPropertyETTwoKeyNavContMany")
+ .setContainsTarget(true)
+ .setCollection(true)
+ .setType(EntityTypeProvider.nameETTwoKeyNav);
+
// EnumProperties --------------------------------------------------------------------------------------------------
public static final Property propertyEnumString_ENString = new Property()
- .setName("PropertyEnumString")
- .setType(EnumTypeProvider.nameENString)
- .setNullable(false);
-
+ .setName("PropertyEnumString")
+ .setType(EnumTypeProvider.nameENString)
+ .setNullable(false);
+
public static final Property propertyEnumString_ENString_Nullable = new Property()
- .setName("PropertyEnumString")
- .setType(EnumTypeProvider.nameENString);
+ .setName("PropertyEnumString")
+ .setType(EnumTypeProvider.nameENString);
public static final Property collPropertyEnumString_ENString = new Property()
- .setName("CollPropertyEnumString")
- .setType(EnumTypeProvider.nameENString)
- .setCollection(true);
+ .setName("CollPropertyEnumString")
+ .setType(EnumTypeProvider.nameENString)
+ .setCollection(true);
// TypeDefinition Properties ---------------------------------------------------------------------------------------
public static final Property propertyTypeDefinition_TDString = new Property()
- .setName("PropertyDefString")
- .setType(TypeDefinitionProvider.nameTDString)
- .setMaxLength(15);
+ .setName("PropertyDefString")
+ .setType(TypeDefinitionProvider.nameTDString)
+ .setMaxLength(15);
public static final Property collPropertyTypeDefinition_TDString = new Property()
- .setName("CollPropertyDefString")
- .setType(TypeDefinitionProvider.nameTDString)
- .setMaxLength(15)
- .setCollection(true);
+ .setName("CollPropertyDefString")
+ .setType(TypeDefinitionProvider.nameTDString)
+ .setMaxLength(15)
+ .setCollection(true);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
index b8e5ad3..33f98a6 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
@@ -46,10 +46,17 @@ public class SchemaProvider {
schema.setNamespace(NAMESPACE);
schema.setAlias("Namespace1_Alias");
schemas.add(schema);
+
// EnumTypes
List<EnumType> enumTypes = new ArrayList<EnumType>();
schema.setEnumTypes(enumTypes);
+
+ // TypeDefinitions
+ List<TypeDefinition> typeDefinitions = new ArrayList<TypeDefinition>();
+ schema.setTypeDefinitions(typeDefinitions);
+ typeDefinitions.add(prov.getTypeDefinition(TypeDefinitionProvider.nameTDString));
enumTypes.add(prov.getEnumType(EnumTypeProvider.nameENString));
+
// EntityTypes
List<EntityType> entityTypes = new ArrayList<EntityType>();
schema.setEntityTypes(entityTypes);
@@ -59,6 +66,7 @@ public class SchemaProvider {
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETTwoPrim));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETMixPrimCollComp));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETTwoKeyTwoPrim));
+ entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETMixEnumDefCollComp));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETBase));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETTwoBase));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETAllKey));
@@ -74,12 +82,12 @@ public class SchemaProvider {
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETTwoKeyNav));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETTwoBaseTwoKeyNav));
+ entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETKeyNavCont));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETCompMixPrimCollComp));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETKeyPrimNav));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETAbstract));
entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETAbstractBase));
- entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETMixEnumDefCollComp));
- entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETKeyNavCont));
+
// ComplexTypes
List<ComplexType> complexType = new ArrayList<ComplexType>();
@@ -89,6 +97,7 @@ public class SchemaProvider {
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTCollAllPrim));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoPrim));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTMixPrimCollComp));
+ complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTMixEnumDef));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTBase));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoBase));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTCompComp));
@@ -98,24 +107,20 @@ public class SchemaProvider {
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTBasePrimCompNav));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoBasePrimCompNav));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTCompNav));
- complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTMixEnumDef));
complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTNavCont));
- // TypeDefinitions
- List<TypeDefinition> typeDefinitions = new ArrayList<TypeDefinition>();
- schema.setTypeDefinitions(typeDefinitions);
- typeDefinitions.add(prov.getTypeDefinition(TypeDefinitionProvider.nameTDString));
// Actions
List<Action> actions = new ArrayList<Action>();
schema.setActions(actions);
- actions.addAll(prov.getActions(ActionProvider.nameBAETAllPrimRT));
actions.addAll(prov.getActions(ActionProvider.nameBAETTwoKeyNavRTETTwoKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAESAllPrimRTETAllPrim));
- actions.addAll(prov.getActions(ActionProvider.nameBAESTwoKeyNavRTESKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAESTwoKeyNavRTESTwoKeyNav));
+ actions.addAll(prov.getActions(ActionProvider.nameBAESTwoKeyNavRTESKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAETBaseTwoKeyNavRTETBaseTwoKeyNav));
actions.addAll(prov.getActions(ActionProvider.nameBAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav));
+ actions.addAll(prov.getActions(ActionProvider.nameBAETAllPrimRT));
+ actions.addAll(prov.getActions(ActionProvider.nameBAESAllPrimRT));
actions.addAll(prov.getActions(ActionProvider.nameUARTString));
actions.addAll(prov.getActions(ActionProvider.nameUARTCollStringTwoParam));
actions.addAll(prov.getActions(ActionProvider.nameUARTCTTwoPrimParam));
@@ -135,7 +140,6 @@ public class SchemaProvider {
functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTInt16));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNav));
- functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETKeyNavContParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNavParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETTwoKeyNavParamCTTwoPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTStringTwoParam));
@@ -150,10 +154,12 @@ public class SchemaProvider {
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollCTTwoPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETMedia));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETMedia));
- functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETMixPrimCollCompTwoParam));
+ functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTCollETMixPrimCollCompTwoParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTETAllPrimTwoParam));
- functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTESMixPrimCollCompTwoParam));
+ functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETMixPrimCollCompTwoParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTCollCTNavFiveProp));
+ functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETKeyNavContParam));
+
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTESTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCStringRTESTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCETBaseTwoKeyNavRTETTwoKeyNav));
@@ -173,19 +179,19 @@ public class SchemaProvider {
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCCollCTPrimCompRTESAllPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESKeyNavRTETKeyNav));
- functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESKeyNavRTESTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCETKeyNavRTETKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFESTwoKeyNavRTESTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCETTwoKeyNavRTETTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCETTwoKeyNavRTCTTwoPrim));
-
+ //functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTESMixPrimCollCompTwoParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTCTNavFiveProp));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTCollCTNavFiveProp));
-
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTStringParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESKeyNavRTETKeyNavParam));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCCTPrimCompRTETTwoKeyNavParam));
- functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTCollETMixPrimCollCompTwoParam));
+ functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESKeyNavRTESTwoKeyNav));
+
+
// functions.addAll(prov.getFunctions(FunctionProvider.nameBFCCTPrimCompRTESTwoKeyNavParam));
// EntityContainer
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
index f673787..dce6589 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
@@ -89,7 +89,7 @@ public class MetadataDocumentTest {
assertThat(metadata, containsString("<Action Name=\"UARTCTTwoPrimParam\" IsBound=\"false\">"
+ "<Parameter Name=\"ParameterInt16\" Type=\"Edm.Int16\" Nullable=\"false\"/>"
+ "<ReturnType Type=\"Namespace1_Alias.CTTwoPrim\" Nullable=\"false\"/></Action>"));
-
+
assertThat(metadata,
containsString("<Action Name=\"BAESAllPrimRTETAllPrim\" IsBound=\"true\">"
+ "<Parameter Name=\"ParameterESAllPrim\" "
@@ -97,11 +97,12 @@ public class MetadataDocumentTest {
+ "<ReturnType Type=\"Namespace1_Alias.ETAllPrim\"/></Action>"));
assertThat(metadata,
- containsString("<Function Name=\"UFNRTInt16\" IsBound=\"false\" IsComposable=\"false\">"
+ containsString("<Function Name=\"UFNRTInt16\">"
+ "<ReturnType Type=\"Edm.Int16\"/></Function>"));
assertThat(metadata,
- containsString("<Function Name=\"BFCESTwoKeyNavRTESTwoKeyNav\" IsBound=\"true\" IsComposable=\"true\">"
+ containsString("<Function Name=\"BFCESTwoKeyNavRTESTwoKeyNav\" "
+ + "EntitySetPath=\"BindingParam/NavPropertyETTwoKeyNavMany\" IsBound=\"true\" IsComposable=\"true\">"
+ "<Parameter Name=\"BindingParam\" Type=\"Collection(Namespace1_Alias.ETTwoKeyNav)\" "
+ "Nullable=\"false\"/>"
+ "<ReturnType Type=\"Collection(Namespace1_Alias.ETTwoKeyNav)\" Nullable=\"false\"/></Function>"));
@@ -122,7 +123,11 @@ public class MetadataDocumentTest {
containsString("<ActionImport Name=\"AIRTCTTwoPrimParam\" Action=\"Namespace1_Alias.UARTCTTwoPrimParam\"/>"));
assertThat(metadata,
- containsString("<FunctionImport Name=\"FINInvisible2RTInt16\" Function=\"Namespace1_Alias.UFNRTInt16\" "
+ containsString("<FunctionImport Name=\"FINInvisible2RTInt16\" Function=\"Namespace1_Alias.UFNRTInt16\"/>"));
+
+ assertThat(
+ metadata,
+ containsString("<EntitySet Name=\"ESInvisible\" EntityType=\"Namespace1_Alias.ETAllPrim\" "
+ "IncludeInServiceDocument=\"false\"/>"));
assertThat(metadata, containsString("</EntityContainer></Schema></edmx:DataServices></edmx:Edmx>"));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/61b0daa8/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 863b800..416346c 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -585,10 +585,10 @@ public class TestFullResourcePath {
.isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
.isType(EntityTypeProvider.nameETTwoKeyNav);
- testUri.run("ESKeyNav/olingo.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='3')")
+ testUri.run("ESTwoKeyNav/olingo.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='3')")
.isKind(UriInfoKind.resource).goPath()
.first()
- .isEntitySet("ESKeyNav")
+ .isEntitySet("ESTwoKeyNav")
.n()
.isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
.isParameter(0, "ParameterString", "'3'")
[24/50] [abbrv] olingo-odata4 git commit: [OLINGO-609] Fix:
ODataJsonDeserializer
Posted by ch...@apache.org.
[OLINGO-609] Fix: ODataJsonDeserializer
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/92e201b0
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/92e201b0
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/92e201b0
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 92e201b0a828370bb747c79a8479959d5f491a8e
Parents: 62f1001
Author: Christian Holzer <c....@sap.com>
Authored: Tue Mar 31 12:52:02 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Tue Mar 31 12:52:02 2015 +0200
----------------------------------------------------------------------
.../server/core/deserializer/json/ODataJsonDeserializer.java | 2 +-
.../apache/olingo/server/tecsvc/provider/PropertyProvider.java | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/92e201b0/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index a15d84a..ed3454c 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -290,7 +290,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
if (jsonNode != null) {
EdmNavigationProperty edmNavigationProperty = edmEntityType.getNavigationProperty(navigationPropertyName);
boolean isNullable = edmNavigationProperty.isNullable();
- if (jsonNode.isNull() && !isNullable) {
+ if ((jsonNode.isNull() && !isNullable) || (jsonNode.isNull() && edmNavigationProperty.isCollection())) {
throw new DeserializerException("Property: " + navigationPropertyName + " must not be null.",
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, navigationPropertyName);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/92e201b0/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
index bd2ec5b..c21fbce 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
@@ -658,8 +658,7 @@ public class PropertyProvider {
public static final NavigationProperty collectionNavPropertyETTwoPrimMany_ETTwoPrim = new NavigationProperty()
.setName("NavPropertyETTwoPrimMany")
.setType(EntityTypeProvider.nameETTwoPrim)
- .setCollection(true)
- .setNullable(false);
+ .setCollection(true);
public static final NavigationProperty collectionNavPropertyETAllPrimMany_ETAllPrim = new NavigationProperty()
.setName("NavPropertyETAllPrimMany")
[27/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin as example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index e6193df..1f28900 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@ -6,9 +6,9 @@
* 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
@@ -41,11 +41,14 @@ import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
+import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
+
public class DataCreator {
private static final UUID GUID = UUID.fromString("01234567-89ab-cdef-0123-456789abcdef");
-
+ private static final String ctPropComp = ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString();
private final Map<String, EntitySet> data;
public DataCreator() {
@@ -96,7 +99,9 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt16", i))
.addProperty(createPrimitive("PropertyString", "Number:" + i)));
}
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETServerSidePaging.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -106,7 +111,9 @@ public class DataCreator {
entitySet.getEntities().add(createETKeyNavEntity(1, "I am String Property 1"));
entitySet.getEntities().add(createETKeyNavEntity(2, "I am String Property 2"));
entitySet.getEntities().add(createETKeyNavEntity(3, "I am String Property 3"));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETKeyNav.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -115,10 +122,12 @@ public class DataCreator {
return new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", propertyInt16))
.addProperty(createPrimitive("PropertyString", propertyString))
- .addProperty(createComplex("PropertyCompNav",
+ .addProperty(createComplex("PropertyCompNav", ctPropComp,
createPrimitive("PropertyInt16", 1)))
.addProperty(createKeyNavAllPrimComplexValue("PropertyCompAllPrim"))
- .addProperty(createComplex("PropertyCompTwoPrim",
+ .addProperty(
+ createComplex("PropertyCompTwoPrim",
+ ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
createPrimitive("PropertyInt16", 16),
createPrimitive("PropertyString", "Test123")))
.addProperty(createPrimitiveCollection("CollPropertyString",
@@ -126,7 +135,9 @@ public class DataCreator {
"Employee2@company.example",
"Employee3@company.example"))
.addProperty(createPrimitiveCollection("CollPropertyInt16", 1000, 2000, 30112))
- .addProperty(createComplexCollection("CollPropertyComp",
+ .addProperty(
+ createComplexCollection("CollPropertyComp", ComplexTypeProvider.nameCTPrimComp
+ .getFullQualifiedNameAsString(),
Arrays.asList(
createPrimitive("PropertyInt16", 1),
createKeyNavAllPrimComplexValue("PropertyComp")),
@@ -136,9 +147,11 @@ public class DataCreator {
Arrays.asList(
createPrimitive("PropertyInt16", 3),
createKeyNavAllPrimComplexValue("PropertyComp"))))
- .addProperty(createComplex("PropertyCompCompNav",
+ .addProperty(
+ createComplex("PropertyCompCompNav",
+ ComplexTypeProvider.nameCTCompComp.getFullQualifiedNameAsString(),
createPrimitive("PropertyString", "1"),
- createComplex("PropertyComp", createPrimitive("PropertyInt16", 1))));
+ createComplex("PropertyComp", ctPropComp, createPrimitive("PropertyInt16", 1))));
}
private EntitySet createESTwoKeyNav() {
@@ -148,7 +161,9 @@ public class DataCreator {
entitySet.getEntities().add(createESTwoKeyNavEntity(1, "2"));
entitySet.getEntities().add(createESTwoKeyNavEntity(2, "1"));
entitySet.getEntities().add(createESTwoKeyNavEntity(3, "1"));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETTwoKeyNav.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -157,9 +172,9 @@ public class DataCreator {
return new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", propertyInt16))
.addProperty(createPrimitive("PropertyString", propertyString))
- .addProperty(createComplex("PropertyComp",
+ .addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 11),
- createComplex("PropertyComp",
+ createComplex("PropertyComp", ctPropComp,
createPrimitive("PropertyString", "StringValue"),
createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }),
createPrimitive("PropertyBoolean", true),
@@ -175,20 +190,26 @@ public class DataCreator {
createPrimitive("PropertyInt64", Long.MAX_VALUE),
createPrimitive("PropertySByte", Byte.MAX_VALUE),
createPrimitive("PropertyTimeOfDay", getTime(21, 5, 59)))))
- .addProperty(createComplex("PropertyCompNav",
+ .addProperty(
+ createComplex("PropertyCompNav",
+ ComplexTypeProvider.nameCTCompNav.getFullQualifiedNameAsString(),
createPrimitive("PropertyInt16", 1),
createKeyNavAllPrimComplexValue("PropertyComp")))
- .addProperty(createComplexCollection("CollPropertyComp"))
- .addProperty(createComplexCollection("CollPropertyCompNav",
+ .addProperty(createComplexCollection("CollPropertyComp", null))
+ .addProperty(
+ createComplexCollection("CollPropertyCompNav",
+ ComplexTypeProvider.nameCTCompNav.getFullQualifiedNameAsString(),
Arrays.asList(createPrimitive("PropertyInt16", 1))))
.addProperty(createPrimitiveCollection("CollPropertyString", 1, 2))
- .addProperty(createComplex("PropertyCompTwoPrim",
+ .addProperty(
+ createComplex("PropertyCompTwoPrim",
+ ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
createPrimitive("PropertyInt16", 11),
createPrimitive("PropertyString", "11")));
}
private Property createKeyNavAllPrimComplexValue(final String name) {
- return createComplex(name,
+ return createComplex(name, ComplexTypeProvider.nameCTAllPrim.getFullQualifiedNameAsString(),
createPrimitive("PropertyString", "First Resource - positive values"),
createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }),
createPrimitive("PropertyBoolean", true),
@@ -213,8 +234,9 @@ public class DataCreator {
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
- .addProperty(createComplex("PropertyComp",
- createComplexCollection("CollPropertyComp",
+ .addProperty(createComplex("PropertyComp", null,
+ createComplexCollection("CollPropertyComp", ComplexTypeProvider.nameCTTwoPrim
+ .getFullQualifiedNameAsString(),
Arrays.asList(
createPrimitive("PropertyInt16", 555),
createPrimitive("PropertyString", "1 Test Complex in Complex Property")),
@@ -227,8 +249,9 @@ public class DataCreator {
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", 12345))
- .addProperty(createComplex("PropertyComp",
- createComplexCollection("CollPropertyComp",
+ .addProperty(createComplex("PropertyComp",null,
+ createComplexCollection("CollPropertyComp", ComplexTypeProvider.nameCTTwoPrim
+ .getFullQualifiedNameAsString(),
Arrays.asList(
createPrimitive("PropertyInt16", 888),
createPrimitive("PropertyString", "11 Test Complex in Complex Property")),
@@ -238,7 +261,9 @@ public class DataCreator {
Arrays.asList(
createPrimitive("PropertyInt16", 0),
createPrimitive("PropertyString", "13 Test Complex in Complex Property"))))));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETCompCollComp.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -260,7 +285,9 @@ public class DataCreator {
entitySet.getEntities().add(new EntityImpl()
.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
.addProperty(createPrimitive("PropertyString", "Test String4")));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETTwoPrim.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -322,7 +349,9 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyDuration", 0))
.addProperty(createPrimitive("PropertyGuid", UUID.fromString("76543201-23ab-cdef-0123-456789cccddd")))
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(0, 1, 1))));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETAllPrim.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -331,7 +360,7 @@ public class DataCreator {
Entity entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE));
- entity.addProperty(createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyString", "First Resource - first"),
createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
@@ -353,7 +382,7 @@ public class DataCreator {
entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 7));
- entity.addProperty(createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyString", "Second Resource - second"),
createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
@@ -375,7 +404,7 @@ public class DataCreator {
entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 0));
- entity.addProperty(createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyString", "Third Resource - third"),
createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
@@ -394,7 +423,9 @@ public class DataCreator {
createPrimitive("PropertySByte", Byte.MAX_VALUE),
createPrimitive("PropertyTimeOfDay", getTime(13, 27, 45))));
entitySet.getEntities().add(entity);
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETCompAllPrim.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -444,13 +475,15 @@ public class DataCreator {
entity.getProperties().addAll(entitySet.getEntities().get(0).getProperties());
entity.getProperties().set(0, createPrimitive("PropertyInt16", 3));
entitySet.getEntities().add(entity);
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETCollAllPrim.getFullQualifiedNameAsString());
+ }
return entitySet;
}
private EntitySet createESMixPrimCollComp() {
@SuppressWarnings("unchecked")
- final Property complexCollection = createComplexCollection("CollPropertyComp",
+ final Property complexCollection = createComplexCollection("CollPropertyComp", ctPropComp,
Arrays.asList(createPrimitive("PropertyInt16", 123), createPrimitive("PropertyString", "TEST 1")),
Arrays.asList(createPrimitive("PropertyInt16", 456), createPrimitive("PropertyString", "TEST 2")),
Arrays.asList(createPrimitive("PropertyInt16", 789), createPrimitive("PropertyString", "TEST 3")));
@@ -461,7 +494,7 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
.addProperty(createPrimitiveCollection("CollPropertyString",
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
+ .addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 111),
createPrimitive("PropertyString", "TEST A")))
.addProperty(complexCollection));
@@ -470,7 +503,7 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt16", 7))
.addProperty(createPrimitiveCollection("CollPropertyString",
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
+ .addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 222),
createPrimitive("PropertyString", "TEST B")))
.addProperty(complexCollection));
@@ -479,11 +512,13 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt16", 0))
.addProperty(createPrimitiveCollection("CollPropertyString",
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
+ .addProperty(createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 333),
createPrimitive("PropertyString", "TEST C")))
.addProperty(complexCollection));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETMixPrimCollComp.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -519,7 +554,9 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyDuration", 6))
.addProperty(createPrimitive("PropertyGuid", GUID))
.addProperty(createPrimitive("PropertyTimeOfDay", getTime(2, 48, 21))));
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETAllKey.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -528,20 +565,22 @@ public class DataCreator {
Entity entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 1));
- entity.addProperty(createComplex("PropertyComp",
- createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp", null,
+ createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 123),
createPrimitive("PropertyString", "String 1"))));
entitySet.getEntities().add(entity);
entity = new EntityImpl();
entity.addProperty(createPrimitive("PropertyInt16", 2));
- entity.addProperty(createComplex("PropertyComp",
- createComplex("PropertyComp",
+ entity.addProperty(createComplex("PropertyComp", null,
+ createComplex("PropertyComp",ctPropComp,
createPrimitive("PropertyInt16", 987),
createPrimitive("PropertyString", "String 2"))));
entitySet.getEntities().add(entity);
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETCompComp.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -571,7 +610,9 @@ public class DataCreator {
.addProperty(createPrimitive(DataProvider.MEDIA_PROPERTY_NAME, createImage("black")));
entity.setMediaContentType("image/svg+xml");
entitySet.getEntities().add(entity);
-
+ for (Entity en:entitySet.getEntities()) {
+ en.setType(EntityTypeProvider.nameETMedia.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -677,22 +718,23 @@ public class DataCreator {
return new PropertyImpl(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(values));
}
- protected static Property createComplex(final String name, final Property... properties) {
+ protected static Property createComplex(final String name, String type, final Property... properties) {
ComplexValue complexValue = new ComplexValueImpl();
for (final Property property : properties) {
complexValue.getValue().add(property);
}
- return new PropertyImpl(null, name, ValueType.COMPLEX, complexValue);
+ return new PropertyImpl(type, name, ValueType.COMPLEX, complexValue);
}
- protected static Property createComplexCollection(final String name, final List<Property>... propertiesList) {
+ protected static Property createComplexCollection(final String name, String type,
+ final List<Property>... propertiesList) {
List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
for (final List<Property> properties : propertiesList) {
ComplexValue complexValue = new ComplexValueImpl();
complexValue.getValue().addAll(properties);
complexCollection.add(complexValue);
}
- return new PropertyImpl(null, name, ValueType.COLLECTION_COMPLEX, complexCollection);
+ return new PropertyImpl(type, name, ValueType.COLLECTION_COMPLEX, complexCollection);
}
private Calendar getDateTime(final int year, final int month, final int day,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
index fed499f..4fc9300 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
@@ -6,9 +6,9 @@
* 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
@@ -138,7 +138,7 @@ public class DataProvider {
final List<Entity> entities = entitySet.getEntities();
final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntitySet.getEntityType());
final Entity newEntity = new EntityImpl();
-
+ newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
for (final String keyName : edmEntityType.getKeyPredicateNames()) {
newEntity.addProperty(DataCreator.createPrimitive(keyName, newKey.get(keyName)));
}
@@ -194,7 +194,8 @@ public class DataProvider {
return true;
}
- private void createProperties(final EdmStructuredType type, List<Property> properties) throws DataProviderException {
+ private void createProperties(final EdmStructuredType type, List<Property> properties)
+ throws DataProviderException {
final List<String> keyNames = type instanceof EdmEntityType ?
((EdmEntityType) type).getKeyPredicateNames() : Collections.<String> emptyList();
for (final String propertyName : type.getPropertyNames()) {
@@ -204,11 +205,11 @@ public class DataProvider {
}
}
}
-
- private Property createProperty(final EdmProperty edmProperty, final String propertyName)
+
+ private Property createProperty(final EdmProperty edmProperty, final String propertyName)
throws DataProviderException {
Property newProperty;
-
+
if (edmProperty.isPrimitive()) {
newProperty = edmProperty.isCollection() ?
DataCreator.createPrimitiveCollection(propertyName) :
@@ -216,17 +217,19 @@ public class DataProvider {
} else {
if (edmProperty.isCollection()) {
@SuppressWarnings("unchecked")
- Property newProperty2 = DataCreator.createComplexCollection(propertyName);
+ Property newProperty2 = DataCreator.createComplexCollection(propertyName, edmProperty
+ .getType().getFullQualifiedName().getFullQualifiedNameAsString());
newProperty = newProperty2;
} else {
- newProperty = DataCreator.createComplex(propertyName);
+ newProperty = DataCreator.createComplex(propertyName, edmProperty.getType()
+ .getFullQualifiedName().getFullQualifiedNameAsString());
createProperties((EdmComplexType) edmProperty.getType(), newProperty.asComplex().getValue());
}
}
-
+
return newProperty;
}
-
+
public void update(final String rawBaseUri, final EdmEntitySet edmEntitySet, Entity entity,
final Entity changedEntity, final boolean patch, final boolean isInsert) throws DataProviderException {
@@ -433,7 +436,7 @@ public class DataProvider {
}
}
- private ComplexValue createComplexValue(final EdmProperty edmProperty, final ComplexValue complexValue,
+ private ComplexValue createComplexValue(final EdmProperty edmProperty, final ComplexValue complexValue,
final boolean patch) throws DataProviderException {
final ComplexValueImpl result = new ComplexValueImpl();
final EdmComplexType edmType = (EdmComplexType) edmProperty.getType();
@@ -445,7 +448,7 @@ public class DataProvider {
final Property currentProperty = findProperty(propertyName, givenProperties);
final Property newProperty = createProperty(innerEdmProperty, propertyName);
result.getValue().add(newProperty);
-
+
if (currentProperty != null) {
updateProperty(innerEdmProperty, newProperty, currentProperty, patch);
} else {
@@ -459,7 +462,7 @@ public class DataProvider {
}
}
}
-
+
return result;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
index 5451d5d..316a7b0 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
@@ -31,6 +31,7 @@ import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.uri.UriParameter;
import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException;
+import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
public class FunctionData {
@@ -80,12 +81,12 @@ public class FunctionData {
} else if (name.equals("UFCRTCollString")) {
return data.get("ESCollAllPrim").getEntities().get(0).getProperty("CollPropertyString");
} else if (name.equals("UFCRTCTTwoPrim")) {
- return DataCreator.createComplex(name,
+ return DataCreator.createComplex(name, ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
DataCreator.createPrimitive("PropertyInt16", 16),
DataCreator.createPrimitive("PropertyString", "UFCRTCTTwoPrim string value"));
} else if (name.equals("UFCRTCTTwoPrimParam")) {
try {
- return DataCreator.createComplex(name,
+ return DataCreator.createComplex(name,ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
DataCreator.createPrimitive("PropertyInt16",
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16).valueOfString(
getParameterText("ParameterInt16", parameters),
@@ -99,7 +100,7 @@ public class FunctionData {
throw new DataProviderException("Error in function " + name + ".", e);
}
} else if (name.equals("UFCRTCollCTTwoPrim")) {
- return DataCreator.createComplexCollection(name,
+ return DataCreator.createComplexCollection(name,ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 16),
DataCreator.createPrimitive("PropertyString", "Test123")),
Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 17),
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index f610fc2b..841eabe 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -6,9 +6,9 @@
* 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
@@ -38,6 +38,7 @@ import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
import org.apache.olingo.server.api.processor.ActionEntityCollectionProcessor;
@@ -74,8 +75,11 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
EntityProcessor, ActionEntityProcessor, MediaEntityProcessor,
ActionVoidProcessor {
- public TechnicalEntityProcessor(final DataProvider dataProvider) {
+ private final ServiceMetadata serviceMetadata;
+
+ public TechnicalEntityProcessor(final DataProvider dataProvider, ServiceMetadata serviceMetadata) {
super(dataProvider);
+ this.serviceMetadata = serviceMetadata;
}
@Override
@@ -109,21 +113,24 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
entitySet,
edmEntitySet,
request.getRawRequestUri());
-
+
// Apply expand system query option
final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
-
+
// Create a shallow copy of each entity. So the expanded navigation properties can be modified for serialization,
// without affecting the data stored in the database.
final ExpandSystemQueryOptionHandler expandHandler = new ExpandSystemQueryOptionHandler();
final EntitySet entitySetSerialization = expandHandler.copyEntitySetShallowRekursive(entitySet);
expandHandler.applyExpandQueryOptions(entitySetSerialization, edmEntitySet, expand);
-
+
// Serialize
- response.setContent(serializer.entityCollection(edmEntityType, entitySetSerialization,
+ response.setContent(serializer.entityCollection(
+ this.serviceMetadata,
+ edmEntityType,
+ entitySetSerialization,
EntityCollectionSerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, edmEntityType, false, expand, select))
@@ -170,17 +177,20 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
edmEntitySet.getEntityType();
final Entity entity = readEntity(uriInfo);
-
+
final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
-
+
final ExpandSystemQueryOptionHandler expandHandler = new ExpandSystemQueryOptionHandler();
final Entity entitySerialization = expandHandler.copyEntityShallowRekursive(entity);
expandHandler.applyExpandQueryOptions(entitySerialization, edmEntitySet, expand);
-
- response.setContent(serializer.entity(edmEntitySet.getEntityType(), entitySerialization,
+
+ response.setContent(serializer.entity(
+ this.serviceMetadata,
+ edmEntitySet.getEntityType(),
+ entitySerialization,
EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, edmEntityType, true, expand, select))
@@ -233,7 +243,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
final ODataFormat format = ODataFormat.fromContentType(responseFormat);
ODataSerializer serializer = odata.createSerializer(format);
- response.setContent(serializer.entity(edmEntityType, entity,
+ response.setContent(serializer.entity(this.serviceMetadata, edmEntityType, entity,
EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, edmEntityType, true, null, null))
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
index e36dc6b..b853e48 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalPrimitiveComplexProcessor.java
@@ -6,9 +6,9 @@
* 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
@@ -44,6 +44,7 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.processor.ActionComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ActionComplexProcessor;
@@ -81,8 +82,12 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
ComplexProcessor, ActionComplexProcessor,
ComplexCollectionProcessor, ActionComplexCollectionProcessor {
- public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider) {
+ private final ServiceMetadata serviceMetadata;
+
+ public TechnicalPrimitiveComplexProcessor(final DataProvider dataProvider,
+ ServiceMetadata serviceMetadata) {
super(dataProvider);
+ this.serviceMetadata = serviceMetadata;
}
@Override
@@ -246,7 +251,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
.build()));
break;
case COMPLEX:
- response.setContent(serializer.complex((EdmComplexType) type, property,
+ response.setContent(serializer.complex(this.serviceMetadata,(EdmComplexType) type, property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
.build()));
@@ -262,7 +267,7 @@ public class TechnicalPrimitiveComplexProcessor extends TechnicalProcessor
.build()));
break;
case COLLECTION_COMPLEX:
- response.setContent(serializer.complexCollection((EdmComplexType) type, property,
+ response.setContent(serializer.complexCollection(this.serviceMetadata, (EdmComplexType) type, property,
ComplexSerializerOptions.with().contextURL(contextURL)
.expand(expand).select(select)
.build()));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
index 76edb33..4549a03 100644
--- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
+++ b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
@@ -22,9 +22,9 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
index cd421f4..870f7c3 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
@@ -6,9 +6,9 @@
* 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
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 038c668..ee38684 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -41,11 +41,12 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
-import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.api.uri.UriHelper;
@@ -64,9 +65,9 @@ import org.junit.Test;
import org.mockito.Mockito;
public class ODataJsonSerializerTest {
-
- private static final Edm edm = OData.newInstance().createServiceMetadata(
- new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
+ private static final ServiceMetadata metadata = OData.newInstance().createServiceMetadata(
+ new EdmTechProvider(), Collections.<EdmxReference> emptyList());
+ private static final Edm edm = metadata.getEdm();
private static final EdmEntityContainer entityContainer = edm.getEntityContainer(
new FullQualifiedName("olingo.odata.test1", "Container"));
private final DataProvider data = new DataProvider();
@@ -77,7 +78,7 @@ public class ODataJsonSerializerTest {
public void entitySimple() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -109,7 +110,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
- final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity,
+ final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(),
+ entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()));
@@ -130,7 +132,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().clear();
- serializer.entity(edmEntitySet.getEntityType(), entity,
+ serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -142,7 +144,7 @@ public class ODataJsonSerializerTest {
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().get(0).setValue(ValueType.PRIMITIVE, false);
try {
- serializer.entity(edmEntitySet.getEntityType(), entity,
+ serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -163,7 +165,7 @@ public class ODataJsonSerializerTest {
entitySet.setNext(URI.create("/next"));
CountOption countOption = Mockito.mock(CountOption.class);
Mockito.when(countOption.getValue()).thenReturn(true);
- InputStream result = serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ InputStream result = serializer.entityCollection(metadata, edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build())
.count(countOption)
@@ -188,7 +190,7 @@ public class ODataJsonSerializerTest {
public void entityCollAllPrim() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().serviceRoot(URI.create("http://host/service/"))
.entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
@@ -224,7 +226,7 @@ public class ODataJsonSerializerTest {
public void entityCompAllPrim() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -257,7 +259,7 @@ public class ODataJsonSerializerTest {
public void entityMixPrimCollComp() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build());
@@ -280,7 +282,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
- final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity,
+ final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()));
@@ -295,7 +297,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA)
- .entity(edmEntitySet.getEntityType(), entity, null);
+ .entity(metadata, edmEntitySet.getEntityType(), entity, null);
final String resultString = IOUtils.toString(result);
final String expectedResult = "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}";
Assert.assertEquals(expectedResult, resultString);
@@ -306,7 +308,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final EntitySet entitySet = data.readAll(edmEntitySet);
InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA)
- .entityCollection(edmEntitySet.getEntityType(), entitySet,
+ .entityCollection(metadata, edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build());
final String resultString = IOUtils.toString(result);
@@ -323,7 +325,8 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
entity.setMediaETag("theMediaETag");
- final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity,
+ final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(),
+ entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()));
@@ -337,7 +340,8 @@ public class ODataJsonSerializerTest {
public void entitySetMedia() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
final EntitySet entitySet = data.readAll(edmEntitySet);
- final String resultString = IOUtils.toString(serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ final String resultString = IOUtils.toString(serializer.entityCollection(metadata,
+ edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build()));
final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia\",\"value\":["
@@ -358,7 +362,7 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
selectItem1, selectItem2, selectItem2));
InputStream result = serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, null, select))
@@ -380,7 +384,7 @@ public class ODataJsonSerializerTest {
SelectItem selectItem2 = Mockito.mock(SelectItem.class);
Mockito.when(selectItem2.isStar()).thenReturn(true);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem1, selectItem2));
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.select(select)
@@ -399,7 +403,7 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString")));
InputStream result = serializer
- .entityCollection(entityType, entitySet,
+ .entityCollection(metadata, entityType, entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, null, select))
@@ -424,7 +428,7 @@ public class ODataJsonSerializerTest {
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString"),
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp")));
final String resultString = IOUtils.toString(serializer
- .entityCollection(entityType, entitySet,
+ .entityCollection(metadata, entityType, entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, null, select))
@@ -445,7 +449,7 @@ public class ODataJsonSerializerTest {
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne")));
- InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.expand(expand)
@@ -484,7 +488,7 @@ public class ODataJsonSerializerTest {
Mockito.when(expandItem.getSelectOption()).thenReturn(select);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
final String resultString = IOUtils.toString(serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
@@ -511,7 +515,7 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertySByte")));
final String resultString = IOUtils.toString(serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
@@ -538,7 +542,7 @@ public class ODataJsonSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyTimeOfDay")));
final String resultString = IOUtils.toString(serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
@@ -569,7 +573,7 @@ public class ODataJsonSerializerTest {
Mockito.when(expandItemFirst.getSelectOption()).thenReturn(select);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemFirst));
final String resultString = IOUtils.toString(serializer
- .entity(entityType, entity,
+ .entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
@@ -646,7 +650,7 @@ public class ODataJsonSerializerTest {
final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp");
final String resultString = IOUtils.toString(serializer
- .complex((EdmComplexType) edmProperty.getType(), property,
+ .complex(metadata, (EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with()
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
@@ -665,7 +669,7 @@ public class ODataJsonSerializerTest {
final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
final String resultString = IOUtils.toString(serializer
- .complexCollection((EdmComplexType) edmProperty.getType(), property,
+ .complexCollection(metadata, (EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with()
.contextURL(ContextURL.with()
.entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
index 798c5c0..86cbf0e 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
@@ -6,9 +6,9 @@
* 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
@@ -1064,13 +1064,16 @@ public class TestUriParserImpl {
public void testAlias() throws Exception {
testUri.run("ESAllPrim", "$filter=PropertyInt16 eq @p1&@p1=1)")
.goFilter().is("<<PropertyInt16> eq <@p1>>");
- }
-
+ }
+
@Test
public void testLambda() throws Exception {
testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/all( l : true )")
.goFilter().is("<CollPropertyComp/<ALL;<true>>>");
+ testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/all( x : x/PropertyInt16 eq 2)")
+ .goFilter().is("<CollPropertyComp/<ALL;<<x/PropertyInt16> eq <2>>>>");
+
testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/any( l : true )")
.goFilter().is("<CollPropertyComp/<ANY;<true>>>");
testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/any( )")
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
index 1835bef..db3930e 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
@@ -6,9 +6,9 @@
* 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
@@ -18,6 +18,9 @@
*/
package org.apache.olingo.server.core.uri.validator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.commons.core.edm.provider.EdmProviderImpl;
@@ -31,9 +34,6 @@ import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
public class UriValidatorTest {
private static final String URI_ALL = "$all";
@@ -77,7 +77,7 @@ public class UriValidatorTest {
private static final String QO_SKIPTOKEN = "$skiptoken=123";
private static final String QO_TOP = "$top=1";
- private String[][] urisWithValidSystemQueryOptions = {
+ private final String[][] urisWithValidSystemQueryOptions = {
{ URI_ALL, QO_FILTER }, { URI_ALL, QO_FORMAT }, { URI_ALL, QO_EXPAND }, { URI_ALL, QO_COUNT },
{ URI_ALL, QO_ORDERBY }, /* { URI_ALL, QO_SEARCH }, */{ URI_ALL, QO_SELECT }, { URI_ALL, QO_SKIP },
{ URI_ALL, QO_SKIPTOKEN }, { URI_ALL, QO_TOP },
@@ -105,7 +105,7 @@ public class UriValidatorTest {
{ URI_REFERENCES, QO_FILTER }, { URI_REFERENCES, QO_FORMAT }, { URI_REFERENCES, QO_ORDERBY },
/* { URI_REFERENCES, QO_SEARCH }, */{ URI_REFERENCES, QO_SKIP }, { URI_REFERENCES, QO_SKIPTOKEN },
- { URI_REFERENCES, QO_TOP },
+ { URI_REFERENCES, QO_TOP }, { URI_REFERENCES, QO_ID },
{ URI_REFERENCE, QO_FORMAT },
@@ -160,7 +160,7 @@ public class UriValidatorTest {
{ ContainerProvider.AIRT_STRING }
};
- private String[][] urisWithNonValidSystemQueryOptions = {
+ private final String[][] urisWithNonValidSystemQueryOptions = {
{ URI_ALL, QO_ID },
{ URI_BATCH, QO_FILTER }, { URI_BATCH, QO_FORMAT }, { URI_BATCH, QO_ID }, { URI_BATCH, QO_EXPAND },
@@ -199,7 +199,7 @@ public class UriValidatorTest {
/* { URI_MEDIA_STREAM, QO_SEARCH }, */ { URI_MEDIA_STREAM, QO_SELECT }, { URI_MEDIA_STREAM, QO_SKIP },
{ URI_MEDIA_STREAM, QO_SKIPTOKEN }, { URI_MEDIA_STREAM, QO_TOP },
- { URI_REFERENCES, QO_ID }, { URI_REFERENCES, QO_EXPAND }, { URI_REFERENCES, QO_COUNT },
+ { URI_REFERENCES, QO_EXPAND }, { URI_REFERENCES, QO_COUNT },
{ URI_REFERENCES, QO_SELECT },
{ URI_REFERENCE, QO_FILTER }, { URI_REFERENCE, QO_ID }, { URI_REFERENCE, QO_EXPAND },
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java b/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
index d59d251..2e44e35 100644
--- a/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
+++ b/samples/server/src/main/java/org/apache/olingo/server/sample/data/DataProvider.java
@@ -6,9 +6,9 @@
* 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
@@ -37,10 +37,11 @@ import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.sample.edmprovider.CarsEdmProvider;
public class DataProvider {
- private Map<String, EntitySet> data;
+ private final Map<String, EntitySet> data;
public DataProvider() {
data = new HashMap<String, EntitySet>();
@@ -133,6 +134,9 @@ public class DataProvider {
.addProperty(createPrimitive("Price", 167189.00))
.addProperty(createPrimitive("Currency", "EUR")));
+ for (Entity entity:entitySet.getEntities()) {
+ entity.setType(CarsEdmProvider.ET_CAR.getFullQualifiedNameAsString());
+ }
return entitySet;
}
@@ -149,6 +153,9 @@ public class DataProvider {
.addProperty(createPrimitive("Name", "Horse Powered Racing"))
.addProperty(createAddress("Horse Street 1", "Maranello", "41053", "Italy")));
+ for (Entity entity:entitySet.getEntities()) {
+ entity.setType(CarsEdmProvider.ET_MANUFACTURER.getFullQualifiedNameAsString());
+ }
return entitySet;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
----------------------------------------------------------------------
diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
index 891acbb..71b827d 100644
--- a/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
+++ b/samples/server/src/main/java/org/apache/olingo/server/sample/processor/CarsProcessor.java
@@ -6,9 +6,9 @@
* 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
@@ -74,7 +74,8 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
PrimitiveProcessor, PrimitiveValueProcessor, ComplexProcessor {
private OData odata;
- private DataProvider dataProvider;
+ private final DataProvider dataProvider;
+ private ServiceMetadata edm;
// This constructor is application specific and not mandatory for the Olingo library. We use it here to simulate the
// database access
@@ -85,6 +86,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
@Override
public void init(OData odata, ServiceMetadata edm) {
this.odata = odata;
+ this.edm = edm;
}
@Override
@@ -105,7 +107,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
// Now the content is serialized using the serializer.
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
- InputStream serializedContent = serializer.entityCollection(edmEntitySet.getEntityType(), entitySet,
+ InputStream serializedContent = serializer.entityCollection(edm, edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, false, expand, select, null))
@@ -143,7 +145,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
ODataSerializer serializer = odata.createSerializer(format);
final ExpandOption expand = uriInfo.getExpandOption();
final SelectOption select = uriInfo.getSelectOption();
- InputStream serializedContent = serializer.entity(edmEntitySet.getEntityType(), entity,
+ InputStream serializedContent = serializer.entity(edm, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, true, expand, select, null))
@@ -256,7 +258,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
final ContextURL contextURL = format == ODataFormat.JSON_NO_METADATA ? null :
getContextUrl(edmEntitySet, true, null, null, edmProperty.getName());
InputStream serializerContent = complex ?
- serializer.complex((EdmComplexType) edmProperty.getType(), property,
+ serializer.complex(edm, (EdmComplexType) edmProperty.getType(), property,
ComplexSerializerOptions.with().contextURL(contextURL).build()) :
serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property,
PrimitiveSerializerOptions.with()
@@ -273,7 +275,7 @@ public class CarsProcessor implements EntityCollectionProcessor, EntityProcessor
}
}
}
-
+
private Entity readEntityInternal(final UriInfoResource uriInfo, final EdmEntitySet entitySet)
throws DataProvider.DataProviderException {
// This method will extract the key values and pass them to the data provider
[40/50] [abbrv] olingo-odata4 git commit: [OLINGO-603] Delete
unnecessary deserializer constants
Posted by ch...@apache.org.
[OLINGO-603] Delete unnecessary deserializer constants
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/5855c6b6
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/5855c6b6
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/5855c6b6
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 5855c6b6241842cfc984f3a739f1ab9f55488fc4
Parents: d067037
Author: Christian Amend <ch...@apache.org>
Authored: Wed Apr 1 15:19:41 2015 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Apr 1 15:19:41 2015 +0200
----------------------------------------------------------------------
.../olingo/commons/api/edm/EdmOperation.java | 4 +-
.../serialization/JsonDeltaDeserializer.java | 12 ++--
.../core/serialization/JsonDeserializer.java | 50 +++-----------
.../serialization/JsonEntityDeserializer.java | 70 ++++++++++----------
.../JsonEntitySetDeserializer.java | 18 ++---
.../JsonODataErrorDeserializer.java | 4 +-
.../serialization/JsonPropertyDeserializer.java | 7 +-
7 files changed, 70 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5855c6b6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java
index d6101b3..c90316d 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmOperation.java
@@ -32,6 +32,8 @@ public interface EdmOperation extends EdmType, EdmAnnotatable {
EdmParameter getParameter(String name);
/**
+ * A list of all parameter names. If this is a bound action or function the first parameter name in the list is the
+ * binding parameter
* @return a list of all parameter names
*/
List<String> getParameterNames();
@@ -63,7 +65,7 @@ public interface EdmOperation extends EdmType, EdmAnnotatable {
* @return true if binding parameter is of type collection.
*/
Boolean isBindingParameterTypeCollection();
-
+
/**
* @return the entity set path as a String or null if not present
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5855c6b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java
index 5cb2076..de79cf7 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeltaDeserializer.java
@@ -56,14 +56,14 @@ public class JsonDeltaDeserializer extends JsonDeserializer {
delta.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
}
- if (tree.hasNonNull(jsonCount)) {
- delta.setCount(tree.get(jsonCount).asInt());
+ if (tree.hasNonNull(Constants.JSON_COUNT)) {
+ delta.setCount(tree.get(Constants.JSON_COUNT).asInt());
}
- if (tree.hasNonNull(jsonNextLink)) {
- delta.setNext(URI.create(tree.get(jsonNextLink).textValue()));
+ if (tree.hasNonNull(Constants.JSON_NEXT_LINK)) {
+ delta.setNext(URI.create(tree.get(Constants.JSON_NEXT_LINK).textValue()));
}
- if (tree.hasNonNull(jsonDeltaLink)) {
- delta.setDeltaLink(URI.create(tree.get(jsonDeltaLink).textValue()));
+ if (tree.hasNonNull(Constants.JSON_DELTA_LINK)) {
+ delta.setDeltaLink(URI.create(tree.get(Constants.JSON_DELTA_LINK).textValue()));
}
if (tree.hasNonNull(Constants.VALUE)) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5855c6b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
index fc7e4f8..9641623 100755
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java
@@ -72,36 +72,6 @@ public class JsonDeserializer implements ODataDeserializer {
protected final boolean serverMode;
- protected String jsonType = Constants.JSON_TYPE;
-
- protected String jsonId = Constants.JSON_ID;
-
- protected String jsonETag = Constants.JSON_ETAG;
-
- protected String jsonReadLink = Constants.JSON_READ_LINK;
-
- protected String jsonEditLink = Constants.JSON_EDIT_LINK;
-
- protected String jsonMediaEditLink = Constants.JSON_MEDIA_EDIT_LINK;
-
- protected String jsonMediaReadLink = Constants.JSON_MEDIA_READ_LINK;
-
- protected String jsonMediaContentType = Constants.JSON_MEDIA_CONTENT_TYPE;
-
- protected String jsonMediaETag = Constants.JSON_MEDIA_ETAG;
-
- protected String jsonAssociationLink = Constants.JSON_ASSOCIATION_LINK;
-
- protected String jsonNavigationLink = Constants.JSON_NAVIGATION_LINK;
-
- protected String jsonCount = Constants.JSON_COUNT;
-
- protected String jsonNextLink = Constants.JSON_NEXT_LINK;
-
- protected String jsonDeltaLink = Constants.JSON_DELTA_LINK;
-
- protected String jsonError = Constants.JSON_ERROR;
-
private JsonGeoValueDeserializer geoDeserializer;
private JsonParser parser;
@@ -163,7 +133,7 @@ public class JsonDeserializer implements ODataDeserializer {
private void clientLinks(final Map.Entry<String, JsonNode> field, final Linked linked, final Set<String> toRemove,
final JsonNode tree, final ObjectCodec codec) throws IOException {
- if (field.getKey().endsWith(jsonNavigationLink)) {
+ if (field.getKey().endsWith(Constants.JSON_NAVIGATION_LINK)) {
final LinkImpl link = new LinkImpl();
link.setTitle(getTitle(field));
link.setRel(Constants.NS_NAVIGATION_LINK_REL + getTitle(field));
@@ -176,8 +146,8 @@ public class JsonDeserializer implements ODataDeserializer {
linked.getNavigationLinks().add(link);
toRemove.add(field.getKey());
- toRemove.add(setInline(field.getKey(), jsonNavigationLink, tree, codec, link));
- } else if (field.getKey().endsWith(jsonAssociationLink)) {
+ toRemove.add(setInline(field.getKey(), Constants.JSON_NAVIGATION_LINK, tree, codec, link));
+ } else if (field.getKey().endsWith(Constants.JSON_ASSOCIATION_LINK)) {
final LinkImpl link = new LinkImpl();
link.setTitle(getTitle(field));
link.setRel(Constants.NS_ASSOCIATION_LINK_REL + getTitle(field));
@@ -193,7 +163,7 @@ public class JsonDeserializer implements ODataDeserializer {
final JsonNode tree, final ObjectCodec codec) throws IOException {
if (field.getKey().endsWith(Constants.JSON_BIND_LINK_SUFFIX)
- || field.getKey().endsWith(jsonNavigationLink)) {
+ || field.getKey().endsWith(Constants.JSON_NAVIGATION_LINK)) {
if (field.getValue().isValueNode()) {
final String suffix = field.getKey().replaceAll("^.*@", "@");
@@ -280,7 +250,7 @@ public class JsonDeserializer implements ODataDeserializer {
if (annotatable != null) {
annotatable.getAnnotations().add(entityAnnot);
}
- } else if (type == null && field.getKey().endsWith(getJSONAnnotation(jsonType))) {
+ } else if (type == null && field.getKey().endsWith(getJSONAnnotation(Constants.JSON_TYPE))) {
type = field.getValue().asText();
} else if (annotation == null && customAnnotation.matches() && !"odata".equals(customAnnotation.group(2))) {
annotation = new AnnotationImpl();
@@ -354,8 +324,8 @@ public class JsonDeserializer implements ODataDeserializer {
values.add(child.asText());
}
} else if (child.isContainerNode()) {
- if (child.has(jsonType)) {
- ((ObjectNode) child).remove(jsonType);
+ if (child.has(Constants.JSON_TYPE)) {
+ ((ObjectNode) child).remove(Constants.JSON_TYPE);
}
final Object value = fromComplex((ObjectNode) child, codec);
valueType = ValueType.COLLECTION_COMPLEX;
@@ -387,9 +357,9 @@ public class JsonDeserializer implements ODataDeserializer {
break;
case COMPLEX:
- if (node.has(jsonType)) {
- valuable.setType(node.get(jsonType).asText());
- ((ObjectNode) node).remove(jsonType);
+ if (node.has(Constants.JSON_TYPE)) {
+ valuable.setType(node.get(Constants.JSON_TYPE).asText());
+ ((ObjectNode) node).remove(Constants.JSON_TYPE);
}
final Object value = fromComplex((ObjectNode) node, codec);
valuable.setValue(ValueType.COMPLEX, value);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5855c6b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java
index b63950b..228ac06 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntityDeserializer.java
@@ -82,7 +82,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
if (contextURL != null) {
entity.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
}
-
+
final String metadataETag;
if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) {
metadataETag = tree.get(Constants.JSON_METADATA_ETAG).textValue();
@@ -91,56 +91,57 @@ public class JsonEntityDeserializer extends JsonDeserializer {
metadataETag = null;
}
- if (tree.hasNonNull(jsonETag)) {
- entity.setETag(tree.get(jsonETag).textValue());
- tree.remove(jsonETag);
+ if (tree.hasNonNull(Constants.JSON_ETAG)) {
+ entity.setETag(tree.get(Constants.JSON_ETAG).textValue());
+ tree.remove(Constants.JSON_ETAG);
}
- if (tree.hasNonNull(jsonType)) {
- entity.setType(new EdmTypeInfo.Builder().setTypeExpression(tree.get(jsonType).textValue()).build().internal());
- tree.remove(jsonType);
+ if (tree.hasNonNull(Constants.JSON_TYPE)) {
+ entity.setType(new EdmTypeInfo.Builder().setTypeExpression(tree.get(Constants.JSON_TYPE).textValue()).build()
+ .internal());
+ tree.remove(Constants.JSON_TYPE);
}
- if (tree.hasNonNull(jsonId)) {
- entity.setId(URI.create(tree.get(jsonId).textValue()));
- tree.remove(jsonId);
+ if (tree.hasNonNull(Constants.JSON_ID)) {
+ entity.setId(URI.create(tree.get(Constants.JSON_ID).textValue()));
+ tree.remove(Constants.JSON_ID);
}
- if (tree.hasNonNull(jsonReadLink)) {
+ if (tree.hasNonNull(Constants.JSON_READ_LINK)) {
final LinkImpl link = new LinkImpl();
link.setRel(Constants.SELF_LINK_REL);
- link.setHref(tree.get(jsonReadLink).textValue());
+ link.setHref(tree.get(Constants.JSON_READ_LINK).textValue());
entity.setSelfLink(link);
- tree.remove(jsonReadLink);
+ tree.remove(Constants.JSON_READ_LINK);
}
- if (tree.hasNonNull(jsonEditLink)) {
+ if (tree.hasNonNull(Constants.JSON_EDIT_LINK)) {
final LinkImpl link = new LinkImpl();
if (serverMode) {
link.setRel(Constants.EDIT_LINK_REL);
}
- link.setHref(tree.get(jsonEditLink).textValue());
+ link.setHref(tree.get(Constants.JSON_EDIT_LINK).textValue());
entity.setEditLink(link);
- tree.remove(jsonEditLink);
+ tree.remove(Constants.JSON_EDIT_LINK);
}
- if (tree.hasNonNull(jsonMediaReadLink)) {
- entity.setMediaContentSource(URI.create(tree.get(jsonMediaReadLink).textValue()));
- tree.remove(jsonMediaReadLink);
+ if (tree.hasNonNull(Constants.JSON_MEDIA_READ_LINK)) {
+ entity.setMediaContentSource(URI.create(tree.get(Constants.JSON_MEDIA_READ_LINK).textValue()));
+ tree.remove(Constants.JSON_MEDIA_READ_LINK);
}
- if (tree.hasNonNull(jsonMediaEditLink)) {
- entity.setMediaContentSource(URI.create(tree.get(jsonMediaEditLink).textValue()));
- tree.remove(jsonMediaEditLink);
+ if (tree.hasNonNull(Constants.JSON_MEDIA_EDIT_LINK)) {
+ entity.setMediaContentSource(URI.create(tree.get(Constants.JSON_MEDIA_EDIT_LINK).textValue()));
+ tree.remove(Constants.JSON_MEDIA_EDIT_LINK);
}
- if (tree.hasNonNull(jsonMediaContentType)) {
- entity.setMediaContentType(tree.get(jsonMediaContentType).textValue());
- tree.remove(jsonMediaContentType);
+ if (tree.hasNonNull(Constants.JSON_MEDIA_CONTENT_TYPE)) {
+ entity.setMediaContentType(tree.get(Constants.JSON_MEDIA_CONTENT_TYPE).textValue());
+ tree.remove(Constants.JSON_MEDIA_CONTENT_TYPE);
}
- if (tree.hasNonNull(jsonMediaETag)) {
- entity.setMediaETag(tree.get(jsonMediaETag).textValue());
- tree.remove(jsonMediaETag);
+ if (tree.hasNonNull(Constants.JSON_MEDIA_ETAG)) {
+ entity.setMediaETag(tree.get(Constants.JSON_MEDIA_ETAG).textValue());
+ tree.remove(Constants.JSON_MEDIA_ETAG);
}
final Set<String> toRemove = new HashSet<String>();
@@ -151,7 +152,7 @@ public class JsonEntityDeserializer extends JsonDeserializer {
final Matcher customAnnotation = CUSTOM_ANNOTATION.matcher(field.getKey());
links(field, entity, toRemove, tree, parser.getCodec());
- if (field.getKey().endsWith(getJSONAnnotation(jsonMediaEditLink))) {
+ if (field.getKey().endsWith(getJSONAnnotation(Constants.JSON_MEDIA_EDIT_LINK))) {
final LinkImpl link = new LinkImpl();
link.setTitle(getTitle(field));
link.setRel(Constants.NS_MEDIA_EDIT_LINK_REL + getTitle(field));
@@ -159,14 +160,15 @@ public class JsonEntityDeserializer extends JsonDeserializer {
link.setType(ODataLinkType.MEDIA_EDIT.toString());
entity.getMediaEditLinks().add(link);
- if (tree.has(link.getTitle() + getJSONAnnotation(jsonMediaETag))) {
- link.setMediaETag(tree.get(link.getTitle() + getJSONAnnotation(jsonMediaETag)).asText());
- toRemove.add(link.getTitle() + getJSONAnnotation(jsonMediaETag));
+ if (tree.has(link.getTitle() + getJSONAnnotation(Constants.JSON_MEDIA_ETAG))) {
+ link.setMediaETag(tree.get(link.getTitle() + getJSONAnnotation(Constants.JSON_MEDIA_ETAG)).asText());
+ toRemove.add(link.getTitle() + getJSONAnnotation(Constants.JSON_MEDIA_ETAG));
}
toRemove.add(field.getKey());
- toRemove.add(setInline(field.getKey(), getJSONAnnotation(jsonMediaEditLink), tree, parser.getCodec(), link));
- } else if (field.getKey().endsWith(getJSONAnnotation(jsonMediaContentType))) {
+ toRemove.add(setInline(field.getKey(), getJSONAnnotation(Constants.JSON_MEDIA_EDIT_LINK), tree, parser
+ .getCodec(), link));
+ } else if (field.getKey().endsWith(getJSONAnnotation(Constants.JSON_MEDIA_CONTENT_TYPE))) {
final String linkTitle = getTitle(field);
for (Link link : entity.getMediaEditLinks()) {
if (linkTitle.equals(link.getTitle())) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5855c6b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java
index 00b807e..1e844b5 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySetDeserializer.java
@@ -79,17 +79,17 @@ public class JsonEntitySetDeserializer extends JsonDeserializer {
metadataETag = null;
}
- if (tree.hasNonNull(jsonCount)) {
- entitySet.setCount(tree.get(jsonCount).asInt());
- tree.remove(jsonCount);
+ if (tree.hasNonNull(Constants.JSON_COUNT)) {
+ entitySet.setCount(tree.get(Constants.JSON_COUNT).asInt());
+ tree.remove(Constants.JSON_COUNT);
}
- if (tree.hasNonNull(jsonNextLink)) {
- entitySet.setNext(URI.create(tree.get(jsonNextLink).textValue()));
- tree.remove(jsonNextLink);
+ if (tree.hasNonNull(Constants.JSON_NEXT_LINK)) {
+ entitySet.setNext(URI.create(tree.get(Constants.JSON_NEXT_LINK).textValue()));
+ tree.remove(Constants.JSON_NEXT_LINK);
}
- if (tree.hasNonNull(jsonDeltaLink)) {
- entitySet.setDeltaLink(URI.create(tree.get(jsonDeltaLink).textValue()));
- tree.remove(jsonDeltaLink);
+ if (tree.hasNonNull(Constants.JSON_DELTA_LINK)) {
+ entitySet.setDeltaLink(URI.create(tree.get(Constants.JSON_DELTA_LINK).textValue()));
+ tree.remove(Constants.JSON_DELTA_LINK);
}
if (tree.hasNonNull(Constants.VALUE)) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5855c6b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java
index 8e49a28..89252dc 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonODataErrorDeserializer.java
@@ -43,8 +43,8 @@ public class JsonODataErrorDeserializer extends JsonDeserializer {
final ODataError error = new ODataError();
final ObjectNode tree = parser.getCodec().readTree(parser);
- if (tree.has(jsonError)) {
- final JsonNode errorNode = tree.get(jsonError);
+ if (tree.has(Constants.JSON_ERROR)) {
+ final JsonNode errorNode = tree.get(Constants.JSON_ERROR);
if (errorNode.has(Constants.ERROR_CODE)) {
error.setCode(errorNode.get(Constants.ERROR_CODE).textValue());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5855c6b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java
index 9a9498e..e0732d5 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonPropertyDeserializer.java
@@ -75,9 +75,10 @@ public class JsonPropertyDeserializer extends JsonDeserializer {
contextURL = null;
}
- if (tree.has(jsonType)) {
- property.setType(new EdmTypeInfo.Builder().setTypeExpression(tree.get(jsonType).textValue()).build().internal());
- tree.remove(jsonType);
+ if (tree.has(Constants.JSON_TYPE)) {
+ property.setType(new EdmTypeInfo.Builder().setTypeExpression(tree.get(Constants.JSON_TYPE).textValue()).build()
+ .internal());
+ tree.remove(Constants.JSON_TYPE);
}
if (tree.has(Constants.JSON_NULL) && tree.get(Constants.JSON_NULL).asBoolean()) {
[03/50] [abbrv] olingo-odata4 git commit: [OLINGO-575] Star deleting
unnecessary abstract edm classes
Posted by ch...@apache.org.
[OLINGO-575] Star deleting unnecessary abstract edm classes
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/3a6293b6
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/3a6293b6
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/3a6293b6
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 3a6293b6a594a43980262e67951a30ad1d3cee56
Parents: 0092176
Author: Christian Amend <ch...@apache.org>
Authored: Wed Mar 25 14:48:26 2015 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Wed Mar 25 14:48:26 2015 +0100
----------------------------------------------------------------------
.../proxy/commons/InvokerInvocationHandler.java | 2 +-
.../commons/OperationInvocationHandler.java | 2 +-
...turedComposableInvokerInvocationHandler.java | 3 +-
.../olingo/ext/proxy/utils/CoreUtils.java | 2 +-
.../olingo/ext/pojogen/AbstractUtility.java | 3 +-
.../java/org/apache/olingo/fit/V4Services.java | 2 +-
.../core/serialization/ODataBinderImpl.java | 2 +-
.../commons/api/edm/EdmEntitySetInfo.java | 46 ----
.../commons/api/edm/EdmFunctionImportInfo.java | 40 ---
.../commons/api/edm/EdmSingletonInfo.java | 45 ----
.../core/edm/AbstractEdmBindingTarget.java | 109 ---------
.../core/edm/AbstractEdmComplexType.java | 67 -----
.../core/edm/AbstractEdmEntityContainer.java | 192 ---------------
.../commons/core/edm/AbstractEdmEntityType.java | 129 ----------
.../commons/core/edm/AbstractEdmEnumType.java | 222 -----------------
.../core/edm/AbstractEdmKeyPropertyRef.java | 77 ------
.../commons/core/edm/AbstractEdmMember.java | 58 -----
.../core/edm/AbstractEdmNavigationProperty.java | 88 -------
.../commons/core/edm/AbstractEdmOperation.java | 117 ---------
.../core/edm/AbstractEdmOperationImport.java | 83 -------
.../commons/core/edm/AbstractEdmParameter.java | 49 ----
.../commons/core/edm/AbstractEdmProperty.java | 68 ------
.../edm/AbstractEdmReferentialConstraint.java | 43 ----
.../commons/core/edm/AbstractEdmReturnType.java | 49 ----
.../commons/core/edm/AbstractEdmSchema.java | 197 ---------------
.../core/edm/AbstractEdmStructuredType.java | 152 ------------
.../core/edm/AbstractEdmTypeDefinition.java | 127 ----------
.../core/edm/EdmActionImportInfoImpl.java | 45 ----
.../commons/core/edm/EdmAnnotationHelper.java | 25 --
.../olingo/commons/core/edm/EdmElementImpl.java | 29 ---
.../commons/core/edm/EdmEntitySetInfoImpl.java | 52 ----
.../core/edm/EdmFunctionImportInfoImpl.java | 45 ----
.../olingo/commons/core/edm/EdmNamedImpl.java | 39 ---
.../edm/EdmNavigationPropertyBindingImpl.java | 43 ----
.../core/edm/EdmOperationImportInfoImpl.java | 36 ---
.../commons/core/edm/EdmSingletonInfoImpl.java | 52 ----
.../core/edm/EdmStructuredTypeHelper.java | 35 ---
.../olingo/commons/core/edm/EdmTypeImpl.java | 52 ----
.../olingo/commons/core/edm/EdmTypeInfo.java | 244 -------------------
.../core/edm/annotation/EdmCastImpl.java | 2 +-
.../core/edm/annotation/EdmIsOfImpl.java | 2 +-
.../core/edm/annotation/EdmRecordImpl.java | 2 +-
.../core/edm/provider/EdmAnnotationHelper.java | 24 ++
.../edm/provider/EdmAnnotationHelperImpl.java | 1 -
.../core/edm/provider/EdmAnnotationImpl.java | 1 -
.../core/edm/provider/EdmBindingTargetImpl.java | 84 ++++++-
.../core/edm/provider/EdmComplexTypeImpl.java | 48 +++-
.../core/edm/provider/EdmElementImpl.java | 29 +++
.../edm/provider/EdmEntityContainerImpl.java | 149 ++++++++++-
.../core/edm/provider/EdmEntityTypeImpl.java | 101 +++++++-
.../core/edm/provider/EdmEnumTypeImpl.java | 179 +++++++++++++-
.../edm/provider/EdmKeyPropertyRefImpl.java | 46 +++-
.../core/edm/provider/EdmMemberImpl.java | 31 ++-
.../commons/core/edm/provider/EdmNamedImpl.java | 39 +++
.../EdmNavigationPropertyBindingImpl.java | 43 ++++
.../edm/provider/EdmNavigationPropertyImpl.java | 66 +++--
.../core/edm/provider/EdmOperationImpl.java | 78 +++++-
.../edm/provider/EdmOperationImportImpl.java | 57 ++++-
.../core/edm/provider/EdmParameterImpl.java | 24 +-
.../core/edm/provider/EdmPropertyImpl.java | 37 ++-
.../provider/EdmReferentialConstraintImpl.java | 19 +-
.../core/edm/provider/EdmReturnTypeImpl.java | 25 +-
.../core/edm/provider/EdmSchemaImpl.java | 139 ++++++++++-
.../edm/provider/EdmStructuredTypeHelper.java | 35 +++
.../provider/EdmStructuredTypeHelperImpl.java | 1 -
.../edm/provider/EdmStructuredTypeImpl.java | 152 ++++++++++++
.../commons/core/edm/provider/EdmTermImpl.java | 3 -
.../edm/provider/EdmTypeDefinitionImpl.java | 97 +++++++-
.../commons/core/edm/provider/EdmTypeImpl.java | 52 ++++
.../commons/core/edm/provider/EdmTypeInfo.java | 244 +++++++++++++++++++
.../core/serialization/AtomDeserializer.java | 2 +-
.../core/serialization/AtomSerializer.java | 2 +-
.../core/serialization/JsonDeserializer.java | 2 +-
.../serialization/JsonEntityDeserializer.java | 2 +-
.../serialization/JsonEntitySerializer.java | 2 +-
.../serialization/JsonGeoValueDeserializer.java | 2 +-
.../serialization/JsonPropertyDeserializer.java | 2 +-
.../serialization/JsonPropertySerializer.java | 2 +-
.../core/serialization/JsonSerializer.java | 2 +-
.../core/edm/provider/EdmNamedImplTest.java | 2 +-
.../core/edm/provider/EdmTypeImplTest.java | 2 +-
81 files changed, 1698 insertions(+), 2805 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerInvocationHandler.java
index 44a2d30..5d2dcdd 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/InvokerInvocationHandler.java
@@ -44,7 +44,7 @@ import org.apache.olingo.commons.api.edm.EdmOperation;
import org.apache.olingo.commons.api.edm.EdmReturnType;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.http.HttpMethod;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import org.apache.olingo.ext.proxy.AbstractService;
import org.apache.olingo.ext.proxy.api.ComplexCollection;
import org.apache.olingo.ext.proxy.api.EntityCollection;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
index 73daaf3..90873b4 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
@@ -39,7 +39,7 @@ import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmFunction;
import org.apache.olingo.commons.api.edm.EdmOperation;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import org.apache.olingo.ext.proxy.api.OperationType;
import org.apache.olingo.ext.proxy.api.annotations.Operation;
import org.apache.olingo.ext.proxy.api.annotations.Parameter;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/StructuredComposableInvokerInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/StructuredComposableInvokerInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/StructuredComposableInvokerInvocationHandler.java
index 64e00c9..9adbd05 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/StructuredComposableInvokerInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/StructuredComposableInvokerInvocationHandler.java
@@ -22,10 +22,11 @@ import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.Map;
+
import org.apache.commons.lang3.ArrayUtils;
import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.edm.EdmOperation;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import org.apache.olingo.ext.proxy.AbstractService;
import org.apache.olingo.ext.proxy.api.Operations;
import org.apache.olingo.ext.proxy.api.annotations.Operation;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
index 65af8d6..682fc38 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
@@ -56,8 +56,8 @@ import org.apache.olingo.commons.api.edm.EdmTerm;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.core.domain.ODataAnnotationImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import org.apache.olingo.ext.proxy.AbstractService;
import org.apache.olingo.ext.proxy.api.AbstractTerm;
import org.apache.olingo.ext.proxy.api.ComplexCollection;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java
index 16e4402..2e0ef80 100644
--- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java
+++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java
@@ -35,8 +35,8 @@ import org.apache.olingo.commons.api.edm.EdmSingleton;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import java.io.InputStream;
import java.util.ArrayList;
@@ -47,6 +47,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
public abstract class AbstractUtility {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/fit/src/main/java/org/apache/olingo/fit/V4Services.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
index 0b4f6bd..fe9465e 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
@@ -38,7 +38,7 @@ import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.LinkImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import org.apache.olingo.fit.metadata.Metadata;
import org.apache.olingo.fit.methods.PATCH;
import org.apache.olingo.fit.rest.ResolvingReferencesInterceptor;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
index 46acddb..e74e3fa 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/ODataBinderImpl.java
@@ -97,8 +97,8 @@ import org.apache.olingo.commons.core.domain.ODataAnnotationImpl;
import org.apache.olingo.commons.core.domain.ODataDeletedEntityImpl;
import org.apache.olingo.commons.core.domain.ODataDeltaLinkImpl;
import org.apache.olingo.commons.core.domain.ODataPropertyImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.provider.EdmTypeInfo;
import org.apache.olingo.commons.core.serialization.ContextURLParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntitySetInfo.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntitySetInfo.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntitySetInfo.java
deleted file mode 100644
index 09c428a..0000000
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntitySetInfo.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.net.URI;
-
-/**
- * Objects of this class contain information about one entity set inside the EntityDataModel.
- */
-public interface EdmEntitySetInfo {
-
- /**
- * @return the entity container name which contains this entity set.
- */
- String getEntityContainerName();
-
- /**
- * @return the entity set name
- */
- String getEntitySetName();
-
- /**
- * We use a {@link URI} object here to ensure the right encoding. If a string representation is needed the
- * toASCIIString() method can be used.
- *
- * @return the uri to this entity set e.g. "Employees"
- */
- URI getEntitySetUri();
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImportInfo.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImportInfo.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImportInfo.java
deleted file mode 100644
index 64491ec..0000000
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmFunctionImportInfo.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.net.URI;
-
-/**
- * Objects of this class contain information about one function import inside the EntityDataModel.
- */
-public interface EdmFunctionImportInfo extends EdmOperationImportInfo {
-
- /**
- * @return the function import name
- */
- String getFunctionImportName();
-
- /**
- * We use a {@link URI} object here to ensure the right encoding. If a string representation is needed the
- * toASCIIString() method can be used.
- *
- * @return the uri to this function import
- */
- URI getFunctionImportUri();
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSingletonInfo.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSingletonInfo.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSingletonInfo.java
deleted file mode 100644
index 2cb3ee3..0000000
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmSingletonInfo.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.net.URI;
-
-/**
- * Objects of this class contain information about one singleton inside the EntityDataModel.
- */
-public interface EdmSingletonInfo {
-
- /**
- * @return the entity container name which contains this singleton.
- */
- String getEntityContainerName();
-
- /**
- * @return the singleton name
- */
- String getSingletonName();
-
- /**
- * We use a {@link URI} object here to ensure the right encoding. If a string representation is needed the
- * toASCIIString() method can be used.
- *
- * @return the uri to this singleton e.g. "EmployeeOfTheMonth"
- */
- URI getEntitySetUri();
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java
deleted file mode 100644
index d3d9bf6..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
-
-import java.util.Iterator;
-
-public abstract class AbstractEdmBindingTarget extends EdmNamedImpl implements EdmBindingTarget {
-
- protected final EdmEntityContainer container;
-
- private final FullQualifiedName type;
-
- public AbstractEdmBindingTarget(final Edm edm, final EdmEntityContainer container,
- final String name, final FullQualifiedName type) {
-
- super(edm, name);
- this.container = container;
- this.type = type;
- }
-
- @Override
- public EdmEntityContainer getEntityContainer() {
- return container;
- }
-
- @Override
- public EdmEntityType getEntityType() {
- final EdmEntityType entityType = edm.getEntityType(type);
- if (entityType == null) {
- throw new EdmException("Can´t find entity type: " + type + " for entity set or singleton: " + getName());
- }
- return entityType;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return container.getFullQualifiedName();
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return getName();
- }
-
- @Override
- public EdmBindingTarget getRelatedBindingTarget(final String path) {
- if(path == null){
- return null;
- }
- EdmBindingTarget bindingTarget = null;
- boolean found = false;
- for (final Iterator<EdmNavigationPropertyBinding> itor = getNavigationPropertyBindings().iterator(); itor.hasNext()
- && !found;) {
-
- final EdmNavigationPropertyBinding binding = itor.next();
- if (path.startsWith(binding.getPath())) {
- final Target edmTarget = new Target.Builder(binding.getTarget(), container).build();
-
- final EdmEntityContainer entityContainer = edm.getEntityContainer(edmTarget.getEntityContainer());
- if (entityContainer == null) {
- throw new EdmException("Cannot find entity container with name: " + edmTarget.getEntityContainer());
- }
- try {
- bindingTarget = entityContainer.getEntitySet(edmTarget.getTargetName());
-
- if (bindingTarget == null) {
- throw new EdmException("Cannot find EntitySet " + edmTarget.getTargetName());
- }
- } catch (EdmException e) {
- // try with singletons ...
- bindingTarget = entityContainer.getSingleton(edmTarget.getTargetName());
-
- if (bindingTarget == null) {
- throw new EdmException("Cannot find Singleton " + edmTarget.getTargetName());
- }
- } finally {
- found = bindingTarget != null;
- }
- }
- }
-
- return bindingTarget;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmComplexType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmComplexType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmComplexType.java
deleted file mode 100644
index 642bbc1..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmComplexType.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmComplexType;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-
-public abstract class AbstractEdmComplexType extends AbstractEdmStructuredType implements EdmComplexType {
-
- public AbstractEdmComplexType(
- final Edm edm,
- final FullQualifiedName typeName,
- final FullQualifiedName baseTypeName) {
- super(edm, typeName, EdmTypeKind.COMPLEX, baseTypeName);
- }
-
- @Override
- protected EdmStructuredType buildBaseType(final FullQualifiedName baseTypeName) {
- EdmComplexType baseType = null;
- if (baseTypeName != null) {
- baseType = edm.getComplexType(baseTypeName);
- if (baseType == null) {
- throw new EdmException("Can't find base type with name: " + baseTypeName + " for complex type: "
- + getName());
- }
- }
- return baseType;
- }
-
- @Override
- public EdmComplexType getBaseType() {
- checkBaseType();
- return (EdmComplexType) baseType;
- }
-
- @Override
- protected void checkBaseType() {
- if (baseTypeName != null && baseType == null) {
- baseType = buildBaseType(baseTypeName);
- }
- }
-
- @Override
- public TargetType getAnnotationsTargetType() {
- return TargetType.ComplexType;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java
deleted file mode 100644
index c1dd630..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmActionImport;
-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.commons.api.edm.FullQualifiedName;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements EdmEntityContainer {
-
- protected final FullQualifiedName entityContainerName;
-
- protected final Map<String, EdmSingleton> singletons = new HashMap<String, EdmSingleton>();
-
- private boolean allSingletonsLoaded = false;
-
- protected final Map<String, EdmEntitySet> entitySets = new HashMap<String, EdmEntitySet>();
-
- private boolean allEntitySetsLoaded = false;
-
- protected final Map<String, EdmActionImport> actionImports = new HashMap<String, EdmActionImport>();
-
- private final FullQualifiedName parentContainerName;
-
- private boolean allActionImportsLoaded = false;
-
- protected final Map<String, EdmFunctionImport> functionImports = new HashMap<String, EdmFunctionImport>();
-
- private boolean allFunctionImportsLoaded = false;
-
- public AbstractEdmEntityContainer(final Edm edm, final FullQualifiedName entityContainerName,
- final FullQualifiedName parentContainerName) {
- super(edm, entityContainerName.getName());
- this.entityContainerName = entityContainerName;
- this.parentContainerName = parentContainerName;
- }
-
- @Override
- public String getNamespace() {
- return entityContainerName.getNamespace();
- }
-
- @Override
- public FullQualifiedName getFullQualifiedName() {
- return new FullQualifiedName(getNamespace(), getName());
- }
-
- protected abstract EdmSingleton createSingleton(String singletonName);
-
- @Override
- public EdmSingleton getSingleton(final String singletonName) {
- EdmSingleton singleton = singletons.get(singletonName);
- if (singleton == null) {
- singleton = createSingleton(singletonName);
- if (singleton != null) {
- singletons.put(singletonName, singleton);
- }
- }
- return singleton;
- }
-
- protected abstract EdmEntitySet createEntitySet(String entitySetName);
-
- @Override
- public EdmEntitySet getEntitySet(final String entitySetName) {
- EdmEntitySet entitySet = entitySets.get(entitySetName);
- if (entitySet == null) {
- entitySet = createEntitySet(entitySetName);
- if (entitySet != null) {
- entitySets.put(entitySetName, entitySet);
- }
- }
- return entitySet;
- }
-
- protected abstract EdmActionImport createActionImport(String actionImportName);
-
- @Override
- public EdmActionImport getActionImport(final String actionImportName) {
- EdmActionImport actionImport = actionImports.get(actionImportName);
- if (actionImport == null) {
- actionImport = createActionImport(actionImportName);
- if (actionImport != null) {
- actionImports.put(actionImportName, actionImport);
- }
- }
- return actionImport;
- }
-
- protected abstract EdmFunctionImport createFunctionImport(String functionImportName);
-
- @Override
- public EdmFunctionImport getFunctionImport(final String functionImportName) {
- EdmFunctionImport functionImport = functionImports.get(functionImportName);
- if (functionImport == null) {
- functionImport = createFunctionImport(functionImportName);
- if (functionImport != null) {
- functionImports.put(functionImportName, functionImport);
- }
- }
- 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();
-
- @Override
- public FullQualifiedName getParentContainerName() {
- return parentContainerName;
- }
-
- @Override
- public TargetType getAnnotationsTargetType() {
- return TargetType.EntityContainer;
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return null;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return getFullQualifiedName();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityType.java
deleted file mode 100644
index 6263047..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityType.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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 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.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public abstract class AbstractEdmEntityType extends AbstractEdmStructuredType implements EdmEntityType {
-
- private final boolean hasStream;
-
- protected EdmEntityType entityBaseType;
-
- private final List<String> keyPredicateNames = new ArrayList<String>();
-
- private final Map<String, EdmKeyPropertyRef> keyPropertyRefs = new LinkedHashMap<String, EdmKeyPropertyRef>();
-
- private List<EdmKeyPropertyRef> keyPropertyRefsList;
-
- protected AbstractEdmEntityType(final Edm edm, final FullQualifiedName typeName,
- final FullQualifiedName baseTypeName,
- final boolean hashStream) {
-
- super(edm, typeName, EdmTypeKind.ENTITY, baseTypeName);
- hasStream = hashStream;
- }
-
- protected void setEdmKeyPropertyRef(final List<EdmKeyPropertyRef> edmKey) {
- for (EdmKeyPropertyRef ref : edmKey) {
- if (ref.getAlias() == null) {
- keyPredicateNames.add(ref.getName());
- keyPropertyRefs.put(ref.getName(), ref);
- } else {
- keyPredicateNames.add(ref.getAlias());
- keyPropertyRefs.put(ref.getAlias(), ref);
- }
- }
- }
-
- @Override
- protected EdmStructuredType buildBaseType(final FullQualifiedName baseTypeName) {
- EdmEntityType baseType = null;
- if (baseTypeName != null) {
- baseType = edm.getEntityType(baseTypeName);
- if (baseType == null) {
- throw new EdmException("Cannot find base type with name: " + baseTypeName + " for entity type: " + getName());
- }
- }
- return baseType;
- }
-
- @Override
- public EdmEntityType getBaseType() {
- checkBaseType();
- return entityBaseType;
- }
-
- @Override
- public List<String> getKeyPredicateNames() {
- checkBaseType();
- if (keyPredicateNames.isEmpty() && baseType != null) {
- return entityBaseType.getKeyPredicateNames();
- }
- return keyPredicateNames;
- }
-
- @Override
- public List<EdmKeyPropertyRef> getKeyPropertyRefs() {
- checkBaseType();
- if (keyPropertyRefsList == null) {
- keyPropertyRefsList = new ArrayList<EdmKeyPropertyRef>(keyPropertyRefs.values());
- }
- if (keyPropertyRefsList.isEmpty() && entityBaseType != null) {
- return entityBaseType.getKeyPropertyRefs();
- }
- return keyPropertyRefsList;
- }
-
- @Override
- public EdmKeyPropertyRef getKeyPropertyRef(final String keyPredicateName) {
- checkBaseType();
- final EdmKeyPropertyRef edmKeyPropertyRef = keyPropertyRefs.get(keyPredicateName);
- if (edmKeyPropertyRef == null && entityBaseType != null) {
- return entityBaseType.getKeyPropertyRef(keyPredicateName);
- }
- return edmKeyPropertyRef;
- }
-
- @Override
- public boolean hasStream() {
- return hasStream;
- }
-
- @Override
- protected void checkBaseType() {
- // Current Client implementation doesn`t need this so I implemented an empty body here.
- }
-
- @Override
- public TargetType getAnnotationsTargetType() {
- return TargetType.EntityType;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java
deleted file mode 100644
index 549980f..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEnumType.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * 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 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;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnumType {
-
- private final boolean isFlags;
-
- private final String uriPrefix;
-
- private final String uriSuffix;
-
- private List<String> memberNames;
-
- private Map<String, EdmMember> members;
-
- public AbstractEdmEnumType(final Edm edm, final FullQualifiedName fqn, final boolean isFlags) {
- super(edm, fqn, EdmTypeKind.ENUM);
-
- this.isFlags = isFlags;
- uriPrefix = fqn.getFullQualifiedNameAsString() + '\'';
- uriSuffix = "'";
- }
-
- protected abstract Collection<EdmMember> getMembers();
-
- @Override
- public EdmMember getMember(final String name) {
- if (members == null) {
- members = new LinkedHashMap<String, EdmMember>();
- for (final EdmMember member : getMembers()) {
- members.put(member.getName(), member);
- }
- }
- return members.get(name);
- }
-
- @Override
- public List<String> getMemberNames() {
- if (memberNames == null) {
- memberNames = new ArrayList<String>();
- for (final EdmMember member : getMembers()) {
- memberNames.add(member.getName());
- }
- }
- return memberNames;
- }
-
- @Override
- public abstract EdmPrimitiveType getUnderlyingType();
-
- @Override
- public boolean isCompatible(final EdmPrimitiveType primitiveType) {
- return equals(primitiveType);
- }
-
- @Override
- public Class<?> getDefaultType() {
- return getUnderlyingType().getDefaultType();
- }
-
- @Override
- public boolean validate(final String value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale, final Boolean isUnicode) {
-
- try {
- valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, getDefaultType());
- return true;
- } catch (final EdmPrimitiveTypeException e) {
- return false;
- }
- }
-
- private Long parseEnumValue(final String value) throws EdmPrimitiveTypeException {
- Long result = null;
- for (final String memberValue : value.split(",", isFlags ? -1 : 1)) {
- Long memberValueLong = null;
- for (final EdmMember member : getMembers()) {
- if (member.getName().equals(memberValue) || member.getValue().equals(memberValue)) {
- memberValueLong = Long.decode(member.getValue());
- }
- }
- if (memberValueLong == null) {
- throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
- }
- result = result == null ? memberValueLong : result | memberValueLong;
- }
- return result;
- }
-
- @Override
- public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
- throws EdmPrimitiveTypeException {
-
- if (value == null) {
- if (isNullable != null && !isNullable) {
- throw new EdmPrimitiveTypeException("The literal 'null' is not allowed.");
- }
- return null;
- }
-
- try {
- return EdmInt64.convertNumber(parseEnumValue(value), returnType);
- } catch (final IllegalArgumentException e) {
- throw new EdmPrimitiveTypeException("The literal '" + value
- + "' cannot be converted to value type " + returnType + ".", e);
- } catch (final ClassCastException e) {
- throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
- }
- }
-
- protected String constructEnumValue(final long value) throws EdmPrimitiveTypeException {
- long remaining = value;
- StringBuilder result = new StringBuilder();
-
- for (final EdmMember member : getMembers()) {
- final long memberValue = Long.parseLong(member.getValue());
- if ((memberValue & remaining) == memberValue) {
- if (result.length() > 0) {
- result.append(',');
- }
- result.append(member.getName());
- remaining ^= memberValue;
- }
- }
-
- if (remaining != 0) {
- throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
- }
- return result.toString();
- }
-
- @Override
- public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
-
- if (value == null) {
- if (isNullable != null && !isNullable) {
- throw new EdmPrimitiveTypeException("The value NULL is not allowed.");
- }
- return null;
- }
- if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
- return constructEnumValue(((Number) value).longValue());
- } else {
- throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
- }
- }
-
- @Override
- public String toUriLiteral(final String literal) {
- return literal == null ? null
- : uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix;
- }
-
- @Override
- public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
- if (literal == null) {
- return null;
- } else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) {
- return literal;
- } else if (literal.length() >= uriPrefix.length() + uriSuffix.length()
- && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) {
- return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
- } else {
- throw new EdmPrimitiveTypeException("The literal '" + literal + "' has illegal content.");
- }
- }
-
- @Override
- public boolean isFlags() {
- return isFlags;
- }
-
- @Override
- public TargetType getAnnotationsTargetType() {
- return TargetType.EnumType;
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return null;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return getFullQualifiedName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmKeyPropertyRef.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmKeyPropertyRef.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmKeyPropertyRef.java
deleted file mode 100644
index 05af9cb..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmKeyPropertyRef.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 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.EdmProperty;
-import org.apache.olingo.commons.api.edm.EdmStructuredType;
-
-public abstract class AbstractEdmKeyPropertyRef implements EdmKeyPropertyRef {
-
- private final EdmEntityType edmEntityType;
-
- private EdmProperty property;
-
- public AbstractEdmKeyPropertyRef(final EdmEntityType edmEntityType) {
- this.edmEntityType = edmEntityType;
- }
-
- @Override
- public abstract String getName();
-
- @Override
- public abstract String getAlias();
-
- @Override
- public EdmProperty getProperty() {
- if (property == null) {
- if (getAlias() == null) {
- property = edmEntityType.getStructuralProperty(getName());
- if (property == null) {
- throw new EdmException("Invalid key property ref specified. Can´t find property with name: "
- + getName());
- }
- } else {
- if (getName() == null || getName().isEmpty()) {
- throw new EdmException("Alias but no path specified for propertyRef");
- }
- final String[] splitPath = getName().split("/");
- EdmStructuredType structType = edmEntityType;
- for (int i = 0; i < splitPath.length - 1; i++) {
- final EdmProperty _property = structType.getStructuralProperty(splitPath[i]);
- if (_property == null) {
- throw new EdmException("Invalid property ref specified. Can´t find property with name: " + splitPath[i]
- + " at type: " + structType.getNamespace() + "." + structType.getName());
- }
- structType = (EdmStructuredType) _property.getType();
- }
- property = structType.getStructuralProperty(splitPath[splitPath.length - 1]);
- if (property == null) {
- throw new EdmException("Invalid property ref specified. Can´t find property with name: "
- + splitPath[splitPath.length - 1] + " at type: " + structType.getNamespace() + "."
- + structType.getName());
- }
- }
- }
-
- return property;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmMember.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmMember.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmMember.java
deleted file mode 100644
index 913f26d..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmMember.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmMember;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-
-public abstract class AbstractEdmMember extends EdmNamedImpl implements EdmMember {
-
- private final String value;
-
- private final FullQualifiedName enumFQN;
-
- public AbstractEdmMember(final Edm edm, final FullQualifiedName enumFQN, final String name, final String value) {
- super(edm, name);
-
- this.enumFQN = enumFQN;
- this.value = value;
- }
-
- @Override
- public TargetType getAnnotationsTargetType() {
- return TargetType.Member;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return enumFQN;
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return getName();
- }
-
- @Override
- public String getValue() {
- return value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java
deleted file mode 100644
index 1382389..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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 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.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-
-public abstract class AbstractEdmNavigationProperty extends EdmElementImpl implements EdmNavigationProperty {
-
- private EdmEntityType typeImpl;
-
- private EdmNavigationProperty partnerNavigationProperty;
-
- public AbstractEdmNavigationProperty(final Edm edm, final String name) {
- super(edm, name);
- }
-
- protected abstract FullQualifiedName getTypeFQN();
-
- @Override
- public EdmEntityType getType() {
- if (typeImpl == null) {
- typeImpl = edm.getEntityType(getTypeFQN());
- if (typeImpl == null) {
- throw new EdmException("Cannot find type with name: " + getTypeFQN());
- }
- }
- return typeImpl;
- }
-
- protected abstract String internatGetPartner();
-
- @Override
- public EdmNavigationProperty getPartner() {
- if (partnerNavigationProperty == null) {
- String partner = internatGetPartner();
- if (partner != null) {
- EdmStructuredType type = getType();
- EdmNavigationProperty property = null;
- final String[] split = partner.split("/");
- for (String element : split) {
- property = type.getNavigationProperty(element);
- if (property == null) {
- throw new EdmException("Cannot find navigation property with name: " + element
- + " at type " + type.getName());
- }
- type = property.getType();
- }
- partnerNavigationProperty = property;
- }
- }
- return partnerNavigationProperty;
- }
-
- @Override
- public abstract String getReferencingPropertyName(String referencedPropertyName);
-
- @Override
- public TargetType getAnnotationsTargetType() {
- return TargetType.NavigationProperty;
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmOperation.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmOperation.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmOperation.java
deleted file mode 100644
index dd7ae81..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmOperation.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmOperation;
-import org.apache.olingo.commons.api.edm.EdmParameter;
-import org.apache.olingo.commons.api.edm.EdmReturnType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public abstract class AbstractEdmOperation extends EdmTypeImpl implements EdmOperation {
-
- private final Map<String, EdmParameter> parameters = new LinkedHashMap<String, EdmParameter>();
-
- private String entitySetPath;
-
- private boolean isBound;
-
- private EdmReturnType returnType;
-
- private List<String> parameterNames;
-
- protected AbstractEdmOperation(
- final Edm edm,
- final FullQualifiedName fqn,
- final EdmTypeKind kind) {
-
- super(edm, fqn, kind);
- }
-
- protected void setParameters(final List<EdmParameter> _parameters) {
- for (EdmParameter parameter : _parameters) {
- parameters.put(parameter.getName(), parameter);
- }
- }
-
- protected void setEntitySetPath(final String entitySetPath) {
- this.entitySetPath = entitySetPath;
- }
-
- protected void setIsBound(final boolean isBound) {
- this.isBound = isBound;
- }
-
- protected void setReturnType(final EdmReturnType returnType) {
- this.returnType = returnType;
- }
-
- @Override
- public EdmParameter getParameter(final String name) {
- return parameters.get(name);
- }
-
- @Override
- public List<String> getParameterNames() {
- if (parameterNames == null) {
- parameterNames = new ArrayList<String>(parameters.size());
- for (String parameterName : parameters.keySet()) {
- parameterNames.add(parameterName);
- }
- }
- return parameterNames;
- }
-
- @Override
- public EdmEntitySet getReturnedEntitySet(final EdmEntitySet bindingParameterEntitySet) {
- EdmEntitySet returnedEntitySet = null;
- if (bindingParameterEntitySet != null && entitySetPath != null) {
- final EdmBindingTarget relatedBindingTarget = bindingParameterEntitySet.getRelatedBindingTarget(entitySetPath);
- if (relatedBindingTarget == null) {
- throw new EdmException("Cannot find entity set with path: " + entitySetPath);
- }
- if (relatedBindingTarget instanceof EdmEntitySet) {
- returnedEntitySet = (EdmEntitySet) relatedBindingTarget;
- } else {
- throw new EdmException("BindingTarget with name: " + relatedBindingTarget.getName()
- + " must be an entity set");
- }
- }
- return returnedEntitySet;
- }
-
- @Override
- public EdmReturnType getReturnType() {
- return returnType;
- }
-
- @Override
- public boolean isBound() {
- return isBound;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmOperationImport.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmOperationImport.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmOperationImport.java
deleted file mode 100644
index db05f8b..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmOperationImport.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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 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.EdmException;
-import org.apache.olingo.commons.api.edm.EdmOperationImport;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.Target;
-
-public abstract class AbstractEdmOperationImport extends EdmNamedImpl implements EdmOperationImport {
-
- protected final EdmEntityContainer container;
-
- private final Target entitySet;
-
- private EdmEntitySet returnedEntitySet;
-
- public AbstractEdmOperationImport(
- final Edm edm,
- final EdmEntityContainer container,
- final String name,
- final Target entitySet) {
-
- super(edm, name);
- this.container = container;
- this.entitySet = entitySet;
- }
-
- @Override
- public FullQualifiedName getFullQualifiedName() {
- return new FullQualifiedName(container.getNamespace(), getName());
- }
-
- @Override
- public EdmEntitySet getReturnedEntitySet() {
- if (entitySet != null && returnedEntitySet == null) {
- EdmEntityContainer entityContainer = edm.getEntityContainer(entitySet.getEntityContainer());
- if (entityContainer == null) {
- throw new EdmException("Can´t find entity container with name: " + entitySet.getEntityContainer());
- }
- returnedEntitySet = entityContainer.getEntitySet(entitySet.getTargetName());
- if (returnedEntitySet == null) {
- throw new EdmException("Can´t find entity set with name: " + entitySet.getTargetName());
- }
- }
- return returnedEntitySet;
- }
-
- @Override
- public EdmEntityContainer getEntityContainer() {
- return container;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return container.getFullQualifiedName();
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmParameter.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmParameter.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmParameter.java
deleted file mode 100644
index 0264573..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmParameter.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmParameter;
-import org.apache.olingo.commons.api.edm.EdmType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-
-public abstract class AbstractEdmParameter extends EdmElementImpl implements EdmParameter {
-
- private final EdmTypeInfo typeInfo;
-
- private EdmType typeImpl;
-
- public AbstractEdmParameter(final Edm edm, final String name, final FullQualifiedName paramType) {
- super(edm, name);
- typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(paramType.toString()).build();
- }
-
- @Override
- public EdmType getType() {
- if (typeImpl == null) {
- typeImpl = typeInfo.getType();
- if (typeImpl == null) {
- throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
- }
- }
-
- return typeImpl;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmProperty.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmProperty.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmProperty.java
deleted file mode 100644
index cf3440e..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmProperty.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.EdmType;
-
-public abstract class AbstractEdmProperty extends EdmElementImpl implements EdmProperty {
-
- private EdmType propertyType;
-
- public AbstractEdmProperty(final Edm edm, final String name) {
- super(edm, name);
- }
-
- protected abstract EdmTypeInfo getTypeInfo();
-
- @Override
- public boolean isPrimitive() {
- return getTypeInfo().isPrimitiveType();
- }
-
- @Override
- public EdmType getType() {
- if (propertyType == null) {
- propertyType = getTypeInfo().getType();
- if (propertyType == null) {
- throw new EdmException("Cannot find type with name: " + getTypeInfo().getFullQualifiedName());
- }
- }
-
- return propertyType;
- }
-
- @Override
- public boolean isCollection() {
- return getTypeInfo().isCollection();
- }
-
- @Override
- public TargetType getAnnotationsTargetType() {
- return TargetType.Property;
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReferentialConstraint.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReferentialConstraint.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReferentialConstraint.java
deleted file mode 100644
index 1116af3..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReferentialConstraint.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmReferentialConstraint;
-
-public abstract class AbstractEdmReferentialConstraint implements EdmReferentialConstraint {
-
- private final String property;
-
- private final String referencedProperty;
-
- public AbstractEdmReferentialConstraint(final String property, final String referencedProperty) {
- this.property = property;
- this.referencedProperty = referencedProperty;
- }
-
- @Override
- public String getPropertyName() {
- return property;
- }
-
- @Override
- public String getReferencedPropertyName() {
- return referencedProperty;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReturnType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReturnType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReturnType.java
deleted file mode 100644
index aed5fc1..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmReturnType.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmReturnType;
-import org.apache.olingo.commons.api.edm.EdmType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-
-public abstract class AbstractEdmReturnType implements EdmReturnType {
-
- private final EdmTypeInfo typeInfo;
-
- private EdmType typeImpl;
-
- public AbstractEdmReturnType(final Edm edm, final FullQualifiedName typeName) {
- typeInfo = new EdmTypeInfo.Builder().setEdm(edm).setTypeExpression(typeName.toString()).build();
- }
-
- @Override
- public EdmType getType() {
- if (typeImpl == null) {
- typeImpl = typeInfo.getType();
- if (typeImpl == null) {
- throw new EdmException("Cannot find type with name: " + typeInfo.getFullQualifiedName());
- }
- }
-
- return typeImpl;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmSchema.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmSchema.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmSchema.java
deleted file mode 100644
index ad43727..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmSchema.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.EdmAction;
-import org.apache.olingo.commons.api.edm.EdmAnnotation;
-import org.apache.olingo.commons.api.edm.EdmAnnotations;
-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.EdmTerm;
-import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-
-import java.util.Collections;
-import java.util.List;
-
-public abstract class AbstractEdmSchema implements EdmSchema {
-
- protected final String namespace;
-
- private final String alias;
-
- private List<EdmEnumType> enumTypes;
-
- private List<EdmEntityType> entityTypes;
-
- private List<EdmComplexType> complexTypes;
-
- private List<EdmAction> actions;
-
- private List<EdmFunction> functions;
-
- private List<EdmTypeDefinition> typeDefinitions;
-
- private List<EdmTerm> terms;
-
- private List<EdmAnnotations> annotationGroups;
-
- private List<EdmAnnotation> annotations;
-
- private EdmEntityContainer entityContainer;
-
- public AbstractEdmSchema(final String namespace, final String alias) {
- this.namespace = namespace;
- this.alias = alias;
- }
-
- protected abstract EdmEntityContainer createEntityContainer();
-
- 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();
-
- protected abstract List<EdmTypeDefinition> createTypeDefinitions();
-
- protected abstract List<EdmTerm> createTerms();
-
- protected abstract List<EdmAnnotations> createAnnotationGroups();
-
- protected abstract List<EdmAnnotation> createAnnotations();
-
- @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 List<EdmTypeDefinition> getTypeDefinitions() {
- if (typeDefinitions == null) {
- typeDefinitions = createTypeDefinitions();
- }
- return typeDefinitions;
- }
-
- @Override
- public List<EdmTerm> getTerms() {
- if (terms == null) {
- terms = createTerms();
- }
- return terms;
- }
-
- @Override
- public List<EdmAnnotations> getAnnotationGroups() {
- if (annotationGroups == null) {
- annotationGroups = createAnnotationGroups();
- }
- return annotationGroups;
- }
-
- @Override
- public List<EdmAnnotation> getAnnotations() {
- if (annotations == null) {
- annotations = createAnnotations();
- }
- return annotations;
- }
-
- @Override
- public EdmEntityContainer getEntityContainer() {
- if (entityContainer == null) {
- entityContainer = createEntityContainer();
- }
- return entityContainer;
- }
-
- @Override
- public List<EdmEntityContainer> getEntityContainers() {
- if (getEntityContainer() == null) {
- return Collections.<EdmEntityContainer> emptyList();
- } else {
- return Collections.singletonList(getEntityContainer());
- }
- }
-
- @Override
- public EdmEntityContainer getEntityContainer(final FullQualifiedName name) {
- return getEntityContainer() == null
- ? null
- : name == null
- ? getEntityContainer()
- : name.equals(getEntityContainer().getFullQualifiedName())
- ? getEntityContainer()
- : null;
- }
-
- @Override
- public String getNamespace() {
- return namespace;
- }
-
- @Override
- public String getAlias() {
- return alias;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3a6293b6/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
deleted file mode 100644
index f6c6af1..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmStructuredType.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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 org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmElement;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.EdmType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-public abstract class AbstractEdmStructuredType extends EdmTypeImpl implements EdmStructuredType {
-
- protected EdmStructuredType baseType;
-
- protected FullQualifiedName baseTypeName;
-
- private List<String> propertyNames;
-
- private List<String> navigationPropertyNames;
-
- public AbstractEdmStructuredType(
- final Edm edm,
- final FullQualifiedName typeName,
- final EdmTypeKind kind,
- final FullQualifiedName baseTypeName) {
-
- super(edm, typeName, kind);
- this.baseTypeName = baseTypeName;
- }
-
- protected abstract EdmStructuredType buildBaseType(FullQualifiedName baseTypeName);
-
- protected abstract Map<String, EdmProperty> getProperties();
-
- protected abstract Map<String, EdmNavigationProperty> getNavigationProperties();
-
- protected abstract void checkBaseType();
-
- @Override
- public List<String> getPropertyNames() {
- if (propertyNames == null) {
- propertyNames = new ArrayList<String>();
- checkBaseType();
- if (baseType != null) {
- propertyNames.addAll(baseType.getPropertyNames());
- }
- propertyNames.addAll(getProperties().keySet());
- }
- return propertyNames;
- }
-
- @Override
- public List<String> getNavigationPropertyNames() {
- if (navigationPropertyNames == null) {
- navigationPropertyNames = new ArrayList<String>();
- checkBaseType();
- if (baseType != null) {
- navigationPropertyNames.addAll(baseType.getNavigationPropertyNames());
- }
- navigationPropertyNames.addAll(getNavigationProperties().keySet());
- }
- return navigationPropertyNames;
- }
-
- @Override
- public EdmElement getProperty(final String name) {
- EdmElement property = getStructuralProperty(name);
- if (property == null) {
- property = getNavigationProperty(name);
- }
- return property;
- }
-
- @Override
- public EdmProperty getStructuralProperty(final String name) {
- EdmProperty property = null;
- checkBaseType();
- if (baseType != null) {
- property = baseType.getStructuralProperty(name);
- }
- if (property == null) {
- property = getProperties().get(name);
- }
- return property;
- }
-
- @Override
- public EdmNavigationProperty getNavigationProperty(final String name) {
- EdmNavigationProperty property = null;
- checkBaseType();
- if (baseType != null) {
- property = baseType.getNavigationProperty(name);
- }
- if (property == null) {
- property = getNavigationProperties().get(name);
- }
- return property;
- }
-
- @Override
- public boolean compatibleTo(final EdmType targetType) {
- EdmStructuredType sourceType = this;
- if (targetType == null) {
- throw new EdmException("Target type must not be null");
- }
- while (!sourceType.getName().equals(targetType.getName())
- || !sourceType.getNamespace().equals(targetType.getNamespace())) {
-
- sourceType = sourceType.getBaseType();
- if (sourceType == null) {
- return false;
- }
- }
-
- return true;
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return null;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return getFullQualifiedName();
- }
-
-}
[25/50] [abbrv] olingo-odata4 git commit: [OLINGO-595] Make
EdmProvider an Interface
Posted by ch...@apache.org.
[OLINGO-595] Make EdmProvider an Interface
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/d94edf56
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/d94edf56
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/d94edf56
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: d94edf568c03022872411b3b5343ea251941edf2
Parents: 92e201b
Author: Christian Amend <ch...@apache.org>
Authored: Tue Mar 31 13:47:15 2015 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Tue Mar 31 13:47:15 2015 +0200
----------------------------------------------------------------------
.../client/core/edm/ClientEdmProvider.java | 4 +-
.../api/edm/provider/AbstractEdmProvider.java | 116 +++++++++++++++++++
.../commons/api/edm/provider/EdmProvider.java | 70 +++--------
.../provider/EdmEntityContainerImplTest.java | 25 ++--
.../core/edm/provider/EdmSchemaImplTest.java | 21 ++--
.../xml/MetadataDocumentXmlSerializerTest.java | 3 +-
.../server/tecsvc/provider/EdmTechProvider.java | 14 +--
.../olingo/server/core/ODataHandlerTest.java | 4 +-
.../sample/edmprovider/CarsEdmProvider.java | 4 +-
9 files changed, 173 insertions(+), 88 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d94edf56/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/ClientEdmProvider.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/ClientEdmProvider.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/ClientEdmProvider.java
index 4327e62..b062447 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/ClientEdmProvider.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/ClientEdmProvider.java
@@ -24,13 +24,13 @@ import java.util.Map;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.AbstractEdmProvider;
import org.apache.olingo.commons.api.edm.provider.Action;
import org.apache.olingo.commons.api.edm.provider.ActionImport;
import org.apache.olingo.commons.api.edm.provider.AliasInfo;
import org.apache.olingo.commons.api.edm.provider.Annotatable;
import org.apache.olingo.commons.api.edm.provider.Annotations;
import org.apache.olingo.commons.api.edm.provider.ComplexType;
-import org.apache.olingo.commons.api.edm.provider.EdmProvider;
import org.apache.olingo.commons.api.edm.provider.EntityContainer;
import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo;
import org.apache.olingo.commons.api.edm.provider.EntitySet;
@@ -43,7 +43,7 @@ import org.apache.olingo.commons.api.edm.provider.Singleton;
import org.apache.olingo.commons.api.edm.provider.Term;
import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
-public class ClientEdmProvider extends EdmProvider {
+public class ClientEdmProvider extends AbstractEdmProvider {
private final Map<String, Schema> xmlSchemas;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d94edf56/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/AbstractEdmProvider.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/AbstractEdmProvider.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/AbstractEdmProvider.java
new file mode 100644
index 0000000..d1ada55
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/AbstractEdmProvider.java
@@ -0,0 +1,116 @@
+/*
+ * 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.provider;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+
+public abstract class AbstractEdmProvider implements EdmProvider {
+
+ @Override
+ public EnumType getEnumType(final FullQualifiedName enumTypeName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public TypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public List<Action> getActions(final FullQualifiedName actionName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public List<Function> getFunctions(final FullQualifiedName functionName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public Term getTerm(final FullQualifiedName termName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
+ throws ODataException {
+ return null;
+ }
+
+ @Override
+ public Singleton getSingleton(final FullQualifiedName entityContainer, final String singletonName)
+ throws ODataException {
+ return null;
+ }
+
+ @Override
+ public ActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName)
+ throws ODataException {
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName)
+ throws ODataException {
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(final FullQualifiedName entityContainerName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public List<AliasInfo> getAliasInfos() throws ODataException {
+ return null;
+ }
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ return null;
+ }
+
+ @Override
+ public EntityContainer getEntityContainer() throws ODataException {
+ return null;
+ }
+
+ @Override
+ public Annotations getAnnotationsGroup(FullQualifiedName targetName) throws ODataException {
+ return null;
+ }
+
+ @Override
+ public Annotatable getAnnoatatable(FullQualifiedName annotatedName) throws ODataException {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d94edf56/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java
index 38a03d7..f3511d7 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/provider/EdmProvider.java
@@ -23,7 +23,7 @@ import java.util.List;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
-public abstract class EdmProvider {
+public interface EdmProvider {
/**
* This method should return an {@link EnumType} or <b>null</b> if nothing is found
@@ -32,9 +32,7 @@ public abstract class EdmProvider {
* @return {@link EnumType} for given name
* @throws ODataException
*/
- public EnumType getEnumType(final FullQualifiedName enumTypeName) throws ODataException {
- return null;
- }
+ public EnumType getEnumType(final FullQualifiedName enumTypeName) throws ODataException;
/**
* This method should return an {@link TypeDefinition} or <b>null</b> if nothing is found
@@ -43,9 +41,7 @@ public abstract class EdmProvider {
* @return {@link TypeDefinition} for given name
* @throws ODataException
*/
- public TypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) throws ODataException {
- return null;
- }
+ public TypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) throws ODataException;
/**
* This method should return an {@link EntityType} or <b>null</b> if nothing is found
@@ -54,9 +50,7 @@ public abstract class EdmProvider {
* @return {@link EntityType} for the given name
* @throws ODataException
*/
- public EntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
- return null;
- }
+ public EntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException;
/**
* This method should return a {@link ComplexType} or <b>null</b> if nothing is found.
@@ -65,9 +59,7 @@ public abstract class EdmProvider {
* @return {@link ComplexType} for the given name
* @throws ODataException
*/
- public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
- return null;
- }
+ public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException;
/**
* This method should return a list of all {@link Action} for the FullQualifiedname or <b>null</b> if nothing is found
@@ -76,9 +68,7 @@ public abstract class EdmProvider {
* @return List of {@link Action} or null
* @throws ODataException
*/
- public List<Action> getActions(final FullQualifiedName actionName) throws ODataException {
- return null;
- }
+ public List<Action> getActions(final FullQualifiedName actionName) throws ODataException;
/**
* This method should return a list of all {@link Function} for the FullQualifiedname or <b>null</b> if nothing is
@@ -88,9 +78,7 @@ public abstract class EdmProvider {
* @return List of {@link Function} or null
* @throws ODataException
*/
- public List<Function> getFunctions(final FullQualifiedName functionName) throws ODataException {
- return null;
- }
+ public List<Function> getFunctions(final FullQualifiedName functionName) throws ODataException;
/**
* This method should return a {@link Term} for the FullQualifiedName or <b>null</b> if nothing is found.
@@ -98,9 +86,7 @@ public abstract class EdmProvider {
* @return {@link Term} or null
* @throws ODataException
*/
- public Term getTerm(final FullQualifiedName termName) throws ODataException {
- return null;
- }
+ public Term getTerm(final FullQualifiedName termName) throws ODataException;
/**
* This method should return an {@link EntitySet} or <b>null</b> if nothing is found
@@ -111,9 +97,7 @@ public abstract class EdmProvider {
* @throws ODataException
*/
public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
- throws ODataException {
- return null;
- }
+ throws ODataException;
/**
* This method should return an {@link Singleton} or <b>null</b> if nothing is found
@@ -124,9 +108,7 @@ public abstract class EdmProvider {
* @throws ODataException
*/
public Singleton getSingleton(final FullQualifiedName entityContainer, final String singletonName)
- throws ODataException {
- return null;
- }
+ throws ODataException;
/**
* This method should return an {@link ActionImport} or <b>null</b> if nothing is found
@@ -137,9 +119,7 @@ public abstract class EdmProvider {
* @throws ODataException
*/
public ActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName)
- throws ODataException {
- return null;
- }
+ throws ODataException;
/**
* This method should return a {@link FunctionImport} or <b>null</b> if nothing is found
@@ -150,9 +130,7 @@ public abstract class EdmProvider {
* @throws ODataException
*/
public FunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName)
- throws ODataException {
- return null;
- }
+ throws ODataException;
/**
* This method should return an {@link EntityContainerInfo} or <b>null</b> if nothing is found
@@ -161,9 +139,7 @@ public abstract class EdmProvider {
* @return {@link EntityContainerInfo} for the given name
* @throws ODataException
*/
- public EntityContainerInfo getEntityContainerInfo(final FullQualifiedName entityContainerName) throws ODataException {
- return null;
- }
+ public EntityContainerInfo getEntityContainerInfo(final FullQualifiedName entityContainerName) throws ODataException;
/**
* This method should return a list of all namespaces which have an alias
@@ -171,9 +147,7 @@ public abstract class EdmProvider {
* @return List of alias info
* @throws ODataException
*/
- public List<AliasInfo> getAliasInfos() throws ODataException {
- return null;
- }
+ public List<AliasInfo> getAliasInfos() throws ODataException;
/**
* This method should return a collection of all {@link Schema}
@@ -181,31 +155,23 @@ public abstract class EdmProvider {
* @return List<{@link Schema}>
* @throws ODataException
*/
- public List<Schema> getSchemas() throws ODataException {
- return null;
- }
+ public List<Schema> getSchemas() throws ODataException;
/**
* Returns the entity container of this edm
* @return {@link EntityContainer} of this edm
*/
- public EntityContainer getEntityContainer() throws ODataException {
- return null;
- }
+ public EntityContainer getEntityContainer() throws ODataException;
/**
* @param targetName
* @return {@link Annotations} group for the given Target
*/
- public Annotations getAnnotationsGroup(FullQualifiedName targetName) throws ODataException {
- return null;
- }
+ public Annotations getAnnotationsGroup(FullQualifiedName targetName) throws ODataException;
/**
* @param annotatedName
* @return Annotatble element by target name
*/
- public Annotatable getAnnoatatable(FullQualifiedName annotatedName) throws ODataException {
- return null;
- }
+ public Annotatable getAnnoatatable(FullQualifiedName annotatedName) throws ODataException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d94edf56/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
index 5eba34f..312d636 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEntityContainerImplTest.java
@@ -18,6 +18,17 @@
*/
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.assertNull;
+import static org.junit.Assert.assertTrue;
+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;
@@ -26,6 +37,7 @@ 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.api.edm.provider.AbstractEdmProvider;
import org.apache.olingo.commons.api.edm.provider.ActionImport;
import org.apache.olingo.commons.api.edm.provider.EdmProvider;
import org.apache.olingo.commons.api.edm.provider.EntityContainer;
@@ -38,17 +50,6 @@ import org.apache.olingo.commons.core.edm.provider.EdmProviderImpl;
import org.junit.Before;
import org.junit.Test;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
public class EdmEntityContainerImplTest {
EdmEntityContainer container;
@@ -231,7 +232,7 @@ public class EdmEntityContainerImplTest {
assertNull(container.getEntitySet(null));
}
- private class CustomProvider extends EdmProvider {
+ private class CustomProvider extends AbstractEdmProvider {
@Override
public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
throws ODataException {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d94edf56/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
index 465dca3..9e0b44e 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
@@ -18,6 +18,15 @@
*/
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;
@@ -34,6 +43,7 @@ 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.commons.api.edm.provider.AbstractEdmProvider;
import org.apache.olingo.commons.api.edm.provider.Action;
import org.apache.olingo.commons.api.edm.provider.ActionImport;
import org.apache.olingo.commons.api.edm.provider.AliasInfo;
@@ -54,15 +64,6 @@ import org.apache.olingo.commons.core.edm.provider.EdmProviderImpl;
import org.junit.Before;
import org.junit.Test;
-import java.util.ArrayList;
-import java.util.List;
-
-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;
-
public class EdmSchemaImplTest {
private EdmSchema schema;
@@ -204,7 +205,7 @@ public class EdmSchemaImplTest {
assertTrue(container == edm.getEntityContainer(null));
}
- private class LocalProvider extends EdmProvider {
+ private class LocalProvider extends AbstractEdmProvider {
private static final String ALIAS = "alias";
private static final String NAMESPACE = "org.namespace";
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d94edf56/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
index 2e2d4a6..d092ae9 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java
@@ -38,6 +38,7 @@ import org.apache.olingo.commons.api.edm.EdmComplexType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmSchema;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.AbstractEdmProvider;
import org.apache.olingo.commons.api.edm.provider.Action;
import org.apache.olingo.commons.api.edm.provider.ActionImport;
import org.apache.olingo.commons.api.edm.provider.AliasInfo;
@@ -262,7 +263,7 @@ public class MetadataDocumentXmlSerializerTest {
+ "</ComplexType>"));
}
- private class LocalProvider extends EdmProvider {
+ private class LocalProvider extends AbstractEdmProvider {
private final static String nameSpace = "namespace";
private final FullQualifiedName nameETAbstract = new FullQualifiedName(nameSpace, "ETAbstract");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d94edf56/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EdmTechProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EdmTechProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EdmTechProvider.java
index 2a94c03..410a0bc 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EdmTechProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/EdmTechProvider.java
@@ -18,14 +18,17 @@
*/
package org.apache.olingo.server.tecsvc.provider;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
import org.apache.olingo.commons.api.ODataException;
-import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.AbstractEdmProvider;
import org.apache.olingo.commons.api.edm.provider.Action;
import org.apache.olingo.commons.api.edm.provider.ActionImport;
import org.apache.olingo.commons.api.edm.provider.AliasInfo;
import org.apache.olingo.commons.api.edm.provider.ComplexType;
-import org.apache.olingo.commons.api.edm.provider.EdmProvider;
import org.apache.olingo.commons.api.edm.provider.EntityContainer;
import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo;
import org.apache.olingo.commons.api.edm.provider.EntitySet;
@@ -37,12 +40,9 @@ import org.apache.olingo.commons.api.edm.provider.Schema;
import org.apache.olingo.commons.api.edm.provider.Singleton;
import org.apache.olingo.commons.api.edm.provider.Term;
import org.apache.olingo.commons.api.edm.provider.TypeDefinition;
+import org.apache.olingo.server.api.edmx.EdmxReference;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-public class EdmTechProvider extends EdmProvider {
+public class EdmTechProvider extends AbstractEdmProvider {
public static final String nameSpace = "olingo.odata.test1";
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d94edf56/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
index 45728e1..c317d0c 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
@@ -39,7 +39,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.commons.api.edm.provider.AbstractEdmProvider;
import org.apache.olingo.commons.api.edm.provider.EntitySet;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
@@ -223,7 +223,7 @@ public class ODataHandlerTest {
public void uriParserExceptionResultsInRightResponseEdmCause() throws Exception {
final OData odata = OData.newInstance();
final ServiceMetadata serviceMetadata = odata.createServiceMetadata(
- new EdmProvider() {
+ new AbstractEdmProvider() {
public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
throws ODataException {
throw new ODataException("msg");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d94edf56/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java
----------------------------------------------------------------------
diff --git a/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java b/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java
index dac970d..8036c8f 100644
--- a/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java
+++ b/samples/server/src/main/java/org/apache/olingo/server/sample/edmprovider/CarsEdmProvider.java
@@ -25,8 +25,8 @@ import java.util.List;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.provider.AbstractEdmProvider;
import org.apache.olingo.commons.api.edm.provider.ComplexType;
-import org.apache.olingo.commons.api.edm.provider.EdmProvider;
import org.apache.olingo.commons.api.edm.provider.EntityContainer;
import org.apache.olingo.commons.api.edm.provider.EntityContainerInfo;
import org.apache.olingo.commons.api.edm.provider.EntitySet;
@@ -37,7 +37,7 @@ import org.apache.olingo.commons.api.edm.provider.Property;
import org.apache.olingo.commons.api.edm.provider.PropertyRef;
import org.apache.olingo.commons.api.edm.provider.Schema;
-public class CarsEdmProvider extends EdmProvider {
+public class CarsEdmProvider extends AbstractEdmProvider {
// Service Namespace
public static final String NAMESPACE = "olingo.odata.sample";
[43/50] [abbrv] olingo-odata4 git commit: [OLINGO-573] Minor clean up
after merge with master
Posted by ch...@apache.org.
[OLINGO-573] Minor clean up after merge with master
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/7119be1f
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/7119be1f
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/7119be1f
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 7119be1f26ead1827434057a4d3446c2b2e057f4
Parents: 3f79ced
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Apr 2 10:40:27 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Apr 2 10:40:43 2015 +0200
----------------------------------------------------------------------
.../org/apache/olingo/server/tecsvc/data/DataCreator.java | 9 ---------
.../org/apache/olingo/server/tecsvc/data/DataProvider.java | 6 ++----
.../org/apache/olingo/server/tecsvc/data/FunctionData.java | 7 +++----
3 files changed, 5 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7119be1f/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index 9de7166..7de80e7 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@ -565,10 +565,6 @@ public class DataCreator {
return new PropertyImpl(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(values));
}
- protected static Property createComplex(final String name, String type, final Property... properties) {
- return createComplex(name, properties);
- }
-
protected static Property createComplex(final String name, final Property... properties) {
ComplexValue complexValue = new ComplexValueImpl();
for (final Property property : properties) {
@@ -577,11 +573,6 @@ public class DataCreator {
return new PropertyImpl(null, name, ValueType.COMPLEX, complexValue);
}
- protected static Property createComplexCollection(final String name, String type, final List<Property>...
- propertiesList) {
- return createComplexCollection(name, propertiesList);
- }
-
protected static Property createComplexCollection(final String name, final List<Property>... propertiesList) {
List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
for (final List<Property> properties : propertiesList) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7119be1f/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
index 4fc9300..e4bb0a2 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
@@ -217,12 +217,10 @@ public class DataProvider {
} else {
if (edmProperty.isCollection()) {
@SuppressWarnings("unchecked")
- Property newProperty2 = DataCreator.createComplexCollection(propertyName, edmProperty
- .getType().getFullQualifiedName().getFullQualifiedNameAsString());
+ Property newProperty2 = DataCreator.createComplexCollection(propertyName);
newProperty = newProperty2;
} else {
- newProperty = DataCreator.createComplex(propertyName, edmProperty.getType()
- .getFullQualifiedName().getFullQualifiedNameAsString());
+ newProperty = DataCreator.createComplex(propertyName);
createProperties((EdmComplexType) edmProperty.getType(), newProperty.asComplex().getValue());
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7119be1f/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
index 316a7b0..5451d5d 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/FunctionData.java
@@ -31,7 +31,6 @@ import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.uri.UriParameter;
import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException;
-import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
public class FunctionData {
@@ -81,12 +80,12 @@ public class FunctionData {
} else if (name.equals("UFCRTCollString")) {
return data.get("ESCollAllPrim").getEntities().get(0).getProperty("CollPropertyString");
} else if (name.equals("UFCRTCTTwoPrim")) {
- return DataCreator.createComplex(name, ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
+ return DataCreator.createComplex(name,
DataCreator.createPrimitive("PropertyInt16", 16),
DataCreator.createPrimitive("PropertyString", "UFCRTCTTwoPrim string value"));
} else if (name.equals("UFCRTCTTwoPrimParam")) {
try {
- return DataCreator.createComplex(name,ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
+ return DataCreator.createComplex(name,
DataCreator.createPrimitive("PropertyInt16",
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16).valueOfString(
getParameterText("ParameterInt16", parameters),
@@ -100,7 +99,7 @@ public class FunctionData {
throw new DataProviderException("Error in function " + name + ".", e);
}
} else if (name.equals("UFCRTCollCTTwoPrim")) {
- return DataCreator.createComplexCollection(name,ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
+ return DataCreator.createComplexCollection(name,
Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 16),
DataCreator.createPrimitive("PropertyString", "Test123")),
Arrays.asList(DataCreator.createPrimitive("PropertyInt16", 17),
[28/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin as example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/people.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/people.json b/lib/server-core-ext/src/test/resources/people.json
new file mode 100644
index 0000000..64699bb
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/people.json
@@ -0,0 +1,323 @@
+{
+ "value":[
+ {
+ "UserName":"russellwhyte",
+ "FirstName":"Russell",
+ "LastName":"Whyte",
+ "Emails":[
+ "Russell@example.com",
+ "Russell@contoso.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"187 Suffolk Ln.",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Boise",
+ "Region":"ID"
+ }
+ }
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"scottketchum",
+ "FirstName":"Scott",
+ "LastName":"Ketchum",
+ "Emails":[
+ "Scott@example.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"2817 Milton Dr.",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Albuquerque",
+ "Region":"NM"
+ }
+ }
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"ronaldmundy",
+ "FirstName":"Ronald",
+ "LastName":"Mundy",
+ "Emails":[
+ "Ronald@example.com",
+ "Ronald@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"javieralfred",
+ "FirstName":"Javier",
+ "LastName":"Alfred",
+ "Emails":[
+ "Javier@example.com",
+ "Javier@contoso.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"89 Jefferson Way Suite 2",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Portland",
+ "Region":"WA"
+ }
+ }
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"willieashmore",
+ "FirstName":"Willie",
+ "LastName":"Ashmore",
+ "Emails":[
+ "Willie@example.com",
+ "Willie@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"vincentcalabrese",
+ "FirstName":"Vincent",
+ "LastName":"Calabrese",
+ "Emails":[
+ "Vincent@example.com",
+ "Vincent@contoso.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"55 Grizzly Peak Rd.",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Butte",
+ "Region":"MT"
+ }
+ }
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"clydeguess",
+ "FirstName":"Clyde",
+ "LastName":"Guess",
+ "Emails":[
+ "Clyde@example.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"keithpinckney",
+ "FirstName":"Keith",
+ "LastName":"Pinckney",
+ "Emails":[
+ "Keith@example.com",
+ "Keith@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"marshallgaray",
+ "FirstName":"Marshall",
+ "LastName":"Garay",
+ "Emails":[
+ "Marshall@example.com",
+ "Marshall@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"ryantheriault",
+ "FirstName":"Ryan",
+ "LastName":"Theriault",
+ "Emails":[
+ "Ryan@example.com",
+ "Ryan@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"0",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"elainestewart",
+ "FirstName":"Elaine",
+ "LastName":"Stewart",
+ "Emails":[
+ "Elaine@example.com",
+ "Elaine@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"salliesampson",
+ "FirstName":"Sallie",
+ "LastName":"Sampson",
+ "Emails":[
+ "Sallie@example.com",
+ "Sallie@contoso.com"
+ ],
+ "AddressInfo":[
+ {
+ "Address":"87 Polk St. Suite 5",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"San Francisco",
+ "Region":"CA"
+ }
+ },
+ {
+ "Address":"89 Chiaroscuro Rd.",
+ "City":{
+ "CountryRegion":"United States",
+ "Name":"Portland",
+ "Region":"OR"
+ }
+ }
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"jonirosales",
+ "FirstName":"Joni",
+ "LastName":"Rosales",
+ "Emails":[
+ "Joni@example.com",
+ "Joni@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"georginabarlow",
+ "FirstName":"Georgina",
+ "LastName":"Barlow",
+ "Emails":[
+ "Georgina@example.com",
+ "Georgina@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"angelhuffman",
+ "FirstName":"Angel",
+ "LastName":"Huffman",
+ "Emails":[
+ "Angel@example.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"laurelosborn",
+ "FirstName":"Laurel",
+ "LastName":"Osborn",
+ "Emails":[
+ "Laurel@example.com",
+ "Laurel@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"sandyosborn",
+ "FirstName":"Sandy",
+ "LastName":"Osborn",
+ "Emails":[
+ "Sandy@example.com",
+ "Sandy@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"ursulabright",
+ "FirstName":"Ursula",
+ "LastName":"Bright",
+ "Emails":[
+ "Ursula@example.com",
+ "Ursula@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"genevievereeves",
+ "FirstName":"Genevieve",
+ "LastName":"Reeves",
+ "Emails":[
+ "Genevieve@example.com",
+ "Genevieve@contoso.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ },
+ {
+ "UserName":"kristakemp",
+ "FirstName":"Krista",
+ "LastName":"Kemp",
+ "Emails":[
+ "Krista@example.com"
+ ],
+ "AddressInfo":[
+
+ ],
+ "Gender":"1",
+ "Concurrency":635585295719432047
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/photos.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/photos.json b/lib/server-core-ext/src/test/resources/photos.json
new file mode 100644
index 0000000..127d195
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/photos.json
@@ -0,0 +1,64 @@
+{
+ "value":[
+ {
+ "Id":1,
+ "Name":"My Photo 1"
+ },
+ {
+ "Id":11,
+ "Name":"Trip Photo 11"
+ },
+ {
+ "Id":12,
+ "Name":"Trip Photo 12"
+ },
+ {
+ "Id":13,
+ "Name":"Trip Photo 13"
+ },
+ {
+ "Id":14,
+ "Name":"Trip Photo 14"
+ },
+ {
+ "Id":2,
+ "Name":"My Photo 2"
+ },
+ {
+ "Id":21,
+ "Name":"Trip Photo 21"
+ },
+ {
+ "Id":22,
+ "Name":"Trip Photo 22"
+ },
+ {
+ "Id":23,
+ "Name":"Trip Photo 23"
+ },
+ {
+ "Id":24,
+ "Name":"Trip Photo 24"
+ },
+ {
+ "Id":3,
+ "Name":"My Photo 3"
+ },
+ {
+ "Id":31,
+ "Name":"Trip Photo 31"
+ },
+ {
+ "Id":32,
+ "Name":"Trip Photo 32"
+ },
+ {
+ "Id":33,
+ "Name":"Trip Photo 33"
+ },
+ {
+ "Id":34,
+ "Name":"Trip Photo 34"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/trip-links.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/trip-links.json b/lib/server-core-ext/src/test/resources/trip-links.json
new file mode 100644
index 0000000..df8f9b8
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/trip-links.json
@@ -0,0 +1,28 @@
+{
+ "value":[
+ {
+ "TripId": 1001,
+ "Flights": [1, 2],
+ "Events": [51, 52, 53, 54, 55],
+ "Photos": [21, 22]
+ },
+ {
+ "TripId":2,
+ "Flights": [3, 4],
+ "Events": [55],
+ "Photos": [13, 14]
+ },
+ {
+ "TripId": 1003,
+ "Flights": [5, 6],
+ "Events": [56, 57],
+ "Photos": [23, 24]
+ },
+ {
+ "TripId": 2004,
+ "Flights": [7, 8],
+ "Events": [55, 57],
+ "Photos": [33, 34]
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/trip.json
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/trip.json b/lib/server-core-ext/src/test/resources/trip.json
new file mode 100644
index 0000000..79c6104
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/trip.json
@@ -0,0 +1,224 @@
+{
+ "value":[
+ {
+ "TripId": 1001,
+ "ShareId": "9d9b2fa0-efbf-490e-a5e3-bac8f7d47354",
+ "Description": "Trip from San Francisco to New York City. Nice trip with two friends. It is a 4 days' trip. We actually had a client meeting, but we also took one to go sightseeings in New York.",
+ "Name": "Trip in US",
+ "Budget": 3000.0,
+ "StartsAt":"2014-01-01T00:00:00Z",
+ "EndsAt": "2014-01-04T00:00:00Z",
+ "Tags": ["Trip in New York", "business","sightseeing"]
+ },
+ {
+ "TripId":2,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Description": "Trip from Shanghai to Beijing",
+ "Name":"Trip in Beijing",
+ "Budget": 3000.0,
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 3,
+ "ShareId": "9ce142c3-5fd6-4a71-848e-5220ebf1e9f3",
+ "Name": "Honeymoon",
+ "Budget": 800.0,
+ "Description": "Happy honeymoon trip",
+ "Tags": ["Travel", "honeymoon"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 4,
+ "ShareId": "4CCFB043-C79C-44EF-8CFE-CD493CED6654",
+ "Name": "Business trip to OData",
+ "Budget": 324.6,
+ "Description": "Business trip to OData",
+ "Tags": ["business", "odata"],
+ "StartsAt": "2013-01-01T00:00:00Z",
+ "EndsAt": "2013-01-04T00:00:00Z"
+ },
+ {
+ "TripId": 5,
+ "ShareId": "4546F419-0070-45F7-BA2C-19E4BC3647E1",
+ "Name": "Travel trip in US",
+ "Budget": 1250.0,
+ "Description": "Travel trip in US",
+ "Tags": ["travel", "overseas"],
+ "StartsAt": "2013-01-19T00:00:00Z",
+ "EndsAt": "2013-01-28T00:00:00Z"
+ },
+ {
+ "TripId": 6,
+ "ShareId": "26F0E8F6-657A-4561-BF3B-719366EF04FA",
+ "Name": "Study music in Europe",
+ "Budget": 3200.0,
+ "Description": "Study music in Europe",
+ "Tags": ["study", "overseas"],
+ "StartsAt": "2013-03-01T00:00:00Z",
+ "EndsAt": "2013-05-04T00:00:00Z"
+ },
+ {
+ "TripId": 7,
+ "ShareId": "2E77BF06-A354-454B-8BCA-5F004C1AFB59",
+ "Name": "Conference talk about OData",
+ "Budget": 2120.55,
+ "Description": "Conference talk about ODatan",
+ "Tags": ["odata", "overseas"],
+ "StartsAt": "2013-07-02T00:00:00Z",
+ "EndsAt": "2013-07-05T00:00:00Z"
+ },
+ {
+ "TripId": 8,
+ "ShareId": "E6E23FB2-C428-439E-BDAB-9283482F49F0",
+ "Name": "Vocation at hometown",
+ "Budget": 1500.0,
+ "Description": "Vocation at hometown",
+ "Tags": ["voaction"],
+ "StartsAt": "2013-10-01T00:00:00Z",
+ "EndsAt": "2013-10-05T00:00:00Z"
+ },
+ {
+ "TripId": 9,
+ "ShareId": "FAE31279-35CE-4119-9BDC-53F6E19DD1C5",
+ "Name": "Business trip for tech training",
+ "Budget": 100.0,
+ "Description": "Business trip for tech training",
+ "Tags": ["business"],
+ "StartsAt": "2013-09-01T00:00:00Z",
+ "EndsAt": "2013-09-04T00:00:00Z"
+ },
+ {
+ "TripId": 3009,
+ "ShareId": "dd6a09c0-e59b-4745-8612-f4499b676c47",
+ "Name": "Gradutaion trip",
+ "Budget": 6000.0,
+ "Description": "Gradution trip with friends",
+ "Tags": ["Travel"],
+ "StartsAt": "2013-05-01T00:00:00Z",
+ "EndsAt": "2013-05-08T00:00:00Z"
+ },
+ {
+ "TripId": 2004,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Name": "Trip in Beijing",
+ "Budget": 11000.0,
+ "Description": "Trip from Shanghai to Beijing",
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2013-02-02T00:00:00Z"
+ },
+ {
+ "TripId": 4005,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Name": "Trip in Beijing",
+ "Budget": 800.0,
+ "Description": "Trip from Shanghai to Beijing",
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 5007,
+ "ShareId": "5ae142c3-5ad6-4a71-768e-5220ebf1e9f3",
+ "Name": "Business Trip",
+ "Budget": 3800.5,
+ "Description": "This is my first business trip",
+ "Tags": ["business", "first"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 5008,
+ "ShareId": "9ce32ac3-5fd6-4a72-848e-2250ebf1e9f3",
+ "Name": "Trip in Europe",
+ "Budget": 2000.0,
+ "Description": "The trip is currently in plan.",
+ "Tags": ["Travel", "plan"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 1003,
+ "Name": "Trip in Beijing",
+ "Budget": 2000.0,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Description": "Trip from Shanghai to Beijing",
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 2004,
+ "ShareId": "f94e9116-8bdd-4dac-ab61-08438d0d9a71",
+ "Name": "Trip in Beijing",
+ "Budget": 11000.0,
+ "Description": "Trip from Shanghai to Beijing",
+ "Tags": ["Travel", "Beijing"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 1007,
+ "ShareId": "9ce142c3-5fd6-4a71-848e-5220ebf1e9f3",
+ "Name": "Honeymoon",
+ "Budget": 2650.0,
+ "Description": "Happy honeymoon trip",
+ "Tags": ["Travel", "honeymoon"],
+ "StartsAt": "2014-02-01T00:00:00Z",
+ "EndsAt": "2014-02-04T00:00:00Z"
+ },
+ {
+ "TripId": 7010,
+ "ShareId": "dd6a09c0-e59b-4745-8612-f4499b676c47",
+ "Name": "Gradutaion trip",
+ "Budget": 1000.0,
+ "Description": "Gradution trip with friends",
+ "Tags": ["Travel"],
+ "StartsAt": "2013-05-01T00:00:00Z",
+ "EndsAt": "2013-05-08T00:00:00Z"
+ },
+ {
+ "TripId": 8011,
+ "ShareId": "a88f675d-9199-4392-9656-b08e3b46df8a",
+ "Name": "Study trip",
+ "Budget": 1550.3,
+ "Description": "This is a 2 weeks study trip",
+ "Tags": ["study"],
+ "StartsAt": "2014-01-01T00:00:00Z",
+ "EndsAt": "2013-01-14T00:00:00Z"
+ },
+ {
+ "TripId": 13012,
+ "ShareId": "a88f675d-9199-4392-9656-b08e3b46df8a",
+ "Name": "Study trip",
+ "Budget": 600.0,
+ "Description": "This is a 2 weeks study trip",
+ "Tags": ["study"],
+ "StartsAt": "2014-01-01T00:00:00Z",
+ "EndsAt": "2013-01-14T00:00:00Z"
+ },
+ {
+ "TripId": 14013,
+ "ShareId": "a88f675d-9199-4392-9656-b08e3b46df8a",
+ "Name": "Study trip",
+ "Budget": 2000.0,
+ "Description": "This is a 2 weeks study trip",
+ "Tags": ["study"],
+ "StartsAt": "2014-01-01T00:00:00Z",
+ "EndsAt": "2013-01-14T00:00:00Z"
+ },
+ {
+ "TripId": 16014,
+ "ShareId": "cb0b8acb-79cb-4127-8316-772bc4302824",
+ "Name": "DIY Trip",
+ "Budget": 1500.3,
+ "Description": "This is a DIY trip",
+ "Tags": ["Travel", "DIY"],
+ "StartsAt": "2011-02-11T00:00:00Z",
+ "EndsAt": "2011-02-14T00:00:00Z"
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/test/resources/trippin.xml
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/resources/trippin.xml b/lib/server-core-ext/src/test/resources/trippin.xml
new file mode 100644
index 0000000..5970793
--- /dev/null
+++ b/lib/server-core-ext/src/test/resources/trippin.xml
@@ -0,0 +1,356 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
+ <edmx:DataServices>
+ <Schema Namespace="Microsoft.OData.SampleService.Models.TripPin" xmlns="http://docs.oasis-open.org/odata/ns/edm">
+ <EnumType Name="PersonGender">
+ <Member Name="Male" Value="0" />
+ <Member Name="Female" Value="1" />
+ <Member Name="Unknown" Value="2" />
+ </EnumType>
+ <ComplexType Name="City">
+ <Property Name="CountryRegion" Type="Edm.String" Nullable="false" />
+ <Property Name="Name" Type="Edm.String" Nullable="false" />
+ <Property Name="Region" Type="Edm.String" Nullable="false" />
+ </ComplexType>
+ <ComplexType Name="Location" OpenType="true">
+ <Property Name="Address" Type="Edm.String" Nullable="false" />
+ <Property Name="City" Type="Microsoft.OData.SampleService.Models.TripPin.City" Nullable="false" />
+ </ComplexType>
+ <ComplexType Name="EventLocation" BaseType="Microsoft.OData.SampleService.Models.TripPin.Location" OpenType="true">
+ <Property Name="BuildingInfo" Type="Edm.String" />
+ </ComplexType>
+ <ComplexType Name="AirportLocation" BaseType="Microsoft.OData.SampleService.Models.TripPin.Location" OpenType="true">
+ <Property Name="Loc" Type="Edm.GeographyPoint" Nullable="false" SRID="4326" />
+ </ComplexType>
+ <EntityType Name="Photo" HasStream="true">
+ <Key>
+ <PropertyRef Name="Id" />
+ </Key>
+ <Property Name="Id" Type="Edm.Int64" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="Name" Type="Edm.String" />
+ <Annotation Term="Org.OData.Core.V1.AcceptableMediaTypes">
+ <Collection>
+ <String>image/jpeg</String>
+ </Collection>
+ </Annotation>
+ </EntityType>
+ <EntityType Name="Person" OpenType="true">
+ <Key>
+ <PropertyRef Name="UserName" />
+ </Key>
+ <Property Name="UserName" Type="Edm.String" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="FirstName" Type="Edm.String" Nullable="true" />
+ <Property Name="LastName" Type="Edm.String" Nullable="false" />
+ <Property Name="Emails" Type="Collection(Edm.String)" />
+ <Property Name="AddressInfo" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Location)" />
+ <Property Name="Gender" Type="Microsoft.OData.SampleService.Models.TripPin.PersonGender" />
+ <Property Name="Concurrency" Type="Edm.Int64" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Computed" Bool="true" />
+ </Property>
+ <NavigationProperty Name="Friends" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Person)" />
+ <NavigationProperty Name="Trips" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Trip)" ContainsTarget="true" />
+ <NavigationProperty Name="Photo" Type="Microsoft.OData.SampleService.Models.TripPin.Photo" />
+ </EntityType>
+ <EntityType Name="Airline">
+ <Key>
+ <PropertyRef Name="AirlineCode" />
+ </Key>
+ <Property Name="AirlineCode" Type="Edm.String" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="Name" Type="Edm.String" Nullable="false" />
+ <Property Name="Picture" Type="Edm.Stream" Nullable="true" />
+ </EntityType>
+ <EntityType Name="Airport">
+ <Key>
+ <PropertyRef Name="IcaoCode" />
+ </Key>
+ <Property Name="IcaoCode" Type="Edm.String" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="Name" Type="Edm.String" Nullable="false" />
+ <Property Name="IataCode" Type="Edm.String" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Immutable" Bool="true" />
+ </Property>
+ <Property Name="Location" Type="Microsoft.OData.SampleService.Models.TripPin.AirportLocation" Nullable="false" />
+ </EntityType>
+ <EntityType Name="PlanItem">
+ <Key>
+ <PropertyRef Name="PlanItemId" />
+ </Key>
+ <Property Name="PlanItemId" Type="Edm.Int32" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="ConfirmationCode" Type="Edm.String" />
+ <Property Name="StartsAt" Type="Edm.DateTimeOffset" />
+ <Property Name="EndsAt" Type="Edm.DateTimeOffset" />
+ <Property Name="Duration" Type="Edm.Duration" />
+ </EntityType>
+ <EntityType Name="PublicTransportation" BaseType="Microsoft.OData.SampleService.Models.TripPin.PlanItem">
+ <Property Name="SeatNumber" Type="Edm.String" />
+ </EntityType>
+ <EntityType Name="Flight" BaseType="Microsoft.OData.SampleService.Models.TripPin.PublicTransportation">
+ <Property Name="FlightNumber" Type="Edm.String" Nullable="false" />
+ <NavigationProperty Name="From" Type="Microsoft.OData.SampleService.Models.TripPin.Airport" Nullable="false" />
+ <NavigationProperty Name="To" Type="Microsoft.OData.SampleService.Models.TripPin.Airport" Nullable="false" />
+ <NavigationProperty Name="Airline" Type="Microsoft.OData.SampleService.Models.TripPin.Airline" Nullable="false" />
+ </EntityType>
+ <EntityType Name="Event" BaseType="Microsoft.OData.SampleService.Models.TripPin.PlanItem" OpenType="true">
+ <Property Name="Description" Type="Edm.String" />
+ <Property Name="OccursAt" Type="Microsoft.OData.SampleService.Models.TripPin.EventLocation" Nullable="false" />
+ </EntityType>
+ <EntityType Name="Trip">
+ <Key>
+ <PropertyRef Name="TripId" />
+ </Key>
+ <Property Name="TripId" Type="Edm.Int32" Nullable="false">
+ <Annotation Term="Org.OData.Core.V1.Permissions">
+ <EnumMember>Org.OData.Core.V1.Permission/Read</EnumMember>
+ </Annotation>
+ </Property>
+ <Property Name="ShareId" Type="Edm.Guid" />
+ <Property Name="Description" Type="Edm.String" />
+ <Property Name="Name" Type="Edm.String" Nullable="false" />
+ <Property Name="Budget" Type="Edm.Single" Nullable="false">
+ <Annotation Term="Org.OData.Measures.V1.ISOCurrency" String="USD" />
+ <Annotation Term="Org.OData.Measures.V1.Scale" Int="2" />
+ </Property>
+ <Property Name="StartsAt" Type="Edm.DateTimeOffset" Nullable="false" />
+ <Property Name="EndsAt" Type="Edm.DateTimeOffset" Nullable="false" />
+ <Property Name="Tags" Type="Collection(Edm.String)" Nullable="false" />
+ <NavigationProperty Name="Photos" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Photo)" />
+ <NavigationProperty Name="PlanItems" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.PlanItem)" ContainsTarget="true" />
+ </EntityType>
+ <Function Name="GetFavoriteAirline" IsBound="true" EntitySetPath="person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline" IsComposable="true">
+ <Parameter Name="person" Type="Microsoft.OData.SampleService.Models.TripPin.Person" Nullable="false" />
+ <ReturnType Type="Microsoft.OData.SampleService.Models.TripPin.Airline" Nullable="false" />
+ </Function>
+ <Function Name="GetInvolvedPeople" IsBound="true" IsComposable="true">
+ <Parameter Name="trip" Type="Microsoft.OData.SampleService.Models.TripPin.Trip" Nullable="false" />
+ <ReturnType Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Person)" Nullable="false" />
+ </Function>
+ <Function Name="GetFriendsTrips" IsBound="true" EntitySetPath="person/Friends/Trips" IsComposable="true">
+ <Parameter Name="person" Type="Microsoft.OData.SampleService.Models.TripPin.Person" Nullable="false" />
+ <Parameter Name="userName" Type="Edm.String" Nullable="false" />
+ <ReturnType Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Trip)" Nullable="false" />
+ </Function>
+ <Function Name="GetNearestAirport" IsComposable="true">
+ <Parameter Name="lat" Type="Edm.Double" Nullable="false" />
+ <Parameter Name="lon" Type="Edm.Double" Nullable="false" />
+ <ReturnType Type="Microsoft.OData.SampleService.Models.TripPin.Airport" Nullable="false" />
+ </Function>
+ <Action Name="ResetDataSource" />
+ <Action Name="ShareTrip" IsBound="true">
+ <Parameter Name="person" Type="Microsoft.OData.SampleService.Models.TripPin.Person" Nullable="false" />
+ <Parameter Name="userName" Type="Edm.String" Nullable="false" />
+ <Parameter Name="tripId" Type="Edm.Int32" Nullable="false" />
+ </Action>
+ <EntityContainer Name="DefaultContainer">
+ <EntitySet Name="Photos" EntityType="Microsoft.OData.SampleService.Models.TripPin.Photo">
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Photos" />
+ <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
+ <Record>
+ <PropertyValue Property="Searchable" Bool="true" />
+ <PropertyValue Property="UnsupportedExpressions">
+ <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.InsertRestrictions">
+ <Record>
+ <PropertyValue Property="Insertable" Bool="true" />
+ <PropertyValue Property="NonInsertableNavigationProperties">
+ <Collection />
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ </EntitySet>
+ <EntitySet Name="People" EntityType="Microsoft.OData.SampleService.Models.TripPin.Person">
+ <NavigationPropertyBinding Path="Friends" Target="People" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/Airline" Target="Airlines" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/From" Target="Airports" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/To" Target="Airports" />
+ <NavigationPropertyBinding Path="Photo" Target="Photos" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Trip/Photos" Target="Photos" />
+ <Annotation Term="Org.OData.Core.V1.OptimisticConcurrency">
+ <Collection>
+ <PropertyPath>Concurrency</PropertyPath>
+ </Collection>
+ </Annotation>
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="People" />
+ <Annotation Term="Org.OData.Capabilities.V1.NavigationRestrictions">
+ <Record>
+ <PropertyValue Property="Navigability">
+ <EnumMember>Org.OData.Capabilities.V1.NavigationType/None</EnumMember>
+ </PropertyValue>
+ <PropertyValue Property="RestrictedProperties">
+ <Collection>
+ <Record>
+ <PropertyValue Property="NavigationProperty" NavigationPropertyPath="Friends" />
+ <PropertyValue Property="Navigability">
+ <EnumMember>Org.OData.Capabilities.V1.NavigationType/Recursive</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Collection>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
+ <Record>
+ <PropertyValue Property="Searchable" Bool="true" />
+ <PropertyValue Property="UnsupportedExpressions">
+ <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.InsertRestrictions">
+ <Record>
+ <PropertyValue Property="Insertable" Bool="true" />
+ <PropertyValue Property="NonInsertableNavigationProperties">
+ <Collection>
+ <NavigationPropertyPath>Trips</NavigationPropertyPath>
+ <NavigationPropertyPath>Friends</NavigationPropertyPath>
+ </Collection>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ </EntitySet>
+ <EntitySet Name="Airlines" EntityType="Microsoft.OData.SampleService.Models.TripPin.Airline">
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Airlines" />
+ <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
+ <Record>
+ <PropertyValue Property="Searchable" Bool="true" />
+ <PropertyValue Property="UnsupportedExpressions">
+ <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.InsertRestrictions">
+ <Record>
+ <PropertyValue Property="Insertable" Bool="true" />
+ <PropertyValue Property="NonInsertableNavigationProperties">
+ <Collection />
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ </EntitySet>
+ <EntitySet Name="Airports" EntityType="Microsoft.OData.SampleService.Models.TripPin.Airport">
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Airports" />
+ <Annotation Term="Org.OData.Capabilities.V1.SearchRestrictions">
+ <Record>
+ <PropertyValue Property="Searchable" Bool="true" />
+ <PropertyValue Property="UnsupportedExpressions">
+ <EnumMember>Org.OData.Capabilities.V1.SearchExpressions/none</EnumMember>
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.InsertRestrictions">
+ <Record>
+ <PropertyValue Property="Insertable" Bool="false" />
+ <PropertyValue Property="NonInsertableNavigationProperties">
+ <Collection />
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.DeleteRestrictions">
+ <Record>
+ <PropertyValue Property="Deletable" Bool="false" />
+ <PropertyValue Property="NonDeletableNavigationProperties">
+ <Collection />
+ </PropertyValue>
+ </Record>
+ </Annotation>
+ </EntitySet>
+ <Singleton Name="Me" Type="Microsoft.OData.SampleService.Models.TripPin.Person">
+ <NavigationPropertyBinding Path="Friends" Target="People" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/Airline" Target="Airlines" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/From" Target="Airports" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Flight/To" Target="Airports" />
+ <NavigationPropertyBinding Path="Photo" Target="Photos" />
+ <NavigationPropertyBinding Path="Microsoft.OData.SampleService.Models.TripPin.Trip/Photos" Target="Photos" />
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Me" />
+ </Singleton>
+ <FunctionImport Name="GetNearestAirport" Function="Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport" EntitySet="Airports" IncludeInServiceDocument="true">
+ <Annotation Term="Org.OData.Core.V1.ResourcePath" String="Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport" />
+ </FunctionImport>
+ <ActionImport Name="ResetDataSource" Action="Microsoft.OData.SampleService.Models.TripPin.ResetDataSource" />
+ <Annotation Term="Org.OData.Core.V1.Description" String="TripPin service is a sample service for OData V4." />
+ </EntityContainer>
+ <Annotations Target="Microsoft.OData.SampleService.Models.TripPin.DefaultContainer">
+ <Annotation Term="Org.OData.Core.V1.DereferenceableIDs" Bool="true" />
+ <Annotation Term="Org.OData.Core.V1.ConventionalIDs" Bool="true" />
+ <Annotation Term="Org.OData.Capabilities.V1.ConformanceLevel">
+ <EnumMember>Org.OData.Capabilities.V1.ConformanceLevelType/Advanced</EnumMember>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.SupportedFormats">
+ <Collection>
+ <String>application/json;odata.metadata=full;IEEE754Compatible=false;odata.streaming=true</String>
+ <String>application/json;odata.metadata=minimal;IEEE754Compatible=false;odata.streaming=true</String>
+ <String>application/json;odata.metadata=none;IEEE754Compatible=false;odata.streaming=true</String>
+ </Collection>
+ </Annotation>
+ <Annotation Term="Org.OData.Capabilities.V1.AsynchronousRequestsSupported" Bool="true" />
+ <Annotation Term="Org.OData.Capabilities.V1.BatchContinueOnErrorSupported" Bool="false" />
+ <Annotation Term="Org.OData.Capabilities.V1.FilterFunctions">
+ <Collection>
+ <String>contains</String>
+ <String>endswith</String>
+ <String>startswith</String>
+ <String>length</String>
+ <String>indexof</String>
+ <String>substring</String>
+ <String>tolower</String>
+ <String>toupper</String>
+ <String>trim</String>
+ <String>concat</String>
+ <String>year</String>
+ <String>month</String>
+ <String>day</String>
+ <String>hour</String>
+ <String>minute</String>
+ <String>second</String>
+ <String>round</String>
+ <String>floor</String>
+ <String>ceiling</String>
+ <String>cast</String>
+ <String>isof</String>
+ </Collection>
+ </Annotation>
+ </Annotations>
+ </Schema>
+ </edmx:DataServices>
+</edmx:Edmx>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index 74c73c8..a66570f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -20,6 +20,8 @@ package org.apache.olingo.server.core.deserializer.json;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -65,6 +67,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class ODataJsonDeserializer implements ODataDeserializer {
@@ -267,8 +270,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
node.remove(toRemove);
}
- private void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node, final EntityImpl
- entity) throws DeserializerException {
+ private void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node,
+ final EntityImpl entity) throws DeserializerException {
List<String> propertyNames = edmEntityType.getPropertyNames();
for (String propertyName : propertyNames) {
JsonNode jsonNode = node.get(propertyName);
@@ -409,7 +412,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
case ENUM:
value = readEnumValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
jsonNode);
- property.setValue(ValueType.PRIMITIVE, value);
+ property.setValue(ValueType.ENUM, value);
break;
case COMPLEX:
value = readComplexNode(name, type, isNullable, jsonNode);
@@ -706,4 +709,81 @@ public class ODataJsonDeserializer implements ODataDeserializer {
DeserializerException.MessageKeys.NOT_IMPLEMENTED);
}
}
+
+ @Override
+ public Property property(InputStream stream, EdmProperty edmProperty)
+ throws DeserializerException {
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
+ JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
+ final ObjectNode tree = parser.getCodec().readTree(parser);
+
+ Property property = null;
+ JsonNode jsonNode = tree.get(Constants.VALUE);
+ if (jsonNode != null) {
+ property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(),
+ edmProperty.isCollection(),
+ edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(),
+ edmProperty.isUnicode(), edmProperty.getMapping(),
+ jsonNode);
+ tree.remove(Constants.VALUE);
+ } else {
+ property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(),
+ edmProperty.isCollection(),
+ edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(),
+ edmProperty.isUnicode(), edmProperty.getMapping(),
+ tree);
+ }
+ return property;
+ } catch (JsonParseException e) {
+ throw new DeserializerException("An JsonParseException occurred", e,
+ DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
+ } catch (JsonMappingException e) {
+ throw new DeserializerException("Duplicate property detected", e,
+ DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
+ } catch (IOException e) {
+ throw new DeserializerException("An IOException occurred", e, DeserializerException.MessageKeys.IO_EXCEPTION);
+ }
+ }
+
+ public List<URI> entityReferences(InputStream stream) throws DeserializerException {
+ try {
+ ArrayList<URI> parsedValues = new ArrayList<URI>();
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true);
+ JsonParser parser = new JsonFactory(objectMapper).createParser(stream);
+ final ObjectNode tree = parser.getCodec().readTree(parser);
+ final String key = "@odata.id";
+ JsonNode jsonNode = tree.get(Constants.VALUE);
+ if (jsonNode != null) {
+ if (jsonNode.isArray()) {
+ ArrayNode arrayNode = (ArrayNode)jsonNode;
+ Iterator<JsonNode> it = arrayNode.iterator();
+ while(it.hasNext()) {
+ parsedValues.add(new URI(it.next().get(key).asText()));
+ }
+ } else {
+ parsedValues.add(new URI(jsonNode.asText()));
+ }
+ tree.remove(Constants.VALUE);
+ // if this is value there can be only one property
+ return parsedValues;
+ }
+ parsedValues.add(new URI(tree.get(key).asText()));
+ return parsedValues;
+ } catch (JsonParseException e) {
+ throw new DeserializerException("An JsonParseException occurred", e,
+ DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
+ } catch (JsonMappingException e) {
+ throw new DeserializerException("Duplicate property detected", e,
+ DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
+ } catch (IOException e) {
+ throw new DeserializerException("An IOException occurred", e,
+ DeserializerException.MessageKeys.IO_EXCEPTION);
+ } catch (URISyntaxException e) {
+ throw new DeserializerException("failed to read @odata.id", e,
+ DeserializerException.MessageKeys.UNKOWN_CONTENT);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index aab6624..5956e82 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -6,9 +6,9 @@
* 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
@@ -41,6 +41,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.server.api.ODataServerError;
@@ -127,7 +128,8 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream entityCollection(final EdmEntityType entityType, final EntitySet entitySet,
+ public InputStream entityCollection(final ServiceMetadata metadata,
+ final EdmEntityType entityType, final EntitySet entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
@@ -145,8 +147,9 @@ public class ODataJsonSerializer implements ODataSerializer {
json.writeNumberField(Constants.JSON_COUNT, entitySet.getCount());
}
json.writeFieldName(Constants.VALUE);
- writeEntitySet(entityType, entitySet,
- options == null ? null : options.getExpand(), options == null ? null : options.getSelect(), json);
+ writeEntitySet(metadata, entityType, entitySet, options == null ? null : options.getExpand(),
+ options == null ? null : options.getSelect(),
+ options == null ? false : options.onlyReferences(), json);
if (entitySet.getNext() != null) {
json.writeStringField(Constants.JSON_NEXT_LINK, entitySet.getNext().toASCIIString());
}
@@ -159,14 +162,16 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream entity(final EdmEntityType entityType, final Entity entity,
- final EntitySerializerOptions options) throws SerializerException {
+ public InputStream entity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ final Entity entity, final EntitySerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
- writeEntity(entityType, entity, contextURL,
- options == null ? null : options.getExpand(), options == null ? null : options.getSelect(), json);
+ writeEntity(metadata, entityType, entity, contextURL,
+ options == null ? null : options.getExpand(),
+ options == null ? null : options.getSelect(),
+ options == null ? false: options.onlyReferences(), json);
json.close();
} catch (final IOException e) {
throw new SerializerException("An I/O exception occurred.", e,
@@ -184,18 +189,26 @@ public class ODataJsonSerializer implements ODataSerializer {
return contextURL;
}
- protected void writeEntitySet(final EdmEntityType entityType, final EntitySet entitySet,
- final ExpandOption expand, final SelectOption select, final JsonGenerator json)
- throws IOException, SerializerException {
+ protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
+ final EntitySet entitySet, final ExpandOption expand, final SelectOption select,
+ final boolean onlyReference, final JsonGenerator json) throws IOException,
+ SerializerException {
json.writeStartArray();
for (final Entity entity : entitySet.getEntities()) {
- writeEntity(entityType, entity, null, expand, select, json);
+ if (onlyReference) {
+ json.writeStartObject();
+ json.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
+ json.writeEndObject();
+ } else {
+ writeEntity(metadata, entityType, entity, null, expand, select, false, json);
+ }
}
json.writeEndArray();
}
- protected void writeEntity(final EdmEntityType entityType, final Entity entity, final ContextURL contextURL,
- final ExpandOption expand, final SelectOption select, final JsonGenerator json)
+ protected void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ final Entity entity, final ContextURL contextURL, final ExpandOption expand,
+ final SelectOption select, boolean onlyReference, final JsonGenerator json)
throws IOException, SerializerException {
json.writeStartObject();
if (format != ODataFormat.JSON_NO_METADATA) {
@@ -214,9 +227,63 @@ public class ODataJsonSerializer implements ODataSerializer {
}
}
}
- writeProperties(entityType, entity.getProperties(), select, json);
- writeNavigationProperties(entityType, entity, expand, json);
- json.writeEndObject();
+ if (onlyReference) {
+ json.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
+ } else {
+ EdmEntityType resolvedType = resolveEntityType(metadata, entityType, entity.getType());
+ if (!resolvedType.equals(entityType)) {
+ json.writeStringField(Constants.JSON_TYPE, "#"+entity.getType());
+ }
+ writeProperties(resolvedType, entity.getProperties(), select, json);
+ writeNavigationProperties(metadata, resolvedType, entity, expand, json);
+ json.writeEndObject();
+ }
+ }
+
+ protected EdmEntityType resolveEntityType(ServiceMetadata metadata, EdmEntityType baseType,
+ String derivedTypeName) throws SerializerException {
+ if (baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
+ return baseType;
+ }
+ EdmEntityType derivedType = metadata.getEdm().getEntityType(new FullQualifiedName(derivedTypeName));
+ if (derivedType == null) {
+ throw new SerializerException("EntityType not found",
+ SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName);
+ }
+ EdmEntityType type = derivedType.getBaseType();
+ while (type != null) {
+ if (type.getFullQualifiedName().getFullQualifiedNameAsString()
+ .equals(baseType.getFullQualifiedName().getFullQualifiedNameAsString())) {
+ return derivedType;
+ }
+ type = type.getBaseType();
+ }
+ throw new SerializerException("Wrong base type",
+ SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType
+ .getFullQualifiedName().getFullQualifiedNameAsString());
+ }
+
+ protected EdmComplexType resolveComplexType(ServiceMetadata metadata, EdmComplexType baseType,
+ String derivedTypeName) throws SerializerException {
+ if (baseType.getFullQualifiedName().getFullQualifiedNameAsString().equals(derivedTypeName)) {
+ return baseType;
+ }
+ EdmComplexType derivedType = metadata.getEdm().getComplexType(new FullQualifiedName(derivedTypeName));
+ if (derivedType == null) {
+ throw new SerializerException("Complex Type not found",
+ SerializerException.MessageKeys.UNKNOWN_TYPE, derivedTypeName);
+ }
+ EdmComplexType type = derivedType.getBaseType();
+ while (type != null) {
+ if (type.getFullQualifiedName().getFullQualifiedNameAsString()
+ .equals(baseType.getFullQualifiedName().getFullQualifiedNameAsString())) {
+ return derivedType;
+ }
+ type = type.getBaseType();
+ }
+ throw new SerializerException("Wrong base type",
+ SerializerException.MessageKeys.WRONG_BASE_TYPE, derivedTypeName, baseType
+ .getFullQualifiedName().getFullQualifiedNameAsString());
}
protected void writeProperties(final EdmStructuredType type, final List<Property> properties,
@@ -235,8 +302,9 @@ public class ODataJsonSerializer implements ODataSerializer {
}
}
- protected void writeNavigationProperties(final EdmStructuredType type, final Linked linked,
- final ExpandOption expand, final JsonGenerator json) throws SerializerException, IOException {
+ protected void writeNavigationProperties(final ServiceMetadata metadata,
+ final EdmStructuredType type, final Linked linked, final ExpandOption expand,
+ final JsonGenerator json) throws SerializerException, IOException {
if (ExpandSelectHelper.hasExpand(expand)) {
final boolean expandAll = ExpandSelectHelper.isExpandAll(expand);
final Set<String> expanded = expandAll ? null :
@@ -251,7 +319,7 @@ public class ODataJsonSerializer implements ODataSerializer {
throw new SerializerException("Expand options $ref and $levels are not supported.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
- writeExpandedNavigationProperty(property, navigationLink,
+ writeExpandedNavigationProperty(metadata, property, navigationLink,
innerOptions == null ? null : innerOptions.getExpandOption(),
innerOptions == null ? null : innerOptions.getSelectOption(),
json);
@@ -260,7 +328,8 @@ public class ODataJsonSerializer implements ODataSerializer {
}
}
- protected void writeExpandedNavigationProperty(final EdmNavigationProperty property, final Link navigationLink,
+ protected void writeExpandedNavigationProperty(final ServiceMetadata metadata,
+ final EdmNavigationProperty property, final Link navigationLink,
final ExpandOption innerExpand, final SelectOption innerSelect, JsonGenerator json)
throws IOException, SerializerException {
json.writeFieldName(property.getName());
@@ -269,13 +338,15 @@ public class ODataJsonSerializer implements ODataSerializer {
json.writeStartArray();
json.writeEndArray();
} else {
- writeEntitySet(property.getType(), navigationLink.getInlineEntitySet(), innerExpand, innerSelect, json);
+ writeEntitySet(metadata, property.getType(), navigationLink.getInlineEntitySet(), innerExpand,
+ innerSelect, false, json);
}
} else {
if (navigationLink == null || navigationLink.getInlineEntity() == null) {
json.writeNull();
} else {
- writeEntity(property.getType(), navigationLink.getInlineEntity(), null, innerExpand, innerSelect, json);
+ writeEntity(metadata, property.getType(), navigationLink.getInlineEntity(), null,
+ innerExpand, innerSelect, false, json);
}
}
}
@@ -316,6 +387,11 @@ public class ODataJsonSerializer implements ODataSerializer {
} else if (property.isComplex()) {
writeComplexValue((EdmComplexType) edmProperty.getType(), property.asComplex().getValue(),
selectedPaths, json);
+ } else if (property.isEnum()) {
+ writePrimitive((EdmPrimitiveType) edmProperty.getType(), property,
+ edmProperty.isNullable(), edmProperty.getMaxLength(),
+ edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
+ json);
} else {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
@@ -467,8 +543,8 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream complex(final EdmComplexType type, final Property property,
- final ComplexSerializerOptions options) throws SerializerException {
+ public InputStream complex(final ServiceMetadata metadata, final EdmComplexType type,
+ final Property property, final ComplexSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
@@ -477,11 +553,15 @@ public class ODataJsonSerializer implements ODataSerializer {
if (contextURL != null) {
json.writeStringField(Constants.JSON_CONTEXT, ContextURLBuilder.create(contextURL).toASCIIString());
}
+ EdmComplexType resolvedType = resolveComplexType(metadata, type, property.getType());
+ if (!resolvedType.equals(type)) {
+ json.writeStringField(Constants.JSON_TYPE, "#"+property.getType());
+ }
final List<Property> values =
property.isNull() ? Collections.<Property> emptyList() : property.asComplex().getValue();
writeProperties(type, values, options == null ? null : options.getSelect(), json);
if (!property.isNull() && property.isComplex()) {
- writeNavigationProperties(type, property.asComplex(),
+ writeNavigationProperties(metadata, type, property.asComplex(),
options == null ? null : options.getExpand(), json);
}
json.writeEndObject();
@@ -523,8 +603,8 @@ public class ODataJsonSerializer implements ODataSerializer {
}
@Override
- public InputStream complexCollection(final EdmComplexType type, final Property property,
- final ComplexSerializerOptions options) throws SerializerException {
+ public InputStream complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
+ final Property property, final ComplexSerializerOptions options) throws SerializerException {
final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
index 4a3f82a..ac33759 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
@@ -66,7 +66,14 @@ public final class ContextURLBuilder {
if (contextURL.getEntitySetOrSingletonOrType() != null) {
throw new IllegalArgumentException("ContextURL: $ref with Entity Set");
}
- result.append('#').append(ContextURL.Suffix.REFERENCE.getRepresentation());
+ if(contextURL.isCollection()) {
+ result.append('#');
+ result.append("Collection(")
+ .append(ContextURL.Suffix.REFERENCE.getRepresentation())
+ .append(")");
+ } else {
+ result.append('#').append(ContextURL.Suffix.REFERENCE.getRepresentation());
+ }
} else if (contextURL.getSuffix() != null) {
if (contextURL.getEntitySetOrSingletonOrType() == null) {
throw new IllegalArgumentException("ContextURL: Suffix without preceding Entity Set!");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
index acd1ded..34756c1 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java
@@ -6,9 +6,9 @@
* 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
@@ -87,14 +87,15 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream entity(final EdmEntityType entityType, final Entity entity,
- final EntitySerializerOptions options) throws SerializerException {
+ public InputStream entity(final ServiceMetadata metadata, final EdmEntityType entityType,
+ final Entity entity, final EntitySerializerOptions options) throws SerializerException {
throw new SerializerException("Entity serialization not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@Override
- public InputStream entityCollection(final EdmEntityType entityType, final EntitySet entitySet,
+ public InputStream entityCollection(final ServiceMetadata metadata,
+ final EdmEntityType entityType, final EntitySet entitySet,
final EntityCollectionSerializerOptions options) throws SerializerException {
throw new SerializerException("Entityset serialization not implemented for XML format",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
@@ -114,8 +115,8 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream complex(final EdmComplexType type, final Property property,
- final ComplexSerializerOptions options) throws SerializerException {
+ public InputStream complex(final ServiceMetadata metadata, final EdmComplexType type,
+ final Property property, final ComplexSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
@@ -128,8 +129,8 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
}
@Override
- public InputStream complexCollection(final EdmComplexType type, final Property property,
- final ComplexSerializerOptions options) throws SerializerException {
+ public InputStream complexCollection(final ServiceMetadata metadata, final EdmComplexType type,
+ final Property property, final ComplexSerializerOptions options) throws SerializerException {
throw new SerializerException("Serialization not implemented for XML format.",
SerializerException.MessageKeys.NOT_IMPLEMENTED);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
index 82fe743..a78d79f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
@@ -6,9 +6,9 @@
* 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
@@ -56,12 +56,18 @@ public class UriResourceActionImpl extends UriResourceTypedImpl implements UriRe
@Override
public boolean isCollection() {
- return action.getReturnType() !=null && action.getReturnType().isCollection();
+ if (action.getReturnType() != null) {
+ return action.getReturnType().isCollection();
+ }
+ return false;
}
@Override
public EdmType getType() {
- return action.getReturnType() == null ? null : action.getReturnType().getType();
+ if (action.getReturnType() != null) {
+ return action.getReturnType().getType();
+ }
+ return null;
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
index 0b3a5f9..cf54938 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
@@ -6,9 +6,9 @@
* 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
@@ -60,7 +60,7 @@ public class UriValidator {
/* entitySetCount 7 */ { true , false, false, false, false, false, true, false, false, false, false },
/* entity 8 */ { false, true , true , false, false, false, false, true , false, false, false },
/* mediaStream 9 */ { false, false, false, false, false, false, false, false, false, false, false },
- /* references 10 */ { true , true , false, false, false, true , true , false, true , true , true },
+ /* references 10 */ { true , true , false, true, false, true , true , false, true , true , true },
/* reference 11 */ { false, true , false, false, false, false, false, false, false, false, false },
/* propertyComplex 12 */ { false, true , true , false, false, false, false, true , false, false, false },
/* propertyComplexCollection 13 */ { true , true , true , false, true , true , false, true , true , true , true },
@@ -78,7 +78,7 @@ public class UriValidator {
/* GET 0 */ { true , true , true , true, true , true , true , true , true , true , true },
/* POST 0 */ { true , false , true , false, false , true , false , true , false , false , false },
/* PUT 0 */ { false , false , false , false, false , false , false , false , false , false , false },
- /* DELETE 0 */ { false , false , false , false, false , false, false , false, false , false , false },
+ /* DELETE 0 */ { false , false , false , true, false , false, false , false, false , false , false },
/* PATCH 0 */ { false , false , false , false, false , false , false , false , false , false , false }
};
//CHECKSTYLE:ON
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index 76266ea..b8254c3 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -96,6 +96,8 @@ SerializerException.INCONSISTENT_PROPERTY_TYPE=An inconsistency has been detecte
SerializerException.MISSING_PROPERTY=The non-nullable property '%1$s' is missing.
SerializerException.WRONG_PROPERTY_VALUE=The value '%2$s' is not valid for property '%1$s'.
SerializerException.WRONG_PRIMITIVE_VALUE=The value '%2$s' is not valid for the primitive type '%1$s' and the given facets.
+SerializerException.UNKNOWN_TYPE=Type '%1s' not found in metadata.
+SerializerException.WRONG_BASE_TYPE=Type '%1s' is not derived from '%2s'.
DeserializerException.NOT_IMPLEMENTED=The requested deserialization method has not been implemented yet.
DeserializerException.IO_EXCEPTION=An I/O exception occurred.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
index f3e22ef..a301c3d 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerBasicTest.java
@@ -6,9 +6,9 @@
* 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
@@ -18,8 +18,13 @@
*/
package org.apache.olingo.server.core.deserializer.json;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.ByteArrayInputStream;
+import java.net.URI;
+import java.util.List;
+
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
@@ -41,4 +46,33 @@ public class ODataJsonDeserializerBasicTest {
assertNotNull(deserializer);
deserializer = null;
}
+
+ @Test
+ public void testReadingCollectionProperties() throws Exception {
+ String payload = "{\n" +
+ " \"@odata.context\": \"http://host/service/$metadata#Collection($ref)\",\n" +
+ " \"value\": [\n" +
+ " { \"@odata.id\": \"Orders(10643)\" },\n" +
+ " { \"@odata.id\": \"Orders(10759)\" }\n" +
+ " ]\n" +
+ "}";
+ ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
+ List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()));
+ assertEquals(2, values.size());
+ assertEquals("Orders(10643)", values.get(0).toASCIIString());
+ assertEquals("Orders(10759)", values.get(1).toASCIIString());
+ }
+
+ @Test
+ public void testReadingProperties() throws Exception {
+ String payload = "{\n" +
+ " \"@odata.context\": \"http://host/service/$metadata#$ref\",\n" +
+ " \"@odata.id\": \"Orders(10643)\"\n" +
+ "}";
+ ODataDeserializer deserializer = OData.newInstance().createDeserializer(ODataFormat.JSON);
+ List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload
+ .getBytes()));
+ assertEquals(1, values.size());
+ assertEquals("Orders(10643)", values.get(0).toASCIIString());
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 742c5d5..1e4537f 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -6,9 +6,9 @@
* 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
@@ -49,14 +49,17 @@ public class ODataJsonSerializerTest {
final ODataJsonSerializer serializer = new ODataJsonSerializer(ODataFormat.APPLICATION_JSON);
final ComplexSerializerOptions options = ComplexSerializerOptions.with()
.contextURL(ContextURL.with().selectList("ComplexCollection").build()).build();
- final InputStream in = serializer.complexCollection(ComplexTypeHelper.createType(), complexCollection, options);
+ final InputStream in = serializer.complexCollection(null, ComplexTypeHelper.createType(),
+ complexCollection, options);
final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("value")) {
- assertEquals("{\"@odata.context\":\"$metadata(ComplexCollection)\",\"value\":"
- + "[{\"prop1\":\"test1\",\"prop2\":\"test11\"},{\"prop1\":\"test2\",\"prop2\":\"test22\"}]}", line);
+ assertEquals(
+ "{\"@odata.context\":\"$metadata(ComplexCollection)\",\"value\":"
+ + "[{\"prop1\":\"test1\",\"prop2\":\"test11\"},{\"prop1\":\"test2\",\"prop2\":\"test22\"}]}",
+ line);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java
index 7fa981b..4137db0 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java
@@ -6,9 +6,9 @@
* 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
@@ -66,8 +66,8 @@ public class TechnicalServlet extends HttpServlet {
}
ODataHttpHandler handler = odata.createHandler(serviceMetadata);
- handler.register(new TechnicalEntityProcessor(dataProvider));
- handler.register(new TechnicalPrimitiveComplexProcessor(dataProvider));
+ handler.register(new TechnicalEntityProcessor(dataProvider, serviceMetadata));
+ handler.register(new TechnicalPrimitiveComplexProcessor(dataProvider, serviceMetadata));
handler.register(new TechnicalBatchProcessor(dataProvider));
handler.process(req, resp);
} catch (RuntimeException e) {
[50/50] [abbrv] olingo-odata4 git commit: [OLINGO-552] Initial set of
modules for OData JPA processor
Posted by ch...@apache.org.
[OLINGO-552] Initial set of modules for OData JPA processor
Signed-off-by: Chandan V A <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/758143fd
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/758143fd
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/758143fd
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 758143fd2aa05b98d02f6469126a91fd3fcd6371
Parents: 97a0178
Author: Chandan V A <ch...@sap.com>
Authored: Sat Apr 4 22:29:06 2015 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Sat Apr 4 22:29:06 2015 +0530
----------------------------------------------------------------------
ext/odata-jpa/odata-jpa-api/pom.xml | 45 ++++++++
.../apache/olingo/jpa/api/ODataJPAServlet.java | 30 ++++++
ext/odata-jpa/odata-jpa-core/pom.xml | 36 +++++++
ext/odata-jpa/odata-jpa-ref-persistence/pom.xml | 55 ++++++++++
.../apache/olingo/jpa/ref/model/Address.java | 105 +++++++++++++++++++
.../apache/olingo/jpa/ref/model/Customer.java | 52 +++++++++
.../src/main/resources/META-INF/persistence.xml | 33 ++++++
ext/odata-jpa/odata-jpa-ref-web/pom.xml | 44 ++++++++
.../src/main/webapp/WEB-INF/web.xml | 38 +++++++
ext/odata-jpa/pom.xml | 72 +++++++++++++
ext/pom.xml | 5 +-
11 files changed, 512 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/odata-jpa-api/pom.xml
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/odata-jpa-api/pom.xml b/ext/odata-jpa/odata-jpa-api/pom.xml
new file mode 100644
index 0000000..1e154b8
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-api/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<!-- 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. -->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-jpa</artifactId>
+ <version>4.0.0-beta-01-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+
+ <artifactId>odata-jpa-api</artifactId>
+ <name>${project-artifactId}</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-commons-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/odata-jpa-api/src/main/java/org/apache/olingo/jpa/api/ODataJPAServlet.java
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/odata-jpa-api/src/main/java/org/apache/olingo/jpa/api/ODataJPAServlet.java b/ext/odata-jpa/odata-jpa-api/src/main/java/org/apache/olingo/jpa/api/ODataJPAServlet.java
new file mode 100644
index 0000000..6cf038f
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-api/src/main/java/org/apache/olingo/jpa/api/ODataJPAServlet.java
@@ -0,0 +1,30 @@
+/*
+ * 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.jpa.api;
+
+import javax.servlet.http.HttpServlet;
+
+public class ODataJPAServlet extends HttpServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/odata-jpa-core/pom.xml
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/odata-jpa-core/pom.xml b/ext/odata-jpa/odata-jpa-core/pom.xml
new file mode 100644
index 0000000..fbbf03a
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-core/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<!-- 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. -->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-jpa</artifactId>
+ <version>4.0.0-beta-01-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>odata-jpa-core</artifactId>
+ <name>${project.artifactId}</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/odata-jpa-ref-persistence/pom.xml
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/odata-jpa-ref-persistence/pom.xml b/ext/odata-jpa/odata-jpa-ref-persistence/pom.xml
new file mode 100644
index 0000000..77cb0d7
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-ref-persistence/pom.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-jpa</artifactId>
+ <version>4.0.0-beta-01-SNAPSHOT</version>
+ </parent>
+ <artifactId>odata-jpa-ref-persistence</artifactId>
+ <name>${project-artifactId}</name>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- JPA Support -->
+ <dependency>
+ <groupId>org.eclipse.persistence</groupId>
+ <artifactId>eclipselink</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.persistence</groupId>
+ <artifactId>javax.persistence</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>2.3.2</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Address.java
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Address.java b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Address.java
new file mode 100644
index 0000000..fa0afb2
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Address.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * 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.jpa.ref.model;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class Address {
+
+ public Address() {
+ super();
+ }
+
+ public Address(final short houseNumber, final String streetName, final String city,
+ final String country) {
+ this();
+ this.houseNumber = houseNumber;
+ this.streetName = streetName;
+ this.city = city;
+ this.country = country;
+ }
+
+ @Column(name = "HOUSE_NUMBER")
+ private short houseNumber;
+
+ @Column(name = "STREET_NAME")
+ private String streetName;
+
+ @Column(name = "CITY")
+ private String city;
+
+ @Column(name = "COUNTRY")
+ private String country;
+
+ @Column(name = "PINCODE")
+ private String pincode;
+
+ @Column(name = "STATE")
+ private String state;
+
+ public String getPincode() {
+ return pincode;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public void setPincode(final String pincode) {
+ this.pincode = pincode;
+ }
+
+ public short getHouseNumber() {
+ return houseNumber;
+ }
+
+ public void setHouseNumber(final short houseNumber) {
+ this.houseNumber = houseNumber;
+ }
+
+ public String getStreetName() {
+ return streetName;
+ }
+
+ public void setStreetName(final String streetName) {
+ this.streetName = streetName;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(final String city) {
+ this.city = city;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(final String country) {
+ this.country = country;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Customer.java
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Customer.java b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Customer.java
new file mode 100644
index 0000000..b65a056
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/java/org/apache/olingo/jpa/ref/model/Customer.java
@@ -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.jpa.ref.model;
+
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "T_CUSTOMER")
+public class Customer {
+
+ @Column(name = "ID")
+ private long id;
+ @Column(name = "NAME")
+ private String name;
+ @Embedded
+ private Address address;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/odata-jpa-ref-persistence/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/odata-jpa-ref-persistence/src/main/resources/META-INF/persistence.xml b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..66ab54b
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-ref-persistence/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<persistence version="2.0"
+ xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
+ <persistence-unit name="salesorderprocessing"
+ transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <class>org.apache.olingo.jpa.ref.model.Customer</class>
+ <properties>
+ <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
+ <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:apache.olingo.jpa.sample" />
+ <property name="javax.persistence.jdbc.user" value="sa" />
+ <property name="javax.persistence.jdbc.password" value="" />
+ <property name="eclipselink.target-database"
+ value="org.eclipse.persistence.platform.database.HSQLPlatform" />
+ <property name="eclipselink.logging.level" value="ALL" />
+ <property name="eclipselink.orm.throw.exceptions" value="true" />
+ <property name="eclipselink.ddl-generation" value="create-tables" />
+ <property name="eclipselink.ddl-generation.output-mode"
+ value="database" />
+ </properties>
+ </persistence-unit>
+</persistence>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/odata-jpa-ref-web/pom.xml
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/odata-jpa-ref-web/pom.xml b/ext/odata-jpa/odata-jpa-ref-web/pom.xml
new file mode 100644
index 0000000..a7b85cc
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-ref-web/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-jpa</artifactId>
+ <version>4.0.0-beta-01-SNAPSHOT</version>
+ </parent>
+ <artifactId>odata-jpa-ref-web</artifactId>
+ <name>${project.artifactId}</name>
+ <packaging>war</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-jpa-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ </dependencies>
+ <build>
+ <finalName>odata-jpa-ref-web</finalName>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/odata-jpa-ref-web/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/odata-jpa-ref-web/src/main/webapp/WEB-INF/web.xml b/ext/odata-jpa/odata-jpa-ref-web/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..3da07e0
--- /dev/null
+++ b/ext/odata-jpa/odata-jpa-ref-web/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ id="WebApp_ID" version="2.5">
+ <display-name>Apache Olingo OData V 4.0 extension - JPA</display-name>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+
+ <servlet>
+ <servlet-name>ODataJPAReferenceServlet</servlet-name>
+ <servlet-class>org.apache.odata.jpa.api.servlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>ODataJPAReferenceServlet</servlet-name>
+ <url-pattern>/SalesOrderProcessing.svc/*</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/odata-jpa/pom.xml
----------------------------------------------------------------------
diff --git a/ext/odata-jpa/pom.xml b/ext/odata-jpa/pom.xml
new file mode 100644
index 0000000..41c8752
--- /dev/null
+++ b/ext/odata-jpa/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<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>
+
+ <artifactId>odata-jpa</artifactId>
+ <packaging>pom</packaging>
+ <version>4.0.0-beta-01-SNAPSHOT</version>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-ext</artifactId>
+ <version>4.0.0-beta-03-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <properties>
+ <version.odata>4.0.0-beta-03-SNAPSHOT</version.odata>
+ <version.eclipselink>2.5.1</version.eclipselink>
+ <version.javax.persistence>2.0.5</version.javax.persistence>
+ <version.javax.servlet>2.5</version.javax.servlet>
+ </properties>
+
+ <modules>
+ <module>odata-jpa-api</module>
+ <module>odata-jpa-core</module>
+ <module>odata-jpa-ref-persistence</module>
+ <module>odata-jpa-ref-web</module>
+ </modules>
+
+ <dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${version.javax.servlet}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.persistence</groupId>
+ <artifactId>eclipselink</artifactId>
+ <version>${version.eclipselink}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.persistence</groupId>
+ <artifactId>javax.persistence</artifactId>
+ <version>${version.javax.persistence}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-client-api</artifactId>
+ <version>${version.odata}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>odata-commons-api</artifactId>
+ <version>${version.odata}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/758143fd/ext/pom.xml
----------------------------------------------------------------------
diff --git a/ext/pom.xml b/ext/pom.xml
index a36be45..262dfe5 100644
--- a/ext/pom.xml
+++ b/ext/pom.xml
@@ -18,9 +18,7 @@
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">
+--><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>
<groupId>org.apache.olingo</groupId>
@@ -39,5 +37,6 @@
<module>pojogen-maven-plugin</module>
<module>client-proxy</module>
<module>client-android</module>
+ <module>odata-jpa</module>
</modules>
</project>
[31/50] [abbrv] olingo-odata4 git commit: OLINGO-573: New processing
framework on server side with single interface with TripPin as example
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
new file mode 100644
index 0000000..32bf26a
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/DataRequest.java
@@ -0,0 +1,769 @@
+/*
+ * 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.requests;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.ContextURL.Suffix;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmBindingTarget;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.core.data.PropertyImpl;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmStream;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
+import org.apache.olingo.server.api.deserializer.ODataDeserializer;
+import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.uri.UriHelper;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResource;
+import org.apache.olingo.server.api.uri.UriResourceComplexProperty;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.api.uri.UriResourceNavigation;
+import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
+import org.apache.olingo.server.api.uri.UriResourceProperty;
+import org.apache.olingo.server.api.uri.UriResourceSingleton;
+import org.apache.olingo.server.core.ContentNegotiator;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.responses.CountResponse;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public class DataRequest extends ServiceRequest {
+ protected UriResourceEntitySet uriResourceEntitySet;
+ private boolean countRequest;
+ private UriResourceProperty uriResourceProperty;
+ private boolean valueRequest;
+ private final LinkedList<UriResourceNavigation> uriNavigations = new LinkedList<UriResourceNavigation>();
+ private boolean references;
+
+ private RequestType type;
+ private UriResourceSingleton uriResourceSingleton;
+
+ /**
+ * This sub-categorizes the request so that code can be simplified
+ */
+ interface RequestType {
+ public boolean allowedMethod();
+
+ public ContentType getResponseContentType() throws ContentNegotiatorException;
+
+ public ContextURL getContextURL(OData odata) throws SerializerException;
+
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException;
+ }
+
+ public DataRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ public UriResourceEntitySet getUriResourceEntitySet() {
+ return uriResourceEntitySet;
+ }
+
+ public void setUriResourceEntitySet(UriResourceEntitySet uriResourceEntitySet) {
+ this.uriResourceEntitySet = uriResourceEntitySet;
+ this.type = new EntityRequest();
+ }
+
+ public void setCrossJoin(UriInfoCrossjoin info) {
+ this.type = new CrossJoinRequest(info.getEntitySetNames());
+ }
+
+ public boolean isSingleton() {
+ return this.uriResourceSingleton != null;
+ }
+
+ public boolean isCollection() {
+ if (!this.uriNavigations.isEmpty()) {
+ return this.uriNavigations.getLast().isCollection();
+ }
+ return this.uriResourceEntitySet != null && this.uriResourceEntitySet.isCollection();
+ }
+
+ public EdmEntitySet getEntitySet() {
+ return this.uriResourceEntitySet.getEntitySet();
+ }
+
+ public boolean isCountRequest() {
+ return countRequest;
+ }
+
+ public void setCountRequest(boolean countRequest) {
+ this.countRequest = countRequest;
+ this.type = new CountRequest();
+ }
+
+ public boolean isPropertyRequest() {
+ return this.uriResourceProperty != null;
+ }
+
+ public boolean isPropertyComplex() {
+ return (this.uriResourceProperty instanceof UriResourceComplexProperty);
+ }
+
+ public boolean isPropertyStream() {
+ if (isPropertyComplex()) {
+ return false;
+ }
+ EdmProperty property = ((UriResourcePrimitiveProperty)this.uriResourceProperty).getProperty();
+ return (property.getType() instanceof EdmStream);
+ }
+
+ public UriResourceProperty getUriResourceProperty() {
+ return uriResourceProperty;
+ }
+
+ public void setUriResourceProperty(UriResourceProperty uriResourceProperty) {
+ this.uriResourceProperty = uriResourceProperty;
+ this.type = new PropertyRequest();
+ }
+
+ public LinkedList<UriResourceNavigation> getNavigations() {
+ return this.uriNavigations;
+ }
+
+ public void addUriResourceNavigation(UriResourceNavigation uriResourceNavigation) {
+ this.uriNavigations.add(uriResourceNavigation);
+ }
+
+ public UriResourceSingleton getUriResourceSingleton() {
+ return this.uriResourceSingleton;
+ }
+
+ public void setUriResourceSingleton(UriResourceSingleton info) {
+ this.uriResourceSingleton = info;
+ this.type = new SingletonRequest();
+ }
+
+ public List<UriParameter> getKeyPredicates() {
+ if (this.uriResourceEntitySet != null) {
+ return this.uriResourceEntitySet.getKeyPredicates();
+ }
+ return null;
+ }
+
+ public boolean isReferenceRequest() {
+ return this.references;
+ }
+
+ public void setReferenceRequest(boolean ref) {
+ this.references = ref;
+ this.type = new ReferenceRequest();
+ }
+
+ public boolean isValueRequest() {
+ return valueRequest;
+ }
+
+ private boolean hasMediaStream() {
+ return this.uriResourceEntitySet != null && this.uriResourceEntitySet.getEntityType().hasStream();
+ }
+
+ private InputStream getMediaStream() {
+ return this.request.getBody();
+ }
+
+ public void setValueRequest(boolean valueRequest) {
+ this.valueRequest = valueRequest;
+ this.type = new ValueRequest();
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ return this.type.allowedMethod();
+ }
+
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ return type.getContextURL(odata);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!this.type.allowedMethod()) {
+ methodNotAllowed();
+ }
+
+ this.type.execute(handler, response);
+ }
+
+ @Override
+ public <T> T getSerializerOptions(Class<T> serilizerOptions, ContextURL contextUrl, boolean references)
+ throws ContentNegotiatorException {
+ if (serilizerOptions.isAssignableFrom(PrimitiveSerializerOptions.class)) {
+ return (T) PrimitiveSerializerOptions.with().contextURL(contextUrl)
+ .facetsFrom(getUriResourceProperty().getProperty()).build();
+ }
+ return super.getSerializerOptions(serilizerOptions, contextUrl, references);
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return type.getResponseContentType();
+ }
+
+ class EntityRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ // the create/update/delete to navigation property is done through references
+ // see # 11.4.6
+ if (!getNavigations().isEmpty() && !isGET()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), getODataRequest(),
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_ENTITY
+ : RepresentationType.ENTITY);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ EntityResponse entityResponse = EntityResponse.getInstance(DataRequest.this,
+ getContextURL(odata), false, response);
+
+ if (isGET()) {
+ if (isCollection()) {
+ handler.read(DataRequest.this,
+ EntitySetResponse.getInstance(DataRequest.this, getContextURL(odata), false, response));
+ } else {
+ handler.read(DataRequest.this,entityResponse);
+ }
+ } else if (isPUT() || isPATCH()) {
+ // RFC 2616: he result of a request having both an If-Match header field and either
+ // an If-None-Match or an If-Modified-Since header fields is undefined
+ // by this specification.
+ boolean ifMatch = getHeader(HttpHeader.IF_MATCH) != null;
+ boolean ifNoneMatch = getHeader(HttpHeader.IF_NONE_MATCH).equals("*");
+ if(ifMatch) {
+ handler.updateEntity(DataRequest.this, getEntityFromClient(), isPATCH(), getETag(),
+ entityResponse);
+ } else if (ifNoneMatch) {
+ // 11.4.4
+ entityResponse = EntityResponse.getInstance(DataRequest.this,
+ getContextURL(odata), false, response, getReturnRepresentation());
+ handler.createEntity(DataRequest.this, getEntityFromClient(), entityResponse);
+ } else {
+ handler.updateEntity(DataRequest.this, getEntityFromClient(), isPATCH(), getETag(),
+ entityResponse);
+ }
+ } else if (isPOST()) {
+ entityResponse = EntityResponse.getInstance(DataRequest.this,
+ getContextURL(odata), false, response, getReturnRepresentation());
+ handler.createEntity(DataRequest.this, getEntityFromClient(),entityResponse);
+ } else if (isDELETE()) {
+ handler.deleteEntity(DataRequest.this, getETag(), entityResponse);
+ }
+ }
+
+ private Entity getEntityFromClient() throws DeserializerException {
+ ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
+ .fromContentType(getRequestContentType()));
+ return deserializer.entity(getODataRequest().getBody(), getEntitySet().getEntityType());
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ // EntitySet based return
+ final UriHelper helper = odata.createUriHelper();
+ ContextURL.Builder builder = buildEntitySetContextURL(helper, getEntitySet(),
+ getKeyPredicates(), getUriInfo(), getNavigations(), isCollection(), false);
+ return builder.build();
+ }
+ }
+
+ class CountRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ return isGET();
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentType.TEXT_PLAIN;
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ handler.read(DataRequest.this, CountResponse.getInstance(DataRequest.this, response));
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ return null;
+ }
+ }
+
+ /**
+ * Is NavigationProperty Reference.
+ */
+ class ReferenceRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ // references are only allowed on the navigation properties
+ if (getNavigations().isEmpty()) {
+ return false;
+ }
+
+ // 11.4.6.1 - post allowed on only collection valued navigation
+ if (isPOST() && !getNavigations().getLast().isCollection()) {
+ return false;
+ }
+
+ // 11.4.6.3 - PUT allowed on single valued navigation
+ if (isPUT() && getNavigations().getLast().isCollection()) {
+ return false;
+ }
+
+ // No defined behavior in spec
+ if (isPATCH()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), getODataRequest(),
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_REFERENCE
+ : RepresentationType.REFERENCE);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ if (isGET()) {
+ if (isCollection()) {
+ handler.read(DataRequest.this,
+ EntitySetResponse.getInstance(DataRequest.this, getContextURL(odata), true, response));
+ } else {
+ handler.read(DataRequest.this,
+ EntityResponse.getInstance(DataRequest.this, getContextURL(odata), true, response));
+ }
+ } else if (isDELETE()) {
+ // if this against the collection, user need to look at $id param for entity ref #11.4.6.2
+ String id = getQueryParameter("$id");
+ if (id == null) {
+ handler.deleteReference(DataRequest.this, null, getETag(), new NoContentResponse(
+ getServiceMetaData(), response));
+ } else {
+ try {
+ handler.deleteReference(DataRequest.this, new URI(id), getETag(), new NoContentResponse(
+ getServiceMetaData(), response));
+ } catch (URISyntaxException e) {
+ throw new DeserializerException("failed to read $id", e, MessageKeys.UNKOWN_CONTENT);
+ }
+ }
+ } else if (isPUT()) {
+ // note this is always against single reference
+ handler.updateReference(DataRequest.this, getETag(), getPayload().get(0), new NoContentResponse(
+ getServiceMetaData(), response));
+ } else if (isPOST()) {
+ // this needs to be against collection of references
+ handler.addReference(DataRequest.this, getETag(), getPayload(), new NoContentResponse(
+ getServiceMetaData(), response));
+ }
+ }
+
+ // http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os
+ // /odata-json-format-v4.0-errata02-os-complete.html#_Toc403940643
+ // The below code reads as property and converts to an URI
+ private List<URI> getPayload() throws DeserializerException {
+ ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
+ .fromContentType(getRequestContentType()));
+ return deserializer.entityReferences(getODataRequest().getBody());
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ ContextURL.Builder builder = ContextURL.with().suffix(Suffix.REFERENCE);
+ if (isCollection()) {
+ builder.asCollection();
+ }
+ return builder.build();
+ }
+ }
+
+ class PropertyRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ // create of properties is not allowed,
+ // only read, update, delete. Note that delete is
+ // same as update with null
+ if (isPOST()) {
+ return false;
+ }
+
+ // 11.4.9.4, collection properties are not supported with merge
+ if (isPATCH() && (isCollection() || isPropertyStream())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ if (isPropertyComplex()) {
+ return ContentNegotiator.doContentNegotiation(getUriInfo().getFormatOption(),
+ getODataRequest(), getCustomContentTypeSupport(),
+ isCollection() ? RepresentationType.COLLECTION_COMPLEX : RepresentationType.COMPLEX);
+ } else if (isPropertyStream()) {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request,
+ getCustomContentTypeSupport(), RepresentationType.BINARY);
+ }
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), getODataRequest(),
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_PRIMITIVE
+ : RepresentationType.PRIMITIVE);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ EdmProperty edmProperty = getUriResourceProperty().getProperty();
+
+ if (isGET()) {
+ if (isPropertyStream()) {
+ handler.read(DataRequest.this, new StreamResponse(getServiceMetaData(), response));
+ } else {
+ handler.read(DataRequest.this, buildResponse(response, edmProperty));
+ }
+ } else if (isPATCH()) {
+ handler.updateProperty(DataRequest.this, getPropertyValueFromClient(edmProperty), true,
+ getETag(), buildResponse(response, edmProperty));
+ } else if (isPUT()) {
+ if (isPropertyStream()) {
+ handler.upsertStreamProperty(DataRequest.this, getETag(), request.getBody(),
+ new NoContentResponse(getServiceMetaData(), response));
+ } else {
+ handler.updateProperty(DataRequest.this, getPropertyValueFromClient(edmProperty), false,
+ getETag(), buildResponse(response, edmProperty));
+ }
+ } else if (isDELETE()) {
+ if (isPropertyStream()) {
+ handler.upsertStreamProperty(DataRequest.this, getETag(), request.getBody(),
+ new NoContentResponse(getServiceMetaData(), response));
+ } else {
+ Property property = new PropertyImpl();
+ property.setName(edmProperty.getName());
+ property.setType(edmProperty.getType().getFullQualifiedName()
+ .getFullQualifiedNameAsString());
+ handler.updateProperty(DataRequest.this, property, false, getETag(),
+ buildResponse(response, edmProperty));
+ }
+ }
+ }
+
+ private PropertyResponse buildResponse(ODataResponse response, EdmProperty edmProperty)
+ throws ContentNegotiatorException, SerializerException {
+ PropertyResponse propertyResponse = PropertyResponse.getInstance(DataRequest.this, response,
+ edmProperty.getType(), getContextURL(odata), edmProperty.isCollection());
+ return propertyResponse;
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ final UriHelper helper = odata.createUriHelper();
+ EdmProperty edmProperty = getUriResourceProperty().getProperty();
+
+ ContextURL.Builder builder = ContextURL.with().entitySet(getEntitySet());
+ builder = ContextURL.with().entitySet(getEntitySet());
+ builder.keyPath(helper.buildContextURLKeyPredicate(getUriResourceEntitySet()
+ .getKeyPredicates()));
+ String navPath = buildNavPath(helper, getEntitySet().getEntityType(), getNavigations(), true);
+ if (navPath != null && !navPath.isEmpty()) {
+ builder.navOrPropertyPath(navPath+"/"+edmProperty.getName());
+ } else {
+ builder.navOrPropertyPath(edmProperty.getName());
+ }
+ if (isPropertyComplex()) {
+ EdmComplexType type = ((UriResourceComplexProperty) uriResourceProperty).getComplexType();
+ String select = helper.buildContextURLSelectList(type, getUriInfo().getExpandOption(),
+ getUriInfo().getSelectOption());
+ builder.selectList(select);
+ }
+ return builder.build();
+ }
+ }
+
+ class ValueRequest extends PropertyRequest {
+
+ @Override
+ public boolean allowedMethod() {
+ //part2-url-conventions # 4.2
+ if (isPropertyStream() && isGET()) {
+ return false;
+ }
+
+ return isGET() || isDELETE() || isPUT();
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ RepresentationType valueRepresentationType = uriResourceProperty.getType() == EdmPrimitiveTypeFactory
+ .getInstance(EdmPrimitiveTypeKind.Binary) ? RepresentationType.BINARY
+ : RepresentationType.VALUE;
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request,
+ getCustomContentTypeSupport(), valueRepresentationType);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ EdmProperty edmProperty = getUriResourceProperty().getProperty();
+ if (isGET()) {
+ handler.read(DataRequest.this, PrimitiveValueResponse.getInstance(DataRequest.this,
+ response, isCollection(), getUriResourceProperty().getProperty()));
+ } else if (isDELETE()) {
+ Property property = new PropertyImpl();
+ property.setName(edmProperty.getName());
+ property.setType(edmProperty.getType().getFullQualifiedName().getFullQualifiedNameAsString());
+
+ PropertyResponse propertyResponse = PropertyResponse.getInstance(DataRequest.this, response,
+ edmProperty.getType(), getContextURL(odata), edmProperty.isCollection());
+ handler.updateProperty(DataRequest.this, property, false, getETag(), propertyResponse);
+ } else if (isPUT()) {
+ PropertyResponse propertyResponse = PropertyResponse.getInstance(DataRequest.this, response,
+ edmProperty.getType(), getContextURL(odata), edmProperty.isCollection());
+ handler.updateProperty(DataRequest.this, getPropertyValueFromClient(edmProperty), false,
+ getETag(), propertyResponse);
+ }
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ return null;
+ }
+ }
+
+ class SingletonRequest implements RequestType {
+
+ @Override
+ public boolean allowedMethod() {
+ return isGET();
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), getODataRequest(),
+ getCustomContentTypeSupport(), RepresentationType.ENTITY);
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ final UriHelper helper = odata.createUriHelper();
+ ContextURL.Builder builder = buildEntitySetContextURL(helper,
+ uriResourceSingleton.getSingleton(), null, getUriInfo(), getNavigations(), isCollection(), true);
+ return builder.build();
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ handler.read(DataRequest.this,
+ EntityResponse.getInstance(DataRequest.this, getContextURL(odata), false, response));
+ }
+ }
+
+ class CrossJoinRequest implements RequestType {
+ private final List<String> entitySetNames;
+
+ public CrossJoinRequest(List<String> entitySetNames) {
+ this.entitySetNames = entitySetNames;
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ return isGET();
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(getUriInfo().getFormatOption(),
+ getODataRequest(), getCustomContentTypeSupport(), RepresentationType.COLLECTION_COMPLEX);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ handler.crossJoin(DataRequest.this, this.entitySetNames, response);
+ }
+
+ @Override
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ ContextURL.Builder builder = ContextURL.with().asCollection();
+ return builder.build();
+ }
+ }
+
+ private org.apache.olingo.commons.api.data.Property getPropertyValueFromClient(
+ EdmProperty edmProperty) throws DeserializerException {
+ // TODO:this is not right, we should be deserializing the property
+ // (primitive, complex, collection of)
+ // for now it is responsibility of the user
+ ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
+ .fromContentType(getRequestContentType()));
+ return deserializer.property(getODataRequest().getBody(), edmProperty);
+ }
+
+ static ContextURL.Builder buildEntitySetContextURL(UriHelper helper,
+ EdmBindingTarget edmEntitySet, List<UriParameter> keyPredicates, UriInfo uriInfo,
+ LinkedList<UriResourceNavigation> navigations, boolean collectionReturn, boolean singleton)
+ throws SerializerException {
+
+ ContextURL.Builder builder = ContextURL.with().entitySetOrSingletonOrType(edmEntitySet.getName());
+ String select = helper.buildContextURLSelectList(edmEntitySet.getEntityType(),
+ uriInfo.getExpandOption(), uriInfo.getSelectOption());
+ if (!singleton) {
+ builder.suffix(collectionReturn ? null : Suffix.ENTITY);
+ }
+
+ builder.selectList(select);
+
+ final UriInfoResource resource = uriInfo.asUriInfoResource();
+ final List<UriResource> resourceParts = resource.getUriResourceParts();
+ final List<String> path = getPropertyPath(resourceParts);
+ String propertyPath = buildPropertyPath(path);
+ final String navPath = buildNavPath(helper, edmEntitySet.getEntityType(), navigations, collectionReturn);
+ if (navPath != null && !navPath.isEmpty()) {
+ if (keyPredicates != null) {
+ builder.keyPath(helper.buildContextURLKeyPredicate(keyPredicates));
+ }
+ if (propertyPath != null) {
+ propertyPath = navPath+"/"+propertyPath;
+ } else {
+ propertyPath = navPath;
+ }
+ }
+ builder.navOrPropertyPath(propertyPath);
+ return builder;
+ }
+
+ private static List<String> getPropertyPath(final List<UriResource> path) {
+ List<String> result = new LinkedList<String>();
+ int index = 1;
+ while (index < path.size() && path.get(index) instanceof UriResourceProperty) {
+ result.add(((UriResourceProperty) path.get(index)).getProperty().getName());
+ index++;
+ }
+ return result;
+ }
+
+ private static String buildPropertyPath(final List<String> path) {
+ StringBuilder result = new StringBuilder();
+ for (final String segment : path) {
+ result.append(result.length() == 0 ? "" : '/').append(segment); //$NON-NLS-1$
+ }
+ return result.length() == 0?null:result.toString();
+ }
+
+ static String buildNavPath(UriHelper helper, EdmEntityType rootType,
+ LinkedList<UriResourceNavigation> navigations, boolean includeLastPredicates)
+ throws SerializerException {
+ if (navigations.isEmpty()) {
+ return null;
+ }
+ StringBuilder sb = new StringBuilder();
+ boolean containsTarget = false;
+ EdmEntityType type = rootType;
+ for (UriResourceNavigation nav:navigations) {
+ String name = nav.getProperty().getName();
+ EdmNavigationProperty property = type.getNavigationProperty(name);
+ if (property.containsTarget()) {
+ containsTarget = true;
+ }
+ type = nav.getProperty().getType();
+ }
+
+ if (containsTarget) {
+ for (int i = 0; i < navigations.size(); i++) {
+ UriResourceNavigation nav = navigations.get(i);
+ if (i > 0) {
+ sb.append("/");
+ }
+ sb.append(nav.getProperty().getName());
+
+ boolean skipKeys = false;
+ if (navigations.size() == i+1 && !includeLastPredicates ) {
+ skipKeys = true;
+ }
+
+ if (!skipKeys && !nav.getKeyPredicates().isEmpty()) {
+ sb.append("(");
+ sb.append(helper.buildContextURLKeyPredicate(nav.getKeyPredicates()));
+ sb.append(")");
+ }
+
+ if (nav.getTypeFilterOnCollection() != null) {
+ sb.append("/")
+ .append(nav.getTypeFilterOnCollection().getFullQualifiedName().getFullQualifiedNameAsString());
+ } else if (nav.getTypeFilterOnEntry() != null) {
+ sb.append("/")
+ .append(nav.getTypeFilterOnEntry().getFullQualifiedName().getFullQualifiedNameAsString());
+ }
+ }
+ }
+ return sb.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/FunctionRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/FunctionRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/FunctionRequest.java
new file mode 100644
index 0000000..a9f9341
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/FunctionRequest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.requests;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResourceFunction;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.responses.EntityResponse;
+import org.apache.olingo.server.core.responses.EntitySetResponse;
+import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
+import org.apache.olingo.server.core.responses.PropertyResponse;
+
+public class FunctionRequest extends OperationRequest {
+ private UriResourceFunction uriResourceFunction;
+
+ public FunctionRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+
+ // Functions always have return per 11.5.3
+ if (isReturnTypePrimitive()) {
+ // functions can not return a typed property in the context of entity, so
+ // it must be treated
+ // as value based response
+ handler.invoke(this, getODataRequest().getMethod(),
+ PrimitiveValueResponse.getInstance(this, response, isCollection(), getReturnType()));
+ } else if (isReturnTypeComplex()) {
+ handler.invoke(this, getODataRequest().getMethod(), PropertyResponse.getInstance(this, response,
+ getReturnType().getType(), getContextURL(this.odata), isCollection()));
+ } else {
+ // returnType.getType().getKind() == EdmTypeKind.ENTITY
+ if (isCollection()) {
+ handler.invoke(this, getODataRequest().getMethod(),
+ EntitySetResponse.getInstance(this, getContextURL(odata), false, response));
+ } else {
+ handler.invoke(this, getODataRequest().getMethod(),
+ EntityResponse.getInstance(this, getContextURL(odata), false, response));
+ }
+ }
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ // look for discussion about composable functions in odata-discussion
+ // group with thread "Clarification on "Function" invocations"
+ if (getFunction().isComposable()) {
+ return (isGET() || isPATCH() || isDELETE() || isPOST() || isPUT());
+ }
+ return isGET();
+ }
+
+ public UriResourceFunction getUriResourceFunction() {
+ return uriResourceFunction;
+ }
+
+ public void setUriResourceFunction(UriResourceFunction uriResourceFunction) {
+ this.uriResourceFunction = uriResourceFunction;
+ }
+
+ @Override
+ public boolean isBound() {
+ return this.uriResourceFunction.getFunctionImport() != null;
+ }
+
+ public EdmFunction getFunction() {
+ return this.uriResourceFunction.getFunction();
+ }
+
+ public List<UriParameter> getParameters() {
+ return this.uriResourceFunction.getParameters();
+ }
+
+ @Override
+ public boolean isCollection() {
+ return getFunction().getReturnType().isCollection();
+ }
+
+ @Override
+ public EdmReturnType getReturnType() {
+ return getFunction().getReturnType();
+ }
+
+ @Override
+ public boolean hasReturnType() {
+ // Part3 {12.1} says must have return type
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MediaRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MediaRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MediaRequest.java
new file mode 100644
index 0000000..a4a333a
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MediaRequest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.requests;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResourceEntitySet;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.responses.NoContentResponse;
+import org.apache.olingo.server.core.responses.StreamResponse;
+
+public class MediaRequest extends ServiceRequest {
+ private UriResourceEntitySet uriResourceEntitySet;
+
+ public MediaRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+ // POST will not be here, because the media is created as part of media
+ // entity creation
+ if (isGET()) {
+ handler.readMediaStream(this, new StreamResponse(getServiceMetaData(), response));
+ } else if (isPUT()) {
+ handler.upsertMediaStream(this, getETag(), getMediaStream(), new NoContentResponse(
+ getServiceMetaData(), response));
+ } else if (isDELETE()) {
+ handler.upsertMediaStream(this, getETag(), null, new NoContentResponse(getServiceMetaData(),
+ response));
+ }
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ // the request must specify the content type requested.
+ return getRequestContentType();
+ }
+
+ public EdmEntitySet getEntitySet() {
+ return this.uriResourceEntitySet.getEntitySet();
+ }
+
+ public EdmEntityType getEntityType() {
+ return this.uriResourceEntitySet.getEntitySet().getEntityType();
+ }
+
+ public void setUriResourceEntitySet(UriResourceEntitySet uriResourceEntitySet) {
+ this.uriResourceEntitySet = uriResourceEntitySet;
+ }
+
+ public List<UriParameter> getKeyPredicates() {
+ if (this.uriResourceEntitySet != null) {
+ return this.uriResourceEntitySet.getKeyPredicates();
+ }
+ return null;
+ }
+
+ private InputStream getMediaStream() {
+ return this.request.getBody();
+ }
+
+ @Override
+ public boolean allowedMethod() {
+ return isGET() || isPUT() || isDELETE();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MetadataRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MetadataRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MetadataRequest.java
new file mode 100644
index 0000000..e2c5c54
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/MetadataRequest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.requests;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.api.uri.UriInfoMetadata;
+import org.apache.olingo.server.core.ContentNegotiator;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.responses.MetadataResponse;
+
+public class MetadataRequest extends ServiceRequest {
+
+ public MetadataRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(this.uriInfo.getFormatOption(), this.request,
+ this.customContentType, RepresentationType.METADATA);
+ }
+
+ public UriInfoMetadata getUriInfoMetadata() {
+ return uriInfo.asUriInfoMetadata();
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+
+ handler.readMetadata(this, MetadataResponse.getInstance(this, response));
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/OperationRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/OperationRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/OperationRequest.java
new file mode 100644
index 0000000..1f1b194
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/OperationRequest.java
@@ -0,0 +1,118 @@
+/*
+ * 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.requests;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.uri.UriHelper;
+import org.apache.olingo.server.core.ContentNegotiator;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public abstract class OperationRequest extends ServiceRequest {
+
+ public OperationRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ if (!hasReturnType()) {
+ // this default content type
+ return ContentType.APPLICATION_OCTET_STREAM;
+ }
+
+ if (isReturnTypePrimitive()) {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), this.request,
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_PRIMITIVE
+ : RepresentationType.PRIMITIVE);
+ } else if (isReturnTypeComplex()) {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), this.request,
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_COMPLEX
+ : RepresentationType.COMPLEX);
+ } else {
+ return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), this.request,
+ getCustomContentTypeSupport(), isCollection() ? RepresentationType.COLLECTION_ENTITY
+ : RepresentationType.ENTITY);
+ }
+ }
+
+ public abstract boolean isBound();
+
+ public abstract boolean isCollection();
+
+ public abstract EdmReturnType getReturnType();
+
+ public abstract boolean hasReturnType();
+
+ public ContextURL getContextURL(OData odata) throws SerializerException {
+ if (!hasReturnType()) {
+ return null;
+ }
+
+ final UriHelper helper = odata.createUriHelper();
+
+ if (isReturnTypePrimitive() || isReturnTypeComplex()) {
+ // Part 1 {10.14, 10.14} since the function return properties does not
+ // represent a Entity property
+ ContextURL.Builder builder = ContextURL.with().type(getReturnType().getType());
+ if (isCollection()) {
+ builder.asCollection();
+ }
+ return builder.build();
+ }
+
+ /*
+ // EdmTypeKind.ENTITY;
+ if (isBound()) {
+ // Bound means, we know the EnitySet of the return type. Part 1 {10.2,
+ // 10.3}
+ EdmEntitySet entitySet = this.uriResourceFunction.getFunctionImport().getReturnedEntitySet();
+ ContextURL.Builder builder = DataRequest.buildEntitySetContextURL(helper, entitySet,
+ this.uriInfo, isCollection(), false);
+ return builder.build();
+ }
+ */
+
+ // EdmTypeKind.ENTITY; Not Bound
+ // Here we do not know the EntitySet, then follow directions from
+ // Part-1{10.2. 10.3} to use
+ // {context-url}#{type-name}
+ ContextURL.Builder builder = ContextURL.with().type(getReturnType().getType());
+ if (isCollection()) {
+ builder.asCollection();
+ }
+ return builder.build();
+ }
+
+ public boolean isReturnTypePrimitive() {
+ return getReturnType().getType().getKind() == EdmTypeKind.PRIMITIVE;
+ }
+
+ public boolean isReturnTypeComplex() {
+ return getReturnType().getType().getKind() == EdmTypeKind.COMPLEX;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ServiceDocumentRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ServiceDocumentRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ServiceDocumentRequest.java
new file mode 100644
index 0000000..f99aaf5
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/ServiceDocumentRequest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.requests;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.RepresentationType;
+import org.apache.olingo.server.core.ContentNegotiator;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceHandler;
+import org.apache.olingo.server.core.ServiceRequest;
+import org.apache.olingo.server.core.responses.ServiceDocumentResponse;
+
+public class ServiceDocumentRequest extends ServiceRequest {
+
+ public ServiceDocumentRequest(OData odata, ServiceMetadata serviceMetadata) {
+ super(odata, serviceMetadata);
+ }
+
+ @Override
+ public ContentType getResponseContentType() throws ContentNegotiatorException {
+ return ContentNegotiator.doContentNegotiation(getUriInfo().getFormatOption(),
+ getODataRequest(), getCustomContentTypeSupport(), RepresentationType.SERVICE);
+ }
+
+ @Override
+ public void execute(ServiceHandler handler, ODataResponse response)
+ throws ODataTranslatedException, ODataApplicationException {
+
+ if (!allowedMethod()) {
+ methodNotAllowed();
+ }
+ handler.readServiceDocument(this,
+ ServiceDocumentResponse.getInstace(this, response, getResponseContentType()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/CountResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/CountResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/CountResponse.java
new file mode 100644
index 0000000..f7cde33
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/CountResponse.java
@@ -0,0 +1,60 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.http.HttpContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.FixedFormatSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class CountResponse extends ServiceResponse {
+ private final FixedFormatSerializer serializer;
+
+ public static CountResponse getInstance(ServiceRequest request, ODataResponse response) {
+ FixedFormatSerializer serializer = request.getOdata().createFixedFormatSerializer();
+ return new CountResponse(request.getServiceMetaData(), serializer, response,
+ request.getPreferences());
+ }
+
+ private CountResponse(ServiceMetadata metadata, FixedFormatSerializer serializer,
+ ODataResponse response, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ }
+
+ public void writeCount(int count) throws SerializerException {
+ assert (!isClosed());
+
+ this.response.setContent(this.serializer.count(count));
+ writeOK(HttpContentType.TEXT_PLAIN);
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
new file mode 100644
index 0000000..fd29bbd
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntityResponse.java
@@ -0,0 +1,140 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ReturnRepresentation;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class EntityResponse extends ServiceResponse {
+ private final ReturnRepresentation returnRepresentation;
+ private final ODataSerializer serializer;
+ private final EntitySerializerOptions options;
+ private final ContentType responseContentType;
+
+ private EntityResponse(ServiceMetadata metadata, ODataResponse response,
+ ODataSerializer serializer, EntitySerializerOptions options, ContentType responseContentType,
+ Map<String, String> preferences, ReturnRepresentation returnRepresentation) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.options = options;
+ this.responseContentType = responseContentType;
+ this.returnRepresentation = returnRepresentation;
+ }
+
+ public static EntityResponse getInstance(ServiceRequest request, ContextURL contextURL,
+ boolean references, ODataResponse response, ReturnRepresentation returnRepresentation)
+ throws ContentNegotiatorException, SerializerException {
+ EntitySerializerOptions options = request.getSerializerOptions(EntitySerializerOptions.class,
+ contextURL, references);
+ return new EntityResponse(request.getServiceMetaData(), response, request.getSerializer(),
+ options, request.getResponseContentType(), request.getPreferences(), returnRepresentation);
+ }
+
+ public static EntityResponse getInstance(ServiceRequest request, ContextURL contextURL,
+ boolean references, ODataResponse response)
+ throws ContentNegotiatorException, SerializerException {
+ EntitySerializerOptions options = request.getSerializerOptions(EntitySerializerOptions.class,
+ contextURL, references);
+ return new EntityResponse(request.getServiceMetaData(), response, request.getSerializer(),
+ options, request.getResponseContentType(), request.getPreferences(), null);
+ }
+
+ // write single entity
+ public void writeReadEntity(EdmEntityType entityType, Entity entity) throws SerializerException {
+
+ assert (!isClosed());
+
+ if (entity == null) {
+ writeNotFound(true);
+ return;
+ }
+
+ // write the entity to response
+ this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options));
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ public void writeCreatedEntity(EdmEntityType entityType, Entity entity, String locationHeader)
+ throws SerializerException {
+ // upsert/insert must created a entity, otherwise should have throw an
+ // exception
+ assert (entity != null);
+
+ // Note that if media written just like Stream, but on entity URL
+
+ // 8.2.8.7
+ if (this.returnRepresentation == ReturnRepresentation.MINIMAL) {
+ writeNoContent(false);
+ writeHeader(HttpHeader.LOCATION, locationHeader);
+ writeHeader("Preference-Applied", "return=minimal"); //$NON-NLS-1$ //$NON-NLS-2$
+ // 8.3.3
+ writeHeader("OData-EntityId", entity.getId().toASCIIString()); //$NON-NLS-1$
+ close();
+ return;
+ }
+
+ // return the content of the created entity
+ this.response.setContent(this.serializer.entity(this.metadata, entityType, entity, this.options));
+ writeCreated(false);
+ writeHeader(HttpHeader.LOCATION, locationHeader);
+ writeHeader("Preference-Applied", "return=representation"); //$NON-NLS-1$ //$NON-NLS-2$
+ writeHeader(HttpHeader.CONTENT_TYPE, this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ public void writeUpdatedEntity() {
+ // spec says just success response; so either 200 or 204. 200 typically has
+ // payload
+ writeNoContent(true);
+ }
+
+ public void writeDeletedEntityOrReference() {
+ writeNoContent(true);
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+
+ public void writeCreated(boolean closeResponse) {
+ this.response.setStatusCode(HttpStatusCode.CREATED.getStatusCode());
+ if (closeResponse) {
+ close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
new file mode 100644
index 0000000..40276d2
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/EntitySetResponse.java
@@ -0,0 +1,82 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class EntitySetResponse extends ServiceResponse {
+ private final ODataSerializer serializer;
+ private final EntityCollectionSerializerOptions options;
+ private final ContentType responseContentType;
+
+ private EntitySetResponse(ServiceMetadata metadata, ODataResponse response, ODataSerializer serializer,
+ EntityCollectionSerializerOptions options,
+ ContentType responseContentType, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.options = options;
+ this.responseContentType = responseContentType;
+ }
+
+ public static EntitySetResponse getInstance(ServiceRequest request, ContextURL contextURL,
+ boolean referencesOnly, ODataResponse response) throws ContentNegotiatorException, SerializerException {
+ EntityCollectionSerializerOptions options = request.getSerializerOptions(
+ EntityCollectionSerializerOptions.class, contextURL, referencesOnly);
+ return new EntitySetResponse(request.getServiceMetaData(),response, request.getSerializer(), options,
+ request.getResponseContentType(), request.getPreferences());
+ }
+
+ // write collection of entities
+ // TODO: server paging needs to be implemented.
+ public void writeReadEntitySet(EdmEntityType entityType, EntitySet entitySet)
+ throws SerializerException {
+
+ assert (!isClosed());
+
+ if (entitySet == null) {
+ writeNotFound(true);
+ return;
+ }
+
+ // write the whole collection to response
+ this.response.setContent(this.serializer.entityCollection(metadata, entityType, entitySet, this.options));
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
new file mode 100644
index 0000000..055c0b0
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/MetadataResponse.java
@@ -0,0 +1,62 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class MetadataResponse extends ServiceResponse {
+ private final ODataSerializer serializer;
+ private final ContentType responseContentType;
+
+ public static MetadataResponse getInstance(ServiceRequest request,
+ ODataResponse response) throws ContentNegotiatorException, SerializerException {
+ return new MetadataResponse(request.getServiceMetaData(), response, request.getSerializer(),
+ request.getResponseContentType(), request.getPreferences());
+ }
+
+ private MetadataResponse(ServiceMetadata metadata, ODataResponse response, ODataSerializer serializer,
+ ContentType responseContentType, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.responseContentType = responseContentType;
+ }
+
+ public void writeMetadata()throws ODataTranslatedException {
+ assert (!isClosed());
+ this.response.setContent(this.serializer.metadataDocument(this.metadata));
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/NoContentResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/NoContentResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/NoContentResponse.java
new file mode 100644
index 0000000..eb16365
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/NoContentResponse.java
@@ -0,0 +1,100 @@
+/*
+ * 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.responses;
+
+import java.util.Collections;
+
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+
+public class NoContentResponse extends ServiceResponse {
+
+ public NoContentResponse(ServiceMetadata metadata, ODataResponse response) {
+ super(metadata, response, Collections.EMPTY_MAP);
+ }
+
+ // 200
+ public void writeOK() {
+ this.response.setStatusCode(HttpStatusCode.OK.getStatusCode());
+ close();
+ }
+
+ // 201
+ public void writeCreated() {
+ this.response.setStatusCode(HttpStatusCode.CREATED.getStatusCode());
+ close();
+ }
+
+ // 202
+ public void writeAccepted() {
+ this.response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
+ close();
+ }
+
+ // 204
+ public void writeNoContent() {
+ writeNoContent(true);
+ }
+
+ // 304
+ public void writeNotModified() {
+ this.response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
+ close();
+ }
+
+ // error response codes
+
+ // 404
+ public void writeNotFound() {
+ writeNotFound(true);
+ }
+
+ // 501
+ public void writeNotImplemented() {
+ this.response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
+ close();
+ }
+
+ // 405
+ public void writeMethodNotAllowed() {
+ this.response.setStatusCode(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode());
+ close();
+ }
+
+ // 410
+ public void writeGone() {
+ this.response.setStatusCode(HttpStatusCode.GONE.getStatusCode());
+ close();
+ }
+
+ // 412
+ public void writePreConditionFailed() {
+ this.response.setStatusCode(HttpStatusCode.PRECONDITION_FAILED.getStatusCode());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PrimitiveValueResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PrimitiveValueResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PrimitiveValueResponse.java
new file mode 100644
index 0000000..005bfca
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PrimitiveValueResponse.java
@@ -0,0 +1,105 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.commons.api.http.HttpContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.FixedFormatSerializer;
+import org.apache.olingo.server.api.serializer.PrimitiveValueSerializerOptions;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class PrimitiveValueResponse extends ServiceResponse {
+ private final boolean returnCollection;
+ private EdmProperty type;
+ private EdmReturnType returnType;
+ private final FixedFormatSerializer serializer;
+
+ public static PrimitiveValueResponse getInstance(ServiceRequest request, ODataResponse response,
+ boolean collection, EdmProperty type) {
+ FixedFormatSerializer serializer = request.getOdata().createFixedFormatSerializer();
+ return new PrimitiveValueResponse(request.getServiceMetaData(), serializer, response,
+ collection, type, request.getPreferences());
+ }
+
+ public static PrimitiveValueResponse getInstance(ServiceRequest request, ODataResponse response,
+ boolean collection, EdmReturnType type) {
+ FixedFormatSerializer serializer = request.getOdata().createFixedFormatSerializer();
+ return new PrimitiveValueResponse(request.getServiceMetaData(), serializer, response,
+ collection, type, request.getPreferences());
+ }
+
+ private PrimitiveValueResponse(ServiceMetadata metadata, FixedFormatSerializer serializer,
+ ODataResponse response, boolean collection, EdmProperty type, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.returnCollection = collection;
+ this.type = type;
+ this.serializer = serializer;
+ }
+
+ private PrimitiveValueResponse(ServiceMetadata metadata, FixedFormatSerializer serializer,
+ ODataResponse response, boolean collection, EdmReturnType type,
+ Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.returnCollection = collection;
+ this.returnType = type;
+ this.serializer = serializer;
+ }
+
+ public void write(Object value) throws SerializerException {
+ if (value == null) {
+ writeNoContent(true);
+ return;
+ }
+
+ if (this.type != null) {
+ PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with()
+ .facetsFrom(this.type).build();
+
+ this.response.setContent(this.serializer.primitiveValue((EdmPrimitiveType) this.type.getType(),
+ value, options));
+ } else {
+ PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with()
+ .nullable(this.returnType.isNullable()).maxLength(this.returnType.getMaxLength())
+ .precision(this.returnType.getPrecision()).scale(this.returnType.getScale()).build();
+ this.response.setContent(this.serializer.primitiveValue(
+ (EdmPrimitiveType) this.returnType.getType(), value, options));
+ }
+
+ writeOK(HttpContentType.TEXT_PLAIN);
+ }
+
+ public boolean isReturnCollection() {
+ return returnCollection;
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
new file mode 100644
index 0000000..e6b951d
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/PropertyResponse.java
@@ -0,0 +1,144 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class PropertyResponse extends ServiceResponse {
+ private PrimitiveSerializerOptions primitiveOptions;
+ private ComplexSerializerOptions complexOptions;
+ private final ContentType responseContentType;
+ private final ODataSerializer serializer;
+ private final boolean collection;
+
+ public static PropertyResponse getInstance(ServiceRequest request, ODataResponse response,
+ EdmType edmType, ContextURL contextURL, boolean collection) throws ContentNegotiatorException,
+ SerializerException {
+ if (edmType.getKind() == EdmTypeKind.PRIMITIVE) {
+ PrimitiveSerializerOptions options = request.getSerializerOptions(
+ PrimitiveSerializerOptions.class, contextURL, false);
+ ContentType type = request.getResponseContentType();
+ return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response,
+ options, type, collection, request.getPreferences());
+ }
+ ComplexSerializerOptions options = request.getSerializerOptions(ComplexSerializerOptions.class,
+ contextURL, false);
+ ContentType type = request.getResponseContentType();
+ return new PropertyResponse(request.getServiceMetaData(), request.getSerializer(), response,
+ options, type, collection, request.getPreferences());
+ }
+
+ private PropertyResponse(ServiceMetadata metadata, ODataSerializer serializer,
+ ODataResponse response, PrimitiveSerializerOptions options, ContentType contentType,
+ boolean collection, Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.primitiveOptions = options;
+ this.responseContentType = contentType;
+ this.collection = collection;
+ }
+
+ private PropertyResponse(ServiceMetadata metadata, ODataSerializer serializer, ODataResponse response,
+ ComplexSerializerOptions options, ContentType contentType, boolean collection,
+ Map<String, String> preferences) {
+ super(metadata, response, preferences);
+ this.serializer = serializer;
+ this.complexOptions = options;
+ this.responseContentType = contentType;
+ this.collection = collection;
+ }
+
+ public void writeProperty(EdmType edmType, Property property) throws SerializerException {
+ assert (!isClosed());
+
+ if (property == null) {
+ writeNotFound(true);
+ return;
+ }
+
+ if (property.getValue() == null) {
+ writeNoContent(true);
+ return;
+ }
+
+ if (edmType.getKind() == EdmTypeKind.PRIMITIVE) {
+ writePrimitiveProperty((EdmPrimitiveType) edmType, property);
+ } else {
+ writeComplexProperty((EdmComplexType) edmType, property);
+ }
+ }
+
+ private void writeComplexProperty(EdmComplexType type, Property property)
+ throws SerializerException {
+ if (this.collection) {
+ this.response.setContent(this.serializer.complexCollection(this.metadata, type, property,
+ this.complexOptions));
+ } else {
+ this.response.setContent(this.serializer.complex(this.metadata, type, property,
+ this.complexOptions));
+ }
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ private void writePrimitiveProperty(EdmPrimitiveType type, Property property)
+ throws SerializerException {
+ if(this.collection) {
+ this.response.setContent(this.serializer.primitiveCollection(type, property, this.primitiveOptions));
+ } else {
+ this.response.setContent(this.serializer.primitive(type, property, this.primitiveOptions));
+ }
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+
+ public void writePropertyUpdated() {
+ // spec says just success response; so either 200 or 204. 200 typically has
+ // payload
+ writeNoContent(true);
+ }
+
+ public void writePropertyDeleted() {
+ writeNoContent(true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2b73abcc/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
new file mode 100644
index 0000000..86c420b
--- /dev/null
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/responses/ServiceDocumentResponse.java
@@ -0,0 +1,63 @@
+/*
+ * 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.responses;
+
+import java.util.Map;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.core.ContentNegotiatorException;
+import org.apache.olingo.server.core.ServiceRequest;
+
+public class ServiceDocumentResponse extends ServiceResponse {
+ private final ODataSerializer serializer;
+ private final ContentType responseContentType;
+
+ public static ServiceDocumentResponse getInstace(ServiceRequest request, ODataResponse respose,
+ ContentType responseContentType) throws ContentNegotiatorException, SerializerException {
+ return new ServiceDocumentResponse(request.getServiceMetaData(), respose,
+ request.getSerializer(), responseContentType, request.getPreferences());
+ }
+
+ private ServiceDocumentResponse(ServiceMetadata metadata, ODataResponse respose,
+ ODataSerializer serializer, ContentType responseContentType, Map<String, String> preferences) {
+ super(metadata, respose, preferences);
+ this.serializer = serializer;
+ this.responseContentType = responseContentType;
+ }
+
+ public void writeServiceDocument(String serviceRoot)
+ throws ODataTranslatedException {
+ assert (!isClosed());
+ this.response.setContent(this.serializer.serviceDocument(this.metadata.getEdm(), serviceRoot));
+ writeOK(this.responseContentType.toContentTypeString());
+ close();
+ }
+
+ @Override
+ public void accepts(ServiceResponseVisior visitor) throws ODataTranslatedException,
+ ODataApplicationException {
+ visitor.visit(this);
+ }
+}
[44/50] [abbrv] olingo-odata4 git commit: [OLIGNO-573] Removed
'server-core-ext' from build because of JDK7 issues
Posted by ch...@apache.org.
[OLIGNO-573] Removed 'server-core-ext' from build because of JDK7 issues
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/2d445e2a
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/2d445e2a
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/2d445e2a
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 2d445e2a27eac58b4061a3a3f0d7c198b1225175
Parents: 7119be1
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Apr 2 13:14:01 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Apr 2 13:14:01 2015 +0200
----------------------------------------------------------------------
lib/pom.xml | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2d445e2a/lib/pom.xml
----------------------------------------------------------------------
diff --git a/lib/pom.xml b/lib/pom.xml
index d1e8864..44d6d7c 100644
--- a/lib/pom.xml
+++ b/lib/pom.xml
@@ -42,7 +42,9 @@
<module>client-core</module>
<module>server-api</module>
<module>server-core</module>
+ <!-- Temporary disable build of core-ext module
<module>server-core-ext</module>
+ -->
<module>server-tecsvc</module>
<module>server-test</module>
</modules>
[11/50] [abbrv] olingo-odata4 git commit: [OLINGO-545] The
DataProvider supports collections of complex properties
Posted by ch...@apache.org.
[OLINGO-545] The DataProvider supports collections of complex properties
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/4d8a2a40
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/4d8a2a40
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/4d8a2a40
Branch: refs/heads/OLINGO-549-ODataV4-JPA
Commit: 4d8a2a405e33125daee1526c88075fd03dcc8388
Parents: 16b94eb
Author: Christian Holzer <c....@sap.com>
Authored: Fri Mar 27 14:52:26 2015 +0100
Committer: Christian Holzer <c....@sap.com>
Committed: Fri Mar 27 14:52:42 2015 +0100
----------------------------------------------------------------------
.../olingo/fit/tecsvc/client/BasicITCase.java | 137 ++++++++++++++++++-
.../olingo/server/tecsvc/data/DataProvider.java | 105 ++++++++++----
2 files changed, 215 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d8a2a40/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
index 62d13bd..cc9be57 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URI;
@@ -440,7 +441,141 @@ public class BasicITCase extends AbstractBaseTestITCase {
.getPrimitiveValue()
.toValue());
}
-
+
+ @Test
+ public void updateCollectionOfComplexCollection() {
+ final ODataObjectFactory of = getClient().getObjectFactory();
+ final ODataEntity entity = of.newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+
+ entity.getProperties().add(of.newCollectionProperty("CollPropertyComp",
+ of.newCollectionValue("CTPrimComp")
+ .add(of.newComplexValue("CTPrimComp")
+ .add(of.newPrimitiveProperty("PropertyInt16", of.newPrimitiveValueBuilder().buildInt16((short)42)))
+ .add(of.newComplexProperty("PropertyComp", of.newComplexValue("CTAllPrim")
+ .add(of.newPrimitiveProperty("PropertyString", of.newPrimitiveValueBuilder().buildString("42"))))))));
+
+ final URI uri = getClient().newURIBuilder(SERVICE_URI)
+ .appendEntitySetSegment("ESKeyNav")
+ .appendKeySegment(3)
+ .build();
+
+ final ODataEntityUpdateResponse<ODataEntity> response = getClient().getCUDRequestFactory()
+ .getEntityUpdateRequest(uri,
+ UpdateType.PATCH,
+ entity)
+ .execute();
+
+ assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode());
+ final String cookie = response.getHeader(HttpHeader.SET_COOKIE).iterator().next();
+
+ // Check if entity has changed
+ final ODataEntityRequest<ODataEntity> entityRequest = getClient().getRetrieveRequestFactory().getEntityRequest(uri);
+ entityRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
+ final ODataRetrieveResponse<ODataEntity> entityResponse = entityRequest.execute();
+
+ assertEquals(HttpStatusCode.OK.getStatusCode(), entityResponse.getStatusCode());
+ assertNotNull(entityResponse.getBody().getProperty("CollPropertyComp"));
+ assertEquals(1, entityResponse.getBody().getProperty("CollPropertyComp").getCollectionValue().size());
+
+ ODataComplexValue complexProperty = entityResponse.getBody()
+ .getProperty("CollPropertyComp")
+ .getCollectionValue()
+ .iterator()
+ .next()
+ .asComplex();
+ assertEquals(42, complexProperty.get("PropertyInt16").getPrimitiveValue().toValue());
+ assertNotNull(complexProperty.get("PropertyComp"));
+
+ final ODataComplexValue innerComplexProperty = complexProperty.get("PropertyComp").getComplexValue();
+ assertEquals("42", innerComplexProperty.get("PropertyString").getPrimitiveValue().toValue());
+ }
+
+ @Test
+ public void createCollectionOfComplexCollection() {
+ /*
+ * Create a new entity which contains a collection of complex collections
+ * Check if all not filled fields are created by the server
+ */
+ final ODataObjectFactory of = getClient().getObjectFactory();
+ final ODataEntity entity = of.newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+ entity.getProperties().add(
+ of.newPrimitiveProperty("PropertyString",
+ of.newPrimitiveValueBuilder().buildString("Complex collection test")));
+ entity.getProperties().add(of.newComplexProperty("PropertyCompTwoPrim",
+ of.newComplexValue("CTTwoPrim")
+ .add(of.newPrimitiveProperty("PropertyInt16", of.newPrimitiveValueBuilder().buildInt16((short) 1)))
+ .add(of.newPrimitiveProperty("PropertyString", of.newPrimitiveValueBuilder().buildString("1")))));
+
+ entity.getProperties().add(of.newCollectionProperty("CollPropertyComp",
+ of.newCollectionValue("CTPrimComp")
+ .add(of.newComplexValue("CTPrimComp")
+ .add(of.newPrimitiveProperty("PropertyInt16", of.newPrimitiveValueBuilder().buildInt16((short)1)))
+ .add(of.newComplexProperty("PropertyComp", of.newComplexValue("CTAllPrim")
+ .add(of.newPrimitiveProperty("PropertyString", of.newPrimitiveValueBuilder().buildString("1"))))))
+ .add(of.newComplexValue("CTPrimComp")
+ .add(of.newComplexProperty("PropertyComp", of.newComplexValue("CTAllPrim")
+ .add(of.newPrimitiveProperty("PropertyString", of.newPrimitiveValueBuilder().buildString("2")))
+ .add(of.newPrimitiveProperty("PropertyInt16", of.newPrimitiveValueBuilder().buildInt16((short) 2)))
+ .add(of.newPrimitiveProperty("PropertySingle", of.newPrimitiveValueBuilder().buildSingle(2.0f))))))));
+
+ final ODataEntityCreateResponse<ODataEntity> response = getClient().getCUDRequestFactory().getEntityCreateRequest(
+ getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESKeyNav").build(),
+ entity).execute();
+
+
+ // Check if not declared fields are also available
+ assertEquals(HttpStatusCode.CREATED.getStatusCode(), response.getStatusCode());
+ final ODataEntity newEntity = response.getBody();
+
+ assertEquals(2, newEntity.getProperty("CollPropertyComp").getCollectionValue().size());
+ final Iterator<ODataValue> iter = newEntity.getProperty("CollPropertyComp").getCollectionValue().iterator();
+ final ODataComplexValue complexProperty1 = iter.next().asComplex();
+ assertEquals(1, complexProperty1.get("PropertyInt16").getPrimitiveValue().toValue());
+ assertNotNull(complexProperty1.get("PropertyComp"));
+ final ODataComplexValue innerComplexProperty1 = complexProperty1.get("PropertyComp").getComplexValue();
+ assertEquals("1", innerComplexProperty1.get("PropertyString").getPrimitiveValue().toValue());
+ assertTrue(innerComplexProperty1.get("PropertyBinary").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyBoolean").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyByte").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyDate").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyDateTimeOffset").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyDecimal").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyDouble").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyDuration").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyGuid").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyInt16").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyInt32").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyInt64").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertySByte").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyTimeOfDay").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertyInt16").hasNullValue());
+ assertTrue(innerComplexProperty1.get("PropertySingle").hasNullValue());
+
+ final ODataComplexValue complexProperty2 = iter.next().asComplex();
+ assertTrue(complexProperty2.get("PropertyInt16").hasNullValue());
+ assertNotNull(complexProperty2.get("PropertyComp"));
+ final ODataComplexValue innerComplexProperty2 = complexProperty2.get("PropertyComp").getComplexValue();
+ assertEquals("2", innerComplexProperty2.get("PropertyString").getPrimitiveValue().toValue());
+ assertEquals(2, innerComplexProperty2.get("PropertyInt16").getPrimitiveValue().toValue());
+ assertEquals(Double.valueOf(2), innerComplexProperty2.get("PropertySingle").getPrimitiveValue().toValue());
+ assertTrue(innerComplexProperty2.get("PropertyBinary").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyBoolean").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyByte").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyDate").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyDateTimeOffset").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyDecimal").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyDouble").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyDuration").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyGuid").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyInt32").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyInt64").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertySByte").hasNullValue());
+ assertTrue(innerComplexProperty2.get("PropertyTimeOfDay").hasNullValue());
+
+ // Check if not available properties return null
+ assertNull(innerComplexProperty2.get("NotAvailableProperty"));
+ }
+
@Override
protected ODataClient getClient() {
ODataClient odata = ODataClientFactory.getClient();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4d8a2a40/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
index 6db43d0..fed499f 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
+import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
@@ -42,7 +43,9 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.commons.core.data.ComplexValueImpl;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt16;
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
@@ -197,26 +200,33 @@ public class DataProvider {
for (final String propertyName : type.getPropertyNames()) {
if (!keyNames.contains(propertyName)) {
final EdmProperty edmProperty = type.getStructuralProperty(propertyName);
- Property newProperty;
- if (edmProperty.isPrimitive()) {
- newProperty = edmProperty.isCollection() ?
- DataCreator.createPrimitiveCollection(propertyName) :
- DataCreator.createPrimitive(propertyName, null);
- } else {
- if (edmProperty.isCollection()) {
- @SuppressWarnings("unchecked")
- Property newProperty2 = DataCreator.createComplexCollection(propertyName);
- newProperty = newProperty2;
- } else {
- newProperty = DataCreator.createComplex(propertyName);
- createProperties((EdmComplexType) edmProperty.getType(), newProperty.asComplex().getValue());
- }
- }
- properties.add(newProperty);
+ properties.add(createProperty(edmProperty, propertyName));
}
}
}
-
+
+ private Property createProperty(final EdmProperty edmProperty, final String propertyName)
+ throws DataProviderException {
+ Property newProperty;
+
+ if (edmProperty.isPrimitive()) {
+ newProperty = edmProperty.isCollection() ?
+ DataCreator.createPrimitiveCollection(propertyName) :
+ DataCreator.createPrimitive(propertyName, null);
+ } else {
+ if (edmProperty.isCollection()) {
+ @SuppressWarnings("unchecked")
+ Property newProperty2 = DataCreator.createComplexCollection(propertyName);
+ newProperty = newProperty2;
+ } else {
+ newProperty = DataCreator.createComplex(propertyName);
+ createProperties((EdmComplexType) edmProperty.getType(), newProperty.asComplex().getValue());
+ }
+ }
+
+ return newProperty;
+ }
+
public void update(final String rawBaseUri, final EdmEntitySet edmEntitySet, Entity entity,
final Entity changedEntity, final boolean patch, final boolean isInsert) throws DataProviderException {
@@ -255,13 +265,13 @@ public class DataProvider {
final Link navigationLink = changedEntity.getNavigationLink(navPropertyName);
final EdmNavigationProperty navigationProperty = entityType.getNavigationProperty(navPropertyName);
if (!navigationProperty.isCollection() && navigationLink != null && navigationLink.getInlineEntity() == null) {
-
+
// Check if partner is available
if (navigationProperty.getPartner() != null && entity.getNavigationLink(navPropertyName) != null) {
- Entity partnerEntity = entity.getNavigationLink(navPropertyName).getInlineEntity();
+ Entity partnerEntity = entity.getNavigationLink(navPropertyName).getInlineEntity();
removeLink(navigationProperty.getPartner(), partnerEntity);
}
-
+
// Remove link
removeLink(navigationProperty, entity);
}
@@ -337,7 +347,7 @@ public class DataProvider {
private void removeLink(EdmNavigationProperty navigationProperty, Entity entity) {
final Link link = entity.getNavigationLink(navigationProperty.getName());
- if(link != null) {
+ if (link != null) {
entity.getNavigationLinks().remove(link);
}
}
@@ -380,6 +390,7 @@ public class DataProvider {
}
}
+ @SuppressWarnings({ "unchecked" })
public void updateProperty(final EdmProperty edmProperty, Property property, final Property newProperty,
final boolean patch) throws DataProviderException {
if (edmProperty.isPrimitive()) {
@@ -391,11 +402,23 @@ public class DataProvider {
property.setValue(property.getValueType(), value);
}
} else if (edmProperty.isCollection()) {
- if (newProperty != null && !newProperty.asCollection().isEmpty()) {
- throw new DataProviderException("Update of a complex-collection property not supported!",
- HttpStatusCode.NOT_IMPLEMENTED);
- } else {
- property.asCollection().clear();
+ // Updating collection properties mean replacing all entites with the given ones
+ property.asCollection().clear();
+
+ if (newProperty != null) {
+ if (edmProperty.getType().getKind() == EdmTypeKind.COMPLEX) {
+ // Complex type
+ final List<ComplexValue> complexValues = (List<ComplexValue>) newProperty.asCollection();
+
+ // Create each complex value
+ for (final ComplexValue complexValue : complexValues) {
+ ((List<ComplexValue>) property.asCollection()).add(createComplexValue(edmProperty, complexValue, patch));
+ }
+ } else {
+ // Primitive type
+ final List<Object> values = (List<Object>) newProperty.asCollection();
+ ((List<Object>) property.asCollection()).addAll(values);
+ }
}
} else {
final EdmComplexType type = (EdmComplexType) edmProperty.getType();
@@ -410,6 +433,36 @@ public class DataProvider {
}
}
+ private ComplexValue createComplexValue(final EdmProperty edmProperty, final ComplexValue complexValue,
+ final boolean patch) throws DataProviderException {
+ final ComplexValueImpl result = new ComplexValueImpl();
+ final EdmComplexType edmType = (EdmComplexType) edmProperty.getType();
+ final List<Property> givenProperties = complexValue.getValue();
+
+ // Create ALL properties, even if no value is given. Check if null is allowed
+ for (final String propertyName : edmType.getPropertyNames()) {
+ final EdmProperty innerEdmProperty = (EdmProperty) edmType.getProperty(propertyName);
+ final Property currentProperty = findProperty(propertyName, givenProperties);
+ final Property newProperty = createProperty(innerEdmProperty, propertyName);
+ result.getValue().add(newProperty);
+
+ if (currentProperty != null) {
+ updateProperty(innerEdmProperty, newProperty, currentProperty, patch);
+ } else {
+ if (innerEdmProperty.isNullable()) {
+ // Check complex properties ... may be null is not allowed
+ if(edmProperty.getType().getKind() == EdmTypeKind.COMPLEX) {
+ updateProperty(innerEdmProperty, newProperty, null, patch);
+ }
+ } else {
+ throw new DataProviderException("Null is not allowed for property " + edmProperty.getName());
+ }
+ }
+ }
+
+ return result;
+ }
+
private Property findProperty(final String propertyName, final List<Property> properties) {
for (final Property property : properties) {
if (propertyName.equals(property.getName())) {