mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-06 00:29:05 +00:00
[OLINGO-585] Method to get the key predicates from Entity binding links added
Signed-off-by: Michael Bolz <michael.bolz@sap.com>
This commit is contained in:
parent
2ebdea806c
commit
4c23cd9d8c
@ -45,7 +45,8 @@ public class DeserializerException extends ODataTranslatedException {
|
|||||||
/** parameters: primitiveTypeName, propertyName */ UNKNOWN_PRIMITIVE_TYPE,
|
/** parameters: primitiveTypeName, propertyName */ UNKNOWN_PRIMITIVE_TYPE,
|
||||||
/** parameter: navigationPropertyName */NAVIGATION_PROPERTY_NOT_FOUND,
|
/** parameter: navigationPropertyName */NAVIGATION_PROPERTY_NOT_FOUND,
|
||||||
/** parameter: annotationName */INVALID_ANNOTATION_TYPE,
|
/** parameter: annotationName */INVALID_ANNOTATION_TYPE,
|
||||||
/** parameter: annotationName */INVALID_NULL_ANNOTATION;
|
/** parameter: annotationName */INVALID_NULL_ANNOTATION,
|
||||||
|
/** parameter: binding link */INVALID_ENTITY_BINDING_LINK;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
|
@ -21,9 +21,11 @@ package org.apache.olingo.server.api.uri;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
||||||
|
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||||
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
||||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||||
@ -65,4 +67,21 @@ public interface UriHelper {
|
|||||||
* @return the key predicate
|
* @return the key predicate
|
||||||
*/
|
*/
|
||||||
String buildKeyPredicate(EdmEntityType edmEntityType, Entity entity) throws SerializerException;
|
String buildKeyPredicate(EdmEntityType edmEntityType, Entity entity) throws SerializerException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the key predicates from a canonical link to an entity.
|
||||||
|
* A canonical link to an entity must follow the pattern
|
||||||
|
* <code>[<service root>][<entityContainer>.]<entitySet>(<key>)</code>, i.e.,
|
||||||
|
* it must be a relative or absolute URI consisting of an entity set (qualified
|
||||||
|
* with an entity-container name if not in the default entity container) and a
|
||||||
|
* syntactically valid key that identifies a single entity; example:
|
||||||
|
* <code>http://example.server.com/service.svc/Employees('42')</code>.
|
||||||
|
* @param edm the edm the entity belongs to
|
||||||
|
* @param entityLink the link as String
|
||||||
|
* @param rawServiceRoot the root URI of the service
|
||||||
|
* @return a list of key predicates
|
||||||
|
* @throws DeserializationException in case the link is malformed
|
||||||
|
*/
|
||||||
|
List<UriParameter> getKeyPredicatesFromEntityLink(Edm edm, String entityLink, String rawServiceRoot)
|
||||||
|
throws DeserializerException;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ package org.apache.olingo.server.core.uri;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||||
@ -28,12 +29,19 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
|||||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||||
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
||||||
import org.apache.olingo.commons.core.Encoder;
|
import org.apache.olingo.commons.core.Encoder;
|
||||||
|
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||||
|
import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
|
||||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||||
import org.apache.olingo.server.api.uri.UriHelper;
|
import org.apache.olingo.server.api.uri.UriHelper;
|
||||||
import org.apache.olingo.server.api.uri.UriParameter;
|
import org.apache.olingo.server.api.uri.UriParameter;
|
||||||
|
import org.apache.olingo.server.api.uri.UriResource;
|
||||||
|
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
|
||||||
|
import org.apache.olingo.server.api.uri.UriResourceKind;
|
||||||
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
||||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||||
import org.apache.olingo.server.core.serializer.utils.ContextURLHelper;
|
import org.apache.olingo.server.core.serializer.utils.ContextURLHelper;
|
||||||
|
import org.apache.olingo.server.core.uri.parser.Parser;
|
||||||
|
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
||||||
|
|
||||||
public class UriHelperImpl implements UriHelper {
|
public class UriHelperImpl implements UriHelper {
|
||||||
|
|
||||||
@ -83,4 +91,31 @@ public class UriHelperImpl implements UriHelper {
|
|||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UriParameter> getKeyPredicatesFromEntityLink(Edm edm, String entityLink, String rawServiceRoot)
|
||||||
|
throws DeserializerException {
|
||||||
|
|
||||||
|
String oDataPath = entityLink;
|
||||||
|
if(rawServiceRoot != null && entityLink.startsWith(rawServiceRoot)) {
|
||||||
|
oDataPath = entityLink.substring(rawServiceRoot.length());
|
||||||
|
}
|
||||||
|
oDataPath = oDataPath.startsWith("/") ? oDataPath : "/" + oDataPath;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final List<UriResource> uriResourceParts = new Parser().parseUri(oDataPath, null, null, edm)
|
||||||
|
.getUriResourceParts();
|
||||||
|
if (uriResourceParts.size() == 1 && uriResourceParts.get(0).getKind() == UriResourceKind.entitySet) {
|
||||||
|
final UriResourceEntitySet entityUriResource = (UriResourceEntitySet) uriResourceParts.get(0);
|
||||||
|
|
||||||
|
return entityUriResource.getKeyPredicates();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new DeserializerException("Invalid entity binding link", MessageKeys.INVALID_ENTITY_BINDING_LINK,
|
||||||
|
entityLink);
|
||||||
|
} catch (UriParserException e) {
|
||||||
|
throw new DeserializerException("Invalid entity binding link", MessageKeys.INVALID_ENTITY_BINDING_LINK,
|
||||||
|
entityLink);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,7 @@ DeserializerException.DUPLICATE_JSON_PROPERTY="JSON properties must not appear t
|
|||||||
DeserializerException.UNKNOWN_PRIMITIVE_TYPE=Unknown primitive type '%1$s' for property '%2$s';
|
DeserializerException.UNKNOWN_PRIMITIVE_TYPE=Unknown primitive type '%1$s' for property '%2$s';
|
||||||
DeserializerException.NAVIGATION_PROPERTY_NOT_FOUND=Can`t find navigation property with name: '%1$s'.
|
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_ANNOTATION_TYPE=The annotation '%1$s' has the wrong JSON type.
|
||||||
|
DeserializerException.INVALID_ENTITY_BINDING_LINK=The binding link '%1$s' is malformed.
|
||||||
|
|
||||||
BatchDeserializerException.INVALID_BOUNDARY=Invalid boundary at line '%1$s'.
|
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'.
|
BatchDeserializerException.INVALID_CHANGESET_METHOD=Invalid method: a ChangeSet cannot contain retrieve requests at line '%1$s'.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user