private static String getValueAsString(String key, ClientEntity transport) { ClientProperty property = transport.getProperty(key); if(property == null) return null; ClientValue value = property.getValue(); if(value == null) return null; return value.toString(); }
@Override public Map<String, Object> asJavaMap() { final Map<String, Object> result = new LinkedHashMap<String, Object>(); for (Map.Entry<String, ClientProperty> entry : fields.entrySet()) { Object value = null; if (entry.getValue().hasPrimitiveValue()) { value = entry.getValue().getPrimitiveValue().toValue(); } else if (entry.getValue().hasComplexValue()) { value = entry.getValue().getComplexValue().asJavaMap(); } else if (entry.getValue().hasCollectionValue()) { value = entry.getValue().getCollectionValue().asJavaCollection(); } else if (entry.getValue().hasEnumValue()) { value = entry.getValue().getEnumValue().toString(); } result.put(entry.getKey(), value); } return result; }
/** * Adds field to the complex type. * * @param field field to be added. */ @Override public ClientComplexValue add(final ClientProperty field) { fields.put(field.getName(), field); return this; }
final Method getter = ClassUtils.findGetterByAnnotatedName(typeRef, getterAnn, property.getName()); property.getName(), bean.getClass().getName()); } else { try { if (property.hasNullValue()) { setPropertyValue(bean, getter, null); } else if (property.hasPrimitiveValue()) { setPropertyValue(bean, getter, primitiveValueToObject( property.getPrimitiveValue(), getPropertyClass(typeRef, property.getName()))); } else if (property.hasComplexValue()) { final Object complex = Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), populate(client, typeHandler, complex, Property.class, property.getValue().asComplex().iterator()); setPropertyValue(bean, getter, complex); } else if (property.hasCollectionValue()) { final ParameterizedType collType = (ParameterizedType) getter.getGenericReturnType(); final Class<?> collItemClass = (Class<?>) collType.getActualTypeArguments()[0]; final Iterator<ClientValue> collPropItor = property.getValue().asCollection().iterator(); while (collPropItor.hasNext()) { final ClientValue value = collPropItor.next(); if (value.isPrimitive()) { collection.add(primitiveValueToObject( value.asPrimitive(), getPropertyClass(typeRef, property.getName()))); } else if (value.isComplex()) { final Object collItem = Proxy.newProxyInstance(
@SuppressWarnings("unchecked") @Override public Triple<List<T>, URI, List<ClientAnnotation>> fetchPartial(final URI uri, final Class<T> typeRef) { final ODataPropertyRequest<ClientProperty> req = getClient().getRetrieveRequestFactory().getPropertyRequest(uri); req.setPrefer(getClient().newPreferences().includeAnnotations("*")); final ODataRetrieveResponse<ClientProperty> res = req.execute(); final List<T> resItems = new ArrayList<T>(); final ClientProperty property = res.getBody(); if (property != null && property.hasCollectionValue()) { for (ClientValue item : (ClientCollectionValue<ClientValue>) property.getValue()) { Class<?> actualRef = null; if (StringUtils.isNotBlank(item.getTypeName())) { actualRef = service.getComplexTypeClass(item.getTypeName()); } if (actualRef == null) { actualRef = typeRef; } resItems.add((T) getComplex(property.getName(), item, actualRef, null, null, true)); } } return new ImmutableTriple<List<T>, URI, List<ClientAnnotation>>( resItems, null, Collections.<ClientAnnotation> emptyList()); } }
public static Object getKey( final EdmEnabledODataClient client, final EntityInvocationHandler typeHandler, final Class<?> entityTypeRef, final ClientEntity entity) { Object res = null; if (!entity.getProperties().isEmpty()) { final Class<?> keyRef = ClassUtils.getCompoundKeyRef(entityTypeRef); if (keyRef == null) { final ClientProperty property = entity.getProperty(firstValidEntityKey(entityTypeRef)); if (property != null && property.hasPrimitiveValue()) { res = primitiveValueToObject( property.getPrimitiveValue(), getPropertyClass(entityTypeRef, property.getName())); } } else { try { res = keyRef.newInstance(); populate(client, typeHandler, res, CompoundKeyElement.class, entity.getProperties().iterator()); } catch (Exception e) { LOG.error("Error population compound key {}", keyRef.getSimpleName(), e); throw new IllegalArgumentException("Cannot populate compound key"); } } } return res; }
final ClientProperty property = (ClientProperty) result; if (property == null || property.hasNullValue()) { res = null; } else if (returnType.isCollection()) { final List items = new ArrayList(); for (ClientValue item : property.getValue().asCollection()) { items.add(ProxyUtils.getComplexProxy( service, property.getName(), item, itemRef, final List items = new ArrayList(); for (ClientValue item : property.getValue().asCollection()) { items.add(item.asPrimitive().toValue()); if (returnType.isComplexType()) { res = ProxyUtils.getComplexProxy( service, property.getName(), property.getValue().asComplex(), ref, null, null, false); } else { res = CoreUtils.getObjectFromODataValue(property.getValue(), targetRef, service);
res = getComplex( name, property == null || property.hasNullValue() ? null : property.getValue(), ref, getEntityHandler(), if (property == null || property.hasNullValue()) { collectionHandler = new ComplexCollectionInvocationHandler( itemRef, for (ClientValue item : property.getValue().asCollection()) { items.add(getComplex( name, if (property == null || property.hasNullValue()) { collectionHandler = new PrimitiveCollectionInvocationHandler( service, } else { List items = new ArrayList(); for (ClientValue item : property.getValue().asCollection()) { items.add(item.asPrimitive().toValue()); new Class<?>[] {PrimitiveCollection.class}, collectionHandler); } else { res = property == null || property.hasNullValue() ? null : CoreUtils.getObjectFromODataValue(property.getValue(), type, service);
@Override @SuppressWarnings("unchecked") public Triple<List<T>, URI, List<ClientAnnotation>> fetchPartial(final URI uri, final Class<T> typeRef) { final ODataPropertyRequest<ClientProperty> req = getClient().getRetrieveRequestFactory().getPropertyRequest(uri); req.setPrefer(getClient().newPreferences().includeAnnotations("*")); final ODataRetrieveResponse<ClientProperty> res = req.execute(); final List<T> resItems = new ArrayList<T>(); final ClientProperty property = res.getBody(); if (property != null && !property.hasNullValue()) { for (ClientValue item : property.getCollectionValue()) { resItems.add((T) item.asPrimitive().toValue()); } } return new ImmutableTriple<List<T>, URI, List<ClientAnnotation>>( resItems, null, Collections.<ClientAnnotation>emptyList()); }
@Override public ODataPropertyUpdateRequest getPropertyPrimitiveValueUpdateRequest( final URI targetURI, final ClientProperty property) { if (!property.hasPrimitiveValue()) { throw new IllegalArgumentException("A primitive value is required"); } final ODataPropertyUpdateRequest req; if (client.getConfiguration().isUseXHTTPMethod()) { req = new ODataPropertyUpdateRequestImpl(client, HttpMethod.POST, targetURI, property); req.setXHTTPMethod(HttpMethod.PUT.name()); } else { req = new ODataPropertyUpdateRequestImpl(client, HttpMethod.PUT, targetURI, property); } return req; }
@Override public ODataPropertyUpdateRequest getPropertyComplexValueUpdateRequest( final URI targetURI, final UpdateType type, final ClientProperty property) { if (!property.hasComplexValue()) { throw new IllegalArgumentException("A complex value is required"); } final ODataPropertyUpdateRequest req; if (client.getConfiguration().isUseXHTTPMethod()) { req = new ODataPropertyUpdateRequestImpl(client, HttpMethod.POST, targetURI, property); req.setXHTTPMethod(type.getMethod().name()); } else { req = new ODataPropertyUpdateRequestImpl(client, type.getMethod(), targetURI, property); } return req; }
@Override public ODataPropertyUpdateRequest getPropertyCollectionValueUpdateRequest( final URI targetURI, final ClientProperty property) { if (!property.hasCollectionValue()) { throw new IllegalArgumentException("A collection value is required"); } final ODataPropertyUpdateRequest req; if (client.getConfiguration().isUseXHTTPMethod()) { req = new ODataPropertyUpdateRequestImpl(client, HttpMethod.POST, targetURI, property); req.setXHTTPMethod(HttpMethod.PUT.name()); } else { req = new ODataPropertyUpdateRequestImpl(client, HttpMethod.PUT, targetURI, property); } return req; }
private List<ClientAnnotation> internalAnnotations() { List<ClientAnnotation> result = Collections.<ClientAnnotation> emptyList(); if (targetHandler.getInternal() instanceof ClientEntity) { result = propName == null ? ((ClientEntity) targetHandler.getInternal()).getNavigationLink(navPropName).getAnnotations() : ((ClientEntity) targetHandler.getInternal()).getProperty(propName).getAnnotations(); } else if (targetHandler.getInternal() instanceof ClientComplexValue) { result = propName == null ? ((ClientComplexValue) targetHandler.getInternal()).getNavigationLink(navPropName).getAnnotations() : ((ClientComplexValue) targetHandler.getInternal()).get(propName).getAnnotations(); } return result; }
final Method getter = ClassUtils.findGetterByAnnotatedName(typeRef, getterAnn, property.getName()); property.getName(), bean.getClass().getName()); } else { try { if (property.hasNullValue()) { setPropertyValue(bean, getter, null); } else if (property.hasPrimitiveValue()) { setPropertyValue(bean, getter, primitiveValueToObject( property.getPrimitiveValue(), getPropertyClass(typeRef, property.getName()))); } else if (property.hasComplexValue()) { final Object complex = Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), populate(client, typeHandler, complex, Property.class, property.getValue().asComplex().iterator()); setPropertyValue(bean, getter, complex); } else if (property.hasCollectionValue()) { final ParameterizedType collType = (ParameterizedType) getter.getGenericReturnType(); final Class<?> collItemClass = (Class<?>) collType.getActualTypeArguments()[0]; final Iterator<ClientValue> collPropItor = property.getValue().asCollection().iterator(); while (collPropItor.hasNext()) { final ClientValue value = collPropItor.next(); if (value.isPrimitive()) { collection.add(primitiveValueToObject( value.asPrimitive(), getPropertyClass(typeRef, property.getName()))); } else if (value.isComplex()) { final Object collItem = Proxy.newProxyInstance(
@SuppressWarnings("unchecked") @Override public Triple<List<T>, URI, List<ClientAnnotation>> fetchPartial(final URI uri, final Class<T> typeRef) { final ODataPropertyRequest<ClientProperty> req = getClient().getRetrieveRequestFactory().getPropertyRequest(uri); req.setPrefer(getClient().newPreferences().includeAnnotations("*")); final ODataRetrieveResponse<ClientProperty> res = req.execute(); final List<T> resItems = new ArrayList<T>(); final ClientProperty property = res.getBody(); if (property != null && property.hasCollectionValue()) { for (ClientValue item : (ClientCollectionValue<ClientValue>) property.getValue()) { Class<?> actualRef = null; if (StringUtils.isNotBlank(item.getTypeName())) { actualRef = service.getComplexTypeClass(item.getTypeName()); } if (actualRef == null) { actualRef = typeRef; } resItems.add((T) getComplex(property.getName(), item, actualRef, null, null, true)); } } return new ImmutableTriple<List<T>, URI, List<ClientAnnotation>>( resItems, null, Collections.<ClientAnnotation> emptyList()); } }
public static Object getKey( final EdmEnabledODataClient client, final EntityInvocationHandler typeHandler, final Class<?> entityTypeRef, final ClientEntity entity) { Object res = null; if (!entity.getProperties().isEmpty()) { final Class<?> keyRef = ClassUtils.getCompoundKeyRef(entityTypeRef); if (keyRef == null) { final ClientProperty property = entity.getProperty(firstValidEntityKey(entityTypeRef)); if (property != null && property.hasPrimitiveValue()) { res = primitiveValueToObject( property.getPrimitiveValue(), getPropertyClass(entityTypeRef, property.getName())); } } else { try { res = keyRef.newInstance(); populate(client, typeHandler, res, CompoundKeyElement.class, entity.getProperties().iterator()); } catch (Exception e) { LOG.error("Error population compound key {}", keyRef.getSimpleName(), e); throw new IllegalArgumentException("Cannot populate compound key"); } } } return res; }
final ClientProperty property = (ClientProperty) result; if (property == null || property.hasNullValue()) { res = null; } else if (returnType.isCollection()) { final List items = new ArrayList(); for (ClientValue item : property.getValue().asCollection()) { items.add(ProxyUtils.getComplexProxy( service, property.getName(), item, itemRef, final List items = new ArrayList(); for (ClientValue item : property.getValue().asCollection()) { items.add(item.asPrimitive().toValue()); if (returnType.isComplexType()) { res = ProxyUtils.getComplexProxy( service, property.getName(), property.getValue().asComplex(), ref, null, null, false); } else { res = CoreUtils.getObjectFromODataValue(property.getValue(), targetRef, service);
res = getComplex( name, property == null || property.hasNullValue() ? null : property.getValue(), ref, getEntityHandler(), if (property == null || property.hasNullValue()) { collectionHandler = new ComplexCollectionInvocationHandler( itemRef, for (ClientValue item : property.getValue().asCollection()) { items.add(getComplex( name, if (property == null || property.hasNullValue()) { collectionHandler = new PrimitiveCollectionInvocationHandler( service, } else { List items = new ArrayList(); for (ClientValue item : property.getValue().asCollection()) { items.add(item.asPrimitive().toValue()); new Class<?>[] {PrimitiveCollection.class}, collectionHandler); } else { res = property == null || property.hasNullValue() ? null : CoreUtils.getObjectFromODataValue(property.getValue(), type, service);
@Override @SuppressWarnings("unchecked") public Triple<List<T>, URI, List<ClientAnnotation>> fetchPartial(final URI uri, final Class<T> typeRef) { final ODataPropertyRequest<ClientProperty> req = getClient().getRetrieveRequestFactory().getPropertyRequest(uri); req.setPrefer(getClient().newPreferences().includeAnnotations("*")); final ODataRetrieveResponse<ClientProperty> res = req.execute(); final List<T> resItems = new ArrayList<T>(); final ClientProperty property = res.getBody(); if (property != null && !property.hasNullValue()) { for (ClientValue item : property.getCollectionValue()) { resItems.add((T) item.asPrimitive().toValue()); } } return new ImmutableTriple<List<T>, URI, List<ClientAnnotation>>( resItems, null, Collections.<ClientAnnotation>emptyList()); }
@Override public ODataPropertyUpdateRequest getPropertyPrimitiveValueUpdateRequest( final URI targetURI, final ClientProperty property) { if (!property.hasPrimitiveValue()) { throw new IllegalArgumentException("A primitive value is required"); } final ODataPropertyUpdateRequest req; if (client.getConfiguration().isUseXHTTPMethod()) { req = new ODataPropertyUpdateRequestImpl(client, HttpMethod.POST, targetURI, property); req.setXHTTPMethod(HttpMethod.PUT.name()); } else { req = new ODataPropertyUpdateRequestImpl(client, HttpMethod.PUT, targetURI, property); } return req; }