You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2013/10/29 13:39:07 UTC
[1/6] git commit: [OLINGO-37] - Archetype support and sample project
- initial
Updated Branches:
refs/heads/master 5a2a8bbc8 -> ed52dd3a2
[OLINGO-37] - Archetype support and sample project - initial
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/da1714db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/da1714db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/da1714db
Branch: refs/heads/master
Commit: da1714dbfc8ce97d4fcf6ba9496f645fbf825718
Parents: 5a2a8bb
Author: Stephan Klevenz <sk...@apache.org>
Authored: Tue Oct 15 14:18:35 2013 +0200
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Tue Oct 29 09:16:50 2013 +0100
----------------------------------------------------------------------
.../AbstractContentNegotiationTest.java | 7 +-
.../BasicContentNegotiationTest.java | 5 +-
.../olingo/odata2/testutil/fit/BaseTest.java | 5 +-
.../odata2/testutil/server/TestServer.java | 9 +-
odata2-sample/cars-archetype/pom.xml | 47 ++++
.../META-INF/maven/archetype-metadata.xml | 33 +++
.../main/resources/archetype-resources/pom.xml | 59 +++++
.../src/main/java/DataStore.java | 152 +++++++++++
.../src/main/java/MyEdmProvider.java | 263 +++++++++++++++++++
.../src/main/java/MyODataSingleProcessor.java | 135 ++++++++++
.../src/main/java/MyServiceFactory.java | 24 ++
.../src/main/resources/log4j.xml | 19 ++
.../src/main/webapp/WEB-INF/web.xml | 31 +++
.../src/main/webapp/index.html | 37 +++
odata2-sample/cars-archetype/src/pom.xml | 30 +++
.../projects/basic/archetype.properties | 5 +
.../src/test/resources/projects/basic/goal.txt | 0
odata2-sample/cars-service/pom.xml | 59 +++++
.../olingo/odata2/sample/service/DataStore.java | 149 +++++++++++
.../odata2/sample/service/MyEdmProvider.java | 260 ++++++++++++++++++
.../sample/service/MyODataSingleProcessor.java | 132 ++++++++++
.../odata2/sample/service/MyServiceFactory.java | 21 ++
.../cars-service/src/main/resources/log4j.xml | 16 ++
.../src/main/webapp/WEB-INF/web.xml | 28 ++
.../cars-service/src/main/webapp/index.html | 34 +++
odata2-sample/pom.xml | 28 ++
pom.xml | 3 +-
27 files changed, 1579 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java
index 64fe803..edfbd27 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/AbstractContentNegotiationTest.java
@@ -42,7 +42,6 @@ import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.log4j.Logger;
import org.apache.olingo.odata2.api.ODataService;
import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.HttpHeaders;
@@ -55,19 +54,21 @@ import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;
import org.apache.olingo.odata2.core.uri.UriType;
import org.apache.olingo.odata2.ref.edm.ScenarioEdmProvider;
import org.apache.olingo.odata2.ref.model.DataContainer;
-import org.apache.olingo.odata2.ref.processor.ListsProcessor;
import org.apache.olingo.odata2.ref.processor.BeanPropertyAccess;
+import org.apache.olingo.odata2.ref.processor.ListsProcessor;
import org.apache.olingo.odata2.ref.processor.ScenarioDataSource;
import org.apache.olingo.odata2.testutil.fit.AbstractFitTest;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.junit.Assert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
*/
public abstract class AbstractContentNegotiationTest extends AbstractFitTest {
- private static final Logger LOG = Logger.getLogger(AbstractContentNegotiationTest.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractContentNegotiationTest.class);
protected final static List<String> ACCEPT_HEADER_VALUES = Arrays.asList(
"", // for requests with no 'Accept' header set
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/BasicContentNegotiationTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/BasicContentNegotiationTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/BasicContentNegotiationTest.java
index 16b8225..b14d97f 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/BasicContentNegotiationTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/BasicContentNegotiationTest.java
@@ -36,19 +36,20 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.log4j.Logger;
import org.apache.olingo.odata2.api.commons.HttpHeaders;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
*/
public class BasicContentNegotiationTest extends AbstractContentNegotiationTest {
- private static final Logger LOG = Logger.getLogger(BasicContentNegotiationTest.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BasicContentNegotiationTest.class);
@Test
public void acceptHeaderAppAtomXml() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/BaseTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/BaseTest.java b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/BaseTest.java
index b1deda1..1612e36 100644
--- a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/BaseTest.java
+++ b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/fit/BaseTest.java
@@ -23,12 +23,13 @@ import java.util.Map;
import java.util.Map.Entry;
import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Provides basic support for JUnit tests<br>
@@ -42,7 +43,7 @@ public abstract class BaseTest {
DOMConfigurator.configureAndWatch("/log4j.xml");
}
- protected final Logger log = Logger.getLogger(this.getClass());
+ protected final Logger log = LoggerFactory.getLogger(this.getClass());
private final Map<Class<?>, Level> disabledLoggings = new HashMap<Class<?>, Level>();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java
index 1a91e05..6be0315 100644
--- a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java
+++ b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/server/TestServer.java
@@ -23,19 +23,20 @@ import java.net.InetSocketAddress;
import java.net.URI;
import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet;
-import org.apache.log4j.Logger;
import org.apache.olingo.odata2.api.ODataService;
import org.apache.olingo.odata2.api.ODataServiceFactory;
import org.apache.olingo.odata2.testutil.fit.FitStaticServiceFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
*/
public class TestServer {
- private static final Logger log = Logger.getLogger(TestServer.class);
+ private static final Logger log = LoggerFactory.getLogger(TestServer.class);
private static final int PORT_MIN = 19000;
private static final int PORT_MAX = 19200;
@@ -87,7 +88,7 @@ public class TestServer {
endpoint = new URI(DEFAULT_SCHEME, null, DEFAULT_HOST, isa.getPort(), "/abc" + path, null, null);
log.trace("Started server at endpoint " + endpoint.toASCIIString());
} catch (final Exception e) {
- log.error(e);
+ log.error("server start failed", e);
throw new ServerRuntimeException(e);
}
}
@@ -115,7 +116,7 @@ public class TestServer {
throw new BindException("no free port in range of [" + PORT_MIN + ".." + PORT_MAX + "]");
}
} catch (final Exception e) {
- log.error(e);
+ log.error("server start failed", e);
throw new ServerRuntimeException(e);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/pom.xml b/odata2-sample/cars-archetype/pom.xml
new file mode 100644
index 0000000..830a672
--- /dev/null
+++ b/odata2-sample/cars-archetype/pom.xml
@@ -0,0 +1,47 @@
+<?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.apache.olingo</groupId>
+ <artifactId>olingo-odata2-sample-cars-service-incubating-archetype</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <packaging>maven-archetype</packaging>
+
+ <name>${project.artifactId}</name>
+
+ <build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-packaging</artifactId>
+ <version>2.2</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>integration-test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/odata2-sample/cars-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644
index 0000000..6a4f0ae
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="olingo-odata2-sample-cars-service-incubating"
+ xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/webapp</directory>
+ <includes>
+ <include>**/*.xml</include>
+ <include>**/*.html</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.xml</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory></directory>
+ <includes>
+ <include>.classpath</include>
+ <include>.project</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</archetype-descriptor>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
new file mode 100644
index 0000000..5ac1469
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,59 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <name>${project.artifactId}</name>
+ <version>${version}</version>
+
+ <packaging>war</packaging>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-archetype</id>
+ <goals>
+ <goal>create-from-project</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-core-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>2.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/DataStore.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/DataStore.java
new file mode 100644
index 0000000..d19a3a9
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/DataStore.java
@@ -0,0 +1,152 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package};
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+public class DataStore {
+
+ // Data accessors
+ public Map<String, Object> getCar(int id) {
+ Map<String, Object> data = null;
+
+ Calendar updated = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ updated.set(2012, 11, 11, 11, 11, 11);
+ data = createCar(1, "F1 W03", 1, 189189.43, "EUR", "2012", updated, "file://imagePath/w03");
+ break;
+
+ case 2:
+ updated.set(2013, 11, 11, 11, 11, 11);
+ data = createCar(2, "F1 W04", 1, 199999.99, "EUR", "2013", updated, "file://imagePath/w04");
+ break;
+
+ case 3:
+ updated.set(2012, 12, 12, 12, 12, 12);
+ data = createCar(3, "F2012", 2, 137285.33, "EUR", "2012", updated, "http://pathToImage/f2012");
+ break;
+
+ case 4:
+ updated.set(2013, 12, 12, 12, 12, 12);
+ data = createCar(4, "F2013", 2, 145285.00, "EUR", "2013", updated, "http://pathToImage/f2013");
+ break;
+
+ case 5:
+ updated.set(2011, 11, 11, 11, 11, 11);
+ data = createCar(5, "F1 W02", 1, 167189.00, "EUR", "2011", updated, "file://imagePath/wXX");
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createCar(int carId, String model, int manufacturerId, double price,
+ String currency, String modelYear, Calendar updated, String imagePath) {
+ Map<String, Object> data = new HashMap<String, Object>();
+
+ data.put("Id", carId);
+ data.put("Model", model);
+ data.put("ManufacturerId", manufacturerId);
+ data.put("Price", price);
+ data.put("Currency", currency);
+ data.put("ModelYear", modelYear);
+ data.put("Updated", updated);
+ data.put("ImagePath", imagePath);
+
+ return data;
+ }
+
+ public Map<String, Object> getManufacturer(int id) {
+ Map<String, Object> data = null;
+ Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ Map<String, Object> addressStar = createAddress("Star Street 137", "Stuttgart", "70173", "Germany");
+ date.set(1954, 7, 4);
+ data = createManufacturer(1, "Star Powered Racing", addressStar, date);
+ break;
+
+ case 2:
+ Map<String, Object> addressHorse = createAddress("Horse Street 1", "Maranello", "41053", "Italy");
+ date.set(1929, 11, 16);
+ data = createManufacturer(2, "Horse Powered Racing", addressHorse, date);
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createManufacturer(int id, String name, Map<String, Object> address, Calendar updated) {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("Id", id);
+ data.put("Name", name);
+ data.put("Address", address);
+ data.put("Updated", updated);
+ return data;
+ }
+
+ private Map<String, Object> createAddress(String street, String city, String zipCode, String country) {
+ Map<String, Object> address = new HashMap<String, Object>();
+ address.put("Street", street);
+ address.put("City", city);
+ address.put("ZipCode", zipCode);
+ address.put("Country", country);
+ return address;
+ }
+
+ public List<Map<String, Object>> getCars() {
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.add(getCar(1));
+ cars.add(getCar(2));
+ cars.add(getCar(3));
+ cars.add(getCar(4));
+ cars.add(getCar(5));
+ return cars;
+ }
+
+ public List<Map<String, Object>> getManufacturers() {
+ List<Map<String, Object>> manufacturers = new ArrayList<Map<String, Object>>();
+ manufacturers.add(getManufacturer(1));
+ manufacturers.add(getManufacturer(2));
+ return manufacturers;
+ }
+
+ public List<Map<String, Object>> getCarsFor(int manufacturerId) {
+ List<Map<String, Object>> cars = getCars();
+ List<Map<String, Object>> carsForManufacturer = new ArrayList<Map<String, Object>>();
+
+ for (Map<String, Object> car : cars) {
+ if (Integer.valueOf(manufacturerId).equals(car.get("ManufacturerId"))) {
+ carsForManufacturer.add(car);
+ }
+ }
+
+ return carsForManufacturer;
+ }
+
+ public Map<String, Object> getManufacturerFor(int carId) {
+ Map<String, Object> car = getCar(carId);
+ if (car != null) {
+ Object manufacturerId = car.get("ManufacturerId");
+ if (manufacturerId != null) {
+ return getManufacturer((Integer) manufacturerId);
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyEdmProvider.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyEdmProvider.java
new file mode 100644
index 0000000..a375f9a
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyEdmProvider.java
@@ -0,0 +1,263 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package};
+
+import java.util.ArrayList;
+import java.util.List;
+
+import ${groupId}.odata2.api.edm.EdmConcurrencyMode;
+import ${groupId}.odata2.api.edm.EdmMultiplicity;
+import ${groupId}.odata2.api.edm.EdmSimpleTypeKind;
+import ${groupId}.odata2.api.edm.EdmTargetPath;
+import ${groupId}.odata2.api.edm.FullQualifiedName;
+import ${groupId}.odata2.api.edm.provider.Association;
+import ${groupId}.odata2.api.edm.provider.AssociationEnd;
+import ${groupId}.odata2.api.edm.provider.AssociationSet;
+import ${groupId}.odata2.api.edm.provider.AssociationSetEnd;
+import ${groupId}.odata2.api.edm.provider.ComplexProperty;
+import ${groupId}.odata2.api.edm.provider.ComplexType;
+import ${groupId}.odata2.api.edm.provider.CustomizableFeedMappings;
+import ${groupId}.odata2.api.edm.provider.EdmProvider;
+import ${groupId}.odata2.api.edm.provider.EntityContainer;
+import ${groupId}.odata2.api.edm.provider.EntityContainerInfo;
+import ${groupId}.odata2.api.edm.provider.EntitySet;
+import ${groupId}.odata2.api.edm.provider.EntityType;
+import ${groupId}.odata2.api.edm.provider.Facets;
+import ${groupId}.odata2.api.edm.provider.FunctionImport;
+import ${groupId}.odata2.api.edm.provider.Key;
+import ${groupId}.odata2.api.edm.provider.NavigationProperty;
+import ${groupId}.odata2.api.edm.provider.Property;
+import ${groupId}.odata2.api.edm.provider.PropertyRef;
+import ${groupId}.odata2.api.edm.provider.ReturnType;
+import ${groupId}.odata2.api.edm.provider.Schema;
+import ${groupId}.odata2.api.edm.provider.SimpleProperty;
+import ${groupId}.odata2.api.exception.ODataException;
+
+public class MyEdmProvider extends EdmProvider {
+
+ static final String ENTITY_SET_NAME_MANUFACTURERS = "Manufacturers";
+ static final String ENTITY_SET_NAME_CARS = "Cars";
+ static final String ENTITY_NAME_MANUFACTURER = "Manufacturer";
+ static final String ENTITY_NAME_CAR = "Car";
+
+ private static final String NAMESPACE = "${groupId}.odata2.ODataCars";
+
+ private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_CAR);
+ private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_MANUFACTURER);
+
+ private static final FullQualifiedName COMPLEX_TYPE = new FullQualifiedName(NAMESPACE, "Address");
+
+ private static final FullQualifiedName ASSOCIATION_CAR_MANUFACTURER = new FullQualifiedName(NAMESPACE,
+ "Car_Manufacturer_Manufacturer_Cars");
+
+ private static final String ROLE_1_1 = "Car_Manufacturer";
+ private static final String ROLE_1_2 = "Manufacturer_Cars";
+
+ private static final String ENTITY_CONTAINER = "ODataCarsEntityContainer";
+
+ private static final String ASSOCIATION_SET = "Cars_Manufacturers";
+
+ private static final String FUNCTION_IMPORT = "NumberOfCars";
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ List<Schema> schemas = new ArrayList<Schema>();
+
+ Schema schema = new Schema();
+ schema.setNamespace(NAMESPACE);
+
+ List<EntityType> entityTypes = new ArrayList<EntityType>();
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
+ schema.setEntityTypes(entityTypes);
+
+ List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ complexTypes.add(getComplexType(COMPLEX_TYPE));
+ schema.setComplexTypes(complexTypes);
+
+ List<Association> associations = new ArrayList<Association>();
+ associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER));
+ schema.setAssociations(associations);
+
+ List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
+ EntityContainer entityContainer = new EntityContainer();
+ entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
+
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS));
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS));
+ entityContainer.setEntitySets(entitySets);
+
+ List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER,
+ ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2));
+ entityContainer.setAssociationSets(associationSets);
+
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT));
+ entityContainer.setFunctionImports(functionImports);
+
+ entityContainers.add(entityContainer);
+ schema.setEntityContainers(entityContainers);
+
+ schemas.add(schema);
+
+ return schemas;
+ }
+
+ @Override
+ public EntityType getEntityType(FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+
+ if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Model").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100).setDefaultValue("Hugo"))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new SimpleProperty().setName("ManufacturerId").setType(EdmSimpleTypeKind.Int32));
+ properties.add(new SimpleProperty().setName("Price").setType(EdmSimpleTypeKind.Decimal));
+ properties.add(new SimpleProperty().setName("Currency").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(3)));
+ properties.add(new SimpleProperty().setName("ModelYear").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(4)));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+ properties.add(new SimpleProperty().setName("ImagePath").setType(EdmSimpleTypeKind.String));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Manufacturer")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_1.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new ComplexProperty().setName("Address").setType(new FullQualifiedName(NAMESPACE, "Address")));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Cars")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_2.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
+ return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Association getAssociation(FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (ASSOCIATION_CAR_MANUFACTURER.getName().equals(edmFQName.getName())) {
+ return new Association().setName(ASSOCIATION_CAR_MANUFACTURER.getName())
+ .setEnd1(
+ new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setEnd2(
+ new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(String entityContainer, String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ENTITY_SET_NAME_CARS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(String entityContainer, FullQualifiedName association,
+ String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ASSOCIATION_CAR_MANUFACTURER.equals(association)) {
+ return new AssociationSet().setName(ASSOCIATION_SET)
+ .setAssociation(ASSOCIATION_CAR_MANUFACTURER)
+ .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_NAME_MANUFACTURERS))
+ .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_NAME_CARS));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(String entityContainer, String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (FUNCTION_IMPORT.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setHttpMethod("GET");
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(String name) throws ODataException {
+ if (name == null || "ODataCarsEntityContainer".equals(name)) {
+ return new EntityContainerInfo().setName("ODataCarsEntityContainer").setDefaultEntityContainer(true);
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyODataSingleProcessor.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyODataSingleProcessor.java
new file mode 100644
index 0000000..b4a08c4
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyODataSingleProcessor.java
@@ -0,0 +1,135 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package};
+
+import static ${package}.MyEdmProvider.ENTITY_SET_NAME_CARS;
+import static ${package}.MyEdmProvider.ENTITY_SET_NAME_MANUFACTURERS;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import ${groupId}.odata2.api.edm.EdmEntitySet;
+import ${groupId}.odata2.api.edm.EdmLiteralKind;
+import ${groupId}.odata2.api.edm.EdmProperty;
+import ${groupId}.odata2.api.edm.EdmSimpleType;
+import ${groupId}.odata2.api.ep.EntityProvider;
+import ${groupId}.odata2.api.ep.EntityProviderWriteProperties;
+import ${groupId}.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
+import ${groupId}.odata2.api.exception.ODataException;
+import ${groupId}.odata2.api.exception.ODataNotFoundException;
+import ${groupId}.odata2.api.exception.ODataNotImplementedException;
+import ${groupId}.odata2.api.processor.ODataResponse;
+import ${groupId}.odata2.api.processor.ODataSingleProcessor;
+import ${groupId}.odata2.api.uri.KeyPredicate;
+import ${groupId}.odata2.api.uri.info.GetEntitySetUriInfo;
+import ${groupId}.odata2.api.uri.info.GetEntityUriInfo;
+
+public class MyODataSingleProcessor extends ODataSingleProcessor {
+
+ private final DataStore dataStore;
+
+ public MyODataSingleProcessor() {
+ dataStore = new DataStore();
+ }
+
+ @Override
+ public ODataResponse readEntitySet(GetEntitySetUriInfo uriInfo, String contentType) throws ODataException {
+
+ EdmEntitySet entitySet;
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ entitySet = uriInfo.getTargetEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.addAll(dataStore.getCarsFor(manufacturerKey));
+
+ return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
+ getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ @Override
+ public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ EdmEntitySet entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getCar(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getManufacturer(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+
+ Map<String, Object> data = null;
+
+ if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ data = dataStore.getManufacturerFor(carKey);
+ }
+
+ if (data != null) {
+ return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
+ data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ private int getKeyValue(KeyPredicate key) throws ODataException {
+ EdmProperty property = key.getProperty();
+ EdmSimpleType type = (EdmSimpleType) property.getType();
+ return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceFactory.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceFactory.java
new file mode 100644
index 0000000..021a241
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceFactory.java
@@ -0,0 +1,24 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package};
+
+import ${groupId}.odata2.api.ODataService;
+import ${groupId}.odata2.api.ODataServiceFactory;
+import ${groupId}.odata2.api.edm.provider.EdmProvider;
+import ${groupId}.odata2.api.exception.ODataException;
+import ${groupId}.odata2.api.processor.ODataContext;
+import ${groupId}.odata2.api.processor.ODataSingleProcessor;
+
+public class MyServiceFactory extends ODataServiceFactory {
+
+ @Override
+ public ODataService createService(ODataContext ctx) throws ODataException {
+
+ EdmProvider edmProvider = new MyEdmProvider();
+
+ ODataSingleProcessor singleProcessor = new MyODataSingleProcessor();
+
+ return createODataSingleProcessorService(edmProvider, singleProcessor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
new file mode 100644
index 0000000..81dc733
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
@@ -0,0 +1,19 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p %c{1} - %m%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <priority value="error" />
+ <appender-ref ref="console" />
+ </root>
+</log4j:configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..c9bcfba
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,31 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <display-name>${groupId}.odata2.sample</display-name>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+
+ <servlet>
+ <servlet-name>MyODataSampleServlet</servlet-name>
+ <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>${groupId}.odata2.core.rest.app.ODataApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>${groupId}.odata2.service.factory</param-name>
+ <param-value>${package}.MyServiceFactory</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>MyODataSampleServlet</servlet-name>
+ <url-pattern>/MyODataSample.svc/*</url-pattern>
+ </servlet-mapping>
+</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
new file mode 100644
index 0000000..d0b1c39
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
@@ -0,0 +1,37 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <h1>My OData Sample Project</h1>
+ <div>
+ <ul>
+ <li><a href="MyODataSample.svc">Link to Sample Service Root - /MyODataSample.svc</a></li>
+ <li><a href="MyODataSample.svc/${symbol_dollar}metadata">Link to Sample Service Metadata - /MyODataSample.svc/${symbol_dollar}metadata</a></li>
+ </ul>
+ </div>
+ <div>
+ <ul>
+ <li>Entity Sets
+ <ul>
+ <li><a href="MyODataSample.svc/Cars">/Cars</a></li>
+ <li><a href="MyODataSample.svc/Manufacturers">/Manufacturers</a></li>
+ </ul>
+ </li>
+ <li>Sample Entities
+ <ul>
+ <li><a href="MyODataSample.svc/Cars(1)">/Cars(1)</a></li>
+ <li><a href="MyODataSample.svc/Cars(3)">/Cars(3)</a></li>
+ <li><a href="MyODataSample.svc/Cars(3)/Manufacturer">/Cars(3)/Manufacturer</a></li>
+ <li><a href="MyODataSample.svc/Manufacturers(1)">/Manufacturers(1)</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ </body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/pom.xml b/odata2-sample/cars-archetype/src/pom.xml
new file mode 100644
index 0000000..346e421
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/pom.xml
@@ -0,0 +1,30 @@
+<?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.apache.olingo</groupId>
+ <artifactId>olingo-odata2-sample-cars-service-incubating-archetype</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <packaging>maven-archetype</packaging>
+
+ <name>olingo-odata2-sample-cars-service-incubating-archetype</name>
+
+ <build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-packaging</artifactId>
+ <version>2.2</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties b/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
new file mode 100644
index 0000000..3e458e2
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
@@ -0,0 +1,5 @@
+#Tue Oct 29 09:14:13 CET 2013
+package=it.pkg
+version=0.1-SNAPSHOT
+groupId=archetype.it
+artifactId=basic
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-archetype/src/test/resources/projects/basic/goal.txt
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/test/resources/projects/basic/goal.txt b/odata2-sample/cars-archetype/src/test/resources/projects/basic/goal.txt
new file mode 100644
index 0000000..e69de29
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-service/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/pom.xml b/odata2-sample/cars-service/pom.xml
new file mode 100755
index 0000000..7174919
--- /dev/null
+++ b/odata2-sample/cars-service/pom.xml
@@ -0,0 +1,59 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-sample-cars-service-incubating</artifactId>
+ <name>${project.artifactId}</name>
+ <version>1.1.0-SNAPSHOT</version>
+
+ <packaging>war</packaging>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-archetype</id>
+ <goals>
+ <goal>create-from-project</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-core-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>2.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java
new file mode 100644
index 0000000..935abbf
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java
@@ -0,0 +1,149 @@
+package org.apache.olingo.odata2.sample.service;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+public class DataStore {
+
+ // Data accessors
+ public Map<String, Object> getCar(int id) {
+ Map<String, Object> data = null;
+
+ Calendar updated = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ updated.set(2012, 11, 11, 11, 11, 11);
+ data = createCar(1, "F1 W03", 1, 189189.43, "EUR", "2012", updated, "file://imagePath/w03");
+ break;
+
+ case 2:
+ updated.set(2013, 11, 11, 11, 11, 11);
+ data = createCar(2, "F1 W04", 1, 199999.99, "EUR", "2013", updated, "file://imagePath/w04");
+ break;
+
+ case 3:
+ updated.set(2012, 12, 12, 12, 12, 12);
+ data = createCar(3, "F2012", 2, 137285.33, "EUR", "2012", updated, "http://pathToImage/f2012");
+ break;
+
+ case 4:
+ updated.set(2013, 12, 12, 12, 12, 12);
+ data = createCar(4, "F2013", 2, 145285.00, "EUR", "2013", updated, "http://pathToImage/f2013");
+ break;
+
+ case 5:
+ updated.set(2011, 11, 11, 11, 11, 11);
+ data = createCar(5, "F1 W02", 1, 167189.00, "EUR", "2011", updated, "file://imagePath/wXX");
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createCar(int carId, String model, int manufacturerId, double price,
+ String currency, String modelYear, Calendar updated, String imagePath) {
+ Map<String, Object> data = new HashMap<String, Object>();
+
+ data.put("Id", carId);
+ data.put("Model", model);
+ data.put("ManufacturerId", manufacturerId);
+ data.put("Price", price);
+ data.put("Currency", currency);
+ data.put("ModelYear", modelYear);
+ data.put("Updated", updated);
+ data.put("ImagePath", imagePath);
+
+ return data;
+ }
+
+ public Map<String, Object> getManufacturer(int id) {
+ Map<String, Object> data = null;
+ Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ Map<String, Object> addressStar = createAddress("Star Street 137", "Stuttgart", "70173", "Germany");
+ date.set(1954, 7, 4);
+ data = createManufacturer(1, "Star Powered Racing", addressStar, date);
+ break;
+
+ case 2:
+ Map<String, Object> addressHorse = createAddress("Horse Street 1", "Maranello", "41053", "Italy");
+ date.set(1929, 11, 16);
+ data = createManufacturer(2, "Horse Powered Racing", addressHorse, date);
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createManufacturer(int id, String name, Map<String, Object> address, Calendar updated) {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("Id", id);
+ data.put("Name", name);
+ data.put("Address", address);
+ data.put("Updated", updated);
+ return data;
+ }
+
+ private Map<String, Object> createAddress(String street, String city, String zipCode, String country) {
+ Map<String, Object> address = new HashMap<String, Object>();
+ address.put("Street", street);
+ address.put("City", city);
+ address.put("ZipCode", zipCode);
+ address.put("Country", country);
+ return address;
+ }
+
+ public List<Map<String, Object>> getCars() {
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.add(getCar(1));
+ cars.add(getCar(2));
+ cars.add(getCar(3));
+ cars.add(getCar(4));
+ cars.add(getCar(5));
+ return cars;
+ }
+
+ public List<Map<String, Object>> getManufacturers() {
+ List<Map<String, Object>> manufacturers = new ArrayList<Map<String, Object>>();
+ manufacturers.add(getManufacturer(1));
+ manufacturers.add(getManufacturer(2));
+ return manufacturers;
+ }
+
+ public List<Map<String, Object>> getCarsFor(int manufacturerId) {
+ List<Map<String, Object>> cars = getCars();
+ List<Map<String, Object>> carsForManufacturer = new ArrayList<Map<String, Object>>();
+
+ for (Map<String, Object> car : cars) {
+ if (Integer.valueOf(manufacturerId).equals(car.get("ManufacturerId"))) {
+ carsForManufacturer.add(car);
+ }
+ }
+
+ return carsForManufacturer;
+ }
+
+ public Map<String, Object> getManufacturerFor(int carId) {
+ Map<String, Object> car = getCar(carId);
+ if (car != null) {
+ Object manufacturerId = car.get("ManufacturerId");
+ if (manufacturerId != null) {
+ return getManufacturer((Integer) manufacturerId);
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java
new file mode 100755
index 0000000..0d7ccda
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java
@@ -0,0 +1,260 @@
+package org.apache.olingo.odata2.sample.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTargetPath;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.CustomizableFeedMappings;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.ReturnType;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+
+public class MyEdmProvider extends EdmProvider {
+
+ static final String ENTITY_SET_NAME_MANUFACTURERS = "Manufacturers";
+ static final String ENTITY_SET_NAME_CARS = "Cars";
+ static final String ENTITY_NAME_MANUFACTURER = "Manufacturer";
+ static final String ENTITY_NAME_CAR = "Car";
+
+ private static final String NAMESPACE = "org.apache.olingo.odata2.ODataCars";
+
+ private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_CAR);
+ private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_MANUFACTURER);
+
+ private static final FullQualifiedName COMPLEX_TYPE = new FullQualifiedName(NAMESPACE, "Address");
+
+ private static final FullQualifiedName ASSOCIATION_CAR_MANUFACTURER = new FullQualifiedName(NAMESPACE,
+ "Car_Manufacturer_Manufacturer_Cars");
+
+ private static final String ROLE_1_1 = "Car_Manufacturer";
+ private static final String ROLE_1_2 = "Manufacturer_Cars";
+
+ private static final String ENTITY_CONTAINER = "ODataCarsEntityContainer";
+
+ private static final String ASSOCIATION_SET = "Cars_Manufacturers";
+
+ private static final String FUNCTION_IMPORT = "NumberOfCars";
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ List<Schema> schemas = new ArrayList<Schema>();
+
+ Schema schema = new Schema();
+ schema.setNamespace(NAMESPACE);
+
+ List<EntityType> entityTypes = new ArrayList<EntityType>();
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
+ schema.setEntityTypes(entityTypes);
+
+ List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ complexTypes.add(getComplexType(COMPLEX_TYPE));
+ schema.setComplexTypes(complexTypes);
+
+ List<Association> associations = new ArrayList<Association>();
+ associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER));
+ schema.setAssociations(associations);
+
+ List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
+ EntityContainer entityContainer = new EntityContainer();
+ entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
+
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS));
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS));
+ entityContainer.setEntitySets(entitySets);
+
+ List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER,
+ ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2));
+ entityContainer.setAssociationSets(associationSets);
+
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT));
+ entityContainer.setFunctionImports(functionImports);
+
+ entityContainers.add(entityContainer);
+ schema.setEntityContainers(entityContainers);
+
+ schemas.add(schema);
+
+ return schemas;
+ }
+
+ @Override
+ public EntityType getEntityType(FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+
+ if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Model").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100).setDefaultValue("Hugo"))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new SimpleProperty().setName("ManufacturerId").setType(EdmSimpleTypeKind.Int32));
+ properties.add(new SimpleProperty().setName("Price").setType(EdmSimpleTypeKind.Decimal));
+ properties.add(new SimpleProperty().setName("Currency").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(3)));
+ properties.add(new SimpleProperty().setName("ModelYear").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(4)));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+ properties.add(new SimpleProperty().setName("ImagePath").setType(EdmSimpleTypeKind.String));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Manufacturer")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_1.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new ComplexProperty().setName("Address").setType(new FullQualifiedName(NAMESPACE, "Address")));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Cars")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_2.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
+ return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Association getAssociation(FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (ASSOCIATION_CAR_MANUFACTURER.getName().equals(edmFQName.getName())) {
+ return new Association().setName(ASSOCIATION_CAR_MANUFACTURER.getName())
+ .setEnd1(
+ new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setEnd2(
+ new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(String entityContainer, String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ENTITY_SET_NAME_CARS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(String entityContainer, FullQualifiedName association,
+ String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ASSOCIATION_CAR_MANUFACTURER.equals(association)) {
+ return new AssociationSet().setName(ASSOCIATION_SET)
+ .setAssociation(ASSOCIATION_CAR_MANUFACTURER)
+ .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_NAME_MANUFACTURERS))
+ .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_NAME_CARS));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(String entityContainer, String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (FUNCTION_IMPORT.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setHttpMethod("GET");
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(String name) throws ODataException {
+ if (name == null || "ODataCarsEntityContainer".equals(name)) {
+ return new EntityContainerInfo().setName("ODataCarsEntityContainer").setDefaultEntityContainer(true);
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java
new file mode 100755
index 0000000..8ebfea5
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java
@@ -0,0 +1,132 @@
+package org.apache.olingo.odata2.sample.service;
+
+import static org.apache.olingo.odata2.sample.service.MyEdmProvider.ENTITY_SET_NAME_CARS;
+import static org.apache.olingo.odata2.sample.service.MyEdmProvider.ENTITY_SET_NAME_MANUFACTURERS;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+
+public class MyODataSingleProcessor extends ODataSingleProcessor {
+
+ private final DataStore dataStore;
+
+ public MyODataSingleProcessor() {
+ dataStore = new DataStore();
+ }
+
+ @Override
+ public ODataResponse readEntitySet(GetEntitySetUriInfo uriInfo, String contentType) throws ODataException {
+
+ EdmEntitySet entitySet;
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ entitySet = uriInfo.getTargetEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.addAll(dataStore.getCarsFor(manufacturerKey));
+
+ return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
+ getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ @Override
+ public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ EdmEntitySet entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getCar(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getManufacturer(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+
+ Map<String, Object> data = null;
+
+ if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ data = dataStore.getManufacturerFor(carKey);
+ }
+
+ if (data != null) {
+ return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
+ data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ private int getKeyValue(KeyPredicate key) throws ODataException {
+ EdmProperty property = key.getProperty();
+ EdmSimpleType type = (EdmSimpleType) property.getType();
+ return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java
new file mode 100755
index 0000000..c15cb18
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java
@@ -0,0 +1,21 @@
+package org.apache.olingo.odata2.sample.service;
+
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+
+public class MyServiceFactory extends ODataServiceFactory {
+
+ @Override
+ public ODataService createService(ODataContext ctx) throws ODataException {
+
+ EdmProvider edmProvider = new MyEdmProvider();
+
+ ODataSingleProcessor singleProcessor = new MyODataSingleProcessor();
+
+ return createODataSingleProcessorService(edmProvider, singleProcessor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-service/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/resources/log4j.xml b/odata2-sample/cars-service/src/main/resources/log4j.xml
new file mode 100644
index 0000000..616e2d5
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/resources/log4j.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p %c{1} - %m%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <priority value="error" />
+ <appender-ref ref="console" />
+ </root>
+</log4j:configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml b/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
new file mode 100755
index 0000000..e1ad1fb
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+ <display-name>org.apache.olingo.odata2.sample</display-name>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+
+ <servlet>
+ <servlet-name>MyODataSampleServlet</servlet-name>
+ <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>org.apache.olingo.odata2.service.factory</param-name>
+ <param-value>org.apache.olingo.odata2.sample.service.MyServiceFactory</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>MyODataSampleServlet</servlet-name>
+ <url-pattern>/MyODataSample.svc/*</url-pattern>
+ </servlet-mapping>
+</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/cars-service/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/webapp/index.html b/odata2-sample/cars-service/src/main/webapp/index.html
new file mode 100644
index 0000000..7b5d183
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/webapp/index.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <h1>My OData Sample Project</h1>
+ <div>
+ <ul>
+ <li><a href="MyODataSample.svc">Link to Sample Service Root - /MyODataSample.svc</a></li>
+ <li><a href="MyODataSample.svc/$metadata">Link to Sample Service Metadata - /MyODataSample.svc/$metadata</a></li>
+ </ul>
+ </div>
+ <div>
+ <ul>
+ <li>Entity Sets
+ <ul>
+ <li><a href="MyODataSample.svc/Cars">/Cars</a></li>
+ <li><a href="MyODataSample.svc/Manufacturers">/Manufacturers</a></li>
+ </ul>
+ </li>
+ <li>Sample Entities
+ <ul>
+ <li><a href="MyODataSample.svc/Cars(1)">/Cars(1)</a></li>
+ <li><a href="MyODataSample.svc/Cars(3)">/Cars(3)</a></li>
+ <li><a href="MyODataSample.svc/Cars(3)/Manufacturer">/Cars(3)/Manufacturer</a></li>
+ <li><a href="MyODataSample.svc/Manufacturers(1)">/Manufacturers(1)</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ </body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/odata2-sample/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/pom.xml b/odata2-sample/pom.xml
new file mode 100644
index 0000000..86cdeb0
--- /dev/null
+++ b/odata2-sample/pom.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<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>
+
+ <artifactId>olingo-odata2-sample</artifactId>
+ <packaging>pom</packaging>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-parent-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <modules>
+ <module>cars-service</module>
+ <module>cars-archetype</module>
+ </modules>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/da1714db/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a1a4eab..45b2684 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,7 @@
<module>odata2-lib</module>
<module>odata2-processor-jpa</module>
<module>odata2-dist</module>
+ <module>odata2-sample</module>
</modules>
<build>
@@ -152,7 +153,7 @@
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
- </plugins>
+ </plugins>
</pluginManagement>
<plugins>
<plugin>
[2/6] [OLINGO-37] - Archetype support and sample project - refactor
sample
Posted by sk...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarEdmProvider.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarEdmProvider.java
new file mode 100755
index 0000000..c274ece
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarEdmProvider.java
@@ -0,0 +1,278 @@
+/*******************************************************************************
+ * 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.odata2.sample.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTargetPath;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.CustomizableFeedMappings;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.ReturnType;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+
+public class CarEdmProvider extends EdmProvider {
+
+ static final String ENTITY_SET_NAME_MANUFACTURERS = "Manufacturers";
+ static final String ENTITY_SET_NAME_CARS = "Cars";
+ static final String ENTITY_NAME_MANUFACTURER = "Manufacturer";
+ static final String ENTITY_NAME_CAR = "Car";
+
+ private static final String NAMESPACE = "org.apache.olingo.odata2.ODataCars";
+
+ private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_CAR);
+ private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_MANUFACTURER);
+
+ private static final FullQualifiedName COMPLEX_TYPE = new FullQualifiedName(NAMESPACE, "Address");
+
+ private static final FullQualifiedName ASSOCIATION_CAR_MANUFACTURER = new FullQualifiedName(NAMESPACE,
+ "Car_Manufacturer_Manufacturer_Cars");
+
+ private static final String ROLE_1_1 = "Car_Manufacturer";
+ private static final String ROLE_1_2 = "Manufacturer_Cars";
+
+ private static final String ENTITY_CONTAINER = "ODataCarsEntityContainer";
+
+ private static final String ASSOCIATION_SET = "Cars_Manufacturers";
+
+ private static final String FUNCTION_IMPORT = "NumberOfCars";
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ List<Schema> schemas = new ArrayList<Schema>();
+
+ Schema schema = new Schema();
+ schema.setNamespace(NAMESPACE);
+
+ List<EntityType> entityTypes = new ArrayList<EntityType>();
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
+ schema.setEntityTypes(entityTypes);
+
+ List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ complexTypes.add(getComplexType(COMPLEX_TYPE));
+ schema.setComplexTypes(complexTypes);
+
+ List<Association> associations = new ArrayList<Association>();
+ associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER));
+ schema.setAssociations(associations);
+
+ List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
+ EntityContainer entityContainer = new EntityContainer();
+ entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
+
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS));
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS));
+ entityContainer.setEntitySets(entitySets);
+
+ List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER,
+ ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2));
+ entityContainer.setAssociationSets(associationSets);
+
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT));
+ entityContainer.setFunctionImports(functionImports);
+
+ entityContainers.add(entityContainer);
+ schema.setEntityContainers(entityContainers);
+
+ schemas.add(schema);
+
+ return schemas;
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+
+ if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Model").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100).setDefaultValue("Hugo"))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new SimpleProperty().setName("ManufacturerId").setType(EdmSimpleTypeKind.Int32));
+ properties.add(new SimpleProperty().setName("Price").setType(EdmSimpleTypeKind.Decimal));
+ properties.add(new SimpleProperty().setName("Currency").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(3)));
+ properties.add(new SimpleProperty().setName("ModelYear").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(4)));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+ properties.add(new SimpleProperty().setName("ImagePath").setType(EdmSimpleTypeKind.String));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Manufacturer")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_1.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new ComplexProperty().setName("Address").setType(new FullQualifiedName(NAMESPACE, "Address")));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Cars")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_2.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
+ return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (ASSOCIATION_CAR_MANUFACTURER.getName().equals(edmFQName.getName())) {
+ return new Association().setName(ASSOCIATION_CAR_MANUFACTURER.getName())
+ .setEnd1(
+ new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setEnd2(
+ new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ENTITY_SET_NAME_CARS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association,
+ final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ASSOCIATION_CAR_MANUFACTURER.equals(association)) {
+ return new AssociationSet().setName(ASSOCIATION_SET)
+ .setAssociation(ASSOCIATION_CAR_MANUFACTURER)
+ .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_NAME_MANUFACTURERS))
+ .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_NAME_CARS));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (FUNCTION_IMPORT.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setHttpMethod("GET");
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataException {
+ if (name == null || "ODataCarsEntityContainer".equals(name)) {
+ return new EntityContainerInfo().setName("ODataCarsEntityContainer").setDefaultEntityContainer(true);
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarODataSingleProcessor.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarODataSingleProcessor.java
new file mode 100755
index 0000000..8ee7f88
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarODataSingleProcessor.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * 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.odata2.sample.service;
+
+import static org.apache.olingo.odata2.sample.service.CarEdmProvider.ENTITY_SET_NAME_CARS;
+import static org.apache.olingo.odata2.sample.service.CarEdmProvider.ENTITY_SET_NAME_MANUFACTURERS;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+
+public class CarODataSingleProcessor extends ODataSingleProcessor {
+
+ private final CarDataStore dataStore;
+
+ public CarODataSingleProcessor() {
+ dataStore = new CarDataStore();
+ }
+
+ @Override
+ public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
+ throws ODataException {
+
+ EdmEntitySet entitySet;
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ entitySet = uriInfo.getTargetEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.addAll(dataStore.getCarsFor(manufacturerKey));
+
+ return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
+ getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ @Override
+ public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ EdmEntitySet entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getCar(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getManufacturer(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+
+ Map<String, Object> data = null;
+
+ if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ data = dataStore.getManufacturerFor(carKey);
+ }
+
+ if (data != null) {
+ return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
+ data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ private int getKeyValue(final KeyPredicate key) throws ODataException {
+ EdmProperty property = key.getProperty();
+ EdmSimpleType type = (EdmSimpleType) property.getType();
+ return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarServiceFactory.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarServiceFactory.java
new file mode 100755
index 0000000..82dc7ba
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarServiceFactory.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.sample.service;
+
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+
+public class CarServiceFactory extends ODataServiceFactory {
+
+ @Override
+ public ODataService createService(final ODataContext ctx) throws ODataException {
+
+ EdmProvider edmProvider = new CarEdmProvider();
+
+ ODataSingleProcessor singleProcessor = new CarODataSingleProcessor();
+
+ return createODataSingleProcessorService(edmProvider, singleProcessor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java
deleted file mode 100644
index 935abbf..0000000
--- a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package org.apache.olingo.odata2.sample.service;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-
-public class DataStore {
-
- // Data accessors
- public Map<String, Object> getCar(int id) {
- Map<String, Object> data = null;
-
- Calendar updated = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
- switch (id) {
- case 1:
- updated.set(2012, 11, 11, 11, 11, 11);
- data = createCar(1, "F1 W03", 1, 189189.43, "EUR", "2012", updated, "file://imagePath/w03");
- break;
-
- case 2:
- updated.set(2013, 11, 11, 11, 11, 11);
- data = createCar(2, "F1 W04", 1, 199999.99, "EUR", "2013", updated, "file://imagePath/w04");
- break;
-
- case 3:
- updated.set(2012, 12, 12, 12, 12, 12);
- data = createCar(3, "F2012", 2, 137285.33, "EUR", "2012", updated, "http://pathToImage/f2012");
- break;
-
- case 4:
- updated.set(2013, 12, 12, 12, 12, 12);
- data = createCar(4, "F2013", 2, 145285.00, "EUR", "2013", updated, "http://pathToImage/f2013");
- break;
-
- case 5:
- updated.set(2011, 11, 11, 11, 11, 11);
- data = createCar(5, "F1 W02", 1, 167189.00, "EUR", "2011", updated, "file://imagePath/wXX");
- break;
-
- default:
- break;
- }
-
- return data;
- }
-
- private Map<String, Object> createCar(int carId, String model, int manufacturerId, double price,
- String currency, String modelYear, Calendar updated, String imagePath) {
- Map<String, Object> data = new HashMap<String, Object>();
-
- data.put("Id", carId);
- data.put("Model", model);
- data.put("ManufacturerId", manufacturerId);
- data.put("Price", price);
- data.put("Currency", currency);
- data.put("ModelYear", modelYear);
- data.put("Updated", updated);
- data.put("ImagePath", imagePath);
-
- return data;
- }
-
- public Map<String, Object> getManufacturer(int id) {
- Map<String, Object> data = null;
- Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
- switch (id) {
- case 1:
- Map<String, Object> addressStar = createAddress("Star Street 137", "Stuttgart", "70173", "Germany");
- date.set(1954, 7, 4);
- data = createManufacturer(1, "Star Powered Racing", addressStar, date);
- break;
-
- case 2:
- Map<String, Object> addressHorse = createAddress("Horse Street 1", "Maranello", "41053", "Italy");
- date.set(1929, 11, 16);
- data = createManufacturer(2, "Horse Powered Racing", addressHorse, date);
- break;
-
- default:
- break;
- }
-
- return data;
- }
-
- private Map<String, Object> createManufacturer(int id, String name, Map<String, Object> address, Calendar updated) {
- Map<String, Object> data = new HashMap<String, Object>();
- data.put("Id", id);
- data.put("Name", name);
- data.put("Address", address);
- data.put("Updated", updated);
- return data;
- }
-
- private Map<String, Object> createAddress(String street, String city, String zipCode, String country) {
- Map<String, Object> address = new HashMap<String, Object>();
- address.put("Street", street);
- address.put("City", city);
- address.put("ZipCode", zipCode);
- address.put("Country", country);
- return address;
- }
-
- public List<Map<String, Object>> getCars() {
- List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
- cars.add(getCar(1));
- cars.add(getCar(2));
- cars.add(getCar(3));
- cars.add(getCar(4));
- cars.add(getCar(5));
- return cars;
- }
-
- public List<Map<String, Object>> getManufacturers() {
- List<Map<String, Object>> manufacturers = new ArrayList<Map<String, Object>>();
- manufacturers.add(getManufacturer(1));
- manufacturers.add(getManufacturer(2));
- return manufacturers;
- }
-
- public List<Map<String, Object>> getCarsFor(int manufacturerId) {
- List<Map<String, Object>> cars = getCars();
- List<Map<String, Object>> carsForManufacturer = new ArrayList<Map<String, Object>>();
-
- for (Map<String, Object> car : cars) {
- if (Integer.valueOf(manufacturerId).equals(car.get("ManufacturerId"))) {
- carsForManufacturer.add(car);
- }
- }
-
- return carsForManufacturer;
- }
-
- public Map<String, Object> getManufacturerFor(int carId) {
- Map<String, Object> car = getCar(carId);
- if (car != null) {
- Object manufacturerId = car.get("ManufacturerId");
- if (manufacturerId != null) {
- return getManufacturer((Integer) manufacturerId);
- }
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java
deleted file mode 100755
index 0d7ccda..0000000
--- a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java
+++ /dev/null
@@ -1,260 +0,0 @@
-package org.apache.olingo.odata2.sample.service;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTargetPath;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.CustomizableFeedMappings;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Facets;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.Key;
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata2.api.edm.provider.ReturnType;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.api.exception.ODataException;
-
-public class MyEdmProvider extends EdmProvider {
-
- static final String ENTITY_SET_NAME_MANUFACTURERS = "Manufacturers";
- static final String ENTITY_SET_NAME_CARS = "Cars";
- static final String ENTITY_NAME_MANUFACTURER = "Manufacturer";
- static final String ENTITY_NAME_CAR = "Car";
-
- private static final String NAMESPACE = "org.apache.olingo.odata2.ODataCars";
-
- private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_CAR);
- private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_MANUFACTURER);
-
- private static final FullQualifiedName COMPLEX_TYPE = new FullQualifiedName(NAMESPACE, "Address");
-
- private static final FullQualifiedName ASSOCIATION_CAR_MANUFACTURER = new FullQualifiedName(NAMESPACE,
- "Car_Manufacturer_Manufacturer_Cars");
-
- private static final String ROLE_1_1 = "Car_Manufacturer";
- private static final String ROLE_1_2 = "Manufacturer_Cars";
-
- private static final String ENTITY_CONTAINER = "ODataCarsEntityContainer";
-
- private static final String ASSOCIATION_SET = "Cars_Manufacturers";
-
- private static final String FUNCTION_IMPORT = "NumberOfCars";
-
- @Override
- public List<Schema> getSchemas() throws ODataException {
- List<Schema> schemas = new ArrayList<Schema>();
-
- Schema schema = new Schema();
- schema.setNamespace(NAMESPACE);
-
- List<EntityType> entityTypes = new ArrayList<EntityType>();
- entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
- entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
- schema.setEntityTypes(entityTypes);
-
- List<ComplexType> complexTypes = new ArrayList<ComplexType>();
- complexTypes.add(getComplexType(COMPLEX_TYPE));
- schema.setComplexTypes(complexTypes);
-
- List<Association> associations = new ArrayList<Association>();
- associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER));
- schema.setAssociations(associations);
-
- List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
- EntityContainer entityContainer = new EntityContainer();
- entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
-
- List<EntitySet> entitySets = new ArrayList<EntitySet>();
- entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS));
- entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS));
- entityContainer.setEntitySets(entitySets);
-
- List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
- associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER,
- ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2));
- entityContainer.setAssociationSets(associationSets);
-
- List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
- functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT));
- entityContainer.setFunctionImports(functionImports);
-
- entityContainers.add(entityContainer);
- schema.setEntityContainers(entityContainers);
-
- schemas.add(schema);
-
- return schemas;
- }
-
- @Override
- public EntityType getEntityType(FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
-
- if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
-
- // Properties
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
- new Facets().setNullable(false)));
- properties.add(new SimpleProperty().setName("Model").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setNullable(false).setMaxLength(100).setDefaultValue("Hugo"))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
- properties.add(new SimpleProperty().setName("ManufacturerId").setType(EdmSimpleTypeKind.Int32));
- properties.add(new SimpleProperty().setName("Price").setType(EdmSimpleTypeKind.Decimal));
- properties.add(new SimpleProperty().setName("Currency").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setMaxLength(3)));
- properties.add(new SimpleProperty().setName("ModelYear").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setMaxLength(4)));
- properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
- .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
- properties.add(new SimpleProperty().setName("ImagePath").setType(EdmSimpleTypeKind.String));
-
- // Navigation Properties
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("Manufacturer")
- .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
-
- // Key
- List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
- keyProperties.add(new PropertyRef().setName("Id"));
- Key key = new Key().setKeys(keyProperties);
-
- return new EntityType().setName(ENTITY_TYPE_1_1.getName())
- .setProperties(properties)
- .setKey(key)
- .setNavigationProperties(navigationProperties);
-
- } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
-
- // Properties
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
- new Facets().setNullable(false)));
- properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setNullable(false).setMaxLength(100))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
- properties.add(new ComplexProperty().setName("Address").setType(new FullQualifiedName(NAMESPACE, "Address")));
- properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
- .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
-
- // Navigation Properties
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("Cars")
- .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
-
- // Key
- List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
- keyProperties.add(new PropertyRef().setName("Id"));
- Key key = new Key().setKeys(keyProperties);
-
- return new EntityType().setName(ENTITY_TYPE_1_2.getName())
- .setProperties(properties)
- .setKey(key)
- .setNavigationProperties(navigationProperties);
-
- }
- }
-
- return null;
- }
-
- @Override
- public ComplexType getComplexType(FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
- if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
- return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
- }
- }
-
- return null;
- }
-
- @Override
- public Association getAssociation(FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
- if (ASSOCIATION_CAR_MANUFACTURER.getName().equals(edmFQName.getName())) {
- return new Association().setName(ASSOCIATION_CAR_MANUFACTURER.getName())
- .setEnd1(
- new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
- .setEnd2(
- new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
- }
- }
- return null;
- }
-
- @Override
- public EntitySet getEntitySet(String entityContainer, String name) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (ENTITY_SET_NAME_CARS.equals(name)) {
- return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
- return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
- }
- }
- return null;
- }
-
- @Override
- public AssociationSet getAssociationSet(String entityContainer, FullQualifiedName association,
- String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (ASSOCIATION_CAR_MANUFACTURER.equals(association)) {
- return new AssociationSet().setName(ASSOCIATION_SET)
- .setAssociation(ASSOCIATION_CAR_MANUFACTURER)
- .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_NAME_MANUFACTURERS))
- .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_NAME_CARS));
- }
- }
- return null;
- }
-
- @Override
- public FunctionImport getFunctionImport(String entityContainer, String name) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (FUNCTION_IMPORT.equals(name)) {
- return new FunctionImport().setName(name)
- .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
- .setHttpMethod("GET");
- }
- }
- return null;
- }
-
- @Override
- public EntityContainerInfo getEntityContainerInfo(String name) throws ODataException {
- if (name == null || "ODataCarsEntityContainer".equals(name)) {
- return new EntityContainerInfo().setName("ODataCarsEntityContainer").setDefaultEntityContainer(true);
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java
deleted file mode 100755
index 8ebfea5..0000000
--- a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package org.apache.olingo.odata2.sample.service;
-
-import static org.apache.olingo.odata2.sample.service.MyEdmProvider.ENTITY_SET_NAME_CARS;
-import static org.apache.olingo.odata2.sample.service.MyEdmProvider.ENTITY_SET_NAME_MANUFACTURERS;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-
-public class MyODataSingleProcessor extends ODataSingleProcessor {
-
- private final DataStore dataStore;
-
- public MyODataSingleProcessor() {
- dataStore = new DataStore();
- }
-
- @Override
- public ODataResponse readEntitySet(GetEntitySetUriInfo uriInfo, String contentType) throws ODataException {
-
- EdmEntitySet entitySet;
-
- if (uriInfo.getNavigationSegments().size() == 0) {
- entitySet = uriInfo.getStartEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
-
- } else if (uriInfo.getNavigationSegments().size() == 1) {
- // navigation first level, simplified example for illustration purposes only
- entitySet = uriInfo.getTargetEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
-
- List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
- cars.addAll(dataStore.getCarsFor(manufacturerKey));
-
- return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
- getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- throw new ODataNotImplementedException();
- }
-
- @Override
- public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
-
- if (uriInfo.getNavigationSegments().size() == 0) {
- EdmEntitySet entitySet = uriInfo.getStartEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
- Map<String, Object> data = dataStore.getCar(id);
-
- if (data != null) {
- URI serviceRoot = getContext().getPathInfo().getServiceRoot();
- ODataEntityProviderPropertiesBuilder propertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(serviceRoot);
-
- return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
- }
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
- Map<String, Object> data = dataStore.getManufacturer(id);
-
- if (data != null) {
- URI serviceRoot = getContext().getPathInfo().getServiceRoot();
- ODataEntityProviderPropertiesBuilder propertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(serviceRoot);
-
- return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
- }
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
-
- } else if (uriInfo.getNavigationSegments().size() == 1) {
- // navigation first level, simplified example for illustration purposes only
- EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
-
- Map<String, Object> data = null;
-
- if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
- data = dataStore.getManufacturerFor(carKey);
- }
-
- if (data != null) {
- return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
- data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- throw new ODataNotImplementedException();
- }
-
- private int getKeyValue(KeyPredicate key) throws ODataException {
- EdmProperty property = key.getProperty();
- EdmSimpleType type = (EdmSimpleType) property.getType();
- return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java
deleted file mode 100755
index c15cb18..0000000
--- a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.apache.olingo.odata2.sample.service;
-
-import org.apache.olingo.odata2.api.ODataService;
-import org.apache.olingo.odata2.api.ODataServiceFactory;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-
-public class MyServiceFactory extends ODataServiceFactory {
-
- @Override
- public ODataService createService(ODataContext ctx) throws ODataException {
-
- EdmProvider edmProvider = new MyEdmProvider();
-
- ODataSingleProcessor singleProcessor = new MyODataSingleProcessor();
-
- return createODataSingleProcessorService(edmProvider, singleProcessor);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/resources/log4j.xml b/odata2-sample/cars-service/src/main/resources/log4j.xml
index 616e2d5..aa456fb 100644
--- a/odata2-sample/cars-service/src/main/resources/log4j.xml
+++ b/odata2-sample/cars-service/src/main/resources/log4j.xml
@@ -1,6 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ 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.
+-->
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
-
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml b/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
index e1ad1fb..e3d1f41 100755
--- a/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
+++ b/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
<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"
@@ -9,7 +27,7 @@
</welcome-file-list>
<servlet>
- <servlet-name>MyODataSampleServlet</servlet-name>
+ <servlet-name>CarServiceServlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
@@ -17,12 +35,12 @@
</init-param>
<init-param>
<param-name>org.apache.olingo.odata2.service.factory</param-name>
- <param-value>org.apache.olingo.odata2.sample.service.MyServiceFactory</param-value>
+ <param-value>org.apache.olingo.odata2.sample.service.CarServiceFactory</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
- <servlet-name>MyODataSampleServlet</servlet-name>
- <url-pattern>/MyODataSample.svc/*</url-pattern>
+ <servlet-name>CarServiceServlet</servlet-name>
+ <url-pattern>/CarService.svc/*</url-pattern>
</servlet-mapping>
</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/webapp/index.html b/odata2-sample/cars-service/src/main/webapp/index.html
index 7b5d183..4d9a8e9 100644
--- a/odata2-sample/cars-service/src/main/webapp/index.html
+++ b/odata2-sample/cars-service/src/main/webapp/index.html
@@ -1,31 +1,49 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+ 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.
+-->
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
- <h1>My OData Sample Project</h1>
+ <h1>Apache Olingo - OData Car Sample Project</h1>
<div>
<ul>
- <li><a href="MyODataSample.svc">Link to Sample Service Root - /MyODataSample.svc</a></li>
- <li><a href="MyODataSample.svc/$metadata">Link to Sample Service Metadata - /MyODataSample.svc/$metadata</a></li>
+ <li><a href="CarService.svc">Link to Car Sample Service Root - /CarService.svc</a></li>
+ <li><a href="CarService.svc/$metadata">Link to Car Sample Service Metadata - /CarService.svc/$metadata</a></li>
</ul>
</div>
<div>
<ul>
<li>Entity Sets
<ul>
- <li><a href="MyODataSample.svc/Cars">/Cars</a></li>
- <li><a href="MyODataSample.svc/Manufacturers">/Manufacturers</a></li>
+ <li><a href="CarService.svc/Cars">/Cars</a></li>
+ <li><a href="CarService.svc/Manufacturers">/Manufacturers</a></li>
</ul>
</li>
<li>Sample Entities
<ul>
- <li><a href="MyODataSample.svc/Cars(1)">/Cars(1)</a></li>
- <li><a href="MyODataSample.svc/Cars(3)">/Cars(3)</a></li>
- <li><a href="MyODataSample.svc/Cars(3)/Manufacturer">/Cars(3)/Manufacturer</a></li>
- <li><a href="MyODataSample.svc/Manufacturers(1)">/Manufacturers(1)</a></li>
+ <li><a href="CarService.svc/Cars(1)">/Cars(1)</a></li>
+ <li><a href="CarService.svc/Cars(3)">/Cars(3)</a></li>
+ <li><a href="CarService.svc/Cars(3)/Manufacturer">/Cars(3)/Manufacturer</a></li>
+ <li><a href="CarService.svc/Manufacturers(1)">/Manufacturers(1)</a></li>
</ul>
</li>
</ul>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 45b2684..40c76e8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -232,6 +232,7 @@
<encoding>UTF-8</encoding>
<failOnViolation>true</failOnViolation>
<violationSeverity>warning</violationSeverity>
+ <excludes>**/archetype-resources/**/*</excludes>
</configuration>
</plugin>
<plugin>
@@ -323,6 +324,10 @@
<exclude>**/*.batch</exclude>
<exclude>**/NOTICE</exclude>
<exclude>**/DEPENDENCIES</exclude>
+ <exclude>**/archetype-resources/**</exclude>
+ <exclude>**/archetype-metadata.xml</exclude>
+ <exclude>**/archetype.properties</exclude>
+ <exclude>**/*.txt</exclude>
</excludes>
</configuration>
</execution>
[3/6] git commit: [OLINGO-37] - Archetype support and sample project
- refactor sample
Posted by sk...@apache.org.
[OLINGO-37] - Archetype support and sample project - refactor sample
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/c348f0ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/c348f0ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/c348f0ad
Branch: refs/heads/master
Commit: c348f0ade10275aca3b066f7741d55cd1139fe77
Parents: da1714d
Author: Stephan Klevenz <sk...@apache.org>
Authored: Tue Oct 29 10:13:32 2013 +0100
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Tue Oct 29 12:53:06 2013 +0100
----------------------------------------------------------------------
odata2-sample/cars-archetype/pom.xml | 16 +-
.../main/resources/archetype-resources/pom.xml | 60 +++-
.../src/main/java/CarDataStore.java | 173 ++++++++++++
.../src/main/java/CarEdmProvider.java | 281 +++++++++++++++++++
.../src/main/java/CarODataSingleProcessor.java | 154 ++++++++++
.../src/main/java/CarServiceFactory.java | 42 +++
.../src/main/java/DataStore.java | 152 ----------
.../src/main/java/MyEdmProvider.java | 263 -----------------
.../src/main/java/MyODataSingleProcessor.java | 135 ---------
.../src/main/java/MyServiceFactory.java | 24 --
.../src/main/resources/log4j.xml | 19 +-
.../src/main/webapp/WEB-INF/web.xml | 32 ++-
.../src/main/webapp/index.html | 36 ++-
odata2-sample/cars-archetype/src/pom.xml | 30 --
.../projects/basic/archetype.properties | 2 +-
odata2-sample/cars-service/pom.xml | 62 +++-
.../odata2/sample/service/CarDataStore.java | 170 +++++++++++
.../odata2/sample/service/CarEdmProvider.java | 278 ++++++++++++++++++
.../sample/service/CarODataSingleProcessor.java | 151 ++++++++++
.../sample/service/CarServiceFactory.java | 39 +++
.../olingo/odata2/sample/service/DataStore.java | 149 ----------
.../odata2/sample/service/MyEdmProvider.java | 260 -----------------
.../sample/service/MyODataSingleProcessor.java | 132 ---------
.../odata2/sample/service/MyServiceFactory.java | 21 --
.../cars-service/src/main/resources/log4j.xml | 19 +-
.../src/main/webapp/WEB-INF/web.xml | 26 +-
.../cars-service/src/main/webapp/index.html | 36 ++-
pom.xml | 5 +
28 files changed, 1546 insertions(+), 1221 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/pom.xml b/odata2-sample/cars-archetype/pom.xml
index 830a672..0251118 100644
--- a/odata2-sample/cars-archetype/pom.xml
+++ b/odata2-sample/cars-archetype/pom.xml
@@ -1,14 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
<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.apache.olingo</groupId>
<artifactId>olingo-odata2-sample-cars-service-incubating-archetype</artifactId>
+ <name>${project.artifactId}</name>
<version>1.1.0-SNAPSHOT</version>
+
<packaging>maven-archetype</packaging>
- <name>${project.artifactId}</name>
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-sample</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
<build>
<extensions>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
index 5ac1469..55f2acf 100644
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
@@ -1,5 +1,11 @@
<?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/maven-v4_0_0.xsd">
+<!-- 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. --><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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId>
@@ -9,20 +15,52 @@
<packaging>war</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
<build>
<finalName>${project.artifactId}</finalName>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.4</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <version>2.9</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
<plugins>
<plugin>
- <artifactId>maven-archetype-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-archetype</id>
- <goals>
- <goal>create-from-project</goal>
- </goals>
- <phase>package</phase>
- </execution>
- </executions>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <addGroupIdToProjectName>true</addGroupIdToProjectName>
+ <addVersionToProjectName>true</addVersionToProjectName>
+ <wtpversion>2.0</wtpversion>
+ <downloadSources>true</downloadSources>
+ <downloadJavadocs>true</downloadJavadocs>
+ </configuration>
</plugin>
</plugins>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java
new file mode 100644
index 0000000..a39f1b7
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java
@@ -0,0 +1,173 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*******************************************************************************
+ * 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 ${package};
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+public class CarDataStore {
+
+ // Data accessors
+ public Map<String, Object> getCar(final int id) {
+ Map<String, Object> data = null;
+
+ Calendar updated = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ updated.set(2012, 11, 11, 11, 11, 11);
+ data = createCar(1, "F1 W03", 1, 189189.43, "EUR", "2012", updated, "file://imagePath/w03");
+ break;
+
+ case 2:
+ updated.set(2013, 11, 11, 11, 11, 11);
+ data = createCar(2, "F1 W04", 1, 199999.99, "EUR", "2013", updated, "file://imagePath/w04");
+ break;
+
+ case 3:
+ updated.set(2012, 12, 12, 12, 12, 12);
+ data = createCar(3, "F2012", 2, 137285.33, "EUR", "2012", updated, "http://pathToImage/f2012");
+ break;
+
+ case 4:
+ updated.set(2013, 12, 12, 12, 12, 12);
+ data = createCar(4, "F2013", 2, 145285.00, "EUR", "2013", updated, "http://pathToImage/f2013");
+ break;
+
+ case 5:
+ updated.set(2011, 11, 11, 11, 11, 11);
+ data = createCar(5, "F1 W02", 1, 167189.00, "EUR", "2011", updated, "file://imagePath/wXX");
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createCar(final int carId, final String model, final int manufacturerId,
+ final double price,
+ final String currency, final String modelYear, final Calendar updated, final String imagePath) {
+ Map<String, Object> data = new HashMap<String, Object>();
+
+ data.put("Id", carId);
+ data.put("Model", model);
+ data.put("ManufacturerId", manufacturerId);
+ data.put("Price", price);
+ data.put("Currency", currency);
+ data.put("ModelYear", modelYear);
+ data.put("Updated", updated);
+ data.put("ImagePath", imagePath);
+
+ return data;
+ }
+
+ public Map<String, Object> getManufacturer(final int id) {
+ Map<String, Object> data = null;
+ Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ Map<String, Object> addressStar = createAddress("Star Street 137", "Stuttgart", "70173", "Germany");
+ date.set(1954, 7, 4);
+ data = createManufacturer(1, "Star Powered Racing", addressStar, date);
+ break;
+
+ case 2:
+ Map<String, Object> addressHorse = createAddress("Horse Street 1", "Maranello", "41053", "Italy");
+ date.set(1929, 11, 16);
+ data = createManufacturer(2, "Horse Powered Racing", addressHorse, date);
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createManufacturer(final int id, final String name, final Map<String, Object> address,
+ final Calendar updated) {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("Id", id);
+ data.put("Name", name);
+ data.put("Address", address);
+ data.put("Updated", updated);
+ return data;
+ }
+
+ private Map<String, Object> createAddress(final String street, final String city, final String zipCode,
+ final String country) {
+ Map<String, Object> address = new HashMap<String, Object>();
+ address.put("Street", street);
+ address.put("City", city);
+ address.put("ZipCode", zipCode);
+ address.put("Country", country);
+ return address;
+ }
+
+ public List<Map<String, Object>> getCars() {
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.add(getCar(1));
+ cars.add(getCar(2));
+ cars.add(getCar(3));
+ cars.add(getCar(4));
+ cars.add(getCar(5));
+ return cars;
+ }
+
+ public List<Map<String, Object>> getManufacturers() {
+ List<Map<String, Object>> manufacturers = new ArrayList<Map<String, Object>>();
+ manufacturers.add(getManufacturer(1));
+ manufacturers.add(getManufacturer(2));
+ return manufacturers;
+ }
+
+ public List<Map<String, Object>> getCarsFor(final int manufacturerId) {
+ List<Map<String, Object>> cars = getCars();
+ List<Map<String, Object>> carsForManufacturer = new ArrayList<Map<String, Object>>();
+
+ for (Map<String, Object> car : cars) {
+ if (Integer.valueOf(manufacturerId).equals(car.get("ManufacturerId"))) {
+ carsForManufacturer.add(car);
+ }
+ }
+
+ return carsForManufacturer;
+ }
+
+ public Map<String, Object> getManufacturerFor(final int carId) {
+ Map<String, Object> car = getCar(carId);
+ if (car != null) {
+ Object manufacturerId = car.get("ManufacturerId");
+ if (manufacturerId != null) {
+ return getManufacturer((Integer) manufacturerId);
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java
new file mode 100644
index 0000000..d1ecdac
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java
@@ -0,0 +1,281 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*******************************************************************************
+ * 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 ${package};
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTargetPath;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.CustomizableFeedMappings;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.ReturnType;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+
+public class CarEdmProvider extends EdmProvider {
+
+ static final String ENTITY_SET_NAME_MANUFACTURERS = "Manufacturers";
+ static final String ENTITY_SET_NAME_CARS = "Cars";
+ static final String ENTITY_NAME_MANUFACTURER = "Manufacturer";
+ static final String ENTITY_NAME_CAR = "Car";
+
+ private static final String NAMESPACE = "org.apache.olingo.odata2.ODataCars";
+
+ private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_CAR);
+ private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_MANUFACTURER);
+
+ private static final FullQualifiedName COMPLEX_TYPE = new FullQualifiedName(NAMESPACE, "Address");
+
+ private static final FullQualifiedName ASSOCIATION_CAR_MANUFACTURER = new FullQualifiedName(NAMESPACE,
+ "Car_Manufacturer_Manufacturer_Cars");
+
+ private static final String ROLE_1_1 = "Car_Manufacturer";
+ private static final String ROLE_1_2 = "Manufacturer_Cars";
+
+ private static final String ENTITY_CONTAINER = "ODataCarsEntityContainer";
+
+ private static final String ASSOCIATION_SET = "Cars_Manufacturers";
+
+ private static final String FUNCTION_IMPORT = "NumberOfCars";
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ List<Schema> schemas = new ArrayList<Schema>();
+
+ Schema schema = new Schema();
+ schema.setNamespace(NAMESPACE);
+
+ List<EntityType> entityTypes = new ArrayList<EntityType>();
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
+ schema.setEntityTypes(entityTypes);
+
+ List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ complexTypes.add(getComplexType(COMPLEX_TYPE));
+ schema.setComplexTypes(complexTypes);
+
+ List<Association> associations = new ArrayList<Association>();
+ associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER));
+ schema.setAssociations(associations);
+
+ List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
+ EntityContainer entityContainer = new EntityContainer();
+ entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
+
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS));
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS));
+ entityContainer.setEntitySets(entitySets);
+
+ List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER,
+ ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2));
+ entityContainer.setAssociationSets(associationSets);
+
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT));
+ entityContainer.setFunctionImports(functionImports);
+
+ entityContainers.add(entityContainer);
+ schema.setEntityContainers(entityContainers);
+
+ schemas.add(schema);
+
+ return schemas;
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+
+ if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Model").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100).setDefaultValue("Hugo"))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new SimpleProperty().setName("ManufacturerId").setType(EdmSimpleTypeKind.Int32));
+ properties.add(new SimpleProperty().setName("Price").setType(EdmSimpleTypeKind.Decimal));
+ properties.add(new SimpleProperty().setName("Currency").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(3)));
+ properties.add(new SimpleProperty().setName("ModelYear").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(4)));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+ properties.add(new SimpleProperty().setName("ImagePath").setType(EdmSimpleTypeKind.String));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Manufacturer")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_1.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new ComplexProperty().setName("Address").setType(new FullQualifiedName(NAMESPACE, "Address")));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Cars")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_2.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
+ return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (ASSOCIATION_CAR_MANUFACTURER.getName().equals(edmFQName.getName())) {
+ return new Association().setName(ASSOCIATION_CAR_MANUFACTURER.getName())
+ .setEnd1(
+ new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setEnd2(
+ new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ENTITY_SET_NAME_CARS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association,
+ final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ASSOCIATION_CAR_MANUFACTURER.equals(association)) {
+ return new AssociationSet().setName(ASSOCIATION_SET)
+ .setAssociation(ASSOCIATION_CAR_MANUFACTURER)
+ .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_NAME_MANUFACTURERS))
+ .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_NAME_CARS));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (FUNCTION_IMPORT.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setHttpMethod("GET");
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataException {
+ if (name == null || "ODataCarsEntityContainer".equals(name)) {
+ return new EntityContainerInfo().setName("ODataCarsEntityContainer").setDefaultEntityContainer(true);
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java
new file mode 100644
index 0000000..b18355d
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java
@@ -0,0 +1,154 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*******************************************************************************
+ * 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 ${package};
+
+import static ${package}.CarEdmProvider.ENTITY_SET_NAME_CARS;
+import static ${package}.CarEdmProvider.ENTITY_SET_NAME_MANUFACTURERS;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+
+public class CarODataSingleProcessor extends ODataSingleProcessor {
+
+ private final CarDataStore dataStore;
+
+ public CarODataSingleProcessor() {
+ dataStore = new CarDataStore();
+ }
+
+ @Override
+ public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
+ throws ODataException {
+
+ EdmEntitySet entitySet;
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ entitySet = uriInfo.getTargetEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.addAll(dataStore.getCarsFor(manufacturerKey));
+
+ return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
+ getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ @Override
+ public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ EdmEntitySet entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getCar(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getManufacturer(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+
+ Map<String, Object> data = null;
+
+ if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ data = dataStore.getManufacturerFor(carKey);
+ }
+
+ if (data != null) {
+ return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
+ data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ private int getKeyValue(final KeyPredicate key) throws ODataException {
+ EdmProperty property = key.getProperty();
+ EdmSimpleType type = (EdmSimpleType) property.getType();
+ return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java
new file mode 100644
index 0000000..6806631
--- /dev/null
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java
@@ -0,0 +1,42 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*******************************************************************************
+ * 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 ${package};
+
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+
+public class CarServiceFactory extends ODataServiceFactory {
+
+ @Override
+ public ODataService createService(final ODataContext ctx) throws ODataException {
+
+ EdmProvider edmProvider = new CarEdmProvider();
+
+ ODataSingleProcessor singleProcessor = new CarODataSingleProcessor();
+
+ return createODataSingleProcessorService(edmProvider, singleProcessor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/DataStore.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/DataStore.java
deleted file mode 100644
index d19a3a9..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/DataStore.java
+++ /dev/null
@@ -1,152 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-package ${package};
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-
-public class DataStore {
-
- // Data accessors
- public Map<String, Object> getCar(int id) {
- Map<String, Object> data = null;
-
- Calendar updated = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
- switch (id) {
- case 1:
- updated.set(2012, 11, 11, 11, 11, 11);
- data = createCar(1, "F1 W03", 1, 189189.43, "EUR", "2012", updated, "file://imagePath/w03");
- break;
-
- case 2:
- updated.set(2013, 11, 11, 11, 11, 11);
- data = createCar(2, "F1 W04", 1, 199999.99, "EUR", "2013", updated, "file://imagePath/w04");
- break;
-
- case 3:
- updated.set(2012, 12, 12, 12, 12, 12);
- data = createCar(3, "F2012", 2, 137285.33, "EUR", "2012", updated, "http://pathToImage/f2012");
- break;
-
- case 4:
- updated.set(2013, 12, 12, 12, 12, 12);
- data = createCar(4, "F2013", 2, 145285.00, "EUR", "2013", updated, "http://pathToImage/f2013");
- break;
-
- case 5:
- updated.set(2011, 11, 11, 11, 11, 11);
- data = createCar(5, "F1 W02", 1, 167189.00, "EUR", "2011", updated, "file://imagePath/wXX");
- break;
-
- default:
- break;
- }
-
- return data;
- }
-
- private Map<String, Object> createCar(int carId, String model, int manufacturerId, double price,
- String currency, String modelYear, Calendar updated, String imagePath) {
- Map<String, Object> data = new HashMap<String, Object>();
-
- data.put("Id", carId);
- data.put("Model", model);
- data.put("ManufacturerId", manufacturerId);
- data.put("Price", price);
- data.put("Currency", currency);
- data.put("ModelYear", modelYear);
- data.put("Updated", updated);
- data.put("ImagePath", imagePath);
-
- return data;
- }
-
- public Map<String, Object> getManufacturer(int id) {
- Map<String, Object> data = null;
- Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
- switch (id) {
- case 1:
- Map<String, Object> addressStar = createAddress("Star Street 137", "Stuttgart", "70173", "Germany");
- date.set(1954, 7, 4);
- data = createManufacturer(1, "Star Powered Racing", addressStar, date);
- break;
-
- case 2:
- Map<String, Object> addressHorse = createAddress("Horse Street 1", "Maranello", "41053", "Italy");
- date.set(1929, 11, 16);
- data = createManufacturer(2, "Horse Powered Racing", addressHorse, date);
- break;
-
- default:
- break;
- }
-
- return data;
- }
-
- private Map<String, Object> createManufacturer(int id, String name, Map<String, Object> address, Calendar updated) {
- Map<String, Object> data = new HashMap<String, Object>();
- data.put("Id", id);
- data.put("Name", name);
- data.put("Address", address);
- data.put("Updated", updated);
- return data;
- }
-
- private Map<String, Object> createAddress(String street, String city, String zipCode, String country) {
- Map<String, Object> address = new HashMap<String, Object>();
- address.put("Street", street);
- address.put("City", city);
- address.put("ZipCode", zipCode);
- address.put("Country", country);
- return address;
- }
-
- public List<Map<String, Object>> getCars() {
- List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
- cars.add(getCar(1));
- cars.add(getCar(2));
- cars.add(getCar(3));
- cars.add(getCar(4));
- cars.add(getCar(5));
- return cars;
- }
-
- public List<Map<String, Object>> getManufacturers() {
- List<Map<String, Object>> manufacturers = new ArrayList<Map<String, Object>>();
- manufacturers.add(getManufacturer(1));
- manufacturers.add(getManufacturer(2));
- return manufacturers;
- }
-
- public List<Map<String, Object>> getCarsFor(int manufacturerId) {
- List<Map<String, Object>> cars = getCars();
- List<Map<String, Object>> carsForManufacturer = new ArrayList<Map<String, Object>>();
-
- for (Map<String, Object> car : cars) {
- if (Integer.valueOf(manufacturerId).equals(car.get("ManufacturerId"))) {
- carsForManufacturer.add(car);
- }
- }
-
- return carsForManufacturer;
- }
-
- public Map<String, Object> getManufacturerFor(int carId) {
- Map<String, Object> car = getCar(carId);
- if (car != null) {
- Object manufacturerId = car.get("ManufacturerId");
- if (manufacturerId != null) {
- return getManufacturer((Integer) manufacturerId);
- }
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyEdmProvider.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyEdmProvider.java
deleted file mode 100644
index a375f9a..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyEdmProvider.java
+++ /dev/null
@@ -1,263 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-package ${package};
-
-import java.util.ArrayList;
-import java.util.List;
-
-import ${groupId}.odata2.api.edm.EdmConcurrencyMode;
-import ${groupId}.odata2.api.edm.EdmMultiplicity;
-import ${groupId}.odata2.api.edm.EdmSimpleTypeKind;
-import ${groupId}.odata2.api.edm.EdmTargetPath;
-import ${groupId}.odata2.api.edm.FullQualifiedName;
-import ${groupId}.odata2.api.edm.provider.Association;
-import ${groupId}.odata2.api.edm.provider.AssociationEnd;
-import ${groupId}.odata2.api.edm.provider.AssociationSet;
-import ${groupId}.odata2.api.edm.provider.AssociationSetEnd;
-import ${groupId}.odata2.api.edm.provider.ComplexProperty;
-import ${groupId}.odata2.api.edm.provider.ComplexType;
-import ${groupId}.odata2.api.edm.provider.CustomizableFeedMappings;
-import ${groupId}.odata2.api.edm.provider.EdmProvider;
-import ${groupId}.odata2.api.edm.provider.EntityContainer;
-import ${groupId}.odata2.api.edm.provider.EntityContainerInfo;
-import ${groupId}.odata2.api.edm.provider.EntitySet;
-import ${groupId}.odata2.api.edm.provider.EntityType;
-import ${groupId}.odata2.api.edm.provider.Facets;
-import ${groupId}.odata2.api.edm.provider.FunctionImport;
-import ${groupId}.odata2.api.edm.provider.Key;
-import ${groupId}.odata2.api.edm.provider.NavigationProperty;
-import ${groupId}.odata2.api.edm.provider.Property;
-import ${groupId}.odata2.api.edm.provider.PropertyRef;
-import ${groupId}.odata2.api.edm.provider.ReturnType;
-import ${groupId}.odata2.api.edm.provider.Schema;
-import ${groupId}.odata2.api.edm.provider.SimpleProperty;
-import ${groupId}.odata2.api.exception.ODataException;
-
-public class MyEdmProvider extends EdmProvider {
-
- static final String ENTITY_SET_NAME_MANUFACTURERS = "Manufacturers";
- static final String ENTITY_SET_NAME_CARS = "Cars";
- static final String ENTITY_NAME_MANUFACTURER = "Manufacturer";
- static final String ENTITY_NAME_CAR = "Car";
-
- private static final String NAMESPACE = "${groupId}.odata2.ODataCars";
-
- private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_CAR);
- private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_MANUFACTURER);
-
- private static final FullQualifiedName COMPLEX_TYPE = new FullQualifiedName(NAMESPACE, "Address");
-
- private static final FullQualifiedName ASSOCIATION_CAR_MANUFACTURER = new FullQualifiedName(NAMESPACE,
- "Car_Manufacturer_Manufacturer_Cars");
-
- private static final String ROLE_1_1 = "Car_Manufacturer";
- private static final String ROLE_1_2 = "Manufacturer_Cars";
-
- private static final String ENTITY_CONTAINER = "ODataCarsEntityContainer";
-
- private static final String ASSOCIATION_SET = "Cars_Manufacturers";
-
- private static final String FUNCTION_IMPORT = "NumberOfCars";
-
- @Override
- public List<Schema> getSchemas() throws ODataException {
- List<Schema> schemas = new ArrayList<Schema>();
-
- Schema schema = new Schema();
- schema.setNamespace(NAMESPACE);
-
- List<EntityType> entityTypes = new ArrayList<EntityType>();
- entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
- entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
- schema.setEntityTypes(entityTypes);
-
- List<ComplexType> complexTypes = new ArrayList<ComplexType>();
- complexTypes.add(getComplexType(COMPLEX_TYPE));
- schema.setComplexTypes(complexTypes);
-
- List<Association> associations = new ArrayList<Association>();
- associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER));
- schema.setAssociations(associations);
-
- List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
- EntityContainer entityContainer = new EntityContainer();
- entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
-
- List<EntitySet> entitySets = new ArrayList<EntitySet>();
- entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS));
- entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS));
- entityContainer.setEntitySets(entitySets);
-
- List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
- associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER,
- ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2));
- entityContainer.setAssociationSets(associationSets);
-
- List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
- functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT));
- entityContainer.setFunctionImports(functionImports);
-
- entityContainers.add(entityContainer);
- schema.setEntityContainers(entityContainers);
-
- schemas.add(schema);
-
- return schemas;
- }
-
- @Override
- public EntityType getEntityType(FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
-
- if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
-
- // Properties
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
- new Facets().setNullable(false)));
- properties.add(new SimpleProperty().setName("Model").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setNullable(false).setMaxLength(100).setDefaultValue("Hugo"))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
- properties.add(new SimpleProperty().setName("ManufacturerId").setType(EdmSimpleTypeKind.Int32));
- properties.add(new SimpleProperty().setName("Price").setType(EdmSimpleTypeKind.Decimal));
- properties.add(new SimpleProperty().setName("Currency").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setMaxLength(3)));
- properties.add(new SimpleProperty().setName("ModelYear").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setMaxLength(4)));
- properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
- .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
- properties.add(new SimpleProperty().setName("ImagePath").setType(EdmSimpleTypeKind.String));
-
- // Navigation Properties
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("Manufacturer")
- .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
-
- // Key
- List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
- keyProperties.add(new PropertyRef().setName("Id"));
- Key key = new Key().setKeys(keyProperties);
-
- return new EntityType().setName(ENTITY_TYPE_1_1.getName())
- .setProperties(properties)
- .setKey(key)
- .setNavigationProperties(navigationProperties);
-
- } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
-
- // Properties
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
- new Facets().setNullable(false)));
- properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setNullable(false).setMaxLength(100))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
- properties.add(new ComplexProperty().setName("Address").setType(new FullQualifiedName(NAMESPACE, "Address")));
- properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
- .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
-
- // Navigation Properties
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("Cars")
- .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
-
- // Key
- List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
- keyProperties.add(new PropertyRef().setName("Id"));
- Key key = new Key().setKeys(keyProperties);
-
- return new EntityType().setName(ENTITY_TYPE_1_2.getName())
- .setProperties(properties)
- .setKey(key)
- .setNavigationProperties(navigationProperties);
-
- }
- }
-
- return null;
- }
-
- @Override
- public ComplexType getComplexType(FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
- if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
- return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
- }
- }
-
- return null;
- }
-
- @Override
- public Association getAssociation(FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
- if (ASSOCIATION_CAR_MANUFACTURER.getName().equals(edmFQName.getName())) {
- return new Association().setName(ASSOCIATION_CAR_MANUFACTURER.getName())
- .setEnd1(
- new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
- .setEnd2(
- new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
- }
- }
- return null;
- }
-
- @Override
- public EntitySet getEntitySet(String entityContainer, String name) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (ENTITY_SET_NAME_CARS.equals(name)) {
- return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
- return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
- }
- }
- return null;
- }
-
- @Override
- public AssociationSet getAssociationSet(String entityContainer, FullQualifiedName association,
- String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (ASSOCIATION_CAR_MANUFACTURER.equals(association)) {
- return new AssociationSet().setName(ASSOCIATION_SET)
- .setAssociation(ASSOCIATION_CAR_MANUFACTURER)
- .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_NAME_MANUFACTURERS))
- .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_NAME_CARS));
- }
- }
- return null;
- }
-
- @Override
- public FunctionImport getFunctionImport(String entityContainer, String name) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (FUNCTION_IMPORT.equals(name)) {
- return new FunctionImport().setName(name)
- .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
- .setHttpMethod("GET");
- }
- }
- return null;
- }
-
- @Override
- public EntityContainerInfo getEntityContainerInfo(String name) throws ODataException {
- if (name == null || "ODataCarsEntityContainer".equals(name)) {
- return new EntityContainerInfo().setName("ODataCarsEntityContainer").setDefaultEntityContainer(true);
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyODataSingleProcessor.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyODataSingleProcessor.java
deleted file mode 100644
index b4a08c4..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyODataSingleProcessor.java
+++ /dev/null
@@ -1,135 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-package ${package};
-
-import static ${package}.MyEdmProvider.ENTITY_SET_NAME_CARS;
-import static ${package}.MyEdmProvider.ENTITY_SET_NAME_MANUFACTURERS;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import ${groupId}.odata2.api.edm.EdmEntitySet;
-import ${groupId}.odata2.api.edm.EdmLiteralKind;
-import ${groupId}.odata2.api.edm.EdmProperty;
-import ${groupId}.odata2.api.edm.EdmSimpleType;
-import ${groupId}.odata2.api.ep.EntityProvider;
-import ${groupId}.odata2.api.ep.EntityProviderWriteProperties;
-import ${groupId}.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
-import ${groupId}.odata2.api.exception.ODataException;
-import ${groupId}.odata2.api.exception.ODataNotFoundException;
-import ${groupId}.odata2.api.exception.ODataNotImplementedException;
-import ${groupId}.odata2.api.processor.ODataResponse;
-import ${groupId}.odata2.api.processor.ODataSingleProcessor;
-import ${groupId}.odata2.api.uri.KeyPredicate;
-import ${groupId}.odata2.api.uri.info.GetEntitySetUriInfo;
-import ${groupId}.odata2.api.uri.info.GetEntityUriInfo;
-
-public class MyODataSingleProcessor extends ODataSingleProcessor {
-
- private final DataStore dataStore;
-
- public MyODataSingleProcessor() {
- dataStore = new DataStore();
- }
-
- @Override
- public ODataResponse readEntitySet(GetEntitySetUriInfo uriInfo, String contentType) throws ODataException {
-
- EdmEntitySet entitySet;
-
- if (uriInfo.getNavigationSegments().size() == 0) {
- entitySet = uriInfo.getStartEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
-
- } else if (uriInfo.getNavigationSegments().size() == 1) {
- // navigation first level, simplified example for illustration purposes only
- entitySet = uriInfo.getTargetEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
-
- List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
- cars.addAll(dataStore.getCarsFor(manufacturerKey));
-
- return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
- getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- throw new ODataNotImplementedException();
- }
-
- @Override
- public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
-
- if (uriInfo.getNavigationSegments().size() == 0) {
- EdmEntitySet entitySet = uriInfo.getStartEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
- Map<String, Object> data = dataStore.getCar(id);
-
- if (data != null) {
- URI serviceRoot = getContext().getPathInfo().getServiceRoot();
- ODataEntityProviderPropertiesBuilder propertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(serviceRoot);
-
- return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
- }
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
- Map<String, Object> data = dataStore.getManufacturer(id);
-
- if (data != null) {
- URI serviceRoot = getContext().getPathInfo().getServiceRoot();
- ODataEntityProviderPropertiesBuilder propertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(serviceRoot);
-
- return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
- }
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
-
- } else if (uriInfo.getNavigationSegments().size() == 1) {
- // navigation first level, simplified example for illustration purposes only
- EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
-
- Map<String, Object> data = null;
-
- if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
- data = dataStore.getManufacturerFor(carKey);
- }
-
- if (data != null) {
- return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
- data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- throw new ODataNotImplementedException();
- }
-
- private int getKeyValue(KeyPredicate key) throws ODataException {
- EdmProperty property = key.getProperty();
- EdmSimpleType type = (EdmSimpleType) property.getType();
- return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceFactory.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceFactory.java
deleted file mode 100644
index 021a241..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceFactory.java
+++ /dev/null
@@ -1,24 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-package ${package};
-
-import ${groupId}.odata2.api.ODataService;
-import ${groupId}.odata2.api.ODataServiceFactory;
-import ${groupId}.odata2.api.edm.provider.EdmProvider;
-import ${groupId}.odata2.api.exception.ODataException;
-import ${groupId}.odata2.api.processor.ODataContext;
-import ${groupId}.odata2.api.processor.ODataSingleProcessor;
-
-public class MyServiceFactory extends ODataServiceFactory {
-
- @Override
- public ODataService createService(ODataContext ctx) throws ODataException {
-
- EdmProvider edmProvider = new MyEdmProvider();
-
- ODataSingleProcessor singleProcessor = new MyODataSingleProcessor();
-
- return createODataSingleProcessorService(edmProvider, singleProcessor);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
index 81dc733..ed91239 100644
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
@@ -2,8 +2,25 @@
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ 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.
+-->
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
-
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
index c9bcfba..b5b07da 100644
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -2,30 +2,48 @@
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
<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">
- <display-name>${groupId}.odata2.sample</display-name>
+ <display-name>org.apache.olingo.odata2.sample</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
- <servlet-name>MyODataSampleServlet</servlet-name>
+ <servlet-name>CarServiceServlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
- <param-value>${groupId}.odata2.core.rest.app.ODataApplication</param-value>
+ <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>
</init-param>
<init-param>
- <param-name>${groupId}.odata2.service.factory</param-name>
- <param-value>${package}.MyServiceFactory</param-value>
+ <param-name>org.apache.olingo.odata2.service.factory</param-name>
+ <param-value>${package}.CarServiceFactory</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
- <servlet-name>MyODataSampleServlet</servlet-name>
- <url-pattern>/MyODataSample.svc/*</url-pattern>
+ <servlet-name>CarServiceServlet</servlet-name>
+ <url-pattern>/CarService.svc/*</url-pattern>
</servlet-mapping>
</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
index d0b1c39..810c748 100644
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
+++ b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
@@ -2,33 +2,51 @@
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+ 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.
+-->
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
- <h1>My OData Sample Project</h1>
+ <h1>Apache Olingo - OData Car Sample Project</h1>
<div>
<ul>
- <li><a href="MyODataSample.svc">Link to Sample Service Root - /MyODataSample.svc</a></li>
- <li><a href="MyODataSample.svc/${symbol_dollar}metadata">Link to Sample Service Metadata - /MyODataSample.svc/${symbol_dollar}metadata</a></li>
+ <li><a href="CarService.svc">Link to Car Sample Service Root - /CarService.svc</a></li>
+ <li><a href="CarService.svc/${symbol_dollar}metadata">Link to Car Sample Service Metadata - /CarService.svc/${symbol_dollar}metadata</a></li>
</ul>
</div>
<div>
<ul>
<li>Entity Sets
<ul>
- <li><a href="MyODataSample.svc/Cars">/Cars</a></li>
- <li><a href="MyODataSample.svc/Manufacturers">/Manufacturers</a></li>
+ <li><a href="CarService.svc/Cars">/Cars</a></li>
+ <li><a href="CarService.svc/Manufacturers">/Manufacturers</a></li>
</ul>
</li>
<li>Sample Entities
<ul>
- <li><a href="MyODataSample.svc/Cars(1)">/Cars(1)</a></li>
- <li><a href="MyODataSample.svc/Cars(3)">/Cars(3)</a></li>
- <li><a href="MyODataSample.svc/Cars(3)/Manufacturer">/Cars(3)/Manufacturer</a></li>
- <li><a href="MyODataSample.svc/Manufacturers(1)">/Manufacturers(1)</a></li>
+ <li><a href="CarService.svc/Cars(1)">/Cars(1)</a></li>
+ <li><a href="CarService.svc/Cars(3)">/Cars(3)</a></li>
+ <li><a href="CarService.svc/Cars(3)/Manufacturer">/Cars(3)/Manufacturer</a></li>
+ <li><a href="CarService.svc/Manufacturers(1)">/Manufacturers(1)</a></li>
</ul>
</li>
</ul>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/pom.xml b/odata2-sample/cars-archetype/src/pom.xml
deleted file mode 100644
index 346e421..0000000
--- a/odata2-sample/cars-archetype/src/pom.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?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.apache.olingo</groupId>
- <artifactId>olingo-odata2-sample-cars-service-incubating-archetype</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <packaging>maven-archetype</packaging>
-
- <name>olingo-odata2-sample-cars-service-incubating-archetype</name>
-
- <build>
- <extensions>
- <extension>
- <groupId>org.apache.maven.archetype</groupId>
- <artifactId>archetype-packaging</artifactId>
- <version>2.2</version>
- </extension>
- </extensions>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <artifactId>maven-archetype-plugin</artifactId>
- <version>2.2</version>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties b/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
index 3e458e2..2a43880 100644
--- a/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
+++ b/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
@@ -1,4 +1,4 @@
-#Tue Oct 29 09:14:13 CET 2013
+#Tue Oct 29 12:52:49 CET 2013
package=it.pkg
version=0.1-SNAPSHOT
groupId=archetype.it
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/pom.xml b/odata2-sample/cars-service/pom.xml
index 7174919..c1b55a6 100755
--- a/odata2-sample/cars-service/pom.xml
+++ b/odata2-sample/cars-service/pom.xml
@@ -1,28 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.olingo</groupId>
+ <groupId>org.apache.olingo.sample</groupId>
<artifactId>olingo-odata2-sample-cars-service-incubating</artifactId>
<name>${project.artifactId}</name>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
<build>
<finalName>${project.artifactId}</finalName>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.4</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <version>2.9</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
<plugins>
<plugin>
- <artifactId>maven-archetype-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-archetype</id>
- <goals>
- <goal>create-from-project</goal>
- </goals>
- <phase>package</phase>
- </execution>
- </executions>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <addGroupIdToProjectName>true</addGroupIdToProjectName>
+ <addVersionToProjectName>true</addVersionToProjectName>
+ <wtpversion>2.0</wtpversion>
+ <downloadSources>true</downloadSources>
+ <downloadJavadocs>true</downloadJavadocs>
+ </configuration>
</plugin>
</plugins>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c348f0ad/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarDataStore.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarDataStore.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarDataStore.java
new file mode 100644
index 0000000..d96fc21
--- /dev/null
+++ b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarDataStore.java
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * 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.odata2.sample.service;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+public class CarDataStore {
+
+ // Data accessors
+ public Map<String, Object> getCar(final int id) {
+ Map<String, Object> data = null;
+
+ Calendar updated = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ updated.set(2012, 11, 11, 11, 11, 11);
+ data = createCar(1, "F1 W03", 1, 189189.43, "EUR", "2012", updated, "file://imagePath/w03");
+ break;
+
+ case 2:
+ updated.set(2013, 11, 11, 11, 11, 11);
+ data = createCar(2, "F1 W04", 1, 199999.99, "EUR", "2013", updated, "file://imagePath/w04");
+ break;
+
+ case 3:
+ updated.set(2012, 12, 12, 12, 12, 12);
+ data = createCar(3, "F2012", 2, 137285.33, "EUR", "2012", updated, "http://pathToImage/f2012");
+ break;
+
+ case 4:
+ updated.set(2013, 12, 12, 12, 12, 12);
+ data = createCar(4, "F2013", 2, 145285.00, "EUR", "2013", updated, "http://pathToImage/f2013");
+ break;
+
+ case 5:
+ updated.set(2011, 11, 11, 11, 11, 11);
+ data = createCar(5, "F1 W02", 1, 167189.00, "EUR", "2011", updated, "file://imagePath/wXX");
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createCar(final int carId, final String model, final int manufacturerId,
+ final double price,
+ final String currency, final String modelYear, final Calendar updated, final String imagePath) {
+ Map<String, Object> data = new HashMap<String, Object>();
+
+ data.put("Id", carId);
+ data.put("Model", model);
+ data.put("ManufacturerId", manufacturerId);
+ data.put("Price", price);
+ data.put("Currency", currency);
+ data.put("ModelYear", modelYear);
+ data.put("Updated", updated);
+ data.put("ImagePath", imagePath);
+
+ return data;
+ }
+
+ public Map<String, Object> getManufacturer(final int id) {
+ Map<String, Object> data = null;
+ Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ Map<String, Object> addressStar = createAddress("Star Street 137", "Stuttgart", "70173", "Germany");
+ date.set(1954, 7, 4);
+ data = createManufacturer(1, "Star Powered Racing", addressStar, date);
+ break;
+
+ case 2:
+ Map<String, Object> addressHorse = createAddress("Horse Street 1", "Maranello", "41053", "Italy");
+ date.set(1929, 11, 16);
+ data = createManufacturer(2, "Horse Powered Racing", addressHorse, date);
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createManufacturer(final int id, final String name, final Map<String, Object> address,
+ final Calendar updated) {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("Id", id);
+ data.put("Name", name);
+ data.put("Address", address);
+ data.put("Updated", updated);
+ return data;
+ }
+
+ private Map<String, Object> createAddress(final String street, final String city, final String zipCode,
+ final String country) {
+ Map<String, Object> address = new HashMap<String, Object>();
+ address.put("Street", street);
+ address.put("City", city);
+ address.put("ZipCode", zipCode);
+ address.put("Country", country);
+ return address;
+ }
+
+ public List<Map<String, Object>> getCars() {
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.add(getCar(1));
+ cars.add(getCar(2));
+ cars.add(getCar(3));
+ cars.add(getCar(4));
+ cars.add(getCar(5));
+ return cars;
+ }
+
+ public List<Map<String, Object>> getManufacturers() {
+ List<Map<String, Object>> manufacturers = new ArrayList<Map<String, Object>>();
+ manufacturers.add(getManufacturer(1));
+ manufacturers.add(getManufacturer(2));
+ return manufacturers;
+ }
+
+ public List<Map<String, Object>> getCarsFor(final int manufacturerId) {
+ List<Map<String, Object>> cars = getCars();
+ List<Map<String, Object>> carsForManufacturer = new ArrayList<Map<String, Object>>();
+
+ for (Map<String, Object> car : cars) {
+ if (Integer.valueOf(manufacturerId).equals(car.get("ManufacturerId"))) {
+ carsForManufacturer.add(car);
+ }
+ }
+
+ return carsForManufacturer;
+ }
+
+ public Map<String, Object> getManufacturerFor(final int carId) {
+ Map<String, Object> car = getCar(carId);
+ if (car != null) {
+ Object manufacturerId = car.get("ManufacturerId");
+ if (manufacturerId != null) {
+ return getManufacturer((Integer) manufacturerId);
+ }
+ }
+ return null;
+ }
+}
[5/6] [OLINGO-37] - Archetype support - refactoring
Posted by sk...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java
new file mode 100644
index 0000000..b18355d
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java
@@ -0,0 +1,154 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*******************************************************************************
+ * 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 ${package};
+
+import static ${package}.CarEdmProvider.ENTITY_SET_NAME_CARS;
+import static ${package}.CarEdmProvider.ENTITY_SET_NAME_MANUFACTURERS;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+
+public class CarODataSingleProcessor extends ODataSingleProcessor {
+
+ private final CarDataStore dataStore;
+
+ public CarODataSingleProcessor() {
+ dataStore = new CarDataStore();
+ }
+
+ @Override
+ public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
+ throws ODataException {
+
+ EdmEntitySet entitySet;
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ entitySet = uriInfo.getTargetEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.addAll(dataStore.getCarsFor(manufacturerKey));
+
+ return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
+ getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ @Override
+ public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
+
+ if (uriInfo.getNavigationSegments().size() == 0) {
+ EdmEntitySet entitySet = uriInfo.getStartEntitySet();
+
+ if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getCar(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ Map<String, Object> data = dataStore.getManufacturer(id);
+
+ if (data != null) {
+ URI serviceRoot = getContext().getPathInfo().getServiceRoot();
+ ODataEntityProviderPropertiesBuilder propertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(serviceRoot);
+
+ return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
+ }
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+
+ } else if (uriInfo.getNavigationSegments().size() == 1) {
+ // navigation first level, simplified example for illustration purposes only
+ EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+
+ Map<String, Object> data = null;
+
+ if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
+ int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
+ data = dataStore.getManufacturerFor(carKey);
+ }
+
+ if (data != null) {
+ return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
+ data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ throw new ODataNotImplementedException();
+ }
+
+ private int getKeyValue(final KeyPredicate key) throws ODataException {
+ EdmProperty property = key.getProperty();
+ EdmSimpleType type = (EdmSimpleType) property.getType();
+ return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java
new file mode 100644
index 0000000..6806631
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java
@@ -0,0 +1,42 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*******************************************************************************
+ * 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 ${package};
+
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+
+public class CarServiceFactory extends ODataServiceFactory {
+
+ @Override
+ public ODataService createService(final ODataContext ctx) throws ODataException {
+
+ EdmProvider edmProvider = new CarEdmProvider();
+
+ ODataSingleProcessor singleProcessor = new CarODataSingleProcessor();
+
+ return createODataSingleProcessorService(edmProvider, singleProcessor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
new file mode 100644
index 0000000..ed91239
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
@@ -0,0 +1,36 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ 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.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p %c{1} - %m%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <priority value="error" />
+ <appender-ref ref="console" />
+ </root>
+</log4j:configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..b5b07da
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,49 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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">
+ <display-name>org.apache.olingo.odata2.sample</display-name>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+
+ <servlet>
+ <servlet-name>CarServiceServlet</servlet-name>
+ <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>
+ </init-param>
+ <init-param>
+ <param-name>org.apache.olingo.odata2.service.factory</param-name>
+ <param-value>${package}.CarServiceFactory</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>CarServiceServlet</servlet-name>
+ <url-pattern>/CarService.svc/*</url-pattern>
+ </servlet-mapping>
+</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
new file mode 100644
index 0000000..810c748
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
@@ -0,0 +1,55 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--
+ 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.
+-->
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <h1>Apache Olingo - OData Car Sample Project</h1>
+ <div>
+ <ul>
+ <li><a href="CarService.svc">Link to Car Sample Service Root - /CarService.svc</a></li>
+ <li><a href="CarService.svc/${symbol_dollar}metadata">Link to Car Sample Service Metadata - /CarService.svc/${symbol_dollar}metadata</a></li>
+ </ul>
+ </div>
+ <div>
+ <ul>
+ <li>Entity Sets
+ <ul>
+ <li><a href="CarService.svc/Cars">/Cars</a></li>
+ <li><a href="CarService.svc/Manufacturers">/Manufacturers</a></li>
+ </ul>
+ </li>
+ <li>Sample Entities
+ <ul>
+ <li><a href="CarService.svc/Cars(1)">/Cars(1)</a></li>
+ <li><a href="CarService.svc/Cars(3)">/Cars(3)</a></li>
+ <li><a href="CarService.svc/Cars(3)/Manufacturer">/Cars(3)/Manufacturer</a></li>
+ <li><a href="CarService.svc/Manufacturers(1)">/Manufacturers(1)</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ </body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/test/resources/projects/basic/archetype.properties
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/test/resources/projects/basic/archetype.properties b/odata2-sample/cars-service-archetype/src/test/resources/projects/basic/archetype.properties
new file mode 100644
index 0000000..ac7b438
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/test/resources/projects/basic/archetype.properties
@@ -0,0 +1,5 @@
+#Tue Oct 29 12:59:58 CET 2013
+package=it.pkg
+version=0.1-SNAPSHOT
+groupId=archetype.it
+artifactId=basic
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/test/resources/projects/basic/goal.txt
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/test/resources/projects/basic/goal.txt b/odata2-sample/cars-service-archetype/src/test/resources/projects/basic/goal.txt
new file mode 100644
index 0000000..e69de29
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/pom.xml b/odata2-sample/pom.xml
index d80b703..576d4f0 100644
--- a/odata2-sample/pom.xml
+++ b/odata2-sample/pom.xml
@@ -22,6 +22,6 @@
</parent>
<modules>
- <module>cars-archetype</module>
+ <module>cars-service-archetype</module>
</modules>
</project>
[6/6] git commit: [OLINGO-37] - Archetype support - refactoring
Posted by sk...@apache.org.
[OLINGO-37] - Archetype support - refactoring
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/ed52dd3a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/ed52dd3a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/ed52dd3a
Branch: refs/heads/master
Commit: ed52dd3a23054e299f8589b5d44fc18bed181d29
Parents: 59373b9
Author: Stephan Klevenz <sk...@apache.org>
Authored: Tue Oct 29 13:37:39 2013 +0100
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Tue Oct 29 13:37:39 2013 +0100
----------------------------------------------------------------------
odata2-sample/cars-archetype/pom.xml | 72 -----
.../META-INF/maven/archetype-metadata.xml | 33 ---
.../main/resources/archetype-resources/pom.xml | 97 -------
.../src/main/java/CarDataStore.java | 173 ------------
.../src/main/java/CarEdmProvider.java | 281 -------------------
.../src/main/java/CarODataSingleProcessor.java | 154 ----------
.../src/main/java/CarServiceFactory.java | 42 ---
.../src/main/resources/log4j.xml | 36 ---
.../src/main/webapp/WEB-INF/web.xml | 49 ----
.../src/main/webapp/index.html | 55 ----
.../projects/basic/archetype.properties | 5 -
.../src/test/resources/projects/basic/goal.txt | 0
odata2-sample/cars-service-archetype/pom.xml | 72 +++++
.../META-INF/maven/archetype-metadata.xml | 33 +++
.../main/resources/archetype-resources/pom.xml | 97 +++++++
.../src/main/java/CarDataStore.java | 173 ++++++++++++
.../src/main/java/CarEdmProvider.java | 281 +++++++++++++++++++
.../src/main/java/CarODataSingleProcessor.java | 154 ++++++++++
.../src/main/java/CarServiceFactory.java | 42 +++
.../src/main/resources/log4j.xml | 36 +++
.../src/main/webapp/WEB-INF/web.xml | 49 ++++
.../src/main/webapp/index.html | 55 ++++
.../projects/basic/archetype.properties | 5 +
.../src/test/resources/projects/basic/goal.txt | 0
odata2-sample/pom.xml | 2 +-
25 files changed, 998 insertions(+), 998 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/pom.xml b/odata2-sample/cars-archetype/pom.xml
deleted file mode 100644
index fd956e3..0000000
--- a/odata2-sample/cars-archetype/pom.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<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.apache.olingo</groupId>
- <artifactId>olingo-odata2-sample-cars-service-incubating-archetype</artifactId>
- <name>${project.artifactId}</name>
- <version>1.1.0-SNAPSHOT</version>
-
- <packaging>maven-archetype</packaging>
-
- <parent>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-sample-incubating</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <build>
- <extensions>
- <extension>
- <groupId>org.apache.maven.archetype</groupId>
- <artifactId>archetype-packaging</artifactId>
- <version>2.2</version>
- </extension>
- </extensions>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-archetype-plugin</artifactId>
- <version>2.2</version>
- </plugin>
- </plugins>
- </pluginManagement>
-
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-archetype-plugin</artifactId>
- <executions>
- <execution>
- <id>integration-test</id>
- <goals>
- <goal>integration-test</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/odata2-sample/cars-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
deleted file mode 100644
index 6a4f0ae..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="olingo-odata2-sample-cars-service-incubating"
- xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <fileSets>
- <fileSet filtered="true" packaged="true" encoding="UTF-8">
- <directory>src/main/java</directory>
- <includes>
- <include>**/*.java</include>
- </includes>
- </fileSet>
- <fileSet filtered="true" encoding="UTF-8">
- <directory>src/main/webapp</directory>
- <includes>
- <include>**/*.xml</include>
- <include>**/*.html</include>
- </includes>
- </fileSet>
- <fileSet filtered="true" encoding="UTF-8">
- <directory>src/main/resources</directory>
- <includes>
- <include>**/*.xml</include>
- </includes>
- </fileSet>
- <fileSet filtered="true" encoding="UTF-8">
- <directory></directory>
- <includes>
- <include>.classpath</include>
- <include>.project</include>
- </includes>
- </fileSet>
- </fileSets>
-</archetype-descriptor>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
deleted file mode 100644
index 55f2acf..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/pom.xml
+++ /dev/null
@@ -1,97 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. --><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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>${groupId}</groupId>
- <artifactId>${artifactId}</artifactId>
- <name>${project.artifactId}</name>
- <version>${version}</version>
-
- <packaging>war</packaging>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <build>
- <finalName>${project.artifactId}</finalName>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <version>2.4</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-eclipse-plugin</artifactId>
- <version>2.9</version>
- </plugin>
- </plugins>
- </pluginManagement>
-
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-eclipse-plugin</artifactId>
- <configuration>
- <addGroupIdToProjectName>true</addGroupIdToProjectName>
- <addVersionToProjectName>true</addVersionToProjectName>
- <wtpversion>2.0</wtpversion>
- <downloadSources>true</downloadSources>
- <downloadJavadocs>true</downloadJavadocs>
- </configuration>
- </plugin>
- </plugins>
-
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-core-incubating</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-frontend-jaxrs</artifactId>
- <version>2.7.5</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.1</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.1</version>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java
deleted file mode 100644
index a39f1b7..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java
+++ /dev/null
@@ -1,173 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*******************************************************************************
- * 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 ${package};
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-
-public class CarDataStore {
-
- // Data accessors
- public Map<String, Object> getCar(final int id) {
- Map<String, Object> data = null;
-
- Calendar updated = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
- switch (id) {
- case 1:
- updated.set(2012, 11, 11, 11, 11, 11);
- data = createCar(1, "F1 W03", 1, 189189.43, "EUR", "2012", updated, "file://imagePath/w03");
- break;
-
- case 2:
- updated.set(2013, 11, 11, 11, 11, 11);
- data = createCar(2, "F1 W04", 1, 199999.99, "EUR", "2013", updated, "file://imagePath/w04");
- break;
-
- case 3:
- updated.set(2012, 12, 12, 12, 12, 12);
- data = createCar(3, "F2012", 2, 137285.33, "EUR", "2012", updated, "http://pathToImage/f2012");
- break;
-
- case 4:
- updated.set(2013, 12, 12, 12, 12, 12);
- data = createCar(4, "F2013", 2, 145285.00, "EUR", "2013", updated, "http://pathToImage/f2013");
- break;
-
- case 5:
- updated.set(2011, 11, 11, 11, 11, 11);
- data = createCar(5, "F1 W02", 1, 167189.00, "EUR", "2011", updated, "file://imagePath/wXX");
- break;
-
- default:
- break;
- }
-
- return data;
- }
-
- private Map<String, Object> createCar(final int carId, final String model, final int manufacturerId,
- final double price,
- final String currency, final String modelYear, final Calendar updated, final String imagePath) {
- Map<String, Object> data = new HashMap<String, Object>();
-
- data.put("Id", carId);
- data.put("Model", model);
- data.put("ManufacturerId", manufacturerId);
- data.put("Price", price);
- data.put("Currency", currency);
- data.put("ModelYear", modelYear);
- data.put("Updated", updated);
- data.put("ImagePath", imagePath);
-
- return data;
- }
-
- public Map<String, Object> getManufacturer(final int id) {
- Map<String, Object> data = null;
- Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
- switch (id) {
- case 1:
- Map<String, Object> addressStar = createAddress("Star Street 137", "Stuttgart", "70173", "Germany");
- date.set(1954, 7, 4);
- data = createManufacturer(1, "Star Powered Racing", addressStar, date);
- break;
-
- case 2:
- Map<String, Object> addressHorse = createAddress("Horse Street 1", "Maranello", "41053", "Italy");
- date.set(1929, 11, 16);
- data = createManufacturer(2, "Horse Powered Racing", addressHorse, date);
- break;
-
- default:
- break;
- }
-
- return data;
- }
-
- private Map<String, Object> createManufacturer(final int id, final String name, final Map<String, Object> address,
- final Calendar updated) {
- Map<String, Object> data = new HashMap<String, Object>();
- data.put("Id", id);
- data.put("Name", name);
- data.put("Address", address);
- data.put("Updated", updated);
- return data;
- }
-
- private Map<String, Object> createAddress(final String street, final String city, final String zipCode,
- final String country) {
- Map<String, Object> address = new HashMap<String, Object>();
- address.put("Street", street);
- address.put("City", city);
- address.put("ZipCode", zipCode);
- address.put("Country", country);
- return address;
- }
-
- public List<Map<String, Object>> getCars() {
- List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
- cars.add(getCar(1));
- cars.add(getCar(2));
- cars.add(getCar(3));
- cars.add(getCar(4));
- cars.add(getCar(5));
- return cars;
- }
-
- public List<Map<String, Object>> getManufacturers() {
- List<Map<String, Object>> manufacturers = new ArrayList<Map<String, Object>>();
- manufacturers.add(getManufacturer(1));
- manufacturers.add(getManufacturer(2));
- return manufacturers;
- }
-
- public List<Map<String, Object>> getCarsFor(final int manufacturerId) {
- List<Map<String, Object>> cars = getCars();
- List<Map<String, Object>> carsForManufacturer = new ArrayList<Map<String, Object>>();
-
- for (Map<String, Object> car : cars) {
- if (Integer.valueOf(manufacturerId).equals(car.get("ManufacturerId"))) {
- carsForManufacturer.add(car);
- }
- }
-
- return carsForManufacturer;
- }
-
- public Map<String, Object> getManufacturerFor(final int carId) {
- Map<String, Object> car = getCar(carId);
- if (car != null) {
- Object manufacturerId = car.get("ManufacturerId");
- if (manufacturerId != null) {
- return getManufacturer((Integer) manufacturerId);
- }
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java
deleted file mode 100644
index d1ecdac..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java
+++ /dev/null
@@ -1,281 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*******************************************************************************
- * 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 ${package};
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTargetPath;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.CustomizableFeedMappings;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Facets;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.Key;
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata2.api.edm.provider.ReturnType;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.api.exception.ODataException;
-
-public class CarEdmProvider extends EdmProvider {
-
- static final String ENTITY_SET_NAME_MANUFACTURERS = "Manufacturers";
- static final String ENTITY_SET_NAME_CARS = "Cars";
- static final String ENTITY_NAME_MANUFACTURER = "Manufacturer";
- static final String ENTITY_NAME_CAR = "Car";
-
- private static final String NAMESPACE = "org.apache.olingo.odata2.ODataCars";
-
- private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_CAR);
- private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_MANUFACTURER);
-
- private static final FullQualifiedName COMPLEX_TYPE = new FullQualifiedName(NAMESPACE, "Address");
-
- private static final FullQualifiedName ASSOCIATION_CAR_MANUFACTURER = new FullQualifiedName(NAMESPACE,
- "Car_Manufacturer_Manufacturer_Cars");
-
- private static final String ROLE_1_1 = "Car_Manufacturer";
- private static final String ROLE_1_2 = "Manufacturer_Cars";
-
- private static final String ENTITY_CONTAINER = "ODataCarsEntityContainer";
-
- private static final String ASSOCIATION_SET = "Cars_Manufacturers";
-
- private static final String FUNCTION_IMPORT = "NumberOfCars";
-
- @Override
- public List<Schema> getSchemas() throws ODataException {
- List<Schema> schemas = new ArrayList<Schema>();
-
- Schema schema = new Schema();
- schema.setNamespace(NAMESPACE);
-
- List<EntityType> entityTypes = new ArrayList<EntityType>();
- entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
- entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
- schema.setEntityTypes(entityTypes);
-
- List<ComplexType> complexTypes = new ArrayList<ComplexType>();
- complexTypes.add(getComplexType(COMPLEX_TYPE));
- schema.setComplexTypes(complexTypes);
-
- List<Association> associations = new ArrayList<Association>();
- associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER));
- schema.setAssociations(associations);
-
- List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
- EntityContainer entityContainer = new EntityContainer();
- entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
-
- List<EntitySet> entitySets = new ArrayList<EntitySet>();
- entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS));
- entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS));
- entityContainer.setEntitySets(entitySets);
-
- List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
- associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER,
- ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2));
- entityContainer.setAssociationSets(associationSets);
-
- List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
- functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT));
- entityContainer.setFunctionImports(functionImports);
-
- entityContainers.add(entityContainer);
- schema.setEntityContainers(entityContainers);
-
- schemas.add(schema);
-
- return schemas;
- }
-
- @Override
- public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
-
- if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
-
- // Properties
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
- new Facets().setNullable(false)));
- properties.add(new SimpleProperty().setName("Model").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setNullable(false).setMaxLength(100).setDefaultValue("Hugo"))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
- properties.add(new SimpleProperty().setName("ManufacturerId").setType(EdmSimpleTypeKind.Int32));
- properties.add(new SimpleProperty().setName("Price").setType(EdmSimpleTypeKind.Decimal));
- properties.add(new SimpleProperty().setName("Currency").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setMaxLength(3)));
- properties.add(new SimpleProperty().setName("ModelYear").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setMaxLength(4)));
- properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
- .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
- properties.add(new SimpleProperty().setName("ImagePath").setType(EdmSimpleTypeKind.String));
-
- // Navigation Properties
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("Manufacturer")
- .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
-
- // Key
- List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
- keyProperties.add(new PropertyRef().setName("Id"));
- Key key = new Key().setKeys(keyProperties);
-
- return new EntityType().setName(ENTITY_TYPE_1_1.getName())
- .setProperties(properties)
- .setKey(key)
- .setNavigationProperties(navigationProperties);
-
- } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
-
- // Properties
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
- new Facets().setNullable(false)));
- properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setNullable(false).setMaxLength(100))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
- properties.add(new ComplexProperty().setName("Address").setType(new FullQualifiedName(NAMESPACE, "Address")));
- properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
- .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
-
- // Navigation Properties
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("Cars")
- .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
-
- // Key
- List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
- keyProperties.add(new PropertyRef().setName("Id"));
- Key key = new Key().setKeys(keyProperties);
-
- return new EntityType().setName(ENTITY_TYPE_1_2.getName())
- .setProperties(properties)
- .setKey(key)
- .setNavigationProperties(navigationProperties);
-
- }
- }
-
- return null;
- }
-
- @Override
- public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
- if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
- return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
- }
- }
-
- return null;
- }
-
- @Override
- public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
- if (ASSOCIATION_CAR_MANUFACTURER.getName().equals(edmFQName.getName())) {
- return new Association().setName(ASSOCIATION_CAR_MANUFACTURER.getName())
- .setEnd1(
- new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
- .setEnd2(
- new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
- }
- }
- return null;
- }
-
- @Override
- public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (ENTITY_SET_NAME_CARS.equals(name)) {
- return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
- return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
- }
- }
- return null;
- }
-
- @Override
- public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association,
- final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (ASSOCIATION_CAR_MANUFACTURER.equals(association)) {
- return new AssociationSet().setName(ASSOCIATION_SET)
- .setAssociation(ASSOCIATION_CAR_MANUFACTURER)
- .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_NAME_MANUFACTURERS))
- .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_NAME_CARS));
- }
- }
- return null;
- }
-
- @Override
- public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (FUNCTION_IMPORT.equals(name)) {
- return new FunctionImport().setName(name)
- .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
- .setHttpMethod("GET");
- }
- }
- return null;
- }
-
- @Override
- public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataException {
- if (name == null || "ODataCarsEntityContainer".equals(name)) {
- return new EntityContainerInfo().setName("ODataCarsEntityContainer").setDefaultEntityContainer(true);
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java
deleted file mode 100644
index b18355d..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarODataSingleProcessor.java
+++ /dev/null
@@ -1,154 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*******************************************************************************
- * 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 ${package};
-
-import static ${package}.CarEdmProvider.ENTITY_SET_NAME_CARS;
-import static ${package}.CarEdmProvider.ENTITY_SET_NAME_MANUFACTURERS;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-
-public class CarODataSingleProcessor extends ODataSingleProcessor {
-
- private final CarDataStore dataStore;
-
- public CarODataSingleProcessor() {
- dataStore = new CarDataStore();
- }
-
- @Override
- public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
- throws ODataException {
-
- EdmEntitySet entitySet;
-
- if (uriInfo.getNavigationSegments().size() == 0) {
- entitySet = uriInfo.getStartEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
-
- } else if (uriInfo.getNavigationSegments().size() == 1) {
- // navigation first level, simplified example for illustration purposes only
- entitySet = uriInfo.getTargetEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
-
- List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
- cars.addAll(dataStore.getCarsFor(manufacturerKey));
-
- return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
- getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- throw new ODataNotImplementedException();
- }
-
- @Override
- public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
-
- if (uriInfo.getNavigationSegments().size() == 0) {
- EdmEntitySet entitySet = uriInfo.getStartEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
- Map<String, Object> data = dataStore.getCar(id);
-
- if (data != null) {
- URI serviceRoot = getContext().getPathInfo().getServiceRoot();
- ODataEntityProviderPropertiesBuilder propertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(serviceRoot);
-
- return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
- }
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
- Map<String, Object> data = dataStore.getManufacturer(id);
-
- if (data != null) {
- URI serviceRoot = getContext().getPathInfo().getServiceRoot();
- ODataEntityProviderPropertiesBuilder propertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(serviceRoot);
-
- return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
- }
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
-
- } else if (uriInfo.getNavigationSegments().size() == 1) {
- // navigation first level, simplified example for illustration purposes only
- EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
-
- Map<String, Object> data = null;
-
- if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
- data = dataStore.getManufacturerFor(carKey);
- }
-
- if (data != null) {
- return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
- data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- throw new ODataNotImplementedException();
- }
-
- private int getKeyValue(final KeyPredicate key) throws ODataException {
- EdmProperty property = key.getProperty();
- EdmSimpleType type = (EdmSimpleType) property.getType();
- return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java
deleted file mode 100644
index 6806631..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/java/CarServiceFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-/*******************************************************************************
- * 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 ${package};
-
-import org.apache.olingo.odata2.api.ODataService;
-import org.apache.olingo.odata2.api.ODataServiceFactory;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-
-public class CarServiceFactory extends ODataServiceFactory {
-
- @Override
- public ODataService createService(final ODataContext ctx) throws ODataException {
-
- EdmProvider edmProvider = new CarEdmProvider();
-
- ODataSingleProcessor singleProcessor = new CarODataSingleProcessor();
-
- return createODataSingleProcessorService(edmProvider, singleProcessor);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
deleted file mode 100644
index ed91239..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/resources/log4j.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- 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.
--->
-<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
- <appender name="console" class="org.apache.log4j.ConsoleAppender">
- <param name="Target" value="System.out" />
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%-5p %c{1} - %m%n" />
- </layout>
- </appender>
-
- <root>
- <priority value="error" />
- <appender-ref ref="console" />
- </root>
-</log4j:configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index b5b07da..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<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">
- <display-name>org.apache.olingo.odata2.sample</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- </welcome-file-list>
-
- <servlet>
- <servlet-name>CarServiceServlet</servlet-name>
- <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
- <init-param>
- <param-name>javax.ws.rs.Application</param-name>
- <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>
- </init-param>
- <init-param>
- <param-name>org.apache.olingo.odata2.service.factory</param-name>
- <param-value>${package}.CarServiceFactory</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>CarServiceServlet</servlet-name>
- <url-pattern>/CarService.svc/*</url-pattern>
- </servlet-mapping>
-</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html b/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
deleted file mode 100644
index 810c748..0000000
--- a/odata2-sample/cars-archetype/src/main/resources/archetype-resources/src/main/webapp/index.html
+++ /dev/null
@@ -1,55 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<!--
- 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.
--->
-<html>
- <head>
- <title></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
- <body>
- <h1>Apache Olingo - OData Car Sample Project</h1>
- <div>
- <ul>
- <li><a href="CarService.svc">Link to Car Sample Service Root - /CarService.svc</a></li>
- <li><a href="CarService.svc/${symbol_dollar}metadata">Link to Car Sample Service Metadata - /CarService.svc/${symbol_dollar}metadata</a></li>
- </ul>
- </div>
- <div>
- <ul>
- <li>Entity Sets
- <ul>
- <li><a href="CarService.svc/Cars">/Cars</a></li>
- <li><a href="CarService.svc/Manufacturers">/Manufacturers</a></li>
- </ul>
- </li>
- <li>Sample Entities
- <ul>
- <li><a href="CarService.svc/Cars(1)">/Cars(1)</a></li>
- <li><a href="CarService.svc/Cars(3)">/Cars(3)</a></li>
- <li><a href="CarService.svc/Cars(3)/Manufacturer">/Cars(3)/Manufacturer</a></li>
- <li><a href="CarService.svc/Manufacturers(1)">/Manufacturers(1)</a></li>
- </ul>
- </li>
- </ul>
- </div>
- </body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties b/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
deleted file mode 100644
index ac7b438..0000000
--- a/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-#Tue Oct 29 12:59:58 CET 2013
-package=it.pkg
-version=0.1-SNAPSHOT
-groupId=archetype.it
-artifactId=basic
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-archetype/src/test/resources/projects/basic/goal.txt
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/test/resources/projects/basic/goal.txt b/odata2-sample/cars-archetype/src/test/resources/projects/basic/goal.txt
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/pom.xml b/odata2-sample/cars-service-archetype/pom.xml
new file mode 100644
index 0000000..fd956e3
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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.apache.olingo</groupId>
+ <artifactId>olingo-odata2-sample-cars-service-incubating-archetype</artifactId>
+ <name>${project.artifactId}</name>
+ <version>1.1.0-SNAPSHOT</version>
+
+ <packaging>maven-archetype</packaging>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-sample-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-packaging</artifactId>
+ <version>2.2</version>
+ </extension>
+ </extensions>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>integration-test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/odata2-sample/cars-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644
index 0000000..6a4f0ae
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="olingo-odata2-sample-cars-service-incubating"
+ xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/webapp</directory>
+ <includes>
+ <include>**/*.xml</include>
+ <include>**/*.html</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.xml</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory></directory>
+ <includes>
+ <include>.classpath</include>
+ <include>.project</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</archetype-descriptor>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/pom.xml b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/pom.xml
new file mode 100644
index 0000000..55f2acf
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. --><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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <name>${project.artifactId}</name>
+ <version>${version}</version>
+
+ <packaging>war</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.4</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <version>2.9</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <addGroupIdToProjectName>true</addGroupIdToProjectName>
+ <addVersionToProjectName>true</addVersionToProjectName>
+ <wtpversion>2.0</wtpversion>
+ <downloadSources>true</downloadSources>
+ <downloadJavadocs>true</downloadJavadocs>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-core-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>2.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java
new file mode 100644
index 0000000..a39f1b7
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarDataStore.java
@@ -0,0 +1,173 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*******************************************************************************
+ * 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 ${package};
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+public class CarDataStore {
+
+ // Data accessors
+ public Map<String, Object> getCar(final int id) {
+ Map<String, Object> data = null;
+
+ Calendar updated = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ updated.set(2012, 11, 11, 11, 11, 11);
+ data = createCar(1, "F1 W03", 1, 189189.43, "EUR", "2012", updated, "file://imagePath/w03");
+ break;
+
+ case 2:
+ updated.set(2013, 11, 11, 11, 11, 11);
+ data = createCar(2, "F1 W04", 1, 199999.99, "EUR", "2013", updated, "file://imagePath/w04");
+ break;
+
+ case 3:
+ updated.set(2012, 12, 12, 12, 12, 12);
+ data = createCar(3, "F2012", 2, 137285.33, "EUR", "2012", updated, "http://pathToImage/f2012");
+ break;
+
+ case 4:
+ updated.set(2013, 12, 12, 12, 12, 12);
+ data = createCar(4, "F2013", 2, 145285.00, "EUR", "2013", updated, "http://pathToImage/f2013");
+ break;
+
+ case 5:
+ updated.set(2011, 11, 11, 11, 11, 11);
+ data = createCar(5, "F1 W02", 1, 167189.00, "EUR", "2011", updated, "file://imagePath/wXX");
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createCar(final int carId, final String model, final int manufacturerId,
+ final double price,
+ final String currency, final String modelYear, final Calendar updated, final String imagePath) {
+ Map<String, Object> data = new HashMap<String, Object>();
+
+ data.put("Id", carId);
+ data.put("Model", model);
+ data.put("ManufacturerId", manufacturerId);
+ data.put("Price", price);
+ data.put("Currency", currency);
+ data.put("ModelYear", modelYear);
+ data.put("Updated", updated);
+ data.put("ImagePath", imagePath);
+
+ return data;
+ }
+
+ public Map<String, Object> getManufacturer(final int id) {
+ Map<String, Object> data = null;
+ Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+
+ switch (id) {
+ case 1:
+ Map<String, Object> addressStar = createAddress("Star Street 137", "Stuttgart", "70173", "Germany");
+ date.set(1954, 7, 4);
+ data = createManufacturer(1, "Star Powered Racing", addressStar, date);
+ break;
+
+ case 2:
+ Map<String, Object> addressHorse = createAddress("Horse Street 1", "Maranello", "41053", "Italy");
+ date.set(1929, 11, 16);
+ data = createManufacturer(2, "Horse Powered Racing", addressHorse, date);
+ break;
+
+ default:
+ break;
+ }
+
+ return data;
+ }
+
+ private Map<String, Object> createManufacturer(final int id, final String name, final Map<String, Object> address,
+ final Calendar updated) {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("Id", id);
+ data.put("Name", name);
+ data.put("Address", address);
+ data.put("Updated", updated);
+ return data;
+ }
+
+ private Map<String, Object> createAddress(final String street, final String city, final String zipCode,
+ final String country) {
+ Map<String, Object> address = new HashMap<String, Object>();
+ address.put("Street", street);
+ address.put("City", city);
+ address.put("ZipCode", zipCode);
+ address.put("Country", country);
+ return address;
+ }
+
+ public List<Map<String, Object>> getCars() {
+ List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
+ cars.add(getCar(1));
+ cars.add(getCar(2));
+ cars.add(getCar(3));
+ cars.add(getCar(4));
+ cars.add(getCar(5));
+ return cars;
+ }
+
+ public List<Map<String, Object>> getManufacturers() {
+ List<Map<String, Object>> manufacturers = new ArrayList<Map<String, Object>>();
+ manufacturers.add(getManufacturer(1));
+ manufacturers.add(getManufacturer(2));
+ return manufacturers;
+ }
+
+ public List<Map<String, Object>> getCarsFor(final int manufacturerId) {
+ List<Map<String, Object>> cars = getCars();
+ List<Map<String, Object>> carsForManufacturer = new ArrayList<Map<String, Object>>();
+
+ for (Map<String, Object> car : cars) {
+ if (Integer.valueOf(manufacturerId).equals(car.get("ManufacturerId"))) {
+ carsForManufacturer.add(car);
+ }
+ }
+
+ return carsForManufacturer;
+ }
+
+ public Map<String, Object> getManufacturerFor(final int carId) {
+ Map<String, Object> car = getCar(carId);
+ if (car != null) {
+ Object manufacturerId = car.get("ManufacturerId");
+ if (manufacturerId != null) {
+ return getManufacturer((Integer) manufacturerId);
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ed52dd3a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java
new file mode 100644
index 0000000..d1ecdac
--- /dev/null
+++ b/odata2-sample/cars-service-archetype/src/main/resources/archetype-resources/src/main/java/CarEdmProvider.java
@@ -0,0 +1,281 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*******************************************************************************
+ * 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 ${package};
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTargetPath;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.CustomizableFeedMappings;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.ReturnType;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+
+public class CarEdmProvider extends EdmProvider {
+
+ static final String ENTITY_SET_NAME_MANUFACTURERS = "Manufacturers";
+ static final String ENTITY_SET_NAME_CARS = "Cars";
+ static final String ENTITY_NAME_MANUFACTURER = "Manufacturer";
+ static final String ENTITY_NAME_CAR = "Car";
+
+ private static final String NAMESPACE = "org.apache.olingo.odata2.ODataCars";
+
+ private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_CAR);
+ private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_MANUFACTURER);
+
+ private static final FullQualifiedName COMPLEX_TYPE = new FullQualifiedName(NAMESPACE, "Address");
+
+ private static final FullQualifiedName ASSOCIATION_CAR_MANUFACTURER = new FullQualifiedName(NAMESPACE,
+ "Car_Manufacturer_Manufacturer_Cars");
+
+ private static final String ROLE_1_1 = "Car_Manufacturer";
+ private static final String ROLE_1_2 = "Manufacturer_Cars";
+
+ private static final String ENTITY_CONTAINER = "ODataCarsEntityContainer";
+
+ private static final String ASSOCIATION_SET = "Cars_Manufacturers";
+
+ private static final String FUNCTION_IMPORT = "NumberOfCars";
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ List<Schema> schemas = new ArrayList<Schema>();
+
+ Schema schema = new Schema();
+ schema.setNamespace(NAMESPACE);
+
+ List<EntityType> entityTypes = new ArrayList<EntityType>();
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
+ entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
+ schema.setEntityTypes(entityTypes);
+
+ List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ complexTypes.add(getComplexType(COMPLEX_TYPE));
+ schema.setComplexTypes(complexTypes);
+
+ List<Association> associations = new ArrayList<Association>();
+ associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER));
+ schema.setAssociations(associations);
+
+ List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
+ EntityContainer entityContainer = new EntityContainer();
+ entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
+
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS));
+ entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS));
+ entityContainer.setEntitySets(entitySets);
+
+ List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER,
+ ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2));
+ entityContainer.setAssociationSets(associationSets);
+
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT));
+ entityContainer.setFunctionImports(functionImports);
+
+ entityContainers.add(entityContainer);
+ schema.setEntityContainers(entityContainers);
+
+ schemas.add(schema);
+
+ return schemas;
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+
+ if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Model").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100).setDefaultValue("Hugo"))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new SimpleProperty().setName("ManufacturerId").setType(EdmSimpleTypeKind.Int32));
+ properties.add(new SimpleProperty().setName("Price").setType(EdmSimpleTypeKind.Decimal));
+ properties.add(new SimpleProperty().setName("Currency").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(3)));
+ properties.add(new SimpleProperty().setName("ModelYear").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setMaxLength(4)));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+ properties.add(new SimpleProperty().setName("ImagePath").setType(EdmSimpleTypeKind.String));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Manufacturer")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_1.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
+
+ // Properties
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
+ new Facets().setNullable(false)));
+ properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String).setFacets(
+ new Facets().setNullable(false).setMaxLength(100))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
+ properties.add(new ComplexProperty().setName("Address").setType(new FullQualifiedName(NAMESPACE, "Address")));
+ properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
+ .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
+ .setCustomizableFeedMappings(
+ new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
+
+ // Navigation Properties
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("Cars")
+ .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
+
+ // Key
+ List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ keyProperties.add(new PropertyRef().setName("Id"));
+ Key key = new Key().setKeys(keyProperties);
+
+ return new EntityType().setName(ENTITY_TYPE_1_2.getName())
+ .setProperties(properties)
+ .setKey(key)
+ .setNavigationProperties(navigationProperties);
+
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
+ properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
+ return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
+ if (NAMESPACE.equals(edmFQName.getNamespace())) {
+ if (ASSOCIATION_CAR_MANUFACTURER.getName().equals(edmFQName.getName())) {
+ return new Association().setName(ASSOCIATION_CAR_MANUFACTURER.getName())
+ .setEnd1(
+ new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setEnd2(
+ new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ENTITY_SET_NAME_CARS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
+ } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
+ return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association,
+ final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (ASSOCIATION_CAR_MANUFACTURER.equals(association)) {
+ return new AssociationSet().setName(ASSOCIATION_SET)
+ .setAssociation(ASSOCIATION_CAR_MANUFACTURER)
+ .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_NAME_MANUFACTURERS))
+ .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_NAME_CARS));
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
+ if (ENTITY_CONTAINER.equals(entityContainer)) {
+ if (FUNCTION_IMPORT.equals(name)) {
+ return new FunctionImport().setName(name)
+ .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
+ .setHttpMethod("GET");
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataException {
+ if (name == null || "ODataCarsEntityContainer".equals(name)) {
+ return new EntityContainerInfo().setName("ODataCarsEntityContainer").setDefaultEntityContainer(true);
+ }
+
+ return null;
+ }
+}
[4/6] git commit: [OLINGO-37] - Archetype support - sample not needed
Posted by sk...@apache.org.
[OLINGO-37] - Archetype support - sample not needed
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/59373b99
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/59373b99
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/59373b99
Branch: refs/heads/master
Commit: 59373b9936a3b2bbe3f80ef414315ce0ac1dbe5b
Parents: c348f0a
Author: Stephan Klevenz <sk...@apache.org>
Authored: Tue Oct 29 13:33:54 2013 +0100
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Tue Oct 29 13:33:54 2013 +0100
----------------------------------------------------------------------
odata2-sample/cars-archetype/pom.xml | 27 +-
.../projects/basic/archetype.properties | 2 +-
odata2-sample/cars-service/pom.xml | 99 -------
.../odata2/sample/service/CarDataStore.java | 170 ------------
.../odata2/sample/service/CarEdmProvider.java | 278 -------------------
.../sample/service/CarODataSingleProcessor.java | 151 ----------
.../sample/service/CarServiceFactory.java | 39 ---
.../cars-service/src/main/resources/log4j.xml | 33 ---
.../src/main/webapp/WEB-INF/web.xml | 46 ---
.../cars-service/src/main/webapp/index.html | 52 ----
odata2-sample/pom.xml | 3 +-
11 files changed, 21 insertions(+), 879 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-archetype/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/pom.xml b/odata2-sample/cars-archetype/pom.xml
index 0251118..fd956e3 100644
--- a/odata2-sample/cars-archetype/pom.xml
+++ b/odata2-sample/cars-archetype/pom.xml
@@ -1,11 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. -->
+<!--
+ 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.
+-->
<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>
@@ -19,7 +30,7 @@
<parent>
<groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-sample</artifactId>
+ <artifactId>olingo-odata2-sample-incubating</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties b/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
index 2a43880..ac7b438 100644
--- a/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
+++ b/odata2-sample/cars-archetype/src/test/resources/projects/basic/archetype.properties
@@ -1,4 +1,4 @@
-#Tue Oct 29 12:52:49 CET 2013
+#Tue Oct 29 12:59:58 CET 2013
package=it.pkg
version=0.1-SNAPSHOT
groupId=archetype.it
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-service/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/pom.xml b/odata2-sample/cars-service/pom.xml
deleted file mode 100755
index c1b55a6..0000000
--- a/odata2-sample/cars-service/pom.xml
+++ /dev/null
@@ -1,99 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. -->
-<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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>org.apache.olingo.sample</groupId>
- <artifactId>olingo-odata2-sample-cars-service-incubating</artifactId>
- <name>${project.artifactId}</name>
- <version>1.1.0-SNAPSHOT</version>
-
- <packaging>war</packaging>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <build>
- <finalName>${project.artifactId}</finalName>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <version>2.4</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-eclipse-plugin</artifactId>
- <version>2.9</version>
- </plugin>
- </plugins>
- </pluginManagement>
-
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-eclipse-plugin</artifactId>
- <configuration>
- <addGroupIdToProjectName>true</addGroupIdToProjectName>
- <addVersionToProjectName>true</addVersionToProjectName>
- <wtpversion>2.0</wtpversion>
- <downloadSources>true</downloadSources>
- <downloadJavadocs>true</downloadJavadocs>
- </configuration>
- </plugin>
- </plugins>
-
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-core-incubating</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-frontend-jaxrs</artifactId>
- <version>2.7.5</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.1</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.1</version>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarDataStore.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarDataStore.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarDataStore.java
deleted file mode 100644
index d96fc21..0000000
--- a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarDataStore.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.sample.service;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-
-public class CarDataStore {
-
- // Data accessors
- public Map<String, Object> getCar(final int id) {
- Map<String, Object> data = null;
-
- Calendar updated = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
- switch (id) {
- case 1:
- updated.set(2012, 11, 11, 11, 11, 11);
- data = createCar(1, "F1 W03", 1, 189189.43, "EUR", "2012", updated, "file://imagePath/w03");
- break;
-
- case 2:
- updated.set(2013, 11, 11, 11, 11, 11);
- data = createCar(2, "F1 W04", 1, 199999.99, "EUR", "2013", updated, "file://imagePath/w04");
- break;
-
- case 3:
- updated.set(2012, 12, 12, 12, 12, 12);
- data = createCar(3, "F2012", 2, 137285.33, "EUR", "2012", updated, "http://pathToImage/f2012");
- break;
-
- case 4:
- updated.set(2013, 12, 12, 12, 12, 12);
- data = createCar(4, "F2013", 2, 145285.00, "EUR", "2013", updated, "http://pathToImage/f2013");
- break;
-
- case 5:
- updated.set(2011, 11, 11, 11, 11, 11);
- data = createCar(5, "F1 W02", 1, 167189.00, "EUR", "2011", updated, "file://imagePath/wXX");
- break;
-
- default:
- break;
- }
-
- return data;
- }
-
- private Map<String, Object> createCar(final int carId, final String model, final int manufacturerId,
- final double price,
- final String currency, final String modelYear, final Calendar updated, final String imagePath) {
- Map<String, Object> data = new HashMap<String, Object>();
-
- data.put("Id", carId);
- data.put("Model", model);
- data.put("ManufacturerId", manufacturerId);
- data.put("Price", price);
- data.put("Currency", currency);
- data.put("ModelYear", modelYear);
- data.put("Updated", updated);
- data.put("ImagePath", imagePath);
-
- return data;
- }
-
- public Map<String, Object> getManufacturer(final int id) {
- Map<String, Object> data = null;
- Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
- switch (id) {
- case 1:
- Map<String, Object> addressStar = createAddress("Star Street 137", "Stuttgart", "70173", "Germany");
- date.set(1954, 7, 4);
- data = createManufacturer(1, "Star Powered Racing", addressStar, date);
- break;
-
- case 2:
- Map<String, Object> addressHorse = createAddress("Horse Street 1", "Maranello", "41053", "Italy");
- date.set(1929, 11, 16);
- data = createManufacturer(2, "Horse Powered Racing", addressHorse, date);
- break;
-
- default:
- break;
- }
-
- return data;
- }
-
- private Map<String, Object> createManufacturer(final int id, final String name, final Map<String, Object> address,
- final Calendar updated) {
- Map<String, Object> data = new HashMap<String, Object>();
- data.put("Id", id);
- data.put("Name", name);
- data.put("Address", address);
- data.put("Updated", updated);
- return data;
- }
-
- private Map<String, Object> createAddress(final String street, final String city, final String zipCode,
- final String country) {
- Map<String, Object> address = new HashMap<String, Object>();
- address.put("Street", street);
- address.put("City", city);
- address.put("ZipCode", zipCode);
- address.put("Country", country);
- return address;
- }
-
- public List<Map<String, Object>> getCars() {
- List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
- cars.add(getCar(1));
- cars.add(getCar(2));
- cars.add(getCar(3));
- cars.add(getCar(4));
- cars.add(getCar(5));
- return cars;
- }
-
- public List<Map<String, Object>> getManufacturers() {
- List<Map<String, Object>> manufacturers = new ArrayList<Map<String, Object>>();
- manufacturers.add(getManufacturer(1));
- manufacturers.add(getManufacturer(2));
- return manufacturers;
- }
-
- public List<Map<String, Object>> getCarsFor(final int manufacturerId) {
- List<Map<String, Object>> cars = getCars();
- List<Map<String, Object>> carsForManufacturer = new ArrayList<Map<String, Object>>();
-
- for (Map<String, Object> car : cars) {
- if (Integer.valueOf(manufacturerId).equals(car.get("ManufacturerId"))) {
- carsForManufacturer.add(car);
- }
- }
-
- return carsForManufacturer;
- }
-
- public Map<String, Object> getManufacturerFor(final int carId) {
- Map<String, Object> car = getCar(carId);
- if (car != null) {
- Object manufacturerId = car.get("ManufacturerId");
- if (manufacturerId != null) {
- return getManufacturer((Integer) manufacturerId);
- }
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarEdmProvider.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarEdmProvider.java
deleted file mode 100755
index c274ece..0000000
--- a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarEdmProvider.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.sample.service;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTargetPath;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.CustomizableFeedMappings;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Facets;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.Key;
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata2.api.edm.provider.ReturnType;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.api.exception.ODataException;
-
-public class CarEdmProvider extends EdmProvider {
-
- static final String ENTITY_SET_NAME_MANUFACTURERS = "Manufacturers";
- static final String ENTITY_SET_NAME_CARS = "Cars";
- static final String ENTITY_NAME_MANUFACTURER = "Manufacturer";
- static final String ENTITY_NAME_CAR = "Car";
-
- private static final String NAMESPACE = "org.apache.olingo.odata2.ODataCars";
-
- private static final FullQualifiedName ENTITY_TYPE_1_1 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_CAR);
- private static final FullQualifiedName ENTITY_TYPE_1_2 = new FullQualifiedName(NAMESPACE, ENTITY_NAME_MANUFACTURER);
-
- private static final FullQualifiedName COMPLEX_TYPE = new FullQualifiedName(NAMESPACE, "Address");
-
- private static final FullQualifiedName ASSOCIATION_CAR_MANUFACTURER = new FullQualifiedName(NAMESPACE,
- "Car_Manufacturer_Manufacturer_Cars");
-
- private static final String ROLE_1_1 = "Car_Manufacturer";
- private static final String ROLE_1_2 = "Manufacturer_Cars";
-
- private static final String ENTITY_CONTAINER = "ODataCarsEntityContainer";
-
- private static final String ASSOCIATION_SET = "Cars_Manufacturers";
-
- private static final String FUNCTION_IMPORT = "NumberOfCars";
-
- @Override
- public List<Schema> getSchemas() throws ODataException {
- List<Schema> schemas = new ArrayList<Schema>();
-
- Schema schema = new Schema();
- schema.setNamespace(NAMESPACE);
-
- List<EntityType> entityTypes = new ArrayList<EntityType>();
- entityTypes.add(getEntityType(ENTITY_TYPE_1_1));
- entityTypes.add(getEntityType(ENTITY_TYPE_1_2));
- schema.setEntityTypes(entityTypes);
-
- List<ComplexType> complexTypes = new ArrayList<ComplexType>();
- complexTypes.add(getComplexType(COMPLEX_TYPE));
- schema.setComplexTypes(complexTypes);
-
- List<Association> associations = new ArrayList<Association>();
- associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER));
- schema.setAssociations(associations);
-
- List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
- EntityContainer entityContainer = new EntityContainer();
- entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);
-
- List<EntitySet> entitySets = new ArrayList<EntitySet>();
- entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS));
- entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS));
- entityContainer.setEntitySets(entitySets);
-
- List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
- associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER,
- ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2));
- entityContainer.setAssociationSets(associationSets);
-
- List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
- functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT));
- entityContainer.setFunctionImports(functionImports);
-
- entityContainers.add(entityContainer);
- schema.setEntityContainers(entityContainers);
-
- schemas.add(schema);
-
- return schemas;
- }
-
- @Override
- public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
-
- if (ENTITY_TYPE_1_1.getName().equals(edmFQName.getName())) {
-
- // Properties
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
- new Facets().setNullable(false)));
- properties.add(new SimpleProperty().setName("Model").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setNullable(false).setMaxLength(100).setDefaultValue("Hugo"))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
- properties.add(new SimpleProperty().setName("ManufacturerId").setType(EdmSimpleTypeKind.Int32));
- properties.add(new SimpleProperty().setName("Price").setType(EdmSimpleTypeKind.Decimal));
- properties.add(new SimpleProperty().setName("Currency").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setMaxLength(3)));
- properties.add(new SimpleProperty().setName("ModelYear").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setMaxLength(4)));
- properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
- .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
- properties.add(new SimpleProperty().setName("ImagePath").setType(EdmSimpleTypeKind.String));
-
- // Navigation Properties
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("Manufacturer")
- .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_1).setToRole(ROLE_1_2));
-
- // Key
- List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
- keyProperties.add(new PropertyRef().setName("Id"));
- Key key = new Key().setKeys(keyProperties);
-
- return new EntityType().setName(ENTITY_TYPE_1_1.getName())
- .setProperties(properties)
- .setKey(key)
- .setNavigationProperties(navigationProperties);
-
- } else if (ENTITY_TYPE_1_2.getName().equals(edmFQName.getName())) {
-
- // Properties
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.Int32).setFacets(
- new Facets().setNullable(false)));
- properties.add(new SimpleProperty().setName("Name").setType(EdmSimpleTypeKind.String).setFacets(
- new Facets().setNullable(false).setMaxLength(100))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_TITLE)));
- properties.add(new ComplexProperty().setName("Address").setType(new FullQualifiedName(NAMESPACE, "Address")));
- properties.add(new SimpleProperty().setName("Updated").setType(EdmSimpleTypeKind.DateTime)
- .setFacets(new Facets().setNullable(false).setConcurrencyMode(EdmConcurrencyMode.Fixed))
- .setCustomizableFeedMappings(
- new CustomizableFeedMappings().setFcTargetPath(EdmTargetPath.SYNDICATION_UPDATED)));
-
- // Navigation Properties
- List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
- navigationProperties.add(new NavigationProperty().setName("Cars")
- .setRelationship(ASSOCIATION_CAR_MANUFACTURER).setFromRole(ROLE_1_2).setToRole(ROLE_1_1));
-
- // Key
- List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
- keyProperties.add(new PropertyRef().setName("Id"));
- Key key = new Key().setKeys(keyProperties);
-
- return new EntityType().setName(ENTITY_TYPE_1_2.getName())
- .setProperties(properties)
- .setKey(key)
- .setNavigationProperties(navigationProperties);
-
- }
- }
-
- return null;
- }
-
- @Override
- public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
- if (COMPLEX_TYPE.getName().equals(edmFQName.getName())) {
- List<Property> properties = new ArrayList<Property>();
- properties.add(new SimpleProperty().setName("Street").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("City").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("ZipCode").setType(EdmSimpleTypeKind.String));
- properties.add(new SimpleProperty().setName("Country").setType(EdmSimpleTypeKind.String));
- return new ComplexType().setName(COMPLEX_TYPE.getName()).setProperties(properties);
- }
- }
-
- return null;
- }
-
- @Override
- public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
- if (NAMESPACE.equals(edmFQName.getNamespace())) {
- if (ASSOCIATION_CAR_MANUFACTURER.getName().equals(edmFQName.getName())) {
- return new Association().setName(ASSOCIATION_CAR_MANUFACTURER.getName())
- .setEnd1(
- new AssociationEnd().setType(ENTITY_TYPE_1_1).setRole(ROLE_1_1).setMultiplicity(EdmMultiplicity.MANY))
- .setEnd2(
- new AssociationEnd().setType(ENTITY_TYPE_1_2).setRole(ROLE_1_2).setMultiplicity(EdmMultiplicity.ONE));
- }
- }
- return null;
- }
-
- @Override
- public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (ENTITY_SET_NAME_CARS.equals(name)) {
- return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_1);
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(name)) {
- return new EntitySet().setName(name).setEntityType(ENTITY_TYPE_1_2);
- }
- }
- return null;
- }
-
- @Override
- public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association,
- final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (ASSOCIATION_CAR_MANUFACTURER.equals(association)) {
- return new AssociationSet().setName(ASSOCIATION_SET)
- .setAssociation(ASSOCIATION_CAR_MANUFACTURER)
- .setEnd1(new AssociationSetEnd().setRole(ROLE_1_2).setEntitySet(ENTITY_SET_NAME_MANUFACTURERS))
- .setEnd2(new AssociationSetEnd().setRole(ROLE_1_1).setEntitySet(ENTITY_SET_NAME_CARS));
- }
- }
- return null;
- }
-
- @Override
- public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
- if (ENTITY_CONTAINER.equals(entityContainer)) {
- if (FUNCTION_IMPORT.equals(name)) {
- return new FunctionImport().setName(name)
- .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
- .setHttpMethod("GET");
- }
- }
- return null;
- }
-
- @Override
- public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataException {
- if (name == null || "ODataCarsEntityContainer".equals(name)) {
- return new EntityContainerInfo().setName("ODataCarsEntityContainer").setDefaultEntityContainer(true);
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarODataSingleProcessor.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarODataSingleProcessor.java
deleted file mode 100755
index 8ee7f88..0000000
--- a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarODataSingleProcessor.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.sample.service;
-
-import static org.apache.olingo.odata2.sample.service.CarEdmProvider.ENTITY_SET_NAME_CARS;
-import static org.apache.olingo.odata2.sample.service.CarEdmProvider.ENTITY_SET_NAME_MANUFACTURERS;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-
-public class CarODataSingleProcessor extends ODataSingleProcessor {
-
- private final CarDataStore dataStore;
-
- public CarODataSingleProcessor() {
- dataStore = new CarDataStore();
- }
-
- @Override
- public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
- throws ODataException {
-
- EdmEntitySet entitySet;
-
- if (uriInfo.getNavigationSegments().size() == 0) {
- entitySet = uriInfo.getStartEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- return EntityProvider.writeFeed(contentType, entitySet, dataStore.getCars(),
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- return EntityProvider.writeFeed(contentType, entitySet, dataStore.getManufacturers(),
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
-
- } else if (uriInfo.getNavigationSegments().size() == 1) {
- // navigation first level, simplified example for illustration purposes only
- entitySet = uriInfo.getTargetEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- int manufacturerKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
-
- List<Map<String, Object>> cars = new ArrayList<Map<String, Object>>();
- cars.addAll(dataStore.getCarsFor(manufacturerKey));
-
- return EntityProvider.writeFeed(contentType, entitySet, cars, EntityProviderWriteProperties.serviceRoot(
- getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- throw new ODataNotImplementedException();
- }
-
- @Override
- public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
-
- if (uriInfo.getNavigationSegments().size() == 0) {
- EdmEntitySet entitySet = uriInfo.getStartEntitySet();
-
- if (ENTITY_SET_NAME_CARS.equals(entitySet.getName())) {
- int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
- Map<String, Object> data = dataStore.getCar(id);
-
- if (data != null) {
- URI serviceRoot = getContext().getPathInfo().getServiceRoot();
- ODataEntityProviderPropertiesBuilder propertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(serviceRoot);
-
- return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
- }
- } else if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- int id = getKeyValue(uriInfo.getKeyPredicates().get(0));
- Map<String, Object> data = dataStore.getManufacturer(id);
-
- if (data != null) {
- URI serviceRoot = getContext().getPathInfo().getServiceRoot();
- ODataEntityProviderPropertiesBuilder propertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(serviceRoot);
-
- return EntityProvider.writeEntry(contentType, entitySet, data, propertiesBuilder.build());
- }
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
-
- } else if (uriInfo.getNavigationSegments().size() == 1) {
- // navigation first level, simplified example for illustration purposes only
- EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
-
- Map<String, Object> data = null;
-
- if (ENTITY_SET_NAME_MANUFACTURERS.equals(entitySet.getName())) {
- int carKey = getKeyValue(uriInfo.getKeyPredicates().get(0));
- data = dataStore.getManufacturerFor(carKey);
- }
-
- if (data != null) {
- return EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(),
- data, EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).build());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- throw new ODataNotImplementedException();
- }
-
- private int getKeyValue(final KeyPredicate key) throws ODataException {
- EdmProperty property = key.getProperty();
- EdmSimpleType type = (EdmSimpleType) property.getType();
- return type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Integer.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarServiceFactory.java b/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarServiceFactory.java
deleted file mode 100755
index 82dc7ba..0000000
--- a/odata2-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/CarServiceFactory.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.sample.service;
-
-import org.apache.olingo.odata2.api.ODataService;
-import org.apache.olingo.odata2.api.ODataServiceFactory;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-
-public class CarServiceFactory extends ODataServiceFactory {
-
- @Override
- public ODataService createService(final ODataContext ctx) throws ODataException {
-
- EdmProvider edmProvider = new CarEdmProvider();
-
- ODataSingleProcessor singleProcessor = new CarODataSingleProcessor();
-
- return createODataSingleProcessorService(edmProvider, singleProcessor);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-service/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/resources/log4j.xml b/odata2-sample/cars-service/src/main/resources/log4j.xml
deleted file mode 100644
index aa456fb..0000000
--- a/odata2-sample/cars-service/src/main/resources/log4j.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- 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.
--->
-<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
- <appender name="console" class="org.apache.log4j.ConsoleAppender">
- <param name="Target" value="System.out" />
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%-5p %c{1} - %m%n" />
- </layout>
- </appender>
-
- <root>
- <priority value="error" />
- <appender-ref ref="console" />
- </root>
-</log4j:configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml b/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
deleted file mode 100755
index e3d1f41..0000000
--- a/odata2-sample/cars-service/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<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">
- <display-name>org.apache.olingo.odata2.sample</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- </welcome-file-list>
-
- <servlet>
- <servlet-name>CarServiceServlet</servlet-name>
- <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
- <init-param>
- <param-name>javax.ws.rs.Application</param-name>
- <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>
- </init-param>
- <init-param>
- <param-name>org.apache.olingo.odata2.service.factory</param-name>
- <param-value>org.apache.olingo.odata2.sample.service.CarServiceFactory</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>CarServiceServlet</servlet-name>
- <url-pattern>/CarService.svc/*</url-pattern>
- </servlet-mapping>
-</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/cars-service/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/odata2-sample/cars-service/src/main/webapp/index.html b/odata2-sample/cars-service/src/main/webapp/index.html
deleted file mode 100644
index 4d9a8e9..0000000
--- a/odata2-sample/cars-service/src/main/webapp/index.html
+++ /dev/null
@@ -1,52 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<!--
- 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.
--->
-<html>
- <head>
- <title></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
- <body>
- <h1>Apache Olingo - OData Car Sample Project</h1>
- <div>
- <ul>
- <li><a href="CarService.svc">Link to Car Sample Service Root - /CarService.svc</a></li>
- <li><a href="CarService.svc/$metadata">Link to Car Sample Service Metadata - /CarService.svc/$metadata</a></li>
- </ul>
- </div>
- <div>
- <ul>
- <li>Entity Sets
- <ul>
- <li><a href="CarService.svc/Cars">/Cars</a></li>
- <li><a href="CarService.svc/Manufacturers">/Manufacturers</a></li>
- </ul>
- </li>
- <li>Sample Entities
- <ul>
- <li><a href="CarService.svc/Cars(1)">/Cars(1)</a></li>
- <li><a href="CarService.svc/Cars(3)">/Cars(3)</a></li>
- <li><a href="CarService.svc/Cars(3)/Manufacturer">/Cars(3)/Manufacturer</a></li>
- <li><a href="CarService.svc/Manufacturers(1)">/Manufacturers(1)</a></li>
- </ul>
- </li>
- </ul>
- </div>
- </body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/59373b99/odata2-sample/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-sample/pom.xml b/odata2-sample/pom.xml
index 86cdeb0..d80b703 100644
--- a/odata2-sample/pom.xml
+++ b/odata2-sample/pom.xml
@@ -10,7 +10,7 @@
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>
- <artifactId>olingo-odata2-sample</artifactId>
+ <artifactId>olingo-odata2-sample-incubating</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
@@ -22,7 +22,6 @@
</parent>
<modules>
- <module>cars-service</module>
<module>cars-archetype</module>
</modules>
</project>