[OLINGO-63] First draft of an uri parser with antlr
This commit is contained in:
parent
fe10bb5c76
commit
013859b74b
|
@ -57,4 +57,7 @@ public interface EdmEntityContainer extends EdmNamed {
|
|||
* @return {@link EdmFunctionImport}
|
||||
*/
|
||||
EdmFunctionImport getFunctionImport(String name);
|
||||
|
||||
//TODO:evaluate
|
||||
EdmNamed getElement(String odataIdentifier);
|
||||
}
|
|
@ -35,7 +35,7 @@ public interface EdmEntityType extends EdmStructuralType {
|
|||
* Get all key properties references as list of {@link EdmKeyPropertyRef}.
|
||||
* @return collection of key properties of type List<EdmKeyPropertyRef>
|
||||
*/
|
||||
List<EdmKeyPropertyRef> getKeyPropertYRefs();
|
||||
List<EdmKeyPropertyRef> getKeyPropertyRefs();
|
||||
|
||||
/**
|
||||
* Get a key property ref by its name.
|
||||
|
|
|
@ -23,7 +23,12 @@ public interface EdmKeyPropertyRef {
|
|||
/**
|
||||
* @return name of the key predicate
|
||||
*/
|
||||
String getKeyPredicateName();
|
||||
String getKeyPropertyName();
|
||||
|
||||
/**
|
||||
* @return alias of this reference or null if not set
|
||||
*/
|
||||
String getAlias();
|
||||
|
||||
/**
|
||||
* @return path to the property
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.apache.olingo.commons.api.edm.EdmActionImport;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmNamed;
|
||||
import org.apache.olingo.commons.api.edm.EdmSingleton;
|
||||
import org.apache.olingo.commons.api.edm.helper.EntityContainerInfo;
|
||||
|
||||
|
@ -42,4 +43,9 @@ public class EdmEntityContainerImpl extends EdmNamedImpl implements EdmEntityCon
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmNamed getElement(String odataIdentifier) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class EdmEntityTypeImpl extends EdmStructuralTypeImpl implements EdmEntit
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<EdmKeyPropertyRef> getKeyPropertYRefs() {
|
||||
public List<EdmKeyPropertyRef> getKeyPropertyRefs() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*******************************************************************************
|
||||
* 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.api.uri;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
|
||||
|
||||
/**
|
||||
* Key predicate, consisting of a simple-type property and its value as String literal
|
||||
* @org.apache.olingo.odata2.DoNotImplement
|
||||
*
|
||||
*/
|
||||
public interface KeyPredicate {
|
||||
|
||||
/**
|
||||
* <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();
|
||||
|
||||
}
|
|
@ -43,6 +43,44 @@
|
|||
<artifactId>olingo-odata4-commons-core-incubating</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-runtime</artifactId>
|
||||
<version>${antlr.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<version>${antlr.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<!--<arguments><argument>-atn</argument></arguments>-->
|
||||
<listener>true</listener>
|
||||
<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>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,361 @@
|
|||
grammar Uri;
|
||||
//Naming convention
|
||||
//- Helper Rules ending with "Path" like "colNavigationPath" are expected to be used behind a
|
||||
// slash ('/') e.g. "rule : entitySetName( '/' colNavigationPath)?;"
|
||||
//- Helper Rules ending with "OnQual" like "colNavigationPathOnQual" are expected to be used behind a
|
||||
// qualified identifiere.g. "colNavigationPath : ...| qualified colNavigationPathOnQual;"
|
||||
//- Helper Rules ending with "OnCast" like "singleNavigationPathOnCast" are expected to be used behind a
|
||||
// cast to a typename e.g. "singleNavigationPathOnQual : ... | entityTypeName '/' singleNavigationPathOnCast;"
|
||||
//Decoding encoding
|
||||
//- within rule "resourcePath": special chars used in EDM.Strings must still be encoded when
|
||||
// used as tokenizer input
|
||||
// e.g. .../Employees(id='Hugo%2FMueller')/EmployeeName <-- '/' must be encodet to '%2F' in "Hugo/Mueller"
|
||||
// but it must not be encoded before the EmployeeName
|
||||
//- within rules "entityOptions"/"format"/"queryOptions":
|
||||
|
||||
options {
|
||||
language = Java;
|
||||
}
|
||||
|
||||
import UriLexerPart; //contain Lexer rules
|
||||
|
||||
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 0. URI
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
//ABNF odataUri and serviceRoot are currently not used here
|
||||
//odataUri = serviceRoot [ odataRelativeUri ]
|
||||
//
|
||||
//serviceRoot = ( "https" / "http" ) ; Note: case-insensitive
|
||||
// "://" host [ ":" port ]
|
||||
// "/" *( segment-nz "/" )
|
||||
|
||||
|
||||
|
||||
odataRelativeUri : ( '$batch' //; Note: case-sensitive!
|
||||
| '$entity' '?' entityOptions //; Note: case-sensitive!
|
||||
| '$metadata' ( '?' format )? ( FRAGMENT contextFragment )?
|
||||
| resourcePath ( '?' queryOptions )?
|
||||
) EOF;
|
||||
|
||||
odataRelativeUriA : odataRelativeUriB? EOF;
|
||||
odataRelativeUriB : '$batch' # batch //; Note: case-sensitive!
|
||||
| '$entity' '?' entityOptions # entityA //; Note: case-sensitive!
|
||||
| '$metadata' ( '?' format )? ( FRAGMENT contextFragment )? # metadata
|
||||
| resourcePath ( '?' queryOptions )? # resourcePathA
|
||||
;
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 1. Resource Path
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
resourcePath : '$all' # all
|
||||
| crossjoin #crossjoinA
|
||||
| pathSegments #pathSegmentsA
|
||||
;
|
||||
crossjoin : '$crossjoin' OPEN odataIdentifier ( COMMA odataIdentifier )* CLOSE;
|
||||
|
||||
pathSegments : pathSegment ('/' pathSegment)* constSegment?;
|
||||
|
||||
pathSegment : ns=namespace* odi=odataIdentifier fp=functionParameters? kp=keypredicates?;
|
||||
|
||||
pathOdataIdentifier : ODATAIDENTIFIER;
|
||||
|
||||
functionParameters : OPEN ( fps+=functionParameter ( COMMA fps+=functionParameter )* )? CLOSE;
|
||||
functionParameter : odi=parameterName EQ ( ali=parameterAlias | val=primitiveLiteral );
|
||||
parameterName : odataIdentifier;
|
||||
parameterAlias : AT_ODATAIDENTIFIER;
|
||||
|
||||
keypredicates : simpleKey | compoundKey;
|
||||
simpleKey : OPEN keyPropertyValue CLOSE;
|
||||
compoundKey : OPEN kvp+=keyValuePair ( COMMA kvp+=keyValuePair )* CLOSE;
|
||||
keyValuePair : odi=odataIdentifier EQ val=keyPropertyValue;
|
||||
keyPropertyValue : primitiveLiteral;
|
||||
|
||||
|
||||
constSegment : '/' (value | count | ref );
|
||||
count : COUNT;
|
||||
ref : REF;
|
||||
value : VALUE;
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 2. Query Options
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
queryOptions : queryOption ( '&' queryOption )*;
|
||||
queryOption : systemQueryOption
|
||||
| aliasAndValue
|
||||
| customQueryOption
|
||||
;
|
||||
|
||||
entityOptions : (entityOption '&' )* id ( '&' entityOption )*;
|
||||
entityOption : expand
|
||||
| format
|
||||
| select
|
||||
| customQueryOption
|
||||
;
|
||||
|
||||
id : ID;
|
||||
|
||||
systemQueryOption : expand
|
||||
| filter
|
||||
| format
|
||||
| id
|
||||
| inlinecount
|
||||
| orderby
|
||||
| search
|
||||
| select
|
||||
| skip
|
||||
| SKIPTOKEN
|
||||
| top ;
|
||||
|
||||
expand : '$expand' EQ expandItemList;
|
||||
|
||||
expandItemList : expandItem ( COMMA expandItem )*;
|
||||
|
||||
expandItem : STAR ( '/' ref | OPEN LEVELS CLOSE )?
|
||||
| expandPath expandPathExtension?;
|
||||
|
||||
expandPath : ( namespace* odataIdentifier ) ( '/' namespace* odataIdentifier )*;
|
||||
expandPathExtension : '/' ref ( OPEN expandRefOption ( SEMI expandRefOption )* CLOSE )?
|
||||
| '/' count ( OPEN expandCountOption ( SEMI expandCountOption )* CLOSE )?
|
||||
| OPEN expandOption ( SEMI expandOption )* CLOSE
|
||||
;
|
||||
expandCountOption : filter
|
||||
| search
|
||||
;
|
||||
expandRefOption : expandCountOption
|
||||
| orderby
|
||||
| skip
|
||||
| top
|
||||
| inlinecount
|
||||
;
|
||||
expandOption : expandRefOption
|
||||
| select
|
||||
| expand
|
||||
| LEVELS;
|
||||
|
||||
filter : '$filter' EQ commonExpr;
|
||||
|
||||
orderby : '$orderby' EQ orderbyItem ( COMMA orderbyItem )*;
|
||||
orderbyItem : commonExpr ( WS+ ( 'asc' | 'desc' ) )?;
|
||||
|
||||
//this is completly done in lexer grammer to avoid ambiguities with odataIdentifier and STRING
|
||||
skip : SKIP;
|
||||
top : TOP;
|
||||
format : FORMAT;
|
||||
|
||||
inlinecount : '$count' EQ BOOLEAN;
|
||||
|
||||
//search is not like the ABNF to support operator precedence
|
||||
search : '$search' searchSpecialToken;
|
||||
|
||||
searchSpecialToken : { ((UriLexer) this.getInputStream().getTokenSource()).SetSWallowed(true); }
|
||||
EQ WS* searchExpr
|
||||
{ ((UriLexer) this.getInputStream().getTokenSource()).SetSWallowed(false); }
|
||||
;
|
||||
|
||||
searchExpr : 'NOT' WS+ searchExpr
|
||||
| searchExpr WS+ ('AND' WS+)? searchExpr
|
||||
| searchExpr WS+ 'OR' WS+ searchExpr
|
||||
| searchPhrase
|
||||
| searchWord
|
||||
;
|
||||
|
||||
searchPhrase : SEARCHPHRASE;
|
||||
searchWord : SEARCHWORD;
|
||||
|
||||
select : '$select' EQ selectItem ( COMMA selectItem )*;
|
||||
selectItem : namespace* '*'
|
||||
| (namespace* odataIdentifier functionParameters? ) ( '/' namespace* odataIdentifier functionParameters? )*
|
||||
;
|
||||
|
||||
aliasAndValue : parameterAlias EQ parameterValue;
|
||||
parameterValue : /*arrayOrObject*/
|
||||
commonExpr;
|
||||
customQueryOption : { ((UriLexer) this.getInputStream().getTokenSource()).SetCUSTallowed(true); }
|
||||
customName ( EQ customValue)?
|
||||
{ ((UriLexer) this.getInputStream().getTokenSource()).SetCUSTallowed(false); }
|
||||
;
|
||||
customName : 'CUSTOMNAME';
|
||||
customValue : 'CUSTOMVALUE';
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 3. Context URL Fragments
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
contextFragment : 'Collection($ref)'
|
||||
| '$ref'
|
||||
| 'Collection(Edm.EntityType)'
|
||||
| 'Collection(Edm.ComplexType)'
|
||||
| PRIMITIVETYPENAME
|
||||
| 'collection' OPEN
|
||||
( PRIMITIVETYPENAME
|
||||
| namespace odataIdentifier
|
||||
) CLOSE
|
||||
| namespace* odataIdentifier ( '/$deletedEntity'
|
||||
| '/$link'
|
||||
| '/$deletedLink'
|
||||
| keypredicates? ( '/' namespace* odataIdentifier)* ( propertyList )? ( '/$delta' )? ( entity )?
|
||||
)?
|
||||
;
|
||||
|
||||
propertyList : OPEN propertyListItem ( COMMA propertyListItem )* CLOSE;
|
||||
propertyListItem : STAR //; all structural properties
|
||||
| propertyListProperty
|
||||
;
|
||||
propertyListProperty : odataIdentifier ( '+' )? ( propertyList )?
|
||||
| odataIdentifier ( '/' propertyListProperty )?
|
||||
;
|
||||
|
||||
entity : '/$entity';
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 4. Expressions
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
// this expression part of the grammer is not similar to the ABNF because
|
||||
// we had to introduced operator precesence witch is not reflected in the ABNF
|
||||
|
||||
|
||||
commonExpr : OPEN commonExpr CLOSE
|
||||
| methodCallExpr
|
||||
| unary WS+ commonExpr
|
||||
| memberExpr
|
||||
| commonExpr WS+ ('mul'|'div'|'mod') WS+ commonExpr
|
||||
| commonExpr WS+ ('add'|'sub') WS+ commonExpr
|
||||
| commonExpr WS+ ('gt'|'ge'|'lt'|'le'|'isof') WS+ commonExpr
|
||||
| commonExpr WS+ ('eq'|'ne') WS+ commonExpr
|
||||
| commonExpr WS+ ('and') WS+ commonExpr
|
||||
| commonExpr WS+ ('or') WS+ commonExpr
|
||||
| rootExpr //; $...
|
||||
| parameterAlias //; @...
|
||||
| primitiveLiteral //; ...
|
||||
;
|
||||
|
||||
unary : ('-'|'not') ;
|
||||
|
||||
rootExpr : '$root/' pathSegments;
|
||||
|
||||
memberExpr : '$it' | '$it/'? pathSegments;
|
||||
|
||||
anyExpr : 'any' OPEN WS* /* [ lambdaVariableExpr BWS COLON BWS lambdaPredicateExpr ] WS* */ CLOSE;
|
||||
allExpr : 'all' OPEN WS* /* lambdaVariableExpr BWS COLON BWS lambdaPredicateExpr WS* */ CLOSE;
|
||||
|
||||
methodCallExpr : indexOfMethodCallExpr
|
||||
| toLowerMethodCallExpr
|
||||
| toUpperMethodCallExpr
|
||||
| trimMethodCallExpr
|
||||
| substringMethodCallExpr
|
||||
| concatMethodCallExpr
|
||||
| lengthMethodCallExpr
|
||||
| yearMethodCallExpr
|
||||
| monthMethodCallExpr
|
||||
| dayMethodCallExpr
|
||||
| hourMethodCallExpr
|
||||
| minuteMethodCallExpr
|
||||
| secondMethodCallExpr
|
||||
| fractionalsecondsMethodCallExpr
|
||||
| totalsecondsMethodCallExpr
|
||||
| dateMethodCallExpr
|
||||
| timeMethodCallExpr
|
||||
| roundMethodCallExpr
|
||||
| floorMethodCallExpr
|
||||
| ceilingMethodCallExpr
|
||||
| distanceMethodCallExpr
|
||||
| geoLengthMethodCallExpr
|
||||
| totalOffsetMinutesMethodCallExpr
|
||||
| minDateTimeMethodCallExpr
|
||||
| maxDateTimeMethodCallExpr
|
||||
| nowMethodCallExpr
|
||||
//from boolean
|
||||
| isofExpr
|
||||
| castExpr
|
||||
| endsWithMethodCallExpr
|
||||
| startsWithMethodCallExpr
|
||||
| containsMethodCallExpr
|
||||
| intersectsMethodCallExpr
|
||||
;
|
||||
|
||||
|
||||
containsMethodCallExpr : 'contains' OPEN WS* commonExpr WS* COMMA WS* commonExpr WS* CLOSE;
|
||||
startsWithMethodCallExpr : 'startswith' OPEN WS* commonExpr WS* COMMA WS* commonExpr WS* CLOSE;
|
||||
endsWithMethodCallExpr : 'endswith' OPEN WS* commonExpr WS* COMMA WS* commonExpr WS* CLOSE;
|
||||
lengthMethodCallExpr : 'length' OPEN WS* commonExpr WS* CLOSE;
|
||||
indexOfMethodCallExpr : 'indexof' OPEN WS* commonExpr WS* COMMA WS* commonExpr WS* CLOSE;
|
||||
substringMethodCallExpr : 'substring' OPEN WS* commonExpr WS* COMMA WS* commonExpr WS* ( COMMA WS* commonExpr WS* ) CLOSE;
|
||||
toLowerMethodCallExpr : 'tolower' OPEN WS* commonExpr WS* CLOSE;
|
||||
toUpperMethodCallExpr : 'toupper' OPEN WS* commonExpr WS* CLOSE;
|
||||
trimMethodCallExpr : 'trim' OPEN WS* commonExpr WS* CLOSE;
|
||||
concatMethodCallExpr : 'concat' OPEN WS* commonExpr WS* COMMA WS* commonExpr WS* CLOSE;
|
||||
|
||||
yearMethodCallExpr : 'year' OPEN WS* commonExpr WS* CLOSE;
|
||||
monthMethodCallExpr : 'month' OPEN WS* commonExpr WS* CLOSE;
|
||||
dayMethodCallExpr : 'day' OPEN WS* commonExpr WS* CLOSE;
|
||||
hourMethodCallExpr : 'hour' OPEN WS* commonExpr WS* CLOSE;
|
||||
minuteMethodCallExpr : 'minute' OPEN WS* commonExpr WS* CLOSE;
|
||||
secondMethodCallExpr : 'second' OPEN WS* commonExpr WS* CLOSE;
|
||||
fractionalsecondsMethodCallExpr : 'fractionalseconds' OPEN WS* commonExpr WS* CLOSE;
|
||||
totalsecondsMethodCallExpr : 'totalseconds' OPEN WS* commonExpr WS* CLOSE;
|
||||
dateMethodCallExpr : 'date' OPEN WS* commonExpr WS* CLOSE;
|
||||
timeMethodCallExpr : 'time' OPEN WS* commonExpr WS* CLOSE;
|
||||
totalOffsetMinutesMethodCallExpr : 'totaloffsetminutes' OPEN WS* commonExpr WS* CLOSE;
|
||||
|
||||
minDateTimeMethodCallExpr : 'mindatetime' OPEN WS* CLOSE;
|
||||
maxDateTimeMethodCallExpr : 'maxdatetime' OPEN WS* CLOSE;
|
||||
nowMethodCallExpr : 'now' OPEN WS* CLOSE;
|
||||
|
||||
roundMethodCallExpr : 'round' OPEN WS* commonExpr WS* CLOSE;
|
||||
floorMethodCallExpr : 'floor' OPEN WS* commonExpr WS* CLOSE;
|
||||
ceilingMethodCallExpr : 'ceiling' OPEN WS* commonExpr WS* CLOSE;
|
||||
|
||||
distanceMethodCallExpr : 'geo.distance' OPEN WS* commonExpr WS* COMMA WS* commonExpr WS* CLOSE;
|
||||
geoLengthMethodCallExpr : 'geo.length' OPEN WS* commonExpr WS* CLOSE;
|
||||
intersectsMethodCallExpr : 'geo.intersects' OPEN WS* commonExpr WS* COMMA WS* commonExpr WS* CLOSE;
|
||||
|
||||
isofExpr : 'isof' OPEN WS* commonExpr WS* COMMA WS* qualifiedtypename WS* CLOSE;
|
||||
castExpr : 'cast' OPEN WS* ( commonExpr WS* COMMA WS* ) qualifiedtypename WS* CLOSE;
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 6. Names and identifiers
|
||||
//;------------------------------------------------------------------------------
|
||||
POINT : '.';
|
||||
|
||||
qualifiedtypename : PRIMITIVETYPENAME
|
||||
| namespace odataIdentifier
|
||||
| 'collection' OPEN
|
||||
( PRIMITIVETYPENAME
|
||||
| namespace odataIdentifier
|
||||
) CLOSE
|
||||
;
|
||||
|
||||
namespace : (odataIdentifier POINT)+;
|
||||
|
||||
odataIdentifier : ODATAIDENTIFIER;
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 7. Literal Data Values
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
/*TODO add missing values*/
|
||||
primitiveLiteral : nullrule
|
||||
| BOOLEAN
|
||||
| DECIMAL
|
||||
| INT
|
||||
| BINARY
|
||||
| DATE
|
||||
| DATETIMEOFFSET
|
||||
//|duration
|
||||
| string
|
||||
| TIMEOFDAY
|
||||
// enum
|
||||
| parameterAlias
|
||||
;
|
||||
|
||||
|
||||
nullrule : NULLVALUE;// (SQUOTE qualifiedtypename SQUOTE)?;
|
||||
string : STRING;
|
||||
/*TODO
|
||||
enum : qualifiedEnumTypeName SQUOTE enumValue SQUOTE
|
||||
enumValue : singleEnumValue *( COMMA singleEnumValue )
|
||||
singleEnumValue : enumerationMember / int64Value
|
||||
*/
|
|
@ -0,0 +1,307 @@
|
|||
lexer grammar UriLexerPart;
|
||||
|
||||
@lexer::members {
|
||||
//custom lexer members -->
|
||||
boolean debug = false;
|
||||
private void out(String out) { if(debug) { System.out.println(out); } };
|
||||
|
||||
|
||||
boolean SWallowed = false;
|
||||
public boolean IsSWallowed() { out("?SW?="+SWallowed); return SWallowed; };
|
||||
public void SetSWallowed(boolean value) { SWallowed=value; out("SW=set to "+ SWallowed); };
|
||||
|
||||
boolean CUSTallowed = false;
|
||||
public boolean IsCUSTallowed() { out("?CUST?="+CUSTallowed); return CUSTallowed; };
|
||||
public void SetCUSTallowed(boolean value) { SWallowed=value; out("CUST=set to "+ CUSTallowed); };
|
||||
|
||||
//<-- 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+ //; <a data service specific value indicating a
|
||||
); //; format specific to the specific data service> or
|
||||
//; <An IANA-defined [IANA-MMT] content type>
|
||||
ID : '$id' EQ QCHAR_NO_AMP+;
|
||||
|
||||
SKIPTOKEN : '$skiptoken' EQ QCHAR_NO_AMP+;
|
||||
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 4. Expressions
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
|
||||
ImplicitVariableExpr : '$it';
|
||||
|
||||
INDEXOF: 'indexof';
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 5. JSON format for function parameters
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 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
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
SEARCHPHRASE : QUOTATION_MARK QCHAR_NO_AMP_DQUOTE+ QUOTATION_MARK;
|
||||
|
||||
|
||||
fragment QUOTATION_MARK : DQUOTE | '%22';
|
||||
|
||||
fragment ESCAPE : '\\' | '%5C' ; // ; reverse solidus U+005C
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 6. Names and identifiers
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
fragment IDENTIFIERLEADINGCHARACTER : ALPHA | '_'; //TODO; plus Unicode characters from the categories L or Nl
|
||||
fragment IDENTIFIERCHARACTER : 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 )?
|
||||
)
|
||||
;
|
||||
|
||||
ABSTRACTSPATIALTYPENAME : 'Geography'
|
||||
| 'Geometry';
|
||||
CONCRETESPATIALTYPENAME : 'Collection'
|
||||
| 'LineString'
|
||||
| 'MultiLineString'
|
||||
| 'MultiPoint'
|
||||
| 'MultiPolygon'
|
||||
| 'Point'
|
||||
| 'Polygon';
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 7. Literal Data Values
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
NULLVALUE : 'null';
|
||||
fragment SQUOTEinSTRING : SQUOTE SQUOTE ;
|
||||
|
||||
BINARY : ('X'| B I N A R Y) SQUOTE BINARYVALUE SQUOTE;
|
||||
fragment BINARYVALUE: (HEXDIG HEXDIG)*;
|
||||
|
||||
BOOLEAN : T R U E
|
||||
| F A L S E
|
||||
;
|
||||
//DIGITS :DIGIT+;
|
||||
|
||||
DECIMAL : SIGN? DIGIT+ '.' DIGIT+; // decimal = [SIGN] 1*DIGIT ["." 1*DIGIT] der 2. optionale Teil erschwert der Unterschied zwischen INT und DECIMAL -> nicht optional
|
||||
|
||||
INT : SIGN? DIGIT+;// { !IsIRIallowed() }?;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// --------------------- DATE ---------------------
|
||||
DATE : DATETOKEN SQUOTE DATEVALUE SQUOTE;
|
||||
fragment DATETOKEN : D A T E;
|
||||
fragment DATEVALUE : YEAR '-' MONTH '-' DAY;
|
||||
|
||||
|
||||
// --------------------- DATETIMEOFFSET ---------------------
|
||||
DATETIMEOFFSET : DATEOSTOKEN SQUOTE DATETIMEOFFSETVALUE SQUOTE;
|
||||
fragment DATEOSTOKEN: D A T E T I M E O F F S E T;
|
||||
|
||||
fragment DATETIMEOFFSETVALUE
|
||||
: YEAR '-' MONTH '-' DAY T HOUR ':' MINUTE ( ':' SECOND ( '.' FRACTIONALSECONDS )? )? ( Z | SIGN HOUR ':' MINUTE )
|
||||
;
|
||||
// --------------------- 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' ( '1'..'3')
|
||||
;
|
||||
|
||||
fragment MINUTE : ZEROtoFIFTYNINE;
|
||||
fragment SECOND : ZEROtoFIFTYNINE;
|
||||
fragment FRACTIONALSECONDS : DIGIT+;
|
||||
fragment ZEROtoFIFTYNINE : ('0'..'5') DIGIT;
|
||||
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; 9. Punctuation
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
WS : ( SP | HTAB | '%20' | '%09' ); //; "required" whitespace
|
||||
//fragment OWS : WS*;
|
||||
//rws : WS+;
|
||||
|
||||
|
||||
AT : '@' | '%40';
|
||||
|
||||
COMMA : ',' | '%2C';
|
||||
EQ : '=';
|
||||
SIGN : '+' | '%2B' |'-';
|
||||
SEMI : ';' | '%3B';
|
||||
STAR : '*';
|
||||
SQUOTE : '\'' | '%27';
|
||||
OPEN : '(' | '%28';
|
||||
CLOSE : ')' | '%29';
|
||||
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; A. URI syntax [RFC3986]
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
QM : '?' -> channel(HIDDEN);
|
||||
|
||||
fragment PCHAR : UNRESERVED | PCT_ENCODED | SUB_DELIMS | ':' | '@';
|
||||
|
||||
fragment PCHARnoSQUOTE : UNRESERVED| PCTENCODEDnoSQUOTE | OTHERDELIMS | '$' | '&' | EQ | ':' | '@';
|
||||
|
||||
fragment PCT_ENCODED : '%' HEXDIG HEXDIG;
|
||||
fragment UNRESERVED : ALPHA | DIGIT | '-' |'.' | '_' | '~';
|
||||
fragment SUB_DELIMS : '$' | '&' | '\'' | '=' | OTHER_DELIMS;
|
||||
fragment OTHER_DELIMS : '!' | '(' | ')' | '*' | '+' | ',' | ';';
|
||||
|
||||
fragment OTHERDELIMS : '!' | '(' | ')' | '*' | '+' | ',' | ';'
|
||||
;
|
||||
|
||||
fragment PCTENCODEDnoSQUOTE
|
||||
: '%' ( '0'|'1'|'3'..'9' | AtoF ) HEXDIG
|
||||
| '%' '2' ( '0'..'6'|'8'|'9' | AtoF )
|
||||
;
|
||||
|
||||
fragment QCHAR_NO_AMP : UNRESERVED | PCT_ENCODED | OTHERDELIMS | ':' | '@' | '/' | '?' | '$' | '\'' | '=';// { IsIRIallowed() }?;
|
||||
fragment QCHAR_NO_AMP_EQ : UNRESERVED | PCT_ENCODED | OTHERDELIMS | ':' | '@' | '/' | '?' | '$' | '\'';
|
||||
fragment QCHAR_NO_AMP_EQ_AT_DOLLAR : UNRESERVED | PCT_ENCODED | OTHERDELIMS | ':' | '/' | '?' | '\'';
|
||||
|
||||
fragment QCHAR_UNESCAPED : UNRESERVED | PCT_ENCODED_UNESCAPED | OTHERDELIMS | ':' | '@' | '/' | '?' | '$' | '\'' | '=';
|
||||
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';
|
||||
DIGIT : '0'..'9';/* ('0'|ONEtoNINE)
|
||||
| '%x3'('0'..'9');*/
|
||||
fragment HEXDIG : DIGIT | AtoF;
|
||||
fragment AtoF : 'a'..'f'|'A'..'F';
|
||||
DQUOTE : '\u0022';
|
||||
SP : ' ';//'\u0020'; // a simple space
|
||||
HTAB : '%09';
|
||||
|
||||
fragment VCHAR : '\u0021'..'\u007E';
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; End of odata-abnf-construction-rules
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//;------------------------------------------------------------------------------
|
||||
//; HELPER
|
||||
//;------------------------------------------------------------------------------
|
||||
|
||||
fragment A : 'a'|'A';
|
||||
fragment B : 'b'|'B';
|
||||
fragment D : 'd'|'D';
|
||||
fragment E : 'e'|'E';
|
||||
fragment F : 'f'|'F';
|
||||
fragment I : 'i'|'I';
|
||||
fragment L : 'l'|'L';
|
||||
fragment M : 'm'|'M';
|
||||
fragment N : 'n'|'N';
|
||||
fragment O : 'o'|'O';
|
||||
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;
|
||||
|
||||
SEARCHWORD : ALPHA+ { IsSWallowed() }?; //; Actually: any character from the Unicode categories L or Nl,
|
||||
// //; but not the words AND, OR, and NOT which are match far above
|
||||
//CUSTOMNAME : QCHAR_NO_AMP_EQ_AT_DOLLAR QCHAR_NO_AMP_EQ* { IsCUSTallowed() }?;
|
||||
//CUSTOMVALUE : QCHAR_NO_AMP+ { IsCUSTallowed() }?;
|
||||
|
||||
|
||||
ODATAIDENTIFIER : IDENTIFIERLEADINGCHARACTER (IDENTIFIERCHARACTER)*;
|
||||
|
||||
AT_ODATAIDENTIFIER : AT ODATAIDENTIFIER;
|
||||
/* 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*/
|
|
@ -0,0 +1,36 @@
|
|||
package org.apache.olingo.producer.core.uri;
|
||||
|
||||
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.producer.core.uri.antlr.UriLexer;
|
||||
|
||||
public class ErrorHandler<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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*******************************************************************************
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
******************************************************************************/
|
||||
package org.apache.olingo.producer.core.uri;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.producer.api.uri.KeyPredicate;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class KeyPredicateImpl implements KeyPredicate {
|
||||
|
||||
public KeyPredicateImpl(final String literal, final EdmProperty property) {
|
||||
super();
|
||||
this.literal = literal;
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
private String literal;
|
||||
private EdmProperty property;
|
||||
|
||||
@Override
|
||||
public String getLiteral() {
|
||||
return literal;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.apache.olingo.producer.core.uri;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmBindingTarget;
|
||||
|
||||
public class UriInfo {
|
||||
private UriType uriType;
|
||||
private EdmBindingTarget bindingTarget;
|
||||
private List<String> keyNames = Collections.emptyList();
|
||||
|
||||
public UriType getUriType() {
|
||||
return uriType;
|
||||
}
|
||||
|
||||
public void setUriType(final UriType uriType) {
|
||||
this.uriType = uriType;
|
||||
}
|
||||
|
||||
public EdmBindingTarget getBindingTarget() {
|
||||
return bindingTarget;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.apache.olingo.producer.core.uri;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
|
||||
public class UriInfoImpl extends UriInfo {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.EdmTyped;
|
||||
import org.apache.olingo.producer.api.uri.KeyPredicate;
|
||||
//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 {
|
||||
|
||||
public enum PathInfoType {
|
||||
/* only first */
|
||||
entitySet,
|
||||
singleton,
|
||||
actionImport,
|
||||
functioncall,
|
||||
/* not first */
|
||||
boundFunctioncall,
|
||||
boundActionImport,
|
||||
navicationProperty
|
||||
/* complexTypeFilter */// may be future
|
||||
}
|
||||
|
||||
public static class PropertyItem {
|
||||
EdmTyped property;
|
||||
EdmType typeFilter;
|
||||
|
||||
public PropertyItem(final EdmTyped property) {
|
||||
this.property = property;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ActualFunctionParameter {
|
||||
String name;
|
||||
String value;
|
||||
|
||||
public ActualFunctionParameter(final String name, final String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCollection;
|
||||
public PathInfoType type;
|
||||
|
||||
public EdmEntityContainer entityContainer;
|
||||
|
||||
public EdmType targetType;
|
||||
public EdmEntitySet targetEntityset;
|
||||
|
||||
public EdmType typeBeforeKeyPredicates;
|
||||
public List<KeyPredicate> keyPredicates = null;
|
||||
public EdmType typeAfterKeyPredicates;
|
||||
|
||||
public List<ActualFunctionParameter> functionParameter = new ArrayList<ActualFunctionParameter>();
|
||||
|
||||
public List<PropertyItem> properties = new ArrayList<PropertyItem>();
|
||||
|
||||
public PathInfoType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(final PathInfoType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package org.apache.olingo.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.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriLexer;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser.OdataRelativeUriAContext;
|
||||
|
||||
public class UriTreeReader {
|
||||
|
||||
// //@Test
|
||||
// public void Test() {
|
||||
// String uri = "EntityColFunctionImport(ParameterName1=1)(1)/Namespace1.EntityTypeName/EntityFunctionImport()/"
|
||||
// + "Namespace1.EntityTypeName?$expand=ComplexColProperty/Namespace1.ComplexTypeName/EntityNavigationProperty"
|
||||
// + "&$filter=Namespace1.EntityTypeName/Namespace1.EntityFunction() eq 1 and true";
|
||||
// //String uri = "$entity?$id=1";
|
||||
// readUri(uri);
|
||||
// }
|
||||
|
||||
public UriInfoImpl readUri(final String uri, final Edm edm) {
|
||||
UriInfoImpl ret = new UriInfoImpl();
|
||||
OdataRelativeUriAContext root = parseUri(uri);
|
||||
|
||||
root.accept(new UriTreeVisitor(ret, edm));
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* if (root.getChildCount() == 1 ) {
|
||||
* System.out.println("is service");
|
||||
* return null;
|
||||
* }
|
||||
*
|
||||
* ParserRuleContext c0 = (ParserRuleContext) root.children.get(0);
|
||||
* if (c0 instanceof BatchContext)
|
||||
* {
|
||||
* System.out.print("is $batch");
|
||||
* return null;
|
||||
* } else if (c0 instanceof EntityAContext)
|
||||
* {
|
||||
* readEntity(c0);
|
||||
* return null;
|
||||
* } else if (c0 instanceof MetadataContext)
|
||||
* {
|
||||
* readMetadata(c0);
|
||||
* return null;
|
||||
* } else if (c0 instanceof ResourcePathAContext)
|
||||
* {
|
||||
* readResourcePath(c0.getChild(0));
|
||||
* if (c0.getChildCount() > 2) {
|
||||
* readQueryOptions(c0.getChild(0));
|
||||
* }
|
||||
* return null;
|
||||
* }
|
||||
*
|
||||
* System.out.println("Error");
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
private OdataRelativeUriAContext parseUri(final String uri) {
|
||||
|
||||
ANTLRInputStream input = new ANTLRInputStream(uri);
|
||||
|
||||
UriLexer lexer = new UriLexer(input);
|
||||
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
UriParser parser = new UriParser(tokens);
|
||||
|
||||
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.odataRelativeUriA();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,372 @@
|
|||
package org.apache.olingo.producer.core.uri;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.misc.NotNull;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmActionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmElement;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmNamed;
|
||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmSingleton;
|
||||
import org.apache.olingo.commons.api.edm.EdmStructuralType;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.EdmTyped;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.helper.FullQualifiedName;
|
||||
import org.apache.olingo.producer.api.uri.KeyPredicate;
|
||||
import org.apache.olingo.producer.core.uri.UriPathInfoImpl.PathInfoType;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriBaseVisitor;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser.CompoundKeyContext;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser.FunctionParameterContext;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser.FunctionParametersContext;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser.KeyValuePairContext;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser.KeypredicatesContext;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser.PathSegmentContext;
|
||||
import org.apache.olingo.producer.core.uri.antlr.UriParser.SimpleKeyContext;
|
||||
|
||||
public class UriTreeVisitor extends UriBaseVisitor<Object> {
|
||||
private Edm edm = null;
|
||||
private UriInfoImpl uriInfo = null;
|
||||
private EdmEntityContainer entityContainer = null;
|
||||
private boolean isFirst;
|
||||
|
||||
/**
|
||||
* @param uriInfo
|
||||
* @param edm
|
||||
*/
|
||||
UriTreeVisitor(final UriInfoImpl uriInfo, final Edm edm) {
|
||||
this.uriInfo = uriInfo;
|
||||
this.edm = edm;
|
||||
// this.entityContainer = edm.getEntityContainer(null, null);//"RefScenario","Container1"
|
||||
entityContainer = edm.getEntityContainer(null);// "RefScenario","Container1"
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitBatch(@NotNull final UriParser.BatchContext ctx) {
|
||||
// Set UriType to Batch
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitEntityA(@NotNull final UriParser.EntityAContext ctx) {
|
||||
// Set UriType to Entity
|
||||
// uriInfo.AddResSelector(new OriResourceSelector());
|
||||
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitMetadata(@NotNull final UriParser.MetadataContext ctx) {
|
||||
// Set UriType to Entity
|
||||
// uriInfo.AddResSelector(new OriResourceSelector());
|
||||
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitPathSegment(@NotNull final UriParser.PathSegmentContext ctx) {
|
||||
// info crossjoin and all have own ruleContexts
|
||||
if (isFirst) {
|
||||
handleFirstPathSegment(ctx);
|
||||
isFirst = false;
|
||||
} else {
|
||||
handlePathSegments(ctx);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitPathSegments(@NotNull final UriParser.PathSegmentsContext ctx) {
|
||||
isFirst = true;
|
||||
return visitChildren(ctx);
|
||||
}
|
||||
|
||||
private void handleFirstPathSegment(final UriParser.PathSegmentContext ctx) {
|
||||
if (ctx.ns != null) {
|
||||
// Error: First pathsegment can not be qualified. Allowed is entityset|function...
|
||||
}
|
||||
|
||||
if (ctx.odi == null) {
|
||||
// Error: First pathsegment must contain an odata identifier
|
||||
}
|
||||
|
||||
String odataIdentifier = ctx.odi.getText();
|
||||
|
||||
// get element "odataIdentifier" from EDM
|
||||
EdmNamed edmObject = entityContainer.getElement(odataIdentifier);
|
||||
|
||||
// is EdmEntitySet
|
||||
if (edmObject instanceof EdmEntitySet) {
|
||||
EdmEntitySet entityset = (EdmEntitySet) edmObject;
|
||||
UriPathInfoImpl pathInfo = new UriPathInfoImpl(); // TODO change to UriPathInfoImplEntitySet
|
||||
pathInfo.type = PathInfoType.entitySet;
|
||||
pathInfo.entityContainer = entityContainer;
|
||||
pathInfo.targetEntityset = entityset;
|
||||
pathInfo.targetType = entityset.getEntityType();
|
||||
pathInfo.isCollection = true;
|
||||
// TODO check if kp may have been collected into fp
|
||||
if (ctx.kp != null) {
|
||||
pathInfo.keyPredicates = readkeypredicates(ctx.kp, entityset.getEntityType());
|
||||
pathInfo.isCollection = false;
|
||||
}
|
||||
|
||||
uriInfo.addUriPathInfo(pathInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
// is EdmSingleton
|
||||
if (edmObject instanceof EdmSingleton) {
|
||||
EdmSingleton singleton = (EdmSingleton) edmObject;
|
||||
UriPathInfoImpl pathInfo = new UriPathInfoImpl(); // TODO change to UriPathInfoImplEntitySet
|
||||
pathInfo.type = PathInfoType.singleton;
|
||||
pathInfo.entityContainer = entityContainer;
|
||||
pathInfo.targetType = singleton.getEntityType();
|
||||
pathInfo.isCollection = false;
|
||||
uriInfo.addUriPathInfo(pathInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
// is EdmActionImport
|
||||
if (edmObject instanceof EdmActionImport) {
|
||||
UriPathInfoImpl pathInfo = new UriPathInfoImpl();
|
||||
pathInfo.type = PathInfoType.actionImport;
|
||||
|
||||
uriInfo.addUriPathInfo(pathInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
// is EdmFunctionImport
|
||||
if (edmObject instanceof EdmFunctionImport) {
|
||||
|
||||
EdmFunctionImport fi = (EdmFunctionImport) edmObject;
|
||||
UriPathInfoImpl pathInfo = new UriPathInfoImpl();
|
||||
pathInfo.type = PathInfoType.functioncall;
|
||||
|
||||
if (ctx.fp != null) {
|
||||
pathInfo.functionParameter = readFunctionParameters(ctx.fp);
|
||||
}
|
||||
if (ctx.kp != null) {
|
||||
pathInfo.keyPredicates = readkeypredicates(ctx.kp, fi.getReturnedEntitySet().getEntityType()/* TODO fix */);
|
||||
}
|
||||
|
||||
uriInfo.addUriPathInfo(pathInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handlePathSegments(final UriParser.PathSegmentContext ctx) {
|
||||
|
||||
UriPathInfoImpl prev = uriInfo.getLastUriPathInfo();
|
||||
|
||||
String namespace = (ctx.ns != null) ? ctx.ns.getText().substring(0, ctx.ns.getText().length() - 1) : null;
|
||||
|
||||
if (namespace != null) {
|
||||
// is type filter, action or function
|
||||
|
||||
String odataIdentifier = ctx.odi.getText();
|
||||
EdmType type = edm.getTypeDefinition(new FullQualifiedName(namespace, odataIdentifier));
|
||||
|
||||
if (type != null) {
|
||||
handleTypeFilter(ctx, type);
|
||||
return;
|
||||
}
|
||||
|
||||
// check for bound actions
|
||||
EdmAction action = null;
|
||||
EdmFunction function = null;
|
||||
if ((action =
|
||||
edm.getAction(new FullQualifiedName(namespace, odataIdentifier), new FullQualifiedName(prev.targetType
|
||||
.getNamespace(), prev.targetType.getName()), prev.isCollection)) != null) {
|
||||
handleBoundAction(ctx, action);
|
||||
} else if ((function =
|
||||
edm.getFunction(new FullQualifiedName(namespace, odataIdentifier), new FullQualifiedName(prev.targetType
|
||||
.getNamespace(), prev.targetType.getName()), prev.isCollection, null)) != null) {
|
||||
handleBoundFunction(ctx, function);
|
||||
}
|
||||
|
||||
// Error: namespace.odataIdentifier unknown
|
||||
|
||||
} else {
|
||||
// check for property
|
||||
EdmType type = prev.targetType;
|
||||
String odataIdentifier = ctx.odi.getText();
|
||||
|
||||
if (!(type instanceof EdmStructuralType)) {
|
||||
// Error: type is not structured ...
|
||||
}
|
||||
|
||||
EdmTyped property = ((EdmStructuralType) type).getProperty(odataIdentifier);
|
||||
if (property != null) {
|
||||
handleProperty(ctx, prev, property);
|
||||
}
|
||||
|
||||
// Error: odataIdentifier is not a property of type ...
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleProperty(final UriParser.PathSegmentContext ctx, final UriPathInfoImpl prev,
|
||||
final EdmTyped property) {
|
||||
|
||||
// TODO add check that prev is not a collection
|
||||
if (property instanceof EdmNavigationProperty) {
|
||||
|
||||
// add to prev properties so that it can be selected when processing the previous pathInfo
|
||||
prev.properties.add(new UriPathInfoImpl.PropertyItem(property));
|
||||
|
||||
UriPathInfoImpl pathInfo = new UriPathInfoImpl();
|
||||
pathInfo.type = PathInfoType.navicationProperty;
|
||||
|
||||
if (ctx.kp != null) {
|
||||
if (pathInfo.isCollection == false) {
|
||||
// Error keyPredicates can only applied to a collection
|
||||
}
|
||||
pathInfo.keyPredicates = readkeypredicates(ctx.kp, property.getType());
|
||||
pathInfo.isCollection = false;
|
||||
}
|
||||
|
||||
uriInfo.addUriPathInfo(pathInfo);
|
||||
|
||||
} else if (property instanceof EdmProperty) {
|
||||
|
||||
prev.properties.add(new UriPathInfoImpl.PropertyItem(property));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBoundFunction(final PathSegmentContext ctx, final EdmFunction function) {
|
||||
UriPathInfoImpl pathInfo = new UriPathInfoImpl();
|
||||
pathInfo.type = PathInfoType.boundFunctioncall;
|
||||
|
||||
if (ctx.fp != null) {
|
||||
pathInfo.functionParameter = readFunctionParameters(ctx.fp);
|
||||
}
|
||||
uriInfo.addUriPathInfo(pathInfo);
|
||||
}
|
||||
|
||||
private void handleBoundAction(final PathSegmentContext ctx, final EdmAction action) {
|
||||
UriPathInfoImpl pathInfo = new UriPathInfoImpl();
|
||||
pathInfo.type = PathInfoType.boundActionImport;
|
||||
|
||||
if (ctx.fp != null) {
|
||||
pathInfo.functionParameter = readFunctionParameters(ctx.fp);
|
||||
}
|
||||
uriInfo.addUriPathInfo(pathInfo);
|
||||
}
|
||||
|
||||
private void handleTypeFilter(final UriParser.PathSegmentContext ctx, final EdmType type) {
|
||||
UriPathInfoImpl prev = uriInfo.getLastUriPathInfo();
|
||||
|
||||
if (type == null) {
|
||||
// Error: type not found
|
||||
}
|
||||
|
||||
if (prev.keyPredicates == null) {
|
||||
prev.typeBeforeKeyPredicates = type;
|
||||
} else {
|
||||
prev.typeAfterKeyPredicates = type;
|
||||
}
|
||||
prev.targetType = type;
|
||||
|
||||
if (ctx.kp != null) {
|
||||
if (!prev.isCollection) {
|
||||
// Error: Keypredicates only allowed on collection
|
||||
}
|
||||
if (prev.typeAfterKeyPredicates != null) {
|
||||
// Internal logic error
|
||||
}
|
||||
|
||||
prev.keyPredicates = readkeypredicates(ctx.kp, prev.targetType);
|
||||
}
|
||||
}
|
||||
|
||||
private List<UriPathInfoImpl.ActualFunctionParameter> readFunctionParameters(final FunctionParametersContext fp) {
|
||||
List<UriPathInfoImpl.ActualFunctionParameter> ret = new ArrayList<UriPathInfoImpl.ActualFunctionParameter>();
|
||||
|
||||
for (FunctionParameterContext fps : fp.fps) {
|
||||
String parameterName = fps.odi.getText();
|
||||
String parameterValue = null;
|
||||
|
||||
if (fps.val != null) {
|
||||
parameterValue = fps.val.getText();
|
||||
} else if (fps.ali != null) {
|
||||
parameterValue = fps.ali.getText();
|
||||
}
|
||||
|
||||
ret.add(new UriPathInfoImpl.ActualFunctionParameter(parameterName, parameterValue));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<KeyPredicate> readkeypredicates(final KeypredicatesContext kp, final EdmType edmType1) {
|
||||
|
||||
EdmEntityType edmType;
|
||||
if (edmType1 instanceof EdmEntityType) {
|
||||
edmType = (EdmEntityType) edmType1;
|
||||
} else {
|
||||
return null;// TODO better error
|
||||
}
|
||||
|
||||
List<KeyPredicate> ret = new ArrayList<KeyPredicate>();
|
||||
|
||||
ParseTree child = kp.getChild(0);
|
||||
if (child instanceof SimpleKeyContext) {
|
||||
// it is a simple key without a name
|
||||
|
||||
if (edmType.getKeyPredicateNames().size() != 1) {
|
||||
// Error Simple Key only allowed if there is only one keyproperty
|
||||
}
|
||||
|
||||
String keyPredicateName = edmType.getKeyPredicateNames().get(0);
|
||||
String keyPropertyName = edmType.getKeyPropertyRef(keyPredicateName).getKeyPropertyName();
|
||||
EdmElement property = edmType.getProperty(keyPropertyName);
|
||||
if (property == null) {
|
||||
// error keyproperty not found
|
||||
}
|
||||
|
||||
EdmType type = property.getType();
|
||||
if (type.getKind() != EdmTypeKind.PRIMITIVE) {
|
||||
// error property has wrong type
|
||||
}
|
||||
|
||||
String keyLiteral = child.getText();
|
||||
// TODO detect type of keyLiteral and compare with "type"
|
||||
|
||||
ret.add(new KeyPredicateImpl(keyLiteral, (EdmProperty) property));
|
||||
} else if (child instanceof CompoundKeyContext) {
|
||||
CompoundKeyContext compoundKey = (CompoundKeyContext) child;
|
||||
|
||||
for (KeyValuePairContext kvp : compoundKey.kvp) {
|
||||
String keyPropertyName = kvp.odi.getText();
|
||||
EdmElement property = edmType.getProperty(keyPropertyName);
|
||||
if (property == null) {
|
||||
// error keyproperty not found
|
||||
}
|
||||
|
||||
String keyLiteral = kvp.val.getText();
|
||||
// TODO detect type of keyLiteral and compare with "type"
|
||||
|
||||
KeyPredicate keyPredicate = new KeyPredicateImpl(keyLiteral, (EdmProperty) property);
|
||||
ret.add(keyPredicate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package org.apache.olingo.producer.core.uri;
|
||||
|
||||
public enum UriType {
|
||||
TYPE_ENTITY_SET,
|
||||
TYPE_ENTITY_SET_COUNT,
|
||||
TYPE_MEDIA_REFERENCE,
|
||||
TYPE_REFERENCE_COLLECTION,
|
||||
/*
|
||||
* Singleton
|
||||
*/
|
||||
TYPE_ENTITY,
|
||||
TYPE_MEDIA_STREAM,
|
||||
TYPE_REFERENCE,
|
||||
|
||||
/*
|
||||
* Property Path
|
||||
*/
|
||||
TYPE_PROPERTY_PRIMITIVE,
|
||||
TYPE_PROPERTY_PRIMITIVE_COLLECTION,
|
||||
TYPE_PROPERTY_PRIMITIVE_VALUE,
|
||||
TYPE_PROPERTY_COMPLEX,
|
||||
|
||||
/*
|
||||
* Crossjoin
|
||||
*/
|
||||
TYPE_CROSSJOIN,
|
||||
|
||||
/*
|
||||
* $all
|
||||
*/
|
||||
TYPE_SERVICE_ALL,
|
||||
/*
|
||||
* ActionImport
|
||||
*/
|
||||
TYPE_AI_ENTITY,
|
||||
/*
|
||||
* FunctionImport
|
||||
*/
|
||||
TYPE_FI_ENTITY,
|
||||
TYPE_FI_ENTITY_SET,
|
||||
TYPE_FI_ENTITY_SET_COUNT,
|
||||
TYPE_FI_PROPERTY_PRIMITIVE,
|
||||
TYPE_FI_PROPERTY_PRIMITIVE_COLL,
|
||||
TYPE_FI_PROPERTY_PRIMITIVE_COLL_COUNT,
|
||||
TYPE_FI_PROPERTY_COMPLEX,
|
||||
TYPE_FI_PROPERTY_COMPLEX_COLL,
|
||||
TYPE_FI_PROPERTY_COMPLEX_COLL_COUNT,
|
||||
/*
|
||||
* BoundFunction
|
||||
*/
|
||||
TYPE_BF_ENTITY,
|
||||
TYPE_BF_ENTITY_SET,
|
||||
TYPE_BF_PROP_PRIM,
|
||||
TYPE_BF_PROP_COMP,
|
||||
TYPE_BF_PROP_COMP_COLL,
|
||||
TYPE_BF_PROP_PRIM_COLL,
|
||||
/*
|
||||
* BoundAction
|
||||
*/
|
||||
TYPE_BA_ENTITY_SET,
|
||||
TYPE_BA_ENTITY,
|
||||
TYPE_BA_PROP_PRIM,
|
||||
TYPE_BA_PROP_PRIM_COLL,
|
||||
TYPE_BA_PROP_COMP;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.apache.olingo.producer.core.uri.antlr;
|
||||
|
||||
public class ParserException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ParserException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ParserException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public ParserException(final String msg, final Throwable e) {
|
||||
super(msg, e);
|
||||
}
|
||||
|
||||
public ParserException(final Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,728 @@
|
|||
package org.apache.olingo.producer.core.testutil;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmActionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef;
|
||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmReturnType;
|
||||
import org.apache.olingo.commons.api.edm.EdmServiceMetadata;
|
||||
import org.apache.olingo.commons.api.edm.EdmSingleton;
|
||||
import org.apache.olingo.commons.api.edm.EdmStructuralType;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.helper.FullQualifiedName;
|
||||
|
||||
public class EdmMock implements Edm {
|
||||
public static final String NAMESPACE_SCHEMA = "RefScenario";
|
||||
public static final FullQualifiedName CONTAINER_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Container1");
|
||||
|
||||
public static final FullQualifiedName ACTION_IMPORT1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "actionImport1");
|
||||
public static final FullQualifiedName COMPANY_SINGLETON_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Company");
|
||||
public static final FullQualifiedName TEAMS_SET_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Teams");
|
||||
public static final FullQualifiedName MANAGERS_SET_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Managers");
|
||||
public static final FullQualifiedName EMPLOYEES_SET_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Employees");
|
||||
public static final FullQualifiedName EMPLOYEES_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "EmployeeType");
|
||||
public static final FullQualifiedName TEAMS_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "TeamType");
|
||||
public static final FullQualifiedName MANAGERS_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "ManagerType");
|
||||
public static final FullQualifiedName COMPANY_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "CompanyType");
|
||||
public static final FullQualifiedName FUNCTION1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "function1");
|
||||
public static final FullQualifiedName FUNCTION_MAXIMAL_AGE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"MaximalAge");
|
||||
public static final FullQualifiedName FUNCTION_EMPLOYEE_SEARCH_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"EmployeeSearch");
|
||||
public static final FullQualifiedName FUNCTION_ALL_USED_ROOMS_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"AllUsedRoomIds");
|
||||
public static final FullQualifiedName FUNCTION_MOST_COMMON_LOCATION_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"MostCommonLocation");
|
||||
public static final FullQualifiedName FUNCTION_ALL_LOCATIONS_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"AllLocations");
|
||||
public static final FullQualifiedName ACTION1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "action1");
|
||||
public static final FullQualifiedName TYPE_DEF1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "tdtypeDef1");
|
||||
public static final FullQualifiedName RATING_ENUM_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "eRating");
|
||||
public static final FullQualifiedName LOCATION_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "cLocation");
|
||||
public static final FullQualifiedName NON_BINDING_PARAMETER = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"NonBindingParameter");
|
||||
|
||||
public static final FullQualifiedName FUNCTION_IMPORT1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"functionImport1");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_EMPLOYEE_SEARCH_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"EmployeeSearch");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_MAXIMAL_AGE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"MaximalAge");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_ALL_USED_ROOMS_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"AllUsedRoomIds");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_MOST_COMMON_LOCATION_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "MostCommonLocation");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_ALL_LOCATIONS_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"AllLocations");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_entity");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_SET_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_entity_set");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_PPROP_RT_ENTITY_SET_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_pprop_rt_entity_set");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_PPROP_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_pprop");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_CPROP_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_cprop");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_CPROP_COLL_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_cprop_coll");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_PPROP_COLL_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_pprop_coll");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_SINGLETON_RT_ENTITY_SET_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_singleton_rt_entity_set");
|
||||
public static final FullQualifiedName BOUND_ACTION_PPROP_RT_ENTITY_SET_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"ba_pprop_rt_entity_set");
|
||||
public static final FullQualifiedName BOUND_ACTION_ENTITY_RT_ENTITY_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"ba_entity_rt_entity");
|
||||
public static final FullQualifiedName BOUND_ACTION_ENTITY_RT_PPROP_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"ba_entity_rt_pprop");
|
||||
public static final FullQualifiedName BOUND_ACTION_ENTITY_RT_PPROP_COLL_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "ba_entity_rt_pprop_coll");
|
||||
public static final FullQualifiedName BOUND_ACTION_ENTITY_SET_RT_CPROP_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"ba_entity_set_rt_cprop");
|
||||
|
||||
private final EdmEntityType companyType = mock(EdmEntityType.class);
|
||||
private final EdmEntityType managerType = mock(EdmEntityType.class);
|
||||
private final EdmEntityType employeeType = mock(EdmEntityType.class);
|
||||
private final EdmEntityType teamType = mock(EdmEntityType.class);
|
||||
|
||||
private final EdmFunction function1 = mock(EdmFunction.class);
|
||||
private final EdmFunction maximalAgeFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction mostCommonLocationFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction allUsedRoomIdsFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction employeeSearchFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction allLocationsFunction = mock(EdmFunction.class);
|
||||
|
||||
private final EdmFunction boundFunctionEntitySetRtEntity = mock(EdmFunction.class);
|
||||
private final EdmFunction boundEntityColFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionPPropRtEntitySet = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionEntitySetRtPProp = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionEntitySetRtCProp = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionEntitySetRtCPropColl = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionEntitySetRtPPropColl = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionSingletonRtEntitySet = mock(EdmFunction.class);
|
||||
|
||||
private final EdmAction action1 = mock(EdmAction.class);
|
||||
private final EdmAction boundActionPpropRtEntitySet = mock(EdmAction.class);
|
||||
private final EdmAction boundActionEntityRtEntity = mock(EdmAction.class);
|
||||
private final EdmAction boundActionEntityRtPProp = mock(EdmAction.class);
|
||||
private final EdmAction boundActionEntityRtPPropColl = mock(EdmAction.class);
|
||||
private final EdmAction boundActionEntitySetRtCProp = mock(EdmAction.class);
|
||||
private final EdmEnumType ratingEnumType = mock(EdmEnumType.class);
|
||||
private final EdmTypeDefinition typeDef1 = mock(EdmTypeDefinition.class);
|
||||
private final EdmComplexType locationType = mock(EdmComplexType.class);
|
||||
|
||||
private final EdmEntitySet employeesSet = mock(EdmEntitySet.class);
|
||||
private final EdmEntitySet managersSet = mock(EdmEntitySet.class);
|
||||
private final EdmEntitySet teamsSet = mock(EdmEntitySet.class);
|
||||
private final EdmSingleton company = mock(EdmSingleton.class);
|
||||
private final EdmActionImport actionImport1 = mock(EdmActionImport.class);
|
||||
private final EdmFunctionImport functionImport1 = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport employeeSearchFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport maximalAgeFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport mostCommonLocationFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport allUsedRoomIdsFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport allLocationsFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmEntityContainer container1 = mock(EdmEntityContainer.class);
|
||||
|
||||
public EdmMock() {
|
||||
enhanceEmployeesEntitySet();
|
||||
enhanceManagersEntitySet();
|
||||
enhanceTeamsEntitySet();
|
||||
enhanceCompany();
|
||||
enhanceContainer1();
|
||||
|
||||
enhanceEmployeeType();
|
||||
enhanceManagerType();
|
||||
enhanceTeamType();
|
||||
enhanceCompanyType();
|
||||
enhanceLocationType();
|
||||
|
||||
enhanceActionImport1();
|
||||
enhanceFunctionImport1();
|
||||
enhanceFunctionImportEmployeeSearch();
|
||||
enhanceMaximalAgeFunctionImport();
|
||||
enhanceMostCommonLocationFunctionImport();
|
||||
enhanceAllUsedRoomIdsFunctionImport();
|
||||
enhanceAllLocationsFunctionImport();
|
||||
|
||||
enhanceAction1();
|
||||
enhanceFunction1();
|
||||
enhanceFunctionEmployeeSearch();
|
||||
enhanceMaximalAgeFunction();
|
||||
enhanceMostCommonLocationFunction();
|
||||
enhanceAllUsedRoomIdsFunction();
|
||||
enhanceAllLocationsFunction();
|
||||
enhanceBoundEntityFunction();
|
||||
enhanceBoundFunctionEntitySetRtEntitySet();
|
||||
enhanceBoundFunctionPPropRtEntitySet();
|
||||
enhanceBoundFunctionEntitySetRtPProp();
|
||||
enhanceBoundFunctionEntitySetRtPPropColl();
|
||||
enhanceBoundFunctionEntitySetRtCProp();
|
||||
enhanceBoundFunctionEntitySetRtCPropColl();
|
||||
enhanceBoundFunctionSingletonRtEntitySet();
|
||||
enhanceBoundActionPPropRtEntitySet();
|
||||
enhanceBoundActionEntityRtEntity();
|
||||
enhanceBoundActionEntityRtPProp();
|
||||
enhanceBoundActionEntityRtPPropColl();
|
||||
enhanceBoundActionEntitySetRtCProp();
|
||||
}
|
||||
|
||||
private void enhanceTeamType() {
|
||||
when(teamType.getName()).thenReturn(TEAMS_TYPE_NAME.getName());
|
||||
when(teamType.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(teamType.getKind()).thenReturn(EdmTypeKind.ENTITY);
|
||||
when(teamType.hasStream()).thenReturn(false);
|
||||
List<String> keyPredicateNames = new ArrayList<String>();
|
||||
when(teamType.getKeyPredicateNames()).thenReturn(keyPredicateNames);
|
||||
List<EdmKeyPropertyRef> keyPropertyRefs = new ArrayList<EdmKeyPropertyRef>();
|
||||
when(teamType.getKeyPropertyRefs()).thenReturn(keyPropertyRefs);
|
||||
List<String> navigationNames = new ArrayList<String>();
|
||||
when(teamType.getNavigationPropertyNames()).thenReturn(navigationNames);
|
||||
List<String> propertyNames = new ArrayList<String>();
|
||||
when(teamType.getPropertyNames()).thenReturn(propertyNames);
|
||||
|
||||
addKeyProperty(teamType, "Id");
|
||||
|
||||
addNavigationProperty(teamType, "nt_Employees", true, employeeType);
|
||||
|
||||
addProperty(teamType, "Name", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(teamType, "IsScrumTeam", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(teamType, "Rating", true, mock(EdmPrimitiveType.class));
|
||||
}
|
||||
|
||||
private void enhanceManagerType() {
|
||||
when(managerType.getName()).thenReturn(MANAGERS_TYPE_NAME.getName());
|
||||
when(managerType.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(managerType.getKind()).thenReturn(EdmTypeKind.ENTITY);
|
||||
when(managerType.hasStream()).thenReturn(true);
|
||||
when(managerType.getBaseType()).thenReturn(employeeType);
|
||||
List<String> keyPredicateNames = new ArrayList<String>();
|
||||
when(managerType.getKeyPredicateNames()).thenReturn(keyPredicateNames);
|
||||
List<EdmKeyPropertyRef> keyPropertyRefs = new ArrayList<EdmKeyPropertyRef>();
|
||||
when(managerType.getKeyPropertyRefs()).thenReturn(keyPropertyRefs);
|
||||
List<String> navigationNames = new ArrayList<String>();
|
||||
when(managerType.getNavigationPropertyNames()).thenReturn(navigationNames);
|
||||
List<String> propertyNames = new ArrayList<String>();
|
||||
when(managerType.getPropertyNames()).thenReturn(propertyNames);
|
||||
|
||||
addKeyProperty(managerType, "EmployeeId");
|
||||
|
||||
addNavigationProperty(managerType, "ne_Manager", false, managerType);
|
||||
addNavigationProperty(managerType, "ne_Team", false, teamType);
|
||||
addNavigationProperty(managerType, "nm_Employees", true, employeeType);
|
||||
|
||||
addProperty(managerType, "EmployeeName", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(managerType, "ManagerId", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(managerType, "Location", false, locationType);
|
||||
addProperty(managerType, "Age", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(managerType, "EntryDate", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(managerType, "ImageUrl", true, mock(EdmPrimitiveType.class));
|
||||
}
|
||||
|
||||
// when().thenReturn();
|
||||
private void enhanceEmployeeType() {
|
||||
when(employeeType.getName()).thenReturn(EMPLOYEES_TYPE_NAME.getName());
|
||||
when(employeeType.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(employeeType.getKind()).thenReturn(EdmTypeKind.ENTITY);
|
||||
when(employeeType.hasStream()).thenReturn(true);
|
||||
List<String> keyPredicateNames = new ArrayList<String>();
|
||||
when(employeeType.getKeyPredicateNames()).thenReturn(keyPredicateNames);
|
||||
List<EdmKeyPropertyRef> keyPropertyRefs = new ArrayList<EdmKeyPropertyRef>();
|
||||
when(employeeType.getKeyPropertyRefs()).thenReturn(keyPropertyRefs);
|
||||
List<String> navigationNames = new ArrayList<String>();
|
||||
when(employeeType.getNavigationPropertyNames()).thenReturn(navigationNames);
|
||||
List<String> propertyNames = new ArrayList<String>();
|
||||
when(employeeType.getPropertyNames()).thenReturn(propertyNames);
|
||||
|
||||
addKeyProperty(employeeType, "EmployeeId");
|
||||
|
||||
addNavigationProperty(employeeType, "ne_Manager", false, managerType);
|
||||
addNavigationProperty(employeeType, "ne_Team", false, teamType);
|
||||
|
||||
addProperty(employeeType, "EmployeeName", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(employeeType, "ManagerId", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(employeeType, "Location", false, locationType);
|
||||
addProperty(employeeType, "Age", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(employeeType, "EntryDate", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(employeeType, "ImageUrl", true, mock(EdmPrimitiveType.class));
|
||||
}
|
||||
|
||||
private void enhanceLocationType() {
|
||||
addProperty(locationType, "Country", true, mock(EdmPrimitiveType.class));
|
||||
when(locationType.getName()).thenReturn(LOCATION_TYPE_NAME.getName());
|
||||
}
|
||||
|
||||
private void enhanceCompanyType() {
|
||||
when(companyType.getName()).thenReturn(COMPANY_TYPE_NAME.getName());
|
||||
when(companyType.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(companyType.getKind()).thenReturn(EdmTypeKind.ENTITY);
|
||||
}
|
||||
|
||||
private void addNavigationProperty(final EdmEntityType entityType, final String propertyName,
|
||||
final boolean isCollection, final EdmType type) {
|
||||
EdmNavigationProperty property = mock(EdmNavigationProperty.class);
|
||||
entityType.getNavigationPropertyNames().add(propertyName);
|
||||
when(property.getName()).thenReturn(propertyName);
|
||||
when(entityType.getProperty(propertyName)).thenReturn(property);
|
||||
when(property.isCollection()).thenReturn(isCollection);
|
||||
when(property.getType()).thenReturn(type);
|
||||
}
|
||||
|
||||
private void addKeyProperty(final EdmEntityType entityType, final String propertyName) {
|
||||
entityType.getKeyPredicateNames().add(propertyName);
|
||||
EdmProperty keyProp = addProperty(entityType, propertyName, true, mock(EdmPrimitiveType.class));
|
||||
EdmKeyPropertyRef keyRef = mock(EdmKeyPropertyRef.class);
|
||||
when(keyRef.getKeyPropertyName()).thenReturn(propertyName);
|
||||
when(keyRef.getProperty()).thenReturn(keyProp);
|
||||
entityType.getKeyPropertyRefs().add(keyRef);
|
||||
when(entityType.getKeyPropertyRef(propertyName)).thenReturn(keyRef);
|
||||
}
|
||||
|
||||
private EdmProperty addProperty(final EdmStructuralType structuralType, final String propertyName,
|
||||
final boolean isPrimitive, final EdmType type) {
|
||||
EdmProperty property = mock(EdmProperty.class);
|
||||
when(property.getName()).thenReturn(propertyName);
|
||||
structuralType.getPropertyNames().add(propertyName);
|
||||
when(structuralType.getProperty(propertyName)).thenReturn(property);
|
||||
when(property.isPrimitive()).thenReturn(isPrimitive);
|
||||
when(property.getType()).thenReturn(type);
|
||||
return property;
|
||||
}
|
||||
|
||||
private void enhanceContainer1() {
|
||||
when(container1.getName()).thenReturn(CONTAINER_NAME.getName());
|
||||
when(container1.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
|
||||
when(container1.getEntitySet(EMPLOYEES_SET_NAME.getName())).thenReturn(employeesSet);
|
||||
when(container1.getEntitySet(MANAGERS_SET_NAME.getName())).thenReturn(managersSet);
|
||||
when(container1.getEntitySet(TEAMS_SET_NAME.getName())).thenReturn(teamsSet);
|
||||
when(container1.getSingleton(COMPANY_SINGLETON_NAME.getName())).thenReturn(company);
|
||||
when(container1.getActionImport(ACTION_IMPORT1_NAME.getName())).thenReturn(actionImport1);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT1_NAME.getName())).thenReturn(functionImport1);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_MAXIMAL_AGE_NAME.getName())).thenReturn(maximalAgeFunctionImport);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_MOST_COMMON_LOCATION_NAME.getName())).thenReturn(
|
||||
mostCommonLocationFunctionImport);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_ALL_USED_ROOMS_NAME.getName())).thenReturn(
|
||||
allUsedRoomIdsFunctionImport);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_EMPLOYEE_SEARCH_NAME.getName())).thenReturn(
|
||||
employeeSearchFunctionImport);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_ALL_LOCATIONS_NAME.getName())).thenReturn(
|
||||
allLocationsFunctionImport);
|
||||
|
||||
when(container1.getElement(EMPLOYEES_SET_NAME.getName())).thenReturn(employeesSet);
|
||||
when(container1.getElement(TEAMS_SET_NAME.getName())).thenReturn(teamsSet);
|
||||
when(container1.getElement(COMPANY_SINGLETON_NAME.getName())).thenReturn(company);
|
||||
when(container1.getElement(ACTION_IMPORT1_NAME.getName())).thenReturn(actionImport1);
|
||||
when(container1.getElement(FUNCTION_IMPORT_MAXIMAL_AGE_NAME.getName())).thenReturn(maximalAgeFunctionImport);
|
||||
|
||||
}
|
||||
|
||||
private void enhanceActionImport1() {
|
||||
when(actionImport1.getName()).thenReturn(ACTION_IMPORT1_NAME.getName());
|
||||
when(actionImport1.getEntityContainer()).thenReturn(container1);
|
||||
when(actionImport1.getReturnedEntitySet()).thenReturn(employeesSet);
|
||||
when(actionImport1.getOperation()).thenReturn(action1);
|
||||
}
|
||||
|
||||
private void enhanceFunctionImport1() {
|
||||
when(functionImport1.getName()).thenReturn(FUNCTION_IMPORT1_NAME.getName());
|
||||
when(functionImport1.getEntityContainer()).thenReturn(container1);
|
||||
when(functionImport1.getReturnedEntitySet()).thenReturn(teamsSet);
|
||||
when(functionImport1.getOperation()).thenReturn(function1);
|
||||
}
|
||||
|
||||
private void enhanceFunctionImportEmployeeSearch() {
|
||||
when(employeeSearchFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_EMPLOYEE_SEARCH_NAME.getName());
|
||||
when(employeeSearchFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
when(employeeSearchFunctionImport.getReturnedEntitySet()).thenReturn(teamsSet);
|
||||
when(employeeSearchFunctionImport.getOperation()).thenReturn(employeeSearchFunction);
|
||||
}
|
||||
|
||||
private void enhanceFunctionEmployeeSearch() {
|
||||
when(employeeSearchFunction.getName()).thenReturn(FUNCTION1_NAME.getName());
|
||||
when(employeeSearchFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(employeeSearchFunction.getReturnType().isCollection()).thenReturn(true);
|
||||
when(employeeSearchFunction.getReturnType().getType()).thenReturn(employeeType);
|
||||
}
|
||||
|
||||
private void enhanceMaximalAgeFunctionImport() {
|
||||
when(maximalAgeFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_MAXIMAL_AGE_NAME.getName());
|
||||
when(maximalAgeFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
// TODO: getReturnedEntitySet()
|
||||
when(maximalAgeFunctionImport.getOperation()).thenReturn(maximalAgeFunction);
|
||||
}
|
||||
|
||||
private void enhanceMaximalAgeFunction() {
|
||||
when(maximalAgeFunction.getName()).thenReturn(FUNCTION_MAXIMAL_AGE_NAME.getName());
|
||||
when(maximalAgeFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(maximalAgeFunction.getReturnType().isCollection()).thenReturn(false);
|
||||
when(maximalAgeFunction.getReturnType().getType()).thenReturn(mock(EdmPrimitiveType.class));
|
||||
|
||||
}
|
||||
|
||||
private void enhanceAllUsedRoomIdsFunctionImport() {
|
||||
when(allUsedRoomIdsFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_ALL_USED_ROOMS_NAME.getName());
|
||||
when(allUsedRoomIdsFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
// TODO: getReturnedEntitySet()
|
||||
when(allUsedRoomIdsFunctionImport.getOperation()).thenReturn(allUsedRoomIdsFunction);
|
||||
}
|
||||
|
||||
private void enhanceAllUsedRoomIdsFunction() {
|
||||
when(allUsedRoomIdsFunction.getName()).thenReturn(FUNCTION_ALL_USED_ROOMS_NAME.getName());
|
||||
when(allUsedRoomIdsFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(allUsedRoomIdsFunction.getReturnType().isCollection()).thenReturn(true);
|
||||
when(allUsedRoomIdsFunction.getReturnType().getType()).thenReturn(mock(EdmPrimitiveType.class));
|
||||
|
||||
}
|
||||
|
||||
private void enhanceMostCommonLocationFunctionImport() {
|
||||
when(mostCommonLocationFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_MOST_COMMON_LOCATION_NAME.getName());
|
||||
when(mostCommonLocationFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
// TODO: getReturnedEntitySet()
|
||||
when(mostCommonLocationFunctionImport.getOperation()).thenReturn(mostCommonLocationFunction);
|
||||
}
|
||||
|
||||
private void enhanceMostCommonLocationFunction() {
|
||||
when(mostCommonLocationFunction.getName()).thenReturn(FUNCTION_MOST_COMMON_LOCATION_NAME.getName());
|
||||
when(mostCommonLocationFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(mostCommonLocationFunction.getReturnType().isCollection()).thenReturn(false);
|
||||
when(mostCommonLocationFunction.getReturnType().getType()).thenReturn(locationType);
|
||||
|
||||
}
|
||||
|
||||
private void enhanceAllLocationsFunctionImport() {
|
||||
when(allLocationsFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_ALL_LOCATIONS_NAME.getName());
|
||||
when(allLocationsFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
// TODO: getReturnedEntitySet()
|
||||
when(allLocationsFunctionImport.getOperation()).thenReturn(allLocationsFunction);
|
||||
}
|
||||
|
||||
private void enhanceAllLocationsFunction() {
|
||||
when(allLocationsFunction.getName()).thenReturn(FUNCTION_ALL_LOCATIONS_NAME.getName());
|
||||
when(allLocationsFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(allLocationsFunction.getReturnType().isCollection()).thenReturn(true);
|
||||
when(allLocationsFunction.getReturnType().getType()).thenReturn(locationType);
|
||||
|
||||
}
|
||||
|
||||
private void enhanceBoundEntityFunction() {
|
||||
when(boundFunctionEntitySetRtEntity.getName()).thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_NAME.getName());
|
||||
when(boundFunctionEntitySetRtEntity.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtEntity.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundFunctionEntitySetRtEntity.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundFunctionEntitySetRtEntity.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtEntity.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtEntitySet() {
|
||||
when(boundEntityColFunction.getName()).thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_SET_NAME.getName());
|
||||
when(boundEntityColFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundEntityColFunction.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundEntityColFunction.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundEntityColFunction.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundEntityColFunction.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionPPropRtEntitySet() {
|
||||
when(boundFunctionPPropRtEntitySet.getName()).thenReturn(BOUND_FUNCTION_PPROP_RT_ENTITY_SET_NAME.getName());
|
||||
when(boundFunctionPPropRtEntitySet.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionPPropRtEntitySet.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundFunctionPPropRtEntitySet.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundFunctionPPropRtEntitySet.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionPPropRtEntitySet.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtPProp() {
|
||||
when(boundFunctionEntitySetRtPProp.getName()).thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_PPROP_NAME.getName());
|
||||
when(boundFunctionEntitySetRtPProp.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtPProp.getReturnType().isCollection()).thenReturn(false);
|
||||
EdmPrimitiveType primitiveType = mock(EdmPrimitiveType.class);
|
||||
when(boundFunctionEntitySetRtPProp.getReturnType().getType()).thenReturn(primitiveType);
|
||||
when(boundFunctionEntitySetRtPProp.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtPProp.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtPPropColl() {
|
||||
when(boundFunctionEntitySetRtPPropColl.getName())
|
||||
.thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_PPROP_COLL_NAME.getName());
|
||||
when(boundFunctionEntitySetRtPPropColl.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtPPropColl.getReturnType().isCollection()).thenReturn(true);
|
||||
EdmPrimitiveType primitiveType = mock(EdmPrimitiveType.class);
|
||||
when(boundFunctionEntitySetRtPPropColl.getReturnType().getType()).thenReturn(primitiveType);
|
||||
when(boundFunctionEntitySetRtPPropColl.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtPPropColl.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtCProp() {
|
||||
when(boundFunctionEntitySetRtCProp.getName()).thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_CPROP_NAME.getName());
|
||||
when(boundFunctionEntitySetRtCProp.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtCProp.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundFunctionEntitySetRtCProp.getReturnType().getType()).thenReturn(locationType);
|
||||
when(boundFunctionEntitySetRtCProp.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtCProp.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtCPropColl() {
|
||||
when(boundFunctionEntitySetRtCPropColl.getName())
|
||||
.thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_CPROP_COLL_NAME.getName());
|
||||
when(boundFunctionEntitySetRtCPropColl.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtCPropColl.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundFunctionEntitySetRtCPropColl.getReturnType().getType()).thenReturn(locationType);
|
||||
when(boundFunctionEntitySetRtCPropColl.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtCPropColl.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionSingletonRtEntitySet() {
|
||||
when(boundFunctionSingletonRtEntitySet.getName()).thenReturn(BOUND_FUNCTION_SINGLETON_RT_ENTITY_SET_NAME.getName());
|
||||
when(boundFunctionSingletonRtEntitySet.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionSingletonRtEntitySet.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundFunctionSingletonRtEntitySet.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundFunctionSingletonRtEntitySet.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionSingletonRtEntitySet.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionPPropRtEntitySet() {
|
||||
when(boundActionPpropRtEntitySet.getName()).thenReturn(BOUND_ACTION_PPROP_RT_ENTITY_SET_NAME.getName());
|
||||
when(boundActionPpropRtEntitySet.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundActionPpropRtEntitySet.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundActionPpropRtEntitySet.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundActionPpropRtEntitySet.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionPpropRtEntitySet.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionEntityRtEntity() {
|
||||
when(boundActionEntityRtEntity.getName()).thenReturn(BOUND_ACTION_ENTITY_RT_ENTITY_NAME.getName());
|
||||
when(boundActionEntityRtEntity.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundActionEntityRtEntity.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundActionEntityRtEntity.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundActionEntityRtEntity.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionEntityRtEntity.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionEntityRtPProp() {
|
||||
when(boundActionEntityRtPProp.getName()).thenReturn(BOUND_ACTION_ENTITY_RT_PPROP_NAME.getName());
|
||||
when(boundActionEntityRtPProp.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
EdmPrimitiveType primitiveType = mock(EdmPrimitiveType.class);
|
||||
when(boundActionEntityRtPProp.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundActionEntityRtPProp.getReturnType().getType()).thenReturn(primitiveType);
|
||||
when(boundActionEntityRtPProp.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionEntityRtPProp.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionEntityRtPPropColl() {
|
||||
when(boundActionEntityRtPPropColl.getName()).thenReturn(BOUND_ACTION_ENTITY_RT_PPROP_NAME.getName());
|
||||
when(boundActionEntityRtPPropColl.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
EdmPrimitiveType primitiveType = mock(EdmPrimitiveType.class);
|
||||
when(boundActionEntityRtPPropColl.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundActionEntityRtPPropColl.getReturnType().getType()).thenReturn(primitiveType);
|
||||
when(boundActionEntityRtPPropColl.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionEntityRtPPropColl.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionEntitySetRtCProp() {
|
||||
when(boundActionEntitySetRtCProp.getName()).thenReturn(BOUND_ACTION_ENTITY_SET_RT_CPROP_NAME.getName());
|
||||
when(boundActionEntitySetRtCProp.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundActionEntitySetRtCProp.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundActionEntitySetRtCProp.getReturnType().getType()).thenReturn(locationType);
|
||||
when(boundActionEntitySetRtCProp.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionEntitySetRtCProp.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceFunction1() {
|
||||
when(function1.getName()).thenReturn(FUNCTION1_NAME.getName());
|
||||
when(function1.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(function1.getReturnType().isCollection()).thenReturn(false);
|
||||
when(function1.getReturnType().getType()).thenReturn(teamType);
|
||||
}
|
||||
|
||||
private void enhanceAction1() {
|
||||
when(action1.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(action1.getReturnType().isCollection()).thenReturn(false);
|
||||
when(action1.getReturnType().getType()).thenReturn(employeeType);
|
||||
}
|
||||
|
||||
private void enhanceCompany() {
|
||||
when(company.getName()).thenReturn(COMPANY_SINGLETON_NAME.getName());
|
||||
when(company.getEntityContainer()).thenReturn(container1);
|
||||
when(company.getEntityType()).thenReturn(companyType);
|
||||
}
|
||||
|
||||
private void enhanceManagersEntitySet() {
|
||||
when(managersSet.getName()).thenReturn(MANAGERS_SET_NAME.getName());
|
||||
when(managersSet.getEntityContainer()).thenReturn(container1);
|
||||
when(managersSet.getEntityType()).thenReturn(managerType);
|
||||
}
|
||||
|
||||
private void enhanceTeamsEntitySet() {
|
||||
when(teamsSet.getName()).thenReturn(TEAMS_SET_NAME.getName());
|
||||
when(teamsSet.getEntityContainer()).thenReturn(container1);
|
||||
when(teamsSet.getEntityType()).thenReturn(teamType);
|
||||
}
|
||||
|
||||
private void enhanceEmployeesEntitySet() {
|
||||
when(employeesSet.getName()).thenReturn(EMPLOYEES_SET_NAME.getName());
|
||||
when(employeesSet.getEntityContainer()).thenReturn(container1);
|
||||
when(employeesSet.getEntityType()).thenReturn(employeeType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmEntityContainer getEntityContainer(final FullQualifiedName fqn) {
|
||||
|
||||
if (fqn == null || NAMESPACE_SCHEMA.equals(fqn.getNamespace()) && CONTAINER_NAME.equals(fqn.getName())) {
|
||||
return container1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmEnumType getEnumType(final FullQualifiedName fqn) {
|
||||
if (RATING_ENUM_TYPE_NAME.equals(fqn)) {
|
||||
return ratingEnumType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmTypeDefinition getTypeDefinition(final FullQualifiedName fqn) {
|
||||
if (TYPE_DEF1_NAME.equals(fqn)) {
|
||||
return typeDef1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmEntityType getEntityType(final FullQualifiedName fqn) {
|
||||
if (NAMESPACE_SCHEMA.equals(fqn.getNamespace())) {
|
||||
if (EMPLOYEES_TYPE_NAME.equals(fqn)) {
|
||||
return employeeType;
|
||||
} else if (MANAGERS_TYPE_NAME.equals(fqn)) {
|
||||
return managerType;
|
||||
} else if (TEAMS_TYPE_NAME.equals(fqn)) {
|
||||
return teamType;
|
||||
} else if (COMPANY_TYPE_NAME.equals(fqn)) {
|
||||
return companyType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmComplexType getComplexType(final FullQualifiedName fqn) {
|
||||
if (LOCATION_TYPE_NAME.equals(fqn)) {
|
||||
return locationType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmServiceMetadata getServiceMetadata() {
|
||||
return mock(EdmServiceMetadata.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAction getAction(final FullQualifiedName actionFqn, final FullQualifiedName bindingParameterTypeFqn,
|
||||
final Boolean isBindingParameterTypeCollection) {
|
||||
if (NAMESPACE_SCHEMA.equals(actionFqn.getNamespace())) {
|
||||
if (ACTION1_NAME.equals(actionFqn)) {
|
||||
return action1;
|
||||
} else if (BOUND_ACTION_PPROP_RT_ENTITY_SET_NAME.equals(actionFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionPpropRtEntitySet;
|
||||
} else if (BOUND_ACTION_ENTITY_RT_ENTITY_NAME.equals(actionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionEntityRtEntity;
|
||||
} else if (BOUND_ACTION_ENTITY_RT_PPROP_NAME.equals(actionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionEntityRtPProp;
|
||||
} else if (BOUND_ACTION_ENTITY_RT_PPROP_COLL_NAME.equals(actionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionEntityRtPPropColl;
|
||||
} else if (BOUND_ACTION_ENTITY_SET_RT_CPROP_NAME.equals(actionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionEntitySetRtCProp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmFunction getFunction(final FullQualifiedName functionFqn,
|
||||
final FullQualifiedName bindingParameterTypeFqn,
|
||||
final Boolean isBindingParameterTypeCollection, final List<String> bindingParameterNames) {
|
||||
if (functionFqn != null) {
|
||||
if (NAMESPACE_SCHEMA.equals(functionFqn.getNamespace())) {
|
||||
if (FUNCTION1_NAME.equals(functionFqn)) {
|
||||
return function1;
|
||||
} else if (FUNCTION_ALL_LOCATIONS_NAME.equals(functionFqn)) {
|
||||
return allLocationsFunction;
|
||||
} else if (FUNCTION_EMPLOYEE_SEARCH_NAME.equals(functionFqn)) {
|
||||
return employeeSearchFunction;
|
||||
} else if (FUNCTION_MAXIMAL_AGE_NAME.equals(functionFqn)) {
|
||||
return maximalAgeFunction;
|
||||
} else if (FUNCTION_MOST_COMMON_LOCATION_NAME.equals(functionFqn)) {
|
||||
return mostCommonLocationFunction;
|
||||
} else if (FUNCTION_ALL_USED_ROOMS_NAME.equals(functionFqn)) {
|
||||
return allUsedRoomIdsFunction;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtEntity;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_SET_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundEntityColFunction;
|
||||
} else if (BOUND_FUNCTION_PPROP_RT_ENTITY_SET_NAME.equals(functionFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionPPropRtEntitySet;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_PPROP_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtPProp;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_PPROP_COLL_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtPPropColl;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_CPROP_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtCProp;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_CPROP_COLL_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtCPropColl;
|
||||
} else if (BOUND_FUNCTION_SINGLETON_RT_ENTITY_SET_NAME.equals(functionFqn)
|
||||
&& COMPANY_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionSingletonRtEntitySet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package org.apache.olingo.producer.core.uri.antlr;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.apache.olingo.producer.core.testutil.EdmMock;
|
||||
import org.apache.olingo.producer.core.uri.UriInfoImpl;
|
||||
import org.apache.olingo.producer.core.uri.UriPathInfoImpl;
|
||||
import org.apache.olingo.producer.core.uri.UriTreeReader;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UriTreeReaderTest {
|
||||
|
||||
@Test
|
||||
public void testEntitySet() {
|
||||
testUri("Employees", UriPathInfoImpl.PathInfoType.entitySet);
|
||||
testUri("Employees('1')", UriPathInfoImpl.PathInfoType.entitySet);
|
||||
testUri("Employees(EmployeeId='1')", UriPathInfoImpl.PathInfoType.entitySet);
|
||||
|
||||
testUri("Employees('1')/EmployeeName", UriPathInfoImpl.PathInfoType.entitySet);
|
||||
|
||||
testUri("Employees/RefScenario.ManagerType", UriPathInfoImpl.PathInfoType.entitySet);
|
||||
testUri("Employees/RefScenario.ManagerType('1')", UriPathInfoImpl.PathInfoType.entitySet);
|
||||
|
||||
testUri("Employees/Location", UriPathInfoImpl.PathInfoType.entitySet);
|
||||
testUri("Employees/Location/Country", UriPathInfoImpl.PathInfoType.entitySet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleton() {
|
||||
testUri("Company", UriPathInfoImpl.PathInfoType.singleton);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActionImport() {
|
||||
testUri("actionImport1", UriPathInfoImpl.PathInfoType.actionImport);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionImport() {
|
||||
testUri("MaximalAge", UriPathInfoImpl.PathInfoType.functioncall);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundFunctions() {
|
||||
testUri("Employees/RefScenario.bf_entity_set_rt_entity(NonBindingParameter='1')",
|
||||
UriPathInfoImpl.PathInfoType.boundFunctioncall);
|
||||
testUri("Employees('1')/EmployeeName/RefScenario.bf_pprop_rt_entity_set()",
|
||||
UriPathInfoImpl.PathInfoType.boundFunctioncall);
|
||||
testUri("Company/RefScenario.bf_singleton_rt_entity_set()('1')",
|
||||
UriPathInfoImpl.PathInfoType.boundFunctioncall);
|
||||
// testUri("Company/RefScenario.bf_singleton_rt_entity_set()('1')/EmployeeName/"
|
||||
// +"RefScenario.bf_pprop_rt_entity_set()",
|
||||
// UriPathInfoImpl.PathInfoType.boundFunctioncall);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundActions() {
|
||||
testUri("Employees('1')/RefScenario.ba_entity_rt_pprop", UriPathInfoImpl.PathInfoType.boundActionImport);
|
||||
testUri("Employees('1')/EmployeeName/RefScenario.ba_pprop_rt_entity_set",
|
||||
UriPathInfoImpl.PathInfoType.boundActionImport);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNavigationFunction() {
|
||||
testUri("Employees('1')/ne_Manager", UriPathInfoImpl.PathInfoType.navicationProperty);
|
||||
testUri("Teams('1')/nt_Employees('1')", UriPathInfoImpl.PathInfoType.navicationProperty);
|
||||
// testUri("Teams('1')/nt_Employees('1')/EmployeeName", UriPathInfoImpl.PathInfoType.navicationProperty);
|
||||
}
|
||||
|
||||
private static UriInfoImpl parseUri(final String uri) {
|
||||
UriTreeReader reader = new UriTreeReader();
|
||||
UriInfoImpl uriInfo = reader.readUri(uri, new EdmMock());
|
||||
return uriInfo;
|
||||
}
|
||||
|
||||
private static void testUri(final String uri, final UriPathInfoImpl.PathInfoType expectedType) {
|
||||
UriInfoImpl uriInfo = parseUri(uri);
|
||||
assertNotNull(uriInfo.getLastUriPathInfo());
|
||||
assertEquals(expectedType, uriInfo.getLastUriPathInfo().getType());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue