You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/09/23 12:05:29 UTC
git commit: Sample for Basic Read Tutorial
Updated Branches:
refs/heads/Samples [created] dcd18553c
Sample for Basic Read Tutorial
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/dcd18553
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/dcd18553
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/dcd18553
Branch: refs/heads/Samples
Commit: dcd18553ca48b327d6bed3ef0d8bff2d6aa90f9b
Parents: 80c0e6c
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Sep 23 12:05:06 2013 +0200
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Sep 23 12:05:06 2013 +0200
----------------------------------------------------------------------
odata-sample/cars-service/pom.xml | 32 +++
.../olingo/odata2/sample/service/DataStore.java | 151 ++++++++++++
.../odata2/sample/service/MyEdmProvider.java | 245 +++++++++++++++++++
.../sample/service/MyODataSingleProcessor.java | 127 ++++++++++
.../odata2/sample/service/MyServiceFactory.java | 21 ++
.../cars-service/src/main/resources/log4j.xml | 16 ++
odata-sample/cars-web/pom.xml | 41 ++++
.../cars-web/src/main/webapp/WEB-INF/web.xml | 28 +++
.../cars-web/src/main/webapp/index.html | 34 +++
odata-sample/pom.xml | 61 +++++
10 files changed, 756 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/dcd18553/odata-sample/cars-service/pom.xml
----------------------------------------------------------------------
diff --git a/odata-sample/cars-service/pom.xml b/odata-sample/cars-service/pom.xml
new file mode 100755
index 0000000..3066093
--- /dev/null
+++ b/odata-sample/cars-service/pom.xml
@@ -0,0 +1,32 @@
+<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>
+
+ <parent>
+ <groupId>org.apache.olingo.odata2.sample</groupId>
+ <artifactId>org.apache.olingo.odata2.sample.parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>org.apache.olingo.odata2.sample.service</artifactId>
+ <name>Cars-Sample-Project-Service</name>
+
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo.odata2</groupId>
+ <artifactId>api</artifactId>
+ <version>${version.olingo}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${version.org.slf4j}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${version.org.slf4j-l4j}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/dcd18553/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java
----------------------------------------------------------------------
diff --git a/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java b/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java
new file mode 100644
index 0000000..d302099
--- /dev/null
+++ b/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/DataStore.java
@@ -0,0 +1,151 @@
+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/dcd18553/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java b/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java
new file mode 100755
index 0000000..0d53d25
--- /dev/null
+++ b/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyEdmProvider.java
@@ -0,0 +1,245 @@
+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/dcd18553/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java
----------------------------------------------------------------------
diff --git a/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java b/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java
new file mode 100755
index 0000000..3f676c4
--- /dev/null
+++ b/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyODataSingleProcessor.java
@@ -0,0 +1,127 @@
+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/dcd18553/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java b/odata-sample/cars-service/src/main/java/org/apache/olingo/odata2/sample/service/MyServiceFactory.java
new file mode 100755
index 0000000..c15cb18
--- /dev/null
+++ b/odata-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/dcd18553/odata-sample/cars-service/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata-sample/cars-service/src/main/resources/log4j.xml b/odata-sample/cars-service/src/main/resources/log4j.xml
new file mode 100644
index 0000000..616e2d5
--- /dev/null
+++ b/odata-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/dcd18553/odata-sample/cars-web/pom.xml
----------------------------------------------------------------------
diff --git a/odata-sample/cars-web/pom.xml b/odata-sample/cars-web/pom.xml
new file mode 100755
index 0000000..f86f538
--- /dev/null
+++ b/odata-sample/cars-web/pom.xml
@@ -0,0 +1,41 @@
+<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>
+
+ <parent>
+ <groupId>org.apache.olingo.odata2.sample</groupId>
+ <artifactId>org.apache.olingo.odata2.sample.parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>org.apache.olingo.odata2.sample.web</artifactId>
+ <name>Cars-Sample-Project-WebApp</name>
+
+ <packaging>war</packaging>
+ <build>
+ <finalName>org.apache.olingo.odata2.sample.web</finalName>
+ </build>
+ <dependencies>
+ <dependency>
+ <!-- required because of auto detection of web facet 2.5 -->
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${version.javax.servlet}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${version.apache.cxf}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo.odata2.sample</groupId>
+ <artifactId>org.apache.olingo.odata2.sample.service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo.odata2</groupId>
+ <artifactId>core</artifactId>
+ <version>${version.olingo}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/dcd18553/odata-sample/cars-web/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata-sample/cars-web/src/main/webapp/WEB-INF/web.xml b/odata-sample/cars-web/src/main/webapp/WEB-INF/web.xml
new file mode 100755
index 0000000..e1ad1fb
--- /dev/null
+++ b/odata-sample/cars-web/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/dcd18553/odata-sample/cars-web/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/odata-sample/cars-web/src/main/webapp/index.html b/odata-sample/cars-web/src/main/webapp/index.html
new file mode 100644
index 0000000..7b5d183
--- /dev/null
+++ b/odata-sample/cars-web/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/dcd18553/odata-sample/pom.xml
----------------------------------------------------------------------
diff --git a/odata-sample/pom.xml b/odata-sample/pom.xml
new file mode 100755
index 0000000..2db407e
--- /dev/null
+++ b/odata-sample/pom.xml
@@ -0,0 +1,61 @@
+<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.odata2.sample</groupId>
+ <artifactId>org.apache.olingo.odata2.sample.parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Cars-Sample-Project</name>
+
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>cars-service</module>
+ <module>cars-web</module>
+ </modules>
+
+ <properties>
+ <version.apache.cxf>2.7.5</version.apache.cxf>
+ <version.olingo>1.0.0-SNAPSHOT</version.olingo>
+ <version.javax.servlet>2.5</version.javax.servlet>
+ <version.org.slf4j>1.7.1</version.org.slf4j>
+ <version.org.slf4j-l4j>1.7.1</version.org.slf4j-l4j>
+ </properties>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <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-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>
+ <wtpversion>2.0</wtpversion>
+ <downloadSources>true</downloadSources>
+ <downloadJavadocs>true</downloadJavadocs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>