[OLINGO-63] Uri Parser: adoptions in lexer and parser, create UriParserImpl to convert the parsetree into internal structures, moved parser antlr part from .../olingo/producer/... to .../olingo/odata4/producer

This commit is contained in:
Sven Kobler 2013-12-02 16:46:53 +01:00
parent 82ae606001
commit 10ac7ee37e
40 changed files with 3721 additions and 1440 deletions

View File

@ -51,4 +51,11 @@ public interface EdmStructuralType extends EdmType {
* @return {@link EdmStructuralType}
*/
EdmStructuralType getBaseType();
/**
* Checks if this type is convertable to parameter {@link targetType}
*
* @return true if this type is compatible to the testType ( i.e. this type is a subtype of targetType )
*/
boolean compatibleTo(EdmType targetType);
}

View File

@ -42,9 +42,11 @@ public class EdmComplexTypeImpl extends EdmStructuralTypeImpl implements EdmComp
if (baseTypeName != null) {
baseType = edm.getComplexType(baseTypeName);
if (baseType == null) {
throw new EdmException("Cant find base type with name: " + baseTypeName + " for complex type: " + getName());
throw new EdmException("Can't find base type with name: " + baseTypeName + " for complex type: " + getName());
}
}
return baseType;
}
}

View File

@ -36,6 +36,7 @@ import org.apache.olingo.odata4.commons.api.edm.provider.FunctionImport;
import org.apache.olingo.odata4.commons.api.edm.provider.Singleton;
import org.apache.olingo.odata4.commons.api.exception.ODataException;
public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityContainer {
private final FullQualifiedName entityContainerName;

View File

@ -112,4 +112,5 @@ public class EdmEntityTypeImpl extends EdmStructuralTypeImpl implements EdmEntit
return baseType;
}
}

View File

@ -25,12 +25,14 @@ import java.util.Map;
import org.apache.olingo.odata4.commons.api.edm.EdmElement;
import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType;
import org.apache.olingo.odata4.commons.api.edm.EdmType;
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
import org.apache.olingo.odata4.commons.api.edm.provider.NavigationProperty;
import org.apache.olingo.odata4.commons.api.edm.provider.Property;
import org.apache.olingo.odata4.commons.api.edm.provider.StructuralType;
public abstract class EdmStructuralTypeImpl extends EdmTypeImpl implements EdmStructuralType {
private final Map<String, EdmElement> properties = new HashMap<String, EdmElement>();
@ -105,6 +107,22 @@ public abstract class EdmStructuralTypeImpl extends EdmTypeImpl implements EdmSt
}
return navigationPropertyNames;
}
@Override
public boolean compatibleTo(EdmType targetType) {
EdmStructuralType sourceType = this;
while (sourceType.getName() != targetType.getName() ||
sourceType.getNamespace() != targetType.getNamespace()) {
sourceType = sourceType.getBaseType();
if (sourceType == null) {
return false;
}
}
return true;
}
protected abstract EdmStructuralType buildBaseType(FullQualifiedName baseTypeName);
}

View File

@ -20,5 +20,6 @@
package org.apache.olingo.odata4.producer.api.uri;
public enum UriInfoKind {
batch, all, crossjoin;
batch,entity, metadata, all, crossjoin, path;
}

View File

@ -20,5 +20,5 @@
package org.apache.olingo.odata4.producer.api.uri;
public enum UriPathInfoKind {
entitySet, singleton, actionImport, functioncall;
entitySet, navEntitySet, singleton, action, function;
}

View File

@ -77,7 +77,7 @@
<visitor>true</visitor>
<!--maven antlr plugin has trouble with grammer import if the grammerfiles are
not directly inside src/main/antlr4, hence we have to set the libDirectory-->
<libDirectory>src/main/antlr4/org/apache/olingo/producer/core/uri/antlr</libDirectory>
<libDirectory>src/main/antlr4/org/apache/olingo/odata4/producer/core/uri/antlr</libDirectory>
</configuration>
</plugin>
</plugins>

View File

@ -23,12 +23,14 @@ lexer grammar UriLexer;
// On '?' the next mode "MODE_QUERY" is used
// The percent encoding rules a defined in RFC3986 ABNF rule "path-rootless" apply
//;==============================================================================
QM : '?' -> pushMode(MODE_QUERY); //first query parameter
AMP : '&' -> pushMode(MODE_QUERY); //more query parameters
STRING : '\'' -> more, pushMode(MODE_ODATA_STRING);
QM : '?' -> pushMode(MODE_QUERY); //first query parameter
AMP : '&' -> pushMode(MODE_QUERY); //more query parameters
STRING : '\'' -> more, pushMode(MODE_STRING); //reads up to next single '
QUOTATION_MARK : ('\u0022' | '%22') -> more, pushMode(MODE_JSON_STRING); //reads up to next unescaped "
SEARCH_INLINE : '$search' -> pushMode(MODE_SYSTEM_QUERY_SEARCH); //
GEOGRAPHY : G E O G R A P H Y SQUOTE -> pushMode(MODE_ODATA_GEO); //TODO make case insensitive
GEOMETRY : G E O M E T R Y SQUOTE -> pushMode(MODE_ODATA_GEO);
GEOGRAPHY : G E O G R A P H Y SQUOTE -> pushMode(MODE_ODATA_GEO); //TODO make case insensitive
GEOMETRY : G E O M E T R Y SQUOTE -> pushMode(MODE_ODATA_GEO);
//Letters for case insensitivity
fragment A : 'A'|'a';
@ -52,21 +54,30 @@ fragment Y : 'Y'|'y';
fragment Z : 'Z'|'z';
//special chars
OPEN : '(' | '%28';
CLOSE : ')' | '%29';
COMMA : ',' | '%2C';
SLASH : '/';
POINT : '.';
AT : '@';
EQ : '=' ;
STAR : '*';
SEMI : ';';
FRAGMENT : '#';
OPEN : '(' | '%28';
CLOSE : ')' | '%29';
COMMA : ',' | '%2C';
SLASH : '/';
POINT : '.';
AT : '@';
EQ : '=' ;
STAR : '*';
SEMI : ';';
FRAGMENT : '#';
COLON : ':';
EQ_sq : '=' -> type(EQ);
AMP_sq : '&' -> type(AMP), popMode;
fragment WS : ( ' ' | '%09' | '%20' | '%09' );
WSP : WS+;
EQ_sq : '=' -> type(EQ);
AMP_sq : '&' -> type(AMP), popMode;
fragment WS : ( ' ' | '%09' | '%20' | '%09' );
WSP : WS+;
//JSON support
BEGIN_OBJECT : WS* ( '{' / '%7B' ) WS*;
END_OBJECT : WS* ( '}' / '%7D' ) WS*;
BEGIN_ARRAY : WS* ( '[' / '%5B' ) WS*;
END_ARRAY : WS* ( ']' / '%5D' ) WS*;
NAME_SEPARATOR : WS* COLON WS*;
//alpha stuff
fragment ALPHA : 'a'..'z' | 'A'..'Z';
@ -88,7 +99,7 @@ fragment DAY : '0' '1'..'9' | ('1'|'2') DIGIT | '3' ('0'|'1');
fragment MONTH : '0' ONE_TO_NINE | '1' ( '0' | '1' | '2' );
fragment YEAR : ('-')? ( '0' DIGIT DIGIT DIGIT | ONE_TO_NINE DIGIT DIGIT DIGIT );
//tag start with $
//tags start with $
BATCH : '$batch';
ENTITY : '$entity';
METADATA : '$metadata';
@ -104,7 +115,9 @@ COUNT : '$count';
SKIP_INLINE : '$skip';
FILTER_INLINE : '$filter';
ORDERBY_INLINE: '$orderby';
SEARCH_INLINE : '$search'-> pushMode(MODE_SYSTEM_QUERY_SEARCH);
ROOT : '$root/';
@ -121,8 +134,8 @@ DECIMAL : INT '.' DIGITS ('e' SIGN? DIGITS)?;
//primary types
BINARY : B I N A R Y SQUOTE (HEXDIG HEXDIG)* SQUOTE;
DATE : D A T E SQUOTE YEAR '-' MONTH '-' DAY SQUOTE;
DATETIMEOFFSET : D A T E T I M E O F F S E T SQUOTE YEAR '-' MONTH '-' DAY T HOUR ':' MINUTE ( ':' SECOND ( '.' FRACTIONALSECONDS )? )? ( Z | SIGN HOUR ':' MINUTE ) SQUOTE;
DATE : YEAR '-' MONTH '-' DAY;
DATETIMEOFFSET : YEAR '-' MONTH '-' DAY T HOUR ':' MINUTE ( ':' SECOND ( '.' FRACTIONALSECONDS )? )? ( Z | SIGN HOUR ':' MINUTE );
fragment DUSECONDFRAG : DIGITS ('.' DIGITS)? 'S';
fragment DUTIMEFRAG : 'T' (
( DIGITS 'H' (DIGITS 'M')? DUSECONDFRAG?)
@ -130,14 +143,14 @@ fragment DUTIMEFRAG : 'T' (
| DUSECONDFRAG
);
fragment DUDAYTIMEFRAG : DIGITS 'D' DUTIMEFRAG? | DUTIMEFRAG;
DURATION : D U R A T I O N SQUOTE '-'? 'P' DUDAYTIMEFRAG SQUOTE;
TIMEOFDAY : T I M E O F D A Y SQUOTE HOUR ':' MINUTE ( ':' SECOND ( '.' FRACTIONALSECONDS )? )? SQUOTE;
DURATION : D U R A T I O N SQUOTE '-'? 'P' DUDAYTIMEFRAG SQUOTE;
TIMEOFDAY : HOUR ':' MINUTE ( ':' SECOND ( '.' FRACTIONALSECONDS )? )?;
fragment GUIDVALUE : HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG'-'
HEXDIG HEXDIG HEXDIG HEXDIG '-'
HEXDIG HEXDIG HEXDIG HEXDIG '-'
HEXDIG HEXDIG HEXDIG HEXDIG '-'
HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG;
GUID : G U I D SQUOTE GUIDVALUE SQUOTE;
GUID : GUIDVALUE;
//expression tokens
ASC : 'asc';
@ -158,7 +171,6 @@ OR : 'or';
ISOF : 'isof';
NOT : 'not';
MINUS :'-';
ROOT : '$root/';
NANINFINITY : 'NaN' | '-INF' | 'INF';
IMPLICIT_VARIABLE_EXPR : '$it';
@ -210,7 +222,6 @@ DELETED_ENTITY : '$deletedEntity';
LINK : '$link';
DELETED_LINK : '$deletedLink';
DELTA : '$delta';
//ENTITY_IN_FRAGMENT : '/$entity';
LEVELSMAX : '$levels=max';
@ -226,28 +237,24 @@ ODATAIDENTIFIER : ODI_LEADINGCHARACTER (ODI_CHARACTER)*;
mode MODE_QUERY;
//;==============================================================================
FRAGMENT_q : '#' -> type(FRAGMENT);
FILTER : '$filter' -> pushMode(DEFAULT_MODE);
ORDERBY : '$orderby' -> pushMode(DEFAULT_MODE);
EXPAND : '$expand' -> pushMode(DEFAULT_MODE);
SELECT : '$select' -> pushMode(DEFAULT_MODE);
SKIP : '$skip' -> pushMode(DEFAULT_MODE);
SKIPTOKEN : '$skiptoken' -> pushMode(MODE_SYSTEM_QUERY_REST_QCHAR_NO_AMP);
TOP : '$top' -> pushMode(DEFAULT_MODE);
LEVELS_q : '$levels' -> type(LEVELS), pushMode(DEFAULT_MODE);
FORMAT : '$format' -> pushMode(MODE_SYSTEM_QUERY_PCHAR);
COUNT_q : '$count' -> type(COUNT), pushMode(DEFAULT_MODE);
REF_q : '$ref' -> type(REF);
FRAGMENT_q : '#' -> type(FRAGMENT);
FILTER : '$filter' -> pushMode(DEFAULT_MODE);
ORDERBY : '$orderby' -> pushMode(DEFAULT_MODE);
EXPAND : '$expand' -> pushMode(DEFAULT_MODE);
SELECT : '$select' -> pushMode(DEFAULT_MODE);
SKIP : '$skip' -> pushMode(DEFAULT_MODE);
SKIPTOKEN : '$skiptoken' -> pushMode(MODE_SYSTEM_QUERY_REST);
TOP : '$top' -> pushMode(DEFAULT_MODE);
LEVELS_q : '$levels' -> type(LEVELS), pushMode(DEFAULT_MODE);
FORMAT : '$format' -> pushMode(MODE_SYSTEM_QUERY_PCHAR);
COUNT_q : '$count' -> type(COUNT), pushMode(DEFAULT_MODE);
REF_q : '$ref' -> type(REF);
VALUE_q : '$value' -> type(VALUE);
ID : '$id'-> pushMode(MODE_SYSTEM_QUERY_REST_QCHAR_NO_AMP);
SEARCH : '$search'-> pushMode(MODE_SYSTEM_QUERY_SEARCH);
ID : '$id' -> pushMode(MODE_SYSTEM_QUERY_REST);
SEARCH : '$search' -> pushMode(MODE_SYSTEM_QUERY_SEARCH);
EQ_q : '=' -> type(EQ);
AMP_q : '&' -> type(AMP);
AMP_q : '&' -> type(AMP);
CUSTOMNAME : ~[&=@$] ~[&=]*;
CUSTOMVALUE : ~[&=]+;
@ -281,22 +288,13 @@ SLASH_sqp : '/' -> type(SLASH);
EQ_sqp : '=' -> type(EQ);
//;==============================================================================
mode MODE_SYSTEM_QUERY_REST_QCHAR_NO_AMP;
mode MODE_SYSTEM_QUERY_REST;
// Read the remaining characters of a URI queryparameter up to an & or #
// character.
//;==============================================================================
AMP_sqr : '&' -> type(AMP), popMode;
FRAGMENT_sqr : '#' -> popMode;
/*
fragment ALPHA_sqr : 'a'..'z'|'A'..'Z';
fragment A_TO_F_sqr : 'a'..'f'|'A'..'F';
fragment DIGIT_sqr : '0'..'9';
fragment HEXDIG_sqr : DIGIT_sqr | A_TO_F_sqr;
fragment PCT_ENCODED_sqr : '%' HEXDIG_sqr HEXDIG_sqr;
fragment UNRESERVED_sqr : ALPHA_sqr | DIGIT_sqr | '-' |'.' | '_' | '~';
fragment OTHER_DELIMS_sqr : '!' | '(' | ')' | '*' | '+' | ',' | ';';
fragment QCHAR_NO_AMP_sqr : UNRESERVED_sqr | PCT_ENCODED_sqr | OTHER_DELIMS_sqr | ':' | '@' | '/' | '?' | '$' | '\'' | '=';
fragment QCHAR_NO_AMP_EQ_sqr : UNRESERVED_sqr | PCT_ENCODED_sqr | OTHER_DELIMS_sqr | ':' | '@' | '/' | '?' | '$' | '\'' ;
*/
AMP_sqr : '&' -> type(AMP), popMode;
FRAGMENT_sqr : '#' -> type(FRAGMENT), popMode;
EQ_sqr : '=' -> type(EQ);
REST : ~[&#=] ~[&#]*;
@ -307,56 +305,59 @@ REST : ~[&#=] ~[&#]*;
mode MODE_SYSTEM_QUERY_SEARCH;
//;==============================================================================
fragment ALPHA_sqc : 'a'..'z'|'A'..'Z';
fragment WS_sqc : ( SP_g | HTAB_g | '%20' | '%09' );
fragment DQUOTE : '\u0022';
NOT_sqc : 'NOT' -> type(NOT);
AND_sqc : 'AND' -> type(AND);
OR_sqc : 'OR' -> type(OR);
EQ_sqc : '=' -> type(EQ);
fragment WS_sqc : ( ' ' | '\u0009' | '%20' | '%09' );
WSP_sqc : WS_sqc+ -> type(WSP);
QUOTATION_MARK_sqc : '\u0022' | '%22';
QUOTATION_MARK : DQUOTE | '%22';
REF_sqc : '$ref' -> type(REF);
SEARCHWORD : ALPHA_sqc+;
SEARCHPHRASE : QUOTATION_MARK /*QCHAR_NO_AMP_DQUOTE+*/ ~[&"]* QUOTATION_MARK -> popMode;
SEARCHWORD : ('a'..'z'|'A'..'Z')+;
SEARCHPHRASE : QUOTATION_MARK_sqc ~["]* QUOTATION_MARK_sqc -> popMode;
//;==============================================================================
mode MODE_ODATA_STRING;
mode MODE_STRING;
// Read the remaining characters up to an ' character.
// An "'" character inside a string are expressed as double ''
//;==============================================================================
fragment SQUOTE_s : '\'';
STRING_s : ('\'\'' | ~[\u0027] )* SQUOTE_s -> type(STRING), popMode;
STRING_s : ('\'\'' | ~[\u0027] )* '\'' -> type(STRING), popMode;
//;==============================================================================
mode MODE_JSON_STRING;
// Read the remaining characters up to an " character.
// An "'" character inside a string are expressed excaped \"
//;==============================================================================
STRING_IN_JSON : ('\\"' | ~[\u0022] )* ('"' | '%22') -> popMode;
//;==============================================================================
mode MODE_ODATA_GEO;
//;==============================================================================
fragment C_g : 'c'|'C';
fragment D_g : 'd'|'D';
fragment E_g : 'e'|'E';
fragment G_g : 'g'|'G';
fragment H_g : 'h'|'H';
fragment I_g : 'i'|'I';
fragment L_g : 'l'|'L';
fragment M_g : 'm'|'M';
fragment N_g : 'n'|'N';
fragment O_g : 'o'|'O';
fragment P_g : 'p'|'P';
fragment R_g : 'r'|'R';
fragment S_g : 's'|'S';
fragment T_g : 't'|'T';
fragment U_g : 'u'|'U';
fragment Y_g : 'y'|'Y';
fragment C_ : 'c'|'C';
fragment D_ : 'd'|'D';
fragment E_ : 'e'|'E';
fragment G_ : 'g'|'G';
fragment H_ : 'h'|'H';
fragment I_ : 'i'|'I';
fragment L_ : 'l'|'L';
fragment M_ : 'm'|'M';
fragment N_ : 'n'|'N';
fragment O_ : 'o'|'O';
fragment P_ : 'p'|'P';
fragment R_ : 'r'|'R';
fragment S_ : 's'|'S';
fragment T_ : 't'|'T';
fragment U_ : 'u'|'U';
fragment Y_ : 'y'|'Y';
fragment SP_g : ' ';//'\u0020'; // a simple space
fragment HTAB_g : '%09';
fragment WS_g : ( ' ' | HTAB_g | '%20' | '%09' );
fragment WS_g : ( ' ' | '%20' | '%09' );
OPEN_g : ('(' | '%28') -> type(OPEN);
CLOSE_g : (')' | '%29') -> type(CLOSE);
@ -372,14 +373,14 @@ fragment DIGITS_g : DIGIT_g+;
SIGN_g : ('+' | '%2B' |'-') -> type(SIGN);
INT_g : SIGN_g? DIGITS_g -> type(INT);
DECIMAL_g : INT_g '.' DIGITS_g ('e' SIGN_g? DIGITS_g)? -> type(DECIMAL);
COLLECTION_g : C_g O_g L_g L_g E_g C_g T_g I_g O_g N_g -> type(COLLECTION);
LINESTRING : L_g I_g N_g E_g S_g T_g R_g I_g N_g G_g ;
MULTILINESTRING : M_g U_g L_g T_g I_g L_g I_g N_g E_g S_g T_g R_g I_g N_g G_g;
MULTIPOINT : M_g U_g L_g T_g I_g P_g O_g I_g N_g T_g ;
MULTIPOLYGON : M_g U_g L_g T_g I_g P_g O_g L_g Y_g G_g O_g N_g;
GEO_POINT : P_g O_g I_g N_g T_g;
POLYGON : P_g O_g L_g Y_g G_g O_g N_g ;
COLLECTION_g : C_ O_ L_ L_ E_ C_ T_ I_ O_ N_ -> type(COLLECTION);
LINESTRING : L_ I_ N_ E_ S_ T_ R_ I_ N_ G_ ;
MULTILINESTRING : M_ U_ L_ T_ I_ L_ I_ N_ E_ S_ T_ R_ I_ N_ G_;
MULTIPOINT : M_ U_ L_ T_ I_ P_ O_ I_ N_ T_ ;
MULTIPOLYGON : M_ U_ L_ T_ I_ P_ O_ L_ Y_ G_ O_ N_;
GEO_POINT : P_ O_ I_ N_ T_;
POLYGON : P_ O_ L_ Y_ G_ O_ N_ ;
SRID : S_g R_g I_g D_g;
SRID : S_ R_ I_ D_;
SQUOTE : '\'' -> popMode;

View File

@ -86,31 +86,32 @@ options {
odataRelativeUriEOF : odataRelativeUri? EOF;
//QM and FRAGMENT enable next lexer mode
odataRelativeUri : BATCH # batchAlt //TODO alt at beginnig
| ENTITY QM eo=entityOptions # entityAlt
| METADATA ( QM format )? ( FRAGMENT contextFragment )? # metadataAlt
| resourcePath ( QM queryOptions )? # resourcePathAlt
//TODO add the new "ENTITYCAST"
odataRelativeUri : BATCH # altBatch
| ENTITY QM eo=entityOptions # altEntity
| ENTITY SLASH ns=namespace? odi=odataIdentifier QM eo=entityOptions # altEntityCast
| METADATA ( QM format )? ( FRAGMENT contextFragment )? # altMetadata
| resourcePath ( QM queryOptions )? # altResourcePath
;
//;------------------------------------------------------------------------------
//; 1. Resource Path
//;------------------------------------------------------------------------------
resourcePath : ALL # allAlt
| crossjoin # crossjoinAlt
| pathSegments # pathSegmentsAlt
resourcePath : vAll=ALL
| vCJ=crossjoin
| vPSs=pathSegments
;
crossjoin : CROSSJOIN OPEN odi+=odataIdentifier ( COMMA odi+=odataIdentifier )* CLOSE;
pathSegments : ps+=pathSegment (SLASH ps+=pathSegment)* constSegment?;
pathSegments : vlPS+=pathSegment (SLASH vlPS+=pathSegment)* vCS=constSegment?;
pathSegment : ns=namespace? odi=odataIdentifier nvl=nameValueOptList*;
pathSegment : vNS=namespace? vODI=odataIdentifier vlVPO+=nameValueOptList*;
nameValueOptList : vo=valueOnly | nvl=nameValueList;
valueOnly : OPEN (primitiveLiteral ) CLOSE;
nameValueList : OPEN kvp+=nameValuePair ( COMMA kvp+=nameValuePair )* CLOSE;
nameValuePair : odi=odataIdentifier EQ (AT ali=odataIdentifier | val1=primitiveLiteral /*| val2=enumX*/);
nameValueOptList : OPEN (vVO=valueOnly | vNVL=nameValueList)? CLOSE;
valueOnly : vV=primitiveLiteral ;
nameValueList : WSP* vNVP+=nameValuePair WSP* ( COMMA WSP* vNVP+=nameValuePair WSP*)* ;
nameValuePair : vODI=odataIdentifier EQ (AT vALI=odataIdentifier | vVAL=primitiveLiteral /*TODO | val2=enumX*/);
constSegment : SLASH (v=value | c=count | r=ref );
@ -274,7 +275,7 @@ commonExpr : OPEN commonExpr CLOSE
| memberExpr #altMember
| commonExpr (WSP MUL WSP | WSP DIV WSP | WSP MOD WSP ) commonExpr #altMult
| commonExpr (WSP ADD WSP | WSP SUB WSP) commonExpr #altAdd
| commonExpr (WSP GT WSP | WSP GE WSP | WSP LT WSP | WSP LE WSP | WSP ISOF WSP) commonExpr #altComparisn
| commonExpr (WSP GT WSP | WSP GE WSP | WSP LT WSP | WSP LE WSP | WSP ISOF WSP) commonExpr #altComparism
| commonExpr (WSP EQ_ALPHA WSP | WSP NE WSP) commonExpr #altEquality
| commonExpr (WSP AND WSP) commonExpr #altAnd
| commonExpr (WSP OR WSP) commonExpr #altOr
@ -372,66 +373,34 @@ castExpr : CAST_WORD WSP? ( commonExpr WSP? COMMA WSP?
//; Note: the query part of a URI needs to be partially percent-decoded before
//; applying these rules, see comment at the top of this file
//;------------------------------------------------------------------------------
/*
arrayOrObject : complexColInUri
| complexInUri
| rootExprCol
| primitiveColInUri;
complexColInUri : BEGIN_ARRAY
( complexInUri ( WS* COMMA WS* complexInUri )* )?
END_ARRAY;
complexInUri : BEGIN_OBJECT ( jv+=json_value ( WS* COMMA WS* jv+=json_value)* )? END_OBJECT;
json_value : annotationInUri
| primitivePropertyInUri
| complexPropertyInUri
| collectionPropertyInUri
| navigationPropertyInUri
;
arrayOrObject : json_array
| json_object;
collectionPropertyInUri : QUOTATION_MARK odataIdentifier QUOTATION_MARK
NAME_SEPARATOR
( primitiveColInUri | complexColInUri )
;
json_array : BEGIN_ARRAY json_value ( WSP? COMMA WSP? json_value)* END_ARRAY;
primitiveColInUri : BEGIN_ARRAY ( plj+=primitive1LiteralInJSON *( WS* COMMA WS* plj+=primitive1LiteralInJSON ) )? END_ARRAY
;
complexPropertyInUri : QUOTATION_MARK odataIdentifier QUOTATION_MARK
NAME_SEPARATOR
complexInUri
;
json_value : jsonPrimitiv
| rootExpr
| json_object
| json_array;
annotationInUri : QUOTATION_MARK ns=namespace? odi=odataIdentifier QUOTATION_MARK
NAME_SEPARATOR
( complexInUri | complexColInUri | primitive1LiteralInJSON | primitiveColInUri );
json_object : BEGIN_OBJECT
STRING_IN_JSON
NAME_SEPARATOR
json_value
END_OBJECT;
primitivePropertyInUri : QUOTATION_MARK odataIdentifier QUOTATION_MARK
NAME_SEPARATOR
primitive1LiteralInJSON;
navigationPropertyInUri : QUOTATION_MARK odataIdentifier QUOTATION_MARK
NAME_SEPARATOR ( rootExpr | rootExprCol )
;
rootExprCol : BEGIN_ARRAY
( rootExpr *( WS* COMMA WS* rootExpr ) )?
END_ARRAY
;
//; JSON syntax: adapted to URI restrictions from [RFC4627]
primitive1LiteralInJSON : STRING_IN_JSON
| number_in_json
| TRUE
| FALSE
| 'null'
;
jsonPrimitiv : STRING_IN_JSON
| number_in_json
| TRUE
| FALSE
| 'null'
;
number_in_json : INT | DECIMAL;
*/
//;------------------------------------------------------------------------------
//; 6. Names and identifiers
//;------------------------------------------------------------------------------

View File

@ -1,438 +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.
******************************************************************************/
lexer grammar UriLexerPart;
@lexer::members {
//custom lexer members -->
boolean debug = false;
private void out(String out) { if(debug) { System.out.println(out); } };
boolean bInSearch = false;
public boolean inSearch() { /*out("?SW?="+bInSearch);*/ return bInSearch; };
public void setInSearch(boolean value) { bInSearch=value; /*out("SW=set to "+ bInSearch);*/ };
boolean bInGeo = false;
public boolean inGeo() { /*out("?Geo?="+bInGeo);*/ return bInGeo; };
public void setInGeo(boolean value) { bInGeo=value; /*out("Geo=set to "+ bInGeo);*/ };
//testing
boolean bInCustomOption = false;
public boolean inCustomOption() { /*out("?CUST?="+bInCustomOption);*/ return bInCustomOption; };
public void setINCustomOption(boolean value) { bInCustomOption=value; /*out("CUST=set to "+ bInCustomOption);*/ };
//<-- custom lexer members
}
//;------------------------------------------------------------------------------
//; 0. URI
//;------------------------------------------------------------------------------
FRAGMENT : '#';
COUNT : '$count';
REF : '$ref';
VALUE : '$value';
//;------------------------------------------------------------------------------
//; 2. Query Options
//;------------------------------------------------------------------------------
SKIP : '$skip' EQ DIGIT+;
TOP : '$top' EQ DIGIT+;
LEVELS : '$levels' EQ ( DIGIT+ | 'max' );
FORMAT : '$format' EQ
( 'atom'
| 'json'
| 'xml'
| PCHAR+ '/' PCHAR+
);
ID : '$id' EQ QCHAR_NO_AMP+;
SKIPTOKEN : '$skiptoken' EQ QCHAR_NO_AMP+;
//;------------------------------------------------------------------------------
//; 4. Expressions
//;------------------------------------------------------------------------------
IMPLICIT_VARIABLE_EXPR : '$it';
CONTAINS : 'contains';
STARTSWITH : 'startswith';
ENDSWITH : 'endswith';
LENGTH : 'length';
INDEXOF : 'indexof';
SUBSTRING : 'substring';
TOLOWER : 'tolower';
TOUPPER : 'toupper';
TRIM : 'trim';
CONCAT : 'concat';
//;------------------------------------------------------------------------------
//; 5. JSON format for function parameters
//;------------------------------------------------------------------------------
QUOTATION_MARK : DQUOTE | '%22';
fragment CHAR_IN_JSON : QCHAR_UNESCAPED
| QCHAR_JSON_SPECIAL
| ESCAPE
( QUOTATION_MARK
| ESCAPE
| ( '/' | '%2F' ) //; solidus U+002F
| 'b' //; backspace U+0008
| 'f' //; form feed U+000C
| 'n' //; line feed U+000A
| 'r' //; carriage return U+000D
| 't' //; tab U+0009
| 'u' HEXDIG HEXDIG HEXDIG HEXDIG //; U+XXXX
);
fragment QCHAR_JSON_SPECIAL : SP | ':' | '{' | '}' | '[' | ']'; //; some agents put these unencoded into the query part of a URL
fragment ESCAPE : '\\' | '%5C'; //; reverse solidus U+005C
BEGIN_OBJECT : WS* ( '{' / '%7B' ) WS*;
END_OBJECT : WS* ( '}' / '%7D' ) WS*;
BEGIN_ARRAY : WS* ( '[' / '%5B' ) WS*;
END_ARRAY : WS* ( ']' / '%5D' ) WS*;
NAME_SEPARATOR : WS* COLON WS*;
//VALUE_SEPARATOR : WS* COMMA WS*;
//;------------------------------------------------------------------------------
//; 6. Names and identifiers
//;------------------------------------------------------------------------------
fragment ODI_LEADINGCHARACTER : ALPHA | '_'; //TODO; plus Unicode characters from the categories L or Nl
fragment ODI_CHARACTER : ALPHA | '_' | DIGIT; //TODO; plus Unicode characters from the categories L, Nl, Nd, Mn, Mc, Pc, or Cf
PRIMITIVETYPENAME : ('Edm.')?
( 'Binary'
| 'Boolean'
| 'Byte'
| 'Date'
| 'DateTimeOffset'
| 'Decimal'
| 'Double'
| 'Duration'
| 'Guid'
| 'Int16'
| 'Int32'
| 'Int64'
| 'SByte'
| 'Single'
| 'Stream'
| 'String'
| 'TimeOfDay'
| (ABSTRACTSPATIALTYPENAME ) ( CONCRETESPATIALTYPENAME )?
);
fragment ABSTRACTSPATIALTYPENAME : GEOGRAPHY_CS_FIX
| GEOMETRY_CS_FIX
;
fragment CONCRETESPATIALTYPENAME : COLLECTION_CS_FIX
| LINESTRING_CS_FIX
| MULTILINESTRING_CS_FIX
| MULTIPOINT_CS_FIX
| MULTIPOLYGON_CS_FIX
| POINT_CS_FIX
| POLYGON_CS_FIX
;
/*
fragment COLLECTION_CS_FIX1 : 'Collection';
fragment LINESTRING_CS_FIX1 : 'LineString';
fragment MULTILINESTRING_CS_FIX1 : 'MultiLineString';
fragment MULTIPOINT_CS_FIX1 : 'MultiPoint';
fragment MULTIPOLYGON_CS_FIX1 : 'MultiPolygon';
fragment POINT_CS_FIX1 : 'Point';
fragment POLYGON_CS_FIX1 : 'Polygon';
*/
//;------------------------------------------------------------------------------
//; 7. Literal Data Values
//;------------------------------------------------------------------------------
NULLVALUE : 'null';
fragment SQUOTEinSTRING : SQUOTE SQUOTE ;
BINARY : ('X'| B I N A R Y) SQUOTE (HEXDIG HEXDIG)* SQUOTE;
TRUE : 'true';
FALSE : 'false';
BOOLEAN : T R U E
| F A L S E
;
fragment DIGITS : DIGIT+;
INT : SIGN? DIGITS;
DECIMAL : INT '.' DIGITS ('e' SIGN? DIGITS)?;
NANINFINITY : 'NaN' | '-INF' | 'INF';
// --------------------- GUID ---------------------
GUID : G U I D SQUOTE GUIDVALUE SQUOTE;
fragment GUIDVALUE : HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG'-'
HEXDIG HEXDIG HEXDIG HEXDIG '-'
HEXDIG HEXDIG HEXDIG HEXDIG '-'
HEXDIG HEXDIG HEXDIG HEXDIG '-'
HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG HEXDIG;
// --------------------- DATE ---------------------
DATE : DATETOKEN SQUOTE DATETOKEN_VALUE SQUOTE;
fragment DATETOKEN : D A T E;
fragment DATETOKEN_VALUE : YEAR '-' MONTH '-' DAY;
// --------------------- DATETIMEOFFSET ---------------------
DATETIMEOFFSET : DATEOFFSETTOKEN SQUOTE DATETIMEOFFSET_VALUE SQUOTE;
fragment DATEOFFSETTOKEN : D A T E T I M E O F F S E T;
fragment DATETIMEOFFSET_VALUE : YEAR '-' MONTH '-' DAY T HOUR ':' MINUTE ( ':' SECOND ( '.' FRACTIONALSECONDS )? )? ( Z | SIGN HOUR ':' MINUTE );
// --------------------- DURATION ---------------------
DURATION : DURATIONTOKEN SQUOTE DURATIONVALUE SQUOTE;
fragment DURATIONTOKEN : D U R A T I O N;
fragment DUDAYFRAG : DIGITS 'D';
fragment DUHOURFRAG : DIGITS 'H';
fragment DUMINUTEFRAG : DIGITS 'M';
fragment DUSECONDFRAG : DIGITS ('.' DIGITS)? 'S';
fragment DUTIMEFRAG : 'T' (
( DUHOURFRAG DUMINUTEFRAG? DUSECONDFRAG?)
| (DUMINUTEFRAG DUSECONDFRAG?)
| DUSECONDFRAG
);
fragment DUDAYTIMEFRAG : DUDAYFRAG DUTIMEFRAG? | DUTIMEFRAG;
fragment DURATIONVALUE : '-'? 'P' DUDAYTIMEFRAG;
// --------------------- TIMEOFDAY ---------------------
TIMEOFDAY : TIMEOFDAYTO SQUOTE TIMEOFDAYVALUE SQUOTE;
fragment TIMEOFDAYTO : T I M E O F D A Y;
fragment TIMEOFDAYVALUE : HOUR ':' MINUTE ( ':' SECOND ( '.' FRACTIONALSECONDS )? )?;
// --------------------- date helper ---------------------
fragment ONEtoNINE : '1'..'9';
fragment YEAR : ('-')? ( '0' DIGIT DIGIT DIGIT | ONEtoNINE DIGIT DIGIT DIGIT );
fragment MONTH : '0' ONEtoNINE
| '1' ( '0' | '1' | '2' )
;
fragment DAY : '0' ONEtoNINE
| ('1'|'2') DIGIT
| '3' ('0'|'1')
;
fragment HOUR : ('0' | '1') DIGIT
| '2' ( '0'..'3')
;
fragment MINUTE : ZEROtoFIFTYNINE;
fragment SECOND : ZEROtoFIFTYNINE;
fragment FRACTIONALSECONDS : DIGIT+;
fragment ZEROtoFIFTYNINE : ('0'..'5') DIGIT;
COLLECTION_CS_FIX : 'Collection';
fragment LINESTRING_CS_FIX : 'LineString';
fragment MULTILINESTRING_CS_FIX : 'MultiLineString';
fragment MULTIPOINT_CS_FIX : 'MultiPoint';
fragment MULTIPOLYGON_CS_FIX : 'MultiPolygon';
fragment POINT_CS_FIX : 'Point';
fragment POLYGON_CS_FIX : 'Polygon';
COLLECTION_CS : ( COLLECTION_CS_FIX | C O L L E C T I O N );
LINESTRING_CS : ( LINESTRING_CS_FIX | L I N E S T R I N G ) ;
MULTILINESTRING_CS : ( MULTILINESTRING_CS_FIX | M U L T I L I N E S T R I N G);
MULTIPOINT_CS : ( MULTIPOINT_CS_FIX | M U L T I P O I N T );
MULTIPOLYGON_CS : ( MULTIPOLYGON_CS_FIX | M U L T I P O L Y G O N);
POINT_CS : ( POINT_CS_FIX | P O I N T );
POLYGON_CS : ( POLYGON_CS_FIX | P O L Y G O N );
SRID_CS : S R I D;
//fragment SQUOTE1 : ('\'' | '%27')-> mode(DEFAULT_MODE);
GEOGRAPHYPREFIX : (GEOGRAPHY_CS_FIX | G E O G R A P H Y) SQUOTE { setInGeo(true); } ;
GEOMETRYPREFIX : (GEOMETRY_CS_FIX | G E O M E T R Y) SQUOTE { setInGeo(true); } ;
fragment GEOGRAPHY_CS_FIX : 'Geography';
fragment GEOMETRY_CS_FIX : 'Geometry';
//;------------------------------------------------------------------------------
//; 9. Punctuation
//;------------------------------------------------------------------------------
fragment WS : ( SP | HTAB | '%20' | '%09' );
WSP : WS+ { !inGeo() }?;
// we can't not emit a single WS inside filter expression where left-recursion applies
// commonExpr : INT
// | commonExpr WS+ ('mul'|'div'|'mod') WS+ commonExpr
// does not work... ^^^ ^^^ but:
// commonExpr : INT
// | commonExpr WSP ('mul'|'div'|'mod') WSP commonExpr
// a single WS in only allowed/required in geometry
WSG : WS { inGeo() }?;
fragment AT_PURE : '@';
AT : AT_PURE | '%40';
COLON : ':' | '%3A';
COMMA : ',' | '%2C';
EQ : '=';
SIGN : '+' | '%2B' |'-';
SEMI : ';' | '%3B';
STAR : '*';
SQUOTE : '\'' | '%27';
OPEN : '(' | '%28';
CLOSE : ')' | '%29';
//;------------------------------------------------------------------------------
//; A. URI syntax [RFC3986]
//;------------------------------------------------------------------------------
QM : '?';
fragment PCHAR : UNRESERVED | PCT_ENCODED | SUB_DELIMS | ':' | AT_PURE;
fragment PCHARnoSQUOTE : UNRESERVED| PCTENCODEDnoSQUOTE | OTHER_DELIMS | '$' | '&' | EQ | ':' | AT_PURE;
fragment PCT_ENCODED : '%' HEXDIG HEXDIG;
fragment UNRESERVED : ALPHA | DIGIT | '-' |'.' | '_' | '~';
fragment SUB_DELIMS : '$' | '&' | '\'' | EQ | OTHER_DELIMS;
fragment OTHER_DELIMS : '!' | '(' | ')' | '*' | '+' | COMMA | ';';
fragment PCTENCODEDnoSQUOTE : '%' ( '0'|'1'|'3'..'9' | AtoF ) HEXDIG
| '%' '2' ( '0'..'6'|'8'|'9' | AtoF )
;
fragment QCHAR_NO_AMP : UNRESERVED | PCT_ENCODED | OTHER_DELIMS | ':' | AT_PURE | '/' | '?' | '$' | '\'' | EQ;
fragment QCHAR_NO_AMP_EQ : UNRESERVED | PCT_ENCODED | OTHER_DELIMS | ':' | AT_PURE | '/' | '?' | '$' | '\'';
fragment QCHAR_NO_AMP_EQ_AT_DOLLAR : UNRESERVED | PCT_ENCODED | OTHER_DELIMS | ':' | '/' | '?' | '\'';
fragment QCHAR_UNESCAPED : UNRESERVED | PCT_ENCODED_UNESCAPED | OTHER_DELIMS | ':' | AT_PURE | '/' | '?' | '$' | '\'' | EQ;
fragment PCT_ENCODED_UNESCAPED : '%' ( '0' | '1' | '3' | '4' | '6' | '8' | '9' | 'A'..'F' ) HEXDIG
| '%' '2' ( '0' | '1' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A'..'F' )
| '%' '5' ( DIGIT | 'A' | 'B' | 'D' | 'E' | 'F' );
fragment QCHAR_NO_AMP_DQUOTE : QCHAR_UNESCAPED
| ESCAPE ( ESCAPE | QUOTATION_MARK );
//;------------------------------------------------------------------------------
//; B. IRI syntax [RFC3987]
//;------------------------------------------------------------------------------
//; Note: these are over-generous stubs, for the actual patterns refer to RFC3987
//;------------------------------------------------------------------------------
//IRI_IN_HEADER : ( VCHAR | obs-text )+;
//;------------------------------------------------------------------------------
//; C. ABNF core definitions [RFC5234]
//;------------------------------------------------------------------------------
fragment ALPHA : 'a'..'z'|'A'..'Z';
fragment HEXDIG : DIGIT | AtoF;
fragment AtoF : 'a'..'f'|'A'..'F';
//fragment VCHAR : '\u0021'..'\u007E';
DIGIT : '0'..'9';
DQUOTE : '\u0022';
SP : ' ';//'\u0020'; // a simple space
HTAB : '%09';
//;------------------------------------------------------------------------------
//; End of odata-abnf-construction-rules
//;------------------------------------------------------------------------------
//;------------------------------------------------------------------------------
//; HELPER
//;------------------------------------------------------------------------------
fragment A : 'a'|'A';
fragment B : 'b'|'B';
fragment C : 'c'|'C';
fragment D : 'd'|'D';
fragment E : 'e'|'E';
fragment F : 'f'|'F';
fragment G : 'g'|'G';
fragment H : 'h'|'H';
fragment I : 'i'|'I';
fragment L : 'l'|'L';
fragment M : 'm'|'M';
fragment N : 'n'|'N';
fragment O : 'o'|'O';
fragment P : 'p'|'P';
fragment R : 'r'|'R';
fragment S : 's'|'S';
fragment T : 't'|'T';
fragment U : 'u'|'U';
fragment Y : 'y'|'Y';
fragment Z : 'z'|'Z';
/* D O N T C H A N G E T H E O R D E R O F T H I S*/
/* D O N T C H A N G E T H E O R D E R O F T H I S*/
/* D O N T C H A N G E T H E O R D E R O F T H I S*/
STRING : SQUOTE (SQUOTEinSTRING | PCHARnoSQUOTE )* SQUOTE { !inGeo() }?;
//conflict with ODATAIDENTIFIER, fixed with predicate
SEARCHWORD : ALPHA+ { inSearch() }?; //; Actually: any character from the Unicode categories L or Nl,
//; but not the words AND, OR, and NOT which are match far above
//conflict with STRING_IN_JSON, fixed with predicate
SEARCHPHRASE : QUOTATION_MARK QCHAR_NO_AMP_DQUOTE+ QUOTATION_MARK { inSearch() }?;
ODATAIDENTIFIER : ODI_LEADINGCHARACTER (ODI_CHARACTER)*;
//AT_ODATAIDENTIFIER : AT ODATAIDENTIFIER;
STRING_IN_JSON : QUOTATION_MARK CHAR_IN_JSON* QUOTATION_MARK;
/* D O N T C H A N G E T H E O R D E R O F T H I S*/
/* D O N T C H A N G E T H E O R D E R O F T H I S*/
/* D O N T C H A N G E T H E O R D E R O F T H I S*/

View File

@ -25,7 +25,7 @@ import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.apache.olingo.producer.core.uri.antlr.UriLexer;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
public class ErrorHandler<T> extends BaseErrorListener {
@Override

View File

@ -0,0 +1,81 @@
/*******************************************************************************
* 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.odata4.producer.core.uri;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BailErrorStrategy;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.OdataRelativeUriEOFContext;
public class ParserAdapter {
static public OdataRelativeUriEOFContext parseInput(final String input) throws UriParserException {
UriParserParser parser = null;
UriLexer lexer = null;
OdataRelativeUriEOFContext ret = null;
// Use 2 stage approach to improve performance
// see https://github.com/antlr/antlr4/issues/192
// stage= 1
try {
// create parser
lexer = new UriLexer(new ANTLRInputStream(input));
parser = new UriParserParser(new CommonTokenStream(lexer));
// Bail out of parser at first syntax error. --> proceeds in catch block with step 2
parser.setErrorHandler(new BailErrorStrategy());
// User the faster LL parsing
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
ret = parser.odataRelativeUriEOF();
} catch (ParseCancellationException hardException) {
try {
// create parser
lexer = new UriLexer(new ANTLRInputStream(input));
parser = new UriParserParser(new CommonTokenStream(lexer));
// Used default error strategy
parser.setErrorHandler(new DefaultErrorStrategy());
// User the slower SLL parsing
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
ret = parser.odataRelativeUriEOF();
} catch (Exception weakException) {
throw new UriParserException("Error in Parser", weakException);
// exceptionOnStage = 2;
}
} catch (Exception hardException) {
throw new UriParserException("Error in Parser", hardException);
}
return ret;
}
}

View File

@ -18,51 +18,19 @@
******************************************************************************/
package org.apache.olingo.odata4.producer.core.uri;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.odata4.producer.api.uri.UriInfo;
import org.apache.olingo.odata4.producer.api.uri.UriInfoBatch;
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfo;
public class UriInfoImpl implements UriInfo, UriInfoBatch {
public class UriInfoImpl {
private UriInfoKind kind;
private List<UriPathInfo> uriPathInfos = new ArrayList<UriPathInfo>();
@Override
public UriInfoKind getKind() {
return kind;
}
public UriInfoImpl setKind(final UriInfoKind kind) {
this.kind = kind;
return this;
}
public void addUriPathInfo(final UriPathInfo uriPathInfo) {
uriPathInfos.add(uriPathInfo);
public Object getKind() {
return kind;
}
/*
* private Edm edm = null;
* private List<UriPathInfoImpl> pathInfos = new ArrayList<UriPathInfoImpl>();
*
* public Edm getEdm() {
* return edm;
* }
*
* public void addUriPathInfo(final UriPathInfoImpl uriPathInfoImpl) {
* pathInfos.add(uriPathInfoImpl);
* }
*
* public UriPathInfoImpl getLastUriPathInfo() {
* if (!pathInfos.isEmpty()) {
* return pathInfos.get(pathInfos.size() - 1);
* } else {
* return null;
* }
* }
*/
}

View File

@ -16,9 +16,13 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.odata4.producer.core.uri;
public class UriPathInfoSigletonImpl extends UriPathInfoImpl {
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
public class UriInfoImplAll extends UriInfoImpl {
public UriInfoImplAll() {
this.setKind(UriInfoKind.all);
}
}

View File

@ -16,9 +16,12 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.odata4.producer.core.uri;
public class UriPathInfoActionImportImpl extends UriPathInfoImpl {
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
public class UriInfoImplBatch extends UriInfoImpl {
public UriInfoImplBatch() {
this.setKind(UriInfoKind.batch);
}
}

View File

@ -0,0 +1,27 @@
/*******************************************************************************
* 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.odata4.producer.core.uri;
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
public class UriInfoImplCrossjoin extends UriInfoImpl {
public UriInfoImplCrossjoin() {
this.setKind(UriInfoKind.crossjoin);
}
}

View File

@ -0,0 +1,28 @@
/*******************************************************************************
* 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.odata4.producer.core.uri;
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
public class UriInfoImplEntity extends UriInfoImpl {
public UriInfoImplEntity() {
this.setKind(UriInfoKind.entity);
}
}

View File

@ -0,0 +1,27 @@
/*******************************************************************************
* 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.odata4.producer.core.uri;
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
public class UriInfoImplMetadata extends UriInfoImpl {
public UriInfoImplMetadata() {
this.setKind(UriInfoKind.metadata);
}
}

View File

@ -16,33 +16,35 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.odata4.producer.core.uri;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.odata4.producer.api.uri.KeyPredicate;
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
public class UriPathInfoImplFunctionImport extends UriPathInfoImpl {
public class UriInfoImplPath extends UriInfoImpl {
// TODO change to proper Type
private Object functionParameter;
private List<KeyPredicate> keyPredicates;
List<UriPathInfoImpl> pathInfos = new ArrayList<UriPathInfoImpl>();
public Object getFunctionParameter() {
return functionParameter;
public UriInfoImplPath() {
this.setKind(UriInfoKind.path);
}
public void setFunctionParameter(final Object functionParameter) {
this.functionParameter = functionParameter;
public UriInfoImpl addPathInfo(UriPathInfoImpl pathInfo) {
pathInfos.add(pathInfo);
return this;
}
public List<KeyPredicate> getKeyPredicates() {
return keyPredicates;
public UriPathInfoImpl getLastUriPathInfo() {
if (pathInfos.size() > 0) {
return pathInfos.get(pathInfos.size() - 1);
}
return null;
}
public void setKeyPredicates(final List<KeyPredicate> keyPredicates) {
this.keyPredicates = keyPredicates;
public UriPathInfoImpl getUriPathInfo(int index) {
return pathInfos.get(index);
}
}

View File

@ -16,39 +16,32 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.odata4.producer.api.uri;
package org.apache.olingo.odata4.producer.core.uri;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.odata4.commons.api.edm.EdmBindingTarget;
public class UriKeyPredicateList {
public class UriInfo1 {
private UriType uriType;
private EdmBindingTarget bindingTarget;
private List<String> keyNames = Collections.emptyList();
private List<String> names = new ArrayList<String>();
private List<String> values = new ArrayList<String>();
public UriType getUriType() {
return uriType;
public UriKeyPredicateList add(String name, String value) {
names.add(name);
values.add(value);
return this;
}
public void setUriType(final UriType uriType) {
this.uriType = uriType;
public List<String> getNames() {
return names;
}
public EdmBindingTarget getBindingTarget() {
return bindingTarget;
public String getName(int index) {
return names.get(index);
}
public void setBindingTarget(final EdmBindingTarget bindingTarget) {
this.bindingTarget = bindingTarget;
}
public void setKeyNames(final List<String> keyNames) {
this.keyNames = keyNames;
}
public List<String> getKeyNames() {
return keyNames;
public Object getValue(int index) {
return values.get(index);
}
}

View File

@ -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.odata4.producer.core.uri;
import java.util.ArrayList;
import java.util.List;
public class UriParameterlist {
private List<String> names = new ArrayList<String>();
private List<String> values = new ArrayList<String>();
private List<String> aliases = new ArrayList<String>();
public UriParameterlist add(String name, String value, String alias) {
names.add(name);
values.add(value);
aliases.add(alias);
return this;
}
public List<String> getNames() {
return names;
}
}

View File

@ -16,30 +16,18 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.odata4.producer.api.uri;
package org.apache.olingo.odata4.producer.core.uri;
import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
//TODO Check name of this exception when implementing proper error handling
public class UriParserException extends Exception {
/**
* Key predicate, consisting of a simple-type property and its value as String literal
* @org.apache.olingo.odata2.DoNotImplement
*
*/
public interface KeyPredicate {
public UriParserException(String message, Throwable cause) {
super(message, cause);
}
/**
* <p>Gets the literal String in default representation.</p>
* <p>The description for {@link org.apache.olingo.odata2.api.edm.EdmLiteral} has some motivation for using
* this representation.</p>
* @return String literal in default (<em>not</em> URI) representation
* @see org.apache.olingo.odata2.api.edm.EdmLiteralKind
*
*/
public String getLiteral();
/**
* Gets the key property.
* @return {@link EdmProperty} simple-type property
*/
public EdmProperty getProperty();
private static final long serialVersionUID = -1813203179082217112L;
}

View File

@ -16,203 +16,374 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.odata4.producer.core.uri;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.tree.ParseTree;
import java.util.List;
import org.apache.olingo.odata4.commons.api.edm.Edm;
import org.apache.olingo.odata4.commons.api.edm.EdmAction;
import org.apache.olingo.odata4.commons.api.edm.EdmActionImport;
import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
import org.apache.olingo.odata4.commons.api.edm.EdmElement;
import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet;
import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport;
import org.apache.olingo.odata4.commons.api.edm.EdmNamed;
import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
import org.apache.olingo.producer.core.uri.antlr.UriLexer;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.AllAltContext;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.BatchAltContext;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.CrossjoinAltContext;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.EntityAltContext;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.MetadataAltContext;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.OdataRelativeUriContext;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.PathSegmentContext;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.PathSegmentsAltContext;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.PathSegmentsContext;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.ResourcePathAltContext;
import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType;
import org.apache.olingo.odata4.commons.api.edm.EdmType;
import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltBatchContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltEntityCastContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltEntityContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltMetadataContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltResourcePathContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.NameValueListContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.NameValueOptListContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.NameValuePairContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.OdataRelativeUriContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.OdataRelativeUriEOFContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.PathSegmentContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.PathSegmentsContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.QueryOptionsContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.ResourcePathContext;
public class UriParserImpl {
private Edm edm = null;
private EdmEntityContainer edmEntityContainer = null;
private EdmEntityContainer entityContainer = null;
public UriInfoImpl readUri(final String uri, final Edm edm) {
entityContainer = edm.getEntityContainer(null);// "RefScenario","Container1"
UriInfoImpl ret = new UriInfoImpl();
OdataRelativeUriContext root = parseUri(uri);
ret = readODataRelativeUri(root);
return ret;
public UriParserImpl(Edm edm) {
this.edm = edm;
this.edmEntityContainer = edm.getEntityContainer(null);
}
UriInfoImpl readODataRelativeUri(final OdataRelativeUriContext root) {
root.getChildCount();
public UriInfoImpl ParseUri(String uri) throws UriParserException {
OdataRelativeUriEOFContext root = ParserAdapter.parseInput(uri);
return readODataRelativeUriEOF(root);
}
if (root instanceof BatchAltContext) {
return new UriInfoImpl().setKind(UriInfoKind.batch);
private UriInfoImpl readODataRelativeUriEOF(OdataRelativeUriEOFContext node) {
OdataRelativeUriContext first = (OdataRelativeUriContext) node.getChild(0);
return readODataRelativeUri(first);
}
} else if (root instanceof EntityAltContext) {
// TODO implement
} else if (root instanceof MetadataAltContext) {
// TODO implement
} else if (root instanceof ResourcePathAltContext) {
private UriInfoImpl readODataRelativeUri(OdataRelativeUriContext node) {
if (node instanceof AltBatchContext) {
return new UriInfoImplBatch();
} else if (node instanceof AltEntityContext) {
// TODO read the entity options
return new UriInfoImplEntity();
} else if (node instanceof AltEntityCastContext) {
// TODO read the entity options and the cast ns.odi
return new UriInfoImplEntity();
} else if (node instanceof AltMetadataContext) {
// TODO read the metadata queryparameter and fragment
return new UriInfoImplMetadata();
} else if (node instanceof AltResourcePathContext) {
return readAltResourcePath((AltResourcePathContext) node);
}
return null;
}
return readResourcePath(root);
private UriInfoImpl readAltResourcePath(AltResourcePathContext node) {
ResourcePathContext rpc = (ResourcePathContext) node.getChild(0);
QueryOptionsContext qoc = (QueryOptionsContext) node.getChild(2); // is null if there are no options
if (rpc.vPSs != null) {
return readPathSegments(rpc.vPSs);
} else if (rpc.vCJ != null) {
return new UriInfoImplCrossjoin();
} else if (rpc.vAll != null) {
return new UriInfoImplAll();
}
return null;
}
private UriInfoImpl readResourcePath(final OdataRelativeUriContext root) {
ParseTree firstChild = root.getChild(0);
private UriInfoImpl readPathSegments(PathSegmentsContext pathSegments) {
int iSegment = 0;
UriInfoImplPath infoImpl = new UriInfoImplPath();
PathSegmentContext firstChild = (PathSegmentContext) pathSegments.vlPS.get(iSegment);
UriPathInfoImpl firstPathInfo = readFirstPathSegment(infoImpl, firstChild);
if (firstChild instanceof AllAltContext) {
return new UriInfoImpl().setKind(UriInfoKind.all);
} else if (firstChild instanceof CrossjoinAltContext) {
// TODO read ODIs behind crossjoin
return new UriInfoImpl().setKind(UriInfoKind.crossjoin);
} else if (firstChild instanceof PathSegmentsAltContext) {
return readPathSegments((PathSegmentsAltContext) firstChild);
iSegment++;
UriPathInfoImpl prevPathInfo = firstPathInfo;
while (iSegment < pathSegments.vlPS.size()) {
PathSegmentContext nextChild = (PathSegmentContext) pathSegments.vlPS.get(iSegment);
prevPathInfo = readNextPathSegment(infoImpl, nextChild, prevPathInfo);
iSegment++;
}
return null;
return infoImpl;
}
private UriInfoImpl readPathSegments(final PathSegmentsAltContext pathSegmentsAlt) {
PathSegmentsContext firstChild = (PathSegmentsContext) pathSegmentsAlt.getChild(0);
private UriPathInfoImpl readNextPathSegment(UriInfoImplPath infoImpl, PathSegmentContext pathSegment,
UriPathInfoImpl prevPathInfo) {
UriInfoImpl uriInfo = new UriInfoImpl();
UriPathInfoImpl pathInfo = null;
readFirstPathSegment(uriInfo, firstChild.ps.get(0));
String odi = pathSegment.vODI.getText(); // not optional
for (int i = 1; i < firstChild.ps.size(); i++) {
// check for properties
if (pathSegment.vNS == null) {
EdmType prevType = prevPathInfo.getType();
if (prevType instanceof EdmStructuralType) {
EdmStructuralType prevStructType = (EdmStructuralType) prevType;
EdmElement element = prevStructType.getProperty(odi);
if (element == null) {
// TODO exception property not found
}
if (element instanceof EdmProperty) {
prevPathInfo.addProperty((EdmProperty) element);
return prevPathInfo;
} else if (element instanceof EdmNavigationProperty) {
prevPathInfo.addNavigationProperty((EdmNavigationProperty) element);
UriPathInfoNavEntitySet pathInfoNav = new UriPathInfoNavEntitySet();
pathInfoNav.addSourceNavigationProperty((EdmNavigationProperty) element);
infoImpl.addPathInfo(pathInfoNav);
return pathInfoNav;
} else {
}
}
} else {
// check for namespace
String namespace = pathSegment.vNS.getText();
namespace = namespace.substring(0, namespace.length() - 1);
FullQualifiedName fullName = new FullQualifiedName(namespace, odi);
// check for typecasts
if (prevPathInfo.getType() instanceof EdmEntityType) {
EdmEntityType et = edm.getEntityType(fullName);
if (et != null) {
prevPathInfo.addTypeFilter(et);
if (pathSegment.vlVPO.size() != 0) {
UriKeyPredicateList keyPred = readKeyPredicateList(
pathSegment.vlVPO.get(0), (EdmEntityType) prevPathInfo.getType());
prevPathInfo.setKeyPredicates(keyPred);
}
return prevPathInfo;
}
} else if (prevPathInfo.getType() instanceof EdmComplexType) {
EdmComplexType ct = edm.getComplexType(fullName);
if (ct != null) {
prevPathInfo.addTypeFilter(ct);
return prevPathInfo;
}
}
// check for bound action
if (pathSegment.vlVPO == null) {
EdmAction action = edm.getAction(fullName, prevPathInfo.getFullType(), false);
pathInfo = new UriPathInfoActionImpl().setAction(action);
infoImpl.addPathInfo(pathInfo);
return pathInfo;
} else {
// check for bound functions
UriParameterlist parameterList = readParameterList(pathSegment.vlVPO.get(0));
EdmFunction function = edm.getFunction(fullName, prevPathInfo.getFullType(), false, parameterList.getNames());
if (function != null) {
UriPathInfoFunctionImpl pathInfoFunction = new UriPathInfoFunctionImpl();
pathInfoFunction.setFunction(function);
pathInfoFunction.setParameters(parameterList);
if (pathSegment.vlVPO.size() > 1) {
UriKeyPredicateList keyPred = readKeyPredicateList(
pathSegment.vlVPO.get(1), (EdmEntityType) prevPathInfo.getType());
pathInfoFunction.setKeyPredicates(keyPred);
}
infoImpl.addPathInfo(pathInfo);
return pathInfo;
}
}
// Exception unknown typeFilter/action or function
}
return null;
}
private void readFirstPathSegment(final UriInfoImpl uriInfo, final PathSegmentContext ctx) {
/*
* if (ctx.ns != null) {//TODO implement
* // Error: First pathsegment can not be qualified. Allowed is entityset|function...
* }
*/
private UriPathInfoImpl readFirstPathSegment(UriInfoImplPath infoImpl, PathSegmentContext pathSegment) {
UriPathInfoImpl pathInfo = null;
/*
* if (ctx.odi == null) {//TODO implement
* // Error: First pathsegment must contain an odata identifier
* }
*/
// assert pathSegment.vNS = null;
String odi = pathSegment.vODI.getText(); // not optional
// get element "odataIdentifier" from EDM
EdmNamed edmObject = null;// entityContainer.getElement(odataIdentifier);
if (edmObject instanceof EdmEntitySet) {
// is EdmEntitySet
EdmEntitySet entityset = (EdmEntitySet) edmObject;
UriPathInfoEntitySetImpl pathInfo = new UriPathInfoEntitySetImpl();
pathInfo.setKind(UriPathInfoKind.entitySet);
pathInfo.setEntityContainer(entityContainer);
pathInfo.setTargetEntityset(entityset);
pathInfo.setTargetType(entityset.getEntityType());
pathInfo.setCollection(true);
// TODO check if kp may have been collected into fp
/*
* if (ctx.kp != null) {
* //pathInfo.setKeyPredicates(readkeypredicates(ctx.kp, entityset.getEntityType()));
* pathInfo.setCollection(false);
* }
*/
uriInfo.addUriPathInfo(pathInfo);
return;
} else if (edmObject instanceof EdmSingleton) {
// is EdmSingleton
EdmSingleton singleton = (EdmSingleton) edmObject;
UriPathInfoSigletonImpl pathInfo = new UriPathInfoSigletonImpl(); // TODO change to UriPathInfoImplEntitySet
pathInfo.setKind(UriPathInfoKind.singleton);
pathInfo.setEntityContainer(entityContainer);
pathInfo.setTargetType(singleton.getEntityType());
// pathInfo.targetType = singleton.getEntityType();
pathInfo.setCollection(false);
uriInfo.addUriPathInfo(pathInfo);
return;
} else if (edmObject instanceof EdmActionImport) {
// is EdmActionImport
UriPathInfoActionImportImpl pathInfo = new UriPathInfoActionImportImpl();
pathInfo.setKind(UriPathInfoKind.actionImport);
uriInfo.addUriPathInfo(pathInfo);
return;
} else if (edmObject instanceof EdmFunctionImport) {
// is EdmFunctionImport
UriPathInfoImplFunctionImport pathInfo = new UriPathInfoImplFunctionImport();
pathInfo.setKind(UriPathInfoKind.functioncall);
/*
* if (ctx.fp != null) {
* pathInfo.setFunctionParameter(readFunctionParameters(uriInfo, ctx.fp));
* }
*/
/*
* if (ctx.kp != null) {
* pathInfo.setKeyPredicates(readkeypredicates(ctx.kp, fi.getReturnedEntitySet().getEntityType()));
* }
*/
uriInfo.addUriPathInfo(pathInfo);
return;
// EntitySet
EdmEntitySet edmES = edmEntityContainer.getEntitySet(odi);
if (edmES != null) {
pathInfo = readEntitySet(pathSegment, edmES);
}
// Singleton
EdmSingleton edmSI = edmEntityContainer.getSingleton(odi);
if (edmSI != null) {
pathInfo = readSingleton(pathSegment, edmSI);
}
// FunctionImport
EdmFunctionImport edmFI = edmEntityContainer.getFunctionImport(odi);
if (edmFI != null) {
pathInfo = readFunctionImport(pathSegment, edmFI);
}
// ActionImport
EdmActionImport edmAI = edmEntityContainer.getActionImport(odi);
if (edmAI != null) {
pathInfo = readActionImport(pathSegment, edmAI);
}
infoImpl.addPathInfo(pathInfo);
return pathInfo;
}
private OdataRelativeUriContext parseUri(final String uri) {
private UriPathInfoImpl readActionImport(PathSegmentContext pathSegment, EdmActionImport edmFI) {
UriPathInfoActionImpl uriPathInfo = new UriPathInfoActionImpl();
ANTLRInputStream input = new ANTLRInputStream(uri);
EdmAction action = edmFI.getAction();
uriPathInfo.setAction(action);
// UriLexer lexer = new UriLexer(input);
UriLexer lexer = new UriLexer(input);
int num = pathSegment.vlVPO.size();
if (num == 2) {
// TODO exception action parameters not allowed
} else if (num == 1) {
CommonTokenStream tokens = new CommonTokenStream(lexer);
UriParserParser parser = new UriParserParser(tokens);
if (uriPathInfo.isCollection() == true) {
if (uriPathInfo.getType() instanceof EdmEntityType) {
uriPathInfo.setKeyPredicates(
readKeyPredicateList(pathSegment.vlVPO.get(0), (EdmEntityType) uriPathInfo.getType()));
} else {
// TODO exception action keypreticates not allowed
}
} else {
// TODO exception action parameters not allowed
}
}
// parser.addErrorListener(new ErrorHandler());
// if (stage == 1) {
// //see https://github.com/antlr/antlr4/issues/192
// parser.setErrorHandler(new BailErrorStrategy());
// parser.getInterpreter().setPredictionMode(PredictionMode.LL);
// } else {
parser.setErrorHandler(new DefaultErrorStrategy());
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
// }
// parser.d
return parser.odataRelativeUri();
return uriPathInfo;
}
private UriPathInfoImpl readFunctionImport(PathSegmentContext pathSegment, EdmFunctionImport edmFI) {
UriPathInfoFunctionImpl uriPathInfo = new UriPathInfoFunctionImpl();
if (pathSegment.vlVPO == null) {
// TODO exception function parameters missing
}
UriParameterlist parameterList = readParameterList(pathSegment.vlVPO.get(0));
EdmFunction function = edmFI.getFunction(parameterList.getNames());
uriPathInfo.setFunction(function);
uriPathInfo.setParameters(parameterList);
if (pathSegment.vlVPO.size() > 1) {
if (!(uriPathInfo.getType() instanceof EdmEntityType)) {
// TODO exception illegally used keypredicates on function impored returning not an entityset
}
uriPathInfo.setKeyPredicates(
readKeyPredicateList(pathSegment.vlVPO.get(1), (EdmEntityType) uriPathInfo.getType()));
}
return null;
}
private UriPathInfoImpl readSingleton(PathSegmentContext pathSegment, EdmSingleton edmSI) {
UriPathInfoSingletonImpl uriPathInfo = new UriPathInfoSingletonImpl();
uriPathInfo.setSingleton(edmSI);
return uriPathInfo;
}
private UriPathInfoImpl readEntitySet(PathSegmentContext pathSegment, EdmEntitySet edmES) {
UriPathInfoEntitySetImpl uriPathInfo = new UriPathInfoEntitySetImpl();
uriPathInfo.setEntitSet(edmES);
// KeyPredicates
if (pathSegment.vlVPO != null) {
if (pathSegment.vlVPO.size() == 1) {
uriPathInfo.setKeyPredicates(readKeyPredicateList(pathSegment.vlVPO.get(0), edmES.getEntityType()));
} else if (pathSegment.vlVPO.size() > 1) {
// TODO exception ( to much key predicates)
}
}
return uriPathInfo;
}
private UriKeyPredicateList readKeyPredicateList(NameValueOptListContext parameterList, EdmEntityType entityType) {
if (parameterList.vVO != null) {
String value = parameterList.vVO.vV.getText();
List<String> kp = entityType.getKeyPredicateNames();
if (kp.size() != 1) {
// TODO exception "for using a value only keyPredicate there must be exact ONE defined keyProperty
}
String keyName = kp.get(0); // there yhoul
return new UriKeyPredicateList().add(keyName, value);
}
NameValueListContext vNVL = parameterList.vNVL;
if (vNVL == null) {
// TODO throw exception empty keypredicates not allowed
}
UriKeyPredicateList uriPrameterList1 = new UriKeyPredicateList();
for (NameValuePairContext nvl : vNVL.vNVP) {
String name = nvl.vODI.getText();
String value = nvl.vVAL.getText();
uriPrameterList1.add(name, value);
}
return uriPrameterList1;
}
private UriParameterlist readParameterList(NameValueOptListContext parameterList) {
if (parameterList.vVO != null) {
// TODO throw error "Value Only" not allowed for function/action parameters, only in keypredicates
return null;
}
NameValueListContext vNVL = parameterList.vNVL;
UriParameterlist uriPrameterList1 = new UriParameterlist();
for (NameValuePairContext nvl : vNVL.vNVP) {
String name = nvl.vODI.getText();
if (nvl.vVAL != null) {
String value = nvl.vVAL.getText();
uriPrameterList1.add(name, value, null);
} else {
String alias = nvl.vALI.getText();
uriPrameterList1.add(name, null, alias);
}
}
return uriPrameterList1;
}
}

View File

@ -18,44 +18,27 @@
******************************************************************************/
package org.apache.olingo.odata4.producer.core.uri;
import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
import org.apache.olingo.odata4.producer.api.uri.KeyPredicate;
import org.apache.olingo.odata4.commons.api.edm.EdmAction;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
/**
*
* Covers Functionimports and BoundFunction in URI
*/
public class KeyPredicateImpl implements KeyPredicate {
public class UriPathInfoActionImpl extends UriPathInfoImpl {
public KeyPredicateImpl(final String literal, final EdmProperty property) {
super();
this.literal = literal;
this.property = property;
private EdmAction action;
public UriPathInfoActionImpl() {
this.setKind(UriPathInfoKind.action);
}
private String literal;
private EdmProperty property;
public UriPathInfoActionImpl setAction(EdmAction action) {
@Override
public String getLiteral() {
return literal;
}
this.action = action;
this.setType(action.getReturnType().getType());
this.setCollection(action.getReturnType().isCollection());
public void setValue(final String value) {
literal = value;
}
@Override
public EdmProperty getProperty() {
return property;
}
public void setProperty(final EdmProperty property) {
this.property = property;
}
@Override
public String toString() {
return "KeyPredicate: literal=" + literal + ", propertyName=" + property;
return this;
}
}

View File

@ -19,32 +19,22 @@
package org.apache.olingo.odata4.producer.core.uri;
import java.util.List;
import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet;
import org.apache.olingo.odata4.producer.api.uri.KeyPredicate;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
public class UriPathInfoEntitySetImpl extends UriPathInfoImpl {
EdmEntitySet edmEntitySet = null;
private EdmEntitySet targetEntityset;
private List<KeyPredicate> keyPredicates;
public EdmEntitySet getTargetEntityset() {
return targetEntityset;
public UriPathInfoEntitySetImpl() {
this.setKind(UriPathInfoKind.entitySet);
}
// TODO add to Interface UriPathInfoEntitySet
public void setTargetEntityset(final EdmEntitySet targetEntityset) {
this.targetEntityset = targetEntityset;
}
public UriPathInfoEntitySetImpl setEntitSet(EdmEntitySet edmES) {
public List<KeyPredicate> getKeyPredicates() {
return keyPredicates;
}
this.edmEntitySet = edmES;
this.setType(edmES.getEntityType());
public void setKeyPredicates(final List<KeyPredicate> keyPredicates) {
this.keyPredicates = keyPredicates;
return this;
}
}

View File

@ -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.odata4.producer.core.uri;
import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
/**
* Covers Functionimports and BoundFunction in URI
*/
public class UriPathInfoFunctionImpl extends UriPathInfoImpl {
private UriParameterlist parameters;
private EdmFunction function;
private UriKeyPredicateList keyPredicates;
public UriPathInfoFunctionImpl() {
this.setKind(UriPathInfoKind.function);
}
public UriPathInfoFunctionImpl setParameters(UriParameterlist parameters) {
this.parameters = parameters;
return this;
}
public UriParameterlist getParameters() {
return parameters;
}
public UriPathInfoFunctionImpl setFunction(EdmFunction function) {
this.function = function;
super.setType(function.getReturnType().getType());
super.setCollection(function.getReturnType().isCollection());
return this;
}
public UriPathInfoFunctionImpl setKeyPredicates(UriKeyPredicateList keyPredicates) {
this.keyPredicates = keyPredicates;
return this;
}
}

View File

@ -18,58 +18,161 @@
******************************************************************************/
package org.apache.olingo.odata4.producer.core.uri;
import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfo;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.odata4.commons.api.edm.EdmElement;
import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType;
import org.apache.olingo.odata4.commons.api.edm.EdmType;
import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
//import org.apache.olingo.api.commons.InlineCount;
//import org.apache.olingo.api.uri.NavigationPropertySegment;
//import org.apache.olingo.api.uri.NavigationSegment;
//import org.apache.olingo.api.uri.SelectItem;
//import org.apache.olingo.api.uri.expression.FilterExpression;
//import org.apache.olingo.api.uri.expression.OrderByExpression;
/**
*
*/
public class UriPathInfoImpl implements UriPathInfo {
public abstract class UriPathInfoImpl {
private EdmType initialType = null;
private EdmType finalType = null;
private UriPathInfoKind kind;
private EdmEntityContainer entityContainer;
private EdmType collectionTypeFilter = null;
private UriKeyPredicateList keyPredicates = null;
private EdmType singleTypeFilter = null;
private class PathListItem {
private EdmElement property; // ia EdmProperty or EdmNavigationProperty
private EdmType initialType;
private EdmType finalType;
private boolean isCollection;
}
private List<PathListItem> pathList = null;
private boolean isCollection;
private EdmEntityType targetType;
@Override
public EdmEntityContainer getEntityContainer() {
return entityContainer;
public UriPathInfoImpl setType(EdmType edmType) {
this.initialType = edmType;
this.finalType = edmType;
return this;
}
public void setEntityContainer(final EdmEntityContainer entityContainer) {
this.entityContainer = entityContainer;
public EdmType getType() {
return finalType;
}
public EdmType getInitialType() {
return initialType;
}
public FullQualifiedName getFullType() {
return new FullQualifiedName(finalType.getNamespace(), finalType.getName());
}
public UriPathInfoImpl setKind(UriPathInfoKind kind) {
this.kind = kind;
return this;
}
@Override
public UriPathInfoKind getKind() {
return kind;
}
public void setKind(final UriPathInfoKind kind) {
this.kind = kind;
public UriPathInfoImpl setKeyPredicates(UriKeyPredicateList keyPredicates) {
if ( this.isCollection()!= true) {
// throw exception
}
this.keyPredicates = keyPredicates;
this.setCollection(false);
return this;
}
public UriKeyPredicateList getKeyPredicates() {
return this.keyPredicates;
}
public UriPathInfoImpl addTypeFilter(EdmStructuralType targetType) {
// TODO if there is a navigation path the type filter musst be applied to the last
if (pathList == null) {
if (keyPredicates == null) {
if (collectionTypeFilter != null) {
// TODO exception Type filters are not directy chainable
}
if (targetType.compatibleTo((EdmStructuralType) finalType)) {
collectionTypeFilter = targetType;
finalType = targetType;
} else {
// TODO throw exception
}
} else {
if (singleTypeFilter != null) {
// TODO exception Type filters are not directy chainable
}
if (targetType.compatibleTo((EdmStructuralType) finalType)) {
singleTypeFilter = targetType;
finalType = targetType;
} else {
// TODO throw exception
}
}
} else {
PathListItem last = pathList.get(pathList.size() - 1);
if (targetType.compatibleTo(last.finalType)) {
last.finalType = targetType;
}
}
return this;
}
public UriPathInfoImpl addProperty(EdmProperty property) {
if (pathList == null) {
pathList = new ArrayList<PathListItem>();
}
PathListItem newItem = new PathListItem();
newItem.property = property;
newItem.initialType = property.getType();
newItem.finalType = property.getType();
newItem.isCollection = property.isCollection();
pathList.add(newItem);
this.finalType = newItem.finalType;
this.isCollection = newItem.isCollection;
return this;
}
public UriPathInfoImpl addNavigationProperty(EdmNavigationProperty property) {
if (pathList == null) {
pathList = new ArrayList<PathListItem>();
}
PathListItem newItem = new PathListItem();
newItem.property = property;
newItem.initialType = property.getType();
newItem.finalType = property.getType();
newItem.isCollection = property.isCollection();
pathList.add(newItem);
this.finalType = newItem.finalType;
this.isCollection = newItem.isCollection;
return this;
}
public int getPropertyCount() {
return pathList.size();
}
public EdmElement getProperty(int index) {
return pathList.get(index).property;
}
public UriPathInfoImpl setCollection(boolean isCollection) {
this.isCollection = isCollection;
return this;
}
@Override
public boolean isCollection() {
return isCollection;
}
public void setCollection(final boolean isCollection) {
this.isCollection = isCollection;
}
public EdmEntityType getTargetType() {
return targetType;
}
public void setTargetType(final EdmEntityType targetType) {
this.targetType = targetType;
}
}

View File

@ -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.odata4.producer.core.uri;
import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
public class UriPathInfoNavEntitySet extends UriPathInfoImpl {
private EdmNavigationProperty sourceNavigationProperty;
public UriPathInfoNavEntitySet() {
this.setKind(UriPathInfoKind.navEntitySet);
}
public UriPathInfoNavEntitySet addSourceNavigationProperty(EdmNavigationProperty sourceNavigationProperty) {
this.sourceNavigationProperty = sourceNavigationProperty;
this.setType(sourceNavigationProperty.getType());
return this;
}
}

View File

@ -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.odata4.producer.core.uri;
import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
public class UriPathInfoSingletonImpl extends UriPathInfoImpl {
private EdmSingleton singleton;
public UriPathInfoSingletonImpl() {
this.setKind(UriPathInfoKind.singleton);
}
public UriPathInfoSingletonImpl setSingleton(EdmSingleton singleton) {
this.singleton = singleton;
this.setType(singleton.getEntityType());
return this;
}
}

View File

@ -40,9 +40,9 @@ import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.Interval;
import org.apache.olingo.producer.core.uri.antlr.UriLexer;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser;
import org.apache.olingo.producer.core.uri.antlr.UriParserParser.OdataRelativeUriEOFContext;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.OdataRelativeUriEOFContext;
/**
* @author d039346
@ -221,7 +221,7 @@ public class ParserValidator {
parser.addParseListener(new TokenWriter());
}
// write always a error message in case of syntax errors
parser.addErrorListener(new TraceErrorHandler<Object>());
//parser.addErrorListener(new TestErrorHandler<Object>());
// check error message if whether they are allowed or not
parser.addErrorListener(new ErrorCollector(this));
@ -229,7 +229,7 @@ public class ParserValidator {
parser.setErrorHandler(new BailErrorStrategy());
// User the faster LL parsing
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
if (logLevel > 1) {
System.out.println("Step 1 (LL)");
}
@ -252,7 +252,7 @@ public class ParserValidator {
}
// write always a error message in case of syntax errors
parser.addErrorListener(new TraceErrorHandler<Object>());
parser.addErrorListener(new TestErrorHandler<Object>());
// check error message if whether they are allowed or not
parser.addErrorListener(new ErrorCollector(this));
@ -260,7 +260,7 @@ public class ParserValidator {
parser.setErrorHandler(new DefaultErrorStrategy());
// User the slower SLL parsing
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
if (logLevel > 1) {
System.out.println("Step 2 (SLL)");

View File

@ -0,0 +1,56 @@
/*******************************************************************************
* 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.odata4.producer.core.testutil;
import java.util.Collections;
import java.util.List;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
public class TestErrorHandler<T> extends BaseErrorListener {
@Override
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol,
final int line, final int charPositionInLine, final String msg, final RecognitionException e) {
System.err.println("-");
// check also http://stackoverflow.com/questions/14747952/ll-exact-ambig-detection-interpetation
List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
Collections.reverse(stack);
System.err.println("rule stack: " + stack);
if (e != null && e.getOffendingToken() != null) {
// String lexerTokenName =TestSuiteLexer.tokenNames[e.getOffendingToken().getType()];
String lexerTokenName = "";
try {
lexerTokenName = UriLexer.tokenNames[e.getOffendingToken().getType()];
} catch (ArrayIndexOutOfBoundsException es) {
lexerTokenName = "token error";
}
System.err.println("line " + line + ":" + charPositionInLine + " at " +
offendingSymbol + "/" + lexerTokenName + ": " + msg);
} else {
System.err.println("line " + line + ":" + charPositionInLine + " at " + offendingSymbol + ": " + msg);
}
}
}

View File

@ -34,7 +34,7 @@ import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.dfa.DFA;
import org.apache.olingo.producer.core.uri.antlr.UriLexer;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
public class TokenValidator {
private List<? extends Token> tokens = null;
@ -56,6 +56,7 @@ public class TokenValidator {
first();
exFirst();
logLevel = 0;
return this;
}

View File

@ -25,7 +25,7 @@ import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.apache.olingo.producer.core.uri.antlr.UriLexer;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
public class TraceErrorHandler<T> extends BaseErrorListener {
@Override

View File

@ -20,70 +20,184 @@ package org.apache.olingo.odata4.producer.core.testutil;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.List;
import org.apache.olingo.odata4.commons.api.edm.Edm;
import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
import org.apache.olingo.odata4.commons.api.edm.EdmElement;
import org.apache.olingo.odata4.commons.api.edm.EdmType;
import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
import org.apache.olingo.odata4.producer.core.uri.UriInfoImpl;
import org.apache.olingo.odata4.producer.core.uri.UriInfoImplPath;
import org.apache.olingo.odata4.producer.core.uri.UriKeyPredicateList;
import org.apache.olingo.odata4.producer.core.uri.UriParserException;
import org.apache.olingo.odata4.producer.core.uri.UriParserImpl;
import org.apache.olingo.odata4.producer.core.uri.UriPathInfoImpl;
import org.apache.olingo.odata4.producer.core.uri.UriPathInfoEntitySetImpl;
public class UriResourcePathValidator {
UriInfoImpl uriInfo = null;
UriPathInfoImpl uriPathInfo = null; // last
private Edm edm;
private UriInfoImpl uriInfo = null;
private UriPathInfoImpl uriPathInfo = null;
public UriResourcePathValidator setEdm(final Edm edm) {
this.edm = edm;
return this;
}
public UriResourcePathValidator run(final String uri) {
uriInfo = parseUri(uri);
last();
public UriResourcePathValidator run(String uri) {
try {
uriInfo = new UriParserImpl(edm).ParseUri(uri);
} catch (UriParserException e) {
fail("Exception occured");
}
uriPathInfo = null;
if (uriInfo instanceof UriInfoImplPath) {
last();
}
return this;
}
public UriResourcePathValidator isUriPathInfoKind(final UriPathInfoKind infoType) {
public UriResourcePathValidator isUriPathInfoKind(UriPathInfoKind infoType) {
assertNotNull(uriPathInfo);
assertEquals(infoType, uriPathInfo.getKind());
return this;
}
private UriInfoImpl parseUri(final String uri) {
UriParserImpl reader = new UriParserImpl();
UriInfoImpl uriInfo = reader.readUri(uri, edm);
return uriInfo;
}
public UriResourcePathValidator last() {
// TODO implement
// uriPathInfo = uriInfo.getLastUriPathInfo();
if (uriInfo instanceof UriInfoImplPath) {
uriPathInfo = ((UriInfoImplPath) uriInfo).getLastUriPathInfo();
} else {
fail("UriInfo not instanceof UriInfoImplPath");
}
return this;
}
public UriResourcePathValidator at(final int index) {
try {
// uriPathInfo = uriInfo.getUriPathInfo(index);
} catch (IndexOutOfBoundsException ex) {
uriPathInfo = null;
public UriResourcePathValidator at(int index) {
if (uriInfo instanceof UriInfoImplPath) {
try {
uriPathInfo = ((UriInfoImplPath) uriInfo).getUriPathInfo(index);
} catch (IndexOutOfBoundsException ex) {
uriPathInfo = null;
}
} else {
fail("UriInfo not instanceof UriInfoImplPath");
}
return this;
}
public UriResourcePathValidator first() {
try {
// uriPathInfo = uriInfo.getUriPathInfo(0);
} catch (IndexOutOfBoundsException ex) {
uriPathInfo = null;
if (uriInfo instanceof UriInfoImplPath) {
try {
uriPathInfo = ((UriInfoImplPath) uriInfo).getUriPathInfo(0);
} catch (IndexOutOfBoundsException ex) {
uriPathInfo = null;
}
} else {
fail("UriInfo not instanceof UriInfoImplPath");
}
return this;
}
/*
* blic void isKind(UriInfoKind batch) {
* // TODO assertEquals(batch, uriInfo.getKind());
* }
*/
public UriResourcePathValidator isKeyPredicate(int index, String name, String value) {
if (uriPathInfo instanceof UriPathInfoEntitySetImpl) {
UriPathInfoEntitySetImpl info = (UriPathInfoEntitySetImpl) uriPathInfo;
UriKeyPredicateList keyPredicates = info.getKeyPredicates();
assertEquals(name, keyPredicates.getName(index));
assertEquals(value, keyPredicates.getValue(index));
}
return this;
}
public UriResourcePathValidator isType(FullQualifiedName type) {
EdmType actualType = uriPathInfo.getType();
if (actualType == null ) {
fail("type information not set");
}
assertEquals(type, new FullQualifiedName(actualType.getNamespace(), actualType.getName()));
return this;
}
public UriResourcePathValidator isCollection(boolean isCollection) {
EdmType actualType = uriPathInfo.getType();
if (actualType == null ) {
fail("type information not set");
}
assertEquals(isCollection, uriPathInfo.isCollection());
return this;
}
public UriResourcePathValidator isInitialType(FullQualifiedName type) {
EdmType actualType = uriPathInfo.getInitialType();
if (actualType == null ) {
fail("type information not set");
}
assertEquals(type, new FullQualifiedName(actualType.getNamespace(), actualType.getName()));
return this;
}
public void isKind(final UriInfoKind batch) {
assertEquals(batch, uriInfo.getKind());
public UriResourcePathValidator isProperties(List<String> asList) {
assertNotNull(uriPathInfo);
int index = 0;
while (index < asList.size()) {
String propertyName = uriPathInfo.getProperty(index).getName();
assertEquals(asList.get(index), propertyName);
index++;
}
return this;
}
public void isKind(UriInfoKind kind) {
assertEquals(kind, uriInfo.getKind());
}
public UriResourcePathValidator isProperty(int index, String name, FullQualifiedName type) {
if ( index >= uriPathInfo.getPropertyCount()) {
fail("not enougth properties in pathinfo found");
}
EdmElement property = uriPathInfo.getProperty(index);
assertEquals(name, property.getName());
assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName()));
return this;
}
}

View File

@ -16,10 +16,11 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.producer.core.uri.antlr;
package org.apache.olingo.odata4.producer.core.uri.antlr;
import org.antlr.v4.runtime.Lexer;
import org.apache.olingo.odata4.producer.core.testutil.TokenValidator;
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
import org.junit.Test;
public class TestLexer {
@ -46,8 +47,11 @@ public class TestLexer {
@Test
public void test() {
test.globalMode(Lexer.DEFAULT_MODE);
test.run("ODI?$filter=geo.distance(geometry'SRID=0;Point(142.1 64.1)',geometry'SRID=0;Point(142.1 64.1)')");
test.globalMode(UriLexer.DEFAULT_MODE);
//test.run("ODI?$filter=geo.distance(geometry'SRID=0;Point(142.1 64.1)',geometry'SRID=0;Point(142.1 64.1)')");
// test.log(1).run("$filter='ABC'").isText("ABC").isType(UriLexer.STRING);
// test.log(1).run("ODI?$filter=1 add 2 mul 3");
// test.log(1).run("1 + 2 + 3");
@ -151,104 +155,106 @@ public class TestLexer {
}
/*
* // ;------------------------------------------------------------------------------
* // ; 5. JSON format for function parameters
* // ;------------------------------------------------------------------------------
*
* @Test
* public void testQueryJSON_and_otheres() {
* // QUOTATION_MARK
* test.run("\"").isText("\"").isType(UriLexer.QUOTATION_MARK);
* test.run("%22").isText("%22").isType(UriLexer.QUOTATION_MARK);
*
* // Lexer rule QCHAR_UNESCAPED
* test.run("\"abc\"").isText("\"abc\"").isType(UriLexer.STRING_IN_JSON);
*
* // Lexer rule QCHAR_JSON_SPECIAL
* test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
*
* // Lexer rule CHAR_IN_JSON
* test.run("\"" + cQCHAR_UNESCAPED + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
*
* // Lexer rule ESCAPE CHAR_IN_JSON
* test.run("\"" + cESCAPE + cQUOTATION_MARK + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + cESCAPE + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "/" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "%2F" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "b" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "f" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "n" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "r" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "t" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "u12AB" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* }
*
* // ;------------------------------------------------------------------------------
* // ; 6. Names and identifiers
* // ;------------------------------------------------------------------------------
*
* @Test
* public void testNamesAndIdentifiers() {
*
* test.run("Binary").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Boolean").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Byte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Date").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("DateTimeOffset").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Decimal").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Double").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Duration").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Guid").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Int16").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Int32").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Int64").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("SByte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Single").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Stream").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("String").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("TimeOfDay").isInput().isType(UriLexer.PRIMITIVETYPENAME);
*
* test.run("Geography").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Geometry").isInput().isType(UriLexer.PRIMITIVETYPENAME);
*
* String g = "Geography";
* test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
*
* g = "Geometry";
* test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
*
* }
*
* @Test
* public void testNameClaches() {
* -- test.run("Collection").isInput().isType(UriLexer.COLLECTION_CS_FIX);
* test.run("LineString").isInput().isType(UriLexer.LINESTRING_CS_FIX);
* test.run("MultiLineString").isInput().isType(UriLexer.MULTILINESTRING_CS_FIX);
* test.run("MultiPoint").isInput().isType(UriLexer.MULTIPOINT_CS_FIX);
* test.run("MultiPolygon").isInput().isType(UriLexer.MULTIPOLYGON_CS_FIX);
* test.run("Point").isInput().isType(UriLexer.POINT_CS_FIX);
* test.run("Polygon").isInput().isType(UriLexer.POLYGON_CS_FIX);
* test.run("Srid").isInput().isType(UriLexer.SRID_CS);--
* }
*/
// ;------------------------------------------------------------------------------
// ; 5. JSON format for function parameters
// ;------------------------------------------------------------------------------
@Test
public void testQueryJSON_and_otheres() {
// QUOTATION_MARK
//test.run("\"").isText("\"").isType(UriLexer.QUOTATION_MARK);
//test.run("%22").isText("%22").isType(UriLexer.QUOTATION_MARK);
// Lexer rule QCHAR_UNESCAPED
test.run("\"abc\"").isText("\"abc\"").isType(UriLexer.STRING_IN_JSON);
// Lexer rule QCHAR_JSON_SPECIAL
/*
test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
// Lexer rule CHAR_IN_JSON
test.run("\"" + cQCHAR_UNESCAPED + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
// Lexer rule ESCAPE CHAR_IN_JSON
test.run("\"" + cESCAPE + cQUOTATION_MARK + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cESCAPE + cESCAPE + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cESCAPE + "/" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cESCAPE + "%2F" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cESCAPE + "b" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cESCAPE + "f" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cESCAPE + "n" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cESCAPE + "r" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cESCAPE + "t" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
test.run("\"" + cESCAPE + "u12AB" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
*/
}
// ;------------------------------------------------------------------------------
// ; 6. Names and identifiers
// ;------------------------------------------------------------------------------
@Test
public void testNamesAndIdentifiers() {
/*
test.run("Binary").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Boolean").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Byte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Date").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("DateTimeOffset").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Decimal").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Double").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Duration").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Guid").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Int16").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Int32").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Int64").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("SByte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Single").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Stream").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("String").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("TimeOfDay").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Geography").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run("Geometry").isInput().isType(UriLexer.PRIMITIVETYPENAME);
String g = "Geography";
test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
g = "Geometry";
test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
*/
}
@Test
public void testNameClaches() {
/*test.run("Collection").isInput().isType(UriLexer.COLLECTION_CS_FIX);
test.run("LineString").isInput().isType(UriLexer.LINESTRING_CS_FIX);
test.run("MultiLineString").isInput().isType(UriLexer.MULTILINESTRING_CS_FIX);
test.run("MultiPoint").isInput().isType(UriLexer.MULTIPOINT_CS_FIX);
test.run("MultiPolygon").isInput().isType(UriLexer.MULTIPOLYGON_CS_FIX);
test.run("Point").isInput().isType(UriLexer.POINT_CS_FIX);
test.run("Polygon").isInput().isType(UriLexer.POLYGON_CS_FIX);
test.run("Srid").isInput().isType(UriLexer.SRID_CS);*/
}
// ;------------------------------------------------------------------------------
// ; 7. Literal Data Values
// ;------------------------------------------------------------------------------
@ -299,22 +305,21 @@ public class TestLexer {
test.run("INF").isInput().isType(UriLexer.NANINFINITY);
// Lexer rule GUID
test.run("guid'1234ABCD-12AB-23CD-45EF-123456780ABC'").isInput().isType(UriLexer.GUID);
test.run("GuId'1234ABCD-12AB-23CD-45EF-123456780ABC'").isInput().isType(UriLexer.GUID);
test.run("1234ABCD-12AB-23CD-45EF-123456780ABC").isInput().isType(UriLexer.GUID);
test.run("1234ABCD-12AB-23CD-45EF-123456780ABC").isInput().isType(UriLexer.GUID);
// Lexer rule DATE
test.run("date'2013-11-15'").isInput().isType(UriLexer.DATE);
test.run("DaTe'2013-11-15'").isInput().isType(UriLexer.DATE);
test.run("2013-11-15").isInput().isType(UriLexer.DATE);
// Lexer rule DATETIMEOFFSET
test.run("datetimeoffset'2013-11-15T13:35Z'").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("datetimeoffset'2013-11-15T13:35:10Z'").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("datetimeoffset'2013-11-15T13:35:10.1234Z'").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("2013-11-15T13:35Z").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("2013-11-15T13:35:10Z").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("2013-11-15T13:35:10.1234Z").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("datetimeoffset'2013-11-15T13:35:10.1234+01:30'").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("datetimeoffset'2013-11-15T13:35:10.1234-01:12'").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("2013-11-15T13:35:10.1234+01:30").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("2013-11-15T13:35:10.1234-01:12").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("DaTeTiMeOfFsEt'2013-11-15T13:35Z'").isInput().isType(UriLexer.DATETIMEOFFSET);
test.run("2013-11-15T13:35Z").isInput().isType(UriLexer.DATETIMEOFFSET);
// Lexer rule DURATION
test.run("duration'PT67S'").isInput().isType(UriLexer.DURATION);
@ -347,11 +352,11 @@ public class TestLexer {
test.run("DuRaTiOn'P3DT4H5M67.89S'").isInput().isType(UriLexer.DURATION);
test.run("DuRaTiOn'-P3DT4H5M67.89S'").isInput().isType(UriLexer.DURATION);
test.run("timeofday'20:00'").isInput().isType(UriLexer.TIMEOFDAY);
test.run("timeofday'20:15:01'").isInput().isType(UriLexer.TIMEOFDAY);
test.run("timeofday'20:15:01.02'").isInput().isType(UriLexer.TIMEOFDAY);
test.run("20:00").isInput().isType(UriLexer.TIMEOFDAY);
test.run("20:15:01").isInput().isType(UriLexer.TIMEOFDAY);
test.run("20:15:01.02").isInput().isType(UriLexer.TIMEOFDAY);
test.run("timeofday'20:15:01.02'").isInput().isType(UriLexer.TIMEOFDAY);
test.run("20:15:01.02").isInput().isType(UriLexer.TIMEOFDAY);
// String
test.run("'ABC'").isText("'ABC'").isType(UriLexer.STRING);

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.producer.core.uri.antlr;
package org.apache.olingo.odata4.producer.core.uri.antlr;
import org.apache.olingo.odata4.producer.core.testutil.ParserValidator;
import org.junit.Test;
@ -40,6 +40,15 @@ public class TestParser {
@Test
public void test() {
test.log(2).aAM().aFC().aCS().run("ODI?$filter=(1) mul 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr("
+ "commonExpr(( commonExpr(primitiveLiteral(1)) )) "
+ "mul "
+ "commonExpr(primitiveLiteral(2)))))))) <EOF>)");
// test.log(2).run("ESTwoKeyTwoPrim(PropertyInt16=1,PropertyString='ABC')");
/*
* test.log(2).run("ODI?$filter=geo.distance("+
* "geometry'SRID=0;Point(142.1 64.1)',geometry'SRID=0;Point(142.1 64.1)')")
@ -123,67 +132,67 @@ public class TestParser {
test.run("ODI(1)")
.isText(
"odataRelativeUriEOF(odataRelativeUri(resourcePath(pathSegments(pathSegment("
+ "odataIdentifier(ODI) nameValueOptList(valueOnly(( primitiveLiteral(1) ))))))) <EOF>)");
+ "odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )))))) <EOF>)");
test.run("ODI('ABC')")
.isText("odataRelativeUriEOF(odataRelativeUri(resourcePath(pathSegments(pathSegment("
+ "odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(string('ABC')) ))))))) <EOF>)");
+ "odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(string('ABC'))) )))))) <EOF>)");
test.run("ODI(K1=1)")
.isText("odataRelativeUriEOF(odataRelativeUri(resourcePath(pathSegments(pathSegment("
+ "odataIdentifier(ODI) "
+ "nameValueOptList(nameValueList(( nameValuePair(odataIdentifier(K1) = "
+ "primitiveLiteral(1)) ))))))) <EOF>)");
+ "nameValueOptList(( nameValueList(nameValuePair(odataIdentifier(K1) = "
+ "primitiveLiteral(1))) )))))) <EOF>)");
test.run("ODI(K1='ABC')")
.isText(
"odataRelativeUriEOF(odataRelativeUri(resourcePath(pathSegments(pathSegment("
+ "odataIdentifier(ODI) "
+ "nameValueOptList(nameValueList(( nameValuePair(odataIdentifier(K1) = "
+ "primitiveLiteral(string('ABC'))) ))))))) <EOF>)");
+ "nameValueOptList(( nameValueList(nameValuePair(odataIdentifier(K1) = "
+ "primitiveLiteral(string('ABC')))) )))))) <EOF>)");
test.run("ODI(K1='ABC',K2=123)")
.isText(
"odataRelativeUriEOF(odataRelativeUri(resourcePath(pathSegments(pathSegment("
+ "odataIdentifier(ODI) nameValueOptList(nameValueList(( "
+ "odataIdentifier(ODI) nameValueOptList(( nameValueList("
+ "nameValuePair(odataIdentifier(K1) = primitiveLiteral(string('ABC'))) , "
+ "nameValuePair(odataIdentifier(K2) = primitiveLiteral(123)) ))))))) <EOF>)");
+ "nameValuePair(odataIdentifier(K2) = primitiveLiteral(123))) )))))) <EOF>)");
test.run("ODI(K1=1)(P1=1)")
.isText(
"odataRelativeUriEOF(odataRelativeUri(resourcePath(pathSegments(pathSegment("
+ "odataIdentifier(ODI) nameValueOptList(nameValueList(( "
+ "nameValuePair(odataIdentifier(K1) = primitiveLiteral(1)) ))) nameValueOptList(nameValueList(( "
+ "nameValuePair(odataIdentifier(P1) = primitiveLiteral(1)) ))))))) <EOF>)");
+ "odataIdentifier(ODI) nameValueOptList(( nameValueList("
+ "nameValuePair(odataIdentifier(K1) = primitiveLiteral(1))) )) nameValueOptList(( nameValueList("
+ "nameValuePair(odataIdentifier(P1) = primitiveLiteral(1))) )))))) <EOF>)");
test.run("ODI(K1='ABC',K2=123)(P1='ABC',P2=123)")
.isText(
"odataRelativeUriEOF(odataRelativeUri(resourcePath(pathSegments(pathSegment("
+ "odataIdentifier(ODI) nameValueOptList(nameValueList(( "
+ "odataIdentifier(ODI) nameValueOptList(( nameValueList("
+ "nameValuePair(odataIdentifier(K1) = primitiveLiteral(string('ABC'))) , "
+ "nameValuePair(odataIdentifier(K2) = primitiveLiteral(123)) ))) "
+ "nameValueOptList(nameValueList(( "
+ "nameValuePair(odataIdentifier(K2) = primitiveLiteral(123))) )) nameValueOptList(( nameValueList("
+ "nameValuePair(odataIdentifier(P1) = primitiveLiteral(string('ABC'))) , "
+ "nameValuePair(odataIdentifier(P2) = primitiveLiteral(123)) ))))))) <EOF>)");
+ "nameValuePair(odataIdentifier(P2) = primitiveLiteral(123))) )))))) <EOF>)");
test.run("NS.ODI(K1='ABC',K2=123)(P1='ABC',P2=123)")
.isText(
"odataRelativeUriEOF(odataRelativeUri(resourcePath(pathSegments(pathSegment("
+ "namespace(odataIdentifier(NS) .) "
+ "odataIdentifier(ODI) nameValueOptList(nameValueList(( "
+ "odataIdentifier(ODI) nameValueOptList(( nameValueList("
+ "nameValuePair(odataIdentifier(K1) = primitiveLiteral(string('ABC'))) , "
+ "nameValuePair(odataIdentifier(K2) = primitiveLiteral(123)) ))) "
+ "nameValueOptList(nameValueList(( "
+ "nameValuePair(odataIdentifier(K2) = primitiveLiteral(123))) )) "
+ "nameValueOptList(( nameValueList("
+ "nameValuePair(odataIdentifier(P1) = primitiveLiteral(string('ABC'))) , "
+ "nameValuePair(odataIdentifier(P2) = primitiveLiteral(123)) ))))))) <EOF>)");
+ "nameValuePair(odataIdentifier(P2) = primitiveLiteral(123))) )))))) <EOF>)");
test.run("ODI(K1=@ABC)").isText("odataRelativeUriEOF(odataRelativeUri(resourcePath(pathSegments("
+ "pathSegment(odataIdentifier(ODI) nameValueOptList(nameValueList(( "
+ "nameValuePair(odataIdentifier(K1) = @ odataIdentifier(ABC)) ))))))) <EOF>)");
test.run("ODI(K1=@ABC)").isText("odataRelativeUriEOF(odataRelativeUri(resourcePath("
+ "pathSegments(pathSegment(odataIdentifier(ODI) nameValueOptList(( nameValueList("
+ "nameValuePair(odataIdentifier(K1) = @ odataIdentifier(ABC))) )))))) <EOF>)");
test.run("ODI(K1=1,K2=@ABC)").isText("odataRelativeUriEOF(odataRelativeUri(resourcePath("
+ "pathSegments(pathSegment(odataIdentifier(ODI) nameValueOptList(nameValueList(( "
+ "pathSegments(pathSegment(odataIdentifier(ODI) nameValueOptList(( nameValueList("
+ "nameValuePair(odataIdentifier(K1) = primitiveLiteral(1)) , "
+ "nameValuePair(odataIdentifier(K2) = @ odataIdentifier(ABC)) ))))))) <EOF>)");
+ "nameValuePair(odataIdentifier(K2) = @ odataIdentifier(ABC))) )))))) <EOF>)");
}
@ -400,7 +409,7 @@ public class TestParser {
+ "memberExpr(pathSegments(pathSegment(odataIdentifier(ODI))))) desc) , "
+ "orderbyItem(commonExpr(memberExpr(pathSegments(pathSegment(odataIdentifier(ODI))))) asc)))))) <EOF>)");
test.aFC().aCS().run("ODI?$orderby=3 add 4,ODI asc").isText("odataRelativeUriEOF(odataRelativeUri("
test.aFC().aAM().aCS().run("ODI?$orderby=3 add 4,ODI asc").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "orderby($orderby = "
@ -423,19 +432,19 @@ public class TestParser {
+ "systemQueryOption(search("
+ "$search searchSpecialToken(= searchExpr(NOT searchExpr(searchWord(abc))))))))) <EOF>)");
test.aFC().aCS().run("ODI?$search=abc abc").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$search=abc abc").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions(queryOption("
+ "systemQueryOption(search("
+ "$search searchSpecialToken(= searchExpr(searchExpr(searchWord(abc)) s"
+ "earchExpr(searchWord(abc))))))))) <EOF>)");
test.aFC().aCS().run("ODI?$search=abc AND abc").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$search=abc AND abc").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions(queryOption("
+ "systemQueryOption(search("
+ "$search searchSpecialToken(= searchExpr(searchExpr(searchWord(abc)) AND "
+ "searchExpr(searchWord(abc))))))))) <EOF>)");
test.aFC().aCS().run("ODI?$search=abc OR abc").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$search=abc OR abc").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions(queryOption("
+ "systemQueryOption(search($search searchSpecialToken(= searchExpr(searchExpr(searchWord(abc)) OR "
+ "searchExpr(searchWord(abc))))))))) <EOF>)");
@ -576,35 +585,35 @@ public class TestParser {
+ "queryOption(systemQueryOption(filter($filter = commonExpr("
+ "primitiveLiteral(BiNaRy'12AB'))))))) <EOF>)");
test.run("ODI?$filter=date'2013-11-15'").isText("odataRelativeUriEOF(odataRelativeUri("
test.run("ODI?$filter=2013-11-15").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption(filter($filter = commonExpr("
+ "primitiveLiteral(date'2013-11-15'))))))) <EOF>)");
+ "primitiveLiteral(2013-11-15))))))) <EOF>)");
test.run("ODI?$filter=datetimeoffset'2013-11-15T13:35Z'").isText("odataRelativeUriEOF(odataRelativeUri("
test.run("ODI?$filter=2013-11-15T13:35Z").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption(filter($filter = commonExpr("
+ "primitiveLiteral(datetimeoffset'2013-11-15T13:35Z'))))))) <EOF>)");
+ "primitiveLiteral(2013-11-15T13:35Z))))))) <EOF>)");
test.run("ODI?$filter=duration'PT67S'").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption(filter($filter = commonExpr("
+ "primitiveLiteral(duration'PT67S'))))))) <EOF>)");
test.run("ODI?$filter=guid'1234ABCD-12AB-23CD-45EF-123456780ABC'").isText("odataRelativeUriEOF(odataRelativeUri("
test.run("ODI?$filter=1234ABCD-12AB-23CD-45EF-123456780ABC").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption(filter($filter = commonExpr("
+ "primitiveLiteral(guid'1234ABCD-12AB-23CD-45EF-123456780ABC'))))))) <EOF>)");
+ "primitiveLiteral(1234ABCD-12AB-23CD-45EF-123456780ABC))))))) <EOF>)");
test.run("ODI?$filter='ABC'").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption(filter($filter = commonExpr("
+ "primitiveLiteral(string('ABC')))))))) <EOF>)");
test.run("ODI?$filter=timeofday'20:00'").isText("odataRelativeUriEOF(odataRelativeUri("
test.run("ODI?$filter=20:00").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption(filter($filter = commonExpr("
+ "primitiveLiteral(timeofday'20:00'))))))) <EOF>)");
+ "primitiveLiteral(20:00))))))) <EOF>)");
// Test enum
test.run("ODI?$filter=NS.ODI'1'").isText("odataRelativeUriEOF(odataRelativeUri("
@ -786,7 +795,7 @@ public class TestParser {
// Parsing expression required in some cases a FullContextParsing and a report of a ContextSensitivity is fine
// Test commonExpr - parenthesis
test.aFC().aCS().run("ODI?$filter=(1) mul 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=(1) mul 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr("
@ -794,17 +803,17 @@ public class TestParser {
+ "mul "
+ "commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=((((1)))) mul 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=((((1)))) mul 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(( commonExpr(( commonExpr(( commonExpr(( commonExpr("
+ "primitiveLiteral(1)) )) )) )) )) "
+ "mul commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=(1 add 2)").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=(1 add 2)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption(filter($filter = commonExpr(( commonExpr(commonExpr(primitiveLiteral(1)) "
+ "add commonExpr(primitiveLiteral(2))) ))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=1 mul (2 add 3)").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 mul (2 add 3)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption(filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "mul commonExpr(( commonExpr(commonExpr(primitiveLiteral(2)) "
@ -926,17 +935,17 @@ public class TestParser {
+ "filter($filter = commonExpr(methodCallExpr("
+ "totalsecondsMethodCallExpr(totalseconds( commonExpr(primitiveLiteral(duration'PT67S')) ))))))))) <EOF>)");
test.run("ODI?$filter=date(datetimeoffset'2013-11-15T13:35Z')").isText("odataRelativeUriEOF(odataRelativeUri("
test.run("ODI?$filter=date(2013-11-15T13:35Z)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(methodCallExpr("
+ "dateMethodCallExpr(date( commonExpr(primitiveLiteral(datetimeoffset'2013-11-15T13:35Z')) ))))))))) <EOF>)");
+ "dateMethodCallExpr(date( commonExpr(primitiveLiteral(2013-11-15T13:35Z)) ))))))))) <EOF>)");
test.run("ODI?$filter=time(datetimeoffset'2013-11-15T13:35Z')").isText("odataRelativeUriEOF(odataRelativeUri("
test.run("ODI?$filter=time(2013-11-15T13:35Z)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(methodCallExpr("
+ "timeMethodCallExpr(time( commonExpr(primitiveLiteral(datetimeoffset'2013-11-15T13:35Z')) ))))))))) <EOF>)");
+ "timeMethodCallExpr(time( commonExpr(primitiveLiteral(2013-11-15T13:35Z)) ))))))))) <EOF>)");
test.run("ODI?$filter=round(12.34)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
@ -979,12 +988,12 @@ public class TestParser {
* + "LineString lineStringData(( positionLiteral(142.1 64.1) , "
* + "positionLiteral(3.14 2.78) )))) '))) ))))))))) <EOF>)");
*/
test.run("ODI?$filter=totaloffsetminutes(datetimeoffset'2013-11-15T13:35Z')")
test.run("ODI?$filter=totaloffsetminutes(2013-11-15T13:35Z)")
.isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption(filter($filter = commonExpr(methodCallExpr("
+ "totalOffsetMinutesMethodCallExpr(totaloffsetminutes( commonExpr("
+ "primitiveLiteral(datetimeoffset'2013-11-15T13:35Z')) ))))))))) <EOF>)");
+ "primitiveLiteral(2013-11-15T13:35Z)) ))))))))) <EOF>)");
test.run("ODI?$filter=mindatetime()").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
@ -1090,61 +1099,61 @@ public class TestParser {
+ "memberExpr(pathSegments(pathSegment(odataIdentifier(ODI)))))))))) <EOF>)");
// Test commonExpr - mathematical
test.aFC().aCS().run("ODI?$filter=1 mul 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 mul 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "mul commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=1 div 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 div 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "div commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=1 mod 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 mod 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "mod commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=1 add 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 add 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "add commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=1 sub 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 sub 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "sub commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=1 gt 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 gt 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "gt commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=1 ge 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 ge 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "ge commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=1 lt 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 lt 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "lt commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=1 le 2").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=1 le 2").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(1)) "
+ "le commonExpr(primitiveLiteral(2)))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=ODI isof Model.Employee").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=ODI isof Model.Employee").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(memberExpr(pathSegments(pathSegment(odataIdentifier(ODI))))) "
@ -1153,13 +1162,13 @@ public class TestParser {
+ "namespace(odataIdentifier(Model) .) "
+ "odataIdentifier(Employee))))))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=true and false").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=true and false").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(booleanNonCase(true))) "
+ "and commonExpr(primitiveLiteral(booleanNonCase(false))))))))) <EOF>)");
test.aFC().aCS().run("ODI?$filter=true or false").isText("odataRelativeUriEOF(odataRelativeUri("
test.aAM().aFC().aCS().run("ODI?$filter=true or false").isText("odataRelativeUriEOF(odataRelativeUri("
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
+ "queryOption(systemQueryOption("
+ "filter($filter = commonExpr(commonExpr(primitiveLiteral(booleanNonCase(true))) "
@ -1198,9 +1207,8 @@ public class TestParser {
test.run("$metadata#NS.ODI").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(namespace(odataIdentifier(NS) .) odataIdentifier(ODI))) <EOF>)");
test.run("$metadata#Edm.Boolean").isText("odataRelativeUriEOF("
+ "odataRelativeUri($metadata # "
+ "contextFragment(namespace(odataIdentifier(Edm) .) odataIdentifier(Boolean))) <EOF>)");
test.run("$metadata#Edm.Boolean").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(namespace(odataIdentifier(Edm) .) odataIdentifier(Boolean))) <EOF>)");
test.run("$metadata#ODI/$deletedEntity").isText("odataRelativeUriEOF("
+ "odataRelativeUri($metadata # contextFragment(odataIdentifier(ODI) / $deletedEntity)) <EOF>)");
@ -1212,64 +1220,58 @@ public class TestParser {
+ "odataRelativeUri($metadata # contextFragment(odataIdentifier(ODI) / $deletedLink)) <EOF>)");
test.run("$metadata#ODI(1)/ODI").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "/ odataIdentifier(ODI))) <EOF>)");
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )) / "
+ "odataIdentifier(ODI))) <EOF>)");
test.run("$metadata#ODI(1)/NS.ODI").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "/ namespace(odataIdentifier(NS) .) odataIdentifier(ODI))) <EOF>)");
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )) / "
+ "namespace(odataIdentifier(NS) .) odataIdentifier(ODI))) <EOF>)");
test.run("$metadata#ODI(1)/NS.ODI/ODI").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "/ namespace(odataIdentifier(NS) .) odataIdentifier(ODI) "
+ "/ odataIdentifier(ODI))) <EOF>)");
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )) / "
+ "namespace(odataIdentifier(NS) .) odataIdentifier(ODI) / odataIdentifier(ODI))) <EOF>)");
test.run("$metadata#NS.ODI(*)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(namespace(odataIdentifier(NS) .) odataIdentifier(ODI) "
+ "propertyList(( propertyListItem(*) )))) <EOF>)");
test.run("$metadata#ODI(1)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))))) <EOF>)");
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )))) "
+ "<EOF>)");
test.run("$metadata#ODI(1)/ODI").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "/ odataIdentifier(ODI))) <EOF>)");
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )) / "
+ "odataIdentifier(ODI))) <EOF>)");
test.run("$metadata#ODI(1)/NS.ODI").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "/ namespace(odataIdentifier(NS) .) odataIdentifier(ODI))) <EOF>)");
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )) / "
+ "namespace(odataIdentifier(NS) .) odataIdentifier(ODI))) <EOF>)");
test.run("$metadata#ODI(1)/NS.ODI/ODI").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "/ namespace(odataIdentifier(NS) .) odataIdentifier(ODI) / odataIdentifier(ODI))) <EOF>)");
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )) / "
+ "namespace(odataIdentifier(NS) .) odataIdentifier(ODI) / odataIdentifier(ODI))) <EOF>)");
test.run("$metadata#ODI(1)(*)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) propertyList(( propertyListItem(*) )))) <EOF>)");
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )) "
+ "propertyList(( propertyListItem(*) )))) <EOF>)");
test.run("$metadata#ODI(1)(PROP)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "$metadata # contextFragment(odataIdentifier(ODI) nameValueOptList(( valueOnly(primitiveLiteral(1)) )) "
+ "propertyList(( propertyListItem(propertyListProperty(odataIdentifier(PROP))) )))) <EOF>)");
test.run("$metadata#ODI(1)(NAVPROP+)").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "nameValueOptList(( valueOnly(primitiveLiteral(1)) )) "
+ "propertyList(( propertyListItem(propertyListProperty(odataIdentifier(NAVPROP) +)) )))) <EOF>)");
test.run("$metadata#ODI(1)(NAVPROP+(*))").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "nameValueOptList(( valueOnly(primitiveLiteral(1)) )) "
+ "propertyList(( "
+ "propertyListItem(propertyListProperty(odataIdentifier(NAVPROP) + "
+ "propertyList(( "
+ "propertyListItem(*) )))) )))) <EOF>)");
test.run("$metadata#ODI(1)(NAVPROP+(A,B,C))").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "nameValueOptList(( valueOnly(primitiveLiteral(1)) )) "
+ "propertyList(( "
+ "propertyListItem(propertyListProperty(odataIdentifier(NAVPROP) + "
+ "propertyList(( "
@ -1279,7 +1281,7 @@ public class TestParser {
test.run("$metadata#ODI(1)(NAVPROP+(A,B,C))/$delta").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "nameValueOptList(( valueOnly(primitiveLiteral(1)) )) "
+ "propertyList(( "
+ "propertyListItem(propertyListProperty(odataIdentifier(NAVPROP) + "
+ "propertyList(( "
@ -1290,7 +1292,7 @@ public class TestParser {
test.run("$metadata#ODI(1)(NAVPROP+(A,B,C))/$entity").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "nameValueOptList(( valueOnly(primitiveLiteral(1)) )) "
+ "propertyList(( "
+ "propertyListItem(propertyListProperty(odataIdentifier(NAVPROP) + "
+ "propertyList(( "
@ -1300,7 +1302,7 @@ public class TestParser {
+ "/ $entity)) <EOF>)");
test.run("$metadata#ODI(1)(NAVPROP+(A,B,C))/$delta/$entity").isText("odataRelativeUriEOF(odataRelativeUri("
+ "$metadata # contextFragment(odataIdentifier(ODI) "
+ "nameValueOptList(valueOnly(( primitiveLiteral(1) ))) "
+ "nameValueOptList(( valueOnly(primitiveLiteral(1)) )) "
+ "propertyList(( "
+ "propertyListItem(propertyListProperty(odataIdentifier(NAVPROP) + "
+ "propertyList(( "

View File

@ -0,0 +1,354 @@
/*******************************************************************************
* 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.odata4.producer.core.uri.antlr;
import java.util.Arrays;
import org.apache.olingo.odata4.commons.api.edm.Edm;
import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
import org.apache.olingo.odata4.commons.core.edm.provider.EdmProviderImpl;
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
import org.apache.olingo.odata4.producer.core.testutil.EdmTechProvider;
import org.apache.olingo.odata4.producer.core.testutil.UriResourcePathValidator;
import org.junit.Test;
public class TestUriParserImpl {
UriResourcePathValidator test = null;
Edm edm = null;
private final String PropertyString = "PropertyString='ABC'";
private final String PropertyInt16 = "PropertyInt16=1";
private final String PropertyBoolean = "PropertyBoolean=true";
private final String PropertyByte = "PropertyByte=1";
private final String PropertySByte = "PropertySByte=1";
private final String PropertyInt32 = "PropertyInt32=12";
private final String PropertyInt64 = "PropertyInt64=64";
private final String PropertyDecimal = "PropertyDecimal=12";
private final String PropertyDate = "PropertyDate=2013-09-25";
private final String PropertyDateTimeOffset = "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00";
private final String PropertyDuration = "PropertyDuration=duration'P10DT5H34M21.123456789012S'";
private final String PropertyGuid = "PropertyGuid=12345678-1234-1234-1234-123456789012";
private final String PropertyTimeOfDay = "PropertyTimeOfDay=12:34:55.123456789012";
private final String allKeys = PropertyString + "," + PropertyInt16 + "," + PropertyBoolean + "," + PropertyByte
+ "," + PropertySByte + "," + PropertyInt32 + "," + PropertyInt64 + "," + PropertyDecimal + "," + PropertyDate
+ "," + PropertyDateTimeOffset + "," + PropertyDuration + "," + PropertyGuid + "," + PropertyTimeOfDay;
public TestUriParserImpl() {
test = new UriResourcePathValidator();
edm = new EdmProviderImpl(new EdmTechProvider());
test.setEdm(edm);
}
@Test
public void test() {
test.run("ESAllKey(" + allKeys + ")")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isKeyPredicate(0, "PropertyString", "'ABC'")
.isKeyPredicate(1, "PropertyInt16", "1");
}
@Test
public void testShortUris() {
test.run("$batch").isKind(UriInfoKind.batch);
test.run("$all").isKind(UriInfoKind.all);
test.run("$crossjoin(abc)").isKind(UriInfoKind.crossjoin);
}
@Test
public void testDollarEntity() {
// TODO
}
@Test
public void testEntitySet() {
test.run("ESAllPrim")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isType(new FullQualifiedName("com.sap.odata.test1", "ETAllPrim"));
// with one key
test.run("ESAllPrim(1)")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isType(new FullQualifiedName("com.sap.odata.test1", "ETAllPrim"))
.isKeyPredicate(0, "PropertyInt16", "1");
test.run("ESAllPrim(PropertyInt16=1)")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isKeyPredicate(0, "PropertyInt16", "1");
// with two keys
test.run("ESTwoKeyTwoPrim(PropertyInt16=1, PropertyString='ABC')")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isKeyPredicate(0, "PropertyInt16", "1")
.isKeyPredicate(1, "PropertyString", "'ABC'");
// with all keys
test.run("ESAllKey(" + allKeys + ")")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isKeyPredicate(0, "PropertyString", "'ABC'")
.isKeyPredicate(1, "PropertyInt16", "1")
.isKeyPredicate(2, "PropertyBoolean", "true")
.isKeyPredicate(3, "PropertyByte", "1")
.isKeyPredicate(4, "PropertySByte", "1")
.isKeyPredicate(5, "PropertyInt32", "12")
.isKeyPredicate(6, "PropertyInt64", "64")
.isKeyPredicate(7, "PropertyDecimal", "12")
.isKeyPredicate(8, "PropertyDate", "2013-09-25")
.isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00")
.isKeyPredicate(10, "PropertyDuration", "duration'P10DT5H34M21.123456789012S'")
.isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012")
.isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012");
// with property
test.run("ESAllPrim(1)/PropertyString")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isKeyPredicate(0, "PropertyInt16", "1")
.isProperties(Arrays.asList("PropertyString"));
// with complex property
test.run("ESCompAllPrim(1)/PropertyComplex")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isKeyPredicate(0, "PropertyInt16", "1")
.isProperty(0, "PropertyComplex", EdmTechProvider.nameCTAllPrim);
// with two properties
test.run("ESCompAllPrim(1)/PropertyComplex/PropertyString")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isKeyPredicate(0, "PropertyInt16", "1")
.isProperty(0, "PropertyComplex", EdmTechProvider.nameCTAllPrim)
.isProperty(1, "PropertyString", EdmTechProvider.nameString);
}
@Test
public void testEntitySetNav() {
test.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne")
.at(0)
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isInitialType(EdmTechProvider.nameETKeyNav)
.isType(EdmTechProvider.nameETTwoKeyNav)
.isKeyPredicate(0, "PropertyInt16", "1")
.isProperty(0, "NavPropertyETTwoKeyNavOne", EdmTechProvider.nameETTwoKeyNav)
.at(1)
.isUriPathInfoKind(UriPathInfoKind.navEntitySet)
.isType(EdmTechProvider.nameETTwoKeyNav);
test.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/PropertyString")
.at(0)
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isInitialType(EdmTechProvider.nameETKeyNav)
.isType(EdmTechProvider.nameETTwoKeyNav)
.isKeyPredicate(0, "PropertyInt16", "1")
.isProperty(0, "NavPropertyETTwoKeyNavOne", EdmTechProvider.nameETTwoKeyNav)
.at(1)
.isUriPathInfoKind(UriPathInfoKind.navEntitySet)
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
.isType(EdmTechProvider.nameString)
.isProperty(0, "PropertyString", EdmTechProvider.nameString);
test.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/NavPropertyETKeyNavOne")
.at(0)
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isInitialType(EdmTechProvider.nameETKeyNav)
.isType(EdmTechProvider.nameETTwoKeyNav)
.isKeyPredicate(0, "PropertyInt16", "1")
.isProperty(0, "NavPropertyETTwoKeyNavOne", EdmTechProvider.nameETTwoKeyNav)
.at(1)
.isUriPathInfoKind(UriPathInfoKind.navEntitySet)
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
.isType(EdmTechProvider.nameETKeyNav)
.at(2)
.isUriPathInfoKind(UriPathInfoKind.navEntitySet)
.isInitialType(EdmTechProvider.nameETKeyNav)
.isType(EdmTechProvider.nameETKeyNav);
test.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/NavPropertyETKeyNavOne/PropertyString")
.at(0)
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isInitialType(EdmTechProvider.nameETKeyNav)
.isType(EdmTechProvider.nameETTwoKeyNav)
.isKeyPredicate(0, "PropertyInt16", "1")
.isProperty(0, "NavPropertyETTwoKeyNavOne", EdmTechProvider.nameETTwoKeyNav)
.at(1)
.isUriPathInfoKind(UriPathInfoKind.navEntitySet)
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
.isType(EdmTechProvider.nameETKeyNav)
.at(2)
.isUriPathInfoKind(UriPathInfoKind.navEntitySet)
.isInitialType(EdmTechProvider.nameETKeyNav)
.isType(EdmTechProvider.nameString)
.isProperty(0, "PropertyString", EdmTechProvider.nameString);
}
@Test
public void testTypeFilter() {
// test.run("ESTwoPrim");
test.run("ESTwoPrim/com.sap.odata.test1.ETBase")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isType(new FullQualifiedName("com.sap.odata.test1", "ETBase"));
test.run("ESTwoPrim/com.sap.odata.test1.ETBase/AdditionalPropertyString_5")
.isUriPathInfoKind(UriPathInfoKind.entitySet)
.isType(new FullQualifiedName("Edm", "String"))
.isProperties(Arrays.asList("AdditionalPropertyString_5"))
.isProperty(0, "AdditionalPropertyString_5", EdmTechProvider.nameString);
}
@Test
public void testSingleton() {
test.run("SI")
.isUriPathInfoKind(UriPathInfoKind.singleton)
.isType(EdmTechProvider.nameETTwoPrim);
test.run("SI/PropertyInt16")
.isUriPathInfoKind(UriPathInfoKind.singleton)
.isInitialType(EdmTechProvider.nameETTwoPrim)
.isType(EdmTechProvider.nameInt16)
.isProperty(0, "PropertyInt16", EdmTechProvider.nameInt16);
test.run("SI/com.sap.odata.test1.ETBase/AdditionalPropertyString_5")
.isUriPathInfoKind(UriPathInfoKind.singleton)
.isType(new FullQualifiedName("Edm", "String"))
.isProperties(Arrays.asList("AdditionalPropertyString_5"))
.isProperty(0, "AdditionalPropertyString_5", EdmTechProvider.nameString);
test.run("SINav/NavPropertyETKeyNavOne")
.at(0)
.isUriPathInfoKind(UriPathInfoKind.singleton)
.isType(EdmTechProvider.nameETKeyNav)
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
.isCollection(false)
.at(1)
.isType(EdmTechProvider.nameETKeyNav);
test.run("SINav/NavPropertyETKeyNavOne/PropertyInt16")
.at(0)
.isUriPathInfoKind(UriPathInfoKind.singleton)
.isType(EdmTechProvider.nameETKeyNav)
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
.isCollection(false)
.at(1)
.isInitialType(EdmTechProvider.nameETKeyNav)
.isType(EdmTechProvider.nameInt16);
test.run("SINav/NavPropertyETKeyNavMany(1)")
.at(0)
.isUriPathInfoKind(UriPathInfoKind.singleton)
.isType(EdmTechProvider.nameETKeyNav)
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
.isCollection(true)
.at(1)
.isType(EdmTechProvider.nameETKeyNav);
test.run("SINav/NavPropertyETKeyNavMany(1)/PropertyInt16")
.at(0)
.isUriPathInfoKind(UriPathInfoKind.singleton)
.isType(EdmTechProvider.nameETKeyNav)
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
.isCollection(true)
.at(1)
.isInitialType(EdmTechProvider.nameETKeyNav)
.isType(EdmTechProvider.nameInt16);
}
@Test
public void testActionImport() {
test.run("AIRTPrimParam")
.isUriPathInfoKind(UriPathInfoKind.action)
.isType(EdmTechProvider.nameString);
test.run("AIRTPrimCollParam")
.isUriPathInfoKind(UriPathInfoKind.action)
.isType(EdmTechProvider.nameString)
.isCollection(true);
test.run("AIRTETParam")
.isUriPathInfoKind(UriPathInfoKind.action)
.isType(EdmTechProvider.nameETTwoKeyTwoPrim)
.isCollection(false);
test.run("AIRTETCollAllPrimParam")
.isUriPathInfoKind(UriPathInfoKind.action)
.isType(EdmTechProvider.nameETCollAllPrim)
.isCollection(true);
test.run("AIRTETCollAllPrimParam(1)")
.isUriPathInfoKind(UriPathInfoKind.action)
.isType(EdmTechProvider.nameETCollAllPrim)
.isKeyPredicate(0, "PropertyInt16", "1")
.isCollection(false);
test.run("AIRTETCollAllPrimParam(ParameterInt16=1)")
.isUriPathInfoKind(UriPathInfoKind.action)
.isType(EdmTechProvider.nameETCollAllPrim)
.isKeyPredicate(0, "PropertyInt16", "1")
.isCollection(false);
}
/*
* //@Test
* public void testFunctionImport() {
* test.run("MaximalAge").isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.functioncall);
* }
*/
/*
* //@Test
* public void testBoundFunctions() {
*
* test.run("Employees/RefScenario.bf_entity_set_rt_entity(NonBindingParameter='1')").isUriPathInfoKind(
* UriPathInfoImpl.UriPathInfoKind.boundFunctioncall);
* test.run("Employees('1')/EmployeeName/RefScenario.bf_pprop_rt_entity_set()").isUriPathInfoKind(
* UriPathInfoImpl.UriPathInfoKind.boundFunctioncall);
* test.run("Company/RefScenario.bf_singleton_rt_entity_set()('1')").isUriPathInfoKind(
* UriPathInfoImpl.UriPathInfoKind.boundFunctioncall);
* // testUri("Company/RefScenario.bf_singleton_rt_entity_set()('1')/EmployeeName/"
* // +"RefScenario.bf_pprop_rt_entity_set()",
* // UriPathInfoImpl.UriPathInfoKind.boundFunctioncall);
* }
*/
/*
* //@Test
* public void testBoundActions() {
* test.run("Employees('1')/RefScenario.ba_entity_rt_pprop")
* .isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.boundActionImport);
* test.run("Employees('1')/EmployeeName/RefScenario.ba_pprop_rt_entity_set").isUriPathInfoKind(
* UriPathInfoImpl.UriPathInfoKind.boundActionImport);
* }
*/
/*
* //@Test
* public void testNavigationFunction() {
* test.run("Employees('1')/ne_Manager").isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.navicationProperty);
* test.run("Teams('1')/nt_Employees('1')").isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.navicationProperty);
* // testUri("Teams('1')/nt_Employees('1')/EmployeeName", UriPathInfoImpl.UriPathInfoKind.navicationProperty);
* }
*/
@Test
public void testErrors() {
//the following is wrong and must throw an error behind an Action are not () allowed
//test.run("AIRTPrimParam()");
}
}

View File

@ -1,108 +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.producer.core.uri.antlr;
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
import org.apache.olingo.odata4.producer.core.testutil.UriResourcePathValidator;
public class UriTreeReaderTest {
UriResourcePathValidator test = null;
public UriTreeReaderTest() {
test = new UriResourcePathValidator();
// test.setEdm(new EdmIm)
}
/*
* @Test
* public void testShortUris() {
* test.run("$batch").isKind(UriInfoKind.batch);
* test.run("$all").isKind(UriInfoKind.all);
* test.run("$crossjoin(abc)").isKind(UriInfoKind.crossjoin);
* }
*/
// @Test
public void testEntitySet() {
test.run("Employees").isUriPathInfoKind(UriPathInfoKind.entitySet);
test.run("Employees").isUriPathInfoKind(UriPathInfoKind.entitySet);
test.run("Employees('1')").isUriPathInfoKind(UriPathInfoKind.entitySet);
test.run("Employees(EmployeeId='1')").isUriPathInfoKind(UriPathInfoKind.entitySet);
test.run("Employees('1')/EmployeeName").isUriPathInfoKind(UriPathInfoKind.entitySet);
test.run("Employees/RefScenario.ManagerType").isUriPathInfoKind(UriPathInfoKind.entitySet);
test.run("Employees/RefScenario.ManagerType('1')").isUriPathInfoKind(UriPathInfoKind.entitySet);
test.run("Employees/Location").isUriPathInfoKind(UriPathInfoKind.entitySet);
test.run("Employees/Location/Country").isUriPathInfoKind(UriPathInfoKind.entitySet);
}
/*
* //@Test
* public void testSingleton() {
* test.run("Company").isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.singleton);
* }
*/
/*
* //@Test
* public void testActionImport() {
* test.run("actionImport1").isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.actionImport);
* }
*/
/*
* //@Test
* public void testFunctionImport() {
* test.run("MaximalAge").isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.functioncall);
* }
*/
/*
* //@Test
* public void testBoundFunctions() {
*
* test.run("Employees/RefScenario.bf_entity_set_rt_entity(NonBindingParameter='1')").isUriPathInfoKind(
* UriPathInfoImpl.UriPathInfoKind.boundFunctioncall);
* test.run("Employees('1')/EmployeeName/RefScenario.bf_pprop_rt_entity_set()").isUriPathInfoKind(
* UriPathInfoImpl.UriPathInfoKind.boundFunctioncall);
* test.run("Company/RefScenario.bf_singleton_rt_entity_set()('1')").isUriPathInfoKind(
* UriPathInfoImpl.UriPathInfoKind.boundFunctioncall);
* // testUri("Company/RefScenario.bf_singleton_rt_entity_set()('1')/EmployeeName/"
* // +"RefScenario.bf_pprop_rt_entity_set()",
* // UriPathInfoImpl.UriPathInfoKind.boundFunctioncall);
* }
*/
/*
* //@Test
* public void testBoundActions() {
* test.run("Employees('1')/RefScenario.ba_entity_rt_pprop")
* .isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.boundActionImport);
* test.run("Employees('1')/EmployeeName/RefScenario.ba_pprop_rt_entity_set").isUriPathInfoKind(
* UriPathInfoImpl.UriPathInfoKind.boundActionImport);
* }
*/
/*
* //@Test
* public void testNavigationFunction() {
* test.run("Employees('1')/ne_Manager").isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.navicationProperty);
* test.run("Teams('1')/nt_Employees('1')").isUriPathInfoKind(UriPathInfoImpl.UriPathInfoKind.navicationProperty);
* // testUri("Teams('1')/nt_Employees('1')/EmployeeName", UriPathInfoImpl.UriPathInfoKind.navicationProperty);
* }
*/
}