Lookup Resource Maven building
Got rid of Gradle. ODATA docs all supported Maven.
This commit is contained in:
parent
971a40cfed
commit
7d462cbc10
|
@ -15,6 +15,9 @@ hs_err_pid*
|
||||||
|
|
||||||
# working folders
|
# working folders
|
||||||
/temp
|
/temp
|
||||||
|
/lib
|
||||||
|
/sql
|
||||||
|
/web
|
||||||
|
|
||||||
# Project Genereated files
|
# Project Genereated files
|
||||||
.pmd
|
.pmd
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
FROM java:8
|
FROM tomcat:latest
|
||||||
|
|
||||||
COPY ./temp/spring-server-generated/target/swagger-spring-1.0.0.jar reso.jar
|
COPY ./target/RESOservice-1.0.war /usr/local/tomcat/webapps/
|
||||||
|
|
||||||
ENTRYPOINT ["java","-jar","reso.jar"]
|
CMD ["catalina.sh", "run"]
|
23
build.gradle
23
build.gradle
|
@ -1,23 +0,0 @@
|
||||||
plugins {
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
group 'org.example'
|
|
||||||
version '1.0-SNAPSHOT'
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
|
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
|
|
||||||
implementation('org.apache.olingo:odata-server-api:4.5.0')
|
|
||||||
implementation('org.apache.olingo:odata-server-core:4.5.0')
|
|
||||||
implementation('org.apache.olingo:odata-commons-api:4.5.0')
|
|
||||||
implementation('org.apache.olingo:odata-commons-core:4.5.0')
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
6
build.sh
6
build.sh
|
@ -1,9 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
unzip temp/resources/spring-server-generated.zip -d temp/spring-server-generated
|
mvn compile
|
||||||
|
mvn package
|
||||||
mvn -f temp/spring-server-generated compile
|
|
||||||
mvn -f temp/spring-server-generated package
|
|
||||||
|
|
||||||
docker-compose build
|
docker-compose build
|
||||||
rm -rf temp/spring-server-generated
|
rm -rf temp/spring-server-generated
|
||||||
|
|
|
@ -4,10 +4,10 @@ services:
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
build: ./
|
build: ./
|
||||||
expose:
|
expose:
|
||||||
- "10222"
|
- "8080"
|
||||||
ports:
|
ports:
|
||||||
- 10222:10222
|
- 8080:8080
|
||||||
environment:
|
environment:
|
||||||
- WAIT_HOSTS
|
- WAIT_HOSTS
|
||||||
depends_on:
|
# depends_on:
|
||||||
- docker-mysql
|
# - docker-mysql
|
||||||
|
|
Binary file not shown.
|
@ -1,5 +0,0 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
|
@ -1,185 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright 2015 the original author or authors.
|
|
||||||
#
|
|
||||||
# Licensed 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
|
|
||||||
#
|
|
||||||
# https://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.
|
|
||||||
#
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
##
|
|
||||||
## Gradle start up script for UN*X
|
|
||||||
##
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
PRG="$0"
|
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
|
||||||
ls=`ls -ld "$PRG"`
|
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
|
||||||
PRG="$link"
|
|
||||||
else
|
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=`basename "$0"`
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD="maximum"
|
|
||||||
|
|
||||||
warn () {
|
|
||||||
echo "$*"
|
|
||||||
}
|
|
||||||
|
|
||||||
die () {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
nonstop=false
|
|
||||||
case "`uname`" in
|
|
||||||
CYGWIN* )
|
|
||||||
cygwin=true
|
|
||||||
;;
|
|
||||||
Darwin* )
|
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
||||||
else
|
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD="java"
|
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
|
||||||
if [ $? -eq 0 ] ; then
|
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
ulimit -n $MAX_FD
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=`expr $i + 1`
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
0) set -- ;;
|
|
||||||
1) set -- "$args0" ;;
|
|
||||||
2) set -- "$args0" "$args1" ;;
|
|
||||||
3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Escape application args
|
|
||||||
save () {
|
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
|
||||||
echo " "
|
|
||||||
}
|
|
||||||
APP_ARGS=`save "$@"`
|
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
|
|
@ -1,89 +0,0 @@
|
||||||
@rem
|
|
||||||
@rem Copyright 2015 the original author or authors.
|
|
||||||
@rem
|
|
||||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
@rem you may not use this file except in compliance with the License.
|
|
||||||
@rem You may obtain a copy of the License at
|
|
||||||
@rem
|
|
||||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
@rem
|
|
||||||
@rem Unless required by applicable law or agreed to in writing, software
|
|
||||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
@rem See the License for the specific language governing permissions and
|
|
||||||
@rem limitations under the License.
|
|
||||||
@rem
|
|
||||||
|
|
||||||
@if "%DEBUG%" == "" @echo off
|
|
||||||
@rem ##########################################################################
|
|
||||||
@rem
|
|
||||||
@rem Gradle startup script for Windows
|
|
||||||
@rem
|
|
||||||
@rem ##########################################################################
|
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
|
||||||
set APP_BASE_NAME=%~n0
|
|
||||||
set APP_HOME=%DIRNAME%
|
|
||||||
|
|
||||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
||||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
||||||
|
|
||||||
@rem Find java.exe
|
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
|
||||||
if "%ERRORLEVEL%" == "0" goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:execute
|
|
||||||
@rem Setup the command line
|
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
||||||
|
|
||||||
:end
|
|
||||||
@rem End local scope for the variables with windows NT shell
|
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
|
||||||
|
|
||||||
:fail
|
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
||||||
rem the _cmd.exe /c_ return code!
|
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
|
||||||
exit /b 1
|
|
||||||
|
|
||||||
:mainEnd
|
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
|
||||||
|
|
||||||
:omega
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.reso</groupId>
|
||||||
|
<artifactId>RESOservice</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<name>RESOservice</name>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<junit.version>5.7.0</junit.version>
|
||||||
|
<javax.version>2.5</javax.version>
|
||||||
|
<odata.version>4.6.0</odata.version>
|
||||||
|
<slf4j.version>1.7.7</slf4j.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<version>4.0.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.olingo</groupId>
|
||||||
|
<artifactId>odata-server-api</artifactId>
|
||||||
|
<version>${odata.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.olingo</groupId>
|
||||||
|
<artifactId>odata-server-core</artifactId>
|
||||||
|
<version>${odata.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.olingo</groupId>
|
||||||
|
<artifactId>odata-commons-api</artifactId>
|
||||||
|
<version>${odata.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.olingo</groupId>
|
||||||
|
<artifactId>odata-commons-core</artifactId>
|
||||||
|
<version>${odata.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.7.11</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -1,2 +0,0 @@
|
||||||
rootProject.name = 'WebApi'
|
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
package org.reso.service.data;
|
||||||
|
|
||||||
|
import org.apache.olingo.commons.api.data.*;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||||
|
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||||
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
|
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||||
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
|
import org.apache.olingo.server.api.*;
|
||||||
|
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
|
||||||
|
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
|
||||||
|
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||||
|
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||||
|
import org.apache.olingo.server.api.serializer.SerializerResult;
|
||||||
|
import org.apache.olingo.server.api.uri.UriInfo;
|
||||||
|
import org.apache.olingo.server.api.uri.UriResource;
|
||||||
|
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
|
||||||
|
import org.reso.service.edmprovider.LookupEdmProvider;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LookupEntityCollectionProcessor implements EntityCollectionProcessor
|
||||||
|
{
|
||||||
|
private OData odata;
|
||||||
|
private ServiceMetadata serviceMetadata;
|
||||||
|
|
||||||
|
public void init(OData odata, ServiceMetadata serviceMetadata) {
|
||||||
|
this.odata = odata;
|
||||||
|
this.serviceMetadata = serviceMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat)
|
||||||
|
throws ODataApplicationException, SerializerException
|
||||||
|
{
|
||||||
|
|
||||||
|
// 1st we have retrieve the requested EntitySet from the uriInfo object (representation of the parsed service URI)
|
||||||
|
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
|
||||||
|
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); // in our example, the first segment is the EntitySet
|
||||||
|
EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
|
||||||
|
|
||||||
|
// 2nd: fetch the data from backend for this requested EntitySetName
|
||||||
|
// it has to be delivered as EntitySet object
|
||||||
|
EntityCollection entitySet = getData(edmEntitySet);
|
||||||
|
|
||||||
|
// 3rd: create a serializer based on the requested format (json)
|
||||||
|
ODataSerializer serializer = odata.createSerializer(responseFormat);
|
||||||
|
|
||||||
|
// 4th: Now serialize the content: transform from the EntitySet object to InputStream
|
||||||
|
EdmEntityType edmEntityType = edmEntitySet.getEntityType();
|
||||||
|
ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
|
||||||
|
|
||||||
|
final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
|
||||||
|
EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build();
|
||||||
|
SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, entitySet, opts);
|
||||||
|
InputStream serializedContent = serializerResult.getContent();
|
||||||
|
|
||||||
|
// Finally: configure the response object: set the body, headers and status code
|
||||||
|
response.setContent(serializedContent);
|
||||||
|
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
||||||
|
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityCollection getData(EdmEntitySet edmEntitySet){
|
||||||
|
|
||||||
|
EntityCollection lookupsCollection = new EntityCollection();
|
||||||
|
// check for which EdmEntitySet the data is requested
|
||||||
|
if(LookupEdmProvider.ES_LOOKUPS_NAME.equals(edmEntitySet.getName())) {
|
||||||
|
List<Entity> productList = lookupsCollection.getEntities();
|
||||||
|
|
||||||
|
// add some sample product entities
|
||||||
|
final Entity e1 = new Entity()
|
||||||
|
.addProperty(new Property(null, "LookupKey", ValueType.PRIMITIVE, "ABC123"))
|
||||||
|
.addProperty(new Property(null, "LookupName", ValueType.PRIMITIVE, "CountyOrParish"))
|
||||||
|
.addProperty(new Property(null, "LookupValue", ValueType.PRIMITIVE,
|
||||||
|
"Los Angeles County"));
|
||||||
|
e1.setId(createId("Lookups", 1));
|
||||||
|
productList.add(e1);
|
||||||
|
|
||||||
|
final Entity e2 = new Entity()
|
||||||
|
.addProperty(new Property(null, "LookupKey", ValueType.PRIMITIVE, "BCD124"))
|
||||||
|
.addProperty(new Property(null, "LookupName", ValueType.PRIMITIVE, "CountyOrParish"))
|
||||||
|
.addProperty(new Property(null, "LookupValue", ValueType.PRIMITIVE,
|
||||||
|
"Ventura County"));
|
||||||
|
e2.setId(createId("Lookups", 1));
|
||||||
|
productList.add(e2);
|
||||||
|
|
||||||
|
final Entity e3 = new Entity()
|
||||||
|
.addProperty(new Property(null, "LookupKey", ValueType.PRIMITIVE, "CDE125"))
|
||||||
|
.addProperty(new Property(null, "LookupName", ValueType.PRIMITIVE, "CountyOrParish"))
|
||||||
|
.addProperty(new Property(null, "LookupValue", ValueType.PRIMITIVE,
|
||||||
|
"Contra Costa County"));
|
||||||
|
e3.setId(createId("Lookups", 1));
|
||||||
|
productList.add(e3);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lookupsCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private URI createId(String entitySetName, Object id) {
|
||||||
|
try {
|
||||||
|
return new URI(entitySetName + "(" + String.valueOf(id) + ")");
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
package org.reso.service.edmprovider;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
|
import org.apache.olingo.commons.api.edm.provider.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class LookupEdmProvider extends CsdlAbstractEdmProvider
|
||||||
|
{
|
||||||
|
// Service Namespace
|
||||||
|
public static final String NAMESPACE = "RESO.OData.Metadata";
|
||||||
|
|
||||||
|
// EDM Container
|
||||||
|
public static final String CONTAINER_NAME = "Container";
|
||||||
|
public static final FullQualifiedName CONTAINER = new FullQualifiedName(NAMESPACE, CONTAINER_NAME);
|
||||||
|
|
||||||
|
// Entity Types Names
|
||||||
|
public static final String ET_LOOKUP_NAME = "Lookup";
|
||||||
|
public static final FullQualifiedName ET_LOOKUP_FQN = new FullQualifiedName(NAMESPACE, ET_LOOKUP_NAME);
|
||||||
|
|
||||||
|
// Entity Set Names
|
||||||
|
public static final String ES_LOOKUPS_NAME = "Lookups";
|
||||||
|
|
||||||
|
public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {
|
||||||
|
|
||||||
|
// this method is called for one of the EntityTypes that are configured in the Schema
|
||||||
|
if(entityTypeName.equals(ET_LOOKUP_FQN)){
|
||||||
|
|
||||||
|
//create EntityType properties
|
||||||
|
CsdlProperty key = new CsdlProperty().setName("LookupKey").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
|
||||||
|
CsdlProperty name = new CsdlProperty().setName("LookupName").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
|
||||||
|
CsdlProperty value = new CsdlProperty().setName("LookupValue").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
|
||||||
|
|
||||||
|
CsdlProperty stdvalue = new CsdlProperty().setName("StandardLookupValue").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
|
||||||
|
CsdlProperty legacy = new CsdlProperty().setName("LegacyODataValue").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
|
||||||
|
CsdlProperty timestamp = new CsdlProperty().setName("ModificationTimestamp").setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
|
||||||
|
|
||||||
|
// create CsdlPropertyRef for Key element
|
||||||
|
CsdlPropertyRef propertyRef = new CsdlPropertyRef();
|
||||||
|
propertyRef.setName("LookupKey");
|
||||||
|
|
||||||
|
// configure EntityType
|
||||||
|
CsdlEntityType entityType = new CsdlEntityType();
|
||||||
|
entityType.setName(ET_LOOKUP_NAME);
|
||||||
|
entityType.setProperties(Arrays.asList(key, name , value, stdvalue, legacy, timestamp));
|
||||||
|
entityType.setKey(Collections.singletonList(propertyRef));
|
||||||
|
|
||||||
|
return entityType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CsdlEntitySet getEntitySet(FullQualifiedName entityContainer, String entitySetName) {
|
||||||
|
|
||||||
|
if(entityContainer.equals(CONTAINER)){
|
||||||
|
if(entitySetName.equals(ES_LOOKUPS_NAME)){
|
||||||
|
CsdlEntitySet entitySet = new CsdlEntitySet();
|
||||||
|
entitySet.setName(ES_LOOKUPS_NAME);
|
||||||
|
entitySet.setType(ET_LOOKUP_FQN);
|
||||||
|
|
||||||
|
return entitySet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CsdlEntityContainer getEntityContainer() {
|
||||||
|
|
||||||
|
// create EntitySets
|
||||||
|
List<CsdlEntitySet> entitySets = new ArrayList<CsdlEntitySet>();
|
||||||
|
entitySets.add(getEntitySet(CONTAINER, ES_LOOKUPS_NAME));
|
||||||
|
|
||||||
|
// create EntityContainer
|
||||||
|
CsdlEntityContainer entityContainer = new CsdlEntityContainer();
|
||||||
|
entityContainer.setName(CONTAINER_NAME);
|
||||||
|
entityContainer.setEntitySets(entitySets);
|
||||||
|
|
||||||
|
return entityContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CsdlSchema> getSchemas() {
|
||||||
|
|
||||||
|
// create Schema
|
||||||
|
CsdlSchema schema = new CsdlSchema();
|
||||||
|
schema.setNamespace(NAMESPACE);
|
||||||
|
|
||||||
|
// add EntityTypes
|
||||||
|
List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
|
||||||
|
entityTypes.add(getEntityType(ET_LOOKUP_FQN));
|
||||||
|
schema.setEntityTypes(entityTypes);
|
||||||
|
|
||||||
|
// add EntityContainer
|
||||||
|
schema.setEntityContainer(getEntityContainer());
|
||||||
|
|
||||||
|
// finally
|
||||||
|
List<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
|
||||||
|
schemas.add(schema);
|
||||||
|
|
||||||
|
return schemas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CsdlEntityContainerInfo getEntityContainerInfo(FullQualifiedName entityContainerName) {
|
||||||
|
|
||||||
|
// This method is invoked when displaying the Service Document at e.g. http://localhost:8080/DemoService/DemoService.svc
|
||||||
|
if (entityContainerName == null || entityContainerName.equals(CONTAINER)) {
|
||||||
|
CsdlEntityContainerInfo entityContainerInfo = new CsdlEntityContainerInfo();
|
||||||
|
entityContainerInfo.setContainerName(CONTAINER);
|
||||||
|
return entityContainerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package org.reso.service.servlet;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.olingo.commons.api.edmx.EdmxReference;
|
||||||
|
import org.apache.olingo.server.api.OData;
|
||||||
|
import org.apache.olingo.server.api.ODataHttpHandler;
|
||||||
|
import org.apache.olingo.server.api.ServiceMetadata;
|
||||||
|
import org.reso.service.data.LookupEntityCollectionProcessor;
|
||||||
|
import org.reso.service.edmprovider.LookupEdmProvider;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.*;
|
||||||
|
|
||||||
|
public class RESOservlet extends HttpServlet
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(RESOservlet.class);
|
||||||
|
|
||||||
|
protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
try {
|
||||||
|
// create odata handler and configure it with CsdlEdmProvider and Processor
|
||||||
|
OData odata = OData.newInstance();
|
||||||
|
ServiceMetadata edm = odata.createServiceMetadata(new LookupEdmProvider(), new ArrayList<EdmxReference>());
|
||||||
|
ODataHttpHandler handler = odata.createHandler(edm);
|
||||||
|
handler.register(new LookupEntityCollectionProcessor());
|
||||||
|
|
||||||
|
// let the handler do the work
|
||||||
|
handler.process(req, resp);
|
||||||
|
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
LOG.error("Server Error occurred in ExampleServlet", e);
|
||||||
|
throw new ServletException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
id="WebApp_ID" version="2.5">
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>RESOservlet</servlet-name>
|
||||||
|
<servlet-class>org.reso.service.servlet.RESOservlet</servlet-class>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>RESOservlet</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
</web-app>
|
Loading…
Reference in New Issue