Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/olingo-odata4
This commit is contained in:
commit
365ea6f8b7
|
@ -22,6 +22,7 @@ import java.lang.reflect.Proxy;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
|
||||
import org.apache.olingo.client.core.ODataClientFactory;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
|
@ -80,6 +81,10 @@ public final class EntityContainerFactory {
|
|||
this.serviceRoot = serviceRoot;
|
||||
}
|
||||
|
||||
public CommonConfiguration getConfiguration() {
|
||||
return client.getConfiguration();
|
||||
}
|
||||
|
||||
public String getServiceRoot() {
|
||||
return serviceRoot;
|
||||
}
|
||||
|
|
|
@ -24,11 +24,8 @@ import java.lang.reflect.ParameterizedType;
|
|||
import java.lang.reflect.Proxy;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
|
@ -58,14 +55,6 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
|
||||
protected final Class<?> typeRef;
|
||||
|
||||
protected Map<String, Object> propertyChanges = new HashMap<String, Object>();
|
||||
|
||||
protected Map<NavigationProperty, Object> linkChanges = new HashMap<NavigationProperty, Object>();
|
||||
|
||||
protected int propertiesTag;
|
||||
|
||||
protected int linksTag;
|
||||
|
||||
protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
|
||||
|
||||
protected final EntityTypeInvocationHandler<C> targetHandler;
|
||||
|
@ -81,8 +70,6 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
super(client, containerHandler);
|
||||
this.internal = internal;
|
||||
this.typeRef = typeRef;
|
||||
this.propertiesTag = 0;
|
||||
this.linksTag = 0;
|
||||
this.targetHandler = EntityTypeInvocationHandler.class.cast(this);
|
||||
}
|
||||
|
||||
|
@ -94,8 +81,6 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
super(client, targetHandler.containerHandler);
|
||||
this.internal = internal;
|
||||
this.typeRef = typeRef;
|
||||
this.propertiesTag = 0;
|
||||
this.linksTag = 0;
|
||||
this.targetHandler = targetHandler;
|
||||
}
|
||||
|
||||
|
@ -105,14 +90,6 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
return typeRef;
|
||||
}
|
||||
|
||||
public Map<String, Object> getPropertyChanges() {
|
||||
return propertyChanges;
|
||||
}
|
||||
|
||||
public Map<NavigationProperty, Object> getLinkChanges() {
|
||||
return linkChanges;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
||||
|
@ -183,7 +160,12 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
throw new UnsupportedOperationException("Unsupported method " + method.getName());
|
||||
}
|
||||
|
||||
return newComplex(property.name(), getter.getReturnType());
|
||||
final ComplexTypeInvocationHandler<C> complexTypeHandler = newComplex(property.name(), getter.getReturnType());
|
||||
|
||||
return Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
new Class<?>[] {getter.getReturnType()},
|
||||
complexTypeHandler);
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Method not found: " + method);
|
||||
}
|
||||
|
@ -210,7 +192,7 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
protected <NE> NE newComplex(final String propertyName, final Class<NE> reference) {
|
||||
protected ComplexTypeInvocationHandler<C> newComplex(final String propertyName, final Class<?> reference) {
|
||||
final Class<?> complexTypeRef;
|
||||
final boolean isCollection;
|
||||
if (Collection.class.isAssignableFrom(reference)) {
|
||||
|
@ -232,35 +214,19 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
final ODataComplexValue<? extends CommonODataProperty> complex =
|
||||
client.getObjectFactory().newComplexValue(typeName.toString());
|
||||
|
||||
final ComplexTypeInvocationHandler<?> handler =
|
||||
ComplexTypeInvocationHandler.getInstance(complex, complexTypeRef, targetHandler);
|
||||
|
||||
if (isCollection) {
|
||||
Object value = propertyChanges.get(propertyName);
|
||||
|
||||
if (value == null) {
|
||||
value = new ArrayList<ComplexTypeInvocationHandler<?>>();
|
||||
propertyChanges.put(propertyName, value);
|
||||
}
|
||||
|
||||
((Collection<ComplexTypeInvocationHandler<?>>) value).add(handler);
|
||||
} else {
|
||||
propertyChanges.put(propertyName, handler);
|
||||
}
|
||||
final ComplexTypeInvocationHandler<C> handler = (ComplexTypeInvocationHandler<C>) ComplexTypeInvocationHandler.
|
||||
getInstance(complex, complexTypeRef, targetHandler);
|
||||
|
||||
attach(AttachedEntityStatus.CHANGED);
|
||||
|
||||
return (NE) Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
new Class<?>[] {complexTypeRef},
|
||||
handler);
|
||||
addPropertyChanges(propertyName, handler, isCollection);
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
private Object getNavigationPropertyValue(final NavigationProperty property, final Method getter) {
|
||||
if (!(internal instanceof ODataLinked)) {
|
||||
throw new UnsupportedOperationException("Internal object is not navigable");
|
||||
}
|
||||
protected abstract Object getNavigationPropertyValue(final NavigationProperty property, final Method getter);
|
||||
|
||||
protected Object retriveNavigationProperty(final NavigationProperty property, final Method getter) {
|
||||
final Class<?> type = getter.getReturnType();
|
||||
final Class<?> collItemType;
|
||||
if (AbstractEntityCollection.class.isAssignableFrom(type)) {
|
||||
|
@ -273,58 +239,48 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
|
||||
final Object navPropValue;
|
||||
|
||||
if (linkChanges.containsKey(property)) {
|
||||
navPropValue = linkChanges.get(property);
|
||||
final ODataLink link = ((ODataLinked) internal).getNavigationLink(property.name());
|
||||
if (link instanceof ODataInlineEntity) {
|
||||
// return entity
|
||||
navPropValue = getEntityProxy(
|
||||
((ODataInlineEntity) link).getEntity(),
|
||||
property.targetContainer(),
|
||||
property.targetEntitySet(),
|
||||
type,
|
||||
false);
|
||||
} else if (link instanceof ODataInlineEntitySet) {
|
||||
// return entity set
|
||||
navPropValue = getEntityCollection(
|
||||
collItemType,
|
||||
type,
|
||||
property.targetContainer(),
|
||||
((ODataInlineEntitySet) link).getEntitySet(),
|
||||
link.getLink(),
|
||||
false);
|
||||
} else {
|
||||
final ODataLink link = ((ODataLinked) internal).getNavigationLink(property.name());
|
||||
if (link instanceof ODataInlineEntity) {
|
||||
// return entity
|
||||
navPropValue = getEntityProxy(
|
||||
((ODataInlineEntity) link).getEntity(),
|
||||
property.targetContainer(),
|
||||
property.targetEntitySet(),
|
||||
type,
|
||||
false);
|
||||
} else if (link instanceof ODataInlineEntitySet) {
|
||||
// return entity set
|
||||
// navigate
|
||||
final URI uri = URIUtils.getURI(
|
||||
containerHandler.getFactory().getServiceRoot(), link.getLink().toASCIIString());
|
||||
|
||||
if (AbstractEntityCollection.class.isAssignableFrom(type)) {
|
||||
navPropValue = getEntityCollection(
|
||||
collItemType,
|
||||
type,
|
||||
property.targetContainer(),
|
||||
((ODataInlineEntitySet) link).getEntitySet(),
|
||||
link.getLink(),
|
||||
false);
|
||||
client.getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody(),
|
||||
uri,
|
||||
true);
|
||||
} else {
|
||||
// navigate
|
||||
final URI uri = URIUtils.getURI(
|
||||
containerHandler.getFactory().getServiceRoot(), link.getLink().toASCIIString());
|
||||
final ODataRetrieveResponse<CommonODataEntity> res =
|
||||
client.getRetrieveRequestFactory().getEntityRequest(uri).execute();
|
||||
|
||||
if (AbstractEntityCollection.class.isAssignableFrom(type)) {
|
||||
navPropValue = getEntityCollection(
|
||||
collItemType,
|
||||
type,
|
||||
property.targetContainer(),
|
||||
client.getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody(),
|
||||
uri,
|
||||
true);
|
||||
} else {
|
||||
final ODataRetrieveResponse<CommonODataEntity> res =
|
||||
client.getRetrieveRequestFactory().getEntityRequest(uri).execute();
|
||||
|
||||
navPropValue = getEntityProxy(
|
||||
res.getBody(),
|
||||
property.targetContainer(),
|
||||
property.targetEntitySet(),
|
||||
type,
|
||||
res.getETag(),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
if (navPropValue != null) {
|
||||
int checkpoint = linkChanges.hashCode();
|
||||
linkChanges.put(property, navPropValue);
|
||||
updateLinksTag(checkpoint);
|
||||
navPropValue = getEntityProxy(
|
||||
res.getBody(),
|
||||
property.targetContainer(),
|
||||
property.targetEntitySet(),
|
||||
type,
|
||||
res.getETag(),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,6 +293,11 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
return getPropertyValue(property.name(), type);
|
||||
}
|
||||
|
||||
public void addAdditionalProperty(final String name, final Object value) {
|
||||
addPropertyChanges(name, value, false);
|
||||
attach(AttachedEntityStatus.CHANGED);
|
||||
}
|
||||
|
||||
public Object getAdditionalProperty(final String name) {
|
||||
return getPropertyValue(name, null);
|
||||
}
|
||||
|
@ -359,40 +320,25 @@ public abstract class AbstractTypeInvocationHandler<C extends CommonEdmEnabledOD
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final EntityTypeInvocationHandler<C> targetHandler = (EntityTypeInvocationHandler<C>) etih;
|
||||
if (!targetHandler.getTypeRef().isAnnotationPresent(EntityType.class)) {
|
||||
throw new IllegalArgumentException("Invalid argument type " + targetHandler.getTypeRef().getSimpleName());
|
||||
final EntityTypeInvocationHandler<C> linkedHandler = (EntityTypeInvocationHandler<C>) etih;
|
||||
if (!linkedHandler.getTypeRef().isAnnotationPresent(EntityType.class)) {
|
||||
throw new IllegalArgumentException("Invalid argument type " + linkedHandler.getTypeRef().getSimpleName());
|
||||
}
|
||||
|
||||
if (!entityContext.isAttached(targetHandler)) {
|
||||
entityContext.attach(targetHandler, AttachedEntityStatus.LINKED);
|
||||
if (!entityContext.isAttached(linkedHandler)) {
|
||||
entityContext.attach(linkedHandler, AttachedEntityStatus.LINKED);
|
||||
}
|
||||
}
|
||||
|
||||
// 3) add links
|
||||
linkChanges.put(property, value);
|
||||
addLinkChanges(property, value);
|
||||
}
|
||||
|
||||
protected abstract void setPropertyValue(final Property property, final Object value);
|
||||
|
||||
public void addAdditionalProperty(final String name, final Object value) {
|
||||
propertyChanges.put(name, value);
|
||||
if (!entityContext.isAttached(targetHandler)) {
|
||||
entityContext.attach(targetHandler, AttachedEntityStatus.CHANGED);
|
||||
}
|
||||
}
|
||||
protected abstract void addPropertyChanges(final String name, final Object value, final boolean isCollection);
|
||||
|
||||
protected void updatePropertiesTag(final int checkpoint) {
|
||||
if (checkpoint == propertiesTag) {
|
||||
propertiesTag = propertyChanges.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLinksTag(final int checkpoint) {
|
||||
if (checkpoint == linksTag) {
|
||||
linksTag = linkChanges.hashCode();
|
||||
}
|
||||
}
|
||||
protected abstract void addLinkChanges(final NavigationProperty navProp, final Object value);
|
||||
|
||||
public abstract boolean isChanged();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.olingo.ext.proxy.commons;
|
|||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -28,9 +29,15 @@ import java.util.Set;
|
|||
import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinked;
|
||||
import org.apache.olingo.commons.api.edm.EdmElement;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.ComplexType;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.Property;
|
||||
import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
|
||||
import org.apache.olingo.ext.proxy.utils.ClassUtils;
|
||||
import org.apache.olingo.ext.proxy.utils.EngineUtils;
|
||||
|
||||
public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?>>
|
||||
|
@ -57,10 +64,6 @@ public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<
|
|||
|
||||
public void setComplex(final ODataComplexValue<?> complex) {
|
||||
this.internal = complex;
|
||||
this.propertyChanges.clear();
|
||||
this.linkChanges.clear();
|
||||
this.propertiesTag = 0;
|
||||
this.linksTag = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,8 +71,9 @@ public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<
|
|||
return new FullQualifiedName(((ODataComplexValue<?>) this.internal).getTypeName());
|
||||
}
|
||||
|
||||
public ODataComplexValue<?> getComplex() {
|
||||
return (ODataComplexValue<?>) this.internal;
|
||||
@SuppressWarnings("unchecked")
|
||||
public ODataComplexValue<CommonODataProperty> getComplex() {
|
||||
return (ODataComplexValue<CommonODataProperty>) this.internal;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,10 +83,13 @@ public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<
|
|||
|
||||
final CommonODataProperty property = getComplex().get(name);
|
||||
|
||||
if (propertyChanges.containsKey(name)) {
|
||||
res = propertyChanges.get(name);
|
||||
} else if (property.hasComplexValue()) {
|
||||
res = newComplex(name, (Class<?>) type);
|
||||
if (property.hasComplexValue()) {
|
||||
|
||||
res = Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
new Class<?>[] {(Class<?>) type},
|
||||
newComplex(name, (Class<?>) type));
|
||||
|
||||
EngineUtils.populate(
|
||||
client.getCachedEdm(),
|
||||
res,
|
||||
|
@ -90,16 +97,9 @@ public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<
|
|||
Property.class,
|
||||
property.getValue().asComplex().iterator());
|
||||
} else {
|
||||
|
||||
res = type == null
|
||||
? EngineUtils.getValueFromProperty(client.getCachedEdm(), property)
|
||||
: EngineUtils.getValueFromProperty(client.getCachedEdm(), property, type);
|
||||
|
||||
if (res != null) {
|
||||
int checkpoint = propertyChanges.hashCode();
|
||||
propertyChanges.put(name, res);
|
||||
updatePropertiesTag(checkpoint);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -110,21 +110,18 @@ public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<
|
|||
|
||||
@Override
|
||||
public Collection<String> getAdditionalPropertyNames() {
|
||||
final Set<String> res = new HashSet<String>(propertyChanges.keySet());
|
||||
final Set<String> res = new HashSet<String>();
|
||||
final Set<String> propertyNames = new HashSet<String>();
|
||||
for (Method method : typeRef.getMethods()) {
|
||||
final Annotation ann = method.getAnnotation(Property.class);
|
||||
if (ann != null) {
|
||||
final String property = ((Property) ann).name();
|
||||
propertyNames.add(property);
|
||||
|
||||
// maybe someone could add a normal attribute to the additional set
|
||||
res.remove(property);
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<?> itor = ((ODataComplexValue<?>) this.internal).iterator(); itor.hasNext();) {
|
||||
CommonODataProperty property = (CommonODataProperty) itor.next();
|
||||
for (Iterator<? extends CommonODataProperty> itor = getComplex().iterator(); itor.hasNext();) {
|
||||
final CommonODataProperty property = itor.next();
|
||||
if (!propertyNames.contains(property.getName())) {
|
||||
res.add(property.getName());
|
||||
}
|
||||
|
@ -135,13 +132,41 @@ public class ComplexTypeInvocationHandler<C extends CommonEdmEnabledODataClient<
|
|||
|
||||
@Override
|
||||
protected void setPropertyValue(final Property property, final Object value) {
|
||||
propertyChanges.put(property.name(), value);
|
||||
final FullQualifiedName fqn =
|
||||
new FullQualifiedName(ClassUtils.getNamespace(typeRef), typeRef.getAnnotation(ComplexType.class).name());
|
||||
|
||||
final EdmElement edmProperty = client.getCachedEdm().getComplexType(fqn).getProperty(property.name());
|
||||
|
||||
final EdmTypeInfo type = new EdmTypeInfo.Builder().
|
||||
setEdm(client.getCachedEdm()).setTypeExpression(
|
||||
edmProperty.isCollection() ? "Collection(" + property.type() + ")" : property.type()).build();
|
||||
|
||||
client.getBinder().add(getComplex(), EngineUtils.getODataProperty(client, property.name(), type, value));
|
||||
|
||||
if (!entityContext.isAttached(targetHandler)) {
|
||||
entityContext.attach(targetHandler, AttachedEntityStatus.CHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getNavigationPropertyValue(final NavigationProperty property, final Method getter) {
|
||||
if (!(internal instanceof ODataLinked)) {
|
||||
throw new UnsupportedOperationException("Internal object is not navigable");
|
||||
}
|
||||
|
||||
return retriveNavigationProperty(property, getter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addPropertyChanges(final String name, final Object value, final boolean isCollection) {
|
||||
// do nothing ....
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addLinkChanges(final NavigationProperty navProp, final Object value) {
|
||||
// do nothing ....
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChanged() {
|
||||
return targetHandler.isChanged();
|
||||
|
|
|
@ -21,8 +21,10 @@ package org.apache.olingo.ext.proxy.commons;
|
|||
import java.io.InputStream;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -39,6 +41,7 @@ import org.apache.olingo.commons.api.domain.ODataLinked;
|
|||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.ODataMediaFormat;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.EntityType;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty;
|
||||
import org.apache.olingo.ext.proxy.api.annotations.Property;
|
||||
import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
|
||||
import org.apache.olingo.ext.proxy.context.EntityUUID;
|
||||
|
@ -51,6 +54,14 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?
|
|||
|
||||
private CommonODataEntity entity;
|
||||
|
||||
protected Map<String, Object> propertyChanges = new HashMap<String, Object>();
|
||||
|
||||
protected Map<NavigationProperty, Object> linkChanges = new HashMap<NavigationProperty, Object>();
|
||||
|
||||
protected int propertiesTag = 0;
|
||||
|
||||
protected int linksTag = 0;
|
||||
|
||||
private Map<String, InputStream> streamedPropertyChanges = new HashMap<String, InputStream>();
|
||||
|
||||
private InputStream stream;
|
||||
|
@ -157,22 +168,51 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?
|
|||
this.entity.setETag(eTag);
|
||||
}
|
||||
|
||||
public Map<String, Object> getPropertyChanges() {
|
||||
return propertyChanges;
|
||||
}
|
||||
|
||||
public Map<NavigationProperty, Object> getLinkChanges() {
|
||||
return linkChanges;
|
||||
}
|
||||
|
||||
private void updatePropertiesTag(final int checkpoint) {
|
||||
if (checkpoint == propertiesTag) {
|
||||
propertiesTag = propertyChanges.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLinksTag(final int checkpoint) {
|
||||
if (checkpoint == linksTag) {
|
||||
linksTag = linkChanges.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getPropertyValue(final String name, final Type type) {
|
||||
try {
|
||||
final Object res;
|
||||
|
||||
|
||||
final CommonODataProperty property = entity.getProperty(name);
|
||||
|
||||
|
||||
if (propertyChanges.containsKey(name)) {
|
||||
res = propertyChanges.get(name);
|
||||
res = property.hasComplexValue()
|
||||
? Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
new Class<?>[] {(Class<?>) type},
|
||||
(ComplexTypeInvocationHandler<?>) propertyChanges.get(name))
|
||||
: propertyChanges.get(name);
|
||||
} else if (property.hasComplexValue()) {
|
||||
res = newComplex(name, (Class<?>) type);
|
||||
res = Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
new Class<?>[] {(Class<?>) type},
|
||||
newComplex(name, (Class<?>) type));
|
||||
|
||||
EngineUtils.populate(
|
||||
client.getCachedEdm(),
|
||||
res,
|
||||
(Class<?>) type,
|
||||
Property.class,
|
||||
client.getCachedEdm(),
|
||||
res,
|
||||
(Class<?>) type,
|
||||
Property.class,
|
||||
property.getValue().asComplex().iterator());
|
||||
} else {
|
||||
|
||||
|
@ -181,9 +221,7 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?
|
|||
: EngineUtils.getValueFromProperty(client.getCachedEdm(), property, type);
|
||||
|
||||
if (res != null) {
|
||||
int checkpoint = propertyChanges.hashCode();
|
||||
propertyChanges.put(name, res);
|
||||
updatePropertiesTag(checkpoint);
|
||||
addPropertyChanges(name, res, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,7 +260,7 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?
|
|||
if (property.type().equalsIgnoreCase("Edm.Stream")) {
|
||||
setStreamedProperty(property, (InputStream) value);
|
||||
} else {
|
||||
propertyChanges.put(property.name(), value);
|
||||
addPropertyChanges(property.name(), value, false);
|
||||
}
|
||||
|
||||
attach(AttachedEntityStatus.CHANGED);
|
||||
|
@ -303,6 +341,51 @@ public class EntityTypeInvocationHandler<C extends CommonEdmEnabledODataClient<?
|
|||
streamedPropertyChanges.put(property.name(), input);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getNavigationPropertyValue(final NavigationProperty property, final Method getter) {
|
||||
final Object navPropValue;
|
||||
|
||||
if (linkChanges.containsKey(property)) {
|
||||
navPropValue = linkChanges.get(property);
|
||||
} else {
|
||||
navPropValue = retriveNavigationProperty(property, getter);
|
||||
}
|
||||
|
||||
if (navPropValue != null) {
|
||||
addLinkChanges(property, navPropValue);
|
||||
}
|
||||
|
||||
return navPropValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void addPropertyChanges(final String name, final Object value, final boolean isCollection) {
|
||||
int checkpoint = propertyChanges.hashCode();
|
||||
|
||||
if (isCollection) {
|
||||
Object collItem = propertyChanges.get(name);
|
||||
|
||||
if (collItem == null) {
|
||||
collItem = new ArrayList<Object>();
|
||||
propertyChanges.put(name, collItem);
|
||||
}
|
||||
|
||||
((Collection<Object>) collItem).add(value);
|
||||
} else {
|
||||
propertyChanges.put(name, value);
|
||||
}
|
||||
|
||||
updatePropertiesTag(checkpoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addLinkChanges(final NavigationProperty navProp, final Object value) {
|
||||
int checkpoint = linkChanges.hashCode();
|
||||
linkChanges.put(navProp, value);
|
||||
updateLinksTag(checkpoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return uuid.toString();
|
||||
|
|
|
@ -127,7 +127,7 @@ public final class EngineUtils {
|
|||
return value;
|
||||
}
|
||||
|
||||
private static CommonODataProperty getODataEntityProperty(
|
||||
private static CommonODataProperty getODataProperty(
|
||||
final CommonEdmEnabledODataClient<?> client,
|
||||
final FullQualifiedName entity,
|
||||
final String property,
|
||||
|
@ -153,7 +153,7 @@ public final class EngineUtils {
|
|||
return getODataProperty(client, property, type, obj);
|
||||
}
|
||||
|
||||
private static CommonODataProperty getODataProperty(
|
||||
public static CommonODataProperty getODataProperty(
|
||||
final CommonEdmEnabledODataClient<?> client, final String name, final EdmTypeInfo type, final Object obj) {
|
||||
|
||||
CommonODataProperty oprop;
|
||||
|
@ -203,7 +203,7 @@ public final class EngineUtils {
|
|||
}
|
||||
|
||||
((List<CommonODataProperty>) entity.getProperties()).add(
|
||||
getODataEntityProperty(client, entity.getTypeName(), property.getKey(), property.getValue()));
|
||||
getODataProperty(client, entity.getTypeName(), property.getKey(), property.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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.fit.proxy.v3;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
|
||||
import org.apache.olingo.client.core.http.DefaultHttpClientFactory;
|
||||
import org.apache.olingo.ext.proxy.EntityContainerFactory;
|
||||
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
|
||||
DefaultContainer;
|
||||
|
||||
public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
|
||||
|
||||
@BeforeClass
|
||||
public static void enableBasicAuth() {
|
||||
containerFactory.getConfiguration().
|
||||
setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void disableBasicAuth() {
|
||||
containerFactory.getConfiguration().setHttpClientFactory(new DefaultHttpClientFactory());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setupContaner() {
|
||||
containerFactory = EntityContainerFactory.getV3Instance(testAuthServiceRootURL);
|
||||
container = containerFactory.getEntityContainer(DefaultContainer.class);
|
||||
assertNotNull(container);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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.fit.proxy.v4;
|
||||
|
||||
import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
|
||||
import org.apache.olingo.client.core.http.DefaultHttpClientFactory;
|
||||
import org.apache.olingo.ext.proxy.EntityContainerFactory;
|
||||
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
|
||||
|
||||
@BeforeClass
|
||||
public static void enableBasicAuth() {
|
||||
containerFactory.getConfiguration().
|
||||
setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void disableBasicAuth() {
|
||||
containerFactory.getConfiguration().setHttpClientFactory(new DefaultHttpClientFactory());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setupContaner() {
|
||||
containerFactory = EntityContainerFactory.getV3Instance(testAuthServiceRootURL);
|
||||
container = containerFactory.getEntityContainer(InMemoryEntities.class);
|
||||
assertNotNull(container);
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
|||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataValuable;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
|
@ -125,7 +126,7 @@ public class DerivedTypeTestITCase extends AbstractTestITCase {
|
|||
final ODataEntity actual = fetchReq.execute().getBody();
|
||||
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", actual.getTypeName().toString());
|
||||
assertEquals("Microsoft.Test.OData.Services.ODataWCFService.CompanyAddress",
|
||||
actual.getProperty("HomeAddress").getValue().getTypeName());
|
||||
((ODataValuable)actual.getProperty("HomeAddress")).getValue().getTypeName());
|
||||
|
||||
final ODataDeleteRequest deleteReq = client.getCUDRequestFactory().getDeleteRequest(actual.getEditLink());
|
||||
assertEquals(204, deleteReq.execute().getStatusCode());
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
|||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLink;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
|
||||
|
||||
public interface CommonODataBinder extends Serializable {
|
||||
|
@ -69,6 +70,14 @@ public interface CommonODataBinder extends Serializable {
|
|||
*/
|
||||
Property getProperty(CommonODataProperty property, Class<? extends Entity> reference);
|
||||
|
||||
/**
|
||||
* Adds the given property to the given complex value.
|
||||
*
|
||||
* @param complex OData complex value.
|
||||
* @param property OData property.
|
||||
*/
|
||||
void add(ODataComplexValue<CommonODataProperty> complex, CommonODataProperty property);
|
||||
|
||||
/**
|
||||
* Adds the given property to the given entity.
|
||||
*
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.olingo.commons.api.data.v3.LinkCollection;
|
|||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataProperty;
|
||||
|
@ -45,6 +46,11 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
|||
super(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final ODataComplexValue<CommonODataProperty> complex, final CommonODataProperty property) {
|
||||
complex.add((ODataProperty) property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(final CommonODataEntity entity, final CommonODataProperty property) {
|
||||
return ((ODataEntity) entity).getProperties().add((ODataProperty) property);
|
||||
|
@ -89,7 +95,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
|||
|
||||
return new ODataPropertyImpl(property.getPayload().getName(),
|
||||
getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
|
||||
property.getPayload(), property.getContextURL(), property.getMetadataETag()));
|
||||
property.getPayload(), property.getContextURL(), property.getMetadataETag()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,5 +104,4 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
|||
collection.setLinks(linkCollection.getLinks());
|
||||
return collection;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.apache.olingo.commons.api.data.Value;
|
|||
import org.apache.olingo.commons.api.domain.CommonODataEntity;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.CommonODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntity;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.ODataLinked;
|
||||
|
@ -83,6 +84,11 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
|||
super(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final ODataComplexValue<CommonODataProperty> complex, final CommonODataProperty property) {
|
||||
complex.add((ODataProperty) property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(final CommonODataEntity entity, final CommonODataProperty property) {
|
||||
return ((ODataEntity) entity).getProperties().add((ODataProperty) property);
|
||||
|
@ -272,7 +278,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
|||
|
||||
final ODataProperty property = new ODataPropertyImpl(resource.getPayload().getName(),
|
||||
getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
|
||||
resource.getPayload(), resource.getContextURL(), resource.getMetadataETag()));
|
||||
resource.getPayload(), resource.getContextURL(), resource.getMetadataETag()));
|
||||
odataAnnotations(resource.getPayload(), property);
|
||||
|
||||
return property;
|
||||
|
@ -375,5 +381,4 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
|
|||
|
||||
return delta;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,9 @@ public class EdmEnabledODataClientImpl extends ODataClientImpl implements EdmEna
|
|||
|
||||
@Override
|
||||
public Edm getCachedEdm() {
|
||||
if (edm == null) {
|
||||
getEdm(null);
|
||||
}
|
||||
return this.edm;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,9 @@ public class EdmEnabledODataClientImpl extends ODataClientImpl implements EdmEna
|
|||
|
||||
@Override
|
||||
public Edm getCachedEdm() {
|
||||
if (edm == null) {
|
||||
getEdm(null);
|
||||
}
|
||||
return this.edm;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue